Topic: Utilities
Topic Description:
Basic R utilities used in many packages and functions, such as date and string manipulations, statistical distributions, geometry of lines and distances. The R package date is required for the two data functions.
File: utilities/statistics.r
| View File Source | Download File | No help file available |
Function: regress.plot
Function Description: regress.plot
Performs regression in convenient way and returns coefficients and probabilities in a single vector, and plots a graph.Function Arguments:
| Argument | Default Value |
|---|---|
| x | |
| y | |
| title | "" |
| graphit | T |
| add | F |
| pts | T |
| clr | "blue" |
| ptnames | NULL |
| xrange | NULL |
| yrange | NULL |
| xtitle | NULL |
| ytitle | NULL |
Function Source:
regress.plot=function(x,y,title="",graphit=T,add=F,pts=T,clr="blue",ptnames=NULL,xrange=NULL,yrange=
NULL,xtitle=NULL,ytitle=NULL) {
fit=lm(y~x)
regcoef=summary(fit)$coef[,1]
prob=summary(fit)$coef[,4]
rsq=cor(x,y)^2
if(is.null(xrange)) xrange=range(x)
if(is.null(yrange)) yrange=range(y)
if(is.null(xtitle)) xtitle="x"
if(is.null(ytitle)) ytitle="y"
if(graphit)
{
if(add & pts) points(x,y,pch=16)
if(!add & pts) plot(x,y,pch=16,main=title)
abline(fit,col=clr)
if(!is.null(ptnames)) identify(x,y,ptnames)
}
return(list(coef=c(regcoef,prob,rsq),full=summary(fit)))
}