code verifications (EXTRA)/2 - leeg_generation_with_regressors_verification.R

# Sample size
n <- 100

# Covariates
X <- cbind(rep(1,n), runif(n, 0,1), runif(n,0,1))

# Parameters and relations
beta <- c(1, 1.2, 0.2)

mu <- plogis(X%*%beta)
delta <- 2

M <- matrix(NA, 5000, n)
for(i in 1:5000){
  M[i,] <- rleeg(n, mu, delta)
}

# Theoric median versus simulated median
plot(mu, apply(M, 2, median), xlab = expression(mu),
     ylab = expression(M[d]), pch = 16)
abline(0, 1, lty = 2)
legend("bottomright",
       legend = paste("r = ", round(cor(mu, apply(M, 2, median)), 4)), bty = "n")

# Histogram and theoretical density
index <- sample(1:n, 1)
hist(M[, index], prob = TRUE, main = " ")
curve(dleeg(x, mu[index], delta), add = TRUE, col = 2, lwd = 2)
legend("topleft", legend = paste0("Index: ", index), bty = "n")

# Empirical distribution function and theoretical distribution function
index <- sample(1:n, 1)
plot(ecdf(M[, index]), main = " ")
curve(pleeg(x, mu[index], delta), add = TRUE, col = 2)
legend("topleft", legend = paste0("Index: ", index), bty = "n")
rdmatheus/leegarma documentation built on Sept. 19, 2020, 1:31 a.m.