modelSize: Number of response data in a model object

View source: R/modelSize.r

modelSizeR Documentation

Number of response data in a model object

Description

This function returns the number of response data used in a model (i.e., the sample size). If the data are binary it can return the number of 1s and 0s.

Usage

modelSize(x, binary = TRUE, graceful = TRUE)

Arguments

x

A model object. This can be of many classes, including "gbm", "glm", "gam", "MaxEnt", and so on.

binary

Logical, if TRUE (default) then the number of 1s and 0s in the response data is returned. If FALSE then the returned values is the total number of response data.

graceful

Logical, if TRUE (default) then if the function cannot determine the sample size from the model object NA if returned. If FALSE, then the function exits with an error.

Value

One or two integers named integers.

Examples

set.seed(123)
y <- runif(1:101)^2
yBinary <- as.integer(y > 0.6)
x <- data.frame(x1=1:101, x2=rnorm(101))
model <- lm(y ~ x1 + x2, data=x)
modelBinary <- glm(yBinary ~ x1 + x2, data=x, family='binomial')
modelSize(model, FALSE)
modelSize(model, TRUE) # not binary input... notice warning
modelSize(modelBinary)
modelSize(modelBinary, FALSE)

adamlilith/enmSdm documentation built on Jan. 6, 2023, 11 a.m.