Lazymodel
Description
The lazymodel package allows you to easily build models to permform statistical analysis without the need of writting a lots of R code.
This depends on three other packages to work:
- glmmTMB (>= 1.0.1)
- argparser (>= 0.7.1)
- DHARMa (>= 0.2.7)
And needs R >= 3.4.4
to work.
Installation
To install this package, the devtools
package must be installed.
Run in R the following command to install the package:
> install_gitlab("nfontrod/lazymodel", host = "https://gitbio.ens-lyon.fr", quiet = FALSE)
Usage
In R
Here is a small example on how to use the package in R:
> library(lazymodel)
> student <- data("student", package="lazymodel") # fake dataset of 200 students with their size, age and sex.
> head(student)
size age sex
1 191.6936 24 Man
2 205.1404 23 Man
3 175.1561 19 Man
4 161.7353 18 Man
5 186.2363 20 Man
6 181.8675 25 Man
> #?make_analysis: to display the help
> make_analysis("size ~ age + sex", family="gaussian", data=student, output="./") # Analysis to see if the age or the sex of students as an impact on their size
The previous function will produce a diagnotics figures that allows you to see if your model is valid. If you see in the right panel of this figure a non-significant deviation (KS test p>0.05), and red lines in the “residuals vs predicted” plots that match quite well the black dotted lines, this means the model is a good fit to the data.
If the model is a good fit, you can look at the p-values given in the summary file of your current directory.
With a CLI (command line interface) script
First, you must create an R file containing only the following code:
# my_R_file.R
library(lazymodel)
cli_analysis()
Then you can type the following commands to see if everything works:
Rscript my_R_file.R --help
This command should display the following content:
usage: test.R [--] [--help] [--opts OPTS] [--table TABLE] [--formula
FORMULA] [--family FAMILY] [--output OUTPUT]
Model your data according to a given distribution and then performs a
statistical analysis.
flags:
-h, --help show this help message and exit
optional arguments:
-x, --opts RDS file containing argument values
-t, --table A file containing a table inside in which each column
is separated by tabs
-f, --formula The formula of your model
-F, --family The family name of the distribution tested [default:
gaussian]
-o, --output The folder that will contains the results of the
analysis [default: ./]
You have to pass to --table
argument, a file containing a table (columns separated by tabulations) with column header.
You have to pass to --formula
argument, a string corresponding to an R formula (e.g response_variable ~ pred1 + pred2). Note that the name given in the formula must be the same as those in the column header of the file given with the --table
argument.