# NOT RUN {
## Note:
#### The example below uses a simpler synthetic data, a wider bin-width
#### and a shorter MCMC run to keep the run length less than 5s
#### Use ?plot.dapp or ?plot.summary for a more realistic example
## Generate 30 A and 30 B trials with rate functions
## lambda.A(t) = 160*exp(-2*t/1000) + 40*exp(-0.2*t/1000)
## lambda.B(t) = 40*exp(-2*t/1000)
## where time t is measured in ms. Then, generate 25 AB trials,
## roughly 2/3 with flat weight curves with a constant intensity
## either close to A, or close to B (equally likely). The
## remaining 1/3 curves are sinusoidal that snake between 0.01 and 0.99
## with a period randomly drawn between 400 and 1000
ntrials <- c(nA=30, nB=30, nAB=25)
flat.range <- list(A=c(0.85, 0.95),
B=c(0.05, 0.15))
flat.mix <- c(A=1/2, B=1/2)
wavy.span <- c(0.01, 0.99)
wavy.period <- c(400, 1000)
T.horiz <- 1000
rateB <- 40 * exp(-2*(1:T.horiz)/T.horiz)
rateA <- 4*rateB + 40 * exp(-0.2*(1:T.horiz)/T.horiz)
synth.data <- synthesis.dapp(ntrials = ntrials, pr.flat = 2/3,
intervals = flat.range, wts = flat.mix,
span = wavy.span, period.range = wavy.period,
lambda.A=rateA, lambda.B=rateB)
## Generate binned spike counts witb 100 ms bins
spike.counts <- mplex.preprocess(synth.data$spiketimes, bw=100, visualize=FALSE)
## Fit the DAPP model to data
#### A short MCMC run is done below to keep the run length short.
#### Use default or larger values for burn, nsamp and thin
#### for more reliable estimation
fit.post <- dapp(spike.counts, burn=10, nsamp=90, thin=1, verbose=FALSE)
## Visualize model fit
plot(fit.post)
## Post process results to assign second order stochasticity labels
summary(fit.post)
# }
Run the code above in your browser using DataLab