Attached are the first hundred rows of my data in comma separated format.       
Forcing the regression line through the origin, still does not give a 
coefficient on the last independent variable. Also, I don't mind if there is a 
coefficient on the dependent axis. I just want all of the variables to have 
coefficients in the regression equation or a at least a consistent result, 
irrespective of the order of input information.

-----Original Message-----
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Tuesday, April 21, 2009 8:38 AM
To: Vemuri, Aparna
Cc: r-help@r-project.org
Subject: Re: [R] Fitting linear models


On Apr 21, 2009, at 11:12 AM, Vemuri, Aparna wrote:

> David,
> Thanks for the suggestions. No, I did not label my dependent  
> variable "function".

That was from my error in reading your call to lm. In my defense I am  
reasonably sure the proper assignment to arguments is lm(formula= ...)  
rather than lm(function= ...).
>
>
> My dependent variable PBW and all the independent variables are  
> continuous variables. It is especially troubling since the order in  
> which I input independent variables determines whether or not it  
> gets a coefficient.  Like I already mentioned, I checked the  
> correlation matrix and picked the variables with moderate to high  
> correlation with the independent variable. . So I guess it is not so  
> naïve to expect a regression coefficient on all of them.
>
> Dimitri
> model1<-lm(PBW~SO4+NO3+NH4), gives me the same result as before.

Did you get the expected results with;
model1<-lm(formula=PBW~SO4+NO3+NH4+0)

You could, of course, provide either the data or the results of str()  
applied to each of the variables and then we could all stop guessing.

>
> Aparna
>
>>
>>
>> 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.
>
> You really did not name your dependent variable "function" did you?
> Please stop that.
>
> Just a guess, ... since you have not provided enough information to do
> otherwise, ... Are all of those variables 1/0 dummy variables? If so
> and if you want to have an output that satisfies your need for
> labeling the coefficients as you naively anticipate, then put "0+" at
> the beginning of the formula or "-1" at the end, so that the intercept
> will disappear and then all variables will get labeled as you expect.
-- 
David Winsemius, MD
Heritage Laboratories
West Hartford, CT

PBW,SO4,NO3,NH4
0.063,3.218,0.089,1.233
0.036,1.837,0.088,0.714
0.032,1.655,0.188,0.675
0.024,1.249,0.132,0.507
0.053,2.72,0.125,1.056
0.055,2.775,0.028,1.049
0.06,3.035,0.022,1.144
0.029,1.491,0.03,0.568
0.038,1.911,0.049,0.731
0.033,1.675,0.042,0.64
0.043,2.183,0.02,0.825
0.024,1.228,0.03,0.469
0.042,2.159,0.055,0.825
0.04,2.047,0.036,0.778
0.008,0.413,0.027,0.163
0.152,7.678,0.04,2.891
0.106,5.383,0.019,2.024
0.076,3.842,0.071,1.461
0.029,1.474,0.01,0.556
0.048,2.454,0.028,0.928
0.064,3.239,0.03,1.223
0.074,3.761,0.054,1.426
0.074,3.731,0.062,1.417
0.216,10.953,0.027,4.115
0.158,8.095,0.384,3.147
0.065,3.441,0.614,1.468
0.027,1.383,0.079,0.541
0.084,4.242,0.072,1.612
0.096,4.875,0.049,1.842
0.052,2.617,0.052,0.996
0.025,1.257,0.033,0.481
0.057,2.913,0.042,1.104
0.081,4.097,0.051,1.551
0.028,1.431,0.009,0.539
0.134,6.799,0.05,2.564
0.095,4.808,0.056,1.819
0.023,1.173,0.025,0.447
0.024,1.23,0.045,0.474
0.021,1.123,0.148,0.464
0.027,1.366,0.073,0.534
0.049,2.467,0.045,0.938
0.05,2.537,0.061,0.969
0.06,3.033,0.077,1.16
0.093,4.708,0.106,1.796
0.095,4.838,0.073,1.835
0.086,4.342,0.07,1.649
0.032,1.725,0.465,0.782
0.041,2.304,0.881,1.12
0.106,5.919,1.955,2.787
0.062,3.146,0.059,1.197
0.104,5.285,0.065,2.001
0.017,0.849,0.009,0.321
0.03,1.514,0.031,0.577
0.032,1.651,0.058,0.636
0.039,1.975,0.021,0.747
0.048,2.434,0.045,0.926
0.045,2.283,0.073,0.877
0.065,3.294,0.009,1.238
0.105,5.323,0.028,2.004
0.029,1.45,0.02,0.55
0.062,3.202,0.156,1.246
0.119,6.018,0.009,2.259
0.147,7.418,0.009,2.785
0.042,2.116,0.061,0.811
0.03,1.589,0.218,0.659
0.043,2.177,0.055,0.832
0.067,3.377,0.009,1.269
0.051,2.564,0.009,0.964
0.063,3.194,0.041,1.21
0.082,4.183,0.035,1.578
0.047,2.362,0.026,0.893
0.063,3.204,0.089,1.227
0.062,3.151,0.049,1.196
0.039,1.997,0.009,0.751
0.039,1.958,0.023,0.741
0.109,5.516,0.076,2.091
0.171,8.689,0.153,3.303
0.07,3.527,0.047,1.336
0.118,5.998,0.036,2.26
0.132,6.657,0.009,2.499
0.128,6.475,0.009,2.431
0.138,6.987,0.063,2.638
0.141,7.197,0.239,2.768
0.103,5.209,0.009,1.956
0.052,2.621,0.009,0.986
0.098,4.943,0.009,1.856
0.208,10.5,0.009,3.94
0.16,8.081,0.009,3.033
0.143,7.245,0.01,2.72
0.077,3.907,0.06,1.483
0.043,2.167,0.009,0.815
0.079,4.006,0.064,1.521
0.091,4.588,0.009,1.723
0.03,1.517,0.009,0.572
0.041,2.08,0.009,0.783
0.061,3.108,0.026,1.173
0.064,3.246,0.009,1.22
0.063,3.172,0.009,1.192
0.131,6.613,0.03,2.488
0.133,6.721,0.036,2.531
______________________________________________
R-help@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.

Reply via email to