443-970-2353 [email protected] CV Resume

In [6]:

```
data(mtcars) #loading dataset
str(mtcars) # understand the covariates
names(mtcars)
```

Out[6]:

In [7]:

```
mtcars$cyl<-relevel(as.factor(mtcars$cyl), ref='8')
mtcars$vs<-relevel(as.factor(mtcars$vs), ref='0')
mtcars$am<-relevel(as.factor(mtcars$am), ref='0',labels=c('Automatic','Manual'))
mtcars$gear<-relevel(as.factor(mtcars$gear), ref='3')
mtcars$carb<-relevel(as.factor(mtcars$carb), ref='2')
```

Using pairs(mtcars), we get that fuel consumption increases as the number of cylinders (cyl), displacement (disp), horsepower (hp), and weight (wt) increase. That is to say, as these variables increase, the Miles per gallon (MPG) of cars dereases. We also observe that in this old dataset, manual tranmsion cars (am=1) have higher MPG than automatic transmission cars (am=0) as can be observed in Fig. 1.

Letâ€™s use t test and see if the difference in the mean MPG of automatic and maual transmisssion cars is significantly different from zero.

In [8]:

```
t.test(mtcars$mpg[mtcars$am==0],mtcars$mp[mtcars$am==1])
```

Out[8]:

In [9]:

```
modelA<-lm(mpg~., data=mtcars)
```

In [10]:

```
modelB<-step(modelA,direction ="both")
```

Now, letâ€™s see the variables selected by the step function.

In [11]:

```
modelB$coefficients
```

Out[11]:

In [20]:

```
boxplot(mpg~am, data=mtcars, main ='Fig. 1. Fuel Efficiency',
ylab='Miles per gallon',names=c("Automatic","Manual"),notch=FALSE, col=(c("gold","skyblue")))
```

In [22]:

```
coplot(wt ~ am |cyl, data = mtcars,
panel = panel.smooth, rows = 1, main ="Fig. 2")
```

In [23]:

```
coplot(mpg ~ am | cyl, data = mtcars, # cyl is the number of cylinders
panel = panel.smooth, rows = 1, main="Fig. 3") # am is transmision type (0=automatic, 1=manual)
```