### Install nonlinearTseries package Source: https://github.com/constantino-garcia/nonlineartseries/blob/master/README.md Use these commands to install the package from CRAN or the development version from GitHub. ```r # You can install the he latest released version from CRAN: install.packages("nonlinearTseries") # Or the the development version from GitHub: devtools::install_github("constantino-garcia/nonlinearTseries") ``` -------------------------------- ### Construct Takens Vectors Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Builds delay embedding vectors for phase space reconstruction and visualizes the result. ```r # Build Takens vectors for phase space reconstruction takens <- buildTakens(ts.data, embedding.dim = emb.dim, time.lag = tau.ami) # Takens vectors stored as matrix (one vector per row) dim(takens) # Plot reconstructed phase space (first 3 dimensions) plot(takens[,1], takens[,2], type = "l", main = "Reconstructed Phase Space", xlab = "x(t)", ylab = "x(t + tau)") ``` -------------------------------- ### Phase Space Reconstruction Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Tools for estimating parameters required for Takens' embedding theorem. ```APIDOC ## timeLag(ts.data, technique, selection.method, lag.max, do.plot) ### Description Estimates an appropriate time lag for Takens' vectors using autocorrelation or average mutual information. ### Parameters - **ts.data** (vector) - Required - The input time series data. - **technique** (string) - Optional - 'acf' or 'ami'. - **selection.method** (string) - Optional - Method for selecting the lag (e.g., 'first.minimum'). - **lag.max** (integer) - Optional - Maximum lag to search. ## estimateEmbeddingDim(ts.data, ...) ### Description Determines the minimum embedding dimension using Cao's algorithm based on false nearest neighbors. ``` -------------------------------- ### Perform Recurrence Quantification Analysis (RQA) Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Quantifies recurrence patterns in phase space using the rqa function. Requires a time series and embedding parameters. ```r # Generate Rossler system data r <- rossler(time = seq(0, 10, by = 0.01), do.plot = FALSE) # Perform RQA rqa.result <- rqa(time.series = r$x, embedding.dim = 2, time.lag = 1, radius = 1.2, lmin = 2, vmin = 2, distanceToBorder = 2, save.RM = TRUE, do.plot = FALSE) # Access RQA measures cat("Recurrence Rate (REC):", rqa.result$REC, "\n") cat("Determinism (DET):", rqa.result$DET, "\n") cat("Laminarity (LAM):", rqa.result$LAM, "\n") cat("Longest diagonal (Lmax):", rqa.result$Lmax, "\n") cat("Mean diagonal length (Lmean):", rqa.result$Lmean, "\n") cat("Entropy (ENTR):", rqa.result$ENTR, "\n") cat("Trapping time (Vmean):", rqa.result$Vmean, "\n") cat("Trend:", rqa.result$TREND, "\n") # Plot recurrence plot (computationally expensive) plot(rqa.result) ``` -------------------------------- ### Generate Surrogate Data via Phase Randomization Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Creates surrogate time series using FFT-based phase randomization to preserve the power spectrum of the original data. ```r # Generate surrogate data sets original <- arima.sim(list(order = c(1, 0, 1), ar = 0.6, ma = 0.5), n = 500) surrogates <- FFTsurrogate(original, n.samples = 20) # Surrogates have same autocorrelation but randomized phases dim(surrogates) # 20 x 500 matrix # Compare original and surrogate par(mfrow = c(2, 1)) plot(original, type = "l", main = "Original") plot(surrogates[1,], type = "l", main = "Surrogate 1") par(mfrow = c(1, 1)) ``` -------------------------------- ### Generate Lorenz System Time Series Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Generate a 3D time series using Lorenz differential equations with default chaotic parameters. ```r library(nonlinearTseries) # Generate Lorenz system with default chaotic parameters lor <- lorenz(sigma = 10, rho = 28, beta = 8/3, start = c(-13, -14, 47), time = seq(0, 50, by = 0.01), do.plot = FALSE) # Access time series components head(lor$x) # x-component head(lor$y) # y-component head(lor$z) # z-component head(lor$time) # time vector # Plot the x-component time series plot(lor$time, lor$x, type = "l", xlab = "Time", ylab = "x(t)", main = "Lorenz System x-component") ``` -------------------------------- ### Compute Sample Entropy Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Calculates Kolmogorov-Sinai entropy to measure the complexity of a time series. ```r # First compute correlation sums h <- henon(n.sample = 15000, n.transient = 100, do.plot = FALSE) cd <- corrDim(time.series = h$x, min.embedding.dim = 2, max.embedding.dim = 9, time.lag = 1, min.radius = 0.05, max.radius = 1, n.points.radius = 100, theiler.window = 20, do.plot = FALSE) # Compute sample entropy from correlation sums se <- sampleEntropy(cd, do.plot = TRUE) # Estimate from plateau region se.est <- estimate(se, regression.range = c(0.4, 0.6), use.embeddings = 6:9, do.plot = TRUE) cat("Sample entropy estimates:", se.est, "\n") cat("Mean sample entropy:", mean(se.est), "\n") ``` -------------------------------- ### Test for Nonlinearity using Surrogate Data Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Tests the null hypothesis of a linear stochastic process by comparing original data statistics against surrogate data. ```r # Generate nonlinear data lor <- lorenz(do.plot = FALSE) # Perform surrogate data test using time asymmetry statistic sdt <- surrogateTest(time.series = lor$x, significance = 0.05, one.sided = FALSE, K = 5, FUN = timeAsymmetry, verbose = TRUE, do.plot = FALSE) # Plot comparison of original vs surrogate statistics plot(sdt) # Access results cat("Original data statistic:", sdt$data.statistic, "\n") cat("Surrogate statistics range:", range(sdt$surrogates.statistics), "\n") # If original statistic falls outside surrogate range, # reject null hypothesis -> data is nonlinear ``` -------------------------------- ### Generate Rössler System Time Series Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Generate a 3D continuous time series using the Rössler system. ```r # Generate Rossler system r <- rossler(a = 0.2, b = 0.2, w = 5.7, start = c(-2, -10, 0.2), time = seq(0, 100, by = 0.1), do.plot = FALSE) # Plot phase space projection plot(r$x, r$y, type = "l", main = "Rössler System Phase Space (x-y projection)", xlab = "x(t)", ylab = "y(t)") ``` -------------------------------- ### Compute Average Mutual Information (AMI) Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Calculates the AMI function to assist in determining the optimal time lag for phase space reconstruction. ```r # Generate sample data sx <- sinaiMap(a = 0.3, n.sample = 5000, start = c(0.23489, 0.8923), do.plot = FALSE)$x # Compute mutual information mutinf <- mutualInformation(sx, lag.max = 100, n.partitions = 20, units = "Bits", do.plot = TRUE) # Access AMI values head(mutinf$mutual.information) head(mutinf$time.lag) # Find first minimum for optimal time lag first.min <- which.min(mutinf$mutual.information[2:50]) + 1 cat("Suggested time lag:", first.min, "\n") ``` -------------------------------- ### Estimate Embedding Dimension Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Uses Cao's algorithm to determine the appropriate embedding dimension for phase space reconstruction. ```r emb.dim <- estimateEmbeddingDim(ts.data, time.lag = tau.ami, max.embedding.dim = 15, threshold = 0.95, do.plot = TRUE) cat("Estimated embedding dimension:", emb.dim, "\n") ``` -------------------------------- ### Generate Hénon Map Time Series Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Generate a 2D discrete time series using the Hénon map. ```r # Generate Henon map time series h <- henon(a = 1.4, b = 0.3, start = c(0.63954883, 0.04772637), n.sample = 5000, n.transient = 500, do.plot = FALSE) # Access the x and y coordinates plot(h$x, h$y, pch = ".", main = "Hénon Attractor", xlab = "x[n]", ylab = "y[n]") # The x-component can be used for time series analysis ts.plot(h$x[1:500], main = "Hénon x-coordinate") ``` -------------------------------- ### Compute Information Dimension Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Estimates the information dimension (D1) using the fixed-mass algorithm on Henon map data. ```r # Generate Henon map data for information dimension h <- henon(n.sample = 3000, n.transient = 100, do.plot = FALSE) # Compute information dimension id <- infDim(time.series = h$x, min.embedding.dim = 2, max.embedding.dim = 5, time.lag = 1, min.fixed.mass = 0.04, max.fixed.mass = 0.2, number.fixed.mass.points = 100, radius = 0.001, theiler.window = 10, do.plot = FALSE) # Plot and estimate plot(id, type = "l") id.est <- estimate(id, regression.range = c(0.05, 0.15), use.embeddings = 3:5, do.plot = TRUE) cat("Information dimension estimate:", id.est, "\n") ``` -------------------------------- ### Perform Detrended Fluctuation Analysis (DFA) Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Estimates the scaling exponent alpha to detect long-range correlations in time series data. ```r # Generate fractional Gaussian noise-like data set.seed(42) white.noise <- rnorm(5000) # Perform DFA dfa.result <- dfa(time.series = white.noise, window.size.range = c(10, 1000), npoints = 20, do.plot = FALSE) # Plot fluctuation function plot(dfa.result) # Estimate scaling exponent alpha <- estimate(dfa.result, regression.range = c(10, 1000), do.plot = TRUE) cat("DFA scaling exponent (alpha):", alpha, "\n") # Expected for white noise: approximately 0.5 # alpha < 0.5: anti-correlated # alpha = 0.5: uncorrelated (white noise) # alpha > 0.5: long-range correlated # alpha = 1.0: 1/f noise # alpha > 1.0: non-stationary ``` -------------------------------- ### Chaotic System Generators Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Functions to generate time series data from various chaotic dynamical systems. ```APIDOC ## lorenz(sigma, rho, beta, start, time, do.plot) ### Description Generates a 3-dimensional time series using the Lorenz differential equations. ### Parameters - **sigma** (numeric) - Optional - Lorenz parameter sigma. - **rho** (numeric) - Optional - Lorenz parameter rho. - **beta** (numeric) - Optional - Lorenz parameter beta. - **start** (vector) - Optional - Initial conditions c(x, y, z). - **time** (vector) - Optional - Time sequence. - **do.plot** (boolean) - Optional - Whether to plot the result. ## henon(a, b, start, n.sample, n.transient, do.plot) ### Description Generates a 2-dimensional discrete time series using the Hénon map. ### Parameters - **a** (numeric) - Optional - Hénon parameter a. - **b** (numeric) - Optional - Hénon parameter b. - **start** (vector) - Optional - Initial conditions c(x, y). - **n.sample** (integer) - Optional - Number of samples to generate. - **n.transient** (integer) - Optional - Number of transient points to discard. ## logisticMap(r, start, n.sample, n.transient, do.plot) ### Description Generates a 1-dimensional time series using the logistic map. ### Parameters - **r** (numeric) - Optional - Logistic map parameter r. - **start** (numeric) - Optional - Initial value. - **n.sample** (integer) - Optional - Number of samples. ``` -------------------------------- ### Generate Logistic Map Time Series Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Generate a 1D time series using the logistic map. ```r # Generate chaotic logistic map (r=4) lm <- logisticMap(r = 4, start = 0.1, n.sample = 1000, n.transient = 100, do.plot = FALSE) # Plot the time series plot(lm, type = "l", main = "Logistic Map (r=4)", xlab = "n", ylab = "x[n]") ``` -------------------------------- ### Compute Maximum Lyapunov Exponent Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Measures the rate of divergence of nearby trajectories to identify chaotic behavior. ```r # Compute divergence of nearby trajectories ml <- maxLyapunov(time.series = ts.data, sampling.period = 0.01, min.embedding.dim = 4, max.embedding.dim = 7, time.lag = tau.ami, radius = 1, theiler.window = 50, min.neighs = 5, min.ref.points = 500, max.time.steps = 1000, do.plot = FALSE) # Plot S(t) function showing exponential divergence plot(ml, type = "l", xlim = c(0, 8)) # Estimate Lyapunov exponent from linear region ml.est <- estimate(ml, regression.range = c(0, 3), use.embeddings = 5:7, do.plot = TRUE) cat("Maximum Lyapunov exponent:", ml.est, "\n") # Positive value indicates chaos if (ml.est > 0) { cat("System exhibits chaotic behavior\n") } ``` -------------------------------- ### Estimate Time Lag Parameter Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Estimate the time lag for Takens' vectors using autocorrelation or average mutual information. ```r # Generate sample data lor <- lorenz(do.plot = FALSE) ts.data <- lor$x # Estimate time lag using autocorrelation function tau.acf <- timeLag(ts.data, technique = "acf", selection.method = "first.e.decay", lag.max = 100, do.plot = TRUE) cat("Time lag (ACF):", tau.acf, "\n") # Estimate time lag using average mutual information (preferred) tau.ami <- timeLag(ts.data, technique = "ami", selection.method = "first.minimum", lag.max = 100, do.plot = TRUE) cat("Time lag (AMI):", tau.ami, "\n") ``` -------------------------------- ### Compute Correlation Dimension Source: https://context7.com/constantino-garcia/nonlineartseries/llms.txt Estimates the fractal dimension using the Grassberger-Procaccia algorithm. ```r # Compute correlation sums for multiple embedding dimensions cd <- corrDim(time.series = ts.data, min.embedding.dim = 4, max.embedding.dim = 9, time.lag = tau.ami, min.radius = 0.001, max.radius = 50, n.points.radius = 40, theiler.window = 100, do.plot = FALSE) # Plot correlation sums with local scaling exponents plot(cd) # Estimate correlation dimension from linear scaling region cd.est <- estimate(cd, regression.range = c(0.75, 3), use.embeddings = 5:7, do.plot = TRUE) cat("Correlation dimension estimate:", cd.est, "\n") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.