tsgen | R Documentation |
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.
tsgen(ttype, ytype, pf, redpart, s.outlier.fraction = 0, interval, npoints, ncycles, ps, SNR, alpha = 1.5)
ttype |
character string: Specifying the sampling pattern. Possible choices are |
ytype |
character string: Specifying the shape of the periodic fluctuation with period pf. Possible choices are |
pf |
positive number: Period pf of the periodic fluctuation, argument of |
redpart |
numeric value in [0,1]: Proportion of the power law noise in noise components (see Details). The generated measurement accuracies s[i] do not contain information about this noise component. |
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 n for the generated light curve. |
ncycles |
integer value: number ns of sampling cycles that is observed (see Details). |
ps |
positive number: Sampling period ps, influencing the sampling and how the light curve is disturbed (see Details and |
SNR |
positive number: Defines the relation between signal yf and noise yw+yr (see Details). |
alpha |
numeric value: Power law index α for the power law noise component yr (see Details). |
tsgen
generates an artificial light curve consisting of observation times t[1],…,t[n], observation values y[1],…,y[n] and measurement accuracies s[1],…,s[n]. It calls several subfunctions (see there for details):
sampler
is used to sample observation times t[1],…,t[n] in the interval 0,ncycles*ps with a possibly periodic sampling of period ps.
signalgen
generates periodically varying values yf[1],…,yf[n] at time points t[1],…,t[n] with fluctuation period pf.
lc_noise
samples measurement accuracies s[1],…,s[n]
from a Gamma(3,10)-distribution and a white noise component
yw[1],…,yw[n] with from N(0,s[i]^2) distributions. A second noise component yr[1],…,yr[n] does not depend on the s[i]. It is generated as red noise, i.e. following a power law with power law index α. For white noise choose α=0, for flicker noise (pink noise) α=1, for brown noise α=2. The power law noise is generated using TK95_uneq
and TK95
. The noise components are scaled so that the variance of the yr[i] has approximately the proportion redpart
in the overall noise variance and that SNR
is the ratio var(yf)/var(yw+yr). The observed values are set to y[i]=yf[i]+yw[i]+yr[i].
disturber
disturbes the light curve replacing measurement accuracies
s[i] by outliers (if s.outlier.fraction>0
) and observed values
y[i] by atypical values (if interval=TRUE
).
In case of s.outlier.fraction=0
and interval=FALSE
, the function returns all values unchanged.
tt |
numeric vector: Generated observation times\ t_1,…,t_n. |
y |
numeric vector: Generated observation values\ y_1,…,y_n. |
s |
numeric vector: Generated measurement accuracies\ s_1,…,s_n. |
Note that the white noise components' variances are exactly s[i]^2, so the s[i] 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.
Anita M. Thieler and Jonathan Rathjens
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>
Applies sampler
, signalgen
, lc_noise
, disturber
, TK95
, TK95_uneq
.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.