[R] rbinom for a matrix
ACroske
Audy3272 at yahoo.com
Wed Jul 9 22:24:57 CEST 2008
Yes I do want a random assignment, instead of rounding. (From what I
understand of the rbinom command, it will randomly assign 1 or 0, and the
higher the given probability, the higher the likelihood of a 1... Feel free
to correct me if I'm wrong!)
Ben Bolker wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Dylan Beaudette wrote:
> | On Wednesday 09 July 2008, Ben Bolker wrote:
> |> ACroske <Audy3272 <at> yahoo.com> writes:
> |>> I have a large matrix full of probabilities; I would like to convert
> each
> |>> probability to a 1 or a 0 using rbinom.
> |>> How can I do this on the entire matrix? The matrix was converted from
> a
> |>> raster ArcMap dataset, so the matrix is essentially a map. Because of
> |>> this, I have no column headings.
> |>> Thanks!
> |> How about
> |>
> |> matrix(rbinom(length(m),prob=m,size=1),nrow=nrow(m))
> |>
> |> or (perhaps marginally more efficiently?)
> |>
> |> y <- (runif(m)<m)
> |> storage.mode(y) <- "double"
> |>
> |> Ben Bolker
> |>
> |
> | Wait a second. Are you trying to convert each probability into the most
> | likely '1' or '0' through rounding? The code example above will give
> you a
> | different answer every time you run it. Is that what you are looking
> for?
> |
> | Just curious,
> |
> | Dylan
> |
>
> ~ I assumed that since the original poster said "convert each
> probability to a 1 or 0 using rbinom" that they did indeed want
> a random assignment, rather than rounding ...
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFIdRiZc5UpGjwzenMRAuLkAKCA6ZhjrVsg5RJGYFGwq+6vz2pWxgCfetYk
> 9V/ZPGi2jfVGV5jx+LGPs8s=
> =d8c9
> -----END PGP SIGNATURE-----
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
--
View this message in context: http://www.nabble.com/rbinom-for-a-matrix-tp18366867p18370010.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list