repeated::gnlmix()
- PROC NLMIXED -- If the link or its inverse can be represented with the functions available in SAS.
- I need to dig more into the code.
Some repeated::gnlmix()
examples:
library(repeated)
set.seed(99)
dat <- data.frame(id = c(1,1,1, 2,2,2, 3,3,3, 4,4,4),
y = c(1,0,1, 0,1,1, 0,0,0, 1,1,1),
x = rnorm(12)
)
attach(dat)
y_cbind <- cbind(y, 1-y)
# probit regression
gnlmix(y=y_cbind,
distribution = "binomial",
nest = id,
mixture = "normal",
random = "b_id",
mu = ~ pnorm(beta0 + beta1*x + b_id),
pmu = list(beta0=0, beta1=0),
pmix = log(4)
)
# Location parameters:
# estimate se
# beta0 0.2825 0.7878
# beta1 -0.7628 1.1498
#
# Mixing dispersion parameter:
# estimate se
# 0.4249 2.072
# cauchy link
gnlmix(y=y_cbind,
distribution = "binomial",
nest = id,
mixture = "normal",
random = "b_id",
mu = ~ pcauchy(beta0 + beta1*x + b_id),
pmu = list(beta0=0, beta1=0),
pmix = log(4)
)
# Location parameters:
# estimate se
# beta0 0.6973 1.791
# beta1 -1.2328 2.812
#
# Mixing dispersion parameter:
# estimate se
# 1.805 3.038
# logistic regression
gnlmix(y=y_cbind,
distribution = "binomial",
nest = id,
mixture = "normal",
random = "b_id",
mu = ~ plogis(beta0 + beta1*x + b_id),
pmu = list(beta0=0, beta1=0),
pmix = log(4)
)
# Location parameters:
# estimate se
# beta0 0.4981 1.356
# beta1 -1.2740 2.036
#
# Mixing dispersion parameter:
# estimate se
# 1.496 2.177
# custom link / inverse (logistic regression)
custom_inv <- function(eta) exp(eta) / (exp(eta) + 1)
gnlmix(y=y_cbind,
distribution = "binomial",
nest = id,
mixture = "normal",
random = "b_id",
mu = ~ custom_inv(beta0 + beta1*x + b_id),
pmu = list(beta0=0, beta1=0),
pmix = log(4)
)
# Location parameters:
# estimate se
# beta0 0.4981 1.356
# beta1 -1.2740 2.036
#
# Mixing dispersion parameter:
# estimate se
# 1.496 2.177
# custom link / inverse
custom_inv <- function(eta) log(exp(eta)+1) / (log(exp(eta)+1) + pi/2)
gnlmix(y=y_cbind,
distribution = "binomial",
nest = id,
mixture = "normal",
random = "b_id",
mu = ~ custom_inv(beta0 + beta1*x + b_id),
pmu = list(beta0=0, beta1=0),
pmix = log(4)
)
# Location parameters:
# estimate se
# beta0 4.333 5.477
# beta1 -2.291 5.571
#
# Mixing dispersion parameter:
# estimate se
# 3.879 2.386
For GLMs, see gnlm::gnlr()
as shown here.