Skip to content

Instantly share code, notes, and snippets.

@Stan125
Created September 3, 2018 10:06
Show Gist options
  • Save Stan125/72af910fc775e1b434f67b9990c93b65 to your computer and use it in GitHub Desktop.
Save Stan125/72af910fc775e1b434f67b9990c93b65 to your computer and use it in GitHub Desktop.
library("distreg.vis")
library("gamlss")
library("bamlss")
library("dplyr", warn.conflicts = FALSE)
### Fit a Lognormal model
wage <- ISLR::Wage
model <- gamlss(wage ~ year + ps(age) + education,
~ year + ps(age), data = wage,
family = "LOGNO")
ndata <- wage %>%
select(age, year, education) %>%
sample_n(5)
plot_moments(model, int_var = "age", pred_data = ndata)
## Inequality function
ineq <- function(par) {
2 * pnorm((par[["sigma"]] / 2) * sqrt(2)) - 1
}
## Pred_params
pred <- preds(model, ndata)
apply(pred, 1, FUN = ineq)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment