Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 7.83 KB | None | 0 0
  1. * Encoding: UTF-8.
  2.  
  3.  
  4. set mxloops=9000 printback=off width=80  seed = 1953125.
  5. matrix.
  6.  
  7. * Enter the name/location of the data file for analyses after "FILE =";
  8.   If you specify "FILE = *", then the program will read the current,
  9.   active SPSS data file;  You can alternatively enter the name/location
  10.   of a previously saved SPSS systemfile instead of "*";
  11.   you can use the "/ VAR =" subcommand after "/ missing=omit"
  12.   subcommand to select variables for the analyses.
  13.  
  14. GET raw / FILE = * / missing=omit / VAR =  s4  to  s52.  
  15.  
  16. * Enter the desired number of parallel data sets here.
  17. compute ndatsets = 1000.
  18. * Enter the desired percentile here.
  19. compute percent  = 95.
  20.  
  21. * Enter either
  22.   1 for principal components analysis, or
  23.   2 for principal axis/common factor analysis.
  24. compute kind = 2.
  25.  
  26. * Enter either
  27.   1 for normally distributed random data generation parallel analysis, or
  28.   2 for permutations of the raw data set.
  29. compute randtype = 2.
  30.  
  31. ****************** End of user specifications. ******************
  32.  
  33. compute ncases   = nrow(raw).
  34. compute nvars    = ncol(raw).
  35.  
  36. * principal components analysis & random normal data generation.
  37. do if (kind = 1 and randtype = 1).
  38. compute nm1 = 1 / (ncases-1).
  39. compute vcv = nm1 * (sscp(raw) - ((t(csum(raw))*csum(raw))/ncases)).
  40. compute d = inv(mdiag(sqrt(diag(vcv)))).
  41. compute realeval = eval(d * vcv * d).
  42. compute evals = make(nvars,ndatsets,-9999).
  43. loop #nds = 1 to ndatsets.
  44. compute x = sqrt(2 * (ln(uniform(ncases,nvars)) * -1) ) &*
  45.             cos(6.283185 * uniform(ncases,nvars) ).
  46. compute vcv = nm1 * (sscp(x) - ((t(csum(x))*csum(x))/ncases)).
  47. compute d = inv(mdiag(sqrt(diag(vcv)))).
  48. compute evals(:,#nds) = eval(d * vcv * d).
  49. end loop.
  50. end if.
  51.  
  52. * principal components analysis & raw data permutation.
  53. do if (kind = 1 and randtype = 2).
  54. compute nm1 = 1 / (ncases-1).
  55. compute vcv = nm1 * (sscp(raw) - ((t(csum(raw))*csum(raw))/ncases)).
  56. compute d = inv(mdiag(sqrt(diag(vcv)))).
  57. compute realeval = eval(d * vcv * d).
  58. compute evals = make(nvars,ndatsets,-9999).
  59. loop #nds = 1 to ndatsets.
  60. compute x = raw.
  61. loop #c = 1 to nvars.
  62. loop #r = 1 to (ncases -1).
  63. compute k = trunc( (ncases - #r + 1) * uniform(1,1) + 1 )  + #r - 1.
  64. compute d = x(#r,#c).
  65. compute x(#r,#c) = x(k,#c).
  66. compute x(k,#c) = d.
  67. end loop.
  68. end loop.
  69. compute vcv = nm1 * (sscp(x) - ((t(csum(x))*csum(x))/ncases)).
  70. compute d = inv(mdiag(sqrt(diag(vcv)))).
  71. compute evals(:,#nds) = eval(d * vcv * d).
  72. end loop.
  73. end if.
  74.  
  75. * PAF/common factor analysis & random normal data generation.
  76. do if (kind = 2 and randtype = 1).
  77. compute nm1 = 1 / (ncases-1).
  78. compute vcv = nm1 * (sscp(raw) - ((t(csum(raw))*csum(raw))/ncases)).
  79. compute d = inv(mdiag(sqrt(diag(vcv)))).
  80. compute cr = (d * vcv * d).
  81. compute smc = 1 - (1 &/ diag(inv(cr)) ).
  82. call setdiag(cr,smc).
  83. compute realeval = eval(cr).
  84. compute evals = make(nvars,ndatsets,-9999).
  85. compute nm1 = 1 / (ncases-1).
  86. loop #nds = 1 to ndatsets.
  87. compute x = sqrt(2 * (ln(uniform(ncases,nvars)) * -1) ) &*
  88.             cos(6.283185 * uniform(ncases,nvars) ).
  89. compute vcv = nm1 * (sscp(x) - ((t(csum(x))*csum(x))/ncases)).
  90. compute d = inv(mdiag(sqrt(diag(vcv)))).
  91. compute r = d * vcv * d.
  92. compute smc = 1 - (1 &/ diag(inv(r)) ).
  93. call setdiag(r,smc).
  94. compute evals(:,#nds) = eval(r).
  95. end loop.
  96. end if.
  97.  
  98. * PAF/common factor analysis & raw data permutation.
  99. do if (kind = 2 and randtype = 2).
  100. compute nm1 = 1 / (ncases-1).
  101. compute vcv = nm1 * (sscp(raw) - ((t(csum(raw))*csum(raw))/ncases)).
  102. compute d = inv(mdiag(sqrt(diag(vcv)))).
  103. compute cr = (d * vcv * d).
  104. compute smc = 1 - (1 &/ diag(inv(cr)) ).
  105. call setdiag(cr,smc).
  106. compute realeval = eval(cr).
  107. compute evals = make(nvars,ndatsets,-9999).
  108. compute nm1 = 1 / (ncases-1).
  109. loop #nds = 1 to ndatsets.
  110. compute x = raw.
  111. loop #c = 1 to nvars.
  112. loop #r = 1 to (ncases -1).
  113. compute k = trunc( (ncases - #r + 1) * uniform(1,1) + 1 )  + #r - 1.
  114. compute d = x(#r,#c).
  115. compute x(#r,#c) = x(k,#c).
  116. compute x(k,#c) = d.
  117. end loop.
  118. end loop.
  119. compute vcv = nm1 * (sscp(x) - ((t(csum(x))*csum(x))/ncases)).
  120. compute d = inv(mdiag(sqrt(diag(vcv)))).
  121. compute r = d * vcv * d.
  122. compute smc = 1 - (1 &/ diag(inv(r)) ).
  123. call setdiag(r,smc).
  124. compute evals(:,#nds) = eval(r).
  125. end loop.
  126. end if.
  127.  
  128. * identifying the eigenvalues corresponding to the desired percentile.
  129. compute num = rnd((percent*ndatsets)/100).
  130. compute results = { t(1:nvars), realeval, t(1:nvars), t(1:nvars) }.
  131. loop #root = 1 to nvars.
  132. compute ranks = rnkorder(evals(#root,:)).
  133. loop #col = 1 to ndatsets.
  134. do if (ranks(1,#col) = num).
  135. compute results(#root,4) = evals(#root,#col).
  136. break.
  137. end if.
  138. end loop.
  139. end loop.
  140. compute results(:,3) = rsum(evals) / ndatsets.
  141.  
  142. print /title="PARALLEL ANALYSIS:".
  143. do if (kind = 1 and randtype = 1).
  144. print /title="Principal Components & Random Normal Data Generation".
  145. else if (kind = 1 and randtype = 2).
  146. print /title="Principal Components & Raw Data Permutation".
  147. else if (kind = 2 and randtype = 1).
  148. print /title="PAF/Common Factor Analysis & Random Normal Data Generation".
  149. else if (kind = 2 and randtype = 2).
  150. print /title="PAF/Common Factor Analysis & Raw Data Permutation".
  151. end if.
  152. compute specifs = {ncases; nvars; ndatsets; percent}.
  153. print specifs /title="Specifications for this Run:"
  154.  /rlabels="Ncases" "Nvars" "Ndatsets" "Percent".
  155. print results
  156.  /title="Raw Data Eigenvalues, & Mean & Percentile Random Data Eigenvalues"
  157.  /clabels="Root" "Raw Data" "Means" "Prcntyle"  /format "f12.6".
  158.  
  159. do if   (kind = 2).
  160. print / space = 1.
  161. print /title="Warning: Parallel analyses of adjusted correlation matrices".
  162. print /title="eg, with SMCs on the diagonal, tend to indicate more factors".
  163. print /title="than warranted (Buja, A., & Eyuboglu, N., 1992, Remarks on parallel".
  164. print /title="analysis. Multivariate Behavioral Research, 27, 509-540.).".
  165. print /title="The eigenvalues for trivial, negligible factors in the real".
  166. print /title="data commonly surpass corresponding random data eigenvalues".
  167. print /title="for the same roots. The eigenvalues from parallel analyses".
  168. print /title="can be used to determine the real data eigenvalues that are".
  169. print /title="beyond chance, but additional procedures should then be used".
  170. print /title="to trim trivial factors.".
  171. print / space = 2.
  172. print /title="Principal components eigenvalues are often used to determine".
  173. print /title="the number of common factors. This is the default in most".
  174. print /title="statistical software packages, and it is the primary practice".
  175. print /title="in the literature. It is also the method used by many factor".
  176. print /title="analysis experts, including Cattell, who often examined".
  177. print /title="principal components eigenvalues in his scree plots to determine".
  178. print /title="the number of common factors. But others believe this common".
  179. print /title="practice is wrong. Principal components eigenvalues are based".
  180. print /title="on all of the variance in correlation matrices, including both".
  181. print /title="the variance that is shared among variables and the variances".
  182. print /title="that are unique to the variables. In contrast, principal".
  183. print /title="axis eigenvalues are based solely on the shared variance".
  184. print /title="among the variables. The two procedures are qualitatively".
  185. print /title="different. Some therefore claim that the eigenvalues from one".
  186. print /title="extraction method should not be used to determine".
  187. print /title="the number of factors for the other extraction method.".
  188. print /title="The issue remains neglected and unsettled.".
  189. end if.
  190.  
  191. compute root      = results(:,1).
  192. compute rawdata = results(:,2).
  193. compute percntyl = results(:,4).
  194.  
  195. save results /outfile=* / var=root rawdata means percntyl .
  196.  
  197. end matrix.
  198.  
  199. * plots the eigenvalues, by root, for the real/raw data and for the random data;
  200.   This command works in SPSS 12, but not in all earlier versions.
  201. TSPLOT VARIABLES= rawdata means percntyl /ID= root /NOLOG.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement