The formula is just like this. I don't quite understand the usage of the notion "/". It seems that "/" usually be used in dummy variables. But I am not sure about its usage.
lm(y~x/z,data = data.frame(x = rnorm(6), y = rnorm(6), z = rep(0:1,each=3)))
The lm() function is used to fit linear models to data frames in the R Language. It can be used to carry out regression, single stratum analysis of variance, and analysis of covariance to predict the value corresponding to data that is not in the data frame.
In the context of simple linear regression: R: The correlation between the predictor variable, x, and the response variable, y. R2: The proportion of the variance in the response variable that can be explained by the predictor variable in the regression model.
The intercept (sometimes called the “constant”) in a regression model represents the mean value of the response variable when all of the predictor variables in the model are equal to zero. This tutorial explains how to interpret the intercept value in both simple linear regression and multiple linear regression models.
Description. lm is used to fit linear models. It can be used to carry out regression, single stratum analysis of variance and analysis of covariance (although aov may provide a more convenient interface for these).
lm(y ~ x/z, data)
is just a shortcut for lm(y ~ x + x:z, data)
These two give the same results:
lm(mpg ~ disp/hp,data = mtcars)
Call:
lm(formula = mpg ~ disp/hp, data = df)
Coefficients:
(Intercept) disp disp:hp
2.932e+01 -3.751e-02 -1.433e-05
lm(mpg ~ disp + disp:hp, data = mtcars)
Call:
lm(formula = mpg ~ disp + disp:hp, data = mtcars)
Coefficients:
(Intercept) disp disp:hp
2.932e+01 -3.751e-02 -1.433e-05
So, what your doing is modelling mpg
based on disp
alone and on an interaction between disp
and hp
.
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