[R-meta] Specifying variable names in metafor::vec2mat()

Viechtbauer, Wolfgang (NP) wo||g@ng@v|echtb@uer @end|ng |rom m@@@tr|chtun|ver@|ty@n|
Tue Sep 12 10:06:42 CEST 2023


Dear Yuhang,

Since coef(res) is of length 6, vec2mat() will put these values (i.e., the estimated average correlations) into a 4x4 (correlation) matrix. Given the ordering of the values in coef(res), the appropriate dimension names would be something like this:

vec2mat(coef(res), dimnames=c("acog","asom","conf","perf"))

However, there is no general rule for this, as it depends on the ordering of the values in coef(res).

I have tried to make various functions in metafor behave in a consistent manner when it comes to ordering certain elements, but in this case, it is really up to the user to check that adding dimension names even makes sense for the resulting matrix. For example:

vec2mat(sample(coef(res)))

is perfectly fine in principle (albeit a bit weird), but it no longer makes sense to say that all values in the first column/row pertain to the correlations between one of the four variables and the other three variables (unless you get lucky) and so on.

But say the coefficients had been ordered like this:

coef(res)[c(3,5,6,1,2,4)]

Then the appropriate dimension names would be:

vec2mat(coef(res)[c(3,5,6,1,2,4)], dimnames=c("perf","acog","asom","conf"))

Best,
Wolfgang

>-----Original Message-----
>From: R-sig-meta-analysis [mailto:r-sig-meta-analysis-bounces using r-project.org] On
>Behalf Of Yuhang Hu via R-sig-meta-analysis
>Sent: Monday, 11 September, 2023 5:32
>To: R meta
>Cc: Yuhang Hu
>Subject: [R-meta] Specifying variable names in metafor::vec2mat()
>
>Hello Everyone,
>
>I'm using the metafor::vec2mat() as shown in the toy example below.
>However, I wonder how I should specify the order of the variables' names
>defined in "dimnames=" when converting the vector of coefficients to a
>correlation matrix using metafor::vec2mat()?
>
>Is there generally a rule or a technique to order the variables' names
>correctly in "vec2mat()", especially if there are many variable names?
>
>Thanks,
>Yuhang
>
># EXAMPLE:
>tmp <- rcalc(ri ~ var1 + var2 | study, ni=ni, data=dat.craft2003)
>V <- tmp$V
>dat <- tmp$dat
>
>res <- rma.mv(yi~ var1.var2 - 1, V,
>              random = ~  var1.var2| study, struct = "UN",
>              data=dat)
>
>vec2mat(coef(res), dimnames= ??????)



More information about the R-sig-meta-analysis mailing list