Learn R Programming

lavaSearch2 (version 1.0.0)

iidJack: Jacknife iid Decomposition from Model Object

Description

Extract iid decomposition (i.e. influence function) from model object.

Usage

iidJack(x, ...)

# S3 method for default iidJack(x, data = NULL, grouping = NULL, ncpus = 1, keep.warnings = TRUE, keep.error = TRUE, initCpus = TRUE, trace = TRUE, ...)

Arguments

x

model object.

...

additional arguments.

data

dataset used to perform the jacknife.

grouping

variable defining cluster of observations that will be simultaneously removed by the jackknife.

ncpus

number of cpus available for parallel computation.

keep.warnings

keep warning messages obtained when estimating the model with the jackknife samples.

keep.error

keep error messages obtained when estimating the model with the jackknife samples.

initCpus

should the parallel computation be initialized?

trace

should a progress bar be used to trace the execution of the function

Examples

Run this code
# NOT RUN {
n <- 20

#### glm ####
set.seed(10)
m <- lvm(y~x+z)
distribution(m, ~y+z) <- binomial.lvm("logit")
d <- lava::sim(m,n)
g <- glm(y~x+z,data=d,family="binomial")
iid1 <- iidJack(g, ncpus = 1)
iid2 <- lava::iid(g)
quantile(iid1-iid2)
vcov(g)
colSums(iid2^2)
colSums(iid1^2)

#### Cox model ####
library(survival)
data(Melanoma, package = "riskRegression")
m <- coxph(Surv(time,status==1)~ici+age, data = Melanoma, x = TRUE, y = TRUE)

# }
# NOT RUN {
## require riskRegression > 1.4.3
if(utils::packageVersion("riskRegression") > "1.4.3"){
library(riskRegression)
iid1 <- iidJack(m)
iid2 <- iidCox(m)$IFbeta

apply(iid1,2,sd)

print(iid2)

apply(iid2,2,sd)
  }
# }
# NOT RUN {
#### LVM ####
set.seed(10)

mSim <- lvm(c(Y1,Y2,Y3,Y4,Y5) ~ 1*eta)
latent(mSim) <- ~eta
categorical(mSim, K=2) <- ~G
transform(mSim, Id ~ eta) <- function(x){1:NROW(x)}
dW <- lava::sim(mSim, n, latent = FALSE)
dL <- reshape2::melt(dW, id.vars = c("G","Id"),
                     variable.name = "time", value.name = "Y")
dL$time <- gsub("Y","",dL$time)

m1 <- lvm(c(Y1,Y2,Y3,Y4,Y5) ~ 1*eta)
latent(m1) <- ~eta
regression(m1) <- eta ~ G
e <- estimate(m1, data = dW)
# }
# NOT RUN {
iid1 <- iidJack(e)
iid2 <- iid(e)
attr(iid2, "bread") <- NULL

apply(iid1,2,sd)
apply(iid2,2,sd)
quantile(iid2 - iid1)
# }
# NOT RUN {
library(nlme)
e2 <- lme(Y~G+time, random = ~1|Id, weights = varIdent(form =~ 1|Id), data = dL)
e2 <- lme(Y~G, random = ~1|Id, data = dL)
# }
# NOT RUN {
iid3 <- iidJack(e2)
apply(iid3,2,sd)
# }

Run the code above in your browser using DataLab