def __init__(self, list_of_factors, list_of_data_sets): self.list_of_means = [] for i in range(len(list_of_factors)): data = list_of_data_sets[i] self.list_of_means.append(statchar.aritmetic_mean(data)) all_elements = [] for i in range(len(list_of_factors)): all_elements += list_of_data_sets[i] self.grand_mean = statchar.aritmetic_mean(all_elements) self.estimated_effects = [] for i in range(len(list_of_factors)): mean = self.list_of_means[i] self.estimated_effects.append(mean-self.grand_mean) # DF- degrees of freedom self.DFtreat = len(list_of_factors) - 1 self.DFtot = len(all_elements) - 1 self.DFres = (self.DFtot-self.DFtreat) # sum of squares self.SStreat = statchar.SStreat(list_of_data_sets, self.estimated_effects) self.SSres = statchar.SSres(list_of_data_sets, self.list_of_means) self.SStot = statchar.SStot(list_of_data_sets, self.grand_mean) # mean squares self.MStreat = self.SStreat/self.DFtreat self.MSres = self.SSres/self.DFres self.F = self.MStreat/self.MSres
def confidence_interval(data, percentile, number_of_tails): """ Computes confidence interval for the mean of the given data covering the probability given by the variable percentile. * data specifies the given data. * precentile gives the probability that the mean of the data is in the confidence interval. * number_of_tails gives the number of tails of the normal distribution to be considered. """ square = math.pow(len(data), 0.5) mean = statchar.aritmetic_mean(data) std_dev = statchar.std_dev_corrected(data) dist = distributions.NormalDistribution(0, 1) if number_of_tails == 2: alfa = (1-percentile)/2 c = distributions.find_percentile(1-alfa, dist.cdf) left = mean - c*std_dev/square right = mean + c*std_dev/square return left, right elif number_of_tails == 1: alfa = percentile c = distributions.find_percentile(alfa, dist.cdf) SEM = statchar.std_error_of_mean(data) left = mean right = mean + c*SEM/square return right
def __init__(self, regressand_vector_matrix, regressor_matrix): self.regressand_vector_matrix = regressand_vector_matrix self.regressor_matrix = regressor_matrix f = linregression.add_to_matrix_for_intercept # Add intercept for improved performance of the model self.regressor_matrix_for_intecept = f(regressor_matrix) self.coeficents = linregression.coeficents_estimation( regressand_vector_matrix, regressor_matrix) self.mean = statchar.aritmetic_mean(regressand_vector_matrix.matrix[0]) self.SStot = statchar.SS_with_mean(regressand_vector_matrix.matrix[0], self.mean) fi = [] for element in regressor_matrix.matrix: fi.append(LinearRegression.predict(self, matrices.Matrix([element]))) self.SSreg = statchar.SS_with_mean(fi, self.mean) self.SSres = statchar.SS_abstract(fi, regressand_vector_matrix.matrix[0]) self.R_squared = self.SSreg/self.SStot n = len(regressand_vector_matrix.matrix[0]) p = len(regressor_matrix.matrix[0]) A = n - 1 B = n - p - 1 self.adjusted_R_squared = 1-(1-self.R_squared)*(A/B)