---
title: "Homework for lec02"
author: your name and student ID (名前と学籍番号)
output: html_document
---

```{r, message = F}
require(here)
```

Load data
```{r, message = F}
# this data set was analyzed in Zhao 2011 (Nature Communications 2:467)
pheno <- read.csv("RiceDiversityPheno.csv")
line <- read.csv("RiceDiversityLine.csv")
line.pheno <- merge(line, pheno, by.x = "NSFTV.ID", by.y = "NSFTVID")
head(line.pheno)[,1:12]
```

Prepare x and y.
```{r}
data <- data.frame(
    x = line.pheno$Panicle.length,
    y = line.pheno$Seed.number.per.panicle)
data <- na.omit(data)
head(data)
```

## Pleaes answer the following questions:

1. Using the number of seeds per panicle (Seed.number.per.panicle) as the dependent variable $y$ and panicle length (Panicle.length) as the independent variable $x$, fit a simple regression model ($y_i=\mu+\beta x_i+\epsilon_i$) and find the sample intercept m and sample regression coefficient b, which are estimates of $\mu$ and $\beta$.

```{r}
# write R code required for the answer
```

> Please write your answer and comment here

2. Test the null hypothesis $H_0:\beta=0.02$.

```{r}
# write R code required for the answer
```

> Please write your answer and comment here

3. Test the null hypothesis $H_0:\mu=5$.

```{r}
# write R code required for the answer
```

> Please write your answer and comment here

4. Answer the 95% confidence interval between the estimated $y$, i.e., $\hat y$ and the predicted $y$, i.e., $\tilde y$ for $x=27$.

```{r}
# write R code required for the answer
```

> Please write your answer and comment here

5. Fit the polynomial regression model $y_i=\mu+\beta_1 x_i+\beta_2 x_i^2 + \epsilon_i$) using the first- and second-order terms of $x$ and answer the determination coefficient $R^2$ and the adjusted coefficient of determination $R_{adj}^2$.

```{r}
# write R code required for the answer
```

> Please write your answer and comment here

6. Compare the regression model in 5 with the regression model in 1 in an analysis of variance and consider the validity of including a second-order term of $x$ in the regression model.

```{r}
# write R code required for the answer
```

> Please write your answer and comment here

7. Fit the polynomial regression model $y_i=\mu+\beta_1 x_i+\beta_2 x_i^2+\beta_3 x_i^3+\epsilon_i$) using the first- to third-order terms of $x$ and answer the decision coefficient $R^2$ and the he adjusted coefficient of determination $R_{adj}^2$.

```{r}
# write R code required for the answer
```

> Please write your answer and comment here

8. Compare the regression model in 7 with the regression model in 5 in an analysis of variance to examine the validity of extending the second-order polynomial regression model to a third-order polynomial regression model.

```{r}
# write R code required for the answer
```

> Please write your answer and comment here

