Skip to content

Correction in error

5 messages · Gyanendra Pokharel, Sarah Goslee, R. Michael Weylandt +2 more

#
Hi,

I see two problems right off:

On Mon, Nov 7, 2011 at 3:10 PM, Gyanendra Pokharel
<gyanendra.pokharel at gmail.com> wrote:
The rbinom() command here returns a vector of values, but you're
trying to assign it to a single matrix element. You might want to
double-check the help for rbinom() again.
tx isn't defined, but is probably a typo for x
With a nice short function such as this, it's easy to set your
arguments to their default values and actually run the function line
by line at the command prompt so you can see whether what is happening
is what you expect.

Sarah
#
The first argument to rbinom() is how many random samples you want to
draw, not whatever you seem to think it is. It's not matching the size
of what you mean to assign it to: in particular note that x[t-1, 3] is
zero for t=3 which is where you initialize it. (I.e., you are also
probably getting tripped up by an order of operations error)

Michael

On Mon, Nov 7, 2011 at 3:10 PM, Gyanendra Pokharel
<gyanendra.pokharel at gmail.com> wrote:
#
A possible third problem is that
   2:m+1
is the same as
   (2:m) + 1
and you probably want
   2:(m+1)

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
#
Hi:

In your function call, x[1, 1] = theta = 0. In the first line of the
loop, your rbinom() call works out to be
  x[2, 1] <- rbinom(x[1, 3], 1, x[1, 1])       <=> rbinom(10, 1, 0)

That likely accounts for the error message:
Error in x[t, 1] <- rbinom(x[t - 1, 3], 1, x[t - 1, 1]) :
  replacement has length zero

HTH,
Dennis

On Mon, Nov 7, 2011 at 12:10 PM, Gyanendra Pokharel
<gyanendra.pokharel at gmail.com> wrote: