-2

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.

Bella_18
  • 624
  • 1
  • 14
  • 1
    Can you make your post [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) by providing your data using `dput()` and any code you've tried so far? – jrcalabrese Dec 11 '22 at 16:23

1 Answers1

1

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
M.Viking
  • 5,067
  • 4
  • 17
  • 33
  • Thanks @M.Viking I will try that on my data – Bella_18 Dec 11 '22 at 16:30
  • If I increase the percentage to 25% then the pattern might be lost? – Bella_18 Dec 11 '22 at 16:31
  • 1
    I suspect the pattern might be lost. Depends on your data and the width between ranks. Using a normal distribution `rnorm()` instead of a uniform might help, visualized example `hist(rnorm(1000, sd=0.05))`. I think the key word you want is similar to "maintain rank", I don't see an R package with that explicit feature. Perhaps we could add noise, then check if the order is maintained. – M.Viking Dec 11 '22 at 16:45