Ejemplo psicometría

833 days ago by sevillad

Notas de prácticas de AJO 2014-15. El fichero adjunto (CSV) tiene en la primera fila los nombres de los ítems con su valor entre corchetes.

import csv fichero = list( csv.reader(open(DATA+'notas_ajo1415.csv'),delimiter=";") ) clave = fichero[0][1:] clave_u = [qq.decode('latin_1') for qq in clave] clave_short = [qq[0:3] for qq in clave] maxvals = [float(nn[nn.find("[")+1:-1]) for nn in clave] datosdict = dict([(fila[0],map(float,fila[1:])) for fila in fichero[1:]]) # notas normalizadas de 0 a 1 notas = [map(operator.div,datosdict[n],maxvals) for n in sorted(datosdict.keys())] # notas sin normalizar (se hace abajo donde se necesita) notas = [datosdict[n] for n in sorted(datosdict.keys())] items = len(notas[0]) students = len(notas) print students,"estudiantes, ", items,"ítems", clave_short preguntasnotas = zip(*notas) totalnotas = map(sum,notas) 
       
12 estudiantes,  10 ítems ['P0 ', 'P1 ', 'P2 ', 'P3 ', 'P4 ', 'P5 ', 'P6
', 'CUE', 'PAR', 'T. ']
12 estudiantes,  10 ítems ['P0 ', 'P1 ', 'P2 ', 'P3 ', 'P4 ', 'P5 ', 'P6 ', 'CUE', 'PAR', 'T. ']
# índices de normalidad: medias normalizadas entre 0 y 1 p = map(operator.div,map(mean,preguntasnotas),maxvals) p 
       
[0.7166666666666668, 0.7916666667055556, 0.8402777777907408,
0.8177083334305555, 0.513888888875926, 0.325, 0.4166666667444444, 0.555,
0.625, 0.35416666666666674]
[0.7166666666666668, 0.7916666667055556, 0.8402777777907408, 0.8177083334305555, 0.513888888875926, 0.325, 0.4166666667444444, 0.555, 0.625, 0.35416666666666674]
correl_item_test = [ r.cor(preguntasnotas[i],totalnotas).n() for i in range(items) ] correl_item_resto = [ r.cor(preguntasnotas[i], map(operator.sub,totalnotas,preguntasnotas[i])).n() for i in range(items) ] correl_item_test; correl_item_resto 
       
[0.721786598742990, 0.678893245851729, 0.161252636892223,
0.500386168079134, 0.454329150098941, 0.741464194545815,
0.552242354278292, 0.574724706979649, 0.899258610730791,
0.935374413604305]
[0.697733782589219, 0.665095741075175, 0.143206693059570,
0.473507567369247, 0.409708436079680, 0.718273802056305,
0.516423114344883, 0.462312290801168, 0.805959114504777,
0.765092812173782]
[0.721786598742990, 0.678893245851729, 0.161252636892223, 0.500386168079134, 0.454329150098941, 0.741464194545815, 0.552242354278292, 0.574724706979649, 0.899258610730791, 0.935374413604305]
[0.697733782589219, 0.665095741075175, 0.143206693059570, 0.473507567369247, 0.409708436079680, 0.718273802056305, 0.516423114344883, 0.462312290801168, 0.805959114504777, 0.765092812173782]
s = map(lambda x:std(x,bias=True),preguntasnotas) alfa_cronbach = items/(items-1)*(1-sum(map(lambda x:x^2,s))/variance(totalnotas,bias=True)) alfa_cronbach 
       
0.6757961328809959
0.6757961328809959
def alfa_fromitems(n): L = n/items return L*alfa_cronbach/(1+(L-1)*alfa_cronbach) def items_fromalfa(a): return items * a*(1-alfa_cronbach)/alfa_cronbach/(1-a) alfa_fromitems(40); items_fromalfa(0.7) 
       
0.8929097213742622
11.1938446099033
0.8929097213742622
11.1938446099033
porcentaje = 25 num_estudiantes_HL = ceil(students*porcentaje/100) notas_ordenadastotal = sorted(notas,key=sum) # de menor a mayor total nL = map(mean,zip(*notas_ordenadastotal[:num_estudiantes_HL])) nH = map(mean,zip(*notas_ordenadastotal[-num_estudiantes_HL:])) indices_discrim = map(operator.sub,nH,nL) indices_discrim = map(operator.div,indices_discrim,maxvals) indices_discrim 
       
[0.5833333333333333, 0.2777777776740741, 0.1250000001555556,
0.14583333325555553, 0.3888888888370371, 0.5166666666666667,
0.4583333334888889, 0.5599999999999999, 1.0, 0.7166666666666666]
[0.5833333333333333, 0.2777777776740741, 0.1250000001555556, 0.14583333325555553, 0.3888888888370371, 0.5166666666666667, 0.4583333334888889, 0.5599999999999999, 1.0, 0.7166666666666666]
 
       
r3 = lambda x: x.n(digits=3) r3 = lambda x: "%.3f" % x def r3(n): if type(n) == Integer or type(n) == int: return "%.0f" % n else: return "%.3f" % n html.table([ ["n. items","$\\alpha$"], map(r3,[items,alfa_cronbach]), map(r3,[40,alfa_fromitems(40)]), map(r3,[items_fromalfa(0.7),0.7]), ], header=True) html.table([ ["item"]+clave_short, ["p"]+map(r3,p), ["r_test"]+map(r3,correl_item_test), ["r_resto"]+map(r3,correl_item_resto), ["i_discrim"]+map(r3,indices_discrim), ], header=True) 
       
n. items
10 0.676
40 0.893
11.194 0.700
item P0 P1 P2 P3 P4 P5 P6 CUE PAR T.
p 0.717 0.792 0.840 0.818 0.514 0.325 0.417 0.555 0.625 0.354
r_test 0.722 0.679 0.161 0.500 0.454 0.741 0.552 0.575 0.899 0.935
r_resto 0.698 0.665 0.143 0.474 0.410 0.718 0.516 0.462 0.806 0.765
i_discrim 0.583 0.278 0.125 0.146 0.389 0.517 0.458 0.560 1.000 0.717
n. items
10 0.676
40 0.893
11.194 0.700
item P0 P1 P2 P3 P4 P5 P6 CUE PAR T.
p 0.717 0.792 0.840 0.818 0.514 0.325 0.417 0.555 0.625 0.354
r_test 0.722 0.679 0.161 0.500 0.454 0.741 0.552 0.575 0.899 0.935
r_resto 0.698 0.665 0.143 0.474 0.410 0.718 0.516 0.462 0.806 0.765
i_discrim 0.583 0.278 0.125 0.146 0.389 0.517 0.458 0.560 1.000 0.717
 
       
%hide import matplotlib.pyplot as plt #fig = plt.figure(figsize=(8,5)) xx = [1..items] p1 = plt.bar(xx,p, align="center") plt.hlines(0.8, 0, items+1, color="r",linestyles="dotted") plt.hlines(0.2, 0, items+1, color="r",linestyles="dotted") ll = plt.hlines(mean(p), 0, items+1, color="b", label='Inline label') ll.set_label("a") #plt.text(items+1,mean(p)+0.02,"a",color="b") #plt.ylabel('Scores') plt.title(u'Índices de dificultad') plt.xticks( [1..items],clave_short ) plt.yticks( [0,0.1..1] ) plt.legend( [ll], ['media'] ) plt.show() plt.savefig('bar1.png') plt.close() 
       
%hide import matplotlib.pyplot as plt fig = plt.figure(figsize=(8,5)) xx = [1..items] p1 = plt.bar(xx,indices_discrim, align="center") plt.hlines(0, 0, items+1) plt.hlines(0.2, 0, items+1, color="r",linestyles="dotted") #plt.ylabel('Scores') plt.title(u'Índices de discriminación') plt.xticks( [1..items] ) plt.xticks( [1..items], clave_short ) plt.yticks( [0,0.1..1] ) #plt.legend( (p1[0],p1[0]), ('p','p') ) plt.show() plt.savefig('bar1.png') plt.close() 
       
%hide import matplotlib.pyplot as plt fig=plt.figure(figsize=(8,5)) #ax = fig.add_subplot(211) #bx = fig.add_subplot(111) xx = [1..items] p1 = plt.bar(xx,correl_item_test, align="center") p2 = plt.bar(xx,correl_item_resto ,align="center",color="r") #plt.ylabel('Scores') plt.title(u'Correlaciones ítem-test e ítem-resto') plt.xticks( [1..items] ) plt.xticks( [1..items], clave_short ) plt.yticks( [0,0.1..1] ) plt.legend( (p1[0], p2[0]), ('test', 'resto') ) plt.show() plt.savefig('bar3.png') plt.close()