Question

In: Math

Use R studio to do it I need the code, thx. Write your own function, called...

Use R studio to do it I need the code, thx.

Write your own function, called go_mean(). The user will provide a vector and the number of repetitions for the simulation. Your function should:
- Create an empty vector
- Draw a sample the same size as the vector, selecting from the vector itself, with replacement. - Compute the mean of the vector, and store it in the empty vector.

- Repeat the steps above n times.
- Compute an 80% confidence interval of the vector of means.
- Print the interval on the console so that it looks something like this: "Lower limit = value, Upper

limit = value", where the values are rounded to 2 decimal places.

Test your new function by creating a vector of 8000 z scores, and applying your function with 1000 reps

Solutions

Expert Solution

80% confidence interval is level of significance of

The critical value of z is

Using standard normal table/R we get the critical value as

If is the mean of vector of means then 80% confidence interval is

where is the standard error of mean, which is the sample standard deviation of vector of means

R code to implement all these (all statements starting with # are comments)

get the following output

Code in text format is below

go_mean<-function(x,n){

#create an empty vector to hold sample mean

xbar<-numeric(n)

for (i in 1:n) { #repeat n times

#Draw a sample the same size as the vector, with replacement

s<-sample(x,length(x),replace=TRUE)

#Compute the mean of the vector

xbar[i]<-mean(s)

}

#Compute an 80% confidence interval of the vector of means

cl<-80

alpha<-1-cl/100

zcrit<-qnorm(alpha/2,0,1,lower.tail=FALSE)

#get the statndard error of mean

se<-sd(xbar)

#get the lower limit

ll<-mean(xbar)-zcrit*se

#get the upper limit

ul<-mean(xbar)+zcrit*se

sprintf('Lower limit =%.2f, Upper limit = %.2f ',ll,ul)

}

#set the random seed

set.seed(123)

#create a vector of 8000 z scores

z<-rnorm(8000,0,1)

#call the function for n=1000 reps

go_mean(z,1000)


Related Solutions

I need the java code for a 4-function calculator app on android studio (do this on...
I need the java code for a 4-function calculator app on android studio (do this on android studio). Please make sure all the requirements shown below are followed (such as the error portion and etc). The topic of this app is to simply create a 4 function calculator which calculates math expressions (add, subtract, multiply, and divide numbers). The requirements are the following : - The only buttons needed are 0-9, *, /, +, -, a clear, and enter button...
I need the java code for a 4 function calculator app on android studio (do this...
I need the java code for a 4 function calculator app on android studio (do this on android studio) - The requirements are the following : - The only buttons needed are 0-9, *, /, +, -, a clear, and enter button - Implement the onclicklistener on the main activity - The calcuator should use order of operations (PEMDAS) - It should be able to continue from a previous answer (Ex: If you type 2+6 the calculator will display 8....
Hello, i have this excersice in R studio Write a function in R that generates simulations...
Hello, i have this excersice in R studio Write a function in R that generates simulations of a Poisson random variable as follows: define I = [λ], and use p_i + 1 = λp_i / (i + 1) to determine F recursively. Generate a random number U, determine if X≤I by comparing if U≤F (I). If X≤I searches downwards starting at I, otherwise it searches upwards starting from I + 1. Compare the time it takes for the two algorithms...
I need the JAVA code for a 4 function calculator app on andriod studio - The...
I need the JAVA code for a 4 function calculator app on andriod studio - The requirements are the following : - The only buttons needed are 0-9, *, /, +, -, a clear, and enter button - Implement the onclicklistener on the main activity - The calcuator should use order of operations (PEMDAS) - It should be able to continue from a previous answer (Ex: If you type 2+6 the calculator will display 8. If you then multiple by...
R studio questions Write up your answers and paste the R code Copy and paste all...
R studio questions Write up your answers and paste the R code Copy and paste all plots generated. First create a sample drawn from a normal random variable. R has many distributions for which you can get probabilities and draw random numbers. We are going to use the normal. Go to help in R and type in rnorm. You will see a write up for functions associated with the normal distribution. dnorm is the density; pnorm is the probability distribution...
USE R CODING! Pleaseee I need the code With R coding Obs: it supposed to use...
USE R CODING! Pleaseee I need the code With R coding Obs: it supposed to use probability density function like X ~ Binomial( n ,p ) dbinom(X=?, n, prob) pbinom(X=?, n, prob) rbinmo(幾個符合二項分配的X, n, prob) X~Poisson (lamda) dpois(X=?, lamda) ppois (X=?, lamda) rpois (X, lamda) **Suppose the random variable X obeys the binomial allocation B (n=100, p=0.1) (a) Use X as the binomial allocation to calculate P(12≤X≤14) (b) In practice, when np ≥ 5 and n(1-p) ≥ 5, X will...
I need the code for following in C++ working for Visual studio please. Thanks Use a...
I need the code for following in C++ working for Visual studio please. Thanks Use a Struct to create a structure for a Player. The Player will have the following data that it needs maintain: Struct Player int health int level string playerName double gameComplete bool isGodMode Create the 2 functions that will do the following: 1) initialize(string aPlayerName) which takes in a playername string and creates a Player struct health= 100 level= 1 playerName = aPlayerName gameComplete = 0...
Write your own R-function for the linear regression using qr() function. You must not use solve()...
Write your own R-function for the linear regression using qr() function. You must not use solve() function. The input of your function would be a design matrix X and a response vector y and the output must contain - least sqaure estimates and the corresponding stnadard errors. - residuals and MSE - fitted values - ANOVA table
In R/ R Studio, what code would I enter to find the answers to these questions?...
In R/ R Studio, what code would I enter to find the answers to these questions? What is the code to find the descriptive/ summary statistics of all variables in a data set and how do i find the mean values? What is the code to measure the skewness measure of delta time for all of all the values in the data set? What is the code to draw a histogram and q-q plot of the natural log of a...
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?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT