I attached the PDF

I attached the PDF


Week 4 Assignment 3 PLS 350 Week 4 Assignment 3 PLS 350 Kilburn 2/5/2022 Assignment 4 With the data source of the European Social Survey, your assignment is to submit in an RMarkdown file, your code and output for either of the following: 1) a table of country level statistics (means or proportions) summarizing responses to one (or more) survey questions; or 2) a bar plot or similar data visualization displaying the same statistic in visual form. If you haven’t already done so, you need to read about the European Social Survey here: https://www.euro peansocialsurvey.org/. And you can check out the different waves and data here: http://nesstar.ess.nsd.uib. no/webview/. general steps in your analysis of survey data Each time you startup R to analyze survey data you need to keep in mind the following: 1. You will either import a survey dataset as an external file, such as the .dta ANES data file imported for last week. Or load an R workspace (.RData file) that already contains an imported dataset. This week, because the ESS data file is already imported into an R workspace. 2. You will want to start saving your datasets that you edit with all of your newly recoded variables. For example, after editing the ANES dataset, save it in an R workspace. To do so, go to Session > Save Workspace as. . . And then give it a name like PLS 350. You could keep adding datasets to it. 3. Make sure you create script files and save the recoding commands you use within each one. You could save them for each of the assignments you work on, o have one you work with for each assignment. 4. When you are recoding variables in the surveys, create new variables with memorable names rather than recode the existing survey variables. That way, if you make a mistake, the mistake is limited to the newly created variable, such as gender or party_id, rather than the original variable from the survey. recoding examples Loading the ESS data The European Social Survey datasets are relatively large. To make it easier to load them, I’ve saved the most recent wave (wave 9) in a RData workspace. –This is the workspace saved within the ESS RStudio project. Let’s first load the tidyverse and survey packages: library(tidyverse) ## -- Attaching packages --------------------------------------- tidyverse 1.3.1 -- ## v ggplot2 3.3.4 v purrr 0.3.4 ## v tibble 3.1.2 v dplyr 1.0.7 ## v tidyr 1.1.3 v stringr 1.4.0 1 https://www.europeansocialsurvey.org/ https://www.europeansocialsurvey.org/ http://nesstar.ess.nsd.uib.no/webview/ http://nesstar.ess.nsd.uib.no/webview/ ## v readr 1.4.0 v forcats 0.5.1 ## -- Conflicts ------------------------------------------ tidyverse_conflicts() -- ## x dplyr::filter() masks stats::filter() ## x dplyr::lag() masks stats::lag() library(survey) ## Loading required package: grid ## Loading required package: Matrix ## ## Attaching package: 'Matrix' ## The following objects are masked from 'package:tidyr': ## ## expand, pack, unpack ## Loading required package: survival ## ## Attaching package: 'survey' ## The following object is masked from 'package:graphics': ## ## dotchart Set your working directory to the location where you saved the ess9data.RData workspace. Then load it from the line below or use the menu Session > Load Workspace. . . and then find the .RData file. load("ess9data.RData") Accounting for the complex survey design in the ESS requires consulting an additional codebook beyond the one we use for looking up individual variables. Two different situations require different weighting strategies. To combine results from two or more countries, we need to be sure to include a weight that will analyze the surveys proportionally to country population – for example calculating averages across Belgium and Germany compared with another set of countries. Then there is the concern of using the correct weights for non-response and differential probabilities of selection (the ‘analytic weights’). So let’s go through the strata, clusters, and relevant weights. It gets confusing because of how the variables for weighting are named. The ‘analytic weight’ starts with pspwght, which is calculated to correct country samples for imbalances with gender, age, education, and region of the country. Then the variable pweight is the weight to account for different population sizes when combining survey data across countries. The ESS includes a variable anweight, which is the product of these two variables, anweight=pspwght*pweight. When we analyze data across multiple countries, we can use anweight. If we are analyzing data from a single country, we can use either anweight or pspwght, which will provide identical results — since pweight is constant within any one country. The sampling strata are identified by the variable stratum, and the sampling clusters by psu. So going back to the template for specifying the complex survey design: DESIGN_OBJECT<-svydesign(data =="" data,="" ids="~CLUSTER_VARIABLE," strata="~STRATA_VARIABLE," weights="~WEIGHT_VARIABLE)" the="" relevant="" variables="" for="" the="" ess="" survey="" design="" would="" be:="" 2=""><-svydesign(weights=~anweight, ids="~psu," strata="~stratum," data="ess9," nest="TRUE)" this="" line="" above="" is="" a="" survey="" design="" method="" that="" could="" be="" used="" for="" analyses="" combining="" countries="" or="" focusing="" on="" a="" single="" country.="" now,="" before="" you="" start="" running="" this="" line,="" keep="" in="" mind="" that="" the="" survey="" has="" over="" 30="" thousand="" observations,="" and="" the="" survey()="" function="" can="" take="" 20="" or="" 30="" seconds="" to="" complete,="" depending="" on="" how="" fast="" your="" computer="" is.="" so="" it="" may="" be="" preferable="" for="" you="" to="" work="" with="" a="" country="" subset="" of="" the="" data.="" –for="" example,="" you="" analyze="" only="" data="" for="" austria="" or="" belgium,="" or="" both,="" but="" not="" all="" countries.="" code="" below="" shows="" you="" how="" to="" subset="" the="" data.="" there="" are="" several="" available="" for="" the="" data.="" (see="" the="" project="" files.)="" the="" general="" codebook="" describes="" each="" of="" the="" different="" measures="" in="" the="" survey.="" a="" list="" of="" the="" “politics”="" questions="" are="" on="" page="" 8.="" the="" name="" of="" the="" dataset="" in="" the="" r="" workspace="" is="" ess9.="" the="" 36k="" observations="" are="" collected="" across="" all="" the="" countries="" surveyed.="" #example="" construction="" of="" a="" set="" of="" tables="" and="" bar="" plot="" an="" example="" follows.="" by="" country="" we="" will="" tabulate="" responses="" to="" the="" question="" asking="" “to="" what="" extent="" you="" agree="" or="" disagree="" with="" each="" of="" the="" following="" statements.="" .="" .="" gay="" men="" and="" lesbians="" should="" be="" free="" to="" live="" their="" own="" life="" as="" they="" wish.”="" responses="" range="" from="" “agree="" strongly”,="" “agree”,="" “neither="" agree="" nor="" disagree”,="" “disagree”,="" and="" “strongly="" disagree”.="" the="" variable="" is="" freehms,="" on="" page="" 64="" of="" the="" ess="" codebook.="" load("ess9data.rdata")="" #anweight="pspwght*pweight"><-svydesign(weights=~anweight, ids="~psu," strata="~stratum," data="ess9," nest="TRUE)" svytable(~freehms,="" design="ess_design," round="TRUE)" ##="" freehms="" ##="" agree="" strongly="" agree="" ##="" 18010="" 14833="" ##="" neither="" agree="" nor="" disagree="" disagree="" ##="" 4427="" 2356="" ##="" disagree="" strongly="" refusal="" ##="" 1813="" 306="" ##="" don't="" know="" no="" answer="" ##="" 694="" 0="" we="" can="" use="" the="" svytable()="" function="" for="" cross="" tabulating="" the="" responses="" by="" country="" —="" the="" variable="" cntry="" is="" country.="" svytable(~freehms="" +="" cntry,="" design="ess_design," round="TRUE)" ##="" cntry="" ##="" freehms="" at="" be="" bg="" ch="" cy="" cz="" de="" dk="" ee="" es="" ##="" agree="" strongly="" 327="" 524="" 47="" 327="" 11="" 177="" 3355="" 316="" 17="" 2014="" ##="" agree="" 253="" 304="" 132="" 289="" 27="" 362="" 2771="" 121="" 43="" 1427="" ##="" neither="" agree="" nor="" disagree="" 84="" 52="" 184="" 56="" 20="" 206="" 480="" 14="" 25="" 255="" ##="" disagree="" 43="" 37="" 65="" 31="" 8="" 83="" 258="" 9="" 15="" 130="" ##="" disagree="" strongly="" 25="" 23="" 69="" 10="" 6="" 42="" 223="" 20="" 9="" 42="" ##="" refusal="" 7="" 1="" 18="" 3="" 0="" 7="" 26="" 2="" 0="" 30="" ##="" don't="" know="" 16="" 5="" 90="" 6="" 1="" 18="" 50="" 1="" 0="" 70="" ##="" no="" answer="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" ##="" cntry="" ##="" freehms="" fi="" fr="" gb="" hr="" hu="" ie="" is="" it="" lt="" lv="" ##="" agree="" strongly="" 212="" 3583="" 2724="" 55="" 67="" 195="" 20="" 1307="" 13="" 27="" ##="" agree="" 167="" 1219="" 2049="" 138="" 205="" 153="" 7="" 2290="" 58="" 65="" 3="" ##="" neither="" agree="" nor="" disagree="" 47="" 355="" 431="" 52="" 231="" 18="" 1="" 757="" 67="" 23="" ##="" disagree="" 21="" 138="" 138="" 54="" 137="" 9="" 0="" 395="" 52="" 23="" ##="" disagree="" strongly="" 9="" 145="" 67="" 41="" 140="" 5="" 0="" 294="" 41="" 15="" ##="" refusal="" 3="" 11="" 9="" 2="" 11="" 0="" 0="" 98="" 0="" 2="" ##="" don't="" know="" 4="" 30="" 23="" 8="" 44="" 3="" 0="" 100="" 6="" 9="" ##="" no="" answer="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" ##="" cntry="" ##="" freehms="" me="" nl="" no="" pl="" pt="" rs="" se="" si="" sk="" ##="" agree="" strongly="" 4="" 876="" 281="" 513="" 341="" 52="" 542="" 30="" 53="" ##="" agree="" 14="" 464="" 124="" 1153="" 385="" 164="" 231="" 91="" 128="" ##="" neither="" agree="" nor="" disagree="" 14="" 49="" 19="" 623="" 57="" 124="" 32="" 25="" 127="" ##="" disagree="" 9="" 21="" 5="" 434="" 49="" 100="" 11="" 17="" 65="" ##="" disagree="" strongly="" 9="" 11="" 4="" 325="" 36="" 129="" 9="" 9="" 60="" ##="" refusal="" 0="" 2="" 2="" 37="" 4="" 14="" 3="" 1="" 13="" ##="" don't="" know="" 0="" 18="" 2="" 134="" 16="" 17="" 4="" 4="" 13="" ##="" no="" answer="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" we="" will="" create="" a="" new="" variable="" that="" combines="" the="" two="" agree="" and="" then="" the="" two="" disagree="" responses=""><-ess9 %="">% mutate(glfree=freehms)%>% mutate(glfree = fct_recode(glfree, "Agree" = "Agree strongly", "Agree" = "Agree", "Disagree" = "Disagree", "Disagree" = "Disagree strongly")) table(ess9$glfree) ## ## Agree Neither agree nor disagree ## 33956 6737 ## Disagree Refusal ## 7249 397 ## Don't know No answer ## 1179 1 We can tabulate these new responses after re-specifying the survey design. ess_design<-svydesign(weights=~anweight, ids="~psu," strata="~stratum," data="ess9," nest="TRUE)" svytable(~freehms="" +="" cntry,="" design="ess_design," round="TRUE)" ##="" cntry="" ##="" freehms="" at="" be="" bg="" ch="" cy="" cz="" de="" dk="" ee="" es="" ##="" agree="" strongly="" 327="" 524="" 47="" 327="" 11="" 177="" 3355="" 316="" 17="" 2014="" ##="" agree="" 253="" 304="" 132="" 289="" 27="" 362="" 2771="" 121="" 43="" 1427="" ##="" neither="" agree="" nor="" disagree="" 84="" 52="" 184="" 56="" 20="" 206="" 480="" 14="" 25="" 255="" ##="" disagree="" 43="" 37="" 65="" 31="" 8="" 83="" 258="" 9="" 15="" 130="" ##="" disagree="" strongly="" 25="" 23="" 69="" 10="" 6="" 42="" 223="" 20="" 9="" 42="" ##="" refusal="" 7="" 1="" 18="" 3="" 0="" 7="" 26="" 2="" 0="" 30="" ##="" don't="" know="" 16="" 5="" 90="" 6="" 1="" 18="" 50="" 1="" 0="" 70="" ##="" no="" answer="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" ##="" cntry="" ##="" freehms="" fi="" fr="" gb="" hr="" hu="" ie="" is="" it="" lt="" lv="" ##="" agree="" strongly="" 212="" 3583="" 2724="" 55="" 67="" 195="" 20="" 1307="" 13="" 27="" 4="" ##="" agree="" 167="" 1219="" 2049="" 138="" 205="" 153="" 7="" 2290="" 58="" 65="" ##="" neither="" agree="" nor="" disagree="" 47="" 355="" 431="" 52="" 231="" 18="" 1="" 757="" 67="" 23="" ##="" disagree="" 21="" 138="" 138="" 54="" 137="" 9="" 0="" 395="" 52="" 23="" ##="" disagree="" strongly="" 9="" 145="" 67="" 41="" 140="" 5="" 0="" 294="" 41="" 15="" ##="" refusal="" 3="" 11="" 9="" 2="" 11="" 0="" 0="" 98="" 0="" 2="" ##="" don't="" know="" 4="" 30="" 23="" 8="" 44="" 3="" 0="" 100="" 6="" 9="" ##="" no="" answer="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" ##="" cntry="" ##="" freehms="" me="" nl="" no="" pl="" pt="" rs="" se="" si="" sk="" ##="" agree="" strongly="" 4="" 876="" 281="" 513="" 341="" 52="" 542="" 30="" 53="" ##="" agree="" 14="" 464="" 124="" 1153="" 385="" 164="" 231="" 91="" 128="" ##="" neither="" agree="" nor="" disagree="" 14="" 49="" 19="" 623="" 57="" 124="" 32="" 25="" 127="" ##="" disagree="" 9="" 21="" 5="" 434="" 49="" 100="" 11="" 17="" 65="" ##="" disagree="" strongly="" 9="" 11="" 4="" 325="" 36="" 129="" 9="" 9="" 60="" ##="" refusal="" 0="" 2="" 2="" 37="" 4="" 14="" 3="" 1="" 13="" ##="" don't="" know="" 0="" 18="" 2="" 134="" 16="" 17="" 4="" 4="" 13="" ##="" no="" answer="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" svytable(~glfree="" +="" cntry,="" design="ess_design," round="TRUE)" ##="" cntry="" ##="" glfree="" at="" be="" bg="" ch="" cy="" cz="" de="" dk="" ee="" es="" ##="" agree="" 580="" 828="" 179="" 616="" 38="" 539="" 6125="" 437="" 61="" 3440="" ##="" neither="" agree="" nor="" disagree="" 84="" 52="" 184="" 56="" 20="" 206="" 480="" 14="" 25="" 255="" ##="" disagree="" 67="" 60="" 133="" 41="" 13="" 125="" 481="" 28="" 25="" 172="" ##="" refusal="" 7="" 1="" 18="" 3="" 0="" 7="" 26="" 2="" 0="" 30="" ##="" don't="" know="" 16="" 5="" 90="" 6="" 1="" 18="" 50="" 1="" 0="" 70="" ##="" no="" answer="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" ##="" cntry="" ##="" glfree="" fi="" fr="" gb="" hr="" hu="" ie="" is="" it="" lt="" lv="" ##="" agree="" 380="" 4802="" 4772="" 193="" 272="" 347="" 27="" 3597="" 72="" 92="" ##="" neither="" agree="" nor="" disagree="" 47="" 355="" 431="" 52="" 231="" 18="" 1="" 757="" 67="" 23="" ##="" disagree="" 30="" 283="" 205="" 95="" 278="" 13="" 0="" 688="" 93="" 38="" ##="" refusal="" 3="" 11="" 9="" 2="" 11="" 0="" 0="" 98="" 0="" 2="" ##="" don't="" know="" 4="" 30="" 23="" 8="" 44="" 3="" 0="" 100="" 6="" 9="" ##="" no="" answer="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" ##="" cntry="" ##="" glfree="" me="" nl="" no="" pl="" pt="" rs="" se="" si="" sk="" ##="" agree="" 18="" 1340="" 405="" 1666="" 726="" 216="" 773="" 120="" 181="" ##="" neither="" agree="" nor="" disagree="" 14="" 49="" 19="" 623="" 57="" 124="" 32="" 25="" 127="" ##="" disagree="" 18="" 32="" 8="" 759="" 84="" 229="" 20="" 25="" 125="" ##="" refusal="" 0="" 2="" 2="" 37="" 4="" 14="" 3="" 1="" 13="" ##="" don't="" know="" 0="" 18="" 2="" 134="" 16="" 17="" 4="" 4="" 13="" ##="" no="" answer="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" 0="" the="" number="" of="" digits="" is="" messy,="" so="" we="" can="" create="" a="" neater="" table:=""><-prop.table(svytable(~glfree + cntry, design=ess_design, round=true), margin=2) knitr::kable(table1*100, digits=0, caption="percentage agreement or disagreement with gay and lesbian free live own lives") 5 table 1: percentage agreement or disagreement with gay and lesbian free live own lives at be bg ch cy cz de dk ee es fi fr gb hr hu ie is it lt lv me nl no pl pt rs se si sk agree 77 88 30 85 53 60 86 91 55 87 82 88 88 55 33 91 96 69 30 56 36 93 93 52 82 36 93 69 39 neither agree nor disagree 11 5 30 8 28 23 7 3 23 6 10 6 8 15 28 5 4 14 28 14 28 3 4 19 6 21 4 14 28 disagree 9 6 22 6 18 14 7 6 23 4 6 5 4 27 33 3 0 13 39 23 36 2 2 24 9 38 2 14 27 refusal 1 0 3 0 0 1 0 0 0 1 1 0 0 +="" cntry,="" design="ess_design," round="TRUE)," margin="2)" knitr::kable(table1*100,="" digits="0," caption="Percentage agreement or disagreement with gay and lesbian free live own lives" )="" 5="" table="" 1:="" percentage="" agreement="" or="" disagreement="" with="" gay="" and="" lesbian="" free="" live="" own="" lives="" at="" be="" bg="" ch="" cy="" cz="" de="" dk="" ee="" es="" fi="" fr="" gb="" hr="" hu="" ie="" is="" it="" lt="" lv="" me="" nl="" no="" pl="" pt="" rs="" se="" si="" sk="" agree="" 77="" 88="" 30="" 85="" 53="" 60="" 86="" 91="" 55="" 87="" 82="" 88="" 88="" 55="" 33="" 91="" 96="" 69="" 30="" 56="" 36="" 93="" 93="" 52="" 82="" 36="" 93="" 69="" 39="" neither="" agree="" nor="" disagree="" 11="" 5="" 30="" 8="" 28="" 23="" 7="" 3="" 23="" 6="" 10="" 6="" 8="" 15="" 28="" 5="" 4="" 14="" 28="" 14="" 28="" 3="" 4="" 19="" 6="" 21="" 4="" 14="" 28="" disagree="" 9="" 6="" 22="" 6="" 18="" 14="" 7="" 6="" 23="" 4="" 6="" 5="" 4="" 27="" 33="" 3="" 0="" 13="" 39="" 23="" 36="" 2="" 2="" 24="" 9="" 38="" 2="" 14="" 27="" refusal="" 1="" 0="" 3="" 0="" 0="" 1="" 0="" 0="" 0="" 1="" 1="" 0="">
Apr 11, 2023
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here