Skip to content

Commit

Permalink
Revisiting lecture 5 slides (alt text, standard emphasis color, etc.)
Browse files Browse the repository at this point in the history
  • Loading branch information
njlyon0 committed Jun 21, 2024
1 parent 9ca8367 commit 482ad32
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
8 changes: 3 additions & 5 deletions _freeze/materials/slides_5a/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"hash": "15087d4804e162e9e0b471e02658f6dc",
"hash": "0d0678b80af192be288b1467b56dff57",
"result": {
"engine": "knitr",
"markdown": "---\ntitle: \"Intro to Data Science\"\nauthor: \"Lecture 5 -- Multi-Model Inference\"\nengine: knitr\nformat: \n revealjs: \n slide-number: c\n scrollable: false\n code-overflow: wrap\n code-line-numbers: false\n code-copy: hover\n theme: [night, slides.scss]\n reference-location: document\n footer: \"[Programming in R for Biologists](https://njlyon0.github.io/teach_r-for-biologists/)\"\n---\n\n\n## A Guide to Your Process\n\n### [Scheduling]{.blue}\n\n### [Learning Objectives]{.purple}\n\n### [Practice]{.pink}\n\n### [Supporting Information]{.orange}\n\n### [Class Discussion]{.gold}\n\n## [Today's Plan]{.blue}\n\n- Interactions\n- Multi-Model Inference\n- Mid-Term Instructor Evaluations\n- Free Work on Function Tutorials\n\n## [Today's Learning Objectives]{.purple}\n\nAfter today's session you will be able to:\n\n. . .\n\n- Perform analytical tests using R\n- Explain an \"interaction term\" in the context of life sciences\n- Compare model strengths in R\n\n## [Roadmap Reminder]{.orange}\n\n\\\n\n<p align=\"center\">\n<img src=\"images/stats-roadmap-v2.png\" alt=\"Expansion of previous roadmap table with a new row labeled 'multiple (separate)'. Categorical response with multiple continuous explanatory variables is still a generalized linear model. Continuous response with multiple categorical explanatory variables is an 'n-way ANOVA'.\" width=\"80%\">\n</p>\n\n## [Interaction Terms]{.orange}\n\n- So far, we've assumed the effect on Y is due to each X <u>separately</u>\n - In real life, the effect on Y may be due to [interactions among X variables]{.purple}!\n\n\\\n\n. . .\n\n- Arguably _all_ of biology lives in these interactions!\n\n## [Interactions Examples]{.orange}\n\n- Let's consider some examples to hopefully make this \"click\" for you\n\n\\\n\n. . . \n\n1. The number of ant hills (Y) depends on <u>both</u> how hot it is (X) and rainfall amounts (X)\n\n\\\n\n. . . \n\n2. Raccoons are fatter (Y) when they live close to humans (X) <u>and</u> the weather is mild (X)\n\n## [Interaction Visual]{.orange}\n\n- One more example:\n - Students enjoy (Y) talking about stats (X) if there are good visuals (X)\n\n. . .\n\n<p align=\"center\">\n<img src=\"images/interactions-visual.png\" alt=\"Bar graph with 'student enjoyment' on vertical axis and combinations of 'talking about statistics' and 'quality of visuals' on horizontal axis. Bar is highest when not talking about statistics but with good visuals and lowest when talking about stats without good visuals. Not talking about statistics without good visuals is medium low and talking about statistics with good visuals is medium high.\" width=\"55%\">\n</p>\n\n## [Roadmap Extension: Interactions]{.orange}\n\n<p align=\"center\">\n<img src=\"images/stats-roadmap-v3.png\" alt=\"Expansion of previous roadmap table with a new row labeled 'multiple (interacting)'. Categorical response with multiple interacting continuous explanatory variables is still a generalized linear model. Continuous response with multiple interacting categorical explanatory variables is an 'ANCOVA'.\" width=\"80%\">\n</p>\n\n## [R Syntax for Interactions]{.orange} {.smaller}\n\n- Two ways to add additional an interaction between two explanatory variables:\n - Use an asterisk (`*`) between the two terms\n - Use a colon (`:`)\n\n- Using an asterisk includes _both_ terms separately <u>and</u> their interaction\n\n\\\n\n. . . \n\n- Example syntax:\n```{.r}\n# Use the asterisk to test an interaction\nstat_test(response ~ exp1 * exp2, data = my_df)\n\n# Fit the SAME MODEL with a colon instead\nstat_(response ~ exp1 + exp2 + exp1:exp2, data = my_df)\n```\n\n## [<u>An</u>alysis of <u>Co</u>-<u>Va</u>riance (ANCOVA)]{.orange} {.smaller}\n\n- Multiple X variables and Y is continuous\n - X variables may be either categorical or continuous \n - Must also include an \"interaction term\" between (at least) two of the X variables\n\n\\\n\n. . .\n\n- Hypothesis: The effect on Y is due to _the interaction_ of X variables\n - H~0~: The effect on Y is not due to interactions among X variables\n\n\\\n\n. . .\n\n- Returns a P value for the interaction term and each X variable\n\n## [Practice: ANCOVA]{.pink} {.smaller}\n\n![](images/hex-penguins.png){.absolute top=0 left=1100 width=\"12%\"}\n\n- ANCOVA function is the same as the regular ANOVA / _n_-way ANOVA -- `aov`\n\n\\\n\n. . .\n\n- New penguin-related hypothesis:\n - H~A~: The relationship between bill length and bill depth differs by species\n - H~0~: Bill length-depth relationships are not species-dependent\n\n\\\n\n. . . \n\n- Test H~A~ with an interaction term!\n - Was your hypothesis supported?\n - What difference(s) do you see between this and a 2-way ANOVA summary table?\n\n## [Temperature Check]{.purple}\n\n#### How are you Feeling?\n\n<p align=\"center\">\n<img src=\"comics/debugging.png\" alt=\"Comic-style graph depicting someone's emotional state as they debug code (from initial struggle and defeat to eventual triumph)\">\n</p>\n\n## [Discussion: Null Hypothesis Testing]{.gold}\n\n- What lingering questions do you have on this topic?\n\n\\\n\n. . .\n\n- Is the \"roadmap\" helpful?\n - How can I change it to _more_ helpful (for future cohorts of students)?\n\n## [Multi-Model Inference (MMI)]{.orange} {.smaller}\n\n- MMI is an alternative to null hypothesis testing\n - P < 0.05 is an _arbitrary_ cutoff!\n\n\\\n\n. . .\n\n- Instead, we can make several \"candidate models\"\n - Basically several alternate hypotheses (H~A~)\n\n\\\n\n. . .\n\n- Fit data to all candidate models (separately) and compare [strength of fit]{.purple}\n - Candidate hypothesis with the strongest relationship to data is supported\n\n## [\"Model Strengths\"]{.orange} {.smaller}\n\n- 'Relative model strengths' is very different from P values\n - Still all about hypothesis testing though!\n\n\\\n\n. . .\n\n- P values ask \"does this affect things?\"\n - MMI asks \"does this affect things _more than other factors_?\"\n\n\\\n\n. . .\n\n- Model strength evaluated with an [information criterion]{.purple}\n - Way of summarizing each candidate model to decide the \"winner(s)\"\n\n## [Information Criteria]{.orange}\n\n- Most often: <u>A</u>kaike <u>I</u>nformation <u>C</u>riterion (AIC)\n - \\[Ah-kuh-ee-kay\\]\n\n\\\n\n- Lowest information criterion is best model\n - _BUT_ models with **<2 AIC points difference** are basically the same strength of fit\n\n\\\n\n. . .\n\n- Another arbitrary threshold!\n\n## [AIC Function]{.orange} {.smaller}\n\n- AIC function is just a list of all your models\n - Function is--helpfully--`AIC`\n\n\\\n\n. . .\n\n- Fit models using whichever stats test is appropriate\n - Remember the [roadmap]{.purple}!\n\n\\\n\n. . .\n\n- Example syntax:\n```{.r}\n# Fit some candidate models\nmod1 <- stat_test(resp ~ exp_1, data = my_df)\nmod2 <- stat_test(resp ~ exp_2, data = my_df)\nmod3 <- stat_test(resp ~ exp_1 + exp_2, data = my_df)\n\n# Compare their strengths\nAIC(mod1, mod2, mod3)\n```\n\n## [Practice: MMI]{.pink} {.smaller}\n\n- Fit the following four candidate models using the most appropriate test <u>for each</u>\n - H~A~: Penguin body mass differs among species\n - H~A~: Penguin body mass differs between sexes\n - H~A~: Penguin body mass differs among species _and_ between sexes\n - H~A~: Penguin body mass differs among species differently _depending on_ sex\n\n\\\n\n. . .\n\n- Which model best fits the data?\n - I.e., AIC is lowest\n\n\\\n\n. . .\n\n- What is the _next best_ model?\n\n## [Temperature Check]{.purple}\n\n#### How are you Feeling?\n\n<p align=\"center\">\n<img src=\"comics/debugging.png\" alt=\"Comic-style graph depicting someone's emotional state as they debug code (from initial struggle and defeat to eventual triumph)\">\n</p>\n\n## [Instructor Evaluations]{.gold} {.smaller}\n\n- Today is the first day of the second half of the course!\n\n\\\n\n- I hope you all are having a fun time\n - Hopefully not ironic to say that after two days of stats `<svg aria-label=\"Face Smile\" role=\"img\" viewBox=\"0 0 512 512\" style=\"height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:currentColor;overflow:visible;position:relative;\"><title>Face Smile</title><path d=\"M464 256A208 208 0 1 0 48 256a208 208 0 1 0 416 0zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zm177.6 62.1C192.8 334.5 218.8 352 256 352s63.2-17.5 78.4-33.9c9-9.7 24.2-10.4 33.9-1.4s10.4 24.2 1.4 33.9c-22 23.8-60 49.4-113.6 49.4s-91.7-25.5-113.6-49.4c-9-9.7-8.4-24.9 1.4-33.9s24.9-8.4 33.9 1.4zM144.4 208a32 32 0 1 1 64 0 32 32 0 1 1 -64 0zm192-32a32 32 0 1 1 0 64 32 32 0 1 1 0-64z\"/></svg>`{=html}\n\n\\\n\n- Would really appreciate you filling out an _anonymous_ evaluation for me!\n - What am I doing well?\n - What could I improve on for the rest of the course?\n - Any other feedback you'd like to share?\n\n## [Upcoming Due Dates]{.blue} {.smaller}\n\n::::{.columns}\n:::{.column width=\"50%\"}\n\n### Due before lab\n\n#### (By midnight)\n\n- Muddiest Point \\#5\n- [Draft 1]{.pink} of Function Tutorials\n - Double check rubric to see that you’re not leaving any points on the table!\n\n:::\n:::{.column width=\"50%\"}\n\n### Due before lecture\n\n#### (By midnight)\n\n- Homework \\#5\n\n:::\n::::\n\n## [Free Work on Function Tutorials]{.pink} {.smaller}\n\n- Draft 1 is due [tomorrow night at midnight]{.blue}!\n\n\\\n\n. . .\n\n- Tips for success:\n - Check out the rubric and make sure you don't miss any \"easy\" points\n - Don't leave after this slide!\n - I.e., make good use of this free work time to make sure you're looking good for that due date\n\n\\\n\n. . .\n\n- If you have questions, ask them <u>_now_</u> during this free work time\n",
"supporting": [
"slides_5a_files"
],
"markdown": "---\ntitle: \"Intro to Data Science\"\nauthor: \"Lecture 5 -- Multi-Model Inference\"\nengine: knitr\nformat: \n revealjs: \n slide-number: c\n scrollable: false\n code-overflow: wrap\n code-line-numbers: false\n code-copy: hover\n theme: [night, slides.scss]\n reference-location: document\n footer: \"[Programming in R for Biologists](https://njlyon0.github.io/teach_r-for-biologists/)\"\n---\n\n\n## A Guide to Your Process\n\n### [Scheduling]{.blue}\n\n### [Learning Objectives]{.purple}\n\n### [Practice]{.pink}\n\n### [Supporting Information]{.orange}\n\n### [Class Discussion]{.gold}\n\n## [Today's Plan]{.blue}\n\n- Interactions\n- Multi-Model Inference\n- Mid-Term Instructor Evaluations\n- Free Work on Function Tutorials\n\n## [Today's Learning Objectives]{.purple}\n\nAfter today's session you will be able to:\n\n. . .\n\n- Perform more analytical tests using R\n- Explain an \"interaction term\" in the context of life sciences\n- Compare model strengths in R\n\n## [Roadmap Reminder]{.orange}\n\n\\\n\n<p align=\"center\">\n<img src=\"images/stats-roadmap-v2.png\" alt=\"Expansion of previous roadmap table with a new row labeled 'multiple (separate)'. Categorical response with multiple continuous explanatory variables is still a generalized linear model. Continuous response with multiple categorical explanatory variables is an 'n-way ANOVA'.\" width=\"80%\">\n</p>\n\n## [Interaction Terms]{.orange} {.smaller}\n\n- So far, we've assumed the effect on Y is due to each X <u>separately</u>\n - In real life, the effect on Y may be due to [interactions among X variables]{.purple}!\n\n\\\n\n. . .\n\n- Arguably, _all_ of biology lives in these interactions!\n\n## [Interactions Examples]{.orange} {.smaller}\n\n- Let's consider some examples to hopefully make this \"click\" for you\n\n\\\n\n. . . \n\n1. The number of ant hills (Y) depends on <u>both</u> how hot it is (X) and how rainy it is (X)\n\n\\\n\n. . . \n\n2. Raccoons are fatter (Y) when they live close to humans (X) <u>and</u> the weather is mild (X)\n\n## [Interaction Visual]{.orange}\n\n- One more example:\n - Students enjoy (Y) talking about stats (X) if there are good visuals (X)\n\n. . .\n\n<p align=\"center\">\n<img src=\"images/interactions-visual.png\" alt=\"Bar graph with 'student enjoyment' on vertical axis and combinations of 'talking about statistics' and 'quality of visuals' on horizontal axis. Bar is highest when not talking about statistics but with good visuals and lowest when talking about stats without good visuals. Not talking about statistics without good visuals is medium low and talking about statistics with good visuals is medium high.\" width=\"55%\">\n</p>\n\n## [Roadmap Extension: Interactions]{.orange}\n\n<p align=\"center\">\n<img src=\"images/stats-roadmap-v3.png\" alt=\"Expansion of previous roadmap table with a new row labeled 'multiple (interacting)'. Categorical response with multiple interacting continuous explanatory variables is still a generalized linear model. Continuous response with multiple interacting categorical explanatory variables is an 'ANCOVA'.\" width=\"80%\">\n</p>\n\n## [R Syntax for Interactions]{.orange} {.smaller}\n\n- Two ways to add additional an interaction between two explanatory variables:\n - Use an asterisk (`*`) between the two terms\n - Use a colon (`:`)\n\n\\\n\n. . .\n\n- Using an asterisk includes _both_ terms separately <u>and</u> their interaction\n\n\\\n\n. . . \n\n- Example syntax:\n```{.r}\n# Use the asterisk to test an interaction\nstat_test(response ~ exp1 * exp2, data = my_df)\n\n# Fit the SAME MODEL with a colon instead\nstat_(response ~ exp1 + exp2 + exp1:exp2, data = my_df)\n```\n\n## [<u>An</u>alysis of <u>Co</u>-<u>Va</u>riance (ANCOVA)]{.orange} {.smaller}\n\n- Multiple X variables and Y is continuous\n - X variables may be either categorical or continuous \n - Must also include an \"interaction term\" between (at least) two of the X variables\n\n\\\n\n. . .\n\n- Hypothesis: The effect on Y is due to _the interaction_ of X variables\n - H~0~: The effect on Y is not due to interactions among X variables\n\n\\\n\n. . .\n\n- Returns a P value for the interaction term and each X variable separately\n\n## [Practice: ANCOVA]{.pink} {.smaller}\n\n![](images/hex-penguins.png){.absolute top=0 left=1100 width=\"12%\" fig-alt=\"hex logo for the palmerpenguins R package\"}\n\n- ANCOVA function is the same as the regular ANOVA / _n_-way ANOVA -- `aov`\n\n\\\n\n. . .\n\n- New penguin-related hypothesis:\n - H~A~: Penguin body mass differs among species and within a species at different islands\n - H~0~: Island differences on penguin body mass are not species-dependent\n\n\\\n\n. . . \n\n- Test H~A~ with an interaction term!\n - Was your hypothesis supported?\n - What difference(s) do you see between this and a 2-way ANOVA summary table?\n\n## [Temperature Check]{.purple}\n\n#### How are you Feeling?\n\n<p align=\"center\">\n<img src=\"comics/debugging.png\" alt=\"Comic-style graph depicting someone's emotional state as they debug code (from initial struggle and defeat to eventual triumph)\">\n</p>\n\n## [Discussion: Null Hypothesis Testing]{.gold}\n\n- What lingering questions do you have on this topic?\n\n\\\n\n. . .\n\n- Is the \"roadmap\" helpful?\n - How can I change it to _more_ helpful (for future cohorts of students)?\n\n## [Multi-Model Inference (MMI)]{.orange} {.smaller}\n\n- MMI is an alternative to null hypothesis testing\n - P < 0.05 is an _arbitrary_ cutoff!\n\n\\\n\n. . .\n\n- Instead, we can make several \"candidate models\"\n - Basically several alternate hypotheses (H~A~)\n\n\\\n\n. . .\n\n- Fit data to all candidate models (separately) and compare [strength of fit]{.purple}\n - Candidate hypothesis with the strongest relationship to data is supported\n\n## [\"Model Strengths\"]{.orange} {.smaller}\n\n- 'Relative model strengths' is very different from P values\n - Still all about hypothesis testing though!\n\n\\\n\n. . .\n\n- P values ask \"does this affect things _more than if nothing is happening_?\"\n - MMI asks \"does this affect things _more than other variables/combinations of variables_?\"\n\n\\\n\n. . .\n\n- Model strength evaluated with an [information criterion]{.purple}\n - Way of summarizing each candidate model to decide the 'winner(s)'\n\n## [Information Criteria]{.orange} {.smaller}\n\n- Most often: <u>A</u>kaike <u>I</u>nformation <u>C</u>riterion ([AIC]{.purple})\n - \\[Ah-kuh-EE-kay\\]\n\n\\\n\n- Lowest information criterion is best model\n - _BUT_ models with **<2 AIC points difference** are basically the same strength of fit\n\n\\\n\n. . .\n\n- Another arbitrary threshold!\n\n## [AIC Function]{.orange} {.smaller}\n\n- AIC function is just a list of all your models\n - Function is--helpfully--`AIC`\n\n\\\n\n. . .\n\n- Fit models using whichever stats test is appropriate\n - Then compare AIC scores for each model\n\n\\\n\n. . .\n\n- Example syntax:\n```{.r}\n# Fit some candidate models\nmod1 <- stat_test(resp ~ exp_1, data = my_df)\nmod2 <- stat_test(resp ~ exp_2, data = my_df)\nmod3 <- stat_test(resp ~ exp_1 + exp_2, data = my_df)\n\n# Compare their strengths\nAIC(mod1, mod2, mod3)\n```\n\n## [Practice: MMI]{.pink} {.smaller}\n\n![](images/hex-penguins.png){.absolute top=0 left=1100 width=\"12%\" fig-alt=\"hex logo for the palmerpenguins R package\"}\n\n- Fit the following four candidate models using the most appropriate test <u>for each</u>\n - H~A~: Penguin body mass differs among species\n - H~A~: Penguin body mass differs between sexes\n - H~A~: Penguin body mass differs among species _and_ between sexes\n - H~A~: Penguin body mass differences between sexes _depend on_ the species\n\n\\\n\n. . .\n\n- Which model best fits the data?\n - I.e., AIC is lowest\n\n\\\n\n. . .\n\n- What is the _next best_ model?\n\n## [Temperature Check]{.purple}\n\n#### How are you Feeling?\n\n<p align=\"center\">\n<img src=\"comics/debugging.png\" alt=\"Comic-style graph depicting someone's emotional state as they debug code (from initial struggle and defeat to eventual triumph)\">\n</p>\n\n## [Instructor Evaluations]{.gold} {.smaller}\n\n- Today is the first day of the second half of the course!\n\n\\\n\n. . .\n\n- I hope you all are having a fun time\n - Hopefully not ironic to say that after two days of stats `<svg aria-label=\"Face Smile\" role=\"img\" viewBox=\"0 0 512 512\" style=\"height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:currentColor;overflow:visible;position:relative;\"><title>Face Smile</title><path d=\"M464 256A208 208 0 1 0 48 256a208 208 0 1 0 416 0zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zm177.6 62.1C192.8 334.5 218.8 352 256 352s63.2-17.5 78.4-33.9c9-9.7 24.2-10.4 33.9-1.4s10.4 24.2 1.4 33.9c-22 23.8-60 49.4-113.6 49.4s-91.7-25.5-113.6-49.4c-9-9.7-8.4-24.9 1.4-33.9s24.9-8.4 33.9 1.4zM144.4 208a32 32 0 1 1 64 0 32 32 0 1 1 -64 0zm192-32a32 32 0 1 1 0 64 32 32 0 1 1 0-64z\"/></svg>`{=html}\n\n\\\n\n. . .\n\n- Would really appreciate you filling out an _anonymous_ evaluation for me!\n - What am I doing well?\n - What could I improve on for the rest of the course?\n - Any other feedback you'd like to share?\n\n## [Upcoming Due Dates]{.blue} {.smaller}\n\n::::{.columns}\n:::{.column width=\"50%\"}\n\n### Due before lab\n\n#### (By midnight)\n\n- Muddiest Point \\#5\n- [Draft 1]{.blue} of Function Tutorials\n - Double check rubric to see that you’re not leaving any points on the table!\n\n:::\n:::{.column width=\"50%\"}\n\n### Due before lecture\n\n#### (By midnight)\n\n- Homework \\#5\n\n:::\n::::\n\n## [Free Work on Function Tutorials]{.pink} {.smaller}\n\n- Draft 1 is due [tomorrow night at midnight]{.blue}!\n\n\\\n\n. . .\n\n- Tips for success:\n - Check out the rubric and make sure you don't miss any \"easy\" points\n - Don't leave after this slide!\n - I.e., make good use of this free work time to make sure you're looking good for that due date\n\n\\\n\n. . .\n\n- If you have questions, ask them <u>_now_</u> during this free work time\n",
"supporting": [],
"filters": [
"rmarkdown/pagebreak.lua"
],
Expand Down
Loading

0 comments on commit 482ad32

Please sign in to comment.