[R] Regression and data types
Daniel Malter
daniel at umd.edu
Fri Sep 26 18:55:20 CEST 2008
check
is(X1)
is(X2)
to investigate whether the types of the variables are equal. Probably (most
probably), X2 is a factor (treated as dummy variables) so that your 60
values from the second regression are the intercept (i.e. the coefficient
for the first observation) plus 59 dummies for the offset difference between
each of the 59 observations and the first observation.
run:
summary(lm(Y~X1))
summary(lm(Y~X2))
and you will see from the regression output that the second regression is
estimated with dummies for X2 rather than treating X2 as a numeric variable.
Transform X2 to numeric by:
X3=as.numeric(X2)
and check whether the values are otherwise equal to X2.
cbind(X2,X3)
If that's the case, rerun your analysis
summary(lm(Y~X3))
and you will only get one intercept and a slope coefficient.
Cheers,
Daniel
-------------------------
cuncta stricte discussurus
-------------------------
-----Ursprüngliche Nachricht-----
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
Auftrag von GRANT Lewis
Gesendet: Friday, September 26, 2008 8:18 AM
An: r-help at r-project.org
Betreff: [R] Regression and data types
Dear All
I have three data sets, X1, X2 and Y. X1 is data, X2 and Y were generated in
(different) R programs. All three vectors have one column of 60 data points.
I am using the code lm(Y~X1)$coef and lm(Y~X2)$coef. The first returns two
values, an intercept and a slope, but the second returns 60 values.
I suspect there is something in the "type" of X2 such that it forces the
regression to do something different, but I can't work this out.
Please help!
Lewis
**********************************************************************
Hermes Fund Managers Limited
Registered in England No. 1661776, Lloyds Chambers, 1 Portsoken Street,
London E1 8HZ
*** Please read the Hermes email disclaimer at
http://www.hermes.co.uk/email_terms.htm before acting on this email or
opening any attachment ***
The contents of this email are confidential. If you hav...{{dropped:28}}
More information about the R-help
mailing list