Problem 1

Use R to compute the following quantities. Show your R codes and the result.
(a) 1+2+3+…+100
(b) 12+22+32+…+202
(c) 3-2+3-1+30+31+32+33+…+310

\[\sum_{i=1}^{n}i = \frac{(n)(n+1)}{2}\]

\[\sum_{i=1}^{n}i^{2} = \frac{(n)(n+1)(2n+1)}{6}\]

Part C is a series of the form

\[\sum_{i=-2}^{10}3^{i}\]

I wasn’t sure how to use r to solve this so I manually computed it.

(100*101)/2 
## [1] 5050
(20*21*41)/6 
## [1] 2870
3^-2+3^-1+3^0+3^1+3^2+3^3+3^4+3^5+3^6+3^7+3^8+3^9+3^10
## [1] 88573.44

Problem 2

Using the data set fuel.frame, do the following tasks. Your work should contain both the R codes and graphics output.
(a) Draw a boxplot of mileages per vehicle type. The plot should contain the title and axis labels. Choose a color of your choice from the list of available named colors.
(b) Draw a scatterplot of Weight versus Fuel. Include a (regression) line with the plot. The straight line should have a broken line with the red color.
(c) pairs(fuel.frame) draws the scatterplots of all the pairs in the data set. Some of them plots are not suitable for scatterplot. Select a subset of appropriate variables in the data set and redraw the pairs plot.

Note: to find a file path on a mac: open a new Finder window by pressing Command-N, and then press Shift-Command-G to reveal the Go to Folder panel for the new window. Then drag a target file from another window

fuel.frame1<-read.table("/Users/Leland/Desktop/Stat 200/datasets/fuel-frame.txt", header=T, sep=",")

head(fuel.frame1)
##          row.names Weight  Disp. Mileage     Fuel  Type
## 1   Eagle.Summit.4   2560   0.97      33 3.030303 Small
## 2    Ford.Escort.4   2345 114.00      33 3.030303 Small
## 3   Ford.Festiva.4   1845   0.81      37 2.702703 Small
## 4    Honda.Civic.4   2260   0.91      32 3.125000 Small
## 5  Mazda.Protege.4   2440 113.00      32 3.125000 Small
## 6 Mercury.Tracer.4   2285   0.97      26 3.846154 Small
Type<-fuel.frame1$Type
Mileage<-fuel.frame1$Mileage

boxplot(Mileage~Type, main = 'Mileage vs Type', xlab = 'Type', ylab = 'Mileage', col = 'Tomato')

#part b

plot(fuel.frame1$Weight, fuel.frame1$Fuel, main = 'Fuel vs Weight', xlab = 'Weight', ylab = 'Fuel')
fit<-lm(fuel.frame1$Fuel~fuel.frame1$Weight)
abline(fit,col = 'red',lty=2)

# part c
pairs(fuel.frame1)

#Um not exactly sure what I am supposed to do with this question, the wording is imprecise, but i think you want me to alter the output of fuel.frame1 to only show the pairs that make sense to be plotted. Scatterplots should be made with two quantitative variables. So i'll modify the fuel.frame1 data-frame to only include the quantitative variables
head(fuel.frame1)
##          row.names Weight  Disp. Mileage     Fuel  Type
## 1   Eagle.Summit.4   2560   0.97      33 3.030303 Small
## 2    Ford.Escort.4   2345 114.00      33 3.030303 Small
## 3   Ford.Festiva.4   1845   0.81      37 2.702703 Small
## 4    Honda.Civic.4   2260   0.91      32 3.125000 Small
## 5  Mazda.Protege.4   2440 113.00      32 3.125000 Small
## 6 Mercury.Tracer.4   2285   0.97      26 3.846154 Small
fuel.frame1$row.names<-NULL
fuel.frame1$Type<-NULL
head(fuel.frame1)
##   Weight  Disp. Mileage     Fuel
## 1   2560   0.97      33 3.030303
## 2   2345 114.00      33 3.030303
## 3   1845   0.81      37 2.702703
## 4   2260   0.91      32 3.125000
## 5   2440 113.00      32 3.125000
## 6   2285   0.97      26 3.846154
pairs(fuel.frame1)