3
$\begingroup$

New to the site. I am just getting started with R, and want to replicate a feature that is available in SPSS.

Simply, I build a "Custom Table" in SPSS with a single categorical variable in the column and many continuous/scale variables in the rows (no interactions, just stacked on top of each other).

The table reports the means and valid N's for each column (summary statistics are in the rows), and select the option to generate significance tests for column means (each column against the others) using alpha .05 and adjust for unequal variances.

Here is my question.

How can I replicate this in R? What is my best option to build this table and what tests are available that will get me to the same spot? Since I am getting used to R, I am still trying to navigate around what is available.

$\endgroup$

2 Answers 2

3
$\begingroup$

As I read in help for the t.test, it is only applicable for the 2-sample tests. If you want to perform it to every combination of the columns of a matrix A, taken 2 at a time, you could do something like this (for the moment, I can't recall a better way)

apply(combn(1:dim(A)[2],2),2,function(x) t.test(A[,x[1]],A[,x[2]])) 

or, if you just want the p.values

t(apply(combn(1:dim(A)[2],2),2,function(x) c(x[1],x[2],(t.test(A[,x[1]],A[,x[2]]))$p.value)))
$\endgroup$
2
  • 4
    $\begingroup$ You should be very careful in interpreting p-values from these t-tests with this looping approach. If you have 20 columns, and there is no real difference between any of them, at least one comparison is likely to appear significantly different at p < 0.05. You should at least multiply the p-values by the number of tests, to produce the Bonferronoi correction. Or, you could multiply them by their inverse rank for the Holm correction. $\endgroup$
    – JoFrhwld
    Jul 29, 2010 at 15:36
  • $\begingroup$ You are right. I was feeling that something was wrong. They constitute a family of confidence intervals. Perhaps its even better to adjust using Tukey Honest Significant Differences (TukeyHSD in R) $\endgroup$
    – Yorgos
    Jul 31, 2010 at 15:45
1
$\begingroup$
summary(df)

Will give you 5 number summaries and counts of NA for continuous variables, and counts for categorical variables.

As for the significance tests, you'll have to do that by hand with t.test() or wilcox.test().

$\endgroup$
2
  • $\begingroup$ Will t.test() compare the means across all levels of a factor? $\endgroup$
    – Btibert3
    Jul 28, 2010 at 22:59
  • $\begingroup$ I'm not sure what you mean. If you have some continuous variable column A (say people's heights) and some grouping factor column B (say Country of origin), you really want to do a pairwise.t.test(). You would do this like pairwise.t.test(df$A , df$B). This function will automatically correct for multiple comparisons. $\endgroup$
    – JoFrhwld
    Jul 29, 2010 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.