Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 回归,数据集中所有变量的列表_R_List_Regression_Stata - Fatal编程技术网

R 回归,数据集中所有变量的列表

R 回归,数据集中所有变量的列表,r,list,regression,stata,R,List,Regression,Stata,有吗 在R中有没有一种简单或不那么简单的方法来创建 数据集中所有变量的列表 我想循环我的变量,回归到另一个变量上,这样我就可以在关于自变量的假设下预测每个变量的值 在斯塔塔,这看起来像 foreach v of var a b c { qui regress `v' i di "`v' {col 2O}" _b[`i'] * 42 } 42 is an arbitrary number 例如,如果我有三个变量a、b和c,还有另一个独立变量 变量i,我想回归a i,回归

有吗 在R中有没有一种简单或不那么简单的方法来创建 数据集中所有变量的列表

我想循环我的变量,回归到另一个变量上,这样我就可以在关于自变量的假设下预测每个变量的值

在斯塔塔,这看起来像

foreach v of var a b c { 
    qui regress `v' i 
    di "`v' {col 2O}" _b[`i'] * 42 
} 

42 is an arbitrary number
例如,如果我有三个变量a、b和c,还有另一个独立变量 变量i,我想回归a i,回归b i,回归c i和之后 每次回归都取coef并将其乘以i值,以预测 结果

问题是我有一个未知数量的变量 希望能够获取完整的列表并在其中循环

我的数据结构

