mountainMath / mountainMath/cansim

Add functionality for StatCan trend estimates

Open
#33 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
R
Stars
51
Forks
6
Avg merge
15h 34m
Merged PRs (30d)
1

Description

StatCan has a standard procedure for trend estimates, @jciconsult shared his R implementation for the code. We could add this to the base package, it is useful for reproducing StatCan results. Or we could start a separate package with helper functions. Thoughts @dshkol?

Implementation below.

#jci implementation of stc trend
stc_trend<-function(x,method=1){
	weights<-c(
	-0.027,	-0.007,	0.031,	0.067,	0.136,	0.188,	0.224,	0.188,	0.136,	0.067,	0.031,	-0.007,	-0.027)
	#first do the base filter
	result1<-rep(NA,length(x))
	if(method %in% c(1,2)){
		result1<-filter(x,weights,sides=2)
		#now do first 6 cells
		for(icell in 1:6){
			cell_weights<-tail(weights,icell+6)
			cell_weights<-cell_weights/sum(cell_weights)
			numb_weights<-length(cell_weights)
			input_data<-head(x,numb_weights)
			cell_value<-sum(cell_weights*input_data)
			result1[icell]<-cell_value
		}
	}
	#now do last 6 cells
	vlength<-length(result1)
	if(method %in% c(1,3)){
		for(icell in 1:6){
		cell_weights<-head(weights,icell+6)
			cell_weights<-cell_weights/sum(cell_weights)
			numb_weights<-length(cell_weights)
			input_data<-tail(x,numb_weights)
			cell_value<-sum(cell_weights*input_data)
			result1[vlength-icell+1]<-cell_value
		}
	}
	stc_trend<-result1
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the proposed R implementation in the issue and the existing cansim package structure. Resolve whether the functionality belongs in the base package or a separate helper package, then define how its results will be validated against StatCan trend estimates. The issue names no files or tests, so an entry point and completion criteria still need to be established.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.