Homework Assignment
1. Simple Calculations (10%)
\[ 2^{15} ,\quad \frac{20}{\sqrt{\pi}} ,\quad {10 \choose 5} ,\quad \ln{\frac{2+4}{4+3}} ,\quad \sqrt[3]{-27},\quad \sin(270^\circ) \]
\[ \log_5(6) ,\quad \sum_{i=0}^{5}{5} ,\quad \sum_{i=3}^{5}{i \; !} ,\quad \prod_{i=1}^{107}{i},\quad 1-0.000000000000000001 \]
- How many digits does the result (overall number, not only after decimal point) from the second last calculation (Product) have?
- Is the result from the last calculation identical to \(1-0.000000000000000001\) ? Why or why not and what are the implications?
2. Poker Game (40%)
You have a regular set of poker cards. The order of the face cards is as follows (numeric value of card in parantheses):
\[ 2 < 3 < \ldots < 9 < 10 < \text{Jack}\,(11) < \text{Queen}\,(12) < \text{King}\,(13) < \text{Ace}\,(14)\]
The order of the colors is: \[ \text{Diamonds}\,\diamondsuit < \text{Clubs}\,\clubsuit < \text{Hearts}\,\heartsuit < \text{Spades} \,\spadesuit\]
Write a function
poker()
, where each of the two players receives five cards of the described deck. The player with the highest card wins the game. Your function should return the winner of the game only. Hint: It may be easier to use the values instead of the names of the face cards.Manipulate your function from 1. and create the function
poker_p1()
so that Player 1 has a 60% chance of getting a King and therefore wins more often.Make yourself familiar with the function
replicate()
. Apply your knowledge to the original and manipulated function and play the implemented games one million times. Visually prove that Player 1 has a higher chance of winning when using functionpoker_p1()
using a suitable visualization. Include the function name and your matriculation number in the main title of your plots.
OLS Regression
Within R we can easily fit regression models using the lm()
function, which not only gives us the plain coefficients but a lot of additional output. Please write a function my.lm()
that performs a linear regression and returns results in the form of summary(lm(y~1+x1+x2+...))
.
When writing functions, please document all steps in detail to show your procedure and make your programming comprehensible. Before you start, make sure that you are familiar with the associated concepts and provide correct interpretations of your results.
Implement your function my.lm()
. The following steps are the cornerstones of the implementation and may be your guideline while developing the function.
- Estimate the regression coefficients.
- Calculate the variance of the estimated coefficients.
- Perform hypothesis tests to check whether the calculated coefficients are significant, outputting \(t\)-value as well as \(p\)-value.
- Calculate additional metrics that are included in the output like \(R^2\), \(R_{adj}^2\) and the summary statistics of the residuals.
- Perform the F-Test and calculate the necessary elements to interpret the results.
- Wrap everything in a function that uses a vector \(y\) and a matrix or vector \(x\) as input. Make the necessary parameters adjustable for the user and format the output so that it looks like the one from
summary(lm())
.
Hint 1: You do not need to support the formula notation (~) in your function.
Hint 2: If you are not totally sure about interpreting results, you should consult a textbook. A good one to start is Regression Analysis by Example from Chatterjee and Hadi.
To prove that your regression function works corretcly, compare it to an output generated by lm()
with at least 3 regressors (e.g. using the data from the wooldridge::wage1
dataset) and interpret the resulting coefficients
4. Bug Bounty (5%)
Participate in the bug bounty program, either by submitting an error found in the available course notes or by suggesting a substantial improvement to the course notes.