Skip to contents

Prikking av foretak og avrunding eller prikking av personer. Sett parameteren allowTotal til TRUE for at kategorier innen (within) foretak skal prikkes samtidig som totalverdier over disse grupperingene tillates publisert.

Usage

SdcForetakPerson(
  data,
  between = NULL,
  within = NULL,
  by = NULL,
  roundBase = 3,
  maxN = NULL,
  protectZeros = FALSE,
  secondaryZeros = FALSE,
  freqVar = NULL,
  sector = lower_match(data, "sektor"),
  private = "Privat",
  nace = c("nar*", "NACE*", "nace*"),
  nace00 = "00",
  nace00primary = FALSE,
  frtk = lower_match(data, "frtk_id_ssb"),
  virk = lower_match(data, "virk_id_ssb"),
  unik = lower_match(data, "unik_id"),
  makeunik = TRUE,
  removeZeros = !protectZeros,
  preAggregate = TRUE,
  output = NULL,
  decimal = FALSE,
  freqDec = "freqDec*",
  nRep = 3,
  digitsA = 9,
  digitsB = 5,
  allowTotal = FALSE,
  til0 = TRUE,
  iWait = Inf
)

Arguments

data

Datasett som data frame

between

Variabler som grupperer foretak for prikking

within

Ytterligere variabler innen foretak som brukes til avrunding eller prikking av personer

by

Tid eller andre variabler som deler datasettet. Metoden kjøres på hver del og resultatet settes sammen.

roundBase

Base for avrunding

maxN

Max-verdi for primærprikking av personer. Ikke-NULL verdi betyr prikking istedenfor avrunding.

protectZeros

Suppression parameter. Empty cells (count=0) are set as primary suppressed When TRUE.

secondaryZeros

Suppression parameter.

freqVar

A single variable holding counts (name or number) or NULL in the case of micro data (then variable named "freq" will be generated )

sector

Sektor-variabel som inneholder Privat-koden (se parameter "private").

private

Privat-koden

nace

between-variabel med nace-kode eller koding (starter med) som leter etter slik variabel (nace kan settes til NULL)

nace00

nace-koden som foretrekkes til sekundærprikking (nace00 kan settes til NULL)

nace00primary

Ved FALSE utelates nace00-koden (se over) fra primærprikking

frtk

foretak variabel

virk

virksomhet variabel

unik

unik variabel

makeunik

Unik variabel genereres ved TRUE ellers antas det at den finnes

removeZeros

When TRUE, rows with zero count will be removed from the data within the algorithm. Default er at parameteren er motsatt av protectZeros. Altså 0-er i data fjernes når 0-er ikke skal prikkes. Parameteren har betydning for telling av antall foretak bak et tall.

preAggregate

Input til GaussSuppressionFromData. Parameteren er med her for testing og sammenlikning av resultater.

output

Ved avrunding kan ulike type output velges. Enten "rounded" (samme som NULL) eller "suppressed" (liste med begge hvis noe annet). Her kan det bli endring.

decimal

Ved TRUE returneres indre celle-data med desimaltall. Dette kan fungere som input seinere (se nedenfor). Når, i tillegg, maxN er NULL (default), er det mulig å spesifisere between som en formel (se eksempel).

Ved decimal som en data-frame antas at dette er indre celle-data med desimaltall. Prikking vil baseres på aggregering av disse.

freqDec

Navn på variabel(er) med desimaltall eller koding (starter med). Brukes når decimal er en data-frame.

nRep

Antall desimaltallsvariabler, GaussSuppressDec parameter.

digitsA

GaussSuppressDec parameter (9 er vanligvis ok)

digitsB

SuppressionFromDecimals parameter (5 er ok når nRep=3)

allowTotal

Når TRUE, ingen prikking når alle within-variabler er "Total".

til0

Når TRUE: Når ikke-prikket tall som følge av allowTotal=TRUE er avrundet til 0 blir prikking av undergrupper av denne opphevet og erstattet med 0.

iWait

Minimum antall sekunder mellom hver gang det skrives ut ekstra informasjon fra prikkerutinen.

Value

data frame

Details

Default parameterverdier der funksjonen lower_match brukes betyr at default er første variabelnavn i data som matcher når det ikke tas hensyn til små eller store bokstaver. Dette betyr, for eksempel, at parameteren frtk ikke må bli spesifisert av brukeren hvis variabelnavnet i inputdata er "frtk_id_ssb" eller "FRTK_ID_SSB". Det kan også være "frtk_id_SSB" om man vil.

Examples


prikkeVarA <- c("arb_fylke", "ARB_ARBKOMM", "nar8", "sektor")
prikkeVarB <- c("arb_fylke", "ARB_ARBKOMM", "nar17")

z <- SdcData("syssel27")

SdcForetakPerson(z, between = prikkeVarA)
#> [preAggregate 27*14->21*7]
#> [extraAggregate 21*7->10*7] Checking .....
#> GaussSuppression_none: ..............................
#> [aggregate for PLSroundingSuppressed 27*14->10*5]
#>    ARB_ARBKOMM  sektor original rounded difference roundedSuppressed
#> 1        Total   Total       27      28          1                28
#> 2        Total   45-82        6       6          0                 6
#> 3        Total      84       21      22          1                22
#> 4        Total Kommual       12      12          0                12
#> 5        Total  Privat        6       6          0                 6
#> 6        Total Statlig        9      10          1                10
#> 7           05   Total       17      18          1                18
#> 8           05   45-82        4       4          0                NA
#> 9           05      84       13      14          1                NA
#> 10          05 Kommual        9       9          0                 9
#> 11          05  Privat        4       4          0                NA
#> 12          05 Statlig        4       5          1                NA
#> 13          18   Total       10      10          0                10
#> 14          18   45-82        2       2          0                NA
#> 15          18      84        8       8          0                NA
#> 16          18 Kommual        3       3          0                 3
#> 17          18  Privat        2       2          0                NA
#> 18          18 Statlig        5       5          0                NA
#> 19        0518   Total        5       6          1                 6
#> 20        0518   45-82        0       0          0                 0
#> 21        0518      84        5       6          1                 6
#> 22        0518 Kommual        3       3          0                 3
#> 23        0518  Privat        0       0          0                 0
#> 24        0518 Statlig        2       3          1                 3
#> 25        0531   Total       12      12          0                12
#> 26        0531   45-82        4       4          0                NA
#> 27        0531      84        8       8          0                NA
#> 28        0531 Kommual        6       6          0                 6
#> 29        0531  Privat        4       4          0                NA
#> 30        0531 Statlig        2       2          0                NA
#> 31        1821   Total        4       4          0                 4
#> 32        1821   45-82        0       0          0                 0
#> 33        1821      84        4       4          0                 4
#> 34        1821 Kommual        2       2          0                NA
#> 35        1821  Privat        0       0          0                 0
#> 36        1821 Statlig        2       2          0                NA
#> 37        1822   Total        6       6          0                 6
#> 38        1822   45-82        2       2          0                NA
#> 39        1822      84        4       4          0                NA
#> 40        1822 Kommual        1       1          0                NA
#> 41        1822  Privat        2       2          0                NA
#> 42        1822 Statlig        3       3          0                 3
SdcForetakPerson(z, between = prikkeVarA, output = "suppressed")
#> [preAggregate 27*14->21*7]
#> [extraAggregate 21*7->10*7] Checking .....
#> GaussSuppression_none: ..............................
#>    ARB_ARBKOMM  sektor freq nPrivat nOff narWeight primary suppressed prikk
#> 1        Total   Total   27       5   13        27   FALSE      FALSE     0
#> 2        Total   45-82    6       5    0         6   FALSE      FALSE     0
#> 3        Total      84   21       0   13        21   FALSE      FALSE     0
#> 4        Total Kommual   12       0    9        12   FALSE      FALSE     0
#> 5        Total  Privat    6       5    0         6   FALSE      FALSE     0
#> 6        Total Statlig    9       0    4         9   FALSE      FALSE     0
#> 7           05   Total   17       3    9        17   FALSE      FALSE     0
#> 8           05   45-82    4       3    0         4   FALSE       TRUE     1
#> 9           05      84   13       0    9        13   FALSE       TRUE     1
#> 10          05 Kommual    9       0    7         9   FALSE      FALSE     0
#> 11          05  Privat    4       3    0         4   FALSE       TRUE     1
#> 12          05 Statlig    4       0    2         4   FALSE       TRUE     1
#> 13          18   Total   10       2    5        10   FALSE      FALSE     0
#> 14          18   45-82    2       2    0         2    TRUE       TRUE     1
#> 15          18      84    8       0    5         8   FALSE       TRUE     1
#> 16          18 Kommual    3       0    2         3   FALSE      FALSE     0
#> 17          18  Privat    2       2    0         2    TRUE       TRUE     1
#> 18          18 Statlig    5       0    3         5   FALSE       TRUE     1
#> 19        0518   Total    5       0    5         5   FALSE      FALSE     0
#> 20        0518   45-82    0       0    0         0   FALSE      FALSE     0
#> 21        0518      84    5       0    5         5   FALSE      FALSE     0
#> 22        0518 Kommual    3       0    3         3   FALSE      FALSE     0
#> 23        0518  Privat    0       0    0         0   FALSE      FALSE     0
#> 24        0518 Statlig    2       0    2         2   FALSE      FALSE     0
#> 25        0531   Total   12       3    6        12   FALSE      FALSE     0
#> 26        0531   45-82    4       3    0         4   FALSE       TRUE     1
#> 27        0531      84    8       0    6         8   FALSE       TRUE     1
#> 28        0531 Kommual    6       0    4         6   FALSE      FALSE     0
#> 29        0531  Privat    4       3    0         4   FALSE       TRUE     1
#> 30        0531 Statlig    2       0    2         2   FALSE       TRUE     1
#> 31        1821   Total    4       0    3         4   FALSE      FALSE     0
#> 32        1821   45-82    0       0    0         0   FALSE      FALSE     0
#> 33        1821      84    4       0    3         4   FALSE      FALSE     0
#> 34        1821 Kommual    2       0    1         2   FALSE       TRUE     1
#> 35        1821  Privat    0       0    0         0   FALSE      FALSE     0
#> 36        1821 Statlig    2       0    2         2   FALSE       TRUE     1
#> 37        1822   Total    6       2    2         6   FALSE      FALSE     0
#> 38        1822   45-82    2       2    0         2    TRUE       TRUE     1
#> 39        1822      84    4       0    2         4   FALSE       TRUE     1
#> 40        1822 Kommual    1       0    1         1   FALSE       TRUE     1
#> 41        1822  Privat    2       2    0         2    TRUE       TRUE     1
#> 42        1822 Statlig    3       0    1         3   FALSE      FALSE     0

