A user faced trouble for extracting statistics such as R- squared and adjusted R-squared from iris dataset. How to fix that?

584    Asked by Dadhijaraj in Data Science , Asked on Nov 8, 2019
Answered by Dadhija raj

data(iris) model <- summary(lm(Sepal.Length~Sepal.Width,data=iris))

The error is given below

lapply(model, "[", c("r.squared", "adj.r.squared"))

Error in terms.formula(newformula, specials = names(attr(termobj, "specials"))) : invalid model formula in ExtractVars

The function lapply() is not required as we can easily expect the model can return a list of elements.

names(model1)

It contains 11 elements

"Call"

 "terms"

"residuals"

"coefficients"

"aliased"

"sigma"

"df"

"r.squared"

 "adj.r.squared"

"f-statistic"

"cov.unscaled"

The statistics summary such as r-squared and adjusted r-squared can be determined as follows

model[c('r.squared', 'adj.r.squared')]

We can also apply regular expression function to capture all values

model[grepl('squared', names(model))]



Your Answer

Interviews

Parent Categories