9/7/2020
Complete our Problem Session for Chapter 14 exercises
- 14.27 - Meg
- 14.28 - Andrew
Chapter 15 Random Variables
- Discrete versus continuous random variables
- Cumulative distribution function (c.d.f.) - F(x) = P(X<=x)
- Empirical c.d.f. - F-hat(x) = (# of observations <=x)/n
- Expected value
- Variance
- Standard deviation
- WLLN
- Sample proportion - p-hat
Chapter 3 (will be discussed on Wednesday)
- Notational conventions
- Variables - simple variables, vectors, matrices, and arrays
- Objects - variables and user-definied functions
- Branching with if and if-else --- syntax matters, be careful
- sums - with loops or sum(x)
- products - with loops or prod(1:n) or factorial(n)
- Memory use - changing the size of an array takes time
- preallocation - creating a vector
- redimensioning - changing the size of a vector
- While loops - used when we do not know how many times we will need to execute a loop
- Vector based programming - vector opearations are more efficient than looping
- ifelse - very powerful function - e.g., ifelse(x>0, "Pos", "Neg")
- pmin() and pmax() are vectorized versions of min() and max()
- e.g., pmin(c(1,2,3), c(3,2,1), c(2,2,2))
- Program flow - charting the flow of a program is extremely helpful for verifying your logic (i.e., is the program doing what you want?) and finding errors in your code.
- Debugging
- Tip 1 - Use cat() to examing values of your variables at various stages throughout your program
- Tip 2 - Use the KISS principle
- Tip 3 - Use dry runs where you know the answer to test your code
Please read Chapters 3 and 16 for class on Wednesday