I am using R studio. I need write these problem. 3. Write a program that will do
ID: 668727 • Letter: I
Question
I am using R studio. I need write these problem.
3. Write a program that will do the following. Include your codes and necessary outputs to demonstrate
your work.
(a) Generate 90000 random numbers from an exponential distribution with mean 30 and store these
numbers in a vector called myVector. Report a histogram of the numbers you just generated.
(b) Convert myVector into a matrix of 900 columns and assign it to an object called myMatrix.
Report the dimension of myMatrix.
(c) Compute the column means of myMatrix. Report a histogram of those column means.
(d) Explain why the two histograms you have created in questions (3a) and (3c) are different in
shapes.
4. We don’t usually want to write loops in R. Answer the following questions to avoid loops.
(a) Explain what the following R codes are doing.
> myMatrix <- matrix(1:9, ncol=3)
> output <- NULL
> for (i in 1:3){
+ output <- c(output, prod(myMatrix[,i]))
+ }
> output
1
[1] 6 120 504
(b) Provide R codes that will produce the same result without using loop
5. What are the very first few steps one should do once data is loaded onto R? Demonstrate that by
loading tips data from http://www.ggobi.org/book/data/tips.csv
Explanation / Answer
usepackage[vmargin=1in,hmargin=1in]{geometry}
egin{document}
egin{center}
large extsc{Homework 1} \
STAT 4410/8416 Section 001\
extsc{Fall 2014}\
Due: September 12, 2014 by midnight
ormalsize
end{center}
egin{enumerate}
item egin{enumerate}
item What is data science?
item Explain with an example what you mean by data product.
item Carefully read the Cleveland's paper shown in lecture 2 and discuss what he suggested about the field of statistics and data science.
item Explain in a short paragraph how data science is different from computer science.
end{enumerate}
item In our extbf{R} class we created the following function to get the square of a number. The function is written such that it gives us a text output exttt{Big number} if the input is more than 100.
<<>>=
getSquare <- function(x){
if(x>100)
return("Big number") else
return(x^2)
}
@
We checked that the function is working as expected since we have
<<>>=
getSquare(5)
getSquare(500)
@
But the function does not work as expected for the following case. Instead of giving `Big number' as an output it provides the actual square.
<<warning=FALSE>>=
x <- c(25,200)
getSquare(x)
@
Explain what is going wrong here. Also give a solution of this problem.
item Write a program that will do the following. Include your codes and necessary outputs to demonstrate your work.
egin{enumerate}
item label{exp-hist} Generate 90000 random numbers from an exponential distribution with mean 30 and store these numbers in a vector called myVector. extbf{Report} a histrogram of the numbers you just generated.
item Convert myVector into a matrix of 900 columns and assign it to an object called myMatrix. extbf{Report} the dimension of myMatrix.
item label{mean-hist} Compute the column means of myMatrix. extbf{Report} a histogram of those column means.
item Explain why the two histograms you have created in questions ( ef{exp-hist}) and ( ef{mean-hist}) are different in shapes.
end{enumerate}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.