GLMM's for meta-analysis - error using metabin - r
I'm trying to run a generalised linear mixed effects (binomial-normal) meta-analysis for 7 randomised studies, where each study records the presence of an adverse event within the treatment and placebo populations (exposure and control).
To do this, I'm hoping to use the metabin function (meta package). However, I'm getting an error and I'm not sure why. E.g. running this code:
install.packages('meta')
# Data
data<-data.frame(exposure.events=c(11,34,152,4,60,3,25), exposure.population=c(184,152,9500,77,2012,15,60), control.events=c(3,33,4729,133,1441,1,25), control.population=c(184,375,613978,15865,480485,105,238), Study=c("1","2","3","4","5","6","7"))
# Calling metabin
metabin(event.e=exposure.events, n.e=exposure.population, event.c=control.events, n.c=control.population, studlab=Study, data=data, method="GLMM",model.glmm = "CM.AL",method.tau = "ML")
I get this output:
Error in metafor::rma.glmm(ai = event.e[!exclude], n1i = n.e[!exclude], :
Cannot fit ML model.
I've also tried calling the rma.glmm function directly (instead of doing this via metabin), but get the same error message. I've also tried reading the source code for rma.glmm but I'm not sure I understand what's going on. However, I think the issue is related to the third study (the largest), and in particular the size of the control population, as both of the following run smoothly:
# Modifying 3rd row's control population
data<-data.frame(exposure.events=c(11,34,152,4,60,3,25), exposure.population=c(184,152,9500,77,2012,15,60), control.events=c(3,33,4729,133,1441,1,25), control.population=c(184,375,61378,15865,480485,105,238), Study=c("1","2","3","4","5","6","7"))
metabin(event.e=exposure.events, n.e=exposure.population, event.c=control.events, n.c=control.population, studlab=Study, data=data, method="GLMM",model.glmm = "CM.AL",method.tau = "ML")
# Deleting 3rd row
data<-data.frame(exposure.events=c(11,34,4,60,3,25), exposure.population=c(184,152,77,2012,15,60), control.events=c(3,33,133,1441,1,25), control.population=c(184,375,15865,480485,105,238), Study=c("1","2","3","4","5","6"))
metabin(event.e=exposure.events, n.e=exposure.population, event.c=control.events, n.c=control.population, studlab=Study, data=data, method="GLMM",model.glmm = "CM.AL",method.tau = "ML")
Is this a convergence problem, and does anyone know if there is any way around this? The only other thing I can find about this error message is for a problem (and thus solution) which does not apply to me.
Any help would be really appreciated :)
Related
Error in "getCovariate.corSpatial" with gamm function
I am trying to eliminate spatial autocorrelation using the gamm function using the following code: model.data.cp.gamm.exp<-gamm(CP~s(YEAR), random=list(Ambience=~1), corSpatial(form=~Lat+Lon, type="exp", metric="euc"), data=data) Sometimes I change the type to lin, rat, sph and gau. However, for all cases, I keep getting the error: Error in getCovariate.corSpatial(object, data = data) : cannot have zero distances in "corSpatial" Although I have removed all duplicate coordinates within each year from my data, some are repeated over time and there is no way for me to change that. Does anyone know how to fix this error? Thank you!
No missing values in data, still getting this error with boot()--> Error in if (const(t, min(1e-08, mean(t, na.rm = TRUE)/1e+06)))
EDIT: Just wanted to let you all know I figured out the issue-- the indirects function I was using indicated that the boot function should use the 6th regression coefficient in the linear regression model to do its things but it turns out I only had five coefficients in this particular model. Whoops, haha. Thank you to everyone who helped me troubleshoot this! I know this issue has been addressed in past posts (here and here) but I have not been able to resolve it using the answers given there. The first post said that there was a NA in t but I didn't know what t was. The second post said to remove missing values from the variables you're using, but I've checked and none of my variables have missing values. I know I need to give a "reproducible example" (meaning I would need to upload the data set, yes?) but I can't figure out how to upload data to a question. I have checked StackOverflow's help center, FAQ's, and advanced editing help page. I would really, really appreciate it if someone could explain to me how to upload R data in order to give a reproducible example. The code I am using is: indirects = function(data,indices) { return(lm(monin2$directharm~monin2$racismc*monin2$vig+monin2$manip)$coef[6] * lm(monin2$hatecrime~monin2$racismc*monin2$vig+monin2$manip+monin2$directharm,data=data,subset=indices)$coef[6]) } b = boot(data=monin2,statistic=indirects,R=5000) ci = boot.ci(b,conf=.95,type="bca") b ci The error it produces is Error in if (const(t, min(1e-08, mean(t, na.rm = TRUE)/1e+06))) { : missing value where TRUE/FALSE needed I used the following code to check if any of my variables had missing values, and my interpretation of the output is that no missing values exist in any of them: which (is.na(monin2$hatecrime)) integer(0) > which (is.na(monin2$directharm)) integer(0) > which (is.na(monin2$vig)) integer(0) > which (is.na(monin2$manip)) integer(0) > which (is.na(monin2$racismc)) integer(0)
The following code picks out the sixth coefficient in the linear regression model for boot() to use, but in this particular model I only have five coefficients, so I was asking boot() to use a variable that didn't exist. indirects = function(data,indices) { return(lm(monin2$directharm~monin2$racismc*monin2$vig+monin2$manip)$coef[6] * lm(monin2$hatecrime~monin2$racismc*monin2$vig+monin2$manip+monin2$directharm,data=data,subset=indices)$coef[6]) }
Error in aeqSurv(Y) : aeqSurv exception, an interval has effective length 0
I'm using R's coxph function to fit a survival regression model, and I'm trying to model time dependent covariates (see this vignette). When fitting the model, I get the following error: Error in aeqSurv(Y) : aeqSurv exception, an interval has effective length 0 Other than the source code, I couldn't find any references to this error online. Would appreciate any ideas about how to handle this exception.
I found the same error. Probably the cause is the aeqSurv routine that treats time values such that tiny differences are treated as a tie. This is actually useful and the error is potentially pointing an issue with the data. However, if we need to force a solution you can use the coxph.options. Just setting timefix = FALSE in the call to coxph should make the trick! Source: https://rdrr.io/cran/survival/src/R/aeqSurv.R
I had this error after I used the survSplit function to make time intervals, prior to fitting with coxph. I noticed that survSplit introduced trailing digits (i.e., 20 days turned into 20.0 days). So I removed those digits with the round function and it worked.
Like the above answer, adding the control variable in the coxph function should solve the problem. Please see the reference: https://github.com/therneau/survival/issues/76 model <- coxph(formula = Surv(time1, time2, event) ~ cluster(cluster), data = dataframe, control = coxph.control(timefix = FALSE)) # add the control variable
Piecewise regression : Reproducibility problems on breakpoints detection in segmented R package
I'm trying to fit a 3 pieces regression on my data with the help of the segmented package, and I'm a bit lost... First : here is a reproducible example : y=c(520.0000, 620.0000, 653.3333, 853.3333, 1220.0000, 1553.3333, 1586.6667, 1586.6667, 1586.6667, 1586.6667, 1586.6667) x=c(33320, 41020, 49020, 56920, 69220, 76320, 86320, 95420, 103720, 111520, 120320) plot(y~x) out=lm(y~x) My data with 2 visible breakpoints : - First I tried specifying the known number of breakpoints with K=2 : mdl2=segmented(out, seg.Z =~x, psi=NA, control=seg.control(K=2,n.boot=0,it.max=500,stop.if.error=FALSE,display=T)) plot(mdl2) points(y~x) Which gives me, a 1 breakpoint result : - But if I set 2<K<8 (so a wrong value...), I'm able to detect the right number of breakpoints : - And a last point which puzzles me : If I set K=4, the display=T option show me a result with 3 breakpoints, but in the function output I still have two breakpoints... ******EDIT OF THE 09/19/2016****** I tried also by specifying psi directly as I've some priors on the breakpoints location (but it's not my goal), and the results are still really bad with segmented... For some regression I've to run the function many times before the algorithm success to end with a solution. Also, the solutions proposed have often reproducibility problems... Does anyone know a way to robustly estimate these breakpoints ? It looks like my data are not that hard to fit, isn't it ?
Arguments length error when trying to test model using party package in R
I have divided my data set into two groups: transactions.Train (80% of the data) transactions.test (20% of the data) Then I built the decision tree using ctree method from party package as follow: transactions.Tree <- ctree(dt_formula, data=transactions.train) And I can successfully apply predict method on the training set and use table function to output the result as follow: table(predict(transactions.Tree), transactions.train$Satisfaction) But my problem occurs when I try to output the table based on the testing set as follow: testPred <- predict(transactions.Tree, newdata=transactions.test) table(testPred, transactions.test$Satisfaction) And the error is as follow: Error in table(predict(pred = svm.pred, transactions.Tree), transactions.test$Satisfaction) : all arguments must have the same length I have done research on similar cases which suggested omitting any NA values which I did without changing the error outcome. Can anyone help me by poniting out what's the problem here?