Showing posts with label GLMM. Show all posts
Showing posts with label GLMM. Show all posts
Thursday, May 09, 2013
Glmer2stan
Glmer2stan is an interesting software that translates glmer (lme4) syntax into Stan. The software is still at eary stage but looks very promising.
Monday, June 21, 2010
A question
I posted a question to the R-Mixed-Model mailing list but have not had any responses yet:
---------------------------------------------------------------------------------------
Here is the answer from Jens Åströ
---------------------------------------------------------------------------------------
Hi!
Not an expert by any means, but I got it to run by doing this:
1) change inprod2 to inprod in the model file (JAGS does not have
inprod2 function)
2) change ~dflat() to other uninformative prior, e.g.
~dnorm(0.0,1.0E-6) (Jags does not have dflat distribution)
3) specify/compile the model with e.g.
bac.jags<-jags.model("model.bug",data=bacrag$ragged,n.chains=4)
4) update it, update(bac.jags,1000)
5) Collect coda samples,
bacResult<-coda.samples(temp,names(getInits()),n.iter=10000,thin=10)
This seemed to converge well, (gelman.diag(bacResult))
Good luck
----------------------------------------------------------------------------------------
It works.
---------------------------------------------------------------------------------------
Dear All,
I wonder if anybody has tried to make glmmBUGS work with JAGS. My
attempt was not successful.
Here is the simple example I copied from the glmmBUGS Vignettes:
------------------------
library(MASS)
data(bacteria)
bacterianew <- bacteria
bacterianew$yInt = as.integer(bacterianew$y == "y")
levels(bacterianew$trt) <- c("placebo", "drug", "drugplus")
library(glmmBUGS)
bacrag <- glmmBUGS(formula = yInt ~ trt + week, data=bacterianew,
effects = "ID",
modelFile="model.bug", family="bernoulli")
names(bacrag$ragged)
source("getInits.R")
startingValues = bacrag$startingValues
------------------------
With WinBUGS, it runs well:
------------------------
library(R2WinBUGS)
bacResult1 = bugs(bacrag$ragged, getInits, model.file="model.bug", n.chain=3,
n.iter=2000, n.burnin=100, parameters=names(getInits()), n.thin=10)
------------------------
But with JAGS, I got error message "Error in FUN(50L[[1L]], ...) :
invalid first argument"
------------------------
library(R2jags)
jags.parms=names(getInits())
bacResult = jags(data=bacrag$ragged, n.chain=3, n.iter=2000,
model.file=model.bug)
------------------------
I hope somebody can help me figuring out how to make this work. Many thanks.
Best,
Shige
---------------------------------------------------------------------------------------Here is the answer from Jens Åströ
---------------------------------------------------------------------------------------
Hi!
Not an expert by any means, but I got it to run by doing this:
1) change inprod2 to inprod in the model file (JAGS does not have
inprod2 function)
2) change ~dflat() to other uninformative prior, e.g.
~dnorm(0.0,1.0E-6) (Jags does not have dflat distribution)
3) specify/compile the model with e.g.
bac.jags<-jags.model("model.bug",data=bacrag$ragged,n.chains=4)
4) update it, update(bac.jags,1000)
5) Collect coda samples,
bacResult<-coda.samples(temp,names(getInits()),n.iter=10000,thin=10)
This seemed to converge well, (gelman.diag(bacResult))
Good luck
----------------------------------------------------------------------------------------
It works.
Friday, March 05, 2010
GLMM revisted
A short while ago, I reported some discrepancies between the results produced by "lme4" and other R packages as well as Stata. Today I upgraded to the most recent version of "lme4a" and re-ran my model. The error of false convergence disappeared and the new results are very much in line with other packages.
I am glad that the problem eventually got sorted out.
For this version, the adaptive GH quadrature has not been implemented yet; so the only option to estimate a GLMM is laplace transformation.
I am glad that the problem eventually got sorted out.
For this version, the adaptive GH quadrature has not been implemented yet; so the only option to estimate a GLMM is laplace transformation.
Saturday, February 27, 2010
An interesting paper
Ben Bolker has an interesting paper (outline of a paper) comparing different approaches to estimate GLMM in R environment, which is very helpful to what I am doing right now.
The paper pointed out the following options to fit GLMM using R:
The paper pointed out the following options to fit GLMM using R:
- glmer
- glmmML
- glmm (from the repeated package)
- glmmADMB
- MCMCglmm
- glmmBUGS
- glmmPQL
- BUGS (through R2WinBUGS)
- glmmAK
And I would like to add one more, npmlreg.
I am not aware of the glmmAK package before. From the first glance, it seems to be very promising in the sense that it seems to allow non-Gaussian random effect in a Bayesian framework, something similar to what npmlreg does with ML method.
============== edited on March 3 ====================
DPpackage is another package that can estimate GLMM in a Bayesian framework.
============== edited on March 5 ====================
ASReml/ASReml-R is another choice. It is not free software, but it does seem to have some unique strengths. Maybe I should download a demo copy and try it myself.
============== edited on March 29 ===================
hglm is another possibility.
I am not aware of the glmmAK package before. From the first glance, it seems to be very promising in the sense that it seems to allow non-Gaussian random effect in a Bayesian framework, something similar to what npmlreg does with ML method.
============== edited on March 3 ====================
DPpackage is another package that can estimate GLMM in a Bayesian framework.
============== edited on March 5 ====================
ASReml/ASReml-R is another choice. It is not free software, but it does seem to have some unique strengths. Maybe I should download a demo copy and try it myself.
============== edited on March 29 ===================
hglm is another possibility.
Tuesday, February 16, 2010
Generalized linear mixed effect model problem
I am trying to compare cohort difference in infant mortality using generalized linear mixed model. I first estimated the model in Stata:
xi:xtlogit inftmort i.cohort, i(code)
which converged nicely:
Fitting comparison model:
Iteration 0: log likelihood = -1754.4476
Iteration 1: log likelihood = -1749.3366
Iteration 2: log likelihood = -1749.2491
Iteration 3: log likelihood = -1749.2491
Fitting full model:
tau = 0.0 log likelihood = -1749.2491
tau = 0.1 log likelihood = -1743.8418
tau = 0.2 log likelihood = -1739.0769
tau = 0.3 log likelihood = -1736.4914
tau = 0.4 log likelihood = -1739.5415
Iteration 0: log likelihood = -1736.4914
Iteration 1: log likelihood = -1722.6629
Iteration 2: log likelihood = -1694.9114
Iteration 3: log likelihood = -1694.6509
Iteration 4: log likelihood = -1694.649
Iteration 5: log likelihood = -1694.649
Random-effects logistic regression Number of obs = 21694
Group variable: code Number of groups = 10789
Random effects u_i ~ Gaussian Obs per group: min = 1
avg = 2.0
max = 9
Wald chi2(2) = 8.05
Log likelihood = -1694.649 Prob > chi2 = 0.0178
------------------------------------------------------------------------------
inftmort | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_Icohort_2 | -.5246846 .1850328 -2.84 0.005 -.8873422 -.1620269
_Icohort_3 | -.1424331 .140369 -1.01 0.310 -.4175513 .132685
_cons | -5.214642 .1839703 -28.35 0.000 -5.575217 -4.854067
-------------+----------------------------------------------------------------
/lnsig2u | .9232684 .1416214 .6456956 1.200841
-------------+----------------------------------------------------------------
sigma_u | 1.586665 .1123528 1.381055 1.822885
rho | .4335015 .0347791 .3669899 .5024984
------------------------------------------------------------------------------
Likelihood-ratio test of rho=0: chibar2(01) = 109.20 Prob >= chibar2 = 0.000
Then I tried the same model using lme4:
m2 <- glmer(inftmort ~ (1|code) + as.factor(cohort), family=binomial, data=d)
I got:
Warning message:
In mer_finalize(ans) : false convergence (8)
And the results are quite different from what I got from Stata. I tried to estimate the model using "glmmML" and also got into trouble. This time the error message is:
Warning message:
In glmmML.fit(X, Y, weights, cluster.weights, start.coef, start.sigma, :
Hessian non-positive definite. No variance!
I then tried MCMCglmm:
prior=list(R=list(V=1, nu=0, fix=1), G=list(G1=list(V=1, nu=0)))
m2 <- MCMCglmm(inftmort ~ 1 + as.factor(cohort), random=~code, family = "categorical", data=d, prior=prior)
It seems to be working and produced estimates that are comparable to what Stata produced (not identical, of course):
Iterations = 3001:12991
Thinning interval = 10
Number of chains = 1
Sample size per chain = 1000
1. Empirical mean and standard deviation for each variable,
plus standard error of the mean:
Mean SD Naive SE Time-series SE
(Intercept) -5.7145 0.1805 0.005708 0.02295
as.factor(cohort)2 -0.5633 0.1788 0.005653 0.02194
as.factor(cohort)3 -0.1888 0.1471 0.004653 0.01912
2. Quantiles for each variable:
2.5% 25% 50% 75% 97.5%
(Intercept) -6.0464 -5.8324 -5.7251 -5.61120 -5.2817
as.factor(cohort)2 -0.8977 -0.6985 -0.5551 -0.43084 -0.2371
as.factor(cohort)3 -0.4614 -0.2947 -0.1867 -0.09644 0.1232
This is puzzling.
xi:xtlogit inftmort i.cohort, i(code)
which converged nicely:
Fitting comparison model:
Iteration 0: log likelihood = -1754.4476
Iteration 1: log likelihood = -1749.3366
Iteration 2: log likelihood = -1749.2491
Iteration 3: log likelihood = -1749.2491
Fitting full model:
tau = 0.0 log likelihood = -1749.2491
tau = 0.1 log likelihood = -1743.8418
tau = 0.2 log likelihood = -1739.0769
tau = 0.3 log likelihood = -1736.4914
tau = 0.4 log likelihood = -1739.5415
Iteration 0: log likelihood = -1736.4914
Iteration 1: log likelihood = -1722.6629
Iteration 2: log likelihood = -1694.9114
Iteration 3: log likelihood = -1694.6509
Iteration 4: log likelihood = -1694.649
Iteration 5: log likelihood = -1694.649
Random-effects logistic regression Number of obs = 21694
Group variable: code Number of groups = 10789
Random effects u_i ~ Gaussian Obs per group: min = 1
avg = 2.0
max = 9
Wald chi2(2) = 8.05
Log likelihood = -1694.649 Prob > chi2 = 0.0178
------------------------------------------------------------------------------
inftmort | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_Icohort_2 | -.5246846 .1850328 -2.84 0.005 -.8873422 -.1620269
_Icohort_3 | -.1424331 .140369 -1.01 0.310 -.4175513 .132685
_cons | -5.214642 .1839703 -28.35 0.000 -5.575217 -4.854067
-------------+----------------------------------------------------------------
/lnsig2u | .9232684 .1416214 .6456956 1.200841
-------------+----------------------------------------------------------------
sigma_u | 1.586665 .1123528 1.381055 1.822885
rho | .4335015 .0347791 .3669899 .5024984
------------------------------------------------------------------------------
Likelihood-ratio test of rho=0: chibar2(01) = 109.20 Prob >= chibar2 = 0.000
Then I tried the same model using lme4:
m2 <- glmer(inftmort ~ (1|code) + as.factor(cohort), family=binomial, data=d)
I got:
Warning message:
In mer_finalize(ans) : false convergence (8)
And the results are quite different from what I got from Stata. I tried to estimate the model using "glmmML" and also got into trouble. This time the error message is:
Warning message:
In glmmML.fit(X, Y, weights, cluster.weights, start.coef, start.sigma, :
Hessian non-positive definite. No variance!
I then tried MCMCglmm:
prior=list(R=list(V=1, nu=0, fix=1), G=list(G1=list(V=1, nu=0)))
m2 <- MCMCglmm(inftmort ~ 1 + as.factor(cohort), random=~code, family = "categorical", data=d, prior=prior)
It seems to be working and produced estimates that are comparable to what Stata produced (not identical, of course):
Iterations = 3001:12991
Thinning interval = 10
Number of chains = 1
Sample size per chain = 1000
1. Empirical mean and standard deviation for each variable,
plus standard error of the mean:
Mean SD Naive SE Time-series SE
(Intercept) -5.7145 0.1805 0.005708 0.02295
as.factor(cohort)2 -0.5633 0.1788 0.005653 0.02194
as.factor(cohort)3 -0.1888 0.1471 0.004653 0.01912
2. Quantiles for each variable:
2.5% 25% 50% 75% 97.5%
(Intercept) -6.0464 -5.8324 -5.7251 -5.61120 -5.2817
as.factor(cohort)2 -0.8977 -0.6985 -0.5551 -0.43084 -0.2371
as.factor(cohort)3 -0.4614 -0.2947 -0.1867 -0.09644 0.1232
This is puzzling.
Subscribe to:
Posts (Atom)