-1

Consider an experiment that consists of throwing 100 fair dice and adding up the results of the individual dice. Compute the average outcome?

How can I do this in R studio, and how to come up with probability distribution graph in Rstudio

Phil
  • 7,287
  • 3
  • 36
  • 66
Mulalo
  • 11
  • 2
  • Welcome to SO. It's easier to help you if you include the code you have tried. Check out [mre] and [ask] – Peter May 17 '20 at 19:23

2 Answers2

2

I am just showcasing an example

X represents the independent variable of the pdf for the normal distribution, it’s also useful to think of x as a Z-score. Let me show you what I mean by graphing the pdf of the normal distribution with dnorm

z_scores <- seq(-3, 3, by = .1) # First I'll make a vector of Z-scores

# Let's make a vector of the values the function takes given those Z-scores.
# Remember for dnorm the default value for mean is 0 and for sd is 1.

dvalues <- dnorm(z_scores) 

# Now we'll plot these values
plot(dvalues, # Plot where y = values and x = index of the value in the vector
     xaxt = "n", # Don't label the x-axis
     type = "l", # Make it a line plot
     main = "pdf of the Standard Normal",
     xlab= "Z-score") 

# These commands label the x-axis
axis(1, at=which(dvalues == dnorm(0)), labels=c(0))
axis(1, at=which(dvalues == dnorm(1)), labels=c(-1, 1))
axis(1, at=which(dvalues == dnorm(2)), labels=c(-2, 2))

enter image description here

Arun kumar mahesh
  • 2,289
  • 2
  • 14
  • 22
1

Welcome to Stack Overflow. Usally this not a platform for programming tasks. You have to show some effort in solving your problem. So you have to try to solve the problem by yourself and show some code when you got stuck. Furthermore this is not a tutorial for R or other programming languages.

Please take some time and take a look at https://stackoverflow.com/help/how-to-ask in general and at How to make a great R reproducible example in particular for questions regarding R.

Nevertheless:

# define the number of rolls
n <- 100

# sample with replacement draws n times from the numbers 1:6
dice <- sample(1:6, n, replace=TRUE)

# calculate the sum of simluated dice rolls
dice_sum <- sum(dice)

# calculate the average outcome 
result <- dice_sum/n

# draw a histogram with a density plot
hist(dice, breaks=seq(0,6, 0.5), probability = TRUE, col = rainbow(12))
lines(density(dice))

This should give you a start with your problem.

Martin Gal
  • 16,640
  • 5
  • 21
  • 39