ConsReg {ConsReg}R Documentation

Fit a regression model with gaussian or binomial objective function

Description

ConsReg is a function that allows to estimate a regression model: linear regression (gaussian), logistic regression (binomial) or poisson regression. It allows the introduction of restrictions (both lower and upper limits) and restrictions between the coefficients (in the form, for example, of a>b).

Usage

ConsReg(...)

## Default S3 method:
ConsReg(x, y, family, optimizer, ini.pars.coef = NULL,
  constraints = NULL, LOWER = NULL, UPPER = NULL, penalty = 1000,
  ...)

## S3 method for class 'formula'
ConsReg(formula, data = list(), optimizer = "solnp",
  family = c("gaussian", "binomial"), constraints = NULL,
  LOWER = NULL, UPPER = NULL, penalty = 1000,
  na.action = "na.omit", ini.pars.coef = NULL, ...)

Arguments

...

additional parameters passed in the optimizer (number of iterations, ...)

x

matrix of predictive variables

y

vector of outcome variable

family

a description of the error distribution and link function to be used in the model. Possible values are: "gaussian" (linear regression) or "binomial" (logistic regression) and "poisson"

optimizer

Optimizer package used for fit the model (include bayesian and genetic algorithm optimization). Possible values are: "solnp" (default) (Rsolnp), "gosonlp" (Rsolnp), "optim" (stats::optim), "nloptr" (nloptr), DEoptim ("DEoptim"), "dfoptim" (dfoptim), "mcmc" (FME::modMCMC), "MCMCmetrop" (MCMCpack::MCMCmetrop1R),'adaptMCMC'(adaptMCMC::MCMC), "GA" (GA package), "GenSA" (GenSA package)

ini.pars.coef

vector of initial parameters. In case there is some constraint, then the ini.pars.coef should fulfill the constraints

constraints

vector of constraints (see details)

LOWER

(default NULL) vector of lower bounds for the coefficients. If the lenght of LOWER is not equal with the length of the coeefficients, then, the rest will be equal to -Inf

UPPER

(default NULL) vector of lower bounds for the coefficients. If the lenght of UPPER is not equal with the length of the coeefficients, then, the rest will be equal to +Inf

penalty

(default 1000) penalty to the objective function if some constraints do not fullfill

formula

an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted

data

an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which lm is called.

na.action

na.action to the data

Details

Several optimizers of various R packages are implemented, including methods typically used in Bayesian regressions like Markov Chain Monte Carlo simulation.

Constraints will be a string: For example, if x1 and x2 are two coefficient names, then a constraint could be: "x1 > x2" or "x1+x2 > 2". For some constraints, one can write: "x1+x2>2, x1 > 1". Each constraint will be separate by commas.

Important: if there are some constraints that do not fulfill in a model without those constraints, it is recommended to use ini.pars.coef parameter to set initial values that fulfill constraints. See the example

Value

An object of class "ConsReg".

coefficients

Coefficients of the regression

hessian

hessian matrix if the optimizer can return it

family

Model family function

optimizer

optimizer object return (see details of each optimization package)

optimizer.name

name of the optimizer

df

nrow(data) - number of coefficients

rank

number of coefficients

residuals

residuals of the model

fitted

fitted values of the model

metrics

Accuracy metrics of the model

call

the matched call

y

objective variable

x

regressors

formula

formula term

family.name

Name of the family used

Author(s)

Josep Puig Sall├ęs

Examples

data('fake_data')
fit1 = ConsReg(formula = y~x1+x2+x3+ I(x3^2) + x4, family = 'gaussian',
                     optimizer = 'mcmc',
                     data = fake_data)
summary(fit1)

# We impose constraints to x3 and x3^2 and x4
fit2 = ConsReg(formula = y~x1+x2+x3+ I(x3^2) + x4, data = fake_data,
            family = 'gaussian',
            constraints = '(x3 + `I(x3^2)`) > .01, x4 < .2',
            optimizer = 'mcmc',
            ini.pars.coef = c(-1.65, .12, -.004, 0.1, 0.1, .15))

fit1$coefficients
fit2$coefficients


[Package ConsReg version 0.1.0 Index]