Companion to R analysis second addition

Looking for assistance on figuring out how to open and operate gssD dataset. Help would be greatly appreciated. Thank you.

library(poliscidata)
gssD
#> Independent Sampling design (with replacement)
#> survey::svydesign(id = ~1, data = gss, weights = ~wtss)
str(gssD)
#> List of 9
#>  $ cluster   :'data.frame':  1974 obs. of  1 variable:
#>   ..$ id: int [1:1974] 1 2 3 4 5 6 7 8 9 10 ...
#>  $ strata    :'data.frame':  1974 obs. of  1 variable:
#>   ..$ V1: num [1:1974] 1 1 1 1 1 1 1 1 1 1 ...
#>  $ has.strata: logi FALSE
#>  $ prob      : Named num [1:1974] 0.381 0.286 0.572 0.809 1.144 ...
#>   ..- attr(*, "names")= chr [1:1974] "1" "2" "3" "4" ...
#>  $ allprob   :'data.frame':  1974 obs. of  1 variable:
#>   ..$ wtss: num [1:1974] 0.381 0.286 0.572 0.809 1.144 ...
#>  $ call      : language survey::svydesign(id = ~1, data = gss, weights = ~wtss)
#>  $ variables :'data.frame':  1974 obs. of  221 variables:
#>   ..$ year            : num [1:1974] 2012 2012 2012 2012 2012 ...
#>   ..$ id              : num [1:1974] 1 2 3 4 5 6 7 8 9 10 ...
#>   ..$ wrkstat         : Factor w/ 7 levels "WORKING FULL TIME",..: 2 2 1 NA 5 NA 7 7 7 1 ...
#>   ..$ wrkslf          : Factor w/ 2 levels "SELF-EMPLOYED",..: 2 2 2 2 2 2 2 NA NA 2 ...
#>   ..$ wrkgvt          : Factor w/ 2 levels "GOVERNMENT","PRIVATE": 2 2 2 2 1 2 2 NA NA 2 ...
#>   ..$ marital         : Factor w/ 5 levels "Married","Widowed",..: 5 5 1 1 4 2 1 4 1 5 ...
#>   ..$ sibs            : num [1:1974] 1 2 1 2 0 4 2 2 2 0 ...
#>   .. ..- attr(*, "value.labels")= Named num(0) 
#>   .. .. ..- attr(*, "names")= chr(0) 
#>   ..$ childs          : num [1:1974] 0 0 2 2 3 2 2 3 2 0 ...
#>   .. ..- attr(*, "value.labels")= Named num 8
#>   .. .. ..- attr(*, "names")= chr "8+"
#>   ..$ age             : num [1:1974] 22 21 42 49 70 50 35 24 28 28 ...
#>   .. ..- attr(*, "value.labels")= Named num 89
#>   .. .. ..- attr(*, "names")= chr "89+"
#>   ..$ educ            : Factor w/ 22 levels "IAP","None","1st grade",..: 18 14 14 15 18 21 17 13 11 19 ...
#>   ..$ degree          : Factor w/ 5 levels "<HS","HS","Junior Coll",..: 4 2 2 2 4 4 3 1 1 4 ...
#>   ..$ sex             : Factor w/ 2 levels "Male","Female": 1 1 1 2 2 2 2 2 2 2 ...
#>   ..$ race            : Factor w/ 3 levels "White","Black",..: 1 1 3 1 2 1 1 3 2 1 ...
#>   ..$ polviews        : Factor w/ 7 levels "ExtrmLib","Liberal",..: 4 5 5 5 2 4 4 4 6 2 ...
#>   ..$ partyid         : Factor w/ 7 levels "StrDem","WkDem",..: 3 5 3 6 1 1 4 4 4 1 ...
#>   ..$ mobile16        : Factor w/ 3 levels "SAME CITY","SAME ST, DIF CITY",..: 2 1 3 2 1 2 1 1 NA 1 ...
#>   ..$ born            : Factor w/ 2 levels "YES","NO": 1 1 1 1 1 1 1 2 1 1 ...
#>   ..$ income06        : Factor w/ 25 levels "UNDER $1 000",..: 25 25 23 24 19 15 16 5 1 16 ...
#>   ..$ rincom06        : Factor w/ 25 levels "UNDER $1 000",..: NA NA 23 NA NA NA NA NA NA 16 ...
#>   ..$ region          : Factor w/ 9 levels "NEW ENGLAND",..: 1 1 1 1 2 2 2 2 2 2 ...
#>   ..$ size            : num [1:1974] 14 14 14 14 24 24 24 24 24 24 ...
#>   .. ..- attr(*, "value.labels")= Named num(0) 
#>   .. .. ..- attr(*, "names")= chr(0) 
#>   ..$ vote08_coded    : Factor w/ 2 levels "Voted","Did not vote": 2 NA 1 1 1 1 2 NA 1 1 ...
#>   ..$ pres08          : Factor w/ 2 levels "Obama","McCain": NA NA 1 2 1 1 NA NA 1 1 ...
#>   ..$ natspac         : Factor w/ 3 levels "Too little","About right",..: NA NA 2 NA NA 2 1 NA 2 2 ...
#>   ..$ natenvir        : Factor w/ 3 levels "Too little","About right",..: NA NA 2 NA NA 1 1 NA 1 1 ...
#>   ..$ natheal         : Factor w/ 3 levels "Too little","About right",..: NA NA 3 NA NA 1 1 NA 2 1 ...
#>   ..$ natcity         : Factor w/ 3 levels "Too little","About right",..: NA NA 2 NA NA 1 1 NA 1 NA ...
#>   ..$ natcrime        : Factor w/ 3 levels "Too little","About right",..: NA NA 2 NA NA 2 1 NA 2 2 ...
#>   ..$ natdrug         : Factor w/ 3 levels "Too little","About right",..: NA NA NA NA NA 1 2 NA 2 1 ...
#>   ..$ nateduc         : Factor w/ 3 levels "Too little","About right",..: NA NA 1 NA NA 2 1 NA 1 1 ...
#>   ..$ natrace         : Factor w/ 3 levels "Too little","About right",..: NA NA 2 NA NA 3 2 NA 1 1 ...
#>   ..$ natarms         : Factor w/ 3 levels "Too little","About right",..: NA NA 3 NA NA 3 1 NA 2 2 ...
#>   ..$ nataid          : Factor w/ 3 levels "Too little","About right",..: NA NA 3 NA NA 3 2 NA 2 2 ...
#>   ..$ natfare         : Factor w/ 3 levels "Too little","About right",..: NA NA 2 NA NA 3 3 NA 1 1 ...
#>   ..$ natroad         : Factor w/ 3 levels "Too little","About right",..: 3 2 1 1 1 1 1 2 2 1 ...
#>   ..$ natsoc          : Factor w/ 3 levels "Too little","About right",..: 1 3 2 NA 1 3 1 3 2 1 ...
#>   ..$ natmass         : Factor w/ 3 levels "Too little","About right",..: 1 2 NA 2 2 2 2 2 1 1 ...
#>   ..$ natpark         : Factor w/ 3 levels "Too little","About right",..: 2 2 1 3 2 1 2 2 1 NA ...
#>   ..$ natchld         : Factor w/ 3 levels "Too little","About right",..: 2 2 1 NA 2 1 1 1 1 1 ...
#>   ..$ natsci          : Factor w/ 3 levels "Too little","About right",..: 2 1 1 3 1 1 2 2 3 2 ...
#>   ..$ natenrgy        : Factor w/ 3 levels "Too little","About right",..: 1 1 2 1 1 1 2 1 2 1 ...
#>   ..$ eqwlth          : num [1:1974] NA 3 5 7 7 NA 2 1 NA 1 ...
#>   .. ..- attr(*, "value.labels")= Named num [1:2] 7 1
#>   .. .. ..- attr(*, "names")= chr [1:2] "NO GOVT ACTION" "GOVT REDUCE DIFF"
#>   ..$ spkath          : Factor w/ 2 levels "ALLOWED","NOT ALLOWED": NA 1 1 NA NA 1 NA NA 1 1 ...
#>   ..$ colath          : Factor w/ 2 levels "ALLOWED","NOT ALLOWED": 1 2 1 NA NA 2 NA 2 1 1 ...
#>   ..$ libath          : Factor w/ 2 levels "REMOVE","NOT REMOVE": NA 2 2 NA NA 2 NA 2 2 2 ...
#>   ..$ spkrac          : Factor w/ 2 levels "ALLOWED","NOT ALLOWED": 2 1 1 NA NA 1 NA NA 2 1 ...
#>   ..$ colrac          : Factor w/ 2 levels "ALLOWED","NOT ALLOWED": 2 2 2 NA NA 2 NA 2 2 1 ...
#>   ..$ librac          : Factor w/ 2 levels "REMOVE","NOT REMOVE": NA 2 2 NA NA 2 NA 1 1 2 ...
#>   ..$ spkcom          : Factor w/ 2 levels "ALLOWED","NOT ALLOWED": 2 1 1 NA NA 1 NA 2 1 1 ...
#>   ..$ colcom          : Factor w/ 2 levels "FIRED","NOT FIRED": 2 1 2 NA NA NA NA 1 1 2 ...
#>   ..$ libcom          : Factor w/ 2 levels "REMOVE","NOT REMOVE": 2 2 2 NA NA 2 NA 1 2 2 ...
#>   ..$ spkmil          : Factor w/ 2 levels "ALLOWED","NOT ALLOWED": 1 1 1 NA NA 1 NA 2 2 1 ...
#>   ..$ colmil          : Factor w/ 2 levels "ALLOWED","NOT ALLOWED": 2 2 1 NA NA 2 NA NA 2 1 ...
#>   ..$ libmil          : Factor w/ 2 levels "REMOVE","NOT REMOVE": 2 2 2 NA NA 1 NA NA 1 2 ...
#>   ..$ spkhomo         : Factor w/ 2 levels "ALLOWED","NOT ALLOWED": 1 2 1 NA NA 1 NA 1 1 1 ...
#>   ..$ colhomo         : Factor w/ 2 levels "ALLOWED","NOT ALLOWED": 1 2 1 NA NA 1 NA 1 1 1 ...
#>   ..$ libhomo         : Factor w/ 2 levels "REMOVE","NOT REMOVE": 2 2 2 NA NA 2 NA 2 1 2 ...
#>   ..$ spkmslm         : Factor w/ 2 levels "Yes, allowed",..: 2 2 1 NA NA 2 NA 2 2 1 ...
#>   ..$ colmslm         : Factor w/ 2 levels "Yes, allowed",..: NA 2 1 NA NA 2 NA 2 2 2 ...
#>   ..$ libmslm         : Factor w/ 2 levels "Remove","Not remove": 1 1 2 NA NA 1 NA 1 1 2 ...
#>   ..$ cappun          : Factor w/ 2 levels "FAVOR","OPPOSE": NA 1 NA 1 2 2 1 2 NA 2 ...
#>   ..$ gunlaw          : Factor w/ 2 levels "FAVOR","OPPOSE": 2 1 2 NA NA 1 NA 1 1 1 ...
#>   ..$ courts          : Factor w/ 3 levels "TOO HARSH","NOT HARSH ENOUGH",..: NA 2 NA NA 2 2 2 1 1 3 ...
#>   ..$ grass           : Factor w/ 2 levels "LEGAL","NOT LEGAL": NA 1 1 1 2 NA 1 2 NA 1 ...
#>   ..$ relig           : Factor w/ 13 levels "PROTESTANT","CATHOLIC",..: 2 2 1 1 1 1 11 2 4 4 ...
#>   ..$ fund            : Factor w/ 3 levels "FUNDAMENTALIST",..: 2 2 2 3 1 NA 2 2 3 3 ...
#>   ..$ attend          : Factor w/ 9 levels "Never","<Once/yr",..: 3 1 1 1 2 1 4 4 1 3 ...
#>   ..$ reliten         : Factor w/ 4 levels "STRONG","NOT VERY STRONG",..: 2 2 1 2 3 2 3 2 4 4 ...
#>   ..$ postlife        : Factor w/ 2 levels "YES","NO": 1 1 1 1 NA 1 1 2 2 NA ...
#>   ..$ pray            : Factor w/ 6 levels "SEVERAL TIMES A DAY",..: 4 6 1 6 1 1 4 5 6 2 ...
#>   ..$ bible           : Factor w/ 3 levels "WORD OF GOD",..: 2 1 2 2 1 2 1 2 2 2 ...
#>   ..$ affrmact        : Factor w/ 4 levels "STRONGLY SUPPORT PREF",..: NA NA NA 3 3 3 3 NA 1 NA ...
#>   ..$ wrkwayup        : Factor w/ 5 levels "AGREE STRONGLY",..: 2 NA NA 1 1 2 2 NA 1 NA ...
#>   ..$ closeblk        : num [1:1974] 5 6 5 NA NA 5 NA 5 9 7 ...
#>   .. ..- attr(*, "value.labels")= Named num [1:3] 9 5 1
#>   .. .. ..- attr(*, "names")= chr [1:3] "VERY CLOSE" "NEITHER ONE OR THE OTHER" "NOT AT ALL CLOSE"
#>   ..$ closewht        : num [1:1974] 7 7 4 NA NA 5 NA 5 9 5 ...
#>   .. ..- attr(*, "value.labels")= Named num [1:3] 9 5 1
#>   .. .. ..- attr(*, "names")= chr [1:3] "VERY CLOSE" "NEITHER ONE OR THE OTHER" "NOT AT ALL CLOSE"
#>   ..$ happy           : Factor w/ 3 levels "VERY HAPPY","PRETTY HAPPY",..: 1 1 2 1 1 1 2 2 3 2 ...
#>   ..$ confinan        : Factor w/ 3 levels "A GREAT DEAL",..: NA 3 2 1 3 NA 2 2 NA 2 ...
#>   ..$ conbus          : Factor w/ 3 levels "A GREAT DEAL",..: NA 1 2 1 3 NA 3 2 NA 3 ...
#>   ..$ conclerg        : Factor w/ 3 levels "A GREAT DEAL",..: NA 1 2 1 2 NA 2 2 NA 2 ...
#>   ..$ coneduc         : Factor w/ 3 levels "A GREAT DEAL",..: NA 2 2 2 1 NA 3 1 NA 2 ...
#>   ..$ confed          : Factor w/ 3 levels "A GREAT DEAL",..: NA 2 2 3 1 NA 3 3 NA 1 ...
#>   ..$ conlabor        : Factor w/ 3 levels "A GREAT DEAL",..: NA 2 2 3 3 NA 2 2 NA 2 ...
#>   ..$ conpress        : Factor w/ 3 levels "A GREAT DEAL",..: NA 3 2 2 3 NA 2 2 NA 2 ...
#>   ..$ conmedic        : Factor w/ 3 levels "A GREAT DEAL",..: NA 1 1 1 2 NA 2 1 NA 2 ...
#>   ..$ contv           : Factor w/ 3 levels "A GREAT DEAL",..: NA 1 2 2 3 NA 2 2 NA 2 ...
#>   ..$ conjudge        : Factor w/ 3 levels "A GREAT DEAL",..: NA 1 2 2 1 NA 2 1 NA 2 ...
#>   ..$ consci          : Factor w/ 3 levels "A GREAT DEAL",..: NA 1 1 NA 1 NA 2 2 NA 1 ...
#>   ..$ conlegis        : Factor w/ 3 levels "A GREAT DEAL",..: NA 1 3 3 3 NA 2 2 NA 2 ...
#>   ..$ conarmy         : Factor w/ 3 levels "A GREAT DEAL",..: NA 1 1 1 1 NA 1 2 NA 1 ...
#>   ..$ obey            : Factor w/ 5 levels "MOST IMPORTANT",..: NA 2 4 2 4 NA 3 1 NA 5 ...
#>   ..$ popular         : Factor w/ 5 levels "MOST IMPORTANT",..: NA 5 1 5 5 NA 5 5 NA 4 ...
#>   ..$ thnkself        : Factor w/ 5 levels "MOST IMPORTANT",..: NA 3 5 3 1 NA 1 4 NA 2 ...
#>   ..$ workhard        : Factor w/ 5 levels "MOST IMPORTANT",..: NA 1 2 1 2 NA 2 2 NA 3 ...
#>   ..$ helpoth         : Factor w/ 5 levels "MOST IMPORTANT",..: NA 4 3 4 3 NA 4 3 NA 1 ...
#>   ..$ union           : Factor w/ 4 levels "R BELONGS","SPOUSE BELONGS",..: NA 4 4 4 4 NA 4 4 NA 4 ...
#>   ..$ getahead        : Factor w/ 4 levels "HARD WORK","BOTH EQUALLY",..: 2 1 3 NA NA 2 NA 1 2 2 ...
#>   ..$ abdefect        : Factor w/ 2 levels "YES","NO": 1 1 1 NA NA 1 NA 1 1 1 ...
#>   ..$ abnomore        : Factor w/ 2 levels "YES","NO": NA 1 2 NA NA 1 NA 1 2 1 ...
#>   ..$ abhlth          : Factor w/ 2 levels "YES","NO": 1 1 1 NA NA 1 NA 1 1 1 ...
#>   .. [list output truncated]
#>   ..- attr(*, "variable.labels")= Named chr [1:213] "Gss Year For This Respondent" "Respondent Id Number" "Labor Force Status" "R Self-Emp Or Works For Somebody" ...
#>   .. ..- attr(*, "names")= chr [1:213] "year" "ID" "wrkstat" "wrkslf" ...
#>   ..- attr(*, "codepage")= int 65001
#>  $ fpc       :List of 2
#>   ..$ popsize : NULL
#>   ..$ sampsize: int [1:1974, 1] 1974 1974 1974 1974 1974 1974 1974 1974 1974 1974 ...
#>   ..- attr(*, "class")= chr "survey_fpc"
#>  $ pps       : logi FALSE
#>  - attr(*, "class")= chr [1:2] "survey.design2" "survey.design"

Created on 2020-07-27 by the reprex package (v0.3.0)

Ok, but you see how for number three I am trying to set up a chart using that data table and those datapoints. For plugging them into a function, it does not seem to be working for me.

Thank you.

Can you share what code you have tried? The variables you need are all on the dataset that @technocrat pointed out. This seems to be a homework question.

Please take a look at the Homework Policy: FAQ: Homework Policy

1 Like

For sure! Thank you.

library(poliscidata)

wtd.cor(gssD$femrole, gssD$age, weight=gssD$wt)

fit.svyglm(svyglm(femrole ~ age, design=gssD))

lm(femrole ~ age, data=gssD)
summary(lm(femrole ~ age, data=gssD))
biVarModelfemrole = lm(femrole ~ age, data=gssD)

Just based on that, I think I have it, as long as that shows the regression coefficient at -0.01279 for age.

Thanks again.
Nick

That's correct and the output I got as well. Be sure to use svyglm and not glm as that uses the sampling design and weights. I'm not sure the lm will run anyways since gssD is a survey design and not a data.frame.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.