SdcForetakPerson(z, between = prikkeVarB, within = "PERS_KJOENN")
#> [preAggregate 27*14->21*7]
#> [extraAggregate 21*7->6*6] Checking .....
#> GaussSuppression_none: ................
#> [aggregate for PLSroundingSuppressed 27*14->12*5]
#>    ARB_ARBKOMM nar17 PERS_KJOENN original rounded difference roundedSuppressed
#> 1        Total Total       Total       27      27          0                27
#> 2        Total Total           1       12      12          0                12
#> 3        Total Total           2       15      15          0                15
#> 4        Total 58-63       Total        6       6          0                 6
#> 5        Total 58-63           1        3       3          0                 3
#> 6        Total 58-63           2        3       3          0                 3
#> 7        Total    84       Total       21      21          0                21
#> 8        Total    84           1        9       9          0                 9
#> 9        Total    84           2       12      12          0                12
#> 10          05 Total       Total       17      17          0                17
#> 11          05 Total           1        6       5         -1                 5
#> 12          05 Total           2       11      12          1                12
#> 13          05 58-63       Total        4       5          1                NA
#> 14          05 58-63           1        2       2          0                NA
#> 15          05 58-63           2        2       3          1                NA
#> 16          05    84       Total       13      12         -1                NA
#> 17          05    84           1        4       3         -1                NA
#> 18          05    84           2        9       9          0                NA
#> 19          18 Total       Total       10      10          0                10
#> 20          18 Total           1        6       7          1                 7
#> 21          18 Total           2        4       3         -1                 3
#> 22          18 58-63       Total        2       1         -1                NA
#> 23          18 58-63           1        1       1          0                NA
#> 24          18 58-63           2        1       0         -1                NA
#> 25          18    84       Total        8       9          1                NA
#> 26          18    84           1        5       6          1                NA
#> 27          18    84           2        3       3          0                NA
#> 28        0518 Total       Total        5       4         -1                 4
#> 29        0518 Total           1        1       0         -1                 0
#> 30        0518 Total           2        4       4          0                 4
#> 31        0518 58-63       Total        0       0          0                 0
#> 32        0518 58-63           1        0       0          0                 0
#> 33        0518 58-63           2        0       0          0                 0
#> 34        0518    84       Total        5       4         -1                 4
#> 35        0518    84           1        1       0         -1                 0
#> 36        0518    84           2        4       4          0                 4
#> 37        0531 Total       Total       12      13          1                13
#> 38        0531 Total           1        5       5          0                 5
#> 39        0531 Total           2        7       8          1                 8
#> 40        0531 58-63       Total        4       5          1                NA
#> 41        0531 58-63           1        2       2          0                NA
#> 42        0531 58-63           2        2       3          1                NA
#> 43        0531    84       Total        8       8          0                NA
#> 44        0531    84           1        3       3          0                NA
#> 45        0531    84           2        5       5          0                NA
#> 46        1821 Total       Total        4       6          2                 6
#> 47        1821 Total           1        2       3          1                 3
#> 48        1821 Total           2        2       3          1                 3
#> 49        1821 58-63       Total        0       0          0                 0
#> 50        1821 58-63           1        0       0          0                 0
#> 51        1821 58-63           2        0       0          0                 0
#> 52        1821    84       Total        4       6          2                 6
#> 53        1821    84           1        2       3          1                 3
#> 54        1821    84           2        2       3          1                 3
#> 55        1822 Total       Total        6       4         -2                 4
#> 56        1822 Total           1        4       4          0                 4
#> 57        1822 Total           2        2       0         -2                 0
#> 58        1822 58-63       Total        2       1         -1                NA
#> 59        1822 58-63           1        1       1          0                NA
#> 60        1822 58-63           2        1       0         -1                NA
#> 61        1822    84       Total        4       3         -1                NA
#> 62        1822    84           1        3       3          0                NA
#> 63        1822    84           2        1       0         -1                NA

