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)     {        ...
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 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...
Using C++ : What am I doing wrong!?!? Problem Instructions: Implement a program that repeatedly outputs...
Using C++ : What am I doing wrong!?!? Problem Instructions: Implement a program that repeatedly outputs an I of a size entered by the user. Prompt the user for a size. If -1 is entered, quit the program. If an even number or a number smaller than 3 is entered, prompt the user again. Then output a shape of # characters that represent an I. Repeat the program until -1 is entered. What I have so far: #include <iostream> #include...
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...
I need assistance on what I am doing wrong, I've been trying to declare "getRandomLetter" as...
I need assistance on what I am doing wrong, I've been trying to declare "getRandomLetter" as a scope, but haven't found how to all day. It's been about 3+ hours and I still have nothing. Please help fix these and let me know what I am doing wrong (There may be more simple ways of coding all this, but I just need help fixing the errors with current code, thank you). I am trying to have buildAcronym() hold the position...
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
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,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT