# Equivalent Julia package to R package \`prob\`

**URL:** <https://discourse.julialang.org/t/equivalent-julia-package-to-r-package-prob/2829>\
**Category:** Statistics\
**Created:** [March 22, 2017, 11:19pm UTC](https://discourse.julialang.org/t/equivalent-julia-package-to-r-package-prob/2829 "2017-03-22T23:19:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![AjayTalati](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@AjayTalati](https://discourse.julialang.org/u/AjayTalati)\
**Post date:** [March 22, 2017, 11:19pm UTC](https://discourse.julialang.org/t/equivalent-julia-package-to-r-package-prob/2829/1 "2017-03-22T23:19:33Z")

</div>

Hello 🙂,

I’m new to Julia, and have been using R previously. Could I ask if there’s an equivalent package in Julia to the package, `prob` in R.

[https://cran.r-project.org/web/packages/prob/vignettes/prob.pdf](https://cran.r-project.org/web/packages/prob/vignettes/prob.pdf)

I used `prob` to learn basic probability and have a lot of code that uses it. Or, alternatively should I use `RCall`, or try to port the package over to R - that would be hard because I’m new to Julia.

Thanks a lot, Aj

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 22, 2017, 11:27pm UTC](https://discourse.julialang.org/t/equivalent-julia-package-to-r-package-prob/2829/2 "2017-03-22T23:27:51Z")

</div>

> [@AjayTalati](#):
>
> or try to port the package over to R - that would be hard because I’m new to Julia.

I would actually think this would be a great way to learn the language. It shouldn’t be too difficult, and it gives you concrete problems with known solutions to try and tackle. I wouldn’t try “porting” either: I’d just remake the same functionality without looking at their internals.

---

<div class="post-metadata">

**Author:** ![andreasnoack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andreasnoack/32/27_2.png) [@andreasnoack](https://discourse.julialang.org/u/andreasnoack)\
**Post date:** [March 22, 2017, 11:29pm UTC](https://discourse.julialang.org/t/equivalent-julia-package-to-r-package-prob/2829/3 "2017-03-22T23:29:55Z")

</div>

I think many of the necessary pieces for such a package exist in `Distributions.jl` but is probably organized differently than the `prob` package.

---

<div class="post-metadata">

**Author:** ![AjayTalati](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@AjayTalati](https://discourse.julialang.org/u/AjayTalati)\
**Post date:** [March 22, 2017, 11:47pm UTC](https://discourse.julialang.org/t/equivalent-julia-package-to-r-package-prob/2829/4 "2017-03-22T23:47:17Z")

</div>

Great, thanks for the quick reply! I’ll try to implement the functions I need.

The `prob` package at it’s most basic level only uses `data.frames` i.e. probability tables, and `set operations`, it’s got no parametric distributions. It’s very, very simple really 🙂

---

<div class="post-metadata">

**Author:** ![gabrielgellner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gabrielgellner/32/75_2.png) [@gabrielgellner](https://discourse.julialang.org/u/gabrielgellner)\
**Post date:** [March 23, 2017, 3:29am UTC](https://discourse.julialang.org/t/equivalent-julia-package-to-r-package-prob/2829/5 "2017-03-23T03:29:54Z")

</div>

Looks like a fun little project. Some tips to get your started as you are new: check out `PkgDev.jl` to make a nice package layout. And then you will want `Combinatorics.jl` and `StatsBase.jl` to get combinations/permuations as well as sampling with and without replacement. You might also want to check out `Cards.jl` once 0.6 is out to get a nice datastructure for the cards examples! Good luck!

---

<div class="post-metadata">

**Author:** ![gabrielgellner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gabrielgellner/32/75_2.png) [@gabrielgellner](https://discourse.julialang.org/u/gabrielgellner)\
**Post date:** [March 23, 2017, 4:30am UTC](https://discourse.julialang.org/t/equivalent-julia-package-to-r-package-prob/2829/6 "2017-03-23T04:30:34Z")

</div>

Okay this got me thinking … for the `toss_coin` function is there a more straightforward way of doing this than

```julia
using Iterators
toss_coin(n::Int) = collect(product(fill((:H, :T), n)...))

```

The program is meant to give all the possible outcomes from toss a coin `n` times. I think R uses the `expand.grid` function. For some reason the above feels clunky to me.

---

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [March 23, 2017, 4:44am UTC](https://discourse.julialang.org/t/equivalent-julia-package-to-r-package-prob/2829/7 "2017-03-23T04:44:32Z")

</div>

Its a great case for chaining:

```julia
using ChainRecursive
@chain begin
    toss_coin(n::Int) = begin
        (:H, :T) 
        fill(it, n)
        product(it...)
        collect(it)
    end
end

```

---

<div class="post-metadata">

**Author:** ![AjayTalati](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@AjayTalati](https://discourse.julialang.org/u/AjayTalati)\
**Post date:** [March 23, 2017, 2:15pm UTC](https://discourse.julialang.org/t/equivalent-julia-package-to-r-package-prob/2829/8 "2017-03-23T14:15:17Z")

</div>

Thanks a lot for the kind encouragement 🙂, and the pointers to useful packages already in Julia.

The two functions in the `R` package that I always need are, `probspace` to setup the probability space, and `subset` to partition/slice up the probability table.

Once I’ve done those two - it should be OK to do most of the examples in the [vignette](https://cran.r-project.org/web/packages/prob/vignettes/prob.pdf)

---

<div class="post-metadata">

**Author:** ![gabrielgellner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gabrielgellner/32/75_2.png) [@gabrielgellner](https://discourse.julialang.org/u/gabrielgellner)\
**Post date:** [March 23, 2017, 2:32pm UTC](https://discourse.julialang.org/t/equivalent-julia-package-to-r-package-prob/2829/9 "2017-03-23T14:32:32Z")

</div>

Kind of a cool package, like the Mathematica like argument syntax … though I am still not sure I love this way of making the outcome, even if it has a cleaner layout with your version.

---

<div class="post-metadata">

**Author:** ![AjayTalati](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@AjayTalati](https://discourse.julialang.org/u/AjayTalati)\
**Post date:** [March 23, 2017, 2:56pm UTC](https://discourse.julialang.org/t/equivalent-julia-package-to-r-package-prob/2829/10 "2017-03-23T14:56:13Z")

</div>

Here’s also a fun package in Haskell,

> **[probability](https://hackage.haskell.org/package/probability)**
>
> Probabilistic Functional Programming

and here’s a children’s guide to learning Haskell,

[http://learnyouahaskell.com/starting-out](http://learnyouahaskell.com/starting-out)

which is a lot of fun to learn both probability and programming from 🙂
