繁体   English   中英

使用 fixst::feols 和 modelsummary 的几个固定效果模型的 R2

[英]R2 for several fixed effects models using fixest::feols and modelsummary

我有一个数据集

structure(list(NAME_1.y = c("Alibori", "Atakora", "Atlantique", 
"Borgou", "Collines", "Donga", "Kouffo", "Littoral", "Mono", 
"Oueme", "Plateau", "Zou", "Central", "Chobe", "Francistown", 
"Gaborone", "Ghanzi", "Jwaneng", "Kgalagadi", "Kgatleng", "Kweneng", 
"Lobatse", "North-East", "Selibe Phikwe", "South-East", "Southern", 
"Mosteiros", "Paúl", "Porto Novo", "Praia", "Ribeira Grande", 
"Santa Catarina", "Santa Cruz", "Sao Domingos", "Sao Filipe", 
"Sao Miguel", "Sao Vicente", "Tarrafal", "Ashanti", "Brong Ahafo", 
"Central", "Eastern", "Greater Accra", "Northern", "Upper East", 
"Upper West", "Volta", "Western", "Bomet", "Bungoma"), country = c("Benin", 
"Benin", "Benin", "Benin", "Benin", "Benin", "Benin", "Benin", 
"Benin", "Benin", "Benin", "Benin", "Botswana", "Botswana", "Botswana", 
"Botswana", "Botswana", "Botswana", "Botswana", "Botswana", "Botswana", 
"Botswana", "Botswana", "Botswana", "Botswana", "Botswana", "Cape Verde", 
"Cape Verde", "Cape Verde", "Cape Verde", "Cape Verde", "Cape Verde", 
"Cape Verde", "Cape Verde", "Cape Verde", "Cape Verde", "Cape Verde", 
"Cape Verde", "Ghana", "Ghana", "Ghana", "Ghana", "Ghana", "Ghana", 
"Ghana", "Ghana", "Ghana", "Ghana", "Kenya", "Kenya"), year = c(2005, 
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 
2005, 2005, 2005, 2005, 2005), yearvalue = c(0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0), sngq = c(40.3350714285714, 41.8501465773809, 32.1462559523809, 
53.3881378348214, 51.3143125, 45.3290479910714, 30.9222321428571, 
31.8178055555556, 29.6696517857143, 32.6099506302521, 30.4012254464286, 
31.2331401098901, 48.3522208850932, 46.2751339285714, 51.8882346938775, 
49.0520504201681, 49.9850803571429, 49.7569285714286, 48.6707276785714, 
55.5698392857143, 49.1367147108843, 49.6709583333333, 47.7482008928571, 
47.4158928571429, 47.1282232142857, 47.5937851190476, 45.5919585253456, 
39.4586860119048, 34.0096227106227, 37.4234026227679, 35.2635037202381, 
36.663, 39.3566339285714, 39.9424339285714, 38.4452915543576, 
41.0157392857143, 46.5320122818358, 45.8783482142857, 45.1649102484472, 
55.3813660714286, 40.4874038461538, 43.992073015873, 39.0866451990632, 
54.0252091836735, 48.2392232142857, 45.3506232142857, 43.0489608516484, 
36.9757994047619, 38.9841964285714, 36.4050892857143), fac = c(0.365909090909091, 
0.39375, 0.609722222222222, 0.525, 0.664583333333333, 0.546875, 
0.322727272727273, 0.574603174603175, 0.5, 0.633823529411765, 
0.5, 0.428846153846154, 0.344836956521739, 0.3, 0.246428571428571, 
0.169117647058824, 0.733333333333333, 1, 0.7125, 0.428571428571429, 
0.35952380952381, 0.0833333333333333, 0.4, 0, 0.24, 0.381666666666667, 
0.341935483870968, 0.466666666666667, 0.302564102564103, 0.1890625, 
0.35, 0.48, 0.354545454545455, 0.48, 0.323270440251572, 0.35, 
0.323076923076923, 0.233333333333333, 0.508188405797101, 0.641071428571429, 
0.686057692307692, 0.759012345679012, 0.460326086956522, 0.475, 
0.476190476190476, 0.50125, 0.459615384615385, 0.65875, 0.1, 
0.6), svc = c(0.0909090909090909, 0.0833333333333333, 0.44212962962963, 
0.270833333333333, 0.25, 0.166666666666667, 0.299242424242424, 
0.682539682539683, 0.333333333333333, 0.436274509803922, 0.333333333333333, 
0.384615384615385, 0.560688405797101, 0.833333333333333, 0.973214285714286, 
0.742647058823529, 0.555555555555556, 0.666666666666667, 0.666666666666667, 
0.797619047619048, 0.507936507936508, 0.666666666666667, 0.666666666666667, 
0.833333333333333, 0.933333333333333, 0.561111111111111, 0.301075268817204, 
0.833333333333333, 0.534188034188034, 0.657552083333333, 0.638888888888889, 
0.355555555555556, 0.424242424242424, 0.466666666666667, 0.30188679245283, 
0.333333333333333, 0.933634992458522, 0.666666666666667, 0.515942028985507, 
0.523809523809524, 0.756410256410256, 0.511111111111111, 0.947463768115942, 
0.37797619047619, 0.541666666666667, 0.391666666666667, 0.5, 
0.733333333333333, 0.166666666666667, 0.191666666666667)), class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -50L), groups = structure(list(
    year = c(2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 
    2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 
    2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 
    2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 
    2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 
    2005, 2005), country = c("Benin", "Benin", "Benin", "Benin", 
    "Benin", "Benin", "Benin", "Benin", "Benin", "Benin", "Benin", 
    "Benin", "Botswana", "Botswana", "Botswana", "Botswana", 
    "Botswana", "Botswana", "Botswana", "Botswana", "Botswana", 
    "Botswana", "Botswana", "Botswana", "Botswana", "Botswana", 
    "Cape Verde", "Cape Verde", "Cape Verde", "Cape Verde", "Cape Verde", 
    "Cape Verde", "Cape Verde", "Cape Verde", "Cape Verde", "Cape Verde", 
    "Cape Verde", "Cape Verde", "Ghana", "Ghana", "Ghana", "Ghana", 
    "Ghana", "Ghana", "Ghana", "Ghana", "Ghana", "Ghana", "Kenya", 
    "Kenya"), NAME_1.y = c("Alibori", "Atakora", "Atlantique", 
    "Borgou", "Collines", "Donga", "Kouffo", "Littoral", "Mono", 
    "Oueme", "Plateau", "Zou", "Central", "Chobe", "Francistown", 
    "Gaborone", "Ghanzi", "Jwaneng", "Kgalagadi", "Kgatleng", 
    "Kweneng", "Lobatse", "North-East", "Selibe Phikwe", "South-East", 
    "Southern", "Mosteiros", "Paúl", "Porto Novo", "Praia", 
    "Ribeira Grande", "Santa Catarina", "Santa Cruz", "Sao Domingos", 
    "Sao Filipe", "Sao Miguel", "Sao Vicente", "Tarrafal", "Ashanti", 
    "Brong Ahafo", "Central", "Eastern", "Greater Accra", "Northern", 
    "Upper East", "Upper West", "Volta", "Western", "Bomet", 
    "Bungoma"), .rows = structure(list(1L, 2L, 3L, 4L, 5L, 6L, 
        7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 
        19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 
        30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 
        41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L), ptype = integer(0), class = c("vctrs_list_of", 
    "vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -50L), .drop = TRUE))

我想通过累积逐步添加控件来估计固定效应回归,并将结果显示在modelsummary表中。

library(fixest)

model <- feols(sngq ~ csw(yearvalue, fac, svc) | country + year + country^year, df) 

names(model) <- c("Model 1", "Model 2", "Model 3", "Model 4")

modelsummary(model, coef_omit = "Int", stars = c("***" = 0.01, "**" = 0.05, "*" = 0.1), gof_omit = "IC$|Lik.|RMSE|FE", coef_rename = c("yearvalue" = "Extraction Value", "fac" = "Nearby Facilities", "svc" = "Available Services"))

不幸的是,这并没有显示每个模型的 R2。 我知道我可以使用计算单个模型的 R2

r2(feols(sngq ~ yearvalue + fac + svc | country + year + country^year, df), "r2")

但我希望它包含在多个模型的模型modelsummary表中作为正常的拟合优度,有没有办法实现这一点?

我相信这个错误已在上游包中修复。 如果您安装最新的开发版本,您应该能够自动获得 R2:

library(remotes)
install_github("lrberge/fixest")
install_github("easystats/performance")
install_github("vincentarelbundock/modelsummary")

完全重启 R,然后:

library(fixest)
library(modelsummary)

mod <- feols(mpg ~ sw(hp, wt, drat) | cyl, data = mtcars)

modelsummary(mod, output = "markdown")
右:马力 右:重量 右:德拉特
生命值 -0.024
(0.015)
重量 -3.206
(1.188)
德拉特 1.793
(1.564)
数量。 32 32 32
R2 0.754 0.837 0.745
R2 调整。 0.727 0.820 0.718
R2 内 0.080 0.392 0.048
R2 在调整范围内。 0.047 0.371 0.014
AIC 163.9 150.6 165.0
BIC 166.8 153.6 167.9
均方根误差 2.94 2.39 2.99
标准错误 作者:圆柱 作者:圆柱 作者:圆柱
FE:圆柱体 X X X

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM