Guest User

Untitled

a guest
Aug 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. How to do the p-value to print only 4 digits instead of the scientific notation in R?
  2. >options(digits=3, scipen=12)
  3. >Oi <- c(A=321, B=712, C=44)
  4. >Ei <- c(A=203, B=28, C=6)
  5. >chisq.test(Oi, p=Ei,rescale.p=T)"
  6.  
  7. cc <- chisq.test(Oi,p=Ei,rescale.p=TRUE)
  8.  
  9. print(cc)
  10. Chi-squared test for given probabilities
  11.  
  12. data: Oi
  13. X-squared = 3090, df = 2, p-value < 0.00000000000000022
  14.  
  15. List of 9
  16. $ statistic: Named num 3090
  17. ..- attr(*, "names")= chr "X-squared"
  18. $ parameter: Named num 2
  19. ..- attr(*, "names")= chr "df"
  20. $ p.value : num 0
  21. $ method : chr "Chi-squared test for given probabilities"
  22. $ data.name: chr "Oi"
  23. $ observed : Named num [1:3] 321 712 44
  24. ..- attr(*, "names")= chr [1:3] "A" "B" "C"
  25. $ expected : Named num [1:3] 922.5 127.2 27.3
  26. ..- attr(*, "names")= chr [1:3] "A" "B" "C"
  27. $ residuals: Named num [1:3] -19.8 51.8 3.2
  28. ..- attr(*, "names")= chr [1:3] "A" "B" "C"
  29. $ stdres : Named num [1:3] -52.29 55.2 3.25
  30. ..- attr(*, "names")= chr [1:3] "A" "B" "C"
  31. - attr(*, "class")= chr "htest"
  32.  
  33. (pval <- pchisq(3090,2,lower.tail=FALSE,log.p=TRUE))
  34. [1] -1545
  35.  
  36. Oi <- c(A=321, B=712, C=44)
  37. Ei <- c(A=203, B=28, C=6)
  38. tt <- chisq.test(Oi, p=Ei,rescale.p=T)
  39.  
  40. format.pval(tt$p.value, eps=0.0001)
  41. # [1] "<0.0001"
  42.  
  43. ttp <- data.frame(Chisq=tt$statistic, p.value=tt$p.value)
  44. rownames(ttp) <- "Oi vs Ei"
  45. printCoefmat(ttp, has.Pvalue=TRUE, eps.Pvalue=0.0001)
  46. # Chisq p.value
  47. # Oi vs Ei 3090 <0.0001 ***
  48. # ---
  49. # Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Add Comment
Please, Sign In to add comment