-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
213 lines (117 loc) · 4.09 KB
/
__init__.py
File metadata and controls
213 lines (117 loc) · 4.09 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env python
# coding: utf-8
# ## Script to calculate Basic Statistics
# ### Equation for the mean: $\mu_x = \sum_{i=1}^{N}\frac{x_i}{N}$
#
# ### Equation for the standard deviation: $\sigma_x = \sqrt{\sum_{i=1}^{N}\left(x_i - \mu \right)^2}\frac{1}{N-1}$
#
#
# **Instructions:**
#
# **(1) Before you write code, write an algorithm that describes the sequence of steps you will take to compute the mean and standard deviation for your samples. The algorithm can be written in pseudocode or as an itemized list.***
#
# **(2) Use 'for' loops to help yourself compute the average and standard deviation.**
#
# **(3) Use for loops and conditional operators to count the number of samples within $1\sigma$ of the mean.**
#
# **Note:** It is not acceptable to use the pre-programmed routines for mean and st. dev., e.g. numpy.mean()
# ### Edit this box to write an algorithm for computing the mean and std. deviation.
#
# ~~~
#
# #### Mean
#
# count number of inputs
# if number is less than 10, simply just remember the number
# if number is more than 10, write this number down
# add inputs together
# divide by total number of inputs
#
#
# #### Standard Deviation
#
# count number of inputs
# if number is less than 10, simply just remember the number
# if number is more than 10, write this number down
# add inputs together
# divide by total number of inputs
# save the mean as a variable x
# for each input, subtract input minus mean
# square these values
# add squared values together
# take square root of the total
# divide by the total number of inputs + 1
#
#
#
#
#
#
# ~~~
# ### Write your code using instructions in the cells below.
# In[2]:
# Lauren Zane 9/17/21 V. 1
# In[3]:
# In[73]:
# Import the matplotlib module here. No other modules should be used.
import matplotlib as plt
# In[63]:
# Create a list variable that contains at least 25 elements. You can create this list any number of ways.
# This will be your sample.
hw_list = [6,7,8,9,10,11,1,2,3,4,5,60,70,80,90,100,110,109,108,107,106,1,1,1,1,1]
# In[11]:
# Pretend you do not know how long x is; compute it's length, N, without using functions or modules.
get_ipython().run_line_magic('pinfo', 'list')
#length = 26
# In[26]:
# Compute the mean of the elements in list x.
#need sum and division
hw_list = [6,7,8,9,10,11,1,2,3,4,5,60,70,80,90,100,110,109,108,107,106,1,1,1,1,1]
list_sum = 0
for number in hw_list:
list_sum = int(number) + list_sum
mu = list_sum / len(hw_list)
print(mu)
# In[29]:
# Compute the std deviation, using the mean and the elements in list x.
for number in hw_list:
sigma = sum([((int(number) - mu)**2/len(hw_list))**0.5])
print(sigma)
# In[30]:
# Use the 'print' command to report the values of average (mu) and std. dev. (sigma).
print(mu)
print(sigma)
# In[36]:
# Count the number of values that are within +/- 1 std. deviation of the mean.
# A normal distribution will have approx. 68% of the values within this range.
# Based on this criteria is the list normally distributed?
mu + sigma
#46.31439973504274
mu - sigma
#31.45483103418803
#0 values are +/- one std. dev. from the mean, list is not normally distributed
# In[59]:
# Use print() and if statements to report a message about whether the data is normally distributed.
for number in hw_list:
if int(number) > 46:
print(int(number))
list_of_values_greater_than = [60,70,80,90,100,110,109,108,107,106]
get_ipython().run_line_magic('pinfo', 'list_of_values_greater_than')
#length = 10
for number in hw_list:
if int(number) < 31:
print(int(number))
list_of_values_less_than = [1,1,1,1,1,5,4,3,2,1,11,10,9,8,7,6]
get_ipython().run_line_magic('pinfo', 'list_of_values_less_than')
#length = 16
26 -(10 +16)
# 0
0/26
#not normally distributed
# In[ ]:
# In[98]:
### Use Matplotlb.pyplot to make a histogram of x.
from matplotlib import pyplot as plt
import numpy as np
data_array = np.array([6,7,8,9,10,11,1,2,3,4,5,60,70,80,90,100,110,109,108,107,106,1,1,1,1,1])
plot = plt.hist(data_array)