简体   繁体   中英

Linear regression equation R

When we run a linear regression in R, under what variable does R save the actual regression equation, by this I mean does R actually save the equation in the form:

y=B0 +B1x1 + B2x2 + B3x3 etc

I am asking because i would like to call upon that equation later, or would i need to create a new variable and let it equal to the above equation and at the same time include my beta values such that (for example) in R

z=0.1 + 0.2x1 +0.3x2 +0.4x3 etc.

I understand one can use predict function but I am not sure if that is what i am looking for exactly

If you want to get the coefficients, you use summary() on your lm.

To see just the model terms and their estimates, SEs, etc...

my_lm <- lm(Sepal.Length~Sepal.Width+Petal.Width+Petal.Length,iris)
coeffients <- summary(my_lm)$coefficients
coeffients
               Estimate Std. Error   t value     Pr(>|t|)
(Intercept)   1.8559975 0.25077711  7.400984 9.853855e-12
Sepal.Width   0.6508372 0.06664739  9.765380 1.199846e-17
Petal.Width  -0.5564827 0.12754795 -4.362929 2.412876e-05
Petal.Length  0.7091320 0.05671929 12.502483 7.656980e-25

You can then use however you like. Lastly, formula() will return the what you called for in the lm()

formula(my_lm)
Sepal.Length ~ Sepal.Width + Petal.Width + Petal.Length

If you don't want to use predict(), can use this object instead.

my_coef<-(coeffients[,1])
my_coef
 (Intercept)  Sepal.Width  Petal.Width Petal.Length 
   1.8559975    0.6508372   -0.5564827    0.7091320 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM