Using function geeglm
from package geepack
(Generalized Estimating Equation), I have modeled counts as being dependent on two nominal (factor) variables, one continuous variable with 3rd-order interactions and one grouping variable.
This is the model:
m1<-geeglm(formula = dependent.var ~ cat.var1 * cat.var2 * contin.var,
family = poisson, id = group, corstr = "exchangeable")
Factor variable cat.var1 has two levels (CD and WL), factor variable cat.var2 has two levels (SAH and SKA). Group is a grouping variable to account for autocorrelation among somehow related subjects. Using anova
function, I found that the only significant model’s interaction terms are cat.var1 : contin.var and cat.var2 : contin.var.
I would like to plot these two interactions:
I have used the codes below, but I am not happy with the fitted lines. Line for CD-level of cat.var1 in the first figure is the same as line for SAH-level of cat.var2 in the second figure (see figs) – therefore I think that they are not correct and I do not know how to solve this. Which model's coefficients I have to use to construct that lines? The model’s coefficients used for producing of the figures are thereinafter.
Codes:
# 1st plot: cat.var1 : contin.var
par(mfrow=c(1,1))
plot(contin.var, dependent.var, type="n")
points(contin.var[cat.var1=="WL"], jitter(dependent.var[cat.var1=="WL"]))
points(contin.var[cat.var1=="CD"], jitter(dependent.var[cat.var1=="CD"]),
pch=16)
x <- seq(3,7,0.1)
y1 <-exp(-0.1584 + 0.3474*x)
lines(x,y1, lty=2) # CD
y2 <-exp(-0.1584 + 3.7293 +(-0.6685 + 0.3474)*x)
lines(x,y2, lty=1) # WL
# 2nd plot: cat.var2 : contin.var
par(mfrow=c(1,1))
plot(contin.var, dependent.var, type="n")
points(contin.var[cat.var2=="SKA"], jitter(dependent.var[cat.var2=="SKA"]))
points(contin.var[cat.var2=="SAH"], jitter(dependent.var[cat.var2=="SAH"]),
pch=16)
x <- seq(3,7,0.1)
y1 <-exp(-0.1584 + 0.3474*x)
lines(x,y1, lty=2) # SAH
y2 <-exp(-0.1584 + -6.9490 + (1.2249 + 0.3474)*x)
lines(x,y2) # SKA
Here are my model's coefficients, used for producing of figures, outputs from summary(m1)
(statistically significant terms - outputs from anova(m1)
- are denoted with asteriks **):
Coefficients:
Estimate
(Intercept) -0.1584
cat.var1WL 3.7293
cat.var2SKA -6.9490
contin.var 0.3474 *
cat.var1WL: cat.var2SKA 3.9970
cat.var1WL: contin.var -0.6685 *
cat.var2SKA: contin.var 1.2249 **
cat.var1WL: cat.var2SKA: contin.var -0.6860
Factor variable *cat.var1* has two levels (CD and WL),
factor variable *cat.var2* has two levels (SAH and SKA).
Here are the data: https://docs.google.com/file/d/0Bz8ojhHeiNclVi1oT0ZwTEtEN2s/edit