Looking for someone who knows econometrics and good at R coding.

profilechrexdi_ca1
HW1_ARE_106_SS1_2020.pdf

Homework 1

Theory

(1) (8 Points) Imagine that you are playing the fifth edition of Dungeons & Dragons. You are playing a character which uses a shortsword. A shortsword does 1d6 damage per hit.1 That is, to calculate your damage, you roll one standard 6-sided die. You really want to be calculated about your attacks, so you decide to explore the properties of this die roll.

(a) Find the pmf for rolling one die

(b) Find the expected value of this pmf

(c) Find the variance of this pmf (Hint: First find E[X2] then use the formula given in the statistics review)

(d) Draw a histogram of this pmf

(2) (16 Points) Later on in the game, you find an enchanted shortsword. This new shortsword does an additional 1d4 as compared to your old sword. That is, to calculate your damage you will roll both a standard 6-sided die and a 4-sided die.2 Again, you want to be calculated about your attacks, so you decide to explore the distribution of the sum of these two dice.

(a) Find the pmf of the sum of these two die

(b) Find the expected value of the sum of these two dice (Hint: You only need to find one more expectation)

(c) Find the variance of the sum of these two dice (Hint: Be careful here)

(d) Draw a histogram of this pmf

(e) Now imagine that you have a spell which adds an additional 1d6 of damage to each of your attacks.3 Now to calculate the damage on each attack you will roll 2 6-sided dice and 1 4-sided die.

Recalculate the expected value and population variance for these rolls

(f) Lastly, you level-up and just get to add an additional +1 to every attack. How does this change the expected value and population variance?

1See description click here 2If you’re unfamiliar with a 4-sided die, click here 3Consider the spell Hex or Hunter’s Mark

1

(3) (15 Points) You’ve been playing with these people for a while now. The monsters in the game seem harder than normal. You suspect that the Dungeon Master4 is cheating. You think that they may have weighted dice. That is, they have dice that are more likely to give higher values than normal dice. As the Dungeon Master gets up to get a slice of pizza, you quickly role their 6-sided die 5 times. You write down the following results of the rolls:

4, 1, 6, 3, 6

(a) What is the sample average from these roles?

(b) Is this above or below the hypothesized expectation for a fair die?

This seems interesting. You are thinking about confronting the Dungeon Master about this, but you want be sure. So you decide to do a hypothesis test.

(c) First, find the sample variance and standard error for this sample

(d) Perform a t-test test to see if the dice are weighted5

(e) Is this a one-sided or two-sided t-test? Why?

(f) Do you accept or reject the null hypothesis?

(g) Do you think that rolling a die 5 times will give you a solid approximation of the expectation for that die? What statistical law could you use to justify your answer?

(4) (8 Points) Let’s turn our attention to continuous variables. Many continuous variables have fairly complicated pdfs. Even the normal distribution is difficult to work with unless you are very confident in your calculus skills. For now, lets keep things simple. Lets work with the uniform distribution. The uniform distribution gives equal probability to all numbers being drawn within some range. Let’s say we have a uniform distribution that goes from 4 to 6. We would note that as U(4, 6). We can write the general form of the uniform distribution as:

f(x) = 1

b−a

Where b is the highest number in the range and a is the lowest number.

(a) Find the expectation of this distribution

(b) Find the variance of this distribution

(5) (12 Points) In this section, we will dig a bit further into the material that I presented in lecture.

(a) In the lecture I show that the variance can be simplified in the following way:

V ar(X) = E [X −E(X)]2

= E[X2] −E[X]2

Prove this.

4This is the person that controls the monsters 5You can use this t-test calculator to find the critical value

2

(b) In the slides I stated that:

Cov(X, Y ) = E[XY ] −E[X]E[Y ]

Express this in a way that looks more similar to the unsimplified variance formula (Hint: You are basically doing the opposite of what you did in part (a). Try to work backwards from that answer.)

