Question

When we create an array of values and calculate the standard deviation of the array in...

When we create an array of values and calculate the standard deviation of the array in R (using sd() function) and Python (using std() function from NumPy package.), think and give an explanation why the results are different

Homework Answers

Answer #1

This can be illustrated with an example.

R code pasted below for finding standard deviation

a<-c(10,5,30,20,80,76,38)
sd(a)

Output Screen

Python code pasted below for finding standard deviation

import numpy as np
a=np.array([10,5,30,20,80,76,38])
print(a.std())

Python Code in IDLE pasted

Output Screen

The reason we are getting different results is because of the way by which the standard deviation/variance is calculated. R calculates denominator with  N-1, while numpy calculates denominator with N. We will get a numpy result equal to the R result by using a.std(ddof=1), which tells numpy to use N-1 as the denominator when calculating the variance.

Python code pasted below for finding standard deviation

import numpy as np
a=np.array([10,5,30,20,80,76,38])
print(a.std(ddof=1))

Python Code in IDLE pasted

Output Screen

So now the output of both R and Python numpy are the same.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Develop a python program to - Create a 2D 10x10 numpy array and fill it with...
Develop a python program to - Create a 2D 10x10 numpy array and fill it with the random numbers between 1 and 9 (including 0 and 9). - Assume that you are located at (0,0) (upper-left corner) and want to move to (9,9) (lower-right corner) step by step. In each step, you can only move right or down in the array. - Develop a function to simulate random movement from (0,0) to (9,9) and return sum of all cell values...
how to calculate standard deviation in python without any packages and functions except len(). And ensure...
how to calculate standard deviation in python without any packages and functions except len(). And ensure the outcome is same as the output from r function sd().
Create a 1D numpy array that contains int values (4, 3, 1, 33, 21, 67, 27,...
Create a 1D numpy array that contains int values (4, 3, 1, 33, 21, 67, 27, 89, 34, 67, 99, 89, 12, 43). Hint: You can put these values in a python list and start from there. Write code that prints values (67, 27, 89, 34). You must use the colon : based slicing approach to complete this task. Your code should print the following: [67 27 89 34] Write code to print the average (mean) and median values for...
Explain why we cannot calculate the mean and standard deviation for scores on a categorical variable.
Explain why we cannot calculate the mean and standard deviation for scores on a categorical variable.
What happens when we do not know the standard deviation of a population? What is the...
What happens when we do not know the standard deviation of a population? What is the impact on the formula? why?
Calculate the range, mean absolute deviation (MAD), and the standard deviation of the data. A summer...
Calculate the range, mean absolute deviation (MAD), and the standard deviation of the data. A summer class measured from tip of thumb to tip of pinky in inches. The results were: 6 6.25 7 7 7 7.25 7.25 7.5 7.5 7.5 7.5 7.75 8 9 Can these values be calculated if this were a qualitative (categorical) variable?
1.) A distribution of values is normal with a mean of 240 and a standard deviation...
1.) A distribution of values is normal with a mean of 240 and a standard deviation of 8. Find the interval containing the middle-most 84% of scores: Enter your answer accurate to 1 decimal place using interval notation. Example: (2.1,5.6) Hint: To work this out, 1) sketch the distribution, 2) shade the middle 84% of the data, 3) label unkown data values on the horizontal axis just below the upper and lower ends of the shaded region, 4) calculate the...
In this problem, we explore the effect on the standard deviation of adding the same constant...
In this problem, we explore the effect on the standard deviation of adding the same constant to each data value in a data set. (a) Consider the following data set. 8, 13, 14, 9, 9, and compute s. (b) Add 4 to each data value to get the new data set 12, 17, 18, 13, 13. Compute s. Compare the results of parts (a) and (b). In general, how do you think the standard deviation of a data set changes...
We are going to calculate the standard deviation for the following set of sample data. 1)...
We are going to calculate the standard deviation for the following set of sample data. 1) First, calculate the mean. ¯x=x¯= 2) Fill in the table below. Fill in the differences of each data value from the mean, then the squared differences. 3) Calculate the standard deviation. xxx−¯xx-x¯(x−¯x)2(x-x¯)2 14 4 4 14 5 Total
In this problem, we explore the effect on the standard deviation of adding the same constant...
In this problem, we explore the effect on the standard deviation of adding the same constant to each data value in a data set. Consider the following data set. 8, 7, 7, 17, 10 (a) Use the defining formula, the computation formula, or a calculator to compute s. (Enter your answer to one decimal place.) (b) Add 6 to each data value to get the new data set 14, 13, 13, 23, 16. Compute s. (Enter your answer to one...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT