# 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)
## [1] 32.98788
# Buat Scatter Plot
plot(airquality$Wind, airquality$Temp,
main = "Scatter Plot antara Wind dan Temp",
xlab = "Wind", ylab = "Temp", pch = 19, col = "blue")

# Load Dataset
data("mtcars")
# Buat Bar Chart
cyl_count <- table(mtcars$cyl)
barplot(cyl_count, main = "Jumlah Mobil Berdasarkan Cyl",
xlab = "Cylinders", ylab = "Jumlah", col = "lightblue")

# Load Dataset
data("iris")
# Buat Boxplot
boxplot(Petal.Width ~ Species, data = iris,
main = "Boxplot Petal.Width Berdasarkan Species",
xlab = "Species", ylab = "Petal Width", col = c("red", "green", "blue"))

# Hitung Korelasi
correlation <- cor(iris$Sepal.Length, iris$Petal.Length)
correlation
## [1] 0.8717538
# Buat 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
chi_table <- table(mtcars$vs, mtcars$am)
# Uji Chi-Square
chi_result <- chisq.test(chi_table)
chi_result
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: chi_table
## X-squared = 0.34754, df = 1, p-value = 0.5555
# Model Regresi Linear
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
# Buat Scatter Plot dengan Garis Regresi
plot(airquality$Solar.R, airquality$Temp,
main = "Scatter Plot Temp vs Solar.R dengan Garis Regresi",
xlab = "Solar.R", ylab = "Temp", pch = 19, col = "orange")
abline(model, col = "blue", lwd = 2)

# Nilai R Squared
summary(model)$r.squared
## [1] 0.07608786