# Syntax Classic List Threaded 13 messages Open this post in threaded view
|

## Syntax

 What is the function of the syntax highlighted in yellow? I am running this Multinomial Probabilities matrix ```Matrix. * intercept1 intercept2 pared public gpa. * these coefficients are taken from the output. compute b_gen = {1.689354 ; -0.057928 ; 1.162832 ; 0.629541}. compute b_voc = {4.235530 ; -0.113603 ; 0.982670 ; 1.274063}. * overall design matrix including means of public and gpa. compute x = {{1 ; 1; 1}, make(3, 1, 52.775), {1, 0; 0, 1; 0, 0}}. compute lp_gen = exp(x * b_gen). compute lp_voc = exp(x * b_voc). compute lp_aca = {1; 1; 1}. compute p_gen = lp_gen/(lp_aca + lp_gen + lp_voc). compute p_voc = lp_voc/(lp_aca + lp_gen + lp_voc). compute p_aca = lp_aca/(lp_aca + lp_gen + lp_voc). compute p = {p_gen, p_aca, p_voc}. print p /title 'Predicted Probabilities for Outcomes 1 2 3 for ses 1 2 3 at mean of write'. End Matrix.```
Open this post in threaded view
|

## Re: Syntax

 How about running Matrix. compute x = {{1 ; 1; 1}, make(3, 1, 52.775), {1, 0; 0, 1; 0, 0}}. print x. End Matrix. to find out. From: Peter Spangler Sent: Tuesday, February 12, 2013 8:51 PM Subject: Syntax What is the function of the syntax highlighted in yellow? I am running this Multinomial Probabilities matrix ===================== 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
Open this post in threaded view
|

## Re: Syntax

 Administrator In reply to this post by Peter Spangler compute x ={{1 ; 1; 1}, make(3, 1, 52.775), {1, 0; 0, 1; 0, 0}}. Will result in an error! Likely what is required is: compute x ={{1 ; 1; 1}, make(3; 1; 52.775), {1, 0; 0, 1; 0, 0}}. 1   3       1 0 1   1       0 1 1 52.775 0 0 Peter Spangler wrote What is the function of the syntax highlighted in yellow? I am running this Multinomial Probabilities matrix *Matrix. * intercept1 intercept2 pared public gpa. * these coefficients are taken from the output. compute b_gen = {1.689354 ; -0.057928 ; 1.162832 ; 0.629541}. compute b_voc = {4.235530 ; -0.113603 ; 0.982670 ; 1.274063}. * overall design matrix including means of public and gpa. compute x = {{1 ; 1; 1}, make(3, 1, 52.775), {1, 0; 0, 1; 0, 0}}. compute lp_gen = exp(x * b_gen). compute lp_voc = exp(x * b_voc). compute lp_aca = {1; 1; 1}. compute p_gen = lp_gen/(lp_aca + lp_gen + lp_voc). compute p_voc = lp_voc/(lp_aca + lp_gen + lp_voc). compute p_aca = lp_aca/(lp_aca + lp_gen + lp_voc). compute p = {p_gen, p_aca, p_voc}. print p /title 'Predicted Probabilities for Outcomes 1 2 3 for ses 1 2 3 at mean of write'. End Matrix.* 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?"
Open this post in threaded view
|

## Re: Syntax

 Administrator My Bad: Actually no error.  No coffee more like it. The result will actually be: 1 52.775 1 0 1 52.775 0 1 1 52.775 0 0 MAKE (nrows,ncols,value) David Marso wrote compute x ={{1 ; 1; 1}, make(3, 1, 52.775), {1, 0; 0, 1; 0, 0}}. Will result in an error! Likely what is required is: compute x ={{1 ; 1; 1}, make(3; 1; 52.775), {1, 0; 0, 1; 0, 0}}. 1   3       1 0 1   1       0 1 1 52.775 0 0 Peter Spangler wrote What is the function of the syntax highlighted in yellow? I am running this Multinomial Probabilities matrix *Matrix. * intercept1 intercept2 pared public gpa. * these coefficients are taken from the output. compute b_gen = {1.689354 ; -0.057928 ; 1.162832 ; 0.629541}. compute b_voc = {4.235530 ; -0.113603 ; 0.982670 ; 1.274063}. * overall design matrix including means of public and gpa. compute x = {{1 ; 1; 1}, make(3, 1, 52.775), {1, 0; 0, 1; 0, 0}}. compute lp_gen = exp(x * b_gen). compute lp_voc = exp(x * b_voc). compute lp_aca = {1; 1; 1}. compute p_gen = lp_gen/(lp_aca + lp_gen + lp_voc). compute p_voc = lp_voc/(lp_aca + lp_gen + lp_voc). compute p_aca = lp_aca/(lp_aca + lp_gen + lp_voc). compute p = {p_gen, p_aca, p_voc}. print p /title 'Predicted Probabilities for Outcomes 1 2 3 for ses 1 2 3 at mean of write'. End Matrix.* 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?"
