Questions tagged [weighted-average]

The weighted average or weighted mean is similar to an arithmetic mean where instead of each of the data points contributing equally to the final average, some data points contribute more than others.

If all the weights are equal, then the weighted mean is the same as the arithmetic mean.

The mathematical expression for the weighted avergae is

enter image description here

387 questions
9
votes
3 answers

Display weighted mean by group in the data.frame

Issues regarding the command by and weighted.mean already exist but none was able to help solving my problem. I am new to R and am more used to data mining language than programming. I have a data frame with for each individual (observation/row) the…
Elixterra
  • 241
  • 1
  • 3
  • 9
8
votes
3 answers

Weighted average using numpy.average

I have an array: In [37]: bias_2e13 # our array Out[37]: [1.7277990734072355, 1.9718263893212737, 2.469657573252167, 2.869022991373125, 3.314720313010104, 4.232269039271717] The error on each value in the array is: In [38]: bias_error_2e13 #…
Srivatsan
  • 7,913
  • 6
  • 45
  • 76
8
votes
1 answer

How do I calculate the standard deviation between weighted measurements?

I have several weighted values for which I am taking a weighted average. I want to calculate a weighted standard deviation using the weighted values and weighted average. How would I modify the typical standard deviation to include weights on each…
Steven C. Howell
  • 11,482
  • 11
  • 61
  • 79
6
votes
0 answers

Pass weights to scipy.interpolate.griddata() function

I am trying to reconstruct an image for which I know the values are floating-point pixel positions. I'm using scipy.interpolate.griddata() to interpolate the values at each integer location and reconstruct the image. However, I also want to provide…
Nagabhushan S N
  • 4,063
  • 5
  • 26
  • 54
6
votes
4 answers

How to smooth and plot x vs weighted average of y, weighted by x?

I have a dataframe with a column of weights and one of values. I'd need: to discretise weights and, for each interval of weights, plot the weighted average of values, then to extend the same logic to another variable: discretise z, and for each…
6
votes
7 answers

Compute weighted averages for large numbers

I'm trying to get the weighted average of a few numbers. Basically I have: Price - 134.42 Quantity - 15236545 There can be as few as one or two or as many as fifty or sixty pairs of prices and quantities. I need to figure out the weighted…
Travis
  • 133
  • 1
  • 2
  • 5
6
votes
2 answers

How to calculate mix of 4 colors defined in CIELAB L*a*b* model?

I have 4 colors that I converted from RGB to CIELAB L*a*b* model. How can I calculate mix of these 4 colors when I have (L,a,b) for each such color? How can I calculate same mix, if I want to put weights (w1, w2, w3, w4) on such 4 colors, having 1…
Ωmega
  • 37,727
  • 29
  • 115
  • 183
5
votes
1 answer

How to use dplyr to calculate a weighted mean of two grouped variables

I know this must be super easy, but I'm having trouble finding the right dplyr commands to do this. Let's say I want to group a dataset by two variables, and then summarize the count for each row. For this we simply have: mtcars %>% group_by(cyl,…
ds_guy
  • 93
  • 1
  • 4
5
votes
3 answers

Python - Time-weighted average Pandas, grouped by time interval

I have a time-series in a Pandas DataFrame. The timestamps can be uneven (one every 1-5 minutes), but there will always be one every 5 minutes (timestamps with minutes ending in 0,5,10,15,20,25,30,35,40,45,50,55). Example: 2017-01-01 2:05:00 …
Vincent L
  • 561
  • 1
  • 7
  • 19
5
votes
2 answers

Calculate a series of weighted means in R for groups with different weightings

I have the following dataset (simple version of my actual data), 'data', and would like to calculate weighted means for variables x1 and x2, using weightings w1 and w2 respectively, split up into two groups (groups determined by the variable…
Tina218
  • 51
  • 5
4
votes
3 answers

Calculate a weighted (Bayesian) average score/index in stored procedure?

I have an MS SQL Server 2008 database where I store places that serve food (cafés, restaurants, diners etc.). On a web site connected to this database people can rate the places on a scale from 1 to 3. On the web site there's a page where people…
tkahn
  • 1,387
  • 2
  • 18
  • 35
4
votes
3 answers

Python get weighted mean of dict keys based on dict values

I am trying to write code to find the mean of the keys in my dict, but based on the dict values. So, for example, for: d = {1:2, 2:1, 3:2} the dict keys would be: [1,1,2,3,3] I've written the following code, which works for small data sets such as…
J. B.
  • 95
  • 1
  • 5
4
votes
3 answers

Multiply and average data from two data.frames into one column using R

I have the following two example data.frames. set.seed(12345) df1 = data.frame(a=c(rep("a",8), rep("b",5), rep("c",7), rep("d",10)), b=rnorm(30, 6, 2), c=rnorm(30, 12, 3.5), d=rnorm(30, 8, 3) ) df2 = data.frame(p=c("b",…
4
votes
3 answers

Moving average in Haskell

Given a list of weights: let weights = [0.1, 0.2, 0.4, 0.2, 0.1] and an array of measurements, I want to implement the weighted average. This is how I would do it in Python: y=[] w = length(weights) for n in range(w,len(x)-w): …
Uri Goren
  • 11,719
  • 5
  • 46
  • 92
4
votes
2 answers

How would YOU compute IMDB movie rating?

I'm doing this only for learning purposes. I've no intentions of reversing the methods of IMDB. I asked myself I owned IMDB or similar website. How would I compute the movie rating? All I can think of is Weighted Average(which is nothing but…
claws
  • 47,010
  • 55
  • 140
  • 185
1
2
3
25 26