fit_univariate: Fit Univariate Distribution

Description Usage Arguments Value Examples

View source: R/distfun.R

Description

Fit Univariate Distribution

Usage

1
fit_univariate(x, distribution, type = "continuous")

Arguments

x

numeric vector

distribution

character name of distribution

type

discrete or continuous data

Value

a fitted list object of d, p, q, r distribution functions and parameters, MLE for probability distributions, custom fit for empirical

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Fit Discrete Distribution
set.seed(42)
x <- rpois(1000, 3)
fitted <- fit_univariate(x, 'pois', type = 'discrete')
# density function
plot(fitted$dpois(x=0:10),
     xlab = 'x',
     ylab = 'dpois')
# distribution function
plot(fitted$ppois(seq(0, 10, 1)),
     xlab= 'x',
     ylab = 'ppois')
# quantile function
plot(fitted$qpois,
     xlab= 'x',
     ylab = 'qpois')
# sample from theoretical distribution
summary(fitted$rpois(100))
# estimated parameters from MLE
fitted$parameters

set.seed(24)
x <- rweibull(1000, shape = .5, scale = 2)
fitted <- fit_univariate(x, 'weibull')
# density function
plot(fitted$dweibull,
     xlab = 'x',
     ylab = 'dweibull')
# distribution function
plot(fitted$pweibull,
     xlab = 'x',
     ylab = 'pweibull')
# quantile function
plot(fitted$qweibull,
     xlab = 'x',
     ylab = 'qweibull')
# sample from theoretical distribution
summary(fitted$rweibull(100))
# estimated parameters from MLE
fitted$parameters

Example output

   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   0.00    1.00    3.00    2.75    4.00   10.00 
lambda 
  2.93 
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
 0.00001  0.18442  1.18814  4.83963  5.18201 81.99765 
    shape     scale 
0.4879054 2.0564428 

fitur documentation built on May 2, 2019, 6:37 a.m.