提问人:Es003 提问时间:8/21/2023 最后编辑:Es003 更新时间:8/22/2023 访问量:42
生成具有不同概率边际效应结果的表格
Generating a table with different probit marginal effect results
问:
我使用“probitmfx”生成了三个不同的边际效应结果,但是我很难生成一个包含所有结果的表格。有没有一种简单的方法可以获得结果的汇总表?你能帮我吗?
数据:
df2<-dput(df)
structure(list(rate = c(-0.107311222, -0.06023034, -0.138748264,
0.184619982, 0.088974044, -0.058872607, 0.131348687, -0.053702515,
0.068216527, 0.215789344, 0.138639749, -0.051174665, -0.045196985,
-0.095051188, 0.001159392, -0.020764965, 0.033003618, -0.196055395,
0.103205825, 0.056486418, 0.102000598, -0.128290888, 0.036633325,
0.084915261, 0.041698451, -0.016896662, 0.107018677, -0.001678324,
-0.133122898, -0.067082861, 0.116107858, -0.141675429, -0.048393834,
-0.302778038, -0.319781753, 0.122614883, 0.180881509, 0.133791832,
-0.285518419, 0.074120241, 0.146543977, 0.018349889, -0.052550724,
0.102829282, -0.095439954, 0.015700106, -0.019055146, -0.044911272,
-0.035890397, 0.080070564, 0.079254156, -0.128713942, 0.020552319,
0.091787908, 0.026699636, -0.089861291, -0.182022828, 0.165705314,
-0.02526569, 0.071750162, 0.0028876, 0.039990083, -0.145919586,
0.01756501, -0.076821261, -0.096299975, 0.103830743, 0.175349823,
0.132691523, 0.073382863, -0.005396216, -0.025773657, -0.085033273,
-0.126286204, 0.145612984, 0.043970104, 0.082394526, 0.111902488,
-0.108933889, 0.214464764, 0.183460952, 0.043905414, -0.116871092,
-0.009204845, 0.111763943, -0.013511424, -0.019898844, -0.302661135,
0.085131953, 0.088928646, 0.005799219, -0.063777641, 0.089138562,
0.07636777, 0.095144059, -0.167152088, -0.114270214, -0.002021205,
-0.355851723, 0.109255315, 0.226139158, 0.042715715, 0.142060449,
0.051991645, 0.042161443, 0.053057342, -0.015200478, 0.137267308,
0.09010991, -0.01537582, 0.047613153, -0.054587234, -0.027394119,
0.06626462, -0.021128573, -0.08560769, 0.112576949, 0.117056966,
0.137683116, 0.040096638, 0.087228789, -0.007281361, 0.087636202,
0.110457538, 0.020670111, 0.148268886, 0.119604162, 0.072895971,
0.089831888, 0.002903016, -0.244865847, 0.184418542, -0.000261158,
0.047423369, -0.159591184, 0.013388555, -0.020602059, -0.072743877,
0.198643858, 0.031591368, -0.057969321, 0.068837009, -0.125076487,
0.072122093, 0.052908327, -0.057523198, -0.165615035, 0.063041103,
-0.039842437, 0.169087798, 0.041504932, 0.110980852, 0.040990451,
-0.027947848, 0.016794674, 0.081085416, -0.086043452, 0.029303048,
-0.036168786, 0.064452177, 0.016847651, 0.00269111, 0.045024958,
0.042005388, -0.055154066, -0.000458537, -0.061194643, -0.214396792,
-0.113362324, -0.247180845, 0.127000396, -0.40179256, -0.347393071,
0.239251561, 0.199867055, -0.008715713, 0.103426078, -0.167573283,
0.010661758, 0.115340493), biinary = c(0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), hh = c(-1.700208252,
-1.221236402, -1.415366429, -1.724230647, -1.376907443, -1.318593804,
-1.323127141, -0.627964932, -1.771106781, -1.72548326, -1.290849521,
-0.709732326, -0.871852002, -0.982169599, -0.919873475, -0.38658951,
-0.839677984, -1.249780135, -1.144612644, -1.713778862, -1.035289168,
-0.846352849, -0.634889346, -0.410342159, -0.108214183, -0.161877195,
0.346562537, -0.101720078, 0.368500446, 0.562002809, 1.183080796,
0.497918272, 1.527018669, 1.32436549, 1.302712661, 0.399086101,
0.649117935, 0.300229793, -0.206831053, -0.248597605, -0.409761882,
-0.009504444, -0.141062331, 0.293578271, 0.144954889, 0.338743081,
0.484553588, 1.378067756, 1.942658755, 1.653068487, 2.446998329,
2.387138021, 2.994776315, 2.715304743, 2.523578466, 2.545702023,
2.537031823, 2.409704694, 2.137192731, 1.261688289, 0.153714263,
0.650902351, -0.018299915, 0.224361992, 0.239085583, -0.178449939,
-0.579422266, -0.663033604, -1.243675409, -1.467109942, -1.472290989,
-0.881981993, -0.167568798, -0.250467284, 0.283151769, 0.4014822,
0.740266289, 1.343117989, 1.996128572, 2.683991866, 3.056882731,
3.353606175, 3.590863568, 3.735257474, 3.370647316, 3.348697861,
3.199170751, 2.585926833, 2.252272372, 1.96782408, 1.7486161,
1.139118277, 1.057225871, 0.870909502, 0.672488721, 0.526168935,
0.706910395, 0.492259083, 0.419016303, 0.909915413, 0.880885705,
0.792156363, 0.571421514, 0.77073858, 0.691044755, 0.41316398,
0.264507533, -0.006587776, -0.077652221, -0.094061554, -0.05363432,
-0.393007572, -0.570448817, -0.587722668, -0.365502433, -0.417728503,
-0.25108918, 0.119696893, 0.291144679, 0.439919661, 0.596219002,
0.469285674, 0.404677187, 0.416752323, 0.458923606, 0.410485273,
0.339049524, 0.244574322, 0.267518772, 0.298566876, 0.136941538,
0.096886403, 0.092708874, 0.429169916, 0.477281263, 0.499850746,
0.834308948, 0.78589265, 1.147348708, 1.233803692, 1.351269689,
1.415989216, 2.227401467, 2.33033277, 2.377393977, 2.386751109,
2.587956902, 3.007684634, 3.001924336, 3.768072792, 3.327590667,
3.243714561, 3.243664464, 3.204568679, 2.672146377, 2.784252366,
2.613174627, 2.6760856, 2.578419652, 2.33481207, 2.271461712,
1.98385315, 2.235181934, 2.213501194, 2.030414786, 1.898965229,
1.810263641, 1.559248792, 1.737843666, 1.022180445, 0.914149048,
0.644886886, 0.55528642, 0.243583993, -0.242556065, -0.756391924,
-1.089880594, -1.680842722, -2.112480229, -2.381529306), nf = c(-0.721410968,
0.703926607, 1.480815492, 0.428904812, 2.244358009, 2.533114788,
1.741810334, 0.609323961, 0.480387065, -0.133961276, 0.432879031,
1.383401078, 1.262328338, 0.960193986, 1.047190559, 1.820036203,
1.996403901, 1.625606053, 1.824226658, 2.521470163, 1.391647759,
1.849664146, 1.768307203, 1.507432244, 1.073486832, 0.46255946,
0.503969088, 0.059672856, -0.588385137, -0.689274175, 0.010445819,
-1.022047332, 1.015080177, 1.119227683, 1.184444928, 0.648133909,
1.128815159, 0.465145185, -1.084407673, -2.32499172, -3.078684953,
-3.202991544, -3.555853431, -3.03649412, -3.35701576, -3.451503029,
-3.356153804, -2.674339343, -2.257421939, -2.420857206, -1.731147826,
-1.377799865, -0.739500248, -0.538212503, -0.474170451, -0.389379639,
-0.266457898, 0.02310255, 0.109479329, -0.529424167, -1.226760054,
-0.206193352, -0.128853864, 0.338609122, 0.756883799, 0.652485289,
0.870439845, 0.788668758, 0.787707575, 0.2831103, 0.101172826,
0.504598989, 1.135364587, 0.964531422, 1.241644958, 1.473738367,
0.86764212, 0.963812413, 0.59582581, 1.124129224, 1.218568959,
2.000548397, 2.407587913, 2.841535442, 2.771992854, 2.330129875,
2.003500867, 1.386608218, 1.550214567, 1.296228258, 1.332068051,
0.938158767, 0.710234749, 0.296657891, -0.055008054, -0.369439846,
-0.679907135, -0.8503127, -0.964963796, -0.852253623, -1.315799098,
-1.710300134, -2.20880797, -2.701559771, -2.863770746, -3.190666353,
-3.263183924, -3.611698698, -3.266098117, -3.039248746, -2.914920777,
-3.046590429, -2.689920177, -2.450661247, -2.046730475, -1.746459372,
-1.387199542, -0.95890577, -0.768414899, -0.452589985, -0.447734231,
-0.475499478, -0.420730224, -0.370394906, -0.343987385, -0.241718729,
-0.131092755, 0.04728446, 0.190377092, 0.358913722, 0.502465769,
0.552758079, 0.834925373, 1.009999376, 1.273285431, 1.328178262,
1.515026726, 1.546974199, 1.560021739, 1.484378416, 1.259725479,
1.055637729, 1.125434377, 1.051754038, 0.648705376, 0.431227793,
0.095153825, 0.146991215, -0.297805448, -0.50359193, -0.890599817,
-1.189828086, -1.192595195, -1.3934034, -1.549140464, -1.5771226,
-1.519104043, -1.273531682, -1.186936781, -1.032766078, -0.863532077,
-0.474761428, -0.055322374, 0.47403833, 0.602254237, 1.036176901,
1.417714537, 1.741075172, 2.122312722, 2.124121922, 2.274819366,
2.506218636, 2.504073414, 2.146107988, 1.642392324, 0.797024937,
0.416612325, -0.277474419, -0.722985517, -1.282071056)), class = "data.frame", row.names = c(NA,
-180L))
代码:
library("tidyverse")
library("dplyr")
library(tseries)
library("stargazer")
library(mfx)
df2
mod1<-probitmfx(biinary~hh,data = df2, atmean=FALSE)
mod1
mod2<-probitmfx(biinary~nf,data = df2, atmean=FALSE)
mod2
mod3<-probitmfx(biinary~hh+nf,data = df2, atmean=FALSE)
mod3
stargazer(mod1,mod2,mod3,
type="text",
out="/Users/edah/Desktop//three_years_ahead.htm")
答:
0赞
Vincent
8/21/2023
#1
看起来包不支持这些模型对象。 似乎不再积极开发,所以我不希望它在不久的将来支持对象(我可能是错的)。stargazer
stargazer
mfx
一种替代方法是改用该包(免责声明:我是作者)。它支持开箱即用的对象。请注意,使用参数来消除每个术语的“边际”和“条件”估计之间的歧义。这在文档中有详细说明:https://modelsummary.commodelsummary
mfx
shape
library(mfx)
library(modelsummary)
mod1 <- probitmfx(biinary ~ hh, data = df2, atmean = FALSE)
mod2 <- probitmfx(biinary ~ nf, data = df2, atmean = FALSE)
mod3 <- probitmfx(biinary ~ hh + nf, data = df2, atmean = FALSE)
modelsummary(
list(mod1, mod2, mod3),
shape = term + component ~ model,
output = "markdown")
元件 | (1) | (2) | (3) | |
---|---|---|---|---|
呵呵 | 有條件的 | 0.138 | 0.126 | |
有條件的 | (0.096) | (0.096) | ||
边缘的 | 0.021 | 0.018 | ||
边缘的 | (0.015) | (0.014) | ||
(截取) | 有條件的 | -1.508 | -1.489 | -1.599 |
有條件的 | (0.167) | (0.157) | (0.185) | |
NF系列 | 有條件的 | 0.259 | 0.256 | |
有條件的 | (0.110) | (0.111) | ||
边缘的 | 0.037 | 0.036 | ||
边缘的 | (0.016) | (0.016) | ||
Num.Obs. | 180 | 180 | 180 | |
AIC公司 | 105.4 | 100.8 | 101.2 | |
BIC | 111.8 | 107.2 | 110.8 | |
RMSE的 | 0.28 | 0.27 | 0.27 |
编辑以回答修改后的问题:
cm <- c(
"hh conditional" = "hh",
"nf conditional" = "nf",
"(Intercept) conditional" = "Constant"
)
models <- list(
"(1) Price" = mod1,
"(2) Price" = mod2,
"(3) Price" = mod3
)
modelsummary(
# models to summarize side-by-side
models,
# t statistics in parentheses
statistic = "statistic",
# rename the coefficients
coef_map = cm,
# significance stars
stars = TRUE,
# term and component columns are combined
shape = term:component ~ model,
# omit all goodness-of-fit statisitcs except # of observations
gof_map = "nobs")
评论
0赞
Es003
8/21/2023
非常感谢@Vincent。但是,我可以使用您的包裹以我上面上传的表格获得结果吗?
0赞
Vincent
8/22/2023
你可以非常非常接近。我编辑了答案。
评论