#Statistik deskriptif untuk variabel Ozone
# Load dataset airquality
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
#Scatter plot antara variabel Wind dan Temp
# Buat scatter plot
plot(airquality$Wind, airquality$Temp,
xlab = "Wind", ylab = "Temp",
main = "Scatter Plot antara Wind dan Temp")
# Load dataset mtcars
data("mtcars")
# Buat bar chart
barplot(table(mtcars$cyl),
main = "Jumlah Kategori cyl",
xlab = "Kategori cyl",
ylab = "Jumlah",
col = "pink")
#Boxplot untuk Petal.Width berdasarkan Species
# Load dataset iris
data("iris")
# Buat boxplot
boxplot(Petal.Width ~ Species, data = iris,
main = "Boxplot Petal.Width berdasarkan Species",
xlab = "Species", ylab = "Petal.Width", col = "pink")
#Korelasi antara Sepal.Length dan Petal.Length
# Hitung korelasi
cor(iris$Sepal.Length, iris$Petal.Length)
## [1] 0.8717538
# Interpretasi hasil: Jika nilai korelasi mendekati 1 atau -1, berarti hubungan kuat.
#Scatter plot antara Sepal.Length dan Sepal.Width
# Scatter plot dengan warna berdasarkan Species
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.2
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
ggtitle("Scatter Plot Sepal.Length vs Sepal.Width") +
xlab("Sepal.Length") + ylab("Sepal.Width")
## `geom_smooth()` using formula = 'y ~ x'
# Buat tabel kontingensi
table_vs_am <- table(mtcars$vs, mtcars$am)
# Lakukan uji Chi-Square
chisq.test(table_vs_am)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: table_vs_am
## X-squared = 0.34754, df = 1, p-value = 0.5555
# Interpretasi hasil: Jika p-value < 0.05, maka ada hubungan signifikan.
#Tampilkan ringkasan modeL
# 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
#Scatter plot dengan garis regresi
# Scatter plot dengan garis regresi
plot(airquality$Solar.R, airquality$Temp,
main = "Scatter Plot dengan Garis Regresi",
xlab = "Solar.R", ylab = "Temp")
abline(model, col = "green")
#Interpretasi hasil
Persamaan Regresi Model regresi sederhana ini memiliki bentuk: Temp = 72.863 + 0.08255 × Solar.R Temp = 72.863 + 0.08255 × Solar.R Variabel Solar.R berpengaruh signifikan terhadap variabel Temp.
Multiple R-squared: 0.07609 hanya sekitar 7.6%. kemampuan model dalam memprediksi suhu berdasarkan Solar.R cukup lemah.
F-statistic: 11.86, dengan p-value 0.0007518.
kesimpulan umum 1. Solar.R memiliki pengaruh positif yang signifikan terhadap suhu (Temp) meskipun pengaruhnya lemah, terlihat dari nilai R-squared yang rendah.