Load dataset

data(“airquality”)

(a) Hitung statistik deskriptif untuk variabel Ozone

summary(airquality\(Ozone) # Mean, median, min, max, dan kuartil sd(airquality\)Ozone, na.rm = TRUE) # Standar deviasi dengan mengabaikan NA

(b) Scatter plot antara Wind dan Temp

plot(airquality\(Wind, airquality\)Temp, main = “Scatter Plot: Wind vs Temp”, xlab = “Wind”, ylab = “Temperature”, pch = 19, col = “blue”) # Warna dan simbol titik

Load dataset

data(“mtcars”)

Buat bar chart untuk variabel cyl

cyl_counts <- table(mtcars$cyl) # Hitung frekuensi tiap kategori cyl barplot(cyl_counts, main = “Bar Chart of cyl”, xlab = “Number of Cylinders”, ylab = “Frequency”, col = “lightblue”) # Warna lightblue untuk tampilan menarik

Load dataset

data(“iris”)

(a) Boxplot Petal.Width berdasarkan Species

boxplot(Petal.Width ~ Species, data = iris, main = “Boxplot of Petal.Width by Species”, xlab = “Species”, ylab = “Petal Width”, col = c(“red”, “green”, “blue”)) # Warna berbeda untuk setiap spesies

(b) Korelasi antara Sepal.Length dan Petal.Length

correlation <- cor(iris\(Sepal.Length, iris\)Petal.Length) print(paste(“Korelasi antara Sepal.Length dan Petal.Length:”, correlation))

(c) Scatter plot Sepal.Length dan Sepal.Width berdasarkan Species

library(ggplot2) # Library ggplot2 untuk visualisasi

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(size = 3) + # Titik scatter plot geom_smooth(method = “lm”, se = FALSE) + # Garis regresi ggtitle(“Scatter Plot: Sepal.Length vs Sepal.Width”) + xlab(“Sepal Length”) + ylab(“Sepal Width”) + theme_minimal()

Tabel kontingensi antara vs dan am

table_vs_am <- table(mtcars\(vs, mtcars\)am)

Uji Chi-Square

chisq_result <- chisq.test(table_vs_am) print(“Hasil Uji Chi-Square:”) print(chisq_result)

Hapus baris dengan nilai NA

airquality_clean <- na.omit(airquality)

(a) Bangun model regresi linear sederhana

model <- lm(Temp ~ Solar.R, data = airquality_clean) summary_model <- summary(model)

Ringkasan model

print(“Ringkasan Model Regresi Linear:”) print(summary_model)

(b) Scatter plot dengan garis regresi

plot(airquality_clean\(Solar.R, airquality_clean\)Temp, main = “Scatter Plot: Solar.R vs Temp dengan Garis Regresi”, xlab = “Solar Radiation”, ylab = “Temperature”, pch = 19, col = “blue”) # Plot titik data

Tambahkan garis regresi ke scatter plot

abline(model, col = “red”, lwd = 2) # Garis regresi berwarna merah

Interpretasi hasil regresi

cat(“Hasil Model:”)

Koefisien regresi

cat(“Koefisien Intercept (α):”, summary_model\(coefficients[1, 1], "\n") cat("Koefisien Solar.R (β):", summary_model\)coefficients[2, 1], “”)

Nilai R-squared (R^2)

cat(“Nilai R-squared (R^2):”, summary_model$r.squared, “”)

Evaluasi kualitas model berdasarkan R-squared

if (summary_model$r.squared > 0.7) { cat(“Model memiliki kemampuan prediksi yang baik karena R^2 > 0.7.”) } else { cat(“Model memiliki kemampuan prediksi yang lemah atau sedang karena R^2 < 0.7.”) }

R Markdown

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:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.