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
1
vote
1 answer

Using intsvy to generate weighted means in PISA2018 data

I am trying to use the intsvy package to calculate a weighted mean by country and gender for Maths capability from plausible values but I keep receiving the same error message. genderMath <- pisa.mean.pv(pvlabel = "MATH", by = c("CNT",…
olympiaca
  • 11
  • 1
1
vote
2 answers

How to aggregate two different columns with two different functions in R dataframe

I have a data frame that has some records that are duplicated and I need to aggregate the duplicates so there is a unique record per row. An example: Col1 Col2 Col3 Col4 A 0.170 83 0.878 B 0.939 103 0.869 C …
pav
  • 59
  • 1
  • 12
1
vote
1 answer

Weighted Interpolation using means of circular quantities

I am woking on a project of weighted interpolation. Each station has a coordinate point on the map as shown below. var stationCoor = [[408,352],[525,348],[535,495],[420,400],[272,145],[175,195],[197,335]]; I am taking points that are located in the…
user11730880
1
vote
1 answer

Weighted Frequency Table in R

I'm looking to create a frequency table in R for a certain variable (INTERVIEW_DAY) , but taking into account another variable as weight (WEIGHT). I've tried to do that with the package data.table. I would love to do it with the R-Base Package…
Econ_Spectre
  • 65
  • 1
  • 7
1
vote
1 answer

R data frame: Create weighted average group-wise

I'm working on an R dataframe with columns GROUP_COL | TIME| VALUE . Time is in order, value is numerical and group col is a categorical variable I want to group the data by. My goal is to first group by the GROUP_COL variable then, order by…
Julia K
  • 397
  • 3
  • 10
1
vote
1 answer

Matlab find x of weighted average

How to find the weighted average x? From graphing x(y) it looks to be around x=0.45? y = [0.1 0.1 0.2 0.5 0.4 0.2] x = [0.1 0.2 0.3 0.4 0.5 0.6] One way to perhaps compute it would to find x where the area under the curve y(x) is half of the area…
Dwadelfri
  • 454
  • 1
  • 4
  • 15
1
vote
2 answers

How to multiply a layer by a constant vector element wise in Keras?

I want to make a weighted average ensemble of 3 of my trained models. So, I want first to multiply the softmax output of a model (element-wise) by a vector and then average the 3 weighted outputs of the 3 models. I used the following code to…
1
vote
1 answer

pandas grouped weighted average with weights from records and values from column names

I want to compute a grouped weighted average where the weights are present as rows and the value to be averaged is present as the column name: df_dict= {1: {0: 10, 1: 15, 2: 50, 3: 10, 4: 44}, 4: {0: 12, 1: 15, 2: 48, 3: 12, 4: 63}, 7.5: {0: 17,…
Georg Heiler
  • 16,916
  • 36
  • 162
  • 292
1
vote
1 answer

Calculate weighted average with Pandas for decreasing cost

I am installing a ranking system and basically I have a field called site_fees that accounts for 10% of the total for consideration. A site fee of 0 would get all 10 points. What I want to do is calculate how many points the non-zero fields would…
DBA108642
  • 1,995
  • 1
  • 18
  • 55
1
vote
2 answers

Calculating weighted spatial global annual averages across grid cells using netcdf dataset in R

I am currently working on a project that involves climate model data stored in a NetCDF file. I am currently trying to calculate "weighted" spatial annual "global" averages for precipitation. I need to do this for each of the 95 years of global…
Android17
  • 93
  • 1
  • 12
1
vote
1 answer

How can we find E(X^n) for a discrete random variable X in R?

Suppose values of a discrete random variable X, randomNumbers, and its distribution prob is given. I can find E(X) using the following code: weighted.mean(randomNumbers, prob) How can we find E(X^n) in R? Would this code…
user366312
  • 16,949
  • 65
  • 235
  • 452
1
vote
3 answers

How do I use condition with rows in a dataframe (weighted average, R language)?

I need to calculate the weighted average of each row in the dataframe, where: Does anyone know how to do it using the R language? regards t1 <- c(1, 2, 4, 6, 7, 9) t2 <- c(6, 6, 5, 3, 3, 7) df <- data.frame(t1 = t1, t2=t2, stringsAsFactors =…
1
vote
2 answers

Finding Largest Subset of Data where Average Matches Criteria

I'm trying to find the largest subset sum of a particular data set, where the average of a field in the data set matches predetermined criteria. For example, say I have a people's weights (example below) and my goal is to find the largest weight…
Epausti
  • 53
  • 1
  • 8
1
vote
1 answer

Weighted average of time-series with changing weights over time

I need to generate a weighted average of the returns of some number of financial assets, where the weights used change over time. (The application is financial but the problem itself is a very general one). Excerpts of my returns and weights are as…
Doggie52
  • 153
  • 6
1
vote
0 answers

Dax sum and weighted average in filtered data

I'm trying to do a sum and a weighted average in DAX for Power Bi on filtered data. For example I've a table Table and I need another column with the progressive sum of QUANTITA. This quantity must change based on the period of date filtered. I…
LucaC
  • 11
  • 2