Pesquisa de Orcamentos Familiares (POF)

Build Status Build status

Contributed by Dr. Djalma Pessoa <pessoad@gmail.com>

The Pesquisa de Orcamentos Familiares is Brazil’s national survey of household budgets.

  • One table of survey responses per sampled household. Additional tables, many containing one record per expenditure.

  • A complex sample survey designed to generalize to the civilian population of Brazil.

  • Released at irregular intervals, with only 2002-2003 and 2008-2009 microdata available.

  • Administered by the Instituto Brasileiro de Geografia e Estatistica.

Simplified Download and Importation

The R lodown package easily downloads and imports all available POF microdata by simply specifying "pof" with an output_dir = parameter in the lodown() function. Depending on your internet connection and computer processing speed, you might prefer to run this step overnight.

library(lodown)
lodown( "pof" , output_dir = file.path( path.expand( "~" ) , "POF" ) )

lodown also provides a catalog of available microdata extracts with the get_catalog() function. After requesting the POF catalog, you could pass a subsetted catalog through the lodown() function in order to download and import specific extracts (rather than all available extracts).

library(lodown)
# examine all available POF microdata files
pof_cat <-
    get_catalog( "pof" ,
        output_dir = file.path( path.expand( "~" ) , "POF" ) )

# 2008-2009 only
pof_cat <- subset( pof_cat , period == "2008_2009" )
# download the microdata to your local computer
lodown( "pof" , pof_cat )

Analysis Examples with the survey library

Construct a complex sample survey design:

options( survey.lonely.psu = "adjust" )

library(survey)

poststr <- 
    readRDS( 
        file.path( path.expand( "~" ) , "POF" , 
            "2008_2009/poststr.rds" ) 
        )

        
t_morador_s <- 
    readRDS( 
        file.path( path.expand( "~" ) , "POF" , 
            "2008_2009/t_morador_s.rds" ) 
        )

t_morador_s <-
    transform(
        t_morador_s , 
        control = paste0( cod_uf , num_seq , num_dv ) 
    )
    
pof_df <- merge( t_morador_s , poststr )

stopifnot( nrow( pof_df ) == nrow( t_morador_s ) )

pre_stratified_design <- 
    svydesign(
        id = ~control , 
        strata = ~estrato_unico ,
        weights = ~fator_expansao1 ,
        data = pof_df ,
        nest = TRUE
    )

population_totals <- 
    data.frame(
        pos_estrato = unique( pof_df$pos_estrato ) , 
        Freq = unique( pof_df$tot_pop ) 
    )

pof_design <-
    postStratify(
        pre_stratified_design , 
        ~ pos_estrato , 
        population_totals
    )

Variable Recoding

Add new columns to the data set:

pof_design <- 
    update(
        pof_design , 
        
        one = 1 ,
        
        # centimeters instead of meters
        altura_imputado = altura_imputado / 100 ,
        
        age_categories =
            factor( 
                1 + findInterval( idade_anos , 
                    c( 20 , 25 , 30 , 35 , 45 , 55 , 65 , 75 ) ) ,
                levels = 1:9 , labels = c( "under 20" , "20-24" , "25-29" ,
                "30-34" , "35-44" , "45-54" , "55-64" , "65-74" , "75+" )
            ) ,
        
        # create a body mass index (bmi) variable, excluding babies (who have altura_imputado==0)           
        body_mass_index = ifelse( altura_imputado == 0 , 0 , peso_imputado / ( altura_imputado ^ 2 ) ) ,
        
        sexo = ifelse( cod_sexo == '01' , "masculino" , ifelse( cod_sexo == '02' , "feminino" , NA ) )
        
        
    )

pof_design <-
    transform(
        pof_design ,
        
        # individuals with a low bmi - underweight
        underweight = ifelse( body_mass_index < 18.5 , 1 , 0 ) ,
        
        # individuals with a high bmi - overweight
        overweight = ifelse( body_mass_index >= 25 , 1 , 0 ) ,
        
        # individuals with a very high bmi - obese
        obese = ifelse( body_mass_index >= 30 , 1 , 0 )
    )

Unweighted Counts

Count the unweighted number of records in the survey sample, overall and by groups:

sum( weights( pof_design , "sampling" ) != 0 )

svyby( ~ one , ~ sexo , pof_design , unwtd.count )

Weighted Counts

Count the weighted size of the generalizable population, overall and by groups:

svytotal( ~ one , pof_design )

svyby( ~ one , ~ sexo , pof_design , svytotal )

Descriptive Statistics

Calculate the mean (average) of a linear variable, overall and by groups:

svymean( ~ body_mass_index , pof_design , na.rm = TRUE )

svyby( ~ body_mass_index , ~ sexo , pof_design , svymean , na.rm = TRUE )

Calculate the distribution of a categorical variable, overall and by groups:

svymean( ~ age_categories , pof_design )

svyby( ~ age_categories , ~ sexo , pof_design , svymean )

Calculate the sum of a linear variable, overall and by groups:

svytotal( ~ body_mass_index , pof_design , na.rm = TRUE )

svyby( ~ body_mass_index , ~ sexo , pof_design , svytotal , na.rm = TRUE )

Calculate the weighted sum of a categorical variable, overall and by groups:

svytotal( ~ age_categories , pof_design )

svyby( ~ age_categories , ~ sexo , pof_design , svytotal )

Calculate the median (50th percentile) of a linear variable, overall and by groups:

svyquantile( ~ body_mass_index , pof_design , 0.5 , na.rm = TRUE )

svyby( 
    ~ body_mass_index , 
    ~ sexo , 
    pof_design , 
    svyquantile , 
    0.5 ,
    ci = TRUE ,
    keep.var = TRUE ,
    na.rm = TRUE
)

Estimate a ratio:

svyratio( 
    numerator = ~ peso_imputado , 
    denominator = ~ altura_imputado , 
    pof_design ,
    na.rm = TRUE
)

Subsetting

Restrict the survey design to :

sub_pof_design <- subset( pof_design , underweight == 1 )

Calculate the mean (average) of this subset:

svymean( ~ body_mass_index , sub_pof_design , na.rm = TRUE )

Measures of Uncertainty

Extract the coefficient, standard error, confidence interval, and coefficient of variation from any descriptive statistics function result, overall and by groups:

this_result <- svymean( ~ body_mass_index , pof_design , na.rm = TRUE )

coef( this_result )
SE( this_result )
confint( this_result )
cv( this_result )

grouped_result <-
    svyby( 
        ~ body_mass_index , 
        ~ sexo , 
        pof_design , 
        svymean ,
        na.rm = TRUE 
    )
    
coef( grouped_result )
SE( grouped_result )
confint( grouped_result )
cv( grouped_result )

Calculate the degrees of freedom of any survey design object:

degf( pof_design )

Calculate the complex sample survey-adjusted variance of any statistic:

svyvar( ~ body_mass_index , pof_design , na.rm = TRUE )

Include the complex sample design effect in the result for a specific statistic:

# SRS without replacement
svymean( ~ body_mass_index , pof_design , na.rm = TRUE , deff = TRUE )

# SRS with replacement
svymean( ~ body_mass_index , pof_design , na.rm = TRUE , deff = "replace" )

Compute confidence intervals for proportions using methods that may be more accurate near 0 and 1. See ?svyciprop for alternatives:

svyciprop( ~ obese , pof_design ,
    method = "likelihood" , na.rm = TRUE )

Regression Models and Tests of Association

Perform a design-based t-test:

svyttest( body_mass_index ~ obese , pof_design )

Perform a chi-squared test of association for survey data:

svychisq( 
    ~ obese + age_categories , 
    pof_design 
)

Perform a survey-weighted generalized linear model:

glm_result <- 
    svyglm( 
        body_mass_index ~ obese + age_categories , 
        pof_design 
    )

summary( glm_result )

Analysis Examples with srvyr

The R srvyr library calculates summary statistics from survey data, such as the mean, total or quantile using dplyr-like syntax. srvyr allows for the use of many verbs, such as summarize, group_by, and mutate, the convenience of pipe-able functions, the tidyverse style of non-standard evaluation and more consistent return types than the survey package. This vignette details the available features. As a starting point for POF users, this code replicates previously-presented examples:

library(srvyr)
pof_srvyr_design <- as_survey( pof_design )

Calculate the mean (average) of a linear variable, overall and by groups:

pof_srvyr_design %>%
    summarize( mean = survey_mean( body_mass_index , na.rm = TRUE ) )

pof_srvyr_design %>%
    group_by( sexo ) %>%
    summarize( mean = survey_mean( body_mass_index , na.rm = TRUE ) )

Replication Example