Home>

I got the following error message when doing a fisher test on time series data using a function called "get.decluttered" in a package called "tempR" in R.

Error in stats::fisher.test(matrix(x, nrow = 2)):
  all entries of'x' must be nonnegative and finite
Applicable source code
x<- aggregate(name[, -c(1:4)],

 list(samp = name $samp, attribute = name $attribute), sum)
>x
   time_0s1 time_0s2 time_0s3 time_0s4 time_0s5 time_0s6 time_0s7
          0 0 0 0 0 0 0
   time_0s8 time_0s9 time_0s10 time_1s1 time_1s2 time_1s3 time_1s4
          0 0 0 0 0 0 0
   time_1s5 time_1s6 time_1s7 time_1s8 time_1s9 time_1s10 time_2s1
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 1 0 0 0 0 2
0 1 0 1 1 0 5
1 2 2 0 2 0 1
2 0 7 1 2 2 3
7 0 1 4 0 7 5
2 3 10 8 0 1 9
1 8 7 3 6 16 9
0 1 8 2 12 7 3
8 21 13 0 1 9 2
15 8 5 8 22 16 0
1 12 2 17 10 6 9
26 19 0 2 14 2 2 18
11 8 8 26 20 0 3
16 4 19 11 8 8 28
21 0 2 16 4 19 13
8 8 28 22 0 2 17
5 20 13 8 8 27 23
0 2 18 6 22 15 10
8 28 23 0 3 18 6
22 15 12 8 30 24 0
4 18 6 2 2 5 15 14 8
31 24 0 4 20 7 22
16 14 9 30 24 0 4
20 7 22 17 16 8 30
24 0 4 20 7 22 18
17 9 31 25 0 4 21
7 22 18 17 9 31 25
0 4 22 8 22 20 18
9 30 25 0 0 4 23 7
23 21 18 9 30 25 0
4 23 7 23 20 18 9
29 27 0 4 22 7 23
20 19 9 31 27 1 4
22 7 23 20 19 10 3326 2 5 23 7 7 22
19 12 33 26 1 5 23
5 24 22 19 11 34 25
2 5 22 5 5 25 22 19
11 33 25 1 5 22 5
26 22 20 11 33 26 2
5 23 5 25 22 20 11
34 26 2 6 23 5 5
21 20 11 34 34 1 5
23 5 25 21 20 11 35
23 2 4 23 5 5 24 21
19 10 36 23 2 4 22
5 24 21 20 10 38 23
1 4 21 5 5 20 20 19
11 38 24 2 4 22 5
24 20 19 11 38 24 1
4 21 4 25 20 17 12
39 23 2 4 20 4 4 6
20 17 12 38 38 23 2 4
20 3 26 21 17 12 38
23 1 4 20 3 26 21
18 12 38 22 2 4 20
3 25 21 18 11 38 20
2 4 19 3 25 25 18
10 38 20 1 4 17 1
26 21 18 12 37 20 1
4 18 1 25 21 17 12
37 20 0 5 19 1 25
20 17 13 34 34 2 5
20 1 25 20 17 13 33
18 2 5 20 1 23 20
17 12 34 18 1 5 19
1 23 21 16 12 32 18
2 5 18 1 23 20 15
12 34 34 17 5 20
23 21 15 13 13 34 17 1
5 20 1 23 23 15 15
34 16 2 5 19 1 23
21 16 10 33 16 2 4
19 1 24 22 14 11 33
15 1 4 18 1 24 22
14 11 33 16 2 4 4 17
1 21 23 14 8 33 16
1 4 17 1 21 23 14
9 33 16 2 4 18 1
22 23 13 10 33 14 2
4 17 1 23 23 23 13 10
33 14 1 2 17 17 1 23
23 12 10 34 34 14 2 2
18 1 23 23 23 10 34
13 2 2 17 17 1 22 2312 9 33 14 14 1 2 17
1 21 22 12 8 32 14
2 2 17 17 21 22 12
7 33 14 1 2 16 1
21 22 12 7 32 14 2
1 16 1 23 20 9 7
32 13 2 1 16 0 23
20 9 7 31 1 3 1 1
16 0 23 18 9 8 31
13 2 1 15 0 0 24 17
9 7 31 12 2 1 16
0 23 17 9 6 31 12
1 1 16 0 23 23 17 8
6 31 12 2 1 15 0
24 17 8 7 30 11 1
1 15 0 23 17 8 7
28 11 2 1 15 0 20
19 8 5 28 10 2 1
15 0 21 19 7 6 6 27
10 1 1 15 0 0 21 19
7 7 27 10 2 1 15
0 21 18 8 7 27 9
2 1 15 0 20 17 8
6 25 8 1 1 15 0
20 17 7 6 24 8 2
1 15 0 22 15 7 7
24 7 2 1 14 0 22
14 7 5 24 6 6 1 2
13 0 23 14 7 5 24
5 1 2 13 0 22 14
7 5 25 5 0 2 13
0 21 14 6 4 24 5
1 2 14 0 20 13 6
4 24 5 1 2 14 0
22 13 5 5 22 22 5 0
2 14 0 20 13 5 5
21 5 0 2 14 0 21
13 5 5 20 6 0 2
14 0 20 13 5 5 20
6 0 2 14 0 20 12
5 4 19 6 0 2 14
0 19 12 4 4 19 6
0 1 14 0 17 11 4
3 19 6 0 1 14 0
16 11 4 3 19 5 5 0
1 14 0 16 11 4 4
19 3 0 1 13 0 15
12 4 4 18 3 0 1
13 0 13 12 4 4 3 18
3 0 1 13 0 0 13 12
4 3 18 3 0 1 1 130 10 10 2 1 17 3
0 1 12 0 10 8 2
0 16 3 0 1 12 0
 time_100s2 time_100s3 time_100s4 time_100s5 time_100s6 time_100s7 time_100s8
         12 9 1 3 16 3 0
 time_100s9 time_100s10
          1 11
