[R] how to do linear regression when dimension is high
Douglas Bates
bates at stat.wisc.edu
Tue Nov 16 18:20:44 CET 2010
On Tue, Nov 16, 2010 at 10:30 AM, poko2000 <quan.poko2000 at gmail.com> wrote:
> Hi I am a newbie in R.
> I have data with dim of 20.
> How to use lm if i want to do regression with the whole design matrix? My y
> is the first column.
> the left are xs.
> Thanks a lot.
Do you have the data stored in a matrix or in a data frame? If it is
in a data frame and the first column is named "y" then you can use a
call like
lm(y ~ ., mydata)
The '.' on the right hand side of the formula is expanded to a formula
incorporating of the columns in the data frame except for the
response. For example
> summary(lm(Fertility ~ ., swiss))
Call:
lm(formula = Fertility ~ ., data = swiss)
Residuals:
Min 1Q Median 3Q Max
-15.2743 -5.2617 0.5032 4.1198 15.3213
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 66.91518 10.70604 6.250 1.91e-07
Agriculture -0.17211 0.07030 -2.448 0.01873
Examination -0.25801 0.25388 -1.016 0.31546
Education -0.87094 0.18303 -4.758 2.43e-05
Catholic 0.10412 0.03526 2.953 0.00519
Infant.Mortality 1.07705 0.38172 2.822 0.00734
Residual standard error: 7.165 on 41 degrees of freedom
Multiple R-squared: 0.7067, Adjusted R-squared: 0.671
F-statistic: 19.76 on 5 and 41 DF, p-value: 5.594e-10
More information about the R-help
mailing list