SdcForetakPerson(z, between = prikkeVarA, maxN = 2)
#> [preAggregate 27*14->21*7]
#> [extraAggregate 21*7->10*7] Checking .....
#> GaussSuppression_anySumNOTprimary: .........................
#>    ARB_ARBKOMM  sektor freq nPrivat nOff prikket primary suppressed
#> 1        Total   Total   27       5   13      27       0          0
#> 2        Total   45-82    6       5    0       6       0          0
#> 3        Total      84   21       0   13      21       0          0
#> 4        Total Kommual   12       0    9      12       0          0
#> 5        Total  Privat    6       5    0       6       0          0
#> 6        Total Statlig    9       0    4       9       0          0
#> 7           05   Total   17       3    9      17       0          0
#> 8           05   45-82    4       3    0      NA       0          1
#> 9           05      84   13       0    9      NA       0          1
#> 10          05 Kommual    9       0    7       9       0          0
#> 11          05  Privat    4       3    0      NA       0          1
#> 12          05 Statlig    4       0    2      NA       0          1
#> 13          18   Total   10       2    5      10       0          0
#> 14          18   45-82    2       2    0      NA       1          1
#> 15          18      84    8       0    5      NA       0          1
#> 16          18 Kommual    3       0    2       3       0          0
#> 17          18  Privat    2       2    0      NA       1          1
#> 18          18 Statlig    5       0    3      NA       0          1
#> 19        0518   Total    5       0    5       5       0          0
#> 20        0518   45-82    0       0    0       0       0          0
#> 21        0518      84    5       0    5       5       0          0
#> 22        0518 Kommual    3       0    3      NA       0          1
#> 23        0518  Privat    0       0    0       0       0          0
#> 24        0518 Statlig    2       0    2      NA       1          1
#> 25        0531   Total   12       3    6      12       0          0
#> 26        0531   45-82    4       3    0      NA       0          1
#> 27        0531      84    8       0    6      NA       0          1
#> 28        0531 Kommual    6       0    4      NA       0          1
#> 29        0531  Privat    4       3    0      NA       0          1
#> 30        0531 Statlig    2       0    2      NA       1          1
#> 31        1821   Total    4       0    3       4       0          0
#> 32        1821   45-82    0       0    0       0       0          0
#> 33        1821      84    4       0    3       4       0          0
#> 34        1821 Kommual    2       0    1      NA       1          1
#> 35        1821  Privat    0       0    0       0       0          0
#> 36        1821 Statlig    2       0    2      NA       1          1
#> 37        1822   Total    6       2    2       6       0          0
#> 38        1822   45-82    2       2    0      NA       1          1
#> 39        1822      84    4       0    2      NA       0          1
#> 40        1822 Kommual    1       0    1      NA       1          1
#> 41        1822  Privat    2       2    0      NA       1          1
#> 42        1822 Statlig    3       0    1       3       0          0
SdcForetakPerson(z, between = prikkeVarA, maxN = 2, decimal = TRUE)
#> [preAggregate 27*14->21*7]
#> [extraAggregate 21*7->10*7] Checking .....
#> GaussSuppression_anySumNOTprimary: .........................
#>    arb_fylke ARB_ARBKOMM  nar8  sektor freq nPrivat nOff prikk  freqDec1
#> 1         05        0518    84 Kommual    3       0    3     1 3.1504665
#> 2         05        0518    84 Statlig    2       0    2     1 1.8495335
#> 3         05        0531    84 Kommual    6       0    4     1 5.8495335
#> 4         05        0531 45-82  Privat    4       3    0     1 3.4787405
#> 5         05        0531    84 Statlig    2       0    2     1 2.6717260
#> 6         18        1821    84 Kommual    2       0    1     1 2.5212595
#> 7         18        1821    84 Statlig    2       0    2     1 1.4787405
#> 8         18        1822    84 Kommual    1       0    1     1 0.4787405
#> 9         18        1822 45-82  Privat    2       2    0     1 2.5212595
#> 10        18        1822    84 Statlig    3       0    1     0 3.0000000
#>     freqDec2 freqDec3
#> 1  3.0447216 3.925517
#> 2  1.9552784 1.074483
#> 3  5.9552784 5.074483
#> 4  3.6010655 4.573543
#> 5  2.4436561 2.351974
#> 6  2.3989345 1.426457
#> 7  1.6010655 2.573543
#> 8  0.6010655 1.573543
#> 9  2.3989345 1.426457
#> 10 3.0000000 3.000000
SdcForetakPerson(z, between = prikkeVarB, within = "PERS_KJOENN", maxN = 2, decimal = TRUE)
#> [preAggregate 27*14->24*8]
#> [extraAggregate 24*8->12*7] Checking .....
#> GaussSuppression_anySumNOTprimary: .....................................
#>    arb_fylke ARB_ARBKOMM nar17 PERS_KJOENN freq nPrivat nOff prikk   freqDec1
#> 1         05        0518    84           1    1       0    5     1  1.9107055
#> 2         05        0518    84           2    4       0    5     1  3.0892945
#> 3         05        0531 58-63           1    2       3    0     1  1.0892945
#> 4         05        0531 58-63           2    2       3    0     1  3.6211762
#> 5         05        0531    84           1    3       0    6     0  3.0000000
#> 6         05        0531    84           2    5       0    6     1  4.2895294
#> 7         18        1821    84           1    2       0    3     1  2.2229241
#> 8         18        1821    84           2    2       0    3     1  1.7770759
#> 9         18        1822 58-63           1    1       2    0     1  1.9107055
#> 10        18        1822 58-63           2    1       2    0     1 -0.6211762
#> 11        18        1822    84           1    3       0    2     1  1.8663703
#> 12        18        1822    84           2    1       0    2     1  2.8441003
#>      freqDec2   freqDec3
#> 1   1.1812143  1.1928988
#> 2   3.8187857  3.8071012
#> 3   1.8187857  1.8071012
#> 4   3.5291489  3.4884345
#> 5   3.0000000  3.0000000
#> 6   3.6520654  3.7044643
#> 7   1.7094074  1.6271230
#> 8   2.2905926  2.3728770
#> 9   1.1812143  1.1928988
#> 10 -0.5291489 -0.4884345
#> 11  3.1093783  3.1799782
#> 12  2.2385564  2.1155575

