[R-sig-ME] force lmer/glmer to use known random effects

Ben Bolker bbolker at gmail.com
Mon Jan 9 18:05:35 CET 2017


  I think you can actually do this if you're willing to hack a little
bit.  Here's an example modifying the one shown in ?modular :

library(lme4)
## 1.  Parse the data and formula:
glmod <- glFormula(cbind(incidence, size - incidence) ~ period + (1 | herd),
                   data = cbpp, family = binomial)
## 2.  Create the deviance function for optimizing over theta:
##     skip initial (nAGQ=0, theta parameters only) step
devfun <- updateGlmerDevfun(do.call(mkGlmerDevfun, c(glmod, list(nAGQ=1))),
                            reTrms=glmod$reTrms)
devfun2 <- function(beta) {
    devfun(c(1,beta))
}
devfun2(c(0,0,0,0))   ## test: evaluate
## deviance with all fixed-effect parameters set to zero
## optimize
opt <- nloptwrap(fn=devfun2,
          par=c(0,0,0,0),
          lower=rep(-Inf,4),
          upper=rep(Inf,4))
opt$par
[1] -1.4570408 -0.9533831 -1.0913854 -1.5366132


On 17-01-09 05:40 AM, Thierry Onkelinx wrote:
> Dear Alexia,
> 
> IMHO that is not possible with lme4. I think you can do it with INLA which
> has a "copy" feature. See
> http://www.r-inla.org/models/tools#TOC-Copying-a-model. You will need to
> fit both models simultaneous.
> 
> Best regards,
> 
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
> Forest
> team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
> Kliniekstraat 25
> 1070 Anderlecht
> Belgium
> 
> To call in the statistician after the experiment is done may be no more
> than asking him to perform a post-mortem examination: he may be able to say
> what the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does not
> ensure that a reasonable answer can be extracted from a given body of data.
> ~ John Tukey
> 
> 2017-01-07 20:29 GMT+01:00 Alexia Jolicoeur-Martineau <
> alexia.jolicoeur-martineau at mail.mcgill.ca>:
> 
>> In SAS, there is an option to use a known covariance matrix for your
>> random effects (See here: https://support.sas.com/
>> documentation/cdl/en/statug/63033/HTML/default/statug_mixed_sect033.htm).
>> In lme4 we cannot use covariance matrices but we can use random effects. Is
>> there a way for me to do force lmer/glmer to use known random effects
>> variances?
>>
>> My algorithm works in two steps. In step 1, I fit a generalized linear
>> mixed model with a known variable "x". In step 2, I fit the generalized
>> linear mixed model but this time I assume "x" to be unknown and every other
>> parameters to be known (using the parameter estimates from step 1). This is
>> what we call alternating optimization. I thus want to be able to fix the
>> random parameters from the model in step 2 to be the estimates of the
>> random effects from step 1. Is this possible to do?
>>
>>
>> I already implemented my method in SAS but I wish I could also implement
>> in R because 1) SAS macros  are slow and 2) SAS is not free so not everyone
>> could use it.
>>
>>
>> Alexia
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-mixed-models at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>>
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>



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