[R] Q: extracting data from lm

2007-07-27 Thread D. R. Evans
Warning: I am a complete newbie to R. I have read ISwR, but I am still
finding myself completely stuck on some simple concepts.

I have tried everything I can think of to solve this one, and finally
decided that enough was enough and I need a pointer to a solution.

I have the following summary from lm():



 summary(lm(nu1~nu4))

Call:
lm(formula = nu1 ~ nu4)

Residuals:
 Min   1Q   Median   3Q  Max
-1572.62  -150.38   -21.70   168.57  2187.84

Coefficients:
Estimate Std. Error t value Pr(|t|)
(Intercept) 29.88739   43.68881   0.6840.494
nu4  1.000360.01025  97.599   2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 470.9 on 298 degrees of freedom
Multiple R-Squared: 0.9697, Adjusted R-squared: 0.9696
F-statistic:  9526 on 1 and 298 DF,  p-value:  2.2e-16



But I want to access some of these numbers programmatically. I finally
figured out that to get the estimate of the nu4 coefficient I need to do:



 lm(nu1~nu4)$coefficients[2]
 nu4
1.000363



which to me as a long-time C++ programmer is close to black magic (I've
been programming since 1972; I have to say that R is unlike anything I've
ever seen, and it's far from trivial to get my head around some of it --
for example, how I could have known a priori that the above is the way to
get the nu4 coefficient is beyond me). Anyway, having figured out how to
get the estimate of the coefficient, I not-unnaturally wanted also to find
a way to access the std. error of the estimate (the value 0.01025 in the
summary). But I am completely mystified as to how to do it :-(

Any help gratefully (VERY gratefully) received, and I apologise if this is
a really, really stupid question and that the answer lies somewhere in some
documentation that I've obviously not properly taken on board.



__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Q: extracting data from lm

2007-07-30 Thread D. R. Evans
On 27/07/07, Chuck Cleland [EMAIL PROTECTED] wrote:


 coef(summary(lm(nu1 ~ nu2)))[,2]

   Also, try the following which is often useful:

 str(summary(lm(nu1 ~ nu2)))


Oh, wow! Thank you.

Incidentally, just in case anyone got the wrong end of the stick, I'm
not at all complaining about R. It's good at my age to be faced with
something so different. And from an architectural standpoint I
appreciate its elegance and innate power. It's just the logistics of
knowing exactly what to type that causes me to feel overwhelmed, and
although I've become very used in the past couple of days to typing
?something I'm not much good yet at finding out how to help myself
if that doesn't tell me what I want to know.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Q: obtaining non-transparent background in png

2007-07-31 Thread D. R. Evans
I am not understanding something about generating PNG plots.

I have tried several ways to obtain something other than a transparent
background, but nothing I've done seems to change the background.

For example:

dev.print(png, width=800, height=600, bg='red', filename='example.png')

which I thought would give a red background, simply gives the same
transparent background I always get.

And I also don't understand why the default background is transparent,
when the documentation seems to say that it's white:
  png(filename = Rplot%03d.png, width = 480, height = 480,
 pointsize = 12, bg = white,  res = NA,...)

(This is on a Kubuntu dapper 64-bit system.)

[I looked through the mail archives, and there seem to be a few very
old postings talking about the opposite problem, but nothing recent;
so I conclude that I'm doing something wrong.]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Q: obtaining non-transparent background in png

2007-07-31 Thread D. R. Evans
On 31/07/07, Gavin Simpson [EMAIL PROTECTED] wrote:
 On Tue, 2007-07-31 at 10:22 -0600, D. R. Evans wrote:
  I am not understanding something about generating PNG plots.
 
  I have tried several ways to obtain something other than a transparent
  background, but nothing I've done seems to change the background.
 
  For example:
 
  dev.print(png, width=800, height=600, bg='red', filename='example.png')
 
  which I thought would give a red background, simply gives the same
  transparent background I always get.

 ?dev.print says:

  'dev.print' copies the graphics contents of the current device to
  a new device which has been created by the function specified by
  'device' and then shuts the new device.

 Note copies - given that you've already drawn a figure with a white
 background, should this then produce one that is red?

Well, I wondered about that, so the first thing I did was to test it
by changing a different parameter. I created an X11 plot with the
default size (480, I think?) and then printed it to a png with a width
of 800. That indeed created a PNG file of width 800, so I deduced from
that that it was OK to change the parameters of the plot in the
destination device.

 Not sure whether this is as intentional or not, but it does not appear
 to be passing the bg argument on to the 'device', or if it does, it is
 not being used/respected - perhaps all that is need is clarification as
 to what can be specified in '...' in ?dev.print

I think so. Either that or it seems to be a bug (I obviously don't
know enough about how things are supposed to work to make that
determination; but it does seem rather bug-like behaviour, especially
since one can certainly change some of the parameters associated with
the plot).

Anyway, it seems like I need an explicit par(bg='red') before
performing any graphical operations. That seems to do the trick.
Although it's still not clear how one would solve the general problem
in which one has an X11 plot with background colour A, but wants to
copy it to a  PNG with background colour B...

Weirdly (at least it seems weird to me) I just tried the following
with an unexpected result:

I created the following function:
to.png -
function(FILENAME = 'Rplot%03d.png')
{ par(bg='blue')
  dev.print(png, width=800, height=600, filename=FILENAME)
}

par(bg='red')
plot(1:10)# ok, I get a red plot

to.png('should-be-blue.png') # png is red, not blue

plot(1:10)   # now it's blue (as I sort-of expected)

So it isn't obvious that there's anything one can put in the to.png()
function that will control the colour of the background for the PNG
output.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Q: obtaining non-transparent background in png

2007-08-02 Thread D. R. Evans
Prof Brian Ripley said the following at 07/31/2007 12:20 PM :
 You are *copying* the plot, and that means copying the background too (it
 *is* part of the plot).  Almost certainly the plot you are copying had a
 transparent background: that is the default for X11.
 
 All the confusion seems to be over misreadings of this.
 

But following that logic, changing the size of the plot shouldn't work either.

I don't think you can have it both ways. I.e., either it's OK to change the
size and the background, or it's not OK to change either of them. There's
no way to deduce from the word copy that you're allowed to change some
things but not others; I think that's where the confusion enters.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Q: calling par() in .First()

2007-08-02 Thread D. R. Evans
As a result of another thread here, I need to be sure that the
function par(bg='white') has executed before I create a plot. The
simplest thing seemed to put it in .Rprofile:

.First - function() {
  options(width=150)
  par(bg='white')
}

But now R complains at startup:
  Error in .First() : couldn't find function par

I have confirmed that once R has started, I can type par(bg='white')
and R no longer complains.

ISwR has a nice little section on Using par, but there's no hint
that something like this can go wrong :-(

So what am I not understanding this time?

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Q: calling par() in .First()

2007-08-06 Thread D. R. Evans
Thomas Lumley said the following at 08/02/2007 05:25 PM :

 
 par() is in the 'graphics' package, which is not loaded by the time
 .Rprofile runs.  You want graphics::par(bg='white')
 

Thank you, but when I tried that, I got:

  Error in graphics::par(bg = white) : couldn't find function X11

However, executing an explicit library(graphics) seems to do the trick.
Your hint about the graphics package was what gave me the clue to try this;
thank you.

 Information from which this can be deduced and examples are in ?Startup,
 though it isn't explicitly stated there.
 

You are obviously much better at deducing information than I am. I had read
that quite carefully before posting my question -- and I just went back and
re-read it to see what I had missed, and I can't see anything that even
hints at any of this :-(

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Q: how to interrupt long calculation?

2007-08-29 Thread D. R. Evans
The subject says it all really: I've tried hitting control-C (multiple
times), but that doesn't seem to be a reliable way to interrupt a long
calculation. What is the right way to interrupt a calculation that has
been proceeding for several minutes and shows no sign of finishing
soon?

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Q: how to interrupt long calculation?

2007-08-29 Thread D. R. Evans
On 29/08/2007, D. R. Evans [EMAIL PROTECTED] wrote:
 The subject says it all really: I've tried hitting control-C (multiple
 times), but that doesn't seem to be a reliable way to interrupt a long
 calculation. What is the right way to interrupt a calculation that has
 been proceeding for several minutes and shows no sign of finishing
 soon?


I forgot to mention that this is on an amd64 system running dapper (in
case that makes any difference).

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Q: how to interrupt long calculation?

2007-08-30 Thread D. R. Evans
Paul Smith said the following at 08/29/2007 04:32 PM :

 The instance of R running will be immediately killed and then you can
 start R again.

But then I would lose all the work. There must be some way to merely
interrupt the current calculation. Mustn't there?

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Q: how to interrupt long calculation?

2007-08-30 Thread D. R. Evans
Prof Brian Ripley said the following at 08/30/2007 11:00 AM :
 On Thu, 30 Aug 2007, D. R. Evans wrote:
 
 Paul Smith said the following at 08/29/2007 04:32 PM :

 The instance of R running will be immediately killed and then you can
 start R again.
 But then I would lose all the work. There must be some way to merely
 interrupt the current calculation. Mustn't there?
 
 Only if it is long-running in R code, when ctrl-C or equivalent (Esc in 
 Rgui) works. If it is long-running in C or Fortran code, there is not.
 

It's inside loess()... so isn't that R code?

I can sit hitting ctrl-C all day (well, it seems like it), but the code
does not get interrupted :-(

 Assuming a Unix-alike, sending SIGUSR1 will save the current workspace and 
 quit.  Even that is a little dangerous as the workspace need not be in a 
 consistent state.
 

That's helpful, thank you; at least it means I stand a chance of being able
to interrupt the code and recover.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Q: selecting a name when it is known as a string

2007-09-04 Thread D. R. Evans
I am 100% certain that there is an easy way to do this, but after
experimenting off and on for a couple of days, and searching everywhere I
could think of, I haven't been able to find the trick.

I have this piece of code:

...
  attach(d)

  if (ORDINATE == 'ds')
  { lo - loess(percent ~ ncms * ds, d, control=loess.control(trace.hat =
'approximate'))
grid - data.frame(expand.grid(ds=MINVAL:MAXVAL, ncms=MINCMS:MAXCMS))
...

then there several almost-identical if statements for different values of
ORDINATE. For example, the next if statement starts with:

...
  if (ORDINATE == 'dsl')
  { lo - loess(percent ~ ncms * dsl, d, control=loess.control(trace.hat =
'approximate'))
grid - data.frame(expand.grid(dsl=MINVAL:MAXVAL, ncms=MINCMS:MAXCMS))
...

This is obviously pretty silly code (although of course it does work).

I imagine that my question is obvious: given that I have a variable,
ORDINATE, whose value is a string, how do I re-write statements such as the
lo - and grid - statements above so that they use ORDINATE instead of
the hard-coded names ds and dsl.

I am almost sure (almost) that it has something to do with deparse(), but
I couldn't find the right incantation, and the ?deparse() help left my head
swimming.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Q: selecting a name when it is known as a string

2007-09-05 Thread D. R. Evans
D. R. Evans said the following at 09/04/2007 04:14 PM :
 I am 100% certain that there is an easy way to do this, but after

I have reconsidered this and now believe it to be essentially impossible
(or at the very least remarkably difficult) although I don't understand why
it is so :-(

At least, I spent another two hours trying variations on the suggestions I
received, but still nothing worked properly.

It sure seems like it _ought_ to be easy, because of the following argument:

If I type an expression such as A - something then R is perfectly
capable of parsing the something and executing it and assigning the
result to A. So it seems to follow that it ought to be able to parse a
string that contains exactly the same sequence of characters (after all,
why should the R parsing engine care whether the input string comes from
the terminal or from a variable?) and therefore it should be possible to
assign something to a variable and then have R parse that variable
precisely as if it had been typed.

That was my logic as to why this ought to be easy, anyway. (And there was
the subsidiary argument that this is easy in the other languages I use, but
R is sufficiently different that I'm not certain that that argument carries
much force.)

It does seem that there are several ways to make the

  lo - loess(percent ~ ncms * ds, d, control=loess.control(trace.hat =
 'approximate'))

command work OK if the right hand side is in a character variable, but I
haven't been able to find a way to make

  grid - data.frame(expand.grid(ds=MINVAL:MAXVAL, ncms=MINCMS:MAXCMS))

work.

I always end up with a parse error or a complaint that 'newdata' does not
contain the variables needed when I perform the next task:

  plo - predict(lo, grid).

So I guess I have to stick with half a dozen compound if statements, all
of which do essentially the same thing :-(

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Q: loess-like function that allows more predictors?

2007-09-07 Thread D. R. Evans
I have a feeling that this may be a stupid question, but here goes anyway:
is there a function that I can use to replace loess but which allows a
larger number of predictors?

(I have a situation in which it would be very convenient to use 5
predictors, which violates the constraint in loess that the number of
predictors be in the range from 1 to 4.)

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.