-
Notifications
You must be signed in to change notification settings - Fork 0
/
MechaCarChallenge.R
51 lines (35 loc) · 1.58 KB
/
MechaCarChallenge.R
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
###Deliverable 1###########################################
# import csv file
# example code from 15.2.3
# demo_table <- read.csv(file='demo.csv',check.names=F,stringsAsFactors = F)
MechaCar_mpg <- read.csv(file='Assignment Resources/MechaCar_mpg.csv',check.names=F,stringsAsFactors = F)
# Perform linear regression using the lm() function
Mecha_lm <- lm(mpg ~ vehicle_length + vehicle_weight + spoiler_angle + ground_clearance + AWD, data=MechaCar_mpg)
Mecha_lm
# view using summary
summary(Mecha_lm)
# view R-squared
summary(Mecha_lm)$r.squared
################# Start Deliverable 2#################################################
# Import CSV file:
Suspension_Coil <- read.csv(file='Assignment Resources/Suspension_Coil.csv',check.names=F,stringsAsFactors = F)
# create a summary table for suspension_coils
total_summary <- Suspension_Coil %>%
summarize(Mean=mean(PSI), Median=median(PSI), Variance=var(PSI), std_Dev=sd(PSI))
total_summary
# view by lots using grouby:
lot_summary <- Suspension_Coil %>% group_by(Manufacturing_Lot) %>%
summarize(Mean=mean(PSI), Median=median(PSI), Variance=var(PSI), std_Dev=sd(PSI))
#######Deliverable 3##################
# note level of significance is .05
# Ho: mu = 1500
# Ha: mu <> 1500
t.test(Suspension_Coil$PSI, mu=1500)
# Analysis- p-value(0.06) greater than 0.05 therefore we fail to reject Ho
# t.test by lots
# Lot 1
t.test(subset(Suspension_Coil, Manufacturing_Lot=="Lot1")$PSI, mu=1500)
# Lot 2
t.test(subset(Suspension_Coil, Manufacturing_Lot=="Lot2")$PSI, mu=1500)
# Lot 3
t.test(subset(Suspension_Coil, Manufacturing_Lot=="Lot3")$PSI, mu=1500)