Learn R Programming

spatialEco (version 0.1-0)

logistic.regression: Logistic and Auto-logistic regression

Description

Performs a logistic (binomial) and auto-logistic (spatially lagged binomial) regression

Usage

logistic.regression(ldata, y, x, penalty = TRUE, autologistic = FALSE,
  coords = NULL, bw = NULL, type = "inverse", style = "W",
  longlat = FALSE, ...)

Arguments

ldata
data.frame object contaning variables
y
Dependent variable (y) in ldata
x
Independent variable(s) (x) in ldata
penalty
Apply regression penelty (TRUE/FALSE)
autologistic
Add auto-logistic term (TRUE/FALSE)
coords
Geographic coordinates for auto-logistc model
bw
Distance bandwidth to calculate spatial lags (if empty neighbors result, need to increase bandwith)
type
Neighbor weighting scheme (see autocov_dist)
style
Type of neighbor matrix (Wij), default is mean of neighbors
longlat
Are coordinates (coords) in geographic, lat/long (TRUE/FALSE)
...
Additional arguments passed to lrm

Value

  • A list class object with the following components: model lrm model object (rms class) diagTable data.frame of regression diagnostics coefTable data.frame of regression coefficents Residuals data.frame of residuals and standardized residuals AutoCov If an auto-logistic model, AutoCov represents lagged auto-covariance term

References

Le Cessie S, Van Houwelingen JC (1992) Ridge estimators in logistic regression. Applied Statistics 41:191-201 Shao J (1993) Linear model selection by cross-validation. JASA 88:486-494

Examples

Run this code
require(sp)
require(spdep)
require(rms)
data(meuse)
  coordinates(meuse) <- ~x+y
    meuse@data <- data.frame(DepVar=rbinom(dim(meuse)[1], 1, 0.5), meuse@data)

#### Logistic model
lmodel <- logistic.regression(meuse@data, y='DepVar', x=c('dist','cadmium','copper'))
  lmodel$model
    lmodel$diagTable
      lmodel$coefTable

### Auto-logistic model using 'autocov_dist' in 'spdep' package
lmodel <- logistic.regression(meuse@data, y='DepVar', x=c('dist','cadmium','copper'),
                              autologistic=TRUE, coords=coordinates(meuse), bw=5000)
  lmodel$model
    lmodel$diagTable
      lmodel$coefTable
  est <- predict(lmodel$model, type='fitted.ind')

#### Add residuals, standardized residuals and estimated probabilities
VarNames <- rownames(lmodel$model$var)[-1]
  meuse@data$AutoCov <- lmodel$AutoCov
    meuse@data <- data.frame(meuse@data, Residual=lmodel$Residuals[,1],
                             StdResid=lmodel$Residuals[,2], Probs=predict(lmodel$model,
                             meuse@data[,VarNames],type='fitted') )

#### Plot fit and probabilities
resid(lmodel$model, "partial", pl="loess")
resid(lmodel$model, "partial", pl=TRUE)                 # plot residuals
resid(lmodel$model, "gof")                              # global test of goodness of fit
lp1 <- resid(lmodel$model, "lp1")                       # Approx. leave-out linear predictors
-2 * sum(meuse@data$DepVar * lp1 + log(1-plogis(lp1))) # Approx leave-out-1 deviance
spplot(meuse, c('Probs'))                               # plot estimated probs at points

Run the code above in your browser using DataLab