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 Deepayan Sarkar
On Thu, Oct 8, 2009 at 1:57 AM, Paul Chatfield p.s.chatfi...@rdg.ac.uk wrote:

 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)

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

__
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.


Re: [R] Plotting 1 covariate, 3 factors

2009-10-07 Thread Richard M. Heiberger

## Paul

## I think you are looking for interaction2wt

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

## your definition of ff was faulty.  It gave a constant.
f3.f1 - interaction(f3, f1)
interaction.plot(f3.f1, f2, y)

f2 - factor(f2)
f3 - factor(f3)

## lattice would be better
xyplot(y ~ f2 | f3, groups=f2)


## if you don't have HH, you will need to install it and its dependencies
## install.packages(HH)
## You may need to close R and restart R

require(HH)
interaction2wt(y ~ f1 + f2 + f3)

position(f1) - c(1.5, 2.5)
position(f3) - c(1.5, 2.5)
interaction2wt(y ~ f1 + f2 + f3, box.ratio=.6)

## Rich

__
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-07 Thread Douglas Bates
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))

On Wed, Oct 7, 2009 at 11:00 AM, Paul Chatfield p.s.chatfi...@rdg.ac.uk wrote:

 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.


__
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.