-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from statisticsnorway/HAM_SA
Oppdatere med 2 nye funksjoner + quatro-side om metodeområde
- Loading branch information
Showing
6 changed files
with
83 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,59 @@ | ||
# Testing of price index calculations | ||
library(SSBpris) | ||
|
||
|
||
test_that("CalcInd returns correct value", { | ||
data(priceData, package = "SSBpris") | ||
expect_warning( | ||
test_that("CalcInd returns correct value in consumVar groups", { | ||
data(priceData) | ||
suppressWarnings( | ||
ind <- CalcInd(data = priceData, baseVar = "b1", pVar = "p1", groupVar = "varenr", wVar = "weight", | ||
consumVar = "coicop", type = "dutot") | ||
consumVar = "nace3", type = "dutot") | ||
) | ||
|
||
expect_equal(as.numeric(ind[1]), 0.09978126, tolerance = 1E-4) | ||
expect_equal(as.numeric(ind[1]), 1.028245, tolerance = 1E-4) | ||
}) | ||
|
||
|
||
test_that("CalcInd throws a warning if weights must be adjusted, otherwise no warning", { | ||
data(priceData) | ||
priceData <- priceData[priceData$varenr %in% c(1,2),] | ||
expect_warning( | ||
CalcInd(data = priceData, baseVar = "b1", pVar = "p1", groupVar = "varenr", wVar = "weight", | ||
consumVar = "coicop", type = "dutot") | ||
) | ||
priceData$weight <- c(rep(0.5, 6), rep(0.5, 7)) | ||
expect_silent( | ||
CalcInd(data = priceData, baseVar = "b1", pVar = "p1", groupVar = "varenr", wVar = "weight", | ||
consumVar = "coicop", type = "dutot") | ||
) | ||
}) | ||
|
||
test_that("CalcIndS2 returns correct values", { | ||
data(priceData, package = "SSBpris") | ||
ss <- CalcIndS2(data = priceData, baseVar = "b1", pVar = "p1", groupVar = "coicop", | ||
type = "jevons") | ||
expect_equal(length(ss), 3) | ||
expect_equal(as.numeric(ss$s2[1]), 0.0019782, tolerance=1E-4) | ||
|
||
test_that("CalcInd throws warning for missing weight values", { | ||
data(priceData) | ||
priceData <- priceData[priceData$varenr %in% c(1,2),] | ||
priceData$weight <- c(rep(0.5, 6), rep(0.5, 7)) | ||
priceData[1, "weight"] <- NA | ||
expect_warning(ind <- CalcInd(data = priceData, baseVar = "b1", pVar = "p1", groupVar = "varenr", wVar = "weight", | ||
consumVar = "coicop", type = "dutot"), | ||
"wVar has missing or invalid values" | ||
) | ||
|
||
# check that it returns the value though | ||
expect_equal(as.numeric(ind), 1.014, tolerance = 0.001, ignore_attr=F) | ||
}) | ||
|
||
test_that("CalcInd returns vector of length, equal to consumVar", { | ||
data(priceData) | ||
expect_warning(ind <- CalcInd(data = priceData, baseVar = "b1", pVar = "p1", groupVar = "varenr", wVar = "weight", | ||
consumVar = "coicop", type = "dutot"), | ||
"Elementary group weights did not add to one" | ||
) | ||
expect_equal(length(ind), 10) | ||
|
||
# check levels works if only a subset of data is run | ||
priceData$coicop <- factor(priceData$coicop) | ||
priceData <- priceData[priceData$coicop %in% c(1,2),] | ||
expect_warning(ind <- CalcInd(data = priceData, baseVar = "b1", pVar = "p1", groupVar = "varenr", wVar = "weight", | ||
consumVar = "coicop", type = "dutot"), | ||
"Elementary group weights did not add to one" | ||
) | ||
expect_equal(length(ind), 2) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
title: "Sesongjustering og tidsserieanalyse" | ||
format: | ||
html: | ||
echo: false | ||
page-layout: full | ||
sidebar: false | ||
--- | ||
|
||
Sesongjustering er å bruke statistiske metoder for å fjerne systematiske sesongvariasjoner fra en månedlig eller kvartalsvis tidsserie, slik at tidsserien i størst mulig grad uttrykker den reelle utviklingen over tid. I tillegg forsøker man å fjerne kalendereffektene som varierer fra år til år, slik som påske. I sesongjusteringsprosessen spaltes den prekorrigerte (kalenderjusterte) tidsserien opp i tre komponenter: sesong, en irregulær og trend-syklus. Når dataene er korrigert for de sesongrelaterte forholdene, vil man stå igjen med et klarere bilde av den underliggende utviklingen i tidsserien som består av trend-syklus og irregulær komponent. Sesongjusterte data brukes ofte som utgangspunkt for opprettelse eller revidering av økonomisk politikk og økonomisk forskning på høyt nivå. Trend-syklus-komponenten er glattere enn sesongjusterte tall, og kan evt. formidles til brukerne i tillegg. I tidsserieanalyse kan en også justere tidsseriene for evt. brudd. Du kan finne mer informasjon om Sesongjustering og tidsserieanalyse på [Byrånettet](https://ssbno.sharepoint.com/sites/Metodikkistatistikkproduksjonen/SitePages/Sesongjustering.aspx). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters