algorithm,math,statistics,variance,standard-deviation

Given the forward formulas Mk = Mk-1 + (xk – Mk-1) / k Sk = Sk-1 + (xk – Mk-1) * (xk – Mk), it's possible to solve for Mk-1 as a function of Mk and xk and k: Mk-1 = Mk - (xk - Mk) / (k - 1)....

r,ggplot2,mean,facet,standard-deviation

Here's my approach to the solution outlined by @DavidArenburg (though I simplified the data a little, using simple cumulative statistics and a plain index): library(tidyr) library(dplyr) library(TTR) v <- rnorm(1000) df <- data.frame(index = 1:1000, variable = v, mean = runMean(v, n=1, cumulative=TRUE), sd = runSD(v, n=1, cumulative=TRUE)) dd <-...

r,standard-deviation,weighted-average

Here's one way: mean_1 <- 6.27 sd_1 <- 5.9 mean_2 <- 5.91 sd_2 <- 4.9 n_1 <- 34 n_2 <- 6 # the combined mean mean_combined <- weighted.mean(c(mean_1, mean_2), c(n_1, n_2)) # [1] 6.216 # the combined standard deviation (if the samples are not correlated) sd_combined <- sqrt(sd_1^2 + sd_2^2)...

r,normal-distribution,standard-deviation

Here's another version using ggvis: library(dplyr) library(ggvis) ## -- data generation copied from @NickK -- ## data.frame(group = letters[1:4], m = c(130, 134, 132, 105), s = c(20, 14, 12, 10)) %>% group_by(group) %>% do(data_frame(group = .$group, x = 50:200, y = dnorm(x, .$m, .$s), withinSd = abs(x - .$m)...

c++,math,size,containers,standard-deviation

Almost. By table 96 - container requirements in N3797, all containers in the standard library must provide a member function size. It shall have constant execution time and return the value of distance(a.begin(),a.end()) for a container a. However, there is one (and only one) exception mentioned later on: A forward_list...

python,numpy,standard-deviation

NumPy's std yields the standard deviation, which is usually denoted with "sigma". To get the 2-sigma or 3-sigma ranges, you can simply multiply sigma with 2 or 3: print [x.mean() - 3 * x.std(), x.mean() + 3 * x.std()] Output: [-27.545797458510656, 52.315028227741429] For more detailed information, you might refer to...

php,mysql,statistics,standard-deviation

I would recommend doing the calculation manually: select avg(case when col > t.avg then col - t.avgcol end), avg(case when col < t.avg then t.avgcol - col end) from table t cross join (select avg(col) as avgcol) as tavg; This gives the average. If you want the "variance", just square...

java,loops,methods,average,standard-deviation

Try: long sum = 0; long sumSquare = 0; for(int c = 0 ; c < 10 ; c++) { long start = System.nanoTime(); // do work long end = System.nanoTime(); sum += end - start; sumSquare += Math.pow(end - start, 2); } double average = (sum * 1D) /...

numpy,linear-regression,standard-deviation

As already mentioned by @ebarr in the comments, you can use np.polyfit to return the residuals by using the keyword argument full=True. Example: x = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) y = np.array([0.0, 0.8, 0.9, 0.1, -0.8, -1.0]) z, residuals, rank, singular_values, rcond = np.polyfit(x, y, 3, full=True) residuals...

matlab,image-processing,rgb,entropy,standard-deviation

After reading the paper, because you are dealing with colour images, you have three channels of information to access. This means that you could alter one of the channels for a colour image and it could still affect the information it's trying to portray. The author wasn't very clear on...

math,variance,standard-deviation,calculated

The global variation is a sum. You can compute parts of the sum in parallel trivially, and then add them together. sum(x1...x100) = sum(x1...x50) + sum(x51...x100) The same way, you can compute the global averages - compute the global sum, compute the sum of the object counts, divide (don't divide...

mysql,statistics,standard-deviation

Yes, your subquery is an aggregate query with no GROUP BY clause, therefore its result is a single row. When you select from that, you cannot get more than one row. Moreover, it is a MySQL extension that you can include the Result field in the subquery's selection list at...

You set the error bar extents with the 3rd and 4th arguments to the errorbar function. So instead of just giving the standard deviation you can set the limits specifically for example: nSD=3; % number of standard deviations to show errorbar(X,Y,Y-nSD*SD,Y+nSD*SD); Or as used in the OP's question the 3rd...

gnuplot,histogram,standard-deviation

You can iterate over the four blocks with do for, call stats using the same using and every settings as you already have in your plot command. Then, in each iteration, and set the appropriate label using the many values that stats gives you: STATS_mean_x as x-coordinate of the label...

You can use sapply: > string_vector <- c("mpg", "cyl", "disp") > sapply(mtcars[string_vector], sd) mpg cyl disp 6.026948 1.785922 123.938694 ...

arrays,math,java.util.scanner,standard-deviation

Sure - this will do it. package statistics; /** * Statistics * @author Michael * @link http://stackoverflow.com/questions/11978667/online-algorithm-for-calculating-standrd-deviation/11978689#11978689 * @link http://mathworld.wolfram.com/Variance.html * @since 8/15/12 7:34 PM */ public class Statistics { private int n; private double sum; private double sumsq; public void reset() { this.n = 0; this.sum = 0.0; this.sumsq...

statistics,standard-deviation,weighted-average

I just found this wikipedia page discussing data of equal significance vs weighted data. The correct way to calculate the biased weighted estimator of variance is , though this on-the-fly implementation is more efficient computationally as it does not require calculating the weighted average before looping over the sum on...

linux,bash,standard-deviation,bc

<<< needs to be parsed by the shell, which happens before parameter expansion. When you try to execute SD=`$CMD` the string in $CMD is not reparsed, so <<< is treated as a literal string and passed as an argument to bc. You need something like BC_EXPRESSION='scale=10; sqrt((0' for i in...

rnorm(100) gives you a random sample of 100 values from distribution mean = 0 and sd = 1. Because it is random, the actual value of mean(rnorm(100)) depends on which particular values you get back. There is no guarantee that the mean will be 0, but statistically it should converge...

python,math,standard-deviation

You implemented the formula incorrectly. The definition is "The standard deviation is the square root of the average of the squared deviations from the mean." This numpy page explains it well (see the Notes section). The code math.sqrt((average - value)**2) doesn't do what you want; the sqrt and **2 sort...

python,methods,pandas,dataframes,standard-deviation

It has nothing to do with pandas. When you use parentheses, you call whatever is before the parentheses. If you don't use parentheses, you just get that object as an object, whatever it may be. In this case, you have df_first.groupby('build_number').std, which is a method object. You can see the...

java,arrays,add,standard-deviation

Try this for your "//Subtract Average and Square it" for loop: for (int i = 0; i < variance.length; ++i) { variance[i] -= average; variance[i] *= variance[i]; System.out.println(variance[i]); } You are not currently updating the value stored in the array....

algorithm,statistics,median,standard-deviation,outliers

Based on the description you have provided, the problem can be split into 2: Finding and excluding Statistical Outliers from the data set Sorting the resulting values in descending (or just in any) order The general solution to the first problem and example using Microsoft Excel is described at :...

node.js,math,standard-deviation

If you console.log(total) inside your calculation of squaredDeviations, you'll see you're starting out with the value 1.37312, namely the first thing in your list. You need to explicitly tell it to start at 0, which is the third optional argument to reduce. Just replace: var squaredDeviations = _(prices).reduce(function(total, price) {...

java,netbeans,statistics,osx-yosemite,standard-deviation

While the following is untested, they should work. For the median: public static double median(int[] numbers) { Arrays.sort(numbers); // sort numbers int len = numbers.length; if (len % 2 == 0) // length is even return (numbers[len/2] + numbers[len/2-1]) / 2.0d; else // length is odd return (double) numbers[len/2]; }...

.net,entity-framework,aggregation,standard-deviation

You should be able to use EntityFunctions.StandardDeviation in System.Data.Objects like this: StdDev = EntityFunctions.StandardDeviation(s.Select(m => m.Minutes)) (If you were using EF 6, it would be System.Data.Entity.DbFunctions.StandardDeviation())...

java,recursion,arraylist,standard-deviation,helper-functions

Take a look at the recursive definition of calcSum, and see how you can make your calcStd recursive as well. You need to make another "helper" method for this - sumSquareDiffs. The signature of the method would look like this: double sumSquareDiffs(ArrayList <Integer> list, double avg, int i) { ......

probability,matlab,normal-distribution,standard-deviation

Ideally, there are no such maximum and minimum. A normal (Gaussian) pdf has infinite support, so it can produce any value, no matter how high or low, with positive probability. Of course, exceeding a value x is less probable as x grows; but the probability is never 0. In reality,...