calc: Calculating facts

Description Usage Arguments Details Examples

View source: R/calc.r

Description

calc calculates standard estimates of TV viewing, called facts in Instar Analytics. The formulae are documented in Instar Analytics and the Mediapulse documentation "Gold Standards". calc aimes to yeld exactly the same results as Instar Analytics. calc.uni calculates sample and universe, calc.share calculates the share.

Usage

1
2
3
4
5
6
calc(dt, by = "day", period = NULL, unit = "hour", na.rm = TRUE,
  na.to.0 = TRUE)

calc.uni(x, target = NULL, obs = id$view$obs)

calc.share(dt, id.chn)

Arguments

dt

A data.table, a left join of dem and view on the keys day and pin, e.g. calc(dt = view[dem, on = c('day','pin')])

by

A character vector, specifying the groups by which the facts will be calculated. Default is day. Fact are always calculated by day, plus optionally more grouping variables. Make sure that sample and universe were calculated by the very same variables (targets).

period

A character vector, specifying the name of the column which represents the period. By default this is 'day'. The Period is needed to calculated the Rating (rtgT and rtgP). Rating is the summed viewing duration devided by a certain time period. By default ('day') this is 24 hours or 86400 seconds. When calculating facts by timeband, period has to be specified as 'tmb.dur', the duration of each timeband, e.g.: calc(, by = c('day','tmb'), period = 'tmb.dur'). The same applies for calculation by programs, e.g.: calc(, by = c('day','prg'), period = 'prg.dur'). If period is not specified correctly you will see that, compared with Instar, Reach will be correct but Rating is not.

unit

One of 'hour','min','sec'. Currently not implemented. Results are in seconds.

na.to.0

TRUE (default) or FALSE. Replace NAs by Zeros? Useful to compare results with Instar Analytics

x

A data.table, usually the object dem.

target

A character vector, specifying the variables by which sample and universe will be calculated. By default 'day'.

obs

The level observation, either 'ind' or 'hh'. Is the column pin representing individuals or households? By default the value in id$view$obs is taken which was specified previously in setup(..., obs = )

Details

calc.uni calculates sample and universe in the dem file. To calculate facts, first sample and universe have to be calculated and added as columns to dem, see details. calc.share calculates the share, typically between channels. Share by definition is calculated based on the fact rtgP Rating in Percent. By default the following facts are returned: sample,universe,n,dur,rchT,rchP,rtgT,rtgP,share. Attention! share usually is incorrect and has to be calculated separately.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
library(tv)
setup('2018-01-01', dem.var = 'sg', import = TRUE)
dem[] # By default sample and universe are already calculated (added as columns), 
      # targets are all the variables specified in setup(..., dem.var = ).
      # This is not always inteded, make sure to have the correct targets 
      # before calculating facts.

# calculate sample and universe
setup('2018-01-01', 3, dem.var = c('sg','hhsize'), dem.uni = FALSE, import = TRUE)
dem[] # setup(dem.uni = FALSE) will suppress the calculation of sample and universe.
calc.uni(dem, target = 'sg') # calculate sample and universe with target 'sg'
                             # sample and universe are always calculated by day.
                             
# with sample and target by 'sg' we can now calculate facts by 'sg'.
res <- calc(view[dem, on = c('day','pin')], by = c('day','sg'))                             
res[]

# If we want facts by sg and hhsize we first have to calculate the correct sample and universe:                        
calc.uni(dem, target = c('sg','hhsize')) # overwriting the columns sample and universe
res <- calc(view[dem, on = c('day','pin')], by = c('day','sg','hhsize')) 
res[]

rluech/tv-clone documentation built on Jan. 7, 2022, 12:27 a.m.