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
0
votes
2 answers

dplyr: User defined Function in summarise() involving two input vectors

I have a data frame of say 20 columns. Column 1 is group, column 2 is weights (not normalized to 1 or 100) and columns 3 to 20 contain data to be aggregated. There are some 250 rows but just 15 groups. So on an average for each group there are…
Dayne
  • 463
  • 3
  • 12
0
votes
1 answer

Calculating "Trimmed" Weighted Average

Anyone have any ideas on how to create a formula that will calculated a "trimmed" weighted average? For example: I have 10 different numbers with their own weights. How do I go about creating a formula that calculates a weighted average of only the…
H. Nguyen
  • 15
  • 3
0
votes
6 answers

In Python, How to put constraits on four random numbers making two negative and two positive and equating to 0?

How do i make two random negative numbers and two positive random numbers equal zero.For example, array([-.7,-.2,.8,.10]) = 0. [-.3,.2,-.5,.6] = 0. The numbers are constrained between -1 and 1. Size is 4 with 2 neg,2 pos. I dont want np.uniform…
user12359215
0
votes
1 answer

Apply sum product on columns of a dataframe in rolling windows

I have a set of defined weights and I want to calculate the weighted sum of returns in rolling windows on a time series dataframe. I believe we would use rollapplyr here, but I am unsure how to perform rolling window function across each row of the…
0
votes
1 answer

How to reference multiple dataframe columns to calculate a new column of weighted averages in R

I am currently calculating the weighted average column for my dataframe through manual referencing of each column name. Is there a way to shorten the code by multiplying sets of arrays eg: df[,c(A,B,C)] and df[,c(PerA,PerB,PerC)] to obtain the…
sjedi
  • 43
  • 1
  • 7
0
votes
3 answers

Calculating weighted averages excluding some rows for each row using data.table in r

I have been trying to obtain a column of weighted averages which excludes some rows for each row using data.table. In the following example, FIPS is ID variable and STATE is group variable. I want to calculate weighted average of value excluding…
0
votes
1 answer

weighted average from an array in python

I need to form a new sequence of numbers by replacing every data value, starting with the 4th entry and ending with the 4th from the last entry, with a weighted average of the seven points around it, using the following formula: (y[i-3] + 2y[i-2] +…
0
votes
1 answer

How to assign weights to different columns using SQL?

I have a data set with the following headers: product, sales, material_1, material_2, material_3, style_1, style_2, style_3. Based on this data set, I need to find the most successful materials and style based on sales. The column material_1 should…
Balphazar
  • 1
  • 1
0
votes
1 answer

how to solve weighetd average constraints in Cplex OPL?

I am using Cplex to solve supply chain optimization model, Objective function is linear, some constraints include the weighted average moisture content is nonlinear constraints, and errors happen. forall(j in S) minMC<=(sum (i in H) X[i][j]…
0
votes
1 answer

Matlab's weighted variance

I have looked into how to calculate the weighted standard deviation or variance of a sample and found this very helpful post referencing the paper by Gatz and Smith that suggests several methods:…
LenaH
  • 313
  • 2
  • 14
0
votes
2 answers

Knn give more weight to specific feature in distance

I'm using the Kobe Bryant Dataset. I wish to predict the shot_made_flag with KnnRegressor. I've used game_date to extract year and month features: # covert season to years kobe_data_encoded['season'] = kobe_data_encoded['season'].apply(lambda x:…
Jorayen
  • 1,737
  • 2
  • 21
  • 52
0
votes
1 answer

Group by weighted mean, allowing for zero value weights

I want to take the weighted mean of a column in a group-by statement, like this import pandas as pd import numpy as np df = pd.DataFrame({'group': ['A', 'A', 'A', 'B', 'B', 'B'], 'value': [0.4, 0.3, 0.2, 0.4, 0.3, 0.2], …
mortysporty
  • 2,749
  • 6
  • 28
  • 51
0
votes
1 answer

Optimize Stored Procedure for calculation of weighted Average

I used following code to calculate weighted Average of products in my accounting application, but when my records increases it raises an error " Maximum Recursion 100 has been exhausted before statement completion" any suggestion for optimization…
0
votes
0 answers

How to calculate weighted average in netcdf files

I had netcdf file with dimensions 1400*2300*10, Latitude=1400, Longitude=2300, Height=10 I know how to calculate average within Netcdf file for the Height Dimension Dataset.mean(dim=Height) I would like to know that If there is any predefined…
0
votes
0 answers

How to calculate the weighted average of data joining two tables and by grouping two columns

I'm trying to composite assay geology data, this must be done by each lithology from drill-hole, so I have two tables assay and geology. In assay table I have hole number, From, To and P2O5, and in the geology table I have hole number, Ore Zone. I…