Open this post in threaded view
|

## Re: Syntax

 In reply to this post by Peter Spangler What is the role of the two columns of 0,1 combinations in the calculation of this probability matrix? .`{1, 0; 0, 1; 0, 0}}` On Tue, Feb 12, 2013 at 6:51 PM, Peter Spangler wrote: What is the function of the syntax highlighted in yellow? I am running this Multinomial Probabilities matrix ```Matrix. * intercept1 intercept2 pared public gpa. * these coefficients are taken from the output. compute b_gen = {1.689354 ; -0.057928 ; 1.162832 ; 0.629541}. compute b_voc = {4.235530 ; -0.113603 ; 0.982670 ; 1.274063}. * overall design matrix including means of public and gpa. compute x = {{1 ; 1; 1}, make(3, 1, 52.775), {1, 0; 0, 1; 0, 0}}. compute lp_gen = exp(x * b_gen). compute lp_voc = exp(x * b_voc). compute lp_aca = {1; 1; 1}. compute p_gen = lp_gen/(lp_aca + lp_gen + lp_voc). compute p_voc = lp_voc/(lp_aca + lp_gen + lp_voc). compute p_aca = lp_aca/(lp_aca + lp_gen + lp_voc). compute p = {p_gen, p_aca, p_voc}. print p /title 'Predicted Probabilities for Outcomes 1 2 3 for ses 1 2 3 at mean of write'. End Matrix.```
Open this post in threaded view
|

## Re: Syntax

 Administrator What is the point of this whole exercise? Does the concept 'design matrix' resonate? When in doubt write out the math! -- Peter Spangler wrote What is the role of the two columns of 0,1 combinations in the calculation of this probability matrix? . *{1, 0; 0, 1; 0, 0}}* On Tue, Feb 12, 2013 at 6:51 PM, Peter Spangler <[hidden email]>wrote: > What is the function of the syntax highlighted in yellow? I am running > this Multinomial Probabilities matrix > > *Matrix. > * intercept1 intercept2 pared public gpa. > * these coefficients are taken from the output. > compute b_gen = {1.689354 ; -0.057928 ; 1.162832 ; 0.629541}. > compute b_voc = {4.235530 ; -0.113603 ; 0.982670 ; 1.274063}. > * overall design matrix including means of public and gpa.compute x = {{1 ; 1; 1}, make(3, 1, 52.775), {1, 0; 0, 1; 0, 0}}.compute lp_gen = exp(x * b_gen). > compute lp_voc = exp(x * b_voc). > compute lp_aca = {1; 1; 1}. > compute p_gen = lp_gen/(lp_aca + lp_gen + lp_voc). > compute p_voc = lp_voc/(lp_aca + lp_gen + lp_voc). > compute p_aca = lp_aca/(lp_aca + lp_gen + lp_voc). > compute p = {p_gen, p_aca, p_voc}. > print p /title 'Predicted Probabilities for Outcomes 1 2 3 for ses 1 2 3 at mean of write'. > End Matrix.* > > 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?"
Open this post in threaded view
|

## Re: Syntax

 In reply to this post by Peter Spangler Annette Dobson’s _An introduction to generalized linear models_ may be a good reference to understand those matrix operations.          Juan Zuluaga  (jzuluaga – stcloudstate.edu) Research Analyst at the Office of Precollege Programs, St. Cloud State University.
Open this post in threaded view
|

