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: addBinParam
Function Description: addBinParam
Given parameters for a model with N linear bins, creates parameters for N+1 bins which produce the same model.Function Arguments:
| Argument | Default Value |
|---|---|
| x | |
| best | |
| bin |
Function Source:
addBinParam=function(x,best,bin)
{
if(bin==1)
return(c(median(x),best[2],best[2],best[1]))
internal=best[1:(bin-1)]
slope=best[bin:(length(best)-1)]
intercept=best[length(best)]
div=c(min(x),internal,max(x))
widest=which.max(diff(div))
newbreak=0.5*diff(div[c(widest:(widest+1))])+div[widest]
newinternal=sort(c(internal,newbreak))
if(widest else newslope=slope[c(1:widest,widest)]
return(c(newinternal,newslope,intercept))
}
{
if(bin==1)
return(c(median(x),best[2],best[2],best[1]))
internal=best[1:(bin-1)]
slope=best[bin:(length(best)-1)]
intercept=best[length(best)]
div=c(min(x),internal,max(x))
widest=which.max(diff(div))
newbreak=0.5*diff(div[c(widest:(widest+1))])+div[widest]
newinternal=sort(c(internal,newbreak))
if(widest
return(c(newinternal,newslope,intercept))
}