Menginput data airquality
data("airquality")
Menghitung mean, median, dan standar deviasi untuk variabel Ozone
mean(airquality$Ozone, na.rm = TRUE)
## [1] 42.12931
median(airquality$Ozone, na.rm = TRUE)
## [1] 31.5
sd(airquality$Ozone, na.rm = TRUE)
## [1] 32.98788
Membuat scatter plot antara variabel wind dan temp
plot(airquality$Wind, airquality$Temp,
     main = "Scatter plot",
     xlab = "Wind",
     ylab = "Temp",
     pch = 19,
     col = "black")

Menginput data mtcars
data("mtcars")
Membuat bar chart untuk variabel cyl
library(ggplot2)
cyl_count <- as.data.frame(table(mtcars$cyl))
colnames(cyl_count) <- c("cyl", "count")
ggplot(cyl_count, aes(x = factor(cyl), y = count)) +
  geom_bar(stat = "identity", fill = "black") +  geom_text(aes(label = count), vjust = -0.5, size = 5) + labs(title = "Jumlah Mobil Berdasarkan Jumlah Silinder",
       x = "Jumlah Silinder (cyl)",
       y = "Jumlah Mobil") +
  theme_minimal()

Menginput data iris
data("iris")
Membuat boxplot untuk variabel petal.width berdasarkan variabel species
boxplot(Petal.Width ~ Species, data = iris,
        main = "Boxplot petal.width berdasarkan species",
        xlab = "petal.width",
        ylab = "species",
        col = "white")

Menghitung korelasi antara variabel sepal.length dan petal.length
korelasi <- cor(iris$Sepal.Length, iris$Petal.Length)
Menginterprestasi hasil uji korelasi

Setelah di uji menggunakan korelasi, 0.8717 ini menunjukkan bahwa terdapat hubungan positif antara sepal.length dan petal.length

Membuat scatter plot antara variabel sepal.length dan sepla.width berdasarkan spesies
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
  geom_point(size = 3) + geom_smooth(method = "lm", se = FALSE) +  labs(title = "Scatter Plot",
       x = "Sepal Length",
       y = "Sepal Width") +
  theme_minimal() +  # Tema minimalis
  scale_color_manual(values = c("setosa" = "red", 
                                "versicolor" = "yellow", 
                                "virginica" = "green"))
## `geom_smooth()` using formula = 'y ~ x'

Melakukan uji Chi-Square
chisq.test(mtcars$vs,mtcars$am)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  mtcars$vs and mtcars$am
## X-squared = 0.34754, df = 1, p-value = 0.5555
Membangun model regresi linear sederhana
lm(Temp ~ Solar.R, data = airquality)
## 
## Call:
## lm(formula = Temp ~ Solar.R, data = airquality)
## 
## Coefficients:
## (Intercept)      Solar.R  
##    72.86301      0.02825
Menampilkan ringkasan model
summary(lm(Temp ~ Solar.R, data = airquality))
## 
## 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
Membuat Scatter plot dengan garis regresi
ggplot(airquality, aes(x = Solar.R, y = Temp)) +
  geom_point(color = "black", size = 2) + geom_smooth(method = "lm", col = "black") + labs(title = "Scatter Plot",
       x = "Solar Radiation (Solar.R)",
       y = "Temperature (Temp)") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 7 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 7 rows containing missing values or values outside the scale range
## (`geom_point()`).