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 average is

enter image description here

Read more here

476 questions
3
votes
2 answers

SQL sectioning/averaging based on different timetag/timestamps and user-chosen input (T-SQL)

I've got the following problem that I would like to cope with - I have a SQL dataset that I would like to section (e.g. like this one): OldTimetag OldValue 2012-05-03 12:47:00 5 2012-05-03 13:00:00 1.3 2012-05-03…
Jonas
  • 308
  • 1
  • 11
3
votes
1 answer

How to normalize weighted list?

I would like to weight a list of elements and select random element from the list. I have the following javascript, which do that: var generateWeighedList = function(list, weight) { var weighed_list = []; // Loop over weights for (var i…
Ronald
  • 2,721
  • 8
  • 33
  • 44
3
votes
1 answer

Equivalent of Bayesian average for unary rating system

I am really looking forward to implement bayesian average rating system for a site I'm developing. I have faced a problem though - all of the examples I can find on the net, are for multi-value rating systems, with the smallest being binary - likes…
tomsseisums
  • 13,168
  • 19
  • 83
  • 145
3
votes
1 answer

How do I calculate a weighted average in mongoDB using aggregation framework?

I need to calculate weighted average over a set of documents. Each document contains both a weight and a value in a separate field. Here is an example: I have following 2 documents representing a sales transaction. { quantity : 3, price :…
derdo
  • 1,036
  • 12
  • 21
3
votes
1 answer

pandas: groupby and variable weights

I have a dataset with weights for each observation and I want to prepare weighted summaries using groupby but am rusty as to how to best do this. I think it implies a custom aggregation function. My issue is how to properly deal with not item-wise…
ako
  • 3,569
  • 4
  • 27
  • 38
2
votes
2 answers

How to calculate the weighted average of the rows of a matrix, but with different weights per row?

As the title implies, I have a numpy matrix (2d array) that happens to be symmetric with 0s in its diagonal. I wanted to use the np.average method in order to collapse its rows into a 1d column array of weighted averages using a weight array from…
Tal Afek
  • 111
  • 5
2
votes
1 answer

Is there a way to get 'weighted mean' in reactable groupBy in a shiny app?

I want to generate a reactable in my app, group the table using the groupBy argument and in the groups get the weighted mean for each one. The function reactable::colDef() offers a list of options of summary: mean, sum, max, min, median, count,…
2
votes
1 answer

ggplot & boxplot: is it possible to add weights?

I'm trying to plot boxplots about wage according with the area. This is a sample of my dataset ( It is provided by a research institute) > head(final2, 20) nquest nord ireg staciv etalav acontrib nome_reg tpens pesofit 1 173 1 18…
io_boh
  • 193
  • 7
2
votes
1 answer

how to calculate weighted average or sum by groupby from a list?

I have a data frame and a list of weight as follows import pandas as pd import numpy as np data = [ ['A',1,2,3,4], ['A',5,6,7,8], ['A',9,10,11,12], ['B',13,14,15,16], ['B',17,18,19,20], ['B',21,22,23,24], ['B',25,26,27,28], …
Bad Coder
  • 177
  • 11
2
votes
2 answers

Weighted average cost of short-term stock trading

I'm new to programming and trying to learn Julia. I tried to compute the weighted average cost of short-term stock trading activities as I did before in R. I rewrite the code in Julia, unfortunately, it return the incorrect result in data frame…
Najib Noer
  • 23
  • 2
2
votes
1 answer

Adjust prices on stock portfolio based on quantity and price

I am trying to adjust my portfolio of stocks and trying to calculate the adjusted mean price (which is a form of weighted-average). Here is sample data: import pandas as pd import numpy as np sample_dict = {'ticker': {1: 'ABCD', 2: 'ABCD', 3:…
Allan
  • 321
  • 1
  • 8
2
votes
1 answer

Weighted average in pandas with weights based on the value of a column?

I have the following dataframe id type side score 601166 p right 2 601166 p left 6 601166 p right 2 601166 p left 4 601166 r left …
olive
  • 179
  • 1
  • 11
2
votes
2 answers

How do you give weights to dataframe columns iteratively for weighted mean average?

I have a dataframe with multiple columns having numerical float values. What I want to do is give fractional weights to each column and calculate its average to store and append it to the same df. Let's say we have the columns: s1, s2, s3 I want to…
rick458
  • 97
  • 6
2
votes
1 answer

Item-wise weighted average of multiple DataFrames containing strings

I am relatively new to Python and Pandas. I have multiple DataFrames in the same format containing float and string values (in each column and row). The location of string/float items is the same across DataFrames. I would like to take a weighted…
Fhtsm
  • 147
  • 6
2
votes
1 answer

How can I calculated the weighted mean in the qwraps2 library in R?

I am using the qwraps2 library to produce a summary table. When writing my list of summary statistics, I have: summary1 <- list("Wage" = list("min" = ~ min(WAGE), "max" = ~ max(WAGE), "mean (sd)" =…