z100 <- SdcData("syssel100")
out <- SdcForetakPerson(z100, between = prikkeVarB, within = c("PERS_KJOENN", "alder6"))
#> [preAggregate 100*14->56*7]
#> [extraAggregate 56*7->15*6] Checking .....
#> GaussSuppression_none: ................................
#> [aggregate for PLSroundingSuppressed 100*14->57*6]
head(out)
#>   ARB_ARBKOMM nar17 PERS_KJOENN alder6 original rounded difference
#> 1       Total Total       Total  Total      100      99         -1
#> 2       Total Total       Total  15-19        5       3         -2
#> 3       Total Total       Total  20-24        5       3         -2
#> 4       Total Total       Total  25-39       25      27          2
#> 5       Total Total       Total  40-54       41      40         -1
#> 6       Total Total       Total  55-66       20      20          0
#>   roundedSuppressed
#> 1                99
#> 2                 3
#> 3                 3
#> 4                27
#> 5                40
#> 6                20
tail(out)
#>     ARB_ARBKOMM nar17 PERS_KJOENN alder6 original rounded difference
#> 730        1822    85           2  15-19        0       0          0
#> 731        1822    85           2  20-24        0       0          0
#> 732        1822    85           2  25-39        0       0          0
#> 733        1822    85           2  40-54        3       3          0
#> 734        1822    85           2  55-66        0       0          0
#> 735        1822    85           2  67-74        0       0          0
#>     roundedSuppressed
#> 730                 0
#> 731                 0
#> 732                 0
#> 733                 3
#> 734                 0
#> 735                 0

# Setter  allowTotal = TRUE
outT <- SdcForetakPerson(z100, between = prikkeVarB, within = c("PERS_KJOENN", "alder6"), 
                         allowTotal = TRUE)
