- a
# Load dataset
data("airquality")
# Hitung statistik deskriptif
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) # Standar deviasi
## [1] 32.98788
- b
# Scatter plot Wind vs Temp
plot(airquality$Wind, airquality$Temp,
main = "Scatter Plot Wind vs Temp",
xlab = "Wind",
ylab = "Temperature",
col = "blue",
pch = 19)

# Load dataset
data("mtcars")
# Buat bar chart
barplot(table(mtcars$cyl),
main = "Bar Chart of Cylinders",
xlab = "Number of Cylinders",
ylab = "Frequency",
col = "lightblue")

# Tambahkan label jumlah setiap kategori
text(x = barplot(table(mtcars$cyl)), y = table(mtcars$cyl),
label = table(mtcars$cyl), pos = 3, cex = 0.8, col = "darkblue")

- a
# Load dataset
data("iris")
# Buat boxplot
boxplot(Petal.Width ~ Species, data = iris,
main = "Boxplot of Petal.Width by Species",
xlab = "Species",
ylab = "Petal.Width",
col = "lightgreen")

- b
# Korelasi
correlation <- cor(iris$Sepal.Length, iris$Petal.Length)
print(paste("Korelasi antara Sepal.Length dan Petal.Length adalah", round(correlation, 2)))
## [1] "Korelasi antara Sepal.Length dan Petal.Length adalah 0.87"
- c
# Scatter plot dengan warna berdasarkan Species
library(ggplot2)
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(title = "Scatter Plot Sepal.Length vs Sepal.Width",
x = "Sepal Length",
y = "Sepal Width") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

# Buat tabel kontingensi
tabel <- table(mtcars$vs, mtcars$am)
# Uji Chi-Square
chi_result <- chisq.test(tabel)
# Output hasil
print(chi_result)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: tabel
## X-squared = 0.34754, df = 1, p-value = 0.5555
- a
# Buat model regresi
model <- lm(Temp ~ Solar.R, data = airquality)
# Ringkasan model
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
# Scatter plot dengan garis regresi
plot(airquality$Solar.R, airquality$Temp,
main = "Scatter Plot with Regression Line",
xlab = "Solar.R",
ylab = "Temp",
pch = 19,
col = "pink")
# Tambahkan garis regresi
abline(model, col = "darkgreen", lwd = 2)

- c Interpretasinya sebagai berikut
- Variabel Solar.R memiliki pengaruh positif signifikan terhadap Temp
dengan slope kecil (0.028).
- Kekuatan model rendah (𝑅*2 = 7.6%), sehingga prediksi Temp
berdasarkan Solar.R kurang baik.
- Meskipun demikian, model tetap signifikan secara statistik. Untuk
peningkatan akurasi, perlu mempertimbangkan variabel independen lain
yang lebih berpengaruh terhadap Temp.