Re: [R] matrix of random variables from a matrix of means and matrix of sd

2013-05-24 Thread M M
Nice one - didn't think of the array at all as my brain was fixated on lists...
Thanks,
Murali

> Date: Fri, 24 May 2013 21:54:22 +0100
> From: ruipbarra...@sapo.pt
> To: fean...@hotmail.com
> CC: r-help@r-project.org
> Subject: Re: [R] matrix of random variables from a matrix of means and matrix 
> of sd
> 
> Hello,
> 
> The first instruction doesn't call rnorm just once but it seems more 
> appropriate for your problem;
> The second instruction calls rnorm just once.
> 
> 
> set.seed(59187)
> res1 <- replicate(10, matrix(rnorm(4, mean = a, sd = b), ncol = 2))
> 
> set.seed(59187)
> res2 <- array(rnorm(40, mean = a, sd = b), dim = c(2, 2, 10))
> 
> identical(res1, res2)  # TRUE
> 
> 
> Hope this helps,
> 
> Rui Barradas
> 
> Em 24-05-2013 20:22, M M escreveu:
> > folks,
> > if i have a matrix of means:
> > a <- matrix(1:4, 2)
> > and a matrix of std deviations:
> > b <- matrix(5:8, 2)
> > and i want to create a matrix X of random variates such that X[i, j] is a 
> > draw from normal distribution with mean = a[i, j] and std dev =  b[i, j], i 
> > think i can do this?
> > X <- matrix(rnorm(4, mean = a, sd = b), ncol = 2)
> > now if I want to create 10 such matrices, I could possibly do this:
> > lapply(1:10, function(x) matrix(rnorm(4, mean = a, sd = b), ncol = 2))
> > is there a better way to do this with perhaps just one call to the rnorm() 
> > function?
> > cheers,
> > murali  
> > [[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] Change devAskNewPage setting on Escape?

2013-05-24 Thread Prof Brian Ripley

On 24/05/2013 15:21, Ulrike Grömping wrote:

Dear helpeRs,

I would like to include generation of a potentially large number of
plots, and modify the ask settings using the devAskNewPage function, and
return it back to its original state afterwards.
It is not unlikely that the user escapes from the long list of plots
before reaching the end. (How) Can I make sure to return the ask setting
to its original state even if the plots are escaped so that the function
does not reach its natural end?


?on.exit



Best,
Ulrike

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



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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] Continuous columns of matrix

2013-05-24 Thread William Dunlap
What you call "continuous" I call "cyclic" (with period NROW(x) in this case).
An easy to way to deal with this is to repeat the column three times, do the
original analysis, and return the results corresponding to the middle part of 
the
repeated x.  I think the following does the right thing, but have not tested it
much.

fCyclic <- function (x, threshold = 0.8 * max(x),  ...)
{
if (all(x > threshold)) {
index <- which.max(x)
data.frame(Index=index, Value=x[index])
} else {
ret <- f(x = rep(x, 3), threshold, ...)
ret <- ret[ret$Index > length(x) & ret$Index <= 2 * length(x), ]
ret$Index <- ret$Index - length(x)
ret
}
}

It does require a test for all of x being above the threshold, which f didn't
need.  You could put the test in f and take it out of fCyclic.

Again, use apply() if you to want to run it over each column.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

From: eliza botto [mailto:eliza_bo...@hotmail.com]
Sent: Friday, May 24, 2013 4:41 PM
To: ruipbarra...@sapo.pt; William Dunlap
Cc: r-help@r-project.org
Subject: RE: [R] Continuous columns of matrix

Dear Rui,

i just noticed that there is one slight problem in the William' code. If you 
see the results of column number 4 which are

[[4]]

IndexValue

1 12.061959

2122.245474

where as we already dicussed that columns are continuous and 1 and 12 cant be 
picked together.

so the results should have been

[[4]]

IndexValue


1122.245474

how to get rid of this error??

Thanks in advance...

Elisa


> Date: Fri, 24 May 2013 23:38:51 +0100
> From: ruipbarra...@sapo.pt
> To: wdun...@tibco.com
> CC: eliza_bo...@hotmail.com; 
> r-help@r-project.org
> Subject: Re: [R] Continuous columns of matrix
>
> Hello,
>
> Just use
>
> apply(mat, 2, f)
>
> Rui Barradas
>
> Em 24-05-2013 23:25, William Dunlap escreveu:
> > Are you trying to identify the highest point in each run of points higher 
> > than a threshold,
> > akin to the problem of naming mountains so that each minor bump on a high 
> > ridge does not
> > get its own name? The following does that:
> >
> > f <- function (x, threshold = 0.8 * max(x), plot=FALSE)
> > {
> > if (plot) { plot(x, type="l") ; abline(h=threshold) }
> > big <- x > threshold
> > n <- length(big)
> > startRunOfBigs <- which(c(big[1], !big[-n] & big[-1]))
> > if (plot) abline(v=startRunOfBigs, col="green")
> > endRunOfBigs <- which(c(big[-n] & !big[-1], big[n]))
> > if (plot) abline(v=endRunOfBigs, col="red")
> > stopifnot(length(startRunOfBigs) == length(endRunOfBigs),
> > all(startRunOfBigs <= endRunOfBigs))
> > index <- vapply(seq_along(startRunOfBigs),
> > function(i)which.max(x[startRunOfBigs[i]:endRunOfBigs[i]])+startRunOfBigs[i]-1L,
> > 0L)
> > if (plot && length(index)>0) points(cex=1.5, index, x[index])
> > data.frame(Index=index, Value=x[index])
> > }
> >
> > E.g., with your data:
> >> x <- c(0.563879907485297, 0.749077642331436, 0.681023650957497, 
> >> 1.30140773002346,
> > 1.46377246795771, 1.20312609775816, 0.651886452442823, 0.853749099839423,
> > 1.041608733313, 0.690719733451964, 1.49415144965002, 1.30559703478921
> > )
> >> f(x, plot=TRUE) # the plot illustrates what it is doing
> > Index Value
> > 1 5 1.463772
> > 2 11 1.494151
> >
> > Bill Dunlap
> > Spotfire, TIBCO Software
> > wdunlap tibco.com
> >
> >
> >> -Original Message-
> >> From: r-help-boun...@r-project.org 
> >> [mailto:r-help-boun...@r-project.org]
> >>  On Behalf
> >> Of eliza botto
> >> Sent: Friday, May 24, 2013 2:10 PM
> >> To: ruipbarra...@sapo.pt; 
> >> r-help@r-project.org
> >> Subject: Re: [R] Continuous columns of matrix
> >>
> >> Dear Rui,
> >> Regarding your last reply there is a small additional question which i 
> >> want to ask. For the
> >> following column
> >>> dput(mat[,1])c(0.563879907485297, 0.749077642331436, 0.681023650957497,
> >> 1.30140773002346, 1.46377246795771, 1.20312609775816, 0.651886452442823,
> >> 0.853749099839423, 1.041608733313, 0.690719733451964, 1.49415144965002,
> >> 1.30559703478921)
> >> Your loop gives following results
> >> [,1] [,2] [,3] [,4]
> >> index 4.00 5.00 6.00 11.00
> >> values 1.301408 1.463772 1.203126 1.494151
> >> which is very accurate. Index 11 had the maximum value and 4,5,6 were the 
> >> neibhours. i
> >> want to add an other condition which is that if a column has more
> >> than 1 neibhours, than just like the maximum value, those neibhour can not 
> >> be next to
> >> each other as well.
> >> So what i should have is the following
> >> [,1] [,2]
> >> index 5.00 11.00
> >> values 1.463772 1.494151
> >> Is there anyway of doing it??
> >> Thanks in advance
> >> Elisa
> >>
> >>> Date: Fri, 24 May 2013 17:02

[R] Problem reading from NetCDF.

2013-05-24 Thread Simon Knapp
Hi List,

I'm not sure what I'm doing wrong here and would appreciate some help. I
create a NetCDF dataset as follows:

library(ncdf)
combined.ncdf <- with(new.env(), {
nLat <- 7
nLon <- 8
nTime <- 9
missing.val <- -999
filename <- file.path(tempdir(), 'combined_d6fg4s64s6g4l.nc')
lat.dim <- dim.def.ncdf('lat', 'degrees', 1:nLat)
lon.dim <- dim.def.ncdf('lon', 'degrees', 1:nLon)
time.dim <- dim.def.ncdf("time", "days since 1970-01-01",
as.integer(1:nTime), unlim=T)
var.def <- var.def.ncdf('Data', 'mm', list(lon.dim, lat.dim, time.dim),
missing.val, prec='single')
nc <- create.ncdf(filename, var.def)
for(i in 1:nLon)
for(j in 1:nLat)
for(k in 1:nTime)
put.var.ncdf(nc, var.def, i + j*10 + k*100, c(i, j, k),
rep(1, 3))
nc
})


the following do not work:
get.var.ncdf(combined.ncdf)
get.var.ncdf(combined.ncdf, varid='Data')
get.var.ncdf(combined.ncdf, varid=4)

all of which I thought would be equivalent and would give me the same as:
get.var.ncdf(combined.ncdf, forcevarid=4)

Could someone please point out the error of my ways.

Thanx in advance,
Simon Knapp

R version: 2.14.1,
ncdf built with version: 2.14.2
os: windows 7

[[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] Multinomial logistic regression

2013-05-24 Thread Duncan Mackay
Have a look at Brian Ripleys  polr in library(MASS)  and multinom in 
the library(nnet)

There are other packages as well so a search will give you more choices

Be careful to read the help pages carefully and make sure that you 
know what you are testing.


HTH

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au




At 03:00 25/05/2013, you wrote:

Is it possible to use function "glm" in case when my outcome variable has 5
different classes? I have seen examples only when using binomial outcome
variable.

What about using function "multinom"? How do I to get the signifigance and
the confidence levels of the coefficients and the value of goodness of the
model with this function?

Thank You for Your help!



--
View this message in context: 
http://r.789695.n4.nabble.com/Multinomial-logistic-regression-tp4667923.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] Continuous columns of matrix

2013-05-24 Thread eliza botto
Bingo!!!
This time it worked
Thanks arun
Thankyou very much indeed..
:D
Elisa

> Date: Fri, 24 May 2013 17:03:33 -0700
> From: smartpink...@yahoo.com
> Subject: Re: [R] Continuous columns of matrix
> To: eliza_bo...@hotmail.com
> CC: wdun...@tibco.com; r-help@r-project.org
> 
> Hi,
> 
> I changed Bill's code little bit (without the plot).  I hope it works in 
> other cases.
> 
>  lst1<-lapply(split(mat,col(mat)),function(x){big<- x>0.8*max(x); n<- 
> length(big);startRunOfBigs<- which(c(big[1],!big[-n] & big[-1])); 
> endRunOfBigs<- which(c(big[-n] & !big[-1], big[n]));index<- 
> vapply(seq_along(startRunOfBigs),function(i) 
> which.max(x[startRunOfBigs[i]:endRunOfBigs[i]])+startRunOfBigs[i]-1L,0L); 
> index<-ifelse(sum(is.na(match(index,c(1,12==0 & x[index]!=max(x[index]), 
> NA,index);data.frame(Index=index[!is.na(index)],Value=x[index[!is.na(index)]])
>   })
> lst1
> $`1`
>   IndexValue
> 1 5 1.939064
> 212 1.791503
> 
> $`2`
>   IndexValue
> 1 5 1.508740
> 211 1.670409
> 
> $`3`
>   IndexValue
> 1 5 1.463772
> 211 1.494151
> 
> $`4`
>   IndexValue
> 112 2.245474
> 
> $`5`
>   IndexValue
> 1 6 1.592817
> A.K.
> 
> 
> 
> 
> From: eliza botto 
> To: "smartpink...@yahoo.com"  
> Sent: Friday, May 24, 2013 7:16 PM
> Subject: RE: [R] Continuous columns of matrix
> 
> 
> 
> 
> o yes!!! i didnt notice..
> you got any clue??
>  :(
> 
> 
> > Date: Fri, 24 May 2013 15:58:28 -0700
> > From: smartpink...@yahoo.com
> > Subject: Re: [R] Continuous columns of matrix
> > To: eliza_bo...@hotmail.com
> > 
> > Hi Elisa,
> > In case you haven't noticed.
> > 
> > There is a slight difference in output in the matrix example using Bill's 
> > function and other functions.  Probably, you need to tweak the code a bit.
> > [[4]]
> >   IndexValue
> > 1 1 2.061959
> > 212 2.245474
> > 
> > 
> > 
> > 
> > 
> > - Original Message -
> > From: eliza botto 
> > To: William Dunlap ; "r-help@r-project.org" 
> > ; "ruipbarra...@sapo.pt" 
> > Cc: 
> > Sent: Friday, May 24, 2013 6:36 PM
> > Subject: Re: [R] Continuous columns of matrix
> > 
> > Dear William,
> > You loop worked well in case when i work with only one column. but wat if i 
> > have the following data. how will i do it then?
> > structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242, 
> > 1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443, 
> > 0.427434603701202, 0.591932250254601, 0.444627635494183, 1.44407704434405, 
> > 1.79150336746345, 0.94525563730664, 1.1025988539757, 0.944726401770203, 
> > 0.941068515436361, 1.50874009152312, 0.590015480056925, 0.311905493999476, 
> > 0.596771673581893, 1.01502499067153, 0.803273181849135, 1.6704085033648, 
> > 1.57021117646422, 0.563879907485297, 0.749077642331436, 0.681023650957497, 
> > 1.30140773002346, 1.46377246795771, 1.20312609775816, 0.651886452442823, 
> > 0.853749099839423, 1.041608733313, 0.690719733451964, 1.49415144965002, 
> > 1.30559703478921, 2.06195904001605, 1.41493262330451, 1.35748791897328, 
> > 1.19490680241894, 0.702488756183322, 0.338258418490199, 0.123398398622741, 
> > 0.138548982660226, 0.16170889185798, 0.414543218677095, 1.84629295875002, 
> > 2.24547399004563, 0.766278117577654, 0.751997501086888, 0.836280758630117, 
> > 1.188156460303,
> >  1.56771616670373, 1.5928168139479, 0.522523036011874, 0.561678840701488, 
> > 1.11155735914479, 1.26467106348848, 1.09378883406298, 1.17607018089421), 
> > .Dim = c(12L, 5L))
> > I used 3rd column in my first question..
> > 
> > thanks for the help
> > Elisa
> > 
> > 
> > > From: wdun...@tibco.com
> > > To: eliza_bo...@hotmail.com; ruipbarra...@sapo.pt; r-help@r-project.org
> > > Subject: RE: [R] Continuous columns of matrix
> > > Date: Fri, 24 May 2013 22:25:52 +
> > > 
> > > Are you trying to identify the highest point in each run of points higher 
> > > than a threshold,
> > > akin to the problem of naming mountains so that each minor bump on a high 
> > > ridge does not
> > > get its own name?  The following does that:
> > > 
> > > f <- function (x, threshold = 0.8 * max(x), plot=FALSE) 
> > > {
> > > if (plot) { plot(x, type="l") ; abline(h=threshold) }
> > > big <- x > threshold
> > > n <- length(big)
> > > startRunOfBigs <- which(c(big[1], !big[-n] & big[-1]))
> > > if (plot) abline(v=startRunOfBigs, col="green")
> > > endRunOfBigs <- which(c(big[-n] & !big[-1], big[n]))
> > > if (plot) abline(v=endRunOfBigs, col="red")
> > > stopifnot(length(startRunOfBigs) == length(endRunOfBigs),
> > >   all(startRunOfBigs <= endRunOfBigs))
> > > index <- vapply(seq_along(startRunOfBigs),
> > > 
> > > function(i)which.max(x[startRunOfBigs[i]:endRunOfBigs[i]])+startRunOfBigs[i]-1L,
> > > 0L)
> > > if (plot && length(index)>0) points(cex=1.5, index, x[index])
> > > data.frame(Index=index, Value=x[index])
> > > }
> > > 
> > > E.

Re: [R] Continuous columns of matrix

2013-05-24 Thread eliza botto
Dear Rui,
i just noticed that there is one slight problem in the William' code. If you 
see the results of column number 4 which are
[[4]]  IndexValue
1 12.061959
2122.245474 
where as we already dicussed that columns are continuous and 1 and 12 cant be 
picked together.
so the results should have been
[[4]]  IndexValue

1122.245474
how to get rid of this error??
Thanks in advance...
Elisa

> Date: Fri, 24 May 2013 23:38:51 +0100
> From: ruipbarra...@sapo.pt
> To: wdun...@tibco.com
> CC: eliza_bo...@hotmail.com; r-help@r-project.org
> Subject: Re: [R] Continuous columns of matrix
> 
> Hello,
> 
> Just use
> 
> apply(mat, 2, f)
> 
> Rui Barradas
> 
> Em 24-05-2013 23:25, William Dunlap escreveu:
> > Are you trying to identify the highest point in each run of points higher 
> > than a threshold,
> > akin to the problem of naming mountains so that each minor bump on a high 
> > ridge does not
> > get its own name?  The following does that:
> >
> > f <- function (x, threshold = 0.8 * max(x), plot=FALSE)
> > {
> >  if (plot) { plot(x, type="l") ; abline(h=threshold) }
> >  big <- x > threshold
> >  n <- length(big)
> >  startRunOfBigs <- which(c(big[1], !big[-n] & big[-1]))
> >  if (plot) abline(v=startRunOfBigs, col="green")
> >  endRunOfBigs <- which(c(big[-n] & !big[-1], big[n]))
> >  if (plot) abline(v=endRunOfBigs, col="red")
> >  stopifnot(length(startRunOfBigs) == length(endRunOfBigs),
> >all(startRunOfBigs <= endRunOfBigs))
> >  index <- vapply(seq_along(startRunOfBigs),
> >  
> > function(i)which.max(x[startRunOfBigs[i]:endRunOfBigs[i]])+startRunOfBigs[i]-1L,
> >  0L)
> >  if (plot && length(index)>0) points(cex=1.5, index, x[index])
> >  data.frame(Index=index, Value=x[index])
> > }
> >
> > E.g., with your data:
> >> x <- c(0.563879907485297, 0.749077642331436, 0.681023650957497, 
> >> 1.30140773002346,
> >1.46377246795771, 1.20312609775816, 0.651886452442823, 0.853749099839423,
> >1.041608733313, 0.690719733451964, 1.49415144965002, 1.30559703478921
> >)
> >> f(x, plot=TRUE) # the plot illustrates what it is doing
> >IndexValue
> > 1 5 1.463772
> > 211 1.494151
> >
> > Bill Dunlap
> > Spotfire, TIBCO Software
> > wdunlap tibco.com
> >
> >
> >> -Original Message-
> >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 
> >> On Behalf
> >> Of eliza botto
> >> Sent: Friday, May 24, 2013 2:10 PM
> >> To: ruipbarra...@sapo.pt; r-help@r-project.org
> >> Subject: Re: [R] Continuous columns of matrix
> >>
> >> Dear Rui,
> >> Regarding your last reply there is a small additional question which i 
> >> want to ask. For the
> >> following column
> >>> dput(mat[,1])c(0.563879907485297, 0.749077642331436, 0.681023650957497,
> >> 1.30140773002346, 1.46377246795771, 1.20312609775816, 0.651886452442823,
> >> 0.853749099839423, 1.041608733313, 0.690719733451964, 1.49415144965002,
> >> 1.30559703478921)
> >> Your loop gives following results
> >> [,1] [,2] [,3]  [,4]
> >> index  4.00 5.00 6.00 11.00
> >> values 1.301408 1.463772 1.203126  1.494151
> >> which is very accurate. Index 11 had the maximum value and 4,5,6 were the 
> >> neibhours. i
> >> want to add an other condition which is that if a column has more
> >> than 1 neibhours, than just like the maximum value, those neibhour can not 
> >> be next to
> >> each other as well.
> >> So what i should have is the following
> >>  [,1] [,2]
> >> index   5.00 11.00
> >> values  1.463772   1.494151
> >> Is there anyway of doing it??
> >> Thanks in advance
> >> Elisa
> >>
> >>> Date: Fri, 24 May 2013 17:02:56 +0100
> >>> From: ruipbarra...@sapo.pt
> >>> To: eliza_bo...@hotmail.com
> >>> CC: b...@xs4all.nl; r-help@r-project.org
> >>> Subject: Re: [R] Continuous columns of matrix
> >>>
> >>> Hello,
> >>>
> >>> No problem. Just change <0 to >= and Inf to -Inf:
> >>>
> >>> fun2 <- function(x){
> >>>   n <- length(x)
> >>>   imx <- which.max(x)
> >>>   if(imx == 1){
> >>>   x[2] <- x[n] <- -Inf
> >>>   }else if(imx == n){
> >>>   x[1] <- x[n - 1] <- -Inf
> >>>   }else{
> >>>   x[imx - 1] <- -Inf
> >>>   x[imx + 1] <- -Inf
> >>>   }
> >>>   index <- which(x >= 0.8*x[imx])
> >>>   values <- x[index]
> >>>   list(index = index, values = values)
> >>> }
> >>>
> >>> apply(mat, 2, fun2)
> >>>
> >>>
> >>> Rui Barradas
> >>>
> >>> Em 24-05-2013 16:23, eliza botto escreveu:
>  Dear Rui,
> 
>  I infact wanted to have something like the following..
>  suppose the columns are
> 
>  structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242,
> >> 1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443,
> >> 0.427434603701202, 0.591932250254601, 0.444627635494183, 1.44407704434405,
> >> 1.79150336746345, 2.06195904001605, 1.41493262330451, 1.35748791897328,
> >> 1.1949

Re: [R] Pie chart

2013-05-24 Thread Jim Lemon

On 05/25/2013 06:08 AM, Jose Narillos de Santos wrote:

I have a 8 Groups composed by A,B, c, D components. The Group 9 is composed
by the 8 Groups but only components A and C.


I want to chart a plot with 1 big plot of the total Groups (from 1 to 8) on
the right and 8 mini pies on the left composed by the 4 components (the
size of each pie of group should be bigger or smaller depending on the
total).

The same structure but below this plot I want to put on the left the plot
of Group 9 composed by Component A and C and on the left 8 pies composed by
Component B and C on Each Group.

I don´t know if it is posible.


Hi Jose,
Not only possible...

Group1<-c(1100,1000,100)
Group2<-c(728,380,38,10,300)
Group3<-c(320,200,20,50,50)
Group4<-c(110,80,8,20,2)
Group5<-c(75,40,4,5,26)
Group6<-c(38,30,3,2,3)
Group7<-c(16,10,1,5)
Group8<-c(10.5,5,0.5,4,1)
Total<-c(2397.5,1745,174.5,91,387)
Group9<-c(1836,1745,0,91,0)
x11(width=10,height=5)
par(mar=c(1,1,1,1))
plot(0,xlim=c(0,4),ylim=c(0,5),type="n",axes=FALSE)
piecol<-2:6
require(plotrix)
totalpos<-floating.pie(1,2.5,Total,col=piecol)
pielab<-LETTERS[1:5]
pie.labels(1,2.5,totalpos,pielab)
g1pos<-floating.pie(2.3,4,Group1,radius=0.2,col=piecol)
pie.labels(2.3,4,g1pos,pielab[1:3],radius=0.2)
g2pos<-floating.pie(2.7,3,Group2,radius=0.2,col=piecol)
pie.labels(2.7,3,g2pos,pielab,radius=0.2)
g3pos<-floating.pie(2.3,2,Group3,radius=0.2,col=piecol)
pie.labels(2.3,2,g3pos,pielab,radius=0.2)
g4pos<-floating.pie(2.7,1,Group4,radius=0.2,col=piecol)
pie.labels(2.7,1,g4pos,pielab,radius=0.2)
g5pos<-floating.pie(3.3,4,Group5,radius=0.2,col=piecol)
pie.labels(3.3,4,g5pos,pielab,radius=0.2)
g6pos<-floating.pie(3.7,3,Group6,radius=0.2,col=piecol)
pie.labels(3.7,3,g6pos,pielab,radius=0.2)
g7pos<-floating.pie(3.3,2,Group7,radius=0.2,col=piecol[c(1:3,5)])
pie.labels(3.3,2,g7pos,pielab[c(1:3,5)],radius=0.2)
g8pos<-floating.pie(3.7,1,Group8,radius=0.2,col=piecol)
pie.labels(3.7,1,g8pos,pielab,radius=0.2)

That should get you started. I think I will modify floating.pie so that 
it just ignores zero or NA values in the sector proportions.


Jim

__
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] Continuous columns of matrix

2013-05-24 Thread eliza botto
Thanks rui. 
you really are an R genius...
it might have taken me 1000 years to figure it out..
thanks

Elisa

> Date: Fri, 24 May 2013 23:38:51 +0100
> From: ruipbarra...@sapo.pt
> To: wdun...@tibco.com
> CC: eliza_bo...@hotmail.com; r-help@r-project.org
> Subject: Re: [R] Continuous columns of matrix
> 
> Hello,
> 
> Just use
> 
> apply(mat, 2, f)
> 
> Rui Barradas
> 
> Em 24-05-2013 23:25, William Dunlap escreveu:
> > Are you trying to identify the highest point in each run of points higher 
> > than a threshold,
> > akin to the problem of naming mountains so that each minor bump on a high 
> > ridge does not
> > get its own name?  The following does that:
> >
> > f <- function (x, threshold = 0.8 * max(x), plot=FALSE)
> > {
> >  if (plot) { plot(x, type="l") ; abline(h=threshold) }
> >  big <- x > threshold
> >  n <- length(big)
> >  startRunOfBigs <- which(c(big[1], !big[-n] & big[-1]))
> >  if (plot) abline(v=startRunOfBigs, col="green")
> >  endRunOfBigs <- which(c(big[-n] & !big[-1], big[n]))
> >  if (plot) abline(v=endRunOfBigs, col="red")
> >  stopifnot(length(startRunOfBigs) == length(endRunOfBigs),
> >all(startRunOfBigs <= endRunOfBigs))
> >  index <- vapply(seq_along(startRunOfBigs),
> >  
> > function(i)which.max(x[startRunOfBigs[i]:endRunOfBigs[i]])+startRunOfBigs[i]-1L,
> >  0L)
> >  if (plot && length(index)>0) points(cex=1.5, index, x[index])
> >  data.frame(Index=index, Value=x[index])
> > }
> >
> > E.g., with your data:
> >> x <- c(0.563879907485297, 0.749077642331436, 0.681023650957497, 
> >> 1.30140773002346,
> >1.46377246795771, 1.20312609775816, 0.651886452442823, 0.853749099839423,
> >1.041608733313, 0.690719733451964, 1.49415144965002, 1.30559703478921
> >)
> >> f(x, plot=TRUE) # the plot illustrates what it is doing
> >IndexValue
> > 1 5 1.463772
> > 211 1.494151
> >
> > Bill Dunlap
> > Spotfire, TIBCO Software
> > wdunlap tibco.com
> >
> >
> >> -Original Message-
> >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 
> >> On Behalf
> >> Of eliza botto
> >> Sent: Friday, May 24, 2013 2:10 PM
> >> To: ruipbarra...@sapo.pt; r-help@r-project.org
> >> Subject: Re: [R] Continuous columns of matrix
> >>
> >> Dear Rui,
> >> Regarding your last reply there is a small additional question which i 
> >> want to ask. For the
> >> following column
> >>> dput(mat[,1])c(0.563879907485297, 0.749077642331436, 0.681023650957497,
> >> 1.30140773002346, 1.46377246795771, 1.20312609775816, 0.651886452442823,
> >> 0.853749099839423, 1.041608733313, 0.690719733451964, 1.49415144965002,
> >> 1.30559703478921)
> >> Your loop gives following results
> >> [,1] [,2] [,3]  [,4]
> >> index  4.00 5.00 6.00 11.00
> >> values 1.301408 1.463772 1.203126  1.494151
> >> which is very accurate. Index 11 had the maximum value and 4,5,6 were the 
> >> neibhours. i
> >> want to add an other condition which is that if a column has more
> >> than 1 neibhours, than just like the maximum value, those neibhour can not 
> >> be next to
> >> each other as well.
> >> So what i should have is the following
> >>  [,1] [,2]
> >> index   5.00 11.00
> >> values  1.463772   1.494151
> >> Is there anyway of doing it??
> >> Thanks in advance
> >> Elisa
> >>
> >>> Date: Fri, 24 May 2013 17:02:56 +0100
> >>> From: ruipbarra...@sapo.pt
> >>> To: eliza_bo...@hotmail.com
> >>> CC: b...@xs4all.nl; r-help@r-project.org
> >>> Subject: Re: [R] Continuous columns of matrix
> >>>
> >>> Hello,
> >>>
> >>> No problem. Just change <0 to >= and Inf to -Inf:
> >>>
> >>> fun2 <- function(x){
> >>>   n <- length(x)
> >>>   imx <- which.max(x)
> >>>   if(imx == 1){
> >>>   x[2] <- x[n] <- -Inf
> >>>   }else if(imx == n){
> >>>   x[1] <- x[n - 1] <- -Inf
> >>>   }else{
> >>>   x[imx - 1] <- -Inf
> >>>   x[imx + 1] <- -Inf
> >>>   }
> >>>   index <- which(x >= 0.8*x[imx])
> >>>   values <- x[index]
> >>>   list(index = index, values = values)
> >>> }
> >>>
> >>> apply(mat, 2, fun2)
> >>>
> >>>
> >>> Rui Barradas
> >>>
> >>> Em 24-05-2013 16:23, eliza botto escreveu:
>  Dear Rui,
> 
>  I infact wanted to have something like the following..
>  suppose the columns are
> 
>  structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242,
> >> 1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443,
> >> 0.427434603701202, 0.591932250254601, 0.444627635494183, 1.44407704434405,
> >> 1.79150336746345, 2.06195904001605, 1.41493262330451, 1.35748791897328,
> >> 1.19490680241894, 0.702488756183322, 0.338258418490199, 0.123398398622741,
> >> 0.138548982660226, 0.16170889185798, 0.414543218677095, 1.84629295875002,
> >> 2.24547399004563), .Dim = c(12L, 2L))
> 
>  For col 1
>  [[1]]
>  $Index
>  5 12
>  $value
>  1.939 1.79
>  Although value 1.708 o

Re: [R] Continuous columns of matrix

2013-05-24 Thread Rui Barradas

Hello,

Just use

apply(mat, 2, f)

Rui Barradas

Em 24-05-2013 23:25, William Dunlap escreveu:

Are you trying to identify the highest point in each run of points higher than 
a threshold,
akin to the problem of naming mountains so that each minor bump on a high ridge 
does not
get its own name?  The following does that:

f <- function (x, threshold = 0.8 * max(x), plot=FALSE)
{
 if (plot) { plot(x, type="l") ; abline(h=threshold) }
 big <- x > threshold
 n <- length(big)
 startRunOfBigs <- which(c(big[1], !big[-n] & big[-1]))
 if (plot) abline(v=startRunOfBigs, col="green")
 endRunOfBigs <- which(c(big[-n] & !big[-1], big[n]))
 if (plot) abline(v=endRunOfBigs, col="red")
 stopifnot(length(startRunOfBigs) == length(endRunOfBigs),
   all(startRunOfBigs <= endRunOfBigs))
 index <- vapply(seq_along(startRunOfBigs),
 
function(i)which.max(x[startRunOfBigs[i]:endRunOfBigs[i]])+startRunOfBigs[i]-1L,
 0L)
 if (plot && length(index)>0) points(cex=1.5, index, x[index])
 data.frame(Index=index, Value=x[index])
}

E.g., with your data:

x <- c(0.563879907485297, 0.749077642331436, 0.681023650957497, 
1.30140773002346,

   1.46377246795771, 1.20312609775816, 0.651886452442823, 0.853749099839423,
   1.041608733313, 0.690719733451964, 1.49415144965002, 1.30559703478921
   )

f(x, plot=TRUE) # the plot illustrates what it is doing

   IndexValue
1 5 1.463772
211 1.494151

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf
Of eliza botto
Sent: Friday, May 24, 2013 2:10 PM
To: ruipbarra...@sapo.pt; r-help@r-project.org
Subject: Re: [R] Continuous columns of matrix

Dear Rui,
Regarding your last reply there is a small additional question which i want to 
ask. For the
following column

dput(mat[,1])c(0.563879907485297, 0.749077642331436, 0.681023650957497,

1.30140773002346, 1.46377246795771, 1.20312609775816, 0.651886452442823,
0.853749099839423, 1.041608733313, 0.690719733451964, 1.49415144965002,
1.30559703478921)
Your loop gives following results
[,1] [,2] [,3]  [,4]
index  4.00 5.00 6.00 11.00
values 1.301408 1.463772 1.203126  1.494151
which is very accurate. Index 11 had the maximum value and 4,5,6 were the 
neibhours. i
want to add an other condition which is that if a column has more
than 1 neibhours, than just like the maximum value, those neibhour can not be 
next to
each other as well.
So what i should have is the following
 [,1] [,2]
index   5.00 11.00
values  1.463772   1.494151
Is there anyway of doing it??
Thanks in advance
Elisa


Date: Fri, 24 May 2013 17:02:56 +0100
From: ruipbarra...@sapo.pt
To: eliza_bo...@hotmail.com
CC: b...@xs4all.nl; r-help@r-project.org
Subject: Re: [R] Continuous columns of matrix

Hello,

No problem. Just change <0 to >= and Inf to -Inf:

fun2 <- function(x){
n <- length(x)
imx <- which.max(x)
if(imx == 1){
x[2] <- x[n] <- -Inf
}else if(imx == n){
x[1] <- x[n - 1] <- -Inf
}else{
x[imx - 1] <- -Inf
x[imx + 1] <- -Inf
}
index <- which(x >= 0.8*x[imx])
values <- x[index]
list(index = index, values = values)
}

apply(mat, 2, fun2)


Rui Barradas

Em 24-05-2013 16:23, eliza botto escreveu:

Dear Rui,

I infact wanted to have something like the following..
suppose the columns are

structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242,

1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443,
0.427434603701202, 0.591932250254601, 0.444627635494183, 1.44407704434405,
1.79150336746345, 2.06195904001605, 1.41493262330451, 1.35748791897328,
1.19490680241894, 0.702488756183322, 0.338258418490199, 0.123398398622741,
0.138548982660226, 0.16170889185798, 0.414543218677095, 1.84629295875002,
2.24547399004563), .Dim = c(12L, 2L))


For col 1
[[1]]
$Index
5 12
$value
1.939 1.79
Although value 1.708 of index 4 also has value which is above 80% of the maximum

value but as it is in the neighbor of maxmimum value so we wont consider it.

similarly for the column 2
[[1]]
$Index
12
$value
2.245
Although values 1.846 of index 11 and 2.0619 of index 1 also have values which 
are

above 80% of the maximum value but as they are in the neighbor of maxmimum 
value so
we wont consider them.

i am sorry if the manner in which i asked my question was not conclusive.
i hope you wont mind...
Elisa

Date: Fri, 24 May 2013 15:59:50 +0100
From: ruipbarra...@sapo.pt
To: eliza_bo...@hotmail.com
CC: b...@xs4all.nl; r-help@r-project.org
Subject: Re: [R] Continuous columns of matrix

Hello,

Something like this?


fun2 <- function(x){
n <- length(x)
imx <- which.max(x)
if(imx == 1){
x[2] <- x[n] <- Inf
}else if(imx == n){

Re: [R] Continuous columns of matrix

2013-05-24 Thread eliza botto
Dear William,
You loop worked well in case when i work with only one column. but wat if i 
have the following data. how will i do it then?
structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242, 
1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443, 
0.427434603701202, 0.591932250254601, 0.444627635494183, 1.44407704434405, 
1.79150336746345, 0.94525563730664, 1.1025988539757, 0.944726401770203, 
0.941068515436361, 1.50874009152312, 0.590015480056925, 0.311905493999476, 
0.596771673581893, 1.01502499067153, 0.803273181849135, 1.6704085033648, 
1.57021117646422, 0.563879907485297, 0.749077642331436, 0.681023650957497, 
1.30140773002346, 1.46377246795771, 1.20312609775816, 0.651886452442823, 
0.853749099839423, 1.041608733313, 0.690719733451964, 1.49415144965002, 
1.30559703478921, 2.06195904001605, 1.41493262330451, 1.35748791897328, 
1.19490680241894, 0.702488756183322, 0.338258418490199, 0.123398398622741, 
0.138548982660226, 0.16170889185798, 0.414543218677095, 1.84629295875002, 
2.24547399004563, 0.766278117577654, 0.751997501086888, 0.836280758630117, 
1.188156460303, 1.56771616670373, 1.1!
 5928168139479, 0.522523036011874, 0.561678840701488, 1.11155735914479, 
1.26467106348848, 1.09378883406298, 1.17607018089421), .Dim = c(12L, 5L))
I used 3rd column in my first question..