#> [preAggregate 100*14->56*7]
#> [extraAggregate 56*7->15*6] Checking .....
#> GaussSuppression_none: ................................
#> [aggregate for PLSroundingSuppressed 100*14->57*6]
# Rader som har gitt ulik prikking
rader <- which(is.na(outT$roundedSuppressed) != is.na(out$roundedSuppressed))
out[rader, ]
#>     ARB_ARBKOMM nar17 PERS_KJOENN alder6 original rounded difference
#> 127          05 49-53       Total  Total       14      10         -4
#> 148          05 58-63       Total  Total        5       3         -2
#> 232          18 49-53       Total  Total        8       9          1
#> 253          18 58-63       Total  Total        2       0         -2
#> 254          18 58-63       Total  15-19        0       0          0
#> 255          18 58-63       Total  20-24        0       0          0
#> 256          18 58-63       Total  25-39        1       0         -1
#> 257          18 58-63       Total  40-54        1       0         -1
#> 258          18 58-63       Total  55-66        0       0          0
#> 259          18 58-63       Total  67-74        0       0          0
#> 260          18 58-63           1  Total        1       0         -1
#> 261          18 58-63           1  15-19        0       0          0
#> 262          18 58-63           1  20-24        0       0          0
#> 263          18 58-63           1  25-39        0       0          0
#> 264          18 58-63           1  40-54        1       0         -1
#> 265          18 58-63           1  55-66        0       0          0
#> 266          18 58-63           1  67-74        0       0          0
#> 267          18 58-63           2  Total        1       0         -1
#> 268          18 58-63           2  15-19        0       0          0
#> 269          18 58-63           2  20-24        0       0          0
#> 270          18 58-63           2  25-39        1       0         -1
#> 271          18 58-63           2  40-54        0       0          0
#> 272          18 58-63           2  55-66        0       0          0
#> 273          18 58-63           2  67-74        0       0          0
#> 337        0518 49-53       Total  Total        6       4         -2
#> 358        0518 58-63       Total  Total        1       0         -1
#> 359        0518 58-63       Total  15-19        1       0         -1
#> 360        0518 58-63       Total  20-24        0       0          0
#> 361        0518 58-63       Total  25-39        0       0          0
#> 362        0518 58-63       Total  40-54        0       0          0
#> 363        0518 58-63       Total  55-66        0       0          0
#> 364        0518 58-63       Total  67-74        0       0          0
#> 365        0518 58-63           1  Total        0       0          0
#> 366        0518 58-63           1  15-19        0       0          0
#> 367        0518 58-63           1  20-24        0       0          0
#> 368        0518 58-63           1  25-39        0       0          0
#> 369        0518 58-63           1  40-54        0       0          0
#> 370        0518 58-63           1  55-66        0       0          0
#> 371        0518 58-63           1  67-74        0       0          0
#> 372        0518 58-63           2  Total        1       0         -1
#> 373        0518 58-63           2  15-19        1       0         -1
#> 374        0518 58-63           2  20-24        0       0          0
#> 375        0518 58-63           2  25-39        0       0          0
#> 376        0518 58-63           2  40-54        0       0          0
#> 377        0518 58-63           2  55-66        0       0          0
#> 378        0518 58-63           2  67-74        0       0          0
#> 652        1822 49-53       Total  Total        5       6          1
#> 673        1822 58-63       Total  Total        2       0         -2
#> 674        1822 58-63       Total  15-19        0       0          0
#> 675        1822 58-63       Total  20-24        0       0          0
#> 676        1822 58-63       Total  25-39        1       0         -1
#> 677        1822 58-63       Total  40-54        1       0         -1
#> 678        1822 58-63       Total  55-66        0       0          0
#> 679        1822 58-63       Total  67-74        0       0          0
#> 680        1822 58-63           1  Total        1       0         -1
#> 681        1822 58-63           1  15-19        0       0          0
#> 682        1822 58-63           1  20-24        0       0          0
#> 683        1822 58-63           1  25-39        0       0          0
#> 684        1822 58-63           1  40-54        1       0         -1
#> 685        1822 58-63           1  55-66        0       0          0
#> 686        1822 58-63           1  67-74        0       0          0
#> 687        1822 58-63           2  Total        1       0         -1
#> 688        1822 58-63           2  15-19        0       0          0
#> 689        1822 58-63           2  20-24        0       0          0
#> 690        1822 58-63           2  25-39        1       0         -1
#> 691        1822 58-63           2  40-54        0       0          0
#> 692        1822 58-63           2  55-66        0       0          0
#> 693        1822 58-63           2  67-74        0       0          0
#>     roundedSuppressed
#> 127                NA
#> 148                NA
#> 232                NA
#> 253                NA
#> 254                NA
#> 255                NA
#> 256                NA
#> 257                NA
#> 258                NA
#> 259                NA
#> 260                NA
#> 261                NA
#> 262                NA
#> 263                NA
#> 264                NA
#> 265                NA
#> 266                NA
#> 267                NA
#> 268                NA
#> 269                NA
#> 270                NA
#> 271                NA
#> 272                NA
#> 273                NA
#> 337                NA
#> 358                NA
#> 359                NA
#> 360                NA
#> 361                NA
#> 362                NA
#> 363                NA
#> 364                NA
#> 365                NA
#> 366                NA
#> 367                NA
#> 368                NA
#> 369                NA
#> 370                NA
#> 371                NA
#> 372                NA
#> 373                NA
#> 374                NA
#> 375                NA
#> 376                NA
#> 377                NA
#> 378                NA
#> 652                NA
#> 673                NA
#> 674                NA
#> 675                NA
#> 676                NA
#> 677                NA
#> 678                NA
#> 679                NA
#> 680                NA
#> 681                NA
#> 682                NA
#> 683                NA
#> 684                NA
#> 685                NA
#> 686                NA
#> 687                NA
#> 688                NA
#> 689                NA
#> 690                NA
#> 691                NA
#> 692                NA
#> 693                NA
outT[rader, ]
#>     ARB_ARBKOMM nar17 PERS_KJOENN alder6 original rounded difference
#> 127          05 49-53       Total  Total       14      13         -1
#> 148          05 58-63       Total  Total        5       3         -2
#> 232          18 49-53       Total  Total        8       9          1
#> 253          18 58-63       Total  Total        2       0         -2
#> 254          18 58-63       Total  15-19        0       0          0
#> 255          18 58-63       Total  20-24        0       0          0
#> 256          18 58-63       Total  25-39        1       0         -1
#> 257          18 58-63       Total  40-54        1       0         -1
#> 258          18 58-63       Total  55-66        0       0          0
#> 259          18 58-63       Total  67-74        0       0          0
#> 260          18 58-63           1  Total        1       0         -1
#> 261          18 58-63           1  15-19        0       0          0
#> 262          18 58-63           1  20-24        0       0          0
#> 263          18 58-63           1  25-39        0       0          0
#> 264          18 58-63           1  40-54        1       0         -1
#> 265          18 58-63           1  55-66        0       0          0
#> 266          18 58-63           1  67-74        0       0          0
#> 267          18 58-63           2  Total        1       0         -1
#> 268          18 58-63           2  15-19        0       0          0
#> 269          18 58-63           2  20-24        0       0          0
#> 270          18 58-63           2  25-39        1       0         -1
#> 271          18 58-63           2  40-54        0       0          0
#> 272          18 58-63           2  55-66        0       0          0
#> 273          18 58-63           2  67-74        0       0          0
#> 337        0518 49-53       Total  Total        6       4         -2
#> 358        0518 58-63       Total  Total        1       0         -1
#> 359        0518 58-63       Total  15-19        1       0         -1
#> 360        0518 58-63       Total  20-24        0       0          0
#> 361        0518 58-63       Total  25-39        0       0          0
#> 362        0518 58-63       Total  40-54        0       0          0
#> 363        0518 58-63       Total  55-66        0       0          0
#> 364        0518 58-63       Total  67-74        0       0          0
#> 365        0518 58-63           1  Total        0       0          0
#> 366        0518 58-63           1  15-19        0       0          0
#> 367        0518 58-63           1  20-24        0       0          0
#> 368        0518 58-63           1  25-39        0       0          0
#> 369        0518 58-63           1  40-54        0       0          0
#> 370        0518 58-63           1  55-66        0       0          0
#> 371        0518 58-63           1  67-74        0       0          0
#> 372        0518 58-63           2  Total        1       0         -1
#> 373        0518 58-63           2  15-19        1       0         -1
#> 374        0518 58-63           2  20-24        0       0          0
#> 375        0518 58-63           2  25-39        0       0          0
#> 376        0518 58-63           2  40-54        0       0          0
#> 377        0518 58-63           2  55-66        0       0          0
#> 378        0518 58-63           2  67-74        0       0          0
#> 652        1822 49-53       Total  Total        5       6          1
#> 673        1822 58-63       Total  Total        2       0         -2
#> 674        1822 58-63       Total  15-19        0       0          0
#> 675        1822 58-63       Total  20-24        0       0          0
#> 676        1822 58-63       Total  25-39        1       0         -1
#> 677        1822 58-63       Total  40-54        1       0         -1
#> 678        1822 58-63       Total  55-66        0       0          0
#> 679        1822 58-63       Total  67-74        0       0          0
#> 680        1822 58-63           1  Total        1       0         -1
#> 681        1822 58-63           1  15-19        0       0          0
#> 682        1822 58-63           1  20-24        0       0          0
#> 683        1822 58-63           1  25-39        0       0          0
#> 684        1822 58-63           1  40-54        1       0         -1
#> 685        1822 58-63           1  55-66        0       0          0
#> 686        1822 58-63           1  67-74        0       0          0
#> 687        1822 58-63           2  Total        1       0         -1
#> 688        1822 58-63           2  15-19        0       0          0
#> 689        1822 58-63           2  20-24        0       0          0
#> 690        1822 58-63           2  25-39        1       0         -1
#> 691        1822 58-63           2  40-54        0       0          0
#> 692        1822 58-63           2  55-66        0       0          0
#> 693        1822 58-63           2  67-74        0       0          0
#>     roundedSuppressed
#> 127                13
#> 148                 3
#> 232                 9
#> 253                 0
#> 254                 0
#> 255                 0
#> 256                 0
#> 257                 0
#> 258                 0
#> 259                 0
#> 260                 0
#> 261                 0
#> 262                 0
#> 263                 0
#> 264                 0
#> 265                 0
#> 266                 0
#> 267                 0
#> 268                 0
#> 269                 0
#> 270                 0
#> 271                 0
#> 272                 0
#> 273                 0
#> 337                 4
#> 358                 0
#> 359                 0
#> 360                 0
#> 361                 0
#> 362                 0
#> 363                 0
#> 364                 0
#> 365                 0
#> 366                 0
#> 367                 0
#> 368                 0
#> 369                 0
#> 370                 0
#> 371                 0
#> 372                 0
#> 373                 0
#> 374                 0
#> 375                 0
#> 376                 0
#> 377                 0
#> 378                 0
#> 652                 6
#> 673                 0
#> 674                 0
#> 675                 0
#> 676                 0
#> 677                 0
#> 678                 0
#> 679                 0
#> 680                 0
#> 681                 0
#> 682                 0
#> 683                 0
#> 684                 0
#> 685                 0
#> 686                 0
#> 687                 0
#> 688                 0
#> 689                 0
#> 690                 0
#> 691                 0
#> 692                 0
#> 693                 0

