Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!