This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
# Load the necessary library
library(ggplot2)
# Multiple linear regression model: Predicting Petal Length based on Petal Width and Sepal Length
model <- lm(Petal.Length ~ Petal.Width + Sepal.Length, data = iris)
# Summary of the model to check coefficients, R-squared, and other statistics
summary(model)
##
## Call:
## lm(formula = Petal.Length ~ Petal.Width + Sepal.Length, data = iris)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.15506 -0.21920 -0.02115 0.25986 1.35204
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.50714 0.33696 -4.473 1.54e-05 ***
## Petal.Width 1.74810 0.07533 23.205 < 2e-16 ***
## Sepal.Length 0.54226 0.06934 7.820 9.41e-13 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4032 on 147 degrees of freedom
## Multiple R-squared: 0.9485, Adjusted R-squared: 0.9478
## F-statistic: 1354 on 2 and 147 DF, p-value: < 2.2e-16
# Load necessary libraries
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(ggplot2)
# Multiple linear regression model: Predicting Petal Length based on Petal Width and Sepal Length
model <- lm(Petal.Length ~ Petal.Width + Sepal.Length, data = iris)
# Create a grid of values for Petal Width and Sepal Length
petal.width.range <- seq(min(iris$Petal.Width), max(iris$Petal.Width), length.out = 100)
sepal.length.range <- seq(min(iris$Sepal.Length), max(iris$Sepal.Length), length.out = 100)
grid <- expand.grid(Petal.Width = petal.width.range, Sepal.Length = sepal.length.range)
# Predict Petal Length for the grid
grid$Petal.Length <- predict(model, newdata = grid)
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.