thanks for the help
Elisa


> From: wdun...@tibco.com
> To: eliza_bo...@hotmail.com; ruipbarra...@sapo.pt; r-help@r-project.org
> Subject: RE: [R] Continuous columns of matrix
> Date: Fri, 24 May 2013 22:25:52 +
> 
> Are you trying to identify the highest point in each run of points higher 
> than a threshold,
> akin to the problem of naming mountains so that each minor bump on a high 
> ridge does not
> get its own name?  The following does that:
> 
> f <- function (x, threshold = 0.8 * max(x), plot=FALSE) 
> {
> if (plot) { plot(x, type="l") ; abline(h=threshold) }
> big <- x > threshold
> n <- length(big)
> startRunOfBigs <- which(c(big[1], !big[-n] & big[-1]))
> if (plot) abline(v=startRunOfBigs, col="green")
> endRunOfBigs <- which(c(big[-n] & !big[-1], big[n]))
> if (plot) abline(v=endRunOfBigs, col="red")
> stopifnot(length(startRunOfBigs) == length(endRunOfBigs),
>   all(startRunOfBigs <= endRunOfBigs))
> index <- vapply(seq_along(startRunOfBigs),
> 
> function(i)which.max(x[startRunOfBigs[i]:endRunOfBigs[i]])+startRunOfBigs[i]-1L,
> 0L)
> if (plot && length(index)>0) points(cex=1.5, index, x[index])
> data.frame(Index=index, Value=x[index])
> }
> 
> E.g., with your data:
> > x <- c(0.563879907485297, 0.749077642331436, 0.681023650957497, 
> > 1.30140773002346, 
>   1.46377246795771, 1.20312609775816, 0.651886452442823, 0.853749099839423, 
>   1.041608733313, 0.690719733451964, 1.49415144965002, 1.30559703478921
>   )
> > f(x, plot=TRUE) # the plot illustrates what it is doing
>   IndexValue
> 1 5 1.463772
> 211 1.494151
> 
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
> 
> 
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> > Behalf
> > Of eliza botto
> > Sent: Friday, May 24, 2013 2:10 PM
> > To: ruipbarra...@sapo.pt; r-help@r-project.org
> > Subject: Re: [R] Continuous columns of matrix
> > 
> > Dear Rui,
> > Regarding your last reply there is a small additional question which i want 
> > to ask. For the
> > following column
> > > dput(mat[,1])c(0.563879907485297, 0.749077642331436, 0.681023650957497,
> > 1.30140773002346, 1.46377246795771, 1.20312609775816, 0.651886452442823,
> > 0.853749099839423, 1.041608733313, 0.690719733451964, 1.49415144965002,
> > 1.30559703478921)
> > Your loop gives following results
> >[,1] [,2] [,3]  [,4]
> > index  4.00 5.00 6.00 11.00
> > values 1.301408 1.463772 1.203126  1.494151
> > which is very accurate. Index 11 had the maximum value and 4,5,6 were the 
> > neibhours. i
> > want to add an other condition which is that if a column has more
> > than 1 neibhours, than just like the maximum value, those neibhour can not 
> > be next to
> > each other as well.
> > So what i should have is the following
> > [,1] [,2]
> > index   5.00 11.00
> > values  1.463772   1.494151
> > Is there anyway of doing it??
> > Thanks in advance
> > Elisa
> > 
> > > Date: Fri, 24 May 2013 17:02:56 +0100
> > > From: ruipbarra...@sapo.pt
> > > To: eliza_bo...@hotmail.com
> > > CC: b...@xs4all.nl; r-help@r-project.org
> > > Subject: Re: [R] Continuous columns of matrix
> > >
> > > Hello,
> > >
> > > No problem. Just change <0 to >= and Inf to -Inf:
> > >
> > > fun2 <- function(x){
> > >   n <- length(x)
> > >   imx <- which.max(x)
> > >   if(imx == 1){
> > >   x[2] <- x[n] <- -Inf
> > >   }else if(imx == n){
> > >   x[1] <- x[n - 1] <- -Inf
> > >   }else{
> > >   x[imx - 1] <- -Inf
> > >   x[imx + 1] <- -Inf

Re: [R] Continuous columns of matrix

2013-05-24 Thread William Dunlap
Are you trying to identify the highest point in each run of points higher than 
a threshold,
akin to the problem of naming mountains so that each minor bump on a high ridge 
does not
get its own name?  The following does that:

f <- function (x, threshold = 0.8 * max(x), plot=FALSE) 
{
if (plot) { plot(x, type="l") ; abline(h=threshold) }
big <- x > threshold
n <- length(big)
startRunOfBigs <- which(c(big[1], !big[-n] & big[-1]))
if (plot) abline(v=startRunOfBigs, col="green")
endRunOfBigs <- which(c(big[-n] & !big[-1], big[n]))
if (plot) abline(v=endRunOfBigs, col="red")
stopifnot(length(startRunOfBigs) == length(endRunOfBigs),
  all(startRunOfBigs <= endRunOfBigs))
index <- vapply(seq_along(startRunOfBigs),

function(i)which.max(x[startRunOfBigs[i]:endRunOfBigs[i]])+startRunOfBigs[i]-1L,
0L)
if (plot && length(index)>0) points(cex=1.5, index, x[index])
data.frame(Index=index, Value=x[index])
}

E.g., with your data:
> x <- c(0.563879907485297, 0.749077642331436, 0.681023650957497, 
> 1.30140773002346, 
  1.46377246795771, 1.20312609775816, 0.651886452442823, 0.853749099839423, 
  1.041608733313, 0.690719733451964, 1.49415144965002, 1.30559703478921
  )
> f(x, plot=TRUE) # the plot illustrates what it is doing
  IndexValue
1 5 1.463772
211 1.494151

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf
> Of eliza botto
> Sent: Friday, May 24, 2013 2:10 PM
> To: ruipbarra...@sapo.pt; r-help@r-project.org
> Subject: Re: [R] Continuous columns of matrix
> 
> Dear Rui,
> Regarding your last reply there is a small additional question which i want 
> to ask. For the
> following column
> > dput(mat[,1])c(0.563879907485297, 0.749077642331436, 0.681023650957497,
> 1.30140773002346, 1.46377246795771, 1.20312609775816, 0.651886452442823,
> 0.853749099839423, 1.041608733313, 0.690719733451964, 1.49415144965002,
> 1.30559703478921)
> Your loop gives following results
>[,1] [,2] [,3]  [,4]
> index  4.00 5.00 6.00 11.00
> values 1.301408 1.463772 1.203126  1.494151
> which is very accurate. Index 11 had the maximum value and 4,5,6 were the 
> neibhours. i
> want to add an other condition which is that if a column has more
> than 1 neibhours, than just like the maximum value, those neibhour can not be 
> next to
> each other as well.
> So what i should have is the following
> [,1] [,2]
> index   5.00 11.00
> values  1.463772   1.494151
> Is there anyway of doing it??
> Thanks in advance
> Elisa
> 
> > Date: Fri, 24 May 2013 17:02:56 +0100
> > From: ruipbarra...@sapo.pt
> > To: eliza_bo...@hotmail.com
> > CC: b...@xs4all.nl; r-help@r-project.org
> > Subject: Re: [R] Continuous columns of matrix
> >
> > Hello,
> >
> > No problem. Just change <0 to >= and Inf to -Inf:
> >
> > fun2 <- function(x){
> > n <- length(x)
> > imx <- which.max(x)
> > if(imx == 1){
> > x[2] <- x[n] <- -Inf
> > }else if(imx == n){
> > x[1] <- x[n - 1] <- -Inf
> > }else{
> > x[imx - 1] <- -Inf
> > x[imx + 1] <- -Inf
> > }
> > index <- which(x >= 0.8*x[imx])
> > values <- x[index]
> > list(index = index, values = values)
> > }
> >
> > apply(mat, 2, fun2)
> >
> >
> > Rui Barradas
> >
> > Em 24-05-2013 16:23, eliza botto escreveu:
> > > Dear Rui,
> > >
> > > I infact wanted to have something like the following..
> > > suppose the columns are
> > >
> > > structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242,
> 1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443,
> 0.427434603701202, 0.591932250254601, 0.444627635494183, 1.44407704434405,
> 1.79150336746345, 2.06195904001605, 1.41493262330451, 1.35748791897328,
> 1.19490680241894, 0.702488756183322, 0.338258418490199, 0.123398398622741,
> 0.138548982660226, 0.16170889185798, 0.414543218677095, 1.84629295875002,
> 2.24547399004563), .Dim = c(12L, 2L))
> > >
> > > For col 1
> > > [[1]]
> > > $Index
> > > 5 12
> > > $value
> > > 1.939 1.79
> > > Although value 1.708 of index 4 also has value which is above 80% of the 
> > > maximum
> value but as it is in the neighbor of maxmimum value so we wont consider it.
> > > similarly for the column 2
> > > [[1]]
> > > $Index
> > > 12
> > > $value
> > > 2.245
> > > Although values 1.846 of index 11 and 2.0619 of index 1 also have values 
> > > which are
> above 80% of the maximum value but as they are in the neighbor of maxmimum 
> value so
> we wont consider them.
> > > i am sorry if the manner in which i asked my question was not conclusive.
> > > i hope you wont mind...
> > > Elisa
> > >> Date: Fri, 24 May 2013 15:59:50 +0100
> > >> From: ruipbarra...@sapo.pt
> > >> To: eliza_bo...@hotmail.com
> > >> CC: b...@xs4all.nl; r-help@r-project.org
> > >> Subject: Re: [R] Continuo

Re: [R] retaining comments within functions defined in Rprofile.site

2013-05-24 Thread Greg Snow
The help page "?Startup" gives details on the startup procedures and the
order in which different files, variables, etc. are read/executed.  That
may give you insight into where to set and option so that it is in place
when needed.


On Fri, May 24, 2013 at 3:46 PM, Benjamin Tyner  wrote:

> Hi,
>
> I have some functions defined within etc/Rprofile.site which contain
> embedded comments, but it seems the comments get stripped out when the
> site profile is sourced into the base namespace. I'm thinking I need to
> enable options(keep.source=TRUE) somewhere prior to the actual sourcing
> of the site profile, but haven't been able to figure it out yet. Does
> anyone have any suggestions?
>
> Thanks,
> Ben
>
>
> __
> 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

[[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] retaining comments within functions defined in Rprofile.site

2013-05-24 Thread Benjamin Tyner
Hi,

I have some functions defined within etc/Rprofile.site which contain
embedded comments, but it seems the comments get stripped out when the
site profile is sourced into the base namespace. I'm thinking I need to
enable options(keep.source=TRUE) somewhere prior to the actual sourcing
of the site profile, but haven't been able to figure it out yet. Does
anyone have any suggestions?

Thanks,
Ben

__
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] survival in R

2013-05-24 Thread Bert Gunter
It is not OK.

Post to a statistical list, like stats.stackexchange.com  , instead.

-- Bert

On Fri, May 24, 2013 at 1:55 PM, Troels Ring  wrote:
> Dear friends - I hope it is OK to ask a question on the principles of
> survival analysis. I'm a medical person in this project, but wonders about
> the statistical methods proposed. We have a huge dataset and assumption of
> proportional hazard is said to be fulfilled if survival time is fractionated
> into short, intermediate and long time survival. I wonder if it should not
> be better to have a more generalized method encompassing the entirety of the
> observation period.
>
> Best wishes
>
> Troels Ring, MD
> Department of nephrology
> Aalborg, Denmark
>
> __
> 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
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] Continuous columns of matrix

2013-05-24 Thread eliza botto
Dear Rui,
Regarding your last reply there is a small additional question which i want to 
ask. For the following column
> dput(mat[,1])c(0.563879907485297, 0.749077642331436, 0.681023650957497, 
> 1.30140773002346, 1.46377246795771, 1.20312609775816, 0.651886452442823, 
> 0.853749099839423, 1.041608733313, 0.690719733451964, 1.49415144965002, 
> 1.30559703478921)
Your loop gives following results
   [,1] [,2] [,3]  [,4]
index  4.00 5.00 6.00 11.00
values 1.301408 1.463772 1.203126  1.494151
which is very accurate. Index 11 had the maximum value and 4,5,6 were the 
neibhours. i want to add an other condition which is that if a column has more 
than 1 neibhours, than just like the maximum value, those neibhour can not be 
next to each other as well.
So what i should have is the following
[,1] [,2]
index   5.00 11.00
values  1.463772   1.494151
Is there anyway of doing it??
Thanks in advance
Elisa

> Date: Fri, 24 May 2013 17:02:56 +0100
> From: ruipbarra...@sapo.pt
> To: eliza_bo...@hotmail.com
> CC: b...@xs4all.nl; r-help@r-project.org
> Subject: Re: [R] Continuous columns of matrix
> 
> Hello,
> 
> No problem. Just change <0 to >= and Inf to -Inf:
> 
> fun2 <- function(x){
>   n <- length(x)
>   imx <- which.max(x)
>   if(imx == 1){
>   x[2] <- x[n] <- -Inf
>   }else if(imx == n){
>   x[1] <- x[n - 1] <- -Inf
>   }else{
>   x[imx - 1] <- -Inf
>   x[imx + 1] <- -Inf
>   }
>   index <- which(x >= 0.8*x[imx])
>   values <- x[index]
>   list(index = index, values = values)
> }
> 
> apply(mat, 2, fun2)
> 
> 
> Rui Barradas
> 
> Em 24-05-2013 16:23, eliza botto escreveu:
> > Dear Rui,
> >
> > I infact wanted to have something like the following..
> > suppose the columns are
> >
> > structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242, 
> > 1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443, 
> > 0.427434603701202, 0.591932250254601, 0.444627635494183, 1.44407704434405, 
> > 1.79150336746345, 2.06195904001605, 1.41493262330451, 1.35748791897328, 
> > 1.19490680241894, 0.702488756183322, 0.338258418490199, 0.123398398622741, 
> > 0.138548982660226, 0.16170889185798, 0.414543218677095, 1.84629295875002, 
> > 2.24547399004563), .Dim = c(12L, 2L))
> >
> > For col 1
> > [[1]]
> > $Index
> > 5 12
> > $value
> > 1.939 1.79
> > Although value 1.708 of index 4 also has value which is above 80% of the 
> > maximum value but as it is in the neighbor of maxmimum value so we wont 
> > consider it.
> > similarly for the column 2
> > [[1]]
> > $Index
> > 12
> > $value
> > 2.245
> > Although values 1.846 of index 11 and 2.0619 of index 1 also have values 
> > which are above 80% of the maximum value but as they are in the neighbor of 
> > maxmimum value so we wont consider them.
> > i am sorry if the manner in which i asked my question was not conclusive.
> > i hope you wont mind...
> > Elisa
> >> Date: Fri, 24 May 2013 15:59:50 +0100
> >> From: ruipbarra...@sapo.pt
> >> To: eliza_bo...@hotmail.com
> >> CC: b...@xs4all.nl; r-help@r-project.org
> >> Subject: Re: [R] Continuous columns of matrix
> >>
> >> Hello,
> >>
> >> Something like this?
> >>
> >>
> >> fun2 <- function(x){
> >>n <- length(x)
> >>imx <- which.max(x)
> >>if(imx == 1){
> >>x[2] <- x[n] <- Inf
> >>}else if(imx == n){
> >>x[1] <- x[n - 1] <- Inf
> >>}else{
> >>x[imx - 1] <- Inf
> >>x[imx + 1] <- Inf
> >>}
> >>index <- which(x <= 0.8*x[imx])
> >>values <- x[index]
> >>list(index = index, values = values)
> >> }
> >>
> >> apply(mat, 2, fun2)
> >>
> >>
> >> Rui Barradas
> >>
> >> Em 24-05-2013 13:40, eliza botto escreveu:
> >>> Dear Rui,Thankyou very much for your help. just for my own knowledge what 
> >>> if want the values and index, which are less than or equal to 80% of the 
> >>> maximum value other than those in the neighbors?? like if maximum is in 
> >>> row number 5 of any column then the second maximum can be in any row 
> >>> other than 4 and 6. similarly if maximum is in row number 12 than the 
> >>> second maximum can be in any row other than 1 and 11...thankyou very much 
> >>> for your help
> >>> elisa
> >>>
>  Date: Fri, 24 May 2013 12:37:37 +0100
>  From: ruipbarra...@sapo.pt
>  To: eliza_bo...@hotmail.com
>  CC: b...@xs4all.nl; r-help@r-project.org
>  Subject: Re: [R] Continuous columns of matrix
> 
>  Hello,
> 
>  Berend is right, it's at least confusing. To get just the index of the
>  maximum value in each column,
> 
>  apply(mat, 2, which.max)
> 
> 
>  To get that index and the two neighbours (before and after, wraping
>  around) if they are greater than or equal to 80% of the maximum, try
> 
>  fun <- function(x){
>   n <- length(x)
>   imx <- which.max(x)
>   sec <- numeric(2)
>   if(imx == 1){
>  

[R] survival in R

2013-05-24 Thread Troels Ring
Dear friends - I hope it is OK to ask a question on the principles of 
survival analysis. I'm a medical person in this project, but wonders 
about the statistical methods proposed. We have a huge dataset and 
assumption of proportional hazard is said to be fulfilled if survival 
time is fractionated into short, intermediate and long time survival. I 
wonder if it should not be better to have a more generalized method 
encompassing the entirety of the observation period.


Best wishes

Troels Ring, MD
Department of nephrology
Aalborg, Denmark

__
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 of random variables from a matrix of means and matrix of sd

2013-05-24 Thread Rui Barradas

Hello,

The first instruction doesn't call rnorm just once but it seems more 
appropriate for your problem;

The second instruction calls rnorm just once.


set.seed(59187)
res1 <- replicate(10, matrix(rnorm(4, mean = a, sd = b), ncol = 2))

set.seed(59187)
res2 <- array(rnorm(40, mean = a, sd = b), dim = c(2, 2, 10))

identical(res1, res2)  # TRUE


Hope this helps,

Rui Barradas

Em 24-05-2013 20:22, M M escreveu:

folks,
if i have a matrix of means:
a <- matrix(1:4, 2)
and a matrix of std deviations:
b <- matrix(5:8, 2)
and i want to create a matrix X of random variates such that X[i, j] is a draw 
from normal distribution with mean = a[i, j] and std dev =  b[i, j], i think i 
can do this?
X <- matrix(rnorm(4, mean = a, sd = b), ncol = 2)
now if I want to create 10 such matrices, I could possibly do this:
lapply(1:10, function(x) matrix(rnorm(4, mean = a, sd = b), ncol = 2))
is there a better way to do this with perhaps just one call to the rnorm() 
function?
cheers,
murali  
[[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] Pie chart

2013-05-24 Thread Rui Barradas

Hello,

Can you please use ?dput to post your data?
The dataset you've posted doesn't make sense, you say you have 4 
components but each row has 5 values, and that includes Group 9, which 
should have only 2 values (or 4 values with 2 zeros).


Rui Barradas

Em 24-05-2013 21:08, Jose Narillos de Santos escreveu:

I have a 8 Groups composed by A,B, c, D components. The Group 9 is composed
by the 8 Groups but only components A and C.


I want to chart a plot with 1 big plot of the total Groups (from 1 to 8) on
the right and 8 mini pies on the left composed by the 4 components (the
size of each pie of group should be bigger or smaller depending on the
total).

The same structure but below this plot I want to put on the left the plot
of Group 9 composed by Component A and C and on the left 8 pies composed by
Component B and C on Each Group.

I don´t know if it is posible.


And If I have explain well...





components Component A Component B Component C Component D
Group 1 1100 1000 100 0 0
Group 2 728 380 38 10 300
Group 3 320 200 20 50 50
Group 4 110 80 8 20 2
Group 5 75 40 4 5 26
Group 6 38 30 3 2 3
Group 7 16 10 1 0 5
Group 8 10,5 5 0,5 4 1
Total 2397,5 1745 174,5 91 387
Group 9 1836 1745 0 91 0

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


[R] modeling outliers in arfima

2013-05-24 Thread Koopmans, Matthijs
Hello,

I am analyzing a time series trajectory with many outliers.

When I model the outliers using arima (TSA library),  the following program 
statement runs like a charm:

m3.m495<-arima(Rate,order=c(1,0,1),seasonal=list(order=c(1,0,1),period=5),
  xreg=data.frame(t74=1*(seq(Rate)==74),t107=1*(seq(Rate)==107)))

'Rate' is the outcome variable. The program generates the regular arima 
estimates as well as those associated with the outliers (here t=74 and 107).

The corresponding arfima statement (arfima library) follows:

m495.m4a<-arfima(Rate,order=c(1,0,1),lmodel="g", numeach=c(1,1),
 seasonal=list(order=c(1,0,1), period=5,numeach=c(1,1),
 xreg=data.frame(t74=1*(seq(Rate)==74),t107=1*(seq(Rate)==107)))

The program accepts this language and produces the regular arfima estimates, 
but not those associated with the outliers.

I' be greatly helped by any insights as to why this might be the case.

Regards,

Matt Koopmans

__
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] Pie chart

2013-05-24 Thread Jose Narillos de Santos
I have a 8 Groups composed by A,B, c, D components. The Group 9 is composed
by the 8 Groups but only components A and C.


I want to chart a plot with 1 big plot of the total Groups (from 1 to 8) on
the right and 8 mini pies on the left composed by the 4 components (the
size of each pie of group should be bigger or smaller depending on the
total).

The same structure but below this plot I want to put on the left the plot
of Group 9 composed by Component A and C and on the left 8 pies composed by
Component B and C on Each Group.

I don´t know if it is posible.


And If I have explain well...





components Component A Component B Component C Component D
Group 1 1100 1000 100 0 0
Group 2 728 380 38 10 300
Group 3 320 200 20 50 50
Group 4 110 80 8 20 2
Group 5 75 40 4 5 26
Group 6 38 30 3 2 3
Group 7 16 10 1 0 5
Group 8 10,5 5 0,5 4 1
Total 2397,5 1745 174,5 91 387
Group 9 1836 1745 0 91 0

[[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] xtable() with booktabs option problem

2013-05-24 Thread John Kane
i knew it was something stunningly stupid.  Thanks a lot.

John Kane
Kingston ON Canada


> -Original Message-
> From: marc_schwa...@me.com
> Sent: Fri, 24 May 2013 14:41:52 -0500
> To: jrkrid...@inbox.com
> Subject: Re: [R] xtable() with booktabs option problem
> 
> On May 24, 2013, at 2:36 PM, John Kane  wrote:
> 
>> I could have sworn that yesterday xtable(file, booktabs = TRUE) was
>> giving me toprule , midrule and bottomrule outout. Today :
>> 
>> library(xtable)
>> aa  <- table( sample(letters[1:9], 100, replace = TRUE))
>>  xtable(aa,
>> booktabs = TRUE)
>> gives me
>> 
>> \begin{table}[ht]
>> \centering
>> \begin{tabular}{rr}
>>  \hline
>> & V1 \\
>>  \hline
>> a &  15 \\
>>  b &  11 \\
>>  c &  13 \\
>>  d &  14 \\
>>  e &  10 \\
>>  f &  12 \\
>>  g &  10 \\
>>  h &   6 \\
>>  i &   9 \\
>>   \hline
>> \end{tabular}
>> \end{table}
>> 
>> What stunningly stupid thing am I doing?
>> 
>> John Kane
>> Kingston ON Canada
> 
> 
> John,
> 
> The 'booktabs' argument is for print.xtable(), not xtable(). Easy
> mistake.
> 
> Thus:
> 
>> print(xtable(aa), booktabs = TRUE)
> % latex table generated in R 3.0.1 by xtable 1.7-1 package
> % Fri May 24 14:40:07 2013
> \begin{table}[ht]
> \centering
> \begin{tabular}{rr}
>   \toprule
>  & V1 \\
>   \midrule
> a &   9 \\
>   b &   8 \\
>   c &  17 \\
>   d &   9 \\
>   e &   7 \\
>   f &  16 \\
>   g &  13 \\
>   h &  10 \\
>   i &  11 \\
>\bottomrule
> \end{tabular}
> \end{table}
> 
> 
> Regards,
> 
> Marc Schwartz


FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your 
desktop!

__
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] xtable() with booktabs option problem

2013-05-24 Thread Marc Schwartz
On May 24, 2013, at 2:36 PM, John Kane  wrote:

> I could have sworn that yesterday xtable(file, booktabs = TRUE) was giving me 
> toprule , midrule and bottomrule outout. Today :
> 
> library(xtable)
> aa  <- table( sample(letters[1:9], 100, replace = TRUE))
>  xtable(aa, 
> booktabs = TRUE)
> gives me
> 
> \begin{table}[ht]
> \centering
> \begin{tabular}{rr}
>  \hline
> & V1 \\ 
>  \hline
> a &  15 \\ 
>  b &  11 \\ 
>  c &  13 \\ 
>  d &  14 \\ 
>  e &  10 \\ 
>  f &  12 \\ 
>  g &  10 \\ 
>  h &   6 \\ 
>  i &   9 \\ 
>   \hline
> \end{tabular}
> \end{table}
> 
> What stunningly stupid thing am I doing?
> 
> John Kane
> Kingston ON Canada


John,

The 'booktabs' argument is for print.xtable(), not xtable(). Easy mistake.

Thus:

> print(xtable(aa), booktabs = TRUE)
% latex table generated in R 3.0.1 by xtable 1.7-1 package
% Fri May 24 14:40:07 2013
\begin{table}[ht]
\centering
\begin{tabular}{rr}
  \toprule
 & V1 \\ 
  \midrule
a &   9 \\ 
  b &   8 \\ 
  c &  17 \\ 
  d &   9 \\ 
  e &   7 \\ 
  f &  16 \\ 
  g &  13 \\ 
  h &  10 \\ 
  i &  11 \\ 
   \bottomrule
\end{tabular}
\end{table}


Regards,

Marc Schwartz

__
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] xtable() with booktabs option problem

2013-05-24 Thread John Kane
I could have sworn that yesterday xtable(file, booktabs = TRUE) was giving me 
toprule , midrule and bottomrule outout. Today :

library(xtable)
 aa  <- table( sample(letters[1:9], 100, replace = TRUE))
  xtable(aa, 
 booktabs = TRUE)
gives me

\begin{table}[ht]
\centering
\begin{tabular}{rr}
  \hline
 & V1 \\ 
  \hline
a &  15 \\ 
  b &  11 \\ 
  c &  13 \\ 
  d &  14 \\ 
  e &  10 \\ 
  f &  12 \\ 
  g &  10 \\ 
  h &   6 \\ 
  i &   9 \\ 
   \hline
\end{tabular}
\end{table}

What stunningly stupid thing am I doing?

John Kane
Kingston ON Canada


FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!

__
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] To get the dataframe

2013-05-24 Thread arun
Lines1<- readLines(textConnection("[1] 1.000 0.000 0.3425584 0.000
[1] 1.000 0.3425584 1.6693396 0.000
[1] 1.00 1.669340 9.918513 0.00
[1]  1.00  9.918513 24.00  0.00
-- more lines-
- -
[1] 18.0 10.79634 24.0  0.0
[1] 19.00  0.00  5.969107  0.00
[1] 19.00  5.969107  9.245121  0.00
[1] 19.00  9.245121 12.253784  1.00
[1] 19.0 12.25378 15.81035  0.0
[1] 19.0 15.81035 24.0  0.0
[1] 20  0 24  0"))
 dat1<-read.table(text=gsub("\\[.*\\]\\s+","",Lines1),sep="",header=FALSE)
 str(dat1)
#'data.frame':    96 obs. of  4 variables:
# $ V1: num  1 1 1 1 2 2 3 3 3 3 ...
# $ V2: num  0 0.343 1.669 9.919 0 ...
# $ V3: num  0.343 1.669 9.919 24 3.178 ...
# $ V4: num  0 0 0 0 1 0 1 0 0 0 ...
A.K.



ibrary(Rlab) 

for(id in 1:20) 
{ 
start<-stop<-event<-0 
while(stop < 24) 
{ 
t<-rexp(1,1/6) 
stop<-start+t 
d1<-cbind(id,start) 
event<-rbern(1,0.2) 
start<-stop 
if(stop >= 24)event = 0 
if(stop >=24) stop = 24 
d2<-cbind(d1,stop,event) 
d3<-d2[1:4] 
print(d3) 
} 
} 
 If i run this code i m getting result like this 


[1] 1.000 0.000 0.3425584 0.000 
[1] 1.000 0.3425584 1.6693396 0.000 
[1] 1.00 1.669340 9.918513 0.00 
[1]  1.00  9.918513 24.00  0.00 
[1] 2.0 0.0 3.17837 1.0 
[1]  2.0  3.17837 24.0  0.0 
[1] 3.00 0.00 9.476766 1.00 
[1]  3.00  9.476766 15.494332  0.00 
[1]  3.0 15.49433 21.37152  0.0 
[1]  3.0 21.37152 22.16820  0.0 
[1]  3. 22.1682 24.  0. 
[1] 4.00 0.00 1.080512 0.00 
[1] 4.00 1.080512 2.014019 0.00 
[1] 4.00 2.014019 2.569652 0.00 
[1] 4.00 2.569652 6.857931 0.00 
[1]  4.00  6.857931 10.178343  1.00 
[1]  4.0 10.17834 24.0  0.0 
[1] 5.00 0.00 4.511939 0.00 
[1]  5.00  4.511939 11.594630  0.00 
[1]  5.0 11.59463 14.01093  0.0 
[1]  5.0 14.01093 16.00668  1.0 
[1]  5.0 16.00668 24.0  0.0 
[1] 6.00 0.00 1.233892 0.00 
[1] 6.00 1.233892 4.230937 0.00 
[1] 6.00 4.230937 7.896710 0.00 
[1]  6.0  7.89671 12.12295  0.0 
[1]  6.0 12.12295 12.26680  0.0 
[1]  6.0 12.26680 14.16343  0.0 
[1]  6.0 14.16343 24.0  0.0 
[1] 7.000 0.000 0.6095759 1.000 
[1] 7.000 0.6095759 2.5180034 0.000 
[1] 7.00 2.518003 4.447908 0.00 
[1] 7.00 4.447908 5.553377 0.00 
[1] 7.00 5.553377 6.202340 0.00 
[1]  7.0  6.20234 11.38621  0.0 
[1]  7.0 11.38621 14.21892  0.0 
[1]  7.0 14.21892 19.64888  0.0 
[1]  7.0 19.64888 24.0  0.0 
[1]  8.0  0.0 16.98726  0.0 
[1]  8.0 16.98726 24.0  0.0 
[1] 9.00 0.00 5.052501 0.00 
[1]  9.00  5.052501 15.062599  0.00 
[1]  9.0 15.06260 20.92183  1.0 
[1]  9.0 20.92183 21.86589  0.0 
[1]  9.0 21.86589 24.0  0.0 
[1] 10.  0. 11.3999  1. 
[1] 10.0 11.39990 17.13263  0.0 
[1] 10.0 17.13263 24.0  0.0 
[1] 11.0  0.0 11.16255  0.0 
[1] 11.0 11.16255 22.78863  1.0 
[1] 11.0 22.78863 24.0  0.0 
[1] 12.0  0.0  9.17559  1.0 
[1] 12.00  9.175590  9.812284  0.00 
[1] 12.00  9.812284 15.122447  0.00 
[1] 12.0 15.12245 19.82610  0.0 
[1] 12. 19.8261 24.  0. 
[1] 13.00  0.00  9.593531  1.00 
[1] 13.00  9.593531 15.633208  0.00 
[1] 13.0 15.63321 17.93700  0.0 
[1] 13.000 17.937 24.000  0.000 
[1] 14.00  0.00  3.826149  1.00 
[1] 14.00  3.826149  9.580028  1.00 
[1] 14.00  9.580028 17.948443  0.00 
[1] 14.0 17.94844 19.99766  0.0 
[1] 14.0 19.99766 20.60565  0.0 
[1] 14.0 20.60565 23.30993  1.0 
[1] 14.0 23.30993 24.0  0.0 
[1] 15.000  0.000  0.3070073  0.000 
[1] 15.000  0.3070073  4.9818421  1.000 
[1] 15.00  4.981842  6.306170  0.00 
[1] 15.0  6.30617 17.05091  1.0 
[1] 15.0 17.05091 22.98966  0.0 
[1] 15.0 22.98966 24.0  0.0 
[1] 16.000  0.000  0.3339885  1.000 
[1] 16.000  0.3339885  6.3189698  0.000 
[1] 16.0  6.31897 11.75264  0.0 
[1] 16.0 11.75264 14.64896  0.0 
[1] 16.0 14.64896 15.00901  0.0 
[1] 16.0 15.00901 16.88176  1.0 
[1] 16.0 16.88176 19.38106  0.0 
[1] 16.0 19.38106 23.10810  0.0 
[1] 16. 23.1081 24.  0. 
[1] 17  0 24  0 
[1] 18.00  0.00  4.410794  1.00 
[1] 18.00  4.410794  5.545209  0.00 
[1] 18.00  5.545209  7.051287  1.00 
[1] 18.00  7.051287  8.762234  0.00 
[1] 18.00  8.762234 10.718486  0.00 
[1] 18.0 10.71849 10.79634  0.0 
[1] 18.0 10.79634 24.0  0.0 
[1] 19.00  

[R] matrix of random variables from a matrix of means and matrix of sd

2013-05-24 Thread M M
folks,
if i have a matrix of means:
a <- matrix(1:4, 2)
and a matrix of std deviations:
b <- matrix(5:8, 2)
and i want to create a matrix X of random variates such that X[i, j] is a draw 
from normal distribution with mean = a[i, j] and std dev =  b[i, j], i think i 
can do this?
X <- matrix(rnorm(4, mean = a, sd = b), ncol = 2)
now if I want to create 10 such matrices, I could possibly do this:
lapply(1:10, function(x) matrix(rnorm(4, mean = a, sd = b), ncol = 2))  
is there a better way to do this with perhaps just one call to the rnorm() 
function?
cheers,
murali
[[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] R 3.0.0

2013-05-24 Thread Ben Bolker
David Winsemius  comcast.net> writes:

> 
> 
> On May 24, 2013, at 8:29 AM, Simmons, Susan J. wrote:
> 
> > In the newest release of R (R 3.0.0), the "glm" package
>  no longer supports logistic nor probit regression. 
> Was this intentional?  What package is best to use in the 
> newest version of R to perform logistic or probit regression?
> > 
> 
>  I would be very skeptical about that claim. 
> Where is your evidence? Have you looked at:
> 
> ?family  # ?
> ?quasi   # ?

  I'm skeptical too. 'glm()' is the 'stats' package which comes
with R and is automatically loaded.

  glm(...,family=binomial)  runs a logistic regression

(the default link is logit, so this is equivalent to 
family=binomial(link="logit"), if you prefer explicitness
over brevity)

  glm(...,family=binomial(link="probit"))

runs a probit regression.

   I'd actually be quite curious to hear how you reached
this conclusion, in case there is confusing or mis-information
going around that we can correct ...

  Ben Bolker

__
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] Creating an R function wrapper for a bash shell script

2013-05-24 Thread John Pellman
This is exactly what I want!  Thank you very much!


2013/5/24 Greg Snow <538...@gmail.com>

> Look at the 'system.file' function.
>
>
> On Fri, May 24, 2013 at 11:27 AM, John Pellman <
> john.samoylovich.pell...@gmail.com> wrote:
>
>> Hi!
>>
>> I'm trying to set up an R library for a common analysis that my lab does.
>>  This analysis involves the use of an external bash script, which I would
>> like to encapsulate within the R library.  I have been looking at
>> tutorials
>> that detail how to create packages, and many of them mention an
>> experimental "exec" directory where one can store Perl, Java, bash
>> scripts,
>> etc.  I was wondering how one might tell an R function to execute a shell
>> script in this directory (I've been thinking along the lines of using
>> system() to execute the script, but I am uncertain what the path to 'exec'
>> would be; my best guess is that the path to 'exec' might be found using
>> the
>> .libPaths() command).
>>
>> Many thanks,
>> John Pellman
>>
>> [[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.
>>
>
>
>
> --
> Gregory (Greg) L. Snow Ph.D.
> 538...@gmail.com
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Question about Rpart function

2013-05-24 Thread puja makkar
Hello,

When considering linear function where dependent variable is a function of
lags of dependent variables ( co-variates are kind of auto
regressive).Question is .Can i take entire data set for rpart . Then
split data into training and testing and validate the model for testing
data.In testing data previously predicted value will be the lag of
dependent variable for next prediction.


Thanks,
Puja

[[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] Continuous columns of matrix

2013-05-24 Thread eliza botto
Thankyou very very much arun.:Delisa

> Date: Fri, 24 May 2013 11:08:56 -0700
> From: smartpink...@yahoo.com
> Subject: Re: [R] Continuous columns of matrix
> To: eliza_bo...@hotmail.com
> CC: r-help@r-project.org; ruipbarra...@sapo.pt
> 
> Hi,
> You may also try:
> mat: data
> 
> lst1<-lapply(split(mat,col(mat)),function(x) {x1<- which(x>=0.8*max(x));x2<- 
> which.max(x);x1[abs(x1-x2)==1|length(x)-abs(x1-x2)==1]<-NA;rbind(index=x1[!is.na(x1)],values=x[x1[!is.na(x1)]])})
> names(lst1)<-NULL
> 
> lst2<-apply(mat,2,function(x) do.call(rbind,fun2(x))) #Rui's function
>  identical(lst1,lst2)
> #[1] TRUE
> A.K.
> 
> - Original Message -
> 
> From: eliza botto 
> To: Berend Hasselman 
> Cc: "r-help@r-project.org" 
> Sent: Friday, May 24, 2013 6:41 AM
> Subject: Re: [R] Continuous columns of matrix
> 
> There you go!!!
> 
> structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242, 
> 1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443, 
> 0.427434603701202, 0.591932250254601, 0.444627635494183, 1.44407704434405, 
> 1.79150336746345, 0.94525563730664, 1.1025988539757, 0.944726401770203, 
> 0.941068515436361, 1.50874009152312, 0.590015480056925, 0.311905493999476, 
> 0.596771673581893, 1.01502499067153, 0.803273181849135, 1.6704085033648, 
> 1.57021117646422, 0.492096635764151, 0.42688044914, 0.521585941816778, 
> 1.66472272302545, 2.61878329527404, 2.19154489521664, 0.493876245329722, 
> 0.4915787202584, 0.889477365620806, 0.609135860199222, 0.739201878930367, 
> 0.854663750519518, 0.948228727226247, 1.38569091844218, 0.910510759802679, 
> 1.25991218521949, 0.993123416952421, 0.553640392997634, 0.357487763503204, 
> 0.368328033777003, 0.344255688489322, 0.423679560916755, 1.32093576037521, 
> 3.13420679229785, 2.06195904001605, 1.41493262330451, 1.35748791897328,
>  1.19490680241894, 0.70248875618332!
> 2, 0.338258418490199, 0.123398398622741, 0.138548982660226, 0.16170889185798, 
> 0.414543218677095, 1.84629295875002, 2.24547399004563, 0.0849732189580101, 
> 0.070591276171845, 0.0926010253161898, 0.362209761457517, 1.45769283057202, 
> 3.16165004659667, 2.74903557756267, 1.94633472878995, 1.19319875840883, 
> 0.533232612926756, 0.225531074123974, 0.122949089115578), .Dim = c(12L, 6L))
> 
> Thanks once again..
> Elisa
> 
> 
> > Subject: Re: [R] Continuous columns of matrix
> > From: b...@xs4all.nl
> > Date: Fri, 24 May 2013 12:36:47 +0200
> > CC: r-help@r-project.org
> > To: eliza_bo...@hotmail.com
> > 
> > 
> > On 24-05-2013, at 12:24, eliza botto  wrote:
> > 
> > > Dear useRs,If i have a matrix, say, 12 rows and 6 columns. The columns 
> > > are continuous. I  want to find the index of maximum values and the 
> > > actual maximum values. The maximum values in each column are the highest 
> > > values and the values greater than or equal to 80% of the maximum value. 
> > > Moreover, if a column has more than one maximum values than these values 
> > > should come immediately next to each other.  For example, if you column 1 
> > > has a highest value in 6th row then the second maximum values cant be in 
> > > row 5 or 7. And as the columns are continuous therefore, if maximum value 
> > > is in row 12th, then the second maximum cant be in row 11 and 1.Thankyou 
> > > very much indeed in advance
> > 
> > 
> > Incomprehensible.
> > What is a continuous column?
> > 
> > Please give an example input matrix and and the result you want.
> > 
> > Berend
> > 
> > > Elisa
> > > [[alternative HTML version deleted]]
> > > 
> > 
> > Please post in plain text.
> > 
>   
> [[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] Continuous columns of matrix

2013-05-24 Thread arun
Hi,
You may also try:
mat: data

lst1<-lapply(split(mat,col(mat)),function(x) {x1<- which(x>=0.8*max(x));x2<- 
which.max(x);x1[abs(x1-x2)==1|length(x)-abs(x1-x2)==1]<-NA;rbind(index=x1[!is.na(x1)],values=x[x1[!is.na(x1)]])})
names(lst1)<-NULL

lst2<-apply(mat,2,function(x) do.call(rbind,fun2(x))) #Rui's function
 identical(lst1,lst2)
#[1] TRUE
A.K.

- Original Message -

From: eliza botto 
To: Berend Hasselman 
Cc: "r-help@r-project.org" 
Sent: Friday, May 24, 2013 6:41 AM
Subject: Re: [R] Continuous columns of matrix

There you go!!!

structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242, 
1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443, 
0.427434603701202, 0.591932250254601, 0.444627635494183, 1.44407704434405, 
1.79150336746345, 0.94525563730664, 1.1025988539757, 0.944726401770203, 
0.941068515436361, 1.50874009152312, 0.590015480056925, 0.311905493999476, 
0.596771673581893, 1.01502499067153, 0.803273181849135, 1.6704085033648, 
1.57021117646422, 0.492096635764151, 0.42688044914, 0.521585941816778, 
1.66472272302545, 2.61878329527404, 2.19154489521664, 0.493876245329722, 
0.4915787202584, 0.889477365620806, 0.609135860199222, 0.739201878930367, 
0.854663750519518, 0.948228727226247, 1.38569091844218, 0.910510759802679, 
1.25991218521949, 0.993123416952421, 0.553640392997634, 0.357487763503204, 
0.368328033777003, 0.344255688489322, 0.423679560916755, 1.32093576037521, 
3.13420679229785, 2.06195904001605, 1.41493262330451, 1.35748791897328,
 1.19490680241894, 0.70248875618332!
2, 0.338258418490199, 0.123398398622741, 0.138548982660226, 0.16170889185798, 
0.414543218677095, 1.84629295875002, 2.24547399004563, 0.0849732189580101, 
0.070591276171845, 0.0926010253161898, 0.362209761457517, 1.45769283057202, 
3.16165004659667, 2.74903557756267, 1.94633472878995, 1.19319875840883, 
0.533232612926756, 0.225531074123974, 0.122949089115578), .Dim = c(12L, 6L))

Thanks once again..
Elisa


> Subject: Re: [R] Continuous columns of matrix
> From: b...@xs4all.nl
> Date: Fri, 24 May 2013 12:36:47 +0200
> CC: r-help@r-project.org
> To: eliza_bo...@hotmail.com
> 
> 
> On 24-05-2013, at 12:24, eliza botto  wrote:
> 
> > Dear useRs,If i have a matrix, say, 12 rows and 6 columns. The columns are 
> > continuous. I  want to find the index of maximum values and the actual 
> > maximum values. The maximum values in each column are the highest values 
> > and the values greater than or equal to 80% of the maximum value. Moreover, 
> > if a column has more than one maximum values than these values should come 
> > immediately next to each other.  For example, if you column 1 has a highest 
> > value in 6th row then the second maximum values cant be in row 5 or 7. And 
> > as the columns are continuous therefore, if maximum value is in row 12th, 
> > then the second maximum cant be in row 11 and 1.Thankyou very much indeed 
> > in advance
> 
> 
> Incomprehensible.
> What is a continuous column?
> 
> Please give an example input matrix and and the result you want.
> 
> Berend
> 
> > Elisa                            
> >     [[alternative HTML version deleted]]
> > 
> 
> Please post in plain text.
> 
                          
    [[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] Creating an R function wrapper for a bash shell script

2013-05-24 Thread Greg Snow
Look at the 'system.file' function.


On Fri, May 24, 2013 at 11:27 AM, John Pellman <
john.samoylovich.pell...@gmail.com> wrote:

> Hi!
>
> I'm trying to set up an R library for a common analysis that my lab does.
>  This analysis involves the use of an external bash script, which I would
> like to encapsulate within the R library.  I have been looking at tutorials
> that detail how to create packages, and many of them mention an
> experimental "exec" directory where one can store Perl, Java, bash scripts,
> etc.  I was wondering how one might tell an R function to execute a shell
> script in this directory (I've been thinking along the lines of using
> system() to execute the script, but I am uncertain what the path to 'exec'
> would be; my best guess is that the path to 'exec' might be found using the
> .libPaths() command).
>
> Many thanks,
> John Pellman
>
> [[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.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Multinomial logistic regression

2013-05-24 Thread manna
Is it possible to use function "glm" in case when my outcome variable has 5
different classes? I have seen examples only when using binomial outcome
variable.  

What about using function "multinom"? How do I to get the signifigance and
the confidence levels of the coefficients and the value of goodness of the
model with this function? 

Thank You for Your help!



--
View this message in context: 
http://r.789695.n4.nabble.com/Multinomial-logistic-regression-tp4667923.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] Generating Predicted Probabilities in a Data Frame from a Logit Model

2013-05-24 Thread Abraham Mathew
I'm trying to run a logit model in R which has only one predictor. I then
want to construct a data frame with the predictor values on one column and
the probabilities in another column.

Using LDA methodology, I'm able to do the following.

# RUN LDA
r <- lda(y ~ x)

## FIND AND PLOT MODEL PROBABILITIES
xx <- seq(min(x), max(x), length=1000)
pred <- predict(r, data.frame(x=xx), type='response')
yy <- pred$posterior[,2]

t = data.frame(Our_Bid=c(xx), "Pr(win)"=c(yy))
head(t, 10)

> head(t, 10)
 Our_Bid   Pr.win.
1   0.00 0.1525893
2   3.096096 0.1538502
3   6.192192 0.1551196
4   9.288288 0.1563976
5  12.384384 0.1576841
6  15.480480 0.1589792
7  18.576577 0.1602829
8  21.672673 0.1615952
9  24.768769 0.1629162
10 27.864865 0.1642459

I want to do something similar with glm but I'm not finding that I'm able
to manipulate predict() such that I can get a similar output as ^^.

mod1 = glm(posted ~ amount, data=ndat, family=binomial(link="probit"))
summary(mod1)


Can anyone help?



Thanks!




-- 
*Abraham Mathew
Statistical Analyst
**720-648-0108*
*abmathe...@gmail.com
*
*Twitter 
**LinkedIn
**Blog 
**Tumblr
About.Me *

[[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] Creating an R function wrapper for a bash shell script

2013-05-24 Thread John Pellman
Hi!

I'm trying to set up an R library for a common analysis that my lab does.
 This analysis involves the use of an external bash script, which I would
like to encapsulate within the R library.  I have been looking at tutorials
that detail how to create packages, and many of them mention an
experimental "exec" directory where one can store Perl, Java, bash scripts,
etc.  I was wondering how one might tell an R function to execute a shell
script in this directory (I've been thinking along the lines of using
system() to execute the script, but I am uncertain what the path to 'exec'
would be; my best guess is that the path to 'exec' might be found using the
.libPaths() command).

Many thanks,
John Pellman

[[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] R 3.0.0

2013-05-24 Thread Kjetil Halvorsen
I dont know of any package called "glm". Did you try
?glm

Kjetil


On Fri, May 24, 2013 at 5:29 PM, Simmons, Susan J. wrote:

> In the newest release of R (R 3.0.0), the "glm" package no longer supports
> logistic nor probit regression.  Was this intentional?  What package is
> best to use in the newest version of R to perform logistic or probit
> regression?
>
> [[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] R 3.0.0

2013-05-24 Thread David Winsemius

On May 24, 2013, at 8:29 AM, Simmons, Susan J. wrote:

> In the newest release of R (R 3.0.0), the "glm" package no longer supports 
> logistic nor probit regression.  Was this intentional?  What package is best 
> to use in the newest version of R to perform logistic or probit regression?
> 

 I would be very skeptical about that claim. Where is your evidence? Have you 
looked at:

?family  # ?
?quasi   # ?


>   [[alternative HTML version deleted]]

R-help is a plain text mailing list.

-- 

David Winsemius
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.


[R] R 3.0.0

2013-05-24 Thread Simmons, Susan J.
In the newest release of R (R 3.0.0), the "glm" package no longer supports 
logistic nor probit regression.  Was this intentional?  What package is best to 
use in the newest version of R to perform logistic or probit regression?

[[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] Continuous columns of matrix

2013-05-24 Thread eliza botto
Thanks rui..That was all i wanted...
Elisa

> Date: Fri, 24 May 2013 17:02:56 +0100
> From: ruipbarra...@sapo.pt
> To: eliza_bo...@hotmail.com
> CC: b...@xs4all.nl; r-help@r-project.org
> Subject: Re: [R] Continuous columns of matrix
> 
> Hello,
> 
> No problem. Just change <0 to >= and Inf to -Inf:
> 
> fun2 <- function(x){
>   n <- length(x)
>   imx <- which.max(x)
>   if(imx == 1){
>   x[2] <- x[n] <- -Inf
>   }else if(imx == n){
>   x[1] <- x[n - 1] <- -Inf
>   }else{
>   x[imx - 1] <- -Inf
>   x[imx + 1] <- -Inf
>   }
>   index <- which(x >= 0.8*x[imx])
>   values <- x[index]
>   list(index = index, values = values)
> }
> 
> apply(mat, 2, fun2)
> 
> 
> Rui Barradas
> 
> Em 24-05-2013 16:23, eliza botto escreveu:
> > Dear Rui,
> >
> > I infact wanted to have something like the following..
> > suppose the columns are
> >
> > structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242, 
> > 1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443, 
> > 0.427434603701202, 0.591932250254601, 0.444627635494183, 1.44407704434405, 
> > 1.79150336746345, 2.06195904001605, 1.41493262330451, 1.35748791897328, 
> > 1.19490680241894, 0.702488756183322, 0.338258418490199, 0.123398398622741, 
> > 0.138548982660226, 0.16170889185798, 0.414543218677095, 1.84629295875002, 
> > 2.24547399004563), .Dim = c(12L, 2L))
> >
> > For col 1
> > [[1]]
> > $Index
> > 5 12
> > $value
> > 1.939 1.79
> > Although value 1.708 of index 4 also has value which is above 80% of the 
> > maximum value but as it is in the neighbor of maxmimum value so we wont 
> > consider it.
> > similarly for the column 2
> > [[1]]
> > $Index
> > 12
> > $value
> > 2.245
> > Although values 1.846 of index 11 and 2.0619 of index 1 also have values 
> > which are above 80% of the maximum value but as they are in the neighbor of 
> > maxmimum value so we wont consider them.
> > i am sorry if the manner in which i asked my question was not conclusive.
> > i hope you wont mind...
> > Elisa
> >> Date: Fri, 24 May 2013 15:59:50 +0100
> >> From: ruipbarra...@sapo.pt
> >> To: eliza_bo...@hotmail.com
> >> CC: b...@xs4all.nl; r-help@r-project.org
> >> Subject: Re: [R] Continuous columns of matrix
> >>
> >> Hello,
> >>
> >> Something like this?
> >>
> >>
> >> fun2 <- function(x){
> >>n <- length(x)
> >>imx <- which.max(x)
> >>if(imx == 1){
> >>x[2] <- x[n] <- Inf
> >>}else if(imx == n){
> >>x[1] <- x[n - 1] <- Inf
> >>}else{
> >>x[imx - 1] <- Inf
> >>x[imx + 1] <- Inf
> >>}
> >>index <- which(x <= 0.8*x[imx])
> >>values <- x[index]
> >>list(index = index, values = values)
> >> }
> >>
> >> apply(mat, 2, fun2)
> >>
> >>
> >> Rui Barradas
> >>
> >> Em 24-05-2013 13:40, eliza botto escreveu:
> >>> Dear Rui,Thankyou very much for your help. just for my own knowledge what 
> >>> if want the values and index, which are less than or equal to 80% of the 
> >>> maximum value other than those in the neighbors?? like if maximum is in 
> >>> row number 5 of any column then the second maximum can be in any row 
> >>> other than 4 and 6. similarly if maximum is in row number 12 than the 
> >>> second maximum can be in any row other than 1 and 11...thankyou very much 
> >>> for your help
> >>> elisa
> >>>
>  Date: Fri, 24 May 2013 12:37:37 +0100
>  From: ruipbarra...@sapo.pt
>  To: eliza_bo...@hotmail.com
>  CC: b...@xs4all.nl; r-help@r-project.org
>  Subject: Re: [R] Continuous columns of matrix
> 
>  Hello,
> 
>  Berend is right, it's at least confusing. To get just the index of the
>  maximum value in each column,
> 
>  apply(mat, 2, which.max)
> 
> 
>  To get that index and the two neighbours (before and after, wraping
>  around) if they are greater than or equal to 80% of the maximum, try
> 
>  fun <- function(x){
>   n <- length(x)
>   imx <- which.max(x)
>   sec <- numeric(2)
>   if(imx == 1){
>   if(x[n] >= 0.8*x[imx]) sec[1] <- n
>   if(x[2] >= 0.8*x[imx]) sec[2] <- 2
>   }else if(imx == n){
>   if(x[n - 1] >= 0.8*x[imx]) sec[1] <- n - 1
>   if(x[1] >= 0.8*x[imx]) sec[2] <- 1
>   }else{
>   if(x[imx - 1] >= 0.8*x[imx]) sec[1] <- imx - 1
>   if(x[imx + 1] >= 0.8*x[imx]) sec[2] <- imx + 1
>   }
>   sec <- sec[sec != 0]
>   c(imx, sec)
>  }
> 
>  apply(mat, 2, fun)
> 
> 
>  Note that the result comes with the maximum first and the others follow.
> 
>  Hope this helps,
> 
>  Rui Barradas
> 
> 
>  Em 24-05-2013 11:41, eliza botto escreveu:
> > There you go!!!
> >
> > structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242, 
> > 1.70874688194537, 1.93906363083693, 0.89540353128442, 
> > 0.328327645695443, 0.427434603701202, 0.5919322502

Re: [R] Continuous columns of matrix

2013-05-24 Thread Rui Barradas

Hello,

No problem. Just change <0 to >= and Inf to -Inf:

fun2 <- function(x){
n <- length(x)
imx <- which.max(x)
if(imx == 1){
x[2] <- x[n] <- -Inf
}else if(imx == n){
x[1] <- x[n - 1] <- -Inf
}else{
x[imx - 1] <- -Inf
x[imx + 1] <- -Inf
}
index <- which(x >= 0.8*x[imx])
values <- x[index]
list(index = index, values = values)
}

apply(mat, 2, fun2)


Rui Barradas

Em 24-05-2013 16:23, eliza botto escreveu:

Dear Rui,

I infact wanted to have something like the following..
suppose the columns are

structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242, 
1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443, 
0.427434603701202, 0.591932250254601, 0.444627635494183, 1.44407704434405, 
1.79150336746345, 2.06195904001605, 1.41493262330451, 1.35748791897328, 
1.19490680241894, 0.702488756183322, 0.338258418490199, 0.123398398622741, 
0.138548982660226, 0.16170889185798, 0.414543218677095, 1.84629295875002, 
2.24547399004563), .Dim = c(12L, 2L))

For col 1
[[1]]
$Index
5 12
$value
1.939 1.79
Although value 1.708 of index 4 also has value which is above 80% of the 
maximum value but as it is in the neighbor of maxmimum value so we wont 
consider it.
similarly for the column 2
[[1]]
$Index
12
$value
2.245
Although values 1.846 of index 11 and 2.0619 of index 1 also have values which 
are above 80% of the maximum value but as they are in the neighbor of maxmimum 
value so we wont consider them.
i am sorry if the manner in which i asked my question was not conclusive.
i hope you wont mind...
Elisa

Date: Fri, 24 May 2013 15:59:50 +0100
From: ruipbarra...@sapo.pt
To: eliza_bo...@hotmail.com
CC: b...@xs4all.nl; r-help@r-project.org
Subject: Re: [R] Continuous columns of matrix

Hello,

Something like this?


fun2 <- function(x){
n <- length(x)
imx <- which.max(x)
if(imx == 1){
x[2] <- x[n] <- Inf
}else if(imx == n){
x[1] <- x[n - 1] <- Inf
}else{
x[imx - 1] <- Inf
x[imx + 1] <- Inf
}
index <- which(x <= 0.8*x[imx])
values <- x[index]
list(index = index, values = values)
}

apply(mat, 2, fun2)


Rui Barradas

Em 24-05-2013 13:40, eliza botto escreveu:

Dear Rui,Thankyou very much for your help. just for my own knowledge what if 
want the values and index, which are less than or equal to 80% of the maximum 
value other than those in the neighbors?? like if maximum is in row number 5 of 
any column then the second maximum can be in any row other than 4 and 6. 
similarly if maximum is in row number 12 than the second maximum can be in any 
row other than 1 and 11...thankyou very much for your help
elisa


Date: Fri, 24 May 2013 12:37:37 +0100
From: ruipbarra...@sapo.pt
To: eliza_bo...@hotmail.com
CC: b...@xs4all.nl; r-help@r-project.org
Subject: Re: [R] Continuous columns of matrix

Hello,

Berend is right, it's at least confusing. To get just the index of the
maximum value in each column,

apply(mat, 2, which.max)


To get that index and the two neighbours (before and after, wraping
around) if they are greater than or equal to 80% of the maximum, try

fun <- function(x){
n <- length(x)
imx <- which.max(x)
sec <- numeric(2)
if(imx == 1){
if(x[n] >= 0.8*x[imx]) sec[1] <- n
if(x[2] >= 0.8*x[imx]) sec[2] <- 2
}else if(imx == n){
if(x[n - 1] >= 0.8*x[imx]) sec[1] <- n - 1
if(x[1] >= 0.8*x[imx]) sec[2] <- 1
}else{
if(x[imx - 1] >= 0.8*x[imx]) sec[1] <- imx - 1
if(x[imx + 1] >= 0.8*x[imx]) sec[2] <- imx + 1
}
sec <- sec[sec != 0]
c(imx, sec)
}

apply(mat, 2, fun)


Note that the result comes with the maximum first and the others follow.

Hope this helps,

Rui Barradas


Em 24-05-2013 11:41, eliza botto escreveu:

There you go!!!

structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242, 
1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443, 
0.427434603701202, 0.591932250254601, 0.444627635494183, 1.44407704434405, 
1.79150336746345, 0.94525563730664, 1.1025988539757, 0.944726401770203, 
0.941068515436361, 1.50874009152312, 0.590015480056925, 0.311905493999476, 
0.596771673581893, 1.01502499067153, 0.803273181849135, 1.6704085033648, 
1.57021117646422, 0.492096635764151, 0.42688044914, 0.521585941816778, 
1.66472272302545, 2.61878329527404, 2.19154489521664, 0.493876245329722, 
0.4915787202584, 0.889477365620806, 0.609135860199222, 0.739201878930367, 
0.854663750519518, 0.948228727226247, 1.38569091844218, 0.910510759802679, 
1.25991218521949, 0.993123416952421, 0.553640392997634, 0.357487763503204, 
0.368328033777003, 0.344255688489322, 0.423679560916755, 1.32093576037521, 
3.13420679229785, 2.06195904001605, 1.41493262330451, 1.35

Re: [R] Continuous columns of matrix

2013-05-24 Thread eliza botto
Dear Rui,

I infact wanted to have something like the following..
suppose the columns are

structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242, 
1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443, 
0.427434603701202, 0.591932250254601, 0.444627635494183, 1.44407704434405, 
1.79150336746345, 2.06195904001605, 1.41493262330451, 1.35748791897328, 
1.19490680241894, 0.702488756183322, 0.338258418490199, 0.123398398622741, 
0.138548982660226, 0.16170889185798, 0.414543218677095, 1.84629295875002, 
2.24547399004563), .Dim = c(12L, 2L))

For col 1
[[1]]
$Index
5 12
$value
1.939 1.79
Although value 1.708 of index 4 also has value which is above 80% of the 
maximum value but as it is in the neighbor of maxmimum value so we wont 
consider it.
similarly for the column 2
[[1]]
$Index
12
$value
2.245
Although values 1.846 of index 11 and 2.0619 of index 1 also have values which 
are above 80% of the maximum value but as they are in the neighbor of maxmimum 
value so we wont consider them.
i am sorry if the manner in which i asked my question was not conclusive.
i hope you wont mind...
Elisa
> Date: Fri, 24 May 2013 15:59:50 +0100
> From: ruipbarra...@sapo.pt
> To: eliza_bo...@hotmail.com
> CC: b...@xs4all.nl; r-help@r-project.org
> Subject: Re: [R] Continuous columns of matrix
> 
> Hello,
> 
> Something like this?
> 
> 
> fun2 <- function(x){
>   n <- length(x)
>   imx <- which.max(x)
>   if(imx == 1){
>   x[2] <- x[n] <- Inf
>   }else if(imx == n){
>   x[1] <- x[n - 1] <- Inf
>   }else{
>   x[imx - 1] <- Inf
>   x[imx + 1] <- Inf
>   }
>   index <- which(x <= 0.8*x[imx])
>   values <- x[index]
>   list(index = index, values = values)
> }
> 
> apply(mat, 2, fun2)
> 
> 
> Rui Barradas
> 
> Em 24-05-2013 13:40, eliza botto escreveu:
> > Dear Rui,Thankyou very much for your help. just for my own knowledge what 
> > if want the values and index, which are less than or equal to 80% of the 
> > maximum value other than those in the neighbors?? like if maximum is in row 
> > number 5 of any column then the second maximum can be in any row other than 
> > 4 and 6. similarly if maximum is in row number 12 than the second maximum 
> > can be in any row other than 1 and 11...thankyou very much for your help
> > elisa
> >
> >> Date: Fri, 24 May 2013 12:37:37 +0100
> >> From: ruipbarra...@sapo.pt
> >> To: eliza_bo...@hotmail.com
> >> CC: b...@xs4all.nl; r-help@r-project.org
> >> Subject: Re: [R] Continuous columns of matrix
> >>
> >> Hello,
> >>
> >> Berend is right, it's at least confusing. To get just the index of the
> >> maximum value in each column,
> >>
> >> apply(mat, 2, which.max)
> >>
> >>
> >> To get that index and the two neighbours (before and after, wraping
> >> around) if they are greater than or equal to 80% of the maximum, try
> >>
> >> fun <- function(x){
> >>n <- length(x)
> >>imx <- which.max(x)
> >>sec <- numeric(2)
> >>if(imx == 1){
> >>if(x[n] >= 0.8*x[imx]) sec[1] <- n
> >>if(x[2] >= 0.8*x[imx]) sec[2] <- 2
> >>}else if(imx == n){
> >>if(x[n - 1] >= 0.8*x[imx]) sec[1] <- n - 1
> >>if(x[1] >= 0.8*x[imx]) sec[2] <- 1
> >>}else{
> >>if(x[imx - 1] >= 0.8*x[imx]) sec[1] <- imx - 1
> >>if(x[imx + 1] >= 0.8*x[imx]) sec[2] <- imx + 1
> >>}
> >>sec <- sec[sec != 0]
> >>c(imx, sec)
> >> }
> >>
> >> apply(mat, 2, fun)
> >>
> >>
> >> Note that the result comes with the maximum first and the others follow.
> >>
> >> Hope this helps,
> >>
> >> Rui Barradas
> >>
> >>
> >> Em 24-05-2013 11:41, eliza botto escreveu:
> >>> There you go!!!
> >>>
> >>> structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242, 
> >>> 1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443, 
> >>> 0.427434603701202, 0.591932250254601, 0.444627635494183, 
> >>> 1.44407704434405, 1.79150336746345, 0.94525563730664, 1.1025988539757, 
> >>> 0.944726401770203, 0.941068515436361, 1.50874009152312, 
> >>> 0.590015480056925, 0.311905493999476, 0.596771673581893, 
> >>> 1.01502499067153, 0.803273181849135, 1.6704085033648, 1.57021117646422, 
> >>> 0.492096635764151, 0.42688044914, 0.521585941816778, 
> >>> 1.66472272302545, 2.61878329527404, 2.19154489521664, 0.493876245329722, 
> >>> 0.4915787202584, 0.889477365620806, 0.609135860199222, 0.739201878930367, 
> >>> 0.854663750519518, 0.948228727226247, 1.38569091844218, 
> >>> 0.910510759802679, 1.25991218521949, 0.993123416952421, 
> >>> 0.553640392997634, 0.357487763503204, 0.368328033777003, 
> >>> 0.344255688489322, 0.423679560916755, 1.32093576037521, 3.13420679229785, 
> >>> 2.06195904001605, 1.41493262330451, 1.35748791897328, 1.19490680241894, 
> >>> 0.70248875!
 618332!
> >>>2, 0.338258418490199, 0.123398398622741, 0.138548982660226, 
> >>> 0.16170889185798, 0.414543218677095, 1.84629295875002, 2.24547399004563, 
> >>> 0.0849732189580101, 0.

Re: [R] ggmap, hexbin and length distortion in Lat/long

2013-05-24 Thread Jeff Newmiller
I would suggest asking this on R-sig-geo.

https://stat.ethz.ch/mailman/listinfo/r-sig-geo
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Mike Bock  wrote:

>I am working with spatial data in ggmap, generally with great success.
>I have a huge data set with the coordinates in NAD 83 UTM Zone 11
>(meters).  To map the data the coordinates were converted to Lat Long
>in GIS prior to use in R and ggmap/ggplot. I am using hexagonal binning
>to aggregate the data :
>#create bins and calculate stats
>
>hb<-hexbin(DF$lon,DF$lat,xbins=80,IDs=TRUE)
>hb.avg<-hexTapply(hb,DF$Res,mean,na.rm=TRUE)
>hb.mx<-hexTapply(hb,DF$Res,max,na.rm=TRUE)
>hb.p80<-hexTapply(hb,DF$Res,quantile,prob=0.80,na.rm=TRUE)
>#create df for ggplot
>hx_dat <- data.frame(hcell2xy(hb), count = hb@count,
>xo = hb@xcm, yo = hb@ycm, Mean=hb.avg,Max=hb.mx,
>p80=hb.p80)
>
>#Base Map
>#BBox is the bounding box
>Base<-get_map(BBox,source='google')
>m_hx<-ggmap(Base,legend = "bottom",
>base_layer=ggplot(aes(x=x,y=y),data=hx_dat))
>#Map of means
>a<-0.55
>hc<-'grey60'
>
>m_hx+geom_hex(aes(x = x, y = y, fill = Mean),
>  color = hc, ,alpha=a,stat = "identity") +
>  scale_fill_gradientn("Mean",colours=rev(rainbow(4)),trans='sqrt')
>
>...and so on for other stats
>I can also run statistical analyses on hx_dat.
>By creating hexbins based on lat/long it seems there will be distortion
>due to the differences in length of a degree at different locations on
>the earth's surface. What is the most efficient way to eliminate this
>distortion? Should I run hexbin in NAD83 and convert the x/y
>coordinates to Lat Long? Can I get ggmap to convert the baselayer to
>NAD84 and just do everything in NAD(my preferred option)?
>I have tried converting Lat Long to NAD84 and back but the coordinates
>are coming up in the eastern Pacific and not in California, so I am
>missing something and I am not sure that is the best way to solve the
>problem anyway. Thanks in advance, any help is greatly appreciated
>Mike
>
>Michael J. Bock, PhD | Senior Manager
>mb...@environcorp.com
>
>
>
>
>
>
>
>This message contains information that may be
>confidenti...{{dropped:8}}
>
>__
>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] When the interaction term should be interpreted in AIC table?

2013-05-24 Thread Cade, Brian
Galina:  The AIC, delta AIC, and AIC weights all reference an entire model
and provide no information on how you should interpret the individual
parameters within a model.  If you believe  based on your AIC weights that
the model with ZONE + LABRADOR TEA + YEAR + ZONE x LABRADOR TEA is a
reasonable candidate then your decision about interpreting the interaction
should only be based on that term relative to other terms within this
model.  And, yes, if you were going to bother including an interaction in a
model you better be willing to interpret it.  And don't waste your time AIC
model averaging the parameter estimates across these multiple models.
 There is no useful point for doing so other than deluding yourself into
thinking you somehow have addressed model uncertainty.  I'm including a
previous post of mine to r-sig-ecolog list regarding the issues with AIC
model averaging of individual regression parameter estimates, its
ridiculous use for determining relative importance of predictors, etc.

Brian

r-sig-ecology post:

Joana and any others:  You cannot obtain a valid or useful measure of
relative importance of predictor variables across multiple models by
applying relative AIC weights or using model averaged coefficients unless
all your models included a single predictor (which, of course, is not what
is usually done).   And this applies to hurdle or any other models.  AIC
(and relative weights) apply to the log likelihood maximized for estimating
a model that may be composed of 1 to many predictors.  The log likelihood
nor its associated AIC for a model has any ability to distinguish among the
contributions of the individual predictors used in maximizing the log
lilkelihood, and most useful definitions of relative importance of
predictors within a model requires some ability to make that distinction.
 The best that AIC and relative AIC weights applied to individual
 predictor coefficients can tell you is the relative importance of the
models in which the predictors occurred.  And that is not the same as
relative importance of predictors for most statisticians.   It is quite
possible to have a predictor with little relative importance within a model
that has high relative importance, and, of course the opposite is true too.
 This AIC weights approach ignores that fact.  Burnham and Anderson (2002,
2004) have done ecologists a great disservice by suggesting that AIC model
weights can be used to address relative importance of individual predictors
in models that included multiple predictors.  AIC model weights can be used
to assess the relative importance of models (that are combinations of one
to many predictors) but are insufficient to address the relative importance
of individual predictor variables because they don’t recognize the
differential contribution of individual predictors to the likelihood (or
equivalently deviance, or sums of squares).  Indeed, the use of AIC model
weights, as employed by most people, acts as if for a given model that all
predictors  contributed equally to the likelihood and, thus, get the same
weight for being in that model.  That is a totally unreasonable assumption
and never likely in practice.  AIC weights are based on AIC that are
computed from the log likelihood maximized by all predictors
simultaneously.  There is nothing in the theory behind AIC that suggests
you can attribute the log likelihood equally to all predictor variables in
the model.  I’m not sure why Burnham and Anderson (2002) propagated such a
notion as it totally conflicts with and ignores a large body of statistical
literature on methods for assigning relative importance of predictors
within a given statistical model.   Examples from some accessible
statistical and ecological literature include:

Bring, J.  1994.  How to standardize regression coefficients.  The American
Statistician 48: 209-213.

Chevan, A., and M. Sutherland.  1991.  Hierarchical partitioning.  The
American Statistician 45: 90-96.

Christensen, R.  1992.  Comments on Chevan and Sutherland.  The American
Statistician 46: 74.

Grömping, U.  2007.  Estimators of relative importance in linear regression
based on variance decomposition.  The American Statistician 61: 139-147.

Kruskal, W., and R. Majors.  1989.  Concepts of relative importance in
recent scientific literature.  The American Statistician 43: 2-6.

MacNally, R.  2000.  Regression model-building in conservation biology,
biogeography and ecology:  The distinction between – and reconciliation of
– ‘predictive’ and ‘explanatory’ models.  Biodiversity and 
Conservation 9:
655-671.

Murray, K., and M. M. Conner.  2009.  Methods to quantify variable
importance:  implications for the analysis of noisy ecological data.
Ecology 90:348-355.

The paper by Murray and Conner (2009) is a simulation study that confirms
and states what was obvious to most statisticians – AIC was not designed to
differentiate among contributions of individual predictors within a model
and

Re: [R] Continuous columns of matrix

2013-05-24 Thread Rui Barradas

Hello,

Something like this?


fun2 <- function(x){
n <- length(x)
imx <- which.max(x)
if(imx == 1){
x[2] <- x[n] <- Inf
}else if(imx == n){
x[1] <- x[n - 1] <- Inf
}else{
x[imx - 1] <- Inf
x[imx + 1] <- Inf
}
index <- which(x <= 0.8*x[imx])
values <- x[index]
list(index = index, values = values)
}

apply(mat, 2, fun2)


Rui Barradas

Em 24-05-2013 13:40, eliza botto escreveu:

Dear Rui,Thankyou very much for your help. just for my own knowledge what if 
want the values and index, which are less than or equal to 80% of the maximum 
value other than those in the neighbors?? like if maximum is in row number 5 of 
any column then the second maximum can be in any row other than 4 and 6. 
similarly if maximum is in row number 12 than the second maximum can be in any 
row other than 1 and 11...thankyou very much for your help
elisa


Date: Fri, 24 May 2013 12:37:37 +0100
From: ruipbarra...@sapo.pt
To: eliza_bo...@hotmail.com
CC: b...@xs4all.nl; r-help@r-project.org
Subject: Re: [R] Continuous columns of matrix

Hello,

Berend is right, it's at least confusing. To get just the index of the
maximum value in each column,

apply(mat, 2, which.max)


To get that index and the two neighbours (before and after, wraping
around) if they are greater than or equal to 80% of the maximum, try

fun <- function(x){
n <- length(x)
imx <- which.max(x)
sec <- numeric(2)
if(imx == 1){
if(x[n] >= 0.8*x[imx]) sec[1] <- n
if(x[2] >= 0.8*x[imx]) sec[2] <- 2
}else if(imx == n){
if(x[n - 1] >= 0.8*x[imx]) sec[1] <- n - 1
if(x[1] >= 0.8*x[imx]) sec[2] <- 1
}else{
if(x[imx - 1] >= 0.8*x[imx]) sec[1] <- imx - 1
if(x[imx + 1] >= 0.8*x[imx]) sec[2] <- imx + 1
}
sec <- sec[sec != 0]
c(imx, sec)
}

apply(mat, 2, fun)


Note that the result comes with the maximum first and the others follow.

Hope this helps,

Rui Barradas


Em 24-05-2013 11:41, eliza botto escreveu:

There you go!!!

structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242, 
1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443, 
0.427434603701202, 0.591932250254601, 0.444627635494183, 1.44407704434405, 
1.79150336746345, 0.94525563730664, 1.1025988539757, 0.944726401770203, 
0.941068515436361, 1.50874009152312, 0.590015480056925, 0.311905493999476, 
0.596771673581893, 1.01502499067153, 0.803273181849135, 1.6704085033648, 
1.57021117646422, 0.492096635764151, 0.42688044914, 0.521585941816778, 
1.66472272302545, 2.61878329527404, 2.19154489521664, 0.493876245329722, 
0.4915787202584, 0.889477365620806, 0.609135860199222, 0.739201878930367, 
0.854663750519518, 0.948228727226247, 1.38569091844218, 0.910510759802679, 
1.25991218521949, 0.993123416952421, 0.553640392997634, 0.357487763503204, 
0.368328033777003, 0.344255688489322, 0.423679560916755, 1.32093576037521, 
3.13420679229785, 2.06195904001605, 1.41493262330451, 1.35748791897328, 
1.19490680241894, 0.7024887561!

8332!

   2, 0.338258418490199, 0.123398398622741, 0.138548982660226, 
0.16170889185798, 0.414543218677095, 1.84629295875002, 2.24547399004563, 
0.0849732189580101, 0.070591276171845, 0.0926010253161898, 0.362209761457517, 
1.45769283057202, 3.16165004659667, 2.74903557756267, 1.94633472878995, 
1.19319875840883, 0.533232612926756, 0.225531074123974, 0.122949089115578), 
.Dim = c(12L, 6L))

Thanks once again..
Elisa



Subject: Re: [R] Continuous columns of matrix
From: b...@xs4all.nl
Date: Fri, 24 May 2013 12:36:47 +0200
CC: r-help@r-project.org
To: eliza_bo...@hotmail.com


On 24-05-2013, at 12:24, eliza botto  wrote:


Dear useRs,If i have a matrix, say, 12 rows and 6 columns. The columns are 
continuous. I  want to find the index of maximum values and the actual maximum 
values. The maximum values in each column are the highest values and the values 
greater than or equal to 80% of the maximum value. Moreover, if a column has 
more than one maximum values than these values should come immediately next to 
each other.  For example, if you column 1 has a highest value in 6th row then 
the second maximum values cant be in row 5 or 7. And as the columns are 
continuous therefore, if maximum value is in row 12th, then the second maximum 
cant be in row 11 and 1.Thankyou very much indeed in advance



Incomprehensible.
What is a continuous column?

Please give an example input matrix and and the result you want.

Berend


Elisa   
[[alternative HTML version deleted]]



Please post in plain text.



[[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:/

Re: [R] Rcpp with OpenMP - Need example Makevars

2013-05-24 Thread Asis Hallab
Many thanks to Dirk and Brian!

The tips helped me a lot.

Kind 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] Change devAskNewPage setting on Escape?

2013-05-24 Thread Ulrike Grömping

Dear helpeRs,

I would like to include generation of a potentially large number of 
plots, and modify the ask settings using the devAskNewPage function, and 
return it back to its original state afterwards.
It is not unlikely that the user escapes from the long list of plots 
before reaching the end. (How) Can I make sure to return the ask setting 
to its original state even if the plots are escaped so that the function 
does not reach its natural end?


Best,
Ulrike

__
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] Download data

2013-05-24 Thread David Reiner
Actually I think the one you want is 'FRED/DCOILWTICO'

-- David


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of David Reiner
Sent: Friday, May 24, 2013 8:46 AM
To: Christofer Bogaso; r-help
Subject: Re: [R] Download data

Quandl package is your friend:
library(Quandl) # download and install if necessary
oil <- Quandl('FRED/WCOILWTICO', type='xts')
# Search the quandl.com site to make sure this is the data you want.
# I just put in your text string 'WTI - Cushing, Oklahoma' and got several 
results which might be the one you want.

This may give a warning if you haven't gotten an authentication token.

David L. Reiner, Ph.D.
Head Quant
XR Trading LLC
550 West Jackson Boulevard, Suite 1000
Chicago, IL 60661-5704
(312) 244-4610 direct
(312) 244-4500 main
david.rei...@xrtrading.com

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Christofer Bogaso
Sent: Thursday, May 23, 2013 11:32 PM
To: r-help
Subject: [R] Download data

Hello again,

I need to download 'WTI - Cushing, Oklahoma' from '
http://www.eia.gov/dnav/pet/pet_pri_spt_s1_d.htm' which is available under
the column 'View
History'

While I can get the data manually, however I was looking for some R
implementation which can directly download data into R.

Can somebody point me how to achieve that?

Thanks for your help.

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


This e-mail and any materials attached hereto, including, without limitation, 
all content hereof and thereof (collectively, "XR Content") are confidential 
and proprietary to XR Trading, LLC ("XR") and/or its affiliates, and are 
protected by intellectual property laws.  Without the prior written consent of 
XR, the XR Content may not (i) be disclosed to any third party or (ii) be 
reproduced or otherwise used by anyone other than current employees of XR or 
its affiliates, on behalf of XR or its affiliates.

THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY 
KIND.  TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY 
DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR 
CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE 
FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, 
DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS 
AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE UPON, OR 
INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE POSSIBILITY OF 
SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE.

__
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] ggmap, hexbin and length distortion in Lat/long

