if (spaMM.getOption("example_maxtime")>7) {
data("blackcap")
# Generate fits of null and full models:
lrt <- fixedLRT(null.formula=migStatus ~ 1 + Matern(1|longitude+latitude),
formula=migStatus ~ means + Matern(1|longitude+latitude),
method='ML',data=blackcap)
# The 'simuland' argument:
myfun <- function(y, what=NULL, lrt, ...) {
data <- lrt$fullfit$data
data$migStatus <- y ## replaces original response (! more complicated for binomial fits)
full_call <- getCall(lrt$fullfit) ## call for full fit
full_call$data <- data
res <- eval(full_call) ## fits the full model on the simulated response
if (!is.null(what)) res <- eval(what)(res=res) ## post-process the fit
return(res) ## the fit, or anything produced by evaluating 'what'
}
# where the 'what' argument (not required) of myfun() allows one to control
# what the function returns without redefining the function.
# Call myfun() with no 'what' argument: returns a list of fits
spaMM_boot(lrt$nullfit, simuland = myfun, nsim=1, lrt=lrt,
type ="marginal")[["bootreps"]]
# Return only a model coefficient for each fit:
spaMM_boot(lrt$nullfit, simuland = myfun, nsim=7,
what=quote(function(res) fixef(res)[2L]),
lrt=lrt, type ="marginal")[["bootreps"]]
if (FALSE) {
# Parametric bootstrap by spaMM2boot() and spaMM_boot():
boot.ci_info <- spaMM2boot(lrt$nullfit, statFUN = function(refit) fixef(refit)[1],
nsim=99, type ="marginal")
boot::boot.ci(boot.ci_info, , type=c("basic","perc","norm"))
nullfit <- lrt$nullfit
boot_t <- spaMM_boot(lrt$nullfit, simuland = function(y, nullfit) {
refit <- update_resp(nullfit, y)
fixef(refit)[1]
}, nsim=99, type ="marginal", nullfit=nullfit)$bootreps
boot::boot.ci(list(R = length(boot_t), sim="parametric"), t0=fixef(nullfit)[1],
t= t(boot_t), type=c("basic","perc","norm"))
}
}
Run the code above in your browser using DataLab