# NOT RUN {
# }
# NOT RUN {
# Example 1 of Pham & Wand (2018):
set.seed(39402)
m <- 100 ; n <- 2
beta0True <- 0.5 ; betaxTrue <- 1.7
sigsqTrue <- 0.8 ; idnum <- rep(1:m,each=n)
x <- runif(m*n)
U <- rep(rnorm(m,0,sqrt(sigsqTrue)),each=n)
mu <- 1/(1+exp(-(beta0True+betaxTrue*x+U)))
y <- rbinom((m*n),1,mu)
fit1 <- gSlc(y ~ x,random = list(idnum = ~1),family = "binomial")
summary(fit1)
# }
# NOT RUN {
# }
# NOT RUN {
# Example 2 of Pham & Wand (2018):
set.seed(53902)
n <- 400 ; x <- runif(n)
fTrue <- function(x) return(cos(4*pi*x) + 2*x - 1)
mu <- exp(fTrue(x)) ; y <- rpois(n,mu)
fit2 <- gSlc(y~s(x),family="poisson")
summary(fit2)
plot(fit2)
# }
# NOT RUN {
# }
# NOT RUN {
# Example 3 of Pham & Wand (2018):
set.seed(981127)
n <- 500 ; betax1True <- 0.5; x1 <- sample(c(0,1),n,replace=TRUE)
x2 <- runif(n) ; fTrue <- function(x) return(sin(2*pi*x))
mu <- 1/(1+exp(-(betax1True*x1+fTrue(x2)))) ; y <- rpois(n,mu)
y <- rbinom(n,1,mu)
fit3 <- gSlc(y ~ x1 + s(x2),family="binomial")
summary(fit3)
plot(fit3)
# }
# NOT RUN {
# }
# NOT RUN {
# Example 4 of Pham & Wand (2018):
set.seed(2966703)
m <- 100 ; n <- 10; x1 <- runif(m*n); x2 <- runif(m*n)
idnum <- rep(1:m,each=n) ; sigsqTrue <- 1
U <- rep(rnorm(m,0,sqrt(sigsqTrue)),each=n)
mu <- exp(U + cos(4*pi*x1) + 2*x1 + sin(2*pi*x2^2)) ; y <- rpois(m*n,mu)
fit4 <- gSlc(y ~ s(x1) + s(x2),random = list(idnum=~1),family = "poisson")
summary(fit4)
plot(fit4)
# }
Run the code above in your browser using DataLab