[R] t-test: many changing groups.
White Sky
bluebarbarossa at hotmail.com
Sat Mar 7 17:05:43 CET 2015
I'd like to perform a t-test between groups 'A' and 'B'. The difficulty is that although there is only one response variable, there are many observations, and the grouping (A or B) differs with each observation. My code for generating the input data is shown below.
I'd like to know how to approach doing the test, ideally so that the t-test results for each observation are presented in a table. I'm not sure where to start as other searches have been futile... something along the lines of t.test(ind_vars ~ resp_vars) , maybe using rapply, and separating groups by A and B each time...
# Matrix for response variableN_samples <- 20resp_vars <- matrix(runif(n=N_samples, min=0, max=1))sample_names <- paste0("sample_", 1:N_samples )rownames(x=resp_vars) <- sample_namescolnames(x=resp_vars) <- "resp"resp_vars [1:5,]
# Matrix for independent variablesN_observations <- 100ind_vars <- matrix(NA, N_observations, N_samples)ind_vars <- apply(ind_vars, c(1,2), function(x) sample(c("A", "B"),1))ind_var_names <- paste0("obs_", 1:N_observations)rownames(x=ind_vars) <- ind_var_namescolnames(x=ind_vars) <- sample_namesind_vars[1:3,1:5]
[[alternative HTML version deleted]]
More information about the R-help
mailing list