R/r.crit.R

Defines functions r.crit

Documented in r.crit

##' Compute the critical r value, or return the p value of an r, assuming a given number of degrees of freedom.
##'
##' @title Compute critical r or p.
##' @param n The sample size.
##' @param p the probability. Defaults to .025.
##' @param r The observed r value
##' @param two.tailed Should the probability be cut in half?
##' @export
##' @return the critical r value or the observed p value for a given r
##' @author Dustin Fife
##' @examples
##' r.crit(n=100, p=.025)
##' r.crit(n=20, r=.6, p=.05)
r.crit = function(n, r=NULL, p=.025, two.tailed=T){
	
	if (is.null(r)){
		tcrit = qt(p, n)
		rcrit = sqrt(tcrit^2 / (n-2+tcrit^2))
		return(rcrit)
	} else {
		tobs = r*sqrt((n-2)/(1-r^2))
		if (two.tailed){
			tobs = abs(tobs)
		}
		pobt = 1-pt(tobs, df=n-2)
		tcrit = qt(p, n)
		rcrit = sqrt(tcrit^2 / (n-2+tcrit^2))		
		list(rcrit=rcrit, pobt=pobt)
	}
}

Try the fifer package in your browser

Any scripts or data that you put into this service are public.

fifer documentation built on May 30, 2017, 7:40 a.m.