[R-meta] Possible bug in metafor::weights()
Viechtbauer, Wolfgang (SP)
wo||g@ng@v|echtb@uer @end|ng |rom m@@@tr|chtun|ver@|ty@n|
Thu Feb 17 18:38:53 CET 2022
Dear Stefanou,
Thanks for reporting this. Easy fix - will update the devel version soon and then this will be fixed.
Best,
Wolfgang
>-----Original Message-----
>From: Stefanou Revesz [mailto:stefanourevesz using gmail.com]
>Sent: Thursday, 17 February, 2022 17:13
>To: R meta
>Cc: Viechtbauer, Wolfgang (SP)
>Subject: Possible bug in metafor::weights()
>
>Dear Meta-analysis Experts,
>
>I just came across the following post
>**https://stat.ethz.ch/pipermail/r-sig-meta-analysis/2022-February/003851.html**
>about the weights in rma.mv() models. I have two questions.
>
>1- It looks like the weights() function in metafor doesn't work if a
>model has used 'sparse=TRUE' (reproducible example below)?
>
>2- The above-linked post provides a method to detect negative weights
>for effect estimates as a way to discover the inadequacy of using a
>single r in the V matrix. But I tried that method with Dr.
>Pustejovsky's own demo and I still see negative weights (below). So,
>are negative weights sometimes OK?
>
>Thanks,
>Stefanou
>
>TSL15 <- readRDS(url("https://osf.io/xpmjk/download")) %>%
> filter(!is.na(percoll), !is.na(attrition_all), !is.na(permale))
>
>TSL15_cent <-
> TSL15 %>%
> mutate(
> postwks_c = pmin(postwks, 26) - 12,
> postwks_long = as.numeric(postwks > 26),
> percoll_c = percoll - 1,
> permale_c = permale - 0.5,
> attrition_c = attrition_all - median(attrition_all),
> study_dv = paste(studyid, dv_cat, sep = "-"),
> study_ctype = paste(studyid, Ctype, sep = "-"))
>
>
>V_mat <- impute_covariance_matrix(TSL15_cent$V,
> cluster = TSL15_cent$studyid,
> r = .6, smooth_vi = TRUE)
>
>##-- change to sparse=TRUE to see weights() bug
>dv_multilevel <- rma.mv(es ~ 0 + dv_cat + postwks_c + postwks_long +
>percoll_c + permale_c + attrition_c,
> V = V_mat, random = ~ 1 | studyid / esid,
> data = TSL15_cent, sparse = FALSE)
>
>W <- weights(dv_multilevel, type = "matrix")
>X <- model.matrix(dv_multilevel)
>WX <- W %*% X
>B <- solve(t(X) %*% WX)
>weighting_mat <- WX %*% B
>any(weighting_mat < 0) # <--- TRUE
More information about the R-sig-meta-analysis
mailing list