[R] Using spline parameters to generate data
Spencer Graves
spencer.graves at pdf.com
Fri Aug 15 12:31:35 CEST 2003
1. Did you plot the data within subsets to evaluate the appropriateness
of any particular model?
2. Did you previously use "nls" to estimate parameters in the
exponential model to appropriate subsets of the data? If yes, did you
make various plots of residuals, e.g., vs. predicted to evaluate lack of
fit, normal probability plots (qqnorm) to evaluate the distribution of
residuals, and absolute values of residuals vs. predicted to evaluate
homogeniety of variance.
3. Only if residual plots suggest lack of fit would I abandon the
exponential model. Even then, I would be loath to embrace splines just
because they are too unconstrained and not tied to any theoretical model
of the phenomena of interest. What does available theory tell you about
possible functional forms for the model? If an exponential does not
hold in part of the regions of interest, what alternative functional
forms might be suggested by the available theory?
4. Have you also made qqplots, e.g., qqnorm, of parameters estimated
from model fits? My preference is to look for normality everywhere it
make physical sense in the application, to transform, e.g., with
logarithms or logits or probits or log(-log(yield)), where the transform
would more likely be normal [possibly adding a small constant or
multiplying by a number close to 1 to avoid taking logarithm of 0].
Then I use rnorm rather than runif.
hope this helps.
spencer graves
chumpmonkey3 at hushmail.com wrote:
> # 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:
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
More information about the R-help
mailing list