我在metafor
包中使用以下代码运行了元回归分析:
output5_MR = map(metrics4,
#magrittr::extract(!. %in% c("Soil NPK availability", "Nutrient use efficiency")),
function(i) metadata1 %>%
dplyr::filter(measurement_n==i) %>%
rma.mv(lnrr, v, random = ~ 1 | publication_title / unique_id, mods = ~ duration_exp + temp_group + soil_texture + country,
method = "REML", data=.))
CCD_ 2包含9个因变量。当我运行模型时,我得到了所有效果修改器(用mods
函数给出(和截距的结果。我想提取某个效应修饰符(比如Biochar_app_rate
(的估计值b
和标准误差se
。我尝试了以下代码
output5_MR_b <- map_dbl(output5_MR,
function(x) as.numeric(x[["b"]]))
output5_MR_se <- map_dbl(output5_MR$Biochar_app_rate,
function(x) as.numeric(x[["se"]]))
但这些代码为所有效果修饰符提取se
和b
。有人知道如何创建一个代码来提取某些效果修饰符的b
和se
吗?
以下是一个示例数据集:
unique_id <- c(1,2,3,4,5,6,7,8,9,10)
publication_title <- c("publication1", "publication1", "publication1", "publication2", "publication2", "publication2",
"publication2", "publication2", "publication2", "publication2")
publication_title <- c(0.04, 0.01, 0.42, 0.34, -0.24, -0.12, 0.30, 0.12, -0.80, 0.03)
v <- c(0.005272691, 0.011742537, 0.169538779, 0.085044762, 0.083513861, 0.056932582, 0.043557358,
0.045750691, 0.001520993, 0.001417840)
measurement_n <- c("Soil total NPK", "Soil mineral nitrogen", "Soil mineral nitrogen", "Plant nutrient level",
"Soil total NPK", "Plant nutrient leve", "Plant nutrient level", "Soil total NPK",
"Plant nutrient level","Plant nutrient level")
duration_exp <- c(150, 150, 150, 90, 90, 90, 90, 90, 90, 90)
temp_group <- c("Medium", "Medium", "Medium", "High", "High", "High", "High", "High", "High", "High")
soil_texture <- c("sandy clay loam", "sandy clay loam", "sandy clay loam", "Sandy loam", "Sandy loam",
"Sandy loam", "Sandy loam", "Sandy loam", "Sandy loam", "Sandy loam")
country <- c("Brazil", "Brazil", "Brazil", "China", "China", "China", "China", "China", "China", "China")
metadata1 <- data.frame(unique_id, publication_title, publication_title, v, measurement_n, duration_exp,
temp_group, soil_texture, country)
我可以使用dplyr
的filter
函数来解决这个问题,如下所示
output5_MR_table = map(output5_MR,
function(x) tibble("name" = rownames(x[["b"]]),
"b" = as.numeric(x[["b"]]),
"se" = x[["se"]]) %>%
filter(str_detect(name, "intrcpt|Biochar_app_rate")) )
在这里,我提取了回归分析的特定变量(Biochar_app_rate(的estimate
和se
。请注意,我使用了purrr
的map
函数,它以列表形式返回结果。