fit_steplength {cylcop}R Documentation

Fit a Linear Univariate Distribution

Description

This function finds parameter estimates of the marginal linear distribution, or gives a kernel density estimate using a Gaussian smoothing kernel.

Usage

fit_steplength(
  x,
  parametric = c("beta", "cauchy", "chi-squared", "chisq", "exponential", "exp", "gamma",
    "lognormal", "lnorm", "lognorm", "logistic", "normal", "t", "weibull", "normalmix",
    "weibullmix", "gammamix", "lnormmix", FALSE),
  start = NULL,
  bandwidth = NULL,
  ncomp = 2
)

Arguments

x

numeric vector of measurements of a linear random variable in [0,\infty).

parametric

either a character string describing what distribution should be fitted ("beta", "cauchy", "chi-squared", "exponential", "gamma", "lognormal", "logistic", "normal", "t", "weibull","normalmix", "weibullmix", "gammamix", or "lnormmix"), or the logical FALSE if a non-parametric estimation (kernel density) should be made.

start

(optional, except when parametric = "chi-squared") named list containing the parameters to be optimized with initial values.

bandwidth

numeric value for the kernel density bandwidth. Default is cylcop::opt_lin_bw(x, "nrd").

ncomp

integer, number of components of the mixed distribution. Only has an effect if parametric %in% c("normalmix", "weibullmix", "gammamix", "lnormmix").

Value

If a parametric estimate is made, a list is returned containing the estimated parameters, their standard errors, the log-likelihood, the AIC and the name of the distribution. If a non-parametric estimate is made, the output is a a 'density' object, which is obtained with the function GoFKernel::density.reflected() of the 'GoFKernel' package.

See Also

GoFKernel::density.reflected(), fit_angle(), opt_lin_bw().

Examples

require(graphics)
set.seed(123)

silent_curr <- cylcop_get_option("silent")
cylcop_set_option(silent = TRUE)

n <- 100 #n (number of samples) is set small for performance.

x <- rweibull(n, shape = 10)

dens_non_param <- fit_steplength(x = x, parametric = FALSE)
weibull <- fit_steplength(x = x, parametric = "weibull")
gamma <- fit_steplength(x = x, parametric = "gamma")
chisq <- fit_steplength(x = x, parametric = "chi-squared", start = list(df = 1))

true_dens <- dweibull(seq(0, max(x), length.out = 200),
  shape = 10
)
dens_weibull <- dweibull(seq(0, max(x),length.out = 200),
  shape = weibull$coef$shape,
  scale = weibull$coef$scale
)
dens_gamma <- dgamma(seq(0, max(x),length.out = 200),
  shape = gamma$coef$shape,
  rate = gamma$coef$rate
)
dens_chisq <- dchisq(seq(0, max(x),length.out = 200),
  df = chisq$coef$df
)

plot(seq(0,max(x),length.out = 200), true_dens, type = "l")
lines(dens_non_param$x, dens_non_param$y, col = "red")
lines(seq(0,max(x),length.out = 200), dens_weibull, col = "green")
lines(seq(0,max(x),length.out = 200), dens_gamma, col = "blue")
lines(seq(0,max(x),length.out = 200), dens_chisq, col = "cyan")

cylcop_set_option(silent = silent_curr)


[Package cylcop version 0.2.0 Index]