[R] Errors using large numbers ((i) all entries of 'x' must be nonnegative and finite and (ii) NAs introduced by coercion)
jgibbons1
jgibbons at hsph.harvard.edu
Tue Jul 16 16:43:35 CEST 2013
Hello,
I am fairly new to R, so please forgive me if this is a fairly easy
solution.
I am trying to perform multiple Fisher's Exact tests or Pearson's
Chi-squared contingency tests from a datamatrix in which data from each row
is data for an independent test.
My data is formatted as such:
AAA 75533 4756922556 88210 6715122129
BBB 14869 4756983220 16384 6715193955
CCC 7230 4756990859 8559 6715201780
DDD 18332 4756979757 23336 6715187003
EEE 14733 4756983356 16826 6715193513
FFF 2918 4756995171 3433 6715206906
GGG 3726 4756994363 4038 6715206301
HHH 6196 4756991893 7011 6715203328
III 7925 4756990164 9130 6715201209
JJJ 1434 4756996655 1602 6715208737
Where the 1st column is the identifier, the 2nd column = observations 1, the
3rd column = background counts 1, the 4th column = observations 2 and the
5th column = background counts 2.
I am loading my data as such:
> data=read.table("My.File", header=FALSE)
And I am looping through each row to perform a test like this:
> pvalues=c("pvalue")
> for(i in 1:10){
+ datamatrix=matrix(c(as.integer(data[i,2:5])),nrow=2)
+ fisherresult=fisher.test(datamatrix)
+ pvalues=cbind(pvalues,fisherresult[1])
+ }
Here is the Error I am Getting:
Error in fisher.test(datamatrix) :
all entries of 'x' must be nonnegative and finite
In addition: Warning messages:
1: In matrix(c(as.integer(data[i, 2:5])), nrow = 2) :
NAs introduced by coercion
2: In matrix(c(as.integer(data[i, 2:5])), nrow = 2) :
NAs introduced by coercion
When I replace the large number in the 3rd and 5th column with smaller
numbers, the statistical calculation works fine.
Any ideas? Any help would be GREATLY appreciated!
--
View this message in context: http://r.789695.n4.nabble.com/Errors-using-large-numbers-i-all-entries-of-x-must-be-nonnegative-and-finite-and-ii-NAs-introduced-b-tp4671685.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list