-
Notifications
You must be signed in to change notification settings - Fork 0
/
Probabilities, Normal Distributions.R
70 lines (43 loc) · 1.8 KB
/
Probabilities, Normal Distributions.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
### Probabilities, Normal Distributions
# Probability of making a deal < 7500$
pnorm(7500, mean = 5000, sd = 2000)
# Probability of deal > 1000
pnorm(1000, mean = 5000, sd = 2000, lower.tail = FALSE)
# Probability of deal between 3000 and 7000
pnorm(7000, mean = 5000, sd = 2000) - pnorm(3000, mean = 5000, sd = 2000)
# Calculate amount that 75% of deals will be more than
qnorm(0.75, mean = 5000, sd = 2000, lower.tail = FALSE)
#########################################################
# Calculate new average amount if sales increase by 20% from 5000
new_mean <- 5000 * 1.2
# Calculate new standard deviation if it increases by 30%
new_sd <- 2000 * 1.3
# Simulate 36 sales
new_sales <- new_sales %>%
mutate(amount = rnorm(36, mean = new_mean, sd = new_sd))
# Create histogram with 10 bins
ggplot(new_sales, aes(amount)) + geom_hist(bins = 10)
# Calculate percent of sales over 1000$
pnorm(1000, mean = 5000, sd = 2000, lower.tail = FALSE)
###############################################################
# SAMPLES
# Sample 20 num_users with replacement from amir_deals
sample(amir_deals$num_users, size = 20, replace = TRUE) %>%
# Take mean
mean()
# Repeat the above 100 times
sample_means <- replicate(100, sample(amir_deals$num_users, size = 20, replace = TRUE)
%>% mean())
##################################################################
# POISSON DISTRIBUTIONS
# Probability of something happening AT LEAST 5 times in a day when the mean is 4
dpois(5, 4)
# Probablity of something happening AT MOST 2 times in a day when mean is 4
ppois(2, 4)
# Probability of > 10 responses
ppois(10, 4, lower.tail = FALSE)
# EXPONENTIAL DISTRIBUTIONS
# Probability something takes < 1hr when mean time is 2.5 hrs
pexp(1, rate = 1/2.5)
# Probability it takes > 4 hours
pexp(4, rate = 1/2.5, lower.tail = FALSE)