Created
March 27, 2016 21:35
-
-
Save mick001/5b75924bc0755e96f279 to your computer and use it in GitHub Desktop.
How to fit a copula model in R [heavily revised]. Part 2: fitting the copula. Full article at
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Estimate x gamma distribution parameters and visually compare simulated vs observed data | |
x_mean <- mean(mydata$x) | |
x_var <- var(mydata$x) | |
x_rate <- x_mean / x_var | |
x_shape <- ( (x_mean)^2 ) / x_var | |
hist(mydata$x, breaks = 20, col = "green", density = 20) | |
hist(rgamma( nrow(mydata), rate = x_rate, shape = x_shape), breaks = 20,col = "blue", add = T, density = 20, angle = -45) | |
# Estimate y gamma distribution parameters and visually compare simulated vs observed data | |
y_mean <- mean(mydata$y) | |
y_var <- var(mydata$y) | |
y_rate <- y_mean / y_var | |
y_shape <- ( (y_mean)^2 ) / y_var | |
hist(mydata$y, breaks = 20, col = "green", density = 20) | |
hist(rgamma(nrow(mydata), rate = y_rate, shape = y_shape), breaks = 20, col = "blue", add = T, density = 20, angle = -45) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment