ajdamico / convey

variance of distribution measures estimation of survey data
GNU General Public License v3.0
17 stars 7 forks source link

why does svyafc not match jindra's presentation? #168

Closed ajdamico closed 8 months ago

ajdamico commented 7 years ago
# load the convey package
library(convey)

# load the survey library
library(survey)

# load the stata-style webuse library
library(webuse)

# load the same microdata set used by Jindra in his presentation
webuse("nlsw88")

# coerce that `tbl_df` to a standard R `data.frame`
nlsw88 <- data.frame( nlsw88 )

# create a `collgrad` column
nlsw88$collgrad <-
    factor( 
        as.numeric( nlsw88$collgrad ) , 
        label = c( 'not college grad' , 'college grad' ) , 
        ordered = TRUE 
      )

# initiate a linearized survey design object
des_nlsw88 <- svydesign( ids = ~1 , data = nlsw88 )

# immediately run the `convey_prep` function on the survey design
des_nlsw88 <- convey_prep(des_nlsw88)

# these calculations match pdf page 13
# http://www.ophi.org.uk/wp-content/uploads/Jindra_151109_OPHISeminar.pdf#page=13
svyafc(
    ~ wage + collgrad + hours , 
    design = des_nlsw88 , 
    cutoffs = list( 4, 'college grad' , 26 ) , 
    k = 0.75 , 
    g = 0 , 
    dimw = c( 0.5 , 0.25 , 0.25 ) ,
    na.rm = TRUE
)

svyafc(
    ~ wage + collgrad + hours , 
    design = des_nlsw88 , 
    cutoffs = list( 4, 'college grad' , 26 ) , 
    k = 1 , 
    g = 0 , 
    dimw = c( 0.5 , 0.25 , 0.25 ) ,
    na.rm = TRUE
)

# why does this number not match the 0.5 from pdf page 13?
# http://www.ophi.org.uk/wp-content/uploads/Jindra_151109_OPHISeminar.pdf#page=13
svyafc(
    ~ wage + collgrad + hours , 
    design = des_nlsw88 , 
    cutoffs = list( 4, 'college grad' , 26 ) , 
    k = 0.5 , 
    g = 0 , 
    dimw = c( 0.5 , 0.25 , 0.25 ) ,
    na.rm = TRUE
)
guilhermejacob commented 7 years ago

can you run this in stata?

ajdamico commented 7 years ago

20161210 reproduce slides 9 and 13.txt

is this what you need?

guilhermejacob commented 7 years ago

the functions had dome incorrect matrix operations, but the last commits fixed them.

So try this:

# these calculations match pdf page 13
# http://www.ophi.org.uk/wp-content/uploads/Jindra_151109_OPHISeminar.pdf#page=13
svyafc(
  ~ wage + collgrad + hours , 
  design = des_nlsw88 , 
  cutoffs = list( 4, 'college grad' , 26 ) , 
  k = 0.5 , 
  g = 0 , 
  dimw = c( 0.5 , 0.25 , 0.25 ) ,
  na.rm = TRUE
)

svyafc(
  ~ wage + collgrad + hours , 
  design = des_nlsw88 , 
  cutoffs = list( 4, 'college grad' , 26 ) , 
  k = 0.75 , 
  g = 0 , 
  dimw = c( 0.5 , 0.25 , 0.25 ) ,
  na.rm = TRUE
)

svyafc(
  ~ wage + collgrad + hours , 
  design = des_nlsw88 , 
  cutoffs = list( 4, 'college grad' , 26 ) , 
  k = 1 , 
  g = 0 , 
  dimw = c( 0.5 , 0.25 , 0.25 ) ,
  na.rm = TRUE
)

Closing it!

ajdamico commented 7 years ago

thanks!

ajdamico commented 10 months ago

also might be useful for me to show in 6.1