First commit

This commit is contained in:
Brian Albert Monroe 2018-04-19 12:17:08 +02:00
commit d6e58deab2
13 changed files with 155 additions and 0 deletions

2
.Rbuildignore Normal file
View File

@ -0,0 +1,2 @@
^.*\.Rproj$
^\.Rproj\.user$

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
tags

16
DESCRIPTION Normal file
View File

@ -0,0 +1,16 @@
Package: rcbelief
Title: RC Belief Task Estimation
Version: 0.0.0.9000
Authors@R: person('Brian Albert', 'Monroe', email = 'brianalbertmonroe@gmail.com', role = c('aut', 'cre'))
Description: This package provides functions to estimate beliefs from a QSR beliefs task.
Depends: R (>= 3.4.4)
License: MIT
Encoding: UTF-8
LazyData: true
maintainer: 'Brian Albert Monroe' <brianalbertmonroe@gmail.com>
LinkingTo: Rcpp, RcppArmadillo
Imports:
Rcpp,
RcppArmadillo,
dplyr
RoxygenNote: 6.0.1

6
NAMESPACE Normal file
View File

@ -0,0 +1,6 @@
# Generated by roxygen2: do not edit by hand
export(mkoutcomes)
import(dplyr)
importFrom(Rcpp,sourceCpp)
useDynLib(rcbelief)

10
R/RcppExports.R Normal file
View File

@ -0,0 +1,10 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
#' Generic Likelihood calculation
#'
#' @export mkoutcomes
mkoutcomes <- function(bins, reports, r, a, b) {
.Call('_rcbelief_mkoutcomes', PACKAGE = 'rcbelief', bins, reports, r, a, b)
}

5
R/extra.R Normal file
View File

@ -0,0 +1,5 @@
#' @useDynLib rcbelief
#' @importFrom Rcpp sourceCpp
#' @import dplyr
NULL

11
man/mkoutcomes.Rd Normal file
View File

@ -0,0 +1,11 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/RcppExports.R
\name{mkoutcomes}
\alias{mkoutcomes}
\title{Generic Likelihood calculation}
\usage{
mkoutcomes(bins, reports, r, a, b)
}
\description{
Generic Likelihood calculation
}

16
rcbelief.Rproj Normal file
View File

@ -0,0 +1,16 @@
Version: 1.0
RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
Encoding: UTF-8
AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace

3
src/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.o
*.so
*.dll

1
src/Makevars Normal file
View File

@ -0,0 +1 @@
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

1
src/Makevars.win Normal file
View File

@ -0,0 +1 @@
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

33
src/RcppExports.cpp Normal file
View File

@ -0,0 +1,33 @@
// Generated by using Rcpp::compileAttributes() -> do not edit by hand
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
#include <RcppArmadillo.h>
#include <Rcpp.h>
using namespace Rcpp;
// mkoutcomes
arma::mat mkoutcomes(int bins, arma::vec reports, double r, double a, double b);
RcppExport SEXP _rcbelief_mkoutcomes(SEXP binsSEXP, SEXP reportsSEXP, SEXP rSEXP, SEXP aSEXP, SEXP bSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< int >::type bins(binsSEXP);
Rcpp::traits::input_parameter< arma::vec >::type reports(reportsSEXP);
Rcpp::traits::input_parameter< double >::type r(rSEXP);
Rcpp::traits::input_parameter< double >::type a(aSEXP);
Rcpp::traits::input_parameter< double >::type b(bSEXP);
rcpp_result_gen = Rcpp::wrap(mkoutcomes(bins, reports, r, a, b));
return rcpp_result_gen;
END_RCPP
}
static const R_CallMethodDef CallEntries[] = {
{"_rcbelief_mkoutcomes", (DL_FUNC) &_rcbelief_mkoutcomes, 5},
{NULL, NULL, 0}
};
RcppExport void R_init_rcbelief(DllInfo *dll) {
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
R_useDynamicSymbols(dll, FALSE);
}

47
src/main.cpp Normal file
View File

@ -0,0 +1,47 @@
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
using namespace Rcpp;
double crra_prime(double x, double r) {
return(pow(x, r));
}
double qsr(double rep, arma::vec repvec, double a, double b) {
repvec = pow(repvec, 2);
double out = a + b*(2*rep - sum(repvec));
return(out);
}
//' Generic Likelihood calculation
//'
//' @export mkoutcomes
// [[Rcpp::export]]
arma::mat mkoutcomes(int bins, arma::vec reports, double r, double a, double b) {
arma::vec bvec = arma::linspace<arma::vec>(1, bins, bins);
arma::mat outcomes = arma::zeros<arma::mat>(bins, bins);
double brep, krep;
for (int bin = 0 ; bin < bins ; bin++ ) {
brep = reports(bin);
for (int k = 0 ; bin < bins ; k++ ) {
krep = reports(k);
if (k == bin) {
outcomes(bin, k) = (1 - brep) * crra_prime(qsr(krep, reports, a, b), r);
}
else {
outcomes(bin, k) = (0 - brep) * crra_prime(qsr(krep, reports, a, b), r);
}
}
}
return(outcomes);
}