r - ks.test with left truncated weibull -


the distribution accept values follow left truncated weibull distribution. know parameters a, shape , scale of distribution using ptrunc command:

require(truncdist);  ptrunc(x,"weibull",a=a,scale=b,shape=c) 

so want ks.test command (see below) use described left truncated weibull distribution instead of "normal weibull".

myvalues<-c(37.5, 35.4, 27.1, 32.9, 35.9, 35.1, 34.1, 32.5, 35.5, 31.5, 38.2, 36.1,,29.9, 30.1, 34.7, 38.7 ,32.3, 38.0, 34.9, 44.2, 35.8, 30.8, 39.3, 26.0, 34.2, 40.0, 36.1 ,41.5 ,32.8, 31.9, 41.3 ,30.5, 39.9, 35.0 ,31.2 ,35.0, 30.3, 29.0, 34.4, 35.7, 34.1, 35.4);  a<-7; scale<-36.37516; shape<-9.437013;  

so know, in case not necessary left-side truncation. in others be.

ks.test(myvalues,"pweibull",scale=b,shape=c) #for normal weibull 

but

ks.test(myvalues,ptrunc(x,"weibull",a=a,scale=b,shape=c)) # leftruncated 

gives wrong result.

first of all, ptrunc should replaced rtrunc. ptrunc gives vector of probability values. documentation of ks.test need sample, , rtrunc gives us. if argument a of rtrunc set -inf, there no truncation , result a=-inf indeed same a=7:

library(truncdist)  myvalues <- c(37.5, 35.4, 27.1, 32.9, 35.9, 35.1, 34.1, 32.5, 35.5, 31.5, 38.2, 36.1,29.9, 30.1, 34.7, 38.7 ,32.3, 38.0, 34.9, 44.2, 35.8, 30.8, 39.3, 26.0, 34.2, 40.0, 36.1 ,41.5 ,32.8, 31.9, 41.3 ,30.5, 39.9, 35.0 ,31.2 ,35.0, 30.3, 29.0, 34.4, 35.7, 34.1, 35.4)  <- 7 scale<-36.37516 shape <- 9.437013  set.seed(1) y1 <- rtrunc(myvalues,"weibull",a=-inf,scale=scale,shape=shape)  set.seed(1) y2 <- rtrunc(myvalues,"weibull",a=a,scale=scale,shape=shape)  set.seed(1) ks0 <- ks.test( myvalues, "pweibull",scale=scale,shape=shape  )  set.seed(1) ks1 <- ks.test( myvalues, y1 )  set.seed(1) ks2 <- ks.test( myvalues, y2 ) 

.

> ks1      two-sample kolmogorov-smirnov test  data:  myvalues , y1 d = 0.21429, p-value = 0.2898 alternative hypothesis: two-sided  > ks2      two-sample kolmogorov-smirnov test  data:  myvalues , y2 d = 0.21429, p-value = 0.2898 alternative hypothesis: two-sided 

but still result of ks.test( myvalues, "pweibull",scale=scale,shape=shape ) different:

> ks0      one-sample kolmogorov-smirnov test  data:  myvalues d = 0.15612, p-value = 0.2576 alternative hypothesis: two-sided 

the reason myvalues small. if make larger in call of rtrunc (not ks.test), ks0, ks1, , ks2 same:

library(truncdist)  myvalues <- c(37.5, 35.4, 27.1, 32.9, 35.9, 35.1, 34.1, 32.5, 35.5, 31.5, 38.2, 36.1,29.9, 30.1, 34.7, 38.7 ,32.3, 38.0, 34.9, 44.2, 35.8, 30.8, 39.3, 26.0, 34.2, 40.0, 36.1 ,41.5 ,32.8, 31.9, 41.3 ,30.5, 39.9, 35.0 ,31.2 ,35.0, 30.3, 29.0, 34.4, 35.7, 34.1, 35.4)  mymanyvalues <- c(outer((0:9999)/100000,myvalues,"+"))  <- 7 scale<-36.37516 shape <- 9.437013  set.seed(1) y1 <- rtrunc(mymanyvalues,"weibull",a=-inf,scale=scale,shape=shape)  set.seed(1) y2 <- rtrunc(mymanyvalues,"weibull",a=a,scale=scale,shape=shape)  set.seed(1) ks0 <- ks.test( myvalues, "pweibull",scale=scale,shape=shape  )  set.seed(1) ks1 <- ks.test( myvalues, y1 )  set.seed(1) ks2 <- ks.test( myvalues, y2 ) 

.

> ks0      one-sample kolmogorov-smirnov test  data:  myvalues d = 0.15612, p-value = 0.2576 alternative hypothesis: two-sided  > ks1      two-sample kolmogorov-smirnov test  data:  myvalues , y1 d = 0.15655, p-value = 0.2548 alternative hypothesis: two-sided  > ks2      two-sample kolmogorov-smirnov test  data:  myvalues , y2 d = 0.15655, p-value = 0.2548 alternative hypothesis: two-sided 

now let's see happens when do truncate distribution:

library(truncdist)  myvalues <- c(37.5, 35.4, 27.1, 32.9, 35.9, 35.1, 34.1, 32.5, 35.5, 31.5, 38.2, 36.1,29.9, 30.1, 34.7, 38.7 ,32.3, 38.0, 34.9, 44.2, 35.8, 30.8, 39.3, 26.0, 34.2, 40.0, 36.1 ,41.5 ,32.8, 31.9, 41.3 ,30.5, 39.9, 35.0 ,31.2 ,35.0, 30.3, 29.0, 34.4, 35.7, 34.1, 35.4)  mymanyvalues <- c(outer((0:9999)/100000,myvalues,"+"))  <- 29 scale<-36.37516 shape <- 9.437013  set.seed(1) y1 <- rtrunc(mymanyvalues,"weibull",a=-inf,scale=scale,shape=shape)  set.seed(1) y2 <- rtrunc(mymanyvalues,"weibull",a=a,scale=scale,shape=shape)  set.seed(1) ks0 <- ks.test( myvalues, "pweibull",scale=scale,shape=shape  )  set.seed(1) ks1 <- ks.test( myvalues, y1 )  set.seed(1) ks2 <- ks.test( myvalues, y2 ) 

.

> ks0      one-sample kolmogorov-smirnov test  data:  myvalues d = 0.15612, p-value = 0.2576 alternative hypothesis: two-sided  > ks1      two-sample kolmogorov-smirnov test  data:  myvalues , y1 d = 0.15655, p-value = 0.2548 alternative hypothesis: two-sided  > ks2      two-sample kolmogorov-smirnov test  data:  myvalues , y2 d = 0.2059, p-value = 0.05683 alternative hypothesis: two-sided 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -