zelig-gammasurvey

Gamma Regression for Continuous, Positive Dependent Variables

Use the gamma regression model if you have a positive-valued dependent variable such as the number of years a parliamentary cabinet endures, or the seconds you can stay airborne while jumping. The gamma distribution assumes that all waiting times are complete by the end of the study (censoring is not allowed).

Syntax

With reference classes:

z5 <- zgammasurvey$new()
z5$zelig(Y ~ X1 + X ~ X, weights = w, data = mydata)
z5$setx()
z5$sim()

With the Zelig 4 compatibility wrappers:

z.out <- zelig(Y ~ X1 + X2, model = "gamma.survey", weights = w, data = mydata)
x.out <- setx(z.out)
s.out <- sim(z.out, x = x.out, x1 = NULL)

Examples

Example 1: User has Existing Sample Weights

Attach sample data and variable names:

data(api, package="survey")

In this example, we will estimate a model using the percentages of students who receive subsidized lunch and an indicator for whether schooling is year-round to predict California public schools’ academic performance index scores:

z.out1 <- zelig(api00 ~ meals + yr.rnd, model = "gamma.survey",
  weights=~pw, data = apistrat)
## Warning in readLines(zeligmixedmodels): incomplete final line found on
## '/usr/lib64/R/library/ZeligMultilevel/JSON/zelig5mixedmodels.json'
## Warning: Supplied weights argument is not a vector or a variable name in the dataset, and will be ignored.
## How to cite this model in Zelig:
##   Nicholas Carnes. 2017.
##   gamma-survey: Gamma Regression with Survey Weights
##   in Christine Choirat, Christopher Gandrud, James Honaker, Kosuke Imai, Gary King, and Olivia Lau,
##   "Zelig: Everyone's Statistical Software," http://zeligproject.org/
summary(z.out1)
## Model:
##
## Call:
## z5$zelig(formula = api00 ~ meals + yr.rnd, data = apistrat, weights = ~pw)
##
## Survey design:
## survey::svydesign(data = data, ids = ids, probs = probs, strata = strata,
##     fpc = fpc, nest = nest, check.strata = check.strata, weights = localWeights)
##
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.16e-03   1.65e-05   70.66   <2e-16
## meals       7.86e-06   4.36e-07   18.01   <2e-16
## yr.rndYes   2.81e-05   4.46e-05    0.63     0.53
##
## (Dispersion parameter for Gamma family taken to be 0.01251)
##
## Number of Fisher Scoring iterations: 4
##
## Next step: Use 'setx' method

Set explanatory variables to their default (mean/mode) values, and set a high (80th percentile) and low (20th percentile) value for “meals,” the percentage of students who receive subsidized meals:

x.low <- setx(z.out1, meals= quantile(apistrat$meals, 0.2))
x.high <- setx(z.out1, meals= quantile(apistrat$meals, 0.8))

Generate first differences for the effect of high versus low “meals” on academic performance:

s.out1 <- sim(z.out1, x=x.high, x1=x.low)
summary(s.out1)
##
##  sim x :
##  -----
## ev
##      mean    sd   50%  2.5% 97.5%
## [1,]  573 7.591 573.1 558.7 588.1
## pv
##       mean    sd   50% 2.5% 97.5%
## [1,] 571.2 63.47 569.7  451   700
##
##  sim x1 :
##  -----
## ev
##       mean    sd   50%  2.5% 97.5%
## [1,] 766.8 7.038 766.7 752.9 780.7
## pv
##       mean    sd   50%  2.5% 97.5%
## [1,] 766.3 89.52 762.2 605.8 947.5
## fd
##       mean    sd   50%  2.5% 97.5%
## [1,] 193.8 9.678 193.7 174.5 212.2

Generate a second set of fitted values and a plot:

plot(s.out1)

Graphs of Quantities of Interest for Gamma Survey

Example 2: User has Details about Complex Survey Design (but not sample weights)

Suppose that the survey house that provided the dataset excluded probability weights but made other details about the survey design available. We can still estimate a model without probability weights that takes instead variables that identify each the stratum and/or cluster from which each observation was selected and the size of the finite sample from which each observation was selected.

z.out2 <- zelig(api00 ~ meals + yr.rnd, model = "gamma.survey",
  strata=~stype, fpc=~fpc, data = apistrat)
## Warning in readLines(zeligmixedmodels): incomplete final line found on
## '/usr/lib64/R/library/ZeligMultilevel/JSON/zelig5mixedmodels.json'
## How to cite this model in Zelig:
##   Nicholas Carnes. 2017.
##   gamma-survey: Gamma Regression with Survey Weights
##   in Christine Choirat, Christopher Gandrud, James Honaker, Kosuke Imai, Gary King, and Olivia Lau,
##   "Zelig: Everyone's Statistical Software," http://zeligproject.org/
summary(z.out2)
## Model:
##
## Call:
## z5$zelig(formula = api00 ~ meals + yr.rnd, data = apistrat, strata = ~stype,
##     fpc = ~fpc)
##
## Survey design:
## survey::svydesign(data = data, ids = ids, probs = probs, strata = strata,
##     fpc = fpc, nest = nest, check.strata = check.strata, weights = localWeights)
##
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.16e-03   1.47e-05   78.98   <2e-16
## meals       7.86e-06   4.28e-07   18.38   <2e-16
## yr.rndYes   2.81e-05   4.39e-05    0.64     0.52
##
## (Dispersion parameter for Gamma family taken to be 0.01251)
##
## Number of Fisher Scoring iterations: 4
##
## Next step: Use 'setx' method

