R psych tetrachoric - dichotomic variables2019 Community Moderator Electionerror.bars.bypsych Multiple variablesHow do I enter environmental variables only as a factor (not as continuous variables) in the capscale function?R: Testing each level of a factor without creating new variablesRunning Omega with Psych library in RSelecting factor loadings above threshold in RR Function to automate analyses over a list of permutated variablesR Psych package: multi histogram labels by variableChange factor labels in psych::fa or psych::fa.diagramSeparating binary data based on variationperforming correspondence analysis on a dataset?

Virginia employer terminated employee and wants signing bonus returned

How much attack damage does the AC boost from a shield prevent on average?

Do items de-spawn in Diablo?

A three room house but a three headED dog

Can you reject a postdoc offer after the PI has paid a large sum for flights/accommodation for your visit?

MTG: Can I kill an opponent in response to lethal activated abilities, and not take the damage?

String reversal in Python

How do I locate a classical quotation?

How do I express some one as a black person?

Could you please stop shuffling the deck and play already?

Finding algorithms of QGIS commands?

Why does Captain Marvel assume the planet where she lands would recognize her credentials?

Is Gradient Descent central to every optimizer?

Why would a jet engine that runs at temps excess of 2000°C burn when it crashes?

What are some noteworthy "mic-drop" moments in math?

Making a sword in the stone, in a medieval world without magic

Latest web browser compatible with Windows 98

Solving "Resistance between two nodes on a grid" problem in Mathematica

2×2×2 rubik's cube corner is twisted!

Should I tell my boss the work he did was worthless

Why is there a voltage between the mains ground and my radiator?

How did Alan Turing break the enigma code using the hint given by the lady in the bar?

PTIJ: Why can't I eat anything?

Can someone explain what is being said here in color publishing in the American Mathematical Monthly?



R psych tetrachoric - dichotomic variables



2019 Community Moderator Electionerror.bars.bypsych Multiple variablesHow do I enter environmental variables only as a factor (not as continuous variables) in the capscale function?R: Testing each level of a factor without creating new variablesRunning Omega with Psych library in RSelecting factor loadings above threshold in RR Function to automate analyses over a list of permutated variablesR Psych package: multi histogram labels by variableChange factor labels in psych::fa or psych::fa.diagramSeparating binary data based on variationperforming correspondence analysis on a dataset?










1















I have a dataframe of dichotomic variables corresponding to items of a personality questionnaire. Here are the first lines.



 head(mixclinic)
# A tibble: 6 x 15
CMS_1 CMS_2 CMS_3 CMS_4 CMS_5 CMS_6 CMS_7 CMS_8 CMS_9 CMS_10 CMS_11
<fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct>
1 1 1 0 1 0 1 0 0 0 0 0
2 1 1 0 1 0 0 0 1 0 0 0
3 1 1 0 1 0 1 0 0 0 0 0
4 0 1 0 1 0 1 0 1 0 0 0
5 0 1 0 1 0 1 0 0 0 0 0
6 1 1 0 1 1 1 0 0 0 0 0


I would like to perform tetrachoric correlation in order to find the factors explaining the greatest part of the variability. Searching R-based resources, I came across the 'psych' package which has the function tetrachoric. I read the documentation but, nonetheless, I could not perform the analysis. There seems to be a lack of tutorial to help out. Could anyone help or refer to useful sources? Thanks










