tsgen {RobPer} | R Documentation |
Artificial light curve generator
Description
This function generates light curves (special time series) with unequally sampled observation times, different periodicities both in sampling and observed values, with white and power law (red) noise in the observed values and possibly disturbed observations.
See RobPer-package
for more information about light curves and also Thieler, Fried and Rathjens (2016) for more details in general.
Usage
tsgen(ttype, ytype, pf, redpart, s.outlier.fraction = 0, interval, npoints,
ncycles, ps, SNR, alpha = 1.5)
Arguments
ttype |
character string: Specifying the sampling pattern. Possible choices are |
ytype |
character string: Specifying the shape of the periodic fluctuation with period |
pf |
positive number: Period |
redpart |
numeric value in [0,1]: Proportion of the power law noise in noise components (see Details). The generated measurement accuracies |
s.outlier.fraction |
numeric value in [0,1]: Fraction of measurement accuracies to be replaced by outliers. A value of 0 means that no measurement accuracy is replaced by an outlier (for more details see |
interval |
logical: If |
npoints |
integer value: Defines the sample size |
ncycles |
integer value: number |
ps |
positive number: Sampling period |
SNR |
positive number: Defines the relation between signal |
alpha |
numeric value: Power law index |
Details
tsgen
generates an artificial light curve consisting of observation times , observation values
and measurement accuracies
. It calls several subfunctions (see there for details):
sampler
is used to sample observation times in the interval
with a possibly periodic sampling of period
.
signalgen
generates periodically varying values at time points
with fluctuation period
.
lc_noise
samples measurement accuracies
from a Gamma(3,10)-distribution and a white noise component
with from
distributions. A second noise component
does not depend on the
. It is generated as red noise, i.e. following a power law with power law index
. For white noise choose
, for flicker noise (pink noise)
, for brown noise
. The power law noise is generated using
TK95_uneq
and TK95
. The noise components are scaled so that the variance of the has approximately the proportion
redpart
in the overall noise variance and that SNR
is the ratio . The observed values are set to
.
disturber
disturbes the light curve replacing measurement accuracies
by outliers (if
s.outlier.fraction>0
) and observed values
by atypical values (if
interval=TRUE
).
In case of s.outlier.fraction=0
and interval=FALSE
, the function returns all values unchanged.
Value
tt |
numeric vector: Generated observation times |
y |
numeric vector: Generated observation values |
s |
numeric vector: Generated measurement accuracies |
Note
Note that the white noise components' variances are exactly , so the
are no estimates, but true values. In this sense, the measurement accuracies of a generated light curve are more informative than for real light curves, where the measurement accuracies are estimates, see Thieler et al. (2013), where also a former version of this function is applied.
To lower the informativity of the measurement accuracies, set redpart
to a strictly positive value, possibly with alpha=0
if no other noise components than white ones are required.
Author(s)
Anita M. Thieler and Jonathan Rathjens
References
Thieler, A. M., Backes, M., Fried, R. and Rhode, W. (2013): Periodicity Detection in Irregularly Sampled Light Curves by Robust Regression and Outlier Detection. Statistical Analysis and Data Mining, 6 (1), 73-89
Thieler, A. M., Fried, R. and Rathjens, J. (2016): RobPer: An R Package to Calculate Periodograms for Light Curves Based on Robust Regression. Journal of Statistical Software, 69 (9), 1-36, <doi:10.18637/jss.v069.i09>
See Also
Applies sampler
, signalgen
, lc_noise
, disturber
, TK95
, TK95_uneq
.
Examples
# Generate a light curve:
set.seed(22)
lightcurve<- tsgen(ttype="sine", ytype="peak" , pf=7, redpart=0.1, s.outlier.fraction=0,
interval=FALSE, npoints=200, ncycles=100, ps=5, SNR=3, alpha=0)
# Or do it step by step:
# First sampling observation times:
set.seed(22)
tt <- sampler(ttype="sine", npoints=200, ncycles=100, ps=5)
# show obviously irregular observation times as grey vertical bars on a red time line:
plot(tt, tt*0, type="n", axes=FALSE, xlab="Observation Times", ylab="")
abline(v=tt, col="grey")
axis(1, pos=0, col="red", col.axis="red")
# Sampling period is 5, look at observation times modulo 10:
hist(tt%%5, xlab="Observation time modulo 5",
main="Sine Distribution for the phase (tt modulo 5)", freq=FALSE)
dsin <- function(tt) 0.2*(sin(2*pi*tt/5)+1)
curve(dsin, add=TRUE)
# Then generate periodic fluctuation
yf <- signalgen(tt, ytype="peak", pf=7)
plot(tt, yf, xlab="Observation Times", ylab="Periodic Fluctuation")
plot(tt%%7, yf, main="Phase Diagram (time modulo 7)",
xlab="Observation time modulo 7", ylab="Periodic Fluctuation")
# Add noise and scale signal to the right SNR
temp <- lc_noise(tt,sig=yf, SNR=3, redpart=0.1, alpha=0)
y <- temp$y
s <- temp$s
# Plotting the light curve (vertical bars show measurement accuracies)
plot(tt, y, pch=16, cex=0.5, xlab="t", ylab="y", main="a Light Curve")
rect(tt, y+s, tt, y-s)
# The lightcurve has period 7:
plot(tt%%7, y, pch=16, cex=0.5, xlab="t", ylab="y",
main="Phase Diagram of a Light Curve")
rect(tt%%7, y+s, tt%%7, y-s)
# replace measurement accuracies by tiny outliers or include a peak
temp <- disturber(tt,y,s,ps=5, s.outlier.fraction=0, interval=FALSE)
# Phase diagram (observation times modulo 10)
plot(tt%%7, temp$y, pch=16, cex=0.5, xlab="t", ylab="y",
main="Phase Diagram of a Light Curve")
rect(tt%%7, temp$y+temp$s, tt%%7, temp$y-temp$s)
# The result is the same:
all(cbind(tt,temp$y,temp$s)==lightcurve)