예제 #1
0
파일: enem.py 프로젝트: ewout/stats-utils
def ltmgrid(df,acertos,ncols=5,nrows=9,fig=None):
    ''
    if not fig:
        fig = plt.figure()
    qn = 1
    provid = df['ID_PROVA_CN'].values[0]
    for row in range(nrows):
        for col in range(ncols):
            ax = plt.subplot2grid((nrows,ncols),(row,col))
            itemstats, teststats = stats(acertos,hs = 'notapadrao',df=df)
            hscale = itemstats['hscale']
            icc = itemstats['icc'][qn-1]
            hbin = icc[:,0]
            nbin = icc[:,1]
            acertos_no_bin = icc[:,2]
            prob = icc[:,3]
            err = icc[:,4]

            ax.errorbar(hbin,prob,yerr=err,fmt='o')

            x = np.linspace(0.9*min(hscale),1.1*max(hscale),200)
            ltmdif,ltmdisc = ltmfitparams(provid)
            a = ltmdisc['value'][qn]
            b = ltmdif['value'][qn]
            p = invlogit(1.0*a*(x-b))
            ax.plot(x,p,'k-')
            ax.set_ylim(0,1)
            ax.set_yticks([0,0.5,1])

            qn += 1
        fig.subplots_adjust(left=0.1,right=0.95,bottom=0.05,top=0.9,wspace=0.4,hspace=0.4)
    return fig
예제 #2
0
def iccgraph(df,acertos,qn,hs = "scores",fig=None,ax=None):
    ''
    if not fig:
        fig = plt.figure()
    if not ax:
        ax = fig.add_subplot(111)
        ax.set_title(u"Curva Característica do Item "+str(qn))

    itemstats, teststats = stats(acertos,hs = hs,df=df)
    hscale = itemstats['hscale']
    icc = itemstats['icc'][qn-1]
    hbin = icc[:,0]
    nbin = icc[:,1]
    acertos_no_bin = icc[:,2]
    prob = icc[:,3]
    err = icc[:,4]

    const,sconst,nota,snota,itemd,sitemd = itemstats['iccfitsparam'][qn-1]
    ax.errorbar(hbin,prob,yerr=err,fmt='o')
    x = np.linspace(0.9*min(hscale),1.1*max(hscale),200)
    p = invlogit(const+nota*x)
    ax.plot(x,p,'g-')  
    ax.set_ylim(0,1)
    ax.set_yticks([0,0.5,1])
    if hs == 'scores':
        ax.set_xlabel(u"Acertos")
    else:
        ax.set_xlabel(u"Escore Enem")
    ax.set_ylabel(u"Probabilidade")
    
    return fig, ax
예제 #3
0
파일: enem.py 프로젝트: ewout/stats-utils
def ltmfitgraph(df,acertos,qn1,qn2,fig=None):
    'Só usar com prova 89 ou 49!'

    provid = df['ID_PROVA_CN'].values[0]

    if not fig:
        fig = plt.figure()
        fig.suptitle(u"Curvas Características dos Itens "+str(qn1)+" e "+str(qn2)+" (+ ajuste 2PL TRI)")
    ax1 = fig.add_subplot(121)
    ax2 = fig.add_subplot(122)

    for qn,ax in [(qn1,ax1),(qn2,ax2)]:
        itemstats, teststats = stats(acertos,hs = 'notapadrao',df=df)
        hscale = itemstats['hscale']
        icc = itemstats['icc'][qn-1]
        hbin = icc[:,0]
        nbin = icc[:,1]
        acertos_no_bin = icc[:,2]
        prob = icc[:,3]
        err = icc[:,4]

        ax.errorbar(hbin,prob,yerr=err,fmt='o')

        x = np.linspace(0.9*min(hscale),1.1*max(hscale),200)
        ltmdif,ltmdisc = ltmfitparams(provid)
        a = ltmdisc['value'][qn]
        b = ltmdif['value'][qn]
        p = invlogit(1.0*a*(x-b))
        ax.plot(x,p,'k-')
        ax.set_ylim(0,1)
        ax.set_yticks([0,0.5,1])
        ax.set_xlabel(u"Escore Enem Padronizada")
        ax.set_ylabel(u"Probabilidade")

    ax2.set_ylabel('')
    ax1.text(0.05,0.9,'Q'+str(qn1),transform = ax1.transAxes,fontsize='medium',weight='bold')
    ax2.text(0.05,0.9,'Q'+str(qn2),transform = ax2.transAxes,fontsize='medium',weight='bold')


    return fig