Re: [R] lean text label below barplot table

2009-09-13 Thread Ilai

 par(xpd=T)
 bp<- barplot(matrix(1:50,5,10),names=F)
 text(bp,-2,c('these labels','are tooo','looong'),pos=2,srt=45)
 


Xiaogang Yang wrote:
> 
> Hi, everyone:
> I am plotting an graph with bar plot, but the label after every bar is too
> long, I wanna if I can draw the label lean to an angle
> thanks
> 
> -- 
> Xiaogang Yang
> Sensorweb Research Laboratory
> http://sensorweb.vancouver.wsu.edu/
> Washington State University Vancouver
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/lean-text-label-below-barplot-table-tp25336287p25426596.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] Changing mtext direction, or using text for the margin?

2013-01-07 Thread ilai
On Mon, Jan 7, 2013 at 11:52 AM, David Winsemius wrote:

>
> If you are going that route you may want to look at the gridBase package.
>
> Yes for mixing base and grid graphics but IMHO overkill here. Replacing
the last mtext line with

grid::grid.text('dependent B', 0.985 , 0.5 , rot = 270)

should take care of it (leaving exact placement and justification to the OP)

cheers



> --
> David.
>
>  Mike
>>
>> David Winsemius wrote:
>>
>>>
>>> On Jan 7, 2013, at 8:06 AM, Michael Rennie wrote:
>>>
>>>
 Any thoughts on what that dirty hack might be or any leads on where to
 start? Perhaps a whole new plot region in the margin or something? Is that
 even possible? I'm having a difficult time imagining how I can do this.

>>>
>>> The `text` function accepts the 'xpd' argument for `par`.
>>>
>>> ?par
>>> ?text
>>>
>>> (Similar but not exactly the same as R-FAQ "7.27 How can I create
>>> rotated axis labels?")
>>>
>>> I'm not sure what sort of "dirt" Uwe was expecting, but I'm guessing he
>>> meant that you probably were not going to be getting exactly what you
>>> wanted with the first attempt and were going to need to adjust the
>>> locations "by hand" after digging around in the par documentation.
>>>
>>>
>>
> David Winsemius, MD
> Alameda, CA, USA
>
> __**
> 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.
>

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


Re: [R] overlaying zoo plots in lattice

2013-01-11 Thread ilai
str(x) ; str(y) reveals
#‘zoo’ series ...
#  ..$ : chr [1:3] "a" "c" "b"   ## HERE
#  Index:  Date[1:100], format: "2010-01-01" "2010-01-02" "2010-01-03"
"2010-01-04" ...
#'data.frame':99 obs. of  3 variables:
# $ ID   : Factor w/ 3 levels "a","b","c":   ## HERE
# ...
#'

So change the levels of ID in y or in the plot call to fit the zoo object:
xyplot(x)+as.layer(xyplot(value~date|factor(ID,levels=c('a','c','b')), y))





On Fri, Jan 11, 2013 at 12:27 PM, A Duranel wrote:

> Hello
>
> Let's say I have a multivariate zoo timeseries (synchronised automatic
> loggers at different places):
>
> library(zoo)
> library(lattice)
> library(latticeExtra)
>
> x<-zoo(data.frame(a=rnorm(100), c=rnorm(100), b=rnorm(100)),
> seq(from=as.Date("2010-01-01"), by="day", length.out=100))
>
>
> and a dataframe with manual control points at variable dates:
>
> y<-data.frame(ID=rep(c("b", "c", "a"),33), value=rep(c(-2, 0, 2), 33))
> y$date<-seq(from=as.Date("2010-01-01"), by="day", length.out=99)
>
> I would like to create a lattice graph with one panel per column of the zoo
> timeseries, and overlay on each of them the control points that correspond
> to it, on the basis of the "ID" factor in the dataframe that matches the
> column names of the zoo timeseries.
> I tried this:
>
> xyplot(x)+as.layer(xyplot(value~date|ID, y))
>
> Unfortunately the points are not placed according to the name of the panels
> (and of the column names of the zoo timeseries), but to the alphabetical
> order of the "ID" factor it seems.
>
> Any help will be much appreciated!
>
> Arnaud
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/overlaying-zoo-plots-in-lattice-tp4655281.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.
>

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


Re: [R] Log scale on y axis of parallel coordinate plot (lattice)

2013-01-16 Thread ilai
On Wed, Jan 16, 2013 at 12:05 PM, Patrick Connolly <
p_conno...@slingshot.co.nz> wrote:

> On Mon, 07-Jan-2013 at 10:21PM +1100, Roland Seubert wrote:
>
> |> Hello all,
> |>
> |> I would like to make a parallel coordinate plot with lattice. The
> |> plot should have vertical log scale axes, and should in principle
> |> look like this one (I put less chemical elements in my example
> |> below):
> |>
> |> http://www.geokem.com/images/scans/epr-and-N_Chile_Ridge.gif
> |>
> |> The data I am trying to plot are chemical analyses of rock samples
> |> (data frame "df"). The data needs to be normalised against a
> |> reference sample (vector "norm"), to get the actual data to be
> |> plotted (data frame "df_n"). Here is a simplified example:
> |>
> |> > df <- data.frame(La = c(3.0, 2.9, 2.7), Eu = c(0.86, 0.76, 0.66),
> |> Lu = c(0.07, 0.04, 0.04), row.names = c("sample1", "sample2",
> |> "sample3"))
> |> > norm <- c(0.237, 0.0563, 0.0246)
> |> > df_n <- df / norm
> |> > df_n
> |>LaEuLu
> |> sample1  12.65823  3.628692 0.2953586
> |> sample2  51.50977 13.499112 0.7104796
> |> sample3 109.75610 26.829268 1.6260163
> |>
> |> The plot needs the same scale for all axes, so my simple panel
> |> function would be:
> |>
> |> > panel.myplot <- function(..., common.scale) {panel.parallel(...,
> |> common.scale = TRUE)}
> |>
> |> I tried to plot the data with the following command to get vertical
> |> axes with a log scale:
> |>
> |> > parallelplot(~ df_n, panel = panel.myplot, horizontal.axis =
> |> FALSE, scales = list(y = list(log = 10)))
> |>
> |> The problem is that lattice simply ignores the log scale and gives
> |> me the following warning:
> |>
> |> Warning message:
> |> In parallelplot.formula(~df_n, panel = panel.spiderplot,
> |> horizontal.axis = FALSE,  :
> |>   cannot have log y-scale
>
> Check out how to use the scales list in the help for xyplot().  You
> might need to brush up on how the help for axis() to see which
> parameters you need to set.
>
> Actually I don't think that's the OP's problem. My guess the attempt to
set the scale for y was because horizontal.axis = FALSE, which makes
intuitive sense but unfortunately is wrong for parallelplot (which uses
y.scales for annotation of the categories regardless of direction).
OP, try
c(parallelplot(~ df_n, horizontal.axis = FALSE, scales=list(x = list(log =
TRUE))) ,
 parallelplot(~ df_n, horizontal.axis = FALSE))

Cheers



> HTH
>
> --
> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>___Patrick Connolly
>  {~._.~}   Great minds discuss ideas
>  _( Y )_ Average minds discuss events
> (:_~*~_:)  Small minds discuss people
>  (_)-(_)  . Eleanor Roosevelt
>
> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>
> __
> 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.
>

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


Re: [R] Log scale on y axis of parallel coordinate plot (lattice)

2013-01-16 Thread ilai
On Wed, Jan 16, 2013 at 12:46 PM, ilai  wrote:

Oops... That's

require(latticeExtra)

> c(parallelplot(~ df_n, horizontal.axis = FALSE, scales=list(x = list(log =
> TRUE))) ,
>  parallelplot(~ df_n, horizontal.axis = FALSE))
>

or you'll get the full printout of the two objects.
Sorry



> HTH
>>
>> --
>> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>>___Patrick Connolly
>>  {~._.~}   Great minds discuss ideas
>>  _( Y )_ Average minds discuss events
>> (:_~*~_:)  Small minds discuss people
>>  (_)-(_)  . Eleanor Roosevelt
>>
>> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>>
>> __
>> 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.
>>
>
>

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


Re: [R] Lattice levelplot- remove unused levels per panel

2013-01-20 Thread ilai
On Sun, Jan 20, 2013 at 1:59 AM, ronny  wrote:

> Hi,
>
> I am using levelplot, and would like remove from each panel (condition) its
> unused x levels.
>

Uneven scales on categorical axes lead to distortion and a miss
representation (as in your example - the area for levels 4,6 in vs1 will be
bigger than for vs0). In short, don't do it. IMO a solution such as
levelplot(mpg ~ factor(cyl) * factor(gear) | factor(vs) , mtcars,
par.settings=list(panel.background=list(col='grey')))

is much better. Note, your request could make sense for some continuous
variables, so if you insist you could always
levelplot(mpg ~ as.numeric(cyl) * factor(gear) | factor(vs) , mtcars,
scales=list(x=list(relation='free')))

HTH


> e.g.
> Remove from panel vs=1 the cyl level=8.
> data(mtcars)
> levelplot(mpg~factor(cyl)*factor(gear)|factor(vs))
>
> Thanks for your help,
> Ronny
>
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Lattice-levelplot-remove-unused-levels-per-panel-tp4656087.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.
>

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


Re: [R] italic font for legend text when using expression function for symbols

2013-01-23 Thread ilai
plot(1)
legend('topleft',legend=expression(A,italic(A),bolditalic(A),Delta*italic(D)))

On Wed, Jan 23, 2013 at 9:45 AM, raz  wrote:

> Hello,
>
> I'm trying to add a symbol (Delta) to plot legend with text using
> "expression(paste())" but this disables the text.font that allows to use
> bold or italic text.
> as follows:
> x=c(1:10)
> y=c(1:10)
> plot(x,y)
> legend(1,10,legend=c("A","B","C",expression(paste(Delta, D))),
>pch=c(24,18,17,16),cex=2,text.font=3,bty="n")
>
> Any suggestion to how I can add the Delta symbol and have a italic font?
>
> Thanks
>
> --
> \m/
>
> [[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.
>

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


Re: [R] different legends in lattice panels

2013-01-26 Thread ilai
On Sat, Jan 26, 2013 at 10:26 AM, Tito de Morais Luis <
luis.tito-de-mor...@ird.fr> wrote:

> Hi listers,
>
> I want to make lattice plots xyplots with the indication of legends
> inside each panel with only the points and the lines actually ploted
> inside each given panel according to the group(ing) factor.
>
> The code below shows what I have achieved so far and I hope will make
> clear what I want to have.
> It seems to me that my solution is a very "dirty hack" and there
> certainly is a much simple and "clean" way to do it.
> Besides, there is no concordance in lty and pch between the legend above
> the graph with those inside the panels.
>
> No. Look again. It is your panel legends that don't correspond to the
actual plot. The plot symbols and line types for the chosen theme !=
pch[1:10] and lty[1:10]. You can either explicitly set the pch and lty in
the plot and auto.key to be 1:10 and proceed with trellis.focus or insert
draw.key in the panel function to automate the procedure and query the
groups and graphical parameters of each panel :

xyplot(lbt ~ de | type, data=dataf, groups =sta,
 type=c("p","g","r"), layout=c(4,1), par.settings = standard.theme(color =
FALSE),
 auto.key=list(space="top", columns=5, lines=TRUE),
 panel=function(x,y,groups,subscripts,...){
  panel.xyplot(x,y,groups=groups,subscripts=subscripts,...)
  pug <- levels(groups)[levels(groups)%in%groups[subscripts]]
  draw.key(key=list(text = list(as.character(pug)),
lines = list(lty =
rep(trellis.par.get('superpose.line')$lty,10)[as.numeric(pug)]),
points = list(pch =
rep(trellis.par.get('superpose.symbol')$pch,10)[as.numeric(pug)])
   ),
   draw=TRUE , vp=viewport(x=0.25,y=0.9))
})

HTH


> I have searched the archive and the web and found some hints that helped
> me a lot to write the code below. But I am not very familiar with
> lattice trellis graphs and I am sure that I am missing something.
> I would appreciate any suggestion that will help me to improve this.
>
> Thank you in advance,
>
> Tito
>
> require(lattice)
> require(grid)
> # some random data
> lbt <- abs(rnorm(100)) # any biological value
> de <- rep(1:10,10) # the depth
> type <- rep(c("A","C","F","S"), c(20,30,40,10)) # the type of sampling zone
> sta <- as.factor(rep(1:10, c(10,10,10,10,10,10,10,10,10,10))) # the
> station number
> dataf <- data.frame(lbt,de,type,sta) # the dataframe
> # key creation
> keyA <- list(border = FALSE, text =
> list(levels(dataf$sta)[1:2]),lines=TRUE,points=TRUE,lty=c(1:2),pch=c(1:2))
> keyC <- list(border = FALSE, text =
> list(levels(dataf$sta)[3:5]),lines=TRUE,points=TRUE,lty=c(3:5),pch=c(3:5))
> keyF <- list(border = FALSE, text =
> list(levels(dataf$sta)[6:9]),lines=TRUE,points=TRUE,lty=c(6:9),pch=c(6:9))
> keyS <- list(border = FALSE, text =
> list(levels(dataf$sta)[10]),lines=TRUE,points=TRUE,lty=c(10),pch=c(10))
>
> # the plot
> xyplot(lbt ~ de | type, data=dataf, groups =
> sta,type=c("p","g","r"),layout=c(4,1),par.settings =
> standard.theme(color = FALSE), auto.key=list(space="top", columns=5,
> lines=TRUE))
>
> # add "legends" inside the panels
> trellis.focus("panel", 1, 1) ; draw.key(keyA, draw = TRUE, vp =
> viewport(.25, .9))
> trellis.focus("panel", 2, 1) ; draw.key(keyC, draw = TRUE, vp =
> viewport(.75, .9))
> trellis.focus("panel", 3, 1) ; draw.key(keyF, draw = TRUE, vp =
> viewport(.75, .9))
> trellis.focus("panel", 4, 1) ; draw.key(keyS, draw = TRUE, vp =
> viewport(.75, .9))
> trellis.unfocus()
>
>
> --
> Luis Tito de Morais
> IRD - UMR LEMAR (IRD/UBO/CNRS/IFREMER)
>
> Tél. : +33 2 98 49 86 35
> Mob. : +33 6 37 67 21 40
>
> Courriel-1 : luis.tito-de-mor...@ird.fr
> Courriel-2 : luis.titodemor...@univ-brest.fr
>
> Pages web :
> Lab. : http://www-iuem.univ-brest.fr/UMR6539/recherche/equipe-5
> Pers. : http://ird.academia.edu/LuisTitodeMorais
> Reshal : http://www.netvibes.com/reshal#Accueil
> Biblio. : http://www.citeulike.org/user/ltitodem
>
>
> [[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.
>
>

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


Re: [R] glm poisson and quasipoisson

2013-02-01 Thread ilai
On Thu, Jan 31, 2013 at 2:13 PM, Wim Kreinen  wrote:

> Hello,
>
> I have a question about modelling via  glm.


I think you are way off track. Either the data, glm, or both, are not what
you think they are.


> I have a dataset

skn300.tab <- structure(list(n = 1:97, freq = c(0L, 0L, 0L, 0L, 1L, 7L, 40L,
100L, 276L, 543L, 952L, 1414L, 1853L, 2199L, 2435L, 2270L, 2042L,
1679L, 1386L, 1108L, 922L, 792L, 642L, 597L, 453L, 424L, 370L,
297L, 278L, 218L, 208L, 172L, 174L, 149L, 124L, 98L, 98L, 67L,
78L, 67L, 46L, 34L, 31L, 42L, 34L, 21L, 28L, 18L, 18L, 18L, 10L,
19L, 6L, 9L, 10L, 6L, 6L, 5L, 3L, 9L, 4L, 3L, 4L, 5L, 2L, 6L,
4L, 2L, 2L, 3L, 3L, 0L, 0L, 0L, 0L, 2L, 1L, 0L, 0L, 0L, 0L, 0L,
1L, 0L, 0L, 1L, 2L, 1L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 1L),
kum = c(0L, 0L, 0L, 0L, 1L, 8L, 48L, 148L, 424L, 967L, 1919L,
L, 5186L, 7385L, 9820L, 12090L, 14132L, 15811L, 17197L,
18305L, 19227L, 20019L, 20661L, 21258L, 21711L, 22135L, 22505L,
22802L, 23080L, 23298L, 23506L, 23678L, 23852L, 24001L, 24125L,
24223L, 24321L, 24388L, 24466L, 24533L, 24579L, 24613L, 24644L,
24686L, 24720L, 24741L, 24769L, 24787L, 24805L, 24823L, 24833L,
24852L, 24858L, 24867L, 24877L, 24883L, 24889L, 24894L, 24897L,
24906L, 24910L, 24913L, 24917L, 24922L, 24924L, 24930L, 24934L,
24936L, 24938L, 24941L, 24944L, 24944L, 24944L, 24944L, 24944L,
24946L, 24947L, 24947L, 24947L, 24947L, 24947L, 24947L, 24948L,
24948L, 24948L, 24949L, 24951L, 24952L, 24952L, 24952L, 24952L,
24952L, 24954L, 24954L, 24954L, 24954L, 24955L)), .Names = c("n",
"freq", "kum"), row.names = c(NA, -97L), class = "data.frame")


> that looks like as if it where poisson distributed (actually I would
> appreciate that) but it isnt


plot(skn300.tab)

My guess, we are looking at the pdf and cdf (maybe even of a Poisson
process), but not at any "data" that lends itself to a (generalized) linear
model. Consult a statistician, post on stackexchange, read about
regression, or better define your actual R problem here, demonstrating this
is not homework - see the posting guide.

Cheers




> because  mean unequals var.
>
>
> > mean (x)
> [1] 901.7827
> > var (x)
> [1] 132439.3
>
>
> Anyway, I tried to model it via poisson and quasipoisson. Actually, just to
> get an impression how glm works. But I dont know how to interprete the
> data. Of course this is the case because my knowledge concerning logistic
> regressions is rather limited. Hoping there is somebody with mercy I would
> like to understand which parameters are important, e.g. which paramter
> might give me a hint that a poisson model is a bad idea. For hints
> concerning some tutorials  about reading glm-output I would appreciate as
> well.
>
> Thanks
> Wim
>
>
> > skn300.glmp <- glm (freq~n, data=skn300.tab, family=poisson)
> > summary (skn300.glmp)
>
> Call:
> glm(formula = freq ~ n, family = poisson, data = skn300.tab)
>
> Deviance Residuals:
> Min   1Q   Median   3Q  Max
> -51.332   -9.383   -6.599   -3.959   55.111
>
> Coefficients:
>   Estimate Std. Error z value Pr(>|z|)
> (Intercept)  7.2374375  0.0093285   775.8   <2e-16 ***
> n   -0.0539424  0.0003699  -145.8   <2e-16 ***
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> (Dispersion parameter for poisson family taken to be 1)
>
> Null deviance: 71731  on 96  degrees of freedom
> Residual deviance: 37383  on 95  degrees of freedom
> AIC: 37800
>
> Number of Fisher Scoring iterations: 6
>
> >
> > skn300.glmq <- glm (freq~n, data=skn300.tab, family=quasipoisson)
> > summary (skn300.glmq)
>
> Call:
> glm(formula = freq ~ n, family = quasipoisson, data = skn300.tab)
>
> Deviance Residuals:
> Min   1Q   Median   3Q  Max
> -51.332   -9.383   -6.599   -3.959   55.111
>
> Coefficients:
>  Estimate Std. Error t value Pr(>|t|)
> (Intercept)  7.237438   0.186381  38.831  < 2e-16 ***
> n   -0.053942   0.007391  -7.298  8.8e-11 ***
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> (Dispersion parameter for quasipoisson family taken to be 399.1874)
>
> Null deviance: 71731  on 96  degrees of freedom
> Residual deviance: 37383  on 95  degrees of freedom
> AIC: NA
>
> Number of Fisher Scoring iterations: 6
>
>
> >  dput (skn300.tab)
> structure(list(n = 1:97, freq = c(0L, 0L, 0L, 0L, 1L, 7L, 40L,
> 100L, 276L, 543L, 952L, 1414L, 1853L, 2199L, 2435L, 2270L, 2042L,
> 1679L, 1386L, 1108L, 922L, 792L, 642L, 597L, 453L, 424L, 370L,
> 297L, 278L, 218L, 208L, 172L, 174L, 149L, 124L, 98L, 98L, 67L,
> 78L, 67L, 46L, 34L, 31L, 42L, 34L, 21L, 28L, 18L, 18L, 18L, 10L,
> 19L, 6L, 9L, 10L, 6L, 6L, 5L, 3L, 9L, 4L, 3L, 4L, 5L, 2L, 6L,
> 4L, 2L, 2L, 3L, 3L, 0L, 0L, 0L, 0L, 2L, 1L, 0L, 0L, 0L, 0L, 0L,
> 1L, 0L, 0L, 1L, 2L, 1L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 1L),
> kum = c(0L, 0L, 0L, 0L, 1L, 8L, 48L, 148L, 424L, 967L, 1919L,
> L, 5186L, 7385L, 9820L, 12090L, 14132L, 15811L, 17197L,
> 18305L, 19227L, 20019L, 20661L

Re: [R] Remove and add to many matrices in list.

2013-02-05 Thread ilai
1) We don't have your previous email and I doubt anyone here committed your
code to memory
2) No offense but this post is still an eye sore. Actually I am guessing
even worse than the first because there is no working example. The idea is
to provide *minimal* code that reproduces the problem - without extra
info/functionality (setting attributes, stages of the simulation not needed
etc.).
3) There is (still ?)  important info missing like what does "fail" mean ?
with what error ? at what stage of the simulation (initialization ? last
stage ? different iteration every time ? ).
4) Your pseudo-code is worthless as any number of things can go wrong, for
e.g. (but not limited to):
consider your statement
> which.duplicate <- sample(ncol(matrix[[I]], number.to.delete, replace=F)
a) number.to.delete/duplicate is not an integer
b)  missing a closing on ncol(),
c)  supposed to be  number.to.duplicate
d) ncol(matrix[[I]]) is less than number.to.delete/duplicate
...
5) In the mean time, you could try adding print statements to different
objects in your function so if it is the random component in the simulation
causing the fail, you'll see the origin (e.g. prop.to.delete == 1).

HTH

On Tue, Feb 5, 2013 at 4:42 AM, Benjamin Ward (ENV) wrote:

> Hi all,
>
> I realised that my last email question and code was probably going to be a
> bit of an eyesore for some people and that perhaps the best thing for me to
> do is to pose the question of what it is I want to achieve, rather than
> what I've written, if it helps people:
>
> I'm writing a simulation, and during that simulation I have a list of
> matrices – of variable number of columns.
> For every matrix in this list I want to randomly select a proportion of
> them for removal from the matrix, and a proportion for duplication.
> Proportions of columns to be duplicated of deleted are set out in a n by 2
> matrix:
>
> Delete  Duplicate
> 0.99 0.43
> 0.340.32
> 0.540.56
> ….. And so on.
>
> So for each matrix in the list of matrices, I want to:
>
>
>   *   Calculate the number of columns to be deleted or duplicated:
> something like
>  *   number.to.delete <- ncol(matrix list[[I]])*proportionsmatrix[I,1]
>  *   number.to.duplicate <- ncol(matrix
> list[[I]])*proportionsmatrix[I,2]
>   *   Then I want to sample the columns to be deleted, and those to be
> copied : something like:
>  *   which.delete <- sample(ncol(matrix[[I]], number.to.delete,
> replace=F)
>  *   which.duplicate <- sample(ncol(matrix[[I]], number.to.delete,
> replace=F)
>   *   Then I want to make the new matrices: something like:
>  *   new.matrices<- matrix[,-which.delete]
>  *   new.matrices<-cbind(new.matrices, matrix[,which.duplicate]
>
> >From my previous email you'll see I did this by making a function which
> will do this for one matrix out of the entire list, and the applying the
> function to the entire list with lapply. Which works when I copy and paste
> the code into R with usable data, but as part of the simulation it fails.
> This is strange since I do other similar operations on these matrices
> without problem, with the same method of indexing. Debug() and running the
> sim step by step the data does not appear to be altered such that would
> affect the function.
>
> Best,
> Ben.
>
>
>
>
>
> [[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.
>
>

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


Re: [R] Border width on symbols plotted with the lattice package

2013-02-08 Thread ilai
Like this ?
xyplot(4:5~4:5, groups=4:5, lex = 5 ,
par.settings = simpleTheme(cex=10, pch=21, lwd=5),
auto.key=TRUE)



On Fri, Feb 8, 2013 at 6:46 AM, Karl Ove Hufthammer  wrote:

> Dear list members,
>
> I can't figure out how get 'xyplot' or 'dotplot' in the 'lattice' package
> to respect the 'lwd' value for specifying the border with for *symbols*
> (for lines it works fine). Example:
>
> -
> # Base graphics works fine (gives a 'fat’ circle)
> plot(5, cex=10, pch=21, lwd=10)
>
> # But 'xyplot' or 'dotplot' doesn't
> library(lattice)
> xyplot(4:5~4:5, groups=4:5, par.settings = simpleTheme(cex=10, pch=21,
> lwd=5),
> auto.key=TRUE)
> -
>
> For 'xyplot' or 'dotplot' the border stays thin no matter what I set 'lwd'
> to. However, the symbols shown in the *legend* has the 'lwd' correctly
> applied.
>
> How can I fix this? Or is it simply a bug in the 'lattice' package?
>
>
> Karl Ove Hufthammer
>
>
>
> Output of 'sessionInfo()':
>
> R version 2.15.2 (2012-10-26)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=Norwegian-Nynorsk_**Norway.1252
> [2] LC_CTYPE=Norwegian-Nynorsk_**Norway.1252
> [3] LC_MONETARY=Norwegian-Nynorsk_**Norway.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=Norwegian-Nynorsk_**Norway.1252
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
>
> other attached packages:
> [1] lattice_0.20-13
>
> loaded via a namespace (and not attached):
> [1] grid_2.15.2  tools_2.15.2
>
> __**
> 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.
>

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


Re: [R] Border width on symbols plotted with the lattice package

2013-02-08 Thread ilai
On Fri, Feb 8, 2013 at 10:14 AM, David Winsemius wrote:

>
> On Feb 8, 2013, at 8:55 AM, ilai wrote:
>
> > Like this ?
> > xyplot(4:5~4:5, groups=4:5, lex = 5 ,
> > par.settings = simpleTheme(cex=10, pch=21, lwd=5),
> > auto.key=TRUE)
> >
>
> And if I had used a more general search strategy I might have found it,
> too, rather than hacking my way to a less adequate solution; less adequate
> in the sense of no supporting a proper coloring of points.
>
>
> http://markmail.org/search/?q=list%3Aorg.r-project.r-help+xyplot+points++lwd
>
> On the other hand this solution has possibly undesireable effects on the
> key symbols.
>
>
Not sure I follow you, but lex (among others) is described in ?grid::gpar
which indeed may not be pointed to by lattice docs - took the hint from an
old posting myself.



> --
> >
> >
> > On Fri, Feb 8, 2013 at 6:46 AM, Karl Ove Hufthammer 
> wrote:
> >
> >> Dear list members,
> >>
> >> I can't figure out how get 'xyplot' or 'dotplot' in the 'lattice'
> package
> >> to respect the 'lwd' value for specifying the border with for *symbols*
> >> (for lines it works fine). Example:
> >>
> >> -
> >> # Base graphics works fine (gives a 'fat‚ circle)
> >> plot(5, cex=10, pch=21, lwd=10)
> >>
> >> # But 'xyplot' or 'dotplot' doesn't
> >> library(lattice)
> >> xyplot(4:5~4:5, groups=4:5, par.settings = simpleTheme(cex=10, pch=21,
> >> lwd=5),
> >>auto.key=TRUE)
> >> -
> >>
> >> For 'xyplot' or 'dotplot' the border stays thin no matter what I set
> 'lwd'
> >> to. However, the symbols shown in the *legend* has the 'lwd' correctly
> >> applied.
> >>
> >> How can I fix this? Or is it simply a bug in the 'lattice' package?
> >>
> >>
> >> Karl Ove Hufthammer
> >>
> >>
> >>
> >> Output of 'sessionInfo()':
> >>
> >> R version 2.15.2 (2012-10-26)
> >> Platform: x86_64-w64-mingw32/x64 (64-bit)
> >>
> >> locale:
> >> [1] LC_COLLATE=Norwegian-Nynorsk_**Norway.1252
> >> [2] LC_CTYPE=Norwegian-Nynorsk_**Norway.1252
> >> [3] LC_MONETARY=Norwegian-Nynorsk_**Norway.1252
> >> [4] LC_NUMERIC=C
> >> [5] LC_TIME=Norwegian-Nynorsk_**Norway.1252
> >>
> >> attached base packages:
> >> [1] stats graphics  grDevices utils datasets  methods   base
> >>
> >> other attached packages:
> >> [1] lattice_0.20-13
> >>
> >> loaded via a namespace (and not attached):
> >> [1] grid_2.15.2  tools_2.15.2
> >>
> >> __**
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/**listinfo/r-help<
> https://stat.ethz.ch/mailman/listinfo/r-help>
> >> PLEASE do read the posting guide http://www.R-project.org/**
> >> posting-guide.html <http://www.R-project.org/posting-guide.html>
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >
> >   [[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.
>
> David Winsemius
> Alameda, CA, USA
>
>

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


Re: [R] densityplot(~x+y) for vectors of different lengths does what?

2013-02-13 Thread ilai
Hmmm... is this a (unknown or even a) bug ? Not sure this is what OP was
getting at and I haven't gone through the lattice docs to see if this is
mentioned, but, with unequal sizes the extended formula is not producing
what one (or at least I) might expect:

 require(latticeExtra)
set.seed(4321) ; x <- rnorm(20) ; y <- rnorm(10 , 50)
c(dsp <- densityplot( ~ x + y) ,
   densityplot( ~ data , groups = which , make.groups(x, y) ) )

# because
 all.equal(dsp$panel.args[[1]]$x, c(x, y) )
# but regroups ignoring original lengths
summary(dsp$panel.args.common$groups)

An obvious BTW: problem persists using n={19,11} or n = {20,11}

sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
attached base packages:
[1] grDevices utils datasets  stats graphics  methods   base

other attached packages:
[1] nlme_3.1-104latticeExtra_0.6-24 RColorBrewer_1.0-5
[4] lattice_0.20-10


On Wed, Feb 13, 2013 at 6:38 AM, Michael Stob  wrote:

> densityplot(~x+y) does what I expect it to do if x and y have equal
> length.  I know how to get what I want if x and y have different lengths.
> But what is this actually doing if x and y have different lengths?The
> relevant example is
>
> x=rnorm(10)
> y=rnorm(50,1)
> densityplot(~x+y)
>
>
>
> __
> 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.
>
>

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


Re: [R] 3D Histograms on a Geographical Map

2013-04-19 Thread ilai
Also combining the code for figures 6.5, 13.8 and 13.9 in the following link
http://lmdvr.r-forge.r-project.org/figures/figures.html
gets you there.



On Fri, Apr 19, 2013 at 8:38 AM, Barry Rowlingson <
b.rowling...@lancaster.ac.uk> wrote:

> On Fri, Apr 19, 2013 at 3:13 PM, Lorenzo Isella
>  wrote:
> > Dear All,
> > I like very much figure 2.a) and 2.b) of this paper
> >
> > http://www.nature.com/srep/2013/130410/srep01640/pdf/srep01640.pdf
> >
> >
> > and I probably need a similar visualization.
> > Is anything like that doable in R? I have some experience with R and
> > gadm (gadm.org), but that is only to produce maps colored according to
> > a scalar.
> > I do not know how to visualize maps with a "perspective", let alone
> > adding the histograms in 3D.
> > Sorry for not providing an example script, but if I had one I would
> > not be posting at all.
>
>  The panel B maps are "created by using R" so they are definitely
> doable in R. I suspect they are using the rgl package for 3d graphics.
> You just have to get the country outline data, give it a Z of 0, draw
> it using the rgl 3d line functions, then add the bars (they're not
> histograms) by starting at (x,y,0) and drawing a 3d line to (x,y,H)
> for each value of H.
>
>  You might try asking on R-sig-geo for more on mapping stuff with R.
>
>  Clearly my papers don't have enough 3d nonsense graphics to get into
> Nature...
>
> Barry
>
> __
> 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.
>

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


Re: [R] query in plot(intervals....

2013-05-14 Thread ilai
On Tue, May 14, 2013 at 10:05 AM, Michelle Morters
wrote:

> Hi -
>
> I would like the plot ordered by intercept.
>

One way will be to tweak the ?intervals.lmList object

require(nlme)
fm1 <- intervals(lmList(distance ~ age | Subject, Orthodont))
fm2 <- fm1[order(fm1[,2,1]),,]
class(fm2) <- class(fm1)
plot(fm2)

 Next time please, *you* provide the reproducible example...



> Ordering is doable if the intervals function is substituted with the
> confint function and order=1 included. Is ordering doable with intervals
> function, please?
>
> Thanks!
>
> M
>
> results<-lmList(x~slope|id,data)
>
> plot(intervals(results))
>
>
> [[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.
>

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


Re: [R] highlight points in lattice cloud plot

2013-05-29 Thread ilai
On Wed, May 29, 2013 at 7:57 AM, Stefan Lüdtke wrote:

>
> x=runif(100, 1, 2)
> y=runif(100, 2, 4)
> z=runif(100, 1, 4)
>
> data_xyz=as.data.frame(cbind(x, y, z, a=rep(c(1:10), 10), b=rep(c(1:2),
> each=50)))
>
> custom.panel = function(x, y, z, subscripts, ...)
> {
> highlight=(data_xyz$a == 1)
>  highlight.panel = highlight[subscripts]
>
> panel.cloud(x[highlight.panel], y[!highlight.panel], z[!highlight.panel],
>  type='p', pch=18)
> panel.cloud(x[highlight.panel], y[highlight.panel], z[highlight.panel],
>  type='b', col="tomato3")
> }
>
>
If you >args(panel.cloud) or ?panel.cloud you'll notice the order is "x , y
, subscripts , z ,..." *not* x,y,z, hence the error message "z not found"
or something to that effect you should have been getting. In any case
you're code is IMHO a little clunky with groups=TRUE and a panel function
just to get the groups condition. Would something like this do the  job?

cloud(z~x*y|b, groups=factor(a==1), data=data_xyz, pch=c(1,19), type='b',
par.settings=list(superpose.line=list(col=c(0,"#ff00ff"



> #that works of course
> cloud(z~x*y|b, data=data_xyz)
>
> #that not
> cloud(z~x*y|b, data=data_xyz, groups=TRUE,
> panel=custom.panel)
>
>
> ##
>
> On 05/29/2013 03:36 PM, John Kane wrote:
> > No attachment.  The R-help list tendst to strip out many type of
> attached files though pdf and txt , among others get through.
> >
> > It is better to supply the example in the email itself if possible. Have
> a look at https://github.com/hadley/devtools/wiki/Reproducibility for
> suggestions.
> >
> > John Kane
> > Kingston ON Canada
> >
> >
> >> -Original Message-
> >> From: slued...@gfz-potsdam.de
> >> Sent: Tue, 28 May 2013 15:50:33 -0700 (PDT)
> >> To: r-help@r-project.org
> >> Subject: [R] highlight points in lattice cloud plot
> >>
> >> Dear list,
> >>
> >> I am
> >>   struggling with the following problem.
> >>
> >> In a 2d case I managed to highlight a subset of points  through the
> >> panel.xyplot function.
> >>
> >> However, I was trying the same in 3d using panel.cloud, but now luck.
> >>
> >> I attached a minimal example, I think the first plot shows the idea.
> >>
> >> Thanks,
> >>
> >> Stefan
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://r.789695.n4.nabble.com/highlight-points-in-lattice-cloud-plot-tp4668157.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.
> > 
> > FREE ONLINE PHOTOSHARING - Share your photos online with your friends
> and family!
> > Visit http://www.inbox.com/photosharing to find out more!
> >
> >
>
>
> [[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.
>

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


Re: [R] Optim seems not to work properly in foreach

2013-06-03 Thread ilai
On Mon, Jun 3, 2013 at 11:37 AM, Simon Zehnder 

... [Some not minimal, self contained, reproducible code]...


> Data simulation and thecreation of startpar works fine, but the parameters
> in res$par are always the start parameters. If I run the same commands
> directly on the shell I get in res$par the optimized parameters - only
> inside the foreach loop optim seems not to work. What could that be?
>
> Don't know, but but this makes me doubt it has anything to do with optim
being inside foreach:

fr <- function(x) {
 x1 <- x[1] ; x2 <- x[2]
 100 * (x2 - x1 * x1)^2 + (1 - x1)^2
 }
grr <- function(x) {
 x1 <- x[1] ; x2 <- x[2]
 c(-400 * x1 * (x2 - x1 * x1) - 2 * (1 - x1) , 200 * (x2 - x1 * x1))
 }
library("doMC")
registerDoMC(2)
RNGkind("L'Ecuyer")
set.seed(54321)
foreach(i = 1:2) %do% {
  ret <- foreach(j = 1:2) %do%{
   strtpar <- c(-2,2)+rnorm(2)
   optim(strtpar, fr, grr, method =
"L-BFGS-B",control=list(trace=TRUE))$par
  }
  ret
}

Also, wouldn't you want to register 4 cores by default if nesting 2 loops
of 2 ? (to comment on the wisdom of doing so in terms of overhead is beyond
my expertise)

HTH



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

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


Re: [R] corrgram with two datasets

2013-06-27 Thread ilai
?pairs


On Thu, Jun 27, 2013 at 2:48 AM, Meesters, Aesku.Kipp Institute <
meest...@aesku-kipp.com> wrote:

> Hi,
>
> I would like to display inter-parameter scatter plots like those with the
> corrgram package (see upper triangle here:
> http://www.statmethods.net/advgraphs/images/corrgram2.png ), just that I
> would like to plot two datasets instead of one. Say one with black and one
> with red dots. Or a merged dataset where an indicator column is used to
> assign different colors to particular dots - with still the same layout.
>
> Is there a method to generate such a plots around?
>
> TIA
> Christian
>
> [[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.
>

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


Re: [R] Simple Question About Exporting Back to Excel

2012-09-26 Thread ilai
On Wed, Sep 26, 2012 at 3:11 PM, RCar wrote:

> All,
> Relatively new R user so this is probably an easy question to answer.
> I am able to generate a cluster for my dataset using hclust() then ploting
> the data with plot().
> This results in an image with a dendrogram with my sample names along the
> bottom.  Great!
> However, I now need a way to get that sample order from the image into
> excel.
>

Why? What does the order of labels in a dendrogram mean ?
But if you insist

hc <- hclust(dist(USArrests), "ave")
plot(hc)
str(hc)
hc$labels[hc$order]

?write.table



> i.e. sample 7 was on the far left, sample 19 was in position 2, sample 93
> was in position 3, etc.
> As of now the only way for me to do this is to manually type the samples
> from the image into a worksheet.
> Very time consuming as I've got a couple hundred samples and several
> different dendrograms!
> Any thoughts?
>
> Thanks so much!
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Simple-Question-About-Exporting-Back-to-Excel-tp4644296.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.
>

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


Re: [R] changing outlier shapes of boxplots using lattice

2012-09-28 Thread ilai
On Fri, Sep 28, 2012 at 6:57 AM, Richard M. Heiberger wrote:

> Elaine,
>
> For panel.bwplot you see that the central dot and the outlier dots are
> controlled by
> the same pch argument.


??? I don't think so...

bwplot(rgamma(20,.1,1)~gl(2,10), pch=rep(17,2),
panel = lattice::panel.bwplot)

I think you mean panel.bwplot.intermidiate.hh ?

BTW thank you for the useful HH package but in this case OP is using it
with no "at" argument, so why not

Diet.colors <- c("forestgreen", "darkgreen","chocolate1","darkorange2",
"sienna2","red2","firebrick3","saddlebrown","coral4","chocolate4","darkblue","navy","grey38")
 bwplot(rgamma(20*13,1,.1)~gl(13,20),
  fill = Diet.colors, pch = "|",
  par.settings = list(box.umbrella=list(lty=1)))

cheers



I initially set the pch="|" to match your first
> example with the horizontal
> indicator for the median.  I would be inclined to use the default circle
> for the outliers and
> therefore also for the median.
>
> Rich
>
> On Fri, Sep 28, 2012 at 7:13 AM, Sarah Goslee  >wrote:
>
> > I would guess that if you find the bit that says pch="|" and change it to
> > pch=1 it will solve your question, and that reading ?par will tell you
> why.
> >
> > Sarah
> >
> > On Thursday, September 27, 2012, Elaine Kuo wrote:
> >
> > > Hello
> > >
> > > This is Elaine.
> > >
> > > I am using package lattice to generate boxplots.
> > > Using Richard's code, the display was almost perfect except the outlier
> > > shape.
> > > Based on the following code, the outliers are vertical lines.
> > > However, I want the outliers to be empty circles.
> > > Please kindly help how to modify the code to change the outlier shapes.
> > > Thank you.
> > >
> > > code
> > > package (lattice)
> > >
> > > dataN <- data.frame(GE_distance=rnorm(260),
> > >
> > > Diet_B=factor(rep(1:13, each=20)))
> > >
> > > Diet.colors <- c("forestgreen", "darkgreen","chocolate1","darkorange2",
> > >
> > >  "sienna2","red2","firebrick3","saddlebrown","coral4",
> > >
> > >  "chocolate4","darkblue","navy","grey38")
> > >
> > > levels(dataN$Diet_B) <- Diet.colors
> > >
> > > bwplot(GE_distance ~ Diet_B, data=dataN,
> > >
> > >xlab=list("Diet of Breeding Ground", cex = 1.4),
> > >
> > >ylab = list(
> > >
> > >  "Distance between Centers of B and NB Range (1000 km)",
> > >
> > >  cex = 1.4),
> > >
> > >panel=panel.bwplot.intermediate.hh,
> > >
> > >col=Diet.colors,
> > >
> > >pch=rep("|",13),
> > >
> > >scales=list(x=list(rot=90)),
> > >
> > >par.settings=list(box.umbrella=list(lty=1)))
> > >
> > > [[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.
> > >
> >
> >
> > --
> > Sarah Goslee
> > http://www.stringpage.com
> > http://www.sarahgoslee.com
> > http://www.functionaldiversity.org
> >
> > [[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.
> >
>
> [[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.
>

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


Re: [R] changing outlier shapes of boxplots using lattice

2012-09-29 Thread ilai
On Fri, Sep 28, 2012 at 11:03 PM, Elaine Kuo wrote:

> Hello
>
> Thanks again.
>
> I got the attached graph
> Unsure why the color is still inconsistent.
> Please kindly share with your R version.
>

It is not my version you need to worry about, but your own...
Post the following outputs (without the prompt):

> sessionInfo()
> str(dataN)
> The complete code you run on a vanilla session (at this point I can only
guess you changed mine somehow)
> dput(dataN)

That will be better than having me or anyone in R-help play "guess how I
got this plot".





> Also, I want to add one line in the command.
> levels(dataN$Diet_B) <- diet.code
> diet.code <- c("Herbivore_t", "Herbivore_w", "Nectivore", "Frugivore",
> "Granivore",
> "Scavenger", "Carnivore",
> "Insectivore_t", "Insectivore_w", "Insectivore_a",
> "Molluscivore", "Crustacean feeder", "Omnivore")
>
> Please kindly help how to make the levels vertical instead of horizontal.
>
> Elaine
>
> On Sat, Sep 29, 2012 at 12:28 PM, ilai  wrote:
>
>> Not sure why this is going wrong for you.
>> Copy paste AS IS the following to your console in the directory
>> containing for_lattice.csv
>>
>> str(dataN <- read.csv('for_lattice.csv')[,2:3])
>> dataN$Diet_B <- factor(dataN$Diet_B)
>>
>> Diet.colors <- c("forestgreen", "darkgreen","chocolate1","darkorange2",
>> "sienna2","red2","firebrick3","saddlebrown","coral4","chocolate4","darkblue","navy","grey38")
>>  require(lattice)
>> bwplot(MS_midpoint_lat~Diet_B,dataN,pch='|',
>> par.settings = list(
>> plot.symbol =list(col = rep(Diet.colors,c(1,0,0,1,0,0,3,6,1,0,2,0,1)) ),
>> box.dot =list(col=Diet.colors),
>> box.rectangle=list(col=Diet.colors),
>> box.umbrella=list(lty=1,col=Diet.colors)))
>>
>> Are you seeing this ?
>>
>>
>>
>> On Fri, Sep 28, 2012 at 7:06 PM, Elaine Kuo wrote:
>>
>>> Hello
>>>
>>> Thanks for the quick response.
>>>
>>> For your code,
>>> the result is attached Q1.
>>>
>>> Please kindly help with the same color of box line and whisker just like
>>> box 1 of green.
>>>
>>> I attached my data and plot result (Q2).
>>> Please kindly help change the median from "I" to "-."
>>>
>>> Thanks a lot.
>>>
>>> Elaine
>>>
>>>
>>> On Sat, Sep 29, 2012 at 8:21 AM, ilai  wrote:
>>>
>>>> Me again...
>>>> Sorry I just noticed you did provide reproducible code in your
>>>> original. To get your plot:
>>>>
>>>> require(lattice)
>>>> set.seed(5)
>>>>
>>>> Diet.colors <- c("forestgreen", "darkgreen","chocolate1","darkorange2",
>>>> "sienna2","red2","firebrick3","saddlebrown","coral4","chocolate4","darkblue","navy","grey38")
>>>>  bwplot(rgamma(20*13,1,.1)~gl(13,20), pch = "|",
>>>> par.settings = list(
>>>> plot.symbol =list(col = rep(Diet.colors,c(0,1,1,3,1,0,3,0,0,1,1,1,0)) ),
>>>> box.dot =list(col=Diet.colors),
>>>> box.rectangle=list(col=Diet.colors),
>>>> box.umbrella=list(lty=1,col=Diet.colors)))
>>>>
>>>> The box arguments set the box parameters (lty,col etc.) but the
>>>> plot.symbol sets the outliers parameters (again pch, col etc.). Note the
>>>> rep vector! it is because box 1 doesn't have an outlier, but box 4 has 3.
>>>> You will need to construct it based on your real data or the colors will be
>>>> off.
>>>>
>>>> Cheers
>>>>
>>>>
>>>> On Fri, Sep 28, 2012 at 5:55 PM, ilai  wrote:
>>>>
>>>>>
>>>>> On Fri, Sep 28, 2012 at 4:17 PM, Elaine Kuo 
>>>>> wrote:
>>>>>
>>>>>> Hello Ilai,
>>>>>>
>>>>>> Thank you for the response.
>>>>>> It did help a lot.
>>>>>>
>>>>>> However, a beginner to lattice has three questions.
>>>>>>
>>>>>> Q1
>>>>>>
>>>>>> Please kindly explain why "in this case OP i

Re: [R] changing outlier shapes of boxplots using lattice

2012-09-29 Thread ilai
On Sat, Sep 29, 2012 at 7:32 AM, ilai  wrote:

> On Fri, Sep 28, 2012 at 11:03 PM, Elaine Kuo wrote:
>
>> Hello
>>
>> Thanks again.
>>
>> I got the attached graph
>> Unsure why the color is still inconsistent.
>> Please kindly share with your R version.
>>
>
> It is not my version you need to worry about, but your own...
> Post the following outputs (without the prompt):
>
> > sessionInfo()
>
> ls(pat = 'bwplot' )

> > str(dataN)
> > The complete code you run on a vanilla session (at this point I can only
> guess you changed mine somehow)
> > dput(dataN)
>
> That will be better than having me or anyone in R-help play "guess how I
> got this plot".
>
>
>
>
>
>> Also, I want to add one line in the command.
>> levels(dataN$Diet_B) <- diet.code
>> diet.code <- c("Herbivore_t", "Herbivore_w", "Nectivore", "Frugivore",
>> "Granivore",
>> "Scavenger", "Carnivore",
>> "Insectivore_t", "Insectivore_w", "Insectivore_a",
>> "Molluscivore", "Crustacean feeder", "Omnivore")
>>
>> Please kindly help how to make the levels vertical instead of horizontal.
>>
>> Elaine
>>
>> On Sat, Sep 29, 2012 at 12:28 PM, ilai  wrote:
>>
>>> Not sure why this is going wrong for you.
>>> Copy paste AS IS the following to your console in the directory
>>> containing for_lattice.csv
>>>
>>> str(dataN <- read.csv('for_lattice.csv')[,2:3])
>>> dataN$Diet_B <- factor(dataN$Diet_B)
>>>
>>> Diet.colors <- c("forestgreen", "darkgreen","chocolate1","darkorange2",
>>> "sienna2","red2","firebrick3","saddlebrown","coral4","chocolate4","darkblue","navy","grey38")
>>>  require(lattice)
>>> bwplot(MS_midpoint_lat~Diet_B,dataN,pch='|',
>>> par.settings = list(
>>> plot.symbol =list(col = rep(Diet.colors,c(1,0,0,1,0,0,3,6,1,0,2,0,1)) ),
>>> box.dot =list(col=Diet.colors),
>>> box.rectangle=list(col=Diet.colors),
>>> box.umbrella=list(lty=1,col=Diet.colors)))
>>>
>>> Are you seeing this ?
>>>
>>>
>>>
>>> On Fri, Sep 28, 2012 at 7:06 PM, Elaine Kuo wrote:
>>>
>>>> Hello
>>>>
>>>> Thanks for the quick response.
>>>>
>>>> For your code,
>>>> the result is attached Q1.
>>>>
>>>> Please kindly help with the same color of box line and whisker just
>>>> like box 1 of green.
>>>>
>>>> I attached my data and plot result (Q2).
>>>> Please kindly help change the median from "I" to "-."
>>>>
>>>> Thanks a lot.
>>>>
>>>> Elaine
>>>>
>>>>
>>>> On Sat, Sep 29, 2012 at 8:21 AM, ilai  wrote:
>>>>
>>>>> Me again...
>>>>> Sorry I just noticed you did provide reproducible code in your
>>>>> original. To get your plot:
>>>>>
>>>>> require(lattice)
>>>>> set.seed(5)
>>>>>
>>>>> Diet.colors <- c("forestgreen",
>>>>> "darkgreen","chocolate1","darkorange2",
>>>>> "sienna2","red2","firebrick3","saddlebrown","coral4","chocolate4","darkblue","navy","grey38")
>>>>>  bwplot(rgamma(20*13,1,.1)~gl(13,20), pch = "|",
>>>>> par.settings = list(
>>>>> plot.symbol =list(col = rep(Diet.colors,c(0,1,1,3,1,0,3,0,0,1,1,1,0))
>>>>> ),
>>>>> box.dot =list(col=Diet.colors),
>>>>> box.rectangle=list(col=Diet.colors),
>>>>> box.umbrella=list(lty=1,col=Diet.colors)))
>>>>>
>>>>> The box arguments set the box parameters (lty,col etc.) but the
>>>>> plot.symbol sets the outliers parameters (again pch, col etc.). Note the
>>>>> rep vector! it is because box 1 doesn't have an outlier, but box 4 has 3.
>>>>> You will need to construct it based on your real data or the colors will 
>>>>> be
>>>>> off.
>>>>>
>>>>> Cheers
>>>>>
>>>>>
>>>>> On Fri, 

Re: [R] Coda, HPDinterval and multiple chains

2012-10-04 Thread ilai
How about

require(coda)
data(line)
str(line)
cline <- as.mcmc(do.call(rbind,line))
str(cline)

# Thus
HPDinterval(cline) # (or any FUN.mcmc)
sum(cline[,'alpha'] >= median(cline[,'alpha']))/nrow(cline)

Cheers

On Thu, Oct 4, 2012 at 12:22 PM, NORRIS Paul  wrote:

> Dear all,
>
> I'm not 100% sure if this question is best directed at the r-list, or a
> mailing list concerned with Bayesian analysis, so please accept my
> apologies if another audience may be more appropriate.
>
> I have been using the rjags package to run Jags models with multiple
> chains and store the results in a Coda based mcmc list.  For instance,
> having created a jags model and done initial adapting and updating, I run
> the following command:
>
> coda_odp_gini_only <- coda.samples(odp_gini_only,
>variable.names=c("beta","sigma2.u2",
> "deviance"),
>n.iter=itercount, thin=thincount)
>
> This create an object with 4 separate chains as requested in my initial
> call to Jags which created the object "odp_gini_only".  I then use the
>  Coda package to look at the results stored in "coda_odp_gini_only".  Prior
> to running any analysis with Coda, I used the command,
>
> coda.options(combine.plots=TRUE, combine.stats=TRUE)
>
> to ask for results that combine the four separate chains.  Sure enough, if
> I enter "summary(coda_odp_gini_only)", I am given a single set of output
> combining the four chains.  However, if I enter
> "HPDinterval(coda_odp_gini_only)" I receive 4 sets of HPD figures, one for
> each chain.  Is it possible to combine the four chains together to receive
> a single set of HPD estimates?
>
> In a similar vein, is it possible to use the Coda object to estimate the
> proportion of a given parameters distribution which is above (or below) a
> given value, for instance, the proportion of the distribution of beta[1]
> greater than zero?  Again, in doing so, is it possible to combine the
> results of the four chains into a single estimate?
>
> Kind regards, and many thanks in advance for any advice anyone can offer
> me.
>
> Paul
> Dr Paul Norris
> Lecturer in Social Policy
> University of Edinburgh
> --
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
>
> __
> 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.
>

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


Re: [R] how to convert by lists in data.frames

2012-10-09 Thread ilai
On Tue, Oct 9, 2012 at 11:42 AM, Rui Barradas  wrote:

> Hello,
>
> Try
>
> do.call(data.frame, by.list)
>
>
I don't think data.frame inside do.call works in this context. May need it
on the outside to do the job (Only OK here since there is no mixture of
numeric and character/factors in this summary). Something like

by.list <- by(warpbreaks[, 1], warpbreaks[, -1], summary)
by.dtfrm <- data.frame( do.call( rbind, by.list ) )
by.dtfrm <- cbind( do.call( expand.grid, attr( by.list, 'dimnames' ) ),
by.dtfrm )




Hope this helps,
>
> Rui Barradas
> Em 09-10-2012 17:53, Jesus Frias escreveu:
> > Dear R-helpers,
> >
> >
> >
> > I've got a summary of results from a by() call that I am making with a
> list
> > of more than two of factors not very different from the example in the
> by()
> > help page
> >
> >
> >
> > require(stats)
> >
> > by(warpbreaks[, 1],   warpbreaks[, -1],   summary)
> >
> >
> >
> > The result of the command gives a list of the form
> >
> >
> >
> > wool: A
> > tension: L
> > Min. 1st Qu.  MedianMean 3rd Qu.Max.
> >25.00   26.00   51.00   44.56   54.00   70.00
> > ---
> > wool: B
> > tension: L
> > Min. 1st Qu.  MedianMean 3rd Qu.Max.
> >14.00   20.00   29.00   28.22   31.00   44.00
> > ---
> >
> >  And so on.
> >
> >
> >
> >
> >
> > I would like to convert this result in to a flat data.frame with variable
> > names:
> >
> >
> >
> > Wool, Tension, Min, 1stQ, Median, Mean, 3rdQ, Max
> >
> > A, L , 25.00   26.00   51.00   44.56   54.00   70.00
> > B,  L, 14.00   20.00   29.00   28.22   31.00   44.00
> >
> > 
> >
> >
> >
> >
> >
> > Although I've tried the argument "simplify=T" I haven't been able to get
> > this converted.
> >
> >
> >
> > Is there a simple way to achieve this?
> >
> >
> >
> > Thanks in advance!
> >
> >
> >
> > Regards,
> >
> >
> >
> > Jesus
> >
> >
> >
> > Jesús María Frías Celayeta, PhD
> >
> > Ceann Cúntóir, Scoil Eolaíocht an Bhia agus Sláinte an Chomhshaoil
> >
> > Assistant Head, School of Food Science and Environmental Health,
> >
> > Coláiste Eolaíochtaí agus Sláinte/ College of Sciences and Health,
> >
> > Institiúid Teicneolaíochta Átha Cliath/ Dublin Institute of Technology,
> >
> > Sráid Chathal Brugha, Baile Átha Cliath 1, Éire/Cathal Brugha Street,
> Dublin
> > 1, Ireland
> >
> > F: +353-1-4024459
> >
> > E:   jesus.fr...@dit.ie
> >
> > W: http://fseh.dit.ie/o4/StaffListing/JesusFrias.html
> >
> >
> >
> >
> >
> >
> >
> > Tá an teachtaireacht seo scanta ó thaobh ábhar agus víreas ag Seirbhís
> Scanta Ríomhphost de chuid Seirbhísí Faisnéise, ITBÁC agus meastar í a
> bheith slán.  http://www.dit.ie
> >
> > This message has been scanned for content and viruses by the DIT
> Information Services E-Mail Scanning Service, and is believed to be clean.
> http://www.dit.ie
> >
> >
> >   [[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.
>
>
> [[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.
>
>

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


Re: [R] how to convert by lists in data.frames

2012-10-09 Thread ilai
On Tue, Oct 9, 2012 at 12:25 PM, Bert Gunter  wrote:

>
> The only wrinkle here (with either rbind or simplify2array) is getting
> the labels correct if the design is not fully crossed -- i.e. if some
> groups are missing so that expand.grid() won't work. Then you might
> have to work harder to extract the information from by.list.
>

Agreed. In such a case I might decide to let

 aggregate(breaks~wool+tension, subset(warpbreaks, wool != 'A' | tension !=
'H' ), summary)

sort through the headache for me, and overlook the annoying "result is
actually a matrix put in as a single variable in the data.frame". Personal
preference maybe but that never made sense to me in the data frame
construct (even if it is just a list).
Cheers


> > str(by.list)
>
> might help here.
>
> -- Bert
>
> On Tue, Oct 9, 2012 at 11:14 AM, ilai  wrote:
> > On Tue, Oct 9, 2012 at 11:42 AM, Rui Barradas 
> wrote:
> >
> >> Hello,
> >>
> >> Try
> >>
> >> do.call(data.frame, by.list)
> >>
> >>
> > I don't think data.frame inside do.call works in this context. May need
> it
> > on the outside to do the job (Only OK here since there is no mixture of
> > numeric and character/factors in this summary). Something like
> >
> > by.list <- by(warpbreaks[, 1], warpbreaks[, -1], summary)
> > by.dtfrm <- data.frame( do.call( rbind, by.list ) )
> > by.dtfrm <- cbind( do.call( expand.grid, attr( by.list, 'dimnames' ) ),
> > by.dtfrm )
> >
> >
> >
> >
> > Hope this helps,
> >>
> >> Rui Barradas
> >> Em 09-10-2012 17:53, Jesus Frias escreveu:
> >> > Dear R-helpers,
> >> >
> >> >
> >> >
> >> > I've got a summary of results from a by() call that I am making with a
> >> list
> >> > of more than two of factors not very different from the example in the
> >> by()
> >> > help page
> >> >
> >> >
> >> >
> >> > require(stats)
> >> >
> >> > by(warpbreaks[, 1],   warpbreaks[, -1],   summary)
> >> >
> >> >
> >> >
> >> > The result of the command gives a list of the form
> >> >
> >> >
> >> >
> >> > wool: A
> >> > tension: L
> >> > Min. 1st Qu.  MedianMean 3rd Qu.Max.
> >> >25.00   26.00   51.00   44.56   54.00   70.00
> >> > ---
> >> > wool: B
> >> > tension: L
> >> > Min. 1st Qu.  MedianMean 3rd Qu.Max.
> >> >14.00   20.00   29.00   28.22   31.00   44.00
> >> > ---
> >> >
> >> >  And so on.
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > I would like to convert this result in to a flat data.frame with
> variable
> >> > names:
> >> >
> >> >
> >> >
> >> > Wool, Tension, Min, 1stQ, Median, Mean, 3rdQ, Max
> >> >
> >> > A, L , 25.00   26.00   51.00   44.56   54.00   70.00
> >> > B,  L, 14.00   20.00   29.00   28.22   31.00   44.00
> >> >
> >> > 
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > Although I've tried the argument "simplify=T" I haven't been able to
> get
> >> > this converted.
> >> >
> >> >
> >> >
> >> > Is there a simple way to achieve this?
> >> >
> >> >
> >> >
> >> > Thanks in advance!
> >> >
> >> >
> >> >
> >> > Regards,
> >> >
> >> >
> >> >
> >> > Jesus
> >> >
> >> >
> >> >
> >> > Jesús María Frías Celayeta, PhD
> >> >
> >> > Ceann Cúntóir, Scoil Eolaíocht an Bhia agus Sláinte an Chomhshaoil
> >> >
> >> > Assistant Head, School of Food Science and Environmental Health,
> >> >
> >> > Coláiste Eolaíochtaí agus Sláinte/ College of Sciences and Health,
> >> >
> >> > Institiúid Teicneolaíochta Átha Cliath/ Dublin Institute of
> Technology,
> >> >
> >> > Sráid Chathal Brugha, Baile Átha Cliath 1, Éire/Cathal Brugha Street,
> >> Dublin
> >> > 1, Ireland
> >> >

Re: [R] plot.new() and grid functions in multipage pdfs

2012-10-09 Thread ilai
On Tue, Oct 9, 2012 at 1:26 PM, Ali Tofigh  wrote:

> Hi,
>
> when using the grid package, I've come across this weird behaviour
>
> pdf("test.pdf"); plot.new(); grid.rect(gp = gpar(fill="blue"));
> plot.new();  grid.rect(gp = gpar(fill="blue")); dev.off()
>
> The first page is filled completely with a blue rectangle, but in the
> second page, the margins clip the rectangle. This is causing me
> considerable headache, as I rely on many grid functions for plotting.
> This seems like a bug to me, or is there something about the behaviour
> of plot.new() and/or grid functions that I don't understand?
>

Why would you expect plot.new from base graphics to play nice with grid ?
if you like/use grid graphics, stay in that world:

pdf("test.pdf");
grid.rect(gp = gpar(fill="blue"));
grid.newpage();
grid.rect(gp = gpar(fill="blue"));
dev.off()





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

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


Re: [R] Filling points in a trellis object

2012-10-10 Thread ilai
On Wed, Oct 10, 2012 at 4:56 AM, Pierrick Bruneau wrote:

> With the following code :
>
> dat1 <- matrix(nrow=4, ncol=2)
> dat1[1,] <- c(-2, 1)
> dat1[2,] <- c(-1.7, 0.9)
> dat1[3,] <- c(0.1, 0.6)
> dat1[4,] <- c(0.5, 0.5)
> theplot <- xyplot(V2 ~ V1, as.data.frame(dat1), pch=c(4,1,5,4))
> plot(theplot, prefix="theplot") # for a predictable name
> grid.edit("theplot.xyplot.points.panel.1.1", gp=gpar(lwd=c(2,2,2,2),
> cex=c(2,3,3,2),
>   col=1, fill=c("transparent", "grey", "grey", "transparent")))
>
>
> I would like to plot 4 points, and have the circle and diamond shapes
> filledwith grey. What am I missing ?
>
> The correct pch+col (fill is for polygons) specification. Try

theplot <- xyplot(V2 ~ V1, as.data.frame(dat1), pch = c(4,19,18,4) , col =
c(1,'grey35','grey65',1) )
plot(theplot, prefix="theplot") # for a predictable name
grid.edit("theplot.xyplot.points.panel.1.1", gp = gpar( lwd = c(2,2,2,2) ,
cex = c(2,3,3,2) ) )

BTW in R you don't need to declare objects, i.e.

dat1 <- matrix(c(-2,-1.7,0.1,0.5,1,.9,.6,.5), nrow=4, ncol=2)

works just as well (or IMHO better).
Similarly, your plot can be generated in one "go", no need to plot => edit,
just put in the right args to begin with.

HTH




Thanks by advance for your help,
> Pierrick Bruneau
> Research Fellow
> CRP Gabriel Lippmann
>
> [[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.
>

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


Re: [R] Filling points in a trellis object

2012-10-10 Thread ilai
On Wed, Oct 10, 2012 at 4:56 AM, Pierrick Bruneau wrote:

> With the following code :
>
> dat1 <- matrix(nrow=4, ncol=2)
> dat1[1,] <- c(-2, 1)
> dat1[2,] <- c(-1.7, 0.9)
> dat1[3,] <- c(0.1, 0.6)
> dat1[4,] <- c(0.5, 0.5)
> theplot <- xyplot(V2 ~ V1, as.data.frame(dat1), pch=c(4,1,5,4))
> plot(theplot, prefix="theplot") # for a predictable name
> grid.edit("theplot.xyplot.points.panel.1.1", gp=gpar(lwd=c(2,2,2,2),
> cex=c(2,3,3,2),
>   col=1, fill=c("transparent", "grey", "grey", "transparent")))
>
>
> I would like to plot 4 points, and have the circle and diamond shapes
> filledwith grey. What am I missing ?
>
> The correct pch+col (fill is for polygons) specification. Try

theplot <- xyplot(V2 ~ V1, as.data.frame(dat1), pch = c(4,19,18,4) , col =
c(1,'grey35','grey65',1) )
plot(theplot, prefix="theplot") # for a predictable name
grid.edit("theplot.xyplot.points.panel.1.1", gp = gpar( lwd = c(2,2,2,2) ,
cex = c(2,3,3,2) ) )

BTW in R you don't need to declare objects, i.e.

dat1 <- matrix(c(-2,-1.7,0.1,0.5,1,.9,.6,.5), nrow=4, ncol=2)

works just as well (or IMHO better).
Similarly, your plot can be generated in one "go", no need to plot => edit,
just put in the right args to begin with.

HTH




Thanks by advance for your help,
> Pierrick Bruneau
> Research Fellow
> CRP Gabriel Lippmann
>
> [[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.
>

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


Re: [R] plot.new() and grid functions in multipage pdfs

2012-10-17 Thread ilai
On Wed, Oct 17, 2012 at 11:10 AM, Ali Tofigh  wrote:

> my problem is that I usually have no choice but to mix grid and base
> graphics.


What does that have to do with the answer you got ? did you even try it ?
here it is (again) but this time mixing base+grid:

require(gridBase)
pdf("test.pdf")
grid.rect(gp = gpar(fill="blue"))
grid.newpage()
grid.rect(gp=gpar(fill='blue'))
# mix in base+grid. adapted from ?gridPAR in gridBase
par(fig=gridFIG(), new=TRUE)
 plot(1:10)
# plot.new()  # uncomment to see it's unnecessary
plot(1:10)
 pushViewport(viewport(width=0.5, height=0.5)) ;
grid.rect(gp=gpar(col="grey", lwd=2))
plot(rnorm(10))
grid.newpage()
grid.rect(gp=gpar(fill='blue'))
dev.off()


> I use grid as much as possible, but for example for plotting
> dendrograms, I don't know how to plot them other than using base
> graphics. So I use the functions in gridBase to produce those plots.
>

Then you may have noticed the dendrogram examples in the gridBase docs
don't use plot.new() either but use lattice for the layout.


In order to do that I have to call plot.new() at some point in my code
> to initialize the base graphics, and that can mess things up.
>


> No. See example above or provide a minimal reproducible example that does
> require it.
>



> /ali
>
>
> On Tue, Oct 9, 2012 at 4:00 PM, Greg Snow <538...@gmail.com> wrote:
> > The plot.new function is for base graphics and base and grid graphics
> > don't usually play well together.  You probably want to use
> > grid.newpage function instead.
> >
> > On Tue, Oct 9, 2012 at 1:26 PM, Ali Tofigh 
> wrote:
> >> Hi,
> >>
> >> when using the grid package, I've come across this weird behaviour
> >> where a call to plot.new() will start a new page for a multi-page pdf,
> >> but then the margins will somehow behave strangely for all but the
> >> first page: here is some code:
> >>
> >> pdf("test.pdf"); plot.new(); grid.rect(gp = gpar(fill="blue"));
> >> plot.new();  grid.rect(gp = gpar(fill="blue")); dev.off()
> >>
> >> The first page is filled completely with a blue rectangle, but in the
> >> second page, the margins clip the rectangle. This is causing me
> >> considerable headache, as I rely on many grid functions for plotting.
> >> This seems like a bug to me, or is there something about the behaviour
> >> of plot.new() and/or grid functions that I don't understand?
> >>
> >> /Ali
> >>
> >> __
> >> 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.
> >
> >
> >
> > --
> > Gregory (Greg) L. Snow Ph.D.
> > 538...@gmail.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.
>

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


Re: [R] plot.new() and grid functions in multipage pdfs

2012-10-22 Thread ilai
On Fri, Oct 19, 2012 at 6:28 PM, Ali Tofigh  wrote:

> On Wed, Oct 17, 2012 at 4:08 PM, ilai  wrote:
> > On Wed, Oct 17, 2012 at 11:10 AM, Ali Tofigh 
> wrote:
>
> ## this works as intended with a mix of plot.new() and grid.newpage
> pdf("test3.pdf")
> plot.new(); my.plot(); grid.newpage(); my.plot()
> dev.off()
>
>
Ahh. The evolution of problems in R-help threads...what a way to start the
week...
While grid and base don't play nice, that doesn't mean they *can't* be
mixed through proper use of gridBase - which requires some trial and error
on your part to see what works and what doesn't. For example this also
works without explicit calls to newpage:

my.plot <- function(){
plot(1, type='n', axes=FALSE, bty='n', xlab='', ylab='')  # a blank base
plot
grid.rect(c(0.25, 0.75), width=c(0.5, 0.5), gp=gpar(fill=c("blue", "red")),
vp=viewport(w=unit(.5, "npc"),just='left',clip='on'))# note the
clipping

pushViewport(viewport(w=unit(.5, "npc"),just='right'))
par(fig=gridFIG(), new=TRUE)
plot(1:10)
popViewport()
}
pdf(file='test4.pdf')
my.plot() ; my.plot()   # onefile = TRUE by default
dev.off()

What's going on here ? well, maybe some grid gurus more knowledgeable than
I can add insight here but I think you are mixing different issues. The
example you gave, test1 didn't work because when you call par(new=T) the
first time, there is still no plot "to go on". Same "issue" as produces the
warning
graphics.off()
par(new=T)

Modify my.plot() so the grid.rect is drawn *after* the plot(1:10), your
test1.pdf is correct with just a blank first page (from the "extra" call to
par). Thus, new.page() in your test3 solved this annoying issue of the
first par(new=T) call - which implies you can also draw the grid grobs
first, but I would not call this "a mix of new.page and grid.newpage".

In the future, to get the most out of R-help my unsolicited advice is to
remember you are the only one who knows how much / what help you need - and
set up your question / reproducible code accordingly. We the list readers
don't know your level, what things you tried etc. The original example made
no mention of base graphics, and the second reply didn't give any hints as
to how/why mixing base and grid matters here.

Cheers



> /ali
>
> >
> > require(gridBase)
> > pdf("test.pdf")
> >
> > grid.rect(gp = gpar(fill="blue"))
> > grid.newpage()
> > grid.rect(gp=gpar(fill='blue'))
> > # mix in base+grid. adapted from ?gridPAR in gridBase
> > par(fig=gridFIG(), new=TRUE)
> >  plot(1:10)
> > # plot.new()  # uncomment to see it's unnecessary
> > plot(1:10)
> >  pushViewport(viewport(width=0.5, height=0.5)) ;
> > grid.rect(gp=gpar(col="grey", lwd=2))
> > plot(rnorm(10))
> > grid.newpage()
> > grid.rect(gp=gpar(fill='blue'))
> > dev.off()
> >
> >>
> >> I use grid as much as possible, but for example for plotting
> >> dendrograms, I don't know how to plot them other than using base
> >> graphics. So I use the functions in gridBase to produce those plots.
> >
> >
> > Then you may have noticed the dendrogram examples in the gridBase docs
> don't
> > use plot.new() either but use lattice for the layout.
> >
> >
> >> In order to do that I have to call plot.new() at some point in my code
> >> to initialize the base graphics, and that can mess things up.
> >
> >
> >>
> >> No. See example above or provide a minimal reproducible example that
> does
> >> require it.
> >
> >
> >
> >>
> >> /ali
> >>
> >>
> >> On Tue, Oct 9, 2012 at 4:00 PM, Greg Snow <538...@gmail.com> wrote:
> >> > The plot.new function is for base graphics and base and grid graphics
> >> > don't usually play well together.  You probably want to use
> >> > grid.newpage function instead.
> >> >
> >> > On Tue, Oct 9, 2012 at 1:26 PM, Ali Tofigh 
> >> > wrote:
> >> >> Hi,
> >> >>
> >> >> when using the grid package, I've come across this weird behaviour
> >> >> where a call to plot.new() will start a new page for a multi-page
> pdf,
> >> >> but then the margins will somehow behave strangely for all but the
> >> >> first page: here is some code:
> >> >>
> >> >> pdf("test.pdf"); plot.new(); grid.rect(gp = gpar(fill="blue"));
> >> &g

Re: [R] How to include CI in a grouped barplot?

2012-11-08 Thread ilai
On Thu, Nov 8, 2012 at 12:14 PM, Rui Barradas  wrote:

> Hello,
>
> If I understand it right, you can use the arrows() function with an angle
> of 90 to get ci bars.
> Using your data example, but with made up standard errors,
>
>
> a=c(10,15)
> b=c(20,24)
> c=c(21,23)
>
> hei=cbind(a,b,c)
>
> # Standard errors
> sigma <- matrix(runif(6), ncol = 3)
> # helper function
> ci <- function(x, conf = 0.95) x*qnorm(1 - (1 - conf)/2)
>
> lo <- hei - ci(sigma)
> hi <- hei + ci(sigma)
>
> graph1=barplot(hei, beside=T, ylim = c(0, max(hi)))
>

 arrows(graph1, hi, graph1, lo, length = 0.15, angle = 90, code=3)

will suffice  (code = 1,2,3 in ?arrows)



> sapply(1:ncol(graph1), function(j){
> arrows(graph1[,j], hei[,j], graph1[,j], lo[,j], length = 0.15, angle =
> 90)
> arrows(graph1[,j], hei[,j], graph1[,j], hi[,j], length = 0.15, angle =
> 90)
> })
>
>
> Hope this helps,
>
> Rui Barradas
> Em 08-11-2012 13:02, Thais Rangel escreveu:
>
>  Hello everyone!
>>
>> I need to include the confidence interval bar in a grouped barplot. I've
>> found some options on the web, but none of them solved my problem.
>>
>> The question is: my barplot was created using vectors for each pair of bar
>> and them combining them using cbind.
>> I mean:
>>
>> a=c(10,15)
>> b=c(20,24)
>> c=c(21,23) ...
>>
>> hei=cbind(a,b,c)
>> graph1=barplot(hei, beside=T,...)
>>
>> I've tried to include each CI in a vector just like the height of the
>> bars,
>> but it hasn't worked (!!)
>> Is there an easy way to do this??
>>
>> Thanks a lot =)
>>
>>
>> Thais Rangel
>> (Rio de Janeiro, Brazil)
>>
>> [[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-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.
>

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


Re: [R] strip.custom() with more than one conditioning variable

2012-11-15 Thread ilai
 dotplot(variety ~ yield | year+ site, barley,
  strip = function(...,which.given,factor.levels) {
if(which.given==2){
 strip.default(which.given,factor.levels=substr(levels(barley$site), 1,
1),style=4,...)
}
else{

strip.default(which.given=which.given,factor.levels=factor.levels,style=3,...)
}
  }
)


Cheers

On Thu, Nov 15, 2012 at 5:18 PM,  wrote:

> Thanks Duncan, but it's of no use.  It still leaves space for two
> strips and doesn't use the first one.  I don't actually want a style =
> 4.  I used it as an example of when a factor.levels vector might be
> wanted.  In my case I want a vector of expressions which can't be made
> factor levels.  If I didn't need to show two conditioning variables,
> I'd have no problem.
>
> I need to work out how which.given is meant to be used.  It doesn't
> make sense to use it the way I have and I'll desist as soon as I find
> out how to use it properly.
>
>
> best
> Patrick
>
>
> Quoting Duncan Mackay :
>
>  Hi Patrick
>>
>> Not sure what you finally want to achieve but will this do?
>>
>> I have reduced the size of the text to make them readible
>>
>>   dotplot(variety ~ yield | year+ site, barley,
>>  strip = strip.custom(which.given = 2, style = 4,
>>factor.levels = paste(levels(barley$year),
>> substring(levels(barley$site), 1, 1)),
>>par.strip.text = list(cex = 0.75))
>> )
>>
>>
> __**
> 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.
>

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


Re: [R] Calculateing means

2012-11-16 Thread ilai
On Fri, Nov 16, 2012 at 2:42 PM, Khan, Sohail  wrote:

> Thanks. But aggregate will work on rows or columns.  I need to calculate
> mean for subsets of rows in a matrix
> I.E.
>
> Indx x1 x2  x3   x4 x5  x6  x7  x8  x9
> 1   25  30  15  8   12  9   18  21  89
> 2   52  35  42  74  65  20  28  32  12
> 3   12  35  33  88  12  52  32  32  18
> 4   25  25  16  23  89  21  21  21  42
> 
> ...
> I would like to calculate means for x1-x3, x4-x6, x7-x9
> For each row.
>
>
matrix%*%kronecker(diag(6),rep(1/95,95)))

assuming the original is set-up same as above (1-95 , 96 - 190 , ... -570)






> -Sohail
>
>
> -Original Message-
> From: John Kane [mailto:jrkrid...@inbox.com]
> Sent: Friday, November 16, 2012 4:35 PM
> To: Khan, Sohail; 'r-help@r-project.org'
> Subject: RE: [R] Calculateing means
>
> ?aggregate will do it.
>
> x <- data.frame( height= c(50, 174, 145, 200, 210, 140, 175),
> age_group=c(1,2,2,1,1,2,1),
>  ville= c(1,2,3,1,2,3,1))
>
> aggregate(x$height,list(x$age_group, x$ville), mean)
>
> or have a look at the plyr or datatable packages.
>
> John Kane
> Kingston ON Canada
>
>
> > -Original Message-
> > From: skha...@nshs.edu
> > Sent: Fri, 16 Nov 2012 15:58:17 -0500
> > To: r-help@r-project.org
> > Subject: [R] Calculateing means
> >
> >
> > Dear List,
> >
> > I have a data matrix with 570 columns containing 95 (samples) with 6
> > replicates each.
> > How can I calculate the mean of the replicates for 95 samples?
> > Thank you.
> >
> >
> > The information contained in this electronic e-mail transmission and
> > any attachments are intended only for the use of the individual or
> > entity to whom or to which it is addressed, and may contain
> > information that is privileged, confidential and exempt from disclosure
> under applicable law.
> > If the reader of this communication is not the intended recipient, or
> > the employee or agent responsible for delivering this communication to
> > the intended recipient, you are hereby notified that any
> > dissemination, distribution, copying or disclosure of this
> > communication and any attachment is strictly prohibited. If you have
> > received this transmission in error, please notify the sender
> > immediately by telephone and electronic mail, and delete the original
> > communication and any attachment from any computer, server or other
> > electronic recording or storage device or medium. Receipt by anyone
> > other than the intended recipient is not a waiver of any
> attorney-client, physician-patient or other priv!
> >  ilege.
> >   [[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.
>
> 
> Send any screenshot to your friends in seconds...
> Works in all emails, instant messengers, blogs, forums and social networks.
> TRY IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if2 for FREE
>
>
>
>
> The information contained in this electronic e-mail transmission and any
> attachments are intended only for the use of the individual or entity to
> whom or to which it is addressed, and may contain information that is
> privileged, confidential and exempt from disclosure under applicable law.
> If the reader of this communication is not the intended recipient, or the
> employee or agent responsible for delivering this communication to the
> intended recipient, you are hereby notified that any dissemination,
> distribution, copying or disclosure of this communication and any
> attachment is strictly prohibited. If you have received this transmission
> in error, please notify the sender immediately by telephone and electronic
> mail, and delete the original communication and any attachment from any
> computer, server or other electronic recording or storage device or medium.
> Receipt by anyone other than the intended recipient is not a waiver of any
> attorney-client, physician-patient or other priv!
>  ilege.
> __
> 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.
>

[[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-guid

Re: [R] [newbie] convert 3D spatial array to dataframe

2012-11-17 Thread ilai
Errr... You could reshape to a long format data.frame but an arguably
easier way:
dimnames(array.3d) <- list(lat= 1:7 , long = 1:11 , lev = 1:5) # not needed
just for clarity
levelplot(array.3d)


On Sat, Nov 17, 2012 at 9:36 PM, Tom Roche  wrote:

>
> summary: how to convert a 3D array (as obtained from ncdf4::ncvar_get)
> to a dataframe suitable for use by lattice::levelplot(), e.g.,
>
> levelplot(conc ~ lon * lat | lev, data = data.frame)
>
> details:
>
> I have atmospheric data in netCDF files specifying gas concentrations
> over a 3D space with dimensions longitude, latitude, and (vertical)
> level. I need to plot the data by level. Since there are several levels,
> I'm guessing I should use package=lattice, which I have not previously
> used. (I have used package=fields, and I would like to plot the levels
> over a map, but lattice seems to provide the best way to organize
> multiple plots--please correct me if wrong.)
>
> >From reading Sarkar's excellent lattice book
>
> http://dx.doi.org/10.1007/978-0-387-75969-2
>
> it seems that one best provides data to lattice::levelplot() via
> dataframe, since the dataframe provides a sort of namespace for the
> trellis "formula." I know that ncdf4::ncvar_get will return my
> concentrations as the values in a 3D array with dimensions={lon, lat,
> lev} so I'm trying to find a way to convert a 3D array to a dataframe.
> Here's my small, self-contained example:
>
> lon=11
> lat=7
> lev=5
> len=lon*lat*lev
> array.3d <- array(data=c(1:len), dim=c(lat, lon, lev))
>
> # Rewrite the array values "more spatially," i.e., row-wise from
> # bottom left. If there's a more-R-ish way to fill this array
> # as specified, please let me know: I know 'for' loops are deprecated
> # in R.
>
> i=1
> for (z in 1:lev) {
>   for (x in lat:1) {
> for (y in 1:lon) {
>   array.3d[x,y,z]=i ; i=i+1
> }
>   }
> }
>
> produces (with rows=latitudes and cols=longitudes)
>
> > array.3d[,,1]
>  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
> [1,]   67   68   69   70   71   72   73   74   757677
> [2,]   56   57   58   59   60   61   62   63   646566
> [3,]   45   46   47   48   49   50   51   52   535455
> [4,]   34   35   36   37   38   39   40   41   424344
> [5,]   23   24   25   26   27   28   29   30   313233
> [6,]   12   13   14   15   16   17   18   19   202122
> [7,]1234567891011
> > array.3d[,,lev]
>  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
> [1,]  375  376  377  378  379  380  381  382  383   384   385
> [2,]  364  365  366  367  368  369  370  371  372   373   374
> [3,]  353  354  355  356  357  358  359  360  361   362   363
> [4,]  342  343  344  345  346  347  348  349  350   351   352
> [5,]  331  332  333  334  335  336  337  338  339   340   341
> [6,]  320  321  322  323  324  325  326  327  328   329   330
> [7,]  309  310  311  312  313  314  315  316  317   318   319
>
> I want to convert array.3d to a dataframe with structure like the
> following (note order of data values is arbitrary):
>
> lon  lat  lev  conc
> ---  ---  ---  
>   171 1
>   271 2
>   371 3
> ...
>   91175
>  101176
>  111177
> ...
>   915   383
>  1015   384
>  1115   385
>
> How to do that? I'm guessing this involves function=reshape, but I can't
> see how to make `reshape` work for this usecase.
>
> TIA, Tom Roche 
>
> __
> 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.
>

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


Re: [R] lattice: defining grouping variable only for the upper/lower panel with splom

2012-11-19 Thread ilai
On Mon, Nov 19, 2012 at 5:42 AM, AnjaM  wrote:

> Using the mtcars dataset, how to define the grouping variable to be valid
> only for the upper or lower panel?
>
> The following doesn't work:
>
> # Code start
>
>
Almost :

splom(~data.frame(mpg, disp, hp, drat, wt, qsec),
>   data=mtcars, pscales=0,
>   auto.key=list(columns=3),
>   upper.panel = function(...,groups){
> panel.grid(...)
> panel.xyplot(groups=mtcars$cyl,...)
>   }
> )
>
>


> # Code end
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/lattice-defining-grouping-variable-only-for-the-upper-lower-panel-with-splom-tp4650033.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.
>

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


Re: [R] rjags and parallel chains

2012-11-25 Thread ilai
Specifying n >1 chains is not enough. You need some parallel backend. You
can use snow/snowfall or doMC (these are R libraries) for example. Maybe
others, google is your friend. Word of caution about doMC (maybe also
snowfall, never tested it), you might need to specify RNG (seed, sampler)
for each chain in the starting values list because once you split your job,
each core "thinks" you are running just one chain and they all choose
"Wichmann-Hill" with the same .Random.seed and you get 4 copies of the same
chain. With different *parameter* starting values this might not be such a
big deal for you, it depends on your application, just thought I'll mention
it. See jags manual and ?RNG.
Good luck

On Sun, Nov 25, 2012 at 11:57 AM, Noah Silverman wrote:

> Hello,
>
> I have a fairly complex hierarchical model that I using rjags to fit.
>  Short test runs verify that it works and everything appears to be setup
> correctly.
>
> Now that I want to collect a larger sample from the posterior (5,000 or
> more).  This looks like it will take several days to run on my hardware
> (Intel core i7, 16GB RAM)
>
> I read in the rjags documentation that there is an option for parallel
> chains.  Since my cpu has 4 cores, it seems logical to run 4 chains in
> parallel, collection 1,250 samples each.  Should provide a nice speedup.
>
> However, when calling rjags with the n.chains options set to 4, I don't
> see it actually doing anything in parallel.  Watching a cpu monitor, I only
> see a single thread running on a single core.  So clearly something isn't
> working correctly.
>
> Software versions:
> R 2.15.2
> jags 3.2.0
> Ubuntu 12.04  (64bit version)
>
>
> Can anyone suggest where I might look to get this running in parallel?
>
> Thanks
>
>
> --
> Noah Silverman, M.S.
> UCLA Department of Statistics
> 8117 Math Sciences Building
> Los Angeles, CA 90095
>
> __
> 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.
>

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


Re: [R] Problem with glm, gaussian family with log-link

2012-11-26 Thread ilai
On Mon, Nov 26, 2012 at 5:33 AM, Florian Weiler  wrote:

> Dear all,
>
> I am using the book "Generalized Linera Models and Extension" by Hardin and
> Hilbe (second edition, 2007) at the moment. The authors suggest that
> instead of OLS models, "the log link is generally used for response data
> that take only positive values on the continuous scale".




> specifying *family=gaussian(link="log") *I
> am asked to provide starting values. When I set them all equal to zero, I
> always get the message that the algorithm did not converge. Picking other
> values the message is sometimes the same, but more often I get:
> *
> *
> *Error in glm.fit(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  :
> *
> *  NA/NaN/Inf in 'x' *
> *
> *
> As I said, in STATA I can run these models without setting starting values
> and without errors. I tried many different models, and different datasets,
>

And yet you've failed to provide even one of them together with your code
as a reproducible example ...

# This works without starting values:
set.seed(2341)
x <- rep(1:10,3) ; y <- jitter(rpois(30,5+x))
plot(x,y)
(gausslog <- glm(y~x,family=gaussian(link='log')))
exp(coef(gausslog))

# This works only with starting values
set.seed(2341)
x <- rep(1:10,3) ; y <- jitter(rpois(30,x))
plot(x,y) ; summary(y)  # yes,yes, some y <0, just trying to reproduce the
error...
(gausslog <- glm(y~x,family=gaussian(link='log')))
(gausslog <- glm(y~x,family=gaussian(link='log'),start=c(0,0)))

# also
set.seed(2341)
x <- rep(1:10,3) ; y <- rnorm(30,0+0.1*x)
plot(x,y) ; summary(y)
(gausslog <- glm(y~x,family=gaussian(link='log'),start=c(0,0)))

So really this is a non issue without the offending data set and code.

but the problem is always the same (unless I only include one single
> independent variable).


Oh, more information... way to build up the suspense

set.seed(2341)
x <- rep(1:10,3) ; xx <- rep(seq(20,50,l=5),6) ; y <- rnorm(30,5+3*x-2*xx)
(gausslog <- glm(y~x+xx,family=gaussian(link='log'),start=c(0,0,0)))

No joy. Still fits.


> Could anyone tell me why this is the case, or what I
> do wrong,


No


> or why the suggested models from the book might not be
> appropriate? I'd appreciate any help!
>
> Personally I don't care for reproducing some results from STATA and have
no comment on the validity of the above but maybe someone in the list would
have a better answer if you repost.





> Best,
> Florian
>
>
Also this:

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

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


Re: [R] Error message R2Jags

2012-11-28 Thread ilai
On Wed, Nov 28, 2012 at 11:37 AM, alexB wrote:

The error was generated by jags not R or R2Jags (wrong list). Regardless,
your problem is the prior loop is only 1:6


> 
>


> for (i in 1:6) { b[i] ~ dnorm(0.0, 0.01)
>   #  b[i] ~ dunif(-20, +20)
>


So the error is literally b[7] is out of range

Cheers



> }
>
> }
> ",fill = TRUE)
> sink()
>
> inits1 <- function () {
>   list(b = rnorm(7, 0, 0.01))}
>
> out1 <- jags(data = win.data1,
>  inits = inits1,
>  parameters = params1,
>  model.file = "GLM.txt",
>  n.thin = nt,
>  n.chains = nc,
>  n.burnin = nb,
>  n.iter = ni)
>
>
>
>
> That's when R returns this error message:
>
> #
> #Compiling model graph
> #   Resolving undeclared variables
> #   Allocating nodes
> #Deleting model
> #
> #Error in jags.model(model.file, data = data, inits = init.values, n.chains
> = n.chains,  :
> #  RUNTIME ERROR:
> #Compilation error on line 13.
> #Subset out of range: b[7]
> #
>
> So I guess there's a problem with line 13 of the code (i.e. b[7] * I3[i])
> causing the problem, but why... I really don't see the problem :(
>
> Any guess?
>
> Thanks in advance,
>
> aB
>
>
>
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Error-message-R2Jags-tp4651178.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.
>

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


Re: [R] Focus on a sub-panel of a splom with trellis.focs() -- return coordinate of sub-panel, or names of variables therein

2012-12-11 Thread ilai
You could try

require(grid)
trellis.focus()
names(iris)[round(unlist(grid.locator()))]
trellis.unfocus()

cheers

On Tue, Dec 11, 2012 at 11:59 AM, Eric Stone  wrote:

> Hi,
> I'd like to be able to generate a splom plot in R and then use my mouse to
> click on one of the sub-panels (panel.pairs, specifically) and have R
> return either the coordinates of that sub-panel, or even better, the names
> of the corresponding variables plotted in that sub-panel.
>
> Here's an example to work with:
>
> > library(lattice)
> > splom(~iris[1:4], groups = Species, data = iris,
> +   panel = panel.superpose,
> +   key = list(title = "Three Varieties of Iris",
> +  columns = 3,
> +  points = list(pch = super.sym$pch[1:3],
> +col = super.sym$col[1:3]),
> +  text = list(c("Setosa", "Versicolor", "Virginica"
>
> This is what I've been able to come up with so far, but I know it's not
> what I need. I'd like to be able to select an entire sub-panel
>
> > trellis.focus()
> > panel.link.splom() #click on a point in the plot, then hit 'esc'
>
> [1]  80 111
>
> > trellis.unfocus() #to end trellis.focus
>
> Thanks for your help,
> Eric
>
>
> [[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.
>

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


Re: [R] Separate Array Variable Content

2012-06-01 Thread ilai
 Antony,
I am now utterly confused. The conditions involve column names of X1. In
your first post I assumed you just meant "check for each row of x" not
columns. After Arun replied I realized that may have been a wrong
assumption, but I just don't understand how you get, for example the last
TRUE (for the 90). Also, you failed to ?dput again. X2 is a matrix? of what
? expressions ? characters ? any way it looks like a list or a column
vector to me. To avoid loops, David's suggestion could maybe be expanded to
work with ?do.call if is.list(conditions), also see ?outer for matrices,
but again I don't really understand what you're after. Sorry.
Ilai


On Fri, Jun 1, 2012 at 12:53 AM, Akkara, Antony (GE Energy, Non-GE) <
antony.akk...@ge.com> wrote:

> Hi iLai,
>
> ** **
>
> What you showed below, almost same like I am also expecting.
>
> ** **
>
> There is two matrix,
>
> 1) 1st - matrix contain values like this,
>
> ** **
>
> ABC   XYZ PQR
> ABC_CHECK   XYZ_CHECK   PQR_CHECK
>
>   
>   --
> -  
>
>  10  20 30
>
> 40  50 60
>
> 70  80 90
>
> ** **
>
> 2)2nd matrix have some conditions, need to check with  1st
> matrix columns. Like this,
>

>
> 
>
> CHECK
> FOR CONDITION
>
>
> -- -**
> **
>
>
> ABC_CHECKABC > 10 & XYZ < 30 & PQR
> <90
>
>
> XYZ_CHECK ABC > 9 & XYZ < 25 & PQR
> <60
>
>
> PQR_CHECK   ABC > 60 & XYZ < 79 & PQR
> <100
>
> ** **
>
> ** **
>
> Here I need to change the cell content that already created [“*ABC_CHECK*”,”
> *XYZ_CHECK*”,” *PQR_CHECK*”]
>
> So, 
>
> Finally the result should get like this,
>
> ** **
>
> ABC   XYZ PQR
> ABC_CHECK   XYZ_CHECK   PQR_CHECK
>
>   
>   --
> -  
>
>  10  20 30
> FALSETRUE FALSE
>
> 40  50 60
> FALSEFALSEFALSE
>
> 70  80 90
> FALSEFALSETRUE
>
> ** **
>
> And can please tell me which is the best way to do this ?, Can we do this
> with-out loop ?
>
> And, Is it possible to put any other character instead of TRUE & FALSE ?,
> like this
>
> Here 
>
> For TRUE = T , FLASE = F
>
> ** **
>
> ** **
>
> ABC   XYZ PQR
> ABC_CHECK   XYZ_CHECK   PQR_CHECK
>
>   
>   --
> -  
>
>  10  20 30
> F  T  F
>
> 40  50 60
> F  F  F
>
> 70  80 90
> F  F  T
>
> ** **
>
> ** **
>
> Can I get an immediate reply ?
>
> ** **
>
> - Thanks 
>
> Antony.
>
> ** **
>
> ** **
>
> *From:* ila...@gmail.com [mailto:ila...@gmail.com] *On Behalf Of *ilai
> *Sent:* Wednesday, May 30, 2012 10:35 PM
> *To:* Akkara, Antony (GE Energy, Non-GE)
> *Cc:* r-help@r-project.org
> *Subject:* Re: [R] Separate Array Variable Content
>
> ** **
>
> If you haven't done so you *must* read an Introduction to R. The only
> reason this is a problem is Myarray is a character string, not a function
> or expression to be evaluated. I think this will get you what you

Re: [R] how to add a vertical line for each panel in a lattice dotplot with log scale?

2012-06-06 Thread ilai
You say median for each panel but tapply gets medians for each variety
(chartjunk IMHO). Regardless, *this case* has nothing to do with
panel.abline. Add print(median.values) to your panel function would have
hinted as to the missing piece.

# medians for each panel:
dotplot(variety ~ yield | site, data = barley,
   scales=list(x=list(log=TRUE)),
   layout = c(1,6),
   panel = function(x,y,...) {
   panel.dotplot(x,y,...)
   median.values <- median(x)
   panel.abline(v=median.values, col.line="red")
})

# medians for each variety
 dotplot(variety ~ yield | site, data = barley,
   scales=list(x=list(log=TRUE)),
   layout = c(1,6),
   panel = function(x,y,...) {
   panel.dotplot(x,y,...)
   median.values <- tapply(x, y, median)
panel.abline(v=median.values, col.line="red")
   }
   )

Cheers

On Wed, Jun 6, 2012 at 6:10 AM, maxbre  wrote:

> by considering this example from barley dataset
>
> #code start
>
> dotplot(variety ~ yield | site, data = barley,
>scales=list(x=list(log=TRUE)),
>layout = c(1,6),
>panel = function(...) {
>panel.dotplot(...)
>#median.values <- tapply(x, y, median)# medians for each
> variety
>#panel.abline(v=median.values, col.line="red")# but this is not
> working!
>#panel.curve(...) # how to properly
> set this?
>}
>)
>
> #code end
>
> I want to plot as a reference vertical line the medians for each panel
>
> I’ve been reading in
> https://stat.ethz.ch/pipermail/r-help/2009-January/185384.html
> that it’s not possible with panel.abline() and it’s probably necessary to
> use panel.curve() instead; unfortunately I can’t figure (manage) how, any
> help for this?
>
> thank you
>
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-with-log-scale-tp4632513.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.
>

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


Re: [R] error calling Winbugs using R2WinBugs to run a multi-level model

2012-06-06 Thread ilai
Untested because I don't have (use) winbugs and you didn't provide dat*.
But consider
a <- 4 ; f <- 6
list('a','f')
list(a,f)
list(a=a,f=f)

My guess is you wanted sp.data to be a named list, not a list of names...

HTH


On Wed, Jun 6, 2012 at 4:12 AM, Saana Isojunno <
saana.isoju...@googlemail.com> wrote:

> Dear all,
>
> I'm calling Winbugs (1.4.3) through R2WinBugs (2.1-18 coda_0.14-7) to
> fit a switching random walk model, but come up with an instant trap
> with the log only displaying 'check('.
>
> I will paste the trap with session info below; I'd be very grateful
> for any ideas.
>
> Couple of leads:
>
> 1. I presume the problem relates to the r package itself or the way I
> call bugs(), because I can use the same text files specifying the
> model and data directly in Winbugs and it runs fine (i.e syntax ok,
> compilation ok, updates slow but no traps).
>
> 2. The problem occurs in r only when I try to fit the model to
> multiple individuals, i.e. the data contains a matrix of step lengths
> (rows) and individuals (columns) instead of a vector for just one
> individual. I get the same error message regardless of the number of
> data rows in each column (I even tried just one).
>
> The model loops over the path of each animal, estimating a hidden
> movement state and their parameters. For 4 individuals with 100 data
> points each the data looks something like this:
>
> dat1   : num 100
> dat2   : int 4
> dat3   : num [1:4] 8 4 2 5
> dat4   : num [1:100, 1:4] 1 1 1 1 1 2 2 2 2 2 ...
> dat5   : num [1:100, 1:4] 2 2 2 2 2 1 2 2 2 2 ...
> dat6   : num [1:100, 1:4] 16 34.3 33.5 27.9 14.9 ...
> dat7   : num [1:100, 1:4] 0.357 0.474 0.487 0.495 0.524 ...
> dat8: num [1:50, 1:4] 36.4 294.5 24.4 21.1 422.8 ...
>
> This is how I've called WinBugs in r:
>
>  # write data to text file
>  sp.data = list("dat1","dat2","dat3","dat4","dat5","dat6","dat7","dat8")
>  bugs.data(sp.data, digits=5, data.file="dir1\\data1.txt")
>
>  # test the model runs
>  fit =
> bugs(data=paste("C:\\Users\\User1\\Documents\\dir1\\data1.txt",dataFile,sep=""),
> inits=NULL, parameters.to.save=list('par1','par2','par3'),
> model.file=modelFile,
> debug=TRUE, n.chains=3, n.iter=20, n.burnin=3, n.thin=1,
> digits=4)
>
>  ## The trap
>
> incompatible copy
>
>  BugsScript.Action.Do   [0436H]
>.a  BugsScript.Action   [025B6790H]
>.argNum INTEGER 0
>.bugsCommands   ARRAY 240 OF CHAR   7877X, 75A5X, 0B17X, 3701X
>   ...
>.p  ARRAY 3, 120 OF CHARElements
>.s  BugsScanners.ScannerFields
>.scriptCommand  ARRAY 240 OF CHAR   "#Bugs:check"   ...
>.vectorName BOOLEAN FALSE
>  Services.Exec   [0136H]
>.a  Services.Action [025B6790H]
>.t  POINTER [64E10170H]
>  Services.IterateOverActions   [02F4H]
>.p  Services.Action [025B6790H]
>.t  POINTER NIL
>.time   LONGINT 4375656
>  Services.StdHook.Step   [034DH]
>.h  Services.StdHook[0248E380H]
>  HostWindows.Idle   [4A86H]
>.focus  BOOLEAN FALSE
>.tick   Controllers.TickMsg Fields
>.w  HostWindows.Window  NIL
>  HostMenus.TimerTick   [3422H]
>.lParam INTEGER 0
>.opsControllers.PollOpsMsg  Fields
>.wParam INTEGER 1
>.wndINTEGER 1311298
>  Kernel.Try   [3A61H]
>.a  INTEGER 1311298
>.b  INTEGER 1
>.c  INTEGER 0
>.h  PROCEDURE   HostMenus.TimerTick
>  HostMenus.ApplWinHandler   [3841H]
>.Proc   PROCEDURE   NIL
>.hitBOOLEAN FALSE
>.lParam INTEGER 0
>.messageINTEGER 275
>.resINTEGER 1664639202
>.s  ARRAY 256 OF SHORTCHAR  ""   ...
>.w  INTEGER 1970768325
>.wParam INTEGER 1
>.wndINTEGER 1311298
>(pc=75778816H,  fp=0027FB38H)
>(pc=7577898DH,  fp=0027FBB0H)
>(pc=75778AB8H,  fp=0027FC14H)
>(pc=757790E2H,  fp=0027FC24H)
>  HostMenus.Loop   [3BDEH]
>.done   BOOLEAN FALSE
>.f  SET {0..5}
>.n  INTEGER 0
>.resINTEGER 0
>.w  HostWindows.Window  NIL
>  Kernel.Start   [2B8CH]
>.code   PROCEDURE   HostMenus.Loop
>
>
>
>
>
> ## my current R session specs:
>
> R version 2.15.0 (2012-03-30)
> Platform: x86_64-pc-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=English_United Kingdom.1252
> [2] LC_CTYPE=English_United Kingdom.1252
> [3] LC_MONETARY=English_United Kingdom.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United Kingdom.1252
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
>
> other attached packages:
> [1] R2WinBUGS_2.1-18 coda_0.14-7  lattice_0.20-6
>
> loaded via a namespace (and not attached):
> [1] grid_2.15.0  tools_2.15.0
>
>
>
>
> ## also tried these specs:
>
> R version 2.13.2 (2011-09-30)
> Pl

Re: [R] aligning axis labels in a colorkey from levelplot

2012-06-16 Thread ilai
On Sat, Jun 16, 2012 at 2:11 AM, Stephen Eglen wrote:

> R does a great job with the fine details regarding plots.  e.g in the
> following:
>
> library(lattice)
> y <- -4:4/10
> xyplot(y~1, las=1)
>
>
No. las is a parameter in base graphics ?par. It was simply ignored here:
 xyplot(y~1,scales=list(rot=45), las=1)


>
> the numbers in the colorkey seem left-aligned, and because of the minus
> sign, the numbers now do not align on the decimal point.  Likewise when
> the number of digits changes:
>
> levelplot(matrix(4:12,3,3))
>
> The labels are aligned to the colored rect. You want them aligned
differently, change it manually. See the colorkey details in ?levelplot
(also can help with your next thread on positioning). One obvious way is to
add white spaces:
levelplot(matrix(seq(4,120,l=9),3,3))
# or
levelplot(matrix(seq(4,120,l=9),3,3),colorkey=list(at=seq(0,120,20),labels=c('
0',' 20',' 40',' 60',' 80','100','120')))

(If your mail client gobbled them, in the above labels, 0 has two white
spaces before it, 20 has 1 white space, etc.)

Cheers




> Thanks, Stephen
>
> __
> 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.
>

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


Re: [R] plotting two histograms on one plot with hist function

2012-06-26 Thread ilai
On Tue, Jun 26, 2012 at 10:02 AM, John Kane  wrote:

> Why not just plot the two histograms on the same scale in a 2 panel plot?
>

I think OP request was "for comparison". Two panels may do, but why not a
barplot of the histograms in the same panel ?

barplot( rbind(
hist(rbeta(30,2,4),breaks=seq(0,1,.1),plot=F)$counts,
hist(rbeta(30,6,8),breaks=seq(0,1,.1),plot=F)$counts),
beside=T)

see str(hist(yourdata)) or ?hist

Cheers
Ilai



> John Kane
> Kingston ON Canada
>
>
> > -Original Message-
> > From: mb...@sun.ac.za
> > Sent: Tue, 26 Jun 2012 15:24:55 +0200
> > To: r-help@r-project.org
> > Subject: [R] plotting two histograms on one plot with hist function
> >
> > I would like to plot two data sets (frequency (y-axis) of mean values for
> > 0-1(x=axis)) on a single histogram for comparison. The hist() only allow
> > the overlay of two histograms, and although barplot() allows beside=TRUE,
> > it does not show frequency values (like hist) but rather all of the
> > values. Is there any way that I can use the hist() to plot two data sets
> > similar to the barplot(). Any help or advice will be appreciated!
> >
> > Kind regards,
> > Marguerite
> >
> >
> >
> >
> >
> >   
> > E-pos vrywaringsklousule
> >
> > Hierdie e-pos mag vertroulike inligting bevat en mag regtens
> > geprivilegeerd wees en is slegs bedoel vir die persoon aan wie dit
> > geadresseer is. Indien u nie die bedoelde ontvanger is nie, word u
> > hiermee in kennis gestel dat u hierdie dokument geensins mag gebruik,
> > versprei of kopieer nie. Stel ook asseblief die sender onmiddellik per
> > telefoon in kennis en vee die e-pos uit. Die Universiteit aanvaar nie
> > aanspreeklikheid vir enige skade, verlies of uitgawe wat voortspruit uit
> > hierdie e-pos en/of die oopmaak van enige l?ers aangeheg by hierdie e-pos
> > nie.
> >
> > E-mail disclaimer
> >
> > This e-mail may contain confidential information and may...{{dropped:11}}
> >
> > __
> > 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.
>
> 
> GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at
> http://www.inbox.com/smileys
> Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and
> most webmails
>
> __
> 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.
>

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


Re: [R] alternate tick labels and tick marks with lattice xyplot

2012-07-18 Thread ilai
Maybe I'm missing something too but from your example seems like you are
looking for

xyplot(rnorm(12) ~ 1:12 , type="l",
scales=list(x=list(at=seq(2,12,2),labels=c(1, ' ', 3 , ' ' , 5 , ' ' ))),
par.settings=list(axis.components=list(bottom=list(tck=c(0,1)

See "scales" in ?xyplot and str(trellis.par.get()) for some settings in
lattice

HTH

On Wed, Jul 18, 2012 at 12:02 PM, Leah Marian  wrote:

> Yes,
>
> I would be interested in both the ggplot2 and lattice ways of doing
> this. Unfortunately, I am not interested in creating a panel for each
> chromosome. Actually, I would like to create a Manhattan plot using
> xyplot. Thus I would need to alternate tick marks and tick labels.
>
> Thanks!
>
>
>
>
> On Mon, Jul 16, 2012 at 12:11 PM, John Kane  wrote:
> >
> > I have not seen any response yet so I thought I would reply.
> >
> > No idea of how to do this in lattice but an approximation of it can be
> done in ggplot2. I am trying to learn ggplot2 and it was a handy exercise.
>  I still have not figured out how to get the extra line on the x-axis,
> hence the lines in the graph body instead
> >
> > Example:
> > ##++###
> >
> > library(ggplot2)
> > data  <-  structure(list(Chromosome = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3,
> > 3), BasePair = c(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4), Pvalue =
> c(0.819178665755317,
> > 0.462827404495329, 0.44360001408495, 0.871020796708763,
> 0.404167180880904,
> > 0.115009917411953, 0.51048326632008, 0.292681957129389,
> 0.839718346949667,
> > 0.586992112919688, 0.29609977430664, 0.873988818377256), indice = 1:12,
> > group = c("Group 1", "Group 2", "Group 1", "Group 1", "Group 1",
> > "Group 1", "Group 2", "Group 1", "Group 2", "Group 1", "Group 2",
> > "Group 2")), .Names = c("Chromosome", "BasePair", "Pvalue",
> > "indice", "group"), row.names = c(NA, -12L), class = "data.frame")
> >
> > library(ggplot2)
> >
> > p  <-  ggplot(data, aes(indice, -log10(Pvalue))) + geom_line()  +
> >   opts(legend.position = "none") +
> >   scale_y_continuous(expression(paste(-log[10], "p-value"))) +
> >   scale_x_continuous("Chromosome", breaks=c(2.5, 6.5 ,10.5),
> labels=c("1", "2","3")) +
> >   geom_segment(aes(x = 4, y = 0.01, xend = 9, yend = 0.01,
> colour = group))  +
> >   opts(title = "Results")  + facet_grid(. ~ group)
> > p
> >
> > ##===##
> > John Kane
> > Kingston ON Canada
> >
> >
> > > -Original Message-
> > > From: lmpr...@gmail.com
> > > Sent: Fri, 13 Jul 2012 15:33:43 -0400
> > > To: r-help@r-project.org
> > > Subject: [R] alternate tick labels and tick marks with lattice xyplot
> > >
> > > Hi,
> > >
> > > I would like to use xyplot to create a figure. Unfortunately, I cannot
> > > find
> > > documentation in xyplot to specify alternating the x-axis tick labels
> > > with
> > > the x-axis tick marks. I can do this with the regular R plot function
> as
> > > follows.
> > >
> > >
> > > #A small version of my data looks like this
> > > data<-data.frame(matrix(ncol=3,nrow=12))
> > > data[,1]<-rep(c(1,2,3),c(4,4,4))
> > > data[,2]<-rep(c(1,2,3,4),3)
> > > data[,3]<-runif(12,0,1)
> > > names(data)<-c("Chromosome", "BasePair", "Pvalue")
> > > #using R's plot function, I would place the the chromosome label
> between
> > > the
> > > #tick marks as follows:
> > > v1<-c(4,8)
> > > v2<-c(2,6,10)
> > > data$indice<-seq(1:12)
> > > plot(data$indice, -log10(data$Pvalue), type="l", xaxt="n",
> main="Result",
> > >  xlab="Chromosome", ylab=expression(paste(-log[10]," p-value")))
> > > axis(1, v1,labels=FALSE )
> > > axis(1, v2, seq(1:3), tick=FALSE, cex.axis=.6)
> > >
> > > Can this be done with lattice xyplot?
> > >
> > >
> > > --
> > > Leah Preus
> > > Biostatistician
> > > Roswell Park Cancer Institute
> > >
> > >   [[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.
> >
> > 
> > GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at
> http://www.inbox.com/smileys
> > Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™
> and most webmails
> >
> >
>
>
>
> --
> Leah Preus
> Biostatistician
> Roswell Park Cancer Institute
>
> __
> 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mail

Re: [R] Turn categorical array into matrix with dummy variables

2012-07-27 Thread ilai
?model.matrix

On Fri, Jul 27, 2012 at 11:32 AM, xuan zhao  wrote:

> Hi All,
> I want to turn a categorical array (array with factors) into a matrix with
> dummy variables. like array=c(a,a,b,b,b) should be turned into:
> a b
> 1 0
> 1 0
> 0 1
> 0 1
> 0 1
> Do you know any way of doing this?
> Thanks
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Turn-categorical-array-into-matrix-with-dummy-variables-tp4638134.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.
>

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


Re: [R] Multiple lattice levelplots from matrices

2012-08-26 Thread ilai
You want array not list, as in

levelplot(array(rnorm(400,rep(1:4,each=100)),c(10,10,4)))

abind::abind is useful sometimes for binding preexisting matrices to
arrays.

Cheers


On Sun, Aug 26, 2012 at 5:57 AM, Jens Peter Andersen / Region Nordjylland <
je...@rn.dk> wrote:

> Dear R-users,
>
> My goal is to construct a levelplot (from the lattice package) with 4 or
> more individual plots sharing the same colorkey. While this appears to be
> relatively simple using functions, I haven't been able to find a solution
> using data matrices. An example of a working levelplot with just one matrix:
>
> d <- replicate(10,rnorm(10))
> levelplot(d)
>
> I have found partial solutions using print and split to show all 4
> levelplots on the same screen, but these would require me to either turn
> off the colorkey, or show it on every plot. Neither solution is completely
> satisfactory.
>
> If I use the layout-option in levelplot, like so:
>
> levelplot(d, layout=c(2,2))
>
> , I get the desired layout, with one large colorkey, main and xlab/ylab,
> but only one levelplot prints.
>
> I have been trying to construct a formula that yields the desired result,
> but I'm afraid my understanding of data frames, arrays and matrices is not
> deep enough to do so. If anyone knows of a working solution, I would be
> very grateful. What I imagine is something along the line of (not working
> code):
>
> d1 <- replicate(10,rnorm(10))
> d2 <- replicate(10,rnorm(10))
> d3 <- replicate(10,rnorm(10))
> d4 <- replicate(10,rnorm(10))
>
> d <- list(d1,d2,d3,d4)
> di <- c(1,2,3,4)
>
> levelplot(x ~ y | di, data = d, layout=c(2,2))
>
> NB! Avoiding the matrices is not an option. Some of them are obtained from
> raw text files.
>
> Thank you in advance,
> -JP
>
> Jens Peter Andersen
> PhD student, MLIS
> Medical Library, Aalborg Hospital
> Aarhus University Hospital
>
> __
> 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.
>

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


Re: [R] How to colorize the panel backgrounds of pairs()?

2012-03-01 Thread ilai
par('bg') is not what you are looking for - it will set the bg of the
whole graphic device, not panels. I think you want:
count <- 0
mypanel <- function(x, y, ...){
   count <<- count+1
   ll<- par('usr')
   if(count %in% c(1,4,9,12)) bg<- "#FDFF65"
   else bg<- 'transparent'
   rect(ll[1],ll[3],ll[2],ll[4],col=bg)
   points(x, y, cex=0.5)
}

Cheers

On Thu, Mar 1, 2012 at 4:49 PM, Marius Hofert
 wrote:
> Dear expeRts,
>
> I would like to colorize the backgrounds of a pairs plot according to the 
> respective panel number. Here is what I tried (without success):
>
> count <- 0
> mypanel <- function(x, y, ...){
>    count <<- count+1
>    bg. <- if(count %in% c(1,4,9,12)) "#FDFF65" else NA
>    points(x, y, cex=0.5, bg=bg)
> }
>
> U <- matrix(runif(4*500), ncol=4)
> pairs(U, panel=mypanel)
>
> I also tried to set par(bg=bg.) before the call to points(), but that didn't 
> work either. The only thing I found is that "bg=" can be used to fill certain 
> plot symbols, but I would like to colorize the background of each panel, not 
> the drawn circles.
>
> Cheers,
>
> Marius
>
> __
> 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.


Re: [R] Parameterization of Inverse Wishart distribution available in MCMCpack and bayesm libraries

2012-03-01 Thread ilai
What do you make of the following from ?riwish
"
   riwish(v, S)

   v: Degrees of freedom (scalar).
"
does a m/2 parameterization yield a scalar for, say, 3 dof ?



On Thu, Mar 1, 2012 at 9:55 AM, Shantanu MULLICK  wrote:
> Hello Everyone
>
> Both the MCMCpack and the bayesm libraries allow us to make draws from the
> Inverse Wishart distribution.
>
> But I wanted to find out how exactly is the Inverse Wishart distribution
> parameterized in these libraries.
>
> The reason I ask is the following:
>
> Now its generally standard to express Inverse Wishart  as IW(0.5 * DOF,0.5*
> Scale).    (DOF-> Degree of freedom, Scale -> Scale parameter).
>
> If we follow standard usage when we refer to the Degree of Freedom of the
> above IW distribution it is =  DOF (and not 0.5* DOF).
>
> Similarly the Scale parameters of the above IW it is= Scale (and not
> 0.5*Scale).
>
> For the MCMCpack the IW draws are made by riwish(v,S).
>
> *Question:* Does this compute IW( v,S) or IW(0.5*v,0.5*S) ?
>
> This is the reason I want to find out the way these libraries parameterize
> the Inverted Wishart distribution.
>
> Best
> Shantanu
>
>        [[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-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] Parameterization of Inverse Wishart distribution available in MCMCpack and bayesm libraries

2012-03-02 Thread ilai
On Fri, Mar 2, 2012 at 1:22 AM, peter dalgaard  wrote:
>

> Er, yes (scalar does not imply integer)

Dough! awkward... Sorry Shantanu.

I've added
cat('###\n # ',substr(fortunes::fortune(90)$quote,1,146),'\n ### \n')
To .First in my Rhelp directory.
Hope that helps (me).




>
> As a general matter:
>
> 1. This is the Open Source world, you can read the actual function and see 
> what it does. It might even say so in the comments.
>
> 2. You can investigate empirically -- the moments are known as a function of 
> the parameters (check Wikipedia), so how about simulating a few thousand 
> matrices and looking at the means and variances.
>
> (I don't do IW on a daily basis, but AFAICT, the two parametrizations have 
> roughly the same mean, but a factor of two between variances, so it should be 
> fairly easy to spot whether it is one or the other.)
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: pd@cbs.dk  Priv: pda...@gmail.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] Computing line= for mtext

2012-03-02 Thread ilai
On Fri, Mar 2, 2012 at 1:17 PM, Frank Harrell  wrote:
> Hi Rich and Peter,
>
> What I am trying to do is the right-justify a vector of numbers to the right
> of the y-axis so that the leftmost digit of all of the numbers is one
> character to the right of the axis line.  axis() plots tick marks and

No it doesn't (not always)

> left-justifies the numbers.

For axis(4). If you really want right justify on the right hand side,
you could use axis(2) with negative line numbers (device size
dependent). Or you could try something like

plot(1:20)
axis(2,at=seq(1,20,4),labels=T,tick=F,las=T,pos=c(22.25,1))

Hope this is getting there (after only 6 messages...)

Elai

>
> Peter's idea:
> -
> Since you're setting your right margin to 5, why
> not just
>
> mtext(s, side=4, las=1, at=5, adj=1, line = 5, cex=1)
> mtext(s, side=4, las=1, at=7, adj=1, line = 5,  cex=2)
>
> i.e. set the line argument to the right margin?
> -
> comes close to what I'm trying to do but I haven't found out how to compute
> "line" from the maximum width over all the strings in the vector being
> plotted vertically, and I'm not sure it scales properly for different cex=.
> strwidth(s, units='inches')/par('cin')[1] doesn't seem to be a complete
> solution.
>
> Thanks
> Frank
>
>
> Richard M. Heiberger wrote
>>
>> Frank,
>>
>> this is it.  It uses Peter's idea.
>>
>>  plot(1:10)
>>  axis(side=2, 1:10, las=1, line=-31.5, lwd=0)
>>  axis(side=4, 1:10, las=1, labels=FALSE)
>>
>> Rich
>>
>>
>> On Thu, Mar 1, 2012 at 6:52 PM, Frank Harrell wrote:
>>
>>> Rich's pointers deals with lattice/grid graphics.  Does anyone have a
>>> solution for base graphics?
>>> Thanks
>>> Frank
>>>
>>> Richard M. Heiberger wrote
>>> >
>>> > Frank,
>>> >
>>> > This can be done directly with a variant of the panel.axis function.
>>> > See function panel.axis.right in the HH package.  This was provided for
>>> me
>>> > by David Winsemius in response to my query on this list in October 2011
>>> > https://stat.ethz.ch/pipermail/r-help/2011-October/292806.html
>>> >
>>> > The email thread also includes comments by Deepayan Sarkar and Paul
>>> > Murrell.
>>> >
>>> > Rich
>>> >
>>> > On Wed, Feb 29, 2012 at 8:48 AM, Frank Harrell wrote:
>>> >
>>> >> I want to right-justify a vector of numbers in the right margin of a
>>> >> low-level plot.  For this I need to compute the line parameter to give
>>> to
>>> >> mtext.  Is this the correct scalable calculation?
>>> >>
>>> >> par(mar=c(4,3,1,5)); plot(1:20)
>>> >> s <- 'abcde'; w=strwidth(s, units='inches')/par('cin')[1]
>>> >> mtext(s, side=4, las=1, at=5, adj=1, line=w-.5, cex=1)
>>> >> mtext(s, side=4, las=1, at=7, adj=1, line=2*(w-.5), cex=2)
>>> >>
>>> >> Thanks
>>> >> Frank
>>> >>
>>> >> -
>>> >> Frank Harrell
>>> >> Department of Biostatistics, Vanderbilt University
>>> >> --
>>> >> View this message in context:
>>> >>
>>> http://r.789695.n4.nabble.com/Computing-line-for-mtext-tp4431554p4431554.html
>>> >> Sent from the R help mailing list archive at Nabble.com.
>>> >>
>>> >> __
>>> >> R-help@ 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.
>>> >>
>>> >
>>> >       [[alternative HTML version deleted]]
>>> >
>>> > __
>>> > R-help@ 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.
>>> >
>>>
>>>
>>> -
>>> Frank Harrell
>>> Department of Biostatistics, Vanderbilt University
>>> --
>>> View this message in context:
>>> http://r.789695.n4.nabble.com/Computing-line-for-mtext-tp4431554p4436923.html
>>>  Sent from the R help mailing list archive at Nabble.com.
>>>
>>> __
>>> R-help@ 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.
>>>
>>
>>       [[alternative HTML version deleted]]
>>
>> __
>> R-help@ 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.
>>
>
> -
> Frank Harrell
> Department of Biostatistics, Vanderbilt University
> --
> View this message in context: 
> http://r.789695.n4.nabbl

Re: [R] Grouped barchart confidence intervals in lattice

2012-03-03 Thread ilai
On Sat, Mar 3, 2012 at 5:48 PM, Nathan Lemoine  wrote:
>  It appears that the subscripts are only passing two values, the center of 
> each group. There should be six values, one for the center of each bar 
> (correct?),

No. That's also why your code doesn't work. x[subscripts] are not the
centroids. To my knowledge there isn't a barchart equivalent to
boxplot.stats which means for placement you need to recalculate the
location of the bars, as is done internally in panel.barchart. This
panel function may need some tweaking depending on complexity of the
real data (for conditioning add [[packet.number()]] / for limits and
scales - a little more work) but hopefully help get you started:

growth <- c(6.6,7.2,6.9,8.3,7.9,9.2,8.3,8.7,8.1,8.5,9.1,9.0)
diet <- as.factor(rep(c("A","B","C"),2,each=2))
coat <- as.factor(rep(c("light","dark"),each=6))
growth.means <- aggregate(growth,list(coat,diet),mean)
growth.errs <- aggregate(growth,list(coat,diet),sd)
require(lattice)
panel.ci <- function(x, y, sdl, groups, subscripts,box.ratio=box.ratio, ...){
 groupS <- as.numeric(groups[subscripts])
 nv <- nlevels(groups)
 w <- box.ratio/(nv*(1 + box.ratio))
 yy <- as.numeric(y)+sdl
 xx <- as.numeric(x)+(3/4)*w*(groupS - (nv + 1)/2)
 panel.barchart(x, y,groups=groups,subscripts=subscripts,...)
 panel.segments(xx,as.numeric(y),xx,yy,lwd=2)
   }
barchart(x~Group.1, groups=Group.2,data=growth.means,sdl=growth.errs$x,
 horiz=F,stack=F,
ylim=c(0,max(growth.errs$x+growth.means$x)+.2), panel=panel.ci)

Cheers
Elai


but I have no idea how to fix that or what I've done wrong. Here's the
(corrected) code I've got so far...
>
> growth <- c(6.6,7.2,6.9,8.3,7.9,9.2,8.3,8.7,8.1,8.5,9.1,9.0)
> diet <- as.factor(rep(c("A","B","C"),2,each=2))
> coat <- as.factor(rep(c("light","dark"),each=6))
>
> growth.means <- aggregate(growth,list(coat,diet),mean)
> colnames(growth.means)[3] <- "growth"
>
> library(lattice)
>
> panel.ci <- function(x, y, subscripts, ...){
>         panel.barchart(x, y, horiz=F, subscripts=subscripts, 
> groups=growth.means$Group.2, ...)
>         panel.segments(x[subscripts], y, x[subscripts], y+0.5)
>         print(x[subscripts])
>     }
>
> barchart(growth~Group.1, groups=Group.2, data=growth.means,
>        col=c(1,2,3),
>        panel=panel.superpose,
>        panel.groups=panel.ci
>        )
>
> Begin forwarded message:
>
>> From: Nathan Lemoine 
>> Date: March 2, 2012 11:53:24 PM EST
>> To: r-help@r-project.org
>> Subject: Grouped barchart confidence intervals in lattice
>>
>> Hi everyone,
>>
>> I'm having trouble adding error bars to a grouped barchart in lattice. I 
>> know that this topic has been addressed quite a bit, as I've been searching 
>> the internet for a while to try to troubleshoot the issue, but I've not been 
>> able to find any solution that I could get working on my data. I was 
>> wondering if someone could look at my code and tell me what I'm doing wrong. 
>> I was hoping somebody's found a way to do this (I'm sure they have) and can 
>> tell me how to fix my code.
>>
>> # Input example data
>>
>> growth <- c(6.6,7.2,6.9,8.3,7.9,9.2,8.3,8.7,8.1,8.5,9.1,9.0)
>> diet <- as.factor(rep(c("A","B","C"),2,each=2))
>> coat <- as.factor(rep(c("light","dark"),each=6))
>>
>> growth.means <- aggregate(growth,list(coat,diet),mean)
>>
>> library(plotrix)
>>
>> growth.errs <- aggregate(growth,list(coat,diet),std.error)
>>
>> # Try using the superpose call with panel.groups results in an error
>>
>> panel.ci <- function(x, y, subscripts, groups...){
>>         panel.barchart(x, y, groups=groups, subscripts=subscripts, 
>> horiz=F,...)
>>         panel.segments(x[subscripts], y, x[subscripts], y+growth.errs$x, col 
>> = 'black')
>>     }
>>
>> barchart(growth~Group.1, groups=Group.2, data=growth.means,
>>         panel=panel.superpose,
>>         panel.groups=panel.ci
>>         )
>>
>> # Try using the generic plot.barchart command gives three error bars, all 
>> are the appropriate sizes, but all are centered in each group and not on the 
>> grouped bars
>>
>> barchart(x~Group.1, groups=Group.2, data=growth.means,
>>         panel=function(x,y,subscripts, groups){
>>           panel.barchart(x,y,horiz=F,groups=groups, subscripts=subscripts)
>>           
>> panel.segments(as.numeric(x)[subscripts],y,as.numeric(x)[subscripts],y+growth.errs$x)
>>         }
>>         )
>>
>> What am I doing wrong?
>>
>> Thanks,
>>
>> Nathan Lemoine
>>
>>
>>
>>
>>
>>
>>
>
>
>        [[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-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.htm

Re: [R] Grouped barchart confidence intervals in lattice

2012-03-04 Thread ilai
packet.number() will retrieve the panel you are working in. With a
third conditioning variable, you now have say a list of *.err$x, one
for each panel/level of 3rd var. In that case you need
dsl[[packet.number()]] to get at the right place in the list (or
[,packet.number()] if it's a matrix etc.). Regarding the calculations,
you could type panel.barchart in the console to see Deepayan's
original. Sorry but I just don't remember what my logic was when
figuring it out (it has been a short while since my last barchart),
was probably just trial and error until it worked.
Best,

On Sun, Mar 4, 2012 at 1:15 PM, Nathan Lemoine  wrote:
> Also, can you tell me where to add the [[packet.number()]] command for 
> condition? I've been trying several things with no luck.
>
> Thanks for helping, sorry if I'm a nuisance, but I'm still learning my way 
> around the more advanced functions and there's no one else at my university 
> that uses R as extensively as I do.
>
> Nathan

On Sun, Mar 4, 2012 at 11:45 AM, Nathan Lemoine
 wrote:
> Thanks! I really appreciate the help, I don't think I ever would have figured 
> that out.
>
> If you don't mind, I like to understand exactly whats going on in the code.
>
> I see groupS identifies the start center of each group and identifies which 
> group each row belongs to
> w calculates the half-width of each bar with respect to the whole group of 
> bars (i.e. a bar with a width of 1in a group of three bars has a half width 
> of 1/6)
> groupS - (nv+1)/2 gives each bar's relative position to the central bar
>
> Am I interpreting these correctly? One thing I don't get is where 3/4 came 
> from.
>
> Anyway, thanks for all of the help. Wouldn't have gotten it on my own
>
> Nathan
>
>
> On Mar 3, 2012, at 9:46 PM, ilai wrote:
>
>> On Sat, Mar 3, 2012 at 5:48 PM, Nathan Lemoine  
>> wrote:
>>> It appears that the subscripts are only passing two values, the center of 
>>> each group. There should be six values, one for the center of each bar 
>>> (correct?),
>>
>> No. That's also why your code doesn't work. x[subscripts] are not the
>> centroids. To my knowledge there isn't a barchart equivalent to
>> boxplot.stats which means for placement you need to recalculate the
>> location of the bars, as is done internally in panel.barchart. This
>> panel function may need some tweaking depending on complexity of the
>> real data (for conditioning add [[packet.number()]] / for limits and
>> scales - a little more work) but hopefully help get you started:
>>
>> growth <- c(6.6,7.2,6.9,8.3,7.9,9.2,8.3,8.7,8.1,8.5,9.1,9.0)
>> diet <- as.factor(rep(c("A","B","C"),2,each=2))
>> coat <- as.factor(rep(c("light","dark"),each=6))
>> growth.means <- aggregate(growth,list(coat,diet),mean)
>> growth.errs <- aggregate(growth,list(coat,diet),sd)
>> require(lattice)
>> panel.ci <- function(x, y, sdl, groups, subscripts,box.ratio=box.ratio, ...){
>>     groupS <- as.numeric(groups[subscripts])
>>     nv <- nlevels(groups)
>>     w <- box.ratio/(nv*(1 + box.ratio))
>>     yy <- as.numeric(y)+sdl
>>     xx <- as.numeric(x)+(3/4)*w*(groupS - (nv + 1)/2)
>>     panel.barchart(x, y,groups=groups,subscripts=subscripts,...)
>>     panel.segments(xx,as.numeric(y),xx,yy,lwd=2)
>>   }
>> barchart(x~Group.1, groups=Group.2,data=growth.means,sdl=growth.errs$x,
>>         horiz=F,stack=F,
>> ylim=c(0,max(growth.errs$x+growth.means$x)+.2), panel=panel.ci)
>>
>> Cheers
>> Elai
>>
>>
>> but I have no idea how to fix that or what I've done wrong. Here's the
>> (corrected) code I've got so far...
>>>
>>> growth <- c(6.6,7.2,6.9,8.3,7.9,9.2,8.3,8.7,8.1,8.5,9.1,9.0)
>>> diet <- as.factor(rep(c("A","B","C"),2,each=2))
>>> coat <- as.factor(rep(c("light","dark"),each=6))
>>>
>>> growth.means <- aggregate(growth,list(coat,diet),mean)
>>> colnames(growth.means)[3] <- "growth"
>>>
>>> library(lattice)
>>>
>>> panel.ci <- function(x, y, subscripts, ...){
>>>         panel.barchart(x, y, horiz=F, subscripts=subscripts, 
>>> groups=growth.means$Group.2, ...)
>>>         panel.segments(x[subscripts], y, x[subscripts], y+0.5)
>>>         print(x[subscripts])
>>>     }
>>>
>>> barchart(growth~Group.1, groups=Group.2, data=growth.means,
>>>        col=c(1,2,3),
>>>        panel=panel.superpo

Re: [R] GLMing with all possible combinations (automatically)

2012-03-07 Thread ilai
Hi
try
glm(Response~ .^2, data=yourdata.frame)

For all predictors (.) and 2-way interactions (^2).
You might also want to see ?drop.terms and ?formula for automating the
construction of all model combinations.

Side note: R is not SAS (fortunately). Interaction is denoted ":", X*Y
is shorthand for X+Y+X:Y. Your "X+Y+X*Y" is redundant.

HTH

On Wed, Mar 7, 2012 at 4:16 AM, Christofer Bogaso
 wrote:
> Dear all, I was working with a GLM model and wondering whether is it
> possible to have a model description with all possible main effects as
> well as all interactions. Currently I do it manually however this will
> become cumbersome if I have large number of variables.
>
> Means suppose I have 3 explanatory variables and want to feed
> automatically with all possible combinations like:
>
>
> glm(Response~1)
>
> glm(Response~X)
> glm(Response~Y)
> glm(Response~Z)
>
> glm(Response~X+Y)
> glm(Response~X+Z)
> glm(Response~Z+Y)
>
> glm(Response~X+Y+X*Y)
> glm(Response~X+Z+X*Y)
>
>  all combinations
> which are possible
>
> Thanks and regards,
>
> __
> 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.


Re: [R] confidence intervals in dotplots in a for loop

2012-03-07 Thread ilai
On Tue, Mar 6, 2012 at 8:55 PM, Byerly, Mike M (DFG)
 wrote:
>
> estimates <-
 c(67.42,30.49,32.95,23.53,10.26,6.03,23.53,0.93,50.72,24.2,25.84,18.54,
 7.16,3.6,9.35,0.33,87.28,37.25,40.16,28.59,13.77,8.92,40.74,1.68,48.28,23.09,
24.49,17.7,6.63,3.28,7.79,0.26,91.63,38.74,41.6,29.74,14.49,9.51,44.16,1.88)
> estimates.m<- matrix(estimates, 8,5)
> colnames(estimates.m) <- list("est","lci90","uci90","lci95","uci95")
> id <- c(1,1,2,2,3,3,4,4)
> size <- c("All","All","Large","Large","Medium","Medium","Small","Small")
> gear <- rep(c("Camera","Dredge"),4)
> cds.est <- data.frame(id,size,gear,estimates.m)

# From this point try this instead:

library(lattice)
library(gridExtra)
 dat <- by(cds.est,cds.est$id,function(x) x)
 plots <- lapply(dat,function(dat){
   dotplot(gear ~ est , data=dat, xlim = c(min(dat$lci95-10),
 max(dat$uci95 +10)), xlab='Density (num / Nmi^2)',
   main = as.vector(unique(dat$size)),
   panel=function(x,y) {
  panel.xyplot(x,y,pch=16,cex=1)

panel.segments(dat$lci95,as.numeric(y),dat$uci95,as.numeric(y),
lty=1, col=1)

panel.segments(dat$lci90,as.numeric(y),dat$uci90,as.numeric(y),
lty=1,lwd=4, col='grey60')
  panel.xyplot(x,y,pch=16,cex=1.2,col='white')
  panel.xyplot(x,y,pch=1,cex=1.1, col='black')
   }
  )
})
do.call(grid.arrange, plots)

> # cds.est data frame and stores the plots in a list.  Since dotplot() is
> part of the # lattice package, I used grid.arrange to tile the plots.

In my opinion you are going about it the wrong way. You are not using
any of the functionality provided by lattice or dotplot for scaling
and panel arrangement. All you use are panel.xyplot and
panel.segments, manually calculating limits, labels and arranging the
plots yourself - you could have just done this in base graphics (and a
loop). But if that's how you want it to look...

HTH

>
>
>
> library(grid)
>
> library(gridExtra)
>
>
>
> id2 <- 1:max(cds.est$id)
>
> plots <- vector("list", length(id2))
>
> j <- 0
>
> for (i in id2) {
>
>                dat <- cds.est[cds.est$id == i,]
>
>                plots[[ j <- j+1]] <-
>
>                dotplot(gear ~ est , data=dat, xlim = c(min(dat$lci95
> -10), max(dat$uci95 +10)), xlab='Density (num / Nmi^2)',
>
>                main = as.vector(unique(dat$size)),
>
>                panel=function(x,y) {
>
>                                panel.xyplot(x,y,pch=16,cex=1)
>
>
> panel.segments(dat$lci95,as.numeric(y),dat$uci95,as.numeric(y), lty=1,
> col=1)
>
>
> panel.segments(dat$lci90,as.numeric(y),dat$uci90,as.numeric(y), lty=1,
> lwd=4, col='grey60')
>
>
> panel.xyplot(x,y,pch=16,cex=1.2,col='white')
>
>                                panel.xyplot(x,y,pch=1,cex=1.1,
> col='black')
>
> })
>
>
>
> }
>
> do.call(grid.arrange, plots)
>
>
>
> # The script runs and produces all the plots with the correct estimates,
> but the CI's are not
>
> # plotting correctly.  Does anyone have suggestions on what is causing
> this?
>
>
>
> Thanks, Mike
>
>
>
>
>
>
>
>
>        [[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-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 eliminate for next loops in this script

2012-03-07 Thread ilai
?by  ?aggregate

On Tue, Mar 6, 2012 at 4:14 PM, Walter Anderson  wrote:
> I needed to compute a complicated cross tabulation to show weighted means
> and standard deviations and the only method I could get that worked uses a
> series of nested for next loops.  I know that there must be a better way to
> do so, but could use some assistance pointing the way.
>
> Here is my working, but inefficient script:
>
> library(Hmisc)
> rm(list=ls())
> load('NHTS.Rdata')
> day.wt <- day[c("HOUSEID","WTTRDFIN", "TRIPPURP","TRVLCMIN")]
> hh.wt <- hh[c("HOUSEID","WTHHFIN","HHSIZE","HHVEHCNT","HOMETYPE")]
> hh.wt$HHBIN <- with(hh.wt,{ cut(HHSIZE,
> breaks=c(0,1,2,3,4,max(HHSIZE)),labels=c("1","2","3","4","5+"),ordered_result=TRUE)})
> hh.wt$VEHBIN <- with(hh.wt,{ cut(HHVEHCNT,
> breaks=c(-1,0,1,2,max(HHVEHCNT)),labels=c("0","1","2","3+"),ordered_result=TRUE)})
> hh.wt$DUTYPE <- factor(hh.wt$HOMETYPE, exclude=c("-7","-8","-9"))
> levels(hh.wt$DUTYPE) <- c("1","1","2","2","2","2","2")  # Convert home
> types to 1=SF and 2=MF
> trips <- merge(day.wt,hh.wt,by="HOUSEID")
> trips$PURPOSE <- factor(trips$TRIPPURP, exclude=c("-9"))
> trips <- trips[c("HOUSEID","HHBIN","VEHBIN","DUTYPE","PURPOSE","WTTRDFIN",
> "WTHHFIN")]
> sink('TripRates.csv')
> cat("HHBIN,VEHBIN,DUTYPE,TRIPPURP,COUNT,MEAN,STD.DEV\n")
> for (per in levels(trips$HHBIN))
>  for (veh in levels(trips$VEHBIN))
>    for (hom in levels(trips$DUTYPE))
>      for (pur in levels(trips$PURPOSE))
>      {
>        cat(per)
>        cat(",")
>        cat(veh)
>        cat(",")
>        cat(hom)
>        cat(",")
>        cat(pur)
>        cat(",")
>        tmp <- subset(trips,
>                      trips$HHBIN == per & trips$VEHBIN == veh &
>                        trips$DUTYPE == hom & trips$PURPOSE == pur,
>                      select=c("HOUSEID","WTTRDFIN", "WTHHFIN"))
>        cat(length(tmp$HOUSEID))
>        cat(",")
>        tmp$tr <- (tmp$WTTRDFIN/365)/tmp$WTHHFIN
>        w.m <- wtd.mean(tmp$tr,weights=tmp$WTHHFIN)
>        w.sd <- sqrt(wtd.var(tmp$tr, weights=tmp$WTHHFIN))
>        cat(w.m)
>        cat(",")
>        cat(w.sd)
>        cat("\n")
>      }
> sink()
>
>        [[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-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] layer plots.

2012-03-09 Thread ilai
It's hard to help if you keep changing the framework of your problem,
first two matrices - now it's a data.frame and a list of subset row
names in a plotting method from whatever package "suprow" comes from.
Regardless, Michael's original answer already gave you a solution:

plot(table1,type='l',lwd=2)
points(table1[list1$node,],col=2,pch=19)

The points are overlayed on the line plot, so they are not "obscured"
if you have 20 or 20M values.


On Fri, Mar 9, 2012 at 11:09 AM, aaral singh  wrote:
> The response much appreciated. They do match up, one is a small subset of
> the other.
>
> I have this:
>> dput(table1)
> structure(list(var1 = c(2L, 4L, 4L, 1L, 423L), var2 = c(3L, 5L,
> 6L, 342L, 3L)), .Names = c("var1", "var2"), class = "data.frame", row.names
> = c("node1",
> "node2", "node3", "node4", "node5"))
>
>> dput(list1)
> structure(list(node = c("node1", "node2")), .Names = "node")
>
> so one table is a 2 X 5 matrix (called table1) and one table is 1 X 2 table
> (called list1).
>
>
> i then type this:
>
>> plot1 <-plot(table,suprow=c(list1$node),"passive")
> to give me a plot of list1
>
> and this:
>
>> plot2 <-plot(table,suprow=c(list1$node),"active")
> to give me a plot of table1
>
> i want to combine plot 1 and 2.
>
> BUT  i know i can do this:
>> plot2 <-plot(table,suprow=c(list1$node),"all") to plot both on the same
> graph,
> but in my actual dataset, the points in list1 are obscured from sight by
> table1, because in reality table 1 may contain 20,000 points and list1 may
> contain 10 points, so i cannot see where my 10 specific nodes of interest
> are on the graph. So i want to plot the graph so that any nodes in list1
> are seen on top of the plot of table 1.
>
>
>
>
> On Fri, Mar 9, 2012 at 5:36 PM, Michael Weylandt [via R] <
> ml-node+s789695n4460118...@n4.nabble.com> wrote:
>
>> Do your matrices "match up" with each other in any meaningful way or
>> do you just want two independent plots on a single page?
>>
>> You should probably provide the dput() output of each table object so
>> we can see what you've got.
>>
>> Michael
>>
>> On Fri, Mar 9, 2012 at 11:07 AM, aoife doherty <[hidden 
>> email]>
>> wrote:
>>
>> > Many thanks for reply.
>> > I have trouble understanding how to use response, i am sorry.
>> > My question is i have two matrices. I then plot two matrices. Then I
>> have 2
>> > seperate plots. I can color the nodes in the plots in two different
>> colors.
>> > Then, how do i merge the two plots to view one overlapping the other?
>> i.e.
>> > to view two sets of data in one 2D space?
>> >
>> > Many thanks
>> >
>> >
>> > On Fri, Mar 9, 2012 at 3:51 PM, R. Michael Weylandt
>> > <[hidden email] >
>> wrote:
>> >>
>> >> No idea what table1, table2 are
>> >>
>> >> plot(1:5, type = "l")
>> >> points(5:1, col = 2)
>> >>
>> >> should get you started.
>> >>
>> >> Michael
>> >>
>> >> On Fri, Mar 9, 2012 at 10:17 AM, aaral singh <[hidden 
>> >> email]>
>>
>> >> wrote:
>> >> > Hello.
>> >> >
>> >> > I have 2 plots.
>> >> >
>> >> >> plot1 <-plot(table1)
>> >> >> plot2 <-plot(table2)
>> >> >
>> >> > How may i plot these both on the same graph, i.e. layer one graph on
>> top
>> >> > of
>> >> > the other one.
>> >> > The result should look similar to this the image below, where the
>> black
>> >> > lines indicate one plot, and the red dots indicate the second plot.
>> >> >
>> >> > http://r.789695.n4.nabble.com/file/n4459732/R_screen_shot.png
>> >> >
>> >> > Aaral.
>> >> >
>> >> >
>> >> > --
>> >> > View this message in context:
>> >> > http://r.789695.n4.nabble.com/layer-plots-tp4459732p4459732.html
>> >> > 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.
>> >>
>> >> __
>> >> [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.
>> >
>> >
>>
>> __
>> [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.
>>
>>
>> --
>>  If you reply to this email, your message wil

Re: [R] Use different panel functions with lattice

2012-03-10 Thread ilai
On Sat, Mar 10, 2012 at 9:33 AM, Balaitous  wrote:
> Hi,
>
> I have a data.frame df with
> names(df) = c("Var1", "Var2", "Var3", "Var4")
>
> and I plot data with
>
> xyplot(Var1+Var2~Var3|Var4, data=df)
>
> I want to use different panel functions for Var1 and Var2.
> How can I do ?

You didn't specify which "different panel functions" you want. Is
something like this what you're looking for?

 xyplot(Var1+Var2~Var3|Var4, data=df, panel=panel.superpose,
 panel.groups=function(x , y , group.number , ...){
 panel.xyplot(x , y[group.number==1] , ...)
 panel.lines(x , y[group.number==2] , lwd=2 , col=1)
})


>
> Something like :
>
> panel.mypanel = function(x, y, ...) {
>  if (Var1) panel.Var1Panel(x, y, ...)
>  else panel.Var2Panel(x, y, ...)
> }
> xyplot(Var1+Var2~Var3|Var4, data=df, panel=panel.mypanel)
>
> (I have search with google, but I found nothing)
>
> Thanks
>
> __
> 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.


Re: [R] Use different panel functions with lattice

2012-03-10 Thread ilai
Inline

On Sat, Mar 10, 2012 at 1:47 PM, Balaitous  wrote:
> Le samedi 10 mars 2012 à 12:25 -0700, ilai a écrit :
>> On Sat, Mar 10, 2012 at 9:33 AM, Balaitous  wrote:
>
> Var1 and Var2 are 2 two different observed variables (with different scales)

You might want to consider scales=list(y=list(relation='free')) in ?xyplot

> Var3 is the time
> Var4 is the point of observation
>
> I have also a Var5 for groups, but I just want groups for the Var1.



>
> But I don't know how to make the test
>  if(Varx)

> in the function panel.mypanel, because I need
>
> Var1 -> panel.superpose (It's OK)
> Var2 -> panel.lines (I don't want groups for this)
>
> (And I will have others variables with other panel functions to use)
>

Since outer=T (i.e. Var1 and Var2 are in different panels), at the
beginning of the panel or panel.groups function, try

if(packet.number() %in% 1:3) {
panel.rect(x,y,groups,...)  # or whatever for panels 1:3
}
else{
panel.rect(x,y,groups,col=constant,...) # or some other stuff for panels 4:6
}

Hope that works better.



>> >
>> > Something like :
>> >
>> > panel.mypanel = function(x, y, ...) {
>> >  if (Var1) panel.Var1Panel(x, y, ...)
>> >  else panel.Var2Panel(x, y, ...)
>> > }
>> > xyplot(Var1+Var2~Var3|Var4, data=df, panel=panel.mypanel)
>> >
>> > (I have search with google, but I found nothing)
>> >
>> > Thanks
>> >
>> > __
>> > 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.


Re: [R] barplot and NA

2012-03-12 Thread ilai
 d2 <- as.matrix(c(2,NA,4))
 barplot(d2,beside=T)
 barplot(c(d2))
 barplot(na.omit(d2))
 d2[2,] <- 0
 barplot(d2)

# So barplot is not "stopping" at the first NA (first 2 plots). But
what does stacking even mean when you have a missing group in the
middle ? you can't expect barplot to know... if you think it means 0
and the rest can just be stacked on top - define it that way.

Cheers

On Sun, Mar 11, 2012 at 10:22 PM, John D. Muccigrosso
 wrote:
> Am I wrong that barplot is supposed to just skip NAs, and continue with the 
> rest of the data in a matrix column? That's how I read various posts on the 
> subject.
>
> But that's not what happens for me with R64.app (on a Mac, obviously). For 
> example:
>
> d0 <- as.matrix(c(2,3,4))
> d1 <- as.matrix(c(2,3,NA))
> d2 <- as.matrix(c(2,NA,4))
> d3 <- as.matrix(c(NA,3,4))
> barplot(d0)
> barplot(d1)
> barplot(d2)
> barplot(d3)
>
> generates four bar plots. The first has one bar with three visible bands, as 
> expected. The second has two bands; still OK. But the third has only one band 
> (at 2) and the fourth has none.
>
> So it appears that barplot is barfing on those NAs and stopping its plot at 
> those points.
>
> Is that the expected behavior?
>
> Thanks.
>
> John
>
> __
> 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.


Re: [R] 3D Black-Scholes Graph Help!

2012-03-13 Thread ilai
On Tue, Mar 13, 2012 at 3:34 PM, David Winsemius  wrote:
>
> When I got around to running it I was hampered by a lack of knowledge about
> what sort of data-object "price" might have been. I tried putting in a
> single number on hte theory that it would saitisfy the seq() call, and also
>  got the error you report. More input is needed from the OP about the
> problem specification, and hopefully she will provide a test dataset.

It is just a number. The OP function works fine, the error was
generated by wireframe because of the "partial" data passed to formula
- OptionPrice is a matrix, not a column in the grid data.frame which
only holds the scales.

Anna, Replace call to wireframe in your function with

wireframe(OptionPrice,main="3D Option", drape=T, col.regions=heat.colors(100),
scales = 
list(arrows=F,x=list(at=1:length(t),labels=t),y=list(at=1:length(s),labels=s)))

Then:
plotbs(16)

Note, the first value is always NaN but that's from your calculations
- look at the OptionPrice matrix.

Cheers
Elai



> --
> David.
>
>
>>
>> Berend
>>
>
> David Winsemius, MD
> West Hartford, CT
>
> __
> 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.


Re: [R] Visualising multiple response contingency tables

2012-03-13 Thread ilai
Not sure I understand your question (or if there is one) and I am not
familiar with vcd::mosaic. But if you are asking is there a simpler
way ? than yes:
1. work with ?array and ?aperm
2. create the array directly in R from the original data - not excel
3. ?mosaicplot (no package required - it's in grid)

Here is what I mean based on your f.tbl:

>> f.tbl = structure(c(10, 15, 25, 45, 30, 50), .Dim = 2:3, .Dimnames = 
>> structure(list(Sex = c("F", "M"), Responses = c("A", "B", "total 
>> subjects")), .Names = c("Sex", "Responses")), class = "table")

# Calculate the No-A No-B columns:
(ff.tbl <- rbind(f.tbl[,1:2],f.tbl[,3]-f.tbl[,1:2]))
# rearrange to a CxRxB (in this case 2x2x2) array:
dim(ff.tbl) <- c(2,2,2)
# give some names
 dimnames(ff.tbl) <- list(Sex=c('F','M'),c('yes','no'),Response=c('A','B'))
ff.tbl
# plot
 mosaicplot(ff.tbl)
# or plot
mosaicplot(aperm(ff.tbl,3:1))
# or test
apply(ff.tbl, 3 , chisq.test) # and sum the result


Hope this helps get you started


> f.tbl   Responses


> Sex  A  B total subjects
>  F 10 25             30
>  M 15 45             50
>
>
> The answer I have is to adjust my data and then use the mosaic() function
> in package:vcd; however, I'm not sure that's the best way forward and I
> don't have a very efficient way of getting there. I will present my
> solution so you guys can take a look.
>
> The fundamental problem is that because of the multiple response data, you
> can't simply apply a normal Chi-square test to the contingency table.
> There's a raft of approaches, but I've decided to use a simple technique
> introduced by (A. Agresti, I. Liu, Modeling a categorical variable allowing
> arbitrarily many category choices, Biometrics 55 (1999) 936-43.) and
> refined by Thomas and Decady and Bilder and Loughin. In summary, the test
> statistic (a modified Chi square statistic) is calculated by summing up the
> individual chi-square statistics for each of the c marginal r в 2 tables
> relating the single response variable to the multiple response variable
> with df = c(r - 1)). Note, that instead of using the row totals (total
> number of responses) the test statistic is calculated with the total number
> of subjects per row.
>
> (phew, I hope that made sense :) ) Unfortunately, my google-research has
> not revealed an easy way to transform my one data table into c x r x 2
> tables for analysis. So I end up having to create the two different tables
> myself, shown below (note that the Not-A/B columns are calculated as the
> difference between the main data column (A/B) and the total number of
> subjects listed above.
>
>> g.mtrx=matrix(c(10,15,20,35),nrow=2)> g.tbl=as.table(g.mtrx)> 
>> dimnames(g.tbl)=list(Sex=c("F","M"),Responses=c("A","Not-A"))> g.tbl   
>> Responses
> Sex  A  Not-A
>  F  10     20
>  M  15     35
>
>> h.tbl=as.table(h.mtrx)> h.mtrx=matrix(c(25,45,5,5),nrow=2)> 
>> h.tbl=as.table(h.mtrx)> 
>> dimnames(h.tbl)=list(Sex=c("F","M"),Responses=c("B","Not-B"))> h.tbl   
>> Responses
> Sex  B Not-B
>  F 25     5
>  M 45     5
>
>
> If I then preform the normal Chi-square test on each of the two tables
> (chisq.test()) and then sum up the results, I get the answer I want.
> Clearly this is cumbersome, which is why I do it in Excel at the moment (I
> know shame on me). However, I really want to take advantage of the mosaic
> function in vcd. So what I have to do at the moment is create the tables
> above and use abind() (package:abind) to bring my two matrices together to
> form a multidimensional matrix. Example:
>
>> gh.abind = abind(g.mtrx,h.mtrx,along=3)> 
>> dimnames(gh.abind)=list(Sex=c("F","M"),Responses=c("Yes","No"),Factors=c("A","B"))>
>>  gh.abind, , Factors = A
>
>   Responses
> Sex Yes No
>  F  10 20
>  M  15 35
>
> , , Factors = B
>
>   Responses
> Sex Yes No
>  F  25  5
>  M  45  5
>
> Now I can use the simple mosaic function to plot the combined matrix
>
>> mosaic(gh.abind)
>
> So that's it. I don't use any pearson-r shading in mosaic since I
> don't think it would be appropriate to try and model my weird multiple
> response tables (at the moment), but what I will do is look at the
> odds-ratio table and then manually colour the mosaic cells with high
> odds-ratios (greater than 2).
>
> I am literally having to type all this by hand into R, and as you can
> imagine, it gets cumbersome with large multi column tables (which I
> have). Does any body have any thoughts on my approach of using mosaic
> for this sort of data? And if so, any insight on how I can be a bit
> slicker with my R code?
>
> All help is appreciated and I hope that this question wasn't too long
> to read through.Not sure I uderstand your question (or if there is one) and I 
> am not familiar with vcd::mosaic. But if you are asking is there a simpler 
> way ? than yes:
1. work with ?array and ?aperm not tables
2. create the array directly in R from the original data
3. ?mosaicplot (no package required - it's in grid)

Here is what I mean based on your f.tbl:
>> f.tbl = structu

Re: [R] help with expression

2012-03-14 Thread ilai
On Wed, Mar 14, 2012 at 8:56 AM, Thomas Hoffmann
 wrote:
> Hi all,
>
> I still fail to plot an axis title with the following expression:
>
> plot(0,xlab=expression('(SOC [' * kgm^{-2} * '])' * ^{-2}))
>
> the xlab should look like:   (SOC [kgm^2])^0.25
>
> with an out bracket and a superscript.
>

Like this ?
plot(0,xlab=expression(paste('(SOC[',kgm^-2,'])'^0.25,sep='')))


> Thanks for your advice.
>
> Thomas
>
>
>        [[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-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] Needing a better solution to a lookup problem.

2012-03-14 Thread ilai
You could try doing it without a loop (.C or other):

 (rgnsnp <- merge(region,snps))
 (rgnsnp[with(rgnsnp,STOP>=POS & POS >= START),])

Here is my test for merge+search on 100k/200k:

fdf1 <- data.frame(chr=1:10,p=runif(10),d=sample(10))
fdf2 <- data.frame(chr=rep(1:10,2),s=runif(20),t=runif(20))
system.time(with(FDF <- merge(fdf2,fdf1),FDF[s>=p & p >= t,]))
   user  system elapsed
  2.560   0.152   2.905

 Hope this helps
Elai

On Wed, Mar 14, 2012 at 1:27 PM, Davis, Brian  wrote:
> I have a solution (actually a few) to this problem, but none are 
> computationally efficient enough to be useful.  I'm hoping someone can 
> enlighten me to a better solution.
>
> I have data frame of chromosome/position pairs (along with other data for the 
> location).  For each pair I need to determine if it is with in a given data 
> frame of ranges.  I need to keep only the pairs that are within any of the 
> ranges for further processing.
>
> Example:
> snps<-NULL
> snps$CHR<-c("1","2","2","3","X")
> snps$POS<-as.integer(c(295,640,670,100,1100))
> snps$DAT<-seq(1:length(snps$CHR))
> snps<-as.data.frame(snps, stringsAsFactors=FALSE)
>
>  snps
>  CHR  POS DAT
> 1   1  295   1
> 2   2  640   2
> 3   2  670   3
> 4   3  100   4
> 5   X 1100   5
>
> region<-NULL
> region$CHR<-c("1","1","2","2","2","X")
> region$START<-as.integer(c(10,210,430,650,810,1090))
> region$STOP<-as.integer(c(100,350,630,675,850,))
> region<-as.data.frame(region, stringsAsFactors=FALSE)
>
> region
>  CHR START STOP
> 1   1    10  100
> 2   1   210  350
> 3   2   430  630
> 4   2   650  675
> 5   2   810  850
> 6   X  1090 
>
>
> The result I need would look like
>
> Res
>
>  CHR  POS DAT
>   1  295   1
>   2  670   3
>   X 1100   5
>
>
> I have a solution that works reasonably well on small sets, but my current 
> data set is ~100K snp entries, and my regions table has ~200K entries. I have 
> ~1500 files to go through
>
> I haven't found a good way to efficiently solve this problem.  I've tried 
> various versions of mapply/lapply, for loops, etc which get the answer for 
> small sets but takes hours (per file) on my real data.  Bioconductor seemed 
> like the obvious place to look, but my GoogleFu must not be that great.  I 
> never found anything relevant.
>
> Any ideas or points to the right direction would be greatly appreciated.
>
>
>
> Brian Davis
>
> __
> 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.


Re: [R] Adding mean values to boxplots

2012-03-15 Thread ilai
You want to assign your call to boxplot as an object that contains the
plot information

set.seed(1)
b <- matrix(rgamma(100,(1:4)/2,.5),nc=4)
(bxp <- boxplot(b))

Now you can use the info in bxp for placement, e.g.:

text(1:length(bxp$names),bxp$stats[3,],round(bxp$stats[3,],2),pos=3)

By the way, the "line in the middle" is the median, not the mean.

 points(apply(b,2,median),col=2,pch='x')
 points(colMeans(b),col=2)


HTH


On Thu, Mar 15, 2012 at 6:04 AM, Cleland  wrote:
> Hello there,
>
> I was wondering if anyone might be able to help me as I'm pretty new to R.
> I'm trying to create a boxplot from a data table returned from an sproc. I
> have the following code, which generates the plot as I'd like it:
>
> library("RODBC");
> conn <- odbcConnect("datawarehouse"); # connect to datawarehouse
> results <- sqlQuery(conn, "call sproc)");
> ylab <- 'Percentage (%)'
> main = 'Productivity Overview - 6 mnths';
> par(mai=c(1.5,1,1,0.2), las = 2, xpd=TRUE, cex.axis=0.8, cex.lab=0.8);
> col = c('forestgreen', 'forestgreen', 'forestgreen', 'chocolate',
> 'chocolate', 'chocolate', 'goldenrod', 'goldenrod', 'goldenrod');
> b <- results[,4:12]
> boxplot(b, col=col, ylab=ylab, main=main, boxwex=0.4);
>
> What i'd like to do is add the mean value, demarcated by the black line in
> the middle of each box, to the plot. The only way I've managed to add values
> previously is by specifying their exact value and location on the plot e.g.
>
> text(1.4,2.139,format("Mean (2.14)",digits=2), cex=1);
>
> I need these values to be dynamic in the sense that they will be different
> each time the graph is generated (based on the parameters passed through the
> sproc) and will need to be in a different position each time (i.e. in-line
> with the mean for each box).
>
> I'm uncertain about a. whether this is possible in R and b. if it is
> possible, how best I could achieve it.
>
> If anyone has any advice it would be gratefully received.
>
> Thanks in advance.
>
> Tom
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Adding-mean-values-to-boxplots-tp4474700p4474700.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.


Re: [R] coloring wireframe plot with independent/separate matrix of color values.

2012-03-15 Thread ilai
On Wed, Mar 14, 2012 at 9:47 PM, Alex Miller  wrote:
> Dear R Users,
>
> I am trying to plot a matrix (a Digital Elevation Model) using wireframe
> [lattice] and color that matrix based on a separate/independent matrix of
> the same resolution

This makes no sense. the values in DEM are the z-coords of corners,
not centroids of the facet. A matrix of colors of the same dimensions
is not going to work as col.regions

 cloud(outer(1:3,1:3),par.box=list(col=NA),type='p',col=1:9)
 wireframe(outer(1:3,1:3)) # 1:9 makes no sense.

I don't know of an easy way to drape color by something other than the
default "height".  You could maybe modify the shade.colors.palette
function so it returns the colors in your temp matrix.  More details
in ?panel.3dwire

Best,


(both have the same number of rows and columns) as the
> DEM.  More specifically I would like to plot a DEM using wireframe and
> color each cell/tile based on interpolated surface temperature
> measurements.  Within the wireframe function, the arguments
> "color.regions", "drape" and "at" seemed most important to accomplish
> this.  However, I have not been successful.  Below is another explanation
> with some example data.
>
> ###
>
> #say we have a matrix
>
> DEM=matrix(1:100, ncol=10)
>
> #we also have a matrix of interpolated temperatures measurements (or any
> other kind of data with the same resolution as the DEM)
>
> interpTEMP = matrix(floor(runif(100, 1,10)),ncol=10)
>
> #I would normally go through and apply a function to use html color codes
> to coincide with interpTEMP but these values will prove my dilemma.
>
> #now I would like to plot my DEM and color each cell based on the
> "matching" cell of interpTEMP
> #N.B. that this obviously isn't the correct way of doing things as it
> doesn't work!
>
> wireframe(x=DEM, drape=TRUE, col.regions=as.vector(interpTEMP))
>
> ###
>
> any ideas on how to combat this problem?  Please let me know if I need to
> be more clear or provide additional information.  Many blessings for your
> help!
>
> .alex
>
>        [[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-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] Dotplot: how to change size in the y lab ?

2012-03-19 Thread ilai
On Mon, Mar 19, 2012 at 7:56 AM, Jose Bustos Melo  wrote:
> Hi everyone,
>
> I'm trying to reduce the font size in the Y  exe in this plot:

> dotplot( bank ~ MV2007 + MV2009 , data = d, horiz = T,
 par.settings = list(  superpose.symbol = list(  pch = 21,  fill = c(
"lightblue", "lightgreen"),  cex = 4,  col = "black"   ) ) , xlab =
"Market value ($Bn)", key = k,  panel = function(x, y, ...){
panel.dotplot( x, y, ... ) grid.text(  unit( x, "native") , unit( y,
"native") ,  label = x, gp = gpar( cex = .7 ) ) } ### add this
, scales=list(y=list(cex=.5))

)

Cheers


> Thank you in advance!
> José
>
>        [[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-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] Remove wireframe outer box but keep ticks

2012-03-23 Thread ilai
See 'box.3d' in trellis.par.get() :

 wireframe(z ~ x*y, data = test,
 scales=list(arrows=F),
 par.settings = list(box.3d = list(col=NA)))

Note you can have some finer control:

wireframe(z ~ x*y, data = test,
scales=list(arrows=F),
par.settings = list(box.3d = list(col=c(1,2,NA,NA,3,NA,4,5,6)))
)

Hope this helps


On Fri, Mar 23, 2012 at 3:59 AM, Bigelow, Seth W -FS  wrote:
> I would like to eliminate the outer box around a lattice wireframe graph, but 
> the usual recommended solution, which is to assign a color of 'transparent' 
> to the axis.line parameter,
> eliminates ticks if the 'arrows=F' command is used, as shown in the following 
> example:
>
> test = data.frame(expand.grid(c(1:10), c(1:10)))
> z = test[,1] + test[,2]
> test = cbind(test, z)
> names(test) = c("x", "y", "z")
> require(lattice)
> wireframe(z ~ x*y, data = test,
> scales=list(arrows=F),
> par.settings = list(axis.line = list(col = "transparent")),
> )
>
> Is there a way to eliminate the box but keep the ticks?
>
>
> Seth W. Bigelow, Ph.D.
> Research Ecologist
> USDA-FS Pacific Southwest Research Station
> Ph: (802)-379-3444
>
>
>
>
>
> This electronic message contains information generated by the USDA solely for 
> the intended recipients. Any unauthorized interception of this message or the 
> use or disclosure of the information it contains may violate the law and 
> subject the violator to civil or criminal penalties. If you believe you have 
> received this message in error, please notify the sender and delete the email 
> immediately.
>
>        [[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-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] Remove wireframe outer box but keep ticks

2012-03-23 Thread ilai
On Fri, Mar 23, 2012 at 2:07 PM, Bigelow, Seth W -FS  wrote:
> ilai/keren:
>
> Thanks for your response. It's not the 3d bounding box that I wish to 
> eliminate, but the box that surrounds the whole figure and is drawn 
> automatically (I call this the outer box, in contrast to the inner, 3d 
> bounding box).

Hmm... But than what you called 'the usual way' should work. Maybe you
just overlooked "resetting" the scales list? Is this what you want?

wireframe(z ~ x*y, data = test,
scales=list(arrows=F,col=1),
par.settings = list(axis.line = list(col = "transparent")))


The ticks attached to the bounding box are connected, in the software,
to the outer box. I'm assembling a number of these graphs on one page,
and the outer box makes the whole figure look clunky. Lattice is an
incredible piece of software! but these small details can be difficult
to nail down.
>
> --Seth
>
> -Original Message-
> From: ila...@gmail.com [mailto:ila...@gmail.com] On Behalf Of ilai
> Sent: Friday, March 23, 2012 11:10 AM
> To: Bigelow, Seth W -FS
> Cc: r-help@r-project.org
> Subject: Re: [R] Remove wireframe outer box but keep ticks
>
> See 'box.3d' in trellis.par.get() :
>
>  wireframe(z ~ x*y, data = test,
>  scales=list(arrows=F),
>  par.settings = list(box.3d = list(col=NA)))
>
> Note you can have some finer control:
>
> wireframe(z ~ x*y, data = test,
> scales=list(arrows=F),
> par.settings = list(box.3d = list(col=c(1,2,NA,NA,3,NA,4,5,6)))
> )
>
> Hope this helps
>
>
> On Fri, Mar 23, 2012 at 3:59 AM, Bigelow, Seth W -FS  
> wrote:
>> I would like to eliminate the outer box around a lattice wireframe
>> graph, but the usual recommended solution, which is to assign a color of 
>> 'transparent' to the axis.line parameter, eliminates ticks if the 'arrows=F' 
>> command is used, as shown in the following example:
>>
>> test = data.frame(expand.grid(c(1:10), c(1:10))) z = test[,1] +
>> test[,2] test = cbind(test, z)
>> names(test) = c("x", "y", "z")
>> require(lattice)
>> wireframe(z ~ x*y, data = test,
>> scales=list(arrows=F),
>> par.settings = list(axis.line = list(col = "transparent")),
>> )
>>
>> Is there a way to eliminate the box but keep the ticks?
>>
>>
>> Seth W. Bigelow, Ph.D.
>> Research Ecologist
>> USDA-FS Pacific Southwest Research Station
>> Ph: (802)-379-3444
>>
>>
>>
>>
>>
>> This electronic message contains information generated by the USDA solely 
>> for the intended recipients. Any unauthorized interception of this message 
>> or the use or disclosure of the information it contains may violate the law 
>> and subject the violator to civil or criminal penalties. If you believe you 
>> have received this message in error, please notify the sender and delete the 
>> email immediately.
>>
>>        [[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-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] Updating a Markov Chain

2012-03-26 Thread ilai
On Sun, Mar 25, 2012 at 3:50 PM, stivi  wrote:
> Hello,
>
> my question is if anyone has any good ideas how to create a Markov Chain
> from ordered data. So, I have some sort of time series, and if value1
> happens as time1 and value2 happens at time2 I record this as an update to
> the probability transition matrix. The problem is that I cannot predefine
> the size of the matrix (as I don't know how many states(values) I will have
> in the end)

You could create a iter x n matrix of NA's and fill it up with a loop.
Or an empty list
 ll <- list()
 for(i in 1:3) ll[[i]] <- sample(10,i)
 ll
Or, not very efficient, but you can also avoid predefining with something like
trans.prob <- .5
set.seed(1)
for(i in 2:12){
# if(some conditions) or calcs
trans.prob <- c( trans.prob , rbeta(1,12,1,trans.prob[i-1]) )
}
plot(trans.prob,type='l')

and don't really know how to update the prob distribution in the
> rows.

in a loop:
trans.prob.matrix[i, ] <- some.update.fun

> If anyone has any thoughts, i would be grateful for sharing.

If you'd read the posting guide and contemplated some existential
questions like "is it OK if the question (even if it's not) sounds
like homework ?" and "what's this obsession with providing minimal,
reproducible code ? " than maybe the smaRter than me on this list will
be more inclined to share their thoughts ...

Cheers
Elai


> Stivi
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Updating-a-Markov-Chain-tp4504156p4504156.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.


Re: [R] assigning vector or matrix sparsely (for use with mclapply)

2012-03-27 Thread ilai
It is (at least for me) really unclear what the problem is, or how
it's related to mclapply.
You say
" this works fine, except that what I want to get NA's in the return
 positions that were not recalculated.  then, I can write
>
>  newdata$y <- ifelse ( is.na(olddata$y), mc.byselectrows( olddata,
> is.na(olddata$y), fun.calc.y ), olddata$y )
"
Why ???
Are you applying the function twice ?  than why not simply
v1.1 <- mc.byselectrows( d, loc<1, function(x) x[,2]^2 )
the second time ?

If the problem is in keeping track of which rows got calculated, why
not rename with the row.names omitted after mclapply (probably a good
idea anyway):

FUN.ON.ROWS <- function(.index, ...)
as.matrix(FUN(data.notdone[.index,], ...))
  soln <- mclapply( as.list(1:nrow(data.notdone)) , FUN.ON.ROWS, ... )
  rv <- do.call("rbind", soln)  ## omits naming.
  if (ncol(rv)==1){ rv <- as.vector(rv) ; names(rv) <- row.names(data.notdone) }
  else rownames(rv) <- row.names(data.notdone)
 rv
}

And finally, you don't even need row.names for c(v1,d[loc<1,2])

Or am I missing something here ?

BTW your code uses cat.stderr (which is local ? ) instead of cat, and
has no call to multicore.

Cheers



>
On Mon, Mar 26, 2012 at 4:28 PM, ivo welch  wrote:
> Dear R wizards---
>
> I have a wrapper on mclapply() that makes it a little easier for me to
> do multiprocessing.  (Posting this may make life easier for other
> googlers.)  I pass a data frame, a vector that tells me what rows
> should be recomputed, and the function; and I get back a vector or
> matrix of answers.
>
>   d <- data.frame( id=1:6, val=11:16 )
>   loc <- c(TRUE,TRUE,FALSE,TRUE,FALSE,TRUE)
>   v1 <- mc.byselectrows( d, loc, function(x) x[,2]^2 )
>   v2 <- mc.byselectrows(d, loc, function(x) cbind(x[,2]^2,x[,2]^3))
>
> mc.byselectrows <- function(data.in, recalclist, FUN, ...) {
>
>   data.notdone <- data.in[recalclist,]
>   cat.stderr("[mc.byselectrows: ", nrow(data.notdone), "rows to be
> recomputed out of", nrow(data.in), "]\n")
>
>   FUN.ON.ROWS <- function(.index, ...)
> as.matrix(FUN(data.notdone[.index,], ...))
>   soln <- mclapply( as.list(1:nrow(data.notdone)) , FUN.ON.ROWS, ... )
>   rv <- do.call("rbind", soln)  ## omits naming.
>   if (ncol(rv)==1) rv <- as.vector(rv)
>   rv
> }
>
> this works fine, except that what I want to get NA's in the return
> positions that were not recalculated.  then, I can write
>
>  newdata$y <- ifelse ( is.na(olddata$y), mc.byselectrows( olddata,
> is.na(olddata$y), fun.calc.y ), olddata$y )
>
> I can do this very inelegantly, of course.  I can merge recalclist
> into data.in and then write a loop that substitutes for the do.call to
> rbind.  yikes.  or I could do the recalclist contingency inside the
> FUN.ON.ROWS, but this is costly in terms of execution time.  are there
> obvious solutions?  advice appreciated.
>
> regards,
>
> /iaw
> 
> Ivo Welch (ivo.we...@gmail.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.


Re: [R] xyplot lattice fine control of axes limits and thick marks (with log scale)

2012-03-28 Thread ilai
On Wed, Mar 28, 2012 at 4:21 AM, maxbre  wrote:
> After a long and winding road (sorry but I'm a novice) I get to a final
> result which is quite close to what I need;
> nevertheless I would like to tweak a little further the xyplot

Without dput(mydata) you are the only one who can do that...

so that I can
> get ***for each single panel defined by variable z*** a finer control over:
> -the x and y the limits: I would like to be the same for both axes;

relation='same' in the scales. BTW this is the default, why did you
change to 'free' ?

> -the number of thick marks: again I would like to be same for both axes;

Most modifications of tick marks, labels and limits are easy through
the scales argument. ?xyplot and examples.

Best,
Elai

>
> the (general) code snippet here attached does not get this result;
> any help for this ?
>
> thank you
>
>
> #my example
>
> xyplot(y ~ x | z, data=mydata,
>       aspect="xy",
>       scales= list(x=list(relation="free", log=10),
>                    y=list(relation="free", log=10)),
>
>       prepanel = function(x, y, subscripts) {
>         list(xlim = c(min(x,y), max(x,y)))
>         list(ylim= c(min(x,y), max(x,y)))
>       },
>
>       panel = function(x, y ,subscripts,...) {
>         #panel.xyplot(x, y, xlim = c(min(x,y), max(x,y)), ylim =
> c(min(x,y), max(x,y)),...)
>         panel.xyplot(x, y, ...)
>         panel.abline(a = 0, b = 1, lty = 2, col ="gray")
>         panel.text(x, y, labels=mydata$name[subscripts])
>       },
>
>       subscripts=TRUE,
>       xscale.components = xscale.components.logpower,
>       yscale.components = yscale.components.logpower
>     )
>
> in attachment  http://r.789695.n4.nabble.com/file/n4511897/my_example.png
> my_example.png
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/xyplot-lattice-fine-control-of-axes-limits-and-thick-marks-with-log-scale-tp4511897p4511897.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.


Re: [R] matrix(unlist(strsplit(""))) 'missing value' issue

2012-03-28 Thread ilai
On Wed, Mar 28, 2012 at 6:49 AM, Petr PIKAL  wrote:
> What problem? Nabble is not available to all and here is not much to cook
> from.

Indeed. Also the OP actually provided their own solution, just 5 more
minutes of googling to find ?sub.

bankoffer.3 <- factor(c('999','429000:notaccepted','48000:notaccepted'))
bankoffer.3 <- gsub('99','NA:NA',bankoffer.3)
as.data.frame(matrix(unlist(strsplit(as.character(bankoffer.3),":")),
 ncol = 2, byrow = TRUE))

Cheers


>
>>
>> Nobody any solution for my problem??

>>
>> --
>> View this message in context:
> http://r.789695.n4.nabble.com/matrix-unlist-
>> strsplit-missing-value-issue-tp4509065p4511668.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.

__
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] resampling for correlation and testing

2012-03-28 Thread ilai
On Wed, Mar 28, 2012 at 3:53 PM, Benton, Paul
 wrote:
> Hello all R-er,
>
> I'm trying to run a resampling method on some data. The current method I have 
> takes 2+ days or a lot of memory . I was wondering if anyone has a better 
> suggestion.
>
> Currently I take a matrix and get the correlation matrix from it. This will 
> be called rho.A. Each element in this will be tested against the distribution 
> from the resampled correlation B matrix.
>
> Some example code:
>
> A<-matrix(rnorm(100), ncol=10)
> B<-matrix(rnorm(100), ncol=10)
>
> rho.A<-cor(A)
>
> {
> idx<-sample(1:10, 10)
> idx
> # [1] 8 4 5 7 1 9 2 10 6  3
>
> rho.B<-cor(B[,idx])
> } ## repeat this x time (currently 500)
>
> ## in essence we then have the following :
> rho.arrayB<-array(runif((10*10)*500), dim=c(10,10,500))

Err... no we don't. sample(10,10) ; sample(10,10) ... only permutes
the columns, so the 500 cor(B) have exactly the same values in
different off diag positions. Using runif they are unique
>
> ## Then test if rho.A[1,1] come from the distribution of rho.B[1,1]
> pvalueMat[1,1]<-wilcox.test(rho.array[1,1,] , rho.A[1,1])$p.value
>

>From what I know cor(A)[ i , i ] = cor(B)[ j , j ] = 1   for any
choice of A,B,i and j
I don't think Wilcox intended his test to be used in this way

I would start with fixing these issues first so you don't wait 2 days
for a vector of NaN's

Cheers


> However, my array size would be 2300 x 2300 x 500 which R won't let me even 
> make as an empty structure. Any suggestion are more than welcomed !!
>
> Cheers,
>
> Paul
>
> __
> 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.


Re: [R] resampling for correlation and testing

2012-03-28 Thread ilai
On Wed, Mar 28, 2012 at 8:03 PM, Benton, Paul
 wrote:
>
> On Mar 29, 2012, at 1:41 AM, ilai wrote:
>
>> On Wed, Mar 28, 2012 at 3:53 PM, Benton, Paul
>>  wrote:
>>> Hello all R-er,

 

>>>
>>> ## Then test if rho.A[1,1] come from the distribution of rho.B[1,1]
>>> pvalueMat[1,1]<-wilcox.test(rho.array[1,1,] , rho.A[1,1])$p.value
>>>
>>
>> From what I know cor(A)[ i , i ] = cor(B)[ j , j ] = 1   for any
>> choice of A,B,i and j
>
> No, cor(a)[i, j] != cor(b)[i , j]

Clearly. I was talking about the diagonal elements (which in a
correlation matrix are 1's for all). I didn't look at your function
yet (I'll try to find the time soon) so this may be a mute point, but
I think here maybe the answer to your question. Correct me if I'm
wrong (it's been known to happen from time to time :) but here is how
I see it:

For corr matrices A (n x n) and B (p x p) you "only" need to test each
of lower.tri.A[i,j] where i != j vs. some populations of rho's which
are resamples from the vector of p(p-1) lower.tri.B => you will be
performing n(n-1)500 tests. Still maybe a daunting task for large n,
but much more manageable than creating the full dim array of matrices,
where the diagonal is meaningless and the other half is just a
"repeat". I know - you actually want 1000 resamples, not 500, and in
your original you remove the diagonal, etc. etc. but as you yourself
noted creating even an empty array of these dimensions was not
feasible.

Hope I'm not way off and this helps somewhat
Elai



>
> If your concern is because they are coming from the same distribution then 
> again this is example data. Even then I would imagine that the correlation 
> would be different for small n. Either way resampling the columns will give 
> different  correlation values. Please try the code yourself.





>
>> I don't think Wilcox intended his test to be used in this way….
> Probably true …. care to suggest a different statistical test ?
>
>>
>> I would start with fixing these issues first so you don't wait 2 days
>> for a vector of NaN's
>
> Actually I didn't get a vector or NaN's I got a matrix of pvalues. Which has 
> proved useful. Now I want to make the function faster and was looking for a 
> bit of help.
>
>>
>> Cheers
>>
>>
>>> However, my array size would be 2300 x 2300 x 500 which R won't let me even 
>>> make as an empty structure. Any suggestion are more than welcomed !!
>>>
>>> Cheers,
>>>
>>> Paul
>>>
>>> __
>>> 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.


Re: [R] xyplot lattice fine control of axes limits and thick marks (with log scale)

2012-03-29 Thread ilai
On Thu, Mar 29, 2012 at 3:04 AM, maxbre  wrote:



> To answer your question:
> - I did not put relation=’same’ because that is not what I want: i.e **for
> each single panel** (in my case 4) I want to set the same limits for both x
> and y axes (I want the diagonal line exactly bisect each panel); see what
> happen by putting relation=’same’…(I do not want to group the panels by a
> single x and y axes)
> - I need to set the same number of thick arks for both x and y axes *of each
> panel*, but with log scale it’s quite tricky at least seems so to myself)

Oh. I missed the *for each panel* aspect of your question. I believe
you are 5 key strokes away (the change is to prepanel). Is this what
you want ?

xyplot(tv ~ ms | sub_family, data=tm,
  #as.table=TRUE,
  aspect="xy",
  xlab = expression(paste('ms [ fg/', m^3, ' ]', sep = '')),
  ylab = expression(paste('tv [ fg/', m^3, ' ]', sep = '')),
  scales= list(x=list(relation="free", log=10, cex=0.8),
   y=list(relation="free", log=10, cex=0.8)),
  prepanel = function(x, y, subscripts) {
rr<- range(cbind(x,y))
list(xlim = rr, ylim= rr)
  },
  panel = function(x, y ,subscripts,...) {
panel.xyplot(x, y, cex=0.8,...)
panel.abline(a = 0, b = 1, lty = 2, col ="gray")
panel.text(x, y, labels=tm$name_short[subscripts], cex = 0.8,
pos=3, offset=0.5, srt=0, adj=c(1,1))
  },   subscripts=TRUE,
  xscale.components = xscale.components.logpower,
  yscale.components = yscale.components.logpower
  )

Cheers


>
> Thanks for your help
>
> max
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/xyplot-lattice-fine-control-of-axes-limits-and-thick-marks-with-log-scale-tp4511897p4514868.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.


Re: [R] How to create arbitrary number of loops in R

2012-03-29 Thread ilai
To cbind, you don't need a loop

(M <- matrix(1:50,nc=10))
c2way <- combn(ncol(M),2)
MM <- M[,c2way]
dim(MM) <- c(nrow(M),nrow(c2way),ncol(c2way))
MM

c3way <- combn(ncol(M),3)
MMM <- M[,c3way]
dim(MMM) <- c(nrow(M),nrow(c3way),ncol(c3way))
MMM

etc. etc.

Than you can (untested for icc) loop your function as in
apply(MMM,3,somefun)

cheers

On Thu, Mar 29, 2012 at 7:28 AM, Dai, Hongying,  wrote:
> Dear R users,
>
> I'm wondering how I can generate an arbitrary number of loops in R.
> For instance, I can generate two "for" loops to get ICC among any two-way 
> combination among 10 variables. Here is the code
>
> n<-10
> for (i in 1:(n-1))
> {
> for (j in (i+1):n)
> {
> icc(cbind(DATA[,i],DATA[,j]))
> }
> }
> If I need three-way combination, then a code with three "for" loops will be:
> n<-10
> for (i in 1:(n-2))
> {
> for (j in (i+1):(n-1))
> {
> for (k in (j+1):n)
> {
> icc(cbind(DATA[,i],DATA[,j],DATA[,k]))
> }
> }
> }
> But how can I write a code if I need all m=2, 3, 4,... loops for arbitrary 
> m-way combinations?
> Thanks!
> Daisy
>
>
> 
> Electronic mail from Children's Mercy Hospitals and Clinics. This 
> communication is intended only for the use of the addressee. It may contain 
> information that is privileged or confidential under applicable law. If you 
> are not the intended recipient or the agent of the recipient, you are hereby 
> notified that any dissemination, copy or disclosure of this communication is 
> strictly prohibited. If you have received this communication in error, please 
> immediately forward the message to Children's Mercy Hospital's Information 
> Security Officer via return electronic mail at 
> informationsecurityoffi...@cmh.edu and expunge this communication without 
> making any copies. Thank you for your cooperation.
>
>        [[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-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 create arbitrary number of loops in R

2012-03-29 Thread ilai
On Thu, Mar 29, 2012 at 9:27 AM, ilai  wrote:

Oops, sent to fast. A (maybe) clearer solution:

 f <- function(x,m){
cmway <- combn(ncol(x),m)
xx <- x[,cmway]
dim(xx) <- c(nrow(x),nrow(cmway),ncol(cmway))
xx
}

f(M,3)
str(sapply(2:4,f,x=M))

And again lapply / apply , or even return icc(xx) in f

Cheers

> To cbind, you don't need a loop
>
> (M <- matrix(1:50,nc=10))
> c2way <- combn(ncol(M),2)
> MM <- M[,c2way]
> dim(MM) <- c(nrow(M),nrow(c2way),ncol(c2way))
> MM
>
> c3way <- combn(ncol(M),3)
> MMM <- M[,c3way]
> dim(MMM) <- c(nrow(M),nrow(c3way),ncol(c3way))
> MMM
>
> etc. etc.
>
> Than you can (untested for icc) loop your function as in
> apply(MMM,3,somefun)
>
> cheers
>
> On Thu, Mar 29, 2012 at 7:28 AM, Dai, Hongying,  wrote:
>> Dear R users,
>>
>> I'm wondering how I can generate an arbitrary number of loops in R.
>> For instance, I can generate two "for" loops to get ICC among any two-way 
>> combination among 10 variables. Here is the code
>>
>> n<-10
>> for (i in 1:(n-1))
>> {
>> for (j in (i+1):n)
>> {
>> icc(cbind(DATA[,i],DATA[,j]))
>> }
>> }
>> If I need three-way combination, then a code with three "for" loops will be:
>> n<-10
>> for (i in 1:(n-2))
>> {
>> for (j in (i+1):(n-1))
>> {
>> for (k in (j+1):n)
>> {
>> icc(cbind(DATA[,i],DATA[,j],DATA[,k]))
>> }
>> }
>> }
>> But how can I write a code if I need all m=2, 3, 4,... loops for arbitrary 
>> m-way combinations?
>> Thanks!
>> Daisy
>>
>>
>> 
>> Electronic mail from Children's Mercy Hospitals and Clinics. This 
>> communication is intended only for the use of the addressee. It may contain 
>> information that is privileged or confidential under applicable law. If you 
>> are not the intended recipient or the agent of the recipient, you are hereby 
>> notified that any dissemination, copy or disclosure of this communication is 
>> strictly prohibited. If you have received this communication in error, 
>> please immediately forward the message to Children's Mercy Hospital's 
>> Information Security Officer via return electronic mail at 
>> informationsecurityoffi...@cmh.edu and expunge this communication without 
>> making any copies. Thank you for your cooperation.
>>
>>        [[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-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] Filling empty List in a FOR LOOP

2012-04-01 Thread ilai
On Sun, Apr 1, 2012 at 9:59 AM, michaelyb  wrote:
> Basically I need to read the data from an external source using many R
> commands.
> The problem is that sometimes the source is empty, and I get a list with
> empty values, and I need to substitute them by "NA".
> It is def. not hard, I just don't see how
> In the prvious post, the first example had values on the source, but the
> second example didn't

And neither was reproducible as is this post. There is more than one
way to get an "empty" list. I find R-list helpers are good but lacking
in extrasensory perception skills. Frustrating, but if you insist on
not following the posting guide, then you'll just have to figure it
out for yourself.

 lapply(vector('list',2),function(ll) ifelse(is.null(ll),NA,ll)) # works
 lapply(list("","foo"),function(ll) ifelse(is.null(ll),NA,ll)) # fail
 lapply(list("","foo"),function(ll) ifelse(nchar(ll)<1,NA,ll)) # works
# ...
# from your example 1 seems like you're expecting a matrix, so maybe
you need nrow(ll)
# etc.

HTH


>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Filling-empty-List-in-a-FOR-LOOP-tp4522694p4523731.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.


Re: [R] A contour plot question - vis.gam () function in "mgcv"

2012-04-03 Thread ilai
Try to plot the points first followed by vis.gam(...,type='contour',
color='bw', add=T) instead of vis.gam followed by points.

HTH


On Tue, Apr 3, 2012 at 2:48 PM, Ravi Varadhan  wrote:
> Hi,
>
> Please see the attached contour plot (I am sorry about the big file).  This 
> was created using the vis.gam() function in "mgcv" package.  However, my 
> question is somewhat broader.
>
> In generating this figure, I first created the contours using vis.gam() and 
> then I plotted the points.  These point are plotted on top of the contours so 
> that some of the contour lines are only partially visible.  Is there a way to 
> make the contour lines fully visible?  I cannot reverse the order and plot 
> the points first and then call vis.gam().  Or, can I?  Are there other 
> options?
>
> Thanks for any help or hints.
>
> Best,
> Ravi
>
>
> Ravi Varadhan, Ph.D.
> Assistant Professor
> The Center on Aging and Health
> Division of Geriatric Medicine & Gerontology
> Johns Hopkins University
> rvarad...@jhmi.edu
> 410-502-2619
>
>
> __
> 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.


Re: [R] image.plot adding x-axis labels. Please Help

2012-04-03 Thread ilai
On Tue, Apr 3, 2012 at 7:25 PM, David Lyon  wrote:
> if I had a data file like this:
> 1.42 1.29 -0.13
> 1.46 1.34 -0.12
> 1.45 1.32 -0.13
> 1.36 1.26 -0.10
> 1.33 1.29 -0.04
>
> I want to create a image plot like this:
> data1<-read.table("A")
>
> image.plot(t(data1), axes=FALSE, xlab=NA, ylab=NA)
>
> I cant get the labels for the x axis right can some kind person help me?

axis(1,at=seq(0,1,l=ncol(data1)),labels=LETTERS[1:ncol(data1)])


> axis(1.???.labels=c("A", "B", "C"))
>
>
> Many thanks in advance!
>
> __
> 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.


Re: [R] A contour plot question - vis.gam () function in "mgcv"

2012-04-04 Thread ilai
On Tue, Apr 3, 2012 at 6:22 PM, Peter Ehlers  wrote:
> On 2012-04-03 15:49, ilai wrote:
>>
>> Try to plot the points first followed by vis.gam(...,type='contour',
>> color='bw', add=T) instead of vis.gam followed by points.
>>
>> HTH
>
>
> Or, if vis.gam gives you default scales that you wish to preserve,
> then just replot the contours over the points with
>
>   vis.gam(., add = TRUE)
>
> Peter Ehlers

I would say no. This works as a quick and dirty but as a general rule,
in my view "replot" should be discouraged because of the reduced print
quality of the visible elements from the original. Maybe a minor
issue, but annoying to give a presentation and realize labels in the
plot are all fuzzy when projected on the big screen (never happened to
me of course, I'm talking about a friend...:). To preserve the scales
in this case would be better to explicit set limits
plot(...,pch=19,xlim,ylim) ; vis.gam(., add = TRUE)
rather than
vis.gam()
points()
vis.gam()

Cheers
>
>>
>>
>> On Tue, Apr 3, 2012 at 2:48 PM, Ravi Varadhan  wrote:
>>>
>>> Hi,
>>>
>>> Please see the attached contour plot (I am sorry about the big file).
>>>  This was created using the vis.gam() function in "mgcv" package.  However,
>>> my question is somewhat broader.
>>>
>>> In generating this figure, I first created the contours using vis.gam()
>>> and then I plotted the points.  These point are plotted on top of the
>>> contours so that some of the contour lines are only partially visible.  Is
>>> there a way to make the contour lines fully visible?  I cannot reverse the
>>> order and plot the points first and then call vis.gam().  Or, can I?  Are
>>> there other options?
>>>
>>> Thanks for any help or hints.
>>>
>>> Best,
>>> Ravi
>>>
>>>
>>> Ravi Varadhan, Ph.D.
>>> Assistant Professor
>>> The Center on Aging and Health
>>> Division of Geriatric Medicine&  Gerontology
>>>
>>> Johns Hopkins University
>>> rvarad...@jhmi.edu<mailto:rvarad...@jhmi.edu>
>>> 410-502-2619
>>>
>>>
>>> __
>>> 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.
>
>

__
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] image.plot adding x-axis labels. Please Help

2012-04-04 Thread ilai
On Wed, Apr 4, 2012 at 6:05 AM, David Winsemius  wrote:
>
> On Apr 3, 2012, at 11:16 PM, David Lyon wrote:
>
>> Sorry that didnt work for me, any ideas?
>
>
> You _could_ indicate which package the image.plot function comes from. You
> _could_ include dput on a sufficient segment of `data1` to offer a
> reproducible test case. You _could_ indicate in what fashion the axis() call
> "didn't work". I used to look such matters up, add code and make guesses,
> but got tired of doing extra work that was really the responsibility of the
> questioner.
>
> --
> David

Thank you David, you're absolutely right. The critical point here is
par settings of fields::image.plot not the axis(1,at=?...) as could be
understood from the original partial question.

I forgot to cc the list on my private communications with the OP.
Future googlers, the same solution can be achieved with

A<- matrix(1:50,nr=10)
par(mar=c(5.1,2.1,4.1,4.1))
image(t(A),axes=F,col='transparent')
axis(1,at=seq(0,1,l=ncol(A)),labels=LETTERS[1:ncol(A)])
require(fields)
image.plot(t(A),add=T,legend.mar=3.1)


Cheers

>
>>
>>
>> - Original Message -
>> From: ilai 
>> To: David Lyon 
>> Cc: "r-help@r-project.org" 
>> Sent: Tuesday, April 3, 2012 10:43 PM
>> Subject: Re: [R] image.plot adding x-axis labels. Please Help
>>
>> On Tue, Apr 3, 2012 at 7:25 PM, David Lyon  wrote:
>>>
>>> if I had a data file like this:
>>> 1.42 1.29 -0.13
>>> 1.46 1.34 -0.12
>>> 1.45 1.32 -0.13
>>> 1.36 1.26 -0.10
>>> 1.33 1.29 -0.04
>>>
>>> I want to create a image plot like this:
>>> data1<-read.table("A")
>>>
>>> image.plot(t(data1), axes=FALSE, xlab=NA, ylab=NA)
>>>
>>> I cant get the labels for the x axis right can some kind person help me?
>>
>>
>> axis(1,at=seq(0,1,l=ncol(data1)),labels=LETTERS[1:ncol(data1)])
>>
>>
>>> axis(1.???.labels=c("A", "B", "C"))
>>>
>>>
>>> Many thanks in advance!
>>>
>>> __
>>> 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.
>
>
> David Winsemius, MD
> West Hartford, CT
>

__
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] cluster analysis with pairwise data

2012-04-04 Thread ilai
On Wed, Apr 4, 2012 at 10:12 AM, Petr Savicky  wrote:
> On Wed, Apr 04, 2012 at 01:32:10PM +0200, paladini wrote:

>  Var1 <- c("(1,2)", "(7,8)", "(4,7)")
>  Var2 <- c("(1,5)", "(3,88)", "(12,4)")
>  Var3 <- c("(4,2)", "(6,5)", "(4,4)")
>  DF <- data.frame(Var1, Var2, Var3, stringsAsFactors=FALSE)
>
> If you want to use a distance between pairs depending on the
> numbers (and not only equal/different pair), then the data should
> to be transformed to a numeric format.

Or if the pairs have unique meaning ?daisy , also in the cluster
package, comes in handy (in this case you'll want to keep Vi as
factors in the call to DF).

Cheers

For example, as follows
>
>  trans <- function(x)
>  {
>      y <- strsplit(gsub("[()]", "", x), ",")
>      unname(t(vapply(y, FUN=as.numeric, FUN.VALUE=c(0, 0
>  }
>
>  DF <- data.frame(Var1=trans(Var1), Var2=trans(Var2), Var2=trans(Var3))
>  DF
>
>    Var1.1 Var1.2 Var2.1 Var2.2 Var2.1.1 Var2.2.1
>  1      1      2      1      5        4        2
>  2      7      8      3     88        6        5
>  3      4      7     12      4        4        4
>
> Then, see library(help=cluster).
>
> Hope this helps.
>
> Petr Savicky.
>
> __
> 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.


Re: [R] indexing data.frame columns

2012-04-05 Thread ilai
On Thu, Apr 5, 2012 at 1:40 PM, Peter Meilstrup
 wrote:
> Consider the data.frame:
>
> df <- data.frame(A = c(1,4,2,6,7,3,6), B= c(3,7,2,7,3,5,4), C =
> c(2,7,5,2,7,4,5), index = c("A","B","A","C","B","B","C"))
>
> I want to select the column specified in 'index' for every row of 'df', to
> get
>
> goal <- c(1, 7, 2, 2, 3, 5, 5)
>
> This sounds a lot like the indexing-by-a-matrix you can do with arrays;
>
> df[cbind(1:nrow(df), df$index)]
>
> but this returns me values that are all characters where I want numbers.

str(df[,-4][cbind(1:nrow(df),df$index)])
 num [1:7] 1 7 2 2 3 5 5

> (it seems that indexing by an array isn't well supported for data.frames.)

No, it's just that the index column in df is a factor so as.matrix(df)
return a matrix of characters

>
> What is a better way to perform this selection operation?
>

Not that I know of

Cheers


> Peter
>
>        [[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-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] Changing grid defaults

2012-04-06 Thread ilai
You might want to check out package {tikzDevice} and it's
documentation. In essence you turn your R plots to tikz-pgf so they
can be naturally incorporated into a beamer presentation. Colors, bg,
fonts etc. can now be controlled in your main latex doc. I find it
much more convenient, and nicer when the plot annotations make use of
the same latex font rather than e.g. plotmath. Note, for grid graphics
you'll need to use print(yourplot) to the device.

Cheers

On Fri, Apr 6, 2012 at 8:43 AM, Brett Presnell  wrote:
>
> I'm trying to use the vcd package to produce mosaic plots for my class
> notes, written in Sweave and using the LaTeX's beamer document class.
> For projecting the notes in class, I use a dark background with light
> foreground colors.  It's easy enough to change the defaults for R's
> standard graphics to match my color scheme (using the fg, col.axis,
> col.lab, col.main, and col.sub parameter settings), but I can't figure
> out how to do this with grid/strucplot/vcd.
>
> >From my experiments, I think that I might eventually figure out how to
> change the colors of all the text in the mosaic plots to what I want
> using arguments like 'gp_args = list(gp_labels = gpar(col = "yellow")'
> and 'gp_varnames = gpar(col = "yellow")' (although I still haven't
> figured out how to changed the color of the text on the legends), but
> this is obviously not what I need.  I have been reading all the
> documentation I can find, but I still haven't figured this out, so an
> answer accompanied by a reference to some line or the other in some
> piece of documentation would be greatly appreciated.
>
> __
> 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.


Re: [R] filling the matrix row by row in the order from lower to larger elements

2012-04-06 Thread ilai
I maybe missing something but this seems like an indexing problem
which doesn't require a loop at all. Something like this maybe?

(input<-matrix(c(5,1,3,7,2,6,4,8),nc=2))
output <- matrix(0,max(input),2)
output[input[,1],1] <- 100
output[input[,2],2] <- 100
output

Cheers


On Fri, Apr 6, 2012 at 1:49 PM, Dimitri Liakhovitski
 wrote:
> Hello, everybody!
>
> I have a matrix "input" (see example below) - with all unique entries
> that are actually unique ranks (i.e., start with 1, no ties).
> I want to assign a value of 100 to the first row of the column that
> contains the minimum (i.e., value of 1).
> Then, I want to assign a value of 100 to the second row of the column
> that contains the value of 2, etc.
> The results I am looking for are in "desired.results".
> My code (below) does what I need. But it's using a loop through all
> the rows of my matrix and searches for a matrix element every time.
> My actual matrix is very large. Is there a way to do it more efficiently?
> Thank you very much for the tips!
> Dimitri
>
> input<-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8)))
> (input)
> desired.result<-as.matrix(data.frame(a=c(100,0,100,0),b=c(0,100,0,100)))
> (desired.result)
> result<-as.matrix(data.frame(a=c(0,0,0,0),b=c(0,0,0,0)))
> for(i in 1:nrow(input)){ # i<-1
>  mymin<-i
>  mycoords<-which(input==mymin,arr.ind=TRUE)
>  result[i,mycoords[2]]<-100
>  input[mycoords]<-max(input)
> }
> (result)
>
> --
> Dimitri Liakhovitski
>
> __
> 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.


Re: [R] filling the matrix row by row in the order from lower to larger elements

2012-04-06 Thread ilai
On Fri, Apr 6, 2012 at 4:02 PM, Dimitri Liakhovitski
 wrote:
 This works great:

Really ? surprising given it is the EXACT same for-loop as in your
original problem with counter "i" replaced by "k" and reorder to
matrix[!100]<- 0 instead of matrix(0)[i]<- 100
You didn't even attempt to implement Carl's suggestion to use apply
family for looping (which I still think is completely unnecessary).

The only logical conclusion is N=nrow(input) was not large enough to
pose a problem in the first place. In the future please use some brain
power before waisting ours.

Cheers

>
> input<-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8)))
> result<-input
> N<-nrow(input)
> for (k in 1:N){
>  foo <- which (input == k,arr.ind=T)
>  result[k,foo[2]] <-100
> }
> result[result !=100]<-0
>
> Dimitri
>
>
> On Fri, Apr 6, 2012 at 5:14 PM, Carl Witthoft  wrote:
>> I think the OP wants to fill values in an arbitrarily large matrix. Now,
>> first of all, I'd like to know what his real problem is, since this seems
>> like a very tedious and unproductive matrix to produce.  But in the
>> meantime,  since he also left out important information, let's assume the
>> input matrix is N rows by M columns, and that he wants therefore to end up
>> with N instances of "100", not counting the original value of 100 that is
>> one of his ranking values (a bad BAD move IMHO).
>>
>> Then either loop or lapply over an equation like (I've expanded things more
>> than necessary for clarity
>> result<-inmatrix
>> for (k in 1:N){
>> foo <- which (inmatrix == k,arr.ind=T)
>> result[k,foo[2]] <-100
>>
>> }
>>
>>
>>
>> I maybe missing something but this seems like an indexing problem
>> which doesn't require a loop at all. Something like this maybe?
>>
>> (input<-matrix(c(5,1,3,7,2,6,4,8),nc=2))
>> output <- matrix(0,max(input),2)
>> output[input[,1],1] <- 100
>> output[input[,2],2] <- 100
>> output
>>
>> Cheers
>>
>>
>> On Fri, Apr 6, 2012 at 1:49 PM, Dimitri Liakhovitski
>>  wrote:
>>> Hello, everybody!
>>>
>>> I have a matrix "input" (see example below) - with all unique entries
>>> that are actually unique ranks (i.e., start with 1, no ties).
>>> I want to assign a value of 100 to the first row of the column that
>>> contains the minimum (i.e., value of 1).
>>> Then, I want to assign a value of 100 to the second row of the column
>>> that contains the value of 2, etc.
>>> The results I am looking for are in "desired.results".
>>> My code (below) does what I need. But it's using a loop through all
>>> the rows of my matrix and searches for a matrix element every time.
>>> My actual matrix is very large. Is there a way to do it more efficiently?
>>> Thank you very much for the tips!
>>> Dimitri
>>>
>>> input<-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8)))
>>> (input)
>>> desired.result<-as.matrix(data.frame(a=c(100,0,100,0),b=c(0,100,0,100)))
>>> (desired.result)
>>> result<-as.matrix(data.frame(a=c(0,0,0,0),b=c(0,0,0,0)))
>>> for(i in 1:nrow(input)){ # i<-1
>>>  mymin<-i
>>>  mycoords<-which(input==mymin,arr.ind=TRUE)
>>>  result[i,mycoords[2]]<-100
>>>  input[mycoords]<-max(input)
>>> }
>>> (result)
>>>
>> --
>>
>> Sent from my Cray XK6
>> "Quidvis recte factum, quamvis humile, praeclarum."
>>
>>
>> __
>> 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.
>
>
>
> --
> Dimitri Liakhovitski
> marketfusionanalytics.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.


Re: [R] Drawing a line in xyplot

2012-04-07 Thread ilai
On Sat, Apr 7, 2012 at 11:16 AM, David Winsemius  wrote:

> xyplot(mortality ~ type, data=xdat,
>               panel=function(x,y){
>                   panel.xyplot(x,y, jitter.x=TRUE)
>                   panel.segments(x0=c(.9, 1.9, 2.9),
>                                   x1=c(1.1,2.1,3.1),
>                                   y0=tapply(xdat$mortality, xdat$type,
> median),
>                                   y1=tapply(xdat$mortality, xdat$type,
> median),
>                             col="red", lwd=3 )
>
>                       })
>

Actually the OP had formula = mortality ~ factor(attend)|type,
(two conditioning factors). This approach will work but will require
1)  replace type with attend in tapply
2) subset conditional on packet.number
3) loop over the segments for the two sets of x-coords

An alternative will be

bwplot(mortality ~ factor(attend)|type,data=xdat,
 pch=95,cex=5,col=2,
 par.settings=list(
  box.rectangle = list(col = 'transparent'),
  box.umbrella = list(col = 'transparent')
 ),
 panel=function(x,y,...){
  panel.grid(lty=5)
  panel.bwplot(x,y,...)
  panel.xyplot(x,y,pch=16,jitter.x=TRUE,col=1)
 }
)

Hope this helps


>
>> thanks
>>
>>
>>
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/Drawing-a-line-in-xyplot-tp4538689p4539596.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.
>
>
> David Winsemius, MD
> West Hartford, CT
>
>
> __
> 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.


Re: [R] Drawing a line in xyplot

2012-04-08 Thread ilai
On Sat, Apr 7, 2012 at 8:29 PM, wcheckle  wrote:

> Thank you David, the bwplot option does what I need:

> However, I am interested in also learning how to do it in xyplot as well.  I
> wasn’t able to follow the last two set of instructions

That was me. Sorry for any confusion. wcheckle, these were not
instructions but ramblings on an earlier code which used the original
data.frame inside the lattice panel function, which in my view is an
added complication in the case of only 2-3 conditioning variables. You
were not meant to try and follow (the alternative was given in the
form of bwplot).
Your original post had two plots - in base graphics you had one
conditional variable (type) and median lines, and a second was lattice
with 2 variables (attend|type) without median lines. You were offered
2 solutions - David's to reproduce the first plot in lattice, and the
bwplot to add medians to the second.
You could work through the examples in lattice and on-line to find
there is a multitude of ways to add features to grid/lattice plots. An
example with panel.segments might look (untested) something like:

panel=function(x,y,...)
{
panel.xyplot(x,y,...)
yy<- tapply(y,x,median)
panel.segments(x0, x1, y0= yy , y1= yy , col="red",lwd=4)
}

Hope that clarifies things, and again sorry everyone for any confusion
that may have resulted.

Best,
Elai

__
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] xyplot() does not plot legends with "relation=free" scales

2012-04-08 Thread ilai
On Sun, Apr 8, 2012 at 3:42 AM, Kaveh Vakili  wrote:
> Hi all,
>
> I have this problem with lattice that xyplot() won't draw some of my axis 
> labels if the type (i.e. the relation argument) of scales is set as free. For 
> example, in the plot below, I would want it to also show:
>
> 1. the labels E1,...E6 below the 10th panel (i.e. 3rd row, 2 col)just as 
> it is now done below the 12th panel
>

You are setting your scales manually, so you need to make sure you
don't have typos. Change the line
 lbl[[9]] <- lbl[[12]]<-c("E1","E2","E3","E4","E5","E6")
to
 lbl[[10]] <- lbl[[12]]<-c("E1","E2","E3","E4","E5","E6")

> 2. as well as the labels (2,4,6,8) on the top of panels 1 and 3 (by "on top", 
> i mean above the strips, as xyplot normally does by default but can't seem to 
> be willing to do in the example below).

Same thing, I see the y axis labels for 1,3 but nothing for the at or
labels for x-axis for [[1,3]]. Note also you need the appropriate tck
argument for placing 'top-right'

>
>
> PS: i had originally posted this question on stackoverlow but since i didn't 
> get an answer there i've deleted it there and posting it here.

My guess is you didn't get an answer before because this is a
reproducible example (thank you) but very involved. In the future try
to reduce your code to the minimum which produces the problem
behavior, you will often find that in the process of doing so you
answer your own question...

Hope this helped

Elai

>
> Happy Easter,
>
>        B<-structure(list(yval = c(0.7, 0.61, 0.65, 0.63, 6.08, 0.64, 5.68,
> 6.77, 1.48, 7.71, 0.82, 1.15, 0.54, 1.01, 0.59, 4.84, 0.69, 0.71, 8.7, 0.48, 
> 0.69, 4.81, 1.42, 1.19, 0.84, 4.89, 0.85, 0.67, 7.07, 0.66, 7.93, 0.69, 5.94, 
> 0.47, 0.7, 0.73, 0.5, 3.62, 9.55, 4.48, 9.44, 1.06, 0.36, 0.73, 0.67, 1.4, 
> 0.56, 7.07, 0.69, 0.42, 3.72, 0.8, 0.94, 0.66, 0.48, 6.94, 3.19, 0.84, 1.27, 
> 1.85, 5.23, 0.75, 0.55, 4.69, 8.51, 3.98, 0.65, 4.72, 0.94, 0.86, 6.27, 3.42, 
> 1.03, 1.83, 0.86, 8.59, 0.72, 7.92, 0.84, 0.49, 0.78, 7.31, 5.15, 0.88, 0.57, 
> 0.95, 0.69, 8.77, 0.86, 0.82, 2.02, 6.99, 5.01, 0.84, 1.09, 1.02, 0.66, 9.23, 
> 0.74, 2.21), xval = c(0.7, 0.61, 0.65, 0.63, 6.08, 0.64, 5.68, 6.77, 1.48, 
> 7.71, 0.82, 1.15, 0.54, 1.01, 0.59, 4.84, 0.69, 0.71, 8.7, 0.48, 0.69, 4.81, 
> 1.42, 1.19, 0.84, 4.89, 0.85, 0.67, 7.07, 0.66, 7.93, 0.69, 5.94, 0.47, 0.7, 
> 0.73, 0.5, 3.62, 9.55, 4.48, 9.44, 1.06, 0.36, 0.73, 0.67, 1.4, 0.56, 7.07, 
> 0.69, 0.42, 3.72, 0.8, 0.94, 0.66, 0.48, 6.94, 3.19, 0.84, 1.27, 1.85, 5.23, 
> 0.75, 0.55, 4.69, 8.51, 3.98, 0.65, 4.72, 0.94, 0.86, 6.27, 3.42, !
>  1.03, 1.83, 0.86, 8.59, 0.72, 7.92, 0.84, 0.49, 0.78, 7.31, 5.15, 0.88, 
> 0.57, 0.95, 0.69, 8.77, 0.86, 0.82, 2.02, 6.99, 5.01, 0.84, 1.09, 1.02, 0.66, 
> 9.23, 0.74, 2.21), gval = c(1, 3, 4, 4, 1, 5, 5, 4, 6, 4, 2, 6, 4, 3, 4, 4, 
> 3, 5, 1, 5, 1, 5, 6, 6, 6, 1, 1, 1, 1, 5, 1, 3, 4, 5, 4, 3, 5, 1, 5, 4, 5, 6, 
> 3, 4, 3, 6, 3, 1, 2, 1, 3, 2, 1, 3, 4, 5, 4, 6, 6, 6, 5, 2, 1, 4, 5, 5, 4, 1, 
> 1, 1, 3, 2, 2, 6, 2, 3, 3, 4, 1, 3, 2, 1, 3, 6, 5, 2, 6, 4, 2, 2, 1, 1, 5, 2, 
> 6, 6, 3, 1, 4, 3), type = structure(c(2L, 3L, 3L, 3L, 2L, 3L, 3L, 2L, 2L, 2L, 
> 2L, 1L, 3L, 2L, 1L, 3L, 3L, 2L, 1L, 1L, 3L, 2L, 1L, 2L, 3L, 2L, 3L, 3L, 2L, 
> 1L, 2L, 1L, 2L, 3L, 1L, 2L, 3L, 2L, 1L, 3L, 1L, 2L, 3L, 2L, 1L, 1L, 1L, 2L, 
> 3L, 2L, 3L, 3L, 1L, 3L, 2L, 2L, 2L, 3L, 1L, 2L, 2L, 3L, 1L, 2L, 1L, 3L, 3L, 
> 2L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 1L, 3L, 1L, 3L, 1L, 2L, 2L, 2L, 3L, 3L, 2L, 
> 3L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 3L, 1L, 3L, 2L), .Label = c("0", "1", 
> "5"), class = "factor"), cr = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L!
>  , 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
>
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 
> .Label = c("0.2", "0.3", "0.4"), class = "factor"), p = structure(c(1L, 2L, 
> 1L, 1L, 2L, 1L, 4L, 4L, 2L, 4L, 3L, 1L, 2L, 2L, 1L, 4L, 1L, 1L, 3L, 1L, 1L, 
> 3L, 3L, 4L, 3L, 2L, 4L, 1L, 4L, 1L, 4L, 1L, 4L, 3L, 1L, 1L, 3L, 3L, 4L, 4L, 
> 4L, 4L, 2L, 1L, 2L, 1L, 1L, 3L, 1L, 1L, 3L, 2L, 3L, 1L, 1L, 3L, 2L, 3L, 3L, 
> 1L, 2L, 1L, 1L, 3L, 3L, 4L, 3L, 2L, 4L, 4L, 4L, 3L, 3L, 1L, 4L, 4L, 2L, 3L, 
> 3L, 1L, 2L, 4L, 2L, 3L, 1L, 2L, 4L, 4L, 3L, 3L, 4L, 3L, 2L, 3L, 4L, 4L, 1L, 
> 3L, 2L, 4L), .Label = c("4", "8", "12", "20"), class = "factor"), grp = c(4, 
> 2, 2, 2, 4, 2, 2, 4, 4, 4, 4, 5, 2, 4, 5, 2, 2, 4, 5, 5, 2, 4, 5, 4, 2, 4, 2, 
> 2, 4, 5, 4, 5, 4, 2, 5, 4, 2, 4, 5, 2, 5, 4, 2, 4, 5, 5, 5, 4, 2, 4, 2, 2!
>  , 5, 2, 4, 4, 4, 2, 5, 4, 4, 2, 5, 4, 5, 2, 2, 4, 2, 2, 4, 4, 4, 4, 4, 5, 2, 
> 5, 2, 5, 4, 4, 4, 2, 2, 4, 2, 5, 4, 4, 4, 4, 4, 4, 4, 5, 2, 5, 2, 4)), .Names 
> = c("yval", "xval", "gval", "type", "cr", "p", "grp"), row.names = c(NA, 
> -100L), class = "data.frame"

Re: [R] axis labels not showing

2012-04-08 Thread ilai
On Sun, Apr 8, 2012 at 11:40 AM, Vikram Chhatre
 wrote:
> Hello -
>
> I want to generate stacked plots with par(mfrow)) function.  However,
> my axis labels aren't showing.
>

Your mar (2) are too narrow. You could increase back to the default or
use the lines option in mtext to write labels closer to the plot or,
well, a host of other things...

Hope this helps

> My script is here:
> http://pastebin.com/yXXeMQgb
>
> The plot is here:
> http://www.crypticlineage.net/rdisc/strplot.pdf
>
> Thank you for your time.
>
> Vikram
>
> __
> 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.


Re: [R] filling the matrix row by row in the order from lower to larger elements

2012-04-08 Thread ilai
On Sun, Apr 8, 2012 at 8:26 AM, Dimitri Liakhovitski
 wrote:
> Sorry, I didn't have time to check the speed, indeed.
> However - isn't apply the same as a loop, just hidden?
> D.
>

Yes ?apply is a loop but not the same as ?for, see "Intro to R". As
Bert Gunter pointed out the issue here was not speed but that your
problem could have been vectorized to avoid loops all together (which
would have the added benefit of speed). This was given to you in my
first response which assumed a small number of columns in the matrix,
but Rui gave an elegant expansion to use on any ncol(matrix). Using
apply was suggested at some point by others, my comment was simply
that you failed to meet even that adjustment.
Cheers



> On Fri, Apr 6, 2012 at 6:59 PM, ilai  wrote:
>> On Fri, Apr 6, 2012 at 4:02 PM, Dimitri Liakhovitski
>>  wrote:
>>  This works great:
>>
>> Really ? surprising given it is the EXACT same for-loop as in your
>> original problem with counter "i" replaced by "k" and reorder to
>> matrix[!100]<- 0 instead of matrix(0)[i]<- 100
>> You didn't even attempt to implement Carl's suggestion to use apply
>> family for looping (which I still think is completely unnecessary).
>>
>> The only logical conclusion is N=nrow(input) was not large enough to
>> pose a problem in the first place. In the future please use some brain
>> power before waisting ours.
>>
>> Cheers
>>
>>>
>>> input<-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8)))
>>> result<-input
>>> N<-nrow(input)
>>> for (k in 1:N){
>>>  foo <- which (input == k,arr.ind=T)
>>>  result[k,foo[2]] <-100
>>> }
>>> result[result !=100]<-0
>>>
>>> Dimitri
>>>
>>>
>>> On Fri, Apr 6, 2012 at 5:14 PM, Carl Witthoft  wrote:
>>>> I think the OP wants to fill values in an arbitrarily large matrix. Now,
>>>> first of all, I'd like to know what his real problem is, since this seems
>>>> like a very tedious and unproductive matrix to produce.  But in the
>>>> meantime,  since he also left out important information, let's assume the
>>>> input matrix is N rows by M columns, and that he wants therefore to end up
>>>> with N instances of "100", not counting the original value of 100 that is
>>>> one of his ranking values (a bad BAD move IMHO).
>>>>
>>>> Then either loop or lapply over an equation like (I've expanded things more
>>>> than necessary for clarity
>>>> result<-inmatrix
>>>> for (k in 1:N){
>>>> foo <- which (inmatrix == k,arr.ind=T)
>>>> result[k,foo[2]] <-100
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> I maybe missing something but this seems like an indexing problem
>>>> which doesn't require a loop at all. Something like this maybe?
>>>>
>>>> (input<-matrix(c(5,1,3,7,2,6,4,8),nc=2))
>>>> output <- matrix(0,max(input),2)
>>>> output[input[,1],1] <- 100
>>>> output[input[,2],2] <- 100
>>>> output
>>>>
>>>> Cheers
>>>>
>>>>
>>>> On Fri, Apr 6, 2012 at 1:49 PM, Dimitri Liakhovitski
>>>>  wrote:
>>>>> Hello, everybody!
>>>>>
>>>>> I have a matrix "input" (see example below) - with all unique entries
>>>>> that are actually unique ranks (i.e., start with 1, no ties).
>>>>> I want to assign a value of 100 to the first row of the column that
>>>>> contains the minimum (i.e., value of 1).
>>>>> Then, I want to assign a value of 100 to the second row of the column
>>>>> that contains the value of 2, etc.
>>>>> The results I am looking for are in "desired.results".
>>>>> My code (below) does what I need. But it's using a loop through all
>>>>> the rows of my matrix and searches for a matrix element every time.
>>>>> My actual matrix is very large. Is there a way to do it more efficiently?
>>>>> Thank you very much for the tips!
>>>>> Dimitri
>>>>>
>>>>> input<-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8)))
>>>>> (input)
>>>>> desired.result<-as.matrix(data.frame(a=c(100,0,100,0),b=c(0,100,0,100)))
>>>>> (desired.result)
>>>>> result<-as.matrix(data.frame(a=c(0,0,0,0),b=c(0,0,0,0)))
>>>>> for(i in

Re: [R] Gradients in bar charts XXXX

2012-04-09 Thread ilai
On Mon, Apr 9, 2012 at 12:40 PM, Jason Rodriguez
 wrote:
> Hello, I have a graphics-related question:
>
> I was wondering if anyone knows of a way to create a bar chart that is 
> colored with a three-part gradient that changes at fixed y-values. Each bar 
> needs to fade green-to-yellow at Y=.10 and from yellow-to-red at Y=.20. Is 
> there an option in a package somewhere that offers an easy way to do this?

?rainbow ?hsv
In R "an easy way" is an ill-defined term. In the absence of actual data:

bpd <- matrix(c(1,seq(0,1,l=64),2,1,seq(0,1,l=64),5,1,seq(0,1,l=64),7),nc=3)
mycols <- c('green',rainbow(64,start=0,end=.4)[64:1],'red')
barplot(bpd,col=mycols,border=NA)

"Easy" enough ?

Cheers


>
> Attached is a chart I macgyvered together in Excel using a combination of a 
> simple bar chart, fit line, and some drawing tools. I want to avoid doing it 
> this way in the future by finding a way to replicate it in R.
>
> Any ideas?
>
> Thanks,
>
> Jason Michael Rodriguez
> Data Analyst
> State Housing Trust Fund for the Homeless
> Georgia Department of Community Affairs
> Email:  jason.rodrig...@dca.ga.gov
>
>
> __
> 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.


Re: [R] Lattice densityplot with semitransparent filled regions

2012-04-11 Thread ilai
 densityplot(~y|B, groups=A, data=dt,
plot.points="rug",
col=trellis.par.get("superpose.polygon")$col, alpha=.5,
panel=panel.superpose,
panel.groups=my.panel.densityplot)

Worked for me (i.e. semi-transparent superpose.polygon colors). Is
that not what you are seeing ?


On Wed, Apr 11, 2012 at 12:05 PM, Walmes Zeviani
 wrote:
> Hello,
>
> I'm doing some graphics for a paper and a need customize such with filled
> region above the density curve. My attempts I get something very near what
> I need, but I don't solve the problem of use semitransparent filled. Below
> a minimal reproducible code. Someone has any idea?
>
> require(lattice)
>
> # toy data...
> dt <- expand.grid(A=1:2, B=1:3, y=1:50)
> dt$y <- rnorm(nrow(dt), dt$B, dt$A)
>
> # regular plot...
> densityplot(~y|B, groups=A, data=dt, plot.points="rug")
>
> # the actual panel...
> panel.densityplot
>
> # so, I edit this...
> my.panel.densityplot <-
> function (x, darg = list(n = 30), plot.points = "jitter", ref = FALSE,
>    groups = NULL, weights = NULL, jitter.amount = 0.01 *
> diff(current.panel.limits()$ylim),
>    type = "p", ..., identifier = "density")
> {
>    if (ref) {
>        reference.line <- trellis.par.get("reference.line")
>        panel.abline(h = 0, col = reference.line$col, lty =
> reference.line$lty,
>            lwd = reference.line$lwd, identifier = paste(identifier,
>                "abline"))
>    }
>    if (!is.null(groups)) {
>        panel.superpose(x, darg = darg, plot.points = plot.points,
>            ref = FALSE, groups = groups, weights = weights,
>            panel.groups = panel.densityplot, jitter.amount =
> jitter.amount, # alterei para my.panel
>            type = type, ...)
>    }
>    else {
>        switch(as.character(plot.points), `TRUE` = panel.xyplot(x = x,
>            y = rep(0, length(x)), type = type, ..., identifier =
> identifier),
>            rug = panel.rug(x = x, start = 0, end = 0, x.units = c("npc",
>                "native"), type = type, ..., identifier = paste(identifier,
>                "rug")), jitter = panel.xyplot(x = x, y = jitter(rep(0,
>                length(x)), amount = jitter.amount), type = type,
>                ..., identifier = identifier))
>        density.fun <- function(x, weights, subscripts = TRUE,
>            darg, ...) {
>            do.call("density", c(list(x = x, weights =
> weights[subscripts]),
>                darg))
>        }
>        if (sum(!is.na(x)) > 1) {
>            h <- density.fun(x = x, weights = weights, ..., darg = darg)
>            lim <- current.panel.limits()$xlim
>            id <- h$x > min(lim) & h$x < max(lim)
>            panel.lines(x = h$x[id], y = h$y[id], ..., identifier =
> identifier)
> ## line above was added
>            panel.polygon(x=h$x[id], y = h$y[id], ..., identifier =
> identifier, alpha=0.2)
>        }
>    }
> }
>
> # my customized plot, I want semitransparent colors
> # and use the colors of trellis.par.set("superpose.polygon") to fill
> densityplot(~y|B, groups=A, data=dt,
>            plot.points="rug", col=2:3,
>            panel=panel.superpose,
>            panel.groups=my.panel.densityplot)
>
> Thanks!
> Walmes.
>
> ==
> Walmes Marques Zeviani
> LEG (Laboratório de Estatística e Geoinformação, 25.450418 S, 49.231759 W)
> Departamento de Estatística - Universidade Federal do Paraná
> fone: (+55) 41 3361 3573
> VoIP: (3361 3600) 1053 1173
> e-mail: wal...@ufpr.br
> twitter: @walmeszeviani
> homepage: http://www.leg.ufpr.br/~walmes
> linux user number: 531218
> ==
>
>        [[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-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] xyplot lattice fine control of axes limits and thick marks (with log scale)

2012-04-11 Thread ilai
On Wed, Apr 11, 2012 at 7:16 AM, David Winsemius  wrote:
>
> On Apr 11, 2012, at 9:03 AM, David Winsemius wrote:
>
>>
>> On Apr 11, 2012, at 6:28 AM, maxbre wrote:
>>
>>> hi, I just realised I want to go a little further in the control of the
>>> chart
>>> appearance and I would like to have the same number of ticks displayed in
>>> both axes of all panels
>>
>> I'm wondering if you should be using relation="free" when you have already
>> set a panel specific range for the x and y limits? I'm thinking that the
>> panel function may be reversing your earlier prepanel efforts. (No data
>> offered  ... why don't you use one of the many test datasets in the examples
>> of the lattice package?)
>
>
> On further meandering up this thread I see that you omitted the context of
> earlier data offerings, so not I in turn offer what I think is a your
> request. Change relation from "free" to "sliced"

David, you make a good point. Seems OP's long and winding road {end
quote} is slowly circling back to the origin (see the first couple of
messages in thread).

"slice" is better than "free", but isn't tick.number just a suggestion
? i.e. a better choice of n in ?pretty will override ? For example
this data (below), barely noticeable, but see panel(2,1) has 7 ticks
compare with 6 for the others.

Any one please correct me (as I find I mess with these myself too
often... :) but I think if OP wants to force equal ticks (and lose the
"pretty" axis) there is no avoiding changes to x and yscale.components
?

tm <- structure(list(name_short = structure(1:29, .Label = c("D4",
"D5", "D6a", "D6b", "D6c", "D7", "D8", "F4", "F5a", "F5b", "F6a",
"F6b", "F6c", "F6d", "F7a", "F7b", "F8", "P105", "P114", "P118",
"P123", "P126", "P156", "P157", "P167", "P169", "P189", "P77",
"P81"), class = "factor"), sub_family = structure(c(3L, 3L, 3L,
3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L, 1L,
1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 2L), .Label = c("pcb mono-ortho subs",
"pcb non-ortho subs", "pcdd", "pcdf"), class = "factor"), tv = c(1.069,
6.461, 5.461, 12.764, 10.86, 117.912, 256.875, 452.204, 124.02,
327.856, 88.469, 61.539, 17.794, 84.117, 121.668, 13.414, 68.409,
3023.333, 428, 19454.667, 151.333, 324, 11478.667, 1220.667,
5335.333, 124.667, 1542.667, 594.667, 193.333), ms = c(1.787,
4.831, 3.456, 14.105, 10.808, 116.02, 296.957, 30.533, 21.821,
32.969, 33.767, 29.799, 12.812, 49.637, 126.522, 17.522, 106.087,
1787.5, 130, 6751.5, 81, 23, 370, 33.5, 147.5, 5.406, 18.5, 415,
69.906)), .Names = c("name_short", "sub_family", "tv", "ms"), class =
"data.frame", row.names = c(NA, -29L))

# changing to "sliced"
 xyplot(tv ~ ms | sub_family, data=tm,
 #as.table=TRUE,
 aspect="xy",
 xlab = expression(paste('ms [ fg/', m^3, ' ]', sep = '')),
 ylab = expression(paste('tv [ fg/', m^3, ' ]', sep = '')),
 scales= list(x=list(relation="sliced", log=10, cex=0.8),
  y=list(relation="sliced", log=10, cex=0.8)),
 prepanel = function(x, y, subscripts) {
   rr<- range(cbind(x,y))
   list(xlim = rr, ylim= rr)
 },
 panel = function(x, y ,subscripts,...) {
   panel.xyplot(x, y, cex=0.8,...)
   panel.abline(a = 0, b = 1, lty = 2, col ="gray")
   panel.text(x, y, labels=tm$name_short[subscripts], cex = 0.8, pos=3,
offset=0.5, srt=0, adj=c(1,1))
 },
 subscripts=TRUE,
 xscale.components = xscale.components.logpower,
 yscale.components = yscale.components.logpower
 )

# Compare with

 xyplot(tv ~ ms | sub_family, data=tm,
 #as.table=TRUE,
 aspect="xy",
 xlab = expression(paste('ms [ fg/', m^3, ' ]', sep = '')),
 ylab = expression(paste('tv [ fg/', m^3, ' ]', sep = '')),
 scales= list(relation="free", log=10, cex=0.8),
 prepanel = function(x, y, subscripts) {
   rr<- range(cbind(x,y))
   list(xlim = rr, ylim= rr)
 },
 panel = function(x, y ,subscripts,...) {
   panel.xyplot(x, y, cex=0.8,...)
   panel.abline(a = 0, b = 1, lty = 2, col ="gray")
   panel.text(x, y, labels=tm$name_short[subscripts], cex = 0.8, pos=3,
offset=0.5, srt=0, adj=c(1,1))
 },
 subscripts=TRUE,
 xscale.components = function(...)  {
 ans <- xscale.components.logpower(...)
 range <- ans$num.limit
 newtck <- round(seq(range[1],range[2],l=7),1)
 ans$bottom$ticks$at <- newtck
 ans$bottom$labels$at <- newtck
 ans$bottom$labels$labels <-
parse(text=paste('10^',newtck,sep=''))
  ans
 } ,
 yscale.components  = function(...)  {
 ans <- yscale.components.logpower(...)
 range <- ans$num.limit
 newtck <- round(seq(range[1],range[2],l=7),1)
 ans$left$ticks$at <- newtck
 ans$left$labels$at <- newtck
 ans$left$labels$labels <-
parse(text=paste('10^',newtck,sep=''))

Re: [R] Help with vectorization

2012-04-12 Thread ilai
Michael originally suggested ?outer. I think that was enough in this
case (no need for mv or sapply):

wlpk3 <- outer(k3,wl,'+')
ln.phiDIC <- log(k1)+k2/wlpk3
phiDIC<- t(exp(ln.phiDIC))
colnames(phiDIC)<- stations
str(phiDIC)

Cheers


On Thu, Apr 12, 2012 at 8:58 PM, R. Michael Weylandt
 wrote:
> Strange, that isn't the error I get:
>
>>  mouter(wl, k1, k2, k3, FUN = function(w, k1, k2, k3) k1 *exp(k2 / (w + k3)))
> Error in FUN(X, Y, ...) : argument "k2" is missing, with no default
>
> Still, it's a problem with my mouter() function which was only tested
> on binary operators (and then only really to teach myself to use
> Recall()). This should work better:
>
> `mouter` <- function(..., FUN){
>    dotArgs <-as.list(do.call("expand.grid", list(..., KEEP.OUT.ATTRS= F)))
>    names(dotArgs) <- names(formals(FUN))
>    ans <- do.call(FUN, dotArgs)
>    dim(ans) <- sapply(list(...), length)
>    ans
> }
>
> This only works when the function can take all the elements at a time
> though; I'm sure some fooling around could combine them nicely...it
> seems to test right on your data, but I haven't checked it more
> generally.
>
> Michael
>
> On Thu, Apr 12, 2012 at 3:29 PM, Filoche  wrote:
>> Hi and thank you for your time.
>>
>> I got this error when trying your function.
>>
>> mouter(wl, k1, k2, k3, FUN = function(w, k1, k2, k3) k1 *exp(k2 / (w + k3)))
>> "Error in k3/(w + k3) : 'k3' is missing"
>>
>> Regards,
>> Phil
>>
>> --
>> View this message in context: 
>> http://r.789695.n4.nabble.com/Help-with-vectorization-tp4552638p4552833.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.

__
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] Lattice: correct use of ltransform3dto3d to plot a surface under a cloud ?

2012-02-04 Thread ilai
Hello list!
I am trying to project the fitted surface to a 3d plot of the data,
similar to figures 13.7 or 6.5 in Deepayan Sarkar's "Lattice,
Multivariate Data Visualization with R", but replace the contour/map
lines with "levelplot". Problem is I can't get the color regions to
line up after the coordinate transformation. Is there a simple
solution my geometry challenged brain missed? It's been driving me
crazy for 2 days now so any help will be greatly appreciated!
I use lattice for all my other figures and would like to stay
consistent, so solutions of the form "package rgl" don't work. Thank
you all in advance.

Here is a minimal (still long) working example of what I mean, and
what I found out so far:

## make data and predicted surf
set.seed(1718)
d <- data.frame(x=runif(60),y=runif(60),g=gl(2,30))
d$z <- with(d,rnorm(60,2*x^as.numeric(g)-y^3))
d$z <- d$z+abs(min(d$z))  # so 'h' goes to the X-Y plane
surf <- by(d,d$g,function(D){
  fit <- lm(z~poly(x,2)+poly(y,2),data=D)
  outer(seq(0,1,l=10),seq(0,1,l=10),function(x,y,...)
predict(fit,data.frame(x=x,y=y)))
})
###
require(lattice)
# Modified code for plot 13.7 [changed: build clines from surf, -.5
for xy coords (why? don't know, works :), 3dscatter not wire]
panel.3d.contour <- function(x, y, z,rot.mat, distance,
zlim.scaled,nlevels=20,...)
{
add.line <- trellis.par.get("add.line")
clines <- contourLines(surf[[packet.number()]],nlevels = nlevels)
for (ll in clines) {
  m <- ltransform3dto3d(rbind(ll$x-.5, ll$y-.5, zlim.scaled[1]),
rot.mat, distance)
  panel.lines(m[1,], m[2,], col = add.line$col, lty = add.line$lty,
  lwd = add.line$lwd)
}
panel.3dscatter(x, y, z, rot.mat, distance, zlim.scaled = zlim.scaled, ...)
  }
cloud(z~x+y|g,data=d,layout=c(2,1), type='h', panel.3d.cloud = panel.3d.contour,
  zoom = 1,screen=list(z= 21,y=0,x=-60),aspect = c(1,1), panel.aspect = 1,
  scales=list(z=list(arrows=F,tck=0)),par.box=list(lty=0),lwd=3)

# This works. But for my data the contours are messy, so I am trying
to use levelplot:
panel.3d.levels <- function(x, y, z,rot.mat, distance, zlim.scaled,...)
{
zz <- surf[[packet.number()]]
n <- nrow(zz)
s <- seq(-.5,.5,l=n)
m <- ltransform3dto3d(rbind(rep(s,n),rep(s,each=n),zlim.scaled[1]),
  rot.mat, distance)
panel.levelplot(m[1,],m[2,],zz,1:n^2,col.regions=heat.colors(20))
panel.3dscatter(x, y, z, rot.mat, distance, zlim.scaled = zlim.scaled, ...)
  }
cloud(z~x+y|g,data=d,layout=c(2,1), type='h', panel.3d.cloud = panel.3d.levels,
  zoom = 1,screen=list(z= 21,y=0,x=-60),aspect = c(1,1), panel.aspect = 1,
  scales=list(z=list(arrows=F,tck=0)),par.box=list(lty=0),lwd=3)

# Unexpected...
# I can use panel.points for centroids and color them in "manually"
but that leaves white space or overlap:
cloud(z~x+y|g,data=d,layout=c(2,1), type='h', par.box=list(lty=0),
lwd=3, scales=list(z=list(arrows=F,tck=0)),
  panel.3d.cloud = function(x, y, z,rot.mat, distance, zlim.scaled,...){
zz <- surf[[packet.number()]]
n <- nrow(zz)
s <- seq(-.5,.5,l=n)
m <- ltransform3dto3d(rbind(rep(s,n),rep(s,each=n),zlim.scaled[1]),
  rot.mat, distance)
lp <- level.colors(zz, at = do.breaks(range(zz), 20),
col.regions = heat.colors(20))
panel.points(m[1,],m[2,],col=lp,pch=18,cex=2.8)
panel.3dscatter(x, y, z, rot.mat, distance, zlim.scaled =
zlim.scaled, ...)
  })

#So I try to "make my own" using the lp for panel.rect, but I get the
same behavior as points for the x0,x1,y0,y1 :
panel.3d.levels <- function(x, y, z,rot.mat, distance, zlim.scaled,...)
{
zz <- surf[[packet.number()]]
n <- nrow(zz)
s <- seq(-.5,.5,l=n)
lp <- level.colors(zz, at = do.breaks(range(zz), 20),
col.regions = heat.colors(20))
cntrds <- expand.grid(s,s)
apply(cntrds,1,function(i){
  xx <- i[1]+c(-.5,.5)/(n-1) ; yy <- i[2]+c(-.5,.5)/(n-1)
   m <- ltransform3dto3d(rbind(xx,yy,zlim.scaled[1]), rot.mat, distance)
   panel.rect(m[1,1],m[2,1],m[1,2],m[2,2])
 })
panel.3dscatter(x, y, z, rot.mat, distance, zlim.scaled = zlim.scaled, ...)
  }
cloud(z~x+y|g,data=d,layout=c(2,1), type='h', panel.3d.cloud = panel.3d.levels,
  zoom = 1,screen=list(z= 21,y=0,x=-60),aspect = c(1,1), panel.aspect = 1,
  scales=list(z=list(arrows=F,tck=0)),par.box=list(lty=0),lwd=3)

# This is as close as I got, but how to get each diagonal of
rectangles "shifted" to cover the space? I thought ltransform3dto3d
will take care of it when I transform every line in the loop. But it
didn't.

__
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 do I exort a list of numbers into csv file?

2012-02-05 Thread ilai
cat will wrap Josh's "overkill" approach in one line:

mylist<- list(1:3,3:9)
lapply(mylist , cat , sep=',' , fill=T , append=T , file='foo.csv')

Cheers

On Sun, Feb 5, 2012 at 7:42 PM, Joshua Wiley  wrote:
> Hi Michael,
>
> Part of me imagines this is overkill, but this should be one option:
>
> ## your data
> mylist <- list(1:3, 3:6)
> ## open a writeable connection to a file
> con <- file("test.csv", "w")
> ## first collapse each element of the list to be a comma separated
> string, then write each
> ## element of new character vector to con using writeLines
> writeLines(sapply(mylist, paste, collapse = ", "), con = con)
> ## close the connection
> close(con)
>
> see ?writeLines for details on different ways to indicate end of the line.
>
> Hope this helps,
>
> Josh
>
> On Sun, Feb 5, 2012 at 6:01 PM, Michael  wrote:
>> Hi all,
>>
>> I have a list of vector of numbers - the reason I used list of vector was
>> that I each list have different numbers of numbers which I don't know
>> before run-time.
>>
>> mylist[[1]]  = c(1, 2, 3)
>> mylist[[2]] = c (3, 4, 5, 6)
>> ...
>> ...
>> etc.
>>
>> Could you please tell me if there is a way to dump all these at once into
>> csv file such that each row correspond to a vector or a cell of the list as
>> shown above?
>>
>> Thanks a lot!
>>
>>        [[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.
>
>
>
> --
> Joshua Wiley
> Ph.D. Student, Health Psychology
> Programmer Analyst II, Statistical Consulting Group
> University of California, Los Angeles
> https://joshuawiley.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.


Re: [R] Multi-page PDF using dev.copy2pdf(filename, onefile=TRUE)?

2012-02-06 Thread ilai
Doug,
dev.copy2pdf closes the connection after it's "done", so onefile is
meaningless. To look at each plot before copy to a single pdf, you
could open a pdf(...) but revert between it and your graphic device:
graphics.off()
plot(1:7, 1:7)
x11c<- dev.cur()   # your current graphics device
pdf(file="test.pdf")
dev.set(which=x11c)   # back from pdf
dev.copy()  # copy
dev.set(which=x11c)# back to graphic
plot(1:5, 1:5,col=2,pch=2)
dev.copy()
dev.set(which=x11c)
# ...   etc. however many more plots
# don't forget to close the pdf device at the end:
dev.off(which=x11c+1)
# Both plots are in 'test.pdf'

Depending on your application you might be able to simplify things
with dev.next/dev.prev, or wrap this sequence into a little helper
function to be used in a loop.

Enjoy,
Elai


On Mon, Feb 6, 2012 at 6:44 AM, Doug Hill  wrote:
> Hi all. I want to generate a sequence of n plots and save them into a single 
> PDF file, one plot per page. From the R docs and other sources I gather the 
> basic way to do this is save plot 1 into a file then append the 2:n plots to 
> the same file.
> This code shows my basic approach, but for some reason only the last plot is 
> saved into the pdf. I've tried different variations (e.g. using onefile only 
> in the second call, or only in the first), to no avail. The comments show 
> what I see if I step through the code one line at a time:
> scratch<-function() {
> graphics.off()
> plot(1:7, 1:7) # Opens a graphics window and displays a 7-point plot in it, 
> as expected
> dev.copy2pdf(file="test.pdf", onefile=TRUE) # I see the 7-point plot in Adobe 
> reader, as expected
> plot(1:5, 1:5) # Overwrites in the graphics window the 7-point plot with a 
> 5-point, as expected
> dev.copy2pdf(file="test.pdf", onefile=TRUE) # Overwrites test.pdf so that it 
> contains only the 7-point plot
> }
> A couple things:
> (1) The reason I don't just use something like pdf(filename) plot(...) 
> plot(...) dev.off() is that I also want to see the plots before they're saved 
> (I pause after each plot() command). But according to the docs for 
> dev.copy2pdf(), that function accepts the same args as pdf() does, including 
> onefile.
> (2) I wrap my code in a function to be able to use it in the StatEt debugger 
> in Eclipse.
> If you know what I'm doing wrong, or know of a different/better way, advise 
> away! Thanks, Doug
>        [[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-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.


  1   2   >