Description Usage Arguments Value Examples
Fit linear models.
1 2 3 4 5 6 7 |
formula |
an object of class "formula": a symbolic description of the model to be fitted. |
data |
an optional data frame |
intercept |
an indicator to indicate whether the model contains an intercept or not. If TRUE, then the model contains an intercept; if FALSE then the model does not contain an intercept. The default value is TRUE. |
interaction |
a two-column matrix including interaction terms of covariates. The default value is NULL, which means no interaction in the model. |
na.action |
a function which indicates what should happen when the data contain NAs. Options include 'na.omit' (default, to remove rows with NA), 'na.fail'(to stop regression), and 'na.impute' (replace with mean). |
a invisible list containing the following components: "call", "data", "y","x", "coefficients", "fitted.values","summary", "residuals", "rsquare", "adjusted_rsquare","rank", "df.residual","fstat", "fpvalue","SSE", "MSE", "leverage" and "cov.matrix".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | lm1(mpg ~ disp + wt, data = mtcars)
## Set na.action to `na.impute` to replace na with column mean
# Add na values
mtcars.na <- mtcars[,c(1,3,6)]
mtcars.na[1,2] <- NA
# Conduct linear regression
lm1(mpg ~ disp + wt, data = mtcars.na, na.action = "na.impute")
## Linear regression without intercept
lm1(mpg ~ disp + wt, data = mtcars, intercept = FALSE)
## Linear regression with interactions
lm1(mpg ~ disp + wt, data = mtcars, interaction = matrix(c("disp", "wt"),1,2))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.