1. Gunakan dataset airquality:

a. Hitung statistik deskriptif (mean, median, standar deviasi) untuk variabel Ozone:
summary(airquality$Ozone)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##    1.00   18.00   31.50   42.13   63.25  168.00      37
sd(airquality$Ozone, na.rm = TRUE)
## [1] 32.98788
b. Buat scatter plot antara variabel Wind dan Temp:
plot(airquality$Wind, airquality$Temp, 
     xlab = "Wind", ylab = "Temperature", 
     main = "Scatter Plot Wind vs Temperature")

2. Buat bar chart untuk variabel cyl dari dataset mtcars:

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
ggplot(mtcars, aes(x = factor(cyl))) + 
  geom_bar() + 
  labs(x = "Number of Cylinders", y = "Count", title = "Bar Chart of Cylinders")

3. Gunakan dataset iris:

a. Buat boxplot untuk membandingkan Petal.Width berdasarkan variabel Species:
boxplot(Petal.Width ~ Species, data = iris, 
        main = "Boxplot of Petal Width by Species", 
        xlab = "Species", ylab = "Petal Width")

b. Hitung korelasi antara Sepal.Length dan Petal.Length:
cor(iris$Sepal.Length, iris$Petal.Length)
## [1] 0.8717538

Interpretasi: Korelasi positif berarti semakin panjang sepal, semakin panjang pula petal.

c. Buat scatter plot antara Sepal.Length dan Sepal.Width dengan warna berbeda berdasarkan spesies:
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + 
  geom_point() + 
  geom_smooth(method = "lm") +
  scale_color_manual(values = c("setosa" = "purple", "versicolor" = "red", "virginica" = "blue")) +
  labs(title = "Scatter Plot of Sepal Dimensions by Species")
## `geom_smooth()` using formula = 'y ~ x'

4. Uji Chi-Square untuk menguji hubungan antara variabel vs dan am dalam dataset mtcars:
chisq.test(table(mtcars$vs, mtcars$am))
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  table(mtcars$vs, mtcars$am)
## X-squared = 0.34754, df = 1, p-value = 0.5555

5. Model regresi linear sederhana untuk memprediksi Temp berdasarkan Solar.R dari dataset airquality:

a. Tampilkan ringkasan model menggunakan summary():
model <- lm(Temp ~ Solar.R, data = airquality)
summary(model)
## 
## Call:
## lm(formula = Temp ~ Solar.R, data = airquality)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -22.3787  -4.9572   0.8932   5.9111  18.4013 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 72.863012   1.693951  43.014  < 2e-16 ***
## Solar.R      0.028255   0.008205   3.444 0.000752 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.898 on 144 degrees of freedom
##   (7 observations deleted due to missingness)
## Multiple R-squared:  0.07609,    Adjusted R-squared:  0.06967 
## F-statistic: 11.86 on 1 and 144 DF,  p-value: 0.0007518
b. Buat scatter plot dengan garis regresi:
plot(airquality$Solar.R, airquality$Temp, 
     xlab = "Solar Radiation", ylab = "Temperature", 
     main = "Scatter Plot of Temp vs Solar.R")
abline(model, col = "magenta")

c. Interpretasi hasil, termasuk koefisien regresi dan nilai R²:

Koefisien regresi menunjukkan seberapa besar perubahan Temp berdasarkan perubahan Solar.R. Nilai R² menunjukkan seberapa baik variabel Solar.R menjelaskan variabel Temp.