[R] Trellis Conditional contourplot

Deepayan Sarkar deepayan.sarkar at gmail.com
Wed Oct 25 20:40:44 CEST 2006


On 10/25/06, Marco LO <useebi at yahoo.com.hk> 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



More information about the R-help mailing list