add_weights: Add weights based on marketshares

Description Usage Arguments Note Author(s) Examples

Description

This function calculates weights for each entity based on their expected marketshares and number of observations. If a survey is passed to the function, a new column w is added to the df which contains a weight for all the obserations. If a vector of types character or factor is passed to the function, and the entities/ents from a survey, a numeric vector is returned instead.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
add_weights(x, entities = NULL)

## S3 method for class 'survey'
add_weights(srv)

## S3 method for class 'character'
add_weights(x, ms)

## S3 method for class 'factor'
add_weights(x, ms)

Arguments

x

A survey object, or vector of type character or facotor.

entities

Optional: If a vector is passed to x, the entities/ents from a survey object must be passed along with it.

Note

See add_entities for information on the entities object.

Author(s)

Kristian D. Olsen

Examples

1
2
3
x <- survey(data.frame("test" = 1, stringsAsFactors = FALSE))
x <- x %>% add_mm() %>% add_entities() %>% add_weights()
x %>% mutate(w = add_weights(q1, x$ents)) # i.e. create weights for subsets

itsdalmo/reporttool documentation built on May 18, 2019, 7:11 a.m.