This is my first time using R Markdown, but I will try to complete this first homework assignment.

Problem 1

attach (mtcars)
tapply(mpg,am,sample)
## $`0`
##  [1] 21.5 18.1 14.3 19.2 13.3 22.8 10.4 14.7 24.4 21.4 15.5 16.4 10.4 19.2
## [15] 18.7 15.2 17.8 15.2 17.3
## 
## $`1`
##  [1] 15.0 30.4 21.0 26.0 19.7 32.4 33.9 27.3 15.8 30.4 21.4 22.8 21.0
tapply(mpg,am,mean)
##        0        1 
## 17.14737 24.39231
tapply(mpg,am,sd)
##        0        1 
## 3.833966 6.166504
tapply(mpg,am,median)
##    0    1 
## 17.3 22.8
tapply(mpg,am,quantile)
## $`0`
##    0%   25%   50%   75%  100% 
## 10.40 14.95 17.30 19.20 24.40 
## 
## $`1`
##   0%  25%  50%  75% 100% 
## 15.0 21.0 22.8 30.4 33.9
tapply(mpg,am,min)
##    0    1 
## 10.4 15.0
tapply(mpg,am,max)
##    0    1 
## 24.4 33.9
tapply(mpg,am,range)
## $`0`
## [1] 10.4 24.4
## 
## $`1`
## [1] 15.0 33.9

Problem 2

You can also embed plots, for example:

boxplot(mpg~am,data=mtcars, main="Car Mileage Data", 
        xlab="Transmission Type", ylab="Miles Per Gallon")

Problem 3

plot(am, mpg, main="Scatterplot", 
     xlab="Transmission Type ", ylab="Miles Per Gallon ", pch=2)

Problem 4

From examining both the boxplot and scatterplot transmittion type manuals appears to have better fuel economy since they use up less fuel per mile.

Problem 5

x0<-17.14737
x1<-24.39231
x0-x1
## [1] -7.24494
n0<-19
n1<-13
sd0<-3.833966
sd1<-6.166504
sp<-sqrt(((sd0)^2 *(n0-1)+(sd1)^2*(n1-1))/(n0+n1-2))
sp<-sqrt(((3.833966) ^ 2 *(18)+(6.166504) ^ 2 *(12))/(30))
sp<-sqrt(((14.699295*18)+(38.025772*12))/30)
sp<-sqrt((264.5873152+456.309259)/30)
sp
## [1] 4.902029
x0-x1
## [1] -7.24494
sp
## [1] 4.902029
ts<-(x0-x1)/(sp*sqrt((1/n0)+(1/n1)))
ts<-(-7.24494)/((4.902029)*sqrt((1/19)+(1/13)))
ts
## [1] -4.106127
abs(ts)
## [1] 4.106127
#Critial Value
qt(.975,30)
## [1] 2.042272
t<-2.042272

p<-2*pt(abs(ts),30,lower.tail=FALSE)
p<-2*pt(abs(-4.106127),30,lower.tail=FALSE)
p
## [1] 0.0002850207
t.test(mpg ~ am,var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  mpg by am
## t = -4.1061, df = 30, p-value = 0.000285
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -10.84837  -3.64151
## sample estimates:
## mean in group 0 mean in group 1 
##        17.14737        24.39231

Problem 6

summary(lm(mpg ~ am))
## 
## Call:
## lm(formula = mpg ~ am)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9.3923 -3.0923 -0.2974  3.2439  9.5077 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   17.147      1.125  15.247 1.13e-15 ***
## am             7.245      1.764   4.106 0.000285 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.902 on 30 degrees of freedom
## Multiple R-squared:  0.3598, Adjusted R-squared:  0.3385 
## F-statistic: 16.86 on 1 and 30 DF,  p-value: 0.000285