Calculating pre-post effect sizes with metafors escalc-function

Hello everyone,

I have a problem with calculating pre-post effect sizes via metafors escalc function. Here is my reprex:

within<-data.frame(
nBL_T = c(16, 16, 22, 15, 38, 38, 28, 207, 26, 15),
mBL_T = c(3.8, 3.3, 117.90, 16.07, 34.3, 60.65, 25.00, 73.26, 13.2, 35.47),
mEoT_T = c(2.1, 2.3, 74.33, 10.63, 20.32, 56.1, 14.29, 46.70, 5.1, 23),
sdBL_T = c(0.9, 1.1, 29.89, 7.46, 5.34, 6.69, 4.18, 22.18, 4.0, 8.56),
sdEoT_T = c(1.5, 1.3, 44.02, 8.12, 9.99, 9.02, 6.43, 36.84, 4.0, 10.39)
)

es_within <- escalc(measure= "SMCC", m1i= mBL_T, m2i= mEoT_T, sd1i= sdBL_T, sd2i= sdEoT_T, ri= 0.5, ni= nBL_T, data=within)

Everytime I run the code I get the Error "Supplied data vectors are not all of the same length" although I could not spot any differences in length. What am I doing wrong?

Thanks in advance!

Hi @JoJakob,
Welcome to the RStudio Community Forum.
Your ri= vector needs to have the same number of elements as the others in the dataframe (here 10).
So, this works (assuming all the correlations are = 0.5):

library(metafor)

my_df <- data.frame(
  nBL_T = c(16, 16, 22, 15, 38, 38, 28, 207, 26, 15),
  mBL_T = c(3.8, 3.3, 117.90, 16.07, 34.3, 60.65, 25.00, 73.26, 13.2, 35.47),
  mEoT_T = c(2.1, 2.3, 74.33, 10.63, 20.32, 56.1, 14.29, 46.70, 5.1, 23),
  sdBL_T = c(0.9, 1.1, 29.89, 7.46, 5.34, 6.69, 4.18, 22.18, 4.0, 8.56),
  sdEoT_T = c(1.5, 1.3, 44.02, 8.12, 9.99, 9.02, 6.43, 36.84, 4.0, 10.39)
)

my_df
str(my_df)

es_result <- escalc(measure= "SMCC", 
                    m1i= mBL_T, 
                    m2i= mEoT_T, 
                    sd1i= sdBL_T, 
                    sd2i= sdEoT_T, 
                    ri= c(rep(0.5, 10)), 
                    ni= nBL_T, 
                    data=my_df)

summary(es_result)

BTW, within() is an R function - good practice is not to name your object using a function name.
HTH

Hi Davo,
tanks a lot, this makes total sense! And your comment on naming my objects as function names is very helpful as well! :slight_smile:
Made my day!
JJ

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.