data(“airquality”)
summary(airquality\(Ozone) # Mean, median, min, max, dan kuartil sd(airquality\)Ozone, na.rm = TRUE) # Standar deviasi dengan mengabaikan NA
plot(airquality\(Wind, airquality\)Temp, main = “Scatter Plot: Wind vs Temp”, xlab = “Wind”, ylab = “Temperature”, pch = 19, col = “blue”) # Warna dan simbol titik
data(“mtcars”)
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
data(“iris”)
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
correlation <- cor(iris\(Sepal.Length, iris\)Petal.Length) print(paste(“Korelasi antara Sepal.Length dan Petal.Length:”, correlation))
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()
table_vs_am <- table(mtcars\(vs, mtcars\)am)
chisq_result <- chisq.test(table_vs_am) print(“Hasil Uji Chi-Square:”) print(chisq_result)
airquality_clean <- na.omit(airquality)
model <- lm(Temp ~ Solar.R, data = airquality_clean) summary_model <- summary(model)
print(“Ringkasan Model Regresi Linear:”) print(summary_model)
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
abline(model, col = “red”, lwd = 2) # Garis regresi berwarna merah
cat(“Hasil Model:”)
cat(“Koefisien Intercept (α):”, summary_model\(coefficients[1, 1], "\n") cat("Koefisien Solar.R (β):", summary_model\)coefficients[2, 1], “”)
cat(“Nilai R-squared (R^2):”, summary_model$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.”) }
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
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.