[R-sig-ME] Measurement error for mixed models

Krzysztof Bartoszek krzb@r @end|ng |rom protonm@||@ch
Fri Sep 13 11:00:48 CEST 2019


PS
The below code does not work directly
df_Dummy<-as.data.frame(matrix(rnorm(20),ncol=2,nrow=10))
df_Dummy$id<-as.factor(1:nrow(df_Dummy))
df_Dummy$merror<-rexp(10)
colnames(df_Dummy)[1:2]<-c("x","y")
df_Dummy$merror[1:4]<-0
library(metafor)
rma(y ~ x, merror, data=df_Dummy, method="ML")

## produces
## Error in rma(y ~ x, merror, data = df_Dummy, method = "ML") :
##   Division by zero when computing the inverse variance weights.
## In addition: Warning message:
## In rma(y ~ x, merror, data = df_Dummy, method = "ML") :
##   There are outcomes with non-positive sampling variances.
## Taking as I need for nlme::lme() ang mgcv::gamm()

df_Dummy$merror<-df_Dummy$merror+0.0000000001
rma(y ~ x, merror, data=df_Dummy, method="ML")

## produces
## Error in rma(y ~ x, merror, data = df_Dummy, method = "ML") :
##  Ratio of largest to smallest sampling variance extremely large.
## Cannot obtain stable results.
## and

df_Dummy$merror[1:4]<-0;df_Dummy$merror<-df_Dummy$merror+0.000001
rma(y ~ x, merror, data=df_Dummy, method="ML")

## works, hopefully the bounding away from 0 variance is not too
## large to have an effect on estimation

Krzysztof




‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Friday, September 13, 2019 8:30 AM, Krzysztof Bartoszek <krzbar using protonmail.ch> wrote:

> Thanks for the code and suggestions. Trying to run the analysis in metafor was on the TODO list. Thank you for saving me the time on figuring out the syntax.
> If I may ask for clarification, what do you mean by "the variance component is larger than 0" ?
>
> Best wishes
> Krzysztof
>
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Thursday, September 12, 2019 9:04 PM, Viechtbauer, Wolfgang (SP) wolfgang.viechtbauer using maastrichtuniversity.nl wrote:
>
> > Thanks for the feedback.
> > For what it's worth, you can fit the model with those 0 variances with metafor:
> > df_Dummy<-as.data.frame(matrix(rnorm(20),ncol=2,nrow=10))
> > df_Dummy$id<-as.factor(1:nrow(df_Dummy))
> > df_Dummy$merror<-rexp(10)
> > colnames(df_Dummy)[1:2]<-c("x","y")
> > df_Dummy$merror[1:4]<-0
> > library(metafor)
> > rma(y ~ x, merror, data=df_Dummy, method="ML")
> > This will work as long as the variance component is larger than 0.
> > Best,
> > Wolfgang



More information about the R-sig-mixed-models mailing list