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: llike.GaussModelSD
Function Description: llike.GaussModelSD
This is for model.xy. Take the function for the SD, its parameters, and both predicted and observed values of the dependent variable (pred,obs) to generate a likelihood. One of the parameters is passed as testparam, for use with metrop1step. The predicted value for each observation is included, and not calculated from the predicting function. MINIMUM_SD=.0001 MINIMUM_SD should be set in the program calling model.xy, to adjust it appropriately. If MINSD==0, then the sd can collapse to a miniscule number and drive the likelihood very high, preventing parameter searches from ever escaping the sd.Function Arguments:
| Argument | Default Value |
|---|---|
| testparam | |
| allparam | |
| whichtest | |
| x | |
| pred | |
| obs | |
| model | |
| badsd | |
| ... |
Function Source:
llike.GaussModelSD=function(testparam,allparam,whichtest,x,pred,obs,model,badsd,...)
{
extra=list(...)
if(is.null(extra$MINIMUM_SD)) MINIMUM_SD=0
else MINIMUM_SD=extra$MINIMUM_SD
param=arrangeParam.llike(testparam,allparam,whichtest)
sd=model(x=x,param=param)
if(length(which(sd<=MINIMUM_SD))>0) return(-Inf)
if(!is.null(badsd)) if(badsd(x,param)) return(-Inf)
llike=dnorm(obs,mean=pred,sd=sd,log=TRUE)
total=sum(llike)
if(is.na(total) | is.infinite(total) | is.null(total)) browser()
return(total)
}
{
extra=list(...)
if(is.null(extra$MINIMUM_SD)) MINIMUM_SD=0
else MINIMUM_SD=extra$MINIMUM_SD
param=arrangeParam.llike(testparam,allparam,whichtest)
sd=model(x=x,param=param)
if(length(which(sd<=MINIMUM_SD))>0) return(-Inf)
if(!is.null(badsd)) if(badsd(x,param)) return(-Inf)
llike=dnorm(obs,mean=pred,sd=sd,log=TRUE)
total=sum(llike)
if(is.na(total) | is.infinite(total) | is.null(total)) browser()
return(total)
}