Uwe Ligges <ligges <at> statistik.uni-dortmund.de> writes: : : (Ted Harding) wrote: : : > On 20-Nov-04 Uwe Ligges wrote: : > : >>Shigeru Mase wrote: : >> : >>>Dear R experts, : >>> : >>>I am posting this question on behalf of a Japanese R user : >>>who wants to know how to change the siginificant codes default. : >>>As you know, R's default significant codes are: : >>> : >>> Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 : >>> : >>>But he says that it is usual in economics to give codes such as : >>> : >>> `***' for 0.01, `**' for 0.05 and `*' for 0.10 : >>> : >>>I don't know if this is true (common) or not, but what I as well : >>>as he are puzzled is that, apparently, there is no part in the code, : >>>say that of summary.lm, which produces these significant codes : >>>as well as the annotation above. A quick search of "rking" using : >>>keywords "significant codes star" gave me no information. : >>> : >>>Thanks in advance. : >> : >>For example, calling summary(lmObject) dispatches on method : >>summary.lm() : >>hwich creates an object of class "summary.lm". : >>The latter is printed by method print.summary.lm() which calls : >>printCoefmat(). : >> : >>The stars are hard-coded there, and I don't think anybody is going to : >>change that. I suggest to turn of the printing of siginificant codes by : >>specifying : >> print(summary(.....), signif.stars = FALSE) : >>or by setting the corresponding option(). : >> : >>Uwe Ligges : > : > : > It would be possible to re-define 'printCoefmat' privately : > so as to change the lines : > : > cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1), : > symbols = c("***", "**", "*", ".", " ")) : > : > towards the end of its code into whatever you prefer, e.g. : > : > cutpoints = c(0, 0.01, 0.05, 0.1, 1), : > symbols = c("***", "**", "*", " ")) : > : > or : > : > cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1), : > symbols = c("****", "***", "**", "*", " ")) : > : > (both of which are compatible with your description of what : > is needed). : > : > The most straightforward way of redefining it is to copy : > the code for 'printCoefmat' into a file, e.g. : > : > sink("printCoefmat.R") : > printCoefmat : > sink() : > : > and then edit that file. : > NOTE that the code written to the file does not include : > the name of the function, i.e. it starts : > : > function (x, digits = max(3, getOption("digits") - 2),.... : > : > so the first modification has to be : > : > printCoefmat<-function(x, digits = .... ) : > : > Then, when you want your private version, simply do : > : > source("printCoefmat.R") : > : > and it will overlay the original version. (Experts will have : > to advise whether this clashes with any "namespace" issues. : > On my reading of the code, it doesn't seem to; but I'm no : > expert!) : : Ted, it "clashes"! Functions in the namespace are looked up at first. :
True, but one can still get the effect by using assignInNamespace. For example, run these two lines (the body(...) <- line is just for illustration here. You want to ultimately replace that line with your redefined printCoefmat: printCoefmat <- function... as discussed by Ted.) body(printCoefmat) <- parse(text = "cat('Greetings from printCoefmat!!!')") assignInNamespace("printCoefmat", printCoefmat, "stats") Now running summary.lm as shown below displays the desired Greetings line: R> example(lm) ...snip... R> summary(lm.D90) Call: lm(formula = weight ~ group - 1) Residuals: Min 1Q Median 3Q Max -1.0710 -0.4938 0.0685 0.2462 1.3690 Coefficients: Greetings from printCoefmat!!! Residual standard error: 0.6964 on 18 degrees of freedom Multiple R-Squared: 0.9818, Adjusted R-squared: 0.9798 F-statistic: 485.1 on 2 and 18 DF, p-value: < 2.2e-16 ______________________________________________ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html