share|improve this question


























    1















    I have a dataframe of dichotomic variables corresponding to items of a personality questionnaire. Here are the first lines.



     head(mixclinic)
    # A tibble: 6 x 15
    CMS_1 CMS_2 CMS_3 CMS_4 CMS_5 CMS_6 CMS_7 CMS_8 CMS_9 CMS_10 CMS_11
    <fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct>
    1 1 1 0 1 0 1 0 0 0 0 0
    2 1 1 0 1 0 0 0 1 0 0 0
    3 1 1 0 1 0 1 0 0 0 0 0
    4 0 1 0 1 0 1 0 1 0 0 0
    5 0 1 0 1 0 1 0 0 0 0 0
    6 1 1 0 1 1 1 0 0 0 0 0


    I would like to perform tetrachoric correlation in order to find the factors explaining the greatest part of the variability. Searching R-based resources, I came across the 'psych' package which has the function tetrachoric. I read the documentation but, nonetheless, I could not perform the analysis. There seems to be a lack of tutorial to help out. Could anyone help or refer to useful sources? Thanks










    share|improve this question
























      1












      1








      1








      I have a dataframe of dichotomic variables corresponding to items of a personality questionnaire. Here are the first lines.



       head(mixclinic)
      # A tibble: 6 x 15
      CMS_1 CMS_2 CMS_3 CMS_4 CMS_5 CMS_6 CMS_7 CMS_8 CMS_9 CMS_10 CMS_11
      <fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct>
      1 1 1 0 1 0 1 0 0 0 0 0
      2 1 1 0 1 0 0 0 1 0 0 0
      3 1 1 0 1 0 1 0 0 0 0 0
      4 0 1 0 1 0 1 0 1 0 0 0
      5 0 1 0 1 0 1 0 0 0 0 0
      6 1 1 0 1 1 1 0 0 0 0 0


      I would like to perform tetrachoric correlation in order to find the factors explaining the greatest part of the variability. Searching R-based resources, I came across the 'psych' package which has the function tetrachoric. I read the documentation but, nonetheless, I could not perform the analysis. There seems to be a lack of tutorial to help out. Could anyone help or refer to useful sources? Thanks










      share|improve this question














      I have a dataframe of dichotomic variables corresponding to items of a personality questionnaire. Here are the first lines.



       head(mixclinic)
      # A tibble: 6 x 15
      CMS_1 CMS_2 CMS_3 CMS_4 CMS_5 CMS_6 CMS_7 CMS_8 CMS_9 CMS_10 CMS_11
      <fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct>
      1 1 1 0 1 0 1 0 0 0 0 0
      2 1 1 0 1 0 0 0 1 0 0 0
      3 1 1 0 1 0 1 0 0 0 0 0
      4 0 1 0 1 0 1 0 1 0 0 0
      5 0 1 0 1 0 1 0 0 0 0 0
      6 1 1 0 1 1 1 0 0 0 0 0


      I would like to perform tetrachoric correlation in order to find the factors explaining the greatest part of the variability. Searching R-based resources, I came across the 'psych' package which has the function tetrachoric. I read the documentation but, nonetheless, I could not perform the analysis. There seems to be a lack of tutorial to help out. Could anyone help or refer to useful sources? Thanks







      r psych






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 6 at 16:23









      FcmCFcmC

      456




      456






















          1 Answer
          1






          active

          oldest

          votes


















          1














          It may be that the function does not handle factors well when a dataframe is entered as the argument (perhaps if you switched them all to numeric). However, it takes a matrix as an argument so this worked for the data set I created. In the future, it is always helpful to include a reproducible example. Hope this helps!



          Edit: to clarify. I think the issue is that your dataset consisted of factors. The function does not seem to work when the variables are factors. It will work if the variables are numeric or if the data entered is a matrix. So, however you choose to convert your dataframe columns to numeric, or dataframe to a matrix, will work (i.e., the df_matrix <- data.matrix(df) line from my code converted the dataframe to a matrix). Let me know if you have any questions.



          > # Creating your dataset
          >
          > library(tidyverse)
          > library(psych)
          >
          > df <- data.frame(CMS_1 = sample(2, replace = T, size = 10)-1,
          + CMS_2 = sample(2, replace = T, size = 10)-1,
          + CMS_3 = sample(2, replace = T, size = 10)-1,
          + CMS_4 = sample(2, replace = T, size = 10)-1,
          + CMS_5 = sample(2, replace = T, size = 10)-1,
          + CMS_6 = sample(2, replace = T, size = 10)-1,
          + CMS_7 = sample(2, replace = T, size = 10)-1,
          + CMS_8 = sample(2, replace = T, size = 10)-1)
          >
          > df <- df %>% mutate_if(is.numeric, as.factor)
          > str(df)
          'data.frame': 10 obs. of 8 variables:
          $ CMS_1: Factor w/ 2 levels "0","1": 1 2 1 2 2 2 1 2 2 2
          $ CMS_2: Factor w/ 2 levels "0","1": 1 2 2 1 2 2 1 2 1 2
          $ CMS_3: Factor w/ 2 levels "0","1": 1 1 2 2 1 1 1 1 1 1
          $ CMS_4: Factor w/ 2 levels "0","1": 2 2 1 2 1 1 2 1 1 2
          $ CMS_5: Factor w/ 2 levels "0","1": 2 1 1 2 2 2 1 2 1 2
          $ CMS_6: Factor w/ 2 levels "0","1": 2 2 1 1 2 2 2 2 1 2
          $ CMS_7: Factor w/ 2 levels "0","1": 2 1 2 1 1 2 1 1 1 2
          $ CMS_8: Factor w/ 2 levels "0","1": 1 2 2 1 1 2 1 1 1 1
          >
          > # Covnerting your data.frame to a matrix
          > df_matrix <- data.matrix(df)
          >
          >
          > tetrachoric(df_matrix)
          For i = 6 j = 3 A cell entry of 0 was replaced with correct = 0.5. Check your data!
          For i = 8 j = 2 A cell entry of 0 was replaced with correct = 0.5. Check your data!

          Call: tetrachoric(x = df_matrix)
          tetrachoric correlation
          CMS_1 CMS_2 CMS_3 CMS_4 CMS_5 CMS_6 CMS_7 CMS_8
          CMS_1 1.00
          CMS_2 0.47 1.00
          CMS_3 -0.31 -0.21 1.00
          CMS_4 -0.37 -0.54 -0.02 1.00
          CMS_5 0.43 0.27 -0.22 0.02 1.00
          CMS_6 0.14 0.45 -0.74 0.29 0.44 1.00
          CMS_7 -0.44 0.34 0.22 -0.02 0.29 0.20 1.00
          CMS_8 -0.13 0.58 0.33 -0.33 -0.44 -0.10 0.46 1.00

          with tau of
          CMS_1 CMS_2 CMS_3 CMS_4 CMS_5 CMS_6 CMS_7 CMS_8
          -0.52 -0.25 0.84 0.00 -0.25 -0.52 0.25 0.52
          Warning message:
          In cor.smooth(mat) : Matrix was not positive definite, smoothing was done





          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55027778%2fr-psych-tetrachoric-dichotomic-variables%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            It may be that the function does not handle factors well when a dataframe is entered as the argument (perhaps if you switched them all to numeric). However, it takes a matrix as an argument so this worked for the data set I created. In the future, it is always helpful to include a reproducible example. Hope this helps!



            Edit: to clarify. I think the issue is that your dataset consisted of factors. The function does not seem to work when the variables are factors. It will work if the variables are numeric or if the data entered is a matrix. So, however you choose to convert your dataframe columns to numeric, or dataframe to a matrix, will work (i.e., the df_matrix <- data.matrix(df) line from my code converted the dataframe to a matrix). Let me know if you have any questions.



            > # Creating your dataset
            >
            > library(tidyverse)
            > library(psych)
            >
            > df <- data.frame(CMS_1 = sample(2, replace = T, size = 10)-1,
            + CMS_2 = sample(2, replace = T, size = 10)-1,
            + CMS_3 = sample(2, replace = T, size = 10)-1,
            + CMS_4 = sample(2, replace = T, size = 10)-1,
            + CMS_5 = sample(2, replace = T, size = 10)-1,
            + CMS_6 = sample(2, replace = T, size = 10)-1,
            + CMS_7 = sample(2, replace = T, size = 10)-1,
            + CMS_8 = sample(2, replace = T, size = 10)-1)
            >
            > df <- df %>% mutate_if(is.numeric, as.factor)
            > str(df)
            'data.frame': 10 obs. of 8 variables:
            $ CMS_1: Factor w/ 2 levels "0","1": 1 2 1 2 2 2 1 2 2 2
            $ CMS_2: Factor w/ 2 levels "0","1": 1 2 2 1 2 2 1 2 1 2
            $ CMS_3: Factor w/ 2 levels "0","1": 1 1 2 2 1 1 1 1 1 1
            $ CMS_4: Factor w/ 2 levels "0","1": 2 2 1 2 1 1 2 1 1 2
            $ CMS_5: Factor w/ 2 levels "0","1": 2 1 1 2 2 2 1 2 1 2
            $ CMS_6: Factor w/ 2 levels "0","1": 2 2 1 1 2 2 2 2 1 2
            $ CMS_7: Factor w/ 2 levels "0","1": 2 1 2 1 1 2 1 1 1 2
            $ CMS_8: Factor w/ 2 levels "0","1": 1 2 2 1 1 2 1 1 1 1
            >
            > # Covnerting your data.frame to a matrix
            > df_matrix <- data.matrix(df)
            >
            >
            > tetrachoric(df_matrix)
            For i = 6 j = 3 A cell entry of 0 was replaced with correct = 0.5. Check your data!
            For i = 8 j = 2 A cell entry of 0 was replaced with correct = 0.5. Check your data!

            Call: tetrachoric(x = df_matrix)
            tetrachoric correlation
            CMS_1 CMS_2 CMS_3 CMS_4 CMS_5 CMS_6 CMS_7 CMS_8
            CMS_1 1.00
            CMS_2 0.47 1.00
            CMS_3 -0.31 -0.21 1.00
            CMS_4 -0.37 -0.54 -0.02 1.00
            CMS_5 0.43 0.27 -0.22 0.02 1.00
            CMS_6 0.14 0.45 -0.74 0.29 0.44 1.00
            CMS_7 -0.44 0.34 0.22 -0.02 0.29 0.20 1.00
            CMS_8 -0.13 0.58 0.33 -0.33 -0.44 -0.10 0.46 1.00

            with tau of
            CMS_1 CMS_2 CMS_3 CMS_4 CMS_5 CMS_6 CMS_7 CMS_8
            -0.52 -0.25 0.84 0.00 -0.25 -0.52 0.25 0.52
            Warning message:
            In cor.smooth(mat) : Matrix was not positive definite, smoothing was done





            share|improve this answer





























              1














              It may be that the function does not handle factors well when a dataframe is entered as the argument (perhaps if you switched them all to numeric). However, it takes a matrix as an argument so this worked for the data set I created. In the future, it is always helpful to include a reproducible example. Hope this helps!



              Edit: to clarify. I think the issue is that your dataset consisted of factors. The function does not seem to work when the variables are factors. It will work if the variables are numeric or if the data entered is a matrix. So, however you choose to convert your dataframe columns to numeric, or dataframe to a matrix, will work (i.e., the df_matrix <- data.matrix(df) line from my code converted the dataframe to a matrix). Let me know if you have any questions.



              > # Creating your dataset
              >
              > library(tidyverse)
              > library(psych)
              >
              > df <- data.frame(CMS_1 = sample(2, replace = T, size = 10)-1,
              + CMS_2 = sample(2, replace = T, size = 10)-1,
              + CMS_3 = sample(2, replace = T, size = 10)-1,
              + CMS_4 = sample(2, replace = T, size = 10)-1,
              + CMS_5 = sample(2, replace = T, size = 10)-1,
              + CMS_6 = sample(2, replace = T, size = 10)-1,
              + CMS_7 = sample(2, replace = T, size = 10)-1,
              + CMS_8 = sample(2, replace = T, size = 10)-1)
              >
              > df <- df %>% mutate_if(is.numeric, as.factor)
              > str(df)
              'data.frame': 10 obs. of 8 variables:
              $ CMS_1: Factor w/ 2 levels "0","1": 1 2 1 2 2 2 1 2 2 2
              $ CMS_2: Factor w/ 2 levels "0","1": 1 2 2 1 2 2 1 2 1 2
              $ CMS_3: Factor w/ 2 levels "0","1": 1 1 2 2 1 1 1 1 1 1
              $ CMS_4: Factor w/ 2 levels "0","1": 2 2 1 2 1 1 2 1 1 2
              $ CMS_5: Factor w/ 2 levels "0","1": 2 1 1 2 2 2 1 2 1 2
              $ CMS_6: Factor w/ 2 levels "0","1": 2 2 1 1 2 2 2 2 1 2
              $ CMS_7: Factor w/ 2 levels "0","1": 2 1 2 1 1 2 1 1 1 2
              $ CMS_8: Factor w/ 2 levels "0","1": 1 2 2 1 1 2 1 1 1 1
              >
              > # Covnerting your data.frame to a matrix
              > df_matrix <- data.matrix(df)
              >
              >
              > tetrachoric(df_matrix)
              For i = 6 j = 3 A cell entry of 0 was replaced with correct = 0.5. Check your data!
              For i = 8 j = 2 A cell entry of 0 was replaced with correct = 0.5. Check your data!

              Call: tetrachoric(x = df_matrix)
              tetrachoric correlation
              CMS_1 CMS_2 CMS_3 CMS_4 CMS_5 CMS_6 CMS_7 CMS_8
              CMS_1 1.00
              CMS_2 0.47 1.00
              CMS_3 -0.31 -0.21 1.00
              CMS_4 -0.37 -0.54 -0.02 1.00
              CMS_5 0.43 0.27 -0.22 0.02 1.00
              CMS_6 0.14 0.45 -0.74 0.29 0.44 1.00
              CMS_7 -0.44 0.34 0.22 -0.02 0.29 0.20 1.00
              CMS_8 -0.13 0.58 0.33 -0.33 -0.44 -0.10 0.46 1.00

              with tau of
              CMS_1 CMS_2 CMS_3 CMS_4 CMS_5 CMS_6 CMS_7 CMS_8
              -0.52 -0.25 0.84 0.00 -0.25 -0.52 0.25 0.52
              Warning message:
              In cor.smooth(mat) : Matrix was not positive definite, smoothing was done





              share|improve this answer



























                1












                1








                1







                It may be that the function does not handle factors well when a dataframe is entered as the argument (perhaps if you switched them all to numeric). However, it takes a matrix as an argument so this worked for the data set I created. In the future, it is always helpful to include a reproducible example. Hope this helps!



                Edit: to clarify. I think the issue is that your dataset consisted of factors. The function does not seem to work when the variables are factors. It will work if the variables are numeric or if the data entered is a matrix. So, however you choose to convert your dataframe columns to numeric, or dataframe to a matrix, will work (i.e., the df_matrix <- data.matrix(df) line from my code converted the dataframe to a matrix). Let me know if you have any questions.



                > # Creating your dataset
                >
                > library(tidyverse)
                > library(psych)
                >
                > df <- data.frame(CMS_1 = sample(2, replace = T, size = 10)-1,
                + CMS_2 = sample(2, replace = T, size = 10)-1,
                + CMS_3 = sample(2, replace = T, size = 10)-1,
                + CMS_4 = sample(2, replace = T, size = 10)-1,
                + CMS_5 = sample(2, replace = T, size = 10)-1,
                + CMS_6 = sample(2, replace = T, size = 10)-1,
                + CMS_7 = sample(2, replace = T, size = 10)-1,
                + CMS_8 = sample(2, replace = T, size = 10)-1)
                >
                > df <- df %>% mutate_if(is.numeric, as.factor)
                > str(df)
                'data.frame': 10 obs. of 8 variables:
                $ CMS_1: Factor w/ 2 levels "0","1": 1 2 1 2 2 2 1 2 2 2
                $ CMS_2: Factor w/ 2 levels "0","1": 1 2 2 1 2 2 1 2 1 2
                $ CMS_3: Factor w/ 2 levels "0","1": 1 1 2 2 1 1 1 1 1 1
                $ CMS_4: Factor w/ 2 levels "0","1": 2 2 1 2 1 1 2 1 1 2
                $ CMS_5: Factor w/ 2 levels "0","1": 2 1 1 2 2 2 1 2 1 2
                $ CMS_6: Factor w/ 2 levels "0","1": 2 2 1 1 2 2 2 2 1 2
                $ CMS_7: Factor w/ 2 levels "0","1": 2 1 2 1 1 2 1 1 1 2
                $ CMS_8: Factor w/ 2 levels "0","1": 1 2 2 1 1 2 1 1 1 1
                >
                > # Covnerting your data.frame to a matrix
                > df_matrix <- data.matrix(df)
                >
                >
                > tetrachoric(df_matrix)
                For i = 6 j = 3 A cell entry of 0 was replaced with correct = 0.5. Check your data!
                For i = 8 j = 2 A cell entry of 0 was replaced with correct = 0.5. Check your data!

                Call: tetrachoric(x = df_matrix)
                tetrachoric correlation
                CMS_1 CMS_2 CMS_3 CMS_4 CMS_5 CMS_6 CMS_7 CMS_8
                CMS_1 1.00
                CMS_2 0.47 1.00
                CMS_3 -0.31 -0.21 1.00
                CMS_4 -0.37 -0.54 -0.02 1.00
                CMS_5 0.43 0.27 -0.22 0.02 1.00
                CMS_6 0.14 0.45 -0.74 0.29 0.44 1.00
                CMS_7 -0.44 0.34 0.22 -0.02 0.29 0.20 1.00
                CMS_8 -0.13 0.58 0.33 -0.33 -0.44 -0.10 0.46 1.00

                with tau of
                CMS_1 CMS_2 CMS_3 CMS_4 CMS_5 CMS_6 CMS_7 CMS_8
                -0.52 -0.25 0.84 0.00 -0.25 -0.52 0.25 0.52
                Warning message:
                In cor.smooth(mat) : Matrix was not positive definite, smoothing was done





                share|improve this answer















                It may be that the function does not handle factors well when a dataframe is entered as the argument (perhaps if you switched them all to numeric). However, it takes a matrix as an argument so this worked for the data set I created. In the future, it is always helpful to include a reproducible example. Hope this helps!



                Edit: to clarify. I think the issue is that your dataset consisted of factors. The function does not seem to work when the variables are factors. It will work if the variables are numeric or if the data entered is a matrix. So, however you choose to convert your dataframe columns to numeric, or dataframe to a matrix, will work (i.e., the df_matrix <- data.matrix(df) line from my code converted the dataframe to a matrix). Let me know if you have any questions.



                > # Creating your dataset
                >
                > library(tidyverse)
                > library(psych)
                >
                > df <- data.frame(CMS_1 = sample(2, replace = T, size = 10)-1,
                + CMS_2 = sample(2, replace = T, size = 10)-1,
                + CMS_3 = sample(2, replace = T, size = 10)-1,
                + CMS_4 = sample(2, replace = T, size = 10)-1,
                + CMS_5 = sample(2, replace = T, size = 10)-1,
                + CMS_6 = sample(2, replace = T, size = 10)-1,
                + CMS_7 = sample(2, replace = T, size = 10)-1,
                + CMS_8 = sample(2, replace = T, size = 10)-1)
                >
                > df <- df %>% mutate_if(is.numeric, as.factor)
                > str(df)
                'data.frame': 10 obs. of 8 variables:
                $ CMS_1: Factor w/ 2 levels "0","1": 1 2 1 2 2 2 1 2 2 2
                $ CMS_2: Factor w/ 2 levels "0","1": 1 2 2 1 2 2 1 2 1 2
                $ CMS_3: Factor w/ 2 levels "0","1": 1 1 2 2 1 1 1 1 1 1
                $ CMS_4: Factor w/ 2 levels "0","1": 2 2 1 2 1 1 2 1 1 2
                $ CMS_5: Factor w/ 2 levels "0","1": 2 1 1 2 2 2 1 2 1 2
                $ CMS_6: Factor w/ 2 levels "0","1": 2 2 1 1 2 2 2 2 1 2
                $ CMS_7: Factor w/ 2 levels "0","1": 2 1 2 1 1 2 1 1 1 2
                $ CMS_8: Factor w/ 2 levels "0","1": 1 2 2 1 1 2 1 1 1 1
                >
                > # Covnerting your data.frame to a matrix
                > df_matrix <- data.matrix(df)
                >
                >
                > tetrachoric(df_matrix)
                For i = 6 j = 3 A cell entry of 0 was replaced with correct = 0.5. Check your data!
                For i = 8 j = 2 A cell entry of 0 was replaced with correct = 0.5. Check your data!

                Call: tetrachoric(x = df_matrix)
                tetrachoric correlation
                CMS_1 CMS_2 CMS_3 CMS_4 CMS_5 CMS_6 CMS_7 CMS_8
                CMS_1 1.00
                CMS_2 0.47 1.00
                CMS_3 -0.31 -0.21 1.00
                CMS_4 -0.37 -0.54 -0.02 1.00
                CMS_5 0.43 0.27 -0.22 0.02 1.00
                CMS_6 0.14 0.45 -0.74 0.29 0.44 1.00
                CMS_7 -0.44 0.34 0.22 -0.02 0.29 0.20 1.00
                CMS_8 -0.13 0.58 0.33 -0.33 -0.44 -0.10 0.46 1.00

                with tau of
                CMS_1 CMS_2 CMS_3 CMS_4 CMS_5 CMS_6 CMS_7 CMS_8
                -0.52 -0.25 0.84 0.00 -0.25 -0.52 0.25 0.52
                Warning message:
                In cor.smooth(mat) : Matrix was not positive definite, smoothing was done






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 6 at 16:59

























                answered Mar 6 at 16:48









                AndrewAndrew

                428110




                428110





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55027778%2fr-psych-tetrachoric-dichotomic-variables%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    1928 у кіно

                    Захаров Федір Захарович

                    Ель Греко