[R] how to create this design matrix?

John Fox jfox at mcmaster.ca
Thu Nov 16 16:23:31 CET 2006


Dear Michael,

If I follow what you want to do, which is not altogether certain, what
you're describing as the "design matrix" is intended to constitute the
left-hand side of the model. That is, your d1,1, ..., d1,12 are the 12
response variables. If so, I'm not sure why you think that my original
suggestion won't give you the answer, but I guess that at this point I
should leave to someone else who understands more clearly what you want to
sort it out.

Regards,
 John

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
-------------------------------- 

> -----Original Message-----
> From: Michael [mailto:comtech.usa at gmail.com] 
> Sent: Wednesday, November 15, 2006 9:49 PM
> To: John Fox
> Subject: Re: [R] how to create this design matrix?
> 
> How about I make a design matrix as follows:
> 
> 1  d1,1  0   0     0   0     0   0   0
> 0    0   1   d1,2  0   0     0   0   0
> 0    0   0   0     1   d1,3  0   0   0
> ...
> ...
> 
> 0    0    0  0     0   0  ...  ... 1  d1,12 
> 
> 
> The above matrix will work for the 1st row of Y data;
> 
> d1, 1 means the 1st column of the 1st row of data; d1, 12 
> means the 12th column of the 1st row of data.
> 
> 
> But now since I have N samples(rows) of Y data; how do I 
> conceptually do a 3D design matrix? 
> 
> 
> On 11/15/06, John Fox <jfox at mcmaster.ca> wrote:
> 
> 	Dear Michael,
> 	
> 	> -----Original Message-----
> 	> From: Michael [mailto:comtech.usa at gmail.com]
> 	> Sent: Wednesday, November 15, 2006 2:40 PM
> 	> To: John Fox
> 	> Cc: R-help at stat.math.ethz.ch
> 	> Subject: Re: [R] how to create this design matrix?
> 	>
> 	> There are 12 response variables, columns 1 to 12 are response
> 	> variables, i.e., these are y's, they all regress to the 13th
> 	> column, which is the predictor, i.e. the X.
> 	>
> 	
> 	Right.
> 	
> 	> Let's take column 1, call this Y1, and there are n rows(n
> 	> samples) of it,
> 	>
> 	> I need Y1= b0_1 + b1_1* X + epsilon, where X is the 
> 13th column
> 	>
> 	> Similarly, for column 1 to column 12, we do the above,
> 	>
> 	> Y12= b0_12 + b1_12 * X + epsilon, where Y12 is the 
> 12th column, 
> 	>
> 	> they all have different b0's and b1's.
> 	
> 	Right.
> 	
> 	> Totally there are 24 b0's and b1's.
> 	>
> 	
> 	Yes.
> 	
> 	> I want a group regression, not separated regression...
> 	>
> 	
> 	I'm not sure what you mean by a "group regression" 
> rather than "separated 
> 	regressions." The multivarite linear regression that I 
> suggested will give
> 	you 12 slopes and 12 intercepts. They are exactly what 
> you'd get from 12
> 	individual least-squares regression of each Y on X, but 
> the multivariate 
> 	regression can also give you, e.g., the covariances 
> among all of the
> 	coefficients (if you want them).
> 	
> 	John
> 	
> 	> Thanks
> 	>
> 	>
> 	>
> 	>
> 	> On 11/15/06, John Fox < jfox at mcmaster.ca 
> <mailto:jfox at mcmaster.ca> > wrote:
> 	>
> 	>       Dear Michael,
> 	>
> 	>       This looks like a multivariate simple regression --
> 	> that is, 12 response
> 	>       variables, one predictor. If the data are in the matrix 
> 	> X, then lm(X[,1:12]
> 	>       ~ X[,13]) should do the trick.
> 	>
> 	>       I hope this helps,
> 	>       John
> 	>
> 	>       --------------------------------
> 	>       John Fox
> 	>       Department of Sociology 
> 	>       McMaster University
> 	>       Hamilton, Ontario
> 	>       Canada L8S 4M4
> 	>       905-525-9140x23604
> 	>       http://socserv.mcmaster.ca/jfox
> 	>       --------------------------------
> 	>
> 	>       > -----Original Message-----
> 	>       > From: r-help-bounces at stat.math.ethz.ch
> 	>       > [mailto: r-help-bounces at stat.math.ethz.ch
> 	> <mailto:r-help-bounces at stat.math.ethz.ch> ] On Behalf 
> Of Michael
> 	>       > Sent: Wednesday, November 15, 2006 12:23 AM
> 	>       > To: R-help at stat.math.ethz.ch
> 	>       > Subject: [R] how to create this design matrix?
> 	>       >
> 	>       > Hi all,
> 	>       >
> 	>       > I have a multiple-linear regression problem.
> 	>       >
> 	>       > There are 13 columns of data, the whole data 
> matrix is:  n x 
> 	>       > 13, where n is the number of samples.
> 	>       >
> 	>       > Now I want to regress  EACH of the first 12 
> columns onto the
> 	>       > 13th column, with 2-parameter linear model  
> y_i = b0 + b1 * 
> 	>       > x_i, where i goes from 1 to n, and b0 is the 
> intercept.
> 	>       >
> 	>       > How do I create a design matrix to do the 12-column
> 	>       > regression collectively all at once using multiple 
> 	> linear regressions?
> 	>       >
> 	>       > Thanks a lot
> 	>       >
> 	>       >       [[alternative HTML version deleted]]
> 	>       >
> 	>       > ______________________________________________ 
> 	>       > R-help at stat.math.ethz.ch mailing list
> 	>       > https://stat.ethz.ch/mailman/listinfo/r-help 
> 	>       > PLEASE do read the posting guide
> 	>       > http://www.R-project.org/posting-guide.html
> 	> < http://www.R-project.org/posting-guide.html 
> <http://www.R-project.org/posting-guide.html> >
> 	>       > and provide commented, minimal, self-contained,
> 	> reproducible code.
> 	>
> 	>
> 	>
> 	>
> 	>
> 	
> 	
> 
> 
>



More information about the R-help mailing list