All Projects → jthaman → Citools

jthaman / Citools

Licence: gpl-3.0
An R Package for Quick Uncertainty Intervals

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to Citools

Data Science Toolkit
Collection of stats, modeling, and data science tools in Python and R.
Stars: ✭ 169 (+67.33%)
Mutual labels:  modeling, tidyverse
Tidytransit
R package for working with the General Transit Feed Specification (GTFS)
Stars: ✭ 84 (-16.83%)
Mutual labels:  tidyverse
Janitor
simple tools for data cleaning in R
Stars: ✭ 981 (+871.29%)
Mutual labels:  tidyverse
Broom
Convert statistical analysis objects from R into tidy format
Stars: ✭ 1,087 (+976.24%)
Mutual labels:  modeling
Intro spatialr
Introduction to GIS and mapping in R with the sf package
Stars: ✭ 39 (-61.39%)
Mutual labels:  tidyverse
Opensource
Code for geophysical 3D/2D Finite Difference modelling, Marchenko algorithms, 2D/3D x-w migration and utilities.
Stars: ✭ 60 (-40.59%)
Mutual labels:  modeling
Tidy Text Mining
Manuscript of the book "Tidy Text Mining with R" by Julia Silge and David Robinson
Stars: ✭ 961 (+851.49%)
Mutual labels:  tidyverse
Network traffic modeler py3
pyNTM - This is the network traffic modeler written in python 3: pip3 install pyNTM
Stars: ✭ 93 (-7.92%)
Mutual labels:  modeling
Componentarrays.jl
Arrays with arbitrarily nested named components.
Stars: ✭ 72 (-28.71%)
Mutual labels:  modeling
R for data science
Materials for teaching R and tidyverse
Stars: ✭ 54 (-46.53%)
Mutual labels:  tidyverse
Modeler
Free 3D Modeling Tool
Stars: ✭ 50 (-50.5%)
Mutual labels:  modeling
Ggplot Courses
👨‍🏫 ggplot2 Teaching Material
Stars: ✭ 40 (-60.4%)
Mutual labels:  tidyverse
Tidylo
Weighted tidy log odds ratio ⚖️
Stars: ✭ 62 (-38.61%)
Mutual labels:  tidyverse
Cryptobeauty
Crypto Beauty 密碼女孩 - 你專屬的區塊鏈少女卡片創作交易平台. Live on the TRON Blockchain.
Stars: ✭ 37 (-63.37%)
Mutual labels:  modeling
Wrf hydro nwm public
WRF-Hydro model code
Stars: ✭ 85 (-15.84%)
Mutual labels:  modeling
Tidytext
Text mining using tidy tools ✨📄✨
Stars: ✭ 975 (+865.35%)
Mutual labels:  tidyverse
Opengeode
Open source framework for representing and manipulating geometric models
Stars: ✭ 46 (-54.46%)
Mutual labels:  modeling
Prysm
physical optics: integrated modeling, phase retrieval, segmented systems, polynomials and fitting, ...
Stars: ✭ 57 (-43.56%)
Mutual labels:  modeling
Machinelearning
A repo with tutorials for algorithms from scratch
Stars: ✭ 96 (-4.95%)
Mutual labels:  modeling
Intror
这是一本中文 R 语言入门书,基于最新 tidyverse 包。
Stars: ✭ 86 (-14.85%)
Mutual labels:  tidyverse

ciTools: An R Package for Quick Uncertainty Intervals

As seen at RStudio::conf2018!

Overview

ciTools is an R package that makes working with model uncertainty as easy as possible. It gives the user easy access to confidence or prediction intervals for the fitted values of (log-) linear models, generalized linear models, and (log-) linear mixed models. Additionally, we provide functions to determine probabilities and quantiles of the conditional response distribution given each of these models.

Why use ciTools?

Uncertainty intervals (confidence or prediction intervals) for fitted values are easy enough if one is just working with linear models, but when models become more complex, e.g. generalized linear models or linear mixed models, the facilities for quantifying uncertainty for predictions are either more cumbersome to work with or nonexistent. We hope that ciTools provides uniform, model invariant access to these statistics.

Main Components

This package has three main features that make it useful to R users:

  • Data frame first design - Easily pipe commands together (great for ggplot users)
  • Uniform syntax - all commands have the same simple syntax and sane defaults.
  • Generic design - One command for each statistical quantity

All commands in ciTools:

  • add_ci(data, fit, ...) - get confidence intervals and append to data
  • add_pi(data, fit, ...) - get prediction intervals and append to data
  • add_probs(data, fit, q, ...) - get conditional response probabilities, Pr(Response|Covariates < q)
  • add_quantile(data, fit, p, ...) - get conditional response quantiles at level p

Installation

Install from CRAN:

install.packages("ciTools")
library(ciTools)

Install ciTools from Github with devtools:

library(devtools)
devtools::install_github("jthaman/ciTools")
library(ciTools)

If you are behind a corporate firewall, you may have to instead run:

library(httr)
library(devtools)
httr::set_config(config(ssl_verifypeer = FALSE))
devtools::install_github("jthaman/ciTools")
httr::set_config(config(ssl_verifypeer = TRUE))
library(ciTools)

Usage

Here is a short example featuring a linear mixed model, but the idea is the same for any other model.

## Example with a linear mixed model

library(ciTools)
library(lme4)
library(dplyr)

dat <- sleepstudy ## data included with lme4
## Fit a random intercept model
fit <- lmer(Reaction ~ Days + (1 | Subject), data = dat)

## New data for predictions
## A random sample of 20 observations from sleepstudy
new_dat <- sleepstudy[sample(NROW(dat), 20),]

## Append (conditional) 50% CIs and PIs to the new data:
new_dat <- add_ci(new_dat, fit, alpha = 0.5) %>%
    add_pi(fit, alpha = 0.5)

## Append 50% CIs and PIs, but ignore the random effects:
add_ci(new_dat, fit, alpha = 0.5, includeRanef = FALSE,
       names = c("lcb_uncond", "ucb_uncond"), ## custom interval names
       yhatName = "pred_uncond") %>%
    add_pi(fit, alpha = 0.5, includeRanef = FALSE,
           names = c("lpb_uncond", "upb_uncond"))

## Determine the probability that a new Reaction time will be less
## than 300 (given the model and new data):
add_probs(new_dat, fit, 300)

## Or greater than:
add_probs(new_dat, fit, 300, comparison = ">")

## Determine the 0.9-quantile of the predictive distribution, given the
## model and new data:
add_quantile(new_dat, fit, 0.9)

The end result is a data frame that is amenable to plotting with ggplot2. See the documentation for more examples with other types of statistical regression models.

Scope of ciTools

Model Confidence Intervals Prediction Intervals Response Probabilities Response Quantiles
Linear [X] [X] [X] [X]
Log-Linear [X] [X] [X] [X]
GLM [X] [X] [X] [X]
Neg. Binomial [X] [X] [X] [X]
Linear Mixed [X] [X] [X] [X]
Log-Linear Mixed [TODO] [X] [X] [X]
Survival (AFT model) [X] [X] [X] [X]
GLMM [X] [X] [X] [X]

[X] = Implemented

Help us out?

We still have work to do. Submit an Issue if you run into a bug, or a PR if you think you can help us out (see the TODO file).

Authors

John Haman and Matt Avery

Copyright

ciTools (C) 2017 Institute for Defense Analyses

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].