将lm摘要输出导出到包括NA的数据框 [英] Exporting lm summary output to dataframe including NA

查看:128
本文介绍了将lm摘要输出导出到包括NA的数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将LM输出的系数(估计,t值等)提取到数据帧.我需要将所有回归输出的所有系数存储在数据框中,因为我有949个单独的输出.问题是某些输出包含许多变量的NA.当我导出这些摘要时,它会排除NA并仅输出具有真实值的变量.

I want to extract the coefficients (estimates, tvalues, etc) of LM ouputs to a dataframe. I need to store all coefficients in a dataframe for all regression outputs, since I have 949 separate outputs. The PROBLEM is that some of the outputs include NA's for a number of variables. When I export these summaries, it excludes the NA's and only outputs the variables that have true values.

由于我需要将所有值绑定到行中,因此我想保持所有估计的结构相同(并因此包括NA),否则列将不再与值匹配.

Since I need to bind all the values in rows, I want to maintain the same structure of all estimates (and so NA's included), otherwise the columns do not match the values anymore.

一个最小的工作示例:

   Call:
lm(formula = dy ~ ., data = x)

Residuals:
      Min        1Q    Median        3Q       Max 
-0.223091 -0.036780 -0.001159  0.039722  0.216093 

Coefficients: (8 not defined because of singularities)
                          Estimate Std. Error t value Pr(>|t|)    
(Intercept)              5.240e+00  1.192e+00   4.395 1.84e-05 ***
deltalnPrice            -4.385e-01  7.486e-02  -5.858 2.02e-08 ***
deltalnAdvertising              NA         NA      NA       NA    
deltalnDisplay           6.526e-03  2.701e-03   2.416 0.016643 *  
deltaIntrayearCycles    -3.591e-03  1.899e-02  -0.189 0.850257    
deltalnCompetitorPrices -1.149e+00  3.389e-01  -3.389 0.000852 ***
deltalnCompADV           3.107e-04  1.225e-03   0.254 0.800020    
deltalnCompDISP         -5.746e-03  3.405e-03  -1.688 0.093112 .  
deltaADVxDISP                   NA         NA      NA       NA    
deltaADVxCYC                    NA         NA      NA       NA    
deltaDISPxCYC           -3.156e-03  1.824e-03  -1.730 0.085186 .  
deltaADVxDISPxCYC               NA         NA      NA       NA    
lnPriceLag1              1.003e-01  1.060e-01   0.946 0.345190    
lnAdvertisingLag1               NA         NA      NA       NA    
lnDisplayLag1           -2.517e-05  2.917e-03  -0.009 0.993125    
IntrayearCyclesLag1      2.086e-03  7.750e-03   0.269 0.788068    
lnCompetitorPricesLag1  -1.509e-01  1.213e-01  -1.244 0.214992    
lnCompADVLag1            6.551e-04  1.331e-03   0.492 0.623267    
lnCompDISPLag1          -9.989e-03  4.112e-03  -2.430 0.016044 *  
ADVxDISPLag1                    NA         NA      NA       NA    
ADVxCYCLag1                     NA         NA      NA       NA    
DISPxCYCLag1            -1.590e-03  2.412e-03  -0.659 0.510408    
ADVxDISPxCYCLag1                NA         NA      NA       NA    
yLag1                   -3.964e-01  5.747e-02  -6.898 7.52e-11 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.07287 on 191 degrees of freedom
Multiple R-squared:  0.5067,    Adjusted R-squared:  0.468 
F-statistic: 13.08 on 15 and 191 DF,  p-value: < 2.2e-16

structure(list(call = lm(formula = dy ~ ., data = x), terms = dy ~ 
    deltalnPrice + deltalnAdvertising + deltalnDisplay + deltaIntrayearCycles + 
        deltalnCompetitorPrices + deltalnCompADV + deltalnCompDISP + 
        deltaADVxDISP + deltaADVxCYC + deltaDISPxCYC + deltaADVxDISPxCYC + 
        lnPriceLag1 + lnAdvertisingLag1 + lnDisplayLag1 + IntrayearCyclesLag1 + 
        lnCompetitorPricesLag1 + lnCompADVLag1 + lnCompDISPLag1 + 
        ADVxDISPLag1 + ADVxCYCLag1 + DISPxCYCLag1 + ADVxDISPxCYCLag1 + 
        yLag1, residuals = structure(c(0.0313162134166014, 0.00182250788959792, 
0.0635208598048524, 0.0612908975008862, 0.0513116273377191, 0.0480400382837013, 
0.130856138226688, -0.033889496904378, 0.0360890625254884, 0.0247538185743874, 
0.0520942922109017, 0.0478879566090224, 0.0280982502090788, 0.0394289629925177, 
0.030488007828847, 0.0912434200828101, 0.00726172761242586, 0.0678286022801302, 
0.0209936612063826, 0.0848540529010701, -0.00623200646733687, 
0.144695840830401, -0.171621252461323, 0.0818278414589248, 0.0691074207713941, 
0.0400145073292064, 0.0329647062515553, 0.0016008839180754, -0.0011590503897594, 
0.0234782005341917, 0.135540225105302, 0.0777289259658255, -0.0139075363740098, 
0.00137800717667551, 0.077685204016761, 0.0847939376833802, -0.0457852901900442, 
0.120138029151051, -0.12288143285706, 0.0514138444613049, -0.0298487047114452, 
0.0812927463530368, -0.0512527609574749, -0.0148612205366606, 
0.148702325713941, -0.0632769330119765, 0.080265950544292, 0.00825895667573661, 
-0.00123002721170622, 0.00889855776217089, -0.0549650557207191, 
-0.0118897085783888, -0.0055668930751875, 0.00740080644326915, 
-0.0046694347432411, 0.0023987251577269, 0.0512930761571338, 
-0.00528879041821314, -0.00669890961807299, -0.0174279132848388, 
-0.031131219616994, -0.0320932220427221, -0.0335071040551344, 
0.018993724022006, 0.025375253974403, 0.0473556512378115, 0.0243142742474414, 
-0.00750807927659931, 0.0380387349431747, 0.00199467658996756, 
0.0922838084836681, 0.0334959944151696, 0.119412899344281, 0.202645091604003, 
-0.213809120540209, -0.0843989892923826, 0.0224200783175872, 
0.0226524657809046, 0.0308179543978849, 0.00282867040232589, 
0.0251545028103145, 0.0493167370039179, -0.0723142352179929, 
-0.0315452913913602, 0.0126202252665502, 0.025981914601845, -0.0166197765169785, 
-0.00645139264478737, 0.116803114677603, -0.163569543730366, 
0.0428844528909951, 0.0135975956514375, 0.0113040009144668, 0.052787491154424, 
-0.00463136954691906, 0.099934796138239, -0.109334385536971, 
0.00162237256434797, -0.0307534742888629, -0.0429353941668259, 
0.0431030001167699, -0.0148604588408881, 0.000730129281795523, 
-0.0203917088111676, -0.00173524339317549, -0.0164421595877816, 
0.0422968676228454, 0.0312266645274965, -0.0101930164258961, 
0.0462552539327065, -0.0504162376100326, 0.00721182368029046, 
-0.0289719109636131, 0.00833594645094619, -0.0311349376270853, 
-0.0546946395105242, -0.0173563498849062, 0.0622821091349751, 
-0.0143567551490433, -0.0337848338746267, 0.216092927400821, 
-0.130686172931104, 0.0479935622292825, -0.024684492735992, 0.0858505510631271, 
0.15781480628134, -0.223091089778555, 0.0920002096668258, 0.00459916813575695, 
-0.0722456427546306, 0.0114542477748304, -0.0520496803635661, 
-0.0247474942134704, -0.0456495845929104, -0.0341408753457329, 
-0.0313863781916568, -0.0392470879047786, 0.0469961548354113, 
-0.0136872702702917, 0.091959017838499, -0.166388341903581, 0.0456120254775937, 
-0.0056257519751322, 0.169659274267868, -0.196986587904546, 0.057445714725044, 
-0.0583385347399891, -0.0705623076865842, -0.00418019934792342, 
-0.0124797602150215, -0.0528599556626416, -0.043063529897332, 
0.018380667574017, -0.00457466823222506, -0.0663859267075692, 
-0.0436516733412831, -0.0524049658818607, -0.0593911268801198, 
0.0152367208814446, -0.0271834855904899, -0.0531429530905513, 
0.0115780707623485, -0.0831938729827593, -0.0720793636035824, 
-0.0570599543155863, -0.0218120929987075, -0.0898456161247241, 
0.0907948920853566, -0.0278638831872147, -0.024254556276924, 
0.00619908934998819, -0.0255822332285602, -0.054909749809373, 
-0.0383721646129956, 0.126668387691588, -0.124675201775652, 0.00279486664468768, 
0.0617959048697281, -0.194543024659164, 0.00782299452204665, 
-0.0022863794186099, -0.0486269484201011, -0.000490295708275331, 
0.0351450198790226, -0.0528083459304233, -0.0735086152299193, 
-0.0179113962489111, -0.0443070609897254, -0.0378927715230982, 
-0.0391530701242147, -0.0330229272384759, 0.0305424515035558, 
-0.0101437571866827, 0.108843280020761, -0.178332980551711, 0.0209162014706896, 
-0.0494163651725372, 0.0331555475852243, -0.143102038417481, 
-0.0356665707723645, 0.0678312141350734, -0.0874676266777572, 
0.00804693801609979, -0.0257834919523693, -0.0589299498187884, 
-0.0502946338561211, -0.0498012558170634), .Names = c("2", "3", 
"4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", 
"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", 
"27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", 
"38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", 
"49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", 
"60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", 
"71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", 
"82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", 
"93", "94", "95", "96", "97", "98", "99", "100", "101", "102", 
"103", "104", "105", "106", "107", "108", "109", "110", "111", 
"112", "113", "114", "115", "116", "117", "118", "119", "120", 
"121", "122", "123", "124", "125", "126", "127", "128", "129", 
"130", "131", "132", "133", "134", "135", "136", "137", "138", 
"139", "140", "141", "142", "143", "144", "145", "146", "147", 
"148", "149", "150", "151", "152", "153", "154", "155", "156", 
"157", "158", "159", "160", "161", "162", "163", "164", "165", 
"166", "167", "168", "169", "170", "171", "172", "173", "174", 
"175", "176", "177", "178", "179", "180", "181", "182", "183", 
"184", "185", "186", "187", "188", "189", "190", "191", "192", 
"193", "194", "195", "196", "197", "198", "199", "200", "201", 
"202", "203", "204", "205", "206", "207", "208")), coefficients = structure(c(5.24015901393355, 
-0.438523172234815, 0.00652577799798605, -0.00359086501430074, 
-1.14872855093698, 0.000310740119828387, -0.00574619438317483, 
-0.00315648671961721, 0.100276647604364, -2.5172574741192e-05, 
0.00208622090173995, -0.150911530582484, 0.000655084374238763, 
-0.00998944864921308, -0.00159033435475918, -0.396425326073137, 
1.19229923382915, 0.074862784914862, 0.00270129916469264, 0.0189945724647302, 
0.338940693476613, 0.00122495487684004, 0.00340486350036558, 
0.00182420696185296, 0.10596691752117, 0.00291743955268936, 0.00774976399227689, 
0.121303104558558, 0.00133140707613133, 0.0041116883470457, 0.00241164717926104, 
0.0574679303046725, 4.39500325526876, -5.85769248009578, 2.41579240214535, 
-0.189046898579496, -3.38917271677867, 0.253674748109896, -1.68764309716318, 
-1.73033366587471, 0.946301449075665, -0.0086283106424561, 0.269197991554194, 
-1.24408630044281, 0.492024104410082, -2.42952476113386, -0.659439062411477, 
-6.89820085692046, 1.83545504740312e-05, 2.0205218360075e-08, 
0.0166426087624177, 0.850256789771837, 0.000851566079585319, 
0.800019701127057, 0.0931120252561721, 0.0851858833801705, 0.345190484734635, 
0.993124694961348, 0.788067904950151, 0.214992396713186, 0.623267326097252, 
0.0160438476350525, 0.510408171458361, 7.51741254527845e-11), .Dim = c(16L, 
4L), .Dimnames = list(c("(Intercept)", "deltalnPrice", "deltalnDisplay", 
"deltaIntrayearCycles", "deltalnCompetitorPrices", "deltalnCompADV", 
"deltalnCompDISP", "deltaDISPxCYC", "lnPriceLag1", "lnDisplayLag1", 
"IntrayearCyclesLag1", "lnCompetitorPricesLag1", "lnCompADVLag1", 
"lnCompDISPLag1", "DISPxCYCLag1", "yLag1"), c("Estimate", "Std. Error", 
"t value", "Pr(>|t|)"))), aliased = structure(c(FALSE, FALSE, 
TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, 
FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, 
TRUE, FALSE), .Names = c("(Intercept)", "deltalnPrice", "deltalnAdvertising", 
"deltalnDisplay", "deltaIntrayearCycles", "deltalnCompetitorPrices", 
"deltalnCompADV", "deltalnCompDISP", "deltaADVxDISP", "deltaADVxCYC", 
"deltaDISPxCYC", "deltaADVxDISPxCYC", "lnPriceLag1", "lnAdvertisingLag1", 
"lnDisplayLag1", "IntrayearCyclesLag1", "lnCompetitorPricesLag1", 
"lnCompADVLag1", "lnCompDISPLag1", "ADVxDISPLag1", "ADVxCYCLag1", 
"DISPxCYCLag1", "ADVxDISPxCYCLag1", "yLag1")), sigma = 0.0728717673227287, 
    df = c(16L, 191L, 24L), r.squared = 0.506700558626737, adj.r.squared = 0.467959764801612, 
    fstatistic = structure(c(13.0792507999182, 15, 191), .Names = c("value", 
    "numdf", "dendf")), cov.unscaled = structure(c(267.702190582405, 
    -2.29353522248156, -0.0517503451440976, -0.055687475455292, 
    -4.44697034657416, 0.0152279349501574, -0.0207327469035174, 
    -0.0646469608437576, -9.65959651810264, -0.0174540736105867, 
    0.503389265068798, -17.0530294841715, 0.0309625281335505, 
    -0.0924396991919828, -0.138987930945735, -8.25888589405142, 
    -2.29353522248156, 1.05539091927596, 0.00133670067064388, 
    -0.0313965368020614, 0.308568321428587, 0.001058677759189, 
    -0.00397277872259521, -0.000133820671181013, 1.02172739412857, 
    -0.000608087879878462, -0.0107772778012001, -0.215977796376023, 
    0.000142718153567589, -0.00434041139657631, -0.000585654802581366, 
    -0.214893767266193, -0.0517503451440976, 0.00133670067064388, 
    0.00137412665429962, 0.000357757446357807, -0.0276000589400855, 
    4.46648309679497e-05, 8.62551961032778e-05, -0.000187845710941694, 
    0.0143134914614128, 0.000866914371028312, 0.000463330715931342, 
    -0.00513110478039964, 7.27378701672986e-06, -8.93163395383372e-05, 
    -0.000101663762114469, -0.000581231736903212, -0.055687475455292, 
    -0.0313965368020614, 0.000357757446357807, 0.0679423306880886, 
    -0.0824867819667742, 8.24471138556661e-05, 0.000530277905503545, 
    -0.00160355520884178, -0.0370944602386458, -0.000294070999611984, 
    0.00589190160117976, -0.0119776177407598, 0.000241852490920546, 
    0.000827287954452858, -0.00154566623690725, 0.0287879466019947, 
    -4.44697034657416, 0.308568321428587, -0.0276000589400855, 
    -0.0824867819667742, 21.6336013537826, -0.000886120982539492, 
    -0.0129877538076717, 0.0130894051779166, -0.0916160659786231, 
    -0.00452855268245391, -0.0186306477458277, 1.28914488072668, 
    -0.00166196618755305, -0.0116992840268444, 0.00162171887578938, 
    -0.238441469681808, 0.0152279349501574, 0.001058677759189, 
    4.46648309679497e-05, 8.24471138556661e-05, -0.000886120982539492, 
    0.000282567088886986, -2.05812415461296e-05, -3.19475285897076e-05, 
    0.0002148253145001, 1.85298657441704e-05, -0.000134727272629721, 
    0.00156324192163218, 0.00016822850436755, -3.85457974040542e-05, 
    -1.80744637852897e-05, -0.00218879181263994, -0.0207327469035174, 
    -0.00397277872259521, 8.62551961032778e-05, 0.000530277905503545, 
    -0.0129877538076717, -2.05812415461296e-05, 0.00218313607948459, 
    -1.61614352993205e-05, -0.0067970948009426, 0.000101871499320883, 
    -0.000275483099553365, 0.00547707440838084, 6.2309280494767e-05, 
    0.0016023161214919, 3.56272913593494e-05, 0.00168337288915271, 
    -0.0646469608437576, -0.000133820671181013, -0.000187845710941694, 
    -0.00160355520884178, 0.0130894051779166, -3.19475285897076e-05, 
    -1.61614352993205e-05, 0.000626656592540542, -0.00101221617423008, 
    -0.000105532579489215, -0.00137454040140499, 0.00735762074476407, 
    -6.5692518553288e-05, 4.71264862951409e-05, 0.000549382114719615, 
    0.00209068059290048, -9.65959651810264, 1.02172739412857, 
    0.0143134914614128, -0.0370944602386458, -0.0916160659786231, 
    0.0002148253145001, -0.0067970948009426, -0.00101221617423008, 
    2.11456966587936, 0.00807853546256445, -0.0174047584856504, 
    -0.382573753919413, -0.00124812253955227, -0.00901925798859299, 
    9.53842275764575e-05, -0.0800524598366933, -0.0174540736105867, 
    -0.000608087879878462, 0.000866914371028312, -0.000294070999611984, 
    -0.00452855268245391, 1.85298657441704e-05, 0.000101871499320883, 
    -0.000105532579489215, 0.00807853546256445, 0.00160282138538504, 
    0.000989661382856097, -0.00643316552736391, 2.71612702024071e-05, 
    7.20425248082975e-05, -0.000195960953420845, 0.000147537009082643, 
    0.503389265068798, -0.0107772778012001, 0.000463330715931342, 
    0.00589190160117976, -0.0186306477458277, -0.000134727272629721, 
    -0.000275483099553365, -0.00137454040140499, -0.0174047584856504, 
    0.000989661382856097, 0.0113098891679779, -0.0608964376579808, 
    -7.23105273167681e-05, -0.000527726152864066, -0.00279329358218573, 
    -0.00156052231157431, -17.0530294841715, -0.215977796376023, 
    -0.00513110478039964, -0.0119776177407598, 1.28914488072668, 
    0.00156324192163218, 0.00547707440838084, 0.00735762074476407, 
    -0.382573753919413, -0.00643316552736391, -0.0608964376579808, 
    2.77092791201803, 0.00200532737220632, 0.00818796735359182, 
    0.0141072569138213, 0.174029022237292, 0.0309625281335505, 
    0.000142718153567589, 7.27378701672986e-06, 0.000241852490920546, 
    -0.00166196618755305, 0.00016822850436755, 6.2309280494767e-05, 
    -6.5692518553288e-05, -0.00124812253955227, 2.71612702024071e-05, 
    -7.23105273167681e-05, 0.00200532737220632, 0.000333812900861338, 
    2.45285110963878e-05, -9.65462417290809e-05, -0.00304719425523143, 
    -0.0924396991919828, -0.00434041139657631, -8.93163395383372e-05, 
    0.000827287954452858, -0.0116992840268444, -3.85457974040542e-05, 
    0.0016023161214919, 4.71264862951409e-05, -0.00901925798859299, 
    7.20425248082975e-05, -0.000527726152864066, 0.00818796735359182, 
    2.45285110963878e-05, 0.00318362402499968, 9.20274706942472e-05, 
    0.00669394653700606, -0.138987930945735, -0.000585654802581366, 
    -0.000101663762114469, -0.00154566623690725, 0.00162171887578938, 
    -1.80744637852897e-05, 3.56272913593494e-05, 0.000549382114719615, 
    9.53842275764575e-05, -0.000195960953420845, -0.00279329358218573, 
    0.0141072569138213, -9.65462417290809e-05, 9.20274706942472e-05, 
    0.00109523909589124, 0.00419699606459184, -8.25888589405142, 
    -0.214893767266193, -0.000581231736903212, 0.0287879466019947, 
    -0.238441469681808, -0.00218879181263994, 0.00168337288915271, 
    0.00209068059290048, -0.0800524598366933, 0.000147537009082643, 
    -0.00156052231157431, 0.174029022237292, -0.00304719425523143, 
    0.00669394653700606, 0.00419699606459184, 0.621917114099314
    ), .Dim = c(16L, 16L), .Dimnames = list(c("(Intercept)", 
    "deltalnPrice", "deltalnDisplay", "deltaIntrayearCycles", 
    "deltalnCompetitorPrices", "deltalnCompADV", "deltalnCompDISP", 
    "deltaDISPxCYC", "lnPriceLag1", "lnDisplayLag1", "IntrayearCyclesLag1", 
    "lnCompetitorPricesLag1", "lnCompADVLag1", "lnCompDISPLag1", 
    "DISPxCYCLag1", "yLag1"), c("(Intercept)", "deltalnPrice", 
    "deltalnDisplay", "deltaIntrayearCycles", "deltalnCompetitorPrices", 
    "deltalnCompADV", "deltalnCompDISP", "deltaDISPxCYC", "lnPriceLag1", 
    "lnDisplayLag1", "IntrayearCyclesLag1", "lnCompetitorPricesLag1", 
    "lnCompADVLag1", "lnCompDISPLag1", "DISPxCYCLag1", "yLag1"
    )))), .Names = c("call", "terms", "residuals", "coefficients", 
"aliased", "sigma", "df", "r.squared", "adj.r.squared", "fstatistic", 
"cov.unscaled"), class = "summary.lm")

这些导出在我的环境中也是单独的对象,我编写了一个for循环以将这些值提取为数据帧:

These exports are also separate objects in my environment and I write a for loop to extract these values as dataframe:

for(X in c("0"){
 ModelX <- get(paste0("C", X, "B2"))
 allparamest <- ModelX$coefficients} 

然后,模型X对应于我的环境中的特定模型.

Model X then corresponds to the specific model in my environment.

如果我想读取一个摘要输出,则需要使用print()函数而不是summary().对于一个特定的列表对象,我会得到:

If I want to read one summary output, I need to use the print() function instead of summary(). For one specific list object I would get this:

> print(C0B3)

Call:
lm(formula = dy ~ ., data = x)

Residuals:
      Min        1Q    Median        3Q       Max 
-0.223091 -0.036780 -0.001159  0.039722  0.216093 

Coefficients: (8 not defined because of singularities)
                          Estimate Std. Error t value Pr(>|t|)    
(Intercept)              5.240e+00  1.192e+00   4.395 1.84e-05 ***
deltalnPrice            -4.385e-01  7.486e-02  -5.858 2.02e-08 ***
deltalnAdvertising              NA         NA      NA       NA    
deltalnDisplay           6.526e-03  2.701e-03   2.416 0.016643 *  
deltaIntrayearCycles    -3.591e-03  1.899e-02  -0.189 0.850257    
deltalnCompetitorPrices -1.149e+00  3.389e-01  -3.389 0.000852 ***
deltalnCompADV           3.107e-04  1.225e-03   0.254 0.800020    
deltalnCompDISP         -5.746e-03  3.405e-03  -1.688 0.093112 .  
deltaADVxDISP                   NA         NA      NA       NA    
deltaADVxCYC                    NA         NA      NA       NA    
deltaDISPxCYC           -3.156e-03  1.824e-03  -1.730 0.085186 .  
deltaADVxDISPxCYC               NA         NA      NA       NA    
lnPriceLag1              1.003e-01  1.060e-01   0.946 0.345190    
lnAdvertisingLag1               NA         NA      NA       NA    
lnDisplayLag1           -2.517e-05  2.917e-03  -0.009 0.993125    
IntrayearCyclesLag1      2.086e-03  7.750e-03   0.269 0.788068    
lnCompetitorPricesLag1  -1.509e-01  1.213e-01  -1.244 0.214992    
lnCompADVLag1            6.551e-04  1.331e-03   0.492 0.623267    
lnCompDISPLag1          -9.989e-03  4.112e-03  -2.430 0.016044 *  
ADVxDISPLag1                    NA         NA      NA       NA    
ADVxCYCLag1                     NA         NA      NA       NA    
DISPxCYCLag1            -1.590e-03  2.412e-03  -0.659 0.510408    
ADVxDISPxCYCLag1                NA         NA      NA       NA    
yLag1                   -3.964e-01  5.747e-02  -6.898 7.52e-11 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.07287 on 191 degrees of freedom
Multiple R-squared:  0.5067,    Adjusted R-squared:  0.468 
F-statistic: 13.08 on 15 and 191 DF,  p-value: < 2.2e-16

推荐答案

以下是使用stargazertidy函数的两个选项.

Here are two options using the stargazer or tidy functions.

set.seed(101)
#data
dat <- data.frame(one=c(sample(1000:1239)),
                  two=c(sample(200:439)),
                  three=c(sample(600:839)),
                  Jan=c(rep(1,20),rep(0,220)),
                  Feb=c(rep(0,20),rep(1,20),rep(0,200)),
                  Mar=c(rep(0,40),rep(1,20),rep(0,180)),
                  Apr=c(rep(0,60),rep(1,20),rep(0,160)),
                  May=c(rep(0,80),rep(1,20),rep(0,140)),
                  Jun=c(rep(0,100),rep(1,20),rep(0,120)),
                  Jul=c(rep(0,120),rep(1,20),rep(0,100)),
                  Aug=c(rep(0,140),rep(1,20),rep(0,80)),
                  Sep=c(rep(0,160),rep(1,20),rep(0,60)),
                  Oct=c(rep(0,180),rep(1,20),rep(0,40)),
                  Nov=c(rep(0,200),rep(1,20),rep(0,20)),
                  Dec=c(rep(0,220),rep(1,20)))
#model
model <- lm(one ~ two + three + Jan + Feb + Mar + Apr + 
                    May + Jun + Jul + Aug + Sep + Oct + Nov + Dec,
            data=dat)
summary(model) # NA for covariate Dec

## export
# with stargazer
library(stargazer)
stargazer(model, type = "text") # includes Dec
# with broom (convert lm result to data frame)
library(broom); library(dplyr)
tidy(model, quick = TRUE) # with Dec but without se, t.val, p.val
tidy(model, quick = FALSE) # with se, t.val, p.val but without Dec 
df <- left_join(tidy(model, quick = TRUE),
                tidy(model, quick = FALSE),
                by = c("term", "estimate")) # includes Dec, se ...

这篇关于将lm摘要输出导出到包括NA的数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