Skip to main content
added 61 characters in body
Source Link

Some code based on Rob's workaround of setting the negatives to zero and reconcile

# Re-reconciliate when zero values present

# Extract groups
groups <- hts.obj %>%
  aggts() %>%
  get_groups()

x=0 #Counter

# Loop until all positive
while(sum(hts.obj[[1]] <0) > 0){

  # Generate all time series
  hts.obj <- aggts(hts.obj)    
  
  # Overwrite negatives by zero
  hts.obj[hts.obj<0] <- 0
  
  # Reconcile
  hts.obj <- hts.obj %>%
    ts() %>%
    combinef(groups = groups, keep ="gts")
  
  # Count up
  x=x+1

  # Break after 10 loops
  if(x>=10)break

  }

rm("x")

# Overwrite remaining negatives by zero
hts.obj[[1]][hts.obj[[1]]<0] <- 0

In this example forecasts are indexed by [[1]] - this might change. Also note that overwriting zeros leads to biased forecasts.

Some code based on Rob's workaround of setting the negatives to zero and reconcile

# Re-reconciliate when zero values present

# Extract groups
groups <- hts.obj %>%
  aggts() %>%
  get_groups()

x=0 #Counter

# Loop until all positive
while(sum(hts.obj[[1]] <0) > 0){

  # Generate all time series
  hts.obj <- aggts(hts.obj)    
  
  # Overwrite negatives by zero
  hts.obj[hts.obj<0] <- 0
  
  # Reconcile
  hts.obj <- hts.obj %>%
    ts() %>%
    combinef(groups = groups, keep ="gts")
  
  # Count up
  x=x+1

  # Break after 10 loops
  if(x>=10)break

  }

rm("x")

# Overwrite remaining negatives by zero
hts.obj[[1]][hts.obj[[1]]<0] <- 0

In this example forecasts are indexed by [[1]] - this might change.

Some code based on Rob's workaround of setting the negatives to zero and reconcile

# Re-reconciliate when zero values present

# Extract groups
groups <- hts.obj %>%
  aggts() %>%
  get_groups()

x=0 #Counter

# Loop until all positive
while(sum(hts.obj[[1]] <0) > 0){

  # Generate all time series
  hts.obj <- aggts(hts.obj)    
  
  # Overwrite negatives by zero
  hts.obj[hts.obj<0] <- 0
  
  # Reconcile
  hts.obj <- hts.obj %>%
    ts() %>%
    combinef(groups = groups, keep ="gts")
  
  # Count up
  x=x+1

  # Break after 10 loops
  if(x>=10)break

  }

rm("x")

# Overwrite remaining negatives by zero
hts.obj[[1]][hts.obj[[1]]<0] <- 0

In this example forecasts are indexed by [[1]] - this might change. Also note that overwriting zeros leads to biased forecasts.

added 2 characters in body
Source Link

Some code based on Rob's workaround of setting the negatives to zero and reconcile

# Re-reconciliate when zero values present 

# Extract groups
groups <- hts.obj %>%
  aggts() %>%
  get_groups()

x=0 #Counter

# Loop until all positive
while(sum(hts.obj[[1]] <0) > 0){

  # Generate all time series
  hts.obj <- aggts(hts.obj)
   
  # Extract groups
  groups <- get_groups(hts.obj)
  
  # Overwrite negatives by zero
  hts.obj[hts.obj<0] <- 0
  
  # Reconcile
  hts.obj <- hts.obj %>%
    ts() %>%
    combinef(groups = groups, keep ="gts")
  
  # Count up
  x=x+1

  # Break after 10 loops
  if(x>=10)break

  }

rm("x")

# Overwrite remaining negatives by zero
hts.obj[[1]][hts.obj[[1]]<0] <- 0

In this example forecasts are indexed by [[1]] - this might change.

Some code based on Rob's workaround of setting the negatives to zero and reconcile

# Re-reconciliate when zero values present
x=0 #Counter

