![]() ![]() Now, with the help of the lm( ) function, we are going to make a linear model. Step 5: Create a linear regression model. ![]() We can also verify our above analysis that there is a correlation between Blood Pressure and Age by taking the help of the cor( ) function in R, which is used to calculate the correlation between two variables. Step 4: Calculate the correlation between age and blood pressure. It is quite evident from the graph that the distribution on the plot is scattered in a manner that we can fit a straight line through the data points. We can also use the plot function In R for scatterplot and abline function to plot straight lines. Taking the help of the ggplot2 library in R, we can see that there is a correlation between Blood Pressure and Age, as we can see that the increase in Age is followed by an increase in blood pressure. Step 3: Create a scatter plot using the ggplot2 library. This data frame will help us predict blood pressure at Age 53 after creating a linear regression model. Step 2: Create the data frame for predicting values.Ĭreate a data frame that will store Age 53. Blood Pressure, a CSV file using function read.csv( ) in R, and store this dataset into a data frame bp. With the help of this data, we can train a simple linear regression model in R, which will be able to predict blood pressure at ages that are not present in our dataset.Įquation of the regression line in our dataset. Let’s say we have a dataset of the blood pressure and age of a certain group of people. Let’s try to understand the practical application of linear regression in R with another example. The best-fit line would be of the form:ī0 and B1 – Regression parameter Practical Application of Linear Regression Using R ![]() One limitation of linear regression is that it is sensitive to outliers. The linear regression algorithm is basically fitting a straight line to our dataset using the least squares method so that we can predict future events. The above idea of prediction sounds magical, but it’s pure statistics. ![]() Now, by analyzing the correlation between the marketing budget and the sales data, we can predict next year’s sales if the company allocates a certain amount of money to the marketing department. Note that we are not calculating the dependency of the dependent variable on the independent variable, but just the association.įor example, a firm is investing some amount of money in the marketing of a product, and it has also collected sales data throughout the years. The two variables involved are the dependent variable (response variable), which responds to the change of the independent variable (predictor variable). Simple linear regression analysis is a technique to find the association between two variables.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |