Proportion of deviance explained by a GLM
This function calculates the (adjusted) amount of deviance accounted for by a generalized linear model.
Dsquared(model = NULL, obs = NULL, pred = NULL, family = NULL, adjust = FALSE, npar = NULL)
model |
a model object of class "glm". |
obs |
a numeric vector of the observed data. This argument is ignored if |
pred |
a numeric vector of the values predicted by a GLM of the observed data. This argument is ignored if |
family |
a character vector (i.e. in quotes) of length 1 specifying the family of the GLM. This argument is ignored if |
adjust |
logical, whether or not to adjust the D-squared value for the number of observations and parameters in the model (see Details). The default is |
npar |
an integer vector indicating the number of parameters in the model. This argument is ignored if |
Linear models come with an R-squared value that measures the proportion of variation that the model accounts for. The R-squared is provided with summary(model)
in R. For generalized linear models (GLMs), the equivalent is the amount of deviance accounted for (D-squared; Guisan & Zimmermann 2000), but this value is not normally provided with the model summary. The Dsquared
function calculates it. There is also an option to calculate the adjusted D-squared, which takes into account the number of observations and the number of predictors, thus allowing direct comparison among different models (Weisberg 1980, Guisan & Zimmermann 2000).
This functin returns a numeric value indicating the (adjusted) proportion of deviance accounted for by the model.
A. Marcia Barbosa
Guisan, A. & Zimmermann, N.E. (2000) Predictive habitat distribution models in ecology. Ecological Modelling 135: 147-186
Weisberg, S. (1980) Applied Linear Regression. Wiley, New York
# load sample models: data(rotif.mods) # choose a particular model to play with: mod <- rotif.mods$models[[1]] Dsquared(model = mod) Dsquared(model = mod, adjust = TRUE) # you can also use Dsquared with vectors of observed and predicted values # instead of with a model object: presabs <- mod$y prediction <- mod$fitted.values parameters <- attributes(logLik(mod))$df Dsquared(obs = presabs, pred = prediction, family = "binomial") Dsquared(obs = presabs, pred = prediction, family = "binomial", adjust = TRUE, npar = parameters)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.