kott.addvars.RdModifies a kott.design object by adding new variables to it.
kott.addvars(deskott, ...)
| deskott | Object of class |
|---|---|
| … |
|
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.
An object of the same class of deskott, containing new variables but supplied with exactly the same metadata.
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)#> total SE #> population 924101.3 22059.9# Recoding a qualitative variable: kdes2<-kott.addvars(kdes,agerange=as.factor(ifelse(age5c==1, "young","not-young"))) kottby(kdes2,~agerange,est="mean")#> mean SE #> agerange.not-young 0.8604824 0.007587145 #> agerange.young 0.1395176 0.007587145#> not-young young #> mean 1303.762 962.6162 #> SE 10.45407 20.86844 #> l.conf(95%) 1281.34 917.8579 #> u.conf(95%) 1326.184 1007.375# Algebraic operations on numeric variables: kdes2<-kott.addvars(kdes,q=income/z^2) kottby(kdes2,~q)#> total SE #> q 101910.2 3071.595