diff --git a/assignments/_freeze/assignment_instructions/figure-pdf/fig-drowning1-1.pdf b/assignments/_freeze/assignment_instructions/figure-pdf/fig-drowning1-1.pdf index 8355f51e..d81a0bcf 100644 Binary files a/assignments/_freeze/assignment_instructions/figure-pdf/fig-drowning1-1.pdf and b/assignments/_freeze/assignment_instructions/figure-pdf/fig-drowning1-1.pdf differ diff --git a/assignments/_freeze/assignment_instructions/figure-pdf/fig-drowning2-1.pdf b/assignments/_freeze/assignment_instructions/figure-pdf/fig-drowning2-1.pdf index 266774c1..23537657 100644 Binary files a/assignments/_freeze/assignment_instructions/figure-pdf/fig-drowning2-1.pdf and b/assignments/_freeze/assignment_instructions/figure-pdf/fig-drowning2-1.pdf differ diff --git a/assignments/_freeze/assignment_instructions/figure-pdf/unnamed-chunk-7-1.pdf b/assignments/_freeze/assignment_instructions/figure-pdf/unnamed-chunk-7-1.pdf index 413b9ce7..8c150d9f 100644 Binary files a/assignments/_freeze/assignment_instructions/figure-pdf/unnamed-chunk-7-1.pdf and b/assignments/_freeze/assignment_instructions/figure-pdf/unnamed-chunk-7-1.pdf differ diff --git a/assignments/_freeze/simple_template3/execute-results/html.json b/assignments/_freeze/simple_template3/execute-results/html.json index 57ecacf7..e8a8e347 100644 --- a/assignments/_freeze/simple_template3/execute-results/html.json +++ b/assignments/_freeze/simple_template3/execute-results/html.json @@ -1,7 +1,7 @@ { "hash": "9ae5fb20084e2e140e512505681aa444", "result": { - "markdown": "---\ntitle: \"Assignment 3\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n page-layout: article\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n\nThis is the template for [assignment 3](assignment3.html). You can download the qmd-files ([full](https://avehtari.github.io/BDA_course_Aalto/assignments/template3.qmd), [simple](https://avehtari.github.io/BDA_course_Aalto/assignments/simple_template3.qmd)) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up [`markmyassignment`](https://github.com/MansMeg/markmyassignment) to check your functions at the end of the notebook:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(markmyassignment)){\n install.packages(\"markmyassignment\")\n library(markmyassignment)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: markmyassignment\n```\n:::\n\n```{.r .cell-code}\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment3.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment3: Bayesian Data Analysis: Assignment 3\nThe assignment contain the following (6) tasks:\n- mu_point_est\n- mu_interval\n- mu_pred_interval\n- mu_pred_point_est\n- posterior_odds_ratio_point_est\n- posterior_odds_ratio_interval\n```\n:::\n:::\n\n\nThe following installs and loads the `aaltobda` package:\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(aaltobda)){\n install.packages(\"aaltobda\", repos = c(\"https://avehtari.github.io/BDA_course_Aalto/\", getOption(\"repos\")))\n library(aaltobda)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: aaltobda\n```\n:::\n:::\n\nThe following installs and loads the [`latex2exp` package](https://github.com/stefano-meschiari/latex2exp), which allows us to use LaTeX in plots:\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(latex2exp)){\n install.packages(\"latex2exp\")\n library(latex2exp)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: latex2exp\n```\n:::\n:::\n\n\n:::\n::::\n\n\n\n\n# Inference for normal mean and deviation (3 points)\n\nLoading the library and the data.\n\n::: {.cell}\n\n```{.r .cell-code}\ndata(\"windshieldy1\")\n# The data are now stored in the variable `windshieldy1`.\n# The below displays the data:\nwindshieldy1\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 13.357 14.928 14.896 15.297 14.820 12.067 14.824 13.865 17.447\n```\n:::\n:::\n\nThe below data is **only for the tests**, you need to change to the\nfull data `windshieldy1` when reporting your results.\n\n::: {.cell}\n\n```{.r .cell-code}\nwindshieldy_test <- c(13.357, 14.928, 14.896, 14.820)\n```\n:::\n\n\n\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum()\n# and qtnew(), dtnew() (from aaltobda)\n\nmu_point_est <- function(data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 14.5\n\n}\nmu_interval <- function(data, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(13.3, 15.7)\n\n}\n```\n:::\n\n\nYou can plot the density as below if you implement `mu_pdf` to compute the PDF of the posterior $p(\\mu|y)$ of the average hardness $\\mu$.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmu_pdf <- function(data, x){\n # Compute necessary parameters here.\n # These are the correct parameters for `windshieldy_test`\n # with the provided uninformative prior.\n df = 3\n location = 14.5\n scale = 0.3817557\n # Use the computed parameters as below to compute the PDF:\n\n dtnew(x, df, location, scale)\n}\n\nx_interval = mu_interval(windshieldy1, .999)\nlower_x = x_interval[1]\nupper_x = x_interval[2]\nx = seq(lower_x, upper_x, length.out=1000)\nplot(\n x, mu_pdf(windshieldy1, x), type=\"l\",\n xlab=TeX(r'(average hardness $\\mu$)'),\n ylab=TeX(r'(PDF of the posterior $p(\\mu|y)$)')\n)\n```\n\n::: {.cell-output-display}\n![PDF of the posterior $p(\\mu|y)$ of the average hardness $\\mu$](simple_template3_files/figure-html/fig-2b-density-1.png){#fig-2b-density width=672}\n:::\n:::\n\n\n\n\n## (c)\n\n\nWrite your answers and code here!\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum()\n# and qtnew(), dtnew() (from aaltobda)\n\nmu_pred_point_est <- function(data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 14.5\n\n}\nmu_pred_interval <- function(data, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(11.8, 17.2)\n\n}\n```\n:::\n\n\nYou can plot the density as below if you implement `mu_pred_pdf` to compute the PDF of the posterior predictive $p(\\tilde{y}|y)$ of a new hardness observation $\\tilde{y}$.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmu_pred_pdf <- function(data, x){\n # Compute necessary parameters here.\n # These are the correct parameters for `windshieldy_test`\n # with the provided uninformative prior.\n df = 3\n location = 14.5\n scale = 0.8536316\n # Use the computed parameters as below to compute the PDF:\n\n dtnew(x, df, location, scale)\n}\n\nx_interval = mu_pred_interval(windshieldy1, .999)\nlower_x = x_interval[1]\nupper_x = x_interval[2]\nx = seq(lower_x, upper_x, length.out=1000)\nplot(\n x, mu_pred_pdf(windshieldy1, x), type=\"l\",\n xlab=TeX(r'(new hardness observation $\\tilde{y}$)'),\n ylab=TeX(r'(PDF of the posterior predictive $p(\\tilde{y}|y)$)')\n)\n```\n\n::: {.cell-output-display}\n![PDF of the posterior predictive $p(\\tilde{y}|y)$ of a new hardness observation $\\tilde{y}$](simple_template3_files/figure-html/fig-2c-density-1.png){#fig-2c-density width=672}\n:::\n:::\n\n\n\n# Inference for the difference between proportions (3 points)\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\nThe below data is **only for the tests**:\n\n::: {.cell}\n\n```{.r .cell-code}\nset.seed(4711)\nndraws = 1000\np0 = rbeta(ndraws, 5, 95)\np1 = rbeta(ndraws, 10, 90)\n```\n:::\n\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: mean(), quantile()\n\nposterior_odds_ratio_point_est <- function(p0, p1) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 2.650172\n\n}\nposterior_odds_ratio_interval <- function(p0, p1, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(0.6796942,7.3015964)\n\n}\n```\n:::\n\n\n\n\n\n\n## (c)\n\n\nWrite your answers and code here!\n\n\n# Inference for the difference between normal means (3 points)\n\nLoading the library and the data.\n\n::: {.cell}\n\n```{.r .cell-code}\ndata(\"windshieldy2\")\n# The new data are now stored in the variable `windshieldy2`.\n# The below displays the first few rows of the new data:\nhead(windshieldy2)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 15.980 14.206 16.011 17.250 15.993 15.722\n```\n:::\n:::\n\n\n\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum(),\n# rtnew() (from aaltobda), quantile() and hist().\n```\n:::\n\n\n\n\n## (c)\n\n\nWrite your answers here!\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n✔ | F W S OK | Context\n\n⠏ | 0 | task-1-subtask-1-tests \n⠏ | 0 | mu_point_est() \n✖ | 1 3 | mu_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-1-subtask-1-tests.R:17:3'): mu_point_est()\nmu_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-2-subtask-1-tests \n⠏ | 0 | mu_interval() \n✖ | 2 3 | mu_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-2-subtask-1-tests.R:15:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.95) not equivalent to c(3.3, 7.7).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 3.3 == 10\n[2] 15.7 - 7.7 == 8\nError: Incorrect result for 1:10 using a 95% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:16:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.8) not equivalent to c(4.2, 6.8).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 4.2 == 9.1\n[2] 15.7 - 6.8 == 8.9\nError: Incorrect result for 1:10 using a 80% interval.\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-3-subtask-1-tests \n⠏ | 0 | mu_pred_interval() \n✖ | 2 3 | mu_pred_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-3-subtask-1-tests.R:16:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.95) not equivalent to c(-1.7, 12.7).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - -1.7 == 13.5\n[2] 17.2 - 12.7 == 4.5\nError: Incorrect result for 1:10, (95%)\n\nFailure ('test-task-3-subtask-1-tests.R:18:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.8) not equivalent to c(1.1, 9.9).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - 1.1 == 10.7\n[2] 17.2 - 9.9 == 7.3\nError: Incorrect result for 1:10, (80%)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-4-subtask-1-tests \n⠏ | 0 | mu_pred_point_est() \n✖ | 1 3 | mu_pred_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-4-subtask-1-tests.R:16:3'): mu_pred_point_est()\nmu_pred_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-5-subtask-1-tests \n⠏ | 0 | posterior_odds_ratio_point_est() \n✖ | 3 3 | posterior_odds_ratio_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-5-subtask-1-tests.R:18:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 0.5307909.\n1/1 mismatches\n[1] 2.65 - 0.531 == 2.12\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90).\n\nFailure ('test-task-5-subtask-1-tests.R:24:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p0, p1) not equivalent to 1.876519.\n1/1 mismatches\n[1] 2.65 - 1.88 == 0.774\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6).\n\nFailure ('test-task-5-subtask-1-tests.R:25:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 1.24902.\n1/1 mismatches\n[1] 2.65 - 1.25 == 1.4\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5).\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-6-subtask-1-tests \n⠏ | 0 | posterior_odds_ratio_interval() \n⠧ | 6 2 | posterior_odds_ratio_interval() \n✖ | 6 2 | posterior_odds_ratio_interval() [0.1s]\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-6-subtask-1-tests.R:17:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.875367, 6.05911).\n2/2 mismatches (average diff: 0.719)\n[1] 0.68 - 0.875 == -0.196\n[2] 7.30 - 6.059 == 1.242\nError: Incorrect result for p0 = rbeta(100000, 5, 95), p1 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:19:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1650407, 1.142378).\n2/2 mismatches (average diff: 3.34)\n[1] 0.68 - 0.165 == 0.515\n[2] 7.30 - 1.142 == 6.159\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:21:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.2086461, 0.9392956).\n2/2 mismatches (average diff: 3.42)\n[1] 0.68 - 0.209 == 0.471\n[2] 7.30 - 0.939 == 6.362\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 80%.\n\nFailure ('test-task-6-subtask-1-tests.R:27:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.2714472, 5.5970131).\n2/2 mismatches (average diff: 1.06)\n[1] 0.68 - 0.271 == 0.408\n[2] 7.30 - 5.597 == 1.705\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:29:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1786667, 3.6839583).\n2/2 mismatches (average diff: 2.06)\n[1] 0.68 - 0.179 == 0.501\n[2] 7.30 - 3.684 == 3.618\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:31:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.252972, 2.633517).\n2/2 mismatches (average diff: 2.55)\n[1] 0.68 - 0.253 == 0.427\n[2] 7.30 - 2.634 == 4.668\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 80%.\n────────────────────────────────────────────────────────────────────────────────\nMaximum number of failures exceeded; quitting at end of file.\nℹ Increase this number with (e.g.) `testthat::set_max_fails(Inf)` \n\n══ Results ═════════════════════════════════════════════════════════════════════\nDuration: 0.6 s\n\n[ FAIL 15 | WARN 0 | SKIP 0 | PASS 17 ]\n══ Terminated early ════════════════════════════════════════════════════════════\n```\n:::\n:::\n\n\n:::\n::::\n", + "markdown": "---\ntitle: \"Assignment 3\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n page-layout: article\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n\nThis is the template for [assignment 3](assignment3.html). You can download the qmd-files ([full](https://avehtari.github.io/BDA_course_Aalto/assignments/template3.qmd), [simple](https://avehtari.github.io/BDA_course_Aalto/assignments/simple_template3.qmd)) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up [`markmyassignment`](https://github.com/MansMeg/markmyassignment) to check your functions at the end of the notebook:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(markmyassignment)){\n install.packages(\"markmyassignment\")\n library(markmyassignment)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: markmyassignment\n```\n:::\n\n```{.r .cell-code}\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment3.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment3: Bayesian Data Analysis: Assignment 3\nThe assignment contain the following (6) tasks:\n- mu_point_est\n- mu_interval\n- mu_pred_interval\n- mu_pred_point_est\n- posterior_odds_ratio_point_est\n- posterior_odds_ratio_interval\n```\n:::\n:::\n\n\nThe following installs and loads the `aaltobda` package:\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(aaltobda)){\n install.packages(\"aaltobda\", repos = c(\"https://avehtari.github.io/BDA_course_Aalto/\", getOption(\"repos\")))\n library(aaltobda)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: aaltobda\n```\n:::\n:::\n\nThe following installs and loads the [`latex2exp` package](https://github.com/stefano-meschiari/latex2exp), which allows us to use LaTeX in plots:\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(latex2exp)){\n install.packages(\"latex2exp\")\n library(latex2exp)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: latex2exp\n```\n:::\n:::\n\n\n:::\n::::\n\n\n\n\n# Inference for normal mean and deviation (3 points)\n\nLoading the library and the data.\n\n::: {.cell}\n\n```{.r .cell-code}\ndata(\"windshieldy1\")\n# The data are now stored in the variable `windshieldy1`.\n# The below displays the data:\nwindshieldy1\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 13.357 14.928 14.896 15.297 14.820 12.067 14.824 13.865 17.447\n```\n:::\n:::\n\nThe below data is **only for the tests**, you need to change to the\nfull data `windshieldy1` when reporting your results.\n\n::: {.cell}\n\n```{.r .cell-code}\nwindshieldy_test <- c(13.357, 14.928, 14.896, 14.820)\n```\n:::\n\n\n\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum()\n# and qtnew(), dtnew() (from aaltobda)\n\nmu_point_est <- function(data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 14.5\n\n}\nmu_interval <- function(data, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(13.3, 15.7)\n\n}\n```\n:::\n\n\nYou can plot the density as below if you implement `mu_pdf` to compute the PDF of the posterior $p(\\mu|y)$ of the average hardness $\\mu$.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmu_pdf <- function(data, x){\n # Compute necessary parameters here.\n # These are the correct parameters for `windshieldy_test`\n # with the provided uninformative prior.\n df = 3\n location = 14.5\n scale = 0.3817557\n # Use the computed parameters as below to compute the PDF:\n\n dtnew(x, df, location, scale)\n}\n\nx_interval = mu_interval(windshieldy1, .999)\nlower_x = x_interval[1]\nupper_x = x_interval[2]\nx = seq(lower_x, upper_x, length.out=1000)\nplot(\n x, mu_pdf(windshieldy1, x), type=\"l\",\n xlab=TeX(r'(average hardness $\\mu$)'),\n ylab=TeX(r'(PDF of the posterior $p(\\mu|y)$)')\n)\n```\n\n::: {.cell-output-display}\n![PDF of the posterior $p(\\mu|y)$ of the average hardness $\\mu$](simple_template3_files/figure-html/fig-2b-density-1.png){#fig-2b-density width=672}\n:::\n:::\n\n\n\n\n## (c)\n\n\nWrite your answers and code here!\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum()\n# and qtnew(), dtnew() (from aaltobda)\n\nmu_pred_point_est <- function(data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 14.5\n\n}\nmu_pred_interval <- function(data, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(11.8, 17.2)\n\n}\n```\n:::\n\n\nYou can plot the density as below if you implement `mu_pred_pdf` to compute the PDF of the posterior predictive $p(\\tilde{y}|y)$ of a new hardness observation $\\tilde{y}$.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmu_pred_pdf <- function(data, x){\n # Compute necessary parameters here.\n # These are the correct parameters for `windshieldy_test`\n # with the provided uninformative prior.\n df = 3\n location = 14.5\n scale = 0.8536316\n # Use the computed parameters as below to compute the PDF:\n\n dtnew(x, df, location, scale)\n}\n\nx_interval = mu_pred_interval(windshieldy1, .999)\nlower_x = x_interval[1]\nupper_x = x_interval[2]\nx = seq(lower_x, upper_x, length.out=1000)\nplot(\n x, mu_pred_pdf(windshieldy1, x), type=\"l\",\n xlab=TeX(r'(new hardness observation $\\tilde{y}$)'),\n ylab=TeX(r'(PDF of the posterior predictive $p(\\tilde{y}|y)$)')\n)\n```\n\n::: {.cell-output-display}\n![PDF of the posterior predictive $p(\\tilde{y}|y)$ of a new hardness observation $\\tilde{y}$](simple_template3_files/figure-html/fig-2c-density-1.png){#fig-2c-density width=672}\n:::\n:::\n\n\n\n# Inference for the difference between proportions (3 points)\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\nThe below data is **only for the tests**:\n\n::: {.cell}\n\n```{.r .cell-code}\nset.seed(4711)\nndraws = 1000\np0 = rbeta(ndraws, 5, 95)\np1 = rbeta(ndraws, 10, 90)\n```\n:::\n\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: mean(), quantile()\n\nposterior_odds_ratio_point_est <- function(p0, p1) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 2.650172\n\n}\nposterior_odds_ratio_interval <- function(p0, p1, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(0.6796942,7.3015964)\n\n}\n```\n:::\n\n\n\n\n\n\n## (c)\n\n\nWrite your answers and code here!\n\n\n# Inference for the difference between normal means (3 points)\n\nLoading the library and the data.\n\n::: {.cell}\n\n```{.r .cell-code}\ndata(\"windshieldy2\")\n# The new data are now stored in the variable `windshieldy2`.\n# The below displays the first few rows of the new data:\nhead(windshieldy2)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 15.980 14.206 16.011 17.250 15.993 15.722\n```\n:::\n:::\n\n\n\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum(),\n# rtnew() (from aaltobda), quantile() and hist().\n```\n:::\n\n\n\n\n## (c)\n\n\nWrite your answers here!\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n✔ | F W S OK | Context\n\n⠏ | 0 | task-1-subtask-1-tests \n⠏ | 0 | mu_point_est() \n✖ | 1 3 | mu_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-1-subtask-1-tests.R:17:3'): mu_point_est()\nmu_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-2-subtask-1-tests \n⠏ | 0 | mu_interval() \n✖ | 2 3 | mu_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-2-subtask-1-tests.R:15:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.95) not equivalent to c(3.3, 7.7).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 3.3 == 10\n[2] 15.7 - 7.7 == 8\nError: Incorrect result for 1:10 using a 95% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:16:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.8) not equivalent to c(4.2, 6.8).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 4.2 == 9.1\n[2] 15.7 - 6.8 == 8.9\nError: Incorrect result for 1:10 using a 80% interval.\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-3-subtask-1-tests \n⠏ | 0 | mu_pred_interval() \n✖ | 2 3 | mu_pred_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-3-subtask-1-tests.R:16:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.95) not equivalent to c(-1.7, 12.7).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - -1.7 == 13.5\n[2] 17.2 - 12.7 == 4.5\nError: Incorrect result for 1:10, (95%)\n\nFailure ('test-task-3-subtask-1-tests.R:18:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.8) not equivalent to c(1.1, 9.9).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - 1.1 == 10.7\n[2] 17.2 - 9.9 == 7.3\nError: Incorrect result for 1:10, (80%)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-4-subtask-1-tests \n⠏ | 0 | mu_pred_point_est() \n✖ | 1 3 | mu_pred_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-4-subtask-1-tests.R:16:3'): mu_pred_point_est()\nmu_pred_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-5-subtask-1-tests \n⠏ | 0 | posterior_odds_ratio_point_est() \n✖ | 3 3 | posterior_odds_ratio_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-5-subtask-1-tests.R:18:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 0.5307909.\n1/1 mismatches\n[1] 2.65 - 0.531 == 2.12\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90).\n\nFailure ('test-task-5-subtask-1-tests.R:24:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p0, p1) not equivalent to 1.876519.\n1/1 mismatches\n[1] 2.65 - 1.88 == 0.774\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6).\n\nFailure ('test-task-5-subtask-1-tests.R:25:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 1.24902.\n1/1 mismatches\n[1] 2.65 - 1.25 == 1.4\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5).\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-6-subtask-1-tests \n⠏ | 0 | posterior_odds_ratio_interval() \n✖ | 6 2 | posterior_odds_ratio_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-6-subtask-1-tests.R:17:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.875367, 6.05911).\n2/2 mismatches (average diff: 0.719)\n[1] 0.68 - 0.875 == -0.196\n[2] 7.30 - 6.059 == 1.242\nError: Incorrect result for p0 = rbeta(100000, 5, 95), p1 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:19:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1650407, 1.142378).\n2/2 mismatches (average diff: 3.34)\n[1] 0.68 - 0.165 == 0.515\n[2] 7.30 - 1.142 == 6.159\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:21:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.2086461, 0.9392956).\n2/2 mismatches (average diff: 3.42)\n[1] 0.68 - 0.209 == 0.471\n[2] 7.30 - 0.939 == 6.362\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 80%.\n\nFailure ('test-task-6-subtask-1-tests.R:27:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.2714472, 5.5970131).\n2/2 mismatches (average diff: 1.06)\n[1] 0.68 - 0.271 == 0.408\n[2] 7.30 - 5.597 == 1.705\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:29:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1786667, 3.6839583).\n2/2 mismatches (average diff: 2.06)\n[1] 0.68 - 0.179 == 0.501\n[2] 7.30 - 3.684 == 3.618\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:31:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.252972, 2.633517).\n2/2 mismatches (average diff: 2.55)\n[1] 0.68 - 0.253 == 0.427\n[2] 7.30 - 2.634 == 4.668\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 80%.\n────────────────────────────────────────────────────────────────────────────────\nMaximum number of failures exceeded; quitting at end of file.\nℹ Increase this number with (e.g.) `testthat::set_max_fails(Inf)` \n\n══ Results ═════════════════════════════════════════════════════════════════════\nDuration: 0.5 s\n\n[ FAIL 15 | WARN 0 | SKIP 0 | PASS 17 ]\n══ Terminated early ════════════════════════════════════════════════════════════\n```\n:::\n:::\n\n\n:::\n::::\n", "supporting": [ "simple_template3_files" ], diff --git a/assignments/_freeze/simple_template3/execute-results/tex.json b/assignments/_freeze/simple_template3/execute-results/tex.json index 872297fd..c6ceb872 100644 --- a/assignments/_freeze/simple_template3/execute-results/tex.json +++ b/assignments/_freeze/simple_template3/execute-results/tex.json @@ -1,7 +1,7 @@ { "hash": "9ae5fb20084e2e140e512505681aa444", "result": { - "markdown": "---\ntitle: \"Assignment 3\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n page-layout: article\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n\nThis is the template for [assignment 3](assignment3.html). You can download the qmd-files ([full](https://avehtari.github.io/BDA_course_Aalto/assignments/template3.qmd), [simple](https://avehtari.github.io/BDA_course_Aalto/assignments/simple_template3.qmd)) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up [`markmyassignment`](https://github.com/MansMeg/markmyassignment) to check your functions at the end of the notebook:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(markmyassignment)){\n install.packages(\"markmyassignment\")\n library(markmyassignment)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: markmyassignment\n```\n:::\n\n```{.r .cell-code}\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment3.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment3: Bayesian Data Analysis: Assignment 3\nThe assignment contain the following (6) tasks:\n- mu_point_est\n- mu_interval\n- mu_pred_interval\n- mu_pred_point_est\n- posterior_odds_ratio_point_est\n- posterior_odds_ratio_interval\n```\n:::\n:::\n\n\n\nThe following installs and loads the `aaltobda` package:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(aaltobda)){\n install.packages(\"aaltobda\", repos = c(\"https://avehtari.github.io/BDA_course_Aalto/\", getOption(\"repos\")))\n library(aaltobda)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: aaltobda\n```\n:::\n:::\n\n\nThe following installs and loads the [`latex2exp` package](https://github.com/stefano-meschiari/latex2exp), which allows us to use LaTeX in plots:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(latex2exp)){\n install.packages(\"latex2exp\")\n library(latex2exp)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: latex2exp\n```\n:::\n:::\n\n\n\n:::\n::::\n\n\n\n\n# Inference for normal mean and deviation (3 points)\n\nLoading the library and the data.\n\n\n::: {.cell}\n\n```{.r .cell-code}\ndata(\"windshieldy1\")\n# The data are now stored in the variable `windshieldy1`.\n# The below displays the data:\nwindshieldy1\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 13.357 14.928 14.896 15.297 14.820 12.067 14.824 13.865 17.447\n```\n:::\n:::\n\n\nThe below data is **only for the tests**, you need to change to the\nfull data `windshieldy1` when reporting your results.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nwindshieldy_test <- c(13.357, 14.928, 14.896, 14.820)\n```\n:::\n\n\n\n\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum()\n# and qtnew(), dtnew() (from aaltobda)\n\nmu_point_est <- function(data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 14.5\n\n}\nmu_interval <- function(data, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(13.3, 15.7)\n\n}\n```\n:::\n\n\n\nYou can plot the density as below if you implement `mu_pdf` to compute the PDF of the posterior $p(\\mu|y)$ of the average hardness $\\mu$.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmu_pdf <- function(data, x){\n # Compute necessary parameters here.\n # These are the correct parameters for `windshieldy_test`\n # with the provided uninformative prior.\n df = 3\n location = 14.5\n scale = 0.3817557\n # Use the computed parameters as below to compute the PDF:\n\n dtnew(x, df, location, scale)\n}\n\nx_interval = mu_interval(windshieldy1, .999)\nlower_x = x_interval[1]\nupper_x = x_interval[2]\nx = seq(lower_x, upper_x, length.out=1000)\nplot(\n x, mu_pdf(windshieldy1, x), type=\"l\",\n xlab=TeX(r'(average hardness $\\mu$)'),\n ylab=TeX(r'(PDF of the posterior $p(\\mu|y)$)')\n)\n```\n\n::: {.cell-output-display}\n![PDF of the posterior $p(\\mu|y)$ of the average hardness $\\mu$](simple_template3_files/figure-pdf/fig-2b-density-1.pdf){#fig-2b-density fig-pos='H'}\n:::\n:::\n\n\n\n\n\n## (c)\n\n\nWrite your answers and code here!\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum()\n# and qtnew(), dtnew() (from aaltobda)\n\nmu_pred_point_est <- function(data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 14.5\n\n}\nmu_pred_interval <- function(data, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(11.8, 17.2)\n\n}\n```\n:::\n\n\n\nYou can plot the density as below if you implement `mu_pred_pdf` to compute the PDF of the posterior predictive $p(\\tilde{y}|y)$ of a new hardness observation $\\tilde{y}$.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmu_pred_pdf <- function(data, x){\n # Compute necessary parameters here.\n # These are the correct parameters for `windshieldy_test`\n # with the provided uninformative prior.\n df = 3\n location = 14.5\n scale = 0.8536316\n # Use the computed parameters as below to compute the PDF:\n\n dtnew(x, df, location, scale)\n}\n\nx_interval = mu_pred_interval(windshieldy1, .999)\nlower_x = x_interval[1]\nupper_x = x_interval[2]\nx = seq(lower_x, upper_x, length.out=1000)\nplot(\n x, mu_pred_pdf(windshieldy1, x), type=\"l\",\n xlab=TeX(r'(new hardness observation $\\tilde{y}$)'),\n ylab=TeX(r'(PDF of the posterior predictive $p(\\tilde{y}|y)$)')\n)\n```\n\n::: {.cell-output-display}\n![PDF of the posterior predictive $p(\\tilde{y}|y)$ of a new hardness observation $\\tilde{y}$](simple_template3_files/figure-pdf/fig-2c-density-1.pdf){#fig-2c-density fig-pos='H'}\n:::\n:::\n\n\n\n\n# Inference for the difference between proportions (3 points)\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\nThe below data is **only for the tests**:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nset.seed(4711)\nndraws = 1000\np0 = rbeta(ndraws, 5, 95)\np1 = rbeta(ndraws, 10, 90)\n```\n:::\n\n\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: mean(), quantile()\n\nposterior_odds_ratio_point_est <- function(p0, p1) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 2.650172\n\n}\nposterior_odds_ratio_interval <- function(p0, p1, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(0.6796942,7.3015964)\n\n}\n```\n:::\n\n\n\n\n\n\n\n## (c)\n\n\nWrite your answers and code here!\n\n\n# Inference for the difference between normal means (3 points)\n\nLoading the library and the data.\n\n\n::: {.cell}\n\n```{.r .cell-code}\ndata(\"windshieldy2\")\n# The new data are now stored in the variable `windshieldy2`.\n# The below displays the first few rows of the new data:\nhead(windshieldy2)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 15.980 14.206 16.011 17.250 15.993 15.722\n```\n:::\n:::\n\n\n\n\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum(),\n# rtnew() (from aaltobda), quantile() and hist().\n```\n:::\n\n\n\n\n\n## (c)\n\n\nWrite your answers here!\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nv | F W S OK | Context\n\n/ | 0 | task-1-subtask-1-tests \n/ | 0 | mu_point_est() \nx | 1 3 | mu_point_est()\n--------------------------------------------------------------------------------\nFailure ('test-task-1-subtask-1-tests.R:17:3'): mu_point_est()\nmu_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n--------------------------------------------------------------------------------\n\n/ | 0 | task-2-subtask-1-tests \n/ | 0 | mu_interval() \nx | 2 3 | mu_interval()\n--------------------------------------------------------------------------------\nFailure ('test-task-2-subtask-1-tests.R:15:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.95) not equivalent to c(3.3, 7.7).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 3.3 == 10\n[2] 15.7 - 7.7 == 8\nError: Incorrect result for 1:10 using a 95% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:16:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.8) not equivalent to c(4.2, 6.8).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 4.2 == 9.1\n[2] 15.7 - 6.8 == 8.9\nError: Incorrect result for 1:10 using a 80% interval.\n--------------------------------------------------------------------------------\n\n/ | 0 | task-3-subtask-1-tests \n/ | 0 | mu_pred_interval() \nx | 2 3 | mu_pred_interval()\n--------------------------------------------------------------------------------\nFailure ('test-task-3-subtask-1-tests.R:16:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.95) not equivalent to c(-1.7, 12.7).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - -1.7 == 13.5\n[2] 17.2 - 12.7 == 4.5\nError: Incorrect result for 1:10, (95%)\n\nFailure ('test-task-3-subtask-1-tests.R:18:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.8) not equivalent to c(1.1, 9.9).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - 1.1 == 10.7\n[2] 17.2 - 9.9 == 7.3\nError: Incorrect result for 1:10, (80%)\n--------------------------------------------------------------------------------\n\n/ | 0 | task-4-subtask-1-tests \n/ | 0 | mu_pred_point_est() \nx | 1 3 | mu_pred_point_est()\n--------------------------------------------------------------------------------\nFailure ('test-task-4-subtask-1-tests.R:16:3'): mu_pred_point_est()\nmu_pred_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n--------------------------------------------------------------------------------\n\n/ | 0 | task-5-subtask-1-tests \n/ | 0 | posterior_odds_ratio_point_est() \nx | 3 3 | posterior_odds_ratio_point_est()\n--------------------------------------------------------------------------------\nFailure ('test-task-5-subtask-1-tests.R:18:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 0.5307909.\n1/1 mismatches\n[1] 2.65 - 0.531 == 2.12\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90).\n\nFailure ('test-task-5-subtask-1-tests.R:24:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p0, p1) not equivalent to 1.876519.\n1/1 mismatches\n[1] 2.65 - 1.88 == 0.774\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6).\n\nFailure ('test-task-5-subtask-1-tests.R:25:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 1.24902.\n1/1 mismatches\n[1] 2.65 - 1.25 == 1.4\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5).\n--------------------------------------------------------------------------------\n\n/ | 0 | task-6-subtask-1-tests \n/ | 0 | posterior_odds_ratio_interval() \n/ | 6 2 | posterior_odds_ratio_interval() \nx | 6 2 | posterior_odds_ratio_interval() [0.1s]\n--------------------------------------------------------------------------------\nFailure ('test-task-6-subtask-1-tests.R:17:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.875367, 6.05911).\n2/2 mismatches (average diff: 0.719)\n[1] 0.68 - 0.875 == -0.196\n[2] 7.30 - 6.059 == 1.242\nError: Incorrect result for p0 = rbeta(100000, 5, 95), p1 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:19:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1650407, 1.142378).\n2/2 mismatches (average diff: 3.34)\n[1] 0.68 - 0.165 == 0.515\n[2] 7.30 - 1.142 == 6.159\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:21:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.2086461, 0.9392956).\n2/2 mismatches (average diff: 3.42)\n[1] 0.68 - 0.209 == 0.471\n[2] 7.30 - 0.939 == 6.362\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 80%.\n\nFailure ('test-task-6-subtask-1-tests.R:27:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.2714472, 5.5970131).\n2/2 mismatches (average diff: 1.06)\n[1] 0.68 - 0.271 == 0.408\n[2] 7.30 - 5.597 == 1.705\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:29:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1786667, 3.6839583).\n2/2 mismatches (average diff: 2.06)\n[1] 0.68 - 0.179 == 0.501\n[2] 7.30 - 3.684 == 3.618\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:31:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.252972, 2.633517).\n2/2 mismatches (average diff: 2.55)\n[1] 0.68 - 0.253 == 0.427\n[2] 7.30 - 2.634 == 4.668\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 80%.\n--------------------------------------------------------------------------------\nMaximum number of failures exceeded; quitting at end of file.\ni Increase this number with (e.g.) `testthat::set_max_fails(Inf)` \n\n== Results =====================================================================\nDuration: 0.6 s\n\n[ FAIL 15 | WARN 0 | SKIP 0 | PASS 17 ]\n== Terminated early ============================================================\n```\n:::\n:::\n\n\n\n:::\n::::\n", + "markdown": "---\ntitle: \"Assignment 3\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n page-layout: article\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n\nThis is the template for [assignment 3](assignment3.html). You can download the qmd-files ([full](https://avehtari.github.io/BDA_course_Aalto/assignments/template3.qmd), [simple](https://avehtari.github.io/BDA_course_Aalto/assignments/simple_template3.qmd)) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up [`markmyassignment`](https://github.com/MansMeg/markmyassignment) to check your functions at the end of the notebook:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(markmyassignment)){\n install.packages(\"markmyassignment\")\n library(markmyassignment)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: markmyassignment\n```\n:::\n\n```{.r .cell-code}\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment3.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment3: Bayesian Data Analysis: Assignment 3\nThe assignment contain the following (6) tasks:\n- mu_point_est\n- mu_interval\n- mu_pred_interval\n- mu_pred_point_est\n- posterior_odds_ratio_point_est\n- posterior_odds_ratio_interval\n```\n:::\n:::\n\n\n\nThe following installs and loads the `aaltobda` package:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(aaltobda)){\n install.packages(\"aaltobda\", repos = c(\"https://avehtari.github.io/BDA_course_Aalto/\", getOption(\"repos\")))\n library(aaltobda)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: aaltobda\n```\n:::\n:::\n\n\nThe following installs and loads the [`latex2exp` package](https://github.com/stefano-meschiari/latex2exp), which allows us to use LaTeX in plots:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(latex2exp)){\n install.packages(\"latex2exp\")\n library(latex2exp)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: latex2exp\n```\n:::\n:::\n\n\n\n:::\n::::\n\n\n\n\n# Inference for normal mean and deviation (3 points)\n\nLoading the library and the data.\n\n\n::: {.cell}\n\n```{.r .cell-code}\ndata(\"windshieldy1\")\n# The data are now stored in the variable `windshieldy1`.\n# The below displays the data:\nwindshieldy1\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 13.357 14.928 14.896 15.297 14.820 12.067 14.824 13.865 17.447\n```\n:::\n:::\n\n\nThe below data is **only for the tests**, you need to change to the\nfull data `windshieldy1` when reporting your results.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nwindshieldy_test <- c(13.357, 14.928, 14.896, 14.820)\n```\n:::\n\n\n\n\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum()\n# and qtnew(), dtnew() (from aaltobda)\n\nmu_point_est <- function(data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 14.5\n\n}\nmu_interval <- function(data, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(13.3, 15.7)\n\n}\n```\n:::\n\n\n\nYou can plot the density as below if you implement `mu_pdf` to compute the PDF of the posterior $p(\\mu|y)$ of the average hardness $\\mu$.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmu_pdf <- function(data, x){\n # Compute necessary parameters here.\n # These are the correct parameters for `windshieldy_test`\n # with the provided uninformative prior.\n df = 3\n location = 14.5\n scale = 0.3817557\n # Use the computed parameters as below to compute the PDF:\n\n dtnew(x, df, location, scale)\n}\n\nx_interval = mu_interval(windshieldy1, .999)\nlower_x = x_interval[1]\nupper_x = x_interval[2]\nx = seq(lower_x, upper_x, length.out=1000)\nplot(\n x, mu_pdf(windshieldy1, x), type=\"l\",\n xlab=TeX(r'(average hardness $\\mu$)'),\n ylab=TeX(r'(PDF of the posterior $p(\\mu|y)$)')\n)\n```\n\n::: {.cell-output-display}\n![PDF of the posterior $p(\\mu|y)$ of the average hardness $\\mu$](simple_template3_files/figure-pdf/fig-2b-density-1.pdf){#fig-2b-density fig-pos='H'}\n:::\n:::\n\n\n\n\n\n## (c)\n\n\nWrite your answers and code here!\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum()\n# and qtnew(), dtnew() (from aaltobda)\n\nmu_pred_point_est <- function(data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 14.5\n\n}\nmu_pred_interval <- function(data, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(11.8, 17.2)\n\n}\n```\n:::\n\n\n\nYou can plot the density as below if you implement `mu_pred_pdf` to compute the PDF of the posterior predictive $p(\\tilde{y}|y)$ of a new hardness observation $\\tilde{y}$.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmu_pred_pdf <- function(data, x){\n # Compute necessary parameters here.\n # These are the correct parameters for `windshieldy_test`\n # with the provided uninformative prior.\n df = 3\n location = 14.5\n scale = 0.8536316\n # Use the computed parameters as below to compute the PDF:\n\n dtnew(x, df, location, scale)\n}\n\nx_interval = mu_pred_interval(windshieldy1, .999)\nlower_x = x_interval[1]\nupper_x = x_interval[2]\nx = seq(lower_x, upper_x, length.out=1000)\nplot(\n x, mu_pred_pdf(windshieldy1, x), type=\"l\",\n xlab=TeX(r'(new hardness observation $\\tilde{y}$)'),\n ylab=TeX(r'(PDF of the posterior predictive $p(\\tilde{y}|y)$)')\n)\n```\n\n::: {.cell-output-display}\n![PDF of the posterior predictive $p(\\tilde{y}|y)$ of a new hardness observation $\\tilde{y}$](simple_template3_files/figure-pdf/fig-2c-density-1.pdf){#fig-2c-density fig-pos='H'}\n:::\n:::\n\n\n\n\n# Inference for the difference between proportions (3 points)\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\nThe below data is **only for the tests**:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nset.seed(4711)\nndraws = 1000\np0 = rbeta(ndraws, 5, 95)\np1 = rbeta(ndraws, 10, 90)\n```\n:::\n\n\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: mean(), quantile()\n\nposterior_odds_ratio_point_est <- function(p0, p1) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 2.650172\n\n}\nposterior_odds_ratio_interval <- function(p0, p1, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(0.6796942,7.3015964)\n\n}\n```\n:::\n\n\n\n\n\n\n\n## (c)\n\n\nWrite your answers and code here!\n\n\n# Inference for the difference between normal means (3 points)\n\nLoading the library and the data.\n\n\n::: {.cell}\n\n```{.r .cell-code}\ndata(\"windshieldy2\")\n# The new data are now stored in the variable `windshieldy2`.\n# The below displays the first few rows of the new data:\nhead(windshieldy2)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 15.980 14.206 16.011 17.250 15.993 15.722\n```\n:::\n:::\n\n\n\n\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum(),\n# rtnew() (from aaltobda), quantile() and hist().\n```\n:::\n\n\n\n\n\n## (c)\n\n\nWrite your answers here!\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nv | F W S OK | Context\n\n/ | 0 | task-1-subtask-1-tests \n/ | 0 | mu_point_est() \nx | 1 3 | mu_point_est()\n--------------------------------------------------------------------------------\nFailure ('test-task-1-subtask-1-tests.R:17:3'): mu_point_est()\nmu_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n--------------------------------------------------------------------------------\n\n/ | 0 | task-2-subtask-1-tests \n/ | 0 | mu_interval() \nx | 2 3 | mu_interval()\n--------------------------------------------------------------------------------\nFailure ('test-task-2-subtask-1-tests.R:15:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.95) not equivalent to c(3.3, 7.7).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 3.3 == 10\n[2] 15.7 - 7.7 == 8\nError: Incorrect result for 1:10 using a 95% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:16:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.8) not equivalent to c(4.2, 6.8).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 4.2 == 9.1\n[2] 15.7 - 6.8 == 8.9\nError: Incorrect result for 1:10 using a 80% interval.\n--------------------------------------------------------------------------------\n\n/ | 0 | task-3-subtask-1-tests \n/ | 0 | mu_pred_interval() \nx | 2 3 | mu_pred_interval()\n--------------------------------------------------------------------------------\nFailure ('test-task-3-subtask-1-tests.R:16:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.95) not equivalent to c(-1.7, 12.7).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - -1.7 == 13.5\n[2] 17.2 - 12.7 == 4.5\nError: Incorrect result for 1:10, (95%)\n\nFailure ('test-task-3-subtask-1-tests.R:18:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.8) not equivalent to c(1.1, 9.9).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - 1.1 == 10.7\n[2] 17.2 - 9.9 == 7.3\nError: Incorrect result for 1:10, (80%)\n--------------------------------------------------------------------------------\n\n/ | 0 | task-4-subtask-1-tests \n/ | 0 | mu_pred_point_est() \nx | 1 3 | mu_pred_point_est()\n--------------------------------------------------------------------------------\nFailure ('test-task-4-subtask-1-tests.R:16:3'): mu_pred_point_est()\nmu_pred_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n--------------------------------------------------------------------------------\n\n/ | 0 | task-5-subtask-1-tests \n/ | 0 | posterior_odds_ratio_point_est() \nx | 3 3 | posterior_odds_ratio_point_est()\n--------------------------------------------------------------------------------\nFailure ('test-task-5-subtask-1-tests.R:18:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 0.5307909.\n1/1 mismatches\n[1] 2.65 - 0.531 == 2.12\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90).\n\nFailure ('test-task-5-subtask-1-tests.R:24:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p0, p1) not equivalent to 1.876519.\n1/1 mismatches\n[1] 2.65 - 1.88 == 0.774\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6).\n\nFailure ('test-task-5-subtask-1-tests.R:25:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 1.24902.\n1/1 mismatches\n[1] 2.65 - 1.25 == 1.4\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5).\n--------------------------------------------------------------------------------\n\n/ | 0 | task-6-subtask-1-tests \n/ | 0 | posterior_odds_ratio_interval() \nx | 6 2 | posterior_odds_ratio_interval()\n--------------------------------------------------------------------------------\nFailure ('test-task-6-subtask-1-tests.R:17:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.875367, 6.05911).\n2/2 mismatches (average diff: 0.719)\n[1] 0.68 - 0.875 == -0.196\n[2] 7.30 - 6.059 == 1.242\nError: Incorrect result for p0 = rbeta(100000, 5, 95), p1 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:19:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1650407, 1.142378).\n2/2 mismatches (average diff: 3.34)\n[1] 0.68 - 0.165 == 0.515\n[2] 7.30 - 1.142 == 6.159\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:21:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.2086461, 0.9392956).\n2/2 mismatches (average diff: 3.42)\n[1] 0.68 - 0.209 == 0.471\n[2] 7.30 - 0.939 == 6.362\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 80%.\n\nFailure ('test-task-6-subtask-1-tests.R:27:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.2714472, 5.5970131).\n2/2 mismatches (average diff: 1.06)\n[1] 0.68 - 0.271 == 0.408\n[2] 7.30 - 5.597 == 1.705\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:29:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1786667, 3.6839583).\n2/2 mismatches (average diff: 2.06)\n[1] 0.68 - 0.179 == 0.501\n[2] 7.30 - 3.684 == 3.618\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:31:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.252972, 2.633517).\n2/2 mismatches (average diff: 2.55)\n[1] 0.68 - 0.253 == 0.427\n[2] 7.30 - 2.634 == 4.668\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 80%.\n--------------------------------------------------------------------------------\nMaximum number of failures exceeded; quitting at end of file.\ni Increase this number with (e.g.) `testthat::set_max_fails(Inf)` \n\n== Results =====================================================================\nDuration: 0.5 s\n\n[ FAIL 15 | WARN 0 | SKIP 0 | PASS 17 ]\n== Terminated early ============================================================\n```\n:::\n:::\n\n\n\n:::\n::::\n", "supporting": [ "simple_template3_files/figure-pdf" ], diff --git a/assignments/_freeze/simple_template3/figure-pdf/fig-2b-density-1.pdf b/assignments/_freeze/simple_template3/figure-pdf/fig-2b-density-1.pdf index f9052c12..92d1363d 100644 Binary files a/assignments/_freeze/simple_template3/figure-pdf/fig-2b-density-1.pdf and b/assignments/_freeze/simple_template3/figure-pdf/fig-2b-density-1.pdf differ diff --git a/assignments/_freeze/simple_template3/figure-pdf/fig-2c-density-1.pdf b/assignments/_freeze/simple_template3/figure-pdf/fig-2c-density-1.pdf index 8bf91af9..319b1961 100644 Binary files a/assignments/_freeze/simple_template3/figure-pdf/fig-2c-density-1.pdf and b/assignments/_freeze/simple_template3/figure-pdf/fig-2c-density-1.pdf differ diff --git a/assignments/_freeze/template1/execute-results/html.json b/assignments/_freeze/template1/execute-results/html.json index b758f6ef..e4773bf9 100644 --- a/assignments/_freeze/template1/execute-results/html.json +++ b/assignments/_freeze/template1/execute-results/html.json @@ -1,7 +1,7 @@ { "hash": "0ed9dcbcb2b9d3dd38dd58e0b8aa1a67", "result": { - "markdown": "---\ntitle: \"Assignment 1\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\n\nThis 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.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up `markmyassignment` to check your functions at the end of the notebook:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(markmyassignment)\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment1.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment1: Bayesian Data Analysis: Assignment 1\nThe assignment contain the following (3) tasks:\n- p_red\n- p_box\n- p_identical_twin\n```\n:::\n:::\n\n\n:::\n::::\n\n\n# Basic probability theory notation and terms\n\nWrite your answers here!\n\n\n\n# Basic computer skills\n\nDo some setup here. Explain in text what you do.\n\n::: {.cell}\n\n```{.r .cell-code}\n# Do some setup:\ndistribution_mean = .2\ndistribution_variance = .01\n\n# You have to compute the parameters below from the given mean and variance\n# distribution_alpha = ...\n# distribution_beta = ...\n```\n:::\n\n\n\n\n## (a)\n\n\nPlot the PDF here. Explain in text what you do.\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: seq(), plot() and dbeta()\n```\n:::\n\n\n\n\n## (b)\n\n\nSample and plot the histogram here. Explain in text what you do.\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: rbeta() and hist()\n```\n:::\n\n\n\n\n## (c)\n\n\nCompute the sample mean and variance here. Explain in text what you do.\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean() and var()\n```\n:::\n\n\n\n\n## (d)\n\n\nCompute the central interval here. Explain in text what you do.\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: quantile()\n```\n:::\n\n\n\n# Bayes' theorem 1\n\n## (a)\n\n\nCompute the quantities needed to justify your recommendation here. Explain in text what you do.\nYou can do the computation with pen and paper or in R.\nEither way, you have to explain why you compute what you compute.\n\nIf you use pen and paper, you can include scans or pictures as follows (see also [assignment_instructions#fig-workflow](assignment_instructions#fig-workflow)):\n\n![Parts of Bayesian workflow](additional_files/bayes_workflow.jpg){#fig-workflow width=\"350\"}\n\nSee @fig-workflow for illustration of parts of Bayesian workflow.\n\n\n# Bayes' theorem 2\n\nYou will need to change the numbers to the numbers in the exercise.\n\n::: {.cell}\n\n```{.r .cell-code}\nboxes_test <- matrix(c(2,2,1,5,5,1), ncol = 2,\n dimnames = list(c(\"A\", \"B\", \"C\"), c(\"red\", \"white\")))\n```\n:::\n\n\n\n\n## (a)\n\n\nKeep the below name and format for the function to work with `markmyassignment`:\n\n::: {.cell}\n\n```{.r .cell-code}\np_red <- function(boxes) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 0.3928571\n}\n```\n:::\n\n\n\n\n## (b)\n\n\nKeep the below name and format for the function to work with `markmyassignment`:\n\n::: {.cell}\n\n```{.r .cell-code}\np_box <- function(boxes) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(0.29090909,0.07272727,0.63636364)\n}\n```\n:::\n\n\n\n# Bayes' theorem 3\n\n## (a)\n\n\nYou will need to change the numbers to the numbers in the exercise.\n\n::: {.cell}\n\n```{.r .cell-code}\nfraternal_prob = 1/125\nidentical_prob = 1/300\n```\n:::\n\nKeep the below name and format for the function to work with `markmyassignment`:\n\n::: {.cell}\n\n```{.r .cell-code}\np_identical_twin <- function(fraternal_prob, identical_prob) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 0.4545455\n}\n```\n:::\n\n\n\n# The three steps of Bayesian data analysis\n\n## (a)\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n✔ | F W S OK | Context\n\n⠏ | 0 | task-1-subtask-1-tests \n⠏ | 0 | p_red() \n✖ | 1 3 | p_red() [0.1s]\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-1-subtask-1-tests.R:21:3'): p_red()\np_red(boxes = boxes) not equivalent to 0.5.\n1/1 mismatches\n[1] 0.393 - 0.5 == -0.107\nError: Incorrect result for matrix(c(1,1,1,1,1,1), ncol = 2)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-2-subtask-1-tests \n⠏ | 0 | p_box() \n✖ | 1 3 | p_box()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-2-subtask-1-tests.R:19:3'): p_box()\np_box(boxes = boxes) not equivalent to c(0.4, 0.1, 0.5).\n3/3 mismatches (average diff: 0.0909)\n[1] 0.2909 - 0.4 == -0.1091\n[2] 0.0727 - 0.1 == -0.0273\n[3] 0.6364 - 0.5 == 0.1364\nError: Incorrect result for matrix(c(1,1,1,1,1,1), ncol = 2)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-3-subtask-1-tests \n⠏ | 0 | p_identical_twin() \n✖ | 2 3 | p_identical_twin()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-3-subtask-1-tests.R:16:3'): p_identical_twin()\np_identical_twin(fraternal_prob = 1/100, identical_prob = 1/500) not equivalent to 0.2857143.\n1/1 mismatches\n[1] 0.455 - 0.286 == 0.169\nError: Incorrect result for fraternal_prob = 1/100 and identical_prob = 1/500\n\nFailure ('test-task-3-subtask-1-tests.R:19:3'): p_identical_twin()\np_identical_twin(fraternal_prob = 1/10, identical_prob = 1/20) not equivalent to 0.5.\n1/1 mismatches\n[1] 0.455 - 0.5 == -0.0455\nError: Incorrect result for fraternal_prob = 1/10 and identical_prob = 1/20\n────────────────────────────────────────────────────────────────────────────────\n\n══ Results ═════════════════════════════════════════════════════════════════════\nDuration: 0.2 s\n\n[ FAIL 4 | WARN 0 | SKIP 0 | PASS 9 ]\n```\n:::\n:::\n\n\n:::\n::::\n\n", + "markdown": "---\ntitle: \"Assignment 1\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\n\nThis 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.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up `markmyassignment` to check your functions at the end of the notebook:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(markmyassignment)\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment1.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment1: Bayesian Data Analysis: Assignment 1\nThe assignment contain the following (3) tasks:\n- p_red\n- p_box\n- p_identical_twin\n```\n:::\n:::\n\n\n:::\n::::\n\n\n# Basic probability theory notation and terms\n\nWrite your answers here!\n\n\n\n# Basic computer skills\n\nDo some setup here. Explain in text what you do.\n\n::: {.cell}\n\n```{.r .cell-code}\n# Do some setup:\ndistribution_mean = .2\ndistribution_variance = .01\n\n# You have to compute the parameters below from the given mean and variance\n# distribution_alpha = ...\n# distribution_beta = ...\n```\n:::\n\n\n\n\n## (a)\n\n\nPlot the PDF here. Explain in text what you do.\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: seq(), plot() and dbeta()\n```\n:::\n\n\n\n\n## (b)\n\n\nSample and plot the histogram here. Explain in text what you do.\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: rbeta() and hist()\n```\n:::\n\n\n\n\n## (c)\n\n\nCompute the sample mean and variance here. Explain in text what you do.\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean() and var()\n```\n:::\n\n\n\n\n## (d)\n\n\nCompute the central interval here. Explain in text what you do.\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: quantile()\n```\n:::\n\n\n\n# Bayes' theorem 1\n\n## (a)\n\n\nCompute the quantities needed to justify your recommendation here. Explain in text what you do.\nYou can do the computation with pen and paper or in R.\nEither way, you have to explain why you compute what you compute.\n\nIf you use pen and paper, you can include scans or pictures as follows (see also [assignment_instructions#fig-workflow](assignment_instructions#fig-workflow)):\n\n![Parts of Bayesian workflow](additional_files/bayes_workflow.jpg){#fig-workflow width=\"350\"}\n\nSee @fig-workflow for illustration of parts of Bayesian workflow.\n\n\n# Bayes' theorem 2\n\nYou will need to change the numbers to the numbers in the exercise.\n\n::: {.cell}\n\n```{.r .cell-code}\nboxes_test <- matrix(c(2,2,1,5,5,1), ncol = 2,\n dimnames = list(c(\"A\", \"B\", \"C\"), c(\"red\", \"white\")))\n```\n:::\n\n\n\n\n## (a)\n\n\nKeep the below name and format for the function to work with `markmyassignment`:\n\n::: {.cell}\n\n```{.r .cell-code}\np_red <- function(boxes) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 0.3928571\n}\n```\n:::\n\n\n\n\n## (b)\n\n\nKeep the below name and format for the function to work with `markmyassignment`:\n\n::: {.cell}\n\n```{.r .cell-code}\np_box <- function(boxes) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(0.29090909,0.07272727,0.63636364)\n}\n```\n:::\n\n\n\n# Bayes' theorem 3\n\n## (a)\n\n\nYou will need to change the numbers to the numbers in the exercise.\n\n::: {.cell}\n\n```{.r .cell-code}\nfraternal_prob = 1/125\nidentical_prob = 1/300\n```\n:::\n\nKeep the below name and format for the function to work with `markmyassignment`:\n\n::: {.cell}\n\n```{.r .cell-code}\np_identical_twin <- function(fraternal_prob, identical_prob) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 0.4545455\n}\n```\n:::\n\n\n\n# The three steps of Bayesian data analysis\n\n## (a)\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n✔ | F W S OK | Context\n\n⠏ | 0 | task-1-subtask-1-tests \n⠏ | 0 | p_red() \n✖ | 1 3 | p_red()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-1-subtask-1-tests.R:21:3'): p_red()\np_red(boxes = boxes) not equivalent to 0.5.\n1/1 mismatches\n[1] 0.393 - 0.5 == -0.107\nError: Incorrect result for matrix(c(1,1,1,1,1,1), ncol = 2)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-2-subtask-1-tests \n⠏ | 0 | p_box() \n✖ | 1 3 | p_box()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-2-subtask-1-tests.R:19:3'): p_box()\np_box(boxes = boxes) not equivalent to c(0.4, 0.1, 0.5).\n3/3 mismatches (average diff: 0.0909)\n[1] 0.2909 - 0.4 == -0.1091\n[2] 0.0727 - 0.1 == -0.0273\n[3] 0.6364 - 0.5 == 0.1364\nError: Incorrect result for matrix(c(1,1,1,1,1,1), ncol = 2)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-3-subtask-1-tests \n⠏ | 0 | p_identical_twin() \n✖ | 2 3 | p_identical_twin()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-3-subtask-1-tests.R:16:3'): p_identical_twin()\np_identical_twin(fraternal_prob = 1/100, identical_prob = 1/500) not equivalent to 0.2857143.\n1/1 mismatches\n[1] 0.455 - 0.286 == 0.169\nError: Incorrect result for fraternal_prob = 1/100 and identical_prob = 1/500\n\nFailure ('test-task-3-subtask-1-tests.R:19:3'): p_identical_twin()\np_identical_twin(fraternal_prob = 1/10, identical_prob = 1/20) not equivalent to 0.5.\n1/1 mismatches\n[1] 0.455 - 0.5 == -0.0455\nError: Incorrect result for fraternal_prob = 1/10 and identical_prob = 1/20\n────────────────────────────────────────────────────────────────────────────────\n\n══ Results ═════════════════════════════════════════════════════════════════════\nDuration: 0.2 s\n\n[ FAIL 4 | WARN 0 | SKIP 0 | PASS 9 ]\n```\n:::\n:::\n\n\n:::\n::::\n\n", "supporting": [], "filters": [ "rmarkdown/pagebreak.lua" diff --git a/assignments/_freeze/template1/execute-results/tex.json b/assignments/_freeze/template1/execute-results/tex.json index cc719f7f..3df69222 100644 --- a/assignments/_freeze/template1/execute-results/tex.json +++ b/assignments/_freeze/template1/execute-results/tex.json @@ -1,7 +1,7 @@ { "hash": "0ed9dcbcb2b9d3dd38dd58e0b8aa1a67", "result": { - "markdown": "---\ntitle: \"Assignment 1\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\n\nThis 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.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up `markmyassignment` to check your functions at the end of the notebook:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(markmyassignment)\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment1.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment1: Bayesian Data Analysis: Assignment 1\nThe assignment contain the following (3) tasks:\n- p_red\n- p_box\n- p_identical_twin\n```\n:::\n:::\n\n\n\n:::\n::::\n\n\n# Basic probability theory notation and terms\n\nWrite your answers here!\n\n\n\n# Basic computer skills\n\nDo some setup here. Explain in text what you do.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Do some setup:\ndistribution_mean = .2\ndistribution_variance = .01\n\n# You have to compute the parameters below from the given mean and variance\n# distribution_alpha = ...\n# distribution_beta = ...\n```\n:::\n\n\n\n\n\n## (a)\n\n\nPlot the PDF here. Explain in text what you do.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: seq(), plot() and dbeta()\n```\n:::\n\n\n\n\n\n## (b)\n\n\nSample and plot the histogram here. Explain in text what you do.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: rbeta() and hist()\n```\n:::\n\n\n\n\n\n## (c)\n\n\nCompute the sample mean and variance here. Explain in text what you do.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean() and var()\n```\n:::\n\n\n\n\n\n## (d)\n\n\nCompute the central interval here. Explain in text what you do.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: quantile()\n```\n:::\n\n\n\n\n# Bayes' theorem 1\n\n## (a)\n\n\nCompute the quantities needed to justify your recommendation here. Explain in text what you do.\nYou can do the computation with pen and paper or in R.\nEither way, you have to explain why you compute what you compute.\n\nIf you use pen and paper, you can include scans or pictures as follows (see also [assignment_instructions#fig-workflow](assignment_instructions#fig-workflow)):\n\n![Parts of Bayesian workflow](additional_files/bayes_workflow.jpg){#fig-workflow width=\"350\"}\n\nSee @fig-workflow for illustration of parts of Bayesian workflow.\n\n\n# Bayes' theorem 2\n\nYou will need to change the numbers to the numbers in the exercise.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nboxes_test <- matrix(c(2,2,1,5,5,1), ncol = 2,\n dimnames = list(c(\"A\", \"B\", \"C\"), c(\"red\", \"white\")))\n```\n:::\n\n\n\n\n\n## (a)\n\n\nKeep the below name and format for the function to work with `markmyassignment`:\n\n\n::: {.cell}\n\n```{.r .cell-code}\np_red <- function(boxes) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 0.3928571\n}\n```\n:::\n\n\n\n\n\n## (b)\n\n\nKeep the below name and format for the function to work with `markmyassignment`:\n\n\n::: {.cell}\n\n```{.r .cell-code}\np_box <- function(boxes) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(0.29090909,0.07272727,0.63636364)\n}\n```\n:::\n\n\n\n\n# Bayes' theorem 3\n\n## (a)\n\n\nYou will need to change the numbers to the numbers in the exercise.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nfraternal_prob = 1/125\nidentical_prob = 1/300\n```\n:::\n\n\nKeep the below name and format for the function to work with `markmyassignment`:\n\n\n::: {.cell}\n\n```{.r .cell-code}\np_identical_twin <- function(fraternal_prob, identical_prob) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 0.4545455\n}\n```\n:::\n\n\n\n\n# The three steps of Bayesian data analysis\n\n## (a)\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nv | F W S OK | Context\n\n/ | 0 | task-1-subtask-1-tests \n/ | 0 | p_red() \nx | 1 3 | p_red() [0.1s]\n--------------------------------------------------------------------------------\nFailure ('test-task-1-subtask-1-tests.R:21:3'): p_red()\np_red(boxes = boxes) not equivalent to 0.5.\n1/1 mismatches\n[1] 0.393 - 0.5 == -0.107\nError: Incorrect result for matrix(c(1,1,1,1,1,1), ncol = 2)\n--------------------------------------------------------------------------------\n\n/ | 0 | task-2-subtask-1-tests \n/ | 0 | p_box() \nx | 1 3 | p_box()\n--------------------------------------------------------------------------------\nFailure ('test-task-2-subtask-1-tests.R:19:3'): p_box()\np_box(boxes = boxes) not equivalent to c(0.4, 0.1, 0.5).\n3/3 mismatches (average diff: 0.0909)\n[1] 0.2909 - 0.4 == -0.1091\n[2] 0.0727 - 0.1 == -0.0273\n[3] 0.6364 - 0.5 == 0.1364\nError: Incorrect result for matrix(c(1,1,1,1,1,1), ncol = 2)\n--------------------------------------------------------------------------------\n\n/ | 0 | task-3-subtask-1-tests \n/ | 0 | p_identical_twin() \nx | 2 3 | p_identical_twin()\n--------------------------------------------------------------------------------\nFailure ('test-task-3-subtask-1-tests.R:16:3'): p_identical_twin()\np_identical_twin(fraternal_prob = 1/100, identical_prob = 1/500) not equivalent to 0.2857143.\n1/1 mismatches\n[1] 0.455 - 0.286 == 0.169\nError: Incorrect result for fraternal_prob = 1/100 and identical_prob = 1/500\n\nFailure ('test-task-3-subtask-1-tests.R:19:3'): p_identical_twin()\np_identical_twin(fraternal_prob = 1/10, identical_prob = 1/20) not equivalent to 0.5.\n1/1 mismatches\n[1] 0.455 - 0.5 == -0.0455\nError: Incorrect result for fraternal_prob = 1/10 and identical_prob = 1/20\n--------------------------------------------------------------------------------\n\n== Results =====================================================================\nDuration: 0.2 s\n\n[ FAIL 4 | WARN 0 | SKIP 0 | PASS 9 ]\n```\n:::\n:::\n\n\n\n:::\n::::\n\n", + "markdown": "---\ntitle: \"Assignment 1\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\n\nThis 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.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up `markmyassignment` to check your functions at the end of the notebook:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(markmyassignment)\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment1.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment1: Bayesian Data Analysis: Assignment 1\nThe assignment contain the following (3) tasks:\n- p_red\n- p_box\n- p_identical_twin\n```\n:::\n:::\n\n\n\n:::\n::::\n\n\n# Basic probability theory notation and terms\n\nWrite your answers here!\n\n\n\n# Basic computer skills\n\nDo some setup here. Explain in text what you do.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Do some setup:\ndistribution_mean = .2\ndistribution_variance = .01\n\n# You have to compute the parameters below from the given mean and variance\n# distribution_alpha = ...\n# distribution_beta = ...\n```\n:::\n\n\n\n\n\n## (a)\n\n\nPlot the PDF here. Explain in text what you do.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: seq(), plot() and dbeta()\n```\n:::\n\n\n\n\n\n## (b)\n\n\nSample and plot the histogram here. Explain in text what you do.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: rbeta() and hist()\n```\n:::\n\n\n\n\n\n## (c)\n\n\nCompute the sample mean and variance here. Explain in text what you do.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean() and var()\n```\n:::\n\n\n\n\n\n## (d)\n\n\nCompute the central interval here. Explain in text what you do.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: quantile()\n```\n:::\n\n\n\n\n# Bayes' theorem 1\n\n## (a)\n\n\nCompute the quantities needed to justify your recommendation here. Explain in text what you do.\nYou can do the computation with pen and paper or in R.\nEither way, you have to explain why you compute what you compute.\n\nIf you use pen and paper, you can include scans or pictures as follows (see also [assignment_instructions#fig-workflow](assignment_instructions#fig-workflow)):\n\n![Parts of Bayesian workflow](additional_files/bayes_workflow.jpg){#fig-workflow width=\"350\"}\n\nSee @fig-workflow for illustration of parts of Bayesian workflow.\n\n\n# Bayes' theorem 2\n\nYou will need to change the numbers to the numbers in the exercise.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nboxes_test <- matrix(c(2,2,1,5,5,1), ncol = 2,\n dimnames = list(c(\"A\", \"B\", \"C\"), c(\"red\", \"white\")))\n```\n:::\n\n\n\n\n\n## (a)\n\n\nKeep the below name and format for the function to work with `markmyassignment`:\n\n\n::: {.cell}\n\n```{.r .cell-code}\np_red <- function(boxes) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 0.3928571\n}\n```\n:::\n\n\n\n\n\n## (b)\n\n\nKeep the below name and format for the function to work with `markmyassignment`:\n\n\n::: {.cell}\n\n```{.r .cell-code}\np_box <- function(boxes) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(0.29090909,0.07272727,0.63636364)\n}\n```\n:::\n\n\n\n\n# Bayes' theorem 3\n\n## (a)\n\n\nYou will need to change the numbers to the numbers in the exercise.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nfraternal_prob = 1/125\nidentical_prob = 1/300\n```\n:::\n\n\nKeep the below name and format for the function to work with `markmyassignment`:\n\n\n::: {.cell}\n\n```{.r .cell-code}\np_identical_twin <- function(fraternal_prob, identical_prob) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 0.4545455\n}\n```\n:::\n\n\n\n\n# The three steps of Bayesian data analysis\n\n## (a)\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nv | F W S OK | Context\n\n/ | 0 | task-1-subtask-1-tests \n/ | 0 | p_red() \nx | 1 3 | p_red()\n--------------------------------------------------------------------------------\nFailure ('test-task-1-subtask-1-tests.R:21:3'): p_red()\np_red(boxes = boxes) not equivalent to 0.5.\n1/1 mismatches\n[1] 0.393 - 0.5 == -0.107\nError: Incorrect result for matrix(c(1,1,1,1,1,1), ncol = 2)\n--------------------------------------------------------------------------------\n\n/ | 0 | task-2-subtask-1-tests \n/ | 0 | p_box() \nx | 1 3 | p_box()\n--------------------------------------------------------------------------------\nFailure ('test-task-2-subtask-1-tests.R:19:3'): p_box()\np_box(boxes = boxes) not equivalent to c(0.4, 0.1, 0.5).\n3/3 mismatches (average diff: 0.0909)\n[1] 0.2909 - 0.4 == -0.1091\n[2] 0.0727 - 0.1 == -0.0273\n[3] 0.6364 - 0.5 == 0.1364\nError: Incorrect result for matrix(c(1,1,1,1,1,1), ncol = 2)\n--------------------------------------------------------------------------------\n\n/ | 0 | task-3-subtask-1-tests \n/ | 0 | p_identical_twin() \nx | 2 3 | p_identical_twin()\n--------------------------------------------------------------------------------\nFailure ('test-task-3-subtask-1-tests.R:16:3'): p_identical_twin()\np_identical_twin(fraternal_prob = 1/100, identical_prob = 1/500) not equivalent to 0.2857143.\n1/1 mismatches\n[1] 0.455 - 0.286 == 0.169\nError: Incorrect result for fraternal_prob = 1/100 and identical_prob = 1/500\n\nFailure ('test-task-3-subtask-1-tests.R:19:3'): p_identical_twin()\np_identical_twin(fraternal_prob = 1/10, identical_prob = 1/20) not equivalent to 0.5.\n1/1 mismatches\n[1] 0.455 - 0.5 == -0.0455\nError: Incorrect result for fraternal_prob = 1/10 and identical_prob = 1/20\n--------------------------------------------------------------------------------\n\n== Results =====================================================================\nDuration: 0.2 s\n\n[ FAIL 4 | WARN 0 | SKIP 0 | PASS 9 ]\n```\n:::\n:::\n\n\n\n:::\n::::\n\n", "supporting": [ "template1_files" ], diff --git a/assignments/_freeze/template2/execute-results/html.json b/assignments/_freeze/template2/execute-results/html.json index 0702a402..ad4f54f0 100644 --- a/assignments/_freeze/template2/execute-results/html.json +++ b/assignments/_freeze/template2/execute-results/html.json @@ -1,7 +1,7 @@ { "hash": "cca02202af62bbe0917a6bf499f3179b", "result": { - "markdown": "---\ntitle: \"Assignment 2\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\n include-in-header:\n text: |\n % You can add TeX macros here for PDF,\n % see https://quarto.org/docs/output-formats/pdf-basics.html#latex-includes\n \\newcommand{\\BetaDist}{\\mathrm{Beta}}\neditor: source\n---\n\n\n\n::: {.hidden}\n$$\n% You can add TeX macros here for HTML, see https://quarto.org/docs/authoring/markdown-basics.html#equations\n\\renewcommand{\\BetaDist}{\\mathrm{Beta}}\n$$\n:::\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n\nThis is the template for [assignment 2](assignment2.html). You can download the [qmd-file](https://avehtari.github.io/BDA_course_Aalto/assignments/template2.qmd) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up `markmyassignment` to check your functions at the end of the notebook:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(markmyassignment)\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment2.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment2: Bayesian Data Analysis: Assignment 2\nThe assignment contain the following (3) tasks:\n- beta_point_est\n- beta_interval\n- beta_low\n```\n:::\n:::\n\n\nThe following installs the `aaltobda` package:\n\n::: {.cell hash='template2_cache/html/unnamed-chunk-2_012fb100f304aa0d9ab5552538b6b518'}\n\n```{.r .cell-code}\n# Caching should be fine here\ninstall.packages(\"aaltobda\", repos = c(\"https://avehtari.github.io/BDA_course_Aalto/\", getOption(\"repos\")))\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nInstalling package into '/usr/local/lib/R/site-library'\n(as 'lib' is unspecified)\n```\n:::\n:::\n\n\n:::\n::::\n\n\n# Inference for binomial proportion\n\nLoading the library and the data.\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(aaltobda)\ndata(\"algae\")\n# The data are now stored in the variable `algae`.\n# These are the values for the prior required in the assignment\nprior_alpha = 2\nprior_beta = 10\n```\n:::\n\n\nThe below data is **only for the tests**, you need to change to the\nfull data `algae` when reporting your results.\n\n::: {.cell}\n\n```{.r .cell-code}\nalgae_test <- c(0, 1, 1, 0, 0, 0)\n```\n:::\n\n\n\n\n## (a)\n\n\nWrite the likelihood, the prior and the posterior here!\n\n::: {.cell}\n\n```{.r .cell-code}\n# These are not the actual values for the posterior!\n# You will have to compute those from the data!\nposterior_alpha = 2\nposterior_beta = 10\n```\n:::\n\n\nYou can do [string interpolation](https://en.wikipedia.org/wiki/String_interpolation) using [R inline code execution in quarto](https://quarto.org/docs/computations/execution-options.html#knitr) as such:\n\n$\\alpha_\\text{prior}$ is **2** and $\\beta_\\text{prior}$ is **10**.\nOr string interpolation within math: $\\BetaDist(2,10)$\n\nThis template defines a `\\BetaDist` TeX command which renders `$\\BetaDist(1,2)$` as $\\BetaDist(1,2)$.\n\n\n\n## (b)\n\n\nKeep the below name and format for the functions to work with `markmyassignment`:\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: qbeta()\n\nbeta_point_est <- function(prior_alpha, prior_beta, data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above,\n # combined with the prior provided above.\n 0.2222222\n}\nbeta_interval <- function(prior_alpha, prior_beta, data, prob=0.9) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above,\n # combined with the prior provided above.\n c(0.0846451, 0.3956414)\n}\n```\n:::\n\n\n\n\n## (c)\n\n\nKeep the below name and format for the function to work with `markmyassignment`:\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: pbeta()\n\nbeta_low <- function(prior_alpha, prior_beta, data, pi_0=0.2) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above,\n # combined with the correct prior.\n 0.4511238\n}\n```\n:::\n\n\n\n\n## (d)\n\n\nWrite your answer here!\n\n\n\n## (e)\n\n\nPlot the PDFs here. Explain shortly what you do.\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: dbeta()\n```\n:::\n\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n✔ | F W S OK | Context\n\n⠏ | 0 | task-1-subtask-1-tests \n⠏ | 0 | beta_point_est() \n⠹ | 1 2 | beta_point_est() \n✖ | 3 2 | beta_point_est() [0.1s]\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-1-subtask-1-tests.R:16:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.222 - 0.5 == -0.278\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1)\n\nFailure ('test-task-1-subtask-1-tests.R:23:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.222 - 0.5 == -0.278\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1)\n\nFailure ('test-task-1-subtask-1-tests.R:30:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5555556).\n1/1 mismatches\n[1] 0.222 - 0.556 == -0.333\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-2-subtask-1-tests \n⠏ | 0 | beta_interval() \n✖ | 3 2 | beta_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-2-subtask-1-tests.R:16:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.2712499, 0.7287501).\n2/2 mismatches (average diff: 0.26)\n[1] 0.0846 - 0.271 == -0.187\n[2] 0.3956 - 0.729 == -0.333\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1) and 90% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:23:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.2999865, 0.7000135).\n2/2 mismatches (average diff: 0.26)\n[1] 0.0846 - 0.3 == -0.215\n[2] 0.3956 - 0.7 == -0.304\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1) and 90% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:30:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.3640088, 0.7398856).\n2/2 mismatches (average diff: 0.312)\n[1] 0.0846 - 0.364 == -0.279\n[2] 0.3956 - 0.740 == -0.344\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1) and 90% interval.\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-3-subtask-1-tests \n⠏ | 0 | beta_low() \n✖ | 3 2 | beta_low()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-3-subtask-1-tests.R:16:3'): beta_low()\nbeta_low(...) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.451 - 0.5 == -0.0489\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1)\n\nFailure ('test-task-3-subtask-1-tests.R:23:3'): beta_low()\nbeta_low(...) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.451 - 0.5 == -0.0489\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1)\n\nFailure ('test-task-3-subtask-1-tests.R:30:3'): beta_low()\nbeta_low(...) not equivalent to 0.0004932497.\n1/1 mismatches\n[1] 0.451 - 0.000493 == 0.451\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1)\n────────────────────────────────────────────────────────────────────────────────\n\n══ Results ═════════════════════════════════════════════════════════════════════\nDuration: 0.4 s\n\n[ FAIL 9 | WARN 0 | SKIP 0 | PASS 6 ]\n```\n:::\n:::\n\n\n:::\n::::\n", + "markdown": "---\ntitle: \"Assignment 2\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\n include-in-header:\n text: |\n % You can add TeX macros here for PDF,\n % see https://quarto.org/docs/output-formats/pdf-basics.html#latex-includes\n \\newcommand{\\BetaDist}{\\mathrm{Beta}}\neditor: source\n---\n\n\n\n::: {.hidden}\n$$\n% You can add TeX macros here for HTML, see https://quarto.org/docs/authoring/markdown-basics.html#equations\n\\renewcommand{\\BetaDist}{\\mathrm{Beta}}\n$$\n:::\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n\nThis is the template for [assignment 2](assignment2.html). You can download the [qmd-file](https://avehtari.github.io/BDA_course_Aalto/assignments/template2.qmd) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up `markmyassignment` to check your functions at the end of the notebook:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(markmyassignment)\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment2.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment2: Bayesian Data Analysis: Assignment 2\nThe assignment contain the following (3) tasks:\n- beta_point_est\n- beta_interval\n- beta_low\n```\n:::\n:::\n\n\nThe following installs the `aaltobda` package:\n\n::: {.cell hash='template2_cache/html/unnamed-chunk-2_012fb100f304aa0d9ab5552538b6b518'}\n\n```{.r .cell-code}\n# Caching should be fine here\ninstall.packages(\"aaltobda\", repos = c(\"https://avehtari.github.io/BDA_course_Aalto/\", getOption(\"repos\")))\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nInstalling package into '/usr/local/lib/R/site-library'\n(as 'lib' is unspecified)\n```\n:::\n:::\n\n\n:::\n::::\n\n\n# Inference for binomial proportion\n\nLoading the library and the data.\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(aaltobda)\ndata(\"algae\")\n# The data are now stored in the variable `algae`.\n# These are the values for the prior required in the assignment\nprior_alpha = 2\nprior_beta = 10\n```\n:::\n\n\nThe below data is **only for the tests**, you need to change to the\nfull data `algae` when reporting your results.\n\n::: {.cell}\n\n```{.r .cell-code}\nalgae_test <- c(0, 1, 1, 0, 0, 0)\n```\n:::\n\n\n\n\n## (a)\n\n\nWrite the likelihood, the prior and the posterior here!\n\n::: {.cell}\n\n```{.r .cell-code}\n# These are not the actual values for the posterior!\n# You will have to compute those from the data!\nposterior_alpha = 2\nposterior_beta = 10\n```\n:::\n\n\nYou can do [string interpolation](https://en.wikipedia.org/wiki/String_interpolation) using [R inline code execution in quarto](https://quarto.org/docs/computations/execution-options.html#knitr) as such:\n\n$\\alpha_\\text{prior}$ is **2** and $\\beta_\\text{prior}$ is **10**.\nOr string interpolation within math: $\\BetaDist(2,10)$\n\nThis template defines a `\\BetaDist` TeX command which renders `$\\BetaDist(1,2)$` as $\\BetaDist(1,2)$.\n\n\n\n## (b)\n\n\nKeep the below name and format for the functions to work with `markmyassignment`:\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: qbeta()\n\nbeta_point_est <- function(prior_alpha, prior_beta, data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above,\n # combined with the prior provided above.\n 0.2222222\n}\nbeta_interval <- function(prior_alpha, prior_beta, data, prob=0.9) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above,\n # combined with the prior provided above.\n c(0.0846451, 0.3956414)\n}\n```\n:::\n\n\n\n\n## (c)\n\n\nKeep the below name and format for the function to work with `markmyassignment`:\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: pbeta()\n\nbeta_low <- function(prior_alpha, prior_beta, data, pi_0=0.2) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above,\n # combined with the correct prior.\n 0.4511238\n}\n```\n:::\n\n\n\n\n## (d)\n\n\nWrite your answer here!\n\n\n\n## (e)\n\n\nPlot the PDFs here. Explain shortly what you do.\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: dbeta()\n```\n:::\n\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n✔ | F W S OK | Context\n\n⠏ | 0 | task-1-subtask-1-tests \n⠏ | 0 | beta_point_est() \n✖ | 3 2 | beta_point_est() [0.1s]\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-1-subtask-1-tests.R:16:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.222 - 0.5 == -0.278\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1)\n\nFailure ('test-task-1-subtask-1-tests.R:23:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.222 - 0.5 == -0.278\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1)\n\nFailure ('test-task-1-subtask-1-tests.R:30:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5555556).\n1/1 mismatches\n[1] 0.222 - 0.556 == -0.333\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-2-subtask-1-tests \n⠏ | 0 | beta_interval() \n✖ | 3 2 | beta_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-2-subtask-1-tests.R:16:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.2712499, 0.7287501).\n2/2 mismatches (average diff: 0.26)\n[1] 0.0846 - 0.271 == -0.187\n[2] 0.3956 - 0.729 == -0.333\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1) and 90% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:23:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.2999865, 0.7000135).\n2/2 mismatches (average diff: 0.26)\n[1] 0.0846 - 0.3 == -0.215\n[2] 0.3956 - 0.7 == -0.304\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1) and 90% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:30:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.3640088, 0.7398856).\n2/2 mismatches (average diff: 0.312)\n[1] 0.0846 - 0.364 == -0.279\n[2] 0.3956 - 0.740 == -0.344\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1) and 90% interval.\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-3-subtask-1-tests \n⠏ | 0 | beta_low() \n✖ | 3 2 | beta_low()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-3-subtask-1-tests.R:16:3'): beta_low()\nbeta_low(...) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.451 - 0.5 == -0.0489\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1)\n\nFailure ('test-task-3-subtask-1-tests.R:23:3'): beta_low()\nbeta_low(...) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.451 - 0.5 == -0.0489\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1)\n\nFailure ('test-task-3-subtask-1-tests.R:30:3'): beta_low()\nbeta_low(...) not equivalent to 0.0004932497.\n1/1 mismatches\n[1] 0.451 - 0.000493 == 0.451\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1)\n────────────────────────────────────────────────────────────────────────────────\n\n══ Results ═════════════════════════════════════════════════════════════════════\nDuration: 0.3 s\n\n[ FAIL 9 | WARN 0 | SKIP 0 | PASS 6 ]\n```\n:::\n:::\n\n\n:::\n::::\n", "supporting": [], "filters": [ "rmarkdown/pagebreak.lua" diff --git a/assignments/_freeze/template2/execute-results/tex.json b/assignments/_freeze/template2/execute-results/tex.json index ed72e313..56d5daf0 100644 --- a/assignments/_freeze/template2/execute-results/tex.json +++ b/assignments/_freeze/template2/execute-results/tex.json @@ -1,7 +1,7 @@ { "hash": "cca02202af62bbe0917a6bf499f3179b", "result": { - "markdown": "---\ntitle: \"Assignment 2\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\n include-in-header:\n text: |\n % You can add TeX macros here for PDF,\n % see https://quarto.org/docs/output-formats/pdf-basics.html#latex-includes\n \\newcommand{\\BetaDist}{\\mathrm{Beta}}\neditor: source\n---\n\n\n\n\n::: {.hidden}\n$$\n% You can add TeX macros here for HTML, see https://quarto.org/docs/authoring/markdown-basics.html#equations\n\\renewcommand{\\BetaDist}{\\mathrm{Beta}}\n$$\n:::\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n\nThis is the template for [assignment 2](assignment2.html). You can download the [qmd-file](https://avehtari.github.io/BDA_course_Aalto/assignments/template2.qmd) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up `markmyassignment` to check your functions at the end of the notebook:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(markmyassignment)\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment2.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment2: Bayesian Data Analysis: Assignment 2\nThe assignment contain the following (3) tasks:\n- beta_point_est\n- beta_interval\n- beta_low\n```\n:::\n:::\n\n\n\nThe following installs the `aaltobda` package:\n\n\n::: {.cell hash='template2_cache/pdf/unnamed-chunk-2_39095ceb20f8b095ef973a8844a8881a'}\n\n```{.r .cell-code}\n# Caching should be fine here\ninstall.packages(\"aaltobda\", repos = c(\"https://avehtari.github.io/BDA_course_Aalto/\", getOption(\"repos\")))\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nInstalling package into '/usr/local/lib/R/site-library'\n(as 'lib' is unspecified)\n```\n:::\n:::\n\n\n\n:::\n::::\n\n\n# Inference for binomial proportion\n\nLoading the library and the data.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(aaltobda)\ndata(\"algae\")\n# The data are now stored in the variable `algae`.\n# These are the values for the prior required in the assignment\nprior_alpha = 2\nprior_beta = 10\n```\n:::\n\n\n\nThe below data is **only for the tests**, you need to change to the\nfull data `algae` when reporting your results.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nalgae_test <- c(0, 1, 1, 0, 0, 0)\n```\n:::\n\n\n\n\n\n## (a)\n\n\nWrite the likelihood, the prior and the posterior here!\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# These are not the actual values for the posterior!\n# You will have to compute those from the data!\nposterior_alpha = 2\nposterior_beta = 10\n```\n:::\n\n\n\nYou can do [string interpolation](https://en.wikipedia.org/wiki/String_interpolation) using [R inline code execution in quarto](https://quarto.org/docs/computations/execution-options.html#knitr) as such:\n\n$\\alpha_\\text{prior}$ is **2** and $\\beta_\\text{prior}$ is **10**.\nOr string interpolation within math: $\\BetaDist(2,10)$\n\nThis template defines a `\\BetaDist` TeX command which renders `$\\BetaDist(1,2)$` as $\\BetaDist(1,2)$.\n\n\n\n## (b)\n\n\nKeep the below name and format for the functions to work with `markmyassignment`:\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: qbeta()\n\nbeta_point_est <- function(prior_alpha, prior_beta, data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above,\n # combined with the prior provided above.\n 0.2222222\n}\nbeta_interval <- function(prior_alpha, prior_beta, data, prob=0.9) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above,\n # combined with the prior provided above.\n c(0.0846451, 0.3956414)\n}\n```\n:::\n\n\n\n\n\n## (c)\n\n\nKeep the below name and format for the function to work with `markmyassignment`:\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: pbeta()\n\nbeta_low <- function(prior_alpha, prior_beta, data, pi_0=0.2) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above,\n # combined with the correct prior.\n 0.4511238\n}\n```\n:::\n\n\n\n\n\n## (d)\n\n\nWrite your answer here!\n\n\n\n## (e)\n\n\nPlot the PDFs here. Explain shortly what you do.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: dbeta()\n```\n:::\n\n\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nv | F W S OK | Context\n\n/ | 0 | task-1-subtask-1-tests \n/ | 0 | beta_point_est() \n/ | 2 2 | beta_point_est() \nx | 3 2 | beta_point_est() [0.1s]\n--------------------------------------------------------------------------------\nFailure ('test-task-1-subtask-1-tests.R:16:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.222 - 0.5 == -0.278\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1)\n\nFailure ('test-task-1-subtask-1-tests.R:23:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.222 - 0.5 == -0.278\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1)\n\nFailure ('test-task-1-subtask-1-tests.R:30:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5555556).\n1/1 mismatches\n[1] 0.222 - 0.556 == -0.333\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1)\n--------------------------------------------------------------------------------\n\n/ | 0 | task-2-subtask-1-tests \n/ | 0 | beta_interval() \nx | 3 2 | beta_interval()\n--------------------------------------------------------------------------------\nFailure ('test-task-2-subtask-1-tests.R:16:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.2712499, 0.7287501).\n2/2 mismatches (average diff: 0.26)\n[1] 0.0846 - 0.271 == -0.187\n[2] 0.3956 - 0.729 == -0.333\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1) and 90% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:23:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.2999865, 0.7000135).\n2/2 mismatches (average diff: 0.26)\n[1] 0.0846 - 0.3 == -0.215\n[2] 0.3956 - 0.7 == -0.304\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1) and 90% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:30:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.3640088, 0.7398856).\n2/2 mismatches (average diff: 0.312)\n[1] 0.0846 - 0.364 == -0.279\n[2] 0.3956 - 0.740 == -0.344\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1) and 90% interval.\n--------------------------------------------------------------------------------\n\n/ | 0 | task-3-subtask-1-tests \n/ | 0 | beta_low() \nx | 3 2 | beta_low()\n--------------------------------------------------------------------------------\nFailure ('test-task-3-subtask-1-tests.R:16:3'): beta_low()\nbeta_low(...) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.451 - 0.5 == -0.0489\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1)\n\nFailure ('test-task-3-subtask-1-tests.R:23:3'): beta_low()\nbeta_low(...) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.451 - 0.5 == -0.0489\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1)\n\nFailure ('test-task-3-subtask-1-tests.R:30:3'): beta_low()\nbeta_low(...) not equivalent to 0.0004932497.\n1/1 mismatches\n[1] 0.451 - 0.000493 == 0.451\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1)\n--------------------------------------------------------------------------------\n\n== Results =====================================================================\nDuration: 0.4 s\n\n[ FAIL 9 | WARN 0 | SKIP 0 | PASS 6 ]\n```\n:::\n:::\n\n\n\n:::\n::::\n", + "markdown": "---\ntitle: \"Assignment 2\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\n include-in-header:\n text: |\n % You can add TeX macros here for PDF,\n % see https://quarto.org/docs/output-formats/pdf-basics.html#latex-includes\n \\newcommand{\\BetaDist}{\\mathrm{Beta}}\neditor: source\n---\n\n\n\n\n::: {.hidden}\n$$\n% You can add TeX macros here for HTML, see https://quarto.org/docs/authoring/markdown-basics.html#equations\n\\renewcommand{\\BetaDist}{\\mathrm{Beta}}\n$$\n:::\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n\nThis is the template for [assignment 2](assignment2.html). You can download the [qmd-file](https://avehtari.github.io/BDA_course_Aalto/assignments/template2.qmd) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up `markmyassignment` to check your functions at the end of the notebook:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(markmyassignment)\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment2.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment2: Bayesian Data Analysis: Assignment 2\nThe assignment contain the following (3) tasks:\n- beta_point_est\n- beta_interval\n- beta_low\n```\n:::\n:::\n\n\n\nThe following installs the `aaltobda` package:\n\n\n::: {.cell hash='template2_cache/pdf/unnamed-chunk-2_39095ceb20f8b095ef973a8844a8881a'}\n\n```{.r .cell-code}\n# Caching should be fine here\ninstall.packages(\"aaltobda\", repos = c(\"https://avehtari.github.io/BDA_course_Aalto/\", getOption(\"repos\")))\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nInstalling package into '/usr/local/lib/R/site-library'\n(as 'lib' is unspecified)\n```\n:::\n:::\n\n\n\n:::\n::::\n\n\n# Inference for binomial proportion\n\nLoading the library and the data.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(aaltobda)\ndata(\"algae\")\n# The data are now stored in the variable `algae`.\n# These are the values for the prior required in the assignment\nprior_alpha = 2\nprior_beta = 10\n```\n:::\n\n\n\nThe below data is **only for the tests**, you need to change to the\nfull data `algae` when reporting your results.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nalgae_test <- c(0, 1, 1, 0, 0, 0)\n```\n:::\n\n\n\n\n\n## (a)\n\n\nWrite the likelihood, the prior and the posterior here!\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# These are not the actual values for the posterior!\n# You will have to compute those from the data!\nposterior_alpha = 2\nposterior_beta = 10\n```\n:::\n\n\n\nYou can do [string interpolation](https://en.wikipedia.org/wiki/String_interpolation) using [R inline code execution in quarto](https://quarto.org/docs/computations/execution-options.html#knitr) as such:\n\n$\\alpha_\\text{prior}$ is **2** and $\\beta_\\text{prior}$ is **10**.\nOr string interpolation within math: $\\BetaDist(2,10)$\n\nThis template defines a `\\BetaDist` TeX command which renders `$\\BetaDist(1,2)$` as $\\BetaDist(1,2)$.\n\n\n\n## (b)\n\n\nKeep the below name and format for the functions to work with `markmyassignment`:\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: qbeta()\n\nbeta_point_est <- function(prior_alpha, prior_beta, data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above,\n # combined with the prior provided above.\n 0.2222222\n}\nbeta_interval <- function(prior_alpha, prior_beta, data, prob=0.9) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above,\n # combined with the prior provided above.\n c(0.0846451, 0.3956414)\n}\n```\n:::\n\n\n\n\n\n## (c)\n\n\nKeep the below name and format for the function to work with `markmyassignment`:\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: pbeta()\n\nbeta_low <- function(prior_alpha, prior_beta, data, pi_0=0.2) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above,\n # combined with the correct prior.\n 0.4511238\n}\n```\n:::\n\n\n\n\n\n## (d)\n\n\nWrite your answer here!\n\n\n\n## (e)\n\n\nPlot the PDFs here. Explain shortly what you do.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: dbeta()\n```\n:::\n\n\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nv | F W S OK | Context\n\n/ | 0 | task-1-subtask-1-tests \n/ | 0 | beta_point_est() \nx | 3 2 | beta_point_est() [0.1s]\n--------------------------------------------------------------------------------\nFailure ('test-task-1-subtask-1-tests.R:16:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.222 - 0.5 == -0.278\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1)\n\nFailure ('test-task-1-subtask-1-tests.R:23:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.222 - 0.5 == -0.278\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1)\n\nFailure ('test-task-1-subtask-1-tests.R:30:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5555556).\n1/1 mismatches\n[1] 0.222 - 0.556 == -0.333\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1)\n--------------------------------------------------------------------------------\n\n/ | 0 | task-2-subtask-1-tests \n/ | 0 | beta_interval() \nx | 3 2 | beta_interval()\n--------------------------------------------------------------------------------\nFailure ('test-task-2-subtask-1-tests.R:16:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.2712499, 0.7287501).\n2/2 mismatches (average diff: 0.26)\n[1] 0.0846 - 0.271 == -0.187\n[2] 0.3956 - 0.729 == -0.333\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1) and 90% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:23:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.2999865, 0.7000135).\n2/2 mismatches (average diff: 0.26)\n[1] 0.0846 - 0.3 == -0.215\n[2] 0.3956 - 0.7 == -0.304\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1) and 90% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:30:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.3640088, 0.7398856).\n2/2 mismatches (average diff: 0.312)\n[1] 0.0846 - 0.364 == -0.279\n[2] 0.3956 - 0.740 == -0.344\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1) and 90% interval.\n--------------------------------------------------------------------------------\n\n/ | 0 | task-3-subtask-1-tests \n/ | 0 | beta_low() \nx | 3 2 | beta_low()\n--------------------------------------------------------------------------------\nFailure ('test-task-3-subtask-1-tests.R:16:3'): beta_low()\nbeta_low(...) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.451 - 0.5 == -0.0489\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1)\n\nFailure ('test-task-3-subtask-1-tests.R:23:3'): beta_low()\nbeta_low(...) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.451 - 0.5 == -0.0489\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1)\n\nFailure ('test-task-3-subtask-1-tests.R:30:3'): beta_low()\nbeta_low(...) not equivalent to 0.0004932497.\n1/1 mismatches\n[1] 0.451 - 0.000493 == 0.451\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1)\n--------------------------------------------------------------------------------\n\n== Results =====================================================================\nDuration: 0.3 s\n\n[ FAIL 9 | WARN 0 | SKIP 0 | PASS 6 ]\n```\n:::\n:::\n\n\n\n:::\n::::\n", "supporting": [], "filters": [ "rmarkdown/pagebreak.lua" diff --git a/assignments/_freeze/template3/execute-results/html.json b/assignments/_freeze/template3/execute-results/html.json index 3e92b5ee..b9e8250c 100644 --- a/assignments/_freeze/template3/execute-results/html.json +++ b/assignments/_freeze/template3/execute-results/html.json @@ -1,7 +1,7 @@ { "hash": "bdbdb6131717ff0ff6e430a21e4e98aa", "result": { - "markdown": "---\ntitle: \"Assignment 3\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n page-layout: article\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n\nThis is the template for [assignment 3](assignment3.html). You can download the qmd-files ([full](https://avehtari.github.io/BDA_course_Aalto/assignments/template3.qmd), [simple](https://avehtari.github.io/BDA_course_Aalto/assignments/simple_template3.qmd)) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up [`markmyassignment`](https://github.com/MansMeg/markmyassignment) to check your functions at the end of the notebook:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(markmyassignment)){\n install.packages(\"markmyassignment\")\n library(markmyassignment)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: markmyassignment\n```\n:::\n\n```{.r .cell-code}\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment3.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment3: Bayesian Data Analysis: Assignment 3\nThe assignment contain the following (6) tasks:\n- mu_point_est\n- mu_interval\n- mu_pred_interval\n- mu_pred_point_est\n- posterior_odds_ratio_point_est\n- posterior_odds_ratio_interval\n```\n:::\n:::\n\n\nThe following installs and loads the `aaltobda` package:\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(aaltobda)){\n install.packages(\"aaltobda\", repos = c(\"https://avehtari.github.io/BDA_course_Aalto/\", getOption(\"repos\")))\n library(aaltobda)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: aaltobda\n```\n:::\n:::\n\nThe following installs and loads the [`latex2exp` package](https://github.com/stefano-meschiari/latex2exp), which allows us to use LaTeX in plots:\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(latex2exp)){\n install.packages(\"latex2exp\")\n library(latex2exp)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: latex2exp\n```\n:::\n:::\n\n\n:::\n::::\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-tip collapse=false}\n\n## Showcase: Setting up advanced packages (`posterior` and `ggdist`)\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n*This block showcases advanced tools, which you will be allowed and expected to use after this assignment.*\n**For now, you should solve the assignment without the tools showcased herein.**\n\n\n\n\nThe following installs and loads the [`posterior` package](https://mc-stan.org/posterior/index.html),\nwhich allows us to use its [`rvar` Random Variable Datatype\n](https://mc-stan.org/posterior/articles/rvar.html):\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(posterior)){\n install.packages(\"posterior\")\n library(posterior)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: posterior\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThis is posterior version 1.4.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n\nAttaching package: 'posterior'\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following object is masked from 'package:aaltobda':\n\n mcse_quantile\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:stats':\n\n mad, sd, var\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:base':\n\n %in%, match\n```\n:::\n:::\n\n\nThe following installs and loads the [`ggdist` package](https://mjskay.github.io/ggdist/)\nfor advanced plotting functions:\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(ggplot2)){\n install.packages(\"ggplot2\")\n library(ggplot2)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: ggplot2\n```\n:::\n\n```{.r .cell-code}\nggplot2::theme_set(theme_minimal(base_size = 14))\nif(!require(ggdist)){\n install.packages(\"ggdist\")\n library(ggdist)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: ggdist\n```\n:::\n:::\n\n\n\n\n*This block showcases advanced tools, which you will be allowed and expected to use after this assignment.*\n**For now, you should solve the assignment without the tools showcased herein.**\n\n\n\n:::\n::::\n\n\n# Inference for normal mean and deviation (3 points)\n\nLoading the library and the data.\n\n::: {.cell}\n\n```{.r .cell-code}\ndata(\"windshieldy1\")\n# The data are now stored in the variable `windshieldy1`.\n# The below displays the data:\nwindshieldy1\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 13.357 14.928 14.896 15.297 14.820 12.067 14.824 13.865 17.447\n```\n:::\n:::\n\nThe below data is **only for the tests**, you need to change to the\nfull data `windshieldy1` when reporting your results.\n\n::: {.cell}\n\n```{.r .cell-code}\nwindshieldy_test <- c(13.357, 14.928, 14.896, 14.820)\n```\n:::\n\n\n\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum()\n# and qtnew(), dtnew() (from aaltobda)\n\nmu_point_est <- function(data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 14.5\n\n}\nmu_interval <- function(data, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(13.3, 15.7)\n\n}\n```\n:::\n\n\nYou can plot the density as below if you implement `mu_pdf` to compute the PDF of the posterior $p(\\mu|y)$ of the average hardness $\\mu$.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmu_pdf <- function(data, x){\n # Compute necessary parameters here.\n # These are the correct parameters for `windshieldy_test`\n # with the provided uninformative prior.\n df = 3\n location = 14.5\n scale = 0.3817557\n # Use the computed parameters as below to compute the PDF:\n\n dtnew(x, df, location, scale)\n}\n\nx_interval = mu_interval(windshieldy1, .999)\nlower_x = x_interval[1]\nupper_x = x_interval[2]\nx = seq(lower_x, upper_x, length.out=1000)\nplot(\n x, mu_pdf(windshieldy1, x), type=\"l\",\n xlab=TeX(r'(average hardness $\\mu$)'),\n ylab=TeX(r'(PDF of the posterior $p(\\mu|y)$)')\n)\n```\n\n::: {.cell-output-display}\n![PDF of the posterior $p(\\mu|y)$ of the average hardness $\\mu$](template3_files/figure-html/fig-2b-density-1.png){#fig-2b-density width=672}\n:::\n:::\n\n\n\n\n## (c)\n\n\nWrite your answers and code here!\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum()\n# and qtnew(), dtnew() (from aaltobda)\n\nmu_pred_point_est <- function(data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 14.5\n\n}\nmu_pred_interval <- function(data, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(11.8, 17.2)\n\n}\n```\n:::\n\n\nYou can plot the density as below if you implement `mu_pred_pdf` to compute the PDF of the posterior predictive $p(\\tilde{y}|y)$ of a new hardness observation $\\tilde{y}$.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmu_pred_pdf <- function(data, x){\n # Compute necessary parameters here.\n # These are the correct parameters for `windshieldy_test`\n # with the provided uninformative prior.\n df = 3\n location = 14.5\n scale = 0.8536316\n # Use the computed parameters as below to compute the PDF:\n\n dtnew(x, df, location, scale)\n}\n\nx_interval = mu_pred_interval(windshieldy1, .999)\nlower_x = x_interval[1]\nupper_x = x_interval[2]\nx = seq(lower_x, upper_x, length.out=1000)\nplot(\n x, mu_pred_pdf(windshieldy1, x), type=\"l\",\n xlab=TeX(r'(new hardness observation $\\tilde{y}$)'),\n ylab=TeX(r'(PDF of the posterior predictive $p(\\tilde{y}|y)$)')\n)\n```\n\n::: {.cell-output-display}\n![PDF of the posterior predictive $p(\\tilde{y}|y)$ of a new hardness observation $\\tilde{y}$](template3_files/figure-html/fig-2c-density-1.png){#fig-2c-density width=672}\n:::\n:::\n\n\n\n# Inference for the difference between proportions (3 points)\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\nThe below data is **only for the tests**:\n\n::: {.cell}\n\n```{.r .cell-code}\nset.seed(4711)\nndraws = 1000\np0 = rbeta(ndraws, 5, 95)\np1 = rbeta(ndraws, 10, 90)\n```\n:::\n\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: mean(), quantile()\n\nposterior_odds_ratio_point_est <- function(p0, p1) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 2.650172\n\n}\nposterior_odds_ratio_interval <- function(p0, p1, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(0.6796942,7.3015964)\n\n}\n```\n:::\n\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-tip collapse=false}\n\n## Showcase: advanced tools (`posterior`'s `rvar`, `ggdist`'s `stat_dotsinterval`)\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n*This block showcases advanced tools, which you will be allowed and expected to use after this assignment.*\n**For now, you should solve the assignment without the tools showcased herein.**\n\n\n\n\nThe `posterior` package's random variable datatype `rvar` is a\n[\"sample-based representation of random variables\"](https://mc-stan.org/posterior/articles/rvar.html#:~:text=sample%2Dbased%20representation%20of%20random%20variables)\nwhich makes handling of random samples (of draws) such as the ones contained in the above variables `p0` and `p1` easier.\n[By default, it prints as the mean and standard deviation of the draws](https://mc-stan.org/posterior/articles/rvar.html#:~:text=The%20default%20display%20of%20an%20rvar%20shows%20the%20mean%20and%20standard%20deviation%20of%20each%20element%20of%20the%20array.), **such that `rvar(p0)` prints as 0.05 ± 0.021 and `rvar(p1)` prints as 0.1 ± 0.029**.\n\nThe datatype is [\"designed to [...] be able to be used inside `data.frame()`s and `tibble()`s, and to be used with distribution visualizations in the ggdist package.\"](https://mc-stan.org/posterior/articles/rvar.html#:~:text=designed%20to%20interoperate%20with%20vectorized%20distributions%20in%20the%20distributional%20package%2C%20to%20be%20able%20to%20be%20used%20inside%20data.frame()s%20and%20tibble()s%2C%20and%20to%20be%20used%20with%20distribution%20visualizations%20in%20the%20ggdist%20package.)\nThe code below sets up an [R `data.frame()`](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/data.frame) with the draws in `p0` and `p1` wrapped in an `rvar`, and uses that data frame to visualize the draws using [`ggdist`](https://mjskay.github.io/ggdist/index.html), an R package building on [`ggplot2`](https://ggplot2.tidyverse.org/) and [\"designed for both frequentist and Bayesian uncertainty visualization\"](https://mjskay.github.io/ggdist/index.html#:~:text=designed%20for%20both%20frequentist%20and%20Bayesian%20uncertainty%20visualization).\n\nThe below plot, @fig-showcase-probabilities uses `ggdist`'s [`stat_dotsinterval()`](https://mjskay.github.io/ggdist/articles/dotsinterval.html), which by default visualizes\n\n* [an `rvar`'s median and central 66% and 95% intervals](https://mjskay.github.io/ggdist/reference/stat_dotsinterval.html#:~:text=point_interval%20%3D%20%22median_qi%22%2C%0A%20%20.width%20%3D%20c(0.66%2C%200.95)%2C) using a black dot and lines of varying thicknesses as when using `ggdist`'s [`stat_pointinterval()`](https://mjskay.github.io/ggdist/reference/stat_pointinterval.html#examples) and\n* an `rvar`'s draws using grey dots as when using `ggdist`'s [`stat_dots()`](https://mjskay.github.io/ggdist/reference/stat_dots.html#examples):\n\n\n::: {.cell}\n\n```{.r .cell-code}\nr0 = rvar(p0)\nr1 = rvar(p1)\nggplot(data.frame(\n rv_name=c(\"control\", \"treatment\"), rv=c(r0, r1)\n)) +\n aes(xdist=rv, y=rv_name) +\n labs(x=\"probabilities of death\", y=\"patient group\") +\n stat_dotsinterval()\n```\n\n::: {.cell-output-display}\n![Probabilities of death for the two patient groups.](template3_files/figure-html/fig-showcase-probabilities-1.png){#fig-showcase-probabilities width=672}\n:::\n:::\n\n\n`rvar`s make it easy to compute functions of random variables, such as\n\n* differences, e.g. $p_0 - p_1$: `r0 - r1` computes an `rvar` which prints as -0.05 ± 0.037, indicating the **sample mean** and the **sample standard deviation** of the difference of the probabilities of death,\n* products, e.g. $p_0 \\, p_1$: `r0 * r1` computes an `rvar` which prints as 0.005 ± 0.0026 which in this case\nhas no great interpretation, or\n* the odds ratios needed in task 3.b).\n\nBelow, in @fig-showcase-odds-ratios, we compute the odds ratios using the `rvar`s and visualize its median, central intervals and draws, as above in @fig-showcase-probabilities:\n\n::: {.cell}\n\n```{.r .cell-code}\nrodds_ratio = (r1/(1-r1))/(r0/(1-r0))\nggplot(data.frame(\n rv=c(rodds_ratio)\n)) +\n aes(xdist=rv) +\n labs(x=\"odds ratio\", y=\"relative amount of draws\") +\n stat_dotsinterval()\n```\n\n::: {.cell-output-display}\n![Odds ratios of the two patient groups.](template3_files/figure-html/fig-showcase-odds-ratios-1.png){#fig-showcase-odds-ratios width=672}\n:::\n:::\n\n\nYou can use @fig-showcase-odds-ratios to visually check whether the answers you computed for 3.b) make sense.\n\n\n\n*This block showcases advanced tools, which you will be allowed and expected to use after this assignment.*\n**For now, you should solve the assignment without the tools showcased herein.**\n\n\n\n:::\n::::\n\n\n\n## (c)\n\n\nWrite your answers and code here!\n\n\n# Inference for the difference between normal means (3 points)\n\nLoading the library and the data.\n\n::: {.cell}\n\n```{.r .cell-code}\ndata(\"windshieldy2\")\n# The new data are now stored in the variable `windshieldy2`.\n# The below displays the first few rows of the new data:\nhead(windshieldy2)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 15.980 14.206 16.011 17.250 15.993 15.722\n```\n:::\n:::\n\n\n\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum(),\n# rtnew() (from aaltobda), quantile() and hist().\n```\n:::\n\n\n\n\n## (c)\n\n\nWrite your answers here!\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n✔ | F W S OK | Context\n\n⠏ | 0 | task-1-subtask-1-tests \n⠏ | 0 | mu_point_est() \n✖ | 1 3 | mu_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-1-subtask-1-tests.R:17:3'): mu_point_est()\nmu_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-2-subtask-1-tests \n⠏ | 0 | mu_interval() \n✖ | 2 3 | mu_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-2-subtask-1-tests.R:15:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.95) not equivalent to c(3.3, 7.7).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 3.3 == 10\n[2] 15.7 - 7.7 == 8\nError: Incorrect result for 1:10 using a 95% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:16:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.8) not equivalent to c(4.2, 6.8).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 4.2 == 9.1\n[2] 15.7 - 6.8 == 8.9\nError: Incorrect result for 1:10 using a 80% interval.\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-3-subtask-1-tests \n⠏ | 0 | mu_pred_interval() \n✖ | 2 3 | mu_pred_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-3-subtask-1-tests.R:16:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.95) not equivalent to c(-1.7, 12.7).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - -1.7 == 13.5\n[2] 17.2 - 12.7 == 4.5\nError: Incorrect result for 1:10, (95%)\n\nFailure ('test-task-3-subtask-1-tests.R:18:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.8) not equivalent to c(1.1, 9.9).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - 1.1 == 10.7\n[2] 17.2 - 9.9 == 7.3\nError: Incorrect result for 1:10, (80%)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-4-subtask-1-tests \n⠏ | 0 | mu_pred_point_est() \n✖ | 1 3 | mu_pred_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-4-subtask-1-tests.R:16:3'): mu_pred_point_est()\nmu_pred_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-5-subtask-1-tests \n⠏ | 0 | posterior_odds_ratio_point_est() \n✖ | 3 3 | posterior_odds_ratio_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-5-subtask-1-tests.R:18:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 0.5307909.\n1/1 mismatches\n[1] 2.65 - 0.531 == 2.12\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90).\n\nFailure ('test-task-5-subtask-1-tests.R:24:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p0, p1) not equivalent to 1.876519.\n1/1 mismatches\n[1] 2.65 - 1.88 == 0.774\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6).\n\nFailure ('test-task-5-subtask-1-tests.R:25:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 1.24902.\n1/1 mismatches\n[1] 2.65 - 1.25 == 1.4\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5).\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-6-subtask-1-tests \n⠏ | 0 | posterior_odds_ratio_interval() \n⠧ | 6 2 | posterior_odds_ratio_interval() \n✖ | 6 2 | posterior_odds_ratio_interval() [0.1s]\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-6-subtask-1-tests.R:17:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.875367, 6.05911).\n2/2 mismatches (average diff: 0.719)\n[1] 0.68 - 0.875 == -0.196\n[2] 7.30 - 6.059 == 1.242\nError: Incorrect result for p0 = rbeta(100000, 5, 95), p1 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:19:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1650407, 1.142378).\n2/2 mismatches (average diff: 3.34)\n[1] 0.68 - 0.165 == 0.515\n[2] 7.30 - 1.142 == 6.159\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:21:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.2086461, 0.9392956).\n2/2 mismatches (average diff: 3.42)\n[1] 0.68 - 0.209 == 0.471\n[2] 7.30 - 0.939 == 6.362\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 80%.\n\nFailure ('test-task-6-subtask-1-tests.R:27:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.2714472, 5.5970131).\n2/2 mismatches (average diff: 1.06)\n[1] 0.68 - 0.271 == 0.408\n[2] 7.30 - 5.597 == 1.705\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:29:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1786667, 3.6839583).\n2/2 mismatches (average diff: 2.06)\n[1] 0.68 - 0.179 == 0.501\n[2] 7.30 - 3.684 == 3.618\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:31:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.252972, 2.633517).\n2/2 mismatches (average diff: 2.55)\n[1] 0.68 - 0.253 == 0.427\n[2] 7.30 - 2.634 == 4.668\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 80%.\n────────────────────────────────────────────────────────────────────────────────\nMaximum number of failures exceeded; quitting at end of file.\nℹ Increase this number with (e.g.) `testthat::set_max_fails(Inf)` \n\n══ Results ═════════════════════════════════════════════════════════════════════\nDuration: 0.6 s\n\n[ FAIL 15 | WARN 0 | SKIP 0 | PASS 17 ]\n══ Terminated early ════════════════════════════════════════════════════════════\n```\n:::\n:::\n\n\n:::\n::::\n", + "markdown": "---\ntitle: \"Assignment 3\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n page-layout: article\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n\nThis is the template for [assignment 3](assignment3.html). You can download the qmd-files ([full](https://avehtari.github.io/BDA_course_Aalto/assignments/template3.qmd), [simple](https://avehtari.github.io/BDA_course_Aalto/assignments/simple_template3.qmd)) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up [`markmyassignment`](https://github.com/MansMeg/markmyassignment) to check your functions at the end of the notebook:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(markmyassignment)){\n install.packages(\"markmyassignment\")\n library(markmyassignment)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: markmyassignment\n```\n:::\n\n```{.r .cell-code}\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment3.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment3: Bayesian Data Analysis: Assignment 3\nThe assignment contain the following (6) tasks:\n- mu_point_est\n- mu_interval\n- mu_pred_interval\n- mu_pred_point_est\n- posterior_odds_ratio_point_est\n- posterior_odds_ratio_interval\n```\n:::\n:::\n\n\nThe following installs and loads the `aaltobda` package:\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(aaltobda)){\n install.packages(\"aaltobda\", repos = c(\"https://avehtari.github.io/BDA_course_Aalto/\", getOption(\"repos\")))\n library(aaltobda)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: aaltobda\n```\n:::\n:::\n\nThe following installs and loads the [`latex2exp` package](https://github.com/stefano-meschiari/latex2exp), which allows us to use LaTeX in plots:\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(latex2exp)){\n install.packages(\"latex2exp\")\n library(latex2exp)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: latex2exp\n```\n:::\n:::\n\n\n:::\n::::\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-tip collapse=false}\n\n## Showcase: Setting up advanced packages (`posterior` and `ggdist`)\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n*This block showcases advanced tools, which you will be allowed and expected to use after this assignment.*\n**For now, you should solve the assignment without the tools showcased herein.**\n\n\n\n\nThe following installs and loads the [`posterior` package](https://mc-stan.org/posterior/index.html),\nwhich allows us to use its [`rvar` Random Variable Datatype\n](https://mc-stan.org/posterior/articles/rvar.html):\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(posterior)){\n install.packages(\"posterior\")\n library(posterior)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: posterior\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThis is posterior version 1.4.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n\nAttaching package: 'posterior'\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following object is masked from 'package:aaltobda':\n\n mcse_quantile\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:stats':\n\n mad, sd, var\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:base':\n\n %in%, match\n```\n:::\n:::\n\n\nThe following installs and loads the [`ggdist` package](https://mjskay.github.io/ggdist/)\nfor advanced plotting functions:\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(ggplot2)){\n install.packages(\"ggplot2\")\n library(ggplot2)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: ggplot2\n```\n:::\n\n```{.r .cell-code}\nggplot2::theme_set(theme_minimal(base_size = 14))\nif(!require(ggdist)){\n install.packages(\"ggdist\")\n library(ggdist)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: ggdist\n```\n:::\n:::\n\n\n\n\n*This block showcases advanced tools, which you will be allowed and expected to use after this assignment.*\n**For now, you should solve the assignment without the tools showcased herein.**\n\n\n\n:::\n::::\n\n\n# Inference for normal mean and deviation (3 points)\n\nLoading the library and the data.\n\n::: {.cell}\n\n```{.r .cell-code}\ndata(\"windshieldy1\")\n# The data are now stored in the variable `windshieldy1`.\n# The below displays the data:\nwindshieldy1\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 13.357 14.928 14.896 15.297 14.820 12.067 14.824 13.865 17.447\n```\n:::\n:::\n\nThe below data is **only for the tests**, you need to change to the\nfull data `windshieldy1` when reporting your results.\n\n::: {.cell}\n\n```{.r .cell-code}\nwindshieldy_test <- c(13.357, 14.928, 14.896, 14.820)\n```\n:::\n\n\n\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum()\n# and qtnew(), dtnew() (from aaltobda)\n\nmu_point_est <- function(data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 14.5\n\n}\nmu_interval <- function(data, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(13.3, 15.7)\n\n}\n```\n:::\n\n\nYou can plot the density as below if you implement `mu_pdf` to compute the PDF of the posterior $p(\\mu|y)$ of the average hardness $\\mu$.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmu_pdf <- function(data, x){\n # Compute necessary parameters here.\n # These are the correct parameters for `windshieldy_test`\n # with the provided uninformative prior.\n df = 3\n location = 14.5\n scale = 0.3817557\n # Use the computed parameters as below to compute the PDF:\n\n dtnew(x, df, location, scale)\n}\n\nx_interval = mu_interval(windshieldy1, .999)\nlower_x = x_interval[1]\nupper_x = x_interval[2]\nx = seq(lower_x, upper_x, length.out=1000)\nplot(\n x, mu_pdf(windshieldy1, x), type=\"l\",\n xlab=TeX(r'(average hardness $\\mu$)'),\n ylab=TeX(r'(PDF of the posterior $p(\\mu|y)$)')\n)\n```\n\n::: {.cell-output-display}\n![PDF of the posterior $p(\\mu|y)$ of the average hardness $\\mu$](template3_files/figure-html/fig-2b-density-1.png){#fig-2b-density width=672}\n:::\n:::\n\n\n\n\n## (c)\n\n\nWrite your answers and code here!\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum()\n# and qtnew(), dtnew() (from aaltobda)\n\nmu_pred_point_est <- function(data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 14.5\n\n}\nmu_pred_interval <- function(data, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(11.8, 17.2)\n\n}\n```\n:::\n\n\nYou can plot the density as below if you implement `mu_pred_pdf` to compute the PDF of the posterior predictive $p(\\tilde{y}|y)$ of a new hardness observation $\\tilde{y}$.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmu_pred_pdf <- function(data, x){\n # Compute necessary parameters here.\n # These are the correct parameters for `windshieldy_test`\n # with the provided uninformative prior.\n df = 3\n location = 14.5\n scale = 0.8536316\n # Use the computed parameters as below to compute the PDF:\n\n dtnew(x, df, location, scale)\n}\n\nx_interval = mu_pred_interval(windshieldy1, .999)\nlower_x = x_interval[1]\nupper_x = x_interval[2]\nx = seq(lower_x, upper_x, length.out=1000)\nplot(\n x, mu_pred_pdf(windshieldy1, x), type=\"l\",\n xlab=TeX(r'(new hardness observation $\\tilde{y}$)'),\n ylab=TeX(r'(PDF of the posterior predictive $p(\\tilde{y}|y)$)')\n)\n```\n\n::: {.cell-output-display}\n![PDF of the posterior predictive $p(\\tilde{y}|y)$ of a new hardness observation $\\tilde{y}$](template3_files/figure-html/fig-2c-density-1.png){#fig-2c-density width=672}\n:::\n:::\n\n\n\n# Inference for the difference between proportions (3 points)\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\nThe below data is **only for the tests**:\n\n::: {.cell}\n\n```{.r .cell-code}\nset.seed(4711)\nndraws = 1000\np0 = rbeta(ndraws, 5, 95)\np1 = rbeta(ndraws, 10, 90)\n```\n:::\n\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: mean(), quantile()\n\nposterior_odds_ratio_point_est <- function(p0, p1) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 2.650172\n\n}\nposterior_odds_ratio_interval <- function(p0, p1, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(0.6796942,7.3015964)\n\n}\n```\n:::\n\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-tip collapse=false}\n\n## Showcase: advanced tools (`posterior`'s `rvar`, `ggdist`'s `stat_dotsinterval`)\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n*This block showcases advanced tools, which you will be allowed and expected to use after this assignment.*\n**For now, you should solve the assignment without the tools showcased herein.**\n\n\n\n\nThe `posterior` package's random variable datatype `rvar` is a\n[\"sample-based representation of random variables\"](https://mc-stan.org/posterior/articles/rvar.html#:~:text=sample%2Dbased%20representation%20of%20random%20variables)\nwhich makes handling of random samples (of draws) such as the ones contained in the above variables `p0` and `p1` easier.\n[By default, it prints as the mean and standard deviation of the draws](https://mc-stan.org/posterior/articles/rvar.html#:~:text=The%20default%20display%20of%20an%20rvar%20shows%20the%20mean%20and%20standard%20deviation%20of%20each%20element%20of%20the%20array.), **such that `rvar(p0)` prints as 0.05 ± 0.021 and `rvar(p1)` prints as 0.1 ± 0.029**.\n\nThe datatype is [\"designed to [...] be able to be used inside `data.frame()`s and `tibble()`s, and to be used with distribution visualizations in the ggdist package.\"](https://mc-stan.org/posterior/articles/rvar.html#:~:text=designed%20to%20interoperate%20with%20vectorized%20distributions%20in%20the%20distributional%20package%2C%20to%20be%20able%20to%20be%20used%20inside%20data.frame()s%20and%20tibble()s%2C%20and%20to%20be%20used%20with%20distribution%20visualizations%20in%20the%20ggdist%20package.)\nThe code below sets up an [R `data.frame()`](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/data.frame) with the draws in `p0` and `p1` wrapped in an `rvar`, and uses that data frame to visualize the draws using [`ggdist`](https://mjskay.github.io/ggdist/index.html), an R package building on [`ggplot2`](https://ggplot2.tidyverse.org/) and [\"designed for both frequentist and Bayesian uncertainty visualization\"](https://mjskay.github.io/ggdist/index.html#:~:text=designed%20for%20both%20frequentist%20and%20Bayesian%20uncertainty%20visualization).\n\nThe below plot, @fig-showcase-probabilities uses `ggdist`'s [`stat_dotsinterval()`](https://mjskay.github.io/ggdist/articles/dotsinterval.html), which by default visualizes\n\n* [an `rvar`'s median and central 66% and 95% intervals](https://mjskay.github.io/ggdist/reference/stat_dotsinterval.html#:~:text=point_interval%20%3D%20%22median_qi%22%2C%0A%20%20.width%20%3D%20c(0.66%2C%200.95)%2C) using a black dot and lines of varying thicknesses as when using `ggdist`'s [`stat_pointinterval()`](https://mjskay.github.io/ggdist/reference/stat_pointinterval.html#examples) and\n* an `rvar`'s draws using grey dots as when using `ggdist`'s [`stat_dots()`](https://mjskay.github.io/ggdist/reference/stat_dots.html#examples):\n\n\n::: {.cell}\n\n```{.r .cell-code}\nr0 = rvar(p0)\nr1 = rvar(p1)\nggplot(data.frame(\n rv_name=c(\"control\", \"treatment\"), rv=c(r0, r1)\n)) +\n aes(xdist=rv, y=rv_name) +\n labs(x=\"probabilities of death\", y=\"patient group\") +\n stat_dotsinterval()\n```\n\n::: {.cell-output-display}\n![Probabilities of death for the two patient groups.](template3_files/figure-html/fig-showcase-probabilities-1.png){#fig-showcase-probabilities width=672}\n:::\n:::\n\n\n`rvar`s make it easy to compute functions of random variables, such as\n\n* differences, e.g. $p_0 - p_1$: `r0 - r1` computes an `rvar` which prints as -0.05 ± 0.037, indicating the **sample mean** and the **sample standard deviation** of the difference of the probabilities of death,\n* products, e.g. $p_0 \\, p_1$: `r0 * r1` computes an `rvar` which prints as 0.005 ± 0.0026 which in this case\nhas no great interpretation, or\n* the odds ratios needed in task 3.b).\n\nBelow, in @fig-showcase-odds-ratios, we compute the odds ratios using the `rvar`s and visualize its median, central intervals and draws, as above in @fig-showcase-probabilities:\n\n::: {.cell}\n\n```{.r .cell-code}\nrodds_ratio = (r1/(1-r1))/(r0/(1-r0))\nggplot(data.frame(\n rv=c(rodds_ratio)\n)) +\n aes(xdist=rv) +\n labs(x=\"odds ratio\", y=\"relative amount of draws\") +\n stat_dotsinterval()\n```\n\n::: {.cell-output-display}\n![Odds ratios of the two patient groups.](template3_files/figure-html/fig-showcase-odds-ratios-1.png){#fig-showcase-odds-ratios width=672}\n:::\n:::\n\n\nYou can use @fig-showcase-odds-ratios to visually check whether the answers you computed for 3.b) make sense.\n\n\n\n*This block showcases advanced tools, which you will be allowed and expected to use after this assignment.*\n**For now, you should solve the assignment without the tools showcased herein.**\n\n\n\n:::\n::::\n\n\n\n## (c)\n\n\nWrite your answers and code here!\n\n\n# Inference for the difference between normal means (3 points)\n\nLoading the library and the data.\n\n::: {.cell}\n\n```{.r .cell-code}\ndata(\"windshieldy2\")\n# The new data are now stored in the variable `windshieldy2`.\n# The below displays the first few rows of the new data:\nhead(windshieldy2)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 15.980 14.206 16.011 17.250 15.993 15.722\n```\n:::\n:::\n\n\n\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum(),\n# rtnew() (from aaltobda), quantile() and hist().\n```\n:::\n\n\n\n\n## (c)\n\n\nWrite your answers here!\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n✔ | F W S OK | Context\n\n⠏ | 0 | task-1-subtask-1-tests \n⠏ | 0 | mu_point_est() \n✖ | 1 3 | mu_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-1-subtask-1-tests.R:17:3'): mu_point_est()\nmu_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-2-subtask-1-tests \n⠏ | 0 | mu_interval() \n✖ | 2 3 | mu_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-2-subtask-1-tests.R:15:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.95) not equivalent to c(3.3, 7.7).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 3.3 == 10\n[2] 15.7 - 7.7 == 8\nError: Incorrect result for 1:10 using a 95% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:16:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.8) not equivalent to c(4.2, 6.8).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 4.2 == 9.1\n[2] 15.7 - 6.8 == 8.9\nError: Incorrect result for 1:10 using a 80% interval.\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-3-subtask-1-tests \n⠏ | 0 | mu_pred_interval() \n✖ | 2 3 | mu_pred_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-3-subtask-1-tests.R:16:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.95) not equivalent to c(-1.7, 12.7).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - -1.7 == 13.5\n[2] 17.2 - 12.7 == 4.5\nError: Incorrect result for 1:10, (95%)\n\nFailure ('test-task-3-subtask-1-tests.R:18:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.8) not equivalent to c(1.1, 9.9).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - 1.1 == 10.7\n[2] 17.2 - 9.9 == 7.3\nError: Incorrect result for 1:10, (80%)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-4-subtask-1-tests \n⠏ | 0 | mu_pred_point_est() \n✖ | 1 3 | mu_pred_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-4-subtask-1-tests.R:16:3'): mu_pred_point_est()\nmu_pred_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-5-subtask-1-tests \n⠏ | 0 | posterior_odds_ratio_point_est() \n✖ | 3 3 | posterior_odds_ratio_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-5-subtask-1-tests.R:18:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 0.5307909.\n1/1 mismatches\n[1] 2.65 - 0.531 == 2.12\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90).\n\nFailure ('test-task-5-subtask-1-tests.R:24:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p0, p1) not equivalent to 1.876519.\n1/1 mismatches\n[1] 2.65 - 1.88 == 0.774\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6).\n\nFailure ('test-task-5-subtask-1-tests.R:25:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 1.24902.\n1/1 mismatches\n[1] 2.65 - 1.25 == 1.4\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5).\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-6-subtask-1-tests \n⠏ | 0 | posterior_odds_ratio_interval() \n✖ | 6 2 | posterior_odds_ratio_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-6-subtask-1-tests.R:17:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.875367, 6.05911).\n2/2 mismatches (average diff: 0.719)\n[1] 0.68 - 0.875 == -0.196\n[2] 7.30 - 6.059 == 1.242\nError: Incorrect result for p0 = rbeta(100000, 5, 95), p1 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:19:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1650407, 1.142378).\n2/2 mismatches (average diff: 3.34)\n[1] 0.68 - 0.165 == 0.515\n[2] 7.30 - 1.142 == 6.159\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:21:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.2086461, 0.9392956).\n2/2 mismatches (average diff: 3.42)\n[1] 0.68 - 0.209 == 0.471\n[2] 7.30 - 0.939 == 6.362\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 80%.\n\nFailure ('test-task-6-subtask-1-tests.R:27:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.2714472, 5.5970131).\n2/2 mismatches (average diff: 1.06)\n[1] 0.68 - 0.271 == 0.408\n[2] 7.30 - 5.597 == 1.705\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:29:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1786667, 3.6839583).\n2/2 mismatches (average diff: 2.06)\n[1] 0.68 - 0.179 == 0.501\n[2] 7.30 - 3.684 == 3.618\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:31:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.252972, 2.633517).\n2/2 mismatches (average diff: 2.55)\n[1] 0.68 - 0.253 == 0.427\n[2] 7.30 - 2.634 == 4.668\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 80%.\n────────────────────────────────────────────────────────────────────────────────\nMaximum number of failures exceeded; quitting at end of file.\nℹ Increase this number with (e.g.) `testthat::set_max_fails(Inf)` \n\n══ Results ═════════════════════════════════════════════════════════════════════\nDuration: 0.5 s\n\n[ FAIL 15 | WARN 0 | SKIP 0 | PASS 17 ]\n══ Terminated early ════════════════════════════════════════════════════════════\n```\n:::\n:::\n\n\n:::\n::::\n", "supporting": [ "template3_files" ], diff --git a/assignments/_freeze/template3/execute-results/tex.json b/assignments/_freeze/template3/execute-results/tex.json index 7ee29f68..21d9b7e0 100644 --- a/assignments/_freeze/template3/execute-results/tex.json +++ b/assignments/_freeze/template3/execute-results/tex.json @@ -1,7 +1,7 @@ { "hash": "bdbdb6131717ff0ff6e430a21e4e98aa", "result": { - "markdown": "---\ntitle: \"Assignment 3\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n page-layout: article\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n\nThis is the template for [assignment 3](assignment3.html). You can download the qmd-files ([full](https://avehtari.github.io/BDA_course_Aalto/assignments/template3.qmd), [simple](https://avehtari.github.io/BDA_course_Aalto/assignments/simple_template3.qmd)) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up [`markmyassignment`](https://github.com/MansMeg/markmyassignment) to check your functions at the end of the notebook:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(markmyassignment)){\n install.packages(\"markmyassignment\")\n library(markmyassignment)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: markmyassignment\n```\n:::\n\n```{.r .cell-code}\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment3.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment3: Bayesian Data Analysis: Assignment 3\nThe assignment contain the following (6) tasks:\n- mu_point_est\n- mu_interval\n- mu_pred_interval\n- mu_pred_point_est\n- posterior_odds_ratio_point_est\n- posterior_odds_ratio_interval\n```\n:::\n:::\n\n\n\nThe following installs and loads the `aaltobda` package:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(aaltobda)){\n install.packages(\"aaltobda\", repos = c(\"https://avehtari.github.io/BDA_course_Aalto/\", getOption(\"repos\")))\n library(aaltobda)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: aaltobda\n```\n:::\n:::\n\n\nThe following installs and loads the [`latex2exp` package](https://github.com/stefano-meschiari/latex2exp), which allows us to use LaTeX in plots:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(latex2exp)){\n install.packages(\"latex2exp\")\n library(latex2exp)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: latex2exp\n```\n:::\n:::\n\n\n\n:::\n::::\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-tip collapse=false}\n\n## Showcase: Setting up advanced packages (`posterior` and `ggdist`)\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n*This block showcases advanced tools, which you will be allowed and expected to use after this assignment.*\n**For now, you should solve the assignment without the tools showcased herein.**\n\n\n\n\nThe following installs and loads the [`posterior` package](https://mc-stan.org/posterior/index.html),\nwhich allows us to use its [`rvar` Random Variable Datatype\n](https://mc-stan.org/posterior/articles/rvar.html):\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(posterior)){\n install.packages(\"posterior\")\n library(posterior)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: posterior\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThis is posterior version 1.4.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n\nAttaching package: 'posterior'\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following object is masked from 'package:aaltobda':\n\n mcse_quantile\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:stats':\n\n mad, sd, var\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:base':\n\n %in%, match\n```\n:::\n:::\n\n\n\nThe following installs and loads the [`ggdist` package](https://mjskay.github.io/ggdist/)\nfor advanced plotting functions:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(ggplot2)){\n install.packages(\"ggplot2\")\n library(ggplot2)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: ggplot2\n```\n:::\n\n```{.r .cell-code}\nggplot2::theme_set(theme_minimal(base_size = 14))\nif(!require(ggdist)){\n install.packages(\"ggdist\")\n library(ggdist)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: ggdist\n```\n:::\n:::\n\n\n\n\n\n*This block showcases advanced tools, which you will be allowed and expected to use after this assignment.*\n**For now, you should solve the assignment without the tools showcased herein.**\n\n\n\n:::\n::::\n\n\n# Inference for normal mean and deviation (3 points)\n\nLoading the library and the data.\n\n\n::: {.cell}\n\n```{.r .cell-code}\ndata(\"windshieldy1\")\n# The data are now stored in the variable `windshieldy1`.\n# The below displays the data:\nwindshieldy1\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 13.357 14.928 14.896 15.297 14.820 12.067 14.824 13.865 17.447\n```\n:::\n:::\n\n\nThe below data is **only for the tests**, you need to change to the\nfull data `windshieldy1` when reporting your results.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nwindshieldy_test <- c(13.357, 14.928, 14.896, 14.820)\n```\n:::\n\n\n\n\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum()\n# and qtnew(), dtnew() (from aaltobda)\n\nmu_point_est <- function(data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 14.5\n\n}\nmu_interval <- function(data, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(13.3, 15.7)\n\n}\n```\n:::\n\n\n\nYou can plot the density as below if you implement `mu_pdf` to compute the PDF of the posterior $p(\\mu|y)$ of the average hardness $\\mu$.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmu_pdf <- function(data, x){\n # Compute necessary parameters here.\n # These are the correct parameters for `windshieldy_test`\n # with the provided uninformative prior.\n df = 3\n location = 14.5\n scale = 0.3817557\n # Use the computed parameters as below to compute the PDF:\n\n dtnew(x, df, location, scale)\n}\n\nx_interval = mu_interval(windshieldy1, .999)\nlower_x = x_interval[1]\nupper_x = x_interval[2]\nx = seq(lower_x, upper_x, length.out=1000)\nplot(\n x, mu_pdf(windshieldy1, x), type=\"l\",\n xlab=TeX(r'(average hardness $\\mu$)'),\n ylab=TeX(r'(PDF of the posterior $p(\\mu|y)$)')\n)\n```\n\n::: {.cell-output-display}\n![PDF of the posterior $p(\\mu|y)$ of the average hardness $\\mu$](template3_files/figure-pdf/fig-2b-density-1.pdf){#fig-2b-density fig-pos='H'}\n:::\n:::\n\n\n\n\n\n## (c)\n\n\nWrite your answers and code here!\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum()\n# and qtnew(), dtnew() (from aaltobda)\n\nmu_pred_point_est <- function(data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 14.5\n\n}\nmu_pred_interval <- function(data, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(11.8, 17.2)\n\n}\n```\n:::\n\n\n\nYou can plot the density as below if you implement `mu_pred_pdf` to compute the PDF of the posterior predictive $p(\\tilde{y}|y)$ of a new hardness observation $\\tilde{y}$.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmu_pred_pdf <- function(data, x){\n # Compute necessary parameters here.\n # These are the correct parameters for `windshieldy_test`\n # with the provided uninformative prior.\n df = 3\n location = 14.5\n scale = 0.8536316\n # Use the computed parameters as below to compute the PDF:\n\n dtnew(x, df, location, scale)\n}\n\nx_interval = mu_pred_interval(windshieldy1, .999)\nlower_x = x_interval[1]\nupper_x = x_interval[2]\nx = seq(lower_x, upper_x, length.out=1000)\nplot(\n x, mu_pred_pdf(windshieldy1, x), type=\"l\",\n xlab=TeX(r'(new hardness observation $\\tilde{y}$)'),\n ylab=TeX(r'(PDF of the posterior predictive $p(\\tilde{y}|y)$)')\n)\n```\n\n::: {.cell-output-display}\n![PDF of the posterior predictive $p(\\tilde{y}|y)$ of a new hardness observation $\\tilde{y}$](template3_files/figure-pdf/fig-2c-density-1.pdf){#fig-2c-density fig-pos='H'}\n:::\n:::\n\n\n\n\n# Inference for the difference between proportions (3 points)\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\nThe below data is **only for the tests**:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nset.seed(4711)\nndraws = 1000\np0 = rbeta(ndraws, 5, 95)\np1 = rbeta(ndraws, 10, 90)\n```\n:::\n\n\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: mean(), quantile()\n\nposterior_odds_ratio_point_est <- function(p0, p1) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 2.650172\n\n}\nposterior_odds_ratio_interval <- function(p0, p1, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(0.6796942,7.3015964)\n\n}\n```\n:::\n\n\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-tip collapse=false}\n\n## Showcase: advanced tools (`posterior`'s `rvar`, `ggdist`'s `stat_dotsinterval`)\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n*This block showcases advanced tools, which you will be allowed and expected to use after this assignment.*\n**For now, you should solve the assignment without the tools showcased herein.**\n\n\n\n\nThe `posterior` package's random variable datatype `rvar` is a\n[\"sample-based representation of random variables\"](https://mc-stan.org/posterior/articles/rvar.html#:~:text=sample%2Dbased%20representation%20of%20random%20variables)\nwhich makes handling of random samples (of draws) such as the ones contained in the above variables `p0` and `p1` easier.\n[By default, it prints as the mean and standard deviation of the draws](https://mc-stan.org/posterior/articles/rvar.html#:~:text=The%20default%20display%20of%20an%20rvar%20shows%20the%20mean%20and%20standard%20deviation%20of%20each%20element%20of%20the%20array.), **such that `rvar(p0)` prints as 0.05 ± 0.021 and `rvar(p1)` prints as 0.1 ± 0.029**.\n\nThe datatype is [\"designed to [...] be able to be used inside `data.frame()`s and `tibble()`s, and to be used with distribution visualizations in the ggdist package.\"](https://mc-stan.org/posterior/articles/rvar.html#:~:text=designed%20to%20interoperate%20with%20vectorized%20distributions%20in%20the%20distributional%20package%2C%20to%20be%20able%20to%20be%20used%20inside%20data.frame()s%20and%20tibble()s%2C%20and%20to%20be%20used%20with%20distribution%20visualizations%20in%20the%20ggdist%20package.)\nThe code below sets up an [R `data.frame()`](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/data.frame) with the draws in `p0` and `p1` wrapped in an `rvar`, and uses that data frame to visualize the draws using [`ggdist`](https://mjskay.github.io/ggdist/index.html), an R package building on [`ggplot2`](https://ggplot2.tidyverse.org/) and [\"designed for both frequentist and Bayesian uncertainty visualization\"](https://mjskay.github.io/ggdist/index.html#:~:text=designed%20for%20both%20frequentist%20and%20Bayesian%20uncertainty%20visualization).\n\nThe below plot, @fig-showcase-probabilities uses `ggdist`'s [`stat_dotsinterval()`](https://mjskay.github.io/ggdist/articles/dotsinterval.html), which by default visualizes\n\n* [an `rvar`'s median and central 66% and 95% intervals](https://mjskay.github.io/ggdist/reference/stat_dotsinterval.html#:~:text=point_interval%20%3D%20%22median_qi%22%2C%0A%20%20.width%20%3D%20c(0.66%2C%200.95)%2C) using a black dot and lines of varying thicknesses as when using `ggdist`'s [`stat_pointinterval()`](https://mjskay.github.io/ggdist/reference/stat_pointinterval.html#examples) and\n* an `rvar`'s draws using grey dots as when using `ggdist`'s [`stat_dots()`](https://mjskay.github.io/ggdist/reference/stat_dots.html#examples):\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nr0 = rvar(p0)\nr1 = rvar(p1)\nggplot(data.frame(\n rv_name=c(\"control\", \"treatment\"), rv=c(r0, r1)\n)) +\n aes(xdist=rv, y=rv_name) +\n labs(x=\"probabilities of death\", y=\"patient group\") +\n stat_dotsinterval()\n```\n\n::: {.cell-output-display}\n![Probabilities of death for the two patient groups.](template3_files/figure-pdf/fig-showcase-probabilities-1.pdf){#fig-showcase-probabilities fig-pos='H'}\n:::\n:::\n\n\n\n`rvar`s make it easy to compute functions of random variables, such as\n\n* differences, e.g. $p_0 - p_1$: `r0 - r1` computes an `rvar` which prints as -0.05 ± 0.037, indicating the **sample mean** and the **sample standard deviation** of the difference of the probabilities of death,\n* products, e.g. $p_0 \\, p_1$: `r0 * r1` computes an `rvar` which prints as 0.005 ± 0.0026 which in this case\nhas no great interpretation, or\n* the odds ratios needed in task 3.b).\n\nBelow, in @fig-showcase-odds-ratios, we compute the odds ratios using the `rvar`s and visualize its median, central intervals and draws, as above in @fig-showcase-probabilities:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nrodds_ratio = (r1/(1-r1))/(r0/(1-r0))\nggplot(data.frame(\n rv=c(rodds_ratio)\n)) +\n aes(xdist=rv) +\n labs(x=\"odds ratio\", y=\"relative amount of draws\") +\n stat_dotsinterval()\n```\n\n::: {.cell-output-display}\n![Odds ratios of the two patient groups.](template3_files/figure-pdf/fig-showcase-odds-ratios-1.pdf){#fig-showcase-odds-ratios fig-pos='H'}\n:::\n:::\n\n\n\nYou can use @fig-showcase-odds-ratios to visually check whether the answers you computed for 3.b) make sense.\n\n\n\n*This block showcases advanced tools, which you will be allowed and expected to use after this assignment.*\n**For now, you should solve the assignment without the tools showcased herein.**\n\n\n\n:::\n::::\n\n\n\n## (c)\n\n\nWrite your answers and code here!\n\n\n# Inference for the difference between normal means (3 points)\n\nLoading the library and the data.\n\n\n::: {.cell}\n\n```{.r .cell-code}\ndata(\"windshieldy2\")\n# The new data are now stored in the variable `windshieldy2`.\n# The below displays the first few rows of the new data:\nhead(windshieldy2)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 15.980 14.206 16.011 17.250 15.993 15.722\n```\n:::\n:::\n\n\n\n\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum(),\n# rtnew() (from aaltobda), quantile() and hist().\n```\n:::\n\n\n\n\n\n## (c)\n\n\nWrite your answers here!\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nv | F W S OK | Context\n\n/ | 0 | task-1-subtask-1-tests \n/ | 0 | mu_point_est() \nx | 1 3 | mu_point_est()\n--------------------------------------------------------------------------------\nFailure ('test-task-1-subtask-1-tests.R:17:3'): mu_point_est()\nmu_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n--------------------------------------------------------------------------------\n\n/ | 0 | task-2-subtask-1-tests \n/ | 0 | mu_interval() \nx | 2 3 | mu_interval()\n--------------------------------------------------------------------------------\nFailure ('test-task-2-subtask-1-tests.R:15:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.95) not equivalent to c(3.3, 7.7).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 3.3 == 10\n[2] 15.7 - 7.7 == 8\nError: Incorrect result for 1:10 using a 95% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:16:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.8) not equivalent to c(4.2, 6.8).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 4.2 == 9.1\n[2] 15.7 - 6.8 == 8.9\nError: Incorrect result for 1:10 using a 80% interval.\n--------------------------------------------------------------------------------\n\n/ | 0 | task-3-subtask-1-tests \n/ | 0 | mu_pred_interval() \nx | 2 3 | mu_pred_interval()\n--------------------------------------------------------------------------------\nFailure ('test-task-3-subtask-1-tests.R:16:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.95) not equivalent to c(-1.7, 12.7).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - -1.7 == 13.5\n[2] 17.2 - 12.7 == 4.5\nError: Incorrect result for 1:10, (95%)\n\nFailure ('test-task-3-subtask-1-tests.R:18:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.8) not equivalent to c(1.1, 9.9).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - 1.1 == 10.7\n[2] 17.2 - 9.9 == 7.3\nError: Incorrect result for 1:10, (80%)\n--------------------------------------------------------------------------------\n\n/ | 0 | task-4-subtask-1-tests \n/ | 0 | mu_pred_point_est() \nx | 1 3 | mu_pred_point_est()\n--------------------------------------------------------------------------------\nFailure ('test-task-4-subtask-1-tests.R:16:3'): mu_pred_point_est()\nmu_pred_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n--------------------------------------------------------------------------------\n\n/ | 0 | task-5-subtask-1-tests \n/ | 0 | posterior_odds_ratio_point_est() \nx | 3 3 | posterior_odds_ratio_point_est()\n--------------------------------------------------------------------------------\nFailure ('test-task-5-subtask-1-tests.R:18:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 0.5307909.\n1/1 mismatches\n[1] 2.65 - 0.531 == 2.12\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90).\n\nFailure ('test-task-5-subtask-1-tests.R:24:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p0, p1) not equivalent to 1.876519.\n1/1 mismatches\n[1] 2.65 - 1.88 == 0.774\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6).\n\nFailure ('test-task-5-subtask-1-tests.R:25:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 1.24902.\n1/1 mismatches\n[1] 2.65 - 1.25 == 1.4\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5).\n--------------------------------------------------------------------------------\n\n/ | 0 | task-6-subtask-1-tests \n/ | 0 | posterior_odds_ratio_interval() \n/ | 6 2 | posterior_odds_ratio_interval() \nx | 6 2 | posterior_odds_ratio_interval() [0.1s]\n--------------------------------------------------------------------------------\nFailure ('test-task-6-subtask-1-tests.R:17:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.875367, 6.05911).\n2/2 mismatches (average diff: 0.719)\n[1] 0.68 - 0.875 == -0.196\n[2] 7.30 - 6.059 == 1.242\nError: Incorrect result for p0 = rbeta(100000, 5, 95), p1 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:19:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1650407, 1.142378).\n2/2 mismatches (average diff: 3.34)\n[1] 0.68 - 0.165 == 0.515\n[2] 7.30 - 1.142 == 6.159\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:21:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.2086461, 0.9392956).\n2/2 mismatches (average diff: 3.42)\n[1] 0.68 - 0.209 == 0.471\n[2] 7.30 - 0.939 == 6.362\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 80%.\n\nFailure ('test-task-6-subtask-1-tests.R:27:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.2714472, 5.5970131).\n2/2 mismatches (average diff: 1.06)\n[1] 0.68 - 0.271 == 0.408\n[2] 7.30 - 5.597 == 1.705\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:29:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1786667, 3.6839583).\n2/2 mismatches (average diff: 2.06)\n[1] 0.68 - 0.179 == 0.501\n[2] 7.30 - 3.684 == 3.618\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:31:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.252972, 2.633517).\n2/2 mismatches (average diff: 2.55)\n[1] 0.68 - 0.253 == 0.427\n[2] 7.30 - 2.634 == 4.668\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 80%.\n--------------------------------------------------------------------------------\nMaximum number of failures exceeded; quitting at end of file.\ni Increase this number with (e.g.) `testthat::set_max_fails(Inf)` \n\n== Results =====================================================================\nDuration: 0.6 s\n\n[ FAIL 15 | WARN 0 | SKIP 0 | PASS 17 ]\n== Terminated early ============================================================\n```\n:::\n:::\n\n\n\n:::\n::::\n", + "markdown": "---\ntitle: \"Assignment 3\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n page-layout: article\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n\nThis is the template for [assignment 3](assignment3.html). You can download the qmd-files ([full](https://avehtari.github.io/BDA_course_Aalto/assignments/template3.qmd), [simple](https://avehtari.github.io/BDA_course_Aalto/assignments/simple_template3.qmd)) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up [`markmyassignment`](https://github.com/MansMeg/markmyassignment) to check your functions at the end of the notebook:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(markmyassignment)){\n install.packages(\"markmyassignment\")\n library(markmyassignment)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: markmyassignment\n```\n:::\n\n```{.r .cell-code}\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment3.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment3: Bayesian Data Analysis: Assignment 3\nThe assignment contain the following (6) tasks:\n- mu_point_est\n- mu_interval\n- mu_pred_interval\n- mu_pred_point_est\n- posterior_odds_ratio_point_est\n- posterior_odds_ratio_interval\n```\n:::\n:::\n\n\n\nThe following installs and loads the `aaltobda` package:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(aaltobda)){\n install.packages(\"aaltobda\", repos = c(\"https://avehtari.github.io/BDA_course_Aalto/\", getOption(\"repos\")))\n library(aaltobda)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: aaltobda\n```\n:::\n:::\n\n\nThe following installs and loads the [`latex2exp` package](https://github.com/stefano-meschiari/latex2exp), which allows us to use LaTeX in plots:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(latex2exp)){\n install.packages(\"latex2exp\")\n library(latex2exp)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: latex2exp\n```\n:::\n:::\n\n\n\n:::\n::::\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-tip collapse=false}\n\n## Showcase: Setting up advanced packages (`posterior` and `ggdist`)\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n*This block showcases advanced tools, which you will be allowed and expected to use after this assignment.*\n**For now, you should solve the assignment without the tools showcased herein.**\n\n\n\n\nThe following installs and loads the [`posterior` package](https://mc-stan.org/posterior/index.html),\nwhich allows us to use its [`rvar` Random Variable Datatype\n](https://mc-stan.org/posterior/articles/rvar.html):\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(posterior)){\n install.packages(\"posterior\")\n library(posterior)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: posterior\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThis is posterior version 1.4.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n\nAttaching package: 'posterior'\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following object is masked from 'package:aaltobda':\n\n mcse_quantile\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:stats':\n\n mad, sd, var\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:base':\n\n %in%, match\n```\n:::\n:::\n\n\n\nThe following installs and loads the [`ggdist` package](https://mjskay.github.io/ggdist/)\nfor advanced plotting functions:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(ggplot2)){\n install.packages(\"ggplot2\")\n library(ggplot2)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: ggplot2\n```\n:::\n\n```{.r .cell-code}\nggplot2::theme_set(theme_minimal(base_size = 14))\nif(!require(ggdist)){\n install.packages(\"ggdist\")\n library(ggdist)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: ggdist\n```\n:::\n:::\n\n\n\n\n\n*This block showcases advanced tools, which you will be allowed and expected to use after this assignment.*\n**For now, you should solve the assignment without the tools showcased herein.**\n\n\n\n:::\n::::\n\n\n# Inference for normal mean and deviation (3 points)\n\nLoading the library and the data.\n\n\n::: {.cell}\n\n```{.r .cell-code}\ndata(\"windshieldy1\")\n# The data are now stored in the variable `windshieldy1`.\n# The below displays the data:\nwindshieldy1\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 13.357 14.928 14.896 15.297 14.820 12.067 14.824 13.865 17.447\n```\n:::\n:::\n\n\nThe below data is **only for the tests**, you need to change to the\nfull data `windshieldy1` when reporting your results.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nwindshieldy_test <- c(13.357, 14.928, 14.896, 14.820)\n```\n:::\n\n\n\n\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum()\n# and qtnew(), dtnew() (from aaltobda)\n\nmu_point_est <- function(data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 14.5\n\n}\nmu_interval <- function(data, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(13.3, 15.7)\n\n}\n```\n:::\n\n\n\nYou can plot the density as below if you implement `mu_pdf` to compute the PDF of the posterior $p(\\mu|y)$ of the average hardness $\\mu$.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmu_pdf <- function(data, x){\n # Compute necessary parameters here.\n # These are the correct parameters for `windshieldy_test`\n # with the provided uninformative prior.\n df = 3\n location = 14.5\n scale = 0.3817557\n # Use the computed parameters as below to compute the PDF:\n\n dtnew(x, df, location, scale)\n}\n\nx_interval = mu_interval(windshieldy1, .999)\nlower_x = x_interval[1]\nupper_x = x_interval[2]\nx = seq(lower_x, upper_x, length.out=1000)\nplot(\n x, mu_pdf(windshieldy1, x), type=\"l\",\n xlab=TeX(r'(average hardness $\\mu$)'),\n ylab=TeX(r'(PDF of the posterior $p(\\mu|y)$)')\n)\n```\n\n::: {.cell-output-display}\n![PDF of the posterior $p(\\mu|y)$ of the average hardness $\\mu$](template3_files/figure-pdf/fig-2b-density-1.pdf){#fig-2b-density fig-pos='H'}\n:::\n:::\n\n\n\n\n\n## (c)\n\n\nWrite your answers and code here!\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum()\n# and qtnew(), dtnew() (from aaltobda)\n\nmu_pred_point_est <- function(data) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 14.5\n\n}\nmu_pred_interval <- function(data, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(11.8, 17.2)\n\n}\n```\n:::\n\n\n\nYou can plot the density as below if you implement `mu_pred_pdf` to compute the PDF of the posterior predictive $p(\\tilde{y}|y)$ of a new hardness observation $\\tilde{y}$.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmu_pred_pdf <- function(data, x){\n # Compute necessary parameters here.\n # These are the correct parameters for `windshieldy_test`\n # with the provided uninformative prior.\n df = 3\n location = 14.5\n scale = 0.8536316\n # Use the computed parameters as below to compute the PDF:\n\n dtnew(x, df, location, scale)\n}\n\nx_interval = mu_pred_interval(windshieldy1, .999)\nlower_x = x_interval[1]\nupper_x = x_interval[2]\nx = seq(lower_x, upper_x, length.out=1000)\nplot(\n x, mu_pred_pdf(windshieldy1, x), type=\"l\",\n xlab=TeX(r'(new hardness observation $\\tilde{y}$)'),\n ylab=TeX(r'(PDF of the posterior predictive $p(\\tilde{y}|y)$)')\n)\n```\n\n::: {.cell-output-display}\n![PDF of the posterior predictive $p(\\tilde{y}|y)$ of a new hardness observation $\\tilde{y}$](template3_files/figure-pdf/fig-2c-density-1.pdf){#fig-2c-density fig-pos='H'}\n:::\n:::\n\n\n\n\n# Inference for the difference between proportions (3 points)\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\nThe below data is **only for the tests**:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nset.seed(4711)\nndraws = 1000\np0 = rbeta(ndraws, 5, 95)\np1 = rbeta(ndraws, 10, 90)\n```\n:::\n\n\n\n**Keep the below name and format for the functions to work with `markmyassignment`:**\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful function: mean(), quantile()\n\nposterior_odds_ratio_point_est <- function(p0, p1) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 2.650172\n\n}\nposterior_odds_ratio_interval <- function(p0, p1, prob = 0.95) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(0.6796942,7.3015964)\n\n}\n```\n:::\n\n\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-tip collapse=false}\n\n## Showcase: advanced tools (`posterior`'s `rvar`, `ggdist`'s `stat_dotsinterval`)\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n*This block showcases advanced tools, which you will be allowed and expected to use after this assignment.*\n**For now, you should solve the assignment without the tools showcased herein.**\n\n\n\n\nThe `posterior` package's random variable datatype `rvar` is a\n[\"sample-based representation of random variables\"](https://mc-stan.org/posterior/articles/rvar.html#:~:text=sample%2Dbased%20representation%20of%20random%20variables)\nwhich makes handling of random samples (of draws) such as the ones contained in the above variables `p0` and `p1` easier.\n[By default, it prints as the mean and standard deviation of the draws](https://mc-stan.org/posterior/articles/rvar.html#:~:text=The%20default%20display%20of%20an%20rvar%20shows%20the%20mean%20and%20standard%20deviation%20of%20each%20element%20of%20the%20array.), **such that `rvar(p0)` prints as 0.05 ± 0.021 and `rvar(p1)` prints as 0.1 ± 0.029**.\n\nThe datatype is [\"designed to [...] be able to be used inside `data.frame()`s and `tibble()`s, and to be used with distribution visualizations in the ggdist package.\"](https://mc-stan.org/posterior/articles/rvar.html#:~:text=designed%20to%20interoperate%20with%20vectorized%20distributions%20in%20the%20distributional%20package%2C%20to%20be%20able%20to%20be%20used%20inside%20data.frame()s%20and%20tibble()s%2C%20and%20to%20be%20used%20with%20distribution%20visualizations%20in%20the%20ggdist%20package.)\nThe code below sets up an [R `data.frame()`](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/data.frame) with the draws in `p0` and `p1` wrapped in an `rvar`, and uses that data frame to visualize the draws using [`ggdist`](https://mjskay.github.io/ggdist/index.html), an R package building on [`ggplot2`](https://ggplot2.tidyverse.org/) and [\"designed for both frequentist and Bayesian uncertainty visualization\"](https://mjskay.github.io/ggdist/index.html#:~:text=designed%20for%20both%20frequentist%20and%20Bayesian%20uncertainty%20visualization).\n\nThe below plot, @fig-showcase-probabilities uses `ggdist`'s [`stat_dotsinterval()`](https://mjskay.github.io/ggdist/articles/dotsinterval.html), which by default visualizes\n\n* [an `rvar`'s median and central 66% and 95% intervals](https://mjskay.github.io/ggdist/reference/stat_dotsinterval.html#:~:text=point_interval%20%3D%20%22median_qi%22%2C%0A%20%20.width%20%3D%20c(0.66%2C%200.95)%2C) using a black dot and lines of varying thicknesses as when using `ggdist`'s [`stat_pointinterval()`](https://mjskay.github.io/ggdist/reference/stat_pointinterval.html#examples) and\n* an `rvar`'s draws using grey dots as when using `ggdist`'s [`stat_dots()`](https://mjskay.github.io/ggdist/reference/stat_dots.html#examples):\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nr0 = rvar(p0)\nr1 = rvar(p1)\nggplot(data.frame(\n rv_name=c(\"control\", \"treatment\"), rv=c(r0, r1)\n)) +\n aes(xdist=rv, y=rv_name) +\n labs(x=\"probabilities of death\", y=\"patient group\") +\n stat_dotsinterval()\n```\n\n::: {.cell-output-display}\n![Probabilities of death for the two patient groups.](template3_files/figure-pdf/fig-showcase-probabilities-1.pdf){#fig-showcase-probabilities fig-pos='H'}\n:::\n:::\n\n\n\n`rvar`s make it easy to compute functions of random variables, such as\n\n* differences, e.g. $p_0 - p_1$: `r0 - r1` computes an `rvar` which prints as -0.05 ± 0.037, indicating the **sample mean** and the **sample standard deviation** of the difference of the probabilities of death,\n* products, e.g. $p_0 \\, p_1$: `r0 * r1` computes an `rvar` which prints as 0.005 ± 0.0026 which in this case\nhas no great interpretation, or\n* the odds ratios needed in task 3.b).\n\nBelow, in @fig-showcase-odds-ratios, we compute the odds ratios using the `rvar`s and visualize its median, central intervals and draws, as above in @fig-showcase-probabilities:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nrodds_ratio = (r1/(1-r1))/(r0/(1-r0))\nggplot(data.frame(\n rv=c(rodds_ratio)\n)) +\n aes(xdist=rv) +\n labs(x=\"odds ratio\", y=\"relative amount of draws\") +\n stat_dotsinterval()\n```\n\n::: {.cell-output-display}\n![Odds ratios of the two patient groups.](template3_files/figure-pdf/fig-showcase-odds-ratios-1.pdf){#fig-showcase-odds-ratios fig-pos='H'}\n:::\n:::\n\n\n\nYou can use @fig-showcase-odds-ratios to visually check whether the answers you computed for 3.b) make sense.\n\n\n\n*This block showcases advanced tools, which you will be allowed and expected to use after this assignment.*\n**For now, you should solve the assignment without the tools showcased herein.**\n\n\n\n:::\n::::\n\n\n\n## (c)\n\n\nWrite your answers and code here!\n\n\n# Inference for the difference between normal means (3 points)\n\nLoading the library and the data.\n\n\n::: {.cell}\n\n```{.r .cell-code}\ndata(\"windshieldy2\")\n# The new data are now stored in the variable `windshieldy2`.\n# The below displays the first few rows of the new data:\nhead(windshieldy2)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 15.980 14.206 16.011 17.250 15.993 15.722\n```\n:::\n:::\n\n\n\n\n\n## (a)\n\n\nWrite your answers here!\n\n\n\n## (b)\n\n\nWrite your answers and code here!\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: mean(), length(), sqrt(), sum(),\n# rtnew() (from aaltobda), quantile() and hist().\n```\n:::\n\n\n\n\n\n## (c)\n\n\nWrite your answers here!\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nv | F W S OK | Context\n\n/ | 0 | task-1-subtask-1-tests \n/ | 0 | mu_point_est() \nx | 1 3 | mu_point_est()\n--------------------------------------------------------------------------------\nFailure ('test-task-1-subtask-1-tests.R:17:3'): mu_point_est()\nmu_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n--------------------------------------------------------------------------------\n\n/ | 0 | task-2-subtask-1-tests \n/ | 0 | mu_interval() \nx | 2 3 | mu_interval()\n--------------------------------------------------------------------------------\nFailure ('test-task-2-subtask-1-tests.R:15:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.95) not equivalent to c(3.3, 7.7).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 3.3 == 10\n[2] 15.7 - 7.7 == 8\nError: Incorrect result for 1:10 using a 95% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:16:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.8) not equivalent to c(4.2, 6.8).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 4.2 == 9.1\n[2] 15.7 - 6.8 == 8.9\nError: Incorrect result for 1:10 using a 80% interval.\n--------------------------------------------------------------------------------\n\n/ | 0 | task-3-subtask-1-tests \n/ | 0 | mu_pred_interval() \nx | 2 3 | mu_pred_interval()\n--------------------------------------------------------------------------------\nFailure ('test-task-3-subtask-1-tests.R:16:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.95) not equivalent to c(-1.7, 12.7).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - -1.7 == 13.5\n[2] 17.2 - 12.7 == 4.5\nError: Incorrect result for 1:10, (95%)\n\nFailure ('test-task-3-subtask-1-tests.R:18:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.8) not equivalent to c(1.1, 9.9).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - 1.1 == 10.7\n[2] 17.2 - 9.9 == 7.3\nError: Incorrect result for 1:10, (80%)\n--------------------------------------------------------------------------------\n\n/ | 0 | task-4-subtask-1-tests \n/ | 0 | mu_pred_point_est() \nx | 1 3 | mu_pred_point_est()\n--------------------------------------------------------------------------------\nFailure ('test-task-4-subtask-1-tests.R:16:3'): mu_pred_point_est()\nmu_pred_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n--------------------------------------------------------------------------------\n\n/ | 0 | task-5-subtask-1-tests \n/ | 0 | posterior_odds_ratio_point_est() \nx | 3 3 | posterior_odds_ratio_point_est()\n--------------------------------------------------------------------------------\nFailure ('test-task-5-subtask-1-tests.R:18:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 0.5307909.\n1/1 mismatches\n[1] 2.65 - 0.531 == 2.12\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90).\n\nFailure ('test-task-5-subtask-1-tests.R:24:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p0, p1) not equivalent to 1.876519.\n1/1 mismatches\n[1] 2.65 - 1.88 == 0.774\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6).\n\nFailure ('test-task-5-subtask-1-tests.R:25:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 1.24902.\n1/1 mismatches\n[1] 2.65 - 1.25 == 1.4\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5).\n--------------------------------------------------------------------------------\n\n/ | 0 | task-6-subtask-1-tests \n/ | 0 | posterior_odds_ratio_interval() \nx | 6 2 | posterior_odds_ratio_interval()\n--------------------------------------------------------------------------------\nFailure ('test-task-6-subtask-1-tests.R:17:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.875367, 6.05911).\n2/2 mismatches (average diff: 0.719)\n[1] 0.68 - 0.875 == -0.196\n[2] 7.30 - 6.059 == 1.242\nError: Incorrect result for p0 = rbeta(100000, 5, 95), p1 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:19:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1650407, 1.142378).\n2/2 mismatches (average diff: 3.34)\n[1] 0.68 - 0.165 == 0.515\n[2] 7.30 - 1.142 == 6.159\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:21:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.2086461, 0.9392956).\n2/2 mismatches (average diff: 3.42)\n[1] 0.68 - 0.209 == 0.471\n[2] 7.30 - 0.939 == 6.362\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 80%.\n\nFailure ('test-task-6-subtask-1-tests.R:27:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.2714472, 5.5970131).\n2/2 mismatches (average diff: 1.06)\n[1] 0.68 - 0.271 == 0.408\n[2] 7.30 - 5.597 == 1.705\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:29:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1786667, 3.6839583).\n2/2 mismatches (average diff: 2.06)\n[1] 0.68 - 0.179 == 0.501\n[2] 7.30 - 3.684 == 3.618\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:31:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.252972, 2.633517).\n2/2 mismatches (average diff: 2.55)\n[1] 0.68 - 0.253 == 0.427\n[2] 7.30 - 2.634 == 4.668\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 80%.\n--------------------------------------------------------------------------------\nMaximum number of failures exceeded; quitting at end of file.\ni Increase this number with (e.g.) `testthat::set_max_fails(Inf)` \n\n== Results =====================================================================\nDuration: 0.5 s\n\n[ FAIL 15 | WARN 0 | SKIP 0 | PASS 17 ]\n== Terminated early ============================================================\n```\n:::\n:::\n\n\n\n:::\n::::\n", "supporting": [ "template3_files/figure-pdf" ], diff --git a/assignments/_freeze/template3/figure-pdf/fig-2b-density-1.pdf b/assignments/_freeze/template3/figure-pdf/fig-2b-density-1.pdf index 8a9fbddf..09fe7dd3 100644 Binary files a/assignments/_freeze/template3/figure-pdf/fig-2b-density-1.pdf and b/assignments/_freeze/template3/figure-pdf/fig-2b-density-1.pdf differ diff --git a/assignments/_freeze/template3/figure-pdf/fig-2c-density-1.pdf b/assignments/_freeze/template3/figure-pdf/fig-2c-density-1.pdf index 2d0d1394..ea134f10 100644 Binary files a/assignments/_freeze/template3/figure-pdf/fig-2c-density-1.pdf and b/assignments/_freeze/template3/figure-pdf/fig-2c-density-1.pdf differ diff --git a/assignments/_freeze/template3/figure-pdf/fig-showcase-odds-ratios-1.pdf b/assignments/_freeze/template3/figure-pdf/fig-showcase-odds-ratios-1.pdf index 010860aa..764ba725 100644 Binary files a/assignments/_freeze/template3/figure-pdf/fig-showcase-odds-ratios-1.pdf and b/assignments/_freeze/template3/figure-pdf/fig-showcase-odds-ratios-1.pdf differ diff --git a/assignments/_freeze/template3/figure-pdf/fig-showcase-probabilities-1.pdf b/assignments/_freeze/template3/figure-pdf/fig-showcase-probabilities-1.pdf index 06291a91..736e9b3b 100644 Binary files a/assignments/_freeze/template3/figure-pdf/fig-showcase-probabilities-1.pdf and b/assignments/_freeze/template3/figure-pdf/fig-showcase-probabilities-1.pdf differ diff --git a/assignments/_freeze/template4/execute-results/tex.json b/assignments/_freeze/template4/execute-results/tex.json index 0bae0b7f..da6a31f2 100644 --- a/assignments/_freeze/template4/execute-results/tex.json +++ b/assignments/_freeze/template4/execute-results/tex.json @@ -1,7 +1,7 @@ { "hash": "aa7e730f3dc53a44adb7bd8005fbb25d", "result": { - "markdown": "---\ntitle: \"Assignment 4\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n page-layout: article\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n\nThis is the template for [assignment 4](assignment4.html). You can download the [qmd-file](https://avehtari.github.io/BDA_course_Aalto/assignments/template4.qmd) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up [`markmyassignment`](https://github.com/MansMeg/markmyassignment) to check your functions at the end of the notebook:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(markmyassignment)){\n install.packages(\"markmyassignment\")\n library(markmyassignment)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: markmyassignment\n```\n:::\n\n```{.r .cell-code}\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment4.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment4: Bayesian Data Analysis: Assignment 4\nThe assignment contain the following (4) tasks:\n- log_importance_weights\n- normalized_importance_weights\n- S_eff\n- posterior_mean\n```\n:::\n:::\n\n\n\nThe following installs and loads the `aaltobda` package:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(aaltobda)){\n install.packages(\"aaltobda\", repos = c(\"https://avehtari.github.io/BDA_course_Aalto/\", getOption(\"repos\")))\n library(aaltobda)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: aaltobda\n```\n:::\n:::\n\n\nThe following installs and loads the [`latex2exp` package](https://github.com/stefano-meschiari/latex2exp), which allows us to use LaTeX in plots:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(latex2exp)){\n install.packages(\"latex2exp\")\n library(latex2exp)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: latex2exp\n```\n:::\n:::\n\n\n\n:::\n::::\n\n\n# Bioassay model\n\n## (a)\n\n\n## (b)\n\n\nLoading the library and the data.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: quantile()\n# and mcse_quantile() (from aaltobda)\n\ndata(\"bioassay_posterior\")\n# The 4000 draws are now stored in the variable `bioassay_posterior`.\n# The below displays the first rows of the data:\nhead(bioassay_posterior)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n alpha beta\n1 -0.02050577 10.032841\n2 1.21738518 4.504546\n3 3.04829407 16.239424\n4 1.32272770 4.924268\n5 1.36274817 12.880561\n6 1.08593225 5.943731\n```\n:::\n:::\n\n\n\n\n# Importance sampling\n\n## (c)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: bioassaylp (from aaltobda)\nalpha_test = c(1.896, -3.6, 0.374, 0.964, -3.123, -1.581)\nbeta_test = c(24.76, 20.04, 6.15, 18.65, 8.16, 17.4)\n\n\nlog_importance_weights <- function(alpha, beta) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(-8.95, -23.47, -6.02, -8.13, -16.61, -14.57)\n}\n```\n:::\n\n\n\n\n\n## (d)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nnormalized_importance_weights <- function(alpha, beta) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(0.045, 0.000, 0.852, 0.103, 0.000, 0.000)\n}\n```\n:::\n\n\n\n\n\n## (e)\n\n\nWrite your answers and code here!\n\n\n\n## (f)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nS_eff <- function(alpha, beta) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 1.354\n}\n```\n:::\n\n\n\n\n\n## (g)\n\n\n## (h)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nposterior_mean <- function(alpha, beta) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(0.503, 8.275)\n}\n```\n:::\n\n\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nv | F W S OK | Context\n\n/ | 0 | task-1-subtask-1-tests \n/ | 0 | log_importance_weights() \nx | 2 3 | log_importance_weights()\n--------------------------------------------------------------------------------\nFailure ('test-task-1-subtask-1-tests.R:23:3'): log_importance_weights()\nlog_importance_weights(alpha, beta) not equivalent to c(...).\nLengths differ: 6 is not 10\nError: Incorrect result for alpha = c(4.5, 1.8, -2.4, 0.7, 0.3, -3.1, 0.4, 1.7, -0.5, -0.1) and beta = c(25.2, 7, -5.6, 1.1, 14.7, -6.5, 14.2, 25.9, 13.4, 19.8).\n\nFailure ('test-task-1-subtask-1-tests.R:31:3'): log_importance_weights()\nlog_importance_weights(alpha, beta) not equivalent to c(...).\nLengths differ: 6 is not 10\nError: Incorrect result for alpha = c(1.4, 1.5, -2.3, -2.3, -0.5, 1.9, 1.6, -1.8, -2.7, -1.9) and beta = c(11.4, 8.2, 10.8, 7.4, 18.2, 27.8, 5.1, 1.9, -15.7, 25.1).\n--------------------------------------------------------------------------------\n\n/ | 0 | task-2-subtask-1-tests \n/ | 0 | normalized_importance_weights() \nx | 2 3 | normalized_importance_weights()\n--------------------------------------------------------------------------------\nFailure ('test-task-2-subtask-1-tests.R:23:3'): normalized_importance_weights()\nnormalized_importance_weights(alpha, beta) not equivalent to c(0.03, 0.44, 0, 0.01, 0.18, 0, 0.25, 0.04, 0.04, 0.01).\nLengths differ: 6 is not 10\nError: Incorrect result for alpha = c(4.5, 1.8, -2.4, 0.7, 0.3, -3.1, 0.4, 1.7, -0.5, -0.1) and beta = c(25.2, 7, -5.6, 1.1, 14.7, -6.5, 14.2, 25.9, 13.4, 19.8).\n\nFailure ('test-task-2-subtask-1-tests.R:31:3'): normalized_importance_weights()\nnormalized_importance_weights(alpha, beta) not equivalent to c(0.47, 0.42, 0, 0, 0, 0.01, 0.09, 0, 0, 0).\nLengths differ: 6 is not 10\nError: Incorrect result for alpha = c(1.4, 1.5, -2.3, -2.3, -0.5, 1.9, 1.6, -1.8, -2.7, -1.9) and beta = c(11.4, 8.2, 10.8, 7.4, 18.2, 27.8, 5.1, 1.9, -15.7, 25.1).\n--------------------------------------------------------------------------------\n\n/ | 0 | task-3-subtask-1-tests \n/ | 0 | S_eff() \nx | 2 3 | S_eff()\n--------------------------------------------------------------------------------\nFailure ('test-task-3-subtask-1-tests.R:23:3'): S_eff()\nS_eff(alpha, beta) not equivalent to 3.404.\n1/1 mismatches\n[1] 1.35 - 3.4 == -2.05\nError: Incorrect result for alpha = c(4.5, 1.8, -2.4, 0.7, 0.3, -3.1, 0.4, 1.7, -0.5, -0.1) and beta = c(25.2, 7, -5.6, 1.1, 14.7, -6.5, 14.2, 25.9, 13.4, 19.8).\n\nFailure ('test-task-3-subtask-1-tests.R:31:3'): S_eff()\nS_eff(alpha, beta) not equivalent to 2.448.\n1/1 mismatches\n[1] 1.35 - 2.45 == -1.09\nError: Incorrect result for alpha = c(1.4, 1.5, -2.3, -2.3, -0.5, 1.9, 1.6, -1.8, -2.7, -1.9) and beta = c(11.4, 8.2, 10.8, 7.4, 18.2, 27.8, 5.1, 1.9, -15.7, 25.1).\n--------------------------------------------------------------------------------\n\n/ | 0 | task-4-subtask-1-tests \n/ | 0 | posterior_mean() \nx | 2 3 | posterior_mean()\n--------------------------------------------------------------------------------\nFailure ('test-task-4-subtask-1-tests.R:23:3'): posterior_mean()\nposterior_mean(alpha, beta) not equivalent to c(1.111039, 11.854793).\n2/2 mismatches (average diff: 2.09)\n[1] 0.503 - 1.11 == -0.608\n[2] 8.275 - 11.85 == -3.580\nError: Incorrect result for alpha = c(4.5, 1.8, -2.4, 0.7, 0.3, -3.1, 0.4, 1.7, -0.5, -0.1) and beta = c(25.2, 7, -5.6, 1.1, 14.7, -6.5, 14.2, 25.9, 13.4, 19.8).\n\nFailure ('test-task-4-subtask-1-tests.R:30:3'): posterior_mean()\nposterior_mean(alpha, beta) not equivalent to c(1.458649, 9.67896).\n2/2 mismatches (average diff: 1.18)\n[1] 0.503 - 1.46 == -0.956\n[2] 8.275 - 9.68 == -1.404\nError: Incorrect result for alpha = c(1.4, 1.5, -2.3, -2.3, -0.5, 1.9, 1.6, -1.8, -2.7, -1.9) and beta = c(11.4, 8.2, 10.8, 7.4, 18.2, 27.8, 5.1, 1.9, -15.7, 25.1).\n--------------------------------------------------------------------------------\n\n== Results =====================================================================\nDuration: 0.3 s\n\n[ FAIL 8 | WARN 0 | SKIP 0 | PASS 12 ]\n```\n:::\n:::\n\n\n\n:::\n::::\n", + "markdown": "---\ntitle: \"Assignment 4\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n page-layout: article\n pdf:\n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n\n# General information\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\n\nThis is the template for [assignment 4](assignment4.html). You can download the [qmd-file](https://avehtari.github.io/BDA_course_Aalto/assignments/template4.qmd) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.**\n\nThe following will set-up [`markmyassignment`](https://github.com/MansMeg/markmyassignment) to check your functions at the end of the notebook:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(markmyassignment)){\n install.packages(\"markmyassignment\")\n library(markmyassignment)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: markmyassignment\n```\n:::\n\n```{.r .cell-code}\nassignment_path = paste(\"https://github.com/avehtari/BDA_course_Aalto/\",\n\"blob/master/assignments/tests/assignment4.yml\", sep=\"\")\nset_assignment(assignment_path)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nAssignment set:\nassignment4: Bayesian Data Analysis: Assignment 4\nThe assignment contain the following (4) tasks:\n- log_importance_weights\n- normalized_importance_weights\n- S_eff\n- posterior_mean\n```\n:::\n:::\n\n\n\nThe following installs and loads the `aaltobda` package:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(aaltobda)){\n install.packages(\"aaltobda\", repos = c(\"https://avehtari.github.io/BDA_course_Aalto/\", getOption(\"repos\")))\n library(aaltobda)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: aaltobda\n```\n:::\n:::\n\n\nThe following installs and loads the [`latex2exp` package](https://github.com/stefano-meschiari/latex2exp), which allows us to use LaTeX in plots:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nif(!require(latex2exp)){\n install.packages(\"latex2exp\")\n library(latex2exp)\n}\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: latex2exp\n```\n:::\n:::\n\n\n\n:::\n::::\n\n\n# Bioassay model\n\n## (a)\n\n\n## (b)\n\n\nLoading the library and the data.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: quantile()\n# and mcse_quantile() (from aaltobda)\n\ndata(\"bioassay_posterior\")\n# The 4000 draws are now stored in the variable `bioassay_posterior`.\n# The below displays the first rows of the data:\nhead(bioassay_posterior)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n alpha beta\n1 -0.02050577 10.032841\n2 1.21738518 4.504546\n3 3.04829407 16.239424\n4 1.32272770 4.924268\n5 1.36274817 12.880561\n6 1.08593225 5.943731\n```\n:::\n:::\n\n\n\n\n# Importance sampling\n\n## (c)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: bioassaylp (from aaltobda)\nalpha_test = c(1.896, -3.6, 0.374, 0.964, -3.123, -1.581)\nbeta_test = c(24.76, 20.04, 6.15, 18.65, 8.16, 17.4)\n\n\nlog_importance_weights <- function(alpha, beta) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(-8.95, -23.47, -6.02, -8.13, -16.61, -14.57)\n}\n```\n:::\n\n\n\n\n\n## (d)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nnormalized_importance_weights <- function(alpha, beta) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(0.045, 0.000, 0.852, 0.103, 0.000, 0.000)\n}\n```\n:::\n\n\n\n\n\n## (e)\n\n\nWrite your answers and code here!\n\n\n\n## (f)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nS_eff <- function(alpha, beta) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n 1.354\n}\n```\n:::\n\n\n\n\n\n## (g)\n\n\n## (h)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nposterior_mean <- function(alpha, beta) {\n # Do computation here, and return as below.\n # This is the correct return value for the test data provided above.\n c(0.503, 8.275)\n}\n```\n:::\n\n\n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## markmyassignment\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n\n\n\nThe following will check the functions for which `markmyassignment` has been set up:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmark_my_assignment()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nv | F W S OK | Context\n\n/ | 0 | task-1-subtask-1-tests \n/ | 0 | log_importance_weights() \nx | 2 3 | log_importance_weights()\n--------------------------------------------------------------------------------\nFailure ('test-task-1-subtask-1-tests.R:23:3'): log_importance_weights()\nlog_importance_weights(alpha, beta) not equivalent to c(...).\nLengths differ: 6 is not 10\nError: Incorrect result for alpha = c(4.5, 1.8, -2.4, 0.7, 0.3, -3.1, 0.4, 1.7, -0.5, -0.1) and beta = c(25.2, 7, -5.6, 1.1, 14.7, -6.5, 14.2, 25.9, 13.4, 19.8).\n\nFailure ('test-task-1-subtask-1-tests.R:31:3'): log_importance_weights()\nlog_importance_weights(alpha, beta) not equivalent to c(...).\nLengths differ: 6 is not 10\nError: Incorrect result for alpha = c(1.4, 1.5, -2.3, -2.3, -0.5, 1.9, 1.6, -1.8, -2.7, -1.9) and beta = c(11.4, 8.2, 10.8, 7.4, 18.2, 27.8, 5.1, 1.9, -15.7, 25.1).\n--------------------------------------------------------------------------------\n\n/ | 0 | task-2-subtask-1-tests \n/ | 0 | normalized_importance_weights() \nx | 2 3 | normalized_importance_weights()\n--------------------------------------------------------------------------------\nFailure ('test-task-2-subtask-1-tests.R:23:3'): normalized_importance_weights()\nnormalized_importance_weights(alpha, beta) not equivalent to c(0.03, 0.44, 0, 0.01, 0.18, 0, 0.25, 0.04, 0.04, 0.01).\nLengths differ: 6 is not 10\nError: Incorrect result for alpha = c(4.5, 1.8, -2.4, 0.7, 0.3, -3.1, 0.4, 1.7, -0.5, -0.1) and beta = c(25.2, 7, -5.6, 1.1, 14.7, -6.5, 14.2, 25.9, 13.4, 19.8).\n\nFailure ('test-task-2-subtask-1-tests.R:31:3'): normalized_importance_weights()\nnormalized_importance_weights(alpha, beta) not equivalent to c(0.47, 0.42, 0, 0, 0, 0.01, 0.09, 0, 0, 0).\nLengths differ: 6 is not 10\nError: Incorrect result for alpha = c(1.4, 1.5, -2.3, -2.3, -0.5, 1.9, 1.6, -1.8, -2.7, -1.9) and beta = c(11.4, 8.2, 10.8, 7.4, 18.2, 27.8, 5.1, 1.9, -15.7, 25.1).\n--------------------------------------------------------------------------------\n\n/ | 0 | task-3-subtask-1-tests \n/ | 0 | S_eff() \nx | 2 3 | S_eff()\n--------------------------------------------------------------------------------\nFailure ('test-task-3-subtask-1-tests.R:23:3'): S_eff()\nS_eff(alpha, beta) not equivalent to 3.404.\n1/1 mismatches\n[1] 1.35 - 3.4 == -2.05\nError: Incorrect result for alpha = c(4.5, 1.8, -2.4, 0.7, 0.3, -3.1, 0.4, 1.7, -0.5, -0.1) and beta = c(25.2, 7, -5.6, 1.1, 14.7, -6.5, 14.2, 25.9, 13.4, 19.8).\n\nFailure ('test-task-3-subtask-1-tests.R:31:3'): S_eff()\nS_eff(alpha, beta) not equivalent to 2.448.\n1/1 mismatches\n[1] 1.35 - 2.45 == -1.09\nError: Incorrect result for alpha = c(1.4, 1.5, -2.3, -2.3, -0.5, 1.9, 1.6, -1.8, -2.7, -1.9) and beta = c(11.4, 8.2, 10.8, 7.4, 18.2, 27.8, 5.1, 1.9, -15.7, 25.1).\n--------------------------------------------------------------------------------\n\n/ | 0 | task-4-subtask-1-tests \n/ | 0 | posterior_mean() \nx | 2 3 | posterior_mean()\n--------------------------------------------------------------------------------\nFailure ('test-task-4-subtask-1-tests.R:23:3'): posterior_mean()\nposterior_mean(alpha, beta) not equivalent to c(1.111039, 11.854793).\n2/2 mismatches (average diff: 2.09)\n[1] 0.503 - 1.11 == -0.608\n[2] 8.275 - 11.85 == -3.580\nError: Incorrect result for alpha = c(4.5, 1.8, -2.4, 0.7, 0.3, -3.1, 0.4, 1.7, -0.5, -0.1) and beta = c(25.2, 7, -5.6, 1.1, 14.7, -6.5, 14.2, 25.9, 13.4, 19.8).\n\nFailure ('test-task-4-subtask-1-tests.R:30:3'): posterior_mean()\nposterior_mean(alpha, beta) not equivalent to c(1.458649, 9.67896).\n2/2 mismatches (average diff: 1.18)\n[1] 0.503 - 1.46 == -0.956\n[2] 8.275 - 9.68 == -1.404\nError: Incorrect result for alpha = c(1.4, 1.5, -2.3, -2.3, -0.5, 1.9, 1.6, -1.8, -2.7, -1.9) and beta = c(11.4, 8.2, 10.8, 7.4, 18.2, 27.8, 5.1, 1.9, -15.7, 25.1).\n--------------------------------------------------------------------------------\n\n== Results =====================================================================\nDuration: 0.3 s\n\n[ FAIL 8 | WARN 0 | SKIP 0 | PASS 12 ]\n\nFrustration is a natural part of programming :)\n```\n:::\n:::\n\n\n\n:::\n::::\n", "supporting": [ "template4_files" ], diff --git a/assignments/_freeze/template5/figure-pdf/unnamed-chunk-7-1.pdf b/assignments/_freeze/template5/figure-pdf/unnamed-chunk-7-1.pdf index c5fa584d..22d29d7b 100644 Binary files a/assignments/_freeze/template5/figure-pdf/unnamed-chunk-7-1.pdf and b/assignments/_freeze/template5/figure-pdf/unnamed-chunk-7-1.pdf differ diff --git a/assignments/_freeze/template5/figure-pdf/unnamed-chunk-9-1.pdf b/assignments/_freeze/template5/figure-pdf/unnamed-chunk-9-1.pdf index 87d9c05c..17dafc2b 100644 Binary files a/assignments/_freeze/template5/figure-pdf/unnamed-chunk-9-1.pdf and b/assignments/_freeze/template5/figure-pdf/unnamed-chunk-9-1.pdf differ diff --git a/assignments/_freeze/template8/execute-results/html.json b/assignments/_freeze/template8/execute-results/html.json index f036991d..197c2200 100644 --- a/assignments/_freeze/template8/execute-results/html.json +++ b/assignments/_freeze/template8/execute-results/html.json @@ -1,7 +1,7 @@ { - "hash": "7757dcd06c573ff842279b83dcd6abc6", + "hash": "01a32670e8b678e33a6fcaf7d43a1d38", "result": { - "markdown": "---\ntitle: \"Assignment 8\"\nsubtitle: \"LOO-CV model comparison\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n page-layout: article\n pdf: \n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n# General information\n\nThis is the template for [assignment 8](assignment8.html). You can download the [qmd-file](https://avehtari.github.io/BDA_course_Aalto/assignments/template8.qmd) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.** \n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n \n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\n\nThe following loads several needed packages:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(bayesplot)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nThis is bayesplot version 1.10.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- Online documentation and vignettes at mc-stan.org/bayesplot\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- bayesplot theme set to bayesplot::theme_default()\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n * Does _not_ affect other ggplot2 plots\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n * See ?bayesplot_theme_set for details on theme setting\n```\n:::\n\n```{.r .cell-code}\nlibrary(cmdstanr)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nThis is cmdstanr version 0.5.3\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- CmdStanR documentation and vignettes: mc-stan.org/cmdstanr\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- CmdStan path: /root/.cmdstan/cmdstan-2.31.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- CmdStan version: 2.31.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n\nA newer version of CmdStan is available. See ?install_cmdstan() to install it.\nTo disable this check set option or environment variable CMDSTANR_NO_VER_CHECK=TRUE.\n```\n:::\n\n```{.r .cell-code}\nlibrary(dplyr)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\n\nAttaching package: 'dplyr'\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:stats':\n\n filter, lag\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:base':\n\n intersect, setdiff, setequal, union\n```\n:::\n\n```{.r .cell-code}\nlibrary(ggplot2)\nlibrary(ggdist) # for stat_dotsinterval\nlibrary(posterior)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nThis is posterior version 1.4.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n\nAttaching package: 'posterior'\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following object is masked from 'package:bayesplot':\n\n rhat\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:stats':\n\n mad, sd, var\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:base':\n\n %in%, match\n```\n:::\n\n```{.r .cell-code}\nlibrary(brms)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: Rcpp\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading 'brms' package (version 2.19.0). Useful instructions\ncan be found by typing help('brms'). A more detailed introduction\nto the package is available through vignette('brms_overview').\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n\nAttaching package: 'brms'\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:ggdist':\n\n dstudent_t, pstudent_t, qstudent_t, rstudent_t\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following object is masked from 'package:bayesplot':\n\n rhat\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following object is masked from 'package:stats':\n\n ar\n```\n:::\n\n```{.r .cell-code}\n# Globally specfiy cmdstan backend for brms\noptions(brms.backend=\"cmdstanr\")\n# Tell brms to cache results if possible\noptions(brms.file_refit=\"on_change\")\n\n# Set more readable themes with bigger font for plotting packages\nggplot2::theme_set(theme_minimal(base_size = 14))\nbayesplot::bayesplot_theme_set(theme_minimal(base_size = 14))\n```\n:::\n\n\n:::\n::::\n\n\n# A hierarchical model for chicken weight time series\n\n\n## Exploratory data analysis\n\n## (a)\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: ggplot, aes(x=...), geom_histogram\n```\n:::\n\n\n\n\n## (b)\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: ggplot, aes(x=...,y=...,group=...,color=...), geom_line\n```\n:::\n\n\n\n## Linear regression\n\n## (c)\n\n\nIn `brms`, a regression can be specified as below, see also [below (#m)](#m) or [the last template](template7.html#b-1). Fill in the appropriate variables,\ndata, and likelihood family. Specify the priors, then run the model (by removing `#| eval: false` below).\n\n\n::: {.cell}\n\n```{.r .cell-code}\npriors <- c(\n prior(normal(0, ), coef = \"Time\"),\n prior(normal(0, ), coef = \"Diet2\"),\n prior(normal(0, ), coef = \"Diet3\"),\n prior(normal(0, ), coef = \"Diet4\")\n)\n\nf1 <- brms::brm(\n # This specifies the formula\n ~ 1 + + ,\n # This specifies the dataset\n data = ,\n # This specifies the observation model family\n family = ,\n # This passes the priors specified above to brms\n prior = priors,\n # This causes brms to cache the results\n file = \"additional_files/assignment8/f1\"\n)\n```\n:::\n\n\n\n\n## (d)\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: brms::pp_check\n```\n:::\n\n\n\n\n## (e)\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: brms::pp_check(..., type = ..., group=...)\n```\n:::\n\n\n\n## Log-normal linear regression\n\n## (f)\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlog_priors <- c(\n prior(normal(0, log(3)), coef = \"Time\"),\n prior(normal(0, log(5)), coef = \"Diet2\"),\n prior(normal(0, log(5)), coef = \"Diet3\"),\n prior(normal(0, log(5)), coef = \"Diet4\")\n)\n```\n:::\n\n\n\n## Hierarchical log-normal linear regression\n\n## (g)\n\n\n## (h)\n\n## Model comparison using the ELPD\n\n## (i)\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: loo, loo_compare\n```\n:::\n\n\n\n\n## (j)\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: plot(loo(...), label_points = TRUE)\n```\n:::\n\n\n\n\n## (k)\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Creating a dummy example plot \n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\n\nCreating a dummy fit just to be able to generate an example plot below. \nGenerate a similar plot for your hierarchical model.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# The brms-formula (weights ~ ...) below is not one that you should be using in your models!\ndummy_fit <- brms::brm(\n weight ~ 1 + Time + Chick,\n data = ChickWeight,\n file=\"additional_files/assignment8/dummy_fit\"\n)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nStart sampling\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 1 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 2 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 3 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 \n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nChain 4 \n```\n:::\n\n```{.r .cell-code}\n# Adjust the chicken_idxs variable to select appropriate chickens\nchicken_idxs = c(1,3,11,43)\n# Create this plot for your hierarchical model for selected chickens\nbrms::pp_check(\n dummy_fit, type = \"intervals_grouped\", group = \"Chick\", \n newdata=ChickWeight |> filter(Chick %in% chicken_idxs)\n)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nUsing all posterior draws for ppc type 'intervals_grouped' by default.\n```\n:::\n\n::: {.cell-output-display}\n![](template8_files/figure-html/unnamed-chunk-10-1.png){width=672}\n:::\n:::\n\n\n:::\n::::\n\n\n## Model comparison using the RMSE\n\n## (l)\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## `rmse` function implementation\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\n\nThe below function takes a brms fit object and computes either the [root-mean-square error (RMSE)](https://en.wikipedia.org/wiki/Root-mean-square_deviation) or the PSIS-LOO-RMSE, i.e. the RMSE using LOO-CV estimated using PSIS-LOO.\n\n::: {.cell}\n\n```{.r .cell-code}\n# Compute RMSE or LOO-RMSE\nrmse <- function(fit, use_loo=FALSE){\n mean_y_pred <- if(use_loo){\n brms::loo_predict(fit)\n }else{\n colMeans(brms::posterior_predict(fit)) \n }\n sqrt(mean(\n (mean_y_pred - brms::get_y(fit))^2\n ))\n}\n```\n:::\n\n\n:::\n::::\n\n", + "markdown": "---\ntitle: \"Assignment 8\"\nsubtitle: \"LOO-CV model comparison\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n page-layout: article\n pdf: \n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n# General information\n\nThis is the template for [assignment 8](assignment8.html). You can download the [qmd-file](https://avehtari.github.io/BDA_course_Aalto/assignments/template8.qmd) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.** \n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n \n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\n\nThe following loads several needed packages:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(bayesplot)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nThis is bayesplot version 1.10.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- Online documentation and vignettes at mc-stan.org/bayesplot\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- bayesplot theme set to bayesplot::theme_default()\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n * Does _not_ affect other ggplot2 plots\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n * See ?bayesplot_theme_set for details on theme setting\n```\n:::\n\n```{.r .cell-code}\nlibrary(cmdstanr)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nThis is cmdstanr version 0.5.3\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- CmdStanR documentation and vignettes: mc-stan.org/cmdstanr\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- CmdStan path: /root/.cmdstan/cmdstan-2.31.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- CmdStan version: 2.31.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n\nA newer version of CmdStan is available. See ?install_cmdstan() to install it.\nTo disable this check set option or environment variable CMDSTANR_NO_VER_CHECK=TRUE.\n```\n:::\n\n```{.r .cell-code}\nlibrary(dplyr)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\n\nAttaching package: 'dplyr'\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:stats':\n\n filter, lag\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:base':\n\n intersect, setdiff, setequal, union\n```\n:::\n\n```{.r .cell-code}\nlibrary(ggplot2)\nlibrary(ggdist) # for stat_dotsinterval\nlibrary(posterior)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nThis is posterior version 1.4.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n\nAttaching package: 'posterior'\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following object is masked from 'package:bayesplot':\n\n rhat\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:stats':\n\n mad, sd, var\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:base':\n\n %in%, match\n```\n:::\n\n```{.r .cell-code}\nlibrary(brms)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: Rcpp\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading 'brms' package (version 2.19.0). Useful instructions\ncan be found by typing help('brms'). A more detailed introduction\nto the package is available through vignette('brms_overview').\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n\nAttaching package: 'brms'\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:ggdist':\n\n dstudent_t, pstudent_t, qstudent_t, rstudent_t\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following object is masked from 'package:bayesplot':\n\n rhat\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following object is masked from 'package:stats':\n\n ar\n```\n:::\n\n```{.r .cell-code}\n# Globally specfiy cmdstan backend for brms\noptions(brms.backend=\"cmdstanr\")\n# Tell brms to cache results if possible\noptions(brms.file_refit=\"on_change\")\n\n# Set more readable themes with bigger font for plotting packages\nggplot2::theme_set(theme_minimal(base_size = 14))\nbayesplot::bayesplot_theme_set(theme_minimal(base_size = 14))\n```\n:::\n\n\n:::\n::::\n\n\n# A hierarchical model for chicken weight time series\n\n\n## Exploratory data analysis\n\n## (a)\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: ggplot, aes(x=...), geom_histogram\n```\n:::\n\n\n\n\n## (b)\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: ggplot, aes(x=...,y=...,group=...,color=...), geom_line\n```\n:::\n\n\n\n## Linear regression\n\n## (c)\n\n\nIn `brms`, a regression can be specified as below, see also [below (#m)](#m) or [the last template](template7.html#b-1). Fill in the appropriate variables,\ndata, and likelihood family. Specify the priors, then run the model (by removing `#| eval: false` below).\n\n\n::: {.cell}\n\n```{.r .cell-code}\npriors <- c(\n prior(normal(0, ), coef = \"Time\"),\n prior(normal(0, ), coef = \"Diet2\"),\n prior(normal(0, ), coef = \"Diet3\"),\n prior(normal(0, ), coef = \"Diet4\")\n)\n\nf1 <- brms::brm(\n # This specifies the formula\n ~ 1 + + ,\n # This specifies the dataset\n data = ,\n # This specifies the observation model family\n family = ,\n # This passes the priors specified above to brms\n prior = priors,\n # This causes brms to cache the results\n file = \"additional_files/assignment8/f1\"\n)\n```\n:::\n\n\n\n\n## (d)\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: brms::pp_check\n```\n:::\n\n\n\n\n## (e)\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: brms::pp_check(..., type = ..., group=...)\n```\n:::\n\n\n\n## Log-normal linear regression\n\n## (f)\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlog_priors <- c(\n prior(normal(0, log(3)), coef = \"Time\"),\n prior(normal(0, log(5)), coef = \"Diet2\"),\n prior(normal(0, log(5)), coef = \"Diet3\"),\n prior(normal(0, log(5)), coef = \"Diet4\")\n)\n```\n:::\n\n\n\n## Hierarchical log-normal linear regression\n\n## (g)\n\n\n## (h)\n\n## Model comparison using the ELPD\n\n## (i)\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: loo, loo_compare\n```\n:::\n\n\n\n\n## (j)\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: plot(loo(...), label_points = TRUE)\n```\n:::\n\n\n\n\n## (k)\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Creating a dummy example plot \n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\n\nCreating a dummy fit just to be able to generate an example plot below. \nGenerate a similar plot for your hierarchical model.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# The brms-formula (weights ~ ...) below is not one that you should be using in your models!\ndummy_fit <- brms::brm(\n weight ~ 1 + Time + Chick,\n data = ChickWeight,\n file=\"additional_files/assignment8/dummy_fit\"\n)\n# Adjust the chicken_idxs variable to select appropriate chickens\nchicken_idxs = c(1,3,11,43)\n# Create this plot for your hierarchical model for selected chickens\nbrms::pp_check(\n dummy_fit, type = \"intervals_grouped\", group = \"Chick\", \n newdata=ChickWeight |> filter(Chick %in% chicken_idxs)\n)\n```\n:::\n\n\n:::\n::::\n\n\n## Model comparison using the RMSE\n\n## (l)\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## `rmse` function implementation\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\n\nThe below function takes a brms fit object and computes either the [root-mean-square error (RMSE)](https://en.wikipedia.org/wiki/Root-mean-square_deviation) or the PSIS-LOO-RMSE, i.e. the RMSE using LOO-CV estimated using PSIS-LOO.\n\n::: {.cell}\n\n```{.r .cell-code}\n# Compute RMSE or LOO-RMSE\nrmse <- function(fit, use_loo=FALSE){\n mean_y_pred <- if(use_loo){\n brms::loo_predict(fit)\n }else{\n colMeans(brms::posterior_predict(fit)) \n }\n sqrt(mean(\n (mean_y_pred - brms::get_y(fit))^2\n ))\n}\n```\n:::\n\n\n:::\n::::\n\n", "supporting": [ "template8_files" ], diff --git a/assignments/_freeze/template8/execute-results/tex.json b/assignments/_freeze/template8/execute-results/tex.json index 6ad2a8b7..9e186c00 100644 --- a/assignments/_freeze/template8/execute-results/tex.json +++ b/assignments/_freeze/template8/execute-results/tex.json @@ -1,7 +1,7 @@ { - "hash": "7757dcd06c573ff842279b83dcd6abc6", + "hash": "01a32670e8b678e33a6fcaf7d43a1d38", "result": { - "markdown": "---\ntitle: \"Assignment 8\"\nsubtitle: \"LOO-CV model comparison\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n page-layout: article\n pdf: \n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n\n# General information\n\nThis is the template for [assignment 8](assignment8.html). You can download the [qmd-file](https://avehtari.github.io/BDA_course_Aalto/assignments/template8.qmd) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.** \n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n \n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\n\nThe following loads several needed packages:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(bayesplot)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nThis is bayesplot version 1.10.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- Online documentation and vignettes at mc-stan.org/bayesplot\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- bayesplot theme set to bayesplot::theme_default()\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n * Does _not_ affect other ggplot2 plots\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n * See ?bayesplot_theme_set for details on theme setting\n```\n:::\n\n```{.r .cell-code}\nlibrary(cmdstanr)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nThis is cmdstanr version 0.5.3\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- CmdStanR documentation and vignettes: mc-stan.org/cmdstanr\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- CmdStan path: /root/.cmdstan/cmdstan-2.31.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- CmdStan version: 2.31.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n\nA newer version of CmdStan is available. See ?install_cmdstan() to install it.\nTo disable this check set option or environment variable CMDSTANR_NO_VER_CHECK=TRUE.\n```\n:::\n\n```{.r .cell-code}\nlibrary(dplyr)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\n\nAttaching package: 'dplyr'\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:stats':\n\n filter, lag\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:base':\n\n intersect, setdiff, setequal, union\n```\n:::\n\n```{.r .cell-code}\nlibrary(ggplot2)\nlibrary(ggdist) # for stat_dotsinterval\nlibrary(posterior)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nThis is posterior version 1.4.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n\nAttaching package: 'posterior'\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following object is masked from 'package:bayesplot':\n\n rhat\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:stats':\n\n mad, sd, var\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:base':\n\n %in%, match\n```\n:::\n\n```{.r .cell-code}\nlibrary(brms)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: Rcpp\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading 'brms' package (version 2.19.0). Useful instructions\ncan be found by typing help('brms'). A more detailed introduction\nto the package is available through vignette('brms_overview').\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n\nAttaching package: 'brms'\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:ggdist':\n\n dstudent_t, pstudent_t, qstudent_t, rstudent_t\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following object is masked from 'package:bayesplot':\n\n rhat\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following object is masked from 'package:stats':\n\n ar\n```\n:::\n\n```{.r .cell-code}\n# Globally specfiy cmdstan backend for brms\noptions(brms.backend=\"cmdstanr\")\n# Tell brms to cache results if possible\noptions(brms.file_refit=\"on_change\")\n\n# Set more readable themes with bigger font for plotting packages\nggplot2::theme_set(theme_minimal(base_size = 14))\nbayesplot::bayesplot_theme_set(theme_minimal(base_size = 14))\n```\n:::\n\n\n\n:::\n::::\n\n\n# A hierarchical model for chicken weight time series\n\n\n## Exploratory data analysis\n\n## (a)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: ggplot, aes(x=...), geom_histogram\n```\n:::\n\n\n\n\n\n## (b)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: ggplot, aes(x=...,y=...,group=...,color=...), geom_line\n```\n:::\n\n\n\n\n## Linear regression\n\n## (c)\n\n\nIn `brms`, a regression can be specified as below, see also [below (#m)](#m) or [the last template](template7.html#b-1). Fill in the appropriate variables,\ndata, and likelihood family. Specify the priors, then run the model (by removing `#| eval: false` below).\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\npriors <- c(\n prior(normal(0, ), coef = \"Time\"),\n prior(normal(0, ), coef = \"Diet2\"),\n prior(normal(0, ), coef = \"Diet3\"),\n prior(normal(0, ), coef = \"Diet4\")\n)\n\nf1 <- brms::brm(\n # This specifies the formula\n ~ 1 + + ,\n # This specifies the dataset\n data = ,\n # This specifies the observation model family\n family = ,\n # This passes the priors specified above to brms\n prior = priors,\n # This causes brms to cache the results\n file = \"additional_files/assignment8/f1\"\n)\n```\n:::\n\n\n\n\n\n## (d)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: brms::pp_check\n```\n:::\n\n\n\n\n\n## (e)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: brms::pp_check(..., type = ..., group=...)\n```\n:::\n\n\n\n\n## Log-normal linear regression\n\n## (f)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlog_priors <- c(\n prior(normal(0, log(3)), coef = \"Time\"),\n prior(normal(0, log(5)), coef = \"Diet2\"),\n prior(normal(0, log(5)), coef = \"Diet3\"),\n prior(normal(0, log(5)), coef = \"Diet4\")\n)\n```\n:::\n\n\n\n\n## Hierarchical log-normal linear regression\n\n## (g)\n\n\n## (h)\n\n## Model comparison using the ELPD\n\n## (i)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: loo, loo_compare\n```\n:::\n\n\n\n\n\n## (j)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: plot(loo(...), label_points = TRUE)\n```\n:::\n\n\n\n\n\n## (k)\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Creating a dummy example plot \n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\n\nCreating a dummy fit just to be able to generate an example plot below. \nGenerate a similar plot for your hierarchical model.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# The brms-formula (weights ~ ...) below is not one that you should be using in your models!\ndummy_fit <- brms::brm(\n weight ~ 1 + Time + Chick,\n data = ChickWeight,\n file=\"additional_files/assignment8/dummy_fit\"\n)\n# Adjust the chicken_idxs variable to select appropriate chickens\nchicken_idxs = c(1,3,11,43)\n# Create this plot for your hierarchical model for selected chickens\nbrms::pp_check(\n dummy_fit, type = \"intervals_grouped\", group = \"Chick\", \n newdata=ChickWeight |> filter(Chick %in% chicken_idxs)\n)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nUsing all posterior draws for ppc type 'intervals_grouped' by default.\n```\n:::\n\n::: {.cell-output-display}\n![](template8_files/figure-pdf/unnamed-chunk-10-1.pdf){fig-pos='H'}\n:::\n:::\n\n\n\n:::\n::::\n\n\n## Model comparison using the RMSE\n\n## (l)\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## `rmse` function implementation\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\n\nThe below function takes a brms fit object and computes either the [root-mean-square error (RMSE)](https://en.wikipedia.org/wiki/Root-mean-square_deviation) or the PSIS-LOO-RMSE, i.e. the RMSE using LOO-CV estimated using PSIS-LOO.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Compute RMSE or LOO-RMSE\nrmse <- function(fit, use_loo=FALSE){\n mean_y_pred <- if(use_loo){\n brms::loo_predict(fit)\n }else{\n colMeans(brms::posterior_predict(fit)) \n }\n sqrt(mean(\n (mean_y_pred - brms::get_y(fit))^2\n ))\n}\n```\n:::\n\n\n\n:::\n::::\n\n", + "markdown": "---\ntitle: \"Assignment 8\"\nsubtitle: \"LOO-CV model comparison\"\nauthor: anonymous # <-- hand in anonymously\nformat:\n html:\n toc: true\n code-tools: true\n code-line-numbers: true\n number-sections: true\n mainfont: Georgia, serif\n page-layout: article\n pdf: \n geometry:\n - left=1cm,top=1cm,bottom=1cm,right=7cm\n number-sections: true\n code-annotations: none\neditor: source\n---\n\n\n\n\n# General information\n\nThis is the template for [assignment 8](assignment8.html). You can download the [qmd-file](https://avehtari.github.io/BDA_course_Aalto/assignments/template8.qmd) or copy the code from this rendered document after clicking on ` Code` in the top right corner.\n\n**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.** \n\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n \n## Setup\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\n\nThe following loads several needed packages:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(bayesplot)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nThis is bayesplot version 1.10.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- Online documentation and vignettes at mc-stan.org/bayesplot\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- bayesplot theme set to bayesplot::theme_default()\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n * Does _not_ affect other ggplot2 plots\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n * See ?bayesplot_theme_set for details on theme setting\n```\n:::\n\n```{.r .cell-code}\nlibrary(cmdstanr)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nThis is cmdstanr version 0.5.3\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- CmdStanR documentation and vignettes: mc-stan.org/cmdstanr\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- CmdStan path: /root/.cmdstan/cmdstan-2.31.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n- CmdStan version: 2.31.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n\nA newer version of CmdStan is available. See ?install_cmdstan() to install it.\nTo disable this check set option or environment variable CMDSTANR_NO_VER_CHECK=TRUE.\n```\n:::\n\n```{.r .cell-code}\nlibrary(dplyr)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\n\nAttaching package: 'dplyr'\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:stats':\n\n filter, lag\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:base':\n\n intersect, setdiff, setequal, union\n```\n:::\n\n```{.r .cell-code}\nlibrary(ggplot2)\nlibrary(ggdist) # for stat_dotsinterval\nlibrary(posterior)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nThis is posterior version 1.4.0\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n\nAttaching package: 'posterior'\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following object is masked from 'package:bayesplot':\n\n rhat\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:stats':\n\n mad, sd, var\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:base':\n\n %in%, match\n```\n:::\n\n```{.r .cell-code}\nlibrary(brms)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading required package: Rcpp\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nLoading 'brms' package (version 2.19.0). Useful instructions\ncan be found by typing help('brms'). A more detailed introduction\nto the package is available through vignette('brms_overview').\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n\nAttaching package: 'brms'\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following objects are masked from 'package:ggdist':\n\n dstudent_t, pstudent_t, qstudent_t, rstudent_t\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following object is masked from 'package:bayesplot':\n\n rhat\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following object is masked from 'package:stats':\n\n ar\n```\n:::\n\n```{.r .cell-code}\n# Globally specfiy cmdstan backend for brms\noptions(brms.backend=\"cmdstanr\")\n# Tell brms to cache results if possible\noptions(brms.file_refit=\"on_change\")\n\n# Set more readable themes with bigger font for plotting packages\nggplot2::theme_set(theme_minimal(base_size = 14))\nbayesplot::bayesplot_theme_set(theme_minimal(base_size = 14))\n```\n:::\n\n\n\n:::\n::::\n\n\n# A hierarchical model for chicken weight time series\n\n\n## Exploratory data analysis\n\n## (a)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: ggplot, aes(x=...), geom_histogram\n```\n:::\n\n\n\n\n\n## (b)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: ggplot, aes(x=...,y=...,group=...,color=...), geom_line\n```\n:::\n\n\n\n\n## Linear regression\n\n## (c)\n\n\nIn `brms`, a regression can be specified as below, see also [below (#m)](#m) or [the last template](template7.html#b-1). Fill in the appropriate variables,\ndata, and likelihood family. Specify the priors, then run the model (by removing `#| eval: false` below).\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\npriors <- c(\n prior(normal(0, ), coef = \"Time\"),\n prior(normal(0, ), coef = \"Diet2\"),\n prior(normal(0, ), coef = \"Diet3\"),\n prior(normal(0, ), coef = \"Diet4\")\n)\n\nf1 <- brms::brm(\n # This specifies the formula\n ~ 1 + + ,\n # This specifies the dataset\n data = ,\n # This specifies the observation model family\n family = ,\n # This passes the priors specified above to brms\n prior = priors,\n # This causes brms to cache the results\n file = \"additional_files/assignment8/f1\"\n)\n```\n:::\n\n\n\n\n\n## (d)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: brms::pp_check\n```\n:::\n\n\n\n\n\n## (e)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: brms::pp_check(..., type = ..., group=...)\n```\n:::\n\n\n\n\n## Log-normal linear regression\n\n## (f)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlog_priors <- c(\n prior(normal(0, log(3)), coef = \"Time\"),\n prior(normal(0, log(5)), coef = \"Diet2\"),\n prior(normal(0, log(5)), coef = \"Diet3\"),\n prior(normal(0, log(5)), coef = \"Diet4\")\n)\n```\n:::\n\n\n\n\n## Hierarchical log-normal linear regression\n\n## (g)\n\n\n## (h)\n\n## Model comparison using the ELPD\n\n## (i)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: loo, loo_compare\n```\n:::\n\n\n\n\n\n## (j)\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Useful functions: plot(loo(...), label_points = TRUE)\n```\n:::\n\n\n\n\n\n## (k)\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## Creating a dummy example plot \n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\n\nCreating a dummy fit just to be able to generate an example plot below. \nGenerate a similar plot for your hierarchical model.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# The brms-formula (weights ~ ...) below is not one that you should be using in your models!\ndummy_fit <- brms::brm(\n weight ~ 1 + Time + Chick,\n data = ChickWeight,\n file=\"additional_files/assignment8/dummy_fit\"\n)\n# Adjust the chicken_idxs variable to select appropriate chickens\nchicken_idxs = c(1,3,11,43)\n# Create this plot for your hierarchical model for selected chickens\nbrms::pp_check(\n dummy_fit, type = \"intervals_grouped\", group = \"Chick\", \n newdata=ChickWeight |> filter(Chick %in% chicken_idxs)\n)\n```\n:::\n\n\n\n:::\n::::\n\n\n## Model comparison using the RMSE\n\n## (l)\n\n\n:::: {.content-hidden when-format=\"pdf\"}\n::: {.callout-warning collapse=false}\n\n## `rmse` function implementation\n\n\n*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.*\n**Make sure that this does not get displayed in the PDF!**\n \n\n\n\nThe below function takes a brms fit object and computes either the [root-mean-square error (RMSE)](https://en.wikipedia.org/wiki/Root-mean-square_deviation) or the PSIS-LOO-RMSE, i.e. the RMSE using LOO-CV estimated using PSIS-LOO.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Compute RMSE or LOO-RMSE\nrmse <- function(fit, use_loo=FALSE){\n mean_y_pred <- if(use_loo){\n brms::loo_predict(fit)\n }else{\n colMeans(brms::posterior_predict(fit)) \n }\n sqrt(mean(\n (mean_y_pred - brms::get_y(fit))^2\n ))\n}\n```\n:::\n\n\n\n:::\n::::\n\n", "supporting": [ "template8_files/figure-pdf" ], diff --git a/assignments/_freeze/template8/figure-html/unnamed-chunk-10-1.png b/assignments/_freeze/template8/figure-html/unnamed-chunk-10-1.png index 98cccd22..0c398686 100644 Binary files a/assignments/_freeze/template8/figure-html/unnamed-chunk-10-1.png and b/assignments/_freeze/template8/figure-html/unnamed-chunk-10-1.png differ diff --git a/assignments/_freeze/template8/figure-pdf/unnamed-chunk-10-1.pdf b/assignments/_freeze/template8/figure-pdf/unnamed-chunk-10-1.pdf index 7a7fdd61..7bf62a06 100644 Binary files a/assignments/_freeze/template8/figure-pdf/unnamed-chunk-10-1.pdf and b/assignments/_freeze/template8/figure-pdf/unnamed-chunk-10-1.pdf differ diff --git a/assignments/_freeze/template9/figure-html/fit-1.png b/assignments/_freeze/template9/figure-html/fit-1.png index 4cb2d95b..11ecaec3 100644 Binary files a/assignments/_freeze/template9/figure-html/fit-1.png and b/assignments/_freeze/template9/figure-html/fit-1.png differ diff --git a/assignments/_freeze/template9/figure-pdf/fit-1.pdf b/assignments/_freeze/template9/figure-pdf/fit-1.pdf index 35673660..72e5e9a3 100644 Binary files a/assignments/_freeze/template9/figure-pdf/fit-1.pdf and b/assignments/_freeze/template9/figure-pdf/fit-1.pdf differ diff --git a/assignments/additional_files/assignment8/dummy_fit.rds b/assignments/additional_files/assignment8/dummy_fit.rds index 3e911c5a..2a9e9fa6 100644 Binary files a/assignments/additional_files/assignment8/dummy_fit.rds and b/assignments/additional_files/assignment8/dummy_fit.rds differ diff --git a/assignments/assignment_instructions.pdf b/assignments/assignment_instructions.pdf index f9e6dfd3..4275cf47 100644 Binary files a/assignments/assignment_instructions.pdf and b/assignments/assignment_instructions.pdf differ diff --git a/assignments/search.json b/assignments/search.json index ec6fcc4c..7cfa5387 100644 --- a/assignments/search.json +++ b/assignments/search.json @@ -123,7 +123,7 @@ "href": "template1.html#a-4", "title": "Assignment 1", "section": "7.1 (a)", - "text": "7.1 (a)\n\n\n\n\n\n\nmarkmyassignment\n\n\n\n\n\nThis 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!\nThe following will check the functions for which markmyassignment has been set up:\n\nmark_my_assignment()\n\n✔ | F W S OK | Context\n\n⠏ | 0 | task-1-subtask-1-tests \n⠏ | 0 | p_red() \n✖ | 1 3 | p_red() [0.1s]\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-1-subtask-1-tests.R:21:3'): p_red()\np_red(boxes = boxes) not equivalent to 0.5.\n1/1 mismatches\n[1] 0.393 - 0.5 == -0.107\nError: Incorrect result for matrix(c(1,1,1,1,1,1), ncol = 2)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-2-subtask-1-tests \n⠏ | 0 | p_box() \n✖ | 1 3 | p_box()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-2-subtask-1-tests.R:19:3'): p_box()\np_box(boxes = boxes) not equivalent to c(0.4, 0.1, 0.5).\n3/3 mismatches (average diff: 0.0909)\n[1] 0.2909 - 0.4 == -0.1091\n[2] 0.0727 - 0.1 == -0.0273\n[3] 0.6364 - 0.5 == 0.1364\nError: Incorrect result for matrix(c(1,1,1,1,1,1), ncol = 2)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-3-subtask-1-tests \n⠏ | 0 | p_identical_twin() \n✖ | 2 3 | p_identical_twin()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-3-subtask-1-tests.R:16:3'): p_identical_twin()\np_identical_twin(fraternal_prob = 1/100, identical_prob = 1/500) not equivalent to 0.2857143.\n1/1 mismatches\n[1] 0.455 - 0.286 == 0.169\nError: Incorrect result for fraternal_prob = 1/100 and identical_prob = 1/500\n\nFailure ('test-task-3-subtask-1-tests.R:19:3'): p_identical_twin()\np_identical_twin(fraternal_prob = 1/10, identical_prob = 1/20) not equivalent to 0.5.\n1/1 mismatches\n[1] 0.455 - 0.5 == -0.0455\nError: Incorrect result for fraternal_prob = 1/10 and identical_prob = 1/20\n────────────────────────────────────────────────────────────────────────────────\n\n══ Results ═════════════════════════════════════════════════════════════════════\nDuration: 0.2 s\n\n[ FAIL 4 | WARN 0 | SKIP 0 | PASS 9 ]" + "text": "7.1 (a)\n\n\n\n\n\n\nmarkmyassignment\n\n\n\n\n\nThis 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!\nThe following will check the functions for which markmyassignment has been set up:\n\nmark_my_assignment()\n\n✔ | F W S OK | Context\n\n⠏ | 0 | task-1-subtask-1-tests \n⠏ | 0 | p_red() \n✖ | 1 3 | p_red()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-1-subtask-1-tests.R:21:3'): p_red()\np_red(boxes = boxes) not equivalent to 0.5.\n1/1 mismatches\n[1] 0.393 - 0.5 == -0.107\nError: Incorrect result for matrix(c(1,1,1,1,1,1), ncol = 2)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-2-subtask-1-tests \n⠏ | 0 | p_box() \n✖ | 1 3 | p_box()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-2-subtask-1-tests.R:19:3'): p_box()\np_box(boxes = boxes) not equivalent to c(0.4, 0.1, 0.5).\n3/3 mismatches (average diff: 0.0909)\n[1] 0.2909 - 0.4 == -0.1091\n[2] 0.0727 - 0.1 == -0.0273\n[3] 0.6364 - 0.5 == 0.1364\nError: Incorrect result for matrix(c(1,1,1,1,1,1), ncol = 2)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-3-subtask-1-tests \n⠏ | 0 | p_identical_twin() \n✖ | 2 3 | p_identical_twin()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-3-subtask-1-tests.R:16:3'): p_identical_twin()\np_identical_twin(fraternal_prob = 1/100, identical_prob = 1/500) not equivalent to 0.2857143.\n1/1 mismatches\n[1] 0.455 - 0.286 == 0.169\nError: Incorrect result for fraternal_prob = 1/100 and identical_prob = 1/500\n\nFailure ('test-task-3-subtask-1-tests.R:19:3'): p_identical_twin()\np_identical_twin(fraternal_prob = 1/10, identical_prob = 1/20) not equivalent to 0.5.\n1/1 mismatches\n[1] 0.455 - 0.5 == -0.0455\nError: Incorrect result for fraternal_prob = 1/10 and identical_prob = 1/20\n────────────────────────────────────────────────────────────────────────────────\n\n══ Results ═════════════════════════════════════════════════════════════════════\nDuration: 0.2 s\n\n[ FAIL 4 | WARN 0 | SKIP 0 | PASS 9 ]" }, { "objectID": "template8.html", @@ -242,7 +242,7 @@ "href": "template8.html#k", "title": "Assignment 8", "section": "2.16 (k)", - "text": "2.16 (k)\n\n\n\n\n\n\nCreating a dummy example plot\n\n\n\n\n\nThis 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!\nCreating a dummy fit just to be able to generate an example plot below. Generate a similar plot for your hierarchical model.\n\n# The brms-formula (weights ~ ...) below is not one that you should be using in your models!\ndummy_fit <- brms::brm(\n weight ~ 1 + Time + Chick,\n data = ChickWeight,\n file=\"additional_files/assignment8/dummy_fit\"\n)\n\nStart sampling\n\n\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 1 \n\n\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 1 \n\n\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 1 \n\n\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 1 \n\n\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 1 \n\n\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 1 \n\n\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 1 \n\n\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 1 \n\n\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 1 \n\n\nChain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 1 \n\n\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 2 \n\n\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 2 \n\n\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 2 \n\n\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 2 \n\n\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 2 \n\n\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 2 \n\n\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 2 \n\n\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 2 \n\n\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 2 \n\n\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 2 \n\n\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 2 \n\n\nChain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 2 \n\n\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 3 \n\n\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 3 \n\n\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 3 \n\n\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 3 \n\n\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 3 \n\n\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 3 \n\n\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 3 \n\n\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 3 \n\n\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 3 \n\n\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 3 \n\n\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 3 \n\n\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 3 \n\n\nChain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 3 \n\n\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 4 \n\n\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 4 \n\n\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 4 \n\n\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 4 \n\n\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 4 \n\n\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 4 \n\n\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 4 \n\n\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 4 \n\n\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 4 \n\n\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 4 \n\n\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 4 \n\n\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 4 \n\n\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 4 \n\n\nChain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:\n\n\nChain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)\n\n\nChain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,\n\n\nChain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.\n\n\nChain 4 \n\n# Adjust the chicken_idxs variable to select appropriate chickens\nchicken_idxs = c(1,3,11,43)\n# Create this plot for your hierarchical model for selected chickens\nbrms::pp_check(\n dummy_fit, type = \"intervals_grouped\", group = \"Chick\", \n newdata=ChickWeight |> filter(Chick %in% chicken_idxs)\n)\n\nUsing all posterior draws for ppc type 'intervals_grouped' by default." + "text": "2.16 (k)\n\n\n\n\n\n\nCreating a dummy example plot\n\n\n\n\n\nThis 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!\nCreating a dummy fit just to be able to generate an example plot below. Generate a similar plot for your hierarchical model.\n\n# The brms-formula (weights ~ ...) below is not one that you should be using in your models!\ndummy_fit <- brms::brm(\n weight ~ 1 + Time + Chick,\n data = ChickWeight,\n file=\"additional_files/assignment8/dummy_fit\"\n)\n# Adjust the chicken_idxs variable to select appropriate chickens\nchicken_idxs = c(1,3,11,43)\n# Create this plot for your hierarchical model for selected chickens\nbrms::pp_check(\n dummy_fit, type = \"intervals_grouped\", group = \"Chick\", \n newdata=ChickWeight |> filter(Chick %in% chicken_idxs)\n)" }, { "objectID": "template8.html#model-comparison-using-the-rmse", @@ -746,7 +746,7 @@ "href": "template3.html#c-2", "title": "Assignment 3", "section": "4.3 (c)", - "text": "4.3 (c)\nWrite your answers here!\n\n\n\n\n\n\nmarkmyassignment\n\n\n\n\n\nThis 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!\nThe following will check the functions for which markmyassignment has been set up:\n\nmark_my_assignment()\n\n✔ | F W S OK | Context\n\n⠏ | 0 | task-1-subtask-1-tests \n⠏ | 0 | mu_point_est() \n✖ | 1 3 | mu_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-1-subtask-1-tests.R:17:3'): mu_point_est()\nmu_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-2-subtask-1-tests \n⠏ | 0 | mu_interval() \n✖ | 2 3 | mu_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-2-subtask-1-tests.R:15:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.95) not equivalent to c(3.3, 7.7).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 3.3 == 10\n[2] 15.7 - 7.7 == 8\nError: Incorrect result for 1:10 using a 95% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:16:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.8) not equivalent to c(4.2, 6.8).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 4.2 == 9.1\n[2] 15.7 - 6.8 == 8.9\nError: Incorrect result for 1:10 using a 80% interval.\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-3-subtask-1-tests \n⠏ | 0 | mu_pred_interval() \n✖ | 2 3 | mu_pred_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-3-subtask-1-tests.R:16:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.95) not equivalent to c(-1.7, 12.7).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - -1.7 == 13.5\n[2] 17.2 - 12.7 == 4.5\nError: Incorrect result for 1:10, (95%)\n\nFailure ('test-task-3-subtask-1-tests.R:18:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.8) not equivalent to c(1.1, 9.9).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - 1.1 == 10.7\n[2] 17.2 - 9.9 == 7.3\nError: Incorrect result for 1:10, (80%)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-4-subtask-1-tests \n⠏ | 0 | mu_pred_point_est() \n✖ | 1 3 | mu_pred_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-4-subtask-1-tests.R:16:3'): mu_pred_point_est()\nmu_pred_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-5-subtask-1-tests \n⠏ | 0 | posterior_odds_ratio_point_est() \n✖ | 3 3 | posterior_odds_ratio_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-5-subtask-1-tests.R:18:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 0.5307909.\n1/1 mismatches\n[1] 2.65 - 0.531 == 2.12\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90).\n\nFailure ('test-task-5-subtask-1-tests.R:24:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p0, p1) not equivalent to 1.876519.\n1/1 mismatches\n[1] 2.65 - 1.88 == 0.774\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6).\n\nFailure ('test-task-5-subtask-1-tests.R:25:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 1.24902.\n1/1 mismatches\n[1] 2.65 - 1.25 == 1.4\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5).\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-6-subtask-1-tests \n⠏ | 0 | posterior_odds_ratio_interval() \n⠧ | 6 2 | posterior_odds_ratio_interval() \n✖ | 6 2 | posterior_odds_ratio_interval() [0.1s]\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-6-subtask-1-tests.R:17:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.875367, 6.05911).\n2/2 mismatches (average diff: 0.719)\n[1] 0.68 - 0.875 == -0.196\n[2] 7.30 - 6.059 == 1.242\nError: Incorrect result for p0 = rbeta(100000, 5, 95), p1 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:19:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1650407, 1.142378).\n2/2 mismatches (average diff: 3.34)\n[1] 0.68 - 0.165 == 0.515\n[2] 7.30 - 1.142 == 6.159\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:21:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.2086461, 0.9392956).\n2/2 mismatches (average diff: 3.42)\n[1] 0.68 - 0.209 == 0.471\n[2] 7.30 - 0.939 == 6.362\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 80%.\n\nFailure ('test-task-6-subtask-1-tests.R:27:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.2714472, 5.5970131).\n2/2 mismatches (average diff: 1.06)\n[1] 0.68 - 0.271 == 0.408\n[2] 7.30 - 5.597 == 1.705\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:29:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1786667, 3.6839583).\n2/2 mismatches (average diff: 2.06)\n[1] 0.68 - 0.179 == 0.501\n[2] 7.30 - 3.684 == 3.618\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:31:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.252972, 2.633517).\n2/2 mismatches (average diff: 2.55)\n[1] 0.68 - 0.253 == 0.427\n[2] 7.30 - 2.634 == 4.668\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 80%.\n────────────────────────────────────────────────────────────────────────────────\nMaximum number of failures exceeded; quitting at end of file.\nℹ Increase this number with (e.g.) `testthat::set_max_fails(Inf)` \n\n══ Results ═════════════════════════════════════════════════════════════════════\nDuration: 0.6 s\n\n[ FAIL 15 | WARN 0 | SKIP 0 | PASS 17 ]\n══ Terminated early ════════════════════════════════════════════════════════════" + "text": "4.3 (c)\nWrite your answers here!\n\n\n\n\n\n\nmarkmyassignment\n\n\n\n\n\nThis 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!\nThe following will check the functions for which markmyassignment has been set up:\n\nmark_my_assignment()\n\n✔ | F W S OK | Context\n\n⠏ | 0 | task-1-subtask-1-tests \n⠏ | 0 | mu_point_est() \n✖ | 1 3 | mu_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-1-subtask-1-tests.R:17:3'): mu_point_est()\nmu_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-2-subtask-1-tests \n⠏ | 0 | mu_interval() \n✖ | 2 3 | mu_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-2-subtask-1-tests.R:15:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.95) not equivalent to c(3.3, 7.7).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 3.3 == 10\n[2] 15.7 - 7.7 == 8\nError: Incorrect result for 1:10 using a 95% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:16:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.8) not equivalent to c(4.2, 6.8).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 4.2 == 9.1\n[2] 15.7 - 6.8 == 8.9\nError: Incorrect result for 1:10 using a 80% interval.\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-3-subtask-1-tests \n⠏ | 0 | mu_pred_interval() \n✖ | 2 3 | mu_pred_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-3-subtask-1-tests.R:16:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.95) not equivalent to c(-1.7, 12.7).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - -1.7 == 13.5\n[2] 17.2 - 12.7 == 4.5\nError: Incorrect result for 1:10, (95%)\n\nFailure ('test-task-3-subtask-1-tests.R:18:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.8) not equivalent to c(1.1, 9.9).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - 1.1 == 10.7\n[2] 17.2 - 9.9 == 7.3\nError: Incorrect result for 1:10, (80%)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-4-subtask-1-tests \n⠏ | 0 | mu_pred_point_est() \n✖ | 1 3 | mu_pred_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-4-subtask-1-tests.R:16:3'): mu_pred_point_est()\nmu_pred_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-5-subtask-1-tests \n⠏ | 0 | posterior_odds_ratio_point_est() \n✖ | 3 3 | posterior_odds_ratio_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-5-subtask-1-tests.R:18:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 0.5307909.\n1/1 mismatches\n[1] 2.65 - 0.531 == 2.12\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90).\n\nFailure ('test-task-5-subtask-1-tests.R:24:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p0, p1) not equivalent to 1.876519.\n1/1 mismatches\n[1] 2.65 - 1.88 == 0.774\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6).\n\nFailure ('test-task-5-subtask-1-tests.R:25:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 1.24902.\n1/1 mismatches\n[1] 2.65 - 1.25 == 1.4\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5).\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-6-subtask-1-tests \n⠏ | 0 | posterior_odds_ratio_interval() \n✖ | 6 2 | posterior_odds_ratio_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-6-subtask-1-tests.R:17:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.875367, 6.05911).\n2/2 mismatches (average diff: 0.719)\n[1] 0.68 - 0.875 == -0.196\n[2] 7.30 - 6.059 == 1.242\nError: Incorrect result for p0 = rbeta(100000, 5, 95), p1 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:19:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1650407, 1.142378).\n2/2 mismatches (average diff: 3.34)\n[1] 0.68 - 0.165 == 0.515\n[2] 7.30 - 1.142 == 6.159\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:21:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.2086461, 0.9392956).\n2/2 mismatches (average diff: 3.42)\n[1] 0.68 - 0.209 == 0.471\n[2] 7.30 - 0.939 == 6.362\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 80%.\n\nFailure ('test-task-6-subtask-1-tests.R:27:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.2714472, 5.5970131).\n2/2 mismatches (average diff: 1.06)\n[1] 0.68 - 0.271 == 0.408\n[2] 7.30 - 5.597 == 1.705\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:29:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1786667, 3.6839583).\n2/2 mismatches (average diff: 2.06)\n[1] 0.68 - 0.179 == 0.501\n[2] 7.30 - 3.684 == 3.618\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:31:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.252972, 2.633517).\n2/2 mismatches (average diff: 2.55)\n[1] 0.68 - 0.253 == 0.427\n[2] 7.30 - 2.634 == 4.668\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 80%.\n────────────────────────────────────────────────────────────────────────────────\nMaximum number of failures exceeded; quitting at end of file.\nℹ Increase this number with (e.g.) `testthat::set_max_fails(Inf)` \n\n══ Results ═════════════════════════════════════════════════════════════════════\nDuration: 0.5 s\n\n[ FAIL 15 | WARN 0 | SKIP 0 | PASS 17 ]\n══ Terminated early ════════════════════════════════════════════════════════════" }, { "objectID": "index.html", @@ -816,7 +816,7 @@ "href": "template2.html#e", "title": "Assignment 2", "section": "2.5 (e)", - "text": "2.5 (e)\nPlot the PDFs here. Explain shortly what you do.\n\n# Useful function: dbeta()\n\n\n\n\n\n\n\nmarkmyassignment\n\n\n\n\n\nThis 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!\nThe following will check the functions for which markmyassignment has been set up:\n\nmark_my_assignment()\n\n✔ | F W S OK | Context\n\n⠏ | 0 | task-1-subtask-1-tests \n⠏ | 0 | beta_point_est() \n⠹ | 1 2 | beta_point_est() \n✖ | 3 2 | beta_point_est() [0.1s]\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-1-subtask-1-tests.R:16:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.222 - 0.5 == -0.278\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1)\n\nFailure ('test-task-1-subtask-1-tests.R:23:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.222 - 0.5 == -0.278\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1)\n\nFailure ('test-task-1-subtask-1-tests.R:30:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5555556).\n1/1 mismatches\n[1] 0.222 - 0.556 == -0.333\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-2-subtask-1-tests \n⠏ | 0 | beta_interval() \n✖ | 3 2 | beta_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-2-subtask-1-tests.R:16:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.2712499, 0.7287501).\n2/2 mismatches (average diff: 0.26)\n[1] 0.0846 - 0.271 == -0.187\n[2] 0.3956 - 0.729 == -0.333\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1) and 90% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:23:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.2999865, 0.7000135).\n2/2 mismatches (average diff: 0.26)\n[1] 0.0846 - 0.3 == -0.215\n[2] 0.3956 - 0.7 == -0.304\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1) and 90% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:30:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.3640088, 0.7398856).\n2/2 mismatches (average diff: 0.312)\n[1] 0.0846 - 0.364 == -0.279\n[2] 0.3956 - 0.740 == -0.344\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1) and 90% interval.\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-3-subtask-1-tests \n⠏ | 0 | beta_low() \n✖ | 3 2 | beta_low()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-3-subtask-1-tests.R:16:3'): beta_low()\nbeta_low(...) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.451 - 0.5 == -0.0489\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1)\n\nFailure ('test-task-3-subtask-1-tests.R:23:3'): beta_low()\nbeta_low(...) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.451 - 0.5 == -0.0489\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1)\n\nFailure ('test-task-3-subtask-1-tests.R:30:3'): beta_low()\nbeta_low(...) not equivalent to 0.0004932497.\n1/1 mismatches\n[1] 0.451 - 0.000493 == 0.451\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1)\n────────────────────────────────────────────────────────────────────────────────\n\n══ Results ═════════════════════════════════════════════════════════════════════\nDuration: 0.4 s\n\n[ FAIL 9 | WARN 0 | SKIP 0 | PASS 6 ]" + "text": "2.5 (e)\nPlot the PDFs here. Explain shortly what you do.\n\n# Useful function: dbeta()\n\n\n\n\n\n\n\nmarkmyassignment\n\n\n\n\n\nThis 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!\nThe following will check the functions for which markmyassignment has been set up:\n\nmark_my_assignment()\n\n✔ | F W S OK | Context\n\n⠏ | 0 | task-1-subtask-1-tests \n⠏ | 0 | beta_point_est() \n✖ | 3 2 | beta_point_est() [0.1s]\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-1-subtask-1-tests.R:16:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.222 - 0.5 == -0.278\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1)\n\nFailure ('test-task-1-subtask-1-tests.R:23:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.222 - 0.5 == -0.278\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1)\n\nFailure ('test-task-1-subtask-1-tests.R:30:3'): beta_point_est()\nbeta_point_est(prior_alpha = alpha, prior_beta = beta, data = test) not equivalent to c(0.5555556).\n1/1 mismatches\n[1] 0.222 - 0.556 == -0.333\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-2-subtask-1-tests \n⠏ | 0 | beta_interval() \n✖ | 3 2 | beta_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-2-subtask-1-tests.R:16:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.2712499, 0.7287501).\n2/2 mismatches (average diff: 0.26)\n[1] 0.0846 - 0.271 == -0.187\n[2] 0.3956 - 0.729 == -0.333\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1) and 90% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:23:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.2999865, 0.7000135).\n2/2 mismatches (average diff: 0.26)\n[1] 0.0846 - 0.3 == -0.215\n[2] 0.3956 - 0.7 == -0.304\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1) and 90% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:30:3'): beta_interval()\nbeta_interval(...) not equivalent to c(0.3640088, 0.7398856).\n2/2 mismatches (average diff: 0.312)\n[1] 0.0846 - 0.364 == -0.279\n[2] 0.3956 - 0.740 == -0.344\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1) and 90% interval.\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-3-subtask-1-tests \n⠏ | 0 | beta_low() \n✖ | 3 2 | beta_low()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-3-subtask-1-tests.R:16:3'): beta_low()\nbeta_low(...) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.451 - 0.5 == -0.0489\nError: Incorrect result for prior_alpha = 2, prior_beta = 4 and data = c(0, 1, 1, 0, 1, 1)\n\nFailure ('test-task-3-subtask-1-tests.R:23:3'): beta_low()\nbeta_low(...) not equivalent to c(0.5).\n1/1 mismatches\n[1] 0.451 - 0.5 == -0.0489\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1)\n\nFailure ('test-task-3-subtask-1-tests.R:30:3'): beta_low()\nbeta_low(...) not equivalent to 0.0004932497.\n1/1 mismatches\n[1] 0.451 - 0.000493 == 0.451\nError: Incorrect result for prior_alpha = 3, prior_beta = 5 and data = c(0, 1, 1, 0, 1, 1, 0, 1, 1, 1)\n────────────────────────────────────────────────────────────────────────────────\n\n══ Results ═════════════════════════════════════════════════════════════════════\nDuration: 0.3 s\n\n[ FAIL 9 | WARN 0 | SKIP 0 | PASS 6 ]" }, { "objectID": "assignment3.html", @@ -900,6 +900,6 @@ "href": "simple_template3.html#c-2", "title": "Assignment 3", "section": "4.3 (c)", - "text": "4.3 (c)\nWrite your answers here!\n\n\n\n\n\n\nmarkmyassignment\n\n\n\n\n\nThis 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!\nThe following will check the functions for which markmyassignment has been set up:\n\nmark_my_assignment()\n\n✔ | F W S OK | Context\n\n⠏ | 0 | task-1-subtask-1-tests \n⠏ | 0 | mu_point_est() \n✖ | 1 3 | mu_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-1-subtask-1-tests.R:17:3'): mu_point_est()\nmu_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-2-subtask-1-tests \n⠏ | 0 | mu_interval() \n✖ | 2 3 | mu_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-2-subtask-1-tests.R:15:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.95) not equivalent to c(3.3, 7.7).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 3.3 == 10\n[2] 15.7 - 7.7 == 8\nError: Incorrect result for 1:10 using a 95% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:16:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.8) not equivalent to c(4.2, 6.8).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 4.2 == 9.1\n[2] 15.7 - 6.8 == 8.9\nError: Incorrect result for 1:10 using a 80% interval.\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-3-subtask-1-tests \n⠏ | 0 | mu_pred_interval() \n✖ | 2 3 | mu_pred_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-3-subtask-1-tests.R:16:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.95) not equivalent to c(-1.7, 12.7).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - -1.7 == 13.5\n[2] 17.2 - 12.7 == 4.5\nError: Incorrect result for 1:10, (95%)\n\nFailure ('test-task-3-subtask-1-tests.R:18:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.8) not equivalent to c(1.1, 9.9).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - 1.1 == 10.7\n[2] 17.2 - 9.9 == 7.3\nError: Incorrect result for 1:10, (80%)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-4-subtask-1-tests \n⠏ | 0 | mu_pred_point_est() \n✖ | 1 3 | mu_pred_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-4-subtask-1-tests.R:16:3'): mu_pred_point_est()\nmu_pred_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-5-subtask-1-tests \n⠏ | 0 | posterior_odds_ratio_point_est() \n✖ | 3 3 | posterior_odds_ratio_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-5-subtask-1-tests.R:18:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 0.5307909.\n1/1 mismatches\n[1] 2.65 - 0.531 == 2.12\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90).\n\nFailure ('test-task-5-subtask-1-tests.R:24:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p0, p1) not equivalent to 1.876519.\n1/1 mismatches\n[1] 2.65 - 1.88 == 0.774\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6).\n\nFailure ('test-task-5-subtask-1-tests.R:25:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 1.24902.\n1/1 mismatches\n[1] 2.65 - 1.25 == 1.4\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5).\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-6-subtask-1-tests \n⠏ | 0 | posterior_odds_ratio_interval() \n⠧ | 6 2 | posterior_odds_ratio_interval() \n✖ | 6 2 | posterior_odds_ratio_interval() [0.1s]\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-6-subtask-1-tests.R:17:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.875367, 6.05911).\n2/2 mismatches (average diff: 0.719)\n[1] 0.68 - 0.875 == -0.196\n[2] 7.30 - 6.059 == 1.242\nError: Incorrect result for p0 = rbeta(100000, 5, 95), p1 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:19:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1650407, 1.142378).\n2/2 mismatches (average diff: 3.34)\n[1] 0.68 - 0.165 == 0.515\n[2] 7.30 - 1.142 == 6.159\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:21:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.2086461, 0.9392956).\n2/2 mismatches (average diff: 3.42)\n[1] 0.68 - 0.209 == 0.471\n[2] 7.30 - 0.939 == 6.362\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 80%.\n\nFailure ('test-task-6-subtask-1-tests.R:27:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.2714472, 5.5970131).\n2/2 mismatches (average diff: 1.06)\n[1] 0.68 - 0.271 == 0.408\n[2] 7.30 - 5.597 == 1.705\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:29:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1786667, 3.6839583).\n2/2 mismatches (average diff: 2.06)\n[1] 0.68 - 0.179 == 0.501\n[2] 7.30 - 3.684 == 3.618\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:31:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.252972, 2.633517).\n2/2 mismatches (average diff: 2.55)\n[1] 0.68 - 0.253 == 0.427\n[2] 7.30 - 2.634 == 4.668\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 80%.\n────────────────────────────────────────────────────────────────────────────────\nMaximum number of failures exceeded; quitting at end of file.\nℹ Increase this number with (e.g.) `testthat::set_max_fails(Inf)` \n\n══ Results ═════════════════════════════════════════════════════════════════════\nDuration: 0.6 s\n\n[ FAIL 15 | WARN 0 | SKIP 0 | PASS 17 ]\n══ Terminated early ════════════════════════════════════════════════════════════" + "text": "4.3 (c)\nWrite your answers here!\n\n\n\n\n\n\nmarkmyassignment\n\n\n\n\n\nThis 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!\nThe following will check the functions for which markmyassignment has been set up:\n\nmark_my_assignment()\n\n✔ | F W S OK | Context\n\n⠏ | 0 | task-1-subtask-1-tests \n⠏ | 0 | mu_point_est() \n✖ | 1 3 | mu_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-1-subtask-1-tests.R:17:3'): mu_point_est()\nmu_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-2-subtask-1-tests \n⠏ | 0 | mu_interval() \n✖ | 2 3 | mu_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-2-subtask-1-tests.R:15:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.95) not equivalent to c(3.3, 7.7).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 3.3 == 10\n[2] 15.7 - 7.7 == 8\nError: Incorrect result for 1:10 using a 95% interval.\n\nFailure ('test-task-2-subtask-1-tests.R:16:3'): mu_interval()\nmu_interval(data = 1:10, prob = 0.8) not equivalent to c(4.2, 6.8).\n2/2 mismatches (average diff: 9)\n[1] 13.3 - 4.2 == 9.1\n[2] 15.7 - 6.8 == 8.9\nError: Incorrect result for 1:10 using a 80% interval.\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-3-subtask-1-tests \n⠏ | 0 | mu_pred_interval() \n✖ | 2 3 | mu_pred_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-3-subtask-1-tests.R:16:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.95) not equivalent to c(-1.7, 12.7).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - -1.7 == 13.5\n[2] 17.2 - 12.7 == 4.5\nError: Incorrect result for 1:10, (95%)\n\nFailure ('test-task-3-subtask-1-tests.R:18:3'): mu_pred_interval()\nmu_pred_interval(1:10, 0.8) not equivalent to c(1.1, 9.9).\n2/2 mismatches (average diff: 9)\n[1] 11.8 - 1.1 == 10.7\n[2] 17.2 - 9.9 == 7.3\nError: Incorrect result for 1:10, (80%)\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-4-subtask-1-tests \n⠏ | 0 | mu_pred_point_est() \n✖ | 1 3 | mu_pred_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-4-subtask-1-tests.R:16:3'): mu_pred_point_est()\nmu_pred_point_est(data = 1:10) not equivalent to 5.5.\n1/1 mismatches\n[1] 14.5 - 5.5 == 9\nError: Incorrect result for vector 1:10\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-5-subtask-1-tests \n⠏ | 0 | posterior_odds_ratio_point_est() \n✖ | 3 3 | posterior_odds_ratio_point_est()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-5-subtask-1-tests.R:18:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 0.5307909.\n1/1 mismatches\n[1] 2.65 - 0.531 == 2.12\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90).\n\nFailure ('test-task-5-subtask-1-tests.R:24:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p0, p1) not equivalent to 1.876519.\n1/1 mismatches\n[1] 2.65 - 1.88 == 0.774\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6).\n\nFailure ('test-task-5-subtask-1-tests.R:25:3'): posterior_odds_ratio_point_est()\nposterior_odds_ratio_point_est(p1, p0) not equivalent to 1.24902.\n1/1 mismatches\n[1] 2.65 - 1.25 == 1.4\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5).\n────────────────────────────────────────────────────────────────────────────────\n\n⠏ | 0 | task-6-subtask-1-tests \n⠏ | 0 | posterior_odds_ratio_interval() \n✖ | 6 2 | posterior_odds_ratio_interval()\n────────────────────────────────────────────────────────────────────────────────\nFailure ('test-task-6-subtask-1-tests.R:17:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.875367, 6.05911).\n2/2 mismatches (average diff: 0.719)\n[1] 0.68 - 0.875 == -0.196\n[2] 7.30 - 6.059 == 1.242\nError: Incorrect result for p0 = rbeta(100000, 5, 95), p1 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:19:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1650407, 1.142378).\n2/2 mismatches (average diff: 3.34)\n[1] 0.68 - 0.165 == 0.515\n[2] 7.30 - 1.142 == 6.159\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:21:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.2086461, 0.9392956).\n2/2 mismatches (average diff: 3.42)\n[1] 0.68 - 0.209 == 0.471\n[2] 7.30 - 0.939 == 6.362\nError: Incorrect result for p1 = rbeta(100000, 5, 95), p0 = rbeta(100000, 10, 90) and 80%.\n\nFailure ('test-task-6-subtask-1-tests.R:27:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p0, p1, 0.9) not equivalent to c(0.2714472, 5.5970131).\n2/2 mismatches (average diff: 1.06)\n[1] 0.68 - 0.271 == 0.408\n[2] 7.30 - 5.597 == 1.705\nError: Incorrect result for p0 = rbeta(100000, 5, 5), p1 = rbeta(100000, 5, 6) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:29:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.9) not equivalent to c(0.1786667, 3.6839583).\n2/2 mismatches (average diff: 2.06)\n[1] 0.68 - 0.179 == 0.501\n[2] 7.30 - 3.684 == 3.618\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 90%.\n\nFailure ('test-task-6-subtask-1-tests.R:31:3'): posterior_odds_ratio_interval()\nposterior_odds_ratio_interval(p1, p0, 0.8) not equivalent to c(0.252972, 2.633517).\n2/2 mismatches (average diff: 2.55)\n[1] 0.68 - 0.253 == 0.427\n[2] 7.30 - 2.634 == 4.668\nError: Incorrect result for p0 = rbeta(100000, 5, 6), p1 = rbeta(100000, 5, 5) and 80%.\n────────────────────────────────────────────────────────────────────────────────\nMaximum number of failures exceeded; quitting at end of file.\nℹ Increase this number with (e.g.) `testthat::set_max_fails(Inf)` \n\n══ Results ═════════════════════════════════════════════════════════════════════\nDuration: 0.5 s\n\n[ FAIL 15 | WARN 0 | SKIP 0 | PASS 17 ]\n══ Terminated early ════════════════════════════════════════════════════════════" } ] \ No newline at end of file diff --git a/assignments/simple_template3.html b/assignments/simple_template3.html index aec1039b..b41e78c9 100644 --- a/assignments/simple_template3.html +++ b/assignments/simple_template3.html @@ -715,8 +715,7 @@

weight ~ 1 + Time + Chick, data = ChickWeight, file="additional_files/assignment8/dummy_fit" -) -
-
Start sampling
-
-
-
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 1 
-
-
-
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 1 
-
-
-
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 1 
-
-
-
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 1 
-
-
-
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 1 
-
-
-
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 1 
-
-
-
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 1 
-
-
-
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 1 
-
-
-
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 1 
-
-
-
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 1 
-
-
-
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 2 
-
-
-
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 2 
-
-
-
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 2 
-
-
-
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 2 
-
-
-
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 2 
-
-
-
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 2 
-
-
-
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 2 
-
-
-
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 2 
-
-
-
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 2 
-
-
-
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 2 
-
-
-
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 2 
-
-
-
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 2 
-
-
-
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 3 
-
-
-
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 3 
-
-
-
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 3 
-
-
-
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 3 
-
-
-
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 3 
-
-
-
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 3 
-
-
-
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 3 
-
-
-
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 3 
-
-
-
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 3 
-
-
-
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 3 
-
-
-
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 3 
-
-
-
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 3 
-
-
-
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 3 
-
-
-
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 4 
-
-
-
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 4 
-
-
-
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 4 
-
-
-
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 4 
-
-
-
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 4 
-
-
-
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 4 
-
-
-
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 4 
-
-
-
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 4 
-
-
-
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 4 
-
-
-
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 4 
-
-
-
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 4 
-
-
-
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 4 
-
-
-
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 4 
-
-
-
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
-
-
-
Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/tmp/RtmpXbSY6l/model-d6638ce191.stan', line 35, column 4 to column 62)
-
-
-
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
-
-
-
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
-
-
-
Chain 4 
-
-
# Adjust the chicken_idxs variable to select appropriate chickens
-chicken_idxs = c(1,3,11,43)
-# Create this plot for your hierarchical model for selected chickens
-brms::pp_check(
-  dummy_fit, type = "intervals_grouped", group = "Chick", 
-  newdata=ChickWeight |> filter(Chick %in% chicken_idxs)
-)
-
-
Using all posterior draws for ppc type 'intervals_grouped' by default.
-
-
-

-
+) +# Adjust the chicken_idxs variable to select appropriate chickens +chicken_idxs = c(1,3,11,43) +# Create this plot for your hierarchical model for selected chickens +brms::pp_check( + dummy_fit, type = "intervals_grouped", group = "Chick", + newdata=ChickWeight |> filter(Chick %in% chicken_idxs) +) @@ -1384,17 +640,17 @@