Re: [R] lm and anova

2011-05-12 Thread Paul Chatfield
anova uses sequential sums of squares (type 1), summary adjusted sums of
squares (type 3)

Take for example the first line of each output.  In summary this tests
whether vole1 is needed ASSUMING volelag and year are already in the model
(conclusion would then be: it isn't needed p=.89).  Whereas in anova, it's
testing do we need vole1 assuming nothing else is in the model (conclusion:
vole1 is better than nothing. p=.0009).

anova assumes all terms above it are in the model but terms below it are not
so volelag assumes vole1 is in the model but not year.  You can see how
anova changes but summary doesn't by varying the order you put them in.

so the final model I would fit here would probably end up being either
year+volelag or just year,

HTH,

Paul

--
View this message in context: 
http://r.789695.n4.nabble.com/lm-and-anova-tp3516748p3517356.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] All other variables in upper scope arg for stepAIC

2010-10-21 Thread Paul Chatfield

Hi - I am trying to substitute for the_other_y in the code below.  I want
y2 and y3 to be there when i is 1, y1 and y3 to be there when i is 2 and y1
and y2 to be there when i is 3.  I'm sure it's to do with what format the
data should be in and I've tried alldata[,-i], but it fits all the columns
of alldata except i rather than each column one at a time.  I've tried
changing the data i.e. as.matrix or as.list but that's still not the right
format.  I'm sure it's a simple trick, but don't know how to search it out. 
Any help on how to search this as well as the solution would be greatly
appreciated.

y1-rnorm(20);y2-rnorm(20);y3-rnorm(20);alldata-cbind(y1,y2,y3)

library(MASS)
for (i in 1:3)
{mod-lm(get(paste(y, i, sep=))~1)
stepAIC(mod, scope=list(lower=~1, upper=~the_other_y))}

Thanks

Paul

-- 
View this message in context: 
http://r.789695.n4.nabble.com/All-other-variables-in-upper-scope-arg-for-stepAIC-tp3005183p3005183.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] Referencing factor name

2010-09-22 Thread Paul Chatfield

Simple problem - I want the ylab to automatically pick up x1 rather than
having to define x1 in the plot statement.  

x1-c(1.2,2,3);x2-c(1,2.1,2.6)
y-x1
plot(1:3,y, ylab=x1)

There must be a way of accessing the name x1 somehow, but unfortunately I
don't know how to search for it.  Any help would be great,


-- 
View this message in context: 
http://r.789695.n4.nabble.com/Referencing-factor-name-tp2550131p2550131.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] A question about conducting crossed random effects in R

2010-07-07 Thread Paul Chatfield

There is a mixed effects e-mail list you might want to join for more in depth
discussion of these topics - you can subscribe here
https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models.

In general the format for crossed effects would be
lmer(y~f1+f2+(1|r1)+(1|r2))   where f1, f2 are fixed effects and r1, r2 are
random.

I believe that the random lines correspond to those in SAS as below
random int/subject=r1; (1|r1) for random varying intercept with each
r1
random f1/subject=r1;  (f1|r1)for random varying slope with each r1

However, in your case, I suspect that the model might not run because
crossed random effects generally take time and with 3 way interactions
that's probably too much for R.  Either way, you can check that by building
your model up slowly and seeing if it runs for the simpler case.  Let me
know how far you get,

Paul

-- 
View this message in context: 
http://r.789695.n4.nabble.com/A-question-about-conducting-crossed-random-effects-in-R-tp2278443p2280578.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] information reduction-database management question

2010-07-06 Thread Paul Chatfield

If you redefine your NAs as below to be detected as some arbitrary large
number, then the code should work through.  Any 5's left in your dataset can
be replaced just as easily by NAs again.  Not elegant, but effective.

site - c(s1, s1, s1, s2,s2, s2)
pref - c(1, 2, 3, 1, 2, 3)
R1 - c(NA, NA, 1, NA,NA,NA)
R2 - c(NA, 0, 1, 1, NA, 1)
R3 - c(NA, 1, 1, NA, 1, 1)
R4 - c(0, NA, 0, 1, NA, 0)
R5 - c(NA, 0, 1, NA, 1, 1)
datum - data.frame(site, pref, R1, R2, R3, R4, R5)

## For 1 column;
datum$R1[is.na(datum$R1)==T]-5
tapply(datum$R1, datum$site, min, na.rm=T)

## Can loop this over all columns;

new-matrix(0,5,2)
for (i in 3:7)
{datum[,i][is.na(datum[,i])==T]-5
new[i-2,]-tapply(datum[,i], datum$site, min, na.rm=T)}

-- 
View this message in context: 
http://r.789695.n4.nabble.com/information-reduction-database-management-question-tp2278863p2279385.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] A question about conducting crossed random effects in R

2010-07-06 Thread Paul Chatfield

Sounds distinctly like an assignment you've been set for which we wouldn't
help.  All I'll say is crossed random effects can be dealt with effectively
in lmer.  See that for more.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/A-question-about-conducting-crossed-random-effects-in-R-tp2278443p2279508.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] information reduction-database management question

2010-07-06 Thread Paul Chatfield

I don't think the approach would change much with text.  You would have
to write a function which picks the 'min' or whatever that means to you
with text and then it should work ok,

 

Paul

 

From: Brad Patrick Schneid [via R]
[mailto:ml-node+2279677-1095983982-120...@n4.nabble.com] 
Sent: 06 July 2010 15:48
To: Paul Chatfield
Subject: Re: information reduction-database management question

 

Thanks Paul, 
I appreciate your time and this is an interesting approach.
Unfortunately, I need it to work for all types of information, including
character data (i.e. text).   
Again.. thanks for your suggestion! 
Brad 

Paul Chatfield wrote:

If you redefine your NAs as below to be detected as some arbitrary large
number, then the code should work through.  Any 5's left in your dataset
can be replaced just as easily by NAs again.  Not elegant, but
effective. 

site - c(s1, s1, s1, s2,s2, s2) 
pref - c(1, 2, 3, 1, 2, 3) 
R1 - c(NA, NA, 1, NA,NA,NA) 
R2 - c(NA, 0, 1, 1, NA, 1) 
R3 - c(NA, 1, 1, NA, 1, 1) 
R4 - c(0, NA, 0, 1, NA, 0) 
R5 - c(NA, 0, 1, NA, 1, 1) 
datum - data.frame(site, pref, R1, R2, R3, R4, R5) 

## For 1 column; 
datum$R1[is.na(datum$R1)==T]-5 
tapply(datum$R1, datum$site, min, na.rm=T) 

## Can loop this over all columns; 

new-matrix(0,5,2) 
for (i in 3:7) 
{datum[,i][is.na(datum[,i])==T]-5 
new[i-2,]-tapply(datum[,i], datum$site, min, na.rm=T)} 

 



View message @
http://r.789695.n4.nabble.com/information-reduction-database-management-
question-tp2278863p2279677.html 
To unsubscribe from Re: information reduction-database management
question, click here
 (link removed) 
NoYXRmaWVsZEByZWFkaW5nLmFjLnVrfDIyNzkzODV8LTE4MjM2NDg5MTM= . 

 


-- 
View this message in context: 
http://r.789695.n4.nabble.com/information-reduction-database-management-question-tp2278863p2279688.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

__
R-help@r-project.org 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] How to say if error

2010-06-24 Thread Paul Chatfield

Hi - I am looping over a structural equation model for a variety of datasets. 
Occasionally, the model returns an error and the loop then breaks.  I'd like
to set a condition which says something like if error, then print NAs
rather than the loop breaking, but I don't know how to say if error.

I'm sure there's a simple answer; I've tried searching Nabble, but error as
a hitword comes up rather often on Nabble lists :)

Thanks

Paul
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-say-if-error-tp2266619p2266619.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] How to say if error

2010-06-24 Thread Paul Chatfield

I've had a look at the conditions in base and I can't get the ones to work
I've looked at but it is all new to me.  

For example, I can work the examples for tryCatch, but it won't print a
finally message for me when I apply it to my model.  Even if I could get
this to work, I think it would still cause a break e.g.
for (j in 1:10)
{tryCatch(ifelse(j==5, stop(j), j), finally=print(oh dear))}

Thanks for the suggestion though - any others?
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-say-if-error-tp2266619p2266760.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] How to say if error

2010-06-24 Thread Paul Chatfield

Thanks Roman - you're right it can do more than I thought.  We're close now
to solving it I feel.  Essentially I'm trying to get the code below to work. 
If the condition is satisfied, it prints 2, but it doesn't save it in z.  I
want it to save it even though there's an error.  Perhaps you can easily see
what I'm missing,

x-rnorm(0);y-rnorm(0)
z-ifelse(tryCatch(lm(y~x), finally=print(2))==1,
NA,lm(rnorm(10)~rnorm(10)))
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-say-if-error-tp2266619p2266782.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] How to say if error

2010-06-24 Thread Paul Chatfield

That's great.  That solves it.  I can work on eloquence later :)  I just  to
sort out that model problem:

 dof-numeric(10)
for (i in 1:10){
  x-rnorm(i-1);y-rnorm(i-1)
  cc - try(lm(y~x), silent=T)
  if(is(cc,try-error)) {dof[i]-NA}
  else {dof[i]-(summary(lm(rnorm(10)~rgamma(10,1,1)))$coef[1,1])}
}

Thank you!

Paul
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-say-if-error-tp2266619p2267049.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] How to say if error

2010-06-24 Thread Paul Chatfield

On a similar issue, how can you detect a warning in a loop - e.g. the
following gives a warning, so I'd like to set up code to recognise that and
then carry on in a loop

x-rnorm(2);y-c(1,0)
ff-glm(y/23~x, family=binomial)

so this would be incorporated into a loop that might be

x-rnorm(10);y-rep(c(1,0),5)
for (i in 1:10)
{ee-glm(y~x, family=binomial)
ff-glm(y/23~x, family=binomial)}

from which I would recognise the warning in ff and not those in ee, saving
results from ee and not from ff. The last bit would be easy adding a line
if(there_is_a_warning_message) {newvector-NA} else {use results} but how do
you detect the warning message?

Thanks all for your feedback so far,

Paul
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-say-if-error-tp2266619p2267140.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] How to say if error

2010-06-24 Thread Paul Chatfield

Thanks again Joris - you've been very helpful J

 

From: Joris FA Meys [via R]
[mailto:ml-node+2267176-1824205151-120...@n4.nabble.com] 
Sent: 24 June 2010 16:40
To: Paul Chatfield
Subject: Re: How to say if error

 

You could do that using the options, eg : 

set.seed(1) 
x - rnorm(1:10) 
y - letters[1:10] 
z - rnorm(1:10) 

warn -getOption(warn) 
options(warn=2) 
for (i in list(x,y,z)){ 
  cc - try(mean(i), silent=T) 
  if(is(cc,try-error)) {next} 
  print(cc) 
} 
options(warn=warn) 

see ?options under warn 

Cheers 
Joris 

On Thu, Jun 24, 2010 at 5:12 PM, Paul Chatfield 
[hidden email] wrote: 


 
 On a similar issue, how can you detect a warning in a loop - e.g. the 
 following gives a warning, so I'd like to set up code to recognise
that and 
 then carry on in a loop 
 
 x-rnorm(2);y-c(1,0) 
 ff-glm(y/23~x, family=binomial) 
 
 so this would be incorporated into a loop that might be 
 
 x-rnorm(10);y-rep(c(1,0),5) 
 for (i in 1:10) 
 {ee-glm(y~x, family=binomial) 
 ff-glm(y/23~x, family=binomial)} 
 
 from which I would recognise the warning in ff and not those in ee,
