b:head_first_statistics:using_discrete_probability_distributions
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
b:head_first_statistics:using_discrete_probability_distributions [2019/10/14 01:42] – [Fat Dan changed his prices] hkimscil | b:head_first_statistics:using_discrete_probability_distributions [2019/10/14 04:04] – [e.g.] hkimscil | ||
---|---|---|---|
Line 421: | Line 421: | ||
x2e | x2e | ||
</ | </ | ||
+ | |||
+ | < | ||
+ | [1] 400 | ||
+ | > x2e | ||
+ | [1] 415 | ||
+ | > </ | ||
x2e will spend more. | x2e will spend more. | ||
+ | |||
+ | ====== e.g. ====== | ||
+ | <WRAP box> | ||
+ | |||
+ | Sam likes to eat out at two restaurants. Restaurant A is generally more expensive than | ||
+ | restaurant B, but the food quality is generally much better. | ||
+ | Below you’ll find two probability distributions detailing how much Sam tends to spend at each | ||
+ | restaurant. As a general rule, what would you say is the difference in price between the two | ||
+ | restaurants? | ||
+ | </ | ||
+ | | Restaurant A: | ||
+ | | x | 20 | 30 | 40 | 45 | | ||
+ | | P(X = x) | 0.3 | 0.4 | 0.2 | 0.1 | | ||
+ | |||
+ | | Restaurant B: |||| | ||
+ | | y | 10 | 15 | 18 | | ||
+ | | P(Y = y) | 0.2 | 0.6 | 0.2 | | ||
+ | |||
+ | |||
+ | < | ||
+ | x3 <- c(20, | ||
+ | x3p <- c(.3, | ||
+ | x4 <- c(10,15,18) | ||
+ | x4p <- c(.2,.6,.2) | ||
+ | |||
+ | x3e <- sum(x3*x3p) | ||
+ | x4e <- sum(x4*x4p) | ||
+ | |||
+ | x3e | ||
+ | x4e | ||
+ | ## difference in price between the two | ||
+ | x3e-x4e | ||
+ | |||
+ | |||
+ | x3var <- sum(((x3-x3e)^2)*x3p) | ||
+ | x4var <- sum(((x4-x4e)^2)*x4p) | ||
+ | |||
+ | x3var | ||
+ | x4var | ||
+ | ## difference in variance between the two | ||
+ | ## == variance range | ||
+ | x3var+x4var | ||
+ | |||
+ | </ | ||
+ | |||
+ | < | ||
+ | > x3 <- c(20, | ||
+ | > x3p <- c(.3, | ||
+ | > x4 <- c(10,15,18) | ||
+ | > x4p <- c(.2,.6,.2) | ||
+ | > | ||
+ | > x3e <- sum(x3*x3p) | ||
+ | > x4e <- sum(x4*x4p) | ||
+ | > | ||
+ | > x3e | ||
+ | [1] 30.5 | ||
+ | > x4e | ||
+ | [1] 14.6 | ||
+ | > ## difference in price between the two | ||
+ | > x3e-x4e | ||
+ | [1] 15.9 | ||
+ | > | ||
+ | > | ||
+ | > x3var <- sum(((x3-x3e)^2)*x3p) | ||
+ | > x4var <- sum(((x4-x4e)^2)*x4p) | ||
+ | > | ||
+ | > x3var | ||
+ | [1] 72.25 | ||
+ | > x4var | ||
+ | [1] 6.64 | ||
+ | > ## difference in variance between the two | ||
+ | > ## == variance range | ||
+ | > x3var+x4var | ||
+ | [1] 78.89 | ||
+ | </ | ||
b/head_first_statistics/using_discrete_probability_distributions.txt · Last modified: 2023/10/04 10:29 by hkimscil