diff --git a/data/katalogdata.csv b/data/katalogdata.csv index 18dc924..c38d041 100644 --- a/data/katalogdata.csv +++ b/data/katalogdata.csv @@ -15,6 +15,7 @@ "impute_pmm","simputation","Hot deck imputation","Hot-deck imputation methods include random and sequential hot deck, k-nearest neighbours imputation and predictive mean matching.","r imputere donor","https://rdrr.io/cran/simputation/man/impute_hotdeck.html","https://cran.r-project.org/web/packages/simputation/index.html" "impute_proxy","simputation","Impute by variable derivation","Impute missing values by a constant, by copying another variable computing transformations from other variables.","r imputere donor","https://rdrr.io/cran/simputation/man/impute_proxy.html","https://cran.r-project.org/web/packages/simputation/index.html" "impute_rhd","simputation","Hot deck imputation","Hot-deck imputation methods include random and sequential hot deck, k-nearest neighbours imputation and predictive mean matching.","r imputere donor","https://rdrr.io/cran/simputation/man/impute_hotdeck.html","https://cran.r-project.org/web/packages/simputation/index.html" +"konstruksjon","pickmdl","Lage faktorer for kalendereffekter","Fleksibel funksjon som lager ulike kalendervariable, som f.eks. TD-, WD- og påskevariable, tilpasset norske forhold.","r sesongjustering 6.1","https://github.com/statisticsnorway/pickmdl/blob/main/man/konstruksjon.Rd","https://github.com/statisticsnorway/pickmdl/" "lm","stats","Fitting Linear Models","'lm' is used to fit linear models, including multivariate ones. It can be used to carry out regression, single stratum analysis of variance and analysis of covariance (although 'aov' may provide a more convenient interface for these).","r imputere analyse modellbasert","https://rdrr.io/r/stats/lm.html","https://github.com/statisticsnorway/stats/" "LmImpute","Kostra","INTERNAL FUNCTION: Regeression imputation.","Imputation by weighted regeression, using lm, allowing multiple explanatory variables and multiple response variables. Impute missing and wrong values (category 3) by the model based on representative data (category 1). Some data are considered correct but not representative (category 2).","r imputere modellbasert kontrollere statistisk","https://rdrr.io/github/statisticsnorway/Kostra/man/LmImpute.html","https://github.com/statisticsnorway/Kostra/" "model_aggregate","SSBtools","Hierarchical aggregation via model specification","Internally a dummy/model matrix is created according to the model specification. This model matrix is used in the aggregation process via matrix multiplication and/or the function 'aggregate_multiple_fun'.","r strukturere 6.2","https://rdrr.io/cran/SSBtools/man/model_aggregate.html","https://cran.r-project.org/web/packages/SSBtools/index.html" @@ -45,3 +46,4 @@ "x13_both","pickmdl","x13_spec and x13_pickmdl wrapped as a single function","Output is determined by the parameter: both_output.","r sesongjustering 6.1","https://github.com/statisticsnorway/pickmdl/blob/main/man/x13_both.Rd","https://github.com/statisticsnorway/pickmdl/" "x13_pickmdl","pickmdl","x13 with PICKMDL and partial concurrent possibilities","x13 can be run as usual (automdl) or with a PICKMDL specification. The ARIMA model, outliers and filters can be identified at a certain date and then held fixed (with a new outlier-span).","r sesongjustering 6.1","https://github.com/statisticsnorway/pickmdl/blob/main/man/x13_pickmdl.Rd","https://github.com/statisticsnorway/pickmdl/" "x13_spec","RJDemetra","X-13ARIMA model specification, SA/X13","Function to create (and/or modify) a c(""SA_spec"", ""X13"") class object with the SA model specification for the X13 method. It can be done from a pre-defined ""JDemetra+"" model specification (a character), a previous specification (c(""SA_spec"", ""X13"") object) or a seasonal adjustment model (c(""SA"", ""X13"") object).","r sesongjustering 6.1","https://rdrr.io/cran/RJDemetra/man/x13_spec.html","https://cran.r-project.org/web/packages/RJDemetra/index.html" +"x13_text_frame","pickmdl","Multiple x13_both runs with code input from a data frame","Gjør det mulig med sesongjustering av mange serier basert på parametere i en data.frame (f.eks lest inn fra en excel-fil).","r sesongjustering 6.1","https://github.com/statisticsnorway/pickmdl/blob/main/man/x13_text_frame.Rd","https://github.com/statisticsnorway/pickmdl/" diff --git a/internal/create_table.R b/internal/create_table.R index 88dbd01..bc18585 100644 --- a/internal/create_table.R +++ b/internal/create_table.R @@ -102,6 +102,18 @@ add_func("x13_both", "pickmdl", keyword = "r sesongjustering 6.1", url="https:// descrip = "Output is determined by the parameter: both_output.", export = FALSE) +add_func("x13_text_frame", "pickmdl", keyword = "r sesongjustering 6.1", url="https://github.com/statisticsnorway/pickmdl/blob/main/man/x13_text_frame.Rd", + pack_url="https://github.com/statisticsnorway/pickmdl/", + name = "Multiple x13_both runs with code input from a data frame", + descrip = "Gjør det mulig med sesongjustering av mange serier basert på parametere i en data.frame (f.eks lest inn fra en excel-fil).", + export = FALSE) +add_func("konstruksjon", "pickmdl", keyword = "r sesongjustering 6.1", url="https://github.com/statisticsnorway/pickmdl/blob/main/man/konstruksjon.Rd", + pack_url="https://github.com/statisticsnorway/pickmdl/", + name = "Lage faktorer for kalendereffekter", + descrip = "Fleksibel funksjon som lager ulike kalendervariable, som f.eks. TD-, WD- og påskevariable, tilpasset norske forhold.", + export = FALSE) + + # Analyse add_func("shortest_path_igraph", "GISSB", keyword = "r analyse romlig") add_func("shortest_path_cppRouting", "GISSB", keyword = "r analyse romlig") diff --git a/tests/testthat/test-SSBpris.R b/tests/testthat/test-SSBpris.R index b4f0323..b2e5cff 100644 --- a/tests/testthat/test-SSBpris.R +++ b/tests/testthat/test-SSBpris.R @@ -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) +}) diff --git a/website/_quarto.yml b/website/_quarto.yml index ea76209..0b1df34 100644 --- a/website/_quarto.yml +++ b/website/_quarto.yml @@ -24,6 +24,8 @@ website: href: catalogue_edit.html - text: "Konfidensialitet" href: catalogue_conf.html + - text: "Sesongjustering og tidsserieanalyse" + href: catalogue_sesong.html right: - icon: github diff --git a/website/catalogue_sesong.qmd b/website/catalogue_sesong.qmd new file mode 100644 index 0000000..ec37228 --- /dev/null +++ b/website/catalogue_sesong.qmd @@ -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). diff --git a/website/prosess.qmd b/website/prosess.qmd index 84d79a4..e5295ef 100644 --- a/website/prosess.qmd +++ b/website/prosess.qmd @@ -105,7 +105,14 @@ Ingen funksjoner enda ## 6 Analyse :::{.panel-tabset} ## *6.1 Utarbeid produktutkast* -Ingen funksjoner enda. +```{r} +# filter for dataediterings functions +dt_sesong <- dt[grepl("6.1", dt$keyword), -match("keyword", names(dt))] +row.names(dt_sesong) <- NULL +kable(dt_sesong, escape = F, allign="lllcl") %>% +kable_styling() +``` + ## *6.2 Kvalitetssikre produkter* ```{r}