class: center, middle, inverse, title-slide .title[ # Multiple Regression &
Fundamentals of Causal Inference ] .subtitle[ ##
1. Introduction ] .author[ ### Merlin Schaeffer
Department of Sociology ] .date[ ### 2024-09-03 ] --- # Course structure .left-column[ <br> | TA | Fridays | Room | |:---------|:---------|:-----------| | Adna | 8 am | CSS 2-1-02 | | Josefine | 8 am | CSS 4-1-30 | | Elias | 10 am | CSS 2-2-55 | | Jonas | 10 am | CSS 2-1-55 | ] .right-column[ <img src="./img/Structure.png" width="100%" style="display: block; margin: auto;" /> ] --- class: middle center background-image: url("https://stanfordbloodcenter.org/wp-content/uploads/2021/01/iStock-1208283967.jpg") background-position: center background-size: cover .font160[ **My research agenda** ] .font200[ **How Does International Immigration<br><br>Transform our Societies?** ] --- layout: true # Some of my current work --- .left-column[ <img src="https://www.templehealth.org/sites/default/files/styles/without_crop/public/2021-01/man-wearing-mask-coughing-into-shoulder.jpg?itok=Z6mUgWPd" width="100%" style="display: block; margin: auto;" /> ] .right-column[ <img src="./img/Paired_Vignette.png" width="100%" style="display: block; margin: auto;" /> .center[.backgrnote[*Source*: Schaeffer and Haderup Larsen (2023)]] ] --- <img src="./img/jcac025f1.jpeg" width="80%" style="display: block; margin: auto;" /> .center[.backgrnote[*Source*: Schaeffer and Haderup Larsen (2023)]] --- <img src="./img/Krzysz.png" width="42%" style="display: block; margin: auto;" /> .center[.backgrnote[*Source*: Krakowski, Schaeffer, Romarri, and Rosenberg (2022)]] --- <img src="./img/IT-Healthcare.png" width="95%" style="display: block; margin: auto;" /> .center[.backgrnote[*Source*: Krakowski, Schaeffer, Romarri et al. (2022)]] --- <img src="./img/Wiedner.png" width="45%" style="display: block; margin: auto;" /> .center[.backgrnote[*Source*: Wiedner, Schaeffer, Carol, and Böller (2023)]] --- layout: false class: inverse middle center # Explanatory Sociology --- # 4 Types of research questions .push-left[ **(1) Ontological**: What is the nature of .alert[X]? + What is power? + What is gender; how is it different from race? + What is a state? .backgrnote[ > A human community that (successfully) claims the monopoly of the legitimate use of physical force within a given territory > -- Max Weber, "Politics as a Vocation" 1918] **(2) Critical**: Is .alert[X] (un-)just? + Is home office exploitation? + Is the color-blind ideology a new form of racism? ] -- .push-right[ **(3) Descriptive**: What types of .alert[X] exist<br> and how frequent are they? + What are the survival strategies of the poor? + How did Danes structure their days during the COVID-19 lockdowns? **(4) Explanatory**: What is the effect of .alert[X]? - What are the consequences of anomie? <br> .backgrnote[Why does the suicide rate vary across societies?] - How does capitalism affect us? - How does urbanization affect us? - .backgrnote[Why do people obey power?] - .backgrnote[How does a state gain legitimacy over the use of physical force?] ] -- .content-box-green[ .center[ Think of the last exam you wrote. What type of research question did it enage with? ]] --- # 4 Types of research questions .push-left[ **(1) Ontological**: What is the nature of .alert[X]? + What is power? + What is gender; how is it different from race? + What is a state? .backgrnote[ > A human community that (successfully) claims the monopoly of the legitimate use of physical force within a given territory > -- Max Weber, "Politics as a Vocation" 1918] **(2) Critical**: Is .alert[X] (un-)just? + Is home office exploitation? + Is the color-blind ideology a new form of racism? ] .push-right[ **(3) Descriptive**: What types of .alert[X] exist<br> and how frequent are they? + What are the survival strategies of the poor? + How did Danes structure their days during the COVID-19 lockdowns? .content-box-red[ **(4) Explanatory**: What is the effect of `\(X\)`? - What are the consequences of anomie? <br> .backgrnote[Why does the suicide rate vary across societies?] - How does capitalism affect us? - How does urbanization affect us? - .backgrnote[Why do people obey power?] - .backgrnote[How does a state gain legitimacy over the use of physical force?] ]] --- # Goal of empirical sociology .font130[.center[Use data to discover patterns, <br> and the .alert[social mechanisms that bring them about.]]] <img src="https://liu.se/-/media/istock-501261958.jpg?mw=1120&mh=1120&hash=DA8977CCE6A6E600AE80A40CFEE771C9" width="70%" style="display: block; margin: auto;" /> --- class: inverse middle center # Three learning goals --- # Three learning goals .push-left[ **(1) Multiple OLS regression** + Multiple predictors & confounder adjustment, + Interaction effects, + Polynomials. **(2) Visualization of regression results** + Model predictions, + Coefficient plots. <img src="https://www.journals.uchicago.edu/cms/10.1086/686942/asset/images/medium/fg3.gif" width="65%" style="display: block; margin: auto;" /> .backgrnote[.center[*Source:* Legewie and Schaeffer (2016)]] ] -- .push-right[ **(3) Fundamentals of causal inference** + Potential outcomes and directed acyclical graphs, + Randomized Controlled Trials, + Intention to treat & instrument variable regression, + Multiple regression, + 2-SLS instrument variable regression, + Regression discontinuity designs. <img src="1-Introduction_files/figure-html/DAG1-1.png" width="45%" style="display: block; margin: auto;" /> ] --- layout: false class: clear # Example: Regression discontinuity design .push-left[ <img src="https://pbs.twimg.com/media/FOH1FlhWUAIqbN1.jpg:large" width="62%" style="display: block; margin: auto;" /> ] .push-right[ <img src="https://pbs.twimg.com/media/FZIn0ymXgAAOopA.jpg:large" width="100%" style="display: block; margin: auto;" /> ] --- class: clear # Example: Regression discontinuity design .push-left[ <img src="https://pbs.twimg.com/media/FOH1FlhWUAIqbN1.jpg:large" width="62%" style="display: block; margin: auto;" /> ] .push-right[ .center[Municipalities where far-right candidates <br> *ran* versus where they *won*] <img src="./img/Map_Italy.png" width="100%" style="display: block; margin: auto;" /> .backgrnote[.center[*Source:* Romarri (2020)]] ] --- class: clear # Example: Regression discontinuity design <img src="./img/Romarri.png" width="50%" style="display: block; margin: auto;" /> .backgrnote[.center[*Source:* Romarri (2020)]] --- class: clear # Example: Regression discontinuity design .left-column[ <img src="./img/Krzysz.png" width="100%" style="display: block; margin: auto;" /> ] .right-column[ <img src="./img/Figure2a-1.png" width="100%" style="display: block; margin: auto;" /> .backgrnote[.center[*Source:* Krakowski, Schaeffer, Romarri et al. (2022)]] ] --- class: inverse middle center # Break <iframe src='https://www.online-timer.net/' width='400' height='385' frameborder='0' scrolling='yes'></iframe> --- # Course structure .right-column[ <img src="./img/Structure.png" width="100%" style="display: block; margin: auto;" /> ] -- .left-column[ .center[**Recommendations**] - Activate email notifications on Absalon. - Regularly check your KU email or forward it to your personal email. - Ask and answer questions in the [t-R-ouble forum](https://absalon.ku.dk/courses/70545/discussion_topics/563046?module_item_id=2037268) on Absalon. ] --- class: clear <img src="./img/Quizz1.png" width="60%" style="display: block; margin: auto;" /><img src="./img/Quizz2.png" width="60%" style="display: block; margin: auto;" /><img src="./img/Quizz3.png" width="60%" style="display: block; margin: auto;" /> --- # Weekly Absalon Online Quizzes .left-column[ - 13 Online Quizzes on Absalon designed by [Epinion](https://epinionglobal.com/) & Adna. - Based on data Epinion collects for municipality of Copenhagen, DR, Skat, etc. - .alert[Submit at least 10 completed quizzes] to qualify for the integrated exam with "Velfærd, ulighed og mobilitet"! - .alert[Submit individually and within two weeks] after they are made available online (i.e., Wednesdays after the lecture). ] .right-column[ <img src="./img/Quizz1.png" width="80%" style="display: block; margin: auto;" /><img src="./img/Quizz2.png" width="80%" style="display: block; margin: auto;" /><img src="./img/Quizz3.png" width="80%" style="display: block; margin: auto;" /> ] --- class: inverse # Consequently, this course assumes 1. You have basic R coding skills and know how to use RStudio. -- 2. You know basic statistics: + Descriptive statistics: `\(\%\)`, `\(\bar{x}\)`, `\(\text{SD}(x)\)`. + Associations: + Correlation: `\(r_{y,x}\)`, + OLS regression: `\(y_{i} = \alpha + \beta x_{i} + \epsilon_{i}\)`. + Inference: Confidence intervals, `\(t\)`-values & `\(p\)`-values. --- layout: false # Two textbooks `\(\rightarrow\)` Both textbooks are accessible at Academic Books and are available at the university library. .push-left[ .center[The first textbook, carried over from last semester, serves as a reference for regression and statistical inference.] <img src="https://imgcdn.saxo.com/_9781292362328" width="40%" style="display: block; margin: auto;" /> .backgrnote[.center[Veaux, Velleman, and Bock (2021)]] ] .push-right[ .center[To deepen our understanding of how regression analysis can be applied to identify causal effects, we will heavily rely on Angrist and Pischke's textbook] <img src="https://imgcdn.saxo.com/_9780691152844" width="35%" style="display: block; margin: auto;" /> .backgrnote[.center[Angrist and Pischke (2014)]] ] --- class: inverse middle center # Questions <img src="https://www.mountpolley.com/wp-content/uploads/2020/08/pexels-pixabay-356079-1200x726.jpg" width="50%" style="display: block; margin: auto;" /> --- # Task 1 1. Get a [recent version of R (>= 4.3.0)](https://mirrors.dotsrc.org/cran/). 2. [Install RStudio](https://posit.co/download/rstudio-desktop/), or update to the most recent version. --- # Task 2 .font70[Open RStudio and follow these instructions] <img src="https://d33wubrfki0l68.cloudfront.net/8a64bb047429d7ae0e2acae35c40e421e6439bf6/80e5d/diagrams/rstudio-editor.png" width="55%" style="display: block; margin: auto;" /> --- # Task 3 .font70[Set R Studio preferences] .left-column[ Set these preferences to improve *reproducibility*!<br> `\(\rightarrow\)` RStudio/Tools/Global options. ] .right-column[ <img src="https://d33wubrfki0l68.cloudfront.net/7fa44a5471d40025344176ede4169c5ad3159482/1577f/screenshots/rstudio-workspace.png" width="70%" style="display: block; margin: auto;" /> ] --- # R Studio workflow .left-column[ 1. Use **Projects** to manage all files (scripts, data, figures and tables) belonging to the same project. 2. Always start your RStudio session by clicking on the **Project** for this course. 2. Use the editor the write as many **R scripts** as you like, save them in the same folder as your **Project**. Thereby you can reproduce your results. ] .right-column[ <img src="https://d33wubrfki0l68.cloudfront.net/8a64bb047429d7ae0e2acae35c40e421e6439bf6/80e5d/diagrams/rstudio-editor.png" width="85%" style="display: block; margin: auto;" /> ] --- # Set up your "Stats_II" project .left-column[ - Click on the Project button. ] .right-column[ <img src="./img/RProject1.png" width="40%" style="display: block; margin: auto;" /> ] --- layout: true # Set up your "Stats_II" project .left-column[ Set up a new project in R Studio. 1. "New Directory" 2. "New Project" 3. Finally, a name for the folder and under "Browse" where you want that folder to be located. I call mine Stats_II. + This will also generate a folder with the name you chose. Use that folder for everything related to this course. **Done!** Now you should find an empty folder under the path your wanted it to be set up. .alert[In the future, always start RStudio by double clicking on the project icon in your folder for this course.] ] --- .right-column[ <img src="./img/RProject2.png" width="90%" style="display: block; margin: auto;" /> ] --- .right-column[ <img src="./img/RProject3.png" width="90%" style="display: block; margin: auto;" /> ] --- .right-column[ <img src="./img/RProject4.png" width="90%" style="display: block; margin: auto;" /> ] --- .right-column[ <img src="./img/RProject5.png" width="90%" style="display: block; margin: auto;" /> ] --- layout: false layout: true # R Scripts --- .left-column[ 1. Open a new R Script. 2. Save it in your new folder. + Find it under "Files". ] .right-column[ <img src="./img/Rscript1.png" width="100%" style="display: block; margin: auto;" /> ] --- .left-column[ 1. Type the lines shon in the screenshot on the right. 2. Save the file by clicking on the flopy disc icon; - I called mine "Lecture.R". 3. Mark all code and click "run". ] .right-column[ <img src="./img/Rscript3.png" width="100%" style="display: block; margin: auto;" /> ] --- .left-column[ OK, you are good to go! **Pro tip:** *Use the R Script to take notes during the lecture!* A `#` defines a comment. So use it to take notes and code in one single document per lecture. ] .right-column[ <img src="./img/Rscript4.png" width="100%" style="display: block; margin: auto;" /> ] --- layout: false class: clear # AI & Large Language Models like ChatGPT .push-left[ 1. **Privacy**: .alert[Don't use AI/LLMs to process sensitive information!] 2. **Learning**: Use AI/LLMs to *explain, comment, debug, and improve* R code that you drafted. Also use AI/LLMs to get *summaries* of text passages and concepts that you do not understand. This will help you to read complex texts and better understand difficult topics. You can also use use AI/LLMs to *discuss* your understanding of the course materials and ask things that confuse you. 3. **Generation**: Don't use AI/LLMs to *generate, draft, and write* your R code. .alert[You need to learn how to code to assess whether ChatGPT coded what you asked for.] ] .push-right[ <img src="https://media1.giphy.com/media/iiSb58oATiANL65Dd2/giphy.gif?cid=ecf05e470i00dk1kq5bvalzh4irqygm4pieeqkdyz9vk76ht&ep=v1_gifs_search&rid=giphy.gif&ct=g" width="100%" style="display: block; margin: auto;" /> ] --- # References .push-left[ .font70[ Angrist, J. D. and J. Pischke (2014). _Mastering 'Metrics: The Path from Cause to Effect_. Princeton University Press. Krakowski, K., M. Schaeffer, A. Romarri, et al. (2022). "Populist Right-Wing Governors, Healthcare Chauvinism, and Public Health in the Time of the Global Pandemic". In: _Unpublished manuscript_. Legewie, J. and M. Schaeffer (2016). "Contested Boundaries: Explaining Where Ethnoracial Diversity Provokes Neighborhood Conflict". In: _American Journal of Sociology_, pp. 125-161. Romarri, A. (2020). _Do Far-Right Mayors Increase the Probability of Hate Crimes? Evidence From Italy_. SSRN Scholarly Paper ID 3506811. Rochester, NY: Social Science Research Network. Schaeffer, M. and M. Haderup Larsen (2023). "Who Should Get Vaccinated First? Limits of Solidarity during the First Week of the Danish Vaccination Programme". In: _European Sociological Review_, pp. 1-13. ]] .push-right[ .font70[ Veaux, D., Velleman, and Bock (2021). _Stats: Data and Models, Global Edition_. Pearson Higher Ed. Wiedner, J., M. Schaeffer, S. Carol, et al. (2023). "Ethno-Religious Minority Infrastructures: Why Do Some Immigrant Minorities Build Dense Organizational Infrastructures While Others Do not?" In: _Unpublished manuscript_. ]]