Question

In: Statistics and Probability

What am I doing wrong in my bootstrap code for R? x<-c(30, 37, 36, 43, 42,...

What am I doing wrong in my bootstrap code for R?

x<-c(30, 37, 36, 43, 42, 43, 43, 46, 41, 42)
n = 10
x=pnorm(n,mean=40.3,sd=4.6)
mu_0=40.3
s.mean=mean(x)
s.sd=sd(x);s.sd
[1] NA
t.sample=(s.mean-mu_0)/(s.sd/sqrt(n))
B=10000
t=c()
count.less=0
count.more=0
for(j in 1:B)
+ { b.smpl = x[sample(1:n, size = n,replace=TRUE)]
+ ybar.bs = mean(b.smpl)
+ sd.bs = sd(b.smpl)
+ t[j] = (ybar.bs - s.mean)/(sd.bs/sqrt(n))
+ if(t[j]>=t.sample){ count.more=count.more+1}
+ if(t[j]<=t.sample){ count.less=count.less+1}
+ }
Error in if (t[j] >= t.sample) { : missing value where TRUE/FALSE needed
pvalue.right=count.more/B;pvalue.right
[1] 0
pvalue.left=count.less/B;pvalue.left
[1] 0
pvalue/two=2*min(pvalue.right,pvalue.left)
Error in pvalue/two = 2 * min(pvalue.right, pvalue.left) :
object 'pvalue' not found

Solutions

Expert Solution

why error has occur in your code is written in Comment using #

x<-c(30, 37, 36, 43, 42, 43, 43, 46, 41, 42)
n = 10
x=pnorm(n,mean=40.3,sd=4.6) # here your using x again which already used in first line of code so change it
mu_0=40.3
s.mean=mean(x)
s.sd=sd(x);s.sd # here we getting NA because in the 3rd line of code your using  x=pnorm(n,mean=40.3,sd=4.6) and its output will be single number so NA occurs
[1] NA
t.sample=(s.mean-mu_0)/(s.sd/sqrt(n))
B=10000
t=c()
count.less=0
count.more=0
for(j in 1:B)
+ { b.smpl = x[sample(1:n, size = n,replace=TRUE)]
+ ybar.bs = mean(b.smpl)
+ sd.bs = sd(b.smpl)
+ t[j] = (ybar.bs - s.mean)/(sd.bs/sqrt(n))
+ if(t[j]>=t.sample){ count.more=count.more+1}
+ if(t[j]<=t.sample){ count.less=count.less+1}
+ }
Error in if (t[j] >= t.sample) { : missing value where TRUE/FALSE needed # when you do the changes which are mention above this error will not occur
pvalue.right=count.more/B;pvalue.right
[1] 0
pvalue.left=count.less/B;pvalue.left
[1] 0
pvalue/two=2*min(pvalue.right,pvalue.left) # here you should use  pvalue=2*min(c(pvalue.right,pvalue.left))
Error in pvalue/two = 2 * min(pvalue.right, pvalue.left) :
object 'pvalue' not found

Corrected R-code

x<-c(30, 37, 36, 43, 42, 43, 43, 46, 41, 42)
n = 10
p=pnorm(n,mean=40.3,sd=4.6)
mu_0=40.3
s.mean=mean(x)
s.sd=sd(x);s.sd
t.sample=(s.mean-mu_0)/(s.sd/sqrt(n))
B=10000
t=c()
count.less=0
count.more=0
for(j in 1:B)
{ b.smpl = x[sample(1:n, size = n,replace=TRUE)]
ybar.bs = mean(b.smpl)
sd.bs = sd(b.smpl)
t[j] = (ybar.bs - s.mean)/(sd.bs/sqrt(n))
if(t[j]>=t.sample){ count.more=count.more+1}
if(t[j]<=t.sample){ count.less=count.less+1}
}
pvalue.right=count.more/B
pvalue.right
pvalue.left=count.less/B
pvalue.left
pvalue=2*min(c(pvalue.right,pvalue.left))
pvalue


Related Solutions

Okay, can someone please tell me what I am doing wrong?? I will show the code...
Okay, can someone please tell me what I am doing wrong?? I will show the code I submitted for the assignment. However, according to my instructor I did it incorrectly but I am not understanding why. I will show the instructor's comment after providing my original code for the assignment. Thank you in advance. * * * * * HourlyTest Class * * * * * import java.util.Scanner; public class HourlyTest {    public static void main(String[] args)     {        ...
I just need 3 and 5. I am not sure what I am doing wrong. I...
I just need 3 and 5. I am not sure what I am doing wrong. I get different numbers every time. Superior Markets, Inc., operates three stores in a large metropolitan area. A segmented absorption costing income statement for the company for the last quarter is given below: Superior Markets, Inc. Income Statement For the Quarter Ended September 30 Total North Store South Store East Store Sales $ 4,800,000 $ 960,000 $ 1,920,000 $ 1,920,000 Cost of goods sold 2,640,000...
2017-2018 Goals 49 44 43 42 42 41 40 40 39 39 39 37 36 36...
2017-2018 Goals 49 44 43 42 42 41 40 40 39 39 39 37 36 36 35 35 34 34 34 34 2012-2013 Goals 32 29 28 26 23 23 23 22 22 21 21 21 20 20 20 19 19 18 18 18 2007-2008 Goals 65 52 50 47 43 43 42 41 40 40 38 38 36 36 35 34 34 33 33 32 Given the above three sets of data, we want to compare the three seasons...
I am getting 7 errors can someone fix and explain what I did wrong. My code...
I am getting 7 errors can someone fix and explain what I did wrong. My code is at the bottom. Welcome to the DeVry Bank Automated Teller Machine Check balance Make withdrawal Make deposit View account information View statement View bank information Exit          The result of choosing #1 will be the following:           Current balance is: $2439.45     The result of choosing #2 will be the following:           How much would you like to withdraw? $200.50      The...
What am i doing wrong. I want for the program to run through then when it...
What am i doing wrong. I want for the program to run through then when it gets to "do you want to play again?enter yes or no" if they choose yes I want it to run again if they choose no then end. def play(): print("Welcome to the Game of Life!") print("A. Banker") print("B. Carpenter") print("C. Farmer") user_input = input("What is your occupation? ").upper() if user_input == "A": money = 100 elif user_input == "B": money = 70 elif user_input...
What am I doing wrong in this titration problem? Calculate the ph at the equivalence point...
What am I doing wrong in this titration problem? Calculate the ph at the equivalence point for the following titration 0.20M HCl versus 0.20M methylamine (CH3NH2). The Ka of methylammonium is 2.3x10^-11. First I have to divide .20M methylamine by 2 (Why?) to get .10M Then, I set up the equilibrium: (2.3 x 10^-11) = x^2 / .10M Since the ka is SO small, I just multiplied .10 with (2.3 x 10^-11) to get 2.3x10^-12, which is wrong. Why is...
hi i do not know what is wrong with my python code. this is the class:...
hi i do not know what is wrong with my python code. this is the class: class Cuboid: def __init__(self, width, length, height, colour): self.__width = width self.__length = length self.__height = height self.__colour = colour self.surface_area = (2 * (width * length) + 2 * (width * height) + 2 * (length * height)) self.volume = height * length * width def get_width(self): return self.__width def get_length(self): return self.__length def get_height(self): return self.__height def get_colour(self): return self.__colour def set_width(self,...
Answer the following bootstrap question by showing the R code : A set of data X...
Answer the following bootstrap question by showing the R code : A set of data X contains the following numbers: 119.7 104.1 92.8 85.4 108.6 93.4 67.1 88.4 101.0 97.2 95.4 77.2 100.0 114.2 150.3 102.3 105.8 107.5 0.9 94.1 We generated n = 20 observations Xi = 10 Wi+100, where Wi has a contaminated normal distribution with proportion of contamination 20% and σc = 4. Suppose we are interested in testing: H0 : μ = 90 versus H1 :...
For the following Grouped Frequency Distribution below : class 7-12 13-18 19-24 25-30 31-36 37-42 43-48...
For the following Grouped Frequency Distribution below : class 7-12 13-18 19-24 25-30 31-36 37-42 43-48 f 5 6 2 4 1 3 7 1) Find ( Mean , Mode , Standard Deviation , Variance ) 2) Sketch : Histogram , Polygon , and an Ogive
The Table in my homework question below is completely wrong. I am not sure where I...
The Table in my homework question below is completely wrong. I am not sure where I went wrong in my calculations but coud you rework this question and answer the parts below?? Here are earnings per share for two companies by quarter from the first quarter of 2009 through the second quarter of 2012. Forecast earnings per share for the rest of 2012 and 2013. Use exponential smoothing to forecast the third period of 2012, and the time series decomposition...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT