---
title: "R Notebook For Code Execution"
output: 
  html_document:
    toc: true
    toc_depth: 2
    toc_float: true
---


The following provided code should be used to make sure that:
    
- you have the required packages installed;
- you can run a python script from an outside source and get back an example dataset and plot.

The datasets in this notebook are not representative of ones in the Midterms/Exam - see the exercises in the lecture notes for such data examples.

If something does not work - make sure to find out **before your midterm**.

## Some Required Libraries

You may need the following libraries:

```{r}
suppressPackageStartupMessages({
  suppressWarnings({
    suppressMessages({
      library(lmtest)
      library(tseries)
    })
  })
})
```

You can also add any other libraries that you will be using.


## Setting your Student code

Below you should input your student code and run the code source. It should provide a small plot on succesfull completion. Before that, make sure you define your `STUDENT_CODE`:

```{r}
STUDENT_CODE <- YOUR_STUDENT_CODE
```


## Loading Functions and Data From the Notebook

The following functions will generate a dataset:

```{r}
plot_student <- function(student_code, nn){
  par(mar = c(0,0,0,0))
  plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')
  rect(0.2, 0.4, 0.8, 0.6, col = "khaki1")
  center <- c(mean(c(0.2, 0.8)), mean(c(0.4, 0.6)))
  text(x = center[1] / 2.5, y = center[2], paste0("Student: ", student_code, "\nDataset size: ", nn), cex = 1.6, col = "black", pos = 4)
  par(mfrow = c(1,1))  
}
```


```{r}
genr_data <- function(s_code){
  set.seed(s_code)
  #
  N <- sample(seq(from = 100, to = 300, length.out = 9), size = 1)
  x <- rnorm(mean = 12, sd = 4, n = N)
  e <- rnorm(mean = 0, sd = 0.51, n = N)
  y <- 1 + 2 * x + e
  #
  DT <- data.frame(x = x, y = y)
  #
  #
  plot_student(s_code, N)
  #
  return(DT)
}
```


The above function(-s) will be called for initial data generation.

---

---


### Data Example

Run the following code to generate data for your `STUDENT_CODE` via the above functions:

```{r}
DT1 = genr_data(STUDENT_CODE)
```

Your dataset should have some data:

```{r}
print(head(DT1))
```

```{r}
print(summary(DT1))
```


