Hello all,

I've run a model, and now would like to extract residuals. However, I have set sum-to-zero contrasts for the categorical fixed effect (contr.sum). Because I am interested in looking at the variation in the residuals associated with that fixed effect (along with other levels), I need to calculate residuals setting that fixed effect to zero. Any thoughts on how to do this?

thanks,
allie



contr.sum.keepnames <- function(...) {
# make deviation contrasts that don't lose the names of the factors in the model results # from https://stackoverflow.com/questions/10808853/why-does-changing-contrast-type-change-row-labels-in-r-lm-summary
    conS <- contr.sum(...)
    colnames(conS) = rownames(conS)[-length(rownames(conS))]
    conS
}

test_df = data.frame(site = rep(LETTERS[1:10], 10), resp = runif(100), pred = runif(100))

contrasts(test_df$site) = contr.sum.keepnames(levels(test_df$site))

mod = lmer(resp ~ (1 + pred|site) + pred, data = test_df)

residuals = test_df$resp - predict(mod, REform=NA) # I would like the site effect here to be set to zero

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to