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
2
votes
1 answer

Weighted Average Fields

I'm totally new to doing calculations in T-SQL. I guess I'm wondering what is a weighted average and how do you do it in T-SQL for a field? First off as far as I know a weighted average is simply just multiplying 2 columns then average it by…
PositiveGuy
  • 46,620
  • 110
  • 305
  • 471
2
votes
1 answer

Weighted mean of similar elements in a vector in R

I have two vectors x and w. w is a numerical vector of weights the same length as x giving the weights to use for elements of x. I would like to give weighted mean of the elements in vector x which their difference are small(for example 1e-1 or…
Bensor Beny
  • 285
  • 2
  • 13
1
vote
3 answers

Adjusting votes based on different numbers of voters

I have a 1 to 5 voting system and i'm trying to figure out the best way to find the most popular item voted on, taking into consideration the total possible number of votes cast. To get a vote total, i'm counting "1" votes as -3, "2" votes as -2,…
chrishall78
  • 158
  • 7
1
vote
0 answers

Calculating weighted average using (latitude, longitude and altitude) of two nearest weather stations

I want to calculate the weighted average of temperatures of the nearest weather stations around a city. I have data on the latitude, longitude, altitude and temperature of some stations. Mostly, I'm trying to find the formula used by the…
1
vote
0 answers

Convolution/weighted average of two arrays in python

I have an equation that I need to calculate numerically, but I am having doubts about my approach. I also put this question on the Computational Science stack exchange with a bounty. This is the equation I need to program: where $\chi$ is a volume…
theWrongAlice
  • 99
  • 2
  • 10
1
vote
1 answer

Compute weighted average for a list of variables in Pandas

Given a data frame, I would like to write a function to calculate the weighted average by group for a given set of columns. For example, I have a data frame mydf = pd.DataFrame({ 'group' : np.array(['A', 'B', 'C', 'D', 'E']*20), 'weight' :…
PingPong
  • 355
  • 2
  • 11
1
vote
1 answer

Calculating weighted average based on criteria

I have a panel data set, where I have tens of years of data for thousands of assets. There are also rows with NA values in RET/MV/RANK_LAG, which I would like to ignore. I have got my data to this data frame, where I have months (in class(date)),…
datgoaltho
  • 71
  • 4
1
vote
0 answers

How to get weighted average of systemwide?

This is the data: data5 = requests.get('https://data.ny.gov/resource/8mkn-d32t.json?$limit=1000000').text #pulling the data using API json5 = json.loads(data5) #converting the data to json cjtp_df = pd.DataFrame(json5) #storing json to dataframe for…
numa
  • 11
  • 1
1
vote
1 answer

Extracting from List

What I have coded students = ['Rose', 'Dorothy', 'Sophia', 'Blanch'] for i in range(len(students)): print('Hey',students[i],',please input the folowing grades:') weightAvg = [] discussionGrade = int(input('What was your discussion…
1
vote
1 answer

Calculate a Weighted Rolling Average by rows by group in r?

I have a dataframe games_h. This is just a snippet of the table but it has many teams and is sorted by date, team, game number. I am trying to create a weighted rolling average grouped by the team. I would like the most recent game to be…
d3hero23
  • 380
  • 1
  • 12
1
vote
1 answer

Google Sheets, How to use AVERAGEIF with Duration criteria

Here is the formula I am trying to use. Google sheets keeps giving me the Div/zero error. =AVERAGEIF(G4:G1000,OR(AND(NOT(ISNA(MATCH(HOUR(G4:G1000),{6,14,22}, 0))), ISBETWEEN(MINUTE(G4:G1000), 25, 35)) ,AND(NOT(ISNA(MATCH(HOUR(G4:G1000),{0,8,16},…
1
vote
1 answer

Calculate weighted average for multiple columns with NaN values grouped by index in Python

I'm trying to calculate a simple weighted average over multiple columns at once grouped by an index column with some of the column values being NaN. Below is a sample dataset: df = pd.DataFrame(np.random.choice([0,1,np.nan], size=(5,5)),…
Debbie
  • 391
  • 2
  • 18
1
vote
0 answers

Calculation of standardized mean differences (SMD) before & after weighting in R

I am trying to do a balance analysis for a data set before and after applying weights. I can output the SMD's for the unweighted data set relatively easily using TableOne. However, I am having an unexpectedly difficult time with the SMD's after…
Xray
  • 11
  • 2
1
vote
1 answer

calculate weighted average over several columns with NA

I have a data frame like this one: ID duration1 duration2 total_duration quantity1 quantity2 1 5 2 7 3 1 2 NA 4 4 3 4 3 5 NA …
lM__3
  • 85
  • 6
1
vote
1 answer

Presto Weighted Moving Average Syntax Error

I'm trying to run the weighted moving average Silota query with similar data in a Presto database but am encountering an error. The same query in the Redshift database has no issues, however in Presto I receive a syntax error: Query failed…