Automate script to run linear regression R

大憨熊 提交于 2019-12-20 07:35:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!