Skip to content
Permalink
Browse files

Adding JAGS module

  • Loading branch information...
joachimvandekerckhove committed May 14, 2018
1 parent cbd373f commit bff5d8e7ddad0579773540a7f519a15feb887ec1
@@ -1,6 +1,7 @@
# bbc
Bayesian Bias Correction

This GitHub repository contains code for the Bayesian Bias Correction method developed by Maime Guan and Joachim Vandekerckhove.
This GitHub repository contains code for the Bayesian Bias Correction method developed by Maime
Guan and Joachim Vandekerckhove.

The code is applied to a subset of Replicability Project: Psychology.
@@ -0,0 +1,23 @@
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = m4 libltdl src

.PHONY: win32-install win64-install installer docs

example-zip:
(zip -r example example)

win32-install:
make prefix=`pwd`/win/inst32
make install prefix=`pwd`/win/inst32

win64-install:
make prefix=`pwd`/win/inst64
make install prefix=`pwd`/win/inst64

installer:
(cd win && $(MAKE) $@)

docs: FORCE
-@(cd doc && $(MAKE) $@)

FORCE:
@@ -0,0 +1,47 @@
dnl Process this file with autoconf to produce a configure script.

AC_PREREQ([2.68])

AC_INIT([JAGS-CT],[0.1],[joachim@uci.edu],[JAGS-CT-MODULE])
JAGS_MAJOR=4
JAGS_MINOR=0
AC_SUBST(JAGS_MAJOR)
AC_SUBST(JAGS_MINOR)

AC_CANONICAL_HOST
AC_CONFIG_SRCDIR([src/distributions/DCT.cc])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([subdir-objects])

dnl libtool and ltdl configuration
LT_PREREQ(2.2.6)
LT_CONFIG_LTDL_DIR([libltdl])
LT_INIT([dlopen disable-static win32-dll])
LTDL_INIT([recursive])

dnl C++
AC_PROG_CXX

dnl Rmath stuff
AC_DEFINE(MATHLIB_STANDALONE, 1, [Define if you have standalone R math library])

case "${host_os}" in
mingw*)
win=true ;;
*)
win=false ;;
esac
AM_CONDITIONAL(WINDOWS, test x$win = xtrue)

jagsmoddir=${libdir}/JAGS/modules-${JAGS_MAJOR}
AC_SUBST(jagsmoddir)

AC_CONFIG_FILES([
Makefile
m4/Makefile
libltdl/Makefile
src/Makefile
src/distributions/Makefile
])
AC_OUTPUT
@@ -0,0 +1,24 @@
#!/bin/bash

modulename=new-module

echo 'Extracting...'
mkdir -p $modulename
tar -xzf template.tar.gz -C $modulename
#cp ~/Downloads/JAGS-WIENER-MODULE-1.1/* $modulename -r

echo 'Editing...'
cp src-ct.cc $modulename/src/ct.cc
cp src-distributions-HEADER.h $modulename/src/distributions/DCT.h
cp src-distributions-SOURCE.cc $modulename/src/distributions/DCT.cc
cp src-distributions-Makefile.am $modulename/src/distributions/Makefile.am
cp src-Makefile.am $modulename/src/Makefile.am
cp Makefile.am $modulename/Makefile.am
cp configure.ac $modulename/configure.ac

cd $modulename

echo 'Compiling...'
autoreconf -fvi && ./configure --prefix=/usr

make && sudo make install
@@ -0,0 +1,12 @@
SUBDIRS = distributions

jagsmod_LTLIBRARIES = ct.la

ct_la_SOURCES = ct.cc

ct_la_CPPFLAGS = -I$(includedir)/JAGS

ct_la_LIBADD = distributions/ctdist.la
ct_la_LIBADD += -ljags -ljrmath

ct_la_LDFLAGS = -module -avoid-version
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2017 Joachim Vandekerckhove <joachim@uci.edu>
*
* When using this module, please cite as:
* Wabersich, D., & Vandekerckhove, J. (2014). Extending JAGS: A
* tutorial on adding custom distributions to JAGS (with a
* diffusion model example). Behavior Research Methods, 46, 15-28.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <module/Module.h>
#include <distributions/DCT.h>

using std::vector;

namespace jags {
namespace ct {

class CTModule : public Module {
public:
CTModule();
~CTModule();
};

CTModule::CTModule() : Module("ct")
{
DCT *ctdist;
ctdist = new DCT();
//load distributions
insert(ctdist);
}

CTModule::~CTModule()
{
vector<Function*> const &fvec = functions();
for (unsigned int i = 0; i < fvec.size(); ++i) {
delete fvec[i];
}
vector<Distribution*> const &dvec = distributions();
for (unsigned int i = 0; i < dvec.size(); ++i) {
delete dvec[i];
}
}

} // namespace ct
} // namespace jags

jags::ct::CTModule _ct_module;
@@ -0,0 +1,73 @@
/* This class contains functions for the ct (diffusion) model */
#ifndef DCT_H_
#define DCT_H_

#include <distribution/RScalarDist.h>

namespace jags {
namespace ct {

/**
* Non-central t-distribution on k degrees of freedom, with
* location/non-centrality parameter parameter mu, and
* precision parameter tau.
*
* The non-central t has no simple closed-form expression for
* its density but it can be defined constructively in terms
* of underlying normal and chi-squared distributions.
*
* <pre>
* X ~ dnt(mu, tau, k)
* X = U/sqrt(V/k))
* U ~ N(mu, tau)
* V ~ Chi2(k)
* </pre>
*
* The non-central t-distribution is normally only defined for
* tau=1, in which case mu is the non-centrality
* parameter. The 3-parameter form here is a scaled version of
* a standard non-central t with non-centrality parameter
* delta = mu * sqrt(tau).
*
* @short non-central t distribution
*/

class DCT : public RScalarDist
{
public:
DCT();

/*
* logDensity, randomSample and typicalValue use the below defined
* d,p,q,r functions
*
double logDensity(double x, PDFType type,
std::vector<double const *> const &parameters,
double const *lower, double const *upper) const;
double randomSample(std::vector<double const *> const &parameters,
double const *lower, double const *upper,
RNG *rng) const;
double typicalValue(std::vector<double const *> const &parameters,
double const *lower, double const *upper) const;
/*
* Checks that:
* a > 0
* w in intervall [0,1]
* terr > 0
*/
double d(double x, PDFType type,
std::vector<double const *> const &parameters,
bool give_log) const;
double p(double q, std::vector<double const *> const &parameters, bool lower,
bool give_log) const;
double q(double p, std::vector<double const *> const &parameters, bool lower,
bool log_p) const;
double r(std::vector<double const *> const &parameters, RNG *rng) const;

bool checkParameterValue(std::vector<double const *> const &parameters) const;

};
} //namespace ct
} //namespace jags

#endif /* DCT_H_ */
@@ -0,0 +1,9 @@
noinst_LTLIBRARIES = ctdist.la

ctdist_la_CPPFLAGS = -I$(top_srcdir)/src -I$(includedir)/JAGS

ctdist_la_LDFLAGS = -no-undefined -module -avoid-version

ctdist_la_SOURCES = DCT.cc

noinst_HEADERS = DCT.h

0 comments on commit bff5d8e

Please sign in to comment.
You can’t perform that action at this time.