Question
I need to fix an error that deals with length of argument: prompt: Write a function BCI that calculate bootstrap confidence interval. Use three parameters
I need to fix an error that deals with length of argument:
prompt: Write a function BCI that calculate bootstrap confidence interval. Use three parameters with data: dataframe, R:number of bootstrap, level: confidence level. Find the 95% bootstrap confidence interval for the mean of the workingout hours. (Use R=1000 and set.seed(12345))
data called newsem7:that has over 400 responses with some NA values
Lower classmen are <=3 and upper classmen are >3
semester | hours working out |
---|---|
3 | 5 |
8 | 14 |
6 | NA |
5 | 16 |
2 | 8 |
7 | 4 |
1 | 10 |
0 | 4 |
5 | NA |
7 | 8 |
2 | 13 |
6 | 18 |
5 | 7 |
2 | NA |
0 | 4 |
1 | 8 |
4 | 9 |
3 | 3 |
6 | 18 |
2 | 1 |
4 | 7 |
5 | 7 |
3 | 23 |
2 | 21 |
Here is what I have so far:
lowclass<-subset(newsem7, Semester<=3) highclass<-subset(newsem7,Semester>3)
cflevel<-function(vector, interval){ vectorsd<-sd(vector) nsize<-length(vector) vectormean<-mean(vector) errorvalue<-qt((interval+1)/2,df=nsize-1 * vectorsd/sqrt(nsize)) result<-c("lower"=vectormean-errorvalue,"upper"=vectormean+errorvalue) return(result) }
BCI<-function(data, R, level){ set.seed(12345) vectormean<-replicate(R,mean(sample(as.numeric(data),length(data))replace=T, na.rm=T)) cflevel(as.numeric(vectormean),0.95) } BCI(newsem7$Hours.spent.workingout.per.wee , 1000, 0.95) //when I called this function I get an error:
error: Error in integer(n) : invalid 'length' argument
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