Displaying 20 results from an estimated 69 matches for "rmultinom".
Did you mean:
multinom
2023 Apr 08
1
Error message for infinite probability parameters in rbinom() and rmultinom()
>>>>> Christophe Dutang
>>>>> on Sat, 8 Apr 2023 14:21:53 +0200 writes:
> Dear all,
> Using rmultinom() in a stochastic model, I found this function returns an error message 'NA in probability' for an infinite probability.
> Maybe, a more precise message will be helpful when debugging.
>> rmultinom(1, 3:5, c(1/2, 1/3, Inf))
> Error in rmultinom(1, 3:5, c(1/2, 1/3...
2023 Apr 08
1
Error message for infinite probability parameters in rbinom() and rmultinom()
On 08/04/2023 5:53 p.m., Martin Maechler wrote:
>>>>>> Christophe Dutang
>>>>>> on Sat, 8 Apr 2023 14:21:53 +0200 writes:
>
> > Dear all,
>
> > Using rmultinom() in a stochastic model, I found this function returns an error message 'NA in probability' for an infinite probability.
>
> > Maybe, a more precise message will be helpful when debugging.
>
> >> rmultinom(1, 3:5, c(1/2, 1/3, Inf))
> > Error in rm...
2023 Apr 08
1
Error message for infinite probability parameters in rbinom() and rmultinom()
Dear all,
Using rmultinom() in a stochastic model, I found this function returns an error message 'NA in probability' for an infinite probability.
Maybe, a more precise message will be helpful when debugging.
> rmultinom(1, 3:5, c(1/2, 1/3, Inf))
Error in rmultinom(1, 3:5, c(1/2, 1/3, Inf)) : NA in probabili...
2006 Jan 20
3
Troubles with the function rmultinom.c of the R's Random Number Generator
...erate data according to a Markov Random Field called the Potts model.
R Version:
platform i686-pc-linux-gnu
arch i686
os linux-gnu
system i686, linux-gnu
status
major 2
minor 2.1
year 2005
month 12
day 20
svn rev 36812
Each loop of my Fortran calls the function rmultinom.c of the R's Random
Number Generator through the wrapper:
#include <R.h>
#include <Rmath.h>
void F77_SUB(sarmultinom)(int n,
double* prob,
int K,
int* rN){
rmultinom(n, prob, K, rN);}
My fortran progr...
2016 Mar 10
3
rmultinom.c error probability not sum to 1
...or(int j = 0; j < 3; j++)
prob[j] = prob[j]/prob_tot;
//or this give the same error
//prob[2] = 1.0 - prob[1] - prob[0];
//checking indeed prob_tot not exactly 1
for(int j = 0; j < 3; j++)
prob_tot += prob[j];
Rprintf("Prob_tot: %f\n", prob_tot);
int rN[3];
rmultinom(1, prob, 1, rN);
return 0;
}
run R CMD SHLIB test.c to generate the test.so. Now from within R
> dyn.load("test.so")
> .C("main")
Prob_tot: 1.017084
Error: rbinom: probability sum should be 1, but is 0.948075
Maybe I miss some trivial C knowledge why this is not exac...
2002 Aug 08
0
RE: rmultinom
...hm from Luc Devroye's book on "Non-Uniform Random Variate Generation"
You may want to compare this with your hybrid algorithm and see their
relative performance.
Best,
Ravi.
###############################################################
## A multinomial random vector generator
rmultinom <- function(n, p){
ncat <- length(p)
# Check Arguments
if (n < 0) {cat("n < 0 ","\n"); break}
if (ncat <= 1) {cat("ncat <= 1 ","\n"); break}
if (any(p < 0.0)) {cat("Some P(i) < 0 ","\n"); brea...
2002 Aug 08
0
RE: rmultinom
Dear newsgroup,
There was a recent post suggesting the incorporation of a standard
rmultinom(...). This seems like a good idea, but I wasn't sure about basing
this on tabulate( sample( ...)). Despite the attractive succinctness, this
could be very slow and use lots of memory if n or size is large. Instead,
I've tended to use a loop over the boxes of the multinomial, taking
successi...
2006 Dec 09
1
Error in rmultinom(n, size, prob) : too few positive probabilities
// R 2.3.1
Can someone please explain why this error returns?
> y=numeric(100)
> x=matrix(runif(16),4,4)
> for(i in 2:100)
+ {
+ y[i]=which(rmultinom(1, size = 1, prob = x[y[i-1], ])==1)
+ }
Error in rmultinom(n, size, prob) : too few positive probabilities
thx much
ej
2016 Mar 10
0
rmultinom.c error probability not sum to 1
...s give the same error
> //prob[2] = 1.0 - prob[1] - prob[0];
>
prob_tot = 0; missing here
> //checking indeed prob_tot not exactly 1
> for(int j = 0; j < 3; j++)
> prob_tot += prob[j];
>
> Rprintf("Prob_tot: %f\n", prob_tot);
>
> int rN[3];
> rmultinom(1, prob, 1, rN);
Er, where do you tell rmultinom that variates are three-dimensional? It's not going to infer it from array sizes.
-pd
> return 0;
> }
>
> run R CMD SHLIB test.c to generate the test.so. Now from within R
>
>> dyn.load("test.so")
>> .C...
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...
2007 Apr 22
0
rmultinom
Hi
Can anyone help me? I am not an experienced R user (or statistician!). If I
use rmultinom to generate random outcomes of a multinomial distribution, how
do i use these in a way to help conduct an exact chi-squared test?
woozles48
--
View this message in context: http://www.nabble.com/rmultinom-tf3626954.html#a10127600
Sent from the R help mailing list archive at Nabble.com.
2010 Sep 08
11
problem with outer
...t it: but i get this error
message. i hope someone can help me.
Error in dim(robj) <- c(dX, dY) :
dims [product 16] do not match the length of object [1]
p_11=seq(0,0.3,0.1)
p_12=seq(0.1,0.4,0.1)
guete = function(p_11,p_12) {
set.seed(1000)
S_vek=matrix(0,nrow=N,ncol=1)
for(i in 1:N) {
X_0=rmultinom(q-1,size=1,prob=p_0)
X_1=rmultinom(n-q+1,size=1,prob=cbind(p_11,p_12,(1-p_11-p_12)))
N_0=apply(X_0[,(n-2*k-L+1):(n-k-L)],1,sum)
N_1=apply(X_1[,(n-q-k+2):(n-q+1)],1,sum)
S_vek[i]=((sum(((N_1-k*cbind(p_11,p_12,(1-p_11-p_12)))^2)/k*cbind(p_11,p_12,(1-p_11-p_12))))/(sum(((N_0-k*p_0)^2)/k*p_0)))-1
}
1-m...
2004 Sep 05
1
Biased calculations from using rmultinom?
Dear R users,
This is a problem that has puzzled me for quite some time, and I wonder if
anyone could offer me an insight to what is happening?
I generated a multinomial matrix by using
A<-rmultinom(100,1,c(0.4,0.3,0.2,0.1), and multiply this matrix by a set of
values say B<-runif(n,100,50). I then calculate var(colSums(A*B)). I was
able to work out the theoretical mean of var(colSums(A*B)) by using
fun.var.match.gen below.
I was however not sure, why is there a persistent over estimate...
2016 Mar 10
0
rmultinom.c error probability not sum to 1
On 10 Mar 2016, at 12:47 , M.van_Iterson at lumc.nl wrote:
> 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);...
2008 Mar 05
1
Question on "assign(paste.."
...probTrt=matrix(0,4,3);
probTrt;
#malf, death, normal
probTrt[1,]=c(0.064,0.119,0.817);#for Trt 1
probTrt[2,]=c(0.053,0.125,0.823);#for Trt 2
probTrt[3,]=c(0.111,0.139,0.750);#for Trt 3
probTrt[4,]=c(0.351,0.364,0.285);#for Trt 4
for (t in 4){
assign(paste("Trt",t,sep=""),rmultinom(10, size = 5,
prob=probTrt[t,]));
}
But the following does not work.
for (t in 4){
assign(paste("Trt",t,sep=""),rmultinom(10, size = 5,
prob=probTrt[t,]));
rowMeans(paste("Trt",t,sep=""));
}
How can I use it in functions like rowM...
2003 Jan 27
1
rmultinom() -- how \\ via own C code?
...TH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1228 <><
## This is based on rmultz2() from S-news by Alan Zaslavsky & Scott Chasalow;
## in R available from library(combinat) -- but it has
## Arg.names like rbinom(); returns n x p matrix
rmultinom <- function(n, size, prob) {
K <- length(prob) # #{classes}
matrix(tabulate(sample(K, n * size, repl = TRUE, prob) + K * 0:(n - 1),
nbins = n * K),
nrow = n, ncol = K, byrow = TRUE)
}
2011 Jun 27
1
Hardy Weinberg Simulation
...Aa.control <- 2*p.control*q.control # P(G=Aa) #
p.AA.control <- q.control^2 # P(G=AA) #
###################################
##### Generating Control Data #####
###################################
## Minor Allele Frequency ##
for (h in 1:800)
{
datamat[h,] <- t(rmultinom(1, size=c(10, 40, 50), prob=c(0.33, 0.33, 0.34)))
}
for (h in 801:1000)
{
datamat[h,] <- t(rmultinom(1, size=c(10,40,50), prob=c(p.aa.control[h],
p.Aa.control[h], p.AA.control[h])))
}
list.treat[[k]] <- datamat
}
--
Thanks,
Jim.
[[alternative HTML version deleted]]
2009 Sep 21
2
Four concurrent Markov chains
...ationb2[1,2]<-sample(1:6, 1, prob=w, repl=T)
i<-1;observationb3[1,2]<-sample(1:6, 1, prob=w, repl=T)
i<-1;observationb4[1,2]<-sample(1:6, 1, prob=w, repl=T)
while(i<n+1){
stateb1<-observationb1[i,2];
probsb1<-transitions[stateb1,1:6];
nextstateb1<-rmultinom(1,1,probsb1);
seqb1<-which.max(nextstateb1);
j<-i+1;
observationb1[j,2]<-seqb1;i<-j
#-------------------------------------if I close the brackets here this
works but I want to inlcude this next bit of code for bird 2
stateb2<-observationb2[i,2];
pr...
2007 Mar 30
1
faster computation of cumulative multinomial distribution
Dear list members,
I have a series of /unequal/ probabilities [p1,p2,...,pk], describing
mutually exclusive events, and a "remainder" class with a probability
p0=1-p1-p2-....-pk, and need to calculate, for a given number of trials
t>=k, the combined probability that each of the classes 1...k contains
at least 1 "event" (the remainder class may be empty).
To me this reaks
2011 Nov 07
3
Sampling with conditions
Hey everyone,
I am at best, an amateur user of R, but I am stuck on how to set-up the
following situation.
I am trying to select a random sample of numbers from 0 to 10 and insert
them into the first column of a matrix (which will used later in a loop).
However, I need to have those numbers add up to 10. How can I set those
conditions?
So far I have:
n<-matrix(0,nr=5,ncol=10)
for(i in