Search code examples
aggregatemetafor

Error aggregating data using "Metafor" in RStudio


I have dataset (df) for a meta-analysis which looks something like this. It is about cognitive testing at night time vs at daytime. Some studies have several outcomes, and some only have one. To the right, the hedges g (yi) and variance (vi) has been calculated for each outcome of the study.

Study_Name Time_point Time_into_session LabField test Test_outcome yi vi
Study 1 23:00-03:00 2 1 PVT RT -0.32 0.03
Study 1 03:01-06:00 5 1 PVT RT -0.27 0.03
Study 1 06:01-06:59 7 1 PVT RT 0.03 0.04
Study 1 23:00-03:00 2 1 PVT Lapse -0.88 0.16
Study 1 03:01-06:00 5 1 PVT Lapse -0.48 0.12
Study 1 06:01-06:59 7 1 PVT Lapse 0.10 0.05
Study 2 23:00-03:00 3 1 DSST Correct -0.09 0.01
Study 2 06:01-06:59 8 1 DSST Correct 0.22 0.10
Study 3 06:01-06:59 4 2 STM Correct -1.53 0.49
Study 4 03:01-06:00 5 1 PVT RT -0.71 0.15

As some studies have several reported outcomes, I want to aggregate the data into one effect size per study. However, when I do, I get the following error (I am using struct="ID" for the sake of simplicity):

gg_studycluster <- aggregate(df, cluster=Study_Name, struct="ID", addk=TRUE) Error in aggregate.data.frame(df, cluster = Study_Name, struct = "ID", : argument "FUN" is missing, with no default

This should be exactly as how it is done in the following example: https://wviechtb.github.io/metafor/reference/aggregate.escalc.html

Do any of you know what is causing this issue?

I have checked the variable type using str(df), where the yi and vi are both numeric.


Solution

  • If anyone should encounter the same issue:

    I figured out how to "fix" this. I used the "MAd" package instead.

    gg_studycluster <- agg(id = Study_name, es = yi, var = vi, method = "BHHR", cor = 0.50, data = df)

    (shows the aggregation method suited for my data).