Reputation: 2035
Say I have a linear model in R. Using the model object, how can I see the number of observations used to train that model ?
For example
library(ISLR)
lm.fit <- lm(mpg ~ acceleration + weight + horsepower + displacement, data = Auto)
lm.fit
How to see the number of observations used to train the model lm.fit
?
In this example I obviously have access to the Auto
data frame and could look at its rows with nrow(Auto)
. However, once you use the differing training and test sets, it becomes less obvious. I would like to make sure that the expected number of observations were used to train a model with just using the model object.
Upvotes: 1
Views: 1180
Reputation: 73342
Just check the number of the fitted values.
length(lm.fit$fitted.values)
# [1] 392
Check:
dim(Auto)
# [1] 392 9
Upvotes: 1