I think your pcartas
object should be a simple vector, not a data frame. Otherwise you'll have difficulties with extracting elements of a list.
Clear the R workspace, install the prob package and load it.
rm(list=ls())
install.packages("prob")
library(prob)
Create the sample space.
pcartas <- cards()$suit
You'll see that this is a factor vector. I'm going to convert this to a character vector because the urnsamples
function converts the labels into their numeric codes, which makes it difficult when you want to calculate the probabilities. You'll see the problem if you don't do this next step.
pcartas <- unclass(as.character(pcartas))
Sample without replacement from this sample space and convert to a probability space (your first line of code above):
L <- urnsamples(pcartas, size=3, replace=FALSE, ordered=TRUE);
N <- probspace(L);
Calculate the probability of any event. For example, the probability of obtaining a "Spade" on the first card is:
Prob(N, X1=="Spade") # Answer=0.25 or 13/52
And the probability of obtaining a spade on the first card and a heart on the second is:
Prob(N, X1=="Spade" & X2=="Heart") # Answer=0.0637 or 13/52 * 13/51
And finally, the probability of obtaining a spade on the first card and a heart on the second card and a club on the third is:
Prob(N, X1=="Spade" & X2=="Heart" & X3=="Club") # Answer=0.016568 or 13/52 * 13/51 * 13/50
If you didn't convert the sample space object to a character vector, then you would have to use the numeric codes to get the probabilities:
Prob(N, X1==1 & X2==2 & X3==3)