Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Graphing a t-distribution

    I'd like to draw a t-distribution with mean 2, std deviation .2 and 14 degrees of freedom.

    Previously, I wrote the code for a normal distribution that looks like this:

    Code:
       #delimit;
       twoway
       function y=normalden(x,claimed_mu,std_error), range(`=tick1' `=tick9')   ///
                  graphregion(color(white)) clstyle(foreground) || 
       (scatteri 0 `=claimed_mu', mcolor(red)) (scatteri 0 `=sample_mean', mcolor(black)),
       plotregion(style(none))
       legend(off)
       xtitle("Sample means of weights of Kitti's hog-nosed bats (g), n=`=n'")
       xlabel(`=tick1' `=tick2' `=tick3' `=tick4' `=tick5' `=tick6' `=tick7' `=tick8' `=tick9', format(%6.4f))
       ylabel(none)
       yscale(off);
       #delimit cr
    I looked at the help for tden, and ntden but wasn't able to write the code. Any assistance would be appreciated.

  • #2
    Here's the entire code that generates the figure:

    Code:
    // CALCULATE PROBABILITY OF MAKING TYPE-I ERROR (P-VALUE)
    
    // SETUP
    
    // List the sample data
       scalar n = 15
       scalar sample_mean = 1.7133
       scalar sample_stdv = 0.25
      
    // State the claim
       scalar claimed_mu = 1.85
       scalar num_tails = 2
      
    // Choose the level of significance
       scalar alpha = 0.04  
    
    
      
    // SPECIFY THE SAMPLING DISTRIBUTION
          
    // Calculate the sample variance
       scalar sample_var = sample_stdv^2
    
    // Calculate the Bessel-correction factor
       scalar bcf = n/(n-1)
      
    // Estimate the population variance
       scalar est_pop_var = bcf*sample_var
    
    // Estimate the variance of the sample mean
       scalar se2 = est_pop_var/n
    
    // Estimate the standard error
       scalar std_error = se2^0.5
      
      
    
    // GRAPHING  
    
    // Graph the distribution of sample means and mark the claimed mean in red and the observed sample mean in black
     
    // Specify the tick marks used for marking the x-axis  
        scalar tick1 = claimed_mu - 4*std_error
        scalar tick2 = claimed_mu - 3*std_error
        scalar tick3 = claimed_mu - 2*std_error
        scalar tick4 = claimed_mu - 1*std_error
        scalar tick5 = claimed_mu - 0*std_error
        scalar tick6 = claimed_mu + 1*std_error
        scalar tick7 = claimed_mu + 2*std_error
        scalar tick8 = claimed_mu + 3*std_error
        scalar tick9 = claimed_mu + 4*std_error
      
    // Make the figure  
       #delimit;
       twoway
       function y=normalden(x,claimed_mu,std_error), range(`=tick1' `=tick9')   ///
                  graphregion(color(white)) clstyle(foreground) ||
       (scatteri 0 `=claimed_mu', mcolor(red)) (scatteri 0 `=sample_mean', mcolor(black)),
       plotregion(style(none))
       legend(off)
       xtitle("Sample means of weights of Kitti's hog-nosed bats (g), n=`=n'")
       xlabel(`=tick1' `=tick2' `=tick3' `=tick4' `=tick5' `=tick6' `=tick7' `=tick8' `=tick9', format(%6.4f))
       ylabel(none)
       yscale(off);
       #delimit cr

    Comment


    • #3
      Please ignore this post. I figured out my mistake.

      Comment

      Working...
      X