Question

In: Statistics and Probability

1. Basic use of R/R Studio. Solve the following problem in R and print out the...

1. Basic use of R/R Studio. Solve the following problem in R and print out the commands and outputs.

(a) Create a vector of the positive odd integers less than 100; Remove the values greater than 60 and less than 80; Find the variance of the remaining set of values

(b) What’s the difference in output between the commands 2*1:5 and (2*1):5? Why is there a difference?

(c) If you wanted to enter the odd numbers from 1 to 19 in the variable x, what command would you use?

(d) If you create a variable using the following command y=c(-1,2,-3,4,-5), what command would put the positive values of y into the variable z?

(e) What R command would give you the 95th percentile for a chi-squared distribution with 10 degrees of freedom?

(f) Generate a vector of 1000 standard normal random variables using the command x=rnorm(1000), use R to give a five number summary of your simulated data; what is the mean and variance of your x variable? Make and print a histogram for this data.

Solutions

Expert Solution

rm(list=ls())

(a)

#Create a vector of the positive odd integers less than 100
a=seq(from = 1, to = 100, by = 2)
a
[1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49
[26] 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99

#Remove the values greater than 60 and less than 80
b=a[-31:-40]
b
[1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49
[26] 51 53 55 57 59 81 83 85 87 89 91 93 95 97 99
#variance of the remaining set of values
var(b)
[1] 931.2821


#########################################################################

(b)

#Difference in output between the commands 2*1:5 and (2*1):5
2*1:5 # here first work 1:5 then multiply by 2
[1] 2 4 6 8 10

(2*1):5 # here first work 2*1 then work 2:5
[1] 2 3 4 5

##########################################################################

(c)

#If you wanted to enter the odd numbers from 1 to 19 in the variable x
x=seq(1,19,2)
x
[1] 1 3 5 7 9 11 13 15 17 19

############################################################################

(d)

# If you create a variable using the following command y=c(-1,2,-3,4,-5),
# what command would put the positive values of y into the variable z?
z=y[y>0]
z
[1] 2 4
#####################################################################################

(e)

# R command would give you the 95th percentile for a chi-squared distribution with 10 degrees of freedom.
qchisq(0.95,10)
[1] 18.30704

######################################################################################

(f)

x=rnorm(1000)

# summary of given variable
summary(x)
Min. 1st Qu. Median Mean 3rd Qu. Max.
-3.13872 -0.64016 -0.03391 -0.00435 0.66116 3.22207
# mean of x
mean(x)
[1] -0.004350421
# variance of x
var(x)
[1] 1.0273

# Histogram of this data


Related Solutions

Use R to solve the following problem: A study was carried out to investigate the variation...
Use R to solve the following problem: A study was carried out to investigate the variation of rainbow trout weights in a certain creek. The weights (in kilograms) of 10 randomly selected fish are listed below: 0.78, 0.45, 0.35, 0.76, 0.57, 0.42, 0.33, 0.68, 0.66, 0.42 Assume that the population is approximately normally distributed. Test the hypothesis that the unknown population variance is less than 0.08 kg2 at alpha=0.05. Be sure to list (i) your hypotheses, (ii) test statistic, (iii)...
Use R Studio to solve this problem. A simple electronic device consists of two components which...
Use R Studio to solve this problem. A simple electronic device consists of two components which have failure times which may be modeled as independent exponential random variables. The first component has a mean time to failure of 3 months, and the second has a mean time to failure of 6 months. (a) If the electronic device will fail when either of the components fails, use 1000 random samples of the simulated electronic device to estimate the mean and variance...
Use R studio to answer the following. A study was carried out to investigate the variation...
Use R studio to answer the following. A study was carried out to investigate the variation of rainbow trout weights in a certain creek. The weights (in kilograms) of 10 randomly selected fish are listed below:       0.78, 0.45, 0.35, 0.76, 0.57, 0.42, 0.33, 0.68, 0.66, 0.42 Assume that the population is approximately normally distributed.  Hint: make a vector to enter the weight data into R, e.g.: > wt = c(0.78, ..., 0.42) Find the 90% confidence interval for the unknown population...
Use R studio to do this problem. This problem uses the wblake data set in the...
Use R studio to do this problem. This problem uses the wblake data set in the alr4 package. This data set includes samples of small mouth bass collected in West Bearskin Lake, Minnesota, in 1991. Interest is in predicting length with age. Finish this problem without using Im() (a) Compute the regression of length on age, and report the estimates, their standard errors, the value of the coefficient of determination, and the estimate of variance. Write a sentence or two...
Using R studio 1. Read the iris data set into a data frame. 2. Print the...
Using R studio 1. Read the iris data set into a data frame. 2. Print the first few lines of the iris dataset. 3. Output all the entries with Sepal Length > 5. 4. Plot a box plot of Petal Length with a color of your choice. 5. Plot a histogram of Sepal Width. 6. Plot a scatter plot showing the relationship between Petal Length and Petal Width. 7. Find the mean of Sepal Length by species. Hint: You could...
Solve following using Program R studio. Please show code and results. Thank you. 1. Assume that...
Solve following using Program R studio. Please show code and results. Thank you. 1. Assume that ? is a random variable follows binomial probability distribution with parameters 15 and 0.25.   a. Simulate 100 binomial pseudorandom numbers from the given distribution (using set.seed(200)) and assign them to vector called binran. b. Calculate ?(? < 8) using cumulative probability function. c. Calculate ?(? = 8) using probability distribution function. d. Calculate the average of simulated data and compare it with the corresponding...
1. Use R Studio: Include R Code A survey is taken of 250 students, and a...
1. Use R Studio: Include R Code A survey is taken of 250 students, and a phat of 0.48 is found. The same survey is repeated with 1000 students, and the same phat value is found. Compare the two 95% confidence intervals. What is the relationship between them? Is the margin of error for the second one four times smaller? If not, how much smaller is it?
Discuss how to use R programming to solve the following problem. You’re not just writing the...
Discuss how to use R programming to solve the following problem. You’re not just writing the R code, you are also discussing the process. Given a person’s full name in the format of firstName middleName lastName such as Michael Carlos Dumas, write R code(s) to convert it to the format of lastName, middleInitial, firstName. In the case of Michael Carlos Dumas, the converted name is Dumas, C. Michael. Your solution should work with any names that comply with the format....
R Studio Coding Exercise Problem-Set Questions 1-6 # 1) Create the following vector in 1 line...
R Studio Coding Exercise Problem-Set Questions 1-6 # 1) Create the following vector in 1 line of code without using the c() function: # [i] 4 12 20 4 12 20 4 12 # 2) Create a vector of 25 random heights between 54 and 78 inches. Cycle through the vector using a For loop and create a new vector that places each height into a category. People less than 5 feet should be categorized as short, those taller than...
THIS QUESTION REQUIRES THE USE OF R STUDIO. ANY ANSWERS GIVEN THAT ARE NOT IN R...
THIS QUESTION REQUIRES THE USE OF R STUDIO. ANY ANSWERS GIVEN THAT ARE NOT IN R STUDIO CODE WILL NOT SUFFICE. SOLVING WITHOUT THE USE OF R STUDIO IS NOT ACCEPTABLE. The previous question was: Annual salaries for a large company are approximately normally distributed with a mean of 49000 dollars and a standard deviation of 2000 dollars. One manager claims that all of his direct reports are paid "above the 75th percentile" for the company. What is the minimum...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT