how to do factor analysis for 3 dichotomous and 2 ordinal variables?
-
Login or Register
- Log in with
contract mm_social_connection_PC mm_social_connection_TC aversion_score HC_Awareness dataex
like this
* Example generated by -dataex-. For more info, type help dataex clear input float(aversion_score HC_Awareness mm_social_connection_PC mm_social_connection_TC) int _freq 0 0 0 0 1666 0 1 0 0 279 1 1 0 0 1855 0 0 0 .3333333 6 0 1 0 .3333333 6 1 1 0 .3333333 2 0 0 0 .6666667 7 0 1 0 .6666667 7 1 1 0 .6666667 7 0 0 0 1 3 0 1 0 1 1 0 0 .3333333 0 119 0 1 .3333333 0 23 1 1 .3333333 0 42 0 0 .3333333 .3333333 7 0 1 .3333333 .3333333 2 1 1 .3333333 .3333333 1 1 1 .3333333 .6666667 1 0 0 .6666667 0 35 0 1 .6666667 0 13 1 1 .6666667 0 18 0 0 .6666667 .3333333 2 0 0 .6666667 .6666667 2 1 1 .6666667 .6666667 1 0 1 .6666667 1 1 0 0 1 0 6 0 1 1 0 6 1 1 1 0 9 0 1 1 1 4 end
version 18.0 clear * quietly input float(aversion_score HC_Awareness mm_social_connection_PC mm_social_connection_TC) int _freq <redacted for brevity> end * * Begin here * rename (aversion_score HC_Awareness mm_social_connection_PC /// mm_social_connection_TC) (avs hca scp sct) foreach var of varlist sc? { quietly replace `var' = round(3 * `var') } assert _freq > 0 quietly expand _freq drop _freq // Your problem is here tabulate avs hca tetrachoric avs hca // Either exclude one of the collinear indicators . . . polychoric avs sc? factormat r(R), n(`r(N)') ml nolog // . . . or resort to a couple of fudge factors in order to get the crank to turn tetrachoric avs hca, zeroadjust tempname rho scalar define `rho' = r(Rho)[2, 2] polychoric _all local n `r(N)' tempname Rho matrix define `Rho' = r(R) matrix define `Rho'[2, 1] = `rho' matrix define `Rho'[1, 2] = `rho' factormat `Rho', n(`r(N)') forcepsd ml nolog exit
scalar define `rho' = r(Rho)[2, 2]
version 18.0 clear * quietly input float(aversion_score HC_Awareness mm_social_connection_PC mm_social_connection_TC) int _freq <redacted> end * * Begin here * rename (aversion_score HC_Awareness mm_social_connection_PC /// mm_social_connection_TC) (avs hca scp sct) foreach var of varlist sc? { quietly replace `var' = round(3 * `var') } assert _freq > 0 quietly expand _freq drop _freq // Your problem is here tabulate avs hca tetrachoric avs hca // Either exclude one of the collinear indicators . . . polychoric avs sc? factormat r(R), n(`r(N)') factors(1) // . . . or resort to a couple of fudge factors in order to get the crank to turn tetrachoric avs hca, zeroadjust tempname rho scalar define `rho' = r(Rho)[2, 1] polychoric _all tempname Rho matrix define `Rho' = r(R) matrix define `Rho'[2, 1] = `rho' matrix define `Rho'[1, 2] = `rho' factormat `Rho', n(`r(N)') forcepsd factors(1) exit
* Example generated by -dataex-. For more info, type help dataex clear input float(aversion_score HC_Awareness mm_social_connection_PC mm_social_connection_TC) int _freq 0 0 0 0 1666 0 1 0 0 279 1 1 0 0 1855 0 0 0 .3333333 6 0 1 0 .3333333 6 1 1 0 .3333333 2 0 0 0 .6666667 7 0 1 0 .6666667 7 1 1 0 .6666667 7 0 0 0 1 3 0 1 0 1 1 0 0 .3333333 0 119 0 1 .3333333 0 23 1 1 .3333333 0 42 0 0 .3333333 .3333333 7 0 1 .3333333 .3333333 2 1 1 .3333333 .3333333 1 1 1 .3333333 .6666667 1 0 0 .6666667 0 35 0 1 .6666667 0 13 1 1 .6666667 0 18 0 0 .6666667 .3333333 2 0 0 .6666667 .6666667 2 1 1 .6666667 .6666667 1 0 1 .6666667 1 1 0 0 1 0 6 0 1 1 0 6 1 1 1 0 9 0 1 1 1 4 end ds _freq, not local vars `r(varlist)' corr `vars' [fw=_freq] pca `vars' [fw=_freq] foreach v of local vars { local lbl : subinstr local v "_" " ", all label var `v' "`lbl'" } pcacoefsave using pca_results, replace use pca_results, clear gen sign = sign(corr) gen where = -0.1 tabplot varlabel PC [iw=corr] , subtitle(correlations between variables and PCs) sep(sign) bar1(color(stc2)) bar2(color(stc1)) showval(format(%04.3f)) ytitle("") addplot(scatter where PC, ms(none) mlabel(eigenvalue) mlabformat(%4.3f) mlabsize(medium) mlabcolor(magenta)mlabpos(0) ymla(-0.1 "eigenvalues", labcolor(magenta) tlc(none) labsize(medium)))
scalar define `rho' = r(Rho)[2, 2]
version 18.0
clear *
quietly input float(aversion_score HC_Awareness mm_social_connection_PC mm_social_connection_TC) int _freq
<redacted>
end
*
* Begin here
*
rename (aversion_score HC_Awareness mm_social_connection_PC ///
mm_social_connection_TC) (avs hca scp sct)
foreach var of varlist sc? {
quietly replace `var' = round(3 * `var')
}
assert _freq > 0
quietly expand _freq
drop _freq
// Your problem is here
tabulate avs hca
tetrachoric avs hca
// Either exclude one of the collinear indicators . . .
polychoric avs sc?
factormat r(R), n(`r(N)') factors(1)
// . . . or resort to a couple of fudge factors in order to get the crank to turn
tetrachoric avs hca, zeroadjust
tempname rho
scalar define `rho' = r(Rho)[2, 1]
polychoric _all
tempname Rho
matrix define `Rho' = r(R)
matrix define `Rho'[2, 1] = `rho'
matrix define `Rho'[1, 2] = `rho'
factormat `Rho', n(`r(N)') forcepsd factors(1)
exit
Comment