# Ser effekt av allowTotal ved bare prikking
outP <- SdcForetakPerson(z100, between = prikkeVarB, within = c("PERS_KJOENN", "alder6"), maxN = 1)
#> [preAggregate 100*14->83*9]
#> [extraAggregate 83*9->57*8] Checking .....
#> GaussSuppression_anySumNOTprimary: ..........................
outTP <- SdcForetakPerson(z100, between = prikkeVarB, within = c("PERS_KJOENN", "alder6"), maxN = 1, 
                          allowTotal = TRUE)
#> [preAggregate 100*14->83*9]
#> [extraAggregate 83*9->57*8] Checking .....
#> GaussSuppression_anySumNOTprimary: ...........................
# Rader som har gitt ulik primærprikking 
raderP <- which(outTP$primary != outP$primary)
outP[raderP, ]   # Her ble allikevel prikking til slutt lik (suppressed)
#>     ARB_ARBKOMM nar17 PERS_KJOENN alder6 freq nPrivat nOff prikket primary
#> 253          18 58-63       Total  Total    2       2    0      NA       1
#> 673        1822 58-63       Total  Total    2       2    0      NA       1
#>     suppressed
#> 253          1
#> 673          1
outTP[raderP, ]  # Dette pga. singleton-håndtering (1-ere som kan avsløres)
#>     ARB_ARBKOMM nar17 PERS_KJOENN alder6 freq nPrivat nOff prikket primary
#> 253          18 58-63       Total  Total    2       2    0      NA       0
#> 673        1822 58-63       Total  Total    2       2    0      NA       0
#>     suppressed
#> 253          1
#> 673          1


