Skip to content

How to plot results of clmm()?

3 messages · Thomas Friedrichsmeier, Michael Friendly, John Fox

#
Dear list,

I'd like to create a visual plot of a clmm() I've fitted using the 
'ordinal' package in R. It's possible to do this with a glm() by using 
the 'effects' package. For example:

    library(effects)
    data(BEPS)
    mod <- lm(political.knowledge ~ age + gender + vote, data=BEPS)
    eff <- effect("age", mod, default.levels=100)
    plot(eff, colors=c("black", "red"))

Produces: http://i.stack.imgur.com/elo4p.png

The 'effects' package does not support clmm:

    mod <- clmm(as.factor(political.knowledge) ~ age + gender + 
(1|vote), data=BEPS)
    eff <- effect("age", mod, default.levels=100)
    > Error in UseMethod("effect", mod) :
    no applicable method for 'effect' applied to an object of class "clmm"

How would I go about doing this? I can't find any examples with clm() or 
clmm() online. Any suggestions would be much appreciated.

Tom
1 day later
#
On 11/4/2013 9:13 AM, thomas wrote:
You're right that clm() and clmm() models are not supported by the 
effects package.  In principle, this would not be too difficult to add, 
*if* the ordinal package contained the standard collection of methods for
'clm' and 'clmm' objects --- coef(), vcov(), and importantly, predict().
Unfortunately, there is no predict method, and clmm objects don't 
inherit from anything else:

 > methods(class="clmm")
  [1] anova.clmm*      condVar.clmm*    extractAIC.clmm* logLik.clmm*
  [5] nobs.clmm*       print.clmm*      ranef.clmm       summary.clmm*
  [9] VarCorr.clmm     vcov.clmm*
 > class(modc)
[1] "clmm"
 >

If there were, you could simply do what effects does yourself --
obtain predicted values (and CIs) over a grid of values, and plot them,

xlevels <- expand.grid(list(age=seq(20,90,10),
               gender=levels(BEPS$gender), vote=levels(BEPS$vote)))

You can, of course, obtain all the fitted values, and plot those,
but that lacks the simplicity of effect plots in averaging over factors
not shown in a given plot.

library(ordinal)
  modc <- clmm(as.factor(political.knowledge) ~ age + gender +
(1|vote), data=BEPS)

BEPS$fitted <- fitted(modc)
plot(fitted~age, data=BEPS, col=c("red", "blue")[gender])
#
Dear Thomas and Michael,

As Michael knows, there is a default Effect() method in the development
version of the effects package on R-Forge. This should work with almost all
model objects that produce a single fitted value and that respond to coef(),
model.frame(), formula(), and vcov(). 

This might cover plotting the latent response in clm() or clmm() models but
not plots of fitted response-category probabilities such as the effects
package can make for models fit by multinom() in the nnet package or polr()
in the MASS package. 

Best,
 John