The goal of gamlssutils is to provide functions to ease extracting and displaying output from GAMLSS models.
You can install the development version from GitHub with:
# install.packages("devtools")
devtools::install_github("MiguelRodo/gamlssutils")
Here we load the package and create example data:
library(gamlssutils)
set.seed(1)
data_mod <- data.frame(x = rnorm(20, 5) + rgamma(20, 0.01, 0.0001))
data_mod[['y']] <- 3 * data_mod[['x']] + rnorm(20, sd = 5)
head(data_mod)
#> x y
#> 1 4.373585 18.90344
#> 2 5.183644 19.71117
#> 3 4.164371 11.35647
#> 4 6.595281 21.11653
#> 5 5.329508 14.10501
#> 6 4.179532 24.74542
You can easily extract coefficients from all parameters into an organised table:
mod <- gamlss::gamlss(formula = y ~ -1 + x,
family = "BCPE",
data = data_mod,
control = gamlss::gamlss.control(trace = FALSE))
get_coef_tbl(mod = mod)
#> # A tibble: 2 x 5
#> Variable `Mu coefficient` `Sigma coefficie~ `Nu coefficient` `Tau coefficien~
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 Intercept NA 0.389 0.796 0.841
#> 2 x 2.87 NA NA NA
These tables are pleasantly displayed with pander::pandoc.table
(remember to set results = 'asis'
in chunk options):
# install.packages('pander')
pander::pandoc.table(get_coef_tbl(mod = mod))
| Variable | Mu coefficient | Sigma coefficient | Nu coefficient | Tau coefficient | | :-------: | :------------: | :---------------: | :------------: | :-------------: | | Intercept | NA | 0.3889 | 0.7964 | 0.8413 | | x | 2.868 | NA | NA | NA |
You can get the LR test results neatly put into a table:
# data
set.seed(1)
data_mod <- data.frame(x = rnorm(20, 5) + rgamma(20, 0.01, 0.0001))
data_mod[['y']] <- 3 * data_mod[['x']] + rnorm(20, sd = 5)
# models
mod_mu <- gamlss::gamlss(formula = y ~ -1 + x,
family = "NO",
data = data_mod,
control = gamlss::gamlss.control(trace = FALSE))
mod_sigma <- gamlss::gamlss(formula = y ~ -1 + x,
sigma.formula = ~ x,
family = "NO",
data = data_mod,
control = gamlss::gamlss.control(trace = FALSE))
# table
lr_tbl <- get_lr_tbl(mod = mod_sigma, mod_null = mod_mu,
mod_null_name = "sigma")
pander::pandoc.table(lr_tbl)
| Comp. model | LR Chi^2 | LR DF | LR P-value | | :---------: | :------: | :---: | :--------: | | sigma | 3.916 | 1 | 0.04784 |
The function (i.e. the ) method for objects) expects to find the
object passed to the parameter in the call to to be found in the
global environment. However, this may often not be the case, as that
object may have changed or else may longer/may have never existed in the
global environment. The function get_vcov
gets around it. You pass it
the dataframe that was given to the function and the name it had at the
time (as a string), and get_vcov
will then be able to calculate the
variance-covariance matrix in any environment.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.