I have a question regarding application of model coefficients between
datasets. In particular, I have several datasets which I would like to apply
a model estimated from only a single dataset (sort of a crude - out of sample
application - to show the variances).
lets say,
names(a)
[1] "stdnoi" "momentum" "tbm3"
"metcons" "premium" "STDrfa" "t10"
"Y"
attach(a)
mymodel <- lm(Y ~ stdnoi+momentum+tbm3+metcons+premium+ STDrfa + t10)
detach(a)
load('b')
names(b)
[1] "stdnoi" "momentum" "tbm3"
"metcons" "premium" "STDrfa" "t10"
"Y"
attach(b)
b$hat <- predict(mymodel)
The question really is, is b$hat properly defined in terms of (a)coefficients
* (b)variables?
I have attempted this, and was surprised to see b$hat of the appropriate
length for the a dataset - but not the b (which is much larger)
Obviously I could save out the coefficients, but there are actually several
such models and datasets. Besides, I am generally curious if model objects
can be used in such a manner.
========================================Michaell Taylor, PhD
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Michaell Taylor <pols1oh at bestweb.net> writes:> I have a question regarding application of model coefficients between > datasets. In particular, I have several datasets which I would like to apply > a model estimated from only a single dataset (sort of a crude - out of sample > application - to show the variances). > > lets say, > names(a) > [1] "stdnoi" "momentum" "tbm3" "metcons" "premium" "STDrfa" "t10" > "Y" > attach(a) > mymodel <- lm(Y ~ stdnoi+momentum+tbm3+metcons+premium+ STDrfa + t10) > detach(a) > load('b') > names(b) > [1] "stdnoi" "momentum" "tbm3" "metcons" "premium" "STDrfa" "t10" > "Y" > attach(b) > b$hat <- predict(mymodel) > > The question really is, is b$hat properly defined in terms of (a)coefficients > * (b)variables? > > I have attempted this, and was surprised to see b$hat of the appropriate > length for the a dataset - but not the b (which is much larger) > > Obviously I could save out the coefficients, but there are actually several > such models and datasets. Besides, I am generally curious if model objects > can be used in such a manner.A fitted model embodies the data on which it was fitted, so predict(mymodel) gives you the fitted values on your a data frame whether you detach it or not. To predict on a new data frame use the `newdata' argument, as in predict(myplot, newdata=b). You can use help(predict.lm) to learn about this and more. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi, I am a novice to R and have a question here. Is it possible to read a single line from a file into a vector or list etc? If so, is it possible to read comma separated values? Eg: 1000,x,y,z 1001,s,d,f How do I read the first line only i.e. 1000,x,y,z from the file and that too so that I get separate storage for 1000, x, y and z? Thanks in advance. Saket. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._