saving 
 results from ee and not from ff. The last bit would be easy adding a
line 
 if(there_is_a_warning_message) {newvector-NA} else {use results} but
how do 
 you detect the warning message? 
 
 Thanks all for your feedback so far, 
 
 Paul 
 -- 
 View this message in context:
http://r.789695.n4.nabble.com/How-to-say-if-error-tp2266619p2267140.html
http://r.789695.n4.nabble.com/How-to-say-if-error-tp2266619p2267140.htm
l?by-user=t 
 Sent from the R help mailing list archive at Nabble.com. 
 
 __ 
 [hidden email] 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. 
 




-- 
Joris Meys 
Statistical consultant 

Ghent University 
Faculty of Bioscience Engineering 
Department of Applied mathematics, biometrics and process control 

tel : +32 9 264 59 87 
[hidden email] 
--- 
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

__ 
[hidden email] 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. 





View message @
http://r.789695.n4.nabble.com/How-to-say-if-error-tp2266619p2267176.html

To unsubscribe from Re: How to say if error, click here
 (link removed) 
NoYXRmaWVsZEByZWFkaW5nLmFjLnVrfDIyNjcxNDB8LTE4MjM2NDg5MTM= . 

 


-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-say-if-error-tp2266619p2267182.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

__
R-help@r-project.org 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] Read in dataset without saving it

2010-06-09 Thread Paul Chatfield

A simple question - I have a small dataset to read in and want to copy and
paste part from Excel and paste it into an R script file without creating
more files saving it as a .txt/.csv and then reading that in.  I want to
read in 3 columns e.g.
1 2.5 3.4
1 2.3 3.1
1 2.6 3.9
2 2.9 2.8
2 2.6 2.9
2 2.7 2.9
3 2.3 3.3
3 2.4 3.0
3 2.7 3.2

I thought I could use scan() but don't know how to extend it to multiple
columns?  I thought about using colwise (plyr) but think I am making this
more complicated than it probably should be!  Is there an easy way to do
this?

Any ideas gratefully received,

Paul
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Read-in-dataset-without-saving-it-tp2248495p2248495.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] NAs are not allowed in subscripted assignments

2010-04-09 Thread Paul Chatfield

I'm trying to assign NAs to values that satisfy certain conditions (more
complex than shown below) and it gives the right result, but breaks the loop
having done the first one viz:

new-c(rep(5,4),6)
for (i in 1:6)
{new[new[i]5.5][i]-NA}

gives the correct result, though an error message appears which causes a
break if it's in a loop.  If I can get rid of the error message and get the
loop to continue, this should work fine.  I'm sure I'm missing a simple
solution, but can't seem to see it,

Any help, as always, greatly appreciated,

Paul


-- 
View this message in context: 
http://n4.nabble.com/NAs-are-not-allowed-in-subscripted-assignments-tp1819094p1819094.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] NAs are not allowed in subscripted assignments

2010-04-09 Thread Paul Chatfield

Thank you – that’s sorted it.  Trying to make things too complicated! J

 

From: Alain Guillet-2 [via R] 
[mailto:ml-node+1819104-1154170184-120...@n4.nabble.com] 
Sent: 09 April 2010 10:34
To: Paul Chatfield
Subject: Re: NAs are not allowed in subscripted assignments

 

Maybe you can withdraw the [i] in your code... 

  for (i in 1:6) 
+ {new[new[i]5.5]-NA} 
  new 
[1]  5  5  5  5 NA 


Alain 


On 09-Apr-10 11:23, Paul Chatfield wrote: 


 I'm trying to assign NAs to values that satisfy certain conditions (more 
 complex than shown below) and it gives the right result, but breaks the loop 
 having done the first one viz: 
 
 new-c(rep(5,4),6) 
 for (i in 1:6) 
 {new[new[i]5.5][i]-NA} 
 
 gives the correct result, though an error message appears which causes a 
 break if it's in a loop.  If I can get rid of the error message and get the 
 loop to continue, this should work fine.  I'm sure I'm missing a simple 
 solution, but can't seem to see it, 
 
 Any help, as always, greatly appreciated, 
 
 Paul 
 
 
 


