glm_()
is an experimental wrapper around the base stats::glm()
function. It behaves similarly to glm()
, but enriches the returned object
with additional metadata. The order of the arguments differs from glm()
,
and the function uses evaluation through svBase::prepare_data_dot and
svBase::recall_with_data_dot to support the data-dot mechanism.
glm_(data = (.), formula, ..., .data = data)
A data.frame
containing the variables in the model.
An object of class formula
: a symbolic description of the
model to be fitted.
Additional arguments passed to stats::glm()
.
an alias for the data
argument
An object of class glm_
, which inherits from glm
, and includes
additional components such as labels
. If no additional attributes are
added, a standard glm
object is returned.
data(iris)
# Add labels to variables
attr(iris$Sepal.Length, "label") <- "Sepal Length (cm)"
attr(iris$Petal.Length, "label") <- "Petal Length (cm)"
# Fit the model using lm_()
res <- glm_(iris, formula = Petal.Length ~ Sepal.Length + Species)
res
#>
#> Call: stats::glm(formula = formula, data = data)
#>
#> Coefficients:
#> (Intercept) Sepal.Length Speciesversicolor Speciesvirginica
#> -1.7023 0.6321 2.2101 3.0900
#>
#> Degrees of Freedom: 149 Total (i.e. Null); 146 Residual
#> Null Deviance: 464.3
#> Residual Deviance: 11.66 AIC: 52.47
class(res)
#> [1] "glm_" "glm" "lm"
summary(res)
#>
#> Call:
#> stats::glm(formula = formula, data = data)
#>
#> Coefficients:
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) -1.70234 0.23013 -7.397 1.01e-11 ***
#> Sepal.Length 0.63211 0.04527 13.962 < 2e-16 ***
#> Speciesversicolor 2.21014 0.07047 31.362 < 2e-16 ***
#> Speciesvirginica 3.09000 0.09123 33.870 < 2e-16 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for gaussian family taken to be 0.07984347)
#>
#> Null deviance: 464.325 on 149 degrees of freedom
#> Residual deviance: 11.657 on 146 degrees of freedom
#> AIC: 52.474
#>
#> Number of Fisher Scoring iterations: 2
#>
# Access labels
res$labels
#> Petal.Length Sepal.Length Species
#> "Petal Length (cm)" "Sepal Length (cm)" "Species"