Question 1

ghbhjblhjlbhlbhlbhlbhlb

data('mtcars')

cor.test(mtcars$mpg , mtcars$wt)
## 
##  Pearson's product-moment correlation
## 
## data:  mtcars$mpg and mtcars$wt
## t = -9.559, df = 30, p-value = 1.294e-10
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.9338264 -0.7440872
## sample estimates:
##        cor 
## -0.8676594
# The more a car weighs, the less MPG it gets

# Load necessary library
library(plotly)
## Loading required package: ggplot2
## 
## 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
# Load the mtcars dataset
data(mtcars)

# Perform linear regression
model <- lm(mpg ~ wt, data = mtcars)

# Create a data frame with fitted values for the trend line
trendline_data <- data.frame(wt = mtcars$wt, mpg_fitted = predict(model))

# Create an interactive scatter plot with trend line
 plot_ly(data = mtcars, x = ~wt, y = ~mpg, type = 'scatter', mode = 'markers',
               marker = list(size = 10, color = 'blue', opacity = 0.7),
               name = 'Data Points') %>%
  add_trace(data = trendline_data, x = ~wt, y = ~mpg_fitted, type = 'scatter', mode = 'lines',
            line = list(color = 'red'), name = 'Trend Line') %>%
  layout(title = "MPG vs Weight (wt) in mtcars with Trend Line",
         xaxis = list(title = "Weight (wt)"),
         yaxis = list(title = "Miles Per Gallon (mpg)"))
## A marker object has been specified, but markers is not in the mode
## Adding markers to the mode...