title: Having Trouble Visualizing a T-Distribution in Python
body: <p>I'm attempting to add a simple t-score visualization to some analysis utilities I'm writing (plotting scipy's <code>pdf</code> probability density function over an interval). In this example, I'm plotting a Student's t distribution, along with critical t-score cutoffs for a given problem set. However, the simple vis just isn't turning out correctly so far as I can tell.</p>
  
  <p>In this example, I have an <code>n=24</code> dataset and I'm trying to visualize an <code>alpha=0.05</code> two tailed test for it (AKA statistical significance indicated by 2.5% in either tail of the distribution). I would expect the critical t-score to intersect the t-distribution at a y (probability) value of 0.025, but the t-distribution itself seems to be scaled/flattened? by some amount. </p>
  
  <p>So far as I can tell, the t distribution just doesn't match up with what I would expect actual probabilities to be, but the setup is simple enough where I can't tell where I'm going wrong. I am somewhat new to statistics and am wondering if I'm missing something fundamental here? </p>
  
  <pre><code>## Basic T-Distribution
  import scipy.stats as st
  import matplotlib.pyplot as plt
  import numpy as np
  
  ## Setup      
  dof = 23        # Degrees of freedom
  alpha = 0.05    # Significence level
  ntails = 2      # Number of tails 
  
  ## Calculate critical t-score
  tcrit = abs(st.t.ppf(alpha/ntails, dof))
  # +=2.068
  
  plt.figure()
  xs = np.linspace(-10,10,1000)
  plt.plot(xs, st.t.pdf(xs,dof), 'k', label="T-Distribution PDF")
  
  ## Plot some vertical lines representing critical t-score cutoff
  critline = np.linspace(0,alpha/ntails)  # y range for critical line, AKA probability from 0-p*
  xs_1 = len(critline) * [-tcrit]         # X ranges for plotting
  xs_2 = len(critline) * [tcrit]
  plt.plot(xs_1, critline, 'r', label="-t* for dof=23")
  plt.plot(xs_2, critline,'r', label="t* for dof=23")
  plt.legend()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/s9Slr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s9Slr.png" alt="T-Vis"></a></p>