Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visualize ANCOVA incl formulas (e.g. library HH)

Tags:

plot

r

lattice

Package HH seems provide a easy way to visualize ANCOVAs

library(HH)
data(hotdog)
ancova(Sodium ~ Calories * Type, data=hotdog)

enter image description here

Is there a comfortable way to combinate this with something like panel.ablineq from latticeExtra? (http://latticeextra.r-forge.r-project.org#panel.ablineq) to get the concrete functions (slope, intercept)?

like image 874
ckluss Avatar asked Jan 16 '15 16:01

ckluss


1 Answers

The general answer will be to use HH::ancovaplot() directly (rather than implicitly via HH::ancova()) along with latticeExtra's handy layer() function and overloaded + operator. I'll leave it to you to work out the fiddly details required to make it look exactly how you want it to.

ancovaplot(Sodium ~ Calories * Type, data=hotdog) +
layer(panel.ablineq(lm(y ~ x), rot = TRUE, at = 0.5, pos = 3))

enter image description here

like image 84
Josh O'Brien Avatar answered Sep 23 '22 09:09

Josh O'Brien