ghp: Hierarchical Partitioning

Description Usage Arguments Details Examples

View source: R/ghp.R

Description

Core function of the ghp package. Gives the ability to fit all possible models and then find out what influence certain variables or groups of variables have on a specified goodness of fit.

Usage

1
2
3
4
5
6
7
8
9
ghp(
  depname,
  data,
  gof = "r.squared",
  method = "lm",
  npar = 1,
  group_df = NULL,
  ...
)

Arguments

depname

The name of the dependent variable in character form, e.g. "depvar".

data

A data.frame holding all relevant explanatory variables.

gof

Goodness of fit which should be obtained for all models. Which is available depends on the method with which the models were computed. Currently:

  • lm method: "AIC", "r.squared", "loglik", "deviance"

  • gamlss method: "AIC", "deviance", "loglik", "R2e

method

The method with which the models shall be computed. Can be one of "lm" (linear models) and "gamlss".

npar

Number of distributional parameters for which hierarchical partitioning should be done.

group_df

A data.frame object for grouping. One column, varnames depicts the explanatory variables in character form. The other one, called groups depicts the group each variable belongs to, with the dependent variable being in the group 0. See the examples section for an example.

...

Additional arguments, passed on to link[gamlss]{gamlss}.

Details

This function computes the hierarchical partitioning in four steps:

  1. Transforming the data (necessary because of the ability to specify groups of variables), indep_tf

  2. Fitting of all possible models mfit

  3. Obtaining the wanted goodness-of-fit figures gof

  4. Do hierarchical partitioning part

Afterwards, you can plot the results with plot_ghp

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Dataset
india <- ghp::india

# Linear models: Partitioning of r.squared
results_lm <- ghp(depname = "stunting", india, method = "lm", gof = "r.squared")
results_lm

# GAMLSS models: Partitioning of deviance (npar = 2)
results_gamlss <- ghp("stunting", india, method = "gamlss", gof = "deviance", npar = 2)
results_gamlss

Stan125/ghp documentation built on Feb. 1, 2020, 1:21 p.m.