Set up a DGP with correlation between errors for the beta regression

81 Views Asked by At

I want to set up a scenario where errors are correlated. In the first setting, a betaregression should be fit, the second scenario includes a conditional logit model.

In order to correlate the two scenarios, I correlate the errors (or at least that is the idea). However, I'm struggling setting up a scenario for the beta regression. Within here are kind of two questions. First, how to set up the error for the beta regression that preversevs the correlation and second, how to set up the data.

Here is what I have:

This function produces correlated errors for a normal regression scenario and a conditional logit sceanrio:

library(mvtnorm);library(betareg)

error_function <- function(rho.mc){
  vmat <- matrix(c(1,rho.mc, rho.mc, 1), nrow=2)
  v <- mvtnorm::rmvnorm(n, c(0,0), vmat)

  e1 <- v[,1]
  u2 <- pgumbel(v[,2])
  e2 <- -log(1-u2) 
  return(list(e1=e1, e2=e2))
}

n <- 300
mc.correlation <- 0.9
set.seed(1)
x1 <- runif(n) * 4 - 2

error_A <- error_function(mc.correlation)
cor(error_A$e1, error_A$e2)
[1] 0.8476043
# more or less the same

Without the need to define the error by hand I would do this:

eta <- c(1, -0.2)
gamma <- eta
mu <- binomial(link = logit)$linkinv(eta[1] + eta[2]*x1)
phi <- binomial(link = log)$linkinv(gamma[1] + gamma[2]*x1)
set.seed(1)
y_A <- rbeta(n, mu * phi, (1 - mu) * phi)

beta.fit <- betareg::betareg(y_A~x1)

However, this does not preserve the correlation:

cor(residuals(beta.fit), error_A$e2)
[1] 0.1049023

How do I set up a DGP that preserves my correlation?

Thanks, Tom

0

There are 0 best solutions below