问题
I am looking to run Linear Regression on the below data frame.
test<-data.frame(abc=c(2.4,3.2,8.9,9.8,10.0,3.2,5.4),
city1_0=c(5.3,2.6,3,5.4,7.8,4.4,5.5),
city1_1=c(2.3,5.6,3,2.4,3.6,2.4,6.5),
city1_2=c(4.2,1.4,2.6,2,6,3.6,2.4),
city1_3=c(2.4,2.6,9.4,4.6,2.5,1.2,7.5),
city1_4=c(8.2,4.2,7.6,3.4,1.7,5.2,9.7),
city2_0=c(4.3,8.6,6,3.7,7.8,4.7,5.8), city2_1=c(5.3,2.6,3,5.4,7.8,4.4,5.5))
Dataframe "test" is sample of the data. But original data frame contains 100 columns. I want to create a script for predicting values using linear regression. In this case, I want to build many models with different input variables.
For example, in the given dataframe, abc is the y variable. I want to build one model city1_1,city1_2,city1_3,city1_4 (leaving city1_0, city2_0). Then other model with city1_2,city1_3,city1_4 (leaving city1_0,city1_1,city2_0,city2_1) and then 3rd model with input variable city1_3,city1_4 (leaving city1_0,city1_1,city1_2,city2_0,city2_1), and so on.
These all variables are input to the Linear Regression.
This I have to do for 40 dataframes. O/P variable name remains same for every dataframe.
来源:https://stackoverflow.com/questions/45682233/automate-script-to-run-linear-regression-r