Domanda

After using the G.test on all rows of my data subset

apply(datamixG +1 , 1, G.test)

I get an output for each row that looks like this

[[1]]

        G-test for given probabilities

data:  [(newX,,i)
G = 3.9624, df = 1, p-value = 0.04653

I have 46 rows. I need to sum the df and G-values. Is there a way to have R report the G-values differently and/or sum all of the G-values and df?

È stato utile?

Soluzione

I'll assume you're using the G.test function from the RVAideMemoire package:

# Sample data (always a good idea to post!)
dat <- matrix(1:4, nrow=2)
library(RVAideMemoire)
tests <- apply(dat, 1, G.test)

You can use unlist and lapply to extract a single value from each element in a list and to return a vector of the results:

dfs <- unlist(lapply(tests, "[[", "parameter"))
dfs
# df df 
#  1  1 
sum(dfs)
# [1] 2

Gs <- unlist(lapply(tests, "[[", "statistic"))
Gs
#         G         G 
# 1.0464963 0.6795961
sum(Gs)
# [1] 1.726092
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top