programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Please help, how you I write a code to get the averages of groups in a 2d jagged array and find SSW

Lucy Gallagher
Greenhorn
Posts: 5
Can anyone please help me with my java coding.I have a 2d double jagged array (named jag), which contains 17rows(people id) and 19 columns(bloodlevels). I have calculated the average of each column and calculated the sum squared total.This works ok. My problem, is that the people are also arranged into groups, which is set as 5,6,6 in the coding below. So I need to write code to get me the averages of the individual groups in every columns and then calculate the sum squared within.

what we know is that for each one of the bloodlevel measurements (19) there are 17 patients results, and the 17 patients fall into 3 groups, the group sizes being (5,6,6). So using the theory(below) given to me, how do I code to get the averages of the groups in every bloodlevel measurement

the logic is that these groups have say a different genetic variation to the next group etc etc,

Below is the theory behind getting the groups averages but I do not know how to work the theory into coding. Any advice would be great. Apologies, I am not proficient in programming. I have no background in programming, I am from medical perspective.So if this makes no sense, just ask me a question. Thanks

Have a for-loop that runs from 0 up to num_groups (call this variable i). Using the group_sizes array you've already created, inside this i for-loop you create a second for loop (call it j) that adds up all the group_sizes entries from 0 up to i-1, ie sum = groupsizes[0]+groupsizes[1]+...+groupsizes[i-1], then you create two variables, lowerlimit = sum and upperlimit sum+groupsizes[i]. Once the j-for-loop has complete you create another for loop (inside the i loop still, but not inside the j loop), call this one k, which goes (for int k=lowerlimit; k<upperlimit; k++). Inside this k loop you can calculate mean of the i-th patient group and the ssw for the i-th patient group.

int [] group_sizes;

Stephan van Hulst
Saloon Keeper
Posts: 7993
143
Hi Lucy, welcome to CodeRanch!

Please CarefullyChooseOneForum when you start a new topic. I will lock this one, and we will continue in the other: http://www.coderanch.com/t/665235/java/java/averages-groups-SSW-double-jagged