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/distributions.r

View File Source Download File No help file available

Function: linearmodel.bin

Function Description: linearmodel.bin

Multiple bin model predicting y as a function of x in several bins. Within each bin, y is a linear function of x. A model with B bins has B-1 parameters for breaks points (initial B-1 parameters), B parameters as slopes (next B parameters), and one intercept (last parameter). Intercept is assigned at x=0 by default, but argument LINEARBINMEDIAN can be used to change. This function accepts one set of parameters, separates the bin, slope, and intercept, and submits to the general version of the function (linearmodel.bin.set).

Function Arguments:

ArgumentDefault Value
x
param
...

Function Source:

linearmodel.bin=function(x,param,...)
{
x=as.matrix(x)

extra=list(...)
if(is.null(extra$LINEARBINMEDIAN)) medv=0
else medv=extra$LINEARBINMEDIAN

noparam=length(param)
bins=(noparam)/2
if(is.null(medv)) medv=median(x)

if(bins==1) return(linear.model(x-medv,param))

b=param[1:(bins-1)]-medv
v=x-medv
N=length(b)

m=param[bins:(noparam-1)]
inter=param[noparam]

pred=linearmodel.bin.set(v=v,binparam=b,param=c(m,inter))
return(pred)
}