Segment 24

From Computational Statistics (CSE383M and CS395T)
Revision as of 16:53, 3 April 2013 by Kkumar (talk | contribs) (Class Activity)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Calculation Problems

1. Let <math>X</math> be an R.V. that is a linear combination (with known, fixed coefficients <math>\alpha_k</math>) of twenty <math>N(0,1)</math> deviates. That is, <math>X = \sum_{k=1}^{20} \alpha_k T_k</math> where <math>T_k \sim N(0,1)</math>. How can you most simply form a t-value-squared (that is, something distributed as <math>\text{Chisquare}(1)</math> from <math>X</math>? For some particular choice of <math>\alpha_k</math>'s (random is ok), generate a sample of <math>x</math>'s, plot their histogram, and show that it agrees with <math>\text{Chisquare}(1)</math>.

3. Reproduce the table of critical <math>\Delta\chi^2</math> values shown in slide 7.

<math> \Delta\chi^2</math> is the inverse cumulative function of the <math>\chi^2</math> distribution with it's degree of freedom.

chi2.pph(q,df)

where q is the distribution's confidence leven and df the degree of freedom

Food for Thought Problems

Class Activity

Worked with Jin and Sean

from scipy.stats import *
import scipy.optimize
def model(b, x):
    err = norm.rvs(0,1)
    return b[0] + (b[1]*x) + err
xvalue = np.arange(1,101)
x = [xvalue for i in range(1000)]

def genData():
    yvalue = []
    for i in range(len(xvalue)):
        yvalue.append(model(np.array([3, 7]), xvalue[i]))
    return yvalue

def chisq(b,x,y):
    return (y-b[0]-(b[1]*x))

def gen1000Data():
   return [genData() for i in range(1000)]

y = gen1000Data()
chimany = []
for i in range(1000):
    bfit,cofit,chi,_,_ = scipy.optimize.leastsq(chisq, [1,2], args=(x[i],y[i]), full_output=True)
    chimany.append(sum(chi['fvec']**2))
    
chichi = scipy.stats.chi2.pdf(xvalue,98)
chi = []
for i in range(len(chichi)):    
    chi.append(chichi[i]/sum(chichi))
plt.plot(chichi)
plt.hist(chimany,bins=50)

24 ClassActivity.png