rm(list=ls()) ump_b1p_test <- function(data,alpha,p0){ cat("Testing B(1,p) distributed data\n Confidence level: ",alpha,"\n", "Null hypothesis: p=",p0,"\n","Alternative: p>",p0,"\n") if(is.vector(data)){ # finde n n <- length(data) # Bilde die Testgröße T <- sum(data) # Finde die benötigte Schranke für den Test m <- qbinom(1-alpha,size=n,prob=p0) # Finde gamma gamma <- (alpha-(1-pbinom(m,size=n,prob=p0)))/dbinom(m,size=n,prob=p0) if(T>m){ cat("Die Nullhypothese wird verworfen.\n") } else{ if(T==m){ # Werfe eine Münze mit Erfolgswahrscheinlichkeit gamma if(rbinom(1,size=1,prob=gamma)==1){ cat("Die Nullhypothese wird verworfen.\n") } else{ cat("Die Nullhypothese wird angenommen.\n") } } else{ cat("Die Nullhypothese wird angenommen.\n") } } } else{ cat("error: data not provided correctly\n","Please give data as vector.\n") } } ump_plambda_test <- function(data,alpha,lambda0){ cat("Testing P(lambda) distributed data\n Confidence level: ",alpha,"\n", "Null hypothesis: lambda=",lambda0,"\n","Alternative: lambda>",lambda0,"\n") if(is.vector(data)){ # finde n n <- length(data) # Bilde die Testgröße T <- sum(data) # Finde die benötigte Schranke für den Test m <- qpois(1-alpha,lambda=n*lambda0) # Finde gamma gamma <- (alpha-(1-ppois(m,lambda=n*lambda0)))/dpois(m,lambda=n*lambda0) if(T>m){ cat("Die Nullhypothese wird verworfen.\n") } else{ if(T==m){ # Werfe eine Münze mit Erfolgswahrscheinlichkeit gamma if(rbinom(1,size=1,prob=gamma)==1){ cat("Die Nullhypothese wird verworfen.\n") } else{ cat("Die Nullhypothese wird angenommen.\n") } } else{ cat("Die Nullhypothese wird angenommen.\n") } } } else{ cat("error: data not provided correctly\n","Please give data as vector.\n") } } dat <- read.table("C:/Users/Chris/Documents/Stochastik III/R/ump1.dat") ump_b1p_test(dat$x,0.05,0.5) dat <- read.table("C:/Users/Chris/Documents/Stochastik III/R/ump2.dat") ump_plambda_test(dat$x,0.05,3)