Question

In: Computer Science

Run the following R commends. set.seed(2019) x = rnorm(100,mean=0, sd=2) y = rnorm(100,mean=0, sd=20) [NOTE: Do...

Run the following R commends.
set.seed(2019) x = rnorm(100,mean=0, sd=2) y = rnorm(100,mean=0, sd=20)
[NOTE: Do NOT use built-in functions which can directly solve the problems.]
(1) Compute the means of values in the vectors x and y, respectively. Which one is more close to zero? Explain the reason.
(2) Compute the sample standard deviations of values in the vector x and y, respectively.
(3) Find the index positions in x and y of the values between -5 and 5, respectively

Solutions

Expert Solution

1. Computing the mean value of vector x and y :

We know that the mean = sum of all elements in the array / length of the array.

  For Example : Mean o values in array a = [1,2,3,4,5] is :

mean = (1+2+3+4+5) / 5 = 3

Let's solve the question using R :

#Given  

set.seed(2019)

x = rnorm(100,mean=0, sd=2)

y = rnorm(100,mean=0, sd=20)

#Computin mean of x

mean_x = sum(x) / length(x)   # here sum function add all element of the vector and length function fetch the length vector

#Computing the mean of y

mean_y = sum(y) / length(y)

#Printing the value of mean_x and mean_y

prinit(mean_x) # -0.146668

print(mean_y)   #-3.404389

--> Here we get the mean of vector x close to zero because of the small standard deviation. A smaller standard deviation indicates that more of the data is clustered about the mean.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

2. Computing the standard deviation for vector x and y :

#Steps to Compute Standard Deviation :   

  1. Calculate the mean.
  2. Subtract the mean from each observation.
  3. Square each of the resulting observations.
  4. Add these squared results together.
  5. Divide this total by the number of observation
  6. Use the positive square root

#Here we will use the value of variable mean_x and mean_y   

sd_x = sqrt(sum((x-mean_x)^2) / (length(x) - 1))

sd_y =   sqrt(sum((y-mean_y)^2) / (length(y) - 1))

  #printing the sd values of x and y

print(sd_x) #1.810907

print(sd_y) #19.7784

------------------------------------------------------------------------------------------------------------------------------------------------------------------

3. Finding the index for the value between -5 to 5 :

# simple code

  which( x == x[ x>= -5 && x<=5])

# [x>= -5 && x<=5] will fetch the value between -5 to 5 from vector x

# We then compare the original array to the boolean indexed vector

# which function simply print the position of those vector

#Similarly for y

  which( y == y[ y>= -5 && y<=5])

----------------------------------------------------------------------------------------------------------------------------------------------------------------------


Related Solutions

Use student-t to derive the following paired test set.seed(20) girls_height<- rnorm(50, mean = 160, sd =...
Use student-t to derive the following paired test set.seed(20) girls_height<- rnorm(50, mean = 160, sd = 30) boys_height<- rnorm(50, mean = 172, sd = 30) #------------------------------------------------------------- State the hypothesis for the paired-test of the mean of # girls' height and boys' height. Check the three assumptions before running the student t test # for the samples. You need to write and run the code, and # report the results.
student_id=100 set.seed(student_id) Group1=round(rnorm(15,mean=10,sd=4),2) Group2= round(rnorm(12,mean=7,sd=4),2) For this question you are not allowed to use the lm()...
student_id=100 set.seed(student_id) Group1=round(rnorm(15,mean=10,sd=4),2) Group2= round(rnorm(12,mean=7,sd=4),2) For this question you are not allowed to use the lm() command in R or the equivalent of lm() in python or other software. If you want to use a software, only use it as a calculator. So if you are using R, you may only use mean(), sum(), qt() and of course +,-,*,/. (Similar restrictions for Python, excel or others). Consider all the 27 numbers printed under Group1 and Group2 as your y values,...
Find y as a function of x if y′′′+25y′=0 y(0)=2,  y′(0)=20,  y′′(0)=−100 y(x)=
Find y as a function of x if y′′′+25y′=0 y(0)=2,  y′(0)=20,  y′′(0)=−100 y(x)=
Q1. The following is some R code followed by output. > set.seed(24); y1 = rnorm(30, 10,...
Q1. The following is some R code followed by output. > set.seed(24); y1 = rnorm(30, 10, 5) > set.seed(34); y2 = rnorm(25, 11, 5) > t.test(y1,y2, var.equal = TRUE, mu =0, conf.level = 0.90) Two Sample t-test data: y1 and y2 t = ? , df = ?, p-value = ? alternative hypothesis: true difference in means is not equal to 0 90 percent confidence interval: -3.6460449 0.2757534 sample estimates: mean of x mean of y 9.154402 10.839548 What is...
Given Fxy(x,y)=u(x)u(y)[1-Exp(-x/2)-Exp(-y/2)+Exp(-(x+y)/2)]. Note: The step functions mean that Fxy(x,y)=0 for either or both x<0 and y<0....
Given Fxy(x,y)=u(x)u(y)[1-Exp(-x/2)-Exp(-y/2)+Exp(-(x+y)/2)]. Note: The step functions mean that Fxy(x,y)=0 for either or both x<0 and y<0. Any x or y argument range below zero must be truncated at zero. Determine: a) P{X<=1,Y<=2} Ans: 0.2487 b) P{0.5<X<1.5} Ans: 0.3064 c) P{-1.5<X<=2, 1<Y<=3} Ans: 0.2423
Consider the equation x^2+(y-2)^2 and the relation “(x, y) R (0, 2)”, where R is read...
Consider the equation x^2+(y-2)^2 and the relation “(x, y) R (0, 2)”, where R is read as “has distance 1 of”. For example, “(0, 3) R (0, 2)”, that is, “(0, 3) has distance 1 of (0, 2)”. This relation can also be read as “(x, y) belongs to the circle of radius 1 with center (0, 2)”. In other words: “(x, y) satisfies this equation if, and only if, (x, y) R (0, 2)”. Does this equation determine a...
R is included in (R-{0} )x(R-{0} ) R = {(x,y) : xy >0} Show that R...
R is included in (R-{0} )x(R-{0} ) R = {(x,y) : xy >0} Show that R is an equivalent relation and find f its equivalent classes
Q3. (This question is based in R) Now use the simulation ("X = rnorm(1000, mean =...
Q3. (This question is based in R) Now use the simulation ("X = rnorm(1000, mean = 10, sd = 2)", "Y = rnorm(1000, mean = 5, sd = 3)") to estimate the distribution of X+Y and create confidence intervals. A) Form a set of Xs and Ys by repeating the individual experiment for B = 2000 times, where each experiment has n = 1000 samples. You may want to write a for loop and create two matrices "sample_X" and "sample_Y"...
Determine y’, a, and b for the following data: x 0 20 40 60 80 100...
Determine y’, a, and b for the following data: x 0 20 40 60 80 100 120 140 160 180 y 0.01 0.12 0.24 0.38 0.51 0.67 0.84 1.01 1.15 1.31 a)calculate the 0.95 confidence intervals for α and β. b)test to see if a relationship between x and y exists. c)determine the 0.95 confidence limits when x = 90 for: i. α + βx ii. Any one y’ d)determine the 0.95 confidence limits when x = 200 for: i.....
Solve the following differential equations: 1.) y"(x)+ y(x)=4e^x ; y(0)=0, y'(0)=0 2.) x"(t)+3x'(t)+2x(t)=4t^2 ; x(0)=0, x'(0)=0
Solve the following differential equations: 1.) y"(x)+ y(x)=4e^x ; y(0)=0, y'(0)=0 2.) x"(t)+3x'(t)+2x(t)=4t^2 ; x(0)=0, x'(0)=0
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT