
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create Predictive Linear Regression Line in Base R
If we want to create a regression line inside scatterplot then lines function can be used with the linear model function lm but if we want to do it for a particular range of independent variable then this range needs to be defined and passed within the lines function. Check out the below example of linear regression model that considers a range of independent variable for prediction.
Consider the below vectors −
Example
strsplit(x6,"[*]")
Output
Defining the range of x −
Range_of_x <-data.frame(x=1:3)
Adding the regression line for the prediction of range of x values −
Example
lines(Range_of_x$x,predict(lm(y~x),Range_of_x))
Advertisements