** lm()** function in R Language is a linear model function, used for linear regression analysis.

Syntax:lm(formula)

Parameters:

formula:model description, such as x ~ y

**Example 1:**

`# R program to illustrate ` `# lm function ` ` ` `# Creating two vectors x and y ` `x <` `-` `c(rep(` `1` `:` `20` `)) ` `y <` `-` `x ` `*` `2` ` ` `# Calling lm() function to ` `# fit a linear model ` `f <` `-` `lm(x ~ y) ` ` ` `# Getting linear model ` `f ` |

*chevron_right*

*filter_none*

**Output:**

Call: lm(formula = x ~ y) Coefficients: (Intercept) y 1.589e-15 5.000e-01

**Example 2:**

`# R program to illustrate ` `# lm function ` ` ` `# Creating two vectors x and y ` `x <` `-` `c(` `2` `, ` `4` `, ` `6` `, ` `8` `) ` `y <` `-` `c(` `1` `, ` `3` `, ` `5` `, ` `7` `) ` ` ` `# Calling lm() function to ` `# fit a linear model ` `f <` `-` `lm(y ~ x) ` ` ` `# Getting linear model ` `f ` |

*chevron_right*

*filter_none*

**Output:**

Call: lm(formula = y ~ x) Coefficients: (Intercept) x -1 1

## Recommended Posts:

- Perform Probability Density Analysis on t-Distribution in R Programming - dt() Function
- Perform the Probability Cumulative Density Analysis on t-Distribution in R Programming - pt() Function
- Perform the Inverse Probability Cumulative Density Analysis on t-Distribution in R Programming - qt() Function
- Regression Analysis in R Programming
- R-squared Regression Analysis in R Programming
- Linear Discriminant Analysis in R Programming
- Perform Operations over Margins of an Array or Matrix in R Programming - apply() Function
- Poisson Regression in R Programming
- Logistic Regression in R Programming
- Polynomial Regression in R Programming
- Random Forest Approach for Regression in R Programming
- Lasso Regression in R Programming
- Regression and its Types in R Programming
- Regression using k-Nearest Neighbors in R Programming
- Decision Tree for Regression in R Programming
- Ridge Regression in R Programming
- Elastic Net Regression in R Programming
- Quantile Regression in R Programming
- Regression with Categorical Variables in R Programming
- Fitting Linear Models to the Data Set in R Programming - glm() Function

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.