trimWeights: Trim sampling weights

Description Usage Arguments Value See Also Examples

View source: R/grake.R

Description

Trims very high or very low sampling weights to reduce the influence of outlying observations. In a replicate-weight design object, the replicate weights are also trimmed. The total amount trimmed is divided among the observations that were not trimmed, so that the total weight remains the same.

Usage

1
2
3
4
5
trimWeights(design, upper = Inf, lower = -Inf, ...)
## S3 method for class 'survey.design2'
trimWeights(design, upper = Inf, lower = -Inf, strict=FALSE,...)
## S3 method for class 'svyrep.design'
trimWeights(design, upper = Inf, lower = -Inf,compress=FALSE,...)

Arguments

design

A survey design object

upper

Upper bound for weights

lower

Lower bound for weights

strict

The reapportionment of the ‘trimmings’ from the weights can push other weights over the limits. If trim=TRUE the function calls itself recursively to prevent this.

compress

Compress the replicate weights after trimming.

...

Other arguments for future expansion

Value

A new survey design object with trimmed weights.

See Also

calibrate has a trim option for trimming the calibration adjustments.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
data(api)
dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)

pop.totals<-c(`(Intercept)`=6194, stypeH=755, stypeM=1018,
api99=3914069)
dclus1g<-calibrate(dclus1, ~stype+api99, pop.totals)

summary(weights(dclus1g))
dclus1t<-trimWeights(dclus1g,lower=20, upper=45)
summary(weights(dclus1t))
dclus1tt<-trimWeights(dclus1g, lower=20, upper=45,strict=TRUE)
summary(weights(dclus1tt))


svymean(~api99+api00+stype, dclus1g)
svymean(~api99+api00+stype, dclus1t)
svymean(~api99+api00+stype, dclus1tt)

Example output

Loading required package: grid
Loading required package: Matrix
Loading required package: survival

Attaching package: 'survey'

The following object is masked from 'package:graphics':

    dotchart

   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  14.17   25.91   33.58   33.85   40.23   62.05 
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  20.00   26.82   34.48   33.85   41.13   45.74 
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  20.01   26.83   34.49   33.85   41.15   45.00 
            mean     SE
api99  631.91298 0.0000
api00  665.30907 3.4418
stypeE   0.71376 0.0000
stypeH   0.12189 0.0000
stypeM   0.16435 0.0000
            mean     SE
api99  628.91203 1.1673
api00  663.05195 3.5796
stypeE   0.73651 0.0036
stypeH   0.10121 0.0043
stypeM   0.16228 0.0021
            mean     SE
api99  628.87690 1.1695
api00  663.02017 3.5842
stypeE   0.73664 0.0036
stypeH   0.10121 0.0043
stypeM   0.16214 0.0021

survey documentation built on July 19, 2021, 9:06 a.m.