Вопрос

I need to extract the p-value from SIGN.test function in package BSDA:

> library(BSDA)
> x <- c(7.8, 6.6, 6.5, 7.4, 7.3, 7., 6.4, 7.1, 6.7, 7.6, 6.8)
> t1=SIGN.test(x,md=6.5)

        One-sample Sign-Test

data:  x
s = 9, p-value = 0.02148
alternative hypothesis: true median is not equal to 6.5
95 percent confidence interval:
 6.571273 7.457455
sample estimates:
median of x 
          7     

But I am getting the following error:

> t1$p.value
Error in t1$p.value : $ operator is invalid for atomic vectors

I tried also str(t1) with no use.

> str(t1)
 num [1:3, 1:3] 0.935 0.95 0.988 6.6 6.571 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:3] "Lower Achieved CI" "Interpolated CI" "Upper Achieved CI"
  ..$ : chr [1:3] "Conf.Level" "L.E.pt" "U.E.pt"
Это было полезно?

Решение

I looked into the code for the function and it doesn't seem to include that in the output unless a particular criterion (k<1) is satisfied, where k is defined within the function. That's not what the documentation says it should do. Your options are probably either to put a modified version of the function in your own workspace; what you need to do is to replace the last two lines

print(rval)
return(Confidence.Intervals)

with just

 return(rval)

You won't get the confidence intervals you were getting, but you could probably add those to the output list if you wanted as well, with

rval$Confidence.Intervals <- Confidence.Intervals
return(rval)

It might also be worthwhile to contact the package maintainer, though it doesn't look like it's been updated since March 2012, for whatever that's worth.

Другие советы

I faced the same problem and one good R programmer modified the code for me to extract the p-value.

Just do this. Your problem will be solved.

1) Send a line just writing SIGN.test, it will show you the function, copy it, name it whatever you like, then copy the text in step 2 and substitute them to the functions final lines...

2)

print(rval)
list(rval,Confidence.Intervals)
}
}

3) Note that the last lines were

   print(rval)
         return(Confidence.Intervals)
    }
}
<environment: namespace:BSDA>

Replace them by the lines in step 2

4) If we name the function by my, and store the function result in res, then p value is extracted by writing this.

Input

res<-my(x,md=6.5)

Output

res[[1]]$p.value [1] 0.02148438; where x is your vector

Reference :- https://www.facebook.com/groups/rusers/10152075287578740/

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top