Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

Is there a R function for reversing ad-stocked values, or converting ad-stock transformed values to its pre-transformed state?

$
0
0

I have a vector of numeric values (a time series) where I know that an ad-stock carry-over transformation of 20% is applied to it. For instance,

  • X1, X2, X3, … Xn (Pre-transformed time series)
  • P1, P2, P3, … Pn (Ad-stock transformed time series),

where...

  • P1 = X1
  • P2 = P1 * 0.2 + X2
  • P3 = P2 * 0.2 + X3
  • PN = P(n-1) * 0.2 + Xn [the subscripts are a bit off, but hope it's obvious here]

The original adstock effect is applied using a function similar to the below:


    ## Function for calculating adstock
    #'
    #' @param x Numeric vector to be passed through. 
    #' @param rate Decay rate to be applied to `x`
    #' @export
    adstock <- function(x, rate = 0){
      x %>%
        stats::filter(filter = rate, method = "recursive") %>%
        as.numeric() %>% return()
    }

My question is. Assuming I only have the P-series above (i.e. the time series where ad-stock has ALREADY been applied), is there a R function that lets me get back to the X-series (pre-transformed time series)?

Thank you so much!


Viewing all articles
Browse latest Browse all 201945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>