Dear r-help users,
I am using Sweave and Latex to create tables with output from several
statistical test. As an example: I have a grouping variable "group"
with two levels ("x" and "y") which I compare on variables ("a" and
"b").
I have created a table in which means, standard deviations, and the
statistic and p.value resulting from a t.test is printed. The table
looks something like:
?group(x) ? ? ? ? ? ? ? ? ?group(y)
mean ? ? ? ?sd ? ? ? ?mean ? ? ?sd ? ? t-value p-value ?sig.
mean(x,a) ?sd(x,a) mean(y,a) sd(y,a) ? ?t.a ? ? ?p.a
mean(x,b) ?sd(x,b) mean(y,b) sd(y,b) ? ?t.b ? ? ?p.b
What I would like to be able to add to this table is an indication by
means of asterisks ("*") the level of significance of the p.value(s).
I am after an expression to put in column "sig." which evaluates the
p.value and prints *, ** or *** depending on it's value (e.g. if it is
less than .05 print "*", but if it is less than .01 print "**", but if
it is less than .001 print "***", else print " ").
I am able to use a simple function like if (p.value<0.5) print("*")
else print(" "),
but I have not been able to work out how to nest the "if" expressions correctly.
Any help would be greatly appreciated.
Best regards,
Tormod B?e
Automatically assign symbol for statistical significance to x given value of x
3 messages · Marc Schwartz, Tormod Bøe
On Jul 20, 2009, at 10:36 AM, Tormod B?e wrote:
Dear r-help users,
I am using Sweave and Latex to create tables with output from several
statistical test. As an example: I have a grouping variable "group"
with two levels ("x" and "y") which I compare on variables ("a" and
"b").
I have created a table in which means, standard deviations, and the
statistic and p.value resulting from a t.test is printed. The table
looks something like:
group(x) group(y)
mean sd mean sd t-value p-value sig.
mean(x,a) sd(x,a) mean(y,a) sd(y,a) t.a p.a
mean(x,b) sd(x,b) mean(y,b) sd(y,b) t.b p.b
What I would like to be able to add to this table is an indication by
means of asterisks ("*") the level of significance of the p.value(s).
I am after an expression to put in column "sig." which evaluates the
p.value and prints *, ** or *** depending on it's value (e.g. if it is
less than .05 print "*", but if it is less than .01 print "**", but if
it is less than .001 print "***", else print " ").
I am able to use a simple function like if (p.value<0.5) print("*")
else print(" "),
but I have not been able to work out how to nest the "if"
expressions correctly.
Any help would be greatly appreciated.
Best regards,
Tormod B?e
The simple answer is to use symnum(), which is the function the generates the symbology for those tables in R where the 'significance stars' are included. For example, when printing a linear model summary where printCoefmat() is used. See the last example in ?symnum for more information. The philosophical challenge that you will face is that a lot of people are not favorably disposed to the use of this symbology. So the use or non-use of them may be dependent upon your own feelings and those of the consumers of your output. See ?options and note 'show.signif.stars', which a lot of folks, myself included, set to FALSE in .Rprofile. HTH, Marc Schwartz
On Mon, Jul 20, 2009 at 5:47 PM, Marc Schwartz<marc_schwartz at me.com> wrote:
The simple answer is to use symnum(), which is the function the generates the symbology for those tables in R where the 'significance stars' are included. For example, when printing a linear model summary where printCoefmat() is used. See the last example in ?symnum for more information. The philosophical challenge that you will face is that a lot of people are not favorably disposed to the use of this symbology. So the use or non-use of them may be dependent upon your own feelings and those of the consumers of your output. See ?options and note 'show.signif.stars', which a lot of folks, myself included, set to FALSE in .Rprofile. HTH, Marc Schwartz
Thank you very much Marc, the symnum function worked perfectly and I hadn't heard of it until now. With regards to the philosophical challenge; I don't really have an option since (most) journals (in social science) require such symbols. Thanks again! Best regrads, Tormod B?e