Gam780
Gam780

Reputation: 17

Simulating a discrete distribution on a different scale in R

I'm new to R and have this question. As mentioned in the title, I have a distribution of reported dice number from students. In this task, they are given a dice with 6 faces (from 1-6) and are asked to throw it in private. The data are plotted as in the picture.

However, I wonder if it's possible that I can use this data to simulate the situation where they are given a dice with 10 faces instead (from 1-10)? How can I achieve this in R?

enter image description here

Upvotes: 0

Views: 130

Answers (2)

drJones
drJones

Reputation: 1233

Ok second attempt if you want to use your existing six-sided die data. I use the snpackage to fit a skewed normal distribution to your existing data and then scale it to represent a ten-sided die and make it discrete using round.

First I will simulate your data

set.seed(9999)
n=112
a = rnorm( 42, 3, 1 )
b = rnorm( 70, 5, 0.5 )
dat = round(c( a, b))
dat[!(dat %in% 1:6)] = NA
dat=dat[complete.cases(dat)]

hist(dat,breaks = seq(0.5, 6.5,1), col = rgb(0,0,1,0.25))

enter image description here

Just set dat as your existing data if you want.

Now to parametise the distribution using the sn package. (You can try to fit other distributions if you prefer)

require(sn)
cp.est = sn.mple(y=dat,opt.method = "nlminb")$cp 
dp.est = cp2dp(cp.est,family="SN")

##example to sample from the distribution and compare to existing
sim = rsn(n, xi=dp.est[1], omega=dp.est[2], alpha=dp.est[3])
sim = round(sim)
sim[!(sim %in% 1:6)] = NA
hist(sim,breaks = seq(0.5, 6.5,1), col = rgb(1,0,0,0.25), add=T)

enter image description here

Now scale the distribution to represent a ten-sided die.

sim = rsn(n, xi=dp.est[1], omega=dp.est[2], alpha=dp.est[3])/6*10
sim <- round(sim)
sim[!(sim %in% 1:10)] = NA
hist(sim,breaks = seq(0.5, 10.5,1), col = rgb(0,1,0,0.25))

enter image description here

Upvotes: 1

drJones
drJones

Reputation: 1233

To simulate 112 students rolling a ten-sided die and plotting the results in histogram:

n=112
res = sample(1:10, size = n, replace = T)
hist(res)

Upvotes: 0

Related Questions