Visualization of Regression Model

 

To visualize the linear regression model in the R Language, we use the plot() function to plot the scatter plot of data points and then use the abline() pot to plot the regression line.

 

Syntax:

plot( datax, datay )

abline( linear_model)

Parameter:

  • datax and datay: determine the value for the x-axis and y-axis variables.
  • linear_model: determines the linear model for visualization.

 

Example: Here, is a visualization of a linear model with intercept.

 

R




# sample data frame
sample_data <- data.frame( x1= c(2,3,5,4,8),
                  x2= c(0,3,5,6,23),
                  y= c(1,6,9,15,29))
   
# fit linear model
linear_model <- lm(y ~ x1+x2, data=sample_data)
   
# visualize linear model
plot( sample_data$x1, sample_data$y, col= "blue", pch=16 )
points( sample_data$x2, sample_data$y, col="red", pch=16 )
abline(linear_model, col="green", lwd=2 )


 

 

Output:

 

Remove Intercept from Regression Model in R

In this article, we will discuss how to remove intercept from the Regression model in the R Programming Language.

Similar Reads

Extract intercept from the linear regression model

To extract intercept from the linear regression model in the R Language, we use the summary() function of the R Language. We first create the linear regression model using the lm() function. 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. Then we use the summary() function to retrieve the statistical summary of that model which also contains the information of intercept that the fitted model makes....

Visualization of Regression Model

...

Remove intercept from the linear regression model

...

Visualization of linear model without intercept

...

Contact Us