|
Dear SPSS-L, I hate to clog up the listserve with this seemingly easy-to-figure-out question, but for whatever reason I'm stuck. I'm trying to output the correlations Table from the correlation procedure as well as Model Summary Table and Coefficients Table from each of the regression procedures (BELOW) into a single dataset using OMS. I've reviewed various online documentation, and I can't seem to figure out how to output and merge them all into a single dataset.To get very specific, I'm really only interested in outputting the Pearson correlations and the N from the Pearson correlation procedure output (note that I am assuming NO missing data so the sample size will not fluctuate), the multiple correlation coefficient R and standardized regression coefficients BETA from each of the multiple regression analyses output. Having stated that, I'm willing to merge all the information from the Tables and just delete unnecessary information afterwards.
Any guidance would be most appreciated. As always, the code is below my name. Thanks, Ryan -- *Generate data.
set seed 98765432. new file. inp pro. loop ID= 1 to 1000. comp #b0 = 1.2. comp #b1 = 3.2. comp #b2 = 4.2. comp #b3 = 3.2. comp #b4 = 6.2. comp #b5 = 2.4. comp #b6 = 1.2. comp #b7 = 1.4. comp #b8 = 2.1. comp x1 = rv.normal(0,1). comp x2 = x1 + 4*rv.normal(0,1) + 1*rv.normal(0,1). comp x3 = x1 + 2*rv.normal(0,1) + 3*rv.normal(0,1). comp x4 = x1 + 3*rv.normal(0,1) + 1*rv.normal(0,1). comp x5 = x1 + 4*rv.normal(0,1) + 1*rv.normal(0,1). comp x6 = x1 + 2*rv.normal(0,1) + 2*rv.normal(0,1). comp x7 = x4 + 3*rv.normal(0,1) + 2*rv.normal(0,1). comp x8 = x1 + 3*rv.normal(0,1) + 2*rv.normal(0,1). comp y = #b0 + #b1*x1 + #b2*x2 + #b3*x3 + #b4*x4 + #b5*x5 + #b6*x6 + #b7*x7 + #b8*x8 + rv.normal(0,1).
end case. end loop. end file. end inp pro. exe. *Calculate Pearson correlations for x1 through x8. CORRELATIONS /VARIABLES=x1 x2 x3 x4 x5 x6 x7 x8 /PRINT=TWOTAIL NOSIG /MISSING=PAIRWISE. *Run multiple regression analysis with x1, x2, x3, and x4 as IVs and y as the DV. REGRESSION /MISSING LISTWISE /STATISTICS COEFF R /CRITERIA=PIN(.05) POUT(.10) /NOORIGIN /DEPENDENT y /METHOD=ENTER x1 x2 x3 x4. *Run multiple regression analysis with x5, x6, x7, and x8 as the IVs and y as the DV. REGRESSION /MISSING LISTWISE /STATISTICS COEFF R /CRITERIA=PIN(.05) POUT(.10) /NOORIGIN /DEPENDENT y /METHOD=ENTER x5 x6 x7 x8. |
|
Can you give an example of what the end desired format is? The multiple regressions shouldn't be too difficult off-the-cuff, but I don't how you want the correlations weaved into such a table.
Andy |
|
In reply to this post by Ryan
If you are creating a dataset, all the
tables going into a single dataset have to be dimensionally consistent,
i.e., fit into the same rectangle. Try outputting each different
table type into a different dataset ad then consider how you might merge
them with MATCH FILES. Formats other than sav do not have this constraint.
Regards, Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: R B <[hidden email]> To: [hidden email] Date: 09/20/2012 10:42 PM Subject: [SPSSX-L] OMS question - Merging outputted Tables from different procedures into a single dataset Sent by: "SPSSX(r) Discussion" <[hidden email]> Dear SPSS-L, I hate to clog up the listserve with this seemingly easy-to-figure-out question, but for whatever reason I'm stuck. I'm trying to output the correlations Table from the correlation procedure as well as Model Summary Table and Coefficients Table from each of the regression procedures (BELOW) into a single dataset using OMS. I've reviewed various online documentation, and I can't seem to figure out how to output and merge them all into a single dataset.To get very specific, I'm really only interested in outputting the Pearson correlations and the N from the Pearson correlation procedure output (note that I am assuming NO missing data so the sample size will not fluctuate), the multiple correlation coefficient R and standardized regression coefficients BETA from each of the multiple regression analyses output. Having stated that, I'm willing to merge all the information from the Tables and just delete unnecessary information afterwards. Any guidance would be most appreciated. As always, the code is below my name. Thanks, Ryan -- *Generate data. set seed 98765432. new file. inp pro. loop ID= 1 to 1000. comp #b0 = 1.2. comp #b1 = 3.2. comp #b2 = 4.2. comp #b3 = 3.2. comp #b4 = 6.2. comp #b5 = 2.4. comp #b6 = 1.2. comp #b7 = 1.4. comp #b8 = 2.1. comp x1 = rv.normal(0,1). comp x2 = x1 + 4*rv.normal(0,1) + 1*rv.normal(0,1). comp x3 = x1 + 2*rv.normal(0,1) + 3*rv.normal(0,1). comp x4 = x1 + 3*rv.normal(0,1) + 1*rv.normal(0,1). comp x5 = x1 + 4*rv.normal(0,1) + 1*rv.normal(0,1). comp x6 = x1 + 2*rv.normal(0,1) + 2*rv.normal(0,1). comp x7 = x4 + 3*rv.normal(0,1) + 2*rv.normal(0,1). comp x8 = x1 + 3*rv.normal(0,1) + 2*rv.normal(0,1). comp y = #b0 + #b1*x1 + #b2*x2 + #b3*x3 + #b4*x4 + #b5*x5 + #b6*x6 + #b7*x7 + #b8*x8 + rv.normal(0,1). end case. end loop. end file. end inp pro. exe. *Calculate Pearson correlations for x1 through x8. CORRELATIONS /VARIABLES=x1 x2 x3 x4 x5 x6 x7 x8 /PRINT=TWOTAIL NOSIG /MISSING=PAIRWISE. *Run multiple regression analysis with x1, x2, x3, and x4 as IVs and y as the DV. REGRESSION /MISSING LISTWISE /STATISTICS COEFF R /CRITERIA=PIN(.05) POUT(.10) /NOORIGIN /DEPENDENT y /METHOD=ENTER x1 x2 x3 x4. *Run multiple regression analysis with x5, x6, x7, and x8 as the IVs and y as the DV. REGRESSION /MISSING LISTWISE /STATISTICS COEFF R /CRITERIA=PIN(.05) POUT(.10) /NOORIGIN /DEPENDENT y /METHOD=ENTER x5 x6 x7 x8. |
|
In reply to this post by Andy W
Hi Andy, Thanks for responding. It's difficult to answer your question because the equation which utilizes the pearson correlations and standardized regression coefficients (Betas) is quite tedious.
Here is the first equation: Beta_model_1_x1 * (r11*Beta_model_2_x1 + r12*Beta_model_2_x2 + r13*Beta_model_2_x3 + ... + r18*Beta_model_2_x8) + Beta_model_1_x2 * (r21*Beta_model_2_x1 + r22*Beta_model_2_x2 + r23*Beta_model_2_x3 + ... + r28*Beta_model_2_x8) +
Beta_model_1_x3 * (r31*Beta_model_2_x1 + r32*Beta_model_2_x2 + r33*Beta_model_2_x3 + ... + r38*Beta_model_2_x8) + . . . Beta_model_1_x8 * (r81*Beta_model_2_x1 + r82*Beta_model_2_x2 + r83*Beta_model_2_x3 + ... + r88*Beta_model_2_x8)
**Note that some of the Beta's above will be non-existent since there is no overlap between the models. In other words, the predictors in the first regression model are NOT in the second regression model and vice versa. For example, "Beta_model_2_x1" = 0 because x1 is NOT in the second model. But, I'd really like to construct a dataset which allows for the full equation above, so that the approach can generalize to scenarios which have more variables and potentially overlapping variables.
The solution to the first equation (above) will be plugged into the following second equation: Solution to the first equation / (multiple_R_model_1 * multiple_R_model_2) ,,,and the third equation will include the multiple R from each model along the result from the second equation--not worth noting here. -- So, where do I want the correlations to be placed? I suppose in the optimal way such that they can be plugged into the first equation. I'm trying to think of a simple approach, while at the same time, an elegant approach, which can handle other scenarios without much additional work. At the end of the day, if I must, I will just pluck the values one-by-one out of the Tables myself, but this will not serve me in the future when the number of variables changes. I RECOGNIZE THAT THIS IS A VERY COMPLICATED REQUEST--something I will likely need to work through myself.
Of course, any ideas would be much appreciated. Sorry you asked? :-) Ryan On Fri, Sep 21, 2012 at 7:28 AM, Andy W <[hidden email]> wrote: Can you give an example of what the end desired format is? The multiple |
|
Perhaps I am sorry I asked! So to be clear, in the end you want a data matrix that looks (approximately like)
data list free /var (A10) Beta_Model_1_1 Beta_model_2_x1 Beta_model_2_x2 Beta_model_3_x3 r11 r12 r13 (7F8.2). begin data x1,??? x2,??? x3,??? end data. Where the ??? are the beta estimates and the correlation coefficients? Basically the workflow I envision would be as Jon says, one OMS statement for the regressions and one for the correlation (you can actually avoid OMS altogether, for corrs via the "/MATRIX=OUT" subcommand and for regression via the OUTFILE subcommand). Then edit and reshape the seperate files as needed and match files them all together. I don't think it will take to long to show an example, but before I do that I would like to know more holistically what the end goal is. My guess is it sounds like you are building a system to estimate/plot various marginal effects given a set of equations. Perhaps others on the list would be able to provide more straightforward advice about workflows to accomplish such tasks. Andy |
|
Administrator
|
In reply to this post by Ryan
It would probably be pretty easy and general to program this in MATRIX and skip all the fiddling with output.
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?" |
|
Perhaps that is the way to go. When I arrive at the final product, I'll share with the list the solution for those interested. Thanks all. -Ryan
On Fri, Sep 21, 2012 at 11:10 AM, David Marso <[hidden email]> wrote: It would probably be pretty easy and general to program this in MATRIX and |
|
Administrator
|
Here is a quick and dirty (20 minute version).
You will want to accommodate var names and probably do a bit of error checking. Note SWEEP is absolutely the coolest. dataset declare data1. input program. loop caseid=1 to 1000. do repeat x=x1 to x10. compute x=RV.normal(0,1). end repeat. end case. end loop. end file. end input program. compute y1=SUM(1.5,.4*(X1+X2+X3),.6*(x5+X6), RV.Normal(0,1)). compute y2=SUM(1.5,.4*(X1+X7+X8),.6*(x2+X9), RV.Normal(0,1)). compute y3=SUM(2.5,.5*(X3+X5+X9),.6*(x7+X10), RV.Normal(0,1)). compute y4=SUM(3.5,.2*(X1+X4+X6),.6*(x8+X9+x10), RV.Normal(0,4)). EXECUTE. DATASET NAME data1. save outfile 'c:\temp\data1.sav'. dataset declare models. data list list /dv x1 to x10. begin data 1 1 1 1 0 1 1 0 0 0 0 2 1 1 0 0 0 0 1 1 1 0 3 0 0 1 0 1 0 1 0 1 1 4 1 0 0 1 0 1 0 1 1 1 end data. dataset name models. SAVE OUTFILE 'c:\temp\models.sav'. MATRIX . GET X / FILE 'c:\temp\data1.sav' / variables x1 to x10. GET Y / FILE 'c:\temp\data1.sav' / variables y1 to y4. print nrow(x). get modelY / file 'c:\temp\models.sav' / variables dv. get modpred / file 'c:\temp\models.sav' / variables x1 to x10. compute onexy={make(nrow(y),1,1),x,y}. compute Txyxy=T(onexy)*onexy. compute sumsxy=Txyxy(:,1). compute SSCPxy=Txyxy-sumsxy*T(sumsXY)/sumsxy(1,1). compute ncolsscp=NCOL(SSCPxy). COMPUTE SSCPxy=SSCPxy(2:ncolsscp,2:ncolsscp). *print sscpxy. COMPUTE D=INV(MDIAG(SQRT(DIAG(SSCPxy)))). COMPUTE CORRMAT=D*SSCPxy*D. PRINT CORRMAT / FORMAT "F8.4". COMPUTE Beta=MAKE(NROW(MODELY),NCOL(modpred),0). COMPUTE RSq=MAKE(NROW(MODELY),1,0). + LOOP #I=1 TO NROW(MODELY). + COMPUTE CpyCorr=CORRMAT. + LOOP #J=1 TO NCOL(modpred). + DO IF (modpred(#I,#J) EQ 1). + COMPUTE CpyCorr=SWEEP(CpyCorr,#J). + END IF. + END LOOP. + COMPUTE DvIndex=NCOL(modpred)+MODELY(#I). + COMPUTE Beta(#I,:)=-1*modpred(#I,:) &* CpyCorr(DvIndex,1:NCOL(modpred)). + PRINT Beta. + COMPUTE RSq(#I)=1-CpyCorr(DvIndex,DvIndex). + END LOOP. SAVE ({MODELY,Beta,RSq})/OUTFILE *. end matrix. DATASET DECLARE RegResults. dataset name RegResults.
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?" |
|
I will be out of the office until Wednesday September 26, but will check email each day. If you need to reach me, please call my cell phone: 410-258-4623. |
|
In reply to this post by David Marso
Thanks, David. Your quick and dirty is far more elegant than what I came up with. I'll certainly review and incorporate your suggestions. Thanks again. -Ryan
On Mon, Sep 24, 2012 at 3:07 AM, David Marso <[hidden email]> wrote: Here is a quick and dirty (20 minute version). |
|
Administrator
|
Here is a abbrev snippet which does both standardized and nonstandardized.
-- MATRIX . GET X / FILE 'c:\temp\data1.sav' / variables x1 to x10. GET Y / FILE 'c:\temp\data1.sav' / variables y1 to y4. get modelY / file 'c:\temp\models.sav' / variables dv. get modpred / file 'c:\temp\models.sav' / variables x1 to x10. compute onexy={make(nrow(y),1,1),x,y}. compute Txyxy=T(onexy)*onexy. compute sumsxy=Txyxy(:,1). compute SSCPxy=Txyxy-sumsxy*T(sumsXY)/sumsxy(1,1). compute ncolsscp=NCOL(SSCPxy). COMPUTE SSCPxy2=SSCPxy(2:ncolsscp,2:ncolsscp). COMPUTE D=INV(MDIAG(SQRT(DIAG(SSCPxy2)))). COMPUTE CORRMAT=D*SSCPxy2*D. PRINT CORRMAT / FORMAT "F8.4". COMPUTE Beta=MAKE(NROW(MODELY),NCOL(modpred),0). COMPUTE B=MAKE(NROW(MODELY),NCOL(modpred)+1,0). COMPUTE RSq=MAKE(NROW(MODELY),1,0). + COMPUTE NPred= NCOL(modpred). + COMPUTE NDep= NCOL(Y). + LOOP #I=1 TO NROW(MODELY). + COMPUTE CpyCorr=CORRMAT. + COMPUTE CopyTxY=Txyxy. + COMPUTE CopyTxY=SWEEP(CopyTxY,1). + LOOP #J=1 TO NPred. + DO IF (modpred(#I,#J) EQ 1). + COMPUTE CpyCorr=SWEEP(CpyCorr,#J). + COMPUTE CopyTxY=SWEEP(CopyTxY,#J+1). + END IF. + END LOOP. + COMPUTE DvIndex=NPred+MODELY(#I). + COMPUTE Beta(#I,:)=-1*modpred(#I,:) &* CpyCorr(DvIndex,1:NPred). + COMPUTE B(#I,:)=CopyTxY((DvIndex+1),1:(NPred+1)). + COMPUTE RSq(#I)=1-CpyCorr(DvIndex,DvIndex). + END LOOP. + COMPUTE B= -1*{MAKE(NROW(MODELY),1,1),modpred} &*B . SAVE ({MODELY,Beta,B,RSq})/OUTFILE *. end matrix. DATASET DECLARE RegResults. dataset name RegResults.
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?" |
| Free forum by Nabble | Edit this page |
