swihart / gnlrim

Generalized Nonlinear Random Intercept Models in R aka a freestanding `repeated::gnlmix()`
0 stars 0 forks source link

Travis-CI Build
Status

R-package gnlrim: Generalized Non-Linear Random Intercept Models

The goal of gnlrim is to have a freestanding, smaller footprint instance of repeated::gnlmix(). That is, I took the minimum amount of code from rmutil and repeated to get gnlmix working so that gnlrim did not require dependence/imports from rmutil and repeated. I am going to be making edits on gnlmix() to transform it into gnlrim() so that it is basically gnlmix() with the added functionality:

Example

This is a basic example which shows you how to solve a common problem:

## basic example code

Errors and Their (Potential) Fixes

   Likelihood returns Inf or NAs: invalid initial values, wrong model, or probabilities too small to calculate

This is sometimes due to not using a named lists for pmu and pmix.

## without named lists for `pmu` and `pmix`:
# fit_PPN_err <- gnlrim(y=y_cbind,
#                       mu=~pnorm(a+b*dose+rand),
#                       pmu=c(0,0),
#                       pmix=0.5,
#                       p_uppb = c(Inf ,  Inf,   1-1e-5),
#                       p_lowb = c(-Inf, -Inf,   0+1e-5),
#                       distribution="binomial",
#                       nest=id,
#                       random="rand",
#                       mixture="normal-phi")
# Error in gnlrim(y = y_cbind, mu = ~pnorm(a + b * dose + rand), pmu = c(0,  : 
#   Likelihood returns Inf or NAs: invalid initial values, wrong model, or probabilities too small to calculate

## with named lists for `pmu` and `pmix`:
fit_PPN_fix <- gnlrim(y=y_cbind,
                      mu=~pnorm(a+b*dose+rand),
                      pmu=c(a=0,b=0),
                      pmix=c(phi=0.5),
                      p_uppb = c(Inf ,  Inf,   1-1e-5),
                      p_lowb = c(-Inf, -Inf,   0+1e-5),
                      distribution="binomial",
                      nest=id,
                      random="rand",
                      mixture="normal-phi")
#> [1] 3
#>   a   b phi 
#> 0.0 0.0 0.5 
#> [1] 17.02146
## a, b, phi:
fit_PPN_fix$coeff
#> [1] -0.4832740  0.3560651  0.4203699