chumpmonkey3@hushmail.com
2003-Aug-14 22:25 UTC
[R] Using spline parameters to generate data
# I need to generate some data. I'm modeling some time series that follow a # negative exponential decay (mostly). I have 20 samples that can easily be fit with cubic splines. # What I want to do is generate many thousands of similar samples using the parameters from the splines # For instance one data sample looks not unlike this: foo.curve <- 1 * exp(-0.01 * 1:500) + 0.5 ts.plot(foo.curve, lwd = 2) # Another sample looks not unlike this: foo.curve2 <- 0.9 * exp(-0.02 * 1:500) + 0.5 ts.plot(foo.curve2, lwd = 2) # They can be fit with splines easily like so: ts.plot(foo.curve, lwd = 2) spline.model <- smooth.spline(foo.curve) fits4foo <- predict(spline.model)$y spline4foo <- spline(1:500, fits4foo) lines(spline4foo$x, spline4foo$y, col = "red", lwd = 2, lty = "dashed") # I originally generated the data I needed by using a nls model and # adding some noise to the mean of the coefficents from those fits. # However, I've been told to try and do this using splines for arcane reasons. # So, if you had 20 splines like spline.model above and wanted to generate some similar data what would you do? # Thanks in advance. Promote security and make money with the Hushmail Affiliate Program:
Have you considered adding noise to "predict(spline.model)$y"? If this won't solve your problem, then I think I don't understand what you want to do. spencer graves chumpmonkey3 at hushmail.com wrote:> # I need to generate some data. I'm modeling some time series that follow > a > # negative exponential decay (mostly). I have 20 samples that can easily > be fit with cubic splines. > # What I want to do is generate many thousands of similar samples using > the parameters from the splines > > # For instance one data sample looks not unlike this: > foo.curve <- 1 * exp(-0.01 * 1:500) + 0.5 > ts.plot(foo.curve, lwd = 2) > > # Another sample looks not unlike this: > foo.curve2 <- 0.9 * exp(-0.02 * 1:500) + 0.5 > ts.plot(foo.curve2, lwd = 2) > > > > # They can be fit with splines easily like so: > > ts.plot(foo.curve, lwd = 2) > spline.model <- smooth.spline(foo.curve) > > fits4foo <- predict(spline.model)$y > spline4foo <- spline(1:500, fits4foo) > lines(spline4foo$x, spline4foo$y, col = "red", lwd = 2, lty = "dashed") > > # I originally generated the data I needed by using a nls model and > # adding some noise to the mean of the coefficents from those fits. > # However, I've been told to try and do this using splines for arcane > reasons. > > # So, if you had 20 splines like spline.model above and wanted to generate > some similar data what would you do? > # Thanks in advance. > > > > > > > > > > Promote security and make money with the Hushmail Affiliate Program: > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
chumpmonkey3@hushmail.com
2003-Aug-15 03:21 UTC
[R] Using spline parameters to generate data
# Sorry for the confussion. # The way I had originally generated the data was # sort of like this (cut and paste the code below a few times): foo.curve <- runif(1,0.8,1.2) * exp(runif(1,-0.015,-0.005) * 1:500) + runif(1,0.25,0.75) ts.plot(foo.curve, lwd = 2) # where the min and max values in runif() were mined from the data using nls. # Are there similar ways to manipulate the smooth spline parameters to give that kind of data? # I still need a smooth line but would like the nugget, sill and range to change # (to borrow terms from semivariance) On Thu, 14 Aug 2003 17:46:28 -0700 Spencer Graves <spencer.graves at PDF.COM> wrote:>Have you considered adding noise to "predict(spline.model)$y"? If >this >won't solve your problem, then I think I don't understand what you >want >to do. > >spencer graves > >chumpmonkey3 at hushmail.com wrote: >> # I need to generate some data. I'm modeling some time series >that follow >> a >> # negative exponential decay (mostly). I have 20 samples that >can easily >> be fit with cubic splines. >> # What I want to do is generate many thousands of similar samples >using >> the parameters from the splines >> >> # For instance one data sample looks not unlike this: >> foo.curve <- 1 * exp(-0.01 * 1:500) + 0.5 >> ts.plot(foo.curve, lwd = 2) >> >> # Another sample looks not unlike this: >> foo.curve2 <- 0.9 * exp(-0.02 * 1:500) + 0.5 >> ts.plot(foo.curve2, lwd = 2) >> >> >> >> # They can be fit with splines easily like so: >> >> ts.plot(foo.curve, lwd = 2) >> spline.model <- smooth.spline(foo.curve) >> >> fits4foo <- predict(spline.model)$y >> spline4foo <- spline(1:500, fits4foo) >> lines(spline4foo$x, spline4foo$y, col = "red", lwd = 2, lty >"dashed") >> >> # I originally generated the data I needed by using a nls model >and >> # adding some noise to the mean of the coefficents from those >fits. >> # However, I've been told to try and do this using splines for >arcane >> reasons. >> >> # So, if you had 20 splines like spline.model above and wanted >to generate >> some similar data what would you do? >> # Thanks in advance. >> >> >> >> >> >> >> >> >> >> Promote security and make money with the Hushmail Affiliate Program: >> >> ______________________________________________ >> R-help at stat.math.ethz.ch mailing list >> https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > > >Promote security and make money with the Hushmail Affiliate Program: