[R-meta] question on scatter plot of estimates (Fisher's Z) against the standard error
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:
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 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:
Dear Greta, Thank you very much. The code you provided for the funnel plot is exactly what I was looking for. I just changed my refline to zero and adjusted the xlim to the interval [-4 6], so it is exactly the same as the metafor::funnel plot but without all the background, keeping only the scattering of the points. Thanks a lot again. Kind regards, Gabriel On Thu, Jul 20, 2023 at 11:21?PM Dr. Gerta R?cker < gerta.ruecker at uniklinik-freiburg.de> wrote:
Dear Gabriel, Both plots are correct and equivalent (though I like the metafor plot much more). If it is only to get rid of the confidence region, why don't you use the funnel() function of metafor and suppress all elements you don't want? For example, try (object funnel_all taken from your R code, fictitious data coming from me, as you did not provide them!) 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) funnel(funnel_all, back = "white", shade = "white", level = 0, xlim = c(0.5,1.6), refline = 2) The xlim argument is used to fix the x-axis range, while putting the refline outside the visible region (simply a trick, I couldn't find an argument to determine the refline's color). You may also change the y-axis range, e.g., funnel(funnel_all, back = "white", shade = "white", level = 0, xlim = c(0.5,1.6), refline = 2, ylim = c(0.06, 0.105)) if you think this makes sense. With respect to the inverted axis, see Michael's post. Best, Gerta UNIVERSIT?TSKLINIKUM FREIBURG Institute for Medical Biometry and Statistics Dr. Gerta R?cker Guest Scientist Stefan-Meier-Stra?e 26 ? 79104 Freiburg gerta.ruecker at uniklinik-freiburg.de https://www.uniklinik-freiburg.de/imbi-en/employees.html?imbiuser=ruecker -----Urspr?ngliche Nachricht----- Von: R-sig-meta-analysis <r-sig-meta-analysis-bounces at r-project.org> Im Auftrag von Gabriel Cotlier via R-sig-meta-analysis Gesendet: Donnerstag, 20. Juli 2023 16:28 An: Michael Dewey <lists at dewey.myzen.co.uk> Cc: Gabriel Cotlier <gabiklm01 at gmail.com>; R Special Interest Group for Meta-Analysis <r-sig-meta-analysis at r-project.org> Betreff: Re: [R-meta] question on scatter plot of estimates (Fisher's Z) against the standard error Dear Michael, Here is the code below: Thanks a lot. Kind regards, Gabriel ## Transformation of Pearson's Product-moment correlation coefficient (r) to Fisher's Z dat <-escalc(measure = "ZCOR", ri = ri, ni = ni, data = dat) ## funnel_all <- rma.mv(yi, vi, # mods = ~ Type, random = ~ 1 | Article / Sample_ID, data=dat) funnel_all ## funnel plot form metafor funnel(funnel_all) ## Variance : from general model extracted vi_data <-funnel_all$vi ## Estimates : from general model extracted estimates yi_data <-funnel_all$yi[1:150] ## calculate standard error SE: square root of the variance SE<- sqrt(vi_data) # estimates E <-funnel_all$yi ## construct data frame df <- data.frame (Estimates = c(E), Standsrd_Error = c(SE)) View(df) library(ggplot2) ## 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 = "myplot.png", width = 28, height = 18 ,units = "cm" , res =100 ) print(p) dev.off() On Thu, Jul 20, 2023 at 4:51?PM Michael Dewey <lists at dewey.myzen.co.uk> wrote:
Dear Gabriel Comments in-line On 20/07/2023 05:55, Gabriel Cotlier wrote:
Dear Michael, I think you are completely right, in the fact, the plot I am
producing
is indeed valid for the purpose for which I want to use it, meaning
it
is representative of the relationship I want to show. Therefore, I assume that the plot I am getting, is supposed to be sufficient. However, I receive from the function metafore:: funnel (model), for
a
model without modierators, a very nice representation of the
scarring of
the observed outcomes or the estimates (x axis), as a function of
the SE
(e.i., square root of the sampling variance, SE assumef to have a
pseudo
confidence interval region drawn around each of its values). While,
when
I plot by myself x = observed outcomes y = square root of the sampling variance, Then the plot shows that: a. the scattering of the points appears upside down with respect
to the
output of the function metafore:: funnel (model),
I have already answered that one in a previous post. It is just the convention
b. the scale of the y axis, instead of having a defined top at zero
and
from there values are represented downwards, the scale is different.
Without your code it is hard to tell but I suspect you are not
plotting
what you think you are. Are you plotting the inverse of the se? Michael
Anyways, I started thinking that in any case, such a difference in
the
plot I am doing by myself is not necessarily wrong, but is just a different way of representing the data. Just the scattering of the points in one case looks like the upside down scattering of the
other.
And I assume this is because maybe the function metafore::funnel() applies some operation on the square root of the mean (y axis) that
I
presume is the calculation of the aforementioned pseudo confidence interval for each value, but I am not sure. Thanks a lot for your response. Kind regards, Gabriel On Wed, Jul 19, 2023 at 7:20?PM Michael Dewey <
lists at dewey.myzen.co.uk
<mailto:lists at dewey.myzen.co.uk>> wrote:
I am sorry Gabriel but I do not understand why the plot you say
you
produced fails to do what you say you want.
Michael
On 19/07/2023 10:59, Gabriel Cotlier wrote:
> Hello Michael,
> Thank you very much for your response.
> I just would like to show that the of data set I have has
high
> uncertainty given that no possible pattern is observable or
detectable
> and no order is possible to visulize in the scattering,
> I thought that a plot with x axis = fisher's z observed
> outcomes (estimates) and y axis = standard error or any
other measure of
> uncertainty could at least visually demostrate that
assumption.
> If such a lack of pattern or high uncertainty in the data
set can
also
> be demonstrated numerically, even better.
> Kind regards,
> Gabriel
>
> On Wed, Jul 19, 2023 at 12:29?PM Michael Dewey
<lists at dewey.myzen.co.uk <mailto:lists at dewey.myzen.co.uk>
> <mailto:lists at dewey.myzen.co.uk
<mailto:lists at dewey.myzen.co.uk>>> wrote:
>
> Dear Gabriel
>
> I am not realy sure what you are trying to do but one
point
which
> occurs
> to me is that forest plots are conventional plotted with
small
> values of
> standard error at the top.
>
> Michael
>
> On 19/07/2023 06:07, Gabriel Cotlier via
R-sig-meta-analysis
wrote:
> > Dear all,
> >
> > I have already posted this question with no response.
> > Maybe this time I am luckier and someone with more
knowledge than
> me in the
> > Metafor package can answer me.
> >
> > In a nutshell, what I would like is to be able to
produce a
> scatter plot of
> > the observed oucomes or the estimates, in my case
Fisher's
z for
> the x axis
> > and the standard error in the y axis, with the
standard
error
> (SE) the
> > same as it appears when running the funnel() function
for a
> funnel plot
> > with the model (without moderators) as the input
argument.
> Actually, it is
> > a funnel plot without the background of the funnel
distribution
> but just
> > the scatter of points, that is suppressing the funnel
distribution on
> > the background.
> >
> > I tried to do so in agreement with the definition of
SE
used for
> the funnel
> > plot in the package Vignette published at Journal of
Scientific
> software in
> > page 26:
> >
> > "*For models without moderators, the figure shows the
observed
> outcomes on
> > the horizontal axis against their corresponding
standard
errors
> (i.e., the
> > square root of the sampling variances) on the vertical
axis. A
> vertical
> > line indicates the **estimate based on the model. A
pseudo
confidence
> > interval region is drawn around this value with bounds
equal to
> ?1.96 ? SE,
> > where SE is the standard error value from the vertical
axis.*"
> >
> >
> > I tried to reproduce the vertical axis (y) using the
square root
> of the
> > sampling variable, but the result was an upside down
scaling of the
> > observed outcomes or estimates on a different y scale
for
the x
> ticks. The
> > plot seems to have similarities with the funnel plot
from
the
> funnel()
> > function, but it is not exactly the same without the
background
> of the
> > funnel distribution graphic. Maybe the problem could
be
that in the
> > funnel() function, contrary to my simple attempt to
imitate it
> with the
> > square root of the sampling variable, the pseudo
confidence
> interval is
> > estimated for each value? Could this be the reason?
> >
> >
> > If so, how could I reproduce the funnel () function
plot
without
> the funnel
> > distribution graphic in the background and just the
scattering of the
> > points using the same pseudo-confidence interval?
> >
> >
> > Thanks a lot for your help and assistance.
> >
> > Kind regards,
> >
> > Gabriel
> >
> > [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-sig-meta-analysis mailing list @
> R-sig-meta-analysis at r-project.org
<mailto:R-sig-meta-analysis at r-project.org>
> <mailto:R-sig-meta-analysis at r-project.org
<mailto:R-sig-meta-analysis at r-project.org>>
> > To manage your subscription to this mailing list, go
to:
> >
https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis <https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis> > < https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis <https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis>> > > > > -- > Michael > http://www.dewey.myzen.co.uk/home.html <http://www.dewey.myzen.co.uk/home.html> > <http://www.dewey.myzen.co.uk/home.html <http://www.dewey.myzen.co.uk/home.html>> > > > < http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient < http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient Virus-free.www.avg.com <http://Virus-free.www.avg.com> < http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient < http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient > > <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> -- Michael http://www.dewey.myzen.co.uk/home.html <http://www.dewey.myzen.co.uk/home.html> -- Michael http://www.dewey.myzen.co.uk/home.html [[alternative HTML version deleted]] _______________________________________________ R-sig-meta-analysis mailing list @ R-sig-meta-analysis at r-project.org To manage your subscription to this mailing list, go to: https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis
-------------- 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>