(c) In the slides, I said that E[XY ] 6= E[X]E[Y ] generally. Use the formula for covariance to find a case where E[XY ] does in fact equal E[X]E[Y ] (Hint: Set Cov(X, Y ) equal to something and solve)

Empirics

(1) (8 Points) We are going to redo our calculations for Theory Questions (1)-(3) in R. Don’t worry, it will be much faster.

(a) Lets generate a population distribution. To do this, we are going to use the sample() com- mand. Look up the help file for this command. This command works like pulling things out of a bag, or like rolling a die. The first argument you put in is a vector of the possible outcomes. The second is the size of the sample you want, Then you choose whether you want to replace the number in the “bag”. Lastly, you can choose if you want to add probability weights. To simulate a fair die roll, we want replacement and no probability weights. We can use this command to effectively generate a population. We do this by just making the sample size very large.6 Feel free to play around on your computer and see how large of a sample size you can get before you run out of RAM7, its probably more than you think.

Now make a “population” pmf

(b) Find the “expected value” of this distribution

(c) Find the “population variance” of this distribution

(d) Draw a histogram of the pmf (Hint: You will need to call ggplot2 with the library() command)

(2) (15 Points) Now we will re-do Theory Question (2)

(a) Create the pmf described in Theory Quesiton (2)

(b) Find the “expected value” of this pmf

(c) Find the variance of this pmf

(d) Draw a histogram of this pmf

(e) Create the pmf described in Theory Question (2) part (e) and find its mean, variance, and draw a histogram

(f) Create the pmf described in Theory Question (2) part (f) and find its mean and variance

6See LLN 7RAM stands for Random-Access Memory. This is where R stores the data you are using when you are using it.

3

(3) (7 Points) Now we will re-do Theory Question (3)

(a) Create the sample given in Theory Question (3)

(b) What is its sample average?

(c) Use the t.test() method to perform a t-test with this data. Look up the help file for this command. The first argument is the sample you wish to preform the t-test on. Another argument we will want to pay attention to us the mu argument. Here is where you want to put your hypothesized mean. In this case, it will be the expectation of the pmf for a single 6-sided die roll. This command does not give you the critical value - only the t-statistic. So you will still have to look up the critical value.

(d) Do you accept or reject the null hypothesis?

(4) (11 Points) Let’s get into some looping. Sometimes it is nice to generate your own data. Now let’s take our first stab at it.

(a) Lets start simple by just making a counter. Write a loop that just prints the numbers 1 through 5. To do this, first define an object counter8 outside of the loop. Set it equal to zero. Inside the loop use the print() command. It will simply print whatever is inside the brackets.

(b) Now lets use that counter. Make a loop that creates a vector, where the first element is 1, second element is 2, ..., the fifth element is 5:

[1 2 3 4 5]

Stat by making a blank vector so that you can fill it. I always start with a vector full of weird number. For example you could use -999. That way, if something is wrong in your data, you will be able to pick it out right away. After you create this container, you will fill it in the loop.

(c) Lets create a vector of random numbers, all of which come from a normal distribution with a different mean. To do this, we will use the rnorm() command. Look up the help file for this command. The argument n tells it how many numbers to draw. The argument mean tells it what the mean of the distribution is. The argument sd tells it what the standard deviation of the distribution is.

Make a vector where there are 5 elements. The first element should be drawn from a distri- bution with a mean of 3, the second from a distribution with a mean of 7, the third from a distribution with a mean of 4, the fourth from a distribution with a mean of 10, and the fifth from a distribution with a mean of 2. To do this you will need to specify a vector as your list in the for command.

(d) Now we’re going to do something a bit more difficult. I want you to recreate the first 10 numbers in the Fibonacci sequence. To do this, you will again need to create a container vector. Then you will need to feed it the first two numbers in the sequence outside of the loop. Then, you will need to fill the rest of the sequence by using the loop. (Hint: You can create counters inside of the loop to help pick out elements that are already in the matrix)

8You can call it anything you want, this is just an example.

4