-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
enhancementNew feature or requestNew feature or request
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
}
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request