# Luennot vko 38/(20.9.) # Pallojen sijoittaminen lokeroihin #H1.1 # 3 palloa 3:een lokeroon, 3^3 kpl lokerot<-c(1,2,3) expand.grid(p1=lokerot,p2=lokerot,p3=lokerot) # 2 palloa 3:een lokeroon, 3^2 kpl lokerot<-c(1,2,3) expand.grid(p1=lokerot,p2=lokerot) # 3 palloa 2:een lokeroon, 2^3 lokerot<-c(1,2) expand.grid(p1=lokerot,p2=lokerot,p3=lokerot) ####### library(combinat) help("library") library(help = combinat) ######## # Luennot vko 38/(21.9.) # Todennäköisyysfunktio ####################### # Silmälukujen summa, 2 noppaa x<-2:12; p<-c(1:6,5:1)/36 plot(x,p,type="h") points(x,p) # plot(x,p,type="h",xlim=c(0,14),ylim=c(0,0.20)) # sum(p) # Y=min{7,X}, SM:n X funktio x<-2:7; p<-c(1:5,21)/36 plot(x,p,type="h") # points(x,p,pch=19);points(x,p,pch=20) # Kertymäfunktio ################### # Kertymäfunktio, lanttia 2 kertaa, kruunujen lkm x<-0:2 # X:n arvojoukko {0,1,2} p<-c(0,1/4,1/2,1/4) # Arvojen tn:t cp<-cumsum(p) # Arvojen kumulatiiviset tn:t Ffun<-stepfun(x, cp, f = 0) plot(Ffun,verticals= FALSE) # Hypergeometrinen jakauma ########################## dhyper(x, a, b, n) # tnf, a valkoisten ja b mustien pallojen lkm; n otoskoko phyper(x, a, b, n) # kf # x on pallojen lkm otoksessa; x<=min(a,n) a<-2; b<-3; n<-3 x<-0:min(a,n) tnf<-dhyper(x, a, b, n) # tnf:n kuvaaja plot(x,tnf,type="h",xlim=c(-1,3)) points(x,tnf) # Kertymäfunktio F<-c(0,phyper(x, a, b, n)) Ffun<-stepfun(x, F, f = 0) plot(Ffun,verticals= FALSE) F<-phyper(x, a, b, n); Fv<-c(0,F) Ffun<-stepfun(x, Fv, f = 0) plot(Ffun,verticals= FALSE)