Equivalent Julia package to R package `prob`


#1

Hello :slight_smile:,

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

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


#2

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.


#3

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


#4

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 :slight_smile:


#5

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!


#6

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

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.


#7

Its a great case for chaining:

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

#8

Thanks a lot for the kind encouragement :slight_smile:, 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


#9

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.


#10

Here’s also a fun package in Haskell,

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

http://learnyouahaskell.com/starting-out

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