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: logistic.power_simple

Function Description: logistic.power_simple

This is a mixture of logistic and logistic-standard models. The predictors n get a power model, the remaining a simple model. So if nopredictors==8, and n=c(1,7), then the first and seventh predictors use a power model, while the rest a simple model. There must be 1+length(n)+nopredictors parameters, plus additional 1 or 2 for asymptote and basement.

Function Arguments:

ArgumentDefault Value
x
param
logFALSE
N1
...

Function Source:

logistic.power_simple=function(x,param,log=FALSE,N=1,...)
{
x=as.matrix(x)
nopredictor=dim(x)[2]
noparam=length(param)

n=N
non=length(n)
if(non==nopredictor) return(logistic.power(x=x,param=param,log=log))

x1=as.matrix(x[,n])
x2=as.matrix(x[,-n])

a=param[1]
slopes=param[-1]
b=b2=standardparam=numeric()
counter=1

for(j in 1:nopredictor)
{
if(j %in% n)
{
b=c(b,slopes[counter])
b2=c(b2,slopes[counter+1])
counter=counter+2
}
else
{
standardparam=c(standardparam,slopes[counter])
counter=counter+1
}
}

asymp=IfElse(length(param)>non+nopredictor+1,param[noparam-1],1)
basement=IfElse(length(param)>non+nopredictor+2,param[noparam-2],0)
# browser()

X=x1%*%b
X2=x1^2%*%b2
Xstan=x2%*%standardparam

pwr=a+X+X2+Xstan
y=exp(pwr)/(exp(pwr)+1)
prob=y*(asymp-basement)+basement

infinite.pos=which(is.infinite(exp(pwr)))
# prob[infinite.pos]=basement+asymp
prob[infinite.pos]=NA

if(log) return(log(prob))
return(prob)
}