简体   繁体   中英

calculating y_pred in least square regression (R)?

I'm having trouble calculating the y_pred in the least square regression. The idea is something like:

mydata <- read.csv("G:\\sample.csv",header=T)
x<-rep(mydata$wavelength,each=119)
y<-c(mydata$v1,....mydata$v119)
lm(y~x)

A sample data can be download at: https://drive.google.com/file/d/0B86_a8ltyoL3Y3BhU2xFVVo5dnM/view?usp=sharing

In the file, variable "Wavelength" is x, where for each x, there are multiple y measured at different times, as indicated by variables V1 to V119.

I'm not sure the y(multiple)~x(one) regression... Can someone help out to calculate y_pred in this case?

Big thanks!

I think what you want to do is just

mydata <- read.csv("G:\\sample.csv",header=T)
lm(Wavelength ~ ., data = mydata)

This does a regression of Wavelength against all of the other columns in your dataframe.

In your call to

x<-rep(mydata$wavelength,each=119)

x ends up null. You need to capitalize Wavelength .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM