% % Chi-square test % % Deigma n=120 zapi eivai amepolnpto par<-c(26,13,21,29,20,11) th<-rep(1/6,6) th<-th*sum(par) (par-th)^2/th x2<-sum((par-th)^2/th) k<-length(par) round(c(x2,k-1,1-pchisq(x2,k-1)),4) % % Chi-square test % % omoigeveia tessapwv pln8usmwv agopia<-c(32,43,16,9) n<-c(87,108,80,25) prop.test(agopia,n) rbind(agopia,n-agopia) chisq.test(rbind(agopia,n-agopia)) % % Chi-square test % % elegxos kalns prosapmogns par<-c(10,31,40,20,10,4,6) k<-length(par) x<-0:(k-1) x n<-sum(par) n m<-sum(par*x/n) m m<-2 th<-dpois(x,m) th th[k]<-1-sum(th[1:(k-1)]) th<-th*n th (par-th)^2/th x2<-sum((par-th)^2/th) round(c(x2,k-1,1-pchisq(x2,k-1)),4) y<-rep(x,par) chisq.gof(y,dist="poisson",lambda=2) cut1<-0:k-0.1 chisq.gof(y,cut.points=cut1,dist="poisson",lambda=2) cut1<-c(0:(k-2),k)-0.1 chisq.gof(y,cut.points=cut1,dist="poisson",lambda=2) % % Chi-square test % % Deigma n=16 U(0,1) set.seed(10) x<-runif(16) x x<-c(0.03292479, 0.90425688, 0.53824256, 0.56344664, 0.96562332, 0.75159740, 0.70403885, 0.73285125, 0.85374230, 0.39210198, 0.84234411, 0.64437900, 0.47865900, 0.11406144, 0.38779575, 0.65575953) hist(x) x.chi1<-chisq.gof(x,dist="uniform") x.chi1 x.chi1$c x.chi1$e ceiling(2*16^(2/5)) x.chi1$s x.chi1$par x.chi1$p. (x.chi1$c-x.chi1$e)^2/x.chi1$e sum((x.chi1$c-x.chi1$e)^2/x.chi1$e) x.chi1$s 1-pchisq(sum((x.chi1$c-x.chi1$e)^2/x.chi1$e),6) x.chi1$p. x.chi1<-chisq.gof(x,n.classes=3,dist="uniform") x.chi1 x.chi1$c x.chi1$e x<-runif(50) chisq.gof(x,dist="uniform") chisq.gof(x,dist="uniform",min=0,max=1.5) % % Chi-square test % % Deigma n=50 N(0,1) x<-rnorm(50) x chisq.gof(x,dist="norm") chisq.gof(x,dist="norm",mean=0,sd=1) chisq.gof(x,dist="norm",mean=1/3,sd=1/3) chisq.gof(x,dist="norm",n.param.est=2) chisq.gof(x,dist="norm",n.param.est=2,mean=mean(x),sd=sqrt(var(x))) mean(x) var(x) y<-rexp(60,3) y summary(y) par(mfrow=c(1,2)) hist(x) hist(y) cdf.compare(x,distr="norm") cdf.compare(x,distr="norm",mean=mean(x),sd=sqrt(var(x))) mean(x) var(x) cdf.compare(y,distr="norm",mean=mean(y),sd=sqrt(var(y))) cdf.compare(x,y) cdf.compare(y,distr="exp",rate=3) qqnorm(y) qqline(y) qqnorm(x) qqline(x) chisq.gof(y,dist="norm",mean=1/3,sd=1/3) chisq.gof(y,dist="norm",mean=0,sd=1) chisq.gof(x,dist="norm") chisq.gof(x,dist="norm",mean=0,sd=1) chisq.gof(x,dist="norm",mean=1/3,sd=1/3) chisq.gof(x,dist="norm",n.param.est=2) chisq.gof(x,dist="norm",n.param.est=2,mean=mean(x),sd=sqrt(var(x))) mean(x) var(x) x.chi1<-chisq.gof(x,dist="norm") x.chi1$c x.chi1$e x.chi1<-chisq.gof(x,dist="norm",n.param.est=2) x.chi1$c x.chi1$e cut1<-(-3:3) cut1 x.chi1<-chisq.gof(x,cut.points=cut1,dist="norm") x.chi1 x.chi1$c x.chi1$e cut3<-c(min(x)-0.1,seq(-1.5,1.5,by=.5),max(x)+0.1) cut3 x.chi3<-chisq.gof(x,cut.points=cut3,dist="norm") x.chi3$c x.chi3$e x.chi3 sum(x.chi3$e) cut3<-c(min(x)-10,seq(-1.5,1.5,by=.5),max(x)+10) x.chi3<-chisq.gof(x,cut.points=cut3,dist="norm") x.chi3 x.chi3$e x.chi3$c sum(x.chi3$e) ks.gof(x,dist="norm") ks.gof(x,dist="norm",mean=0,sd=1) x<-rbinom(20,size=5,prob=1/2) x table(x) x<-rbinom(20,size=5,prob=1/2) table(x) x<-rbinom(20,size=5,prob=1/2) table(x) chisq.gof(x,dist="binom",size=5,prob=1/2) cut<-quantile(x) table(cut(x,cut)) chisq.gof(x,cut.points=cut,dist="binom",size=5,prob=1/2) cut[1]<-cut[1]-1 cut[4]<-cut[4]+1 cut[5]<-cut[5]+1 cut table(cut(x,cut)) cut<-c(-0.5:5.5,1) cut cut<-c(-0.5:5.5) table(cut(x,cut)) chisq.gof(x,cut.points=cut,dist="binom",size=5,prob=1/2) chisq.gof(x,cut.points=cut,dist="binom",size=5,prob=1/2)$e cut<-c(-0.5,1.5:3.5,5.5) chisq.gof(x,cut.points=cut,dist="binom",size=5,prob=1/2) chisq.gof(x,cut.points=cut,dist="binom",size=5,prob=1/2)$e x<-rep(0:7,c(89,143,94,42,20,8,3,1)) x table(x) cut<-c(0:7) table(cut(x,cut)) cut<-c(-1:7) table(cut(x,cut)) chisq.gof(x,cut.points=cut,n.param.est=1,dist="pois",lambda=mean(x))$e chisq.gof(x,cut.points=cut,n.param.est=1,dist="pois",lambda=mean(x))$c cut<-c(-1:4,7) table(cut(x,cut)) chisq.gof(x,cut.points=cut,n.param.est=1,dist="pois",lambda=mean(x))$e chisq.gof(x,cut.points=cut,n.param.est=1,dist="pois",lambda=mean(x)) sum(chisq.gof(x,cut.points=cut,n.param.est=1,dist="pois",lambda=mean(x))$e) % % Sign-Test % % set.seed(100) x<-rnorm(50,3,1) x hist(x) summary(x) qnorm(0.25,3,1) x