2013-05-24 Thread Mike Bock
I am working with spatial data in ggmap, generally with great success. I have a 
huge data set with the coordinates in NAD 83 UTM Zone 11 (meters).  To map the 
data the coordinates were converted to Lat Long in GIS prior to use in R and 
ggmap/ggplot. I am using hexagonal binning to aggregate the data :
#create bins and calculate stats

hb<-hexbin(DF$lon,DF$lat,xbins=80,IDs=TRUE)
hb.avg<-hexTapply(hb,DF$Res,mean,na.rm=TRUE)
hb.mx<-hexTapply(hb,DF$Res,max,na.rm=TRUE)
hb.p80<-hexTapply(hb,DF$Res,quantile,prob=0.80,na.rm=TRUE)
#create df for ggplot
hx_dat <- data.frame(hcell2xy(hb), count = hb@count,
xo = hb@xcm, yo = hb@ycm, Mean=hb.avg,Max=hb.mx,
p80=hb.p80)

#Base Map
#BBox is the bounding box
Base<-get_map(BBox,source='google')
m_hx<-ggmap(Base,legend = "bottom", base_layer=ggplot(aes(x=x,y=y),data=hx_dat))
#Map of means
a<-0.55
hc<-'grey60'

m_hx+geom_hex(aes(x = x, y = y, fill = Mean),
  color = hc, ,alpha=a,stat = "identity") +
  scale_fill_gradientn("Mean",colours=rev(rainbow(4)),trans='sqrt')

...and so on for other stats
I can also run statistical analyses on hx_dat.
By creating hexbins based on lat/long it seems there will be distortion due to 
the differences in length of a degree at different locations on the earth's 
surface. What is the most efficient way to eliminate this distortion? Should I 
run hexbin in NAD83 and convert the x/y coordinates to Lat Long? Can I get 
ggmap to convert the baselayer to NAD84 and just do everything in NAD(my 
preferred option)?
I have tried converting Lat Long to NAD84 and back but the coordinates are 
coming up in the eastern Pacific and not in California, so I am missing 
something and I am not sure that is the best way to solve the problem anyway. 
Thanks in advance, any help is greatly appreciated
Mike

Michael J. Bock, PhD | Senior Manager
mb...@environcorp.com







This message contains information that may be confidenti...{{dropped:8}}

__
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] Download data

2013-05-24 Thread David Reiner
Quandl package is your friend:
library(Quandl) # download and install if necessary
oil <- Quandl('FRED/WCOILWTICO', type='xts')
# Search the quandl.com site to make sure this is the data you want.
# I just put in your text string 'WTI - Cushing, Oklahoma' and got several 
results which might be the one you want.

This may give a warning if you haven't gotten an authentication token.

David L. Reiner, Ph.D.
Head Quant
XR Trading LLC
550 West Jackson Boulevard, Suite 1000
Chicago, IL 60661-5704
(312) 244-4610 direct
(312) 244-4500 main
david.rei...@xrtrading.com

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Christofer Bogaso
Sent: Thursday, May 23, 2013 11:32 PM
To: r-help
Subject: [R] Download data

