Below are the solutions to these exercises on probability functions.
#################### # # # Exercise 1 # # # #################### set.seed(1) random_numbers <- runif(10) #################### # # # Exercise 2 # # # #################### (coin_tosses_1 <- ifelse(random_numbers>.5, 'head', 'tail'))
## [1] "tail" "tail" "head" "head" "tail" "head" "head" "head" "head" "tail"
set.seed(1) (coin_tosses <- rbinom(n = 1, size = 10, prob = .5))
## [1] 4
#################### # # # Exercise 3 # # # #################### set.seed(1) (coin_tosses_unfair <- rbinom(n = 1, size = 10, prob = .3))
## [1] 2
#################### # # # Exercise 4 # # # #################### set.seed(1) (die_roll <- runif( n = 1, min = 0, max = 6))
## [1] 1.593052
(ceiling(die_roll))
## [1] 2
#################### # # # Exercise 5 # # # #################### set.seed(1) heights <- rnorm(n = 100, mean = 1.70, sd = .1) summary(heights)
## Min. 1st Qu. Median Mean 3rd Qu. Max. ## 1.479 1.651 1.711 1.711 1.769 1.940
#################### # # # Exercise 6 # # # #################### pnorm(1.90, mean = 1.70, sd = .1)
## [1] 0.9772499
1 - pnorm(1.60, mean = 1.70, sd = .1)
## [1] 0.8413447
#################### # # # Exercise 7 # # # #################### set.seed(1) (patients <- rexp(rate = 1/50, n =30))
## [1] 37.759092 59.082139 7.285336 6.989763 21.803431 144.748427 ## [7] 61.478103 26.984142 47.828375 7.352300 69.536756 38.101493 ## [13] 61.880178 221.196711 52.727158 51.762197 93.801759 32.737332 ## [19] 16.846674 29.423986 118.225763 32.094629 14.706019 28.293276 ## [25] 5.303631 2.971958 28.935623 197.946643 58.665605 49.840648
#################### # # # Exercise 8 # # # #################### pexp(q = 10,rate = 1/50)
## [1] 0.1812692
#################### # # # Exercise 9 # # # #################### qexp(.5, rate = 1/50)
## [1] 34.65736
#################### # # # Exercise 10 # # # #################### (1 - pexp(q=60, rate =1/50)) *100
## [1] 30.11942
Leave a Reply