user3075021
user3075021

Reputation: 95

obtain the response vector used in a linear regression in r

A quick question.

lm.fit = lm (y ~ x1 + x2 + x3+ x4+x5, data=mydata)

I know how to obtain the design matrix. model.matrix(lm.fit)

Is there a simple build-in function to obtain the y vector used in the lm fitting?

due to missing data, mydata$y is not the answer.

Upvotes: 0

Views: 2306

Answers (2)

ajb
ajb

Reputation: 702

i believe

lm.fit$model$y

should be give the response variable used in your fitting. Your regression will only use observations where all variables are non-missing (y, x1. x2, x3, x4, x5 in your case), so that should take care of the missing value problem. you can also see the predictor variables used in your model using the same syntax

lm.fit$model$x1

Upvotes: 1

BrodieG
BrodieG

Reputation: 52637

There may be a direct accessor function, but in the meantime you can use:

lm.fit$model$y

Upvotes: 1

Related Questions