Hello again,

I need to download 'WTI - Cushing, Oklahoma' from '
http://www.eia.gov/dnav/pet/pet_pri_spt_s1_d.htm' which is available under
the column 'View
History'

While I can get the data manually, however I was looking for some R
implementation which can directly download data into R.

Can somebody point me how to achieve that?

Thanks for your help.

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


This e-mail and any materials attached hereto, including, without limitation, 
all content hereof and thereof (collectively, "XR Content") are confidential 
and proprietary to XR Trading, LLC ("XR") and/or its affiliates, and are 
protected by intellectual property laws.  Without the prior written consent of 
XR, the XR Content may not (i) be disclosed to any third party or (ii) be 
reproduced or otherwise used by anyone other than current employees of XR or 
its affiliates, on behalf of XR or its affiliates.

THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY 
KIND.  TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY 
DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR 
CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE 
FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, 
DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS 
AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE UPON, OR 
INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE POSSIBILITY OF 
SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE.

__
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] Continuous columns of matrix

2013-05-24 Thread eliza botto
Dear Rui,Thankyou very much for your help. just for my own knowledge what if 
want the values and index, which are less than or equal to 80% of the maximum 
value other than those in the neighbors?? like if maximum is in row number 5 of 
any column then the second maximum can be in any row other than 4 and 6. 
similarly if maximum is in row number 12 than the second maximum can be in any 
row other than 1 and 11...thankyou very much for your help
elisa 

> Date: Fri, 24 May 2013 12:37:37 +0100
> From: ruipbarra...@sapo.pt
> To: eliza_bo...@hotmail.com
> CC: b...@xs4all.nl; r-help@r-project.org
> Subject: Re: [R] Continuous columns of matrix
> 
> Hello,
> 
> Berend is right, it's at least confusing. To get just the index of the 
> maximum value in each column,
> 
> apply(mat, 2, which.max)
> 
> 
> To get that index and the two neighbours (before and after, wraping 
> around) if they are greater than or equal to 80% of the maximum, try
> 
> fun <- function(x){
>   n <- length(x)
>   imx <- which.max(x)
>   sec <- numeric(2)
>   if(imx == 1){
>   if(x[n] >= 0.8*x[imx]) sec[1] <- n
>   if(x[2] >= 0.8*x[imx]) sec[2] <- 2
>   }else if(imx == n){
>   if(x[n - 1] >= 0.8*x[imx]) sec[1] <- n - 1
>   if(x[1] >= 0.8*x[imx]) sec[2] <- 1
>   }else{
>   if(x[imx - 1] >= 0.8*x[imx]) sec[1] <- imx - 1
>   if(x[imx + 1] >= 0.8*x[imx]) sec[2] <- imx + 1
>   }
>   sec <- sec[sec != 0]
>   c(imx, sec)
> }
> 
> apply(mat, 2, fun)
> 
> 
> Note that the result comes with the maximum first and the others follow.
> 
> Hope this helps,
> 
> Rui Barradas
> 
> 
> Em 24-05-2013 11:41, eliza botto escreveu:
> > There you go!!!
> >
> > structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242, 
> > 1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443, 
> > 0.427434603701202, 0.591932250254601, 0.444627635494183, 1.44407704434405, 
> > 1.79150336746345, 0.94525563730664, 1.1025988539757, 0.944726401770203, 
> > 0.941068515436361, 1.50874009152312, 0.590015480056925, 0.311905493999476, 
> > 0.596771673581893, 1.01502499067153, 0.803273181849135, 1.6704085033648, 
> > 1.57021117646422, 0.492096635764151, 0.42688044914, 0.521585941816778, 
> > 1.66472272302545, 2.61878329527404, 2.19154489521664, 0.493876245329722, 
> > 0.4915787202584, 0.889477365620806, 0.609135860199222, 0.739201878930367, 
> > 0.854663750519518, 0.948228727226247, 1.38569091844218, 0.910510759802679, 
> > 1.25991218521949, 0.993123416952421, 0.553640392997634, 0.357487763503204, 
> > 0.368328033777003, 0.344255688489322, 0.423679560916755, 1.32093576037521, 
> > 3.13420679229785, 2.06195904001605, 1.41493262330451, 1.35748791897328, 
> > 1.19490680241894, 0.7024887561!
 8332!
