Repository navigation
Expand file tree
/
Copy pathArrayListMath.java
More file actions
93 lines (67 loc) · 2.33 KB
/
Copy pathArrayListMath.java
File metadata and controls
93 lines (67 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package gnnbeanfix;
import java.util.ArrayList;
public class ArrayListMath {
public static double mean(ArrayList<Double> values){
double total = 0;
if(values.size() != 0){
for(double value : values)
total += value;
return total/values.size();
}else{
System.out.println("ArrayList size is 0. Mean could not be calculated");
return 0;
}
}
public static double standardDeviation(ArrayList<Double> values){
double mean = ArrayListMath.mean(values);
if(values.size() != 0){
// total of (x - mean)^2
double total = 0;
for(double value: values)
total += Math.pow(value - mean, 2);
return Math.sqrt(total / (values.size() - 1));
}else{
System.out.println("ArrayList size is 0. SD could not be calculated");
return 0;
}
}
public static double standardDeviation(ArrayList<Double> values, double mean){
if(values.size() != 0){
// total of (x - Mean)^2
double total = 0;
for(double value: values)
total += Math.pow(value - mean, 2);
return Math.sqrt(total / (values.size() - 1));
}else{
System.out.println("ArrayList size is 0. SD could not be calculated");
return 0;
}
}
public static ArrayList<Double>scaleDataByStandardScore(ArrayList<Double> values){
// scale by the process of ((x - mean) / sd)
if(values.size() != 0){
double mean = ArrayListMath.mean(values);
double sd = ArrayListMath.standardDeviation(values, mean);
// create a new array list so we do not alter the values of the list passed in
ArrayList<Double> standValues = new ArrayList<Double>();
for(double value : values)
standValues.add((value - mean) / sd);
return standValues;
}else{
System.out.println("ArrayList to scale is empty");
return null;
}
}
public static ArrayList<Double>scaleDataByStandardScore(ArrayList<Double> values, double mean,double sd){
if(values.size() != 0){
// create a new array list so we do not alter the values of the list passed in
ArrayList<Double> standValues = new ArrayList<Double>();
for(double value : values)
standValues.add((value - mean) / sd);
return standValues;
}else{
System.out.println("ArrayList to scale is empty");
return new ArrayList<Double>();
}
}
}