-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
157 lines (124 loc) · 7.37 KB
/
README.Rmd
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
echo = FALSE
)
# git add . && git commit -m 'Added function to generate a pdf analyzing a random variable' && git push origin master
embed_png <- function(image_title, width = "100%") {
knitr::asis_output(
glue::glue("<div style=\"text-align: center; padding: 2rem 0;\">",
"<img src=\"man/figures/{image_title}\" width={width} />",
"</div>")
)
}
```
# Adjustr v0.5.0.0
<!-- badges: start -->
<!-- badges: end -->
The goal of Adjustr is to easily fit a given random variable in order to find it's distribution.
## Installation
The development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("moutikabdessabour/adjustr")
```
## Motivation
I actually wrote these functions for a homework in order to simplify the process, now here we are :smiley:.
# Using it
The package is made up of two main functions.
## getfitdistr
To fit continuous random variables
``` r
getfitdistr(x,
short=TRUE,
showplots=TRUE,
plots.as.vars=FALSE,
xlab="Claim amounts",
color=c(gamma = "steelblue", lognormal="firebrick",exponential= "green"))
```
The available arguments are:
| Argument | Description |
| -------- | ----------- |
|`short` | when used the function will return only the best fitted distribution if it exists |
|`x` | The vector that contains the values of the continuous random variable |
|`showplots` | Whether To show the plots or not |
|`plots.as.vars` | Whether you want to add the plots to the result |
|`xlab` | what do you want to name the X axis? |
|`color` |The color you want to use in the plots |
This code is all that's needed to fit your random variable, the returned value is a list. let `distribution` be the name of a distribution we have:
| File | Description |
| ---- | ---- |
|`distributions` | The distribution that the code looped through. |
|`acceptedDistr` | A `data.frame` that contains the distributions that verify the null hypothesis order from the lowest **AIC** to the biggest. |
| `distribution` | A list containing the `$estimate` for said distribution, the `$p.value` for the Kolmogorov-Smirnov test, `$accepthyp` when the Null Hypothesis is accepted or not and `$aic` containing the *Akaike information criterion* for this distribution. |
|`bestdistr`| the best fitted distribution|
## getgoodfit
To fit discrete random variables:
``` r
getgoodfit(x, showplots=F, short=TRUE, plots.as.vars=F, xlab="Number of claims")
```
The available arguments are:
| Argument | Description |
| -------- | ----------- |
|`short` | when used the function will return only the best fitted distribution if it exists |
|`x` | The vector that contains the values of the discrete random variable |
|`showplots` | Whether To show the plots or not |
|`plots.as.vars` | Whether you want to add the plots to the result |
|`xlab` | what do you want to name the X axis? |
This code is all that's needed to fit your random variable, the returned value is a list. let `distribution` be the name of a distribution we have:
| File | Description |
| ---- | ---- |
|`distributions` | The distribution that the code looped through. |
|`acceptedDistr` | A `data.frame` that contains the distributions that verify the null hypothesis order from the lowest **Chi-squared** to the biggest. |
|`distribution` | A list containing the `$estimate` for said distribution, the `$observed` and `$fitted` values, the `$count` and the `$prob`, the `$p.value`, `$Xsquared` and the `$df` degrees of freedom for the Chi-squared test, `$accepthyp` when the Null Hypothesis is accepted or not. |
|`bestdistr`| the best fitted distribution|
# rmd.continuous & rmd.discrete
To create a PDF or HTML file analyzing a continuous/discrete random variable use the following functions:
``` r
rmd.continuous(output_file,
author,
path,
title="Ajustement d'une V.A",
date=Sys.Date(),
output_dir=getwd(),
output_format,
verbose=F,
...)
rmd.discrete(output_file,
author,
path,
title="Ajustement d'une V.A",
date=Sys.Date(),
output_dir=getwd(),
output_format,
verbose=F,
...)
```
The available arguments are:
| Argument | Description |
| -------- | ----------- |
|`output_file` | The name of the output file. If using NULL then the output filename will be based on filename for the input file. If a filename is provided, a path to the output file can also be provided. Note that the output_dir option allows for specifying the output file path as well, however, if also specifying the path, the directory must exist. If output_file is specified but does not have a file extension, an extension will be automatically added according to the output format. To avoid the automatic file extension, put the output_file value in `I()`, e.g., `I('my-output')`. |
| `author` | The author to use in the template |
| `path` | The path to the csv file. note that the column that contains the random variable values must be the second column|
| `title` | The title to be used in the template |
| `date` | The date to be used in the template |
| `output_dir` | The output directory for the rendered output_file. This allows for a choice of an alternate directory to which the output file should be written (the default output directory of that of the input file). If a path is provided with a filename in output_file the directory specified here will take precedence. Please note that any directory path provided will create any necessary directories if they do not exist. |
| `output_format` | The R Markdown output format to convert to. The option "all" will render all formats defined within the file. The option can be the name of a format (e.g. "html_document") and that will render the document to that single format. One can also use a vector of format names to render to multiple formats. Alternatively, you can pass an output format object (e.g. `html_document()`). If using NULL then the output format is the first one defined in the YAML frontmatter in the input file (this defaults to HTML if no format is specified there). |
| `verbose` | An option to suppress printing of the pandoc command line. |
| `...` | Additional arguments to be passed to `rmarkdown::render()` |
When `run_pandoc = TRUE`, the compiled document is written into
the output file, and the path of the output file is returned. When
`run_pandoc = FALSE`, the path of the Markdown output file, with
attributes `knit_meta` (the `knitr` meta data collected from code
chunks) and `intermediates` (the intermediate files/directories
generated by `render()`
**NB**: The `Rmd` templates are only in french :cry: To see the results check the following links
`r paste0(mgsub::mgsub(paste0('(https://moutikabdessabour.github.io/adjustr/inst/examples/',c("continuous", "continuous", "discrete", "discrete"), c(".html)", ".pdf)")), "^(.+/(.+?)\\.(.{3,4})\\))$", "\n- [\\2 format \\3]\\1"))`
# Questions?
Confused by anything? [Open an issue on github](https://github.com/moutikabdessabour/adjustr/issues/new) and let me know.