# I tried multiple tests but could not figure out the issue since it keeps saying "Error in rnorm(n = b, 35, 18) : invalid arguments"

probs = c(.1,.6,.3)
vals = c(1,2,3)
arrPois = c(7,4,2)
tiers= c(1.1,1,.75)
nreps =100

fish = data.frame(matrix(ncol=3,nrow=0))
colnames(fish)=c("Total","Bluefin","Yellowfin")

for (i in 1:nreps) {
i = sample(x=vals,size=1,replace=TRUE,prob=probs)
lam=arrPois[i]
numfish= rpois(n=1,lambda=lam)

yprobs=c(.25,.5,.25)
yvals = c(0,.25,.35)
ypor= sample(x=yvals,size=1,replace=TRUE, prob=yprobs)
b= round(numfish - (1-ypor))
y= numfish - b

yweigh=rnorm(n=y,30,18)
yweigh=yweigh[yweigh>20]
sy=sum(yweigh)

bweigh=rnorm(n=b,35,18)
bweigh=bweigh[bweigh>20]
sb=sum(bweigh)

m=tiers[i]
EYy=msy
EYb=m
sb
total= EYy+EYb

fish[nrow(fish)+1,]=c(total,EYb,EYy)

}

Is it possible that the value of b is negative when you get that error?

Separately, I see that you are assigning a value to i, the variable incremented by the for loop, with the line

``````i = sample(x=vals,size=1,replace=TRUE,prob=probs)
``````

I have not worked through everything your code does but that seems like a bad idea.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.