Data Generation for Pre-determined correations

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Data Generation for Pre-determined correations

Sungeun Chung-2
Dear SPSS Experts

I want to create a data set with five variables for pre-determined correlations.  

 1.000, .075, .400, .286, .309; 
.075, 1.000, .411, .834, -.521; 
.400, .411, 1.000, .846, .564; 
.286, .834, .846, 1.000, .036; 
.309, .521, .564, .036, 1.000

I tried to do it by modifying the syntax that David Marso posted (March 15, 2013).
Specifically, I replaced "3" with "5" in "CRITERIA FACTORS(3)." Then I put correlations for five variables.
But it didn't work. How can I fix the problem?
Thank you for your help in advance,

Sungeun


Sungeun Chung, Ph.D. Associate Professor
Department of Journalism and Mass Communication
40210 Faculty Hall Sungkyunkwan University
53 Myeongyun-Dong 3-Ga Jongno-Gu, Seoul, Korea 110-745
82-02-760-0398; [hidden email][hidden email]

****  David Marso Syntax*.

DEFINE CorrSim (CorrMat !CHAREND ("/") / N !TOKENS(1) / P !TOKENS(1)).

!LET !VLIST1 = !CONCAT('X1 TO X',!P ).
!LET !VLIST2 = !CONCAT('FS1 TO FS',!P ).
!LET !VLIST3 = !CONCAT('Sim1 TO Sim',!P ).

* Simulate raw data of desired dimensionality *.
INPUT PROGRAM.
+  LOOP #=1 TO !N.
+    DO REPEAT V=!VLIST1.
+      COMPUTE V=RV.NORMAL(0,1).
+    END REPEAT.
+    END CASE.
+  END LOOP.
+  END FILE.
END INPUT PROGRAM.

* Orthogonalize Vectors * .
FACTOR VAR !VLIST1 / CRITERIA FACTORS(5)/ SAVE REG (!P,FS).

* Generate Vectors with desired dimensionality *.
MATRIX.
GET RAW  / VAR !VLIST1.
GET FS    / VAR !VLIST2.
COMPUTE CORR={!CorrMat}.
SAVE {RAW,FS,FS*CHOL(CORR)} / OUTFILE * /VARIABLES !VLIST1 !VLIST2 !VLIST3.
END MATRIX.

** Check results (Optional) **.
CORRELATION !VLIST3 .
!ENDDEFINE.
SET MPRINT ON PRINTBACK ON.

* Self explanatory!*.
CorrSim CorrMat 1.000, .075, .400, .286, .309; .075, 1.000, .411, .834, -.521; .400, .411, 1.000, .846, .564; .286, .834, .846, 1.000, .036; .309, .521, .564, .036, 1.000
                / N=291  P=5.

 
Reply | Threaded
Open this post in threaded view
|

Re: Data Generation for Pre-determined correations

Rich Ulrich
It usually helps if you are more specific than "it didn't work";
but this time I can tell you that you gave it a matrix that is
not symmetrical.  And that would account for a failure.

"-.521"  needs to be ".521" so that element (5,2) matches (2,5).

Using negative for both might work, or it might leave the matrix
non-positive definite.  "Positive" looks like what was intended.

--
Rich Ulrich


Date: Thu, 28 Mar 2013 19:10:22 -0700
From: [hidden email]
Subject: Data Generation for Pre-determined correations
To: [hidden email]

Dear SPSS Experts

I want to create a data set with five variables for pre-determined correlations.  

 1.000, .075, .400, .286, .309; 
.075, 1.000, .411, .834, -.521; 
.400, .411, 1.000, .846, .564; 
.286, .834, .846, 1.000, .036; 
.309, .521, .564, .036, 1.000

I tried to do it by modifying the syntax that David Marso posted (March 15, 2013).
Specifically, I replaced "3" with "5" in "CRITERIA FACTORS(3)." Then I put correlations for five variables.
But it didn't work. How can I fix the problem?
Thank you for your help in advance,

Sungeun


Sungeun Chung, Ph.D. Associate Professor
Department of Journalism and Mass Communication
40210 Faculty Hall Sungkyunkwan University
53 Myeongyun-Dong 3-Ga Jongno-Gu, Seoul, Korea 110-745
82-02-760-0398; [hidden email][hidden email]

****  David Marso Syntax*.

DEFINE CorrSim (CorrMat !CHAREND ("/") / N !TOKENS(1) / P !TOKENS(1)).