structure(list(serial = c(19160206, 19160202, 19160203, 32051017, 
32051017), strata = structure(c(347, 347, 347, 244, 244), label = "Strata", class = c("labelled", 
"numeric")), psu = structure(c(553, 553, 553, 822, 822), label = "Primary sampling unit", class = c("labelled", 
"numeric")), pnum = c(1, 3, 2, 5, 6), DMFlag = structure(c(1, 
4, 3, 3, 3), label = "Final case status flag  (IND)", class = c("labelled", 
"numeric")), HhOut = structure(c(110, 210, 110, 110, 110), label = "Final outcome - household", class = c("labelled", 
"numeric")), IndOut = structure(c(11, 43, 11, 11, 11), label = "Final outcome - individual", class = c("labelled", 
"numeric")), ind_wt = c(0.783649023617231, NA, 0.677951319403552, 
NA, NA), IMonth = structure(c(2, 4, 2, 10, 10), label = "Interview month", class = c("labelled", 
"numeric")), IYear = structure(c(2015, 2015, 2015, 2015, 2015
), label = "Interview Year", class = c("labelled", "numeric")), 
    DMSex = structure(c(2, 1, 1, NA, NA), label = "Gender from household grid", class = c("labelled", 
    "numeric")), DM014 = structure(c(0, 1, 2, NA, NA), label = "Number of children aged 0-14", class = c("labelled", 
    "numeric")), DM016 = structure(c(0, 1, 2, NA, NA), label = "Number of children aged 0-16", class = c("labelled", 
    "numeric")), DM510 = structure(c(0, 0, 1, NA, NA), label = "Number of children aged 5-10", class = c("labelled", 
    "numeric")), DM1115 = structure(c(0, 1, 1, NA, NA), label = "Number of children aged 11-15", class = c("labelled", 
    "numeric")), DM1619 = structure(c(0, 0, 0, NA, NA), label = "Number of children aged 16-19", class = c("labelled", 
    "numeric")), WorkSta = structure(c(4, -1, -1, NA, NA), label = "Economic activity status", class = c("labelled", 
    "numeric")), act1_1 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 04:00-04:10", class = c("labelled", 
    "numeric")), act1_2 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 04:10-04:20", class = c("labelled", 
    "numeric")), act1_3 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 04:20-04:30", class = c("labelled", 
    "numeric")), act1_4 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 04:30-04:40", class = c("labelled", 
    "numeric")), act1_5 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 04:40-04:50", class = c("labelled", 
    "numeric")), act1_6 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 04:50-05:00", class = c("labelled", 
    "numeric")), act1_7 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 05:00-05:10", class = c("labelled", 
    "numeric")), act1_8 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 05:10-05:20", class = c("labelled", 
    "numeric")), act1_9 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 05:20-05:30", class = c("labelled", 
    "numeric")), act1_10 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 05:30-05:40", class = c("labelled", 
    "numeric")), act1_11 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 05:40-05:50", class = c("labelled", 
    "numeric")), act1_12 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 05:50-06:00", class = c("labelled", 
    "numeric")), act1_13 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 06:00-06:10", class = c("labelled", 
    "numeric")), act1_14 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 06:10-06:20", class = c("labelled", 
    "numeric")), act1_15 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 06:20-06:30", class = c("labelled", 
    "numeric")), act1_16 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 06:30-06:40", class = c("labelled", 
    "numeric")), act1_17 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 06:40-06:50", class = c("labelled", 
    "numeric")), act1_18 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 06:50-07:00", class = c("labelled", 
    "numeric")), act1_19 = structure(c(110, 110, 110, 111, 110
    ), label = "Primary activity: 07:00-07:10", class = c("labelled", 
    "numeric")), act1_20 = structure(c(110, 110, 110, 111, 110
    ), label = "Primary activity: 07:10-07:20", class = c("labelled", 
    "numeric")), act1_21 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 07:20-07:30", class = c("labelled", 
    "numeric")), act1_22 = structure(c(110, 110, 110, 111, 110
    ), label = "Primary activity: 07:30-07:40", class = c("labelled", 
    "numeric")), act1_23 = structure(c(110, 110, 110, 111, 110
    ), label = "Primary activity: 07:40-07:50", class = c("labelled", 
    "numeric")), act1_24 = structure(c(110, 110, 110, 310, 110
    ), label = "Primary activity: 07:50-08:00", class = c("labelled", 
    "numeric")), act1_25 = structure(c(110, 110, 110, 3110, 111
    ), label = "Primary activity: 08:00-08:10", class = c("labelled", 
    "numeric")), act1_26 = structure(c(110, 110, 110, 310, 210
    ), label = "Primary activity: 08:10-08:20", class = c("labelled", 
    "numeric")), act1_27 = structure(c(110, 110, 110, 310, 3130
    ), label = "Primary activity: 08:20-08:30", class = c("labelled", 
    "numeric")), act1_28 = structure(c(310, 110, 110, 310, 310
    ), label = "Primary activity: 08:30-08:40", class = c("labelled", 
    "numeric")), act1_29 = structure(c(310, 110, 110, 9610, 9610
    ), label = "Primary activity: 08:40-08:50", class = c("labelled", 
    "numeric")), act1_30 = structure(c(7330, 110, 110, 6190, 
    6190), label = "Primary activity: 08:50-09:00", class = c("labelled", 
    "numeric")), act1_31 = structure(c(8210, 110, 110, 6190, 
    6190), label = "Primary activity: 09:00-09:10", class = c("labelled", 
    "numeric")), act1_32 = structure(c(8210, 110, 110, 6190, 
    6190), label = "Primary activity: 09:10-09:20", class = c("labelled", 
    "numeric")), act1_33 = structure(c(8210, 310, 110, 6190, 
    6190), label = "Primary activity: 09:20-09:30", class = c("labelled", 
    "numeric")), act1_34 = structure(c(8210, 310, 310, 6190, 
    6190), label = "Primary activity: 09:30-09:40", class = c("labelled", 
    "numeric")), act1_35 = structure(c(8210, 5110, 210, 6190, 
    6190), label = "Primary activity: 09:40-09:50", class = c("labelled", 
    "numeric")), act1_36 = structure(c(8210, 5110, 310, 6190, 
    6190), label = "Primary activity: 09:50-10:00", class = c("labelled", 
    "numeric")), act1_37 = structure(c(8210, 5110, 7330, 6190, 
    6190), label = "Primary activity: 10:00-10:10", class = c("labelled", 
    "numeric")), act1_38 = structure(c(8210, 9510, 7330, 6190, 
    6190), label = "Primary activity: 10:10-10:20", class = c("labelled", 
    "numeric")), act1_39 = structure(c(8210, 9510, 7330, 6190, 
    6190), label = "Primary activity: 10:20-10:30", class = c("labelled", 
    "numeric")), act1_40 = structure(c(8210, 3611, 7330, 6190, 
    6190), label = "Primary activity: 10:30-10:40", class = c("labelled", 
    "numeric")), act1_41 = structure(c(8210, 210, 7330, 9610, 
    6190), label = "Primary activity: 10:40-10:50", class = c("labelled", 
    "numeric")), act1_42 = structure(c(8210, 210, 7330, 6190, 
    6190), label = "Primary activity: 10:50-11:00", class = c("labelled", 
    "numeric")), act1_43 = structure(c(8210, 9510, 7330, 6190, 
    9610), label = "Primary activity: 11:00-11:10", class = c("labelled", 
    "numeric")), act1_44 = structure(c(8210, 9510, 7330, 6190, 
    6190), label = "Primary activity: 11:10-11:20", class = c("labelled", 
    "numeric")), act1_45 = structure(c(8210, 3290, 8210, 6190, 
    6190), label = "Primary activity: 11:20-11:30", class = c("labelled", 
    "numeric")), act1_46 = structure(c(3240, 3210, 8210, 6190, 
    6190), label = "Primary activity: 11:30-11:40", class = c("labelled", 
    "numeric")), act1_47 = structure(c(3240, 3210, 8210, 6190, 
    6190), label = "Primary activity: 11:40-11:50", class = c("labelled", 
    "numeric")), act1_48 = structure(c(3210, 3210, 8210, 6190, 
    6150), label = "Primary activity: 11:50-12:00", class = c("labelled", 
    "numeric")), act1_49 = structure(c(3210, 3210, 8210, 6190, 
    6150), label = "Primary activity: 12:00-12:10", class = c("labelled", 
    "numeric")), act1_50 = structure(c(8210, 3210, 9370, 5310, 
    6150), label = "Primary activity: 12:10-12:20", class = c("labelled", 
    "numeric")), act1_51 = structure(c(8210, 3210, 9370, 5310, 
    6150), label = "Primary activity: 12:20-12:30", class = c("labelled", 
    "numeric")), act1_52 = structure(c(8210, 5140, 9370, 5310, 
    9610), label = "Primary activity: 12:30-12:40", class = c("labelled", 
    "numeric")), act1_53 = structure(c(8210, 3210, 9370, 5310, 
    3290), label = "Primary activity: 12:40-12:50", class = c("labelled", 
    "numeric")), act1_54 = structure(c(8210, 3210, 9370, 5310, 
    5140), label = "Primary activity: 12:50-13:00", class = c("labelled", 
    "numeric")), act1_55 = structure(c(8210, 3210, 5190, 5310, 
    310), label = "Primary activity: 13:00-13:10", class = c("labelled", 
    "numeric")), act1_56 = structure(c(8210, 3210, 3630, 5310, 
    310), label = "Primary activity: 13:10-13:20", class = c("labelled", 
    "numeric")), act1_57 = structure(c(8210, 5120, 3630, 5310, 
    6311), label = "Primary activity: 13:20-13:30", class = c("labelled", 
    "numeric")), act1_58 = structure(c(8210, 9500, 3630, 6150, 
    5120), label = "Primary activity: 13:30-13:40", class = c("labelled", 
    "numeric")), act1_59 = structure(c(8210, 3290, 5190, 6150, 
    9510), label = "Primary activity: 13:40-13:50", class = c("labelled", 
    "numeric")), act1_60 = structure(c(8210, 210, 6110, 6150, 
    5130), label = "Primary activity: 13:50-14:00", class = c("labelled", 
    "numeric")), act1_61 = structure(c(8210, 210, 6110, 6150, 
    6190), label = "Primary activity: 14:00-14:10", class = c("labelled", 
    "numeric")), act1_62 = structure(c(8210, 5120, 6110, 9610, 
    6190), label = "Primary activity: 14:10-14:20", class = c("labelled", 
    "numeric")), act1_63 = structure(c(8210, 5120, 6110, 3110, 
    6190), label = "Primary activity: 14:20-14:30", class = c("labelled", 
    "numeric")), act1_64 = structure(c(9500, 5120, 6110, 8210, 
    5310), label = "Primary activity: 14:30-14:40", class = c("labelled", 
    "numeric")), act1_65 = structure(c(9500, 5120, 6110, 310, 
    5310), label = "Primary activity: 14:40-14:50", class = c("labelled", 
    "numeric")), act1_66 = structure(c(9990, 9360, 6110, 310, 
    5310), label = "Primary activity: 14:50-15:00", class = c("labelled", 
    "numeric")), act1_67 = structure(c(8210, 9360, 6110, 210, 
    6190), label = "Primary activity: 15:00-15:10", class = c("labelled", 
    "numeric")), act1_68 = structure(c(8210, 9360, 6110, 9610, 
    6190), label = "Primary activity: 15:10-15:20", class = c("labelled", 
    "numeric")), act1_69 = structure(c(8210, 3610, 6110, 6171, 
    6190), label = "Primary activity: 15:20-15:30", class = c("labelled", 
    "numeric")), act1_70 = structure(c(8210, 3610, 6110, 6171, 
    210), label = "Primary activity: 15:30-15:40", class = c("labelled", 
    "numeric")), act1_71 = structure(c(8210, 3610, 6110, 6171, 
    210), label = "Primary activity: 15:40-15:50", class = c("labelled", 
    "numeric")), act1_72 = structure(c(8210, 3610, 6110, 6171, 
    6190), label = "Primary activity: 15:50-16:00", class = c("labelled", 
    "numeric")), act1_73 = structure(c(7330, 3610, 6110, 6171, 
    6190), label = "Primary activity: 16:00-16:10", class = c("labelled", 
    "numeric")), act1_74 = structure(c(7330, 3610, 6110, 6171, 
    6190), label = "Primary activity: 16:10-16:20", class = c("labelled", 
    "numeric")), act1_75 = structure(c(7330, 3610, 6110, 6171, 
    5310), label = "Primary activity: 16:20-16:30", class = c("labelled", 
    "numeric")), act1_76 = structure(c(7330, 3610, 6110, 310, 
    9510), label = "Primary activity: 16:30-16:40", class = c("labelled", 
    "numeric")), act1_77 = structure(c(7330, 3610, 6110, 310, 
    9510), label = "Primary activity: 16:40-16:50", class = c("labelled", 
    "numeric")), act1_78 = structure(c(8210, 3610, 9500, 310, 
    9510), label = "Primary activity: 16:50-17:00", class = c("labelled", 
    "numeric")), act1_79 = structure(c(8210, 3610, 9500, 310, 
    7241), label = "Primary activity: 17:00-17:10", class = c("labelled", 
    "numeric")), act1_80 = structure(c(8210, 3610, 3611, 3611, 
    7241), label = "Primary activity: 17:10-17:20", class = c("labelled", 
    "numeric")), act1_81 = structure(c(210, 9360, 5310, 9500, 
    8210), label = "Primary activity: 17:20-17:30", class = c("labelled", 
    "numeric")), act1_82 = structure(c(210, 9360, 210, 4230, 
    8210), label = "Primary activity: 17:30-17:40", class = c("labelled", 
    "numeric")), act1_83 = structure(c(210, 9360, 210, 4230, 
    8210), label = "Primary activity: 17:40-17:50", class = c("labelled", 
    "numeric")), act1_84 = structure(c(7330, 9360, 9520, 4230, 
    8210), label = "Primary activity: 17:50-18:00", class = c("labelled", 
    "numeric")), act1_85 = structure(c(7330, 9360, 3290, 4230, 
    8210), label = "Primary activity: 18:00-18:10", class = c("labelled", 
    "numeric")), act1_86 = structure(c(7330, 4220, 5310, 4230, 
    8210), label = "Primary activity: 18:10-18:20", class = c("labelled", 
    "numeric")), act1_87 = structure(c(7330, 4220, 5310, 8219, 
    3210), label = "Primary activity: 18:20-18:30", class = c("labelled", 
    "numeric")), act1_88 = structure(c(8210, 5310, 5310, 8219, 
    3210), label = "Primary activity: 18:30-18:40", class = c("labelled", 
    "numeric")), act1_89 = structure(c(8210, 5310, 5310, 8219, 
    3210), label = "Primary activity: 18:40-18:50", class = c("labelled", 
    "numeric")), act1_90 = structure(c(8210, 5100, 5310, 8219, 
    3210), label = "Primary activity: 18:50-19:00", class = c("labelled", 
    "numeric")), act1_91 = structure(c(8210, 5120, 7330, 8219, 
    5140), label = "Primary activity: 19:00-19:10", class = c("labelled", 
    "numeric")), act1_92 = structure(c(8210, 5120, 7330, 8219, 
    5140), label = "Primary activity: 19:10-19:20", class = c("labelled", 
    "numeric")), act1_93 = structure(c(8210, 5120, 7330, 8219, 
    5140), label = "Primary activity: 19:20-19:30", class = c("labelled", 
    "numeric")), act1_94 = structure(c(8210, 9360, 7330, 8219, 
    210), label = "Primary activity: 19:30-19:40", class = c("labelled", 
    "numeric")), act1_95 = structure(c(8210, 3610, 7330, 8219, 
    210), label = "Primary activity: 19:40-19:50", class = c("labelled", 
    "numeric")), act1_96 = structure(c(8210, 9360, 7330, 8219, 
    210), label = "Primary activity: 19:50-20:00", class = c("labelled", 
    "numeric")), act1_97 = structure(c(8210, 3290, 7330, 8219, 
    210), label = "Primary activity: 20:00-20:10", class = c("labelled", 
    "numeric")), act1_98 = structure(c(8210, 5310, 7330, 8219, 
    8210), label = "Primary activity: 20:10-20:20", class = c("labelled", 
    "numeric")), act1_99 = structure(c(310, 210, 7330, 8219, 
    8210), label = "Primary activity: 20:20-20:30", class = c("labelled", 
    "numeric")), act1_100 = structure(c(310, 210, 7330, 9500, 
    8210), label = "Primary activity: 20:30-20:40", class = c("labelled", 
    "numeric")), act1_101 = structure(c(111, 3110, 7330, 8219, 
    8210), label = "Primary activity: 20:40-20:50", class = c("labelled", 
    "numeric")), act1_102 = structure(c(111, 3110, 7330, 8219, 
    8210), label = "Primary activity: 20:50-21:00", class = c("labelled", 
    "numeric")), act1_103 = structure(c(111, 210, 7330, 8219, 
    8210), label = "Primary activity: 21:00-21:10", class = c("labelled", 
    "numeric")), act1_104 = structure(c(110, 210, 7330, 8219, 
    8210), label = "Primary activity: 21:10-21:20", class = c("labelled", 
    "numeric")), act1_105 = structure(c(110, 8210, 7330, 8219, 
    8210), label = "Primary activity: 21:20-21:30", class = c("labelled", 
    "numeric")), act1_106 = structure(c(110, 8210, 7330, 8219, 
    8210), label = "Primary activity: 21:30-21:40", class = c("labelled", 
    "numeric")), act1_107 = structure(c(110, 8210, 7330, 8219, 
    8210), label = "Primary activity: 21:40-21:50", class = c("labelled", 
    "numeric")), act1_108 = structure(c(110, 8210, 7330, 8219, 
    8210), label = "Primary activity: 21:50-22:00", class = c("labelled", 
    "numeric")), act1_109 = structure(c(110, 8210, 7330, 310, 
    310), label = "Primary activity: 22:00-22:10", class = c("labelled", 
    "numeric")), act1_110 = structure(c(110, 8210, 7330, 310, 
    310), label = "Primary activity: 22:10-22:20", class = c("labelled", 
    "numeric")), act1_111 = structure(c(110, 8210, 7330, 111, 
    310), label = "Primary activity: 22:20-22:30", class = c("labelled", 
    "numeric")), act1_112 = structure(c(110, 8210, 7330, 111, 
    310), label = "Primary activity: 22:30-22:40", class = c("labelled", 
    "numeric")), act1_113 = structure(c(110, 8210, 7330, 110, 
    310), label = "Primary activity: 22:40-22:50", class = c("labelled", 
    "numeric")), act1_114 = structure(c(110, 8210, 7330, 110, 
    110), label = "Primary activity: 22:50-23:00", class = c("labelled", 
    "numeric")), act1_115 = structure(c(110, 8210, 8210, 110, 
    110), label = "Primary activity: 23:00-23:10", class = c("labelled", 
    "numeric")), act1_116 = structure(c(110, 8210, 8210, 110, 
    110), label = "Primary activity: 23:10-23:20", class = c("labelled", 
    "numeric")), act1_117 = structure(c(110, 8210, 8210, 110, 
    110), label = "Primary activity: 23:20-23:30", class = c("labelled", 
    "numeric")), act1_118 = structure(c(110, 8210, 8210, 110, 
    110), label = "Primary activity: 23:30-23:40", class = c("labelled", 
    "numeric")), act1_119 = structure(c(110, 8210, 110, 110, 
    110), label = "Primary activity: 23:40-23:50", class = c("labelled", 
    "numeric")), act1_120 = structure(c(110, 310, 110, 110, 110
    ), label = "Primary activity: 23:50-00:00", class = c("labelled", 
    "numeric")), act1_121 = structure(c(110, 310, 110, 110, 110
    ), label = "Primary activity: 00:00-00:10", class = c("labelled", 
    "numeric")), act1_122 = structure(c(110, 8120, 110, 110, 
    110), label = "Primary activity: 00:10-00:20", class = c("labelled", 
    "numeric")), act1_123 = structure(c(110, 8120, 110, 110, 
    110), label = "Primary activity: 00:20-00:30", class = c("labelled", 
    "numeric")), act1_124 = structure(c(110, 8120, 110, 110, 
    110), label = "Primary activity: 00:30-00:40", class = c("labelled", 
    "numeric")), act1_125 = structure(c(110, 8120, 110, 110, 
    110), label = "Primary activity: 00:40-00:50", class = c("labelled", 
    "numeric")), act1_126 = structure(c(110, 8120, 110, 110, 
    110), label = "Primary activity: 00:50-01:00", class = c("labelled", 
    "numeric")), act1_127 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 01:00-01:10", class = c("labelled", 
    "numeric")), act1_128 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 01:10-01:20", class = c("labelled", 
    "numeric")), act1_129 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 01:20-01:30", class = c("labelled", 
    "numeric")), act1_130 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 01:30-01:40", class = c("labelled", 
    "numeric")), act1_131 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 01:40-01:50", class = c("labelled", 
    "numeric")), act1_132 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 01:50-02:00", class = c("labelled", 
    "numeric")), act1_133 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 02:00-02:10", class = c("labelled", 
    "numeric")), act1_134 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 02:10-02:20", class = c("labelled", 
    "numeric")), act1_135 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 02:20-02:30", class = c("labelled", 
    "numeric")), act1_136 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 02:30-02:40", class = c("labelled", 
    "numeric")), act1_137 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 02:40-02:50", class = c("labelled", 
    "numeric")), act1_138 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 02:50-03:00", class = c("labelled", 
    "numeric")), act1_139 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 03:00-03:10", class = c("labelled", 
    "numeric")), act1_140 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 03:10-03:20", class = c("labelled", 
    "numeric")), act1_141 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 03:20-03:30", class = c("labelled", 
    "numeric")), act1_142 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 03:30-03:40", class = c("labelled", 
    "numeric")), act1_143 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 03:40-03:50", class = c("labelled", 
    "numeric")), act1_144 = structure(c(110, 110, 110, 110, 110
    ), label = "Primary activity: 03:50-04:00", class = c("labelled", 
    "numeric"))), .Names = c("serial", "strata", "psu", "pnum", 
"DMFlag", "HhOut", "IndOut", "ind_wt", "IMonth", "IYear", "DMSex", 
"DM014", "DM016", "DM510", "DM1115", "DM1619", "WorkSta", "act1_1", 
"act1_2", "act1_3", "act1_4", "act1_5", "act1_6", "act1_7", "act1_8", 
"act1_9", "act1_10", "act1_11", "act1_12", "act1_13", "act1_14", 
"act1_15", "act1_16", "act1_17", "act1_18", "act1_19", "act1_20", 
"act1_21", "act1_22", "act1_23", "act1_24", "act1_25", "act1_26", 
"act1_27", "act1_28", "act1_29", "act1_30", "act1_31", "act1_32", 
"act1_33", "act1_34", "act1_35", "act1_36", "act1_37", "act1_38", 
"act1_39", "act1_40", "act1_41", "act1_42", "act1_43", "act1_44", 
"act1_45", "act1_46", "act1_47", "act1_48", "act1_49", "act1_50", 
"act1_51", "act1_52", "act1_53", "act1_54", "act1_55", "act1_56", 
"act1_57", "act1_58", "act1_59", "act1_60", "act1_61", "act1_62", 
"act1_63", "act1_64", "act1_65", "act1_66", "act1_67", "act1_68", 
"act1_69", "act1_70", "act1_71", "act1_72", "act1_73", "act1_74", 
"act1_75", "act1_76", "act1_77", "act1_78", "act1_79", "act1_80", 
"act1_81", "act1_82", "act1_83", "act1_84", "act1_85", "act1_86", 
"act1_87", "act1_88", "act1_89", "act1_90", "act1_91", "act1_92", 
"act1_93", "act1_94", "act1_95", "act1_96", "act1_97", "act1_98", 
"act1_99", "act1_100", "act1_101", "act1_102", "act1_103", "act1_104", 
"act1_105", "act1_106", "act1_107", "act1_108", "act1_109", "act1_110", 
"act1_111", "act1_112", "act1_113", "act1_114", "act1_115", "act1_116", 
"act1_117", "act1_118", "act1_119", "act1_120", "act1_121", "act1_122", 
"act1_123", "act1_124", "act1_125", "act1_126", "act1_127", "act1_128", 
"act1_129", "act1_130", "act1_131", "act1_132", "act1_133", "act1_134", 
"act1_135", "act1_136", "act1_137", "act1_138", "act1_139", "act1_140", 
"act1_141", "act1_142", "act1_143", "act1_144"), row.names = c(NA, 
5L), class = "data.frame")

