Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

R studio- Help declaring 'n' variable in my code. Question: Carry out the following bootstrap sampling scheme. Draw B=2000 bootstrap samples. For each sample, calculate

R studio- Help declaring 'n' variable in my code.

Question:

Carry out the following bootstrap sampling scheme. Draw B=2000 bootstrap samples. For each sample, calculate the sample average, using the R built-in function "mean".

You can use a for loop to do this, where the loop index $i$ runs from 1 to $B$. Inside the loop you can do the bootstrap sampling with "bdata=sample(data,n,replace=T)", where $n$ is the number of sample in your dataset

and then you need something similar to:

"bootstrapmeans=c(bootstrapmeans,mean(bdata))".

also, make a histrogram of the bootstrapmeans with 20 bars.

My code:

```{r} set.seed(87612345) # use a variable called B for the number of bootstrap sample (2000) # use a variable called n for the number of sample B=2000 bootstrapmeans=NULL for (i in 1:B){ bdata=sample(data,n,replace=T) bootstrapmeans=c(bootstrapmeans,mean(bdata)) } hist(bootstrapmeans,nclass=20) ``` ---->Error in sample(data, n, replace = T) : object 'n' not found

Must declare n as a variable.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Art Of Proof Basic Training For Deeper Mathematics

Authors: Matthias Beck, Ross Geoghegan

1st Edition

1441970231, 9781441970237

More Books

Students also viewed these Mathematics questions

Question

Is it eyewitness or hearsay evidence?

Answered: 1 week ago

Question

which command is used to verify and correct file systems

Answered: 1 week ago