Description
Problem 1: Random variables review
lim pfXpx ` dxq ´ fXpxqq{dx “ fXpxq. This derivative (if it exists) is dxÑ0 dx known as the probability density function (pdf) of the random variable X.
a) Suppose X is a random variable with pdf proportional to e´λx if x is positive and 0 otherwise. What is the pdf of X? (i.e., what is the constant of proportionality?) What is the cdf of X?
(4 points)
b) Suppose X is a random variable with pdf p. The mean of X is:
ErXs “ ż (1)
´8
What is the mean of the random variable given in part a)?
(4 points) c) Suppose x P R. For the random variable given in part a), what is PrpX “ xq?
(4 points) d) Prove that the pdf of a random variable X is non-negative (provided that the pdf exists).
(4 points)
Problem 2: Review of R
Consider the following for loops in R. For each for loop, list the values (in order) that the variable i takes on in the body of the loop. Briefly (in no more than a few sentences) explain why.
a)
for(i in 1+2:3.4*5) { }
(2 points)
b)
for(i in dim(matrix(0, nr = 7, nc = 8))) { }
(2 points) c)
for(i in rnorm(3)) { }
(2 points)
d)
for(i in iris[1:3,3]) { }
(2 points) e)
for(j in c(1, 2, 3, 4, 5)) {
(2 points) f)
for(i in (function(x) x*x)(c(1, 2, 3))) { }
(2 points)
g)
for(i in NULL) { }
(2 points)
h)
for(i in strsplit(as.character(4*atan(1)),’’)
[[1]][1:10]) { }
(2 points)
Problem 3: Using knitr
–title: “Untitled” output: pdf_document
—
‘‘‘{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE)
‘‘‘
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS
Word documents. For more details on using R
Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this: ‘‘‘{r cars} summary(cars) ‘‘‘
## Including Plots
You can also embed plots, for example:
‘‘‘{r pressure, echo=FALSE} plot(pressure) ‘‘‘
Click the ‘knit’ on the toolbar of RStudio’s editor to render the markdown as a pdf. The document should pop up in a preview window. The pdf will also be saved in the same directory that your new R markdown file is saved in. The element ‘##’ specifies a section title, the element ‘title: “Untitled”’ specifies the document title, the elements ‘‘‘‘{r …} … ‘‘‘’ specify R code that is to be executed. The element echo=FALSE indicates that the R code should not be emitted in the file (and instead, only the results of the code should be emitted). Markdown allows you to specify bolding, hyperlinks, bullets and other text aspects through annotations such as **Knit** for a bold ‘Knit’ (the asterisks indicate the bolding). An overview of the options for formatting and running code in R markdown is available here: https://www.rstudio.com/wp-content/uploads/ 2015/02/rmarkdown-cheatsheet.pdf.
In an R markdown, provide a short summary of the dataset What
is the dataset about? When was it collected? How many items are in the dataset? How many variables are provided? Broadly, what types of variables are there, and broadly, what are their units? (For example, if there are thousands of variables all with the same units indicating measurements at different times, you can just say what the measurement is, what the units are and what the times are: you don’t have to list each individual variable.) This summary should be no more than half a page.
Choose one of the variables and plot a histogram of that variable. Ensure that the x-axis is labelled correctly, with units. Make the histogram so that its y-axis is ‘proportion’ and not ‘count’ (i.e., the sum of the areas of the histogram rectangles should equal 1). Superimpose on top of the histogram a plot of the pdf of a normal distribution (a.k.a. Gaussian distribution, or bell-curve) with mean and variance given by the empirical mean and variance of the variable. (For example, if you’ve chosen the 5th variable of the dataset and the dataset is loaded into R as the variable df, then the empirical mean is mean(df[, 5]) and the empirical variance is var(df[, 5]).) Provide a single pdf including the rendered R markdown followed by a listing of the text of the R markdown file.
(10 points)




Reviews
There are no reviews yet.