[R] Fitting linear models
Bert Gunter
gunter.berton at gene.com
Tue Apr 21 01:42:59 CEST 2009
Is this homework? If so, you need to read the text and/or class notes more
carefully.
-- Bert Gunter
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Vemuri, Aparna
Sent: Monday, April 20, 2009 4:26 PM
To: r-help at r-project.org
Subject: [R] Fitting linear models
I am not sure if this is an R-users question, but since most of you here
are statisticians, I decided to give it a shot.
I am using the lm() function in R to fit a dependent variable to a set
of 3 to 5 independent variables. For this, I used the following
commands:
>model1<-lm(function=PBW~SO4+NO3+NH4)
Coefficients:
(Intercept) SO4 NO3 NH4
0.01323 0.01968 0.01856 NA
and
>model2<-lm(function=PBW~SO4+NO3+NH4+Na+Cl)
Coefficients:
(Intercept) SO4 NO3 NH4
Na Cl
-0.0006987 -0.0119750 -0.0295042 0.0842989 0.1344751
NA
In both cases, the last independent variable has a coefficient of NA in
the result. I say last variable because, when I change the order of the
variables, the coefficient changes (see below). Can anyone point me to
the reason R behaves this way? Is there anyway for me to force R to use
all the variables? I checked the correlation matrices to makes sure
there is no orthogonality between the variables.
Thanks
Aparna
model1<-lm(formula = PBW ~ SO4 + NH4 +NO3)
> model1
Call:
lm(formula = PBW ~ SO4 + NH4 + NO3)
Coefficients:
(Intercept) SO4 NH4 NO3
0.01323 -0.00430 0.06394 NA
> model2<-lm(formula = PBW ~ SO4 + NO3 + Na +Cl +NH4)
> model2
Call:
lm(formula = PBW ~ SO4 + NO3 + Na + Cl + NH4)
Coefficients:
(Intercept) SO4 NO3 Na
Cl NH4
-0.0006987 0.0196371 -0.0050303 0.0685020 0.0427431
NA
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org 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