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 libraries
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
# Load data
movies <- read.csv("C:/Users/Prasad/Downloads/imdb.csv")
# Fit linear model
fit <- lm(revenue ~ budget_x + score, data = movies)
# Model diagnostics
par(mfrow = c(2, 2))
plot(fit)
summary(fit)
##
## Call:
## lm(formula = revenue ~ budget_x + score, data = movies)
##
## Residuals:
## Min 1Q Median 3Q Max
## -849646874 -148107537 -35799539 123828672 1942070819
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -5.133e+08 8.114e+07 -6.326 6.24e-10 ***
## budget_x 3.706e+00 1.907e-01 19.428 < 2e-16 ***
## score 8.114e+06 1.111e+06 7.306 1.32e-12 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 283300000 on 436 degrees of freedom
## Multiple R-squared: 0.4814, Adjusted R-squared: 0.479
## F-statistic: 202.3 on 2 and 436 DF, p-value: < 2.2e-16
# Check assumptions
ggplot(fit, aes(x = .fitted, y = .resid)) +
geom_point() +
geom_smooth()
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
# Create a ggplot object and specify the data
p <- ggplot(data = movies, aes(x = budget_x))
# Add a density plot
p + geom_density()
# Interpretation
summary(fit)$coefficients
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -5.132965e+08 8.114066e+07 -6.326008 6.244670e-10
## budget_x 3.705702e+00 1.907364e-01 19.428398 5.034949e-61
## score 8.114215e+06 1.110626e+06 7.305980 1.321389e-12