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>
Please read ?lm! -- where it says: method: the method to be used; for fitting, currently only method = "qr" is supported; method = "model.frame" returns the model frame (the same as with model = TRUE, see below). More to the point, your request for a "spearman" method for lm() makes little or no sense. There *are* rank-based methods for multiple regression, but that sort of discussion is off topic here. I suggest you talk with a local statistician as you appear to be out of your depth statistically; or you might try posting on a statistical site like stats.stackexchange.com Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Thu, Apr 28, 2016 at 8:35 PM, Hoji, Akihiko <akh22 at pitt.edu> wrote:> 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. > > > > > > ______________________________________________ > R-help at 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.
I think you would just need to replace the lm() function call with cor(x,y,method="spearman". It would probably be more informative to actually plot by the magnitude of the correlation coefficient (all |r| >0.20 or something similar) rather than just by those with P <=0.05. Brian Brian S. Cade, PhD U. S. Geological Survey Fort Collins Science Center 2150 Centre Ave., Bldg. C Fort Collins, CO 80526-8818 email: cadeb at usgs.gov <brian_cade at usgs.gov> tel: 970 226-9326 On Thu, Apr 28, 2016 at 9:35 PM, Hoji, Akihiko <akh22 at pitt.edu> wrote:> 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. > > > > > > ______________________________________________ > R-help at 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. >[[alternative HTML version deleted]]