Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate confidence intervals for model averaged data using shrinkage in R

Tags:

r

statistics

I'm trying to run a nest survival model using the logistic-exposure method based on Shaffer, 2004. I have a range of parameters and wish to compare all possible models and then estimate model-averaged parameters using shrinkage as in Burnham and Anderson, 2002. However, I am having trouble figuring out how to estimate the confidence intervals for the shrinkage adjusted parameters.

Is it possible to estimate confidence intervals for the model-averaged parameters estimated using shrinkage? I can easily extract the mean estimates for the model-averaged parameters with shrinkage using model.average$coef.shrinkage but am unclear how to get the corresponding confidence intervals.

Any help is gratefully appreciated. I'm currently working with the MuMIn package as I get errors with AICcmodavg regarding the link function.

Below is a simplified version of the code I'm using:

library(MuMIn)

# Logistical Exposure Link Function
# See Shaffer, T.  2004. A unifying approach to analyzing nest success. 
# Auk 121(2): 526-540.

logexp <- function(days = 1)
{
  require(MASS)
  linkfun <- function(mu) qlogis(mu^(1/days))
  linkinv <- function(eta) plogis(eta)^days
  mu.eta <- function(eta) days * plogis(eta)^(days-1) *
    .Call("logit_mu_eta", eta, PACKAGE = "stats")
  valideta <- function(eta) TRUE
  link <- paste("logexp(", days, ")", sep="")
  structure(list(linkfun = linkfun, linkinv = linkinv,
             mu.eta = mu.eta, valideta = valideta, name = link),
        class = "link-glm")
}

# randomly generate data
nest.data <- data.frame(egg=rep(1,100), chick=runif(100), exposure=trunc(rnorm(100,113,10)), density=rnorm(100,0,1), height=rnorm(100,0,1))
  nest.data$chick[nest.data$chick<=0.5] <- 0
  nest.data$chick[nest.data$chick!=0] <- 1

# run global logistic exposure model
glm.logexp <- glm(chick/egg ~  density * height, family=binomial(logexp(days=nest.data$exposure)), data=nest.data)

# evaluate all possible models
model.set <- dredge(glm.logexp)

# model average 95% confidence set and estimate parameters using shrinkage
mod.avg <- model.avg(model.set, beta=TRUE)
(mod.avg$coef.shrinkage)

Any ideas on how to extract/generate the corresponding confidence intervals?

Thanks Amy

like image 516
nzwormgirl Avatar asked Nov 12 '12 05:11

nzwormgirl


1 Answers

After pondering about this for a while, I have come up with the following solution based on equation 5 in Lukacs, P. M., Burnham, K. P., & Anderson, D. R. (2009). Model selection bias and Freedman’s paradox. Annals of the Institute of Statistical Mathematics, 62(1), 117–125. Any comments on its validity would be appreciated.

The code follows on from that above:

# MuMIn generated shrinkage estimate  
  shrinkage.coef <- mod.avg$coef.shrinkage 

# beta parameters for each variable/model combination
coef.array <- mod.avg$coefArray
  coef.array <- replace(coef.array, is.na(coef.array), 0) # replace NAs with zeros

# generate empty dataframe for estimates
shrinkage.estimates <- data.frame(shrinkage.coef,variance=NA)

# calculate shrinkage-adjusted variance based on Lukacs et al, 2009
for(i in 1:dim(coef.array)[3]){
  input <- data.frame(coef.array[,,i],weight=model.set$weight)

  variance <- rep(NA,dim(input)[2])
  for (j in 1:dim(input)[2]){
    variance[j] <- input$weight[j] * (input$Std..Err[j]^2 + (input$Estimate[j] - shrinkage.estimates$shrinkage.coef[i])^2)
  }
  shrinkage.estimates$variance[i] <- sum(variance)  
}

# calculate confidence intervals
shrinkage.estimates$lci <- shrinkage.estimates$shrinkage.coef - 1.96*shrinkage.estimates$variance
shrinkage.estimates$uci <- shrinkage.estimates$shrinkage.coef + 1.96*shrinkage.estimates$variance
like image 131
nzwormgirl Avatar answered Sep 22 '22 14:09

nzwormgirl