[R] lm() with spearman corr option ?
Hoji, Akihiko
akh22 at pitt.edu
Fri Apr 29 05:35:33 CEST 2016
Hi,
A following function was kindly provided by GGally’s maintainer, Barret Schloerke.
function(data, mapping, ...) {
p <- ggplot(data = data, mapping = mapping) +
geom_point(color = I("blue")) +
geom_smooth(method = "lm", color = I("black"), ...) +
theme_blank() +
theme(panel.border=element_rect(fill=NA, linetype = "solid", color="black"))
lmModel <- eval(substitute(lm(y ~ x, data = data), mapping))
fs <- summary(lmModel)$fstatistic
pValue <- pf(fs[1], fs[2], fs[3], lower.tail = FALSE)
if (pValue < 0.05) {
p <- p + theme(
panel.border = element_rect(
color = "red",
size = 3,
linetype = "solid",
fill = "transparent"
)
)
}
p
}
Basically, this function draws red squares over pairwise corr plots with p<0.05. Now, since I need to use the spearman rank corr, I tried to modify the lm function by adding “method=spearman” but this did not work at al. Could anybody suggest the way to add the spearman rank corr function in this particular function ?
Thanks.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20160429/ac0f5a6a/attachment.bin>
More information about the R-help
mailing list