For reference, the following is the result (up to the 3rd line) of outputting x with "ojtcata".
>head(x, 3)
  samp attribute time_0s time_1s time_2s time_3s time_4s time_5s time_6s time_7s time_8s
1 1 Astringent 0 0 0 0 0 0 2 2 3
2 2 Astringent 0 0 0 0 1 1 2 3 4
3 3 Astringent 0 0 0 0 1 1 1 2 2
  time_9s time_10s time_11s time_12s time_13s time_14s time_15s time_16s time_17s time_18s
1 3 5 4 6 6 6 6 7 7 7
2 3 3 2 2 2 3 3 3 3 3
3 4 3 4 5 6 5 5 7 7 7
  time_19s time_20s
1 9 9
2 5 5
3 7 8

p.1.checked<- x[x$samp == 1, -c(1:2)]
p.1.eval<- length(unique (name $cons))
p.not1.checked<- aggregate(x[x$samp != 1, -c(1:2)],


                            list(attribute = x$attribute[x$samp != 1]), sum)[, -1]
p.not1.eval<- length(unique(name $cons)) * (length(unique(name $samp))-1)
# reference lines for contrast products
p.1.refline<- p.not1.checked/p.not1.eval
p.1.refline
# decluttering matrix corresponds to the dimensions of p.1.refline
x<- unlist(p.1.checked)
vector.checked
vector.notchecked<- unlist(p.not1.checked)
vector.notchecked
p.1.declutter<- matrix(get.decluttered(x = unlist(p.1.checked), n.x = p.1.eval,
                                        y = unlist(p.not1.checked), n.y = p.not1.eval),
                        nrow = nrow(p.1.checked))
What I tried

I didn't know what to try for a beginner, I tried looking at the example given in the package description, but I didn't know what was different from the example.

Thanks for your guidance.

Supplementary information (FW/tool ​​version, etc.)

R 3.6.3
RStudio
using. I installed them the other day, so I think they are the latest versions.
I'm reading and using a file in Excel text (tab-delimited) format and set the dataset as the example data ("ojtcata") used to describe the package.

r
  • Answer # 1

    This problem seems to be because the data passed to stats::fisher.test called inside get.declutterd is wrong.

    >get.decluttered
    function (x = x, n.x = n.x, y = y, n.y = n.y, alpha = 0.05)
    {
        if (any(is.na(x), is.na(y), is.na(n.x), is.na(n.y)))
            return(print("All parameters required"))
        if (length(x) != length(y))
            return(print("Length of x and y must be equal"))
        if (length(n.x)>1&length(x) != length(n.x))
            return(print("Length of x and n.x are mismatched"))
        if (length(n.y)>1&length(y) != length(n.y))
            return(print("Length of y and n.y are mismatched"))
        tmp<- data.frame(x1 = x, x0 = n.x-x, y1 = y, y0 = n.y-
            y)
        fisher.test2<- function(x) {
            requireNamespace("stats", quietly = TRUE)
            return(stats::fisher.test(matrix(x, nrow = 2))$p)
        }
        declutter = 1 * (apply(tmp, 1, fisher.test2)

    In this way, check the source code of get.decluttered,
    Separately

    myGetDecluttered<- function (x = x, n.x = n.x, y = y, n.y = n.y, alpha = 0.05)
    {
        if (any(is.na(x), is.na(y), is.na(n.x), is.na(n.y)))
            return(print("All parameters required"))
        if (length(x) != length(y))
            return(print("Length of x and y must be equal"))
        if (length(n.x)>1&length(x) != length(n.x))
            return(print("Length of x and n.x are mismatched"))
        if (length(n.y)>1&length(y) != length(n.y))
            return(print("Length of y and n.y are mismatched"))
        tmp<- data.frame(x1 = x, x0 = n.x-x, y1 = y, y0 = n.y-
            y)
        fisher.test2<- function(x) {
            requireNamespace("stats", quietly = TRUE)
            print(x)
            return(stats::fisher.test(matrix(x, nrow = 2))$p)
        }
        declutter = 1 * (apply(tmp, 1, fisher.test2)

    You can find out what is wrong with the content passed to fisher.test by calling as.
    It seems that it seems to be a negative value, so n.x-x is negative, that is, n.x, say by the callerp.1.evalI think there is a problem in the calculation of.

Trends