standard-deviation

Why does numpy std() give a different result to matlab std()?

做~自己de王妃 提交于 2019-12-17 10:13:05
问题 I try to convert matlab code to numpy and figured out that numpy has a different result with the std function. in matlab std([1,3,4,6]) ans = 2.0817 in numpy np.std([1,3,4,6]) 1.8027756377319946 Is this normal? And how should I handle this? 回答1: The NumPy function np.std takes an optional parameter ddof : "Delta Degrees of Freedom". By default, this is 0 . Set it to 1 to get the MATLAB result: >>> np.std([1,3,4,6], ddof=1) 2.0816659994661326 To add a little more context, in the calculation of

Weighted standard deviation in NumPy

守給你的承諾、 提交于 2019-12-17 04:17:24
问题 numpy.average() has a weights option, but numpy.std() does not. Does anyone have suggestions for a workaround? 回答1: How about the following short "manual calculation"? def weighted_avg_and_std(values, weights): """ Return the weighted average and standard deviation. values, weights -- Numpy ndarrays with the same shape. """ average = numpy.average(values, weights=weights) # Fast and numerically precise: variance = numpy.average((values-average)**2, weights=weights) return (average, math.sqrt

existing function to combine standard deviations in R?

旧街凉风 提交于 2019-12-13 12:07:17
问题 I have 4 populations with known means and standard deviations. I would like to know the grand mean and grand sd. The grand mean is obviously simple to calculate, but R has a handy utility function, weighted.mean(). Does a similar function exist for combining standard deviations? The calculation is not complicated, but an existing function would make my code cleaner and easier to understand. Bonus question, what tools do you use to search for functions like this? I know it must be out there,

Adding standard deviation to barplot() in R

对着背影说爱祢 提交于 2019-12-13 10:44:16
问题 In R I have the following dataframe: Group mean sd 1 1 21.2 5.202563 2 2 28.4 6.113737 3 3 21.8 2.529822 I would like to create a barplot with the means and the standard deviations as arrows on top of the means like this example: This is the code I have so far: barCenters <- barplot(height = Ymeans12stdev$mean,main = "Average Time per Group", xlab = "Group", ylab = "Time") However, I am not succeeding in adding the standard deviation bars. Can anyone solve this ? :) 回答1: with base R, you can

Using BigQuery to find outliers with standard deviation results combined with WHERE clause

こ雲淡風輕ζ 提交于 2019-12-13 07:26:29
问题 Standard deviation analysis can be a useful way to find outliers. Is there a way to incorporate the result of this query (finding the value of the fourth standard deviation away from the mean)... SELECT (AVG(weight_pounds) + STDDEV(weight_pounds) * 4) as high FROM [publicdata:samples.natality]; result = 12.721342001626912 ...Into another query that produces information about which states and dates have the most babies born heavier that 4 standard deviations from average? SELECT state, year,

How to calculate the standard deviation for every 100 points in a nx3 vector?

こ雲淡風輕ζ 提交于 2019-12-13 04:13:51
问题 Suppose I have a matrix with n rows, each containing three coordinates, (x, y and z). I want to calculate the standard deviation for every 100 set of points in MATLAB. For example, for the first 100 x coordinates I apply std, then same for the y and z coordinates, and so on... eventually I have one set of x, y and z values for every 100 points. How do I do that? 回答1: I would do this: M = randn(120,3); % substitute this for the actual data; 3 columns N = 100; % number of elements in each set

isinf(mu) error in Scipy stats when calling std for exponweib?

非 Y 不嫁゛ 提交于 2019-12-12 04:23:24
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 2 years ago . I have been getting this error when I call std on a frozen exponweib distribution? Here is the code: d = st.exponweib params = d.fit(y) arg = params[:-2] loc = params[-2] scale = params[-1] rv1 = d(arg,loc,scale) print rv1.std() The parameters after fitting are: arg: (3.445136651705262, 0.10885378466279112) loc: 11770.05 scale: 3.87424773976 Here is the error: ValueError

How to plot a probability density function on a histogram?

百般思念 提交于 2019-12-11 23:05:13
问题 My function called DicePlot, simulates rolling 10 dice 5000 times. In the function, it calculates the sum of values of the 10 dice of each roll, which will be a 1 × 5000 vector, and plot relative frequency histogram with edges of bins being selected in the same manner where each bin in the histogram should represent a possible value of for the sum of the dice. The mean and standard deviation are computed of the 1 × 5000 sums of dice values and the probability density function of normal

2D histogram coloured by standard deviation in each bin

微笑、不失礼 提交于 2019-12-11 17:09:47
问题 Is there a way to create a 2D histogram, in Python, where each bin is coloured by standard deviation of points in each bin rather than by point density? For example, I have a set of 2D data that looks as follows: But I'd like to turn this into a 2D histogram where I expect the purity to decrease in the middle of the gradient-like structure. I realise there's no code in this question but if I could be pointed in the right direction to do this efficiently I's be very grateful. Perhaps there is

Weighted Standard Deviation and Quartiles in excel

非 Y 不嫁゛ 提交于 2019-12-11 12:08:08
问题 I've got a dataset with aggregated data and total values per category. Example: Now I want to create a boxplot to visualize the insights of this dataset and not just the (weighted) averages. I've found some formula's for weighted standard deviation, but nothing I have been able to translate to an excel formula. Is there a default formula that does this in excel? If not, some suggestions on how to handle this? And how about the quartiles? Or is the best way to somehow expand the dataset to