!LET !VLIST1 = !CONCAT('X1 TO X',!P ).
!LET !VLIST2 = !CONCAT('FS1 TO FS',!P ).
!LET !VLIST3 = !CONCAT('Sim1 TO Sim',!P ).

* Simulate raw data of desired dimensionality *.
INPUT PROGRAM.
+  LOOP #=1 TO !N.
+    DO REPEAT V=!VLIST1.
+      COMPUTE V=RV.NORMAL(0,1).
+    END REPEAT.
+    END CASE.
+  END LOOP.
+  END FILE.
END INPUT PROGRAM.

* Orthogonalize Vectors * .
FACTOR VAR !VLIST1 / CRITERIA FACTORS(5)/ SAVE REG (!P,FS).

* Generate Vectors with desired dimensionality *.
MATRIX.
GET RAW  / VAR !VLIST1.
GET FS    / VAR !VLIST2.
COMPUTE CORR={!CorrMat}.
SAVE {RAW,FS,FS*CHOL(CORR)} / OUTFILE * /VARIABLES !VLIST1 !VLIST2 !VLIST3.
END MATRIX.

** Check results (Optional) **.
CORRELATION !VLIST3 .
!ENDDEFINE.
SET MPRINT ON PRINTBACK ON.

* Self explanatory!*.
CorrSim CorrMat 1.000, .075, .400, .286, .309; .075, 1.000, .411, .834, -.521; .400, .411, 1.000, .846, .564; .286, .834, .846, 1.000, .036; .309, .521, .564, .036, 1.000
                / N=291  P=5.

 
Reply | Threaded
Open this post in threaded view
|

Re: Data Generation for Pre-determined correations

Ryan
In reply to this post by Sungeun Chung-2
A little OT...I noticed that the code here:

http://www.uvm.edu/~dhowell/StatPages/More_Stuff/CorrData.SPS

has a RECODE statement with a corresponding note that does not make
any sense to me:

* Now you have your correlated variables. The next lines adjust the
means and variances.
RECODE
  nr5  (-10 thru 0=1)  (.0001 thru 10=2)  .

If anyone plans on using this code, I suggest you grey out this
RECODE. I hope I am corrected if I'm wrong.

Ryan

On Thu, Mar 28, 2013 at 10:10 PM, Sungeun Chung <[hidden email]> wrote:

> Dear SPSS Experts
>
> I want to create a data set with five variables for pre-determined
> correlations.
>
>  1.000, .075, .400, .286, .309;
> .075, 1.000, .411, .834, -.521;
> .400, .411, 1.000, .846, .564;
> .286, .834, .846, 1.000, .036;
> .309, .521, .564, .036, 1.000
>
> I tried to do it by modifying the syntax that David Marso posted (March 15,
> 2013).
> Specifically, I replaced "3" with "5" in "CRITERIA FACTORS(3)." Then I put
> correlations for five variables.
> But it didn't work. How can I fix the problem?
> Thank you for your help in advance,
>
> Sungeun
>
>
> Sungeun Chung, Ph.D. Associate Professor
> Department of Journalism and Mass Communication
> 40210 Faculty Hall Sungkyunkwan University
> 53 Myeongyun-Dong 3-Ga Jongno-Gu, Seoul, Korea 110-745
> 82-02-760-0398; [hidden email]; [hidden email]
>
> ****  David Marso Syntax*.
>
> DEFINE CorrSim (CorrMat !CHAREND ("/") / N !TOKENS(1) / P !TOKENS(1)).
>
> !LET !VLIST1 = !CONCAT('X1 TO X',!P ).
> !LET !VLIST2 = !CONCAT('FS1 TO FS',!P ).
> !LET !VLIST3 = !CONCAT('Sim1 TO Sim',!P ).
>
> * Simulate raw data of desired dimensionality *.
> INPUT PROGRAM.
> +  LOOP #=1 TO !N.
> +    DO REPEAT V=!VLIST1.
> +      COMPUTE V=RV.NORMAL(0,1).
> +    END REPEAT.
> +    END CASE.
> +  END LOOP.
> +  END FILE.
> END INPUT PROGRAM.
>
> * Orthogonalize Vectors * .
> FACTOR VAR !VLIST1 / CRITERIA FACTORS(5)/ SAVE REG (!P,FS).
>
> * Generate Vectors with desired dimensionality *.
> MATRIX.
> GET RAW  / VAR !VLIST1.
> GET FS    / VAR !VLIST2.
> COMPUTE CORR={!CorrMat}.
> SAVE {RAW,FS,FS*CHOL(CORR)} / OUTFILE * /VARIABLES !VLIST1 !VLIST2 !VLIST3.
> END MATRIX.
>
> ** Check results (Optional) **.
> CORRELATION !VLIST3 .
> !ENDDEFINE.
> SET MPRINT ON PRINTBACK ON.
>
> * Self explanatory!*.
> CorrSim CorrMat 1.000, .075, .400, .286, .309; .075, 1.000, .411, .834,
> -.521; .400, .411, 1.000, .846, .564; .286, .834, .846, 1.000, .036; .309,
> .521, .564, .036, 1.000
>                 / N=291  P=5.
>
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Data Generation for Pre-determined correations

