def idbar2(acertos,acertos2,maxitems=10,fig=None,ax=None): '' itemstats, teststats = stats(acertos) itemstats2, teststats2 = stats(acertos2) id27 = itemstats['id25'] id279 = itemstats2['id25'] iddf = pandas.DataFrame(id27,index=range(1,len(id27)+1)) iddf = iddf.sort(columns=0) iddf = iddf[0:maxitems] iddf9 = pandas.DataFrame(id279,index=range(1,len(id279)+1)) iddf9 = iddf9.sort(columns=0) iddf9 = iddf9[0:maxitems] if not fig: fig = plt.figure() if not ax: ax = fig.add_subplot(111) ax.set_title(u"Índice de Discriminação (quartis)") fig,ax = orderedfig(iddf.index,iddf[0],iddf9.index,iddf9[0],maxitems,fig,ax) ax.set_xlabel(u"") ax.set_ylim(-0.01,0.15) ax.text(0.5,-0.1,u"Item",clip_on=False,transform = ax.transAxes,ha='center') return fig,ax
def itemfbar2(acertos,acertos2,maxitems=10,fig=None,ax=None): '' itemstats, teststats = stats(acertos) itemf = itemstats['itemf'] itemstats2, teststats2 = stats(acertos2) itemf2 = itemstats2['itemf'] itemfdf = pandas.DataFrame(itemstats['itemf'],index=range(1,len(itemf)+1)) itemfdf = itemfdf.sort(columns=0) itemfdf = itemfdf[0:maxitems] itemfdf2 = pandas.DataFrame(itemstats2['itemf'],index=range(1,len(itemf2)+1)) itemfdf2 = itemfdf2.sort(columns=0) itemfdf2 = itemfdf2[0:maxitems] if not fig: fig = plt.figure() if not ax: ax = fig.add_subplot(111) ax.set_title(u"Índice de Dificuldade") ax.set_ylabel(u"Fração dos alunos que acertaram a questão") ax.set_ylim(0,0.25) fig,ax = orderedfig(itemfdf.index,itemfdf[0],itemfdf2.index,itemfdf2[0],maxitems,fig,ax) ax.text(0.5,-0.1,u"Itens em ordem de dificuldade",clip_on=False,transform = ax.transAxes,ha='center') return fig,ax
def iccfitgraph(df,acertos,fig=None): '' if not fig: fig = plt.figure() #fig.suptitle(u"Parámetros dos fits logisticos") ax1 = fig.add_subplot(211) ax1.set_title(u"Dificuldade") ax2 = fig.add_subplot(212) ax2.set_title(u"Discriminição") itemstats, teststats = stats(acertos,'nota') iccfitsparam = itemstats['iccfitsparam'] itemds = [p[4] for p in iccfitsparam] err = [p[5] for p in iccfitsparam] x = np.arange(1,len(itemds)+1) ax1.errorbar(x,itemds,yerr=err,fmt='o') ax1.set_ylim(0,1400) ax1.set_xlim(0,48) ax1.set_xticklabels([]) itemn = [p[2] for p in iccfitsparam] err = [p[3] for p in iccfitsparam] x = np.arange(1,len(itemn)+1) ax2.errorbar(x,itemn,yerr=err,fmt='o') ax2.set_xlabel(u"Questão") #ax1.set_ylim(0,1000) ax2.set_xlim(0,48) ax2.set_xticks([1,5,10,15,20,25,30,35,40,45]) return fig
def tpmfitgraph(df,acertos,qn,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)+" (+ 3PL fit)") 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) # p = invlogit(const+nota*x) # ax.plot(x,p,'g-') ax.set_ylim(0,1) ax.set_yticks([0,0.5,1]) ax.set_xlabel(u"Escore Enem Padronizada") ax.set_ylabel(u"Probabilidade") return fig, ax
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
def resvec(df,rescol,gabcol,hscale=None): '' dmap = {'A':1, 'B':2, 'C':3, 'D':4, 'E':5, '.':'NA', '*':'NA' } tonumbers = lambda x: dmap[x] res = df[rescol] gab = df[gabcol] l = [] l1 = [] for rvec,gvec in zip(res,gab): l.append([1 if x==y else 0 for x,y in zip(rvec,gvec)]) l1.append(map(tonumbers,rvec)) a = np.array(l) an = np.array(l1) df['res'] = list(a) df['gab'] = gab df['ressum'] = a.sum(axis=1) df['resstd'] = a.std(axis=1) itemstats, teststats = stats(a,hscale,df) return df, itemstats, teststats, a, an
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
def itemfbar(acertos,acertos2,order=True,fig=None,ax=None): '' itemstats, teststats = stats(acertos) itemf = itemstats['itemf'] itemstats2, teststats2 = stats(acertos2) itemf2 = itemstats2['itemf'] if order: itemfdf = pandas.DataFrame(itemstats['itemf'],index=range(1,len(itemf)+1)) itemfdf = itemfdf.sort(columns=0) itemfdf2 = pandas.DataFrame(itemstats2['itemf'],index=range(1,len(itemf2)+1)) itemfdf2 = itemfdf2.sort(columns=0) if not fig: fig = plt.figure() if not ax: ax = fig.add_subplot(111) ax.set_title(u"Número do item em ordem de dificuldade") width = 0.5 if order: ax.bar(np.arange(1,len(itemf)+1),itemfdf[0],width=width,align='center',color='b',label="ENEM 2010") ax.bar(np.arange(1+width,len(itemf)+1+width),itemfdf2[0],width=width,align='center',color="g",label="ENEM 2009") else: ax.bar(np.arange(1,len(itemf)+1),itemf,width=width,align='center') # ax.plot([0,len(itemf)+1],[0.2,0.2],'b',label="Chute",linewidth=2) # ax.plot([0,len(itemf)+1],[itemf.mean(),itemf.mean()],'k',label=u"Média",linewidth=2) m10 = itemf.mean() m9 = itemf2.mean() ax.annotate(u"Médias",xy=(0,m10),xytext=(10,m10),color='k',arrowprops=dict(facecolor='b',width=2,shrink=0.05)) ax.annotate("",xy=(0,m9),xytext=(10,m9),color='g',arrowprops=dict(facecolor='g',width=2,shrink=0.05)) ax.annotate("Chute",xy=(0,0.2),xytext=(10,0.25),color='k',arrowprops=dict(facecolor='grey',width=1,shrink=0.05)) ax.legend(loc=2) ax.set_ylabel(u"Fração dos alunos que acertaram a questão") ax.set_xlabel(u"Item") ax.set_ylim(0,1) ax.set_xlim(0,len(itemf)+1) if order: ax.set_xticks([]) else: ax.set_xticks([1,5,10,15,20,25,30,35,40,45]) return fig,ax
def idbar(acertos,acertos2,order=True,fig=None,ax=None): '' itemstats, teststats = stats(acertos) itemstats2, teststats2 = stats(acertos2) #id50 = itemstats['id50'] id27 = itemstats['id27'] id279 = itemstats2['id27'] if order: iddf = pandas.DataFrame(id27,index=range(1,len(id27)+1)) iddf = iddf.sort(columns=0) iddf9 = pandas.DataFrame(id279,index=range(1,len(id279)+1)) iddf9 = iddf9.sort(columns=0) if not fig: fig = plt.figure() if not ax: ax = fig.add_subplot(111) ax.set_title(u"Índice de Discriminação") width = 0.5 if order: ax.bar(np.arange(1,len(id27)+1),iddf[0],width=width,align='center',color='b',label=u'2010') ax.bar(np.arange(1+width,len(id279)+1+width),iddf9[0],width=width,align='center',color='g',label="2009") else: ax.bar(np.arange(1,len(id27)+1),id27,width=width,align='center',color='b',label=u'diferença de acertos entre os piores e melhores 27%') #ax.text(u'diferença de acertos entre os piores e melhores 27%') ax.legend(loc="upper left") ax.set_xlabel(u"Itens em ordem de discriminação") ax.set_ylim(-0.05,0.4) ax.set_xlim(0,len(id27)+1) if order: ax.set_xticks([]) else: ax.set_xticks([1,5,10,15,20,25,30,35,40,45]) return fig,ax
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