family_fun: Evaluate GAMLSS family functions from gamlss object

Description Usage Arguments Value Examples

View source: R/samplecensored.R

Description

Function that, given a "gamlss" object, evaluates the distribution-specific functions under predicted parameters of the provided dataframe "predictdata".
The distribution-specific functions are density, cumulative distribution function, quantile function and random generation for the given family of the gamlss object.
CAUTION: Exactly ONE of the arguments x, q, p, n MUST be specfied!
Also make sure that n is a multiple of nrow(predictdata)!

Usage

1
2
family_fun(object, func = c("d", "p", "q", "r"), fitdata, predictdata,
  p = NULL, q = NULL, x = NULL, n = NULL, ...)

Arguments

object

gamlss fit object

func

character. "d", "p", "q", "r" for either density, distribution function, quantile or random data generation.

fitdata

dataframe. Data used as input.

predictdata

dataframe. Containing the observations for which the parameters are predicted.

p

scalar numeric. Probability value if quantile function used.

x, q

scalar numeric. Quantile value if density or probability function used respectively.

n

scalar numeric. Number of observations if random generator function used.

...

argumenst to be passed to the called distributional function.

Value

Depending on the choice of func, the respective vector of (d)density-, (p)probability- , (q)quantile- or (r)random values is returned.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Simulating a dataset
ld <- simulateData(n= 300,
param.formula = list(mu = ~exp(x1) + x2 + x3, sigma = ~sin(x2)),
name = 'x1', subset = ~ (x2 < 0.3 & x3 < 0.4), prob = 0.8, 
damage =c(0.3, 0.9), family = 'NO', 
correlation = NULL)$defected

# Fitting a gamlss model
lmodel <- gamlss(formula = y ~ . -indicator, data=ld)
nl <- length(ld$x1[ld$indicator==1])
lpredict.df <- data.frame(x1 = runif(n = nl), x2 = runif(n = nl), x3 = runif(n = nl), indicator = 1)
family_fun(lmodel, func = 'r',ld, lpredict.df, n = nrow(lpredict.df))

TiStat/Imputegamlss documentation built on May 20, 2019, 9:25 a.m.