Displaying 3 results from an estimated 3 matches for "prob_tot".
2016 Mar 10
3
rmultinom.c error probability not sum to 1
...y problem. Here it is.
I extracted from my code the bit that gives the error. Place this in a file called test.c
#include <math.h>
#include <R.h>
#include <Rmath.h>
#include <float.h>
#include <R_ext/Print.h>
int main(){
double prob[3] = {0.0, 0.0, 0.0};
double prob_tot = 0.;
prob[0] = 0.3*dnorm(2, 0, 1, 0);
prob[1] = 0.5*dnorm(5, 0, 1, 0);
prob[2] = 0.2*dnorm(-3, 0, 1, 0);
//obtain prob_tot
prob_tot = 0.;
for(int j = 0; j < 3; j++)
prob_tot += prob[j];
//normalize probabilities
for(int j = 0; j < 3; j++)
prob[j] = prob[j]/prob_tot...
2016 Mar 10
0
rmultinom.c error probability not sum to 1
...s in a file called test.c
Aha. Missing info #1, C not R...
>
> #include <math.h>
> #include <R.h>
> #include <Rmath.h>
> #include <float.h>
> #include <R_ext/Print.h>
>
> int main(){
>
> double prob[3] = {0.0, 0.0, 0.0};
> double prob_tot = 0.;
>
> prob[0] = 0.3*dnorm(2, 0, 1, 0);
> prob[1] = 0.5*dnorm(5, 0, 1, 0);
> prob[2] = 0.2*dnorm(-3, 0, 1, 0);
>
> //obtain prob_tot
> prob_tot = 0.;
> for(int j = 0; j < 3; j++)
> prob_tot += prob[j];
>
> //normalize probabilities
> for(int j...
2016 Mar 10
2
rmultinom.c error probability not sum to 1
Dear all,
I have a questions regarding using the c function rmultinom.c.
I got the following error message "rbinom: probability sum should be 1, but is 0.999264"
Which is thrown by:
if(fabs((double)(p_tot - 1.)) > 1e-7)
MATHLIB_ERROR(_("rbinom: probability sum should be 1, but is %g"),
(double) p_tot);
I understand my probabilities do not sum to one close enough. I