Note that these results are identical to the results obtained when pre-existing sampling weights were used. When sampling weights are omitted, Zelig estimates them automatically for “gamma.survey” models based on the user-defined description of sampling designs. If no description is present, the default assumption is equal probability sampling.

The methods setx() and sim() can then be run on z.out2 in the same fashion described in Example 1.

Example 3: User has Replicate Weights

Suppose that the survey house that published these data withheld details about the survey design and instead published replication weights.

For the purpose of illustration, create a set of jk1 replicate weights:

library("survey")
## Loading required package: grid
## Loading required package: Matrix
##
## Attaching package: 'survey'
## The following object is masked from 'package:graphics':
##
##     dotchart
jk1reps <- jk1weights(psu=apistrat$dnum)

Estimate the model regressing api00 on the “meals” “yr.rnd” variables.

z.out3 <- zelig(api00 ~ meals + yr.rnd, model = "gamma.survey",
      data = apistrat, repweights=jk1reps$weights,
      type="JK1")
## Warning in readLines(zeligmixedmodels): incomplete final line found on
## '/usr/lib64/R/library/ZeligMultilevel/JSON/zelig5mixedmodels.json'
## How to cite this model in Zelig:
##   Nicholas Carnes. 2017.
##   gamma-survey: Gamma Regression with Survey Weights
##   in Christine Choirat, Christopher Gandrud, James Honaker, Kosuke Imai, Gary King, and Olivia Lau,
##   "Zelig: Everyone's Statistical Software," http://zeligproject.org/
summary(z.out3)
## Model:
##
## Call:
## z5$zelig(formula = api00 ~ meals + yr.rnd, data = apistrat, repweights = jk1reps$weights,
##     type = "JK1")
##
## Survey design:
## survey::svydesign(data = data, ids = ids, probs = probs, strata = strata,
##     fpc = fpc, nest = nest, check.strata = check.strata, weights = localWeights)
##
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept)  1.21e-03   1.86e-05   65.15   <2e-16
## meals        7.87e-06   4.66e-07   16.89   <2e-16
## yr.rndYes   -6.26e-06   4.64e-05   -0.14     0.89
##
## (Dispersion parameter for Gamma family taken to be 0.01459)
##
## Number of Fisher Scoring iterations: 4
##
## Next step: Use 'setx' method

Set the explanatory variable “meals” at high and low values

x.low <- setx(z.out3, meals= quantile(apistrat$meals, 0.2))
x.high <- setx(z.out3, meals= quantile(apistrat$meals, 0.8))

Generate first differences for the effect of the high versus low concentrations of poverty on school performance

s.out3 <- sim(z.out3, x=x.high, x1=x.low)
summary(s.out3)
##
##  sim x :
##  -----
## ev
##       mean    sd   50%  2.5% 97.5%
## [1,] 557.5 7.828 557.5 542.7 573.5
## pv
##       mean    sd   50%  2.5% 97.5%
## [1,] 557.2 69.01 553.7 427.7 701.5
##
##  sim x1 :
##  -----
## ev
##       mean    sd   50%  2.5% 97.5%
## [1,] 739.8 7.723 739.9 725.2 755.3
## pv
##       mean    sd   50%  2.5% 97.5%
## [1,] 739.5 88.68 738.1 573.6 916.5
## fd
##       mean    sd   50% 2.5% 97.5%
## [1,] 182.3 10.46 182.2  162 201.9

Generate a second set of fitted values and a plot:

plot(s.out3)

plot of chunk unnamed-chunk-13

The user should also refer to the gamma model demo, since gamma.survey models can take many of the same options as gamma models.

Model

  • The Gamma distribution with scale parameter \alpha has a stochastic component:

    for 0"/>.
  • The systematic component is given by

Quantities of Interest

  • The expected values (qi$ev) are simulations of the mean of the stochastic component given draws of \alpha and \beta from their posteriors:

  • The predicted values (qi$pr) are draws from the gamma distribution for each given set of parameters .

  • If x1 is specified, sim() also returns the differences in the expected values (qi$fd),

    .

  • In conditional prediction models, the average expected treatment effect (att.ev) for the treatment group is

    where is a binary explanatory variable defining the treatment () and control () groups. Variation in the simulations are due to uncertainty in simulating , the counterfactual expected value of for observations in the treatment group, under the assumption that everything stays the same except that the treatment indicator is switched to .

  • In conditional prediction models, the average predicted treatment effect (att.pr) for the treatment group is

    where is a binary explanatory variable defining the treatment () and control () groups. Variation in the simulations are due to uncertainty in simulating , the counterfactual predicted value of for observations in the treatment group, under the assumption that everything stays the same except that the treatment indicator is switched to .

Output Values

The Zelig object stores fields containing everything needed to rerun the Zelig output, and all the results and simulations as they are generated. In addition to the summary commands demonstrated above, some simply utility functions (known as getters) provide easy access to the raw fields most commonly of use for further investigation.

In the example above z.out$getcoef() returns the estimated coefficients, z.out$getvcov() returns the estimated covariance matrix, and z.out$getpredict() provides predicted values for all observations in the dataset from the analysis.

See also

The gammasurvey model is part of the survey package by Thomas Lumley, which in turn depends heavily on the glm package. Advanced users may wish to refer to help(glm) and help(family).

Lumley T (2016). “survey: analysis of complex survey samples.” R package version 3.31-5.

Lumley T (2004). “Analysis of Complex Survey Samples.” Journal of Statistical Software, 9 (1), pp. 1-19. R package verson 2.2.