# Finner data desimaltall med mange variabler som tas hensyn til.  
# Dessverre en warning som kan sees bort fra 
# Kan unngaas med dataDec <- suppressWarnings(SdcForetakPerson(.....
prikkeVarC <- c("arb_fylke", "ARB_ARBKOMM", "nar8", "sektor", "nar17")
dataDec <- SdcForetakPerson(z100, between = prikkeVarC, nace = "nar8", decimal = TRUE)
#> [preAggregate 100*14->56*8]
#> Warning: Levelnames must be different in nar17, nar8
#> Warning: Settting addName to TRUE (overriding input)
#> [extraAggregate 56*8->26*8] 
#> Warning: Levelnames must be different in nar17, nar8
#> Warning: Settting addName to TRUE (overriding input)
#> Checking .....
#> GaussSuppression_none: ..............................

# Bruker desimaltall som utgangspunkt for prikking
outA <- SdcForetakPerson(z100, between = prikkeVarA, decimal = dataDec)
#> [preAggregate 26*12->23*8]
#> GaussSuppression_none: 
#> [aggregate for PLSroundingSuppressed 100*11->23*5]
outB <- SdcForetakPerson(z100, between = prikkeVarB, within = "PERS_KJOENN", decimal = dataDec)
#> [preAggregate 26*12->15*7]
#> GaussSuppression_none: 
#> [aggregate for PLSroundingSuppressed 100*11->26*5]

# Desimaltall kan genereres med formel 
dataDec2 <- SdcForetakPerson(z100, between = 
                 ~(arb_fylke + ARB_ARBKOMM) * nar8 * sektor + (arb_fylke + ARB_ARBKOMM) * nar17, 
                 nace = "nar8", decimal = TRUE)
#> [preAggregate 100*14->56*8]
#> [extraAggregate 56*8->26*8] Checking .....
#> GaussSuppression_none: ............................

# Lager data med to stataar
z100$stataar <- "2019"
z$stataar <- "2020"
z127 <- rbind(z100, z)
out127 <- SdcForetakPerson(z127, between = prikkeVarB, by = "stataar")
#> [preAggregate 100*15->56*7]
#> [extraAggregate 56*7->15*6] Checking .....
#> GaussSuppression_none: ................................
#> [aggregate for PLSroundingSuppressed 100*15->15*4]
#> [preAggregate 27*15->21*7]
#> [extraAggregate 21*7->6*6] Checking .....
#> GaussSuppression_none: ................
#> [aggregate for PLSroundingSuppressed 27*15->6*4]
head(out127)
#>   stataar ARB_ARBKOMM nar17 original rounded difference roundedSuppressed
#> 1    2019       Total Total      100     100          0               100
#> 2    2019       Total 49-53       22      22          0                22
#> 3    2019       Total 58-63        7       7          0                 7
#> 4    2019       Total    84       32      32          0                32
#> 5    2019       Total    85       39      39          0                39
#> 6    2019          05 Total       67      67          0                67
tail(out127)
#>    stataar ARB_ARBKOMM nar17 original rounded difference roundedSuppressed
#> 51    2020        1821 Total        4       4          0                 4
#> 52    2020        1821 58-63        0       0          0                 0
#> 53    2020        1821    84        4       4          0                 4
#> 54    2020        1822 Total        6       6          0                 6
#> 55    2020        1822 58-63        2       2          0                NA
#> 56    2020        1822    84        4       4          0                NA