Nama : Ibnu Raihan NIM : 2304220044 Matkul : Komputasi Statistika
data = airquality
data = airquality
mean_Ozone <- mean(airquality$Ozone, na.rm = TRUE)
median_Ozone <- median(airquality$Ozone, na.rm = TRUE)
sd_Ozone <- sd(airquality$Ozone, na.rm = TRUE)
cat("Mean Ozone:", mean_Ozone, "\n")
## Mean Ozone: 42.12931
cat("Median Ozone:", median_Ozone, "\n")
## Median Ozone: 31.5
cat("Standar Deviasi Ozone:", sd_Ozone, "\n")
## Standar Deviasi Ozone: 32.98788
plot(airquality$Wind, airquality$Temp,
main = "Scatter Plot antara Wind dan Temp",
xlab = "Wind",
ylab = "Temp",
col = "blue", pch = 16)
grid()
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
ggplot(mtcars, aes(x = factor(cyl))) +
geom_bar(fill = "lightblue", color = "black") +
geom_text(stat = "count", aes(label = ..count..), vjust = -0.5) +
labs(title = "Bar Chart untuk Jumlah Silinder (cyl)",
x = "Jumlah Silinder",
y = "Frekuensi")
## Warning: The dot-dot notation (`..count..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(count)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
data(iris)
boxplot(Petal.Width ~ Species, data = iris,
main = "Boxplot Petal.Width Berdasarkan Species",
xlab = "Species", ylab = "Petal Width",
col = c("skyblue", "lightgreen", "pink"))
korelasi <- cor(iris$Sepal.Length, iris$Petal.Length)
cat("Korelasi antara Sepal.Length dan Petal.Length:", korelasi , "\n")
## Korelasi antara Sepal.Length dan Petal.Length: 0.8717538
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 Sepal.Length vs Sepal.Width Berdasarkan Species",
x = "Sepal Length", y = "Sepal Width")
## `geom_smooth()` using formula = 'y ~ x'
tabel <- table(mtcars$vs, mtcars$am)
chi_result <- chisq.test(tabel)
print(chi_result)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: tabel
## X-squared = 0.34754, df = 1, p-value = 0.5555
model <- lm(Temp ~ Solar.R, data = airquality)
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
plotregresi <- ggplot(airquality, aes(x = Solar.R, y = Temp)) +
geom_point() +
geom_smooth(method = "lm")
print(plotregresi)
## `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()`).