## Re: Syntax

 In reply to this post by David Marso The point of this exercise is to better understand the syntax. The design matrix resonates, calculating log probabilities from the intercept and coefficients. I'll look into Annette Dobson’s _An introduction to generalized linear models On Fri, Feb 15, 2013 at 4:39 AM, David Marso wrote: What is the point of this whole exercise? Does the concept 'design matrix' resonate? When in doubt write out the math! -- Peter Spangler wrote > What is the role of the two columns of 0,1 combinations in the calculation > of this probability matrix? . > > *{1, 0; 0, 1; 0, 0}}* > > > > On Tue, Feb 12, 2013 at 6:51 PM, Peter Spangler < > pspangler@ > >wrote: > >> What is the function of the syntax highlighted in yellow? I am running >> this Multinomial Probabilities matrix >> >> *Matrix. >> * intercept1 intercept2 pared public gpa. >> * these coefficients are taken from the output. >> compute b_gen = {1.689354 ; -0.057928 ; 1.162832 ; 0.629541}. >> compute b_voc = {4.235530 ; -0.113603 ; 0.982670 ; 1.274063}. >> * overall design matrix including means of public and gpa.compute x = {{1 >> ; 1; 1}, make(3, 1, 52.775), {1, 0; 0, 1; 0, 0}}.compute lp_gen = exp(x * >> b_gen). >> compute lp_voc = exp(x * b_voc). >> compute lp_aca = {1; 1; 1}. >> compute p_gen = lp_gen/(lp_aca + lp_gen + lp_voc). >> compute p_voc = lp_voc/(lp_aca + lp_gen + lp_voc). >> compute p_aca = lp_aca/(lp_aca + lp_gen + lp_voc). >> compute p = {p_gen, p_aca, p_voc}. >> print p /title 'Predicted Probabilities for Outcomes 1 2 3 for ses 1 2 3 >> at mean of write'. >> End Matrix.* >> >> ----- Please reply to the list and not to my personal email. Those desiring my consulting or training services please feel free to email me. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Syntax-tp5718048p5718080.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
Open this post in threaded view
|

## Re: Syntax

 In reply to this post by Peter Spangler Peter, Use of matrix algebra is an efficient way of estimating predicted probabilities from a generalized logit model. Let's forget about the matrix code for a moment...Consider the following linear equation (eta_j) for a multinomial logistic regression:  eta_j = b0_j + b1_j*(x1) + ... + b2_j*(xk) With three levels of the response (y=1,2,3) and three independent variables (x1, x2, x3), we would have two linear equations:   eta_1 = b0_1 + b1_1*(x1) + b2_1*(x2) + b3_1*(x3) eta_2 = b0_2 + b1_2*(x1) + b2_2*(x2) + b3_2*(x3)  ...and employing the inverse logit link function would produce the probabilities:  prob_1 = exp(eta_1) / (1 + exp(eta_1) + exp(eta_2))prob_2 = exp(eta_2) / (1 + exp(eta_1) + exp(eta_2))prob_3 =  1 / (1 + exp(eta_1) + exp(eta_2))Now, let's apply what's stated above to your example using COMPUTE: compute lp_gen_write_mean_ses1 = 1.689354 - 0.057928*(52.775) + 1.162832*(1) + 0.629541*(0).compute lp_gen_write_mean_ses2 = 1.689354 - 0.057928*(52.775) + 1.162832*(0) + 0.629541*(1).compute lp_gen_write_mean_ses3 = 1.689354 - 0.057928*(52.775) + 1.162832*(0) + 0.629541*(0). compute lp_voc_write_mean_ses1 = 4.235530 - 0.113603*(52.775) + 0.982670*(1) + 1.274063*(0).compute lp_voc_write_mean_ses2 = 4.235530 - 0.113603*(52.775) + 0.982670*(0) + 1.274063*(1).compute lp_voc_write_mean_ses3 = 4.235530 - 0.113603*(52.775) + 0.982670*(0) + 1.274063*(0). execute. *...and employing the inverse logit link function will produce the nine probabilities. compute p_gen_write_mean_ses1 = exp(lp_gen_write_mean_ses1) / (1 + exp(lp_gen_write_mean_ses1) + exp(lp_voc_write_mean_ses1)). compute p_gen_write_mean_ses2 = exp(lp_gen_write_mean_ses2) / (1 + exp(lp_gen_write_mean_ses2) + exp(lp_voc_write_mean_ses2)).compute p_gen_write_mean_ses3 = exp(lp_gen_write_mean_ses3) / (1 + exp(lp_gen_write_mean_ses3) + exp(lp_voc_write_mean_ses3)). compute p_voc_write_mean_ses1 = exp(lp_voc_write_mean_ses1) / (1 + exp(lp_gen_write_mean_ses1) + exp(lp_voc_write_mean_ses1)).compute p_voc_write_mean_ses2 = exp(lp_voc_write_mean_ses2) / (1 + exp(lp_gen_write_mean_ses2) + exp(lp_voc_write_mean_ses2)). compute p_voc_write_mean_ses3 = exp(lp_voc_write_mean_ses3) / (1 + exp(lp_gen_write_mean_ses3) + exp(lp_voc_write_mean_ses3)).compute p_aca_write_mean_ses1 = 1 / (1 + exp(lp_gen_write_mean_ses1) + exp(lp_voc_write_mean_ses1)). compute p_aca_write_mean_ses2 = 1 / (1 + exp(lp_gen_write_mean_ses2) + exp(lp_voc_write_mean_ses2)).compute p_aca_write_mean_ses3 = 1 / (1 + exp(lp_gen_write_mean_ses3) + exp(lp_voc_write_mean_ses3)).execute. The SPSS code you posted is simply calculating these probabilities in a much more efficient way than my approach because it uses matrix algebra. That is, one obtains the estimated probabilities of each the three response levels from all possible combinations of the two SES indicator variables (1,0; 0,1; 0,0) with the covariate set at its grand mean (52.775) by employing the design matrix. As David suggested, if you work out the actual math the matrix code is performing, it should become self-evident. My hope is that the inelegant, but hopefully educational code I wrote will help you achieve clarity. Still, if you are unable to connect the code I wrote above with the code you posted, write back.   Ryan  On Tue, Feb 12, 2013 at 9:51 PM, Peter Spangler wrote: What is the function of the syntax highlighted in yellow? I am running this Multinomial Probabilities matrix ```Matrix. * intercept1 intercept2 pared public gpa. * these coefficients are taken from the output. compute b_gen = {1.689354 ; -0.057928 ; 1.162832 ; 0.629541}. compute b_voc = {4.235530 ; -0.113603 ; 0.982670 ; 1.274063}. * overall design matrix including means of public and gpa. compute x = {{1 ; 1; 1}, make(3, 1, 52.775), {1, 0; 0, 1; 0, 0}}. compute lp_gen = exp(x * b_gen). compute lp_voc = exp(x * b_voc). compute lp_aca = {1; 1; 1}. compute p_gen = lp_gen/(lp_aca + lp_gen + lp_voc). compute p_voc = lp_voc/(lp_aca + lp_gen + lp_voc). compute p_aca = lp_aca/(lp_aca + lp_gen + lp_voc). compute p = {p_gen, p_aca, p_voc}. print p /title 'Predicted Probabilities for Outcomes 1 2 3 for ses 1 2 3 at mean of write'. End Matrix.```
