[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 18:20:06 CEST 2023


Given the ordering of the coefficients in coef(res), this won't be possible. Look at:

print(res, num=TRUE) 

Note that coefficients 1-6 and 18 all pertain to the correlation between L2DA and the other 7 variables. These should all be together in the same column, but

vec2mat(coef(res))

doesn't know that and so coefficient 18 ends up in the wrong place. This is what I tried to explain in my previous post. First, you need to ensure that the ordering of the coefficients is such that filling them in (columnwise) into the matrix makes sense.

So you first need to rearrange the coefficients so that the first set pertains to L2DA (there are 7 of those), then the second set contains the remaining coefficients that pertain to say variable L2DF (there are 6 of those), and so on. Within each set, the order of the variables also needs to be consistent, so if you start with L2DA.L2DF, L2DA.L2G, L2DA.L2L, ..., in the first set, then the second set must start with L2DF.L2G, L2DF.L2L, ..., and so on.

Once you understand this, then setting the appropriate dimension names is obvious.

Best,
Wolfgang

>-----Original Message-----
>From: Yuhang Hu [mailto:yh342 using nau.edu]
>Sent: Tuesday, 12 September, 2023 17:36
>To: Viechtbauer, Wolfgang (NP)
>Cc: R Special Interest Group for Meta-Analysis
>Subject: Re: [R-meta] Specifying variable names in metafor::vec2mat()
>
>Thank you, Wolfgang. When you say "it depends on the ordering of the values in
>coef(res)", could you please elaborate on how exactly the user should follow that
>ordering when specifying the "dimnames=" esp. when the number of variables is
>larger?
>
>For example, below, I have 8 variables with their names being `c("L2R", "L2DA",
>"L2DF", "L2V", "L2G", "L2P", "L2M", "L2L")`. But I wonder how to order them
>correctly in "dimnames="?
>
>In fact, I think I'm getting the order for 7 of them right `c("L2DA", "L2DF",
>"L2G", "L2L", "L2M", "L2P", "L2V")` but don't know where to put "L2R" in that
>mix?
>
>dat <- read.csv("https://raw.githubusercontent.com/ilzl/i/master/j.csv")
>
>dat1 <- escalc("COR", ri = ri, ni = N, data = dat)
>
>dat2 <-
>transform(dat1,var1.var2=apply(dat1[c("var1","var2")],1,paste0,collapse="."))
>
>res <- rma(yi~var1.var2+0, 1, data=dat2)
>
>vec2mat(coef(res), dimnames = ????)
>Many thanks for your expertise,
>Yuhang
>
>On Tue, Sep 12, 2023 at 1:06 AM Viechtbauer, Wolfgang (NP)
><wolfgang.viechtbauer using maastrichtuniversity.nl> wrote:
>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