[R-sig-ME] Looking for residuals in clmm summary output
Rune Haubo
rune.haubo at gmail.com
Wed Nov 13 10:35:48 CET 2013
Dear Aline,
You are not alone in being surprised of the absence of residuals; I
meet that question on a regular basis. And I would be delighted to
implement residuals for CLMs and CLMMs in ordinal, its only that I
have never seen a relevant definition of such residuals or been able
to come up with one myself. One of the problems is that we are really
taking about a vector-valued response (multinomially distributed), and
so we might be able to define vector-valued residuals. But what would
you use such a residual vector for? Graphing it is not as easy as with
univariate responses, and even if that succeeds, which structures
should you look for?
Here is a possible definition of 'raw' residuals for CLMs (non-random):
## Residuals for CLMs:
library(ordinal)
fm1 <- clm(rating ~ temp + contact, data=wine)
summary(fm1)
pred <- predict(fm1, newdata=wine[, c("contact", "temp")])$fit
Y <- matrix(0, nrow=nrow(wine), ncol=nlevels(wine$rating))
Y <- 1 * (col(Y) == wine$rating)
head(Y) ## multinomial response
head(pred) ## fitted values for multinomial response
raw.resid <- Y - pred
head(raw.resid)
The last lines give:
> head(Y)
[,1] [,2] [,3] [,4] [,5]
[1,] 0 1 0 0 0
[2,] 0 0 1 0 0
[3,] 0 0 1 0 0
[4,] 0 0 0 1 0
[5,] 0 0 0 1 0
[6,] 0 0 0 1 0
> head(pred)
1 2 3 4 5
1 0.20679013 0.5706497 0.1922909 0.02361882 0.00665041
2 0.20679013 0.5706497 0.1922909 0.02361882 0.00665041
3 0.05354601 0.3776461 0.4430599 0.09582084 0.02992711
4 0.05354601 0.3776461 0.4430599 0.09582084 0.02992711
5 0.02088771 0.2014157 0.5015755 0.20049402 0.07562701
6 0.02088771 0.2014157 0.5015755 0.20049402 0.07562701
> raw.resid <- Y - pred
> head(raw.resid)
1 2 3 4 5
1 -0.20679013 0.4293503 -0.1922909 -0.02361882 -0.00665041
2 -0.20679013 -0.5706497 0.8077091 -0.02361882 -0.00665041
3 -0.05354601 -0.3776461 0.5569401 -0.09582084 -0.02992711
4 -0.05354601 -0.3776461 -0.4430599 0.90417916 -0.02992711
5 -0.02088771 -0.2014157 -0.5015755 0.79950598 -0.07562701
6 -0.02088771 -0.2014157 -0.5015755 0.79950598 -0.07562701
There is at present no predict method for clmm objects, so here you
have another challenge. However, as I indicated above, the real
challenge is to figure out what to do with such residuals. Note that
the elements of the i'th predicted probability vector are correlated
as it necessarily sums to 1:
> unique(rowSums(pred))
[1] 1
Cheers,
Rune
On 12 November 2013 20:40, <aline.frank at wsl.ch> wrote:
> Hello
>
> I am working with ordinal data using the clmm() mixed models approach of the R package "ordinal". My interest is in analyzing the random effects of my model, inclusive the residual term. However, the summary of my model does not inlude the residuals. Does this mean that my residuals are "hidden" in one of the random effects, or is there a way to get the residuals anyway? Below you see my model summary output.
>
> Thanks for every hint!
>
> Aline
>
>
>
> model <- clmm(trait~1+(1|Block_Nr)+(1|Pop_Nr)+(1|Fam_Nr)+(1|Block_Nr:Pop_Nr),data=dat)
>
> Data: frost damage on the plants in levels 0-5
>
> Output R:
>
> Cumulative Link Mixed Model fitted with the Laplace approximation
>
> formula: trait ~ 1 + (1 | Block_Nr) + (1 | Pop_Nr) + (1 | Fam_Nr) + (1 | Block_Nr:Pop_Nr)
> data: dat
>
> link threshold nobs logLik AIC niter max.grad cond.H
> logit flexible 4018 -2015.57 4047.14 660(2644) 2.93e-03 3.6e+01
>
> Random effects:
> Groups Name Variance Std.Dev.
> Block_Nr:Pop_Nr (Intercept) 0.0000 0.0000
> Fam_Nr (Intercept) 0.1085 0.3294
> Pop_Nr (Intercept) 0.2694 0.5191
> Block_Nr (Intercept) 0.1351 0.3675
> Number of groups: Block_Nr:Pop_Nr 1435, Fam_Nr 258, Pop_Nr 90, Block_Nr 16
>
> No Coefficients
>
> Threshold coefficients:
> Estimate Std. Error z value
> 0|1 1.9701 0.1221 16.14
> 1|2 3.7404 0.1488 25.13
> 2|3 4.5441 0.1791 25.37
> 3|4 5.3417 0.2322 23.00
> (103 observations deleted due to missingness)
>
> _______________________________________________
> 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