-- 
Alain Guillet 
Statistician and Computer Scientist 

SMCS - IMMAQ - Université catholique de Louvain 
Bureau c.316 
Voie du Roman Pays, 20 
B-1348 Louvain-la-Neuve 
Belgium 

tel: +32 10 47 30 50 

__ 
[hidden email] 
http://n4.nabble.com/user/SendEmail.jtp?type=nodenode=1819104i=0  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. 





View message @ 
http://n4.nabble.com/NAs-are-not-allowed-in-subscripted-assignments-tp1819094p1819104.html
 
To unsubscribe from NAs are not allowed in subscripted assignments, click here 
 (link removed) = . 




-- 
View this message in context: 
http://n4.nabble.com/NAs-are-not-allowed-in-subscripted-assignments-tp1819094p1819280.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

__
R-help@r-project.org 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] Paste expression in graph title

2010-01-25 Thread Paul Chatfield

This was my initial attempt at creating a title on a graph of the R squared
value:

x-rnorm(10)
y-rnorm(10)
plot(x,y, main=paste(expression(R^2), = ,round(summary(lm(y~
x))$r.squared, digits=3), sep=))

I've read various other posts that say expression needs to be taken outside
the paste, but I can't seem to get it work as the following fails

plot(x,y, main=expression(paste(R^2, = ,round(summary(lm(y~
x))$r.squared, digits=3), sep=)))

I tried it with title() and didn't get much further either.

Hmmm, any ideas what am I missing?

Thanks

Paul
-- 
View this message in context: 
http://n4.nabble.com/Paste-expression-in-graph-title-tp1289272p1289272.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] Paste expression in graph title

2010-01-25 Thread Paul Chatfield

Thanks – that’s the most helpful solution – it’s important for code to 
be neat too and that is fairly neat if unintuitive!  I had tried bquote a bit, 
but hadn’t figured it out properly.

 

Cheers!

 

Paul

 

From: Henrique Dallazuanna [via R] 
[mailto:ml-node+1289286-317759...@n4.nabble.com] 
Sent: 25 January 2010 12:21
To: Paul Chatfield
Subject: Re: [R] Paste expression in graph title

 

Try this: 

