RPubs will retire in June 2027. Your existing documents will stay accessible through December 31, 2031
and Connect Cloud is the recommended home for new publishing. Read the blog post

Recently Published

Assignment 6
Transformasi Data
Transformasi Data
METD_3
AOA 3D plot
Publish Document
Assignment 2
Assignment 02 Choose any dataset of your choice. You may use mtcars, or any data you can import through read.csv. 1. Create an appropriate visualization by choosing 1 to 2 variables from your dataset. 2. Showcase the data distribution. You may use colors or shapes. Change the x and y axis units to show data clearly. Show titles, subtitles, x and y axis labels and captions to describe your visualization.
Machine Learning Algorithm (Linear Regression)
## Machine Learning Algorithm (Linear Regression) ## COde # Install required packages if not already installed install.packages("tidyverse") # Load the library library(tidyverse) # Load the dataset data(mtcars) # View the first few rows head(mtcars) # Fit a linear regression model model <- lm(mpg ~ wt, data = mtcars) # Summary of the model summary(model) # Visualize the regression line ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point(color = "blue") + geom_smooth(method = "lm", color = "red") + labs(title = "Linear Regression: MPG vs Weight", x = "Weight of Car", y = "Miles Per Gallon") summary(cars$speed) summary(pressure) plot(pressure) ### Ouptput > # Load the library > library(tidyverse) ── Attaching core tidyverse packages ───────────────────────────────── tidyverse 2.0.0 ── ✔ dplyr 1.1.4 ✔ readr 2.1.5 ✔ forcats 1.0.0 ✔ stringr 1.5.1 ✔ ggplot2 3.5.1 ✔ tibble 3.2.1 ✔ lubridate 1.9.4 ✔ tidyr 1.3.1 ✔ purrr 1.0.4 ── Conflicts ─────────────────────────────────────────────────── tidyverse_conflicts() ── ✖ dplyr::filter() masks stats::filter() ✖ dplyr::lag() masks stats::lag() ℹ Use the conflicted package to force all conflicts to become errors Warning messages: 1: package ‘tidyverse’ was built under R version 4.4.3 2: package ‘ggplot2’ was built under R version 4.4.3 > # Load the dataset > data(mtcars) > # View the first few rows > head(mtcars) mpg cyl disp hp drat wt qsec vs am gear carb Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4 Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1 Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2 Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1 > # Fit a linear regression model > model <- lm(mpg ~ wt, data = mtcars) > # Summary of the model > summary(model) Call: lm(formula = mpg ~ wt, data = mtcars) Residuals: Min 1Q Median 3Q Max -4.5432 -2.3647 -0.1252 1.4096 6.8727 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 37.2851 1.8776 19.858 < 2e-16 *** wt -5.3445 0.5591 -9.559 1.29e-10 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 3.046 on 30 degrees of freedom Multiple R-squared: 0.7528, Adjusted R-squared: 0.7446 F-statistic: 91.38 on 1 and 30 DF, p-value: 1.294e-10 > # Visualize the regression line > ggplot(mtcars, aes(x = wt, y = mpg)) + + geom_point(color = "blue") + + geom_smooth(method = "lm", color = "red") + + labs(title = "Linear Regression: MPG vs Weight", + x = "Weight of Car", + y = "Miles Per Gallon") `geom_smooth()` using formula = 'y ~ x' > summary(cars$speed) Min. 1st Qu. Median Mean 3rd Qu. Max. 4.0 12.0 15.0 15.4 19.0 25.0 > summary(pressure) temperature pressure Min. : 0 Min. : 0.0002 1st Qu.: 90 1st Qu.: 0.1800 Median :180 Median : 8.8000 Mean :180 Mean :124.3367 3rd Qu.:270 3rd Qu.:126.5000 Max. :360 Max. :806.0000 > plot(pressure) >