Skip to content

[R-meta] Error with rma.uni in a Monte Carlo simulation

4 messages · Will Hopkins, Michael Dewey, Guido Schwarzer +1 more

#
Chat GPT helped me to write the code to analyze 5000 simulated datasets I
had created in SAS. It worked fine for a small number of simulations, but
when I ran it for 5000, I got an error and no results.  See below for the
code, due mainly to ChatGPT (I added the control statement in a failed
attempt to get past the error, after I consulted the documentation),
followed by the error message. Can someone tell me how to get past the
error? When an analysis fails in SAS with "by Sim" processing, it simply
doesn't output that particular dataset.  Thanks heaps.

 

Will

 

# Function to perform meta-analysis using rma.uni

perform_meta_analysis <- function(xxx) {

  # Perform meta-analysis using rma.uni

  meta_analysis <- rma.uni(yi = xxx$Ydelta, vi = xxx$YdeltaSEsq,
mods=xxx$Female01, control=list(maxiter=400))

  

  # Return results

  return(meta_analysis)

}

 

# List to store meta-analysis results

meta_results <- list()

 

# Perform meta-analysis for each dataset

for (i in 1:max(data$Sim)) {

  # Subset data for the current meta-analysis

  meta_data <- subset(data, Sim == i)

 

  # Perform meta-analysis using rma.uni

  result <- perform_meta_analysis(meta_data)

  # Store result

  meta_results[[i]] <- result

}

 

Here's the error:

Error in rma.uni(yi = xxx$Ydelta, vi = xxx$YdeltaSEsq, mods = xxx$Female01,
: 

  Fisher scoring algorithm did not converge. See 'help(rma)' for possible
remedies.
#
?try

will probably help

Michael
On 06/03/2024 05:58, Will Hopkins via R-sig-meta-analysis wrote:
#
To elaborate a bit on using try(). The following code uses the DerSimonian-Laird estimator if the REML estimation fails.

m <- try(rma.uni(...))
if (inherits(m, "try-error"))
 m <- try(rma.uni(..., method = "DL"))

Best,
Guido
#
Even easier:

rma(..., method = c("REML","DL"))

I've added functionality to rma() to have a fall-back in case something like REML doesn't converge.

See:

https://wviechtb.github.io/metafor/reference/rma.uni.html#note-1

With respect to convergence, there is also a thorough discussion here:

https://www.metafor-project.org/doku.php/tips:convergence_problems_rma

Best,
Wolfgang