# Loop until all positive
while(sum(hts.obj[[1]] <0) > 0){

  # Generate all time series
  hts.obj <- aggts(hts.obj)
   
  # Extract groups
  groups <- get_groups(hts.obj)
  
  # Overwrite negatives by zero
  hts.obj[hts.obj<0] <- 0
  
  # Reconcile
  hts.obj <- hts.obj %>%
    ts() %>%
    combinef(groups = groups, keep ="gts")
  
  # Count up
  x=x+1

  # Break after 10 loops
  if(x>=10)break

  }

rm("x")

# Overwrite remaining negatives by zero
hts.obj[[1]][hts.obj[[1]]<0] <- 0

In this example forecasts are indexed by [[1]] - this might change.

Some code based on Rob's workaround of setting the negatives to zero and reconcile

# Re-reconciliate when zero values present 

# Extract groups
groups <- hts.obj %>%
  aggts() %>%
  get_groups()

x=0 #Counter

# Loop until all positive
while(sum(hts.obj[[1]] <0) > 0){

  # Generate all time series
  hts.obj <- aggts(hts.obj)    
  
  # Overwrite negatives by zero
  hts.obj[hts.obj<0] <- 0
  
  # Reconcile
  hts.obj <- hts.obj %>%
    ts() %>%
    combinef(groups = groups, keep ="gts")
  
  # Count up
  x=x+1

  # Break after 10 loops
  if(x>=10)break

  }

rm("x")

# Overwrite remaining negatives by zero
hts.obj[[1]][hts.obj[[1]]<0] <- 0

In this example forecasts are indexed by [[1]] - this might change.

added 2 characters in body
Source Link

Some code based on Rob's workaround of setting the negatives to zero and reconcile

# Re-reconciliate when zero values present
x=0 #Counter

# Loop until all positive
while(sum(hts.obj[[1]] <0) > 0){

  # Generate all time series
  hts.obj <- aggts(hts.obj)
  
  # Extract groups
  groups <- get_groups(hts.obj)
  
  # Overwrite negatives by zero
  hts.obj[hts.obj<0] <- 0
  
  # Reconcile
  hts.obj <- hts.obj %>%
    ts() %>%
    combinef(groups = groups, keep ="gts")
  
  # Count up
  x=x+1

  # Break after 10 loops
  if(x>=10)break

  }

rm("x")

# Overwrite remaining negatives by zero
hts.obj[[1]][hts.obj[[1]]<0] <- 0

Its not super lean, but i hope it helpsIn this example forecasts are indexed by [[1]] - this might change.

Some code based on Rob's workaround of setting the negatives to zero and reconcile

# Re-reconciliate when zero values present
x=0 #Counter

# Loop until all positive
while(sum(hts.obj[[1]] <0) > 0){

  # Generate all time series
  hts.obj <- aggts(hts.obj)
  
  # Extract groups
  groups <- get_groups(hts.obj)
  
  # Overwrite negatives by zero
  hts.obj[hts.obj<0] <- 0
  
  # Reconcile
  hts.obj <- hts.obj %>%
    ts() %>%
    combinef(groups = groups, keep ="gts")
  
  # Count up
  x=x+1

  # Break after 10 loops
  if(x>=10)break

}

rm("x")

# Overwrite remaining negatives by zero
hts.obj[[1]][hts.obj[[1]]<0] <- 0

Its not super lean, but i hope it helps

Some code based on Rob's workaround of setting the negatives to zero and reconcile

# Re-reconciliate when zero values present
x=0 #Counter

# Loop until all positive
while(sum(hts.obj[[1]] <0) > 0){

  # Generate all time series
  hts.obj <- aggts(hts.obj)
  
  # Extract groups
  groups <- get_groups(hts.obj)
  
  # Overwrite negatives by zero
  hts.obj[hts.obj<0] <- 0
  
  # Reconcile
  hts.obj <- hts.obj %>%
    ts() %>%
    combinef(groups = groups, keep ="gts")
  
  # Count up
  x=x+1

  # Break after 10 loops
  if(x>=10)break

  }

rm("x")

# Overwrite remaining negatives by zero
hts.obj[[1]][hts.obj[[1]]<0] <- 0

In this example forecasts are indexed by [[1]] - this might change.

added 4 characters in body
Source Link
Loading
Source Link
Loading