Skip to content

[R-meta] question on scatter plot of estimates (Fisher's Z) against the standard error

5 messages · Gabriel Cotlier, Wolfgang Viechtbauer

#
Dear Greta and colleges,

As can be seen below, Greta has provided a nice solution to a problem I
could not solve before, which is to have as an output of metafor's package
function funnel() for plotting the funnel plot without the background of
the funnel itself, which I very slightly modified as follows:

###################
##
##.  CODE FUNNEL
##
###################

## data
ri <- c(0.5, 0.6, 0.7, 0.8, 0.9)
ni <- c(100,110,150,200,250)
dat <-escalc(measure = "ZCOR",  ri = ri, ni = ni)

## model
funnel_all <- rma.mv(yi,  vi,  data=dat)

## get max and min values for plot
#funnel_all$yi
#min(funnel_all$yi)
#max(funnel_all$yi)

## funnel plot
f1 <- funnel(funnel_all,
             back = "white",
             # shade = "white",
             yaxis = "seinv",
             level = 0,
             # ylim = c(1, 5),
             refline=0,
             main="my plot",
             ylab = "Presicion (1/SE)",
             xlim = c(0.53,1.5))
# shade = c("white", "gray55", "gray75"),
# refline = 0)
# bg = "grey")
# legend = TRUE)
#grid(NULL, NULL,lwd = 1.6)
abline(h=c(9.849, 11.316, 12.783, 14.249, 15.716 ), col="grey", lwd=1,
lty=3)
abline(v=1, col="blue", lwd=2)
abline(v=c( 0.6, 0.8, 1, 1.2, 1.4), col="grey", lwd=1, lty=3)


This has been a very efficient solution for my problem of getting exactly
the same funnel plot as the result of the metafore package
function funnel() without the funnel as a background. However, now I am
facing the challenge of having plotted the same funnel plot as the
output from the metafor's funnel() function without the background but
without the option of clustering by coloring or giving different point
shapes to the effect szes (points in the funnel plot) according to a
categorical in my data frame. I assume?probably wrongly?that for this task
I would have to reproduce the same funnel plot as is output from the funnel
plot function in the metafore package without the funnel background, as in
the code above, and use my data frame with the categorical variables to
color the points or give them different shapes and sizes using the
categorical variables in my data frame. Now the funnel plot function plots
in the x-axis the effect sizes, something I can easily get from my data
frame, but in the y-axis it uses 1/standad error (or 1 / SD). The
problem is that, as far as I understand, the standard error (SE)
corresponds to the standard deviation, or the R function sd() which gives
one value per input vector. Therefore, for some reason, plotting the effect
sizes (a vector class numeric) in the x-axis and 1/sd(effect_sizes) will
give me a number, not a vector of the same length as the effect sizes.

*Therefore, how could one reproduce the same funnel plot as in the metafore
function (without the funnel background, just a scatterplot)
with an x-axis composed of the vector of effect sizes and a y-axis with
another vector corresponding to 1/stands error (1/SE) of each element in
the x-axis--If 1/SE is is equal to 1/sd(efect_sizes) which is a scaler and
not a vector ?*

I think maybe this could be achieved somehow by giving, in the y-axis, a
kind of *"element-wise 1/SE"* to each element in the x-axis; that would be
an value corresponding to 1/SE to each of the elements in the vector of
effect sizes in the x-axis. Could this be the idea behind the funnel plot
function with 1/SE on the y-axis?

If so, can this be somehow achieved following the example provided by Greta
below?

ri <- c(0.5, 0.6, 0.7, 0.8, 0.9)
ni <- c(100,110,150,200,250)
dat <-escalc(measure = "ZCOR",  ri = ri, ni = ni)

Thanks a lot for your help and guidance.
Kind regards,
Gabriel
On Fri, Jul 21, 2023 at 9:28?AM Gabriel Cotlier <gabiklm01 at gmail.com> wrote:

            

  
  
#
Hello all,
According to:
https://www.metafor-project.org/doku.php/plots:funnel_plot_variations I
think it could be the argument:


   -

   yaxis="seinv" for the inverse of the standard errors

Is what gives the 1/SE for each element in the vector of effect sizes in
the x-axis.

How can I "stand alone"?that would be outside the metafore package or not
using the funnel function?to plot the same scatterplot of effect sizes
(x-axis) against 1/SE (y-axis) in communion and a simple R scatter
plot?without the funnel background?and afterwards use it to further cluster
by coloring or using shapes ("pch") the effect sizes according to different
categorical variables in the data frame?

Thanks a lot for your help.
Kind regards,
Gabriel
On Tue, Nov 7, 2023 at 9:13?AM Gabriel Cotlier <gabiklm01 at gmail.com> wrote:

            

  
  
#
Dear Gabriel,

The funnel() function accepts vectors for 'col' and 'pch'. So you could do:

ri <- c(0.5, 0.6, 0.7, 0.8, 0.9)
ni <- c(100,110,150,200,250)
dat <-escalc(measure = "ZCOR", ri = ri, ni = ni)
funnel_all <- rma.mv(yi,  vi,  data=dat)

grp <- c(1,2,1,1,2)
cols <- c("red","blue")
pchs <- c(19,15)
funnel(funnel_all, back=NA, level=0, refline=1, yaxis="seinv", col=cols[grp], pch=pchs[grp])
grid()
abline(v=1, col="blue", lwd=2)

Best,
Wolfgang
#
Dear Greta and colleagues:
Probably, I think I found the solution to reproduce outside the metafor
package the funnel plot without funnel background and with :
yaxis="seinv" for the inverse of the standard errors
I got the same results as in the funnel plot from the metafor package using
the inverse of the square root of the variance (not of the standard
deviation) as 1/SE, that would be:
Inv_SE <- 1/sqrt(vi_data),  where vi is the variance data.



## Greta example using metafore function funenel()
ri <- c(0.5, 0.6, 0.7, 0.8, 0.9)
ni <- c(100,110,150,200,250)
dat <-escalc(measure = "ZCOR",  ri = ri, ni = ni)
funnel_all <- rma.mv(yi,  vi,  data=dat)


png(file = "funnel_Greta_example.png",
    width = 250,
    height = 200,
    res = 600,
    units = "mm")
f1 <- funnel(funnel_all,
             back = "white",
             # shade = "white",
             yaxis = "seinv",
             level = 0,
             # ylim = c(1, 5),
             refline=0,
             main="my plot",
             ylab = "Presicion (1/SE)",
             xlim = c(0.53,1.5))
# shade = c("white", "gray55", "gray75"),
# refline = 0)
# bg = "grey")
# legend = TRUE)
#grid(NULL, NULL,lwd = 1.6)
abline(h=c(9.849, 11.316,12.783, 14.249, 15.716 ), col="grey", lwd=1, lty=3)
abline(v=1, col="blue", lwd=2)
abline(v=c( 0.6, 0.8, 1, 1.2, 1.4), col="grey", lwd=1, lty=3)
dev.off()

##

## Variance : from general model extracted
vi_data <-funnel_all$vi

## Estimates : from general model extracted estimates
yi_data <-funnel_all$yi[1:5]

## square root of the variance
SE_5 <- 1/sqrt(vi_data)

# estimates
E <-funnel_all$yi

N<-dat$ni

## construct data frame
df <- data.frame (Estimates = c(E), Standsrd_Error = c(SE_5))
View(df)
library(ggplot2)

###################################### MY PLOT
###################################

## Scatter plot
scaleFUN <- function(x) sprintf("%.2f", x)
p<- ggplot(df, aes(x=Estimates, y=Standsrd_Error)) +
  geom_point(aes(size = Estimates), alpha=0.7,  color="#2568E6")+
  scale_size_area() +
  labs(x = "Fisher's z",
       y = "Standard Error (SE)")+
  theme(plot.title = element_text(hjust = 0.5))+
  # theme(plot.margin = unit(2 ,8, 8, 2), "cm"))+
  scale_y_continuous(n.breaks = 12,labels=scaleFUN)+
  scale_x_continuous(n.breaks = 12,labels=scaleFUN)+
  geom_vline(xintercept = 0)+
  theme(axis.text.y = element_text(size = 15))+
  theme(axis.text.x = element_text(size = 15))+
  theme(axis.title.y = element_text(size = 15))+
  theme(axis.title.x = element_text(size = 15))+
  ggtitle( "Fisher's z vs. Standard Error")+
  theme(plot.title = element_text(size = 17, face = "bold"))+
  theme(legend.text = element_text(size = 15))
p
png(filename = "myExample.png", width = 28,  height = 18 ,units = "cm" ,
res =100 )
print(p)




[image: image.png]
On Tue, Nov 7, 2023 at 9:49?AM Gabriel Cotlier <gabiklm01 at gmail.com> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-meta-analysis/attachments/20231107/4b649718/attachment-0001.html>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 579878 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-meta-analysis/attachments/20231107/4b649718/attachment-0001.png>
#
Dear Wolfgang,
That is amazing; I did not know I could use the funnel() function with
the colors and pch.
Thank you very much!!!
Kind regards,
Gabriel

On Tue, Nov 7, 2023 at 11:43?AM Viechtbauer, Wolfgang (NP) <
wolfgang.viechtbauer at maastrichtuniversity.nl> wrote: