---
title: "Assignment 1"
author: anonymous # <-- hand in anonymously
format:
  html:
    toc: true
    code-tools: true
    code-line-numbers: true
    number-sections: true
    mainfont: Georgia, serif
  pdf:
    geometry:
    - left=1cm,top=1cm,bottom=1cm,right=7cm
    number-sections: true
    code-annotations: none
editor: source
---


# General information

:::: {.content-hidden when-format="pdf"}
::: {.callout-warning collapse=false}

## Setup


*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*
**Make sure that this does not get displayed in the PDF!**
    



This is the template for [assignment 1](assignment1.html). You can download the [qmd-file](https://avehtari.github.io/BDA_course_Aalto/assignments/template1.qmd) or copy the code from this rendered document after clicking on `</> Code` in the top right corner.

**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**

The following will set-up `markmyassignment` to check your functions at the end of the notebook:

```{r}
library(markmyassignment)
assignment_path = paste("https://github.com/avehtari/BDA_course_Aalto/",
"blob/master/assignments/tests/assignment1.yml", sep="")
set_assignment(assignment_path)
```

:::
::::


# Basic probability theory notation and terms

Write your answers here!



# Basic computer skills

Do some setup here. Explain in text what you do.
```{r}
# Do some setup:
distribution_mean = .2
distribution_variance = .01

# You have to compute the parameters below from the given mean and variance
# distribution_alpha = ...
# distribution_beta = ...
```



## (a)


Plot the PDF here. Explain in text what you do.
```{r}
# Useful functions: seq(), plot() and dbeta()
```



## (b)


Sample and plot the histogram here. Explain in text what you do.
```{r}
# Useful functions: rbeta() and hist()
```



## (c)


Compute the sample mean and variance here. Explain in text what you do.
```{r}
# Useful functions: mean() and var()
```



## (d)


Compute the central interval here. Explain in text what you do.
```{r}
# Useful functions: quantile()
```


# Bayes' theorem 1

## (a)


Compute the quantities needed to justify your recommendation here. Explain in text what you do.
You can do the computation with pen and paper or in R.
Either way, you have to explain why you compute what you compute.

If you use pen and paper, you can include scans or pictures as follows (see also [assignment_instructions#fig-workflow](assignment_instructions#fig-workflow)):

![Parts of Bayesian workflow](additional_files/bayes_workflow.jpg){#fig-workflow width="350"}

See @fig-workflow for illustration of parts of Bayesian workflow.


# Bayes' theorem 2

You will need to change the numbers to the numbers in the exercise.
```{r}
boxes_test <- matrix(c(2,2,1,5,5,1), ncol = 2,
    dimnames = list(c("A", "B", "C"), c("red", "white")))
```



## (a)


Keep the below name and format for the function to work with `markmyassignment`:
```{r}
p_red <- function(boxes) {
    # Do computation here, and return as below.
    # This is the correct return value for the test data provided above.
    0.3928571
}
```



## (b)


Keep the below name and format for the function to work with `markmyassignment`:
```{r}
p_box <- function(boxes) {
    # Do computation here, and return as below.
    # This is the correct return value for the test data provided above.
    c(0.29090909,0.07272727,0.63636364)
}
```


# Bayes' theorem 3

## (a)


You will need to change the numbers to the numbers in the exercise.
```{r}
fraternal_prob = 1/125
identical_prob = 1/300
```
Keep the below name and format for the function to work with `markmyassignment`:
```{r}
p_identical_twin <- function(fraternal_prob, identical_prob) {
    # Do computation here, and return as below.
    # This is the correct return value for the test data provided above.
    0.4545455
}
```


# The three steps of Bayesian data analysis

## (a)


:::: {.content-hidden when-format="pdf"}
::: {.callout-warning collapse=false}

## markmyassignment


*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*
**Make sure that this does not get displayed in the PDF!**
    


The following will check the functions for which `markmyassignment` has been set up:

```{r}
mark_my_assignment()
```

:::
::::

