-
Notifications
You must be signed in to change notification settings - Fork 0
/
MechaCarChallenge.Rscript
69 lines (54 loc) · 2.38 KB
/
MechaCarChallenge.Rscript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env Rscript
# This R script works (poorly) in RStudio or git-bash because
# of the 'shebang' in line 1 above. Please use the the 'R Notebook'
# version with the '.Rmd' extension.
cat("\n")
cat("########################################################\n")
cat("####### Deliverable 1 - Linear Regression to Predict MPG\n")
cat("########################################################\n")
cat("\n")
# If you are trying to run this script from git-bash, you may need to
# uncomment and run the following 'install.packages' line so that
# the 'dplyr' library is found:
# install.packages("tidyverse", repos = "http://cran.us.r-project.org")
library(dplyr)
mc_mpg <- read.csv("./MechaCar_mpg.csv")
summary(lm(mpg ~ vehicle_length + vehicle_weight + spoiler_angle + ground_clearance + AWD, data=mc_mpg))
# I can't get the 'car' library to install from 'git-bash',
# but it works find in RStudio.
#
# install.packages("car", repos = "http://cran.us.r-project.org")
#
# In order to generate the 'Added Variable Plots' which plot the dependent
# variable against each and every independent variable, do this:
#library(car)
#model <- lm(mpg ~ vehicle_length + vehicle_weight + spoiler_angle + ground_clearance + AWD, data=mc_mpg)
#avPlots(model, layout=c(2,3), marginal.scale=FALSE)
cat("\n")
cat("############################################################\n")
cat("####### Deliverable 2 - Visualizations for the Trip Analysis\n")
cat("############################################################\n")
cat("\n")
coils <- read.csv("./Suspension_Coil.csv")
total_summary <- summarize(coils, Mean=mean(PSI), Median=median(PSI), Variance=var(PSI), SD=sd(PSI))
cat('\n')
total_summary
cat('\n')
lots <- group_by(coils, Manufacturing_Lot)
lot_summary <- summarize(lots, Mean=mean(PSI), Median=median(PSI), Variance=var(PSI), SD=sd(PSI), .groups="keep")
cat('\n')
lot_summary
cat('\n')
cat("\n")
cat("###################################################\n")
cat("####### Deliverable 3 - T-Tests on Suspension Coils\n")
cat("###################################################\n")
cat("\n")
all_lots_psi <- coils['PSI']
t.test(all_lots_psi[['PSI']], mu=1500)
lot1_psi <- subset(coils, Manufacturing_Lot == "Lot1")
t.test(lot1_psi[['PSI']], mu=1500)
lot2_psi <- subset(coils, Manufacturing_Lot == "Lot2")
t.test(lot2_psi[['PSI']], mu=1500)
lot3_psi <- subset(coils, Manufacturing_Lot == "Lot3")
t.test(lot3_psi[['PSI']], mu=1500)