Introduction to fitur

Thomas Roh

February 13, 2017

Basic Function

fitur is a package to provide wrapper functions for fitting univariate distributions. The main function is fit_univariate where you can supply numeric data to the function along with the desired attributes of the distribution you want to fit. It returns a list object with the density, distribution, quantile, and random deviates functions based on the calculated parameters from the given numeric vector.

Discrete Distributions

set.seed(562)
x <- rpois(100, 1)
fittedPois <- fit_univariate(x, 'pois', 'discrete')
fittedPois$dpois(1)
## [1] 0.3672432
fittedPois$ppois(1)
## [1] 0.713699
fittedPois$qpois(.5)
## [1] 1
fittedPois$rpois(100)
##   [1] 3 0 1 1 1 0 1 0 2 1 0 2 1 1 1 0 1 0 2 1 2 0 1 0 0 1 2 0 0 1 0 0 1 0 1
##  [36] 2 2 2 1 0 1 0 1 1 1 1 1 0 0 3 1 0 1 0 1 2 0 0 0 2 0 1 1 1 1 1 2 1 0 1
##  [71] 4 0 1 0 4 1 3 0 1 1 2 1 1 1 1 0 0 1 1 1 1 1 1 0 1 0 0 0 2 1
fittedPois$parameters
## lambda 
##   1.06

Continuous Distributions

set.seed(562)
x <- rexp(100, 1)
fittedExp <- fit_univariate(x, 'exp')
fittedExp$dexp(1)
## [1] 0.3671239
fittedExp$pexp(1)
## [1] 0.6082921
fittedExp$qexp(.5)
## [1] 0.7395629
fittedExp$rexp(100)
##   [1] 2.351001e+00 2.948149e-05 2.367160e-01 1.112476e-01 2.605569e-01
##   [6] 3.920280e-01 7.761996e-01 1.129285e+00 7.938331e-01 1.314894e+00
##  [11] 4.626290e+00 5.474731e-01 9.630294e-01 5.589443e-02 3.522836e-01
##  [16] 1.593953e+00 1.190270e+00 3.732245e-01 8.164341e-01 1.613205e-01
##  [21] 1.839307e-01 1.251105e+00 1.990244e-01 6.854576e-01 9.426148e-01
##  [26] 1.958607e-02 1.219231e+00 8.030401e-02 1.192183e-01 4.300381e-01
##  [31] 1.519516e+00 1.900270e+00 2.342017e-01 3.429285e+00 1.128696e+00
##  [36] 1.473901e+00 2.840781e+00 1.598224e+00 2.514877e+00 9.126977e-01
##  [41] 2.056496e+00 6.276563e-01 5.496089e+00 7.583716e-01 1.068971e-01
##  [46] 1.909485e+00 1.049224e+00 1.486235e-01 4.234806e-01 1.026815e+00
##  [51] 1.353383e+00 1.920793e+00 5.790217e-01 5.668848e-01 1.338228e+00
##  [56] 3.835856e-01 3.086888e-01 3.008105e-01 5.773580e-01 3.107248e-01
##  [61] 3.473637e+00 3.624335e-01 1.996212e-01 1.005359e+00 8.012569e-02
##  [66] 1.970946e-01 1.407484e-01 1.789542e+00 2.049385e+00 5.796875e-01
##  [71] 1.179815e+00 6.653025e-01 2.514092e-01 1.190967e-01 9.912087e-01
##  [76] 2.690759e-01 1.165251e+00 4.870345e-01 4.050169e-01 2.400283e-01
##  [81] 1.957742e+00 3.530745e+00 1.134700e+00 4.092567e-01 1.598225e+00
##  [86] 2.542079e-01 1.399733e+00 2.630077e-01 5.012669e+00 4.139787e+00
##  [91] 1.646861e+00 5.261133e-01 7.217565e-01 6.484577e+00 1.311477e+00
##  [96] 5.754227e-01 7.194780e-01 7.236361e-01 4.702101e-01 5.925928e-02
fittedPois$parameters
## lambda 
##   1.06

Empirical Distributions

The package also allows users to specify empirical distributions. For discrete distributions, the function will not truncate any integer values with the given input. For continuous distributions, the function will create bins using the Freedman-Diaconis rule.

set.seed(562)
x <- rpois(100, 1)
fittedDEmp <- fit_univariate(x, family = 'empirical', type = 'discrete')
fittedDEmp$dempDis(1)
##   1 
## 0.3
fittedDEmp$pempDis(1)
## [1] 0.69
fittedDEmp$qempDis(.5)
## [1] 0
fittedDEmp$rempDis(100)
##   [1] 3 0 1 1 1 0 1 0 2 1 0 2 1 1 1 0 1 0 3 1 2 0 1 0 0 1 2 0 0 1 0 0 1 0 1
##  [36] 2 3 3 1 0 0 0 1 1 0 1 1 0 0 3 1 0 1 0 1 3 0 0 0 3 0 1 1 1 1 1 2 1 0 1
##  [71] 3 0 1 0 3 0 3 0 1 1 2 1 0 1 1 0 0 1 1 1 1 1 1 0 0 0 0 0 2 1
fittedPois$parameters
## lambda 
##   1.06
set.seed(562)
x <- rexp(100, 1)
fittedCEmp <- fit_univariate(x, family = 'empirical', type = 'continuous')
fittedCEmp$dempCont(1)
## (0.562,1.12] 
##         0.27
fittedCEmp$pempCont(1)
## [1] 0.69
fittedCEmp$qempCont(.5)
## [1] 0.27883
fittedCEmp$rempCont(100)
##   [1] 0.27883 3.08000 0.27883 3.64000 0.27883 0.84100 0.84100 2.52000
##   [9] 0.84100 0.27883 0.84100 0.84100 0.27883 0.27883 0.84100 0.84100
##  [17] 0.84100 0.84100 0.84100 0.84100 0.27883 0.27883 0.27883 0.27883
##  [25] 0.27883 1.40000 0.84100 0.27883 6.43500 0.84100 2.52000 0.84100
##  [33] 1.96000 0.27883 0.84100 0.84100 0.84100 0.84100 0.84100 0.27883
##  [41] 0.27883 2.52000 1.40000 0.27883 0.84100 0.27883 0.84100 2.52000
##  [49] 0.27883 1.96000 0.27883 0.27883 0.27883 0.84100 0.84100 1.40000
##  [57] 0.27883 0.27883 0.84100 0.27883 0.27883 0.84100 0.27883 0.27883
##  [65] 0.27883 1.96000 2.52000 0.27883 0.84100 0.27883 0.27883 0.27883
##  [73] 1.40000 0.27883 0.84100 0.27883 1.40000 0.84100 0.27883 0.27883
##  [81] 1.96000 0.27883 0.84100 3.64000 4.20000 0.84100 0.84100 0.27883
##  [89] 0.84100 0.27883 0.27883 0.84100 0.84100 1.40000 1.40000 0.27883
##  [97] 3.08000 0.84100 0.84100 1.40000
fittedPois$parameters
## lambda 
##   1.06