tegge-classroom / STAT2984-2018

STAT 2984: Statistical Programming I - Spring 2018
1 stars 13 forks source link

Question 8 and 16 #23

Open cahicks opened 6 years ago

cahicks commented 6 years ago

After looking at these two questions for a long time and trying to guess and google where to start, I cannot figure out how to begin. Does anyone have advice on what a good first step is or what I should google to help get it started?

matter698no2 commented 6 years ago

The output for 8 should look something like:

dictionary = {'A': [22, 32, 54], 'B': [21, 32] ... 

So you'd want to make some kind of loop that adds the factors to the dictionary as keys and appends the values to each matching key.

16 uses the same thing we did in class with moving the mean, except this time we want the mean of each factor to be 0

So if you had something like:

dictionary  = {
'A' : [12, 45, 23]
'B' : [65, 32, 21]
}

You'd want to "shift" the mean of each factor to be 0, so that dictionary would now look like:

dictionary  = {
'A' : [-14, 19, -3]
'B' : [26, -7, -18]
}
cahicks commented 6 years ago

How do we center the data again? For some reason I think it is supposed to be factor_list(data, center=0) But it keeps telling me that "data" is not defined

matter698no2 commented 6 years ago

I'm not entirely sure what the factor list is, but you can either call the function in #11, center_list (if you can) in a loop to apply it to your dictionary. Because #11 defaults to a center of 0, you don't need to specify the mean when you call it

[loop here]
    center_list(dictionary[factor])

If you can't call the center_list function, you can manually do it with some math

#find the mean
mean = sum(dictionary[factor])/len(dictionary[factor])

#to center it, you have to subtract the difference between the current mean and the desired mean, so
difference = 0 - mean
for x in dictionary[factor]:
    x = x + difference