- What is it?
- Simple Linear Regression is used to model the relationship between two continuous variables
- The objective is to predict the value of an output variable based on the value of an input variable
2024-02-25
We can use plotly to create a scatterplot to view the data:
## Warning: No trace type specified and no positional attributes specified
## No trace type specified: ## Based on info supplied, a 'scatter' trace seems appropriate. ## Read more about this trace type -> https://plotly.com/r/reference/#scatter
## No scatter mode specifed: ## Setting the mode to markers ## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
We can also use ggplot to create a scatterplot of the data:
We can now use ggplot to create a simple linear regression line:
## `geom_smooth()` using formula = 'y ~ x'
This is a sample of how to write the code to create a simple linear regression model with the scatterplot.
g <- ggplot(data = trees, aes(x = Girth, y = Volume)) + geom_point() s <- g + geom_smooth(method = "lm") s
## `geom_smooth()` using formula = 'y ~ x'