knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

gamlssutils

The goal of gamlssutils is to provide functions to ease extracting and displaying output from GAMLSS models.

Installation

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("MiguelRodo/gamlssutils")

Example

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)

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)

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))

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)

The \code{vcov.gamlss} function (i.e. the \code{vcov}) method for \code{gamlss} objects) expects to find the object passed to the \code{data} parameter in the call to \code{gamlss} 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 \code{gamlss} 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.



MiguelRodo/gamlssutils documentation built on July 9, 2020, 12:48 a.m.