[R] How many samples ACTUALLY used in regression?
Ben Bolker
bbolker at gmail.com
Mon Mar 18 14:08:45 CET 2013
Federico Calboli <f.calboli <at> imperial.ac.uk> writes:
> is there a simple way that covers all regression models to extract
> the number of samples from a data
> frame/matrix actually used in a regression model?
>
> For instance I might have a data of 100 rows and 4 colums
> (1 response + 3 explanatory variables). If 3 samples
> have one or more NAs in the explanatory variable columns
> these samples will be dropped in any model:
my.model = lm(y ~ x + w + z, my.data)
my.model = glm(y ~ x + w + z, my.data, family = binomial)
my.model = polr(y ~ x + w + z, my.data)
> I don't seem to be able to find one single method that works
> in the exact same way -- irrespective of the model
> type -- to interrogate my.model to see how many samples of
> my.data were actually used. Is there such
> function or do I need to hack something together?
I haven't tested it (don't want to bother to put together the
test data), but does nrow(model.frame(my.model)) work ?
More information about the R-help
mailing list