using R assighment

Description

Problem 1. Write your R codes (commands) for the following tasks and present your results clearly.

Don't use plagiarized sources. Get Your Custom Assignment on
using R assighment
From as Little as $13/Page

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


Unformatted Attachment Preview

X
Y
35.0 13.7
41.8 16.7
42.6 16.4
33.2 9.2
47.2 13.8
53.7 17.8
34.0 19.6
34.3 13.3
42.0 20.8
58.8 15.7
47.3 11.1
37.0 12.6
46.8 12.0
44.6 14.1
29.1 11.3

Purchase answer to see full
attachment