[R] regression with replication
Agus Susanto
gusanto at gmail.com
Mon Jul 13 21:56:18 CEST 2009
Dear all,
I would like to fit a linear regression with replication (on each year,
observation is replicated, e.g 4 times). The independent variable ranges
for instance 1-5 year, so I expect to have a linear fit of 5 points.
For that purpose I do these (with dummy variables x and y):
x<-rep(seq(1:5),4)
y<-rnorm(20)
linreg<-lm(y~x)
fitted.values(linreg) # why produce 20 points of estimate?
predict(linreg) # why produce 20 points of estimate?
Please somebody explain:
1. why both fitted.values and predict functions produced 20 points of
estimate, NOT 5 points.
2. is "lm(y~x)" correct to solve this regression case, or there's a
correct procedure.
Many thanks.
More information about the R-help
mailing list