# Calculating spatially weighted average value of vector layer in QGIS 3

I have a vector layer across an area with several different polygons of varying size. Each polygon has a rate of fertilizer as an attribute. I would like to calculate the average rate of fertilizer across the area.

Initially, I used the tool `"Basic statistics for fields"` but I realized that this tool just takes the average of the numbers in the attribute table without adjusting for the polygon sizes. This gives an incorrect average rate since there could be a large polygon with a very low rate, however, this large polygon would count towards the average as much as a very small polygon.

Is there a tool that allows me to calculate the average rate of fertilizer so that when I multiply the average rate by the area, I would get the correct amount of fertilizer needed for the farm?

I can calculate the correct average in Excel or using the field calculator, but I think there must be a faster way to do this in QGIS 3.12.0.

• The easy answer is, create a new field and then calculate rate*area... The weighted average is just then the sum of this new field divided by sum of the area. Is the same I think as you are doing in excel. But, if you are looking for a kind of 'statistical tool' the short answer is : there is not. You may be able to write a python script. But is interesting your question because maybe this tools can be include soon. Feb 29 '20 at 5:48
• You can try to modify this gis.stackexchange.com/questions/99891/… in order to calculate the weighted average, after running the model builder it seems like a toolbox or GUI. Feb 29 '20 at 5:53