I want to fit a linear model in R using lm
to obtain coefficient estimates and p-values + p-value for total model fit (ANOVA-like), so basically the output from summary.lm
.
The problem is that I want to use my own model matrix, instead of specifying it using a formula when calling lm
.
I've tried using the underlying lm.fit
function which allows for this, but then I loose the convenience of the summary.lm
function, and I don't want to recalculate all the test statistics again myself.
Is there a way to 'trick' lm
and give it a model matrix rather than a formula?
Thanks!
Here is an example using the built in BOD data frame:
# inputs
demand <- BOD$demand
mm <- model.matrix(~ Time, BOD) # model matrix
summary(lm(demand ~ mm + 0))
or
summary(lm(demand ~. + 0, as.data.frame(mm)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With