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: cumul.above

Function Description: cumul.above

Given y values as a function of x, this seeks the x at which the curve passes through a given y. It sets a variable whichabove to 0 for all cases where y>cutoff, otherwise 0, then fits a logistic regression. The midpoint of the logistic regression is a good estimate.

Function Arguments:

ArgumentDefault Value
x
y
cutoff
logaxs""
graphitTRUE
returnfullFALSE

Function Source:

cumul.above=function(x,y,cutoff,logaxs="",graphit=TRUE,returnfull=FALSE)
{
whichabove=y>cutoff
if(logaxs=="x" | logaxs=="xy") runx=log(x)
else runx=x

fit=glm(whichabove~runx,family=binomial)

if(logaxs=="x" | logaxs=="xy") mid=exp(-fit$coef[1]/fit$coef[2])
else mid=(-fit$coef[1]/fit$coef[2])

xord=x[order(x)]
yord=y[order(x)]
if(graphit)
{
plot(xord,yord,pch=16,log=logaxs)
abline(v=mid)
abline(h=cutoff)
}

return(mid)
}