David Marso
Administrator
In reply to this post by Sungeun Chung-2
Note that I edited my post later and replaced the hard coded 3 with !P .
The 3 was possibly a premacrofication artifact of my home brewed DoppleBock ;-).
--
FACTOR VAR !VLIST1 / CRITERIA FACTORS(!P)/ SAVE REG (!P,FS).

-- and as Rich noted, the matrix needs to be symmetrical (fix that) --.

"But it didn't work.".
Best to post specific errors so we don't need to crank up (TAFKA)SPSS and replicate.
I can typically sort this type of thing without having to run code if I see the train wreck from the run.
--
Hope this helps, David

Sungeun Chung-2 wrote
Dear SPSS Experts

I want to create a data set with five variables for pre-determined correlations.  

 1.000, .075, .400, .286, .309; 
.075, 1.000, .411, .834, -.521; 
.400, .411, 1.000, .846, .564; 
.286, .834, .846, 1.000, .036; 
.309, .521, .564, .036, 1.000


I tried to do it by modifying the syntax that David Marso posted (March 15, 2013).
Specifically, I replaced "3" with "5" in "CRITERIA FACTORS(3)." Then I put correlations for five variables.
But it didn't work. How can I fix the problem?
Thank you for your help in advance,

Sungeun


Sungeun Chung, Ph.D. Associate Professor
Department of Journalism and Mass Communication
40210 Faculty Hall Sungkyunkwan University
53 Myeongyun-Dong 3-Ga Jongno-Gu, Seoul, Korea 110-745
82-02-760-0398; [hidden email][hidden email]


****  David Marso Syntax*.

DEFINE CorrSim (CorrMat !CHAREND ("/") / N !TOKENS(1) / P !TOKENS(1)).

!LET !VLIST1 = !CONCAT('X1 TO X',!P ).
!LET !VLIST2 = !CONCAT('FS1 TO FS',!P ).
!LET !VLIST3 = !CONCAT('Sim1 TO Sim',!P ).

* Simulate raw data of desired dimensionality *.
INPUT PROGRAM.
+  LOOP #=1 TO !N.
+    DO REPEAT V=!VLIST1.
+      COMPUTE V=RV.NORMAL(0,1).
+    END REPEAT.
+    END CASE.
+  END LOOP.
+  END FILE.
END INPUT PROGRAM.

* Orthogonalize Vectors * .
FACTOR VAR !VLIST1 / CRITERIA FACTORS(5)/ SAVE REG (!P,FS).

* Generate Vectors with desired dimensionality *.
MATRIX.
GET RAW  / VAR !VLIST1.
GET FS    / VAR !VLIST2.
COMPUTE CORR={!CorrMat}.
SAVE {RAW,FS,FS*CHOL(CORR)} / OUTFILE * /VARIABLES !VLIST1 !VLIST2 !VLIST3.
END MATRIX.

** Check results (Optional) **.
CORRELATION !VLIST3 .
!ENDDEFINE.
SET MPRINT ON PRINTBACK ON.

* Self explanatory!*.
CorrSim CorrMat 1.000, .075, .400, .286, .309; .075, 1.000, .411, .834, -.521; .400, .411, 1.000, .846, .564; .286, .834, .846, 1.000, .036; .309, .521, .564, .036, 1.000
                / N=291  P=5.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Data Generation for Pre-determined correations

