1
$\begingroup$

I am trying to fit a GAMM to ordered categorical data using gamm4 in R. In the help file for gamm4, it says the argument 'family' is "A family as used in a call to glm or gam." That being the case, I try to use family ocat from the mgcv package, which is designed for ordered categorical data. However, when I follow the example provided in the ocat help page (but adding random effects), I receive an error. Is this a bug, has ocat not properly been synced with gamm4, or is there some other issue I am missing?

Example:

library(mgcv)
## simulated some ordered categorical data...
set.seed(3);n<-400
dat <- gamSim(1,n=n)
dat$f <- dat$f - mean(dat$f)

alpha <- c(-Inf,-1,0,5,Inf)
R <- length(alpha)-1
y <- dat$f
u <- runif(n)
u <- dat$f + log(u/(1-u)) 
for (i in 1:R) {
  y[u > alpha[i]&u <= alpha[i+1]] <- i
}
dat$y <- y

## plot the data...
par(mfrow=c(2,2))
with(dat,plot(x0,y));with(dat,plot(x1,y))
with(dat,plot(x2,y));with(dat,plot(x3,y))

## fit ocat model to data...
b <- gam(y~s(x0)+s(x1)+s(x2)+s(x3),family=ocat(R=R),data=dat)
b
plot(b,pages=1)
gam.check(b)
summary(b)

##################################################
library(gamm4)

## add in some random effects and use gamm4
dat$f3 <- sample(1:40,400,T)
b2 <- gamm4(y~s(x0)+s(x1)+s(x2)+s(x3),random = ~ (1|f3),family = ocat(R=R),data = dat)
$\endgroup$

closed as off-topic by Michael Chernick, mdewey, Gavin Simpson, Jeremy Miles, Juho Kokkala May 29 '18 at 18:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – Michael Chernick, mdewey, Jeremy Miles, Juho Kokkala
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ I think you would be better on an R-site or e-mailing the maintainer of the package. $\endgroup$ – mdewey May 29 '18 at 14:53
1
$\begingroup$

No, ocat doesn't work with gamm4(). From ?family.mgcv

As well as the standard families documented in family (see also glm) which can be used with functions gam, bam and gamm, mgcv also supplies some extra families, most of which are currently only usable with gam, although some can also be used with bam...

(emphasis added). We need to take this literally.

I believe bits of the documentation have gotten out of sync — you can only use the families that lmer or glmer understand in gamm4().

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.