Giter VIP home page Giter VIP logo

Comments (3)

drizopoulos avatar drizopoulos commented on July 18, 2024

from glmmadaptive.

florianhartig avatar florianhartig commented on July 18, 2024

Hi Dimitris,

for historical reasons, I'm still carrying around 2 versions of calculating everything in DHARMa,

  1. where quantile residuals are created by comparing observed vs. simulated data (default)
  2. where the models are re-fit to the simulated data, and residuals or other properties of the model are compared

The original motivation for this was the idea that option 2 would be more reliable for biased estimators. In practice, I have found few advantages of the refit, but for the moment I'm keeping the option.

More generally though, the refit is important for parametric bootstrap and all that.

from glmmadaptive.

drizopoulos avatar drizopoulos commented on July 18, 2024

Hi Florian,

I have written a short refit() function that seems to do the trick - see below:

# simulate some data
set.seed(123L)
n <- 500
K <- 15
t.max <- 25

betas <- c(-2.13, -0.25, 0.24, -0.05)
D <- matrix(0, 2, 2)
D[1:2, 1:2] <- c(0.48, -0.08, -0.08, 0.18)

times <- c(replicate(n, c(0, sort(runif(K-1, 0, t.max)))))
group <- sample(rep(0:1, each = n/2))
DF <- data.frame(year = times, group = factor(rep(group, each = K)))
X <- model.matrix(~ group * year, data = DF)
Z <- model.matrix(~ year, data = DF)

b <- cbind(rnorm(n, sd = sqrt(D[1, 1])), rnorm(n, sd = sqrt(D[2, 2])))
id <- rep(1:n, each = K)
eta.y <- as.vector(X %*% betas + rowSums(Z * b[id, ]))
DF$y <- rbinom(n * K, 10, plogis(eta.y))
DF$fails <- 10 - DF$y
DF$id <- factor(id)

################################################################
################################################################

fm <- mixed_model(fixed = cbind(y, fails) ~ year * group, 
                  random = ~ 1 | id, data = DF,
                  family = binomial())

refit_MixMod <- function (object, newresp = NULL) {
    if (is.null(newresp)) return(object)
    if (!is.data.frame(newresp)) stop("'newresp' must be a data.frame.")
    newdata <- object$data
    respVars <- all.vars(update.formula(formula(object), . ~ 0))
    newdata[respVars] <- newresp[respVars]
    update(object, data = newdata)
}

fm
refit_MixMod(fm, DF)

from glmmadaptive.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.