# NOT RUN {
########## Fitting a univariate damped random walk process
##### Fitting a univariate damped random walk process based on a simulation
n1 <- 20
# the number of observations in the data set
obs.time1 <- cumsum(rgamma(n1, shape = 3, rate = 1))
# the irregularly-spaced observation times
y1 <- rnorm(n1)
# the measurements/observations/magnitudes
measure.error.SD1 <- rgamma(n1, shape = 0.01)
# optional measurement error standard deviations,
# which is typically known in astronomical time series data
# if not known in other applications, set them to zeros, i.e.,
# measure.error.SD1 <- rep(0, n1)
data1 <- cbind(obs.time1, y1, measure.error.SD1)
# combine the single time series data set into an n by 3 matrix
# Note that when astronomical time series data are loaded on R (e.g., read.table, read.csv),
# the digits of the observation times are typically rounded to seven effective digits.
# That means rounding may occur, which produces ties in observation times even though
# the original observation times are not the same.
# In this case, type the following code before loading the data.
# options(digits = 11)
res1.mle <- drw(data1 = data1, n.datasets = 1, method = "mle")
# obtain maximum likelihood estimates of the model parameters and
# assign the result to object "res1.mle"
names(res1.mle)
# to see the maximum likelihood estimates,
# type "res1.mle$mu", "res1.mle$sigma", "res1.mle$tau"
# }
# NOT RUN {
res1.bayes <- drw(data1 = data1, n.datasets = 1, method = "bayes",
bayes.n.burn = 10, bayes.n.sample = 10)
# }
# NOT RUN {
# obtain 10 posterior samples of each model parameter and
# save the result to object "res1.bayes"
# names(res1.bayes)
# to work on the posterior sample of each parameter, try
# "res1.bayes$mu.accept.rate", "res1.bayes$sigma.accept.rate", "res1.bayes$tau.accept.rate"
# "hist(res1.bayes$mu)", "mean(res1.bayes$mu)", "sd(res1.bayes$mu)",
# "median(log(res1.bayes$sigma, base = 10))",
# "quantile(log(res1.bayes$tau, base = 10), prob = c(0.025, 0.975))"
##### Fitting a multivariate damped random walk process based on simulations
n2 <- 10
# the number of observations in the second data set
obs.time2 <- cumsum(rgamma(n2, shape = 3, rate = 1))
# the irregularly-spaced observation times of the second data set
y2 <- rnorm(n2)
# the measurements/observations/magnitudes of the second data set
measure.error.SD2 <- rgamma(n2, shape = 0.01)
# optional measurement error standard deviations of the second data set,
# which is typically known in astronomical time series data
# if not known in other applications, set them to zeros, i.e.,
# measure.error.SD2 <- rep(0, n2)
data2 <- cbind(obs.time2, y2, measure.error.SD2)
# combine the single time series data set into an n by 3 matrix
# }
# NOT RUN {
res2.mle <- drw(data1 = data1, data2 = data2, n.datasets = 2, method = "mle")
# }
# NOT RUN {
# obtain maximum likelihood estimates of the model parameters and
# assign the result to object "res2.mle"
# }
# NOT RUN {
res2.bayes <- drw(data1 = data1, data2 = data2, n.datasets = 2, method = "bayes",
bayes.n.burn = 10, bayes.n.sample = 10)
# }
# NOT RUN {
# obtain 10 posterior samples of each model parameter and
# save the result to object "res2.bayes"
# names(res2.bayes)
# to work on the posterior sample of each parameter, try
# "hist(res2.bayes$mu[, 1])", "colMeans(res2.bayes$mu)", "apply(res2.bayes$mu, 2, sd)",
# "hist(log(res2.bayes$sigma[, 2], base = 10))",
# "apply(log(res2.bayes$sigma, base = 10), 2, median)",
# "apply(log(res2.bayes$tau, base = 10), 2, quantile, prob = c(0.025, 0.975))"
# }
Run the code above in your browser using DataLab