Sungeun Chung-2
Thanks Ryan, Rich Ulrich, and David for finding errors and giving solutions.
Both Ryan's and David' syntax are working well (with different correlation matrices). It seems that my matrix has a problem (In fact, I don't have raw data but the author of a paper gave me correlations).

Thank again.

Sungeun
   
From: David Marso <[hidden email]>
To: [hidden email]
Sent: Friday, March 29, 2013 1:08 PM
Subject: Re: Data Generation for Pre-determined correations

Note that I edited my post later and replaced the hard coded 3 with !P .
The 3 was possibly a premacrofication artifact of my home brewed DoppleBock
;-).
--
FACTOR VAR !VLIST1 / CRITERIA FACTORS(!P)/ SAVE REG (!P,FS).

-- and as Rich noted, the matrix needs to be symmetrical (fix that) --.

"But it didn't work.".
Best to post specific errors so we don't need to crank up (TAFKA)SPSS and
replicate.
I can typically sort this type of thing without having to run code if I see
the train wreck from the run.
--
Hope this helps, David


Sungeun Chung-2 wrote

> Dear SPSS Experts
>
> I want to create a data set with five variables for pre-determined
> correlations. Â
>
> Â 1.000, .075, .400, .286, .309;Â
> .075, 1.000, .411, .834, -.521;Â
> .400, .411, 1.000, .846, .564;Â
> .286, .834, .846, 1.000, .036;Â
> .309, .521, .564, .036, 1.000
>
>
> I tried to do it by modifying the syntax that David Marso posted (March
> 15, 2013).
> Specifically, I replaced "3" with "5" in "CRITERIA FACTORS(3)." Then I put
> correlations for five variables.
> But it didn't work. How can I fix the problem?
> Thank you for your help in advance,
>
> Sungeun
>
>
> Sungeun Chung, Ph.D. Associate Professor
> Department of Journalism and Mass Communication
> 40210 Faculty Hall Sungkyunkwan University
> 53 Myeongyun-Dong 3-Ga Jongno-Gu, Seoul, Korea 110-745
> 82-02-760-0398;Â

> chseun@

> ;Â

> chseun@

>
>
> **** Â David Marso Syntax*.
>
> DEFINE CorrSim (CorrMat !CHAREND ("/") / N !TOKENS(1) / P !TOKENS(1)).
>
> !LET !VLIST1 = !CONCAT('X1 TO X',!P ).
> !LET !VLIST2 = !CONCAT('FS1 TO FS',!P ).
> !LET !VLIST3 = !CONCAT('Sim1 TO Sim',!P ).
>
> * Simulate raw data of desired dimensionality *.
> INPUT PROGRAM.
> + Â LOOP #=1 TO !N.
> +    DO REPEAT V=!VLIST1.
> +      COMPUTE V=RV.NORMAL(0,1).
> +    END REPEAT.
> +    END CASE.
> + Â END LOOP.
> + Â END FILE.
> END INPUT PROGRAM.
>
> * Orthogonalize Vectors * .
> FACTOR VAR !VLIST1 / CRITERIA FACTORS(5)/ SAVE REG (!P,FS).
>
> * Generate Vectors with desired dimensionality *.
> MATRIX.
> GET RAW Â / VAR !VLIST1.
> GET FS    / VAR !VLIST2.
> COMPUTE CORR={!CorrMat}.
> SAVE {RAW,FS,FS*CHOL(CORR)} / OUTFILE * /VARIABLES !VLIST1 !VLIST2
> !VLIST3.
> END MATRIX.
>
> ** Check results (Optional) **.
> CORRELATION !VLIST3 .
> !ENDDEFINE.
> SET MPRINT ON PRINTBACK ON.
>
> * Self explanatory!*.
> CorrSim CorrMat 1.000, .075, .400, .286, .309; .075, 1.000, .411, .834,
> -.521; .400, .411, 1.000, .846, .564; .286, .834, .846, 1.000, .036; .309,
> .521, .564, .036, 1.000
>                 / N=291  P=5.





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Data-Generation-for-Pre-determined-correations-tp5719160p5719163.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD


Reply | Threaded
Open this post in threaded view
|

Re: Data Generation for Pre-determined correations

Ryan
For the record, that link is not directed to syntax I developed. Since it could be used for the OP's question, along with the fact that I found a potential error, I figured I'd chime in.
 
Ryan