下面是一个不雅观但有效的方法。首先,由于您的数据看起来比理解此方法的要点所需的数据要混乱一些:我创建了一个玩具示例数据集:

设定种子的重复性 第123集 创建我们的变量 我 >电话: >lmformula=as.formulapaste0j,~i,data=dataset > >残差: >最小1季度中值3季度最大值 > -1.6085 -0.5056 -0.2152 0.6932 2.0118 > >系数: >估计标准误差t值Pr>t >截距0.1720 0.1534 1.121 0.272 >i 4.8660 0.1589 30.629-- >签名。代码:0'***'0.001'***'0.01'*'0.05'.'0.1''1 > >剩余标准误差:28个自由度上的0.8393 >倍数R平方:0.971,调整后的R平方:0.97 >F-统计量:1和28 DF上为938.1,p值:<2.2e-16 > >电话: >lmformula=as.formulapaste0j,~i,data=dataset > >残差: >最小1季度中值3季度最大值 > -2.39301 -0.56909 0.03468 0.51764 2.08387 > >系数: >估计标准误差t值Pr>t >截距0.0313 0.1596 0.196 0.846 >i-1.8540 0.1653-11.2187.18e-12*** > -- >签名。代码:0'***'0.001'***'0.01'*'0.05'.'0.1''1 > >剩余标准误差:28个自由度上的0.8731 >倍数R平方:0.818,调整后的R平方:0.8115 >F-统计量:1和28 DF上的125.8,p-值:7.177e-12 > >电话: >lmformula=as.formulapaste0j,~i,data=dataset > >残差: >最小1季度中值3季度最大值 > -1.4989 -0.6435 -0.1436 0.5917 2.2613 > >系数: >估计标准误差t值Pr>| t| >截距-0.09205 0.16855-0.546 0.589 >i 0.03914 0.17454 0.224 0.824 > >剩余标准误差:28个自由度上的0.9221 >多重R平方:0.001793,调整后的R平方:-0.03386 >F统计:1和28 DF上的0.05029,p值:0.8242 你的预测呢 lapplymodels,functionmodel{ predictmodel,newdata=data.framei=42 } > [[1]] > 1 > 204.5426 > > [[2]] > 1 > -77.8355 > > [[3]] > 1 > 1.551869 由v0.2.1于2019-02-08创建

您应该注意到,这种方法与如何为解释变量模拟Stata宏的相关问题非常相似。主要的区别,也是为什么我觉得你的问题应该有一个单独的答案,是因为你有多个DV,你需要多次运行lm,这在某种程度上改变了方法。在这个问题上,在一个lm调用中使用as.formula和paste就足够了,即lmas.formulapasteincome~,pasterregistors,collapse=+,data=Duncan,这里我们需要在循环或*apply调用中使用这种方法,即lapplyDVnames,functionj{lmas.formulapaste0j,~i,data=dataset}。然后我们还需要使用*apply函数来进行所需的预测