plot(x, y, main = bquote(R^2 == .(round(summary(lm(y ~ x))$r.squared, 3 


On Mon, Jan 25, 2010 at 10:06 AM, Paul Chatfield 
[hidden email] 
http://n4.nabble.com/user/SendEmail.jtp?type=nodenode=1289286i=0  wrote: 


 
 This was my initial attempt at creating a title on a graph of the R squared 
 value: 
 
 x-rnorm(10) 
 y-rnorm(10) 
 plot(x,y, main=paste(expression(R^2), = ,round(summary(lm(y~ 
 x))$r.squared, digits=3), sep=)) 
 
 I've read various other posts that say expression needs to be taken outside 
 the paste, but I can't seem to get it work as the following fails 
 
 plot(x,y, main=expression(paste(R^2, = ,round(summary(lm(y~ 
 x))$r.squared, digits=3), sep=))) 
 
 I tried it with title() and didn't get much further either. 
 
 Hmmm, any ideas what am I missing? 
 
 Thanks 
 
 Paul 
 -- 
 View this message in context: 
 http://n4.nabble.com/Paste-expression-in-graph-title-tp1289272p1289272.html
 Sent from the R help mailing list archive at Nabble.com. 
 
 __ 
 [hidden email] 
 http://n4.nabble.com/user/SendEmail.jtp?type=nodenode=1289286i=1  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. 
 




-- 
Henrique Dallazuanna 
Curitiba-Paraná-Brasil 
25° 25' 40 S 49° 16' 22 O 

__ 
[hidden email] 
http://n4.nabble.com/user/SendEmail.jtp?type=nodenode=1289286i=2  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. 





View message @ 
http://n4.nabble.com/Paste-expression-in-graph-title-tp1289272p1289286.html 
To unsubscribe from Paste expression in graph title, click here  (link 
removed) = . 




-- 
View this message in context: 
http://n4.nabble.com/Paste-expression-in-graph-title-tp1289272p1289291.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

__
R-help@r-project.org 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] Patterned shading in ggplot

2009-11-04 Thread Paul Chatfield

Am trying to produce a graph which prints out well in black and white using
ggplot2.  I have the following example set up nicely, but want to shade the
red bars in one pattern and the blue in another so they print out clearly. 
I tried changing colours to 1 light, 1 dark, but then the overlapping colour
looks virtually identical to the darker one.  I noted the option density in
barplot, but couldn't get this to work in ggplot.  I could just replot this
as density plots using kernel smoothing, but quite like this format for the
data I have.  Any help much appreciated.

library(ggplot2)
xy-data.frame(x=c(rnorm(1000), rnorm(1000,2,1)), grp=as.factor(rep(1:2,
each=1000)))
ggplot(xy, aes(x=x, fill=grp, group=grp)) +
geom_histogram(binwidth=0.5,colour=black,position = identity, alpha =
0.5) + 
scale_fill_manual(values = c(red, blue))
-- 
View this message in context: 
http://old.nabble.com/Patterned-shading-in-ggplot-tp26193795p26193795.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] Plotting 1 covariate, 3 factors

2009-10-08 Thread Paul Chatfield

Cheers guys that's helpful.  Doug, you're right, my code for ff should have
been

for (i in 1:length(y))
{if (f1[i]==after  f3[i]==1) ff[i]-1, after
else if(f1[i]==after  f3[i]==2) ff[i]-2, after
else if(f1[i]==before  f3[i]==1) ff[i]-1, before
else if(f1[i]==before  f3[i]==2) ff[i]-2, before}

As I have factors with only 2,2 and 3 levels respectively, your approach
suits the problem perfectly.  Just to round this off, trying to reorient it
back to having the y on axis 2 seems to mean the line now does dot-to-dot
instead of fitting the average.  Am I being dim in missing a key option in
my statement below which would correct this as your code did, Doug, when
oriented the other way, or does it require some kind of panel statement?

dotplot(y~f2|f1, groups=f3, layout=c(2,1), strip=T, type=c(a,p), pch=19)

Thanks

Paul


Douglas Bates-2 wrote:
 
 I'm not sure if this is exactly what you are looking for but I would
 generally create an interaction plot using the lattice 'dotplot' with
 type = c(p,a) so I get both the original data and the lines
 joining the averages for the different factor levels.  I also prefer
 the horizontal orientation to the vertical orientation.  Combining all
 these variations produces something like
 
 dotplot(f2 ~ y | f1, groups = f3, aspect = 0.2, layout = c(1,2), type
 = c(p,a), pch = 21, strip = FALSE, strip.left = TRUE, auto.key =
 list(columns = 2, lines = TRUE))
 
-- 
View this message in context: 
http://www.nabble.com/Plotting-1-covariate%2C-3-factors-tp25789442p25800572.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] Plotting 1 covariate, 3 factors

2009-10-08 Thread Paul Chatfield

That's solved it.  Superb!



 All you probably need is to make f2 a factor (e.g., y ~ factor(f2) |
 f1). Otherwise dotplot() doesn't know which one to treat as
 categorical.
 
 -Deepayan
 
 

-- 
View this message in context: 
http://www.nabble.com/Plotting-1-covariate%2C-3-factors-tp25789442p25800910.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] Plotting 1 covariate, 3 factors

2009-10-07 Thread Paul Chatfield

I'm interested in plotting a y with an x factor as the combination of 2
factors and colour with respect to a third, which the code below does with
interaction.plot().  However, this is because I redefine the x to be 1
factor.  Is there a way of getting it to plot without redefining it, and
ideally to not join up the lines BETWEEN levels a and b, but just join those
between after and before for one level of f3.  I figure this could be done
by manually drawing over blank lines using ?lines but am not sure what the
coordinates would be and figured there is probably an easier way where
someone has dealt with this before.  Any thoughts greatly appreciated,

Paul

#

y-rnorm(36)
f1-rep(c(after,before), 18)
f2-rep(1:3,12)
f3-rep(1:2, each=18)

## Define new factor to be f1 and f3 for x axis - clumsy code, but gets its
done;

ff-numeric(length(y))
for (i in 1:length(y))
{if (f1[i]==a  f3[i]==1) ff[i]-1, a
else if(f1[i]==a  f3[i]==2) ff[i]-2, a
else if(f1[i]==b  f3[i]==1) ff[i]-1, b
else ff[i]-2, b}

## Plot of interest;

interaction.plot(ff,f2,y)
-- 
View this message in context: 
http://www.nabble.com/Plotting-1-covariate%2C-3-factors-tp25789442p25789442.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] Statistician Needed

2009-08-11 Thread Paul Chatfield

Hi Noah - I work for the statistical services centre and could help.  

Email p.s.chatfi...@rdg.ac.uk,

Paul


Noah Silverman-3 wrote:
 
 Hello,
 
 I've come up with some challenges with  my process that are a bit too 
 complicated for the mailing list.
 
 Is there anyone out there, preferably a real statistician, who is 
 willing to consult with me via phone/email for a few hours.  I'm happy 
 to pay you for your time.
 
 Thanks,
 
 -Noah
 
 __
 R-help@r-project.org 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.
 
 

-- 
View this message in context: 
http://www.nabble.com/Statistician-Needed-tp24909288p24916331.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] Combine two matricies

2009-07-13 Thread Paul Chatfield

The following code should do it.  This assumes matrices a and x are of the
same dimension which is why  you can index a as below

x[is.na(x)==TRUE]-a[is.na(x)==TRUE]

-- 
View this message in context: 
http://www.nabble.com/Combine-two-matricies-tp24458609p24458797.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] random sampling or random replacement

2009-06-25 Thread Paul Chatfield

If you want to average 20% missing values then you could try it in 1 step,
viz:

sample(c(1:2, rep(NA, 2000)),100)

Otherwise, 2 steps is preferable.  Use code as below:

sample(1:2,100)-kk
kk[sample(1:100,20)]-NA

Paul
-- 
View this message in context: 
http://www.nabble.com/random-sampling-or-random-replacement-tp24199695p24200736.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] Snap axes to origin rather than around it

2009-06-12 Thread Paul Chatfield

I'm trying to plot a graph where the axes go through 0,0, rather than around
it combined with a box round the graph, so

x-0:10;y-0:10
plot(x,y) 

gives me a box but doesn't go through the point 0,0, but stays at a
distance.

In trying to circumvent this problem, I wrote 

plot(x,y)
axis(1, pos=c(0,0));axis(2,pos=c(0,0)) 

which gives me axes that go through the origin, but then I can't make a box
round a plot (box() goes again at this fixed distance from the origin rather
than through it)

Any thoughts, ideas gratefully accepted.  Perhaps I've been looking at it so
long I'm now missing the obvious! :)

Paul

Any ideas?
-- 
View this message in context: 
http://www.nabble.com/Snap-axes-to-origin-rather-than-around-it-tp23997802p23997802.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] Curved arrows

2009-04-30 Thread Paul Chatfield

I'm trying to draw an arrow with a curved shaft on the graph as a straight
one looks messy on a detailed graph.  I've looked in arrows but it doesn't
seem to give an option.  larrows doesn't look much more promising.  I had a
look in the archive and couldn't find anything.  Any thoughts?

Thanks

Paul
-- 
View this message in context: 
http://www.nabble.com/Curved-arrows-tp23312316p23312316.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.