kott.addvars: Add variables to replicated objects

Description Usage Arguments Details Value Author(s) Examples

Description

Modifies a kott.design object by adding new variables to it.

Usage

1
kott.addvars(deskott, ...)

Arguments

deskott

Object of class kott.design containing the replicated survey data.

...

tag = expr arguments defining columns to be added to deskott.

Details

This function adds to the data frame contained in deskott the new variables defined by the tag = expr arguments. A tag can be specified either by means of an identifier or by a character string; expr can be any expression that it makes sense to evaluate in the deskott environment.

For each argument tag = expr bound to the formal argument ... the added column will have name given by the tag value and values obtained by evaluating the expr expression on deskott. Any input expression unsupplied with a tag will be ignored and will therefore have no effect on the kott.addvars return value.

Variables to be added to the input replicated object have to be new: namely it is not possible to use kott.addvars to modify the values in a pre-existing deskott column.

Value

An object of the same class of deskott, containing new variables but supplied with exactly the same metadata.

Author(s)

Diego Zardetto

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
data(data.examples)

# Creation of a kott.design object:
kdes<-kottdesign(data=example,ids=~towcod+famcod,strata=~SUPERSTRATUM,
      weights=~weight,nrg=15)

# Adding the new 'population' variable to estimate the number
# of final units in the population: 
kdes2<-kott.addvars(kdes,population=1)
kottby(kdes2,~population)

# Recoding a qualitative variable:
kdes2<-kott.addvars(kdes,agerange=as.factor(ifelse(age5c==1,
                                            "young","not-young")))
kottby(kdes2,~agerange,est="mean")
kottby(kdes2,~income,~agerange,estimator="mean",conf.int=TRUE)

# Algebraic operations on numeric variables:
kdes2<-kott.addvars(kdes,q=income/z^2)
kottby(kdes2,~q)

DiegoZardetto/EVER documentation built on April 8, 2021, 1:05 p.m.