diff --git a/.nojekyll b/.nojekyll
index 0639c2c1..01e1f02e 100644
--- a/.nojekyll
+++ b/.nojekyll
@@ -1 +1 @@
-fad23f16
\ No newline at end of file
+b5eb6433
\ No newline at end of file
diff --git a/FAQ.html b/FAQ.html
index 08aa9d04..1a27d84e 100644
--- a/FAQ.html
+++ b/FAQ.html
@@ -414,14 +414,19 @@
Install pystan
I missed some deadline or wasn’t able to do some part of the course
+
Can I combine results from assignments, project, presentation, and e-exam made in different periods / years?
+
+
Yes.
+
I missed the deadline to register for the course in Sisu. Can I join the course?
-
Yes, just register in MyCourses.
+
Yes, just register in MyCourses and contact student services that they add you in Sisu, too.
I missed the deadline for the assignment. Can you accept my late submission?
-
Open MyCourses Quizzes are automatically submitted at the deadline time
-
If you miss the FeedbackFruits deadline first time it’s used due technical problems, but you send the pdf to one of the TAs few minutes after the deadline it can accepted once. As the recommended submission time is before 4pm on Friday, you have in general 56 hours extra hours for submission and several few minute late submissions is not likely just due to the technical problems.
+
Open MyCourses Quizzes are automatically submitted at the deadline time
I was not able to do one of the assignments because [some personal problem]. Can I do some extra work?
diff --git a/assignments/search.json b/assignments/search.json
index 94682954..ef325f65 100644
--- a/assignments/search.json
+++ b/assignments/search.json
@@ -37,7 +37,7 @@
"href": "template7.html",
"title": "Notebook for Assignment 7",
"section": "",
- "text": "1 General information\nThis assignment relates to Lecture 7 and Chapter 5.\nWe recommend using JupyterHub (which has all the needed packages pre-installed).\n\nReading instructions:\n\nThe reading instructions for BDA3 Chapter 5.\n\n\n\n\n\n\n\n\nGeneral Instructions for Answering the Assignment Questions\n\n\n\n\n\n\nQuestions below are exact copies of the text found in the MyCourses quiz and should serve as a notebook where you can store notes and code.\nWe recommend opening these notebooks in the Aalto JupyterHub, see how to use R and RStudio remotely.\nFor inspiration for code, have a look at the BDA R Demos and the specific Assignment code notebooks\nRecommended additional self study exercises for each chapter in BDA3 are listed in the course web page. These will help to gain deeper understanding of the topic.\nCommon questions and answers regarding installation and technical problems can be found in Frequently Asked Questions (FAQ).\nDeadlines for all assignments can be found on the course web page and in MyCourses.\nYou are allowed to discuss assignments with your friends, but it is not allowed to copy solutions directly from other students or from internet.\nDo not share your answers publicly.\nDo not copy answers from the internet or from previous years. We compare the answers to the answers from previous years and to the answers from other students this year.\nUse of AI is allowed on the course, but the most of the work needs to by the student, and you need to report whether you used AI and in which way you used them (See points 5 and 6 in Aalto guidelines for use of AI in teaching).\nAll suspected plagiarism will be reported and investigated. See more about the Aalto University Code of Academic Integrity and Handling Violations Thereof.\nIf you have any suggestions or improvements to the course material, please post in the course chat feedback channel, create an issue, or submit a pull request to the public repository!\n\n\n\n\n\nif (!require(tidybayes)) {\n install.packages(\"tidybayes\")\n library(tidybayes)\n}\n\nLoading required package: tidybayes\n\n\nWarning in library(package, lib.loc = lib.loc, character.only = TRUE,\nlogical.return = TRUE, : there is no package called 'tidybayes'\n\n\nInstalling package into '/home/runner/work/_temp/Library'\n(as 'lib' is unspecified)\n\n\nalso installing the dependencies 'svUnit', 'arrayhelpers'\n\nif (!require(brms)) {\n install.packages(\"brms\")\n library(brms)\n}\n\nLoading required package: brms\n\n\nLoading required package: Rcpp\n\n\nLoading 'brms' package (version 2.22.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\nAttaching package: 'brms'\n\n\nThe following objects are masked from 'package:tidybayes':\n\n dstudent_t, pstudent_t, qstudent_t, rstudent_t\n\n\nThe following object is masked from 'package:stats':\n\n ar\n\nif (!require(metadat)) {\n install.packages(\"metadat\")\n library(metadat)\n}\n\nLoading required package: metadat\n\n\nWarning in library(package, lib.loc = lib.loc, character.only = TRUE,\nlogical.return = TRUE, : there is no package called 'metadat'\n\n\nInstalling package into '/home/runner/work/_temp/Library'\n(as 'lib' is unspecified)\n\n\nalso installing the dependency 'mathjaxr'\n\nif(!require(cmdstanr)){\n install.packages(\"cmdstanr\", repos = c(\"https://mc-stan.org/r-packages/\", getOption(\"repos\")))\n library(cmdstanr)\n}\n\nLoading required package: cmdstanr\n\n\nThis is cmdstanr version 0.8.1\n\n\n- CmdStanR documentation and vignettes: mc-stan.org/cmdstanr\n\n\n- CmdStan path: /home/runner/.cmdstan/cmdstan-2.35.0\n\n\n- CmdStan version: 2.35.0\n\ncmdstan_installed <- function(){\n res <- try(out <- cmdstanr::cmdstan_path(), silent = TRUE)\n !inherits(res, \"try-error\")\n}\nif(!cmdstan_installed()){\n install_cmdstan()\n}\n\n\n\n2 Simulation warm-up\nHere is the function to simulate and plot observations from a hierarchical data-generating process.\n\nhierarchical_sim <- function(group_pop_mean,\n between_group_sd,\n within_group_sd,\n n_groups,\n n_obs_per_group\n ) {\n # Generate group means\n group_means <- rnorm(\n n = n_groups,\n mean = group_pop_mean,\n sd = between_group_sd\n )\n\n # Generate observations\n\n ## Create an empty vector for observations\n y <- numeric()\n ## Create a vector for the group identifier\n group <- rep(1:n_groups, each = n_obs_per_group)\n \n for (j in 1:n_groups) {\n ### Generate one group observations\n group_y <- rnorm(\n n = n_obs_per_group,\n mean = group_means[j],\n sd = within_group_sd\n )\n ### Append the group observations to the vector\n y <- c(y, group_y)\n }\n\n # Combine into a data frame\n data <- data.frame(\n group = factor(group),\n y = y\n )\n\n # Plot the data\n ggplot(data, aes(x = y, y = group)) +\n geom_point() +\n geom_vline(xintercept = group_pop_mean, linetype = \"dashed\")\n}\n\nExample using the function:\n\nhierarchical_sim(\n group_pop_mean = 50,\n between_group_sd = 5,\n within_group_sd = 1,\n n_groups = 10,\n n_obs_per_group = 5\n )\n\nError in ggplot(data, aes(x = y, y = group)): could not find function \"ggplot\"\n\n\n\n\n3 Sleep deprivation\nThe dataset sleepstudy is available by using the command data(sleepstudy, package = \"lme4\")\nBelow is some code for fitting a brms model. This model is a simple pooled model. You will need to fit a hierarchical model as explained in the assignment, but this code should help getting started.\nLoad the dataset\n\ndata(sleepstudy, package = \"lme4\")\n\nError in find.package(package, lib.loc, verbose = verbose): there is no package called 'lme4'\n\n\nSpecify the formula and observation family:\n\nsleepstudy_pooled_formula <- bf(\n Reaction ~ 1 + Days,\n family = \"gaussian\",\n center = FALSE\n)\n\nWe can see the parameters and default priors with\n\nget_prior(pooled_formula, data = sleepstudy)\n\nWe can then specify the priors:\n\n(sleepstudy_pooled_priors <- c(\n prior(\n normal(400, 100),\n class = \"b\",\n coef = \"Intercept\"\n ),\n prior(\n normal(0, 50),\n class = \"b\",\n coef = \"Days\"\n ),\n prior(\n normal(0, 50),\n class = \"sigma\"\n )\n))\n\nAnd then fit the model:\n\nsleepstudy_pooled_fit <- brm(\n formula = pooled_formula,\n prior = pooled_priors,\n data = sleepstudy\n)\n\nWe can inspect the model fit:\n\nsummary(pooled_fit)\n\n\n\n4 School calendar\nMeta-analysis models can be fit in brms. When the standard error is known, the se() function can be used to specify it.\nThe dataset dat.konstantopoulos2011 has the observations for the school calendar intervention meta-analysis.\n\ndata(dat.konstantopoulos2011, package = \"metadat\")\n\nAs mentioned in the assignment instructions, a unique identifier for school needs to be created by combining the district and school:\n\nschoolcalendar_data <- dat.konstantopoulos2011 |>\n dplyr::mutate(\n school = factor(school),\n district = factor(district),\n district_school = interaction(district, school, drop = TRUE, sep = \"_\")\n )\n\nThen the models can be fit\n\nschoolcalendar_pooled_formula <- bf(\n formula = yi | se(sqrt(vi)) ~ 1,\n family = \"gaussian\"\n) \n\nschoolcalendar_pooled_fit <- brm(\n formula = schoolcalendar_pooled_formula,\n data = schoolcalendar_data\n)\n\nPredictions for a new school can be made using the posterior_epred function:\n\nnew_school <- data.frame(\n school = factor(1),\n district = factor(1),\n district_school = factor(\"1_1\"),\n vi = 0 # the expectation of the prediction is not affected by the sampling variance, so this can be any number\n)\n \n\nschoolcalendar_post_epred <- posterior_epred(\n schoolcalendar_pooled_fit,\n newdata = new_school,\n allow_new_levels = TRUE\n )\n\nIt can be helpful to plot the posterior estimates. Here is a function that will do this:\n\nplot_school_posteriors <- function(fit, dataset) {\n tidybayes::add_predicted_draws(dataset, fit) |>\n ggplot(\n aes(\n x = .prediction,\n y = interaction(district, school, sep = \", \", lex.order = TRUE))) +\n tidybayes::stat_halfeye() +\n ylab(\"District, school\") +\n xlab(\"Posterior effect\")\n}\n\nAnd can be used as follows:\n\nplot_school_posteriors(\n fit = schoolcalendar_pooled_fit,\n dataset = school_calendar_data\n)",
+ "text": "1 General information\nThis assignment relates to Lecture 7 and Chapter 5.\nWe recommend using JupyterHub (which has all the needed packages pre-installed).\n\nReading instructions:\n\nThe reading instructions for BDA3 Chapter 5.\n\n\n\n\n\n\n\n\nGeneral Instructions for Answering the Assignment Questions\n\n\n\n\n\n\nQuestions below are exact copies of the text found in the MyCourses quiz and should serve as a notebook where you can store notes and code.\nWe recommend opening these notebooks in the Aalto JupyterHub, see how to use R and RStudio remotely.\nFor inspiration for code, have a look at the BDA R Demos and the specific Assignment code notebooks\nRecommended additional self study exercises for each chapter in BDA3 are listed in the course web page. These will help to gain deeper understanding of the topic.\nCommon questions and answers regarding installation and technical problems can be found in Frequently Asked Questions (FAQ).\nDeadlines for all assignments can be found on the course web page and in MyCourses.\nYou are allowed to discuss assignments with your friends, but it is not allowed to copy solutions directly from other students or from internet.\nDo not share your answers publicly.\nDo not copy answers from the internet or from previous years. We compare the answers to the answers from previous years and to the answers from other students this year.\nUse of AI is allowed on the course, but the most of the work needs to by the student, and you need to report whether you used AI and in which way you used them (See points 5 and 6 in Aalto guidelines for use of AI in teaching).\nAll suspected plagiarism will be reported and investigated. See more about the Aalto University Code of Academic Integrity and Handling Violations Thereof.\nIf you have any suggestions or improvements to the course material, please post in the course chat feedback channel, create an issue, or submit a pull request to the public repository!\n\n\n\n\n\nif (!require(tidybayes)) {\n install.packages(\"tidybayes\")\n library(tidybayes)\n}\n\nLoading required package: tidybayes\n\nif (!require(brms)) {\n install.packages(\"brms\")\n library(brms)\n}\n\nLoading required package: brms\n\n\nLoading required package: Rcpp\n\n\nLoading 'brms' package (version 2.22.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\nAttaching package: 'brms'\n\n\nThe following objects are masked from 'package:tidybayes':\n\n dstudent_t, pstudent_t, qstudent_t, rstudent_t\n\n\nThe following object is masked from 'package:stats':\n\n ar\n\nif (!require(metadat)) {\n install.packages(\"metadat\")\n library(metadat)\n}\n\nLoading required package: metadat\n\nif(!require(cmdstanr)){\n install.packages(\"cmdstanr\", repos = c(\"https://mc-stan.org/r-packages/\", getOption(\"repos\")))\n library(cmdstanr)\n}\n\nLoading required package: cmdstanr\n\n\nThis is cmdstanr version 0.8.1\n\n\n- CmdStanR documentation and vignettes: mc-stan.org/cmdstanr\n\n\n- CmdStan path: /home/runner/.cmdstan/cmdstan-2.35.0\n\n\n- CmdStan version: 2.35.0\n\ncmdstan_installed <- function(){\n res <- try(out <- cmdstanr::cmdstan_path(), silent = TRUE)\n !inherits(res, \"try-error\")\n}\nif(!cmdstan_installed()){\n install_cmdstan()\n}\n\n\n\n2 Simulation warm-up\nHere is the function to simulate and plot observations from a hierarchical data-generating process.\n\nhierarchical_sim <- function(group_pop_mean,\n between_group_sd,\n within_group_sd,\n n_groups,\n n_obs_per_group\n ) {\n # Generate group means\n group_means <- rnorm(\n n = n_groups,\n mean = group_pop_mean,\n sd = between_group_sd\n )\n\n # Generate observations\n\n ## Create an empty vector for observations\n y <- numeric()\n ## Create a vector for the group identifier\n group <- rep(1:n_groups, each = n_obs_per_group)\n \n for (j in 1:n_groups) {\n ### Generate one group observations\n group_y <- rnorm(\n n = n_obs_per_group,\n mean = group_means[j],\n sd = within_group_sd\n )\n ### Append the group observations to the vector\n y <- c(y, group_y)\n }\n\n # Combine into a data frame\n data <- data.frame(\n group = factor(group),\n y = y\n )\n\n # Plot the data\n ggplot(data, aes(x = y, y = group)) +\n geom_point() +\n geom_vline(xintercept = group_pop_mean, linetype = \"dashed\")\n}\n\nExample using the function:\n\nhierarchical_sim(\n group_pop_mean = 50,\n between_group_sd = 5,\n within_group_sd = 1,\n n_groups = 10,\n n_obs_per_group = 5\n )\n\nError in ggplot(data, aes(x = y, y = group)): could not find function \"ggplot\"\n\n\n\n\n3 Sleep deprivation\nThe dataset sleepstudy is available by using the command data(sleepstudy, package = \"lme4\")\nBelow is some code for fitting a brms model. This model is a simple pooled model. You will need to fit a hierarchical model as explained in the assignment, but this code should help getting started.\nLoad the dataset\n\ndata(sleepstudy, package = \"lme4\")\n\nError in find.package(package, lib.loc, verbose = verbose): there is no package called 'lme4'\n\n\nSpecify the formula and observation family:\n\nsleepstudy_pooled_formula <- bf(\n Reaction ~ 1 + Days,\n family = \"gaussian\",\n center = FALSE\n)\n\nWe can see the parameters and default priors with\n\nget_prior(pooled_formula, data = sleepstudy)\n\nWe can then specify the priors:\n\n(sleepstudy_pooled_priors <- c(\n prior(\n normal(400, 100),\n class = \"b\",\n coef = \"Intercept\"\n ),\n prior(\n normal(0, 50),\n class = \"b\",\n coef = \"Days\"\n ),\n prior(\n normal(0, 50),\n class = \"sigma\"\n )\n))\n\nAnd then fit the model:\n\nsleepstudy_pooled_fit <- brm(\n formula = pooled_formula,\n prior = pooled_priors,\n data = sleepstudy\n)\n\nWe can inspect the model fit:\n\nsummary(pooled_fit)\n\n\n\n4 School calendar\nMeta-analysis models can be fit in brms. When the standard error is known, the se() function can be used to specify it.\nThe dataset dat.konstantopoulos2011 has the observations for the school calendar intervention meta-analysis.\n\ndata(dat.konstantopoulos2011, package = \"metadat\")\n\nAs mentioned in the assignment instructions, a unique identifier for school needs to be created by combining the district and school:\n\nschoolcalendar_data <- dat.konstantopoulos2011 |>\n dplyr::mutate(\n school = factor(school),\n district = factor(district),\n district_school = interaction(district, school, drop = TRUE, sep = \"_\")\n )\n\nThen the models can be fit\n\nschoolcalendar_pooled_formula <- bf(\n formula = yi | se(sqrt(vi)) ~ 1,\n family = \"gaussian\"\n) \n\nschoolcalendar_pooled_fit <- brm(\n formula = schoolcalendar_pooled_formula,\n data = schoolcalendar_data\n)\n\nPredictions for a new school can be made using the posterior_epred function:\n\nnew_school <- data.frame(\n school = factor(1),\n district = factor(1),\n district_school = factor(\"1_1\"),\n vi = 0 # the expectation of the prediction is not affected by the sampling variance, so this can be any number\n)\n \n\nschoolcalendar_post_epred <- posterior_epred(\n schoolcalendar_pooled_fit,\n newdata = new_school,\n allow_new_levels = TRUE\n )\n\nIt can be helpful to plot the posterior estimates. Here is a function that will do this:\n\nplot_school_posteriors <- function(fit, dataset) {\n tidybayes::add_predicted_draws(dataset, fit) |>\n ggplot(\n aes(\n x = .prediction,\n y = interaction(district, school, sep = \", \", lex.order = TRUE))) +\n tidybayes::stat_halfeye() +\n ylab(\"District, school\") +\n xlab(\"Posterior effect\")\n}\n\nAnd can be used as follows:\n\nplot_school_posteriors(\n fit = schoolcalendar_pooled_fit,\n dataset = school_calendar_data\n)",
"crumbs": [
"Templates",
"Notebook for Assignment 7"
diff --git a/assignments/template3_files/figure-html/unnamed-chunk-10-2.png b/assignments/template3_files/figure-html/unnamed-chunk-10-2.png
index e6f29e4d..134b066d 100644
Binary files a/assignments/template3_files/figure-html/unnamed-chunk-10-2.png and b/assignments/template3_files/figure-html/unnamed-chunk-10-2.png differ
diff --git a/assignments/template7.html b/assignments/template7.html
index 45b7639c..dd70fa9b 100644
--- a/assignments/template7.html
+++ b/assignments/template7.html
@@ -381,21 +381,10 @@
1 General informa
Loading required package: tidybayes
-
-
Warning in library(package, lib.loc = lib.loc, character.only = TRUE,
-logical.return = TRUE, : there is no package called 'tidybayes'
-
-
-
Installing package into '/home/runner/work/_temp/Library'
-(as 'lib' is unspecified)
-
-
-
also installing the dependencies 'svUnit', 'arrayhelpers'
-
-
if (!require(brms)) {
-install.packages("brms")
-library(brms)
-}
+
if (!require(brms)) {
+install.packages("brms")
+library(brms)
+}
Loading required package: brms
@@ -421,28 +410,17 @@
1 General informa
ar
-
if (!require(metadat)) {
-install.packages("metadat")
-library(metadat)
-}
+
if (!require(metadat)) {
+install.packages("metadat")
+library(metadat)
+}
Loading required package: metadat
-
-
Warning in library(package, lib.loc = lib.loc, character.only = TRUE,
-logical.return = TRUE, : there is no package called 'metadat'
-
-
-
Installing package into '/home/runner/work/_temp/Library'
-(as 'lib' is unspecified)
Error in ggplot(data, aes(x = y, y = group)): could not find function "ggplot"
@@ -534,53 +512,53 @@
3 Sleep deprivati
Below is some code for fitting a brms model. This model is a simple pooled model. You will need to fit a hierarchical model as explained in the assignment, but this code should help getting started.
Load the dataset
-
data(sleepstudy, package ="lme4")
+
data(sleepstudy, package ="lme4")
Error in find.package(package, lib.loc, verbose = verbose): there is no package called 'lme4'
Predictions for a new school can be made using the posterior_epred function:
-
new_school <-data.frame(
-school =factor(1),
-district =factor(1),
-district_school =factor("1_1"),
-vi =0# the expectation of the prediction is not affected by the sampling variance, so this can be any number
-)
-
-
-schoolcalendar_post_epred <-posterior_epred(
- schoolcalendar_pooled_fit,
-newdata = new_school,
-allow_new_levels =TRUE
- )
+
new_school <-data.frame(
+school =factor(1),
+district =factor(1),
+district_school =factor("1_1"),
+vi =0# the expectation of the prediction is not affected by the sampling variance, so this can be any number
+)
+
+
+schoolcalendar_post_epred <-posterior_epred(
+ schoolcalendar_pooled_fit,
+newdata = new_school,
+allow_new_levels =TRUE
+ )
It can be helpful to plot the posterior estimates. Here is a function that will do this:
---
-title: "Notebook for Assignment 7"
-author: "Aki Vehtari et al."
-format:
- html:
- toc: true
- code-tools: true
- code-line-numbers: true
- number-sections: true
- mainfont: Georgia, serif
-editor: source
----
-
-# General information
-
-This assignment relates to Lecture 7 and Chapter 5.
-
-We recommend using [JupyterHub](https://jupyter.cs.aalto.fi) (which has all the needed packages pre-installed).
-
-::: hint
-**Reading instructions:**
-
-- [**The reading instructions for BDA3 Chapter 5**](../BDA3_notes.html#ch5).
-:::
-
-{{< include includes/_general_cloze_instructions.md >}}
-
-```{r}
-if (!require(tidybayes)) {
-install.packages("tidybayes")
-library(tidybayes)
-}
-
-if (!require(brms)) {
-install.packages("brms")
-library(brms)
-}
-
-if (!require(metadat)) {
-install.packages("metadat")
-library(metadat)
-}
-
-if(!require(cmdstanr)){
-install.packages("cmdstanr", repos =c("https://mc-stan.org/r-packages/", getOption("repos")))
-library(cmdstanr)
-}
-cmdstan_installed <-function(){
- res <-try(out <- cmdstanr::cmdstan_path(), silent =TRUE)
-!inherits(res, "try-error")
-}
-if(!cmdstan_installed()){
-install_cmdstan()
-}
-```
-
-# Simulation warm-up
-
-Here is the function to simulate and plot observations from a
-hierarchical data-generating process.
-
-```{r}
-hierarchical_sim <-function(group_pop_mean,
- between_group_sd,
- within_group_sd,
- n_groups,
- n_obs_per_group
- ) {
-# Generate group means
- group_means <-rnorm(
-n = n_groups,
-mean = group_pop_mean,
-sd = between_group_sd
- )
-
-# Generate observations
-
-## Create an empty vector for observations
- y <-numeric()
-## Create a vector for the group identifier
- group <-rep(1:n_groups, each = n_obs_per_group)
-
-for (j in1:n_groups) {
-### Generate one group observations
- group_y <-rnorm(
-n = n_obs_per_group,
-mean = group_means[j],
-sd = within_group_sd
- )
-### Append the group observations to the vector
- y <-c(y, group_y)
- }
-
-# Combine into a data frame
- data <-data.frame(
-group =factor(group),
-y = y
- )
-
-# Plot the data
-ggplot(data, aes(x = y, y = group)) +
-geom_point() +
-geom_vline(xintercept = group_pop_mean, linetype ="dashed")
-}
-```
-
-Example using the function:
-```{r}
-hierarchical_sim(
-group_pop_mean =50,
-between_group_sd =5,
-within_group_sd =1,
-n_groups =10,
-n_obs_per_group =5
- )
-```
-
-# Sleep deprivation
-
-The dataset `sleepstudy` is available by using the command
-`data(sleepstudy, package = "lme4")`
-
-Below is some code for fitting a brms model. This model is a simple
-pooled model. You will need to fit a hierarchical model as explained
-in the assignment, but this code should help getting started.
-
-Load the dataset
-```{r}
-data(sleepstudy, package ="lme4")
-```
-
-Specify the formula and observation family:
-
-```{r}
-#| eval: false
-sleepstudy_pooled_formula <-bf(
- Reaction ~1+ Days,
-family ="gaussian",
-center =FALSE
-)
-```
-
-We can see the parameters and default priors with
-```{r}
-#| eval: false
-get_prior(pooled_formula, data = sleepstudy)
-```
-
-We can then specify the priors:
-
-```{r}
-#| eval: false
-(sleepstudy_pooled_priors <-c(
-prior(
-normal(400, 100),
-class ="b",
-coef ="Intercept"
- ),
-prior(
-normal(0, 50),
-class ="b",
-coef ="Days"
- ),
-prior(
-normal(0, 50),
-class ="sigma"
- )
-))
-```
-
-And then fit the model:
-
-```{r}
-#| eval: false
-sleepstudy_pooled_fit <-brm(
-formula = pooled_formula,
-prior = pooled_priors,
-data = sleepstudy
-)
-```
-
-We can inspect the model fit:
-
-```{r}
-#| eval: false
-summary(pooled_fit)
-```
-
-# School calendar
-
-Meta-analysis models can be fit in brms. When the standard error is
-known, the `se()` function can be used to specify it.
-
-The dataset `dat.konstantopoulos2011` has the observations for the school calendar intervention meta-analysis.
-
-```{r}
-data(dat.konstantopoulos2011, package ="metadat")
-```
-
-As mentioned in the assignment instructions, a unique identifier for
-school needs to be created by combining the district and school:
-
-```{r}
-#| eval: false
-schoolcalendar_data <- dat.konstantopoulos2011 |>
- dplyr::mutate(
-school =factor(school),
-district =factor(district),
-district_school =interaction(district, school, drop =TRUE, sep ="_")
- )
-```
-
-Then the models can be fit
-```{r}
-#| eval: false
-schoolcalendar_pooled_formula <-bf(
-formula = yi |se(sqrt(vi)) ~1,
-family ="gaussian"
-)
-
-schoolcalendar_pooled_fit <-brm(
-formula = schoolcalendar_pooled_formula,
-data = schoolcalendar_data
-)
-```
-
-Predictions for a new school can be made using the `posterior_epred` function:
-```{r}
-#| eval: false
-new_school <-data.frame(
-school =factor(1),
-district =factor(1),
-district_school =factor("1_1"),
-vi =0# the expectation of the prediction is not affected by the sampling variance, so this can be any number
-)
-
-
-schoolcalendar_post_epred <-posterior_epred(
- schoolcalendar_pooled_fit,
-newdata = new_school,
-allow_new_levels =TRUE
- )
-
-```
-
-It can be helpful to plot the posterior estimates. Here is a function that will do this:
-
-```{r}
-#| eval: false
-plot_school_posteriors <-function(fit, dataset) {
- tidybayes::add_predicted_draws(dataset, fit) |>
-ggplot(
-aes(
-x = .prediction,
-y =interaction(district, school, sep =", ", lex.order =TRUE))) +
- tidybayes::stat_halfeye() +
-ylab("District, school") +
-xlab("Posterior effect")
-}
-
-```
-
-And can be used as follows:
-
-```{r}
-#| eval: false
-plot_school_posteriors(
-fit = schoolcalendar_pooled_fit,
-dataset = school_calendar_data
-)
-```
+
---
+title: "Notebook for Assignment 7"
+author: "Aki Vehtari et al."
+format:
+ html:
+ toc: true
+ code-tools: true
+ code-line-numbers: true
+ number-sections: true
+ mainfont: Georgia, serif
+editor: source
+---
+
+# General information
+
+This assignment relates to Lecture 7 and Chapter 5.
+
+We recommend using [JupyterHub](https://jupyter.cs.aalto.fi) (which has all the needed packages pre-installed).
+
+::: hint
+**Reading instructions:**
+
+- [**The reading instructions for BDA3 Chapter 5**](../BDA3_notes.html#ch5).
+:::
+
+{{< include includes/_general_cloze_instructions.md >}}
+
+```{r}
+if (!require(tidybayes)) {
+install.packages("tidybayes")
+library(tidybayes)
+}
+
+if (!require(brms)) {
+install.packages("brms")
+library(brms)
+}
+
+if (!require(metadat)) {
+install.packages("metadat")
+library(metadat)
+}
+
+if(!require(cmdstanr)){
+install.packages("cmdstanr", repos =c("https://mc-stan.org/r-packages/", getOption("repos")))
+library(cmdstanr)
+}
+cmdstan_installed <-function(){
+ res <-try(out <- cmdstanr::cmdstan_path(), silent =TRUE)
+!inherits(res, "try-error")
+}
+if(!cmdstan_installed()){
+install_cmdstan()
+}
+```
+
+# Simulation warm-up
+
+Here is the function to simulate and plot observations from a
+hierarchical data-generating process.
+
+```{r}
+hierarchical_sim <-function(group_pop_mean,
+ between_group_sd,
+ within_group_sd,
+ n_groups,
+ n_obs_per_group
+ ) {
+# Generate group means
+ group_means <-rnorm(
+n = n_groups,
+mean = group_pop_mean,
+sd = between_group_sd
+ )
+
+# Generate observations
+
+## Create an empty vector for observations
+ y <-numeric()
+## Create a vector for the group identifier
+ group <-rep(1:n_groups, each = n_obs_per_group)
+
+for (j in1:n_groups) {
+### Generate one group observations
+ group_y <-rnorm(
+n = n_obs_per_group,
+mean = group_means[j],
+sd = within_group_sd
+ )
+### Append the group observations to the vector
+ y <-c(y, group_y)
+ }
+
+# Combine into a data frame
+ data <-data.frame(
+group =factor(group),
+y = y
+ )
+
+# Plot the data
+ggplot(data, aes(x = y, y = group)) +
+geom_point() +
+geom_vline(xintercept = group_pop_mean, linetype ="dashed")
+}
+```
+
+Example using the function:
+```{r}
+hierarchical_sim(
+group_pop_mean =50,
+between_group_sd =5,
+within_group_sd =1,
+n_groups =10,
+n_obs_per_group =5
+ )
+```
+
+# Sleep deprivation
+
+The dataset `sleepstudy` is available by using the command
+`data(sleepstudy, package = "lme4")`
+
+Below is some code for fitting a brms model. This model is a simple
+pooled model. You will need to fit a hierarchical model as explained
+in the assignment, but this code should help getting started.
+
+Load the dataset
+```{r}
+data(sleepstudy, package ="lme4")
+```
+
+Specify the formula and observation family:
+
+```{r}
+#| eval: false
+sleepstudy_pooled_formula <-bf(
+ Reaction ~1+ Days,
+family ="gaussian",
+center =FALSE
+)
+```
+
+We can see the parameters and default priors with
+```{r}
+#| eval: false
+get_prior(pooled_formula, data = sleepstudy)
+```
+
+We can then specify the priors:
+
+```{r}
+#| eval: false
+(sleepstudy_pooled_priors <-c(
+prior(
+normal(400, 100),
+class ="b",
+coef ="Intercept"
+ ),
+prior(
+normal(0, 50),
+class ="b",
+coef ="Days"
+ ),
+prior(
+normal(0, 50),
+class ="sigma"
+ )
+))
+```
+
+And then fit the model:
+
+```{r}
+#| eval: false
+sleepstudy_pooled_fit <-brm(
+formula = pooled_formula,
+prior = pooled_priors,
+data = sleepstudy
+)
+```
+
+We can inspect the model fit:
+
+```{r}
+#| eval: false
+summary(pooled_fit)
+```
+
+# School calendar
+
+Meta-analysis models can be fit in brms. When the standard error is
+known, the `se()` function can be used to specify it.
+
+The dataset `dat.konstantopoulos2011` has the observations for the school calendar intervention meta-analysis.
+
+```{r}
+data(dat.konstantopoulos2011, package ="metadat")
+```
+
+As mentioned in the assignment instructions, a unique identifier for
+school needs to be created by combining the district and school:
+
+```{r}
+#| eval: false
+schoolcalendar_data <- dat.konstantopoulos2011 |>
+ dplyr::mutate(
+school =factor(school),
+district =factor(district),
+district_school =interaction(district, school, drop =TRUE, sep ="_")
+ )
+```
+
+Then the models can be fit
+```{r}
+#| eval: false
+schoolcalendar_pooled_formula <-bf(
+formula = yi |se(sqrt(vi)) ~1,
+family ="gaussian"
+)
+
+schoolcalendar_pooled_fit <-brm(
+formula = schoolcalendar_pooled_formula,
+data = schoolcalendar_data
+)
+```
+
+Predictions for a new school can be made using the `posterior_epred` function:
+```{r}
+#| eval: false
+new_school <-data.frame(
+school =factor(1),
+district =factor(1),
+district_school =factor("1_1"),
+vi =0# the expectation of the prediction is not affected by the sampling variance, so this can be any number
+)
+
+
+schoolcalendar_post_epred <-posterior_epred(
+ schoolcalendar_pooled_fit,
+newdata = new_school,
+allow_new_levels =TRUE
+ )
+
+```
+
+It can be helpful to plot the posterior estimates. Here is a function that will do this:
+
+```{r}
+#| eval: false
+plot_school_posteriors <-function(fit, dataset) {
+ tidybayes::add_predicted_draws(dataset, fit) |>
+ggplot(
+aes(
+x = .prediction,
+y =interaction(district, school, sep =", ", lex.order =TRUE))) +
+ tidybayes::stat_halfeye() +
+ylab("District, school") +
+xlab("Posterior effect")
+}
+
+```
+
+And can be used as follows:
+
+```{r}
+#| eval: false
+plot_school_posteriors(
+fit = schoolcalendar_pooled_fit,
+dataset = school_calendar_data
+)
+```
diff --git a/search.json b/search.json
index 9b8b848b..37306e23 100644
--- a/search.json
+++ b/search.json
@@ -277,7 +277,7 @@
"href": "FAQ.html#i-missed-some-deadline-or-wasnt-able-to-do-some-part-of-the-course",
"title": "Bayesian Data Analysis course - FAQ",
"section": "I missed some deadline or wasn’t able to do some part of the course",
- "text": "I missed some deadline or wasn’t able to do some part of the course\n\nI missed the deadline to register for the course in Sisu. Can I join the course?\n\nYes, just register in MyCourses.\n\nI missed the deadline for the assignment. Can you accept my late submission?\n\nOpen MyCourses Quizzes are automatically submitted at the deadline time\nIf you miss the FeedbackFruits deadline first time it’s used due technical problems, but you send the pdf to one of the TAs few minutes after the deadline it can accepted once. As the recommended submission time is before 4pm on Friday, you have in general 56 hours extra hours for submission and several few minute late submissions is not likely just due to the technical problems.\n\nI was not able to do one of the assignments because [some personal problem]. Can I do some extra work?\n\nThings happen and you don’t need to tell the course staff your personal reasons (especially you shouldn’t tell any health issue details). Everyone gets a second change in period III. In period III there is just one submission deadline, but otherwise the procedure is the same (ie. you need to return all the assignments). If you submitted the project work in autumn you don’t need to re-submit it if you re-submit assignments.\n\nI missed the deadline to register project group. Can I still register?\n\nYes. Those who registered early are allowed to choose the presentation slots first.\n\nMy group member a) disappeared, b) doesn’t do anything, c) is annoying. Can I continue with the project alone.\n\nFirst we hope you can resolve the issue, but if nothing works, then you can continue the project work alone.\n\nI was not able a) to do the project or b) to give a presentation because [some personal problem]. Can a) I submit it later, b) present later.\n\nThings happen and you don’t need to tell the course staff your personal reasons (especially you shouldn’t tell any health issue details). Everyone gets a second change in period III. In period III there is second project submission deadline and presentation slots. If you are happy with your assignment score, you don’t need to re-submit assignments if you submit the project work in period III."
+ "text": "I missed some deadline or wasn’t able to do some part of the course\n\nCan I combine results from assignments, project, presentation, and e-exam made in different periods / years?\n\nYes.\n\nI missed the deadline to register for the course in Sisu. Can I join the course?\n\nYes, just register in MyCourses and contact student services that they add you in Sisu, too.\n\nI missed the deadline for the assignment. Can you accept my late submission?\n\nOpen MyCourses Quizzes are automatically submitted at the deadline time \n\nI was not able to do one of the assignments because [some personal problem]. Can I do some extra work?\n\nThings happen and you don’t need to tell the course staff your personal reasons (especially you shouldn’t tell any health issue details). Everyone gets a second change in period III. In period III there is just one submission deadline, but otherwise the procedure is the same (ie. you need to return all the assignments). If you submitted the project work in autumn you don’t need to re-submit it if you re-submit assignments.\n\nI missed the deadline to register project group. Can I still register?\n\nYes. Those who registered early are allowed to choose the presentation slots first.\n\nMy group member a) disappeared, b) doesn’t do anything, c) is annoying. Can I continue with the project alone.\n\nFirst we hope you can resolve the issue, but if nothing works, then you can continue the project work alone.\n\nI was not able a) to do the project or b) to give a presentation because [some personal problem]. Can a) I submit it later, b) present later.\n\nThings happen and you don’t need to tell the course staff your personal reasons (especially you shouldn’t tell any health issue details). Everyone gets a second change in period III. In period III there is second project submission deadline and presentation slots. If you are happy with your assignment score, you don’t need to re-submit assignments if you submit the project work in period III."
},
{
"objectID": "FAQ.html#recommended-courses-after-bayesian-data-analysis",
diff --git a/sitemap.xml b/sitemap.xml
index fcdb96e7..fe284749 100644
--- a/sitemap.xml
+++ b/sitemap.xml
@@ -2,50 +2,50 @@
https://avehtari.github.io/BDA_course_Aalto/ta_info_gsu.html
- 2024-11-12T08:43:13.753Z
+ 2024-11-12T10:31:47.737Zhttps://avehtari.github.io/BDA_course_Aalto/project.html
- 2024-11-12T08:43:13.305Z
+ 2024-11-12T10:31:47.289Zhttps://avehtari.github.io/BDA_course_Aalto/gsu2023.html
- 2024-11-12T08:43:13.305Z
+ 2024-11-12T10:31:47.289Zhttps://avehtari.github.io/BDA_course_Aalto/assignments_gsu.html
- 2024-11-12T08:43:13.257Z
+ 2024-11-12T10:31:47.241Zhttps://avehtari.github.io/BDA_course_Aalto/FAQ.html
- 2024-11-12T08:43:13.257Z
+ 2024-11-12T10:31:47.241Zhttps://avehtari.github.io/BDA_course_Aalto/Aalto2024.html
- 2024-11-12T08:43:13.257Z
+ 2024-11-12T10:31:47.241Zhttps://avehtari.github.io/BDA_course_Aalto/Aalto2023.html
- 2024-11-12T08:43:13.257Z
+ 2024-11-12T10:31:47.241Zhttps://avehtari.github.io/BDA_course_Aalto/BDA3_notes.html
- 2024-11-12T08:43:13.257Z
+ 2024-11-12T10:31:47.241Zhttps://avehtari.github.io/BDA_course_Aalto/assignments.html
- 2024-11-12T08:43:13.257Z
+ 2024-11-12T10:31:47.241Zhttps://avehtari.github.io/BDA_course_Aalto/demos.html
- 2024-11-12T08:43:13.257Z
+ 2024-11-12T10:31:47.241Zhttps://avehtari.github.io/BDA_course_Aalto/index.html
- 2024-11-12T08:43:13.305Z
+ 2024-11-12T10:31:47.289Zhttps://avehtari.github.io/BDA_course_Aalto/project_gsu.html
- 2024-11-12T08:43:13.305Z
+ 2024-11-12T10:31:47.289Z