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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started