> >   2, 0.338258418490199, 0.123398398622741, 0.138548982660226, 
> > 0.16170889185798, 0.414543218677095, 1.84629295875002, 2.24547399004563, 
> > 0.0849732189580101, 0.070591276171845, 0.0926010253161898, 
> > 0.362209761457517, 1.45769283057202, 3.16165004659667, 2.74903557756267, 
> > 1.94633472878995, 1.19319875840883, 0.533232612926756, 0.225531074123974, 
> > 0.122949089115578), .Dim = c(12L, 6L))
> >
> > Thanks once again..
> > Elisa
> >
> >
> >> Subject: Re: [R] Continuous columns of matrix
> >> From: b...@xs4all.nl
> >> Date: Fri, 24 May 2013 12:36:47 +0200
> >> CC: r-help@r-project.org
> >> To: eliza_bo...@hotmail.com
> >>
> >>
> >> On 24-05-2013, at 12:24, eliza botto  wrote:
> >>
> >>> Dear useRs,If i have a matrix, say, 12 rows and 6 columns. The columns 
> >>> are continuous. I  want to find the index of maximum values and the 
> >>> actual maximum values. The maximum values in each column are the highest 
> >>> values and the values greater than or equal to 80% of the maximum value. 
> >>> Moreover, if a column has more than one maximum values than these values 
> >>> should come immediately next to each other.  For example, if you column 1 
> >>> has a highest value in 6th row then the second maximum values cant be in 
> >>> row 5 or 7. And as the columns are continuous therefore, if maximum value 
> >>> is in row 12th, then the second maximum cant be in row 11 and 1.Thankyou 
> >>> very much indeed in advance
> >>
> >>
> >> Incomprehensible.
> >> What is a continuous column?
> >>
> >> Please give an example input matrix and and the result you want.
> >>
> >> Berend
> >>
> >>> Elisa 
> >>>   [[alternative HTML version deleted]]
> >>>
> >>
> >> Please post in plain text.
> >>
> > 
> > [[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.
> >
  
[[alter

Re: [R] par(mfrow=c(1,3)) and postscript(file=)

2013-05-24 Thread Sarah Goslee
Probably you need to put the par() function after the postscript() function
- the par changes apply only to the current device, and there's no
postscript device until you start it.

But since you haven't provided an example, it's impossible to be certain.

Sarah

On Friday, May 24, 2013, Öhagen Patrik wrote:

>
>
> I am printing three graphs into the same page using par(mfrow=c(1,3)) and
> the I want to save the file as postscript format using postscript()
>
> When input the postscript file into the manuscript the three graphs appear
> on separate pages. What have I missed and done wrong?
>
> Thank you in advance!
>
> Cheers, Patrik
>
>

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


Re: [R] Continuous columns of matrix

2013-05-24 Thread Rui Barradas

Hello,

Berend is right, it's at least confusing. To get just the index of the 
maximum value in each column,


apply(mat, 2, which.max)


To get that index and the two neighbours (before and after, wraping 
around) if they are greater than or equal to 80% of the maximum, try


fun <- function(x){
n <- length(x)
imx <- which.max(x)
sec <- numeric(2)
if(imx == 1){
if(x[n] >= 0.8*x[imx]) sec[1] <- n
if(x[2] >= 0.8*x[imx]) sec[2] <- 2
}else if(imx == n){
if(x[n - 1] >= 0.8*x[imx]) sec[1] <- n - 1
if(x[1] >= 0.8*x[imx]) sec[2] <- 1
}else{
if(x[imx - 1] >= 0.8*x[imx]) sec[1] <- imx - 1
if(x[imx + 1] >= 0.8*x[imx]) sec[2] <- imx + 1
}
sec <- sec[sec != 0]
c(imx, sec)
}

apply(mat, 2, fun)


Note that the result comes with the maximum first and the others follow.

Hope this helps,

Rui Barradas


Em 24-05-2013 11:41, eliza botto escreveu:

There you go!!!

structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242, 
1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443, 
0.427434603701202, 0.591932250254601, 0.444627635494183, 1.44407704434405, 
1.79150336746345, 0.94525563730664, 1.1025988539757, 0.944726401770203, 
0.941068515436361, 1.50874009152312, 0.590015480056925, 0.311905493999476, 
0.596771673581893, 1.01502499067153, 0.803273181849135, 1.6704085033648, 
1.57021117646422, 0.492096635764151, 0.42688044914, 0.521585941816778, 
1.66472272302545, 2.61878329527404, 2.19154489521664, 0.493876245329722, 
0.4915787202584, 0.889477365620806, 0.609135860199222, 0.739201878930367, 
0.854663750519518, 0.948228727226247, 1.38569091844218, 0.910510759802679, 
1.25991218521949, 0.993123416952421, 0.553640392997634, 0.357487763503204, 
0.368328033777003, 0.344255688489322, 0.423679560916755, 1.32093576037521, 
3.13420679229785, 2.06195904001605, 1.41493262330451, 1.35748791897328, 
1.19490680241894, 0.702488756183!

32!

  2, 0.338258418490199, 0.123398398622741, 0.138548982660226, 0.16170889185798, 
0.414543218677095, 1.84629295875002, 2.24547399004563, 0.0849732189580101, 
0.070591276171845, 0.0926010253161898, 0.362209761457517, 1.45769283057202, 
3.16165004659667, 2.74903557756267, 1.94633472878995, 1.19319875840883, 
0.533232612926756, 0.225531074123974, 0.122949089115578), .Dim = c(12L, 6L))

Thanks once again..
Elisa



Subject: Re: [R] Continuous columns of matrix
From: b...@xs4all.nl
Date: Fri, 24 May 2013 12:36:47 +0200
CC: r-help@r-project.org
To: eliza_bo...@hotmail.com


On 24-05-2013, at 12:24, eliza botto  wrote:


Dear useRs,If i have a matrix, say, 12 rows and 6 columns. The columns are 
continuous. I  want to find the index of maximum values and the actual maximum 
values. The maximum values in each column are the highest values and the values 
greater than or equal to 80% of the maximum value. Moreover, if a column has 
more than one maximum values than these values should come immediately next to 
each other.  For example, if you column 1 has a highest value in 6th row then 
the second maximum values cant be in row 5 or 7. And as the columns are 
continuous therefore, if maximum value is in row 12th, then the second maximum 
cant be in row 11 and 1.Thankyou very much indeed in advance



Incomprehensible.
What is a continuous column?

Please give an example input matrix and and the result you want.

Berend


Elisa   
[[alternative HTML version deleted]]



Please post in plain text.



[[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] Rcpp with OpenMP - Need example Makevars

2013-05-24 Thread Dirk Eddelbuettel

Hi Asis,

On 24 May 2013 at 11:10, Asis Hallab wrote:
| Dear R experts,
| 
| recently I started developing a Rcpp package "OpenMPTest".
| Within that package I want to use OpenMP, as in the following code example:
| 
| // header file
| #include 
| using namespace Rcpp ;
| RcppExport SEXP testOpenMP( SEXP nThreads ) ;
| 
| // cpp file
| SEXP testOpenMP( SEXP nThreads ) {
|   BEGIN_RCPP
| 
|   NumericVector numberThreads = NumericVector( nThreads );
|   omp_set_num_threads( numberThreads(0) );
|   #pragma omp parallel
|   {
| // Code inside this region runs in parallel.
| printf("Hello!\n");
|   }
| 
|   END_RCPP
| }
| 
| As I am an absolute newbie with writing C++ extensions and have not
| much understanding of the Makevars file, I am unsure what to write
| into it. Currently I have:
| 
| ## Use the R_HOME indirection to support installations of multiple R version
| PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"`

This sets a value to PKG_LIBS

| KG_CFLAGS = $(SHLIB_OPENMP_CXXFLAGS)

[ Why KG_CLAGS? ]

| PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS)

This _overwrites_ the previous value of PKG_LIBS. You need to have both.

| ## -- compiling for OpenMP
| PKG_CXXFLAGS=-fopenmp
| ##
| ## -- linking for OpenMP
| PKG_LIBS= -fopenmp -lgomp

This again overwrites.

The fix is pretty simple:

  PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) `$(R_HOME)/bin/Rscript -e 
"Rcpp:::LdFlags()"`
  PKG_CXXFLAGS=-fopenmp

should do. 

| Obviously compilation fails with error:
| 
| R CMD INSTALL OpenMPTest
| Symbol not found: __ZTIN4Rcpp19index_out_of_boundsE
| 
| With standard setup of the above Makevars I get the
| Symbol not found: omp_set_num_threads
| 
| Inline also does not work:
| 
| fb <- 'omp_set_num_threads(10);
| + #pragma omp parallel
| + { Rf_PrintValue(wrap("HALLO JUPP")); }
| + '
| > funk <-  cxxfunction( signature(), body=fb, plugin='Rcpp' )
| 
| error: ‘omp_set_num_threads’ was not declared in this scope
| 
| How do set the PKG_LIBS -and eventually other variables- to all
| required values in a single statement?

For example in the way it is done here:

   http://gallery.rcpp.org/articles/using-rcppprogress/

because sourceCpp() later expands on this initial values ("appends, not
overwrites").

| Could anyone provide me with a working Makevars example, please?

We long had those examples, several are on R-Forge as well. Did you even try
to google 'Rcpp OpenMP'? 
 
Try

PKG_CXXFLAGS="-fopenmp"
PKG_LIBS=$(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) 
$(BLAS_LIBS) $(FLIBS) -fopenmp

Dirk

| Help will be much appreciated!
| Kind regards and have a nice weekend!
| Cheers!
| 
| __
| 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.

-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.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] par(mfrow=c(1,3)) and postscript(file=)

2013-05-24 Thread Öhagen Patrik


I am printing three graphs into the same page using par(mfrow=c(1,3)) and the I 
want to save the file as postscript format using postscript()

When input the postscript file into the manuscript the three graphs appear on 
separate pages. What have I missed and done wrong?

Thank you in advance!

Cheers, Patrik

[[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] Continuous columns of matrix

2013-05-24 Thread eliza botto
There you go!!!

structure(c(0.706461987893674, 0.998391468394261, 0.72402995269242, 
1.70874688194537, 1.93906363083693, 0.89540353128442, 0.328327645695443, 
0.427434603701202, 0.591932250254601, 0.444627635494183, 1.44407704434405, 
1.79150336746345, 0.94525563730664, 1.1025988539757, 0.944726401770203, 
0.941068515436361, 1.50874009152312, 0.590015480056925, 0.311905493999476, 
0.596771673581893, 1.01502499067153, 0.803273181849135, 1.6704085033648, 
1.57021117646422, 0.492096635764151, 0.42688044914, 0.521585941816778, 
1.66472272302545, 2.61878329527404, 2.19154489521664, 0.493876245329722, 
0.4915787202584, 0.889477365620806, 0.609135860199222, 0.739201878930367, 
0.854663750519518, 0.948228727226247, 1.38569091844218, 0.910510759802679, 
1.25991218521949, 0.993123416952421, 0.553640392997634, 0.357487763503204, 
0.368328033777003, 0.344255688489322, 0.423679560916755, 1.32093576037521, 
3.13420679229785, 2.06195904001605, 1.41493262330451, 1.35748791897328, 
1.19490680241894, 0.70248875618332!
 2, 0.338258418490199, 0.123398398622741, 0.138548982660226, 0.16170889185798, 
0.414543218677095, 1.84629295875002, 2.24547399004563, 0.0849732189580101, 
0.070591276171845, 0.0926010253161898, 0.362209761457517, 1.45769283057202, 
3.16165004659667, 2.74903557756267, 1.94633472878995, 1.19319875840883, 
0.533232612926756, 0.225531074123974, 0.122949089115578), .Dim = c(12L, 6L))

Thanks once again..
Elisa


> Subject: Re: [R] Continuous columns of matrix
> From: b...@xs4all.nl
> Date: Fri, 24 May 2013 12:36:47 +0200
> CC: r-help@r-project.org
> To: eliza_bo...@hotmail.com
> 
> 
> On 24-05-2013, at 12:24, eliza botto  wrote:
> 
> > Dear useRs,If i have a matrix, say, 12 rows and 6 columns. The columns are 
> > continuous. I  want to find the index of maximum values and the actual 
> > maximum values. The maximum values in each column are the highest values 
> > and the values greater than or equal to 80% of the maximum value. Moreover, 
> > if a column has more than one maximum values than these values should come 
> > immediately next to each other.  For example, if you column 1 has a highest 
> > value in 6th row then the second maximum values cant be in row 5 or 7. And 
> > as the columns are continuous therefore, if maximum value is in row 12th, 
> > then the second maximum cant be in row 11 and 1.Thankyou very much indeed 
> > in advance
> 
> 
> Incomprehensible.
> What is a continuous column?
> 
> Please give an example input matrix and and the result you want.
> 
> Berend
> 
> > Elisa 
> > [[alternative HTML version deleted]]
> > 
> 
> Please post in plain text.
> 
  
[[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] Continuous columns of matrix

2013-05-24 Thread Berend Hasselman

On 24-05-2013, at 12:24, eliza botto  wrote:

> Dear useRs,If i have a matrix, say, 12 rows and 6 columns. The columns are 
> continuous. I  want to find the index of maximum values and the actual 
> maximum values. The maximum values in each column are the highest values and 
> the values greater than or equal to 80% of the maximum value. Moreover, if a 
> column has more than one maximum values than these values should come 
> immediately next to each other.  For example, if you column 1 has a highest 
> value in 6th row then the second maximum values cant be in row 5 or 7. And as 
> the columns are continuous therefore, if maximum value is in row 12th, then 
> the second maximum cant be in row 11 and 1.Thankyou very much indeed in 
> advance


Incomprehensible.
What is a continuous column?

Please give an example input matrix and and the result you want.

Berend

> Elisa   
>   [[alternative HTML version deleted]]
> 

Please post in plain text.

__
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] Rcpp with OpenMP - Need example Makevars

2013-05-24 Thread Prof Brian Ripley
This really is the wrong list: have you looked at the posting guide? 
The non-Rcpp aspects belong on R-devel.


But in short, you cannot control whether the R installation supports 
OpenMP.  'Writing R Extensions' tells you how to set up Makevars, so the 
example has already been documented for you.  CRAN packages using OpenMP 
include CORElearn FastPCS LDExplorer OpenMPController RcppProgress 
SpatialExtremes TPmsm TimeMachine abn aws blockcluster brnn cghseg dti 
fanc mRMRe mmcm mritc phangorn robustHD sabreR smc sparseLTSEigen 
textir, so there are plenty of examples about.


Remember that one of the three compilers commonly used with R has no 
OpenMP support, and that it is present but does not work in the compiler 
currently used on OS X.


On 24/05/2013 10:10, Asis Hallab wrote:

Dear R experts,

recently I started developing a Rcpp package "OpenMPTest".
Within that package I want to use OpenMP, as in the following code example:

// header file
#include 
using namespace Rcpp ;
RcppExport SEXP testOpenMP( SEXP nThreads ) ;

// cpp file
SEXP testOpenMP( SEXP nThreads ) {
   BEGIN_RCPP

   NumericVector numberThreads = NumericVector( nThreads );
   omp_set_num_threads( numberThreads(0) );
   #pragma omp parallel
   {
 // Code inside this region runs in parallel.
 printf("Hello!\n");
   }

   END_RCPP
}

As I am an absolute newbie with writing C++ extensions and have not
much understanding of the Makevars file, I am unsure what to write
into it. Currently I have:

## Use the R_HOME indirection to support installations of multiple R version
PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"`
KG_CFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS)
## -- compiling for OpenMP
PKG_CXXFLAGS=-fopenmp
##
## -- linking for OpenMP
PKG_LIBS= -fopenmp -lgomp

Obviously compilation fails with error:

R CMD INSTALL OpenMPTest
Symbol not found: __ZTIN4Rcpp19index_out_of_boundsE

With standard setup of the above Makevars I get the
Symbol not found: omp_set_num_threads

Inline also does not work:

fb <- 'omp_set_num_threads(10);
+ #pragma omp parallel
+ { Rf_PrintValue(wrap("HALLO JUPP")); }
+ '

funk <-  cxxfunction( signature(), body=fb, plugin='Rcpp' )


error: ‘omp_set_num_threads’ was not declared in this scope

How do set the PKG_LIBS -and eventually other variables- to all
required values in a single statement?
Could anyone provide me with a working Makevars example, please?

Help will be much appreciated!
Kind regards and have a nice weekend!
Cheers!

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




--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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] Continuous columns of matrix

2013-05-24 Thread eliza botto
Dear useRs,If i have a matrix, say, 12 rows and 6 columns. The columns are 
continuous. I  want to find the index of maximum values and the actual maximum 
values. The maximum values in each column are the highest values and the values 
greater than or equal to 80% of the maximum value. Moreover, if a column has 
more than one maximum values than these values should come immediately next to 
each other.  For example, if you column 1 has a highest value in 6th row then 
the second maximum values cant be in row 5 or 7. And as the columns are 
continuous therefore, if maximum value is in row 12th, then the second maximum 
cant be in row 11 and 1.Thankyou very much indeed in advance
Elisa 
[[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] Rcpp with OpenMP - Need example Makevars

2013-05-24 Thread Asis Hallab
Dear R experts,

recently I started developing a Rcpp package "OpenMPTest".
Within that package I want to use OpenMP, as in the following code example:

// header file
#include 
using namespace Rcpp ;
RcppExport SEXP testOpenMP( SEXP nThreads ) ;

// cpp file
SEXP testOpenMP( SEXP nThreads ) {
  BEGIN_RCPP

  NumericVector numberThreads = NumericVector( nThreads );
  omp_set_num_threads( numberThreads(0) );
  #pragma omp parallel
  {
// Code inside this region runs in parallel.
printf("Hello!\n");
  }

  END_RCPP
}

As I am an absolute newbie with writing C++ extensions and have not
much understanding of the Makevars file, I am unsure what to write
into it. Currently I have:

## Use the R_HOME indirection to support installations of multiple R version
PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"`
KG_CFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS)
## -- compiling for OpenMP
PKG_CXXFLAGS=-fopenmp
##
## -- linking for OpenMP
PKG_LIBS= -fopenmp -lgomp

Obviously compilation fails with error:

R CMD INSTALL OpenMPTest
Symbol not found: __ZTIN4Rcpp19index_out_of_boundsE

With standard setup of the above Makevars I get the
Symbol not found: omp_set_num_threads

Inline also does not work:

fb <- 'omp_set_num_threads(10);
+ #pragma omp parallel
+ { Rf_PrintValue(wrap("HALLO JUPP")); }
+ '
> funk <-  cxxfunction( signature(), body=fb, plugin='Rcpp' )

error: ‘omp_set_num_threads’ was not declared in this scope

How do set the PKG_LIBS -and eventually other variables- to all
required values in a single statement?
Could anyone provide me with a working Makevars example, please?

Help will be much appreciated!
Kind regards and have a nice weekend!
Cheers!

__
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 in png: unable to start png() device

2013-05-24 Thread PIKAL Petr
Hi

Beside of what Uwe recommends. You probably use some cycle. Why not to use 
multipage pdf? I remember I once created pdf with more than 1000 pages without 
any problem.

Regards
Petr

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Ondrej Novak
> Sent: Thursday, May 23, 2013 5:06 PM
> To: r-help@r-project.org
> Subject: [R] Error in png: unable to start png() device
> 
> Hi,
> I use R 2.14.0 on Win XP Pro SP3 and it behaves same - some times.
> After I draw a lot of plots (more then 200, 2 concurrent rgui processes
> running in parallel) to png then I get same error message.
> Bmp(), jpg(), png() - same error. Restart of Rgui helps nothing.
> 
> Solutin - restart system and voila everything is ok.
> 
> I suspect that there might be something wrong with
> allocation/deallocation of Windows resources in windows() function.
> 
> Ondrej Novak
> 
>   [[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.


[R] Construct plot combination using grid without plotting and retrieving an object?

2013-05-24 Thread Johannes Graumann
Hi,

I'm currently combining multiple plots using something along the lines 
of the following pseudo-code:

library(grid)
grid.newpage()
tmpLayout <- grid.layout(
nrow=4,
ncol=2)
pushViewport(viewport(layout = tmpLayout))

and than proceeding with filling the viewports ... works fine, but for 
packaging of functions I would really prefer if I could assemble all of 
this in an object which in the end would be callable with "print".

I'm envisioning something along the lines of what I can do with 
ggplot2: return a plot as a ggpplot object and plot it later rather 
than as I assemble it. Is that possible with a complex grid figure?

Thanks for any pointers.

Joh

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