Open this post in threaded view
|

## Re: Syntax

Open this post in threaded view
|

## Re: Syntax

 It is also worth noting that the line in question:`compute x = {{1 ; 1; 1}, make(3, 1, 52.775), {1, 0; 0, 1; 0, 0}}.`includes the SPSS "make(s1,s2,s3)" function which literally makes a matrix with a specified number of rows (s1), a specified number of columns (s2), and a specified value for each element (s3). So, for this example, the "make(s1,s2,s3)" function is creating a column vector of three rows (3 X 1 matrix) with element values set at 52.755. RyanOn Feb 16, 2013, at 10:28 AM, David Marso <[hidden email]> wrote:Matrix multiplication:A=a bc de f{a,b;c,d;e,f}X=xy{x;y}A*Xax+bycx+dyex+fy------------Matrix addition:A=a bc de fX=u vw xy zMatrix addition:a+u,b+vc+w,d+xe+y,f+z------------------Ryan Black wrotePeter,Use of matrix algebra is an efficient way of estimating predictedprobabilities from a generalized logit model. Let's forget about thematrix code for a moment...Consider the following linear equation (eta_j) for a multinomial logisticregression:eta_j = b0_j + b1_j*(x1) + ... + b2_j*(xk)With three levels of the response (y=1,2,3) and three independentvariables (x1, x2, x3), we would have two linear equations:eta_1 = b0_1 + b1_1*(x1) + b2_1*(x2) + b3_1*(x3)eta_2 = b0_2 + b1_2*(x1) + b2_2*(x2) + b3_2*(x3)...and employing the inverse logit link function would produce theprobabilities:prob_1 = exp(eta_1) / (1 + exp(eta_1) + exp(eta_2))prob_2 = exp(eta_2) / (1 + exp(eta_1) + exp(eta_2))prob_3 =  1 / (1 + exp(eta_1) + exp(eta_2))Now, let's apply what's stated above to your example using COMPUTE:compute lp_gen_write_mean_ses1 = 1.689354 - 0.057928*(52.775) +1.162832*(1) + 0.629541*(0).compute lp_gen_write_mean_ses2 = 1.689354 - 0.057928*(52.775) +1.162832*(0) + 0.629541*(1).compute lp_gen_write_mean_ses3 = 1.689354 - 0.057928*(52.775) +1.162832*(0) + 0.629541*(0).compute lp_voc_write_mean_ses1 = 4.235530 - 0.113603*(52.775) +0.982670*(1) + 1.274063*(0).compute lp_voc_write_mean_ses2 = 4.235530 - 0.113603*(52.775) +0.982670*(0) + 1.274063*(1).compute lp_voc_write_mean_ses3 = 4.235530 - 0.113603*(52.775) +0.982670*(0) + 1.274063*(0).execute.*...and employing the inverse logit link function will produce the nineprobabilities.compute p_gen_write_mean_ses1 = exp(lp_gen_write_mean_ses1) / (1 +exp(lp_gen_write_mean_ses1) + exp(lp_voc_write_mean_ses1)).compute p_gen_write_mean_ses2 = exp(lp_gen_write_mean_ses2) / (1 +exp(lp_gen_write_mean_ses2) + exp(lp_voc_write_mean_ses2)).compute p_gen_write_mean_ses3 = exp(lp_gen_write_mean_ses3) / (1 +exp(lp_gen_write_mean_ses3) + exp(lp_voc_write_mean_ses3)).compute p_voc_write_mean_ses1 = exp(lp_voc_write_mean_ses1) / (1 +exp(lp_gen_write_mean_ses1) + exp(lp_voc_write_mean_ses1)).compute p_voc_write_mean_ses2 = exp(lp_voc_write_mean_ses2) / (1 +exp(lp_gen_write_mean_ses2) + exp(lp_voc_write_mean_ses2)).compute p_voc_write_mean_ses3 = exp(lp_voc_write_mean_ses3) / (1 +exp(lp_gen_write_mean_ses3) + exp(lp_voc_write_mean_ses3)).compute p_aca_write_mean_ses1 = 1 / (1 + exp(lp_gen_write_mean_ses1) +exp(lp_voc_write_mean_ses1)).compute p_aca_write_mean_ses2 = 1 / (1 + exp(lp_gen_write_mean_ses2) +exp(lp_voc_write_mean_ses2)).compute p_aca_write_mean_ses3 = 1 / (1 + exp(lp_gen_write_mean_ses3) +exp(lp_voc_write_mean_ses3)).execute.The SPSS code you posted is simply calculating these probabilities in amuch more efficient way than my approach because it uses matrix algebra.That is, one obtains the estimated probabilities of each the threeresponse levels from all possible combinations of the two SES indicatorvariables (1,0; 0,1; 0,0) with the covariate set at its grand mean(52.775) by employing the design matrix.As David suggested, if you work out the actual math the matrix code isperforming, it should become self-evident.My hope is that the inelegant, but hopefully educational code I wrote willhelp you achieve clarity. Still, if you are unable to connect the code Iwrote above with the code you posted, write back.RyanOn Tue, Feb 12, 2013 at 9:51 PM, Peter Spangler <pspangler@> wrote:What is the function of the syntax highlighted in yellow? I am runningthis Multinomial Probabilities matrixMatrix.* intercept1 intercept2 pared public gpa.* these coefficients are taken from the output.compute b_gen = {1.689354 ; -0.057928 ; 1.162832 ; 0.629541}.compute b_voc = {4.235530 ; -0.113603 ; 0.982670 ; 1.274063}.* overall design matrix including means of public and gpa.compute x = {{1 ; 1; 1}, make(3, 1, 52.775), {1, 0; 0, 1; 0, 0}}.compute lp_gen = exp(x * b_gen).compute lp_voc = exp(x * b_voc).compute lp_aca = {1; 1; 1}.compute p_gen = lp_gen/(lp_aca + lp_gen + lp_voc).compute p_voc = lp_voc/(lp_aca + lp_gen + lp_voc).compute p_aca = lp_aca/(lp_aca + lp_gen + lp_voc).compute p = {p_gen, p_aca, p_voc}.print p /title 'Predicted Probabilities for Outcomes 1 2 3 for ses 1 2 3at mean of write'.End Matrix.-----Please reply to the list and not to my personal email.Those desiring my consulting or training services please feel free to email me.--View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Syntax-tp5718048p5718095.htmlSent 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 thecommand. To leave the list, send the commandSIGNOFF SPSSX-LFor a list of commands to manage subscriptions, send the commandINFO REFCARD
 I received a question off-list, so I think to be complete, I might as well just show the full X matrix: 1 52.755 1 0 1 52.755 0 11 52.755 0 0The first column represents the place for the constant, the second column represents the mean-value of the first predictor, the third column represents the value of the first SES indicator variable, and the fourth column represents the second SES indicator variable. (If there is confusion as to why a categorical predictor with three levels, "SES", is converted into two indicator variables coded 0/1, I suggest brushing up on the use of indicator/dummy coding to capture all the information from a categorical independent variable with more than two levels).  X is then multiplied by the corresponding set of estimated regression coefficients for y=1 ("b_gen") and y=2 ("b_voc"), exponentiated, and then converted to the nine probabilities using the formulas I presented in a previous post. Again, the matrix code posted by the OP is simply a more efficient way of obtaining the probabilities.  Ryan On Sat, Feb 16, 2013 at 11:45 AM, wrote: It is also worth noting that the line in question:`compute x = {{1 ; 1; 1}, make(3, 1, 52.775), {1, 0; 0, 1; 0, 0}}.` includes the SPSS "make(s1,s2,s3)" function which literally makes a matrix with a specified number of rows (s1), a specified number of columns (s2), and a specified value for each element (s3). So, for this example, the "make(s1,s2,s3)" function is creating a column vector of three rows (3 X 1 matrix) with element values set at 52.755.  RyanOn Feb 16, 2013, at 10:28 AM, David Marso <[hidden email]> wrote: Matrix multiplication:A=a bc de f{a,b;c,d;e,f}X=x y{x;y}A*Xax+bycx+dyex+fy------------Matrix addition:A= a bc de fX=u vw xy zMatrix addition:a+u,b+v c+w,d+xe+y,f+z------------------Ryan Black wrotePeter, Use of matrix algebra is an efficient way of estimating predictedprobabilities from a generalized logit model. Let's forget about the matrix code for a moment...Consider the following linear equation (eta_j) for a multinomial logistic regression:eta_j = b0_j + b1_j*(x1) + ... + b2_j*(xk) With three levels of the response (y=1,2,3) and three independentvariables (x1, x2, x3), we would have two linear equations: eta_1 = b0_1 + b1_1*(x1) + b2_1*(x2) + b3_1*(x3)eta_2 = b0_2 + b1_2*(x1) + b2_2*(x2) + b3_2*(x3) ...and employing the inverse logit link function would produce theprobabilities: prob_1 = exp(eta_1) / (1 + exp(eta_1) + exp(eta_2))prob_2 = exp(eta_2) / (1 + exp(eta_1) + exp(eta_2)) prob_3 =  1 / (1 + exp(eta_1) + exp(eta_2))Now, let's apply what's stated above to your example using COMPUTE: compute lp_gen_write_mean_ses1 = 1.689354 - 0.057928*(52.775) +1.162832*(1) + 0.629541*(0). compute lp_gen_write_mean_ses2 = 1.689354 - 0.057928*(52.775) +1.162832*(0) + 0.629541*(1). compute lp_gen_write_mean_ses3 = 1.689354 - 0.057928*(52.775) +1.162832*(0) + 0.629541*(0).compute lp_voc_write_mean_ses1 = 4.235530 - 0.113603*(52.775) + 0.982670*(1) + 1.274063*(0).compute lp_voc_write_mean_ses2 = 4.235530 - 0.113603*(52.775) + 0.982670*(0) + 1.274063*(1).compute lp_voc_write_mean_ses3 = 4.235530 - 0.113603*(52.775) +0.982670*(0) + 1.274063*(0). execute.*...and employing the inverse logit link function will produce the nine probabilities.compute p_gen_write_mean_ses1 = exp(lp_gen_write_mean_ses1) / (1 + exp(lp_gen_write_mean_ses1) + exp(lp_voc_write_mean_ses1)).compute p_gen_write_mean_ses2 = exp(lp_gen_write_mean_ses2) / (1 + exp(lp_gen_write_mean_ses2) + exp(lp_voc_write_mean_ses2)).compute p_gen_write_mean_ses3 = exp(lp_gen_write_mean_ses3) / (1 + exp(lp_gen_write_mean_ses3) + exp(lp_voc_write_mean_ses3)).compute p_voc_write_mean_ses1 = exp(lp_voc_write_mean_ses1) / (1 + exp(lp_gen_write_mean_ses1) + exp(lp_voc_write_mean_ses1)).compute p_voc_write_mean_ses2 = exp(lp_voc_write_mean_ses2) / (1 + exp(lp_gen_write_mean_ses2) + exp(lp_voc_write_mean_ses2)).compute p_voc_write_mean_ses3 = exp(lp_voc_write_mean_ses3) / (1 + exp(lp_gen_write_mean_ses3) + exp(lp_voc_write_mean_ses3)).compute p_aca_write_mean_ses1 = 1 / (1 + exp(lp_gen_write_mean_ses1) + exp(lp_voc_write_mean_ses1)).compute p_aca_write_mean_ses2 = 1 / (1 + exp(lp_gen_write_mean_ses2) + exp(lp_voc_write_mean_ses2)).compute p_aca_write_mean_ses3 = 1 / (1 + exp(lp_gen_write_mean_ses3) +exp(lp_voc_write_mean_ses3)). execute.The SPSS code you posted is simply calculating these probabilities in a much more efficient way than my approach because it uses matrix algebra.That is, one obtains the estimated probabilities of each the three response levels from all possible combinations of the two SES indicatorvariables (1,0; 0,1; 0,0) with the covariate set at its grand mean (52.775) by employing the design matrix.As David suggested, if you work out the actual math the matrix code is performing, it should become self-evident.My hope is that the inelegant, but hopefully educational code I wrote will help you achieve clarity. Still, if you are unable to connect the code Iwrote above with the code you posted, write back. RyanOn Tue, Feb 12, 2013 at 9:51 PM, Peter Spangler < pspangler@> wrote: What is the function of the syntax highlighted in yellow? I am runningthis Multinomial Probabilities matrix Matrix.* intercept1 intercept2 pared public gpa. * these coefficients are taken from the output.compute b_gen = {1.689354 ; -0.057928 ; 1.162832 ; 0.629541}. compute b_voc = {4.235530 ; -0.113603 ; 0.982670 ; 1.274063}. * overall design matrix including means of public and gpa.compute x = {{1 ; 1; 1}, make(3, 1, 52.775), {1, 0; 0, 1; 0, 0}}. compute lp_gen = exp(x * b_gen).compute lp_voc = exp(x * b_voc). compute lp_aca = {1; 1; 1}.compute p_gen = lp_gen/(lp_aca + lp_gen + lp_voc). compute p_voc = lp_voc/(lp_aca + lp_gen + lp_voc).compute p_aca = lp_aca/(lp_aca + lp_gen + lp_voc). compute p = {p_gen, p_aca, p_voc}.print p /title 'Predicted Probabilities for Outcomes 1 2 3 for ses 1 2 3 at mean of write'.End Matrix. -----Please reply to the list and not to my personal email.Those desiring my consulting or training services please feel free to email me. --View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Syntax-tp5718048p5718095.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 thecommand. To leave the list, send the commandSIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the commandINFO REFCARD
 Okay, I have been so used to dummy coding variables without the use of syntax I didn't even think of the 0,1 function as such. So much faster! I certainly would like to crush up on dummy variables with multiple levels. Any recommended texts?Sent from my iPhoneOn Feb 16, 2013, at 10:31 AM, R B <[hidden email]> wrote: I received a question off-list, so I think to be complete, I might as well just show the full X matrix: 1 52.755 1 0 1 52.755 0 11 52.755 0 0 The first column represents the place for the constant, the second column represents the mean-value of the first predictor, the third column represents the value of the first SES indicator variable, and the fourth column represents the second SES indicator variable. (If there is confusion as to why a categorical predictor with three levels, "SES", is converted into two indicator variables coded 0/1, I suggest brushing up on the use of indicator/dummy coding to capture all the information from a categorical independent variable with more than two levels).  X is then multiplied by the corresponding set of estimated regression coefficients for y=1 ("b_gen") and y=2 ("b_voc"), exponentiated, and then converted to the nine probabilities using the formulas I presented in a previous post. Again, the matrix code posted by the OP is simply a more efficient way of obtaining the probabilities.  Ryan On Sat, Feb 16, 2013 at 11:45 AM, wrote: It is also worth noting that the line in question:`compute x = {{1 ; 1; 1}, make(3, 1, 52.775), {1, 0; 0, 1; 0, 0}}.` includes the SPSS "make(s1,s2,s3)" function which literally makes a matrix with a specified number of rows (s1), a specified number of columns (s2), and a specified value for each element (s3). So, for this example, the "make(s1,s2,s3)" function is creating a column vector of three rows (3 X 1 matrix) with element values set at 52.755.  RyanOn Feb 16, 2013, at 10:28 AM, David Marso <[hidden email]> wrote: Matrix multiplication:A=a bc de f{a,b;c,d;e,f}X=x y{x;y}A*Xax+bycx+dyex+fy------------Matrix addition:A= a bc de fX=u vw xy zMatrix addition:a+u,b+v c+w,d+xe+y,f+z------------------Ryan Black wrotePeter, Use of matrix algebra is an efficient way of estimating predictedprobabilities from a generalized logit model. Let's forget about the matrix code for a moment...Consider the following linear equation (eta_j) for a multinomial logistic regression:eta_j = b0_j + b1_j*(x1) + ... + b2_j*(xk) With three levels of the response (y=1,2,3) and three independentvariables (x1, x2, x3), we would have two linear equations: eta_1 = b0_1 + b1_1*(x1) + b2_1*(x2) + b3_1*(x3)eta_2 = b0_2 + b1_2*(x1) + b2_2*(x2) + b3_2*(x3) ...and employing the inverse logit link function would produce theprobabilities: prob_1 = exp(eta_1) / (1 + exp(eta_1) + exp(eta_2))prob_2 = exp(eta_2) / (1 + exp(eta_1) + exp(eta_2)) prob_3 =  1 / (1 + exp(eta_1) + exp(eta_2))Now, let's apply what's stated above to your example using COMPUTE: compute lp_gen_write_mean_ses1 = 1.689354 - 0.057928*(52.775) +1.162832*(1) + 0.629541*(0). compute lp_gen_write_mean_ses2 = 1.689354 - 0.057928*(52.775) +1.162832*(0) + 0.629541*(1). compute lp_gen_write_mean_ses3 = 1.689354 - 0.057928*(52.775) +1.162832*(0) + 0.629541*(0).compute lp_voc_write_mean_ses1 = 4.235530 - 0.113603*(52.775) + 0.982670*(1) + 1.274063*(0).compute lp_voc_write_mean_ses2 = 4.235530 - 0.113603*(52.775) + 0.982670*(0) + 1.274063*(1).compute lp_voc_write_mean_ses3 = 4.235530 - 0.113603*(52.775) +0.982670*(0) + 1.274063*(0). execute.*...and employing the inverse logit link function will produce the nine probabilities.compute p_gen_write_mean_ses1 = exp(lp_gen_write_mean_ses1) / (1 + exp(lp_gen_write_mean_ses1) + exp(lp_voc_write_mean_ses1)).compute p_gen_write_mean_ses2 = exp(lp_gen_write_mean_ses2) / (1 + exp(lp_gen_write_mean_ses2) + exp(lp_voc_write_mean_ses2)).compute p_gen_write_mean_ses3 = exp(lp_gen_write_mean_ses3) / (1 + exp(lp_gen_write_mean_ses3) + exp(lp_voc_write_mean_ses3)).compute p_voc_write_mean_ses1 = exp(lp_voc_write_mean_ses1) / (1 + exp(lp_gen_write_mean_ses1) + exp(lp_voc_write_mean_ses1)).compute p_voc_write_mean_ses2 = exp(lp_voc_write_mean_ses2) / (1 + exp(lp_gen_write_mean_ses2) + exp(lp_voc_write_mean_ses2)).compute p_voc_write_mean_ses3 = exp(lp_voc_write_mean_ses3) / (1 + exp(lp_gen_write_mean_ses3) + exp(lp_voc_write_mean_ses3)).compute p_aca_write_mean_ses1 = 1 / (1 + exp(lp_gen_write_mean_ses1) + exp(lp_voc_write_mean_ses1)).compute p_aca_write_mean_ses2 = 1 / (1 + exp(lp_gen_write_mean_ses2) + exp(lp_voc_write_mean_ses2)).compute p_aca_write_mean_ses3 = 1 / (1 + exp(lp_gen_write_mean_ses3) +exp(lp_voc_write_mean_ses3)). execute.The SPSS code you posted is simply calculating these probabilities in a much more efficient way than my approach because it uses matrix algebra.That is, one obtains the estimated probabilities of each the three response levels from all possible combinations of the two SES indicatorvariables (1,0; 0,1; 0,0) with the covariate set at its grand mean (52.775) by employing the design matrix.As David suggested, if you work out the actual math the matrix code is performing, it should become self-evident.My hope is that the inelegant, but hopefully educational code I wrote will help you achieve clarity. Still, if you are unable to connect the code Iwrote above with the code you posted, write back. RyanOn Tue, Feb 12, 2013 at 9:51 PM, Peter Spangler < pspangler@> wrote: What is the function of the syntax highlighted in yellow? I am runningthis Multinomial Probabilities matrix Matrix.* intercept1 intercept2 pared public gpa. * these coefficients are taken from the output.compute b_gen = {1.689354 ; -0.057928 ; 1.162832 ; 0.629541}. compute b_voc = {4.235530 ; -0.113603 ; 0.982670 ; 1.274063}. * overall design matrix including means of public and gpa.compute x = {{1 ; 1; 1}, make(3, 1, 52.775), {1, 0; 0, 1; 0, 0}}. compute lp_gen = exp(x * b_gen).compute lp_voc = exp(x * b_voc). compute lp_aca = {1; 1; 1}.compute p_gen = lp_gen/(lp_aca + lp_gen + lp_voc). compute p_voc = lp_voc/(lp_aca + lp_gen + lp_voc).compute p_aca = lp_aca/(lp_aca + lp_gen + lp_voc). compute p = {p_gen, p_aca, p_voc}.print p /title 'Predicted Probabilities for Outcomes 1 2 3 for ses 1 2 3 at mean of write'.End Matrix. -----Please reply to the list and not to my personal email.Those desiring my consulting or training services please feel free to email me. --View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Syntax-tp5718048p5718095.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 thecommand. To leave the list, send the commandSIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the commandINFO REFCARD