Skip to content

Installation

Ivan Svetunkov edited this page Jul 21, 2026 · 8 revisions

Installation

This page provides detailed instructions for installing the Greybox package in both R and Python.


R Installation

From CRAN (Recommended)

The easiest way to install Greybox in R is from CRAN:

install.packages("greybox")

To load the package:

library(greybox)

From GitHub (Development Version)

To install the latest development version from GitHub:

# Install from GitHub
remotes::install_github("openforecast-org/greybox")

R Requirements

  • R version 3.5.0 or higher
  • The following R packages are automatically installed as dependencies:
    • stats
    • generics
    • graphics
    • utils
    • pracma
    • nloptr
    • statmod
    • zoo
    • texreg
    • xtable
    • methods
    • Rcpp (LinkingTo)

Verifying Installation

To verify that Greybox is installed correctly in R:

# Check package version
packageVersion("greybox")

# Load the package
library(greybox)

# Get help
?greybox

Quick Start

library(greybox)

# Simple example with mtcars data
data <- mtcars

# Fit a model
model <- alm(mpg ~ wt + disp + hp, data, distribution = "dnorm")

# Get summary
summary(model)

# Make predictions
predictions <- predict(model)

Troubleshooting

Package installation fails

If installation from CRAN fails, try:

  1. Update R to the latest version
  2. Install dependencies manually:
install.packages(c("generics", "pracma", "nloptr", "statmod", "zoo", "texreg", "xtable"))
  1. Try installing from GitHub:
remotes::install_github("openforecast-org/greybox")

Python Installation

From PyPI (Recommended)

The easiest way to install Greybox in Python is from PyPI:

pip install greybox

From GitHub (Development Version)

To install the latest development version from GitHub:

pip install greybox @ git+https://github.com/openforecast-org/greybox.git#subdirectory=python

Or clone and install in editable mode:

git clone https://github.com/openforecast-org/greybox.git
cd greybox/python
pip install -e .

Python Requirements

Minimum Requirements

Package Minimum Version
Python 3.9+
numpy 1.20.0
scipy 1.7.0
pandas 1.3.0
nlopt 2.7.0

Install optional dependencies:

pip install greybox[dev]

Verifying Installation

To verify that Greybox is installed correctly in Python:

# Check package version
import greybox
print(greybox.__version__)

# Import main functions
from greybox import ALM, stepwise, CALM
from greybox.formula import formula

# Check help
help(greybox)

Quick Start (Python)

from greybox.formula import formula
from greybox.alm import ALM

# Simple example
data = {
    'mpg': [21.0, 21.0, 22.8, 24.4, 19.2],
    'wt': [2.62, 2.32, 2.32, 2.46, 2.32],
    'disp': [160, 160, 108, 147, 141],
    'hp': [110, 110, 93, 62, 123]
}

# Parse formula
y, X = formula("mpg ~ wt + disp + hp", data)

# Fit model
model = ALM(distribution="dnorm")
model.fit(X, y)

# Get summary
print(model.summary())

# Make predictions
result = model.predict(X)

Troubleshooting

nlopt installation error

If you encounter issues installing nlopt, you may need to install the nlopt development libraries:

Ubuntu/Debian:

sudo apt-get install libnlopt-dev

macOS:

brew install nlopt

Windows: nlopt should install automatically via pip. If issues persist, try:

pip install --no-cache-dir nlopt

Import errors

If you encounter import errors, make sure all dependencies are installed:

pip install numpy scipy pandas nlopt

Related Pages

  • Home - Main documentation page
  • ALM - Advanced Linear Model documentation
  • stepwise - Stepwise regression
  • distributions - Supported distributions

Clone this wiki locally