def __str__(self): """A human friendly representation of the analysis""" if self == {}: return '(no data in object)' tt = TextTable(48) tt.set_cols_dtype(['t', 'f']) tt.set_cols_align(['l', 'r']) for (k, v) in self.items(): tt.add_row([' %s'%k, v]) tt.set_deco(TextTable.HEADER) return ''.join(['Descriptive Statistics\n ', self.cname, '\n==========================\n', tt.draw()])
def __str__(self): if self == {}: return '(no data in object)' tt = TextTable(max_width=0) tt.set_cols_dtype(['t', 't'] + ['a'] * len(self.conditions_list)) tt.set_cols_align(['l', 'l'] + ['r'] * len(self.conditions_list)) tt.set_deco(TextTable.HEADER | TextTable.HLINES) tt.header(['', ''] + sorted(self.conditions_list)) for a in sorted(self.conditions_list): rline = [a, self.coefficient] pline = ['', 'Sig (2-tailed)'] nline = ['', 'N'] for b in sorted(self.conditions_list): if a == b: rline.append('1') pline.append(' .') nline.append(self.N) elif self.has_key((a, b)): rline.append(self[(a, b)]['r']) pline.append(self[(a, b)]['p']) nline.append(self.N) elif self.has_key((b, a)): rline.append(self[(b, a)]['r']) pline.append(self[(b, a)]['p']) nline.append(self.N) tt.add_row([ '%s\n%s\n%s' % (_str(r), _str(p), _str(n)) for r, p, n in zip(rline, pline, nline) ]) tt_lm = TextTable(max_width=0) tt_lm.set_cols_dtype(['t', 'i', 'f', 'a', 'a', 't']) tt_lm.set_cols_align(['l', 'r', 'r', 'r', 'r', 'l']) tt_lm.set_deco(TextTable.HEADER) tt_lm.header( ['Pair', 'i', 'Correlation', 'P', 'alpha/(k-i+1)', 'Sig.']) for row in self.lm: x, y = row[0] tt_lm.add_row(['%s vs. %s' % (x, y)] + row[1:] + ([''], ['**'])[row[3] < row[4]]) return 'Bivariate Correlations\n\n' + tt.draw() + \ '\n\nLarzelere and Mulaik Significance Testing\n\n' + tt_lm.draw()
def __str__(self): if self == {}: return '(no data in object)' tt_s = TextTable(max_width=0) tt_s.set_cols_dtype(['t', 'a', 'a', 'a', 'a']) tt_s.set_cols_align(['l', 'r', 'r', 'r', 'r']) tt_s.set_deco(TextTable.HEADER) tt_s.header(['Groups', 'Count', 'Sum', 'Average', 'Variance']) for g, c, a, v in zip(self.conditions_list, self['ns'], self['mus'], self['vars']): tt_s.add_row([g, c, c * a, a, v]) tt_o = TextTable(max_width=0) tt_o.set_cols_dtype(['t', 'a', 'a', 'a', 'a', 'a', 'a', 'a']) tt_o.set_cols_align(['l', 'r', 'r', 'r', 'r', 'r', 'r', 'r']) tt_o.set_deco(TextTable.HEADER | TextTable.FOOTER) tt_o.header([ 'Source of Variation', 'SS', 'df', 'MS', 'F', 'P-value', 'eta^2', 'Obs. power' ]) tt_o.add_row([ 'Treatments', self['o_ssbn'], self['o_dfbn'], self['o_msbn'], self['o_f'], self['o_p'], self['o_eta2'], self['o_power'] ]) tt_o.add_row([ 'Error', self['o_sswn'], self['o_dfwn'], self['o_mswn'], ' ', ' ', ' ', ' ' ]) tt_o.footer([ 'Total', self['o_ssbn'] + self['o_sswn'], self['o_dfbn'] + self['o_dfwn'], ' ', ' ', ' ', ' ', ' ' ]) tt_a = TextTable(max_width=0) tt_a.set_cols_dtype(['t', 'a', 'a', 'a', 'a', 'a', 'a', 'a']) tt_a.set_cols_align(['l', 'r', 'r', 'r', 'r', 'r', 'r', 'r']) tt_a.set_deco(TextTable.HEADER | TextTable.FOOTER) tt_a.header([ 'Source of Variation', 'SS', 'df', 'MS', 'F', 'P-value', 'eta^2', 'Obs. power' ]) tt_a.add_row([ 'Treatments', self['ssbn'], self['dfbn'], self['msbn'], self['f'], self['p'], self['eta2'], self['power'] ]) tt_a.add_row([ 'Error', self['sswn'], self['dfwn'], self['mswn'], ' ', ' ', ' ', ' ' ]) tt_a.footer([ 'Total', self['ssbn'] + self['sswn'], self['dfbn'] + self['dfwn'], ' ', ' ', ' ', ' ', ' ' ]) posthoc = '' if self.posthoc.lower() == 'tukey' and self.multtest != None: tt_m = TextTable(max_width=0) tt_m.set_cols_dtype(['t'] + ['a'] * len(self.conditions_list)) tt_m.set_cols_align(['l'] + ['l'] * len(self.conditions_list)) tt_m.set_deco(TextTable.HEADER | TextTable.FOOTER) tt_m.header([''] + sorted(self.conditions_list)) for a in sorted(self.conditions_list): rline = [a] for b in sorted(self.conditions_list): if a == b: rline.append('0') elif (a, b) in self.multtest: q = self.multtest[(a, b)]['q'] sig = self.multtest[(a, b)]['sig'] rline.append('%s %s' % (_str(q), sig)) else: rline.append(' ') tt_m.add_row(rline) tt_m.footer([''] * (len(self.conditions_list) + 1)) q_crit10 = self.multtest[(a, b)]['q_crit10'] q_crit05 = self.multtest[(a, b)]['q_crit05'] q_crit01 = self.multtest[(a, b)]['q_crit01'] k = self.multtest[(a, b)]['q_k'] df = self.multtest[(a, b)]['q_df'] posthoc = 'POSTHOC MULTIPLE COMPARISONS\n\n' posthoc += 'Tukey HSD: Table of q-statistics\n' posthoc += tt_m.draw() posthoc += '\n + p < .10 (q-critical[%i, %i] = %s)' % (k, df, q_crit10) posthoc += '\n * p < .05 (q-critical[%i, %i] = %s)' % (k, df, q_crit05) posthoc += '\n ** p < .01 (q-critical[%i, %i] = %s)' % (k, df, q_crit01) if self.posthoc.lower() == 'snk' and self.multtest != None: tt_m = TextTable(max_width=0) tt_m.set_cols_dtype(['t', 'i', 'f', 'a', 'a', 'a', 'a', 't']) tt_m.set_cols_align(['l', 'r', 'r', 'r', 'r', 'r', 'r', 'l']) tt_m.set_deco(TextTable.HEADER) tt_m.header( ['Pair', 'i', '|diff|', 'q', 'range', 'df', 'p', 'Sig.']) for row in self.multtest: x, y = row[0] tt_m.add_row(['%s vs. %s' % (x, y)] + [(v, '-')[np.isnan(v)] for v in row[1:-1]] + [row[-1]]) posthoc = 'POSTHOC MULTIPLE COMPARISONS\n\n' posthoc += 'SNK: Step-down table of q-statistics\n' posthoc += tt_m.draw() posthoc += '\n + p < .10, * p < .05, ** p < .01, *** p < .001' return 'Anova: Single Factor on %s\n\n'%self.val + \ 'SUMMARY\n%s\n\n'%tt_s.draw() + \ "O'BRIEN TEST FOR HOMOGENEITY OF VARIANCE\n%s\n\n"%tt_o.draw() + \ 'ANOVA\n%s\n\n'%tt_a.draw() + \ posthoc
def __str__(self): tt = TextTable(48) tt.set_cols_dtype(['f', 'f']) tt.set_cols_align(['r', 'r']) for (b, v) in zip(self['bin_edges'], self['values'] + ['']): tt.add_row([b, v]) tt.set_deco(TextTable.HEADER) tt.header(['Bins', 'Values']) return ''.join([('', 'Cumulative ')[self.cumulative], ('', 'Density ')[self.density], 'Histogram for ', self.cname, '\n', tt.draw()])
def __str__(self): """Returns human readable string representation of ChiSquare2way""" if self == {}: return '(no data in object)' # SUMMARY tt_s = TextTable(max_width=0) tt_s.set_cols_dtype(['t'] + ['a'] * (self.N_c + 1)) tt_s.set_cols_align(['l'] + ['r'] * (self.N_c + 1)) tt_s.set_deco(TextTable.HEADER | TextTable.FOOTER) tt_s.header([' '] + sorted(self.col_counter) + ['Total']) for r, rv in sorted(self.row_counter.items()): line = [r] for c, cv in sorted(self.col_counter.items()): o = self.counter[(r, c)] e = (rv * cv) / self['N'] line.append('%s\n(%s)' % (_str(o), _str(e))) line.append(rv) tt_s.add_row(line) tt_s.footer(['Total'] + [v for c, v in sorted(self.col_counter.items())] + [self['N']]) # SYMMETRIC TESTS tt_sym = TextTable(max_width=0) tt_sym.set_cols_dtype(['t', 'a', 'a']) tt_sym.set_cols_align(['l', 'r', 'r']) tt_sym.set_deco(TextTable.HEADER) tt_sym.header(['', 'Value', 'Approx.\nSig.']) tt_sym.add_row(["Cramer's V", self['CramerV'], self['CramerV_prob']]) tt_sym.add_row(["Contingency Coefficient", self['C'], self['C_prob']]) tt_sym.add_row(["N of Valid Cases", self['N'], '']) # CHI-SQUARE TESTS tt_a = TextTable(max_width=0) tt_a.set_cols_dtype(['t', 'a', 'a', 'a']) tt_a.set_cols_align(['l', 'r', 'r', 'r']) tt_a.set_deco(TextTable.HEADER) tt_a.header([' ', 'Value', 'df', 'P']) tt_a.add_row( ['Pearson Chi-Square', self['chisq'], self['df'], self['p']]) if self['ccchisq'] != None: tt_a.add_row([ 'Continuity Correction', self['ccchisq'], self['df'], self['ccp'] ]) tt_a.add_row( ['Likelihood Ratio', self['lnchisq'], self['df'], self['lnp']]) tt_a.add_row(["N of Valid Cases", self['N'], '', '']) # POWER tt_p = TextTable(max_width=0) tt_p.set_cols_dtype(['t', 'a']) tt_p.set_cols_align(['l', 'r']) tt_p.set_deco(TextTable.HEADER) tt_p.header(['Measure', ' ']) tt_p.add_row(['Effect size w', self['w']]) tt_p.add_row(['Non-centrality lambda', self['lambda']]) tt_p.add_row(['Critical Chi-Square', self['crit_chi2']]) tt_p.add_row(['Power', self['power']]) return 'Chi-Square: two Factor\n\n' + \ 'SUMMARY\n%s\n\n'%tt_s.draw() + \ 'SYMMETRIC MEASURES\n%s\n\n'%tt_sym.draw() + \ 'CHI-SQUARE TESTS\n%s\n\n'%tt_a.draw() + \ 'CHI-SQUARE POST-HOC POWER\n%s'%tt_p.draw()
def __str__(self): if self == {}: return '(no data in object)' # SUMMARY tt_s = TextTable(max_width=0) tt_s.set_cols_dtype(['t'] + ['a']*len(self.observed)) tt_s.set_cols_align(['l'] + ['r']*len(self.observed)) tt_s.set_deco(TextTable.HEADER) tt_s.header( [' '] + self.conditions_list) tt_s.add_row(['Observed'] + self.observed) tt_s.add_row(['Expected'] + self.expected) # TESTS tt_a = TextTable(max_width=0) tt_a.set_cols_dtype(['t', 'a', 'a', 'a']) tt_a.set_cols_align(['l', 'r', 'r', 'r']) tt_a.set_deco(TextTable.HEADER) tt_a.header([' ', 'Value', 'df', 'P']) tt_a.add_row(['Pearson Chi-Square', self['chisq'], self['df'], self['p']]) tt_a.add_row(['Likelihood Ratio', self['lnchisq'], self['lndf'], self['lnp']]) tt_a.add_row(['Observations', self['N'],'','']) # POWER tt_p = TextTable(max_width=0) tt_p.set_cols_dtype(['t', 'a']) tt_p.set_cols_align(['l', 'r']) tt_p.set_deco(TextTable.HEADER) tt_p.header( ['Measure',' ']) tt_p.add_row(['Effect size w', self['w']]) tt_p.add_row(['Non-centrality lambda', self['lambda']]) tt_p.add_row(['Critical Chi-Square', self['crit_chi2']]) tt_p.add_row(['Power', self['power']]) return 'Chi-Square: Single Factor\n\n' + \ 'SUMMARY\n%s\n\n'%tt_s.draw() + \ 'CHI-SQUARE TESTS\n%s\n\n'%tt_a.draw() + \ 'POST-HOC POWER\n%s'%tt_p.draw()
def __str__(self): if self == {}: return '(no data in object)' if self.B == None: tt = TextTable(max_width=100000000) tt.set_cols_dtype(['t', 'a']) tt.set_cols_align(['l', 'r']) tt.set_deco(TextTable.HEADER) first = 't-Test: One Sample for means\n' tt.header(['', self.aname]) tt.add_row(['Sample Mean', self['mu']]) tt.add_row(['Hypothesized Pop. Mean', self['pop_mean']]) tt.add_row(['Variance', self['var']]) tt.add_row(['Observations', self['n']]) tt.add_row(['df', self['df']]) tt.add_row(['t Stat', self['t']]) tt.add_row(['alpha', self.alpha]) tt.add_row(['P(T<=t) one-tail', self['p1tail']]) tt.add_row(['t Critical one-tail', self['tc1tail']]) tt.add_row(['P(T<=t) two-tail', self['p2tail']]) tt.add_row(['t Critical two-tail', self['tc2tail']]) tt.add_row(['P(T<=t) two-tail', self['p2tail']]) tt.add_row(['Effect size d', self['cohen_d']]) tt.add_row(['delta', self['delta']]) tt.add_row(['Observed power one-tail', self['power1tail']]) tt.add_row(['Observed power two-tail', self['power2tail']]) return '%s\n%s' % (first, tt.draw()) tt = TextTable(max_width=100000000) tt.set_cols_dtype(['t', 'a', 'a']) tt.set_cols_align(['l', 'r', 'r']) tt.set_deco(TextTable.HEADER) if self.paired == True: first = 't-Test: Paired Two Sample for means\n' tt.header(['', self.aname, self.bname]) tt.add_row(['Mean', self['mu1'], self['mu2']]) tt.add_row(['Variance', self['var1'], self['var2']]) tt.add_row(['Observations', self['n1'], self['n2']]) tt.add_row(['Pearson Correlation', self['r'], '']) tt.add_row(['df', self['df'], '']) tt.add_row(['t Stat', self['t'], '']) tt.add_row(['alpha', self.alpha, '']) tt.add_row(['P(T<=t) one-tail', self['p1tail'], '']) tt.add_row(['t Critical one-tail', self['tc1tail'], '']) tt.add_row(['P(T<=t) two-tail', self['p2tail'], '']) tt.add_row(['t Critical two-tail', self['tc2tail'], '']) tt.add_row(['P(T<=t) two-tail', self['p2tail'], '']) tt.add_row(['Effect size dz', self['cohen_d'], '']) tt.add_row(['delta', self['delta'], '']) tt.add_row(['Observed power one-tail', self['power1tail'], '']) tt.add_row(['Observed power two-tail', self['power2tail'], '']) elif self.equal_variance: first = 't-Test: Two-Sample Assuming Equal Variances\n' tt.header(['', self.aname, self.bname]) tt.add_row(['Mean', self['mu1'], self['mu2']]) tt.add_row(['Variance', self['var1'], self['var2']]) tt.add_row(['Observations', self['n1'], self['n2']]) tt.add_row(['Pooled Variance', self['vpooled'], '']) tt.add_row(['df', self['df'], '']) tt.add_row(['t Stat', self['t'], '']) tt.add_row(['alpha', self.alpha, '']) tt.add_row(['P(T<=t) one-tail', self['p1tail'], '']) tt.add_row(['t Critical one-tail', self['tc1tail'], '']) tt.add_row(['P(T<=t) two-tail', self['p2tail'], '']) tt.add_row(['t Critical two-tail', self['tc2tail'], '']) tt.add_row(['P(T<=t) two-tail', self['p2tail'], '']) tt.add_row(['Effect size d', self['cohen_d'], '']) tt.add_row(['delta', self['delta'], '']) tt.add_row(['Observed power one-tail', self['power1tail'], '']) tt.add_row(['Observed power two-tail', self['power2tail'], '']) else: first = 't-Test: Two-Sample Assuming Unequal Variances\n' tt.header(['', self.aname, self.bname]) tt.add_row(['Mean', self['mu1'], self['mu2']]) tt.add_row(['Variance', self['var1'], self['var2']]) tt.add_row(['Observations', self['n1'], self['n2']]) tt.add_row(['df', self['df'], '']) tt.add_row(['t Stat', self['t'], '']) tt.add_row(['alpha', self.alpha, '']) tt.add_row(['P(T<=t) one-tail', self['p1tail'], '']) tt.add_row(['t Critical one-tail', self['tc1tail'], '']) tt.add_row(['P(T<=t) two-tail', self['p2tail'], '']) tt.add_row(['t Critical two-tail', self['tc2tail'], '']) tt.add_row(['P(T<=t) two-tail', self['p2tail'], '']) tt.add_row(['Effect size d', self['cohen_d'], '']) tt.add_row(['delta', self['delta'], '']) tt.add_row(['Observed power one-tail', self['power1tail'], '']) tt.add_row(['Observed power two-tail', self['power2tail'], '']) return ''.join([first, tt.draw()])
def __str__(self): if self == {}: return '(no data in object)' tt_s = TextTable(max_width=0) tt_s.set_cols_dtype(['t', 'a', 'a', 'a', 'a']) tt_s.set_cols_align(['l', 'r', 'r', 'r', 'r']) tt_s.set_deco(TextTable.HEADER) tt_s.header( ['Groups','Count','Sum', 'Average','Variance']) for g, c, a, v in zip(self.conditions_list, self['ns'], self['mus'], self['vars']): tt_s.add_row([g, c, c * a, a, v]) tt_o = TextTable(max_width=0) tt_o.set_cols_dtype(['t', 'a', 'a', 'a', 'a', 'a', 'a', 'a']) tt_o.set_cols_align(['l', 'r', 'r', 'r', 'r', 'r', 'r', 'r']) tt_o.set_deco(TextTable.HEADER | TextTable.FOOTER) tt_o.header( ['Source of Variation','SS','df','MS','F','P-value','eta^2','Obs. power']) tt_o.add_row(['Treatments',self['o_ssbn'],self['o_dfbn'], self['o_msbn'],self['o_f'],self['o_p'], self['o_eta2'],self['o_power']]) tt_o.add_row(['Error', self['o_sswn'],self['o_dfwn'], self['o_mswn'],' ', ' ',' ', ' ']) tt_o.footer( ['Total',self['o_ssbn']+self['o_sswn'], self['o_dfbn']+self['o_dfwn'],' ',' ',' ',' ', ' ']) tt_a = TextTable(max_width=0) tt_a.set_cols_dtype(['t', 'a', 'a', 'a', 'a', 'a', 'a', 'a']) tt_a.set_cols_align(['l', 'r', 'r', 'r', 'r', 'r', 'r', 'r']) tt_a.set_deco(TextTable.HEADER | TextTable.FOOTER) tt_a.header( ['Source of Variation','SS','df','MS','F','P-value','eta^2','Obs. power']) tt_a.add_row(['Treatments',self['ssbn'],self['dfbn'], self['msbn'],self['f'],self['p'], self['eta2'],self['power']]) tt_a.add_row(['Error', self['sswn'],self['dfwn'], self['mswn'],' ', ' ',' ', ' ']) tt_a.footer( ['Total',self['ssbn']+self['sswn'], self['dfbn']+self['dfwn'],' ',' ',' ',' ', ' ']) posthoc = '' if self.posthoc.lower() == 'tukey' and self.multtest != None: tt_m = TextTable(max_width=0) tt_m.set_cols_dtype(['t'] + ['a']*len(self.conditions_list)) tt_m.set_cols_align(['l'] + ['l']*len(self.conditions_list)) tt_m.set_deco(TextTable.HEADER | TextTable.FOOTER) tt_m.header([''] + sorted(self.conditions_list)) for a in sorted(self.conditions_list): rline = [a] for b in sorted(self.conditions_list): if a == b: rline.append('0') elif self.multtest.has_key((a,b)): q = self.multtest[(a,b)]['q'] sig = self.multtest[(a,b)]['sig'] rline.append('%s %s'%(_str(q), sig)) else: rline.append(' ') tt_m.add_row(rline) tt_m.footer(['']*(len(self.conditions_list) + 1)) q_crit10 = self.multtest[(a,b)]['q_crit10'] q_crit05 = self.multtest[(a,b)]['q_crit05'] q_crit01 = self.multtest[(a,b)]['q_crit01'] k = self.multtest[(a,b)]['q_k'] df = self.multtest[(a,b)]['q_df'] posthoc = 'POSTHOC MULTIPLE COMPARISONS\n\n' posthoc += 'Tukey HSD: Table of q-statistics\n' posthoc += tt_m.draw() posthoc += '\n + p < .10 (q-critical[%i, %i] = %s)'%(k, df, q_crit10) posthoc += '\n * p < .05 (q-critical[%i, %i] = %s)'%(k, df, q_crit05) posthoc += '\n ** p < .01 (q-critical[%i, %i] = %s)'%(k, df, q_crit01) if self.posthoc.lower() == 'snk' and self.multtest != None: tt_m = TextTable(max_width=0) tt_m.set_cols_dtype(['t', 'i', 'f', 'a', 'a', 'a', 'a', 't']) tt_m.set_cols_align(['l', 'r', 'r', 'r', 'r', 'r', 'r', 'l']) tt_m.set_deco(TextTable.HEADER) tt_m.header(['Pair', 'i', '|diff|', 'q', 'range', 'df', 'p', 'Sig.']) for row in self.multtest: x, y = row[0] tt_m.add_row(['%s vs. %s'%(x, y)] + [(v,'-')[np.isnan(v)] for v in row[1:-1]] + [row[-1]]) posthoc = 'POSTHOC MULTIPLE COMPARISONS\n\n' posthoc += 'SNK: Step-down table of q-statistics\n' posthoc += tt_m.draw() posthoc += '\n + p < .10, * p < .05, ** p < .01, *** p < .001' return 'Anova: Single Factor on %s\n\n'%self.val + \ 'SUMMARY\n%s\n\n'%tt_s.draw() + \ "O'BRIEN TEST FOR HOMOGENEITY OF VARIANCE\n%s\n\n"%tt_o.draw() + \ 'ANOVA\n%s\n\n'%tt_a.draw() + \ posthoc
def __str__(self): """Returns human readable string representaition of Marginals""" M = [] for v in self['factorials'].values(): M.append(v) M.append(self['dmu']) M.append(self['dN']) M.append(self['dsem']) M.append(self['dlower']) M.append(self['dupper']) M = zip(*M) # transpose # figure out the width needed by the condition labels so we can # set the width of the table flength = sum([max([len(v) for c in v]) for v in self['factorials'].values()]) flength += len(self['factorials']) * 2 # build the header header = self.factors + 'Mean;Count;Std.\nError;'\ '95% CI\nlower;95% CI\nupper'.split(';') dtypes = ['t'] * len(self.factors) + ['f', 'i', 'f', 'f', 'f'] aligns = ['l'] * len(self.factors) + ['r', 'l', 'r', 'r', 'r'] # initialize the texttable and add stuff tt = TextTable(max_width=10000000) tt.set_cols_dtype(dtypes) tt.set_cols_align(aligns) tt.add_rows(M, header=False) tt.header(header) tt.set_deco(TextTable.HEADER) # output the table return tt.draw()
def __str__(self): tt = TextTable(48) tt.set_cols_dtype(['f', 'f']) tt.set_cols_align(['r', 'r']) for (b, v) in zip(self['bin_edges'],self['values']+['']): tt.add_row([b, v]) tt.set_deco(TextTable.HEADER) tt.header(['Bins','Values']) return ''.join([('','Cumulative ')[self.cumulative], ('','Density ')[self.density], 'Histogram for ', self.cname, '\n', tt.draw()])
def __str__(self): if self == {}: return '(no data in object)' if self.B == None: tt = TextTable(max_width=100000000) tt.set_cols_dtype(['t', 'a']) tt.set_cols_align(['l', 'r']) tt.set_deco(TextTable.HEADER) first = 't-Test: One Sample for means\n' tt.header( ['', self.aname]) tt.add_row(['Sample Mean', self['mu']]) tt.add_row(['Hypothesized Pop. Mean', self['pop_mean']]) tt.add_row(['Variance', self['var']]) tt.add_row(['Observations', self['n']]) tt.add_row(['df', self['df']]) tt.add_row(['t Stat', self['t']]) tt.add_row(['alpha', self.alpha]) tt.add_row(['P(T<=t) one-tail', self['p1tail']]) tt.add_row(['t Critical one-tail', self['tc1tail']]) tt.add_row(['P(T<=t) two-tail', self['p2tail']]) tt.add_row(['t Critical two-tail', self['tc2tail']]) tt.add_row(['P(T<=t) two-tail', self['p2tail']]) tt.add_row(['Effect size d', self['cohen_d']]) tt.add_row(['delta', self['delta']]) tt.add_row(['Observed power one-tail', self['power1tail']]) tt.add_row(['Observed power two-tail', self['power2tail']]) return '%s\n%s'%(first, tt.draw()) tt = TextTable(max_width=100000000) tt.set_cols_dtype(['t', 'a', 'a']) tt.set_cols_align(['l', 'r', 'r']) tt.set_deco(TextTable.HEADER) if self.paired == True: first = 't-Test: Paired Two Sample for means\n' tt.header( ['', self.aname, self.bname]) tt.add_row(['Mean', self['mu1'], self['mu2']]) tt.add_row(['Variance', self['var1'], self['var2']]) tt.add_row(['Observations', self['n1'], self['n2']]) tt.add_row(['Pearson Correlation', self['r'], '']) tt.add_row(['df', self['df'], '']) tt.add_row(['t Stat', self['t'], '']) tt.add_row(['alpha', self.alpha, '']) tt.add_row(['P(T<=t) one-tail', self['p1tail'], '']) tt.add_row(['t Critical one-tail', self['tc1tail'], '']) tt.add_row(['P(T<=t) two-tail', self['p2tail'], '']) tt.add_row(['t Critical two-tail', self['tc2tail'], '']) tt.add_row(['P(T<=t) two-tail', self['p2tail'], '']) tt.add_row(['Effect size dz', self['cohen_d'], '']) tt.add_row(['delta', self['delta'], '']) tt.add_row(['Observed power one-tail', self['power1tail'], '']) tt.add_row(['Observed power two-tail', self['power2tail'], '']) elif self.equal_variance: first = 't-Test: Two-Sample Assuming Equal Variances\n' tt.header( ['', self.aname, self.bname]) tt.add_row(['Mean', self['mu1'], self['mu2']]) tt.add_row(['Variance', self['var1'], self['var2']]) tt.add_row(['Observations', self['n1'], self['n2']]) tt.add_row(['Pooled Variance', self['vpooled'], '']) tt.add_row(['df', self['df'], '']) tt.add_row(['t Stat', self['t'], '']) tt.add_row(['alpha', self.alpha, '']) tt.add_row(['P(T<=t) one-tail', self['p1tail'], '']) tt.add_row(['t Critical one-tail', self['tc1tail'], '']) tt.add_row(['P(T<=t) two-tail', self['p2tail'], '']) tt.add_row(['t Critical two-tail', self['tc2tail'], '']) tt.add_row(['P(T<=t) two-tail', self['p2tail'], '']) tt.add_row(['Effect size d', self['cohen_d'], '']) tt.add_row(['delta', self['delta'], '']) tt.add_row(['Observed power one-tail', self['power1tail'], '']) tt.add_row(['Observed power two-tail', self['power2tail'], '']) else: first = 't-Test: Two-Sample Assuming Unequal Variances\n' tt.header( ['', self.aname, self.bname]) tt.add_row(['Mean', self['mu1'], self['mu2']]) tt.add_row(['Variance', self['var1'], self['var2']]) tt.add_row(['Observations', self['n1'], self['n2']]) tt.add_row(['df', self['df'], '']) tt.add_row(['t Stat', self['t'], '']) tt.add_row(['alpha', self.alpha, '']) tt.add_row(['P(T<=t) one-tail', self['p1tail'], '']) tt.add_row(['t Critical one-tail', self['tc1tail'], '']) tt.add_row(['P(T<=t) two-tail', self['p2tail'], '']) tt.add_row(['t Critical two-tail', self['tc2tail'], '']) tt.add_row(['P(T<=t) two-tail', self['p2tail'], '']) tt.add_row(['Effect size d', self['cohen_d'], '']) tt.add_row(['delta', self['delta'], '']) tt.add_row(['Observed power one-tail', self['power1tail'], '']) tt.add_row(['Observed power two-tail', self['power2tail'], '']) return ''.join([first,tt.draw()])
def __str__(self): """Returns human readable string representation of ChiSquare2way""" if self == {}: return '(no data in object)' # SUMMARY tt_s = TextTable(max_width=0) tt_s.set_cols_dtype(['t'] + ['a']*(self.N_c + 1)) tt_s.set_cols_align(['l'] + ['r']*(self.N_c + 1)) tt_s.set_deco(TextTable.HEADER | TextTable.FOOTER) tt_s.header( [' '] + sorted(self.col_counter) + ['Total']) for r, rv in sorted(self.row_counter.items()): line = [r] for c, cv in sorted(self.col_counter.items()): o = self.counter[(r,c)] e = (rv*cv)/self['N'] line.append('%s\n(%s)'%(_str(o), _str(e))) line.append(rv) tt_s.add_row(line) tt_s.footer(['Total'] + [v for c,v in sorted(self.col_counter.items())] + [self['N']]) # SYMMETRIC TESTS tt_sym = TextTable(max_width=0) tt_sym.set_cols_dtype(['t', 'a', 'a']) tt_sym.set_cols_align(['l', 'r', 'r']) tt_sym.set_deco(TextTable.HEADER) tt_sym.header(['','Value','Approx.\nSig.']) tt_sym.add_row(["Cramer's V", self['CramerV'], self['CramerV_prob']]) tt_sym.add_row(["Contingency Coefficient", self['C'], self['C_prob']]) tt_sym.add_row(["N of Valid Cases", self['N'], '']) # CHI-SQUARE TESTS tt_a = TextTable(max_width=0) tt_a.set_cols_dtype(['t', 'a', 'a', 'a']) tt_a.set_cols_align(['l', 'r', 'r', 'r']) tt_a.set_deco(TextTable.HEADER) tt_a.header([' ', 'Value', 'df', 'P']) tt_a.add_row(['Pearson Chi-Square', self['chisq'], self['df'], self['p']]) if self['ccchisq'] != None: tt_a.add_row(['Continuity Correction', self['ccchisq'], self['df'], self['ccp']]) tt_a.add_row(['Likelihood Ratio', self['lnchisq'], self['df'], self['lnp']]) tt_a.add_row(["N of Valid Cases", self['N'], '', '']) # POWER tt_p = TextTable(max_width=0) tt_p.set_cols_dtype(['t', 'a']) tt_p.set_cols_align(['l', 'r']) tt_p.set_deco(TextTable.HEADER) tt_p.header( ['Measure',' ']) tt_p.add_row(['Effect size w', self['w']]) tt_p.add_row(['Non-centrality lambda', self['lambda']]) tt_p.add_row(['Critical Chi-Square', self['crit_chi2']]) tt_p.add_row(['Power', self['power']]) return 'Chi-Square: two Factor\n\n' + \ 'SUMMARY\n%s\n\n'%tt_s.draw() + \ 'SYMMETRIC MEASURES\n%s\n\n'%tt_sym.draw() + \ 'CHI-SQUARE TESTS\n%s\n\n'%tt_a.draw() + \ 'CHI-SQUARE POST-HOC POWER\n%s'%tt_p.draw()
def __str__(self): if self == {}: return '(no data in object)' tt = TextTable(max_width=0) tt.set_cols_dtype(['t', 't'] + ['a']*len(self.conditions_list)) tt.set_cols_align(['l', 'l'] + ['r']*len(self.conditions_list)) tt.set_deco(TextTable.HEADER | TextTable.HLINES) tt.header(['',''] + sorted(self.conditions_list)) for a in sorted(self.conditions_list): rline = [a, self.coefficient] pline = ['', 'Sig (2-tailed)'] nline = ['', 'N'] for b in sorted(self.conditions_list): if a == b: rline.append('1') pline.append(' .') nline.append(self.N) elif self.has_key((a,b)): rline.append(self[(a,b)]['r']) pline.append(self[(a,b)]['p']) nline.append(self.N) elif self.has_key((b,a)): rline.append(self[(b,a)]['r']) pline.append(self[(b,a)]['p']) nline.append(self.N) tt.add_row(['%s\n%s\n%s'%(_str(r),_str(p),_str(n)) for r,p,n in zip(rline,pline,nline)]) tt_lm = TextTable(max_width=0) tt_lm.set_cols_dtype(['t', 'i', 'f', 'a', 'a', 't']) tt_lm.set_cols_align(['l', 'r', 'r', 'r', 'r', 'l']) tt_lm.set_deco(TextTable.HEADER) tt_lm.header(['Pair', 'i', 'Correlation', 'P', 'alpha/(k-i+1)', 'Sig.']) for row in self.lm: x, y = row[0] tt_lm.add_row(['%s vs. %s'%(x, y)] + row[1:] + ([''],['**'])[row[3] < row[4]]) return 'Bivariate Correlations\n\n' + tt.draw() + \ '\n\nLarzelere and Mulaik Significance Testing\n\n' + tt_lm.draw()