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
plot(airquality$Wind, airquality$Temp,
xlab = "Wind", ylab = "Temperature",
main = "Scatter Plot Wind vs Temperature")
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
ggplot(mtcars, aes(x = factor(cyl))) +
geom_bar() +
labs(x = "Number of Cylinders", y = "Count", title = "Bar Chart of Cylinders")
boxplot(Petal.Width ~ Species, data = iris,
main = "Boxplot of Petal Width by Species",
xlab = "Species", ylab = "Petal Width")
cor(iris$Sepal.Length, iris$Petal.Length)
## [1] 0.8717538
Interpretasi: Korelasi positif berarti semakin panjang sepal, semakin panjang pula petal.
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point() +
geom_smooth(method = "lm") +
scale_color_manual(values = c("setosa" = "purple", "versicolor" = "red", "virginica" = "blue")) +
labs(title = "Scatter Plot of Sepal Dimensions by Species")
## `geom_smooth()` using formula = 'y ~ x'
chisq.test(table(mtcars$vs, mtcars$am))
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: table(mtcars$vs, mtcars$am)
## 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
plot(airquality$Solar.R, airquality$Temp,
xlab = "Solar Radiation", ylab = "Temperature",
main = "Scatter Plot of Temp vs Solar.R")
abline(model, col = "magenta")
Koefisien regresi menunjukkan seberapa besar perubahan Temp berdasarkan perubahan Solar.R. Nilai R² menunjukkan seberapa baik variabel Solar.R menjelaskan variabel Temp.