R Under development (unstable) (2023-08-20 r84995 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > > library("mlt") Loading required package: basefun Loading required package: variables > library("sandwich") > > chk <- function(x, y) stopifnot(all.equal(x, y, tol = 1e-4)) > set.seed(29) > > n <- 100 > d <- data.frame(y = rnorm(n)) > mod <- ctm(as.basis(~ y, data = d)) > off <- runif(n) > fmod <- mlt(mod, data = d, offset = off) > sub <- sample(1:n, n/2, replace = FALSE) > > w <- rep(1, n) > ms1 <- update(fmod, weights = w, subset = sub) > ms2 <- mlt(mod, data = d[sub,,drop = FALSE], offset = off[sub]) > chk(coef(ms1), coef(ms2)) > chk(estfun(ms1), estfun(ms2)) > chk(vcov(ms1), vcov(ms2)) > chk(logLik(ms1), logLik(ms2)) > > w <- runif(n) > ms1 <- update(fmod, weights = w, subset = sub) > ms2 <- mlt(mod, data = d[sub,,drop = FALSE], + weights = w[sub], offset = off[sub]) > chk(coef(ms1), coef(ms2)) > chk(estfun(ms1), estfun(ms2)) > chk(vcov(ms1), vcov(ms2)) > chk(logLik(ms1), logLik(ms2)) > > > y <- rnorm(n) > d <- data.frame(x = runif(n)) > d$y <- R(cleft = y - .1, cright = y + .1) > fmod <- mlt(mod, data = d, offset = off) > sub <- sample(1:n, n/2, replace = FALSE) > > w <- rep(1, n) > ms1 <- update(fmod, weights = w, subset = sub) > ms2 <- mlt(mod, data = d[sub,,drop = FALSE], offset = off[sub]) > chk(coef(ms1), coef(ms2)) > chk(estfun(ms1), estfun(ms2)) > chk(vcov(ms1), vcov(ms2)) > chk(logLik(ms1), logLik(ms2)) > > w <- runif(n) > ms1 <- update(fmod, weights = w, subset = sub) > ms2 <- mlt(mod, data = d[sub,,drop = FALSE], + weights = w[sub], offset = off[sub] ) > chk(coef(ms1), coef(ms2)) > chk(estfun(ms1), estfun(ms2)) > chk(vcov(ms1), vcov(ms2)) > chk(logLik(ms1), logLik(ms2)) > > ex <- sample(1:n, n/2, replace = TRUE) > ye <- yi <- y > ye[-ex] <- NA > yi[ex] <- NA > d$y <- R(ye, cleft = yi - .1, cright = yi + .1) > fmod <- mlt(mod, data = d, offset = off) > sub <- sample(1:n, n/2, replace = FALSE) > > w <- rep(1, n) > ms1 <- update(fmod, weights = w, subset = sub) > ms2 <- mlt(mod, data = d[sub,,drop = FALSE], offset = off[sub]) > chk(coef(ms1), coef(ms2)) > chk(estfun(ms1), estfun(ms2)) > chk(vcov(ms1), vcov(ms2)) > chk(logLik(ms1), logLik(ms2)) > > w <- runif(n) > ms1 <- update(fmod, weights = w, subset = sub) > ms2 <- mlt(mod, data = d[sub,,drop = FALSE], + weights = w[sub], offset = off[sub] ) > chk(coef(ms1), coef(ms2)) > chk(estfun(ms1), estfun(ms2)) > chk(vcov(ms1), vcov(ms2)) > chk(logLik(ms1), logLik(ms2)) > > d$y <- R(ye, cleft = yi - .1, cright = yi + .1, tleft = y - 2, tright = y + 2) > fmod <- mlt(mod, data = d, offset = off) > sub <- sample(1:n, n/2, replace = FALSE) > > w <- rep(1, n) > ms1 <- update(fmod, weights = w, subset = sub) > ### doesn't work without hotstart, problem > ### with computation of starting values??? > ms2 <- mlt(mod, data = d[sub,,drop = FALSE], offset = off[sub], + theta = coef(ms1)) > chk(coef(ms1), coef(ms2)) > chk(estfun(ms1), estfun(ms2)) > chk(vcov(ms1), vcov(ms2)) > chk(logLik(ms1), logLik(ms2)) > > w <- runif(n) > ms1 <- update(fmod, weights = w, subset = sub) > ms2 <- mlt(mod, data = d[sub,,drop = FALSE], + weights = w[sub], offset = off[sub], theta = coef(ms1)) > chk(coef(ms1), coef(ms2)) > chk(estfun(ms1), estfun(ms2)) > chk(vcov(ms1), vcov(ms2)) > chk(logLik(ms1), logLik(ms2)) > > > proc.time() user system elapsed 1.85 0.37 2.21