Problem 1. Write your R codes (commands) for the following tasks and present your results clearly.
Problem 1. Write your R codes (commands) for the following tasks and present your results clearly.
a. Generate a vector x with 30 random numbers from uniform distribution, i.e., U(0, 1). Show the values of x you get.
b. Use the R built-in functions (find the functions on your own if you don’t know them yet) to calculate the sample mean, median, and standard deviation of x.
c. Run the command y<- I(x > 0.5). Is y a numerical vector? Confirm or disapprove it by executing some appropriate R functions. d. Run the command z=cbind(x,y). Is z a matrix or data frame? Is the second column of z a logic vector or numerical vector? Show the output of summary(z).
e. What function can be used to change y into a character vector?
f. Run command xx=diag(x) in R. Is xx a vector or matrix? Find the length of xx by implementing length(xx) in R.
Problem 2. Use R to solve the following questions and present your results clearly.
a. Read data into R from the text file dataP2HW1.txt.
b. Calculate the sample mean and variance of X and Y separately.
c. Calculate Pearson’s correlation coefficient between X and Y .
d. Explore the function “lm” in R by checking “help(lm)” and then use it to fit a simple linear regression with Y being the dependent variable and X the independent variable. Report the fitted linear regression line.
e. Report the estimated regression coefficients in the form of a vector.
f. Create a character variable readme for “This is a simple linear regression problem.”
g. Create a list object (with name listP2HW1) that contains the data containing X and Y in the form of a data frame with 2 columns, the estimated regression coefficients in the form of a vector, the correlation coefficients, and readme. Assign the following names c(“data”, “coef”, “corr”, “readme”) to the objects in listP2HW1. Display listP2HW1 and check out the command listP2HW1$Data$X
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.
