[Rcpp-devel] not sure if it's a rcpp question or a cpp question

Aileen Lin aileenshanhong.lin at gmail.com
Thu Mar 14 04:42:37 CET 2013


My C code:
//[[Rcpp::depends("Rcpp")]]
#include <Rcpp.h>
#include <iostream>
using namespace Rcpp;

//[[Rcpp::export]]
NumericVector sigmutest(double pd, double rsq){
  double qpd = R::qnorm(pd, 0, 1, 1, 0);
  double sgtemp = 0.2;
  double sg = 0.3;
  double eor = 1;

  double w = 0;
  while (eor>=0.0001) {
        sg = sgtemp;
        w = pd * 0.4 / (R::pnorm((qpd - sqrt(rsq) * (-0.42) * sgtemp), 0,
1, 1, 0));
        sgtemp = (-0.5) * w + 0.4;
        std::cout << "sg " << sg << std::endl;
        std::cout << "sgtemp " << sgtemp << std::endl;
        eor = abs(sg - sgtemp);

        std::cout << "error " << eor << std::endl;

      }
  NumericVector out(3);
  out(0) = sg;
  out(1) = sgtemp;
  out(2) = eor;
  return out;
}

My R code:

> Rcpp::sourceCpp('src/sbi.cpp')> x <- sigmutest(0.0002327279, 0.1025499338)sg 0.2
sgtemp 0.219135
error 0


Does anyone know what is going on? Thanks.
-- 
Aileen L.

View my Linkedin profile: http://au.linkedin.com/in/aileen2

 Being happy doesn't mean you're perfect. It just means you've decided to
look beyond the imperfections- K.B Indiana (age
14)<http://www.boardofwisdom.com/default.asp?topic=1010&search=K%2EB+Indiana+%28age+14%29>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130314/8341d2d2/attachment-0001.html>


More information about the Rcpp-devel mailing list