Skip to content

Commit

Permalink
Built site for gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Quarto GHA Workflow Runner committed Nov 12, 2024
1 parent 971a1c2 commit c19e8ca
Show file tree
Hide file tree
Showing 7 changed files with 434 additions and 451 deletions.
2 changes: 1 addition & 1 deletion .nojekyll
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fad23f16
b5eb6433
11 changes: 8 additions & 3 deletions FAQ.html
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,19 @@ <h3 class="anchored" data-anchor-id="install-pystan">Install <code>pystan</code>
<section id="i-missed-some-deadline-or-wasnt-able-to-do-some-part-of-the-course" class="level2">
<h2 class="anchored" data-anchor-id="i-missed-some-deadline-or-wasnt-able-to-do-some-part-of-the-course">I missed some deadline or wasn’t able to do some part of the course</h2>
<ul>
<li>Can I combine results from assignments, project, presentation, and e-exam made in different periods / years?
<ul>
<li>Yes.</li>
</ul></li>
<li>I missed the deadline to register for the course in Sisu. Can I join the course?
<ul>
<li>Yes, just register in MyCourses.</li>
<li>Yes, just register in MyCourses and contact student services that they add you in Sisu, too.</li>
</ul></li>
<li>I missed the deadline for the assignment. Can you accept my late submission?
<ul>
<li>Open MyCourses Quizzes are automatically submitted at the deadline time</li>
<li>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.</li>
<li>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.
--></li>
</ul></li>
<li>I was not able to do one of the assignments because [some personal problem]. Can I do some extra work?
<ul>
Expand Down
2 changes: 1 addition & 1 deletion assignments/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 &lt;- function(){\n res &lt;- try(out &lt;- 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 &lt;- 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 &lt;- 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 &lt;- numeric()\n ## Create a vector for the group identifier\n group &lt;- 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 &lt;- 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 &lt;- c(y, group_y)\n }\n\n # Combine into a data frame\n data &lt;- 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 &lt;- 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 &lt;- 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 &lt;- 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 &lt;- dat.konstantopoulos2011 |&gt;\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 &lt;- bf(\n formula = yi | se(sqrt(vi)) ~ 1,\n family = \"gaussian\"\n) \n\nschoolcalendar_pooled_fit &lt;- 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 &lt;- 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 &lt;- 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 &lt;- function(fit, dataset) {\n tidybayes::add_predicted_draws(dataset, fit) |&gt;\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 &lt;- function(){\n res &lt;- try(out &lt;- 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 &lt;- 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 &lt;- 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 &lt;- numeric()\n ## Create a vector for the group identifier\n group &lt;- 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 &lt;- 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 &lt;- c(y, group_y)\n }\n\n # Combine into a data frame\n data &lt;- 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 &lt;- 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 &lt;- 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 &lt;- 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 &lt;- dat.konstantopoulos2011 |&gt;\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 &lt;- bf(\n formula = yi | se(sqrt(vi)) ~ 1,\n family = \"gaussian\"\n) \n\nschoolcalendar_pooled_fit &lt;- 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 &lt;- 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 &lt;- 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 &lt;- function(fit, dataset) {\n tidybayes::add_predicted_draws(dataset, fit) |&gt;\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"
Expand Down
Binary file modified assignments/template3_files/figure-html/unnamed-chunk-10-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c19e8ca

Please sign in to comment.