On Fri, Mar 29, 2013 at 2:47 AM, Sungeun Chung <[hidden email]> wrote:
Thanks Ryan, Rich Ulrich, and David for finding errors and giving solutions.
Both Ryan's and David' syntax are working well (with different correlation matrices). It seems that my matrix has a problem (In fact, I don't have raw data but the author of a paper gave me correlations).

Thank again.

Sungeun
   
From: David Marso <[hidden email]>
To: [hidden email]
Sent: Friday, March 29, 2013 1:08 PM
Subject: Re: Data Generation for Pre-determined correations

Note that I edited my post later and replaced the hard coded 3 with !P .
The 3 was possibly a premacrofication artifact of my home brewed DoppleBock
;-).
--
FACTOR VAR !VLIST1 / CRITERIA FACTORS(!P)/ SAVE REG (!P,FS).

-- and as Rich noted, the matrix needs to be symmetrical (fix that) --.

"But it didn't work.".
Best to post specific errors so we don't need to crank up (TAFKA)SPSS and
replicate.
I can typically sort this type of thing without having to run code if I see
the train wreck from the run.
--
Hope this helps, David


Sungeun Chung-2 wrote
> Dear SPSS Experts
>
> I want to create a data set with five variables for pre-determined
> correlations. Â
>

> Â 1.000, .075, .400, .286, .309;Â
> .075, 1.000, .411, .834, -.521;Â
> .400, .411, 1.000, .846, .564;Â
> .286, .834, .846, 1.000, .036;Â
> .309, .521, .564, .036, 1.000
>
>
> I tried to do it by modifying the syntax that David Marso posted (March
> 15, 2013).
> Specifically, I replaced "3" with "5" in "CRITERIA FACTORS(3)." Then I put
> correlations for five variables.
> But it didn't work. How can I fix the problem?
> Thank you for your help in advance,
>
> Sungeun
>
>
> Sungeun Chung, Ph.D. Associate Professor
> Department of Journalism and Mass Communication
> 40210 Faculty Hall Sungkyunkwan University
> 53 Myeongyun-Dong 3-Ga Jongno-Gu, Seoul, Korea 110-745
> 82-02-760-0398;Â

> chseun@

> ;Â

> chseun@

>
>
> **** Â David Marso Syntax*.
>
> DEFINE CorrSim (CorrMat !CHAREND ("/") / N !TOKENS(1) / P !TOKENS(1)).
>
> !LET !VLIST1 = !CONCAT('X1 TO X',!P ).
> !LET !VLIST2 = !CONCAT('FS1 TO FS',!P ).
> !LET !VLIST3 = !CONCAT('Sim1 TO Sim',!P ).
>
> * Simulate raw data of desired dimensionality *.
> INPUT PROGRAM.
> + Â LOOP #=1 TO !N.
> +    DO REPEAT V=!VLIST1.
> +      COMPUTE V=RV.NORMAL(0,1).
> +    END REPEAT.
> +    END CASE.
> + Â END LOOP.
> + Â END FILE.
> END INPUT PROGRAM.
>
> * Orthogonalize Vectors * .
> FACTOR VAR !VLIST1 / CRITERIA FACTORS(5)/ SAVE REG (!P,FS).
>
> * Generate Vectors with desired dimensionality *.
> MATRIX.
> GET RAW Â / VAR !VLIST1.
> GET FS    / VAR !VLIST2.
> COMPUTE CORR={!CorrMat}.
> SAVE {RAW,FS,FS*CHOL(CORR)} / OUTFILE * /VARIABLES !VLIST1 !VLIST2
> !VLIST3.

> END MATRIX.
>
> ** Check results (Optional) **.
> CORRELATION !VLIST3 .
> !ENDDEFINE.
> SET MPRINT ON PRINTBACK ON.
>
> * Self explanatory!*.
> CorrSim CorrMat 1.000, .075, .400, .286, .309; .075, 1.000, .411, .834,
> -.521; .400, .411, 1.000, .846, .564; .286, .834, .846, 1.000, .036; .309,
> .521, .564, .036, 1.000
>                 / N=291  P=5.





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Data-Generation-for-Pre-determined-correations-tp5719160p5719163.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD



Reply | Threaded
Open this post in threaded view
|

Re: Data Generation for Pre-determined correations

David Marso
Administrator
In reply to this post by David Marso
FWIW:
Here is a link to my original post (note the 3 had already been corrected to !P on March 15?).
Also cited Howell, but I am unimpressed with code which requires multiple user interventions.
http://spssx-discussion.1045642.n5.nabble.com/Re-Application-of-Rule-set-in-SPSS-Logistic-Regression-tt5718607.html#a5718648
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"