[R] linear model with similar response predictor
David Winsemius
dwinsemius at comcast.net
Thu Aug 5 15:24:06 CEST 2010
On Aug 5, 2010, at 6:50 AM, Giuseppe Amatulli wrote:
> Hi,
> can somebody tell me why R is not able to calculate a linear model
> written in this way?
>
>> lm (seq(1:100)~seq(1:100))
>
> Call:
> lm(formula = seq(1:100) ~ seq(1:100))
>
> Coefficients:
> (Intercept)
> 50.5
>
> Warning messages:
> 1: In model.matrix.default(mt, mf, contrasts) :
> the response appeared on the right-hand side and was dropped
> 2: In model.matrix.default(mt, mf, contrasts) :
> problem with term 1 in model.matrix: no columns are assigned
>>
>
> Seems that is not able to dealing with similar number and so with very
> small numbers for calculating the coefficients. Moreover also
> Intercepts is wrong it should be equal to 0.
The group mean is correctly calculated.
>
> I compile the R 2.11.1 in the Fedora 13.
> Should i download a library?
That would not appear to be necessary:
> x= 1:100
> y=1:100
> lm(y~x)
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
-5.684e-14 1.000e+00
> Some configure options are missing during the installation? or is a
> bug?
Not sure. To determine that you would need to read the help page very
carefully and determine whether putting such raw expressions into a
location where formulas were generally used actually is allowed. A bit
of experimentation shows that it is probably the rhs logic (as was
also suggested by the warning message) where the issue arises.
> lm (seq(1:100)~., data=list(a=1:100))
Call:
lm(formula = seq(1:100) ~ ., data = list(a = 1:100))
Coefficients:
(Intercept) a
-5.684e-14 1.000e+00
Read the help page for formula and note the section regarding the I()
function:
> lm(seq(1:100)~I(seq(1:100)) )
Call:
lm(formula = seq(1:100) ~ I(seq(1:100)))
Coefficients:
(Intercept) I(seq(1:100))
-5.684e-14 1.000e+00
> Thanks in advance
> Giuseppe Amatulli
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list