# Useful R Functions

This package contains functions I often use when working with R. There is chance that some of them might be useful for others, hence wrapping them in a package with documentation and examples.

## Installation

``````install.packages("devtools")
devtools::install_github("ptompalski/UsefulRFunctions")
library(UsefulRFunctions)
``````

## Brief description of selected funcions

Function `calc.error()` is useful for quickly calculating bias and RMSE (and other) between observed and predicted values. This function also check the statistical significance of the differences. For example:

``````ref <- iris\$Sepal.Length
est <- predict(lm(data=iris,iris\$Sepal.Length~iris\$Petal.Width))
calc.error(reference = ref, estimate = est)
``````

Optionally a grouping variable can be added:

``````grouping_var <- iris\$Species
calc.error(reference = ref, estimate = est,by = grouping_var)
``````

I recommend setting the parameter `noinfo = F` during the first run and see how the absolute and relative bias are calculated.

## Plot templates

There are two plot templates: one for scatterplot (`scatter()`) and one for histogram (`h()`).

Using:

``````ref <- iris\$Sepal.Length
est <- predict(lm(data=iris,iris\$Sepal.Length ~ iris\$Petal.Width))
scatter(x = ref, y = est)
``````

will produce a scatter plot with additional information (text box) on the bias and RMSE. Optionally you can disable this by setting `info = F`.

The default behaviour of `h()` is to plot a histogram with chosen descriptive statistics added in a corner. You can turn them off by setting `info = F`. You can also very easly define the width of the histogram bins (much easier than with standard `hist()`) with:

``````h(ref,0.1)
``````

Both `scatter()` and `h()` use ggplot2 package to produce plots. The returned ggplot objects can be further modified with additional options:

``````h(iris\$Sepal.Length) + theme_minimal()
``````

ptompalski/UsefulRFunctions documentation built on May 26, 2019, 11:32 a.m.