e-status

una plataforma basada en web para la realización de problemas de estadística

enlace a e-status

Navegación

Código R de un problema

colo=c("black","red","green","blue","cyan","purple","yellow","grey")
cod=1:8
selc = sample(cod,2,repl=0)
ball1 = colo[selc[1]]
ball2 = colo[selc[2]]
mon=c("heads","tails")
h = sample(1:2,1)         # h=1: heads on left
t = 3-h			  # 'tails'; if h=1, t=2 and viceversa
n = sample(4:15,2,repl=1) # number of balls [left, right]
m1 = sample(2:(n[1]-1),1) # color 1 on left
m2 = sample(2:(n[2]-1),1) # color 1 on right
B1 = c(m1, m2)
q1 = c(rep(selc[1],m1),rep(selc[2],n[1]-m1))
q2 = c(rep(selc[1],m2),rep(selc[2],n[2]-m2))
q1 = sample(q1)
q2 = sample(q2)
x = c(1,3,5,7,9,2,4,6,8,3,5,7,4,6,5)
T = sqrt(3)
y = c(1,1,1,1,1,rep(1+T,4),rep(1+2*T,3),rep(1+3*T,2),1+4*T)
  # (x, y) are coordinates of balls' centers

X1 = x[1:n[1]]
Y1 = y[1:n[1]]
X2 = 15+x[1:n[2]]
Y2 = y[1:n[2]]
bx = c(-1,-1,11,11)
by = c(y[15]+1,0,0,y[15]+1)
graph = ini_imagen(500,250)
op = par();
par(mar=c(0.5,0.5,0.5,0.2));
plot(c(-5,30),c(0,10),type="n",asp=1,axes=0,xlab="",ylab="")
symbols(X1,Y1,circ=rep(1,n[1]),bg=q1,asp=1,inc=0,add=1)
symbols(X2,Y2,circ=rep(1,n[2]),bg=q2,asp=1,inc=0,add=1)
lines(bx,by)
lines(15+bx,by)
text(5,10,lab=mon[h],cex=2)
text(20,10,lab=mon[t],cex=2)
par(op)
fin_imagen()

P_samecolor = (m1*m2 + (n[1]-m1)*(n[2]-m2))/(n[h]*n[t])
B2 = n-B1                  # balls color 2 [left, right]
P_2.H = B2[h]/n[h]
P_2.T = B2[t]/n[t]
P_2 = (P_2.H + P_2.T)/2    # P(h) = P(t) = 0.5
P_H.2 = P_2.H*0.5/P_2
P_1 = 1-P_2
expect = n[1]/m1