Question A (0 pts)

1. Calculate \(\sum_{i=1}^{1000} \frac{1}{i^2}\) (0 pts)

## Your code
i <- 1:1000
sum(1/i^2)
## [1] 1.643935
## replace NULL with your answer (by replacing NULL with the variable containing your answer)

2. Fibonacci number follows the following recurrence relation (0 pts):

\(F_n = F_{n-1} + F_{n-2}\). Given the seed value \(F_1 = 1\) and \(F_2 = 1\), what is \(F_{100}\)?

## Your code
N <- 100
F <- rep(NA, N)
F[1] <- 1
F[2] <- 1
for(n in 3:N){
  F[n] <- F[n-1] + F[n-2]
}

F[N] ## replace NULL with your answer (by replacing NULL with the variable containing your answer)
## [1] 3.542248e+20

Question B (0 pts)

1. In R base package, there is cars’ data. data(cars), plot speed (x axis) vs dist (y axis).

## Your code
plot(x=cars$speed, y = cars$dist, xlab="speed", ylab="dist", main="dist vs speed")

Question C (0 pts)

In R base package, there is mtcars’ data. data(mtcars)

1. Fit a linear model: treat mpg as response variable and cyl, disp, hp and drat as predictors. (0 pts)

## Your code
lmfit <- lm(mpg ~ cyl + disp + hp + drat, data=mtcars)
summary(lmfit)
## 
## Call:
## lm(formula = mpg ~ cyl + disp + hp + drat, data = mtcars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.5660 -1.8161 -0.6469  1.4094  6.5749 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept) 23.98524    7.98905   3.002  0.00571 **
## cyl         -0.81402    0.84368  -0.965  0.34318   
## disp        -0.01390    0.01089  -1.276  0.21287   
## hp          -0.02317    0.01576  -1.470  0.15299   
## drat         2.15405    1.59866   1.347  0.18905   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.012 on 27 degrees of freedom
## Multiple R-squared:  0.7825, Adjusted R-squared:  0.7503 
## F-statistic: 24.29 on 4 and 27 DF,  p-value: 1.314e-08

2. Find the p-value for cyl. (0 pts)

## Your code
pvalue <- summary(lmfit)$coefficients["cyl", "Pr(>|t|)"]

print(pvalue) ## replace NULL with your answer (by replacing NULL with the variable containing your answer)
## [1] 0.3431833

Note:

Homework should be uploaded to courseweb:

  1. Save your compiled result as html file. Rename the file name as: hw0_Lastname_Firstname.html.
  2. RMD file is not required. You only need to upload the html file to the e-leaning website.

If you generate a figure, please write appropriate figure title, labels, legend if necessary.

If your code is not intuitive, please write comments to make the code readible.