regr: Fitting Regression Models

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/regr.R

Description

'regr' fits regression models of various types: ordinary, robust, quantile, Tobit, logistic, generalized linear, multinomial, ordered response, multivariate, ...

It is a wrapper function which calls the respective S fitting functions and yields an extensive result, to be used by the respective print and plot methods.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
regr(formula, data = NULL, tit = NULL, family = NULL, dist = NULL,
  calcdisp = NULL, suffmean = 3, nonlinear = FALSE, start = NULL,
  robust = FALSE, method = NULL, 
  subset = NULL, weights = NULL, na.action = nainf.exclude,
  contrasts=getUserOption("regr.contrasts"),
  model = FALSE, x = TRUE, termtable = TRUE, vif = TRUE,
  factorNA = TRUE, testlevel = 0.05, hatlim=c(0.99,0.5), ...)

## S3 method for class 'regr'
summary(object, ...)

Arguments

formula

a symbolic description of the model to be fit.

data

data frame containing the variables in the model.

tit

title (becomes tit attribute of result)

family

character string describing the type of model and the fitting procedure. By default, regr will fit a model that is suitable for the response variable, if possible.
Can be either "gaussian" for ordinary regression, including multivariate response, "binomial" for logistic regression, "poisson" for Poisson regression, "multinomial" for multinomial regression, "polr" for ordered response (cumulative logits) regression, "weibull", "lognormal", "loglogistic", "extreme" for survival regression with the respective distribution, "ph" for Cox regression, or a suitable argument for glm, i.e.: A description of the error distribution and link function to be used in the model. This can be a character string naming a family function, a family function or the result of a call to a family function. (See 'family' for details of family functions.)

dist

only used for survival regression if family is NULL (the default), introduced for compatibility with the call to survreg

calcdisp

a logical value indicating whether, for family=binomial and family=poisson, dispersion should be calculated (TRUE) or set to 1 (FALSE)

suffmean

!!!

nonlinear

if TRUE, a non-linear model is expected, to be fitted by nlm

start

if nonlin is TRUE, starting values for nlm

robust

if TRUE, robust fitting is used if a function is available, see Details.

method

"rq" or "quantreg" requires fitting by quantile regression. Then, the argument tau is used for setting the quantile: regr(..., method="quantreg", tau=0.9). Otherwise, if suitable, a method argument that is passed to the fitting procedure, see also Details.

subset

an optional vector specifying a subset of observations to be used in the fitting process. Names of variables in data can be used to generate the vector.

weights

an optional vector of weights to be used for fitting.

na.action

a function which indicates what should happen when the data contain 'NA's. The default is 'nainf.exclude'.

contrasts

contrasts used for factors. Either a named list that determines contrasts for each factor or a character vector of two elements giving the names of the functions to be used for unordered and ordered factors, respectively. See contrast.arg in model.matrix.default or contrasts in options.

model, x

logical values indicating whether the model frame or the model matrix, respectively, should be included as a component of the returned value.

termtable

if FALSE, the regr type term table will not be generated

vif

a logical value indicating whether the collinearity measure R2.j ahould be calculated

factorNA

a logical value indicating whether missing values in factors should be re-coded by a respective level

testlevel

level for significance testing and confidence intervals

hatlim

bound for leverages to be used in standardizing residuals and calculation of standardized residuals from smooth

...

other argument to be passed to the fitting function

object

'summary.regr' simply returns its only argument object.

Details

Robust fitting is available for ordinary linear models, by setting robust = TRUE. By default, the function lmrob from package robustbase is called with the argument setting="KS2011". This default will be changed in future versions. Alternative methods can be obtained by setting the method argument. Choosing method="rlm" calls function rlm from package MASS with default method="MM". Any further elements of method will be passed on to the methods argument of the called function.

The 'summary' generic function does nothing to 'regr' objects, since all useful information is already collected in the object.

Value

regr returns a list object of class regr and secondary class as produced by the fitting function. The components include generally those of the results of the fitting function and its summary. The important additional components are:

termtable

data.frame, table for testing terms both for single and mulitple degree terms (continuous or binary explanatory variables and factors). The columns are The print method for the whole regr object will by default not show all of them.

allcoef

All coefficients. This is a list with a component for each term. Each component characterizes the coefficients similar to the termtable just explained, but without the columns df, stcoef, R2.x. Note that the interpretation of the coefficients of dummy variables depends on the contrasts used for the factor. Tests need to be interpreted correspondingly, and with caution.

stres

Standardized residuals

sigma

estimated standard deviation for normal errors,
sqrt(dispersion) for glm

h

leverage values

allvars

the variables used for fitting the model

binfac

levels of binary factors

fitfun, funcall

R function and call that has been used for fitting the model

Author(s)

Werner A. Stahel, Seminar for Statistics, ETH Zurich

See Also

lm, glm, rlm, multinom, polr,...

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
data(d.blast)
( r.blast <-
  regr(log10(tremor)~location+log10(distance)+log10(charge), data=d.blast) )

## Anorexia
data(anorexia, package="MASS")
r.anorexia <- regr(Postwt ~ Prewt + Treat + offset(Prewt),
                   data = anorexia)

## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
     ## Page 9: Plant Weight Data.
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
d.dob <- data.frame(group = gl(2,10,20, labels=c("Ctl","Trt")),
                    weight = c(ctl, trt))
(r.dob <- regr(weight ~ group, data=d.dob))

## multinomial regression
data(d.surveyenvir)
d.surveyenvir$dist.unordered <- factor(as.character(d.surveyenvir$disturbance))
t.r <- regr(dist.unordered~age+education+location, data=d.surveyenvir)

## ordered regression
## This example fails in the installation phase...
require(MASS) ## should not be needed
data(housing, package="MASS")
t.r <- regr(Sat ~ Infl + Type + Cont, weights = Freq, data = housing)
plot(t.r)

## multivariate regression
data(d.fossiles)
r.mregr <-
  regr(cbind(sAngle,lLength,rWidth)~SST.Mean+Salinity+lChlorophyll+region+N,
                data=d.fossiles)

regr0 documentation built on May 31, 2017, 2:26 a.m.