rdataframenoise

add noise to the data without compromising the data pattern


I have a time series data

I want to create a dummy data from the original time series data by adding some noise.

How can i do that without compromising the data pattern (example: I have Mondays high value in my time series) - even after adding the noise I want to have high values on mondays.


Solution

  • I would multiply by a small amount of random uniform (runif()) amount or random normal (rnorm()) noise. For example, multiplying by a random +-5% of the value, or standard deviation 0.05.

    df <- data.frame(x=1:10)
    set.seed(2022)
    df$y <- df$x * (1 + runif(n=10, min=-0.05, max=0.05))
    df$z <- df$x * (1 + rnorm(n=10, sd=0.05)) 
    
    > df
        x         y
    1   1  1.031598
    2   2  2.029452
    3   3  2.886099
    4   4  4.017520
    5   5  4.842365
    6   6  6.081475
    7   7  6.702009
    8   8  7.633581
    9   9  8.883285
    10 10 10.257253