I’m working on my scatter plot project, and the data set I’m using weights each data point. They give a formula for calculating an estimate, but the math they use is new to me. After some research, I think I’ve figured it out. I’m just looking for somebody who’s smarter than I am to verify that I’m doing this correctly. Here are the instructions from the data set:
And here is a small subset of the data that I’m working with. It represents the number of minutes spent playing games for each respondent, along with the weight. If I understand the instructions correctly:
fwgt(i) = data.weight
T(ij) = data.minutes
[ { year: 2014, age: 18, sex: 'M', minutes: 0, weight: 1 },
{ year: 2014, age: 18, sex: 'M', minutes: 570, weight: 1 },
{ year: 2014, age: 18, sex: 'M', minutes: 60, weight: 1 },
{ year: 2014, age: 18, sex: 'M', minutes: 135, weight: 1 },
{ year: 2014, age: 18, sex: 'M', minutes: 90, weight: 4734291 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 1 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 4381314 },
{ year: 2014, age: 18, sex: 'M', minutes: 90, weight: 7970627 },
{ year: 2014, age: 18, sex: 'M', minutes: 329, weight: 5999389 },
{ year: 2014, age: 18, sex: 'M', minutes: 50, weight: 1 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 2 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 6769183 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 9722641 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 2 },
{ year: 2014, age: 18, sex: 'M', minutes: 395, weight: 1 },
{ year: 2014, age: 18, sex: 'M', minutes: 60, weight: 2 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 9145549 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 1 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 3 },
{ year: 2014, age: 18, sex: 'M', minutes: 118, weight: 4466045 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 7149976 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 6195287 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 2 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 1 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 2 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 9759886 },
{ year: 2014, age: 18, sex: 'M', minutes: 660, weight: 7210502 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 2 },
{ year: 2014, age: 18, sex: 'M', minutes: 180, weight: 4769934 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 4255097 },
{ year: 2014, age: 18, sex: 'M', minutes: 180, weight: 7844106 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 3 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 4051823 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 6980967 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 2 },
{ year: 2014, age: 18, sex: 'M', minutes: 195, weight: 5948595 },
{ year: 2014, age: 18, sex: 'M', minutes: 60, weight: 3421269 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 6932904 },
{ year: 2014, age: 18, sex: 'M', minutes: 60, weight: 1 },
{ year: 2014, age: 18, sex: 'M', minutes: 149, weight: 6187478 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 9243905 },
{ year: 2014, age: 18, sex: 'M', minutes: 33, weight: 5706961 },
{ year: 2014, age: 18, sex: 'M', minutes: 45, weight: 4923626 },
{ year: 2014, age: 18, sex: 'M', minutes: 60, weight: 1 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 6336646 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 1 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 2 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 9931656 },
{ year: 2014, age: 18, sex: 'M', minutes: 0, weight: 4547729 },
{ year: 2014, age: 18, sex: 'M', minutes: 270, weight: 1 } ]
Here is the code that I’m using to try to solve the expression that is included in the instructions.
var accMinutes = 0,
accWeight = 0;
for (var i = 0; i < data.length; i++) {
accMinutes = accMinutes + (data[i].minutes * data[i].weight);
accWeight = accWeight + data[i].weight;
}
var estMinutes = accMinutes / accWeight;
console.log("Estimate: " + estMinutes);
The estimate that I arrive at for the given subset of data is 76.58498157779648.
Somebody help me, am I doing this correctly? Thank you in advance!