Homework 1 - Solution

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Homework 1

General Instructions. Due Sunday, September 13 th at 11:59pm. Please submit your code and a log of
your output for Part TWO. For Part ONE submit an electronic version through Canvas. The TA will grade
these for completeness.

Part ONE
Consult Chapter 1 and Chapter 2 of OpenIntro Statistics from the syllabus for Topics we’ve covered.
Chapter 1 is Introduction to Data and Chapter 2 is on Probability.

Short Questions

1. If the we roll a 4-sided die and an 8 sided-die simultaneously. Use the chart to compute the
probabilities for the following events:

a) P (1,1)=1/32
b) P (sum=5)=4/32
c) P (sum>9)=6/32
d) P (sum=odd)=16/32
e) P (sum=5 or sum>9)=10/32

2. Suppose you flip a coin 5 times, observing heads (H) or tails (T) on each flip. Define X to be a
Random Variable that equals 1 if the coin comes up heads at least one time and 0 otherwise.
Compute the expected value of X , denoted E [X ].

The distribution of X is

X 0 1
P[X=x] 1/32 31/32

Applying the formula for E[X], E[X] = 0*(1/32) + 1*(31/32) = 31/32.


Part TWO
Practice with R. Use R to complete the following exercise. You can modify the script from class to do
this, but save your commands in a separate script file.

Begin by setting the seed, so that the results can be replicated. Run the command set.seed(5030)
to do this.

Generate sample spaces and sample from them.

1. Sample spaces.
a. Following the example of a five-sided die from class, generate a sample space for an
eight-sided die, and save it in an object called S_oct.
b. Generate a sample space of a coin with outcomes labeled “H” and “T.” Save in an object
named S_coin.
2. Sampling
a. Draw a sample of size = 100 observations from the discrete RV sample spaces in (1).
Store in objects labeled X_oct and X_coin.
b. Draw a sample of size = 100 observations from the following continuous distributions:
i. Uniform[-1,+1]. As in Class_1_code file, use the runif() function. Store in
object labeled X_uni.
ii. Normal(mean = 5, sd = 1). Similar to the uniform, use the rnorm() function.
Store the result in an object labeled X_norm.
1. Tip: To learn about how to use rnorm(), type the command
help(rnorm). There are lots of options, but only a few that you’ll
need to use/ specify. By comparison, look at help(runif).

3. Summarize the samples.


a. For each of the samples in 2 (X_oct, X_coin, X_uni, and X_norm), summarize
the sample.
i. Report the output from summary(“object”) where “object” is one of the
samples generated in 2. Use a comment in the code to note what you notice in
each case (if you type a pound sign #, what follows the # on that line is not
interpreted as code, but is a comment).
ii. For the discrete samples, X_oct and X_coin, coerce the variable to become a
factor using the as.factor() function (e.g., object_factor =
as.factor(object)). Use the summary() function on the factor version of
these samples. What additional information does this add? [include your
answer in a comment in the script]
b. Use the sd() function to compute the standard deviation of each sample.

You might also like