<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Verdana;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Aptos;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:12.0pt;
font-family:"Aptos",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
{mso-style-priority:99;
mso-style-link:"Plain Text Char";
margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-ligatures:standardcontextual;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Aptos",sans-serif;
color:windowtext;}
span.PlainTextChar
{mso-style-name:"Plain Text Char";
mso-style-priority:99;
mso-style-link:"Plain Text";
font-family:"Calibri",sans-serif;
mso-ligatures:standardcontextual;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple style='word-wrap:break-word'><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt'>Thanks for all the work, Tobias. I tried your program for tau2, and it worked. I had already adapted my (and ChatGPT's) program to do also the coverage of the fixed effects, which is also working. Your program seems to be more elegant, in that it produces list objects separately with rma, selmodel and confint, rather than using the for loop. I get lost more with your program than mine, but I will see if I can come to terms with it and implement it for the fixed effects. <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt'><o:p> </o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>Yesterday, Michael Dewey made the point that "</span>I doubt whether the standard error of tau2 is useful for much and certainly not for establishing a confidence interval. I think Wolfgang alluded to that in a previous e-mail.<span style='font-family:"Aptos",sans-serif'>" Yes, but SAS is happy enough to create confidence limits for random effects by assuming normality of the sampling distribution, and over the years I have done many simulations to show that it works well. I have implemented it here with the tau2 and its SE provided by selmodel, and it works practically perfectly. See below for the results for the fixed and random effects from my program so far, with a dataset generated by SAS with publication bias simulated by selecting all significant study estimates and 20% of non-significant study estimates. In the 2500 simulations, on average there were 12 significant and 2 non-significant female study estimates, and 13 significant and 14 non-significant male study estimates, for on average a total of 40 study-estimates (range 24-55) of mean sample size 13 (range 10-30) per simulation. The true means for females and males were 3 and 1, and the true heterogeneity SD was 0.5 (as shown below). We have implemented the PEESE approach in SAS (adjusting for publication bias with an SE^2 moderator), and for this simulation it's not quite as good as the "3PSM" implemented with selmodel: it adjusts perfectly for the males, but it over-adjusts for the females and for the heterogeneity.<o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'><o:p> </o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>Will<o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'><o:p> </o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>Here are the results. I have also attached as an easy-to-read text file generated by R using the sink("results.txt")… sink() approach suggested by ChatGPT (is there a better way?).<o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'><o:p> </o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>Female mean provided by selmodel:<o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>SexFemale lb ub TrueMean Coverage <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'> 3.11 2.53 3.69 3.00 87.96 <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>Non-missing values for the above:<o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>SexFemale lb ub TrueMean Coverage <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'> 2500 2483 2483 2500 2483 <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'><o:p> </o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>Male mean provided by selmodel:<o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'> SexMale lb ub TrueMean Coverage <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'> 1.18 0.63 1.73 1.00 78.70 <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>Non-missing values for the above:<o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'> SexMale lb ub TrueMean Coverage <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'> 2500 2483 2483 2500 2483 <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'><o:p> </o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'><o:p> </o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>Tau^2 with CLs provided by confint applied to selmodel-adjusted estimates:<o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>estimate ci.lb ci.ub TrueSD2 Coverage <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'> 0.46 0.13 1.16 0.25 76.88 <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>Number of simulations with non-missing values for the above:<o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>estimate ci.lb ci.ub TrueSD2 Coverage <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'> 2500 2500 2500 2500 2500 <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'><o:p> </o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>Tau with CLs provided by confint applied to selmodel-adjusted estimates:<o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>estimate ci.lb ci.ub TrueSD Coverage <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'> 0.61 0.27 1.04 0.50 76.88 <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>Number of simulations with non-missing values for the above:<o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>estimate ci.lb ci.ub TrueSD Coverage <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'> 2500 2500 2500 2500 2500 <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'><o:p> </o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>Tau^2 and Tau with CLs via Tau2 and its SE provided by selmodel:<o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'> Tau2 Tau2SE Tau2LCL Tau2UCL TrueSD2 Coverage Tau TauLCL TauUCL TrueSD <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'> 0.46 0.32 -0.05 1.00 0.25 91.43 0.61 -0.09 0.96 0.50 <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'>Non-missing values for the above:<o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'> Tau2 Tau2SE Tau2LCL Tau2UCL TrueSD2 Coverage Tau TauLCL TauUCL TrueSD <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'> 2500 2391 2391 2391 2500 2391 2500 2391 2391 2500 <o:p></o:p></span></p><p class=MsoPlainText><span style='font-family:"Aptos",sans-serif'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> R-sig-meta-analysis <r-sig-meta-analysis-bounces@r-project.org> <b>On Behalf Of </b>Tobias Saueressig via R-sig-meta-analysis<br><b>Sent:</b> Monday, March 11, 2024 8:08 PM<br><b>To:</b> r-sig-meta-analysis@r-project.org<br><b>Cc:</b> Tobias Saueressig <t.saueressig@gmx.de>; r-sig-meta-analysis@r-project.org<br><b>Subject:</b> Re: [R-meta] Extracting values from a list of confint() objects<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>Sorry Will, two more mistakes had crept in. It's probably too early in the morning after all. So here is the script again.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>library(metafor)<br> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>dat <- dat.baskerville2012<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>dat<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>#create a list of dfs with 10 replications of dat<br>dat_list <- replicate(10, list(dat), simplify = FALSE)<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'># fit random-effects model for each data set in list<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'># Define a function to apply metafor::rma()<br>apply_rma <- function(dat) {<br> metafor::rma(smd, se^2, data = dat, method = "ML", digits = 3)<br>}<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'># Apply the function to each element of dat_list using lapply<br>res <- lapply(dat_list, apply_rma)<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>#run selection model for each list<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'># Define a function to apply metafor::selmodel()<br>apply_selmodel <- function(x) {<br> metafor::selmodel(x, type = "beta")<br>}<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'># Apply the function to each element of res using lapply<br>sel <- lapply(res, apply_selmodel)<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'><br># Define a function to calculate the confidence interval for tau^2<br>calculate_tau2_ci <- function(model) {<br> confint(model, tau2 = TRUE)<br>}<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'># Apply the function to each element of sel using lapply<br>tau2_ci <- lapply(sel, calculate_tau2_ci)<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'># Define a function to extract df from a given model<br>extract_tau <- function(model) {<br> df <- model$random<br> return(df)<br>}<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'># Define a function to extract all tau2 from all lists<br>extract_all_df <- function(tau2_ci) {<br> all_df <- lapply(tau2_ci, extract_tau)<br> return(all_df)<br>}<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>all_tau2 <- extract_all_df(tau2_ci)<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>all_tau2<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>c <- as.data.frame(all_tau2)<br>c<o:p></o:p></span></p></div></div><div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p><div style='border:none;border-left:solid #C3D9E5 1.5pt;padding:0cm 0cm 0cm 8.0pt;margin-left:7.5pt;margin-top:7.5pt;margin-right:3.75pt;margin-bottom:3.75pt;-webkit-nbsp-mode: space;-webkit-line-break: after-white-space' name=quote><div style='margin-bottom:7.5pt'><p class=MsoNormal><b><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>Gesendet:</span></b><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> Montag, 11. März 2024 um 07:54 Uhr<br><b>Von:</b> "Tobias Saueressig via R-sig-meta-analysis" <<a href="mailto:r-sig-meta-analysis@r-project.org">r-sig-meta-analysis@r-project.org</a>><br><b>An:</b> <a href="mailto:r-sig-meta-analysis@r-project.org">r-sig-meta-analysis@r-project.org</a><br><b>Cc:</b> "Tobias Saueressig" <<a href="mailto:t.saueressig@gmx.de">t.saueressig@gmx.de</a>>, "'R Special Interest Group for Meta-Analysis'" <<a href="mailto:r-sig-meta-analysis@r-project.org">r-sig-meta-analysis@r-project.org</a>><br><b>Betreff:</b> Re: [R-meta] Extracting values from a list of confint() objects<o:p></o:p></span></p></div><div name=quoted-content><div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>Dear Will,<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>I misread and did not know that you were working with a list (!) of models. Sorry! So I changed my example a bit. <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>library(metafor)<br> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>dat <- dat.baskerville2012<br>dat<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>#create a list of dfs with 10 replications of dat<br>dat_list <- replicate(10, list(dat), simplify = FALSE)<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'># fit random-effects model for each data set in list<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'># Define a function to apply metafor::rma()<br>apply_rma <- function(dat) {<br> metafor::rma(dat$smd, dat$se^2, data = dat, method = "ML", digits = 3)<br>}<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'># Apply the function to each element of dat_list using lapply<br>res <- lapply(dat_list, apply_rma)<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>#run selection model for each list<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'># Define a function to apply metafor::selmodel()<br>apply_selmodel <- function(x) {<br> metafor::selmodel(x, type = "beta")<br>}<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'># Apply the function to each element of res using lapply<br>sel <- lapply(res, apply_selmodel)<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'># Define a function to calculate the confidence interval for tau^2<br>calculate_tau2_ci <- function(model) {<br> confint(model, tau2 = TRUE)<br>}<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'># Apply the function to each element of sel using lapply<br>tau2_ci <- lapply(sel, calculate_tau2_ci)<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'># Define a function to extract df from a given model<br>extract_tau <- function(model) {<br> df <- model$random<br> return(df)<br>}<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'># Define a function to extract all tau2 from all lists<br>extract_all_df <- function(tau2_ci) {<br> all_df <- lapply(tau2_ci, extract_df)<br> return(all_df)<br>}<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>all_tau2 <- extract_all_df(tau2_ci)<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>all_tau2<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>#put results in a df<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>c <- as.data.frame(all_tau2)<o:p></o:p></span></p></div></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p><div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>Best Regards,<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>Tobias<o:p></o:p></span></p></div><div style='border:none;border-left:solid #C3D9E5 1.5pt;padding:0cm 0cm 0cm 8.0pt;margin-left:7.5pt;margin-top:7.5pt;margin-right:3.75pt;margin-bottom:3.75pt'><div style='margin-bottom:7.5pt'><p class=MsoNormal><b><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>Gesendet:</span></b><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'> Sonntag, 10. März 2024 um 23:40 Uhr<br><b>Von:</b> "Will Hopkins via R-sig-meta-analysis" <<a href="mailto:r-sig-meta-analysis@r-project.org">r-sig-meta-analysis@r-project.org</a>><br><b>An:</b> "'R Special Interest Group for Meta-Analysis'" <<a href="mailto:r-sig-meta-analysis@r-project.org">r-sig-meta-analysis@r-project.org</a>><br><b>Cc:</b> "Will Hopkins" <<a href="mailto:willthekiwi@gmail.com">willthekiwi@gmail.com</a>><br><b>Betreff:</b> Re: [R-meta] Extracting values from a list of confint() objects<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>Tobias, that dataset appears to be for a single meta, not a set of many (simulated) metas for checking bias and coverage of the fixed effects and tau2. Nevertheless I tried the last few steps on my list of confint objects (adjusted_confint).<br><br>> #get an overview of the list, so that you can see what you need to extract<br><br>> str(adjusted_confint)<br><br>List of 2500<br><br>$ :List of 2<br><br>..$ fixed : num [1:2, 1:3] 1.5 1.74 1.05 1.1 1.95 ...<br><br>.. ..- attr(*, "dimnames")=List of 2<br><br>.. .. ..$ : chr [1:2] "intrcpt" "mods"<br><br>.. .. ..$ : chr [1:3] "estimate" "ci.lb" "ci.ub"<br><br>..$ digits: Named num [1:9] 4 4 4 4 4 4 4 4 4<br><br>.. ..- attr(*, "names")= chr [1:9] "est" "se" "test" "pval" ...<br><br>..- attr(*, "class")= chr "confint.rma"<br><br>$ :List of 2<br><br>..$ fixed : num [1:2, 1:3] 1.665 1.191 1.148 0.563 2.183 ...<br><br>.. ..- attr(*, "dimnames")=List of 2<br><br>.. .. ..$ : chr [1:2] "intrcpt" "mods"<br><br>.. .. ..$ : chr [1:3] "estimate" "ci.lb" "ci.ub"<br><br>..$ digits: Named num [1:9] 4 4 4 4 4 4 4 4 4<br><br>.. ..- attr(*, "names")= chr [1:9] "est" "se" "test" "pval" ...<br><br>..- attr(*, "class")= chr "confint.rma"<br><br>etc., etc.<br><br>I find this hard to understand, but it looks like the stats for tau2 may not be in there.<br><br>The next step didn't work:<br><br>> #extract tau2 and tau from list<br><br>> adjsel <- as.data.frame(adjusted_confint[["random"]])<br><br>> adjsel<br><br>data frame with 0 columns and 0 rows<br><br><br><br>Nor did the alternative version you suggested:<br><br>> adjsel <- as.data.frame(adjusted_confint$random)<br><br>> adjsel<br><br>data frame with 0 columns and 0 rows<br><br><br><br>However, my adjust_conflim was generated with this line of code within a function:<br><br>adjusted_confint <- confint(xxx, level=90, fixed=TRUE, random=TRUE, type="PL")<br><br><br><br>So I made it:<br><br>adjusted_confint <- confint(xxx, level=90, fixed=FALSE, tau2=TRUE, type="PL")<br><br><br><br>Now str(adjusted_confint) gave this:<br><br>$ :List of 5<br><br>..$ random : num [1:2, 1:3] 0.909 0.954 0.303 0.55 2.108 ...<br><br>.. ..- attr(*, "dimnames")=List of 2<br><br>.. .. ..$ : chr [1:2] "tau^2" "tau"<br><br>.. .. ..$ : chr [1:3] "estimate" "ci.lb" "ci.ub"<br><br>..$ digits : Named num [1:9] 4 4 4 4 4 4 4 4 4<br><br>.. ..- attr(*, "names")= chr [1:9] "est" "se" "test" "pval" ...<br><br>..$ ci.null: logi FALSE<br><br>..$ lb.sign: chr ""<br><br>..$ ub.sign: chr ""<br><br>..- attr(*, "class")= chr "confint.rma"<br><br>$ :List of 5<br><br>etc., etc.<br><br><br><br>So we're nearly there. I don’t know how to translate the above information into code that will extract the values of tau^2, tau, and their confidence limits. Your previous suggestions, adjsel <- as.data.frame(adjusted_confint[["random"]]) and adjsel <- as.data.frame(adjusted_confint$random), still gave:<br><br>data frame with 0 columns and 0 rows<br><br>And my attempts to use sapply() still don't work. I hope you can suggest something else, or point out any silly mistake I might be making.<br><br><br><br>Thanks<br><br><br><br>Will<br><br><br><br>From: R-sig-meta-analysis <<a href="mailto:r-sig-meta-analysis-bounces@r-project.org">r-sig-meta-analysis-bounces@r-project.org</a>> On Behalf Of Tobias Saueressig via R-sig-meta-analysis<br>Sent: Monday, March 11, 2024 12:42 AM<br>To: <a href="mailto:r-sig-meta-analysis@r-project.org">r-sig-meta-analysis@r-project.org</a><br>Cc: Tobias Saueressig <<a href="mailto:t.saueressig@gmx.de">t.saueressig@gmx.de</a>><br>Subject: Re: [R-meta] Extracting values from a list of confint() objects<br><br><br><br>Dear Will,<br><br><br><br>you can do the following to get the values:<br><br><br><br>install.packages("metafor")<br><br>library(metafor)<br><br><br><br>dat <- dat.baskerville2012<br>dat<br><br><br><br># fit random-effects model<br>res <- rma(smd, se^2, data=dat, method="ML", digits=3)<br>res<br><br><br><br>sel <- selmodel(res, type="beta")<br>sel<br><br><br><br>#calculate confidence interval for tau2<br>a <- confint(sel,tau2=TRUE)<br><br><br><br>#get an overview of the list, so that you can see what you need to extract<br>str(a)<br><br><br><br>#extract tau2 and tau from list<br>c <- as.data.frame(a[["random"]])<br>c<br><br><br><br>#you can also use $ to get access<br>d <- as.data.frame(a$random)<br>d<br><br><br><br>#now you can export the data e.g. to excel<br><br>install.packages("openxlsx")<br><br>library(openxlsx)<br><br><br><br># Export data to an Excel file<br><br>write.xlsx(d, "tau2_data.xlsx", rowNames = FALSE)<br><br><br><br>Best Regards,<br><br><br><br>Tobias<br><br><br><br><br><br>Gesendet: Sonntag, 10. März 2024 um 05:58 Uhr<br>Von: "Will Hopkins via R-sig-meta-analysis" < <<a href="mailto:r-sig-meta-analysis@r-project.org">mailto:r-sig-meta-analysis@r-project.org</a>> <a href="mailto:r-sig-meta-analysis@r-project.org">r-sig-meta-analysis@r-project.org</a>><br>An: "'R Special Interest Group for Meta-Analysis'" < <<a href="mailto:r-sig-meta-analysis@r-project.org">mailto:r-sig-meta-analysis@r-project.org</a>> <a href="mailto:r-sig-meta-analysis@r-project.org">r-sig-meta-analysis@r-project.org</a>><br>Cc: "Will Hopkins" < <<a href="mailto:willthekiwi@gmail.com">mailto:willthekiwi@gmail.com</a>> <a href="mailto:willthekiwi@gmail.com">willthekiwi@gmail.com</a>><br>Betreff: [R-meta] Extracting values from a list of confint() objects<br><br>With the help of ChatGPT, I have managed to extract values from a list of<br>rma() objects and values from a list of selmodel() objects derived from the<br>list of rma() objects. However, I cannot extract values from a list of<br>confint() objects derived from the selmodel() objects. I hope I am using the<br>right jargon here. If not, please be gentle, as I am still on the steep part<br>of the learning curve.<br><br><br><br>For example, this code (mysteriously) extracts tau2 from meta_results, which<br>is a list of rma objects:<br><br>tau2 <- sapply(meta_results, function(x) x$tau2).<br><br><br><br>And this code (equally mysteriously) extracts the SE of tau2 from<br>adjusted_meta, which is a list of selmodel objects derived by applying<br>selmodel() to meta_results:<br><br>seltau2se <- sapply(adjusted_meta, function(x) x$se.tau2).<br><br><br><br>But I have a list I have called adjusted_confint, which is a list of confint<br>objects derived by applying confint to the list adjusted_meta. I don't know<br>how to use sapply on this list to extract the confidence limits for tau2<br>that are contained within this list. I have "copied blindly" the syntax of<br>the other sapply statements without success. Basically I don't know what to<br>put for the x$..., and everything I have tried fails. ChatGPT was not<br>helpful here. I hope a real maven can help here. Thanks.<br><br><br><br>Will<br><br><br>[[alternative HTML version deleted]]<br><br>_______________________________________________<br>R-sig-meta-analysis mailing list @ <<a href="mailto:R-sig-meta-analysis@r-project.org">mailto:R-sig-meta-analysis@r-project.org</a>> <a href="mailto:R-sig-meta-analysis@r-project.org">R-sig-meta-analysis@r-project.org</a><br>To manage your subscription to this mailing list, go to:<br><<a href="https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis" target="_blank">https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis</a>> <a href="https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis" target="_blank">https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis</a><br><br><br>[[alternative HTML version deleted]]<br><br>_______________________________________________<br>R-sig-meta-analysis mailing list @ <a href="mailto:R-sig-meta-analysis@r-project.org">R-sig-meta-analysis@r-project.org</a><br>To manage your subscription to this mailing list, go to:<br><a href="https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis" target="_blank">https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis</a><o:p></o:p></span></p></div></div></div></div></div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Verdana",sans-serif'>_______________________________________________ R-sig-meta-analysis mailing list @ <a href="mailto:R-sig-meta-analysis@r-project.org">R-sig-meta-analysis@r-project.org</a> To manage your subscription to this mailing list, go to: <a href="https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis" target="_blank">https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis</a><o:p></o:p></span></p></div></div></div></div></div></div></body></html>