Re: [R] Trellis Conditional contourplot

2006-10-27 Thread Marco LO
Finally I got the unreasonable contour plotted.
   
  http://www.geocities.com/useebi/data/kdecontour.jpeg
   
  The codes to get the plot,
   
  cdplot2d(survived ~ age + sibsp, data = titanic3)
   
  are in http://www.geocities.com/useebi/data/cdplot2d.txt
   
  One step that I couldn't accomplish as in cdplot is to eliminate those 
undefined conditional densities outside the ranges of the two covariates.  The 
plot dosen't make sense for areas with no x and y observation.  Probably, this 
is why the goal did not sound like anything reasonable.
   
  Anyway, I guess the naked eyes are pretty good to estimate the conditional 
density from the color coded scatterplot if nothing else works!
   
  marco


Deepayan Sarkar [EMAIL PROTECTED] wrote:
  On 10/25/06, Marco LO wrote:
 OK!

 # The R codes to generate the Trellis plot are from the R help archive by
 Karl Ove Hufthammer

 panel.estcontplot - function(x, y, ..., pretty=TRUE, region=FALSE)
 {
 cest.gr=kde2d(x, y)
 cest.gr.lat=con2tr(cest.gr)
 panel.contourplot(cest.gr.lat$x, cest.gr.lat$y, cest.gr.lat$z,
 subscripts = seq(nrow(cest.gr.lat)),
 pretty=pretty, region=region, contour=TRUE, ...)
 }

 # The titanic3 dataset is from
 http://biostat.mc.vanderbilt.edu/twiki/pub/Main/DataSets/titanic3.xls
 with missing value imputations according to the book

 library(Hmisc)
 set.seed(17)
 xtrans - transcan(~ I(age) + pclass + sex + sibsp + parch + survived, data
 = titanic3,
 n.impute=5, pl=F, trantab=T, imputed=T, transformed=TRUE)
 titanic3[ ,'age'] - xtrans$transformed[ ,'age']
 titanic3[ ,'survived'] - as.factor(titanic[ ,'survived'])

 library(lattice)
 xyplot(age ~ sibsp | survived, data = titanic3, panel=panel.estcontplot)


 Anyway, I realized that Trellis could only be conditional on the categorical
 variable while what I really want is conditional density plot of survived on
 the two covariates.

That goal does not sound like anything reasonable to me, but I don't
know much about categorical data analysis, so I'll let someone else
answer. However, based on your first post where you implied that you
expected 'densities' to 'add up to 1', I _will_ suggest this: if the
phrase counting measure does not mean anything to you, you should
seriously consider consulting a local statistician to whom it does.

-Deepayan



-

[[alternative HTML version deleted]]

__
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] Trellis Conditional contourplot

2006-10-27 Thread hadley wickham
 Finally I got the unreasonable contour plotted.

   http://www.geocities.com/useebi/data/kdecontour.jpeg

   The codes to get the plot,

   cdplot2d(survived ~ age + sibsp, data = titanic3)

   are in http://www.geocities.com/useebi/data/cdplot2d.txt

   One step that I couldn't accomplish as in cdplot is to eliminate those 
 undefined conditional densities outside the ranges of the two covariates.  
 The plot dosen't make sense for areas with no x and y observation.  Probably, 
 this is why the goal did not sound like anything reasonable.


You can do something pretty similar with ggplot:
qplot(age, sibsp, . ~ survived,  data=titanic3, type=c(jitter,2density))

(except clearly the density calculation is very different)

Hadley

__
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] Trellis Conditional contourplot

2006-10-25 Thread Marco LO
OK!
   
  # The R codes to generate the Trellis plot are from the R help archive by 
Karl Ove Hufthammer
   
  panel.estcontplot - function(x, y, ..., pretty=TRUE, region=FALSE)
{
  cest.gr=kde2d(x, y)
  cest.gr.lat=con2tr(cest.gr)
  panel.contourplot(cest.gr.lat$x, cest.gr.lat$y, cest.gr.lat$z,
   subscripts = seq(nrow(cest.gr.lat)),
   pretty=pretty, region=region, contour=TRUE, ...)
}
   
  # The titanic3 dataset is from 
http://biostat.mc.vanderbilt.edu/twiki/pub/Main/DataSets/titanic3.xls with 
missing value imputations according to the book
   
  library(Hmisc)
set.seed(17)
xtrans - transcan(~ I(age) + pclass + sex + sibsp + parch + survived, data = 
titanic3,
n.impute=5, pl=F, trantab=T, imputed=T, transformed=TRUE)
titanic3[ ,'age'] - xtrans$transformed[ ,'age']
titanic3[ ,'survived'] - as.factor(titanic[ ,'survived'])
   
  library(lattice)
  xyplot(age ~ sibsp | survived, data = titanic3, panel=panel.estcontplot)
   
   
  Anyway, I realized that Trellis could only be conditional on the categorical 
variable while what I really want is conditional density plot of survived on 
the two covariates.  Thus I tried to twist cdplot with kde2d to substitute 
density.
   
  http://www.geocities.com/useebi/data/cdplot2d.txt
   
  However, I still have no success.  Would anyone help, please!
   
  Thanks
  marco
  

Deepayan Sarkar [EMAIL PROTECTED] wrote:
  On 10/24/06, Marco LO wrote:
 Hello All,

 I've problems to interpret the contourplot for a binary response dependent 
 variable. For example, I ploted the survived probability for the titanic3 
 dataset,

 http://www.geocities.com/useebi/data/CondenContour.jpeg

 Trellis displayed two panels of contour, one for dead and one for alive. 
 However,
 the contours between the two panels didn't conform to the rule of prob(dead) =
 1 - prob(alive). How I should read the contours? What I did wrongly?

Hard to say, since we have no idea what you actually did. As the
footer of every r-help message says:

PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

-Deepayan

 Is there an example that I could follow?

 Thanks!
 marco



-


[[alternative HTML version deleted]]

__
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] Trellis Conditional contourplot

2006-10-25 Thread Deepayan Sarkar
On 10/25/06, Marco LO [EMAIL PROTECTED] wrote:
 OK!

 # The R codes to generate the Trellis plot are from the R help archive by
 Karl Ove Hufthammer

 panel.estcontplot - function(x, y, ..., pretty=TRUE, region=FALSE)
 {
   cest.gr=kde2d(x, y)
   cest.gr.lat=con2tr(cest.gr)
   panel.contourplot(cest.gr.lat$x, cest.gr.lat$y, cest.gr.lat$z,
subscripts = seq(nrow(cest.gr.lat)),
pretty=pretty, region=region, contour=TRUE, ...)
 }

 # The titanic3 dataset is from
 http://biostat.mc.vanderbilt.edu/twiki/pub/Main/DataSets/titanic3.xls
 with missing value imputations according to the book

 library(Hmisc)
 set.seed(17)
 xtrans - transcan(~ I(age) + pclass + sex + sibsp + parch + survived, data
 = titanic3,
 n.impute=5, pl=F, trantab=T, imputed=T, transformed=TRUE)
 titanic3[ ,'age'] - xtrans$transformed[ ,'age']
 titanic3[ ,'survived'] - as.factor(titanic[ ,'survived'])

 library(lattice)
 xyplot(age ~ sibsp | survived, data = titanic3, panel=panel.estcontplot)


 Anyway, I realized that Trellis could only be conditional on the categorical
 variable while what I really want is conditional density plot of survived on
 the two covariates.

That goal does not sound like anything reasonable to me, but I don't
know much about categorical data analysis, so I'll let someone else
answer. However, based on your first post where you implied that you
expected 'densities' to 'add up to 1', I _will_ suggest this: if the
phrase counting measure does not mean anything to you, you should
seriously consider consulting a local statistician to whom it does.

-Deepayan

__
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] Trellis Conditional contourplot

2006-10-24 Thread Marco LO
Hello All,
   
  I've problems to interpret the contourplot for a binary response dependent 
variable.  For example, I ploted the survived probability for the titanic3 
dataset,
   
  http://www.geocities.com/useebi/data/CondenContour.jpeg
   
  Trellis displayed two panels of contour, one for dead and one for alive.  
However, the contours between the two panels didn't conform to the rule of 
prob(dead) = 1 - prob(alive).  How I should read the contours?  What I did 
wrongly?  Is there an example that I could follow?
   
  Thanks!
  marco
   


-


[[alternative HTML version deleted]]

__
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] Trellis Conditional contourplot

2006-10-24 Thread Deepayan Sarkar
On 10/24/06, Marco LO [EMAIL PROTECTED] wrote:
 Hello All,

   I've problems to interpret the contourplot for a binary response dependent 
 variable.  For example, I ploted the survived probability for the titanic3 
 dataset,

   http://www.geocities.com/useebi/data/CondenContour.jpeg

   Trellis displayed two panels of contour, one for dead and one for alive.  
 However,
 the contours between the two panels didn't conform to the rule of prob(dead) =
 1 - prob(alive).  How I should read the contours?  What I did wrongly?

Hard to say, since we have no idea what you actually did. As the
footer of every r-help message says:

PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

-Deepayan

 Is there an example that I could follow?

   Thanks!
   marco

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