"In R, define a function counting the values that are less than 0 for two vectors x=rnorm(50) and y=rnorm(5000) respectively. Define another function to calcute the proportion that values are less than 0 for x and y respectively. Compare calculated proportions with theoretical proportion 0.5, what conclusions can you make?"
Please help me with the source code! Thanks!
R-Code
X=rnorm(50)
length(X)
Z=as.vector(Z)
# Here the Z vector is created now we count the value in X which are less than 0
# Here the R vector is created now we count the value in Y which are less than 0
#In Loop vector Z is created such that if X is less than 0 the value is added. so the last value of this vector is the total count of value in X which are less than 0ifelse(X[1]<0,Z[1]+1,Z[1]+0)
for(i in 2:50)
{
if(X[i]<0)
Z[i]=Z[i-1]+1
else
Z[i]=Z[i-1]
}
Z
Y=rnorm(5000)
R=as.vector(R)
# Here the R vector is created now we count the value in Y which are less than 0
#In Loop vector R is created such that if Y is less than 0 the value is added. so the last value of this vector is the total count of value in Y which are less than 0
ifelse(Y[1]<0,R[1]+1,R[1]+0)
for(i in 2:5000)
{
if(Y[i]<0)
R[i]=R[i-1]+1
else
R[i]=R[i-1]
}
#Here the last value from Z & R is the count of value whcih are less than 0 in X & Y respectively
# The proportion is n/N
p1=Z[50]/50
p2=R[5000]/5000
p1
p2
# Test for Proportion
#H0: p1=0.5 Vs. H1 :p1 not equal to 0.5
#H0:p2=0.5 Vs. H1 :p2 not equal to 0.5
sd=sqrt(0.5*(1-0.5)/50)
Test1=(p1-0.5)/sd
Test1
Test2=(p2-0.5)/sd
Test2
#Calculate p-value to make decision
Prob1=pnorm(Test1,0,1)
Prob2=pnorm(Test2,0,1)
The conclusion is based on pvalue for the test ad it is dependent on X & Y. and Here X & Y are random so the test statistic change every time. The output is of when the program is run.
Run the given code
Output
> X=rnorm(50)
> length(X)
[1] 50
> Z=as.vector(Z)
> # Here the Z vector is created now we count the value in X which are less than 0
> # Here the R vector is created now we count the value in Y which are less than 0
> #In Loop vector Z is created such that if X is less than 0 the value is added. so the last value of this vector is the total count of value in X which are less than 0ifelse(X[1]<0,Z[1]+1,Z[1]+0)
> for(i in 2:50)
+ {
+ if(X[i]<0)
+ Z[i]=Z[i-1]+1
+ else
+ Z[i]=Z[i-1]
+ }
> Z
[1] 0 1 1 2 2 3 3 4 4 5 6 7 8 8 9 9 10 10 10 11 11 11 11 12
[25] 12 13 14 15 15 15 16 16 17 17 17 18 19 20 21 21 21 22 23 24 24 24 25 25
[49] 25 25
> Y=rnorm(5000)
> R=as.vector(R)
> # Here the R vector is created now we count the value in Y which are less than 0
> #In Loop vector R is created such that if Y is less than 0 the value is added. so the last value of this vector is the total count of value in Y which are less than 0
> ifelse(Y[1]<0,R[1]+1,R[1]+0)
[1] 2
> for(i in 2:5000)
+ {
+ if(Y[i]<0)
+ R[i]=R[i-1]+1
+ else
+ R[i]=R[i-1]
+ }
> #Here the last value from Z & R is the count of value whcih are less than 0 in X & Y respectively
> # The proportion is n/N
> p1=Z[50]/50
> p2=R[5000]/5000
> p1
[1] 0.5
> p2
[1] 0.5014
>
> # Test for Proportion
> #H0: p1=0.5 Vs. H1 :p1 not equal to 0.5
> #H0:p2=0.5 Vs. H1 :p2 not equal to 0.5
> sd=sqrt(0.5*(1-0.5)/50)
> Test1=(p1-0.5)/sd
> Test1
[1] 0
> Test2=(p2-0.5)/sd
> Test2
[1] 0.01979899
> #Calculate p-value to make decision
> Prob1=pnorm(Test1,0,1)
> Prob2=pnorm(Test2,0,1)
> Prob1
[1] 0.5
> Prob2
[1] 0.5078981
Here for both X & Y p-value is >0.05. so we fail to reject null hypothesis than proportion is 0.5
"In R, define a function counting the values that are less than 0 for two vectors...
Creat a matlab function that calculates: f(x, y) = xy/(exp(x) + exp(-y)) for two vectors of values x and y. Name your function function_xy: The inputs should be in the same order: .X: vector of values • y: vector of values The ouput is: • A: is the calculated array f(x,y) Function 1 function (Outputs] = YourFunctionName(Inputs) 2 % Input code here end Code to call your function 1 X=-4:0.5:4 2 y=-5:1:5 4 A = function xy(x,y)
Find k so that the following function is continuous on any interval:f(x)= kx 0 (less than or equal to) x (less than) 23x^22 (less than or equal to x)i know the answer is 12 but i don't know how to arrive at that. could you please walk me through the steps? thanks.
Can I please get some help with this?? It's matlab. Code 1 1) Define a function as [NE]- nb_elemt24( n1,n2). 2) Define two vectors A and B by randi(10, [1,n1]) and randi(10, [1,n2]), respectively. 3) Using the commend [C1,D1] hist(A, unique(A)) to find four vectors C1, D1 (for A) and C2, D2 (for B), respectively. Here, vector C1 shows how many times each element of A is repeated. And the elements of vector D1 are the same as elements of...
Below is the graph of the function y(x) which is a solution to the differential equation dy dx = f(x, y). please help me, thanks so much Below is the graph of the function y(I) which is a solution to the differential equation due = f(,y). The 2-values of the labeled points below are -3, -2, and 1.7 respectively. Suppose that for geometric reasons we also know the y-values of points A and B. I wish to use Euler's method...
MATLAB Define the following computer programming terms and give an example of each. MATLAB example Sequence Selection structure- Repetition structure - Relational operators (True = 1, False = 0) Logical operators (True = 1, False =0) And Or Less than Less than or equal to Greater than Greater than or equal to Equal to Not equal to Not ans ans Type the following relational operator commands into MATLAB in the command window one at a time. Write the results to...
Need help with number 3, thanks! isplays l itnuml is less than num2. 2. (50+30- 80 Points) Write a MATLAB function numcomp502 (numl, num2) that takes two numbers numl and as input and returns num3 as output, such that num3 is equal to 0, 1, and-1 depending on whether numl is equal to, greater than or less than num2 respectively. Test your code with the pairs (10, 5), (-3,-3), and (2, 10) as input. Attach a screen-shot. 3. 80 Points...
Define the cumulative distribution function F(t) oft by F(t) = P(W <t). Shade the region consisting of each point (x, y) in which x > 0, and F(X) < y < 1. Compute the area of the shaded region. Let X be binomial with parameters n = 10 and p = 0.5. Compute P(X = 5). Compute P(3 sX s 6). Compute P(X s 3). Submit You have used 0 of 3 attempts The annual income of graduates from college...
please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks.please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me...
Matlab & Differential Equations Help Needed I need help with this Matlab project for differential equations. I've got 0 experience with Matlab other than a much easier project I did in another class a few semesters ago. All we've been given is this piece of paper and some sample code. I don't even know how to begin to approach this. I don't know how to use Matlab at all and I barely can do this material. Here's the handout: Here's...
I DESPERATELY NEED HELP WITH THIS DIFFERENTIAL EQUATIONS MATLAB ASSIGNMENT IM SUPPOSED TO BE LEARNING BUT WE HAVE A SUB AND HE DIDN'T TEACH IT! ITS EULER AND IMPROVED EULER IN MATLAB! HERE IS THE LINK FOR THE IMAGE FILE THAT SHOWS THE FULL INSTRUCTIONS FOR THE CODE. https://imgur.com/a/gjmypLs Also, here is my code so far that I borrowed form an old assignment but the data is all wrong and the application of the code is slightly different so either...