Question A (0 pts)

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

## Your code
i <- 1:1000
result_A1 <- sum(1/i^2)

result_A1
## [1] 1.643935

2. Fibonacci number follows the following recurrence relation:

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

## 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[100]
## [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)

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

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

pvalue
## [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, only upload the html file to the e-leaning website..
  3. This is just an example homework, so 0 pts will be counted to your final grade.

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.