[R-meta] R-sig-meta-analysis Digest, Vol 35, Issue 7
Hi Michael, Sorry. I copied the wrong link. I am using data from this link. Attaching the data as a csv as well. Below is the code and output. http://www.metafor-project.org/doku.php/tips:rma.uni_vs_rma.mv Perhaps just to be clear - I am trying to bootstrap errors in estimation which uses rma.mv and moderator variables. ##Code dat <- read_csv("test.csv") #RE rma(yi, vi, data=dat) #CRVE rma.mv(yi, vi, random = ~ 1 | trial, data=dat) #Bootstrapping res <-rma.mv(yi, vi, random = ~ 1 | trial, data=dat, mods = ~ alloc) boot.func <- function(df, indices) { sub <- dat[indices,] res <-rma.mv(yi, vi, random = ~ 1 | trial, data=dat, mods = ~ alloc) if (is.element("try-error", class(res))) NA else c(coef(res), vcov(res)) } ## Output Bootstrap Statistics : original bias std. error t1* -0.51792376 0 0 t2* -0.44786464 0 0 t3* 0.08899601 0 0 t4* 0.19465035 0 0 t5* -0.19465035 0 0 t6* -0.19465035 0 0 t7* -0.19465035 0 0 t8* 0.26607085 0 0 t9* 0.19465035 0 0 t10* -0.19465035 0 0 t11* 0.19465035 0 0 t12* 0.31363498 0 0 Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : index 0 outside bounds In addition: Warning messages: 1: In sqrt(tv[, 2L]) : NaNs produced 2: In norm.inter(z, (1 + c(conf, -conf))/2) : extreme order statistics used as endpoints Tarun Khanna PhD Researcher Hertie School Friedrichstra?e 180 10117 Berlin ? Germany khanna at hertie-school.org ? www.hertie-school.org<http://www.hertie-school.org/>
From: Michael Dewey <lists at dewey.myzen.co.uk>
Sent: 21 April 2020 17:28:43
To: Tarun Khanna; Viechtbauer, Wolfgang (SP); r-sig-meta-analysis at r-project.org
Subject: Re: [R-meta] R-sig-meta-analysis Digest, Vol 35, Issue 7
Sent: 21 April 2020 17:28:43
To: Tarun Khanna; Viechtbauer, Wolfgang (SP); r-sig-meta-analysis at r-project.org
Subject: Re: [R-meta] R-sig-meta-analysis Digest, Vol 35, Issue 7
Dear Tarun In the example on that page it uses dat.collins1985b but that does not contain either a variable trial, nor one called alloc. Can you post a complete minimal reproducible example showing the packages you use and which data-set you are using? Michael On 21/04/2020 15:35, Tarun Khanna wrote: > Hi Wolfgang, > > > Let me start by just using the example on Metafor help. > > > I used the dataset provided in the example on the Metafor page: http://www.metafor-project.org/doku.php/tips:bootstrapping_with_ma. I was able to replicate the results on the page. Then I added the variable alloc as a moderator variable in the estimation. > > > ##Code > > > #Bootstrapping > res <-rma.mv(yi, vi, random = ~ 1 | trial, data=dat, mods = ~ alloc) > > boot.func <- function(df, indices) { > sub <- dat[indices,] > res <-rma.mv(yi, vi, random = ~ 1 | trial, data=dat, mods = ~ alloc) > if (is.element("try-error", class(res))) NA else c(coef(res), vcov(res)) > } > > library(boot) > > set.seed(8781328) > res.boot <- boot(dat, boot.func, R=10000) > boot.ci(res.boot, index=1:2) #CI for average effect > boot.ci(res.boot, index=3:4) #CI for tau2 > > > ## Output > > > Bootstrap Statistics : > original bias std. error > t1* -0.51792376 0 0 > t2* -0.44786464 0 0 > t3* 0.08899601 0 0 > t4* 0.19465035 0 0 > t5* -0.19465035 0 0 > t6* -0.19465035 0 0 > t7* -0.19465035 0 0 > t8* 0.26607085 0 0 > t9* 0.19465035 0 0 > t10* -0.19465035 0 0 > t11* 0.19465035 0 0 > t12* 0.31363498 0 0 > > > Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : > index 0 outside bounds > In addition: Warning messages: > 1: In sqrt(tv[, 2L]) : NaNs produced > 2: In norm.inter(z, (1 + c(conf, -conf))/2) : > extreme order statistics used as endpoints > > > Best > > Tarun > > > Tarun Khanna > > PhD Researcher > > Hertie School > > > Friedrichstra?e 180 > > 10117 Berlin ? Germany > khanna at hertie-school.org ? www.hertie-school.org<http://www.hertie-school.org/<http://www.hertie-school.org<http://www.hertie-school.org/>> > > ________________________________ > From: Viechtbauer, Wolfgang (SP) <wolfgang.viechtbauer at maastrichtuniversity.nl> > Sent: 21 April 2020 15:05:08 > To: Tarun Khanna; r-sig-meta-analysis at r-project.org > Subject: RE: R-sig-meta-analysis Digest, Vol 35, Issue 7 > > Yes, one can also use bootstrapping on regression coefficients. Please provide a fully reproducible example that illustrates your attempts. > > Best, > Wolfgang > >> -----Original Message----- >> From: R-sig-meta-analysis [mailto:r-sig-meta-analysis-bounces at r-project.org] >> On Behalf Of Tarun Khanna >> Sent: Tuesday, 21 April, 2020 14:35 >> To: r-sig-meta-analysis at r-project.org >> Subject: Re: [R-meta] R-sig-meta-analysis Digest, Vol 35, Issue 7 >> >> Dear Wolfgang, >> >> I have a follow up question to Crystals'. Does bootstrapping also work with >> regressions that have moderator variables? >> >> I used the link that you provided, http://www.metafor- >> project.org/doku.php/tips:bootstrapping_with_ma, and ran a regression with >> "alloc" as a moderator variable and then tried bootstrapping the errors but >> the std. errrs were calculated as zero. This is the output that i got: >> >> Bootstrap Statistics : >> original bias std. error >> t1* -0.51792376 0 0 >> t2* -0.44786464 0 0 >> t3* 0.08899601 0 0 >> t4* 0.19465035 0 0 >> t5* -0.19465035 0 0 >> t6* -0.19465035 0 0 >> t7* -0.19465035 0 0 >> t8* 0.26607085 0 0 >> t9* 0.19465035 0 0 >> t10* -0.19465035 0 0 >> t11* 0.19465035 0 0 >> t12* 0.31363498 0 0 >> >>> boot.ci(res.boot, index=1:2) #CI for average effect >> Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : >> index 0 outside bounds >> In addition: Warning messages: >> 1: In sqrt(tv[, 2L]) : NaNs produced >> 2: In norm.inter(z, (1 + c(conf, -conf))/2) : >> extreme order statistics used as endpoints >> >> I also tried doing it with my own data set and got the following error: >> >> Error in t.star[r, ] <- res[[r]] : >> number of items to replace is not a multiple of replacement length >> In addition: There were 50 or more warnings (use warnings() to see the first >> 50) >> >> If bootstrapping does indeed work with moderator variables, what might be >> wrong? >> >> Best >> Tarun >> >> Tarun Khanna >> PhD Researcher >> Hertie School >> >> Friedrichstra?e 180 >> 10117 Berlin ? Germany >> khanna at hertie-school.org ? www.hertie-school.org<http://www.hertie-<http://www.hertie-school.org<http://www.hertie-<http://www.hertie-school.org<http://www.hertie-<http://www.hertie-school.org<http://www.hertie->> >> school.org/> > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-meta-analysis mailing list > R-sig-meta-analysis at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis > > -- Michael http://www.dewey.myzen.co.uk/home.html -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://stat.ethz.ch/pipermail/r-sig-meta-analysis/attachments/20200421/f1b04ee8/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: test.csv Type: text/csv Size: 960 bytes Desc: test.csv URL: <https://stat.ethz.ch/pipermail/r-sig-meta-analysis/attachments/20200421/f1b04ee8/attachment-0001.csv>