[R] how to create this design matrix?

John Fox jfox at mcmaster.ca
Wed Nov 15 14:46:59 CET 2006

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 Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4

> -----Original Message-----
> From: 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
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list