fNonlinear/ 0000755 0001762 0000144 00000000000 13203405404 012340 5 ustar ligges users fNonlinear/inst/ 0000755 0001762 0000144 00000000000 13201353171 013316 5 ustar ligges users fNonlinear/inst/COPYRIGHT.html 0000644 0001762 0000144 00000020411 11645005112 015551 0 ustar ligges users
Rmetrics::COPYRIGHT
Rmetrics
Copyrights
2005-12-18 Built 221.10065
________________________________________________________________________________
Copyrights (C) for
R:
see R's copyright and license file
Version R 2.0.0 claims:
- The stub packages from 1.9.x have been removed.
- All the datasets formerly in packages 'base' and 'stats' have
been moved to a new package 'datasets'.
- Package 'graphics' has been split into 'grDevices' (the graphics
devices shared between base and grid graphics) and 'graphics'
(base graphics).
- Packages must have been re-installed for this version, and
library() will enforce this.
- Package names must now be given exactly in library() and
require(), regardless of whether the underlying file system is
case-sensitive or not.
________________________________________________________________________________
for
Rmetrics:
(C) 1999-2005, Diethelm Wuertz, GPL
Diethelm Wuertz
www.rmetrics.org
info@rmetrics.org
________________________________________________________________________________
for non default loaded basic packages part of R's basic distribution
MASS:
Main Package of Venables and Ripley's MASS.
We assume that MASS is available.
Package 'lqs' has been returned to 'MASS'.
S original by Venables & Ripley.
R port by Brian Ripley .
Earlier work by Kurt Hornik and Albrecht Gebhardt.
methods:
Formally defined methods and classes for R objects, plus other
programming tools, as described in the reference "Programming
with Data" (1998), John M. Chambers, Springer NY.
R Development Core Team.
mgcv:
Routines for GAMs and other generalized ridge regression
with multiple smoothing parameter selection by GCV or UBRE.
Also GAMMs by REML or PQL. Includes a gam() function.
Simon Wood
nnet:
Feed-forward Neural Networks and Multinomial Log-Linear Models
Original by Venables & Ripley.
R port by Brian Ripley .
Earlier work by Kurt Hornik and Albrecht Gebhardt.
________________________________________________________________________________
for the code partly included as builtin functions from other R ports:
fBasics:CDHSC.F
GRASS program for distributional testing.
By James Darrell McCauley
Original Fortran Source by Paul Johnson EZ006244@ALCOR.UCDAVIS.EDU>
fBasics:nortest
Five omnibus tests for the composite hypothesis of normality
R-port by Juergen Gross
fBasics:SYMSTB.F
Fast numerical approximation to the Symmetric Stable distribution
and density functions.
By Hu McCulloch
fBasics:tseries
Functions for time series analysis and computational finance.
Compiled by Adrian Trapletti
fCalendar:date
The tiny C program from Terry Therneau is used
R port by Th. Lumley ,
K. Halvorsen , and
Kurt Hornik
fCalendar:holidays
The holiday information was collected from the internet and
governmental sources obtained from a few dozens of websites
fCalendar:libical
Libical is an Open Source implementation of the IETF's
iCalendar Calendaring and Scheduling protocols. (RFC 2445, 2446,
and 2447). It parses iCal components and provides a C API for
manipulating the component properties, parameters, and subcomponents.
fCalendar:vtimezone
Olsen's VTIMEZONE database consists of data files are released under
the GNU General Public License, in keeping with the license options of
libical.
fSeries:bdstest.c
C Program to compute the BDS Test.
Blake LeBaron
fSeries:fracdiff
R functions, help pages and the Fortran Code for the 'fracdiff'
function are included.
S original by Chris Fraley
R-port by Fritz Leisch
since 2003-12: Martin Maechler
fSeries:lmtest
R functions and help pages for the linear modelling tests are included .
Compiled by Torsten Hothorn ,
Achim Zeileis , and
David Mitchell
fSeries:mda
R functions, help pages and the Fortran Code for the 'mars' function
are implemeted.
S original by Trevor Hastie & Robert Tibshirani,
R port by Friedrich Leisch, Kurt Hornik and Brian D. Ripley
fSeries:modreg
Brian Ripley and the R Core Team
fSeries:polspline
R functions, help pages and the C/Fortran Code for the 'polymars'
function are implemented
Charles Kooperberg
fSeries:systemfit
Simultaneous Equation Estimation Package.
R port by Jeff D. Hamann and
Arne Henningsen
fSeries:tseries
Functions for time series analysis and computational finance.
Compiled by Adrian Trapletti
fSeries:UnitrootDistribution:
The program uses the Fortran routine and the tables
from J.G. McKinnon.
fSeries:urca
Unit root and cointegration tests for time series data.
R port by Bernhard Pfaff .
fExtremes:evd
Functions for extreme value distributions.
R port by Alec Stephenson
Function 'fbvpot' by Chris Ferro.
fExtremes:evir
Extreme Values in R
Original S functions (EVIS) by Alexander McNeil
R port by Alec Stephenson
fExtremes:ismev
An Introduction to Statistical Modeling of Extreme Values
Original S functions by Stuart Coles
R port/documentation by Alec Stephenson
fOptions
Option Pricing formulas are implemented along the book and
the Excel spreadsheets of E.G. Haug, "The Complete Guide to Option
Pricing"; documentation is partly taken from www.derivicom.com which
implements a C Library based on Haug. For non-academic and commercial
use we recommend the professional software from "www.derivicom.com".
fOptions:SOBOL.F
ACM Algorithm 659 by P. Bratley and B.L. Fox
Extension on Algorithm 659 by S. Joe and F.Y. Kuo
fOptions:CGAMA.F
Complex gamma and related functions.
Fortran routines by Jianming Jin.
fOptions:CONHYP.F
Confluenet Hypergeometric and related functions.
ACM Algorithm 707 by mark Nardin, W.F. Perger, A. Bhalla
fPortfolio:mvtnorm
Multivariate Normal and T Distribution.
Alan Genz ,
Frank Bretz
R port by Torsten Hothorn
fPortfolio:quadprog
Functions to solve Quadratic Programming Problems.
S original by Berwin A. Turlach
R port by Andreas Weingessel
fPortfolio:sn
The skew-normal and skew-t distributions.
R port by Adelchi Azzalini
fPortfolio:tseries
Functions for time series analysis and computational finance.
Compiled by Adrian Trapletti
fNonlinear/inst/unitTests/ 0000755 0001762 0000144 00000000000 13201353171 015320 5 ustar ligges users fNonlinear/inst/unitTests/Makefile 0000644 0001762 0000144 00000000423 13203345304 016760 0 ustar ligges users PKG=fNonlinear
TOP=../..
SUITE=doRUnit.R
R=R
all: inst test
inst: # Install package -- but where ?? -- will that be in R_LIBS ?
cd ${TOP}/..;\
${R} CMD INSTALL ${PKG}
test: # Run unit tests
export RCMDCHECK=FALSE;\
cd ${TOP}/tests;\
${R} --vanilla --slave < ${SUITE}
fNonlinear/inst/unitTests/runit.NonLinModelling.R 0000644 0001762 0000144 00000014277 11645005112 021645 0 ustar ligges users
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General
# Public License along with this library; if not, write to the
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
# Copyrights (C)
# for this R-port:
# 1999 - 2007, Diethelm Wuertz, GPL
# Diethelm Wuertz
# info@rmetrics.org
# www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
# see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
# see Rmetrics's copyright file
################################################################################
# FUNCTION: CHAOTIC TIME SERIES MAPS:
# tentSim Simulates series from Tent map
# henonSim Simulates series from Henon map
# ikedaSim Simulates series from Ikeda map
# logisticSim Simulates series from Logistic map
# lorentzSim Simulates series from Lorentz map
# roesslerSim Simulates series from Roessler map
# FUNCTION: PHASE SPACE REPRESENTATION:
# mutualPlot Creates mutual information plot
# fnnPlot Creates false nearest neigbours plot
# FUNCTION: NON STATIONARITY PLOTS:
# recurrencePlot Creates recurrence plot
# separationPlot Creates space-time separation plot
# FUNCTION: LYAPUNOV EXPONENTS:
# lyapunovPlot Maximum Lyapunov plot
################################################################################
test.tentSim =
function()
{
# tentSim - Simulates series from Tent map
# Tent Map:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
par (mfrow = c(1, 1))
ts = tentSim(n = 1000, n.skip = 100, parms = c(a = 2), start = runif(1),
doplot = TRUE)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.henonSim =
function()
{
# henonSim - Simulates series from Henon map
# Henon Map - 2D:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
par (mfrow = c(1, 1))
ts = henonSim(n = 1000, n.skip = 100, parms = c(a = 1.4, b = 0.3),
start = runif(2), doplot = TRUE)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.ikedaSim =
function()
{
# ikedaSim - Simulates series from Ikeda map
# Ikeda Map - 2D:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
par (mfrow = c(2, 2))
ts = ikedaSim(n = 1000, n.skip = 100, parms = c(a = 0.4, b = 6, c = 0.9),
start = runif(2), doplot = TRUE)
head(ts)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.logisticSim =
function()
{
# logisticSim - Simulates series from Logistic map
# lorentzSim - Simulates series from Lorentz map
# roesslerSim - Simulates series from Roessler map
# Logistic Map:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
par (mfrow = c(1, 1))
logisticSim(n = 1000, n.skip = 100, parms = c(r = 4), start = runif(1),
doplot = TRUE)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.lorentzSim =
function()
{
# lorentzSim - Simulates series from Lorentz map
# Lorentz Map:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
par (mfrow = c(3, 2))
ts = lorentzSim(times = seq(0, 20, by = 0.01), parms = c(sigma = 16,
r = 45.92, b = 4), start = c(-14, -13, 47), doplot = TRUE)
head(ts)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.roesslerSim =
function()
{
# roesslerSim - Simulates series from Roessler map
# Roessler Map:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
par (mfrow = c(3, 2))
ts = roesslerSim(times = seq(0, 80, by = 0.05), parms = c(a = 0.2,
b = 0.2, c = 8), start = c(-1.894, -9.92, 0.025), doplot = TRUE)
head(ts)
# Return Value:
return()
}
################################################################################
test.henonSlider =
function()
{
# Henon Slider:
henonSlider = function()
{
refresh.code = function(...)
{
# Sliders:
N = .sliderMenu(no = 1)
a = .sliderMenu(no = 2)
b = .sliderMenu(no = 3)
# Plot Henon Map:
ts = henonSim(n = N, n.skip = 100, parms = c(a = a, b = b),
start = c(pi/4, exp(1)/4), doplot = TRUE)
# Frame:
par(mfrow = c(1, 1), cex = 0.7)
}
# Open Slider Menu:
.sliderMenu(refresh.code,
names = c( "N", "a", "b"),
minima = c( 100, 1.00, 0.00),
maxima = c(5000, 2.00, 1.00),
resolutions = c( 100, 0.01, 0.01),
starts = c(2000, 1.40, 0.30))
}
# Try:
# henonSlider()
# Return Value:
return()
}
################################################################################
fNonlinear/inst/unitTests/runit.Gallery.R 0000644 0001762 0000144 00000005154 11645005112 020206 0 ustar ligges users
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General
# Public License along with this library; if not, write to the
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
# Copyrights (C)
# for this R-port:
# 1999 - 2007, Diethelm Wuertz, GPL
# Diethelm Wuertz
# info@rmetrics.org
# www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
# see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
# see Rmetrics's copyright file
################################################################################
test.mutualPlotGallery =
function()
{
# Mutual Information Index:
lorentz = lorentzSim(
times = seq(0, 40, by = 0.01),
parms = c(sigma = 16, r = 45.92, b = 4),
start = c(-14, -13, 47),
doplot = FALSE)
# Plot:
par(mfrow = c(1, 1))
mutualPlot(x = lorentz[, 2], partitions = 16, lag.max = 20, doplot = TRUE)
mtext("Lorentz Map", line = 0.5, cex = 0.7)
mtext(paste("times=seq(0,40,by=0.01) | parms=c(sigma=16,r=45.92,b=4) |",
"start=c(-14,-13,47)"), side = 4, adj = 0, col = "darkgrey", cex = 0.7)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.falsennPlotGallery =
function()
{
# False Nearest Neighbours:
roessler = roesslerSim(
times = seq(0, 100, by = 0.01),
parms = c(a = 0.2, b = 0.2, c = 8),
start = c(-1.894, -9.92, 0.025),
doplot = FALSE)
# Plot:
par(mfrow = c(1, 1))
falsennPlot(x = roessler[, 2], m = 6, d = 8, t = 180, eps = 1, rt = 3)
abline(h = 0, col = "grey")
grid()
mtext("Roessler Map", line = 0.5, cex = 0.7)
mtext(paste("times=seq(0,100,by=0.01) | parms=c(a=0.2, b=0.2, c=8) |",
"start=c(-1.894,-9.92,0.025)"), side = 4, adj = 0,
col = "darkgrey", cex = 0.7)
# Return Value:
return()
}
# ------------------------------------------------------------------------------ fNonlinear/inst/unitTests/runTests.R 0000644 0001762 0000144 00000004532 11645005112 017275 0 ustar ligges users pkg <- "fNonlinear"
if(require("RUnit", quietly = TRUE))
{
library(package=pkg, character.only = TRUE)
if(!(exists("path") && file.exists(path)))
path <- system.file("unitTests", package = pkg)
## --- Testing ---
## Define tests
testSuite <- defineTestSuite(name = paste(pkg, "unit testing"),
dirs = path)
if(interactive()) {
cat("Now have RUnit Test Suite 'testSuite' for package '",
pkg, "' :\n", sep='')
str(testSuite)
cat('', "Consider doing",
"\t tests <- runTestSuite(testSuite)", "\nand later",
"\t printTextProtocol(tests)", '', sep = "\n")
} else {
## run from shell / Rscript / R CMD Batch / ...
## Run
tests <- runTestSuite(testSuite)
if(file.access(path, 02) != 0) {
## cannot write to path -> use writable one
tdir <- tempfile(paste(pkg, "unitTests", sep="_"))
dir.create(tdir)
pathReport <- file.path(tdir, "report")
cat("RUnit reports are written into ", tdir, "/report.(txt|html)",
sep = "")
} else {
pathReport <- file.path(path, "report")
}
## Print Results:
printTextProtocol(tests, showDetails = FALSE)
printTextProtocol(tests, showDetails = FALSE,
fileName = paste(pathReport, "Summary.txt", sep = ""))
printTextProtocol(tests, showDetails = TRUE,
fileName = paste(pathReport, ".txt", sep = ""))
## Print HTML Version to a File:
## printHTMLProtocol has problems on Mac OS X
if (Sys.info()["sysname"] != "Darwin")
printHTMLProtocol(tests,
fileName = paste(pathReport, ".html", sep = ""))
## stop() if there are any failures i.e. FALSE to unit test.
## This will cause R CMD check to return error and stop
tmp <- getErrors(tests)
if(tmp$nFail > 0 | tmp$nErr > 0) {
stop(paste("\n\nunit testing failed (#test failures: ", tmp$nFail,
", R errors: ", tmp$nErr, ")\n\n", sep=""))
}
}
} else {
cat("R package 'RUnit' cannot be loaded -- no unit tests run\n",
"for package", pkg,"\n")
}
################################################################################
fNonlinear/inst/unitTests/runit.NonLinPlots.R 0000644 0001762 0000144 00000010013 11645005112 021014 0 ustar ligges users
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# A copy of the GNU General Public License is available via WWW at
# http://www.gnu.org/copyleft/gpl.html. You can also obtain it by
# writing to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA.
# Copyrights (C)
# for this R-port:
# 1999 - 2007, Diethelm Wuertz, GPL
# Diethelm Wuertz
# info@rmetrics.org
# www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
# see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
# see Rmetrics's copyright file
################################################################################
# FUNCTION: PHASE SPACE REPRESENTATION:
# mutualPlot Creates mutual information plot
# falsennPlot Creates false nearest neigbours plot
# FUNCTION: NON STATIONARITY:
# recurrencePlot Creates recurrence plot
# separationPlot Creates space-time separation plot
# FUNCTION: LYAPUNOV EXPONENTS:
# lyapunovPlot Maximum Lyapunov plot
################################################################################
test.mutualPlot =
function()
{
# Mutual Information Index:
par(mfrow = c(1, 1))
lorentz = lorentzSim(
times = seq(0, 40, by = 0.01),
parms = c(sigma = 16, r = 45.92, b = 4),
start = c(-14, -13, 47),
doplot = FALSE)
mutualPlot(x = lorentz[, 2], partitions = 16, lag.max = 20, doplot = TRUE)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.falsennPlot =
function()
{
# False Nearest Neighbours:
par(mfrow = c(1, 1))
roessler = roesslerSim(
times = seq(0, 100, by = 0.01),
parms = c(a = 0.2, b = 0.2, c = 8),
start = c(-1.894, -9.92, 0.025),
doplot = FALSE)
falsennPlot(x = roessler[, 2], m = 6, d = 8, t = 180, eps = 1, rt = 3)
abline(h = 0, col = "grey")
grid()
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.recurrencePlot =
function()
{
# Recurrence Plot:
par(mfrow = c(2, 2), cex = 0.7)
lorentz = lorentzSim(
times = seq(0, 40, by = 0.01),
parms = c(sigma = 16, r = 45.92, b = 4),
start = c(-14, -13, 47),
doplot = FALSE)
recurrencePlot(lorentz[, 2], m = 3, d = 2, end.time = 800, eps = 3,
nt = 5, pch = '.', cex = 2)
recurrencePlot(lorentz[, 3], m = 3, d = 2, end.time = 800, eps = 3,
nt = 5, pch = '.', cex = 2)
recurrencePlot(lorentz[, 4], m = 3, d = 2, end.time = 800, eps = 3,
nt = 5, pch = '.', cex = 2)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.separationPlot =
function()
{
# Separation Plot:
par(mfrow = c(1, 1))
roessler = roesslerSim(
times = seq(0, 100, by = 0.01),
parms = c(a = 0.2, b = 0.2, c = 8),
start = c(-1.894, -9.92, 0.025),
doplot = FALSE)
separationPlot(roessler[, 2], m = 3, d = 8, idt = 1, mdt = 250)
# Return Value:
return()
}
################################################################################
test.lyapunovPlot =
function()
{
# Lyapunov Plot:
NA
# Return Value:
return()
}
################################################################################
fNonlinear/inst/unitTests/runit.NonLinTests.R 0000644 0001762 0000144 00000012512 11645005112 021023 0 ustar ligges users
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General
# Public License along with this library; if not, write to the
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
# Copyrights (C)
# for this R-port:
# 1999 - 2007, Diethelm Wuertz, GPL
# Diethelm Wuertz
# info@rmetrics.org
# www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
# see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
# see Rmetrics's copyright file
################################################################################
# FUNCTION: DESCRIPION:
# tsTest Time Series Test Suite
# FUNCTION: DEPENDENCY TEST:
# bdsTest Brock-Dechert-Scheinkman test for iid series
# FUNCTION: NONLINEARITY TESTS:
# wnnTest White Neural Network Test for Nonlinearity
# tnnTest Teraesvirta Neural Network Test for Nonlinearity
################################################################################
test.tsSuite =
function()
{
# NA
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.bdsTest =
function()
{
# iid example:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
x = rnorm(100)
plot(x, type = "l", col = "steelblue")
test = bdsTest(x)
print(test)
p.value = as.vector(test@test$p.value)
# Is each of the 8 p.values greater 0.1?
checkEqualsNumeric(sum(p.value > 0.1), 8)
# Not identically distributed:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
x = c(rnorm(50), runif(50))
test = bdsTest(x)
print(test)
p.value = as.vector(test@test$p.value)
# Is each of the 8 p.values smaller 1e-3?
checkEqualsNumeric(sum(p.value < 1e-3), 8)
# Not independent:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
n = 500
x = rep(0, times = n)
for(i in (2:n)) x[i] = 0.4*x[i-1] + tanh(x[i-1]) + rnorm(1, sd = 0.5)
plot(x, type = "l", col = "steelblue")
test = bdsTest(x)
print(test)
p.value = as.vector(test@test$p.value)
# Is each of the 8 p.values smaller 1e-6?
checkEqualsNumeric(sum(p.value < 1e-6), 8)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.wnnTest =
function()
{
# White NN Test:
# See tseries Package:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
x = runif(1000, -1, 1)
plot(x, type = "l", col = "steelblue")
test = wnnTest(x)
print(test)
p.value = as.vector(test@test$p.value)
# Is each of the two p.values greater 0.5?
checkTrue(as.logical(mean(p.value > 0.5)))
## Generate time series which is nonlinear in ``mean''
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
n = 1000
x = rep(0, times = n)
for(i in (2:n)) x[i] <- 0.4*x[i-1] + tanh(x[i-1]) + rnorm(1, sd = 0.5)
plot(x, type = "l", col = "steelblue")
test = wnnTest(x)
print(test)
p.value = as.vector(test@test$p.value)
# Is each of the two p.values smaller than 1e-4?
checkTrue(as.logical(mean(p.value < 1e-4)))
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.tnnTest =
function()
{
# Teraesvirta NN Test:
# See example from tseries Package:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
x = runif(1000, -1, 1)
plot(x, type = "l", col = "steelblue")
test = tnnTest(x)
print(test)
p.value = as.vector(test@test$p.value)
# Is each of the two p.values greater 0.5?
checkTrue(as.logical(mean(p.value > 0.5)))
## Generate time series which is nonlinear in ``mean''
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
n = 1000
x = rep(0, times = n)
for(i in (2:n)) x[i] <- 0.4*x[i-1] + tanh(x[i-1]) + rnorm(1, sd = 0.5)
plot(x, type = "l", col = "steelblue")
test = tnnTest(x)
print(test)
p.value = as.vector(test@test$p.value)
# Is each of the two p.values smaller than 1e-4?
checkTrue(as.logical(mean(p.value < 1e-4)))
# Return Value:
return()
}
################################################################################
fNonlinear/tests/ 0000755 0001762 0000144 00000000000 13201353171 013503 5 ustar ligges users fNonlinear/tests/doRUnit.R 0000644 0001762 0000144 00000001644 11645005112 015216 0 ustar ligges users #### doRUnit.R --- Run RUnit tests
####------------------------------------------------------------------------
### Origianlly follows Gregor Gojanc's example in CRAN package 'gdata'
### and the corresponding section in the R Wiki:
### http://wiki.r-project.org/rwiki/doku.php?id=developers:runit
### MM: Vastly changed: This should also be "runnable" for *installed*
## package which has no ./tests/
## ----> put the bulk of the code e.g. in ../inst/unitTests/runTests.R :
if(require("RUnit", quietly = TRUE)) {
## --- Setup ---
wd <- getwd()
pkg <- sub("\\.Rcheck$", '', basename(dirname(wd)))
library(package = pkg, character.only = TRUE)
path <- system.file("unitTests", package = pkg)
stopifnot(file.exists(path), file.info(path.expand(path))$isdir)
source(file.path(path, "runTests.R"), echo = TRUE)
}
################################################################################
fNonlinear/src/ 0000755 0001762 0000144 00000000000 13201353171 013130 5 ustar ligges users fNonlinear/src/Makevars 0000644 0001762 0000144 00000000056 13203345304 014626 0 ustar ligges users PKG_LIBS=$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
fNonlinear/src/BDSTest.c 0000644 0001762 0000144 00000027730 13203345304 014556 0 ustar ligges users /*
Blake LeBaron
Dept. Of Economics
University Of Wisconsin-Madison
July 1988
March 1990
This software is distributed with the understanding that it is free.
Users may distribute it to anyone as long as they don't charge anything.
Also, the author gives this out without any support or
responsibility for errors of any kind. I hope that the
distribution of this software will further enhance are understanding
of these new measures of dependence.
*/
/* Changes for loading into R, A. Trapletti, 20.12.2000 */
#include
#include
#include
/* NBITS is the number of useable bits per word entry. Technically
on the sun this should be 32, as the sun uses 4 byte integers.
Since the counting algorithm uses a table lookup method we must
keep that table reasonable, so only 15 bits are used. This may be
changed if space is a problem.
*/
#define NBITS 15
#define ALLBITS 0xffff
#define PREC double
#define TABLEN 32767
static int BDS_DEBUG;
/* ----------- grid macro: turn bits on --------------------------- */
#define GRIDON(x,y) \
if(x!=y) { \
if(x>y) { \
ix = y; \
iy = x; \
} \
else { \
ix = x; \
iy = y; \
} \
iy = iy-ix-1; \
ipos = iy / NBITS; \
ibit = NBITS - 1 - (iy % NBITS); \
*(*(start+ix)+ipos) |= bits[ibit];\
}
/* define struct */
struct position {
PREC value;
int pos;
};
/* globals */
static int bits[NBITS],
*mask;
static short int *grid,
**start;
static int *lookup,first=1;
static struct position *postab,*postlast;
/*
free all memory allocations
*/
static void
freeall()
{
Free(grid);
Free(mask);
Free(postab);
Free(start);
Free(lookup);
}
/* module function definitions */
/*
generate mask
mask pattern for row l, nbits: number of bits used
omit: number of bits omitted
mask: mask[0],mask[1] two word mask
*/
static void
genmask(l,n,nbits,omit,mask)
int l,n,nbits,omit,mask[];
{
int i,k,j,last,itrue;
mask[0] = mask[1] = ALLBITS;
last = (n-l-1)/nbits;
for(i=n-omit;i 2 ) {
for (i = *(start+j);i< *(start+j+1)-2;i++) {
count += lookup[*i];
if(lookup[*i]>15)
Rprintf("%d %d %d\n", (int)(i-grid),*i,lookup[*i]);
}
for(i = *(start+j+1)-2;i< *(start+j+1);i++) {
count += lookup[ (*i) & mask[j*2+ *(start+j+1)-i-1]];
}
}
else {
for(i = *(start+j);i<*(start+j+1);i++) {
count += lookup[ (*i) & mask[j*2+ *(start+j+1)-i-1]];
}
}
}
if(BDS_DEBUG)
Rprintf("count = %ld\n",count);
return ( 2*((double)count)/ (nd*(nd-1)));
}
static
double
ipow(x,m)
double x;
int m;
{
int j;
double y;
y = 1;
for(j=0;jvalue>b->value)
return(1);
else if(a->valuevalue)
return(-1);
else
return(0);
}
static void
fkc(x,n,k,c,m,remove,eps)
PREC x[],eps;
int n,m,remove;
double *k,c[];
{
/* junk integers */
int i,j;
short int *ip;
int memsize;
int nobs;
/* pointers */
register struct position *pt;
struct position *p;
/* long counts */
long count,tcount;
/* double length */
double dlength;
double phi;
register int ix,iy,ibit,ipos;
nobs = n-remove;
dlength = (double)nobs;
/* allocate memory */
if(first ) {
mask = Calloc(2*n,int);
lookup = Calloc(TABLEN+1,int);
if(BDS_DEBUG)
Rprintf("set up grid\n");
postab = Calloc(n,struct position);
/* build start : grid pointers */
if(BDS_DEBUG)
Rprintf("build start\n");
start = Calloc(n+1,short int *);
/* find out how big grid has to be */
memsize = 0;
for(i=0;i<=n;i++)
memsize += (n-i)/NBITS + 1;
/* grid is defined as short (2 byte integers) */
grid = Calloc(memsize,short);
if(grid==NULL) {
error("Out of memory\n");
/*exit(-1);*/
}
start[0] = grid;
for(i=1;i<=n;i++)
start[i] = start[i-1] + (n-i)/NBITS + 1;
/* bit vector */
bits[0] = 1;
for(i=1;i<15;i++)
bits[i] = (bits[i-1] << 1);
/* table for bit countining */
if(BDS_DEBUG)
Rprintf("build lookup\n");
for(i=0;i<=TABLEN;i++){
*(lookup+i) = 0;
for(j=0;jvalue = x[i];
(postab+i)->pos = i;
}
if(BDS_DEBUG)
Rprintf("sort\n");
qsort((char *)postab,n,sizeof(struct position),comp);
postlast = postab+n-1;
/* start row by row construction */
/* use theiler method */
if(BDS_DEBUG)
Rprintf("set grid\n");
count = 0;
phi = 0;
for(p=postab;p<=postlast;p++) {
tcount = 0;
pt = p ;
/* count to right */
while( (pt->value - p->value)<=eps) {
GRIDON(p->pos,pt->pos);
if( (p->posposvalue - pt->value)<=eps) {
if( (p->posposiy){
temp = ix;
ix = iy;
iy = temp;
}
iy = iy-ix-1;
ipos = iy / NBITS;
ibit = NBITS - 1 - (iy % NBITS);
*(*(start+ix)+ipos) |= bits[ibit];
if( *(*(start+ix)+ipos)<0)
Rprintf("%d %d %d %d\n",ipos,ibit,ix,iy);
}
*/
/*
friendly front end - This main program is a friendly
front end program that calls the routines to calculate the
bds statistic. It allows unix user to:
1.) have an easy to use command imediately
2.) see how to use the calling routines for calculations
Users doing montecarlo work will probably want to use
the subroutines directly.
These routines are:
fkc(x,n,k,c,m,n,eps)
cstat(c,cm,k,m,n)
freeall()
fkc(x,n,k,c,m,mask,eps)
x = vector of series to test (double *), but it can be modified
using the PREC definition. Setting PREC to float or int, will
allow the use of other types of series.
n = length of series (int)
k = returned value of k (double *)
c = raw c values c[1],c[2],c[3].... (Note: the correct subscripts are used.)
(double *)
m = maximum embedding - cstats will calculated for i=1 to m (int)
mask = number of points to ignore at the end of the series.
Since the calculation of c(2) can effectively use more
points then c(3), c(4) ..., often the last several points
are ignored so that all statistics are calculated on the
same set of points. ie. for m=3 we might only use x(1) through
x(n-2) for the calculations of c(2) and c(3). This is generally
set to m-1 to allow all c to be estimated on a point set of
n-m+1. (int)
eps = epsilon value for close points (double) or set to (PREC).
cstat(c,cm,k,m,n)
This simple routine calculates the standard error and the normalized
bds stat. It closely follows formulas in Brock Hsieh and LeBaron
on page 43.
c = c[1] c for embedding 1
cm = c[m] c for embedding m
k = k stat
m = embedding
n = length of series
freeall()
The fkc algorithm allocates large amounts of memory. This is
time consuming and for montecarlo simulations it is not desirable
to reallocate every time. The routine can tell whether it needs
to reallocate. For simulations fkc should be called repeatedly.
When the program is finally done freeall() should be called
to free all the allocated space.
This front end module can be removed from the begin front
end comment to the end front end comment. The remaining
routines can be compiled as a stand alone library to be
called by other programs.
fkc_slow()
This extra routine is also included. It is a slower algorithm
which performs exactly the same function as fkc. Its only advantage
is that it is simpler and requires much less memory than the fast
algorithm.
To implement it just replace the call to fkc with fkc_slow() the
arguments are exactly the same.
*/
/* begin front end ---------------------------------- */
void bdstest_main (int *N, int *M, double *x, double *c, double *cstan, double *EPS, int *TRACE)
{
int i;
double k;
int n, m;
double eps;
n = (*N);
m = (*M);
eps = (*EPS);
BDS_DEBUG = (*TRACE);
/* calculate raw c and k statistics : This is the hard part */
fkc(x,n,&k,c,m,m-1,eps);
if(BDS_DEBUG) {
Rprintf("k = %f\n",k);
for(i=1;i<=m;i++) {
Rprintf("c(%d) %f\n",i,c[i]);
}
}
/* calculate normalized stats: This is the easy part */
for(i=2;i<=m;i++) {
cstan[i] = cstat(c[1],c[i],k,i,n-m+1);
}
/* free allocated memory: This must be done when finished */
freeall();
}
/* end front end ------------------------------------------*/
fNonlinear/src/Tisean.c 0000644 0001762 0000144 00000021103 13203345304 014515 0 ustar ligges users /* -------------------------------------------------------------------------- */
#ifndef tseriesChaos_h
#define tseriesChaos_h
#include
#include
#define sqr(a) (a)*(a)
#define MIN(a,b) (a)<(b) ? (a) : (b)
#define MAX(a,b) (a)>(b) ? (a) : (b)
#endif
/* -------------------------------------------------------------------------- */
void C2(double *in_series, int *in_m, int *in_d, int *in_length,
int *in_t, double *in_eps, double *out)
{
double *series;
double eps, tmp;
int m, d, length;
long blength;
int i, j, w, t, md;
series = in_series;
m = *in_m;
d = *in_d;
t = *in_t;
eps = *in_eps;
eps = sqr(eps);
length = *in_length;
blength = length - (m-1)*d;
md = m*d; *out=0;
for(i=0; i=eps) continue;
id++;
dst = ( dst + sqr(series[i+w+d] - series[j+w+d]) )/ dst;
if (dst>rt) num++;
}
denum+=id;
}
(*out) = (double)num/(double)denum;
(*out2)= denum;
}
/* -------------------------------------------------------------------------- */
#define output2(a,b) out[(b)*ref + (a)]
void find_nearest(double *in_series, int *in_m, int *in_d, int *in_t,
int *in_length, double *in_eps, int *in_ref, int *in_k, int *in_s,
int *out)
{
double eps, *series;
int m,d, t, s, ref, k, length, blength;
int i,j,w,md;
double *dsts;
int id; int *ids;
/*
BIND PARAMETERS
*/
m = *in_m;
d = *in_d;
t = *in_t;
s = *in_s;
ref=*in_ref;
k = *in_k;
eps=*in_eps;
series=in_series;
length=*in_length;
/**/
blength = length - (m-1)*d - s;
md = m*d;
for(i = 0; i[=eps) continue;
ids[id] = j;
id++;
}
R_qsort_I(dsts, ids, 1, id);
for(j=0; (j]