I'm trying to illustrate the effects of data removal and log-transformation on the distribution of residuals in an otherwise unaltered LMM. When I plot with facet_wrap, the same y-axis applies to all four plots, pushing the (naturally) much smaller log-transformed values together (which, ironically, is one of the reasons why to transform at all). Is there a simple way to draw the plots with different scales? Here's the code:
print(m1 <- lmer(potato~treatment + (1|subject), french_fries), cor=FALSE)
print(m2 <- lmer(log(potato+1)~treatment + (1|subject), french_fries), cor=FALSE)
print(m3 <- lmer(potato~treatment + (1|subject), subset(french_fries, potato!=0)), cor=FALSE)
print(m4 <- lmer(log(potato)~treatment + (1|subject), subset(french_fries, potato!=0)), cor=FALSE)
res1 <- data.frame(res = resid(m1), fit=scale(fitted(m1)))
res1$DV <- 1
res2 <- data.frame(res = resid(m2), fit=scale(fitted(m2)))
res2$DV <- 2
res3 <- data.frame(res = resid(m3), fit=scale(fitted(m3)))
res3$DV <- 3
res4 <- data.frame(res = resid(m4), fit=scale(fitted(m4)))
res4$DV <- 4
xx <- rbind(res1,res2,res3,res4)
xx$DV <- factor(xx$DV)
levels(xx$DV) <- c("a)", "b)", "c)", "d")
p <-qplot(x=fit, y=res, data=xx, geom="point", facets= . ~ DV,
xlab="Fitted values", ylab="Standardized Residuals")
p + geom_hline(yintercept=0) + theme_bw()
It's not as bad in this example, because potato-y-ness goes only to 15, but you can image the same plots with values up to 3500. At least now it's reproducible for everyone.
Best,
Paul
---
Paul Metzner
Humboldt-Universität zu Berlin
Philosophische Fakultät II
Institut für deutsche Sprache und Linguistik
Post: Unter den Linden 6 | 10099 Berlin | Deutschland
Besuch: Dorotheenstraße 24 | 10117 Berlin | Deutschland
+49-(0)30-2093-9726
paul.m...@rz.hu-berlin.de
http://amor.rz.hu-berlin.de/~metznerp/
I'm sure I've mucked up something in the code, but it's hard to tell
without your data.
ggplot(data=xx, aes(x=fit, y=res))+
geom_point()+
facet_grid(. ~ DV, scales='free')+
geom_hline(yintercept=0)+
scale_x_continuous("Fitted Values")+
scale_y_continuous("Standardized Residuals")
theme_bw()
Does that work?
Brandon
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
The main purpose of the plot is to illustrate the superiority of log-transformation and zero-removal regarding the distribution of residuals. Insofar, overplotting is ok. However, saving the plots as post-script seems to omit jittering and alpha. Is that the usual behaviour? Exporting as PNG preserves transparency, but I need to change the fonts manually after export, which is a lot easier with vector graphics. I put the dataframe (created with dput) into my dropbox, here's the current code:
p <-qplot(x=fit, y=res, data=xx, geom="point", shape=1, xlab="Fitted Values", ylab="Standardized Residuals")
p <- p + geom_hline(yintercept=0) + theme_bw(base_size=10) + facet_wrap(~DV, scales="free_y", nrow=2)
p + geom_jitter(position = position_jitter(width = 0.6), alpha = 0.2)
ggsave(file="ggdistmod.png", width=6, height=4.5)
Best,
Paul
Data: http://dl.dropbox.com/u/6281903/xx
>>> http://amor.rz.hu-berlin.de/~metznerp/<http://amor.rz.hu-berlin.de/%7Emetznerp/>
>>>
>>> --
>>> You received this message because you are subscribed to the ggplot2
>> mailing list.
>>> Please provide a reproducible example: http://gist.github.com/270442
>>>
>>> To post: email ggp...@googlegroups.com
>>> To unsubscribe: email ggplot2+u...@googlegroups.com<ggplot2%2Bunsu...@googlegroups.com>
>>> More options: http://groups.google.com/group/ggplot2
>>
>> --
>> You received this message because you are subscribed to the ggplot2 mailing
>> list.
>> Please provide a reproducible example: http://gist.github.com/270442
>>
>> To post: email ggp...@googlegroups.com
>> To unsubscribe: email ggplot2+u...@googlegroups.com<ggplot2%2Bunsu...@googlegroups.com>
>> More options: http://groups.google.com/group/ggplot2
>>
---
Paul Metzner
Manfred-von-Richthofen-Str. 13
12101 Berlin
Deutschland
Tel.: +49-(0)30-6730-9220
Mobil: +49-(0)17-8288-1059