Re: [R] Trouble retrieving the second largest value from each row of a data.frame

2010-07-23 Thread Joshua Wiley
Maybe efficiency is less of an issue than I thought, on 2 million
rows, it only took a bit over a minute, and my system only jumped up ~
600 MB of memory so it wasn't much of a strain there either.

> data.test <- matrix(
+  sample(seq(min(yourdata),max(yourdata)), size = 1000, replace = TRUE),
+  ncol = 5)
> nrow(data.test)
[1] 200
> system.time(my.finder(data.test))
   user  system elapsed
  74.540.20   75.20

On Fri, Jul 23, 2010 at 11:01 PM, Joshua Wiley  wrote:
> Hi,
>
> Here is a little function that will do what you want and return a nice output:
>
> #Function To calculate top two values and return
> my.finder <- function(mydata) {
>  my.fun <- function(data) {
>    strongest <- which.max(data)
>    secondstrongest <- which.max(data[-strongest])
>    strongestantenna <- names(data)[strongest]
>    secondstrongantenna <- names(data[-strongest])[secondstrongest]
>    value <- matrix(c(data[strongest], data[secondstrongest],
>                      strongestantenna, secondstrongantenna), ncol =4)
>    return(value)
>  }
>  dat <- apply(mydata, 1, my.fun)
>  dat <- t(dat)
>  dat <- as.data.frame(dat, stringsAsFactors = FALSE)
>  colnames(dat) <- c("strongest", "secondstrongest",
>                     "strongestantenna", "secondstrongantenna")
>  dat[ , "strongest"] <- as.numeric(dat[ , "strongest"])
>  dat[ , "secondstrongest"] <- as.numeric(dat[ , "secondstrongest"])
>  return(dat)
> }
>
>
> #Using your example data:
>
> yourdata <- structure(list(value0 = c(-13007L, -12838L, -12880L, -12805L,
> -12834L, -11068L, -12807L, -12770L, -12988L, -11779L), value60 = c(-11707L,
> -13210L, -11778L, -11653L, -13527L, -11698L, -14068L, -11665L,
> -11736L, -12873L), value120 = c(-11072L, -11176L, -3L, -11071L,
> -11067L, -12430L, -11092L, -11061L, -11137L, -12973L), value180 = c(-12471L,
> -11799L, -12439L, -12385L, -11638L, -12430L, -11709L, -12373L,
> -12570L, -12537L), value240 = c(-12838L, -13210L, -13089L, -11561L,
> -13527L, -12430L, -11607L, -11426L, -13467L, -12973L), value300 = c(-13357L,
> -13845L, -13880L, -13317L, -13873L, -12814L, -13025L, -12805L,
> -13739L, -11146L)), .Names = c("value0", "value60", "value120",
> "value180", "value240", "value300"), class = "data.frame", row.names = c("1",
> "2", "3", "4", "5", "6", "7", "8", "9", "10"))
>
> my.finder(yourdata) #and what you want is in a nicely labeled data frame
>
> #A potential problem is that it is not very efficient
>
> #Here is a test using a matrix of 100,000 rows
> #sampled from the same range as your data
> #with the same number of columns
>
> data.test <- matrix(
>  sample(seq(min(yourdata),max(yourdata)), size = 50, replace = TRUE),
>  ncol = 5)
>
> system.time(my.finder(data.test))
>
> #On my system I get
>
>> system.time(my.finder(data.test))
>   user  system elapsed
>   2.89    0.00    2.89
>
> Hope that helps,
>
> Josh
>
>
>
> On Fri, Jul 23, 2010 at 6:20 PM,   wrote:
>> I have a data frame with a couple million lines and want to retrieve the 
>> largest and second largest values in each row, along with the label of the 
>> column these values are in. For example
>>
>> row 1
>> strongest=-11072
>> secondstrongest=-11707
>> strongestantenna=value120
>> secondstrongantenna=value60
>>
>> Below is the code I am using and a truncated data.frame.  Retrieving the 
>> largest value was easy, but I have been getting errors every way I have 
>> tried to retrieve the second largest value.  I have not even tried to 
>> retrieve the labels for the value yet.
>>
>> Any help would be appreciated
>> Mike
>>
>>
>>> data<-data.frame(value0,value60,value120,value180,value240,value300)
>>> data
>>   value0 value60 value120 value180 value240 value300
>> 1  -13007  -11707   -11072   -12471   -12838   -13357
>> 2  -12838  -13210   -11176   -11799   -13210   -13845
>> 3  -12880  -11778   -3   -12439   -13089   -13880
>> 4  -12805  -11653   -11071   -12385   -11561   -13317
>> 5  -12834  -13527   -11067   -11638   -13527   -13873
>> 6  -11068  -11698   -12430   -12430   -12430   -12814
>> 7  -12807  -14068   -11092   -11709   -11607   -13025
>> 8  -12770  -11665   -11061   -12373   -11426   -12805
>> 9  -12988  -11736   -11137   -12570   -13467   -13739
>> 10 -11779  -12873   -12973   -12537   -12973   -11146
>>> #largest value in the row
>>> strongest<-apply(data,1,max)
>>>
>>>
>>> #second largest value in the row
>>> n<-function(data)(1/(min(1/(data[1,]-max(data[1,]+ (max(data[1,])))
>>> secondstrongest<-apply(data,1,n)
>> Error in data[1, ] : incorrect number of dimensions
>>>
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --
> Joshua Wiley
> Ph.D. Student, Health Psychology
> University of California, Los Angeles
> http://www.joshuawiley.com/
>



-- 
Joshua Wiley
Ph.D. Student, Hea

Re: [R] Trouble retrieving the second largest value from each row of a data.frame

2010-07-23 Thread Joshua Wiley
Hi,

Here is a little function that will do what you want and return a nice output:

#Function To calculate top two values and return
my.finder <- function(mydata) {
  my.fun <- function(data) {
strongest <- which.max(data)
secondstrongest <- which.max(data[-strongest])
strongestantenna <- names(data)[strongest]
secondstrongantenna <- names(data[-strongest])[secondstrongest]
value <- matrix(c(data[strongest], data[secondstrongest],
  strongestantenna, secondstrongantenna), ncol =4)
return(value)
  }
  dat <- apply(mydata, 1, my.fun)
  dat <- t(dat)
  dat <- as.data.frame(dat, stringsAsFactors = FALSE)
  colnames(dat) <- c("strongest", "secondstrongest",
 "strongestantenna", "secondstrongantenna")
  dat[ , "strongest"] <- as.numeric(dat[ , "strongest"])
  dat[ , "secondstrongest"] <- as.numeric(dat[ , "secondstrongest"])
  return(dat)
}


#Using your example data:

yourdata <- structure(list(value0 = c(-13007L, -12838L, -12880L, -12805L,
-12834L, -11068L, -12807L, -12770L, -12988L, -11779L), value60 = c(-11707L,
-13210L, -11778L, -11653L, -13527L, -11698L, -14068L, -11665L,
-11736L, -12873L), value120 = c(-11072L, -11176L, -3L, -11071L,
-11067L, -12430L, -11092L, -11061L, -11137L, -12973L), value180 = c(-12471L,
-11799L, -12439L, -12385L, -11638L, -12430L, -11709L, -12373L,
-12570L, -12537L), value240 = c(-12838L, -13210L, -13089L, -11561L,
-13527L, -12430L, -11607L, -11426L, -13467L, -12973L), value300 = c(-13357L,
-13845L, -13880L, -13317L, -13873L, -12814L, -13025L, -12805L,
-13739L, -11146L)), .Names = c("value0", "value60", "value120",
"value180", "value240", "value300"), class = "data.frame", row.names = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10"))

my.finder(yourdata) #and what you want is in a nicely labeled data frame

#A potential problem is that it is not very efficient

#Here is a test using a matrix of 100,000 rows
#sampled from the same range as your data
#with the same number of columns

data.test <- matrix(
 sample(seq(min(yourdata),max(yourdata)), size = 50, replace = TRUE),
 ncol = 5)

system.time(my.finder(data.test))

#On my system I get

> system.time(my.finder(data.test))
   user  system elapsed
   2.890.002.89

Hope that helps,

Josh



On Fri, Jul 23, 2010 at 6:20 PM,   wrote:
> I have a data frame with a couple million lines and want to retrieve the 
> largest and second largest values in each row, along with the label of the 
> column these values are in. For example
>
> row 1
> strongest=-11072
> secondstrongest=-11707
> strongestantenna=value120
> secondstrongantenna=value60
>
> Below is the code I am using and a truncated data.frame.  Retrieving the 
> largest value was easy, but I have been getting errors every way I have tried 
> to retrieve the second largest value.  I have not even tried to retrieve the 
> labels for the value yet.
>
> Any help would be appreciated
> Mike
>
>
>> data<-data.frame(value0,value60,value120,value180,value240,value300)
>> data
>   value0 value60 value120 value180 value240 value300
> 1  -13007  -11707   -11072   -12471   -12838   -13357
> 2  -12838  -13210   -11176   -11799   -13210   -13845
> 3  -12880  -11778   -3   -12439   -13089   -13880
> 4  -12805  -11653   -11071   -12385   -11561   -13317
> 5  -12834  -13527   -11067   -11638   -13527   -13873
> 6  -11068  -11698   -12430   -12430   -12430   -12814
> 7  -12807  -14068   -11092   -11709   -11607   -13025
> 8  -12770  -11665   -11061   -12373   -11426   -12805
> 9  -12988  -11736   -11137   -12570   -13467   -13739
> 10 -11779  -12873   -12973   -12537   -12973   -11146
>> #largest value in the row
>> strongest<-apply(data,1,max)
>>
>>
>> #second largest value in the row
>> n<-function(data)(1/(min(1/(data[1,]-max(data[1,]+ (max(data[1,])))
>> secondstrongest<-apply(data,1,n)
> Error in data[1, ] : incorrect number of dimensions
>>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

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


Re: [R] Trouble retrieving the second largest value from each row of a data.frame

2010-07-23 Thread jim holtman
try this:

> x <- read.table(textConnection("  value0 value60 value120 value180 value240 
> value300
+ 1  -13007  -11707   -11072   -12471   -12838   -13357
+ 2  -12838  -13210   -11176   -11799   -13210   -13845
+ 3  -12880  -11778   -3   -12439   -13089   -13880
+ 4  -12805  -11653   -11071   -12385   -11561   -13317
+ 5  -12834  -13527   -11067   -11638   -13527   -13873
+ 6  -11068  -11698   -12430   -12430   -12430   -12814
+ 7  -12807  -14068   -11092   -11709   -11607   -13025
+ 8  -12770  -11665   -11061   -12373   -11426   -12805
+ 9  -12988  -11736   -11137   -12570   -13467   -13739
+ 10 -11779  -12873   -12973   -12537   -12973   -11146"), header=TRUE)
> closeAllConnections()
> # generate the indices of 1st&2nd largest in each row
> indx <- apply(x, 1, function(z){
+ order(z, decreasing=TRUE)[1:2]
+ })
> # now print out the data for each row
> for (i in seq(ncol(indx))){
+ cat('row:', i,
+ '1st:', x[i, indx[1,i]], 'col:', colnames(x)[indx[1,i]],
+ '2nd:', x[i, indx[2,i]], 'col:', colnames(x)[indx[2,i]], '\n')
+ }
row: 1 1st: -11072 col: value120 2nd: -11707 col: value60
row: 2 1st: -11176 col: value120 2nd: -11799 col: value180
row: 3 1st: -3 col: value120 2nd: -11778 col: value60
row: 4 1st: -11071 col: value120 2nd: -11561 col: value240
row: 5 1st: -11067 col: value120 2nd: -11638 col: value180
row: 6 1st: -11068 col: value0 2nd: -11698 col: value60
row: 7 1st: -11092 col: value120 2nd: -11607 col: value240
row: 8 1st: -11061 col: value120 2nd: -11426 col: value240
row: 9 1st: -11137 col: value120 2nd: -11736 col: value60
row: 10 1st: -11146 col: value300 2nd: -11779 col: value0
>
>


On Fri, Jul 23, 2010 at 9:20 PM,   wrote:
> I have a data frame with a couple million lines and want to retrieve the 
> largest and second largest values in each row, along with the label of the 
> column these values are in. For example
>
> row 1
> strongest=-11072
> secondstrongest=-11707
> strongestantenna=value120
> secondstrongantenna=value60
>
> Below is the code I am using and a truncated data.frame.  Retrieving the 
> largest value was easy, but I have been getting errors every way I have tried 
> to retrieve the second largest value.  I have not even tried to retrieve the 
> labels for the value yet.
>
> Any help would be appreciated
> Mike
>
>
>> data<-data.frame(value0,value60,value120,value180,value240,value300)
>> data
>   value0 value60 value120 value180 value240 value300
> 1  -13007  -11707   -11072   -12471   -12838   -13357
> 2  -12838  -13210   -11176   -11799   -13210   -13845
> 3  -12880  -11778   -3   -12439   -13089   -13880
> 4  -12805  -11653   -11071   -12385   -11561   -13317
> 5  -12834  -13527   -11067   -11638   -13527   -13873
> 6  -11068  -11698   -12430   -12430   -12430   -12814
> 7  -12807  -14068   -11092   -11709   -11607   -13025
> 8  -12770  -11665   -11061   -12373   -11426   -12805
> 9  -12988  -11736   -11137   -12570   -13467   -13739
> 10 -11779  -12873   -12973   -12537   -12973   -11146
>> #largest value in the row
>> strongest<-apply(data,1,max)
>>
>>
>> #second largest value in the row
>> n<-function(data)(1/(min(1/(data[1,]-max(data[1,]+ (max(data[1,])))
>> secondstrongest<-apply(data,1,n)
> Error in data[1, ] : incorrect number of dimensions
>>
>
> __
> R-help@r-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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@r-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] union data in column

2010-07-23 Thread jim holtman
try this:

> x <- read.table(textConnection(" GENEID  col1  col2 
> col3col4
+  G234064 1 0  0   0
+  G234064 1 0  0   0
+  G234064 1 0  0   0
+  G234064 0 1  0   0
+  G234065 0 1  0   0
+  G234065 0 1  0   0
+  G234065 0 1  0   0
+  G234065 0 0  1   0
+  G234065 0 0  1   0
+  G234065 0 0  0
 1"), header=TRUE, as.is=TRUE)
>  closeAllConnections()
> # split the data and process the columns
> do.call(rbind, lapply(split(x, x$GENEID), function(z){
+ # 'or' the columns
+
+ colOR <- t(apply(z[-1], 2, any)) + 0L
+ data.frame(GENEID=z[[1]][1], colOR)
+ }))
 GENEID col1 col2 col3 col4
G234064 G2340641100
G234065 G2340650111
>


On Sat, Jul 24, 2010 at 12:10 AM, Fahim Md  wrote:
> Is there any function/way to merge/unite the following data
>
>  GENEID      col1          col2             col3                col4
>  G234064         1             0                  0                   0
>  G234064         1             0                  0                   0
>  G234064         1             0                  0                   0
>  G234064         0             1                  0                   0
>  G234065         0             1                  0                   0
>  G234065         0             1                  0                   0
>  G234065         0             1                  0                   0
>  G234065         0             0                  1                   0
>  G234065         0             0                  1                   0
>  G234065         0             0                  0                   1
>
>
> into
> GENEID      col1          col2             col3                col4
>  G234064         1             1                  0                   0
> // 1 appears in col1 and col2 above, rest are zero
>  G234065         0             1                  1                   1
> // 1 appears in col2 , 3 and 4 above.
>
>
> Thanks
>
>
>
> --
> Fahim
>
>        [[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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@r-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] union data in column

2010-07-23 Thread Fahim Md
Is there any function/way to merge/unite the following data

  GENEID  col1  col2 col3col4
  G234064 1 0  0   0
  G234064 1 0  0   0
  G234064 1 0  0   0
  G234064 0 1  0   0
  G234065 0 1  0   0
  G234065 0 1  0   0
  G234065 0 1  0   0
  G234065 0 0  1   0
  G234065 0 0  1   0
  G234065 0 0  0   1


into
GENEID  col1  col2 col3col4
  G234064 1 1  0   0
// 1 appears in col1 and col2 above, rest are zero
  G234065 0 1  1   1
// 1 appears in col2 , 3 and 4 above.


Thanks



-- 
Fahim

[[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] Trouble retrieving the second largest value from each row of a data.frame

2010-07-23 Thread mpward
I have a data frame with a couple million lines and want to retrieve the 
largest and second largest values in each row, along with the label of the 
column these values are in. For example 

row 1
strongest=-11072
secondstrongest=-11707
strongestantenna=value120
secondstrongantenna=value60

Below is the code I am using and a truncated data.frame.  Retrieving the 
largest value was easy, but I have been getting errors every way I have tried 
to retrieve the second largest value.  I have not even tried to retrieve the 
labels for the value yet.

Any help would be appreciated
Mike


> data<-data.frame(value0,value60,value120,value180,value240,value300)
> data
   value0 value60 value120 value180 value240 value300
1  -13007  -11707   -11072   -12471   -12838   -13357
2  -12838  -13210   -11176   -11799   -13210   -13845
3  -12880  -11778   -3   -12439   -13089   -13880
4  -12805  -11653   -11071   -12385   -11561   -13317
5  -12834  -13527   -11067   -11638   -13527   -13873
6  -11068  -11698   -12430   -12430   -12430   -12814
7  -12807  -14068   -11092   -11709   -11607   -13025
8  -12770  -11665   -11061   -12373   -11426   -12805
9  -12988  -11736   -11137   -12570   -13467   -13739
10 -11779  -12873   -12973   -12537   -12973   -11146
> #largest value in the row
> strongest<-apply(data,1,max)
> 
> 
> #second largest value in the row
> n<-function(data)(1/(min(1/(data[1,]-max(data[1,]+ (max(data[1,])))
> secondstrongest<-apply(data,1,n)
Error in data[1, ] : incorrect number of dimensions
>

__
R-help@r-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] glm - prediction of a factor with several levels

2010-07-23 Thread blackscorpio

Dear community,
I'm currently attempting to predict the occurence of an event (factor)
having more than 2 levels with several continuous predictors. The model
being ordinal, I was waiting the glm function to return several intercepts,
which is not the case when looking to my results (I only have one
intercept). I finally managed to perform an ordinal polytomous logisitc
regression with the polr function, which gives several intercepts.
But does anyone know what was the model performed with glm and why only one
intercept was given ?
Thanks a lot for your help !

-- 
View this message in context: 
http://r.789695.n4.nabble.com/glm-prediction-of-a-factor-with-several-levels-tp2300793p2300793.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] densityplot on date objects

2010-07-23 Thread Jack T.

Hi, I'm looking for a way to use densityplot in the lattice package on Date
data or manipulate the labels for tick marks.

Here's an example:
#generate psuedo dates
dat.Date  <- as.Date('2009-12-31')+as.integer(abs(rnorm(1))*100)
  #convert to a julian date for densityplot
  #because it doesn't do Date or POSIX.. objects
  densityplot(as.numeric(format(as.Date(dat.Date), "%j")), plot.points=F)

My conversion to julian date here was only to 'force' densityplot to plot
some Date data

My question specifically is:

How could I express the X axis in this figure as Dates 
perhaps sequenced by month (e.g. '2010-01-01', '2010-02-01', etc).

I could do this with the base R graphics but am at a loss with lattice
densityplot.

Thanks for any advice in advance!

JT

-- 
View this message in context: 
http://r.789695.n4.nabble.com/densityplot-on-date-objects-tp2300570p2300570.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] , Updating Table

2010-07-23 Thread Marcus Liu
Hi everyone,

Is there any command for updating table withing a loop?  For instance, at i, I 
have a table as ZZ = table(data.raw[1:ind[i]]) where "ind" = c(10, 20, 30, 
...).  Then , ZZ will be as follow

"A" "B" "C"
 3    10   2

At (i + 1), ZZ = table(data.raw[(ind[i]+1):ind[i+1]])

"A" "B" "D"
 4    7    8

Is there any command that can update the table ZZ for each time so that in the 
above example, ZZ will be

"A" "B" "C" "D"
 7    17   2    8

Thanks.

liu



  
[[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] 64 bit use of odbcConnectExcel

2010-07-23 Thread mdsumner
 Try using odbcConnectExcel2007, instead of odbcConnectExcel. 

That has worked for me. 

Cheers, Mike.

> Message: 60
> Date: Thu, 22 Jul 2010 09:14:23 -0700 (PDT)
> From: "Jack T." 
> To: r-help@r-project.org
> Subject: [R] 64 bit use of odbcConnectExcel
> Message-ID: <1279815263840-2298927.p...@n4.nabble.com>
> Content-Type: text/plain; charset=us-ascii
> 
> 
> Hi All, 
> 
> I'm using R 2.11.1 on 64 bit windows XP.  The little function I wrote below
> I use often to import the first 1001 lines in an excel sheet to R.  This
> works fine on the 32 bit version of R but fails on the 64 bit [both on the
> same machine, using the same function, importing the same .xls file].  The
> message from 64 bit R is:
> 
> Error in sqlTables(channel1) : 
>   first argument is not an open RODBC channel
> In addition: Warning messages:
> 1: In odbcDriverConnect(con, tabQuote = c("[", "]"), ...) :
>   [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver
> Manager] Data source name not found and no default driver specified
> 2: In odbcDriverConnect(con, tabQuote = c("[", "]"), ...) :
>   ODBC connection failed
> 
> 
> I've also tried functions in the xlsReadWrite library.  Is reading .xls
> files just something that the 64-bit R can't do yet?  I would prefer to use
> 64 bit R all of the time because it makes use of all the RAM on my computer
> (> 4 gig) and for files with millions of rows this is useful but it seems it
> is still under development.  For now I switch back an forth between 64 bit
> and 32 bit depending on what I'm working on.
> 
> Any suggested solutions for xls import problems?
> 
> My function
> get.xls.file <- function(xlsfile){
> library(RODBC)
> #xlsfile <- file.choose()
> channel1 <- odbcConnectExcel(xlsfile)
> a <- sqlTables(channel1)
> b <- nchar(a$TABLE_NAME[1])
> x <- substring(a$TABLE_NAME[1], 2, b-2)
> data <- sqlFetch(channel1, x, max=1001)
> odbcCloseAll()
> return(data)
> }
> 
> 
> JT
> -- 
> View this message in context: 
> http://r.789695.n4.nabble.com/64-bit-use-of-odbcConnectExcel-tp2298927p2298927.html
> Sent from the R help mailing list archive at Nabble.com.

 
Michael Sumner 
Institute for Marine and Antarctic Studies, University of Tasmania 
Hobart, Australia 
e-mail: mdsum...@utas.edu.au

__
R-help@r-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] greek letters in rgl plot3d

2010-07-23 Thread Duncan Murdoch

On 23/07/2010 7:39 AM, james.fo...@diamond.ac.uk wrote:

Dear RGL experts,
I haven't been able to add greek letters to my rgl plot3d.
I have tried "expression" with no success.

Here is the interested bit:

> library(rgl)
> cb <- cube3d()
> plot3d(cb,xlab=expression(alpha),ylab="",zlab="",box=FALSE,alpha=0.5)

The expression(alpha) appears as "alpha", rather than as a greek symbol.
I suspect greek and mathematical symbols in general can be added to a plot3d
in rgl. Is that true?
  


You can probably add the symbols if you choose a font that contains 
them, but there is no support for the plotmath mechanism that's in the 
standard graphics system.


I think the best you could do would be to typeset the label into a 
bitmap, then display it as a sprite or texture in rgl.


Adding plotmath support to rgl is something that would be really 
interesting, but quite difficult. 


Duncan Murdoch

J

Dr James Foadi PhD
Membrane Protein Laboratory (MPL)
Diamond Light Source Ltd
Diamond House
Harewell Science and Innovation Campus
Chilton, Didcot
Oxfordshire OX11 0DE

Email:  james.fo...@diamond.ac.uk
Alt Email:  j.fo...@imperial.ac.uk





__
R-help@r-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] (no subject)

2010-07-23 Thread w 霍

Dear R list,

I use the constrOptim to maximize a function with four constriants but the 
answer does not leave from the starting value and there is only one outer 
iteration. The function is defined as follows:
tm<-function(p){
p1<-p[1]; p2<-p[2]; p3<-p[3];
p4<-1-p1-p2-p3;
p1*p2*p3*p4}

##the constraints are p1>=0; p2>=0; p3>=0 and p4>=0 i.e. p1+p2+p3<=1
start<-c(0.991,0.001,0.001)
dev<-rbind(diag(3),-diag(3),rep(-1,3))
bvec<-c(rep(0,3),rep(-1,4))
constrOptim(start,tm,NULL,ui=dev,ci=bvec,control=list(maxit=1))

Am i missing something obviously that cause the problem or there is some bugs 
in constrOptim. Could you please help me out

Cheers

Wenwen


  
_
Hotmail: Free, trusted and rich email service.

[[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] Tutorial Tinn-R

2010-07-23 Thread Tom La Bone

Seems to be a relevant and reasonable question to me. 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Tutorial-Tinn-R-tp2300451p2300648.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] how to calculate the product of every two elements in two vectors

2010-07-23 Thread aegea

Thanks in advance!

A=c(1, 2,3)
B=c (9, 10, 11, 12)

I want to get C=c(1*9, 1*10, 1*11, 1*12, ., 3*9, 3*10, 3*11, 3*12)?
C is still a vector with 12 elements
Is there a way to do that?
-- 
View this message in context: 
http://r.789695.n4.nabble.com/how-to-calculate-the-product-of-every-two-elements-in-two-vectors-tp2300299p2300299.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to import simple java/mathematica expression to R

2010-07-23 Thread David Winsemius


On Jul 23, 2010, at 10:29 PM, jim holtman wrote:


Well, I took you equation and put the following at the start:

Power <- function(x,y) x^y
EE <- function(x) x
alp <- 2

x <- 900*Power(-0.2030178326474623 + 0.23024073983368956*(1 -  
alp) +

   0.2807352820970084*(1 - alp)*(1 - alp*(1 + EE(1))) +
0.2145643524071315*(1 - alp)*
   Power(1 - alp*(1 + EE(1)),2) + 0.11519022530097237*(1 -
alp)*Power(1 - alp*(1 + EE(1)),3) +
   0.046127977611990736*(1 - alp)*Power(1 - alp*(1 + EE(1)),4) +
0.014279410543117517*(1 - alp)*
   Power(1 - alp*(1 + EE(1)),5) + 0.2145643524071315*(Power(1 -
alp,2)*alp*(1 + EE(1)) +
   (1 - alp)*alp*(1 + EE(1))*(1 - alp*(1 + EE(1))) + Power(1 -
alp,2)*alp*(1 + EE(2))) +
   0.11519022530097237*(Power(1 - alp,2)*alp*(1 + EE(1))*(1 - alp*(1
+ EE(1))) +
   2*(1 - alp)*alp*(1 + EE(1))*Power(1 - alp*(1 + EE(1)),2) +
   Power(1 - alp,2)*alp*(1 - alp*(1 + EE(1)))*(1 + EE(2))) +
.

since there appeared to be functions "Power" and "EE", and the
variable 'alp'. This evaluated as-is to:  32157617213

so what you have appears to be a legal equation that R can parse as
is.  There you can probably put it in a function and use one of the R
routines to minimize it,  It does not look like you will have any
problem importing it to R; just have to make sure you have the
appropriate functions defined.


It has some interesting properties with that identity definition of  
EE(x). Local maxima at 1 and 0, "blows up" beyond -1 and 2, and  
several local minima nearby:


Math.Fn <- function(alp) {  }
plot( seq(-.3,1.5,by=0.01), Math.Fn(seq(-.3,1.5,by=0.01) ), cex=0.2)

--
David.



On Fri, Jul 23, 2010 at 1:29 PM, Andrey Siver  
 wrote:

Hello,

2010/7/23 jim holtman :

It would be nice if you could post what the data looks like that you
want to import.  R can import any text file and then you have string
manipulation that you can do to parse it.  So the basic answer is
probably yes, but we do need to understand the format of the data to
give a more precise answer.


I put the target expression to minimize (with some constrains) here:

http://analytic-products4you.com/target.txt

Is it possible to import it as a function to minimize?



What is the problem that you are trying to solve?



We solve a problem for parameters estimation with ties.

--

David Winsemius, MD
West Hartford, CT

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


Re: [R] How to import simple java/mathematica expression to R

2010-07-23 Thread jim holtman
Well, I took you equation and put the following at the start:

Power <- function(x,y) x^y
EE <- function(x) x
alp <- 2

x <- 900*Power(-0.2030178326474623 + 0.23024073983368956*(1 - alp) +
0.2807352820970084*(1 - alp)*(1 - alp*(1 + EE(1))) +
0.2145643524071315*(1 - alp)*
Power(1 - alp*(1 + EE(1)),2) + 0.11519022530097237*(1 -
alp)*Power(1 - alp*(1 + EE(1)),3) +
0.046127977611990736*(1 - alp)*Power(1 - alp*(1 + EE(1)),4) +
0.014279410543117517*(1 - alp)*
Power(1 - alp*(1 + EE(1)),5) + 0.2145643524071315*(Power(1 -
alp,2)*alp*(1 + EE(1)) +
(1 - alp)*alp*(1 + EE(1))*(1 - alp*(1 + EE(1))) + Power(1 -
alp,2)*alp*(1 + EE(2))) +
0.11519022530097237*(Power(1 - alp,2)*alp*(1 + EE(1))*(1 - alp*(1
+ EE(1))) +
2*(1 - alp)*alp*(1 + EE(1))*Power(1 - alp*(1 + EE(1)),2) +
Power(1 - alp,2)*alp*(1 - alp*(1 + EE(1)))*(1 + EE(2))) +
.

since there appeared to be functions "Power" and "EE", and the
variable 'alp'. This evaluated as-is to:  32157617213

so what you have appears to be a legal equation that R can parse as
is.  There you can probably put it in a function and use one of the R
routines to minimize it,  It does not look like you will have any
problem importing it to R; just have to make sure you have the
appropriate functions defined.

On Fri, Jul 23, 2010 at 1:29 PM, Andrey Siver  wrote:
> Hello,
>
> 2010/7/23 jim holtman :
>> It would be nice if you could post what the data looks like that you
>> want to import.  R can import any text file and then you have string
>> manipulation that you can do to parse it.  So the basic answer is
>> probably yes, but we do need to understand the format of the data to
>> give a more precise answer.
>
> I put the target expression to minimize (with some constrains) here:
>
> http://analytic-products4you.com/target.txt
>
> Is it possible to import it as a function to minimize?
>
>>
>> What is the problem that you are trying to solve?
>>
>
> We solve a problem for parameters estimation with ties.
>
> Thank You for the answer.
>
> --
> Regards,
>
>    -Andrey
>
> __
> R-help@r-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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@r-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] latent class analysis with mixed variable types

2010-07-23 Thread Donald Braman
As an alternative to Latent GOLD, I'm wondering if anyone knows of and R
package that can manage Latent Class Analysis with mixed variable types
(continuous, ordinal, and nominal/binary).

[[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] UseR! 2010 - my impressions

2010-07-23 Thread Ravi Varadhan
Dear UseRs!,

Everything about UseR! 2010 was terrific!  I really mean "everything" - the 
tutorials, invited talks, kaleidoscope sessions, focus sessions, breakfast, 
snacks, lunch, conference dinner, shuttle services, and the participants. The 
organization was fabulous.  NIST were gracious hosts, and provided top notch 
facilities.  The rousing speech by Antonio Possolo, who is the chief of 
Statistical Engineering Division at NIST, set the tempo for the entire 
conference.  Excellent invited lectures by Luke Tierney, Frank Harrell, Mark 
Handcock, Diethelm Wurtz, Uwe Ligges, and Fritz Leisch.  All the sessions that 
I attended had many interesting ideas and useful contributions.  During the 
whole time that I was there, I could not help but get the feeling that I am a 
part of something great. 

Before I end, let me add a few words about a special person.  This conference 
would not have been as great as it was without the tireless efforts of Kate 
Mullen.  The great thing about Kate is that she did so much without ever 
hogging the limelight.  Thank you, Kate and thank you NIST!

I cannot wait for UseR!2011!

Best,
Ravi. 



Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvarad...@jhmi.edu

__
R-help@r-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] sink function

2010-07-23 Thread Matt Shotwell
I had addressed a problem similar to this only a few days ago. Please
see the following URL:

http://tolstoy.newcastle.edu.au/R/e11/help/10/07/1677.html

On Fri, 2010-07-23 at 08:45 -0400, nuncio m wrote:
> I have the following code to write the output from auto.arima function.  The
> issue is not in finding the model but to divert its out put
> fit to a file order_fit.txt. code runs but nothing is written to
> order_fit.txt
> where am I going wrong
> 
> library(forecast)
> for (i in 1:2) {
> filen = paste("file",i,".txt",sep="")
> data <- read.table(filen)
> dat1 <- data[,1]
> xt <- ts(dat1,start=c(1978,11),end=c(2006,12),frequency=12)
> #dat1[dat1 == -99.989998] <- NA
> if (min(dat1) != max(dat1)){
> fit <- auto.arima(xt,D=1)
> 
> *sink(file="order_fit.txt")
> fit
> sink()*
> 
> residfit <- residuals(fit)
> filenou1 = paste("fileree",i,"_out",".txt",sep="")
> residfit
> write.table(residfit,filenou1,sep="\t",col.names=FALSE,row.names=FALSE,quote=FALSE)
> 
> }else{
> *fiit <- "ARIMA(-6,-6,-6)(-6,-6,-6)[12]"
> sink(file="order_fit.txt")
> fiit
> sink()*
> filenou1 = paste("fileree",i,"_out",".txt",sep="")
> residfit=rep(-99.99,338)
> residfit
> write.table(residfit,filenou1,sep="\t",col.names=FALSE,row.names=FALSE,quote=FALSE)
> rm(data,dat1,residfit,xt)
> }
> }
> 

--

__
R-help@r-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] Reconciling 2 datasets

2010-07-23 Thread Bert Gunter
Have you read AN INTRODUCTION TO R?

?%in%

Bert Gunter
Genentech Nonclinical Statistics

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of chipmaney
> Sent: Friday, July 23, 2010 3:39 PM
> To: r-help@r-project.org
> Subject: [R] Reconciling 2 datasets
> 
> 
> I have a dataframe:
> 
> Empirical.df <- data.frame(ID=c("MCUP1-2","MCUP2-5", "MCUP3-3",
> "MCUP4-3","MCUP5-9"), Cover=c(60,40,45,68,72))
> 
> 
> However, I only want to use a subset of Cover.df for my analysis. The
> samples I want to use are:
> 
> Samples.v <- c("MCUP1-2", "MCUP4-3","MCUP5-9")
> 
> How do I use indexing Empirical.df by Samples.v to return a new dataframe
> with only the data I am interested in?
> 
> Here is what I mean:
> 
> Cover.df <- Empirical.df[???,]
> 
> returns:
> 
> Cover.df
> >> Cover.df
>IDCover
> 1 MCUP1-260
> 3 MCUP4-368
> 5 MCUP5-972
> --
> View this message in context: http://r.789695.n4.nabble.com/Reconciling-2-
> datasets-tp2300772p2300772.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] Reconciling 2 datasets

2010-07-23 Thread Jorge Ivan Velez
Try

Empirical.df[Empirical.df$ID %in% Samples.v,]

See ?"%in%" for more informartion.

HTH,
Jorge



On Fri, Jul 23, 2010 at 6:38 PM, chipmaney <> wrote:
>
> I have a dataframe:
>
> Empirical.df <- data.frame(ID=c("MCUP1-2","MCUP2-5", "MCUP3-3",
> "MCUP4-3","MCUP5-9"), Cover=c(60,40,45,68,72))
>
>
> However, I only want to use a subset of Cover.df for my analysis. The
> samples I want to use are:
>
> Samples.v <- c("MCUP1-2", "MCUP4-3","MCUP5-9")
>
> How do I use indexing Empirical.df by Samples.v to return a new dataframe
> with only the data I am interested in?
>
> Here is what I mean:
>
> Cover.df <- Empirical.df[???,]
>
> returns:
>
> Cover.df
>>> Cover.df
>       ID        Cover
> 1 MCUP1-2    60
> 3 MCUP4-3    68
> 5 MCUP5-9    72
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Reconciling-2-datasets-tp2300772p2300772.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


[R] Reconciling 2 datasets

2010-07-23 Thread chipmaney

I have a dataframe:

Empirical.df <- data.frame(ID=c("MCUP1-2","MCUP2-5", "MCUP3-3",
"MCUP4-3","MCUP5-9"), Cover=c(60,40,45,68,72))


However, I only want to use a subset of Cover.df for my analysis. The
samples I want to use are:

Samples.v <- c("MCUP1-2", "MCUP4-3","MCUP5-9")

How do I use indexing Empirical.df by Samples.v to return a new dataframe
with only the data I am interested in?

Here is what I mean:

Cover.df <- Empirical.df[???,]

returns:

Cover.df
>> Cover.df
   IDCover
1 MCUP1-260
3 MCUP4-368
5 MCUP5-972
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Reconciling-2-datasets-tp2300772p2300772.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Convert Row Names to data.frame column

2010-07-23 Thread David Winsemius


On Jul 23, 2010, at 6:18 PM, chipmaney wrote:



Here is an example dataset:

ZoneCover.df<- data.frame(Value=c(1,2))
row.names(ZoneCover.df) <- c("Floodplain1.Tree", "Floodplain1.Shrub")


I want to Export the Row.Names to a column in the dataframe:

ZoneCover.df$ID <- names(ZoneCover.df)

which yields this:


ZoneCover.df

 ValueID
Floodplain1.Tree  1  Floodplain1.Tree
Floodplain1.Shrub 2 Floodplain1.Shrub


QUESTION:

How do I remove the .Tree and .Shrub extensions from the ZoneCover$ID
values?


?gsub
?regex

(The "." character needs to be "escaped" with doubled "\" but the  
second "." is a regex for any character.)


> gsub("\\..*$","", c("Floodplain1.Tree", "Floodplain1.Shrub"))
[1] "Floodplain1" "Floodplain1"

Use the same method with assignment to the column:

ZoneCover.df$ID <-  gsub("\\..*$","", ZoneCover.df$ID)
--

David Winsemius, MD
West Hartford, CT

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


[R] Convert Row Names to data.frame column

2010-07-23 Thread chipmaney

Here is an example dataset:

ZoneCover.df<- data.frame(Value=c(1,2))
row.names(ZoneCover.df) <- c("Floodplain1.Tree", "Floodplain1.Shrub")


I want to Export the Row.Names to a column in the dataframe: 

ZoneCover.df$ID <- names(ZoneCover.df)

which yields this:

> ZoneCover.df
  ValueID
Floodplain1.Tree  1  Floodplain1.Tree
Floodplain1.Shrub 2 Floodplain1.Shrub


QUESTION:

How do I remove the .Tree and .Shrub extensions from the ZoneCover$ID
values?
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Convert-Row-Names-to-data-frame-column-tp2300758p2300758.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] re-ordering bwplot

2010-07-23 Thread Steven McKinney

Here's one way - you can reorder the levels of a factor variable by specifying
the levels the way you want them.  

> require("lattice")
Loading required package: lattice
> bwplot( conc ~ Type : Treatment, data = CO2 )
> str(CO2$Type)
 Factor w/ 2 levels "Quebec","Mississippi": 1 1 1 1 1 1 1 1 1 1 ...
> 
> str(CO2$Treatment)
 Factor w/ 2 levels "nonchilled","chilled": 1 1 1 1 1 1 1 1 1 1 ...
> ?bwplot
> CO2 <- CO2  ## Make a copy in the global environment
> CO2$Type2 <- factor(as.character(CO2$Type), levels = c("Mississippi", 
> "Quebec"))
> with(CO2, table(Type, Type2))
 Type2
Type  Mississippi Quebec
  Quebec0 42
  Mississippi  42  0
> quartz() ## Your plot window type here (quartz() works on a Mac)
> bwplot( conc ~ Type : Treatment, data = CO2 )
> quartz()
> bwplot( conc ~ Type2 : Treatment, data = CO2 )
> 

Steven McKinney

Statistician
Molecular Oncology and Breast Cancer Program
British Columbia Cancer Research Centre



From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
Eck, Bradley J [brad@mail.utexas.edu]
Sent: July 23, 2010 10:02 AM
To: r-help@r-project.org
Subject: [R] re-ordering bwplot

Dear list:

I'm using bwplot to compare concentrations by location and treatment as in:

# using built in data
bwplot( conc ~ Type : Treatment, data = CO2 )

I would like the order of the plots to be: 3,4,1,2.   I can't seem to figure 
this out with index.cond or permc.cond.

Any help is appreciated!

Brad Eck


[[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] Survival analysis MLE gives NA or enormous standard errors

2010-07-23 Thread Charles C. Berry

On Fri, 23 Jul 2010, Christopher David Desjardins wrote:


Sorry. I should have included some data. I've attached a subset of my
data (50/192) cases in a Rdata file and have pasted it below.

Running anova I get the following:


anova(sr.reg.s4.nore)

  Df Deviance Resid. Df-2*LL P(>|Chi|)
NULL   NA   NA45 33.89752NA
as.factor(lifedxm)  2 2.43821143 31.45931 0.2954943

That would just be an omnibus test right and should that first NULL NA
line be worrisome? What if I want to test specifically that CONTROL and
BIPOLAR were different and that MAJOR DEPRESSION and BIPOLAR were
different?


Construct a likelikehood ratio test for each hypothesis by fitting three 
models - two containing each term  and one containing both - and comparing 
each simpler model to the fuller model.




I'll look at Hauck-Donner effect.

Thanks,
Chris


bip.surv.s

  age_sym4 sym4 lifedxm
1  16.128680   MAJOR
2  19.326490   MAJOR
3  16.550310 CONTROL
4  19.367560 CONTROL
5  16.090350   MAJOR
6  21.505820   MAJOR
7  16.361400   MAJOR
8  20.572210   MAJOR
9  16.457220 CONTROL
10 19.945240 CONTROL
11 15.791920   MAJOR
12 20.766600   MAJOR
13 16.150580 BIPOLAR
14 19.258040 BIPOLAR
15 17.363450   MAJOR
16 21.180010   MAJOR
17   NA0 BIPOLAR
18   NA0 BIPOLAR
19 16.317591   MAJOR
20 18.297060   MAJOR
21 16.407940   MAJOR
22 19.137580   MAJOR
23 16.194390 CONTROL
24 21.368930 CONTROL
25 15.890490 CONTROL
26 18.997950 CONTROL
27   NA0 BIPOLAR
28 18.904860 BIPOLAR
29 16.364130   MAJOR
30 20.427100   MAJOR
31 16.659820   MAJOR
32 19.457910   MAJOR
33 16.643390 CONTROL
34 19.400410 CONTROL
35 15.373031 BIPOLAR
36 19.838470 BIPOLAR
37 15.422311   MAJOR
38 19.370290   MAJOR
39 15.069130   MAJOR
40 17.815200   MAJOR
41 15.504450 BIPOLAR
42 17.921970 BIPOLAR
43 15.345650 CONTROL
44 18.075290 CONTROL
45 15.594800 CONTROL
46 19.674200 CONTROL
47 14.789870   MAJOR
48 20.054760   MAJOR
49 14.787130   MAJOR
50 19.868580   MAJOR


On Fri, 2010-07-23 at 11:52 -0700, Charles C. Berry wrote:

On Fri, 23 Jul 2010, Christopher David Desjardins wrote:


Hi,
I am trying to fit the following model:

sr.reg.s4.nore <- survreg(Surv(age_sym4,sym4), as.factor(lifedxm),
data=bip.surv)


Next time include a reproducible example. i.e. something we can run.

Now, Google "Hauck Donner Effect" to understand why

anova(sr.reg.s4.nore)

is preferred.

Chuck




Where age_sym4 is the age that a subject develops clinical thought
problems; sym4 is whether they develop clinical thoughts problems (0 or
1); and lifedxm is mother's diagnosis: BIPOLAR, MAJOR DEPRESSION, or
CONTROL.

I am interested in whether or not survival differs by this covariate.

When I run my model, I am getting the following output:


summary(sr.reg.s4.nore)


Call:
survreg(formula = Surv(age_sym4, sym4) ~ as.factor(lifedxm),
   data = bip.surv)
  Value Std. Error z   p
(Intercept)4.037  0.455  8.86643
0.00755
as.factor(lifedxm)CONTROL 14.844   4707.383  0.00315
0.997484052845082791450
as.factor(lifedxm)MAJOR0.706  0.447  1.58037
0.114022774867277756905
Log(scale)-0.290  0.267 -1.08493
0.277952437474223823521

Scale= 0.748

Weibull distribution
Loglik(model)= -76.3   Loglik(intercept only)= -82.6
Chisq= 12.73 on 2 degrees of freedom, p= 0.0017
Number of Newton-Raphson Iterations: 21
n=186 (6 observations deleted due to missingness)


I am concerned about the p-value of 0.997 and the SE of 4707. I am
curious if it has to do with the fact that the CONTROL group doesn't
have a mixed response, meaning that all my subjects do not develop
clinical levels of thought problems and subsequently 'survive'.


table(bip.surv$sym4,bip.surv$lifedxm)


   BIPOLAR CONTROL MAJOR
 0  41  6078
 1   7   0 6

Is there some sort of way that I can overcome this? Is my model
misspecified? Is this better suited to be run as a Bayesian model using
priors to overcome the lack of a mixed response?

Also, please cc me on an email as I am a digest subscriber.
Thanks,
Chris


--
Christopher David Desjardins
PhD student, Quantitative Methods in Education
MS student, Statistics
University of Minnesota
192 Education Sciences Building
http://cddesjardins.wordpress.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.



Charles C. Berry(858) 534-2098
 Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://fampre

Re: [R] sparsity

2010-07-23 Thread Allan Engelhardt
The functions {summary,bandwidth}.rq() in the package quantreg looks 
promising, but it is not really my area...


http://lmgtfy.com/?q=Hall-Sheater+sparsity+%22r-project%22

Hope this helps a little.

Allan

On 23/07/10 21:02, Nathalie Gimenes wrote:

Hi All,

I would like to estimate the "sparsity function" using Hall Sheater
bandwidth.

Is there any command for this?

Thanks,

NGS

[[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] Figures in Latex

2010-07-23 Thread Felipe Carrillo
Hannah: I am not sure if this is what you
need but you can use an array to do that.
Copy and paste the below code to your latex code.

\newpage
\begin{landscape}
\begin{figure}[h]
\begin{center}$
\begin{array}{cc}
\includegraphics[width=2in]{yourgraphicname} &
\includegraphics[width=2in]{yourgraphicname} \\
\includegraphics[width=2in]{yourgraphicname} &
\includegraphics[width=2in]{yourgraphicname\\
\includegraphics[width=2in]{yourgraphicname} &
\includegraphics[width=2in]{yourgraphicname}\\
\end{array}$
\end{center}
\caption{is this what you had in mind?}
\end{figure}
\end{landscape}
 
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA



- Original Message 
> From: Kingsford Jones 
> To: li li 
> Cc: r-help 
> Sent: Fri, July 23, 2010 12:49:20 PM
> Subject: Re: [R] Figures in Latex
> 
> to make the desired within R's plotting device rather than in latex try:
> 
> par(mfrow = c(3, 2))
> 
> and you'll probably want to adjust other mar, parameters as well (e.g.
> mar, cex.lab, etc).
> 
> Or, take advantage of the flexibility offered by the graphics package
> by studying ?layout
> 
> hth,
> Kingsford
> 
> 
> 
> On Fri, Jul 23, 2010 at 7:43 AM, li li  wrote:
> > Hi all,
> >   I want to add 6 plots in the format of 2 columns and 3 rows as one
> > figure in latex. The plots are in .eps file.
> > I know how to add 2 plots side by side, but could not figure out how to do
> > multiple rows.
> >  I know this may not be the right place to ask such a question. But I do
> > not know who to ask, so just try my
> > luck here.
> >  Thank you in advance.
> >                                                      Hannah
> >
> >        [[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-help@r-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] sparsity

2010-07-23 Thread Nathalie Gimenes
Hi All,

I would like to estimate the "sparsity function" using Hall Sheater
bandwidth.

Is there any command for this?

Thanks,

NGS

[[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] Figures in Latex

2010-07-23 Thread Kingsford Jones
to make the desired within R's plotting device rather than in latex try:

par(mfrow = c(3, 2))

and you'll probably want to adjust other mar, parameters as well (e.g.
mar, cex.lab, etc).

Or, take advantage of the flexibility offered by the graphics package
by studying ?layout

hth,
Kingsford



On Fri, Jul 23, 2010 at 7:43 AM, li li  wrote:
> Hi all,
>   I want to add 6 plots in the format of 2 columns and 3 rows as one
> figure in latex. The plots are in .eps file.
> I know how to add 2 plots side by side, but could not figure out how to do
> multiple rows.
>  I know this may not be the right place to ask such a question. But I do
> not know who to ask, so just try my
> luck here.
>  Thank you in advance.
>                                                      Hannah
>
>        [[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] Survival analysis MLE gives NA or enormous standard errors

2010-07-23 Thread Christopher David Desjardins
Sorry. I should have included some data. I've attached a subset of my
data (50/192) cases in a Rdata file and have pasted it below.

Running anova I get the following:

> anova(sr.reg.s4.nore)
   Df Deviance Resid. Df-2*LL P(>|Chi|)
NULL   NA   NA45 33.89752NA
as.factor(lifedxm)  2 2.43821143 31.45931 0.2954943

That would just be an omnibus test right and should that first NULL NA
line be worrisome? What if I want to test specifically that CONTROL and
BIPOLAR were different and that MAJOR DEPRESSION and BIPOLAR were
different?

I'll look at Hauck-Donner effect.

Thanks,
Chris

> bip.surv.s
   age_sym4 sym4 lifedxm
1  16.128680   MAJOR
2  19.326490   MAJOR
3  16.550310 CONTROL
4  19.367560 CONTROL
5  16.090350   MAJOR
6  21.505820   MAJOR
7  16.361400   MAJOR
8  20.572210   MAJOR
9  16.457220 CONTROL
10 19.945240 CONTROL
11 15.791920   MAJOR
12 20.766600   MAJOR
13 16.150580 BIPOLAR
14 19.258040 BIPOLAR
15 17.363450   MAJOR
16 21.180010   MAJOR
17   NA0 BIPOLAR
18   NA0 BIPOLAR
19 16.317591   MAJOR
20 18.297060   MAJOR
21 16.407940   MAJOR
22 19.137580   MAJOR
23 16.194390 CONTROL
24 21.368930 CONTROL
25 15.890490 CONTROL
26 18.997950 CONTROL
27   NA0 BIPOLAR
28 18.904860 BIPOLAR
29 16.364130   MAJOR
30 20.427100   MAJOR
31 16.659820   MAJOR
32 19.457910   MAJOR
33 16.643390 CONTROL
34 19.400410 CONTROL
35 15.373031 BIPOLAR
36 19.838470 BIPOLAR
37 15.422311   MAJOR
38 19.370290   MAJOR
39 15.069130   MAJOR
40 17.815200   MAJOR
41 15.504450 BIPOLAR
42 17.921970 BIPOLAR
43 15.345650 CONTROL
44 18.075290 CONTROL
45 15.594800 CONTROL
46 19.674200 CONTROL
47 14.789870   MAJOR
48 20.054760   MAJOR
49 14.787130   MAJOR
50 19.868580   MAJOR


On Fri, 2010-07-23 at 11:52 -0700, Charles C. Berry wrote:
> On Fri, 23 Jul 2010, Christopher David Desjardins wrote:
> 
> > Hi,
> > I am trying to fit the following model:
> >
> > sr.reg.s4.nore <- survreg(Surv(age_sym4,sym4), as.factor(lifedxm),
> > data=bip.surv)
> 
> Next time include a reproducible example. i.e. something we can run.
> 
> Now, Google "Hauck Donner Effect" to understand why
> 
>   anova(sr.reg.s4.nore)
> 
> is preferred.
> 
> Chuck
> 
> 
> >
> > Where age_sym4 is the age that a subject develops clinical thought
> > problems; sym4 is whether they develop clinical thoughts problems (0 or
> > 1); and lifedxm is mother's diagnosis: BIPOLAR, MAJOR DEPRESSION, or
> > CONTROL.
> >
> > I am interested in whether or not survival differs by this covariate.
> >
> > When I run my model, I am getting the following output:
> >
> >> summary(sr.reg.s4.nore)
> >
> > Call:
> > survreg(formula = Surv(age_sym4, sym4) ~ as.factor(lifedxm),
> >data = bip.surv)
> >   Value Std. Error z   p
> > (Intercept)4.037  0.455  8.86643
> > 0.00755
> > as.factor(lifedxm)CONTROL 14.844   4707.383  0.00315
> > 0.997484052845082791450
> > as.factor(lifedxm)MAJOR0.706  0.447  1.58037
> > 0.114022774867277756905
> > Log(scale)-0.290  0.267 -1.08493
> > 0.277952437474223823521
> >
> > Scale= 0.748
> >
> > Weibull distribution
> > Loglik(model)= -76.3   Loglik(intercept only)= -82.6
> > Chisq= 12.73 on 2 degrees of freedom, p= 0.0017
> > Number of Newton-Raphson Iterations: 21
> > n=186 (6 observations deleted due to missingness)
> >
> >
> > I am concerned about the p-value of 0.997 and the SE of 4707. I am
> > curious if it has to do with the fact that the CONTROL group doesn't
> > have a mixed response, meaning that all my subjects do not develop
> > clinical levels of thought problems and subsequently 'survive'.
> >
> >> table(bip.surv$sym4,bip.surv$lifedxm)
> >
> >BIPOLAR CONTROL MAJOR
> >  0  41  6078
> >  1   7   0 6
> >
> > Is there some sort of way that I can overcome this? Is my model
> > misspecified? Is this better suited to be run as a Bayesian model using
> > priors to overcome the lack of a mixed response?
> >
> > Also, please cc me on an email as I am a digest subscriber.
> > Thanks,
> > Chris
> >
> >
> > -- 
> > Christopher David Desjardins
> > PhD student, Quantitative Methods in Education
> > MS student, Statistics
> > University of Minnesota
> > 192 Education Sciences Building
> > http://cddesjardins.wordpress.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.
> >
> 
> Charles C. Berry(858) 534-2098
>  Dept of Family/Preventive 
> Medicine
> E mailto:cbe...@tajo.u

Re: [R] Tutorial Tinn-R

2010-07-23 Thread Kingsford Jones
I found the user guide available at Help > Main > User Guide > Html to
be quite useful for getting started.  I don't think this was available
when first I looked at Tinn-R a couple years ago, at which point I too
felt the help files were very poor.  But under 2.3.5.2 the file is
there, and Tinn-R is now my favorite interface to R under Windows.
Yesterday I used the document comparison tool for the first time
(Tools > Differences) ...very nice.

Kingsford Jones

On Fri, Jul 23, 2010 at 10:55 AM, Bert Gunter  wrote:
> Google on "tinn-r tutorial." However, I believe that you will find that the
> answer is no, there isn't anything useful out there. Moreover, TINN-R's help
> files are minimal and terrible, even though the package itself is quite
> useful (I find). Please Do NOT post further TINN-R questions to this list --
> it is for R, not TINN-R. Perhaps someone will be able to tell you where to
> post TINN-R questions. I just had to struggle to figure it out and get it
> set up; but I use it all the time as a pseudo- IDE.
>
> Bert Gunter
> Genentech Nonclinical Statistics
>
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
>> On Behalf Of suse
>> Sent: Friday, July 23, 2010 9:44 AM
>> To: r-help@r-project.org
>> Subject: [R] Tutorial Tinn-R
>>
>>
>> Hi,
>>
>> does anyone know a tutorial for Tinn-R? During all my search I only found
>> R-Tutorials...
>> The problem now is: I would like to make Tinn-R an autosave. But since I
>> had
>> several questions before concerning Tinn-R (for example, how to have Tinn-
>> R
>> and R in one window or how do the new versions work), I think it is easier
>> to have a tutorial instead of asking here everything.
>>
>> Thank you!
>> --
>> View this message in context: http://r.789695.n4.nabble.com/Tutorial-Tinn-
>> R-tp2300451p2300451.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-
>> guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] Survival analysis MLE gives NA or enormous standard errors

2010-07-23 Thread Charles C. Berry

On Fri, 23 Jul 2010, Christopher David Desjardins wrote:


Hi,
I am trying to fit the following model:

sr.reg.s4.nore <- survreg(Surv(age_sym4,sym4), as.factor(lifedxm),
data=bip.surv)


Next time include a reproducible example. i.e. something we can run.

Now, Google "Hauck Donner Effect" to understand why

anova(sr.reg.s4.nore)

is preferred.

Chuck




Where age_sym4 is the age that a subject develops clinical thought
problems; sym4 is whether they develop clinical thoughts problems (0 or
1); and lifedxm is mother's diagnosis: BIPOLAR, MAJOR DEPRESSION, or
CONTROL.

I am interested in whether or not survival differs by this covariate.

When I run my model, I am getting the following output:


summary(sr.reg.s4.nore)


Call:
survreg(formula = Surv(age_sym4, sym4) ~ as.factor(lifedxm),
   data = bip.surv)
  Value Std. Error z   p
(Intercept)4.037  0.455  8.86643
0.00755
as.factor(lifedxm)CONTROL 14.844   4707.383  0.00315
0.997484052845082791450
as.factor(lifedxm)MAJOR0.706  0.447  1.58037
0.114022774867277756905
Log(scale)-0.290  0.267 -1.08493
0.277952437474223823521

Scale= 0.748

Weibull distribution
Loglik(model)= -76.3   Loglik(intercept only)= -82.6
Chisq= 12.73 on 2 degrees of freedom, p= 0.0017
Number of Newton-Raphson Iterations: 21
n=186 (6 observations deleted due to missingness)


I am concerned about the p-value of 0.997 and the SE of 4707. I am
curious if it has to do with the fact that the CONTROL group doesn't
have a mixed response, meaning that all my subjects do not develop
clinical levels of thought problems and subsequently 'survive'.


table(bip.surv$sym4,bip.surv$lifedxm)


   BIPOLAR CONTROL MAJOR
 0  41  6078
 1   7   0 6

Is there some sort of way that I can overcome this? Is my model
misspecified? Is this better suited to be run as a Bayesian model using
priors to overcome the lack of a mixed response?

Also, please cc me on an email as I am a digest subscriber.
Thanks,
Chris


--
Christopher David Desjardins
PhD student, Quantitative Methods in Education
MS student, Statistics
University of Minnesota
192 Education Sciences Building
http://cddesjardins.wordpress.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.



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
R-help@r-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] Figures in Latex

2010-07-23 Thread Saeed Abu Nimeh
http://nixtricks.wordpress.com/2009/11/09/latex-multiple-figures-under-the-same-caption-using-subfigure/
"It will create two rows of subfigures with two subfigures on each row"

On Fri, Jul 23, 2010 at 6:43 AM, li li  wrote:
> Hi all,
>   I want to add 6 plots in the format of 2 columns and 3 rows as one
> figure in latex. The plots are in .eps file.
> I know how to add 2 plots side by side, but could not figure out how to do
> multiple rows.
>  I know this may not be the right place to ask such a question. But I do
> not know who to ask, so just try my
> luck here.
>  Thank you in advance.
>                                                      Hannah
>
>        [[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] Error produced by read.zoo: "bad entries"

2010-07-23 Thread Gabor Grothendieck
On Fri, Jul 23, 2010 at 2:07 PM, Dimitri Liakhovitski
 wrote:
> David/Gabor,
>
> you helped me a lot.
> Gabor - I've run table(OrigData$Month) - and it looked weird.
> I went back to my file and changed the format of the date (Month) in
> Excel. I have no idea what it does - but after I saved it again, it
> worked.
> Thanks a lot!
>
> I'll open another thread where I'll ask how to best save dates in
> Excel if one saves them as .csv.
>
> Dimitri

Try out the various packages listed on this page:

   http://rwiki.sciviews.org/doku.php?id=tips:data-io:ms_windows

which directly read Excel files.  Hopefully at least one of these
packages will be able to handle the dates independently of the format
you use for them.

__
R-help@r-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 produced by read.zoo: "bad entries"

2010-07-23 Thread Dimitri Liakhovitski
David/Gabor,

you helped me a lot.
Gabor - I've run table(OrigData$Month) - and it looked weird.
I went back to my file and changed the format of the date (Month) in
Excel. I have no idea what it does - but after I saved it again, it
worked.
Thanks a lot!

I'll open another thread where I'll ask how to best save dates in
Excel if one saves them as .csv.

Dimitri


On Fri, Jul 23, 2010 at 2:00 PM, David Winsemius  wrote:
>
> On Jul 23, 2010, at 1:50 PM, Dimitri Liakhovitski wrote:
>
>> I am expecting to see the week names as row labels of z and the
>> corresponding values (like in the "monthly" example). I am pretty sure
>> - in order to get it one needs to install the latest version of zoo.
>> I've done it just a couple of days ago.
>> I am getting the error - and nothing is produced. Can it have to do
>> with the fact that I am using the newer version of zoo?
>> Again, my full code for that OrigData.csv file I sent is:
>
> Yep, updating to the current version of zoo on CRAN, zoo_1.6-4, now produces
> an error where before with the penultimate version, zoo_1.6-3, it did not.
>
> --
> David.
>>
>> OrigData<-read.csv("OrigData.csv")
>> OrigData$Month<-as.character(OrigData$Month)
>> OrigData$Month<-as.Date(OrigData$Month,"%m/%d/%y")
>> str(OrigData)
>>
>> 'data.frame':   440 obs. of  3 variables:
>> $ Brand: Factor w/ 11 levels " Plus","agrow",..: 2 2 2 2 2 2 2 2 2 2 ...
>> $ Month:Class 'Date'  num [1:440] 18262 18293 18322 18353 18383 ...
>> $ Value: int  NA NA NA 100 100 100 100 100 100 99 ...
>>
>> library(zoo)
>> z <- read.zoo(OrigData, index.column = 2, split = "Brand")
>>
>> Error in merge.zoo(` Plus` = c(NA, 98L, 95L, 97L, NA, 98L, 97L, 98L, NA,
>>  :
>>  series cannot be merged with non-unique index entries in a series
>> In addition: There were 11 warnings (use warnings() to see them)
>>
>> warnings()
>> Warning messages:
>> 1: In zoo(rval4[[i]], ix[[i]]) :
>>  some methods for “zoo” objects do not work if the index entries in
>> ‘order.by’ are not unique
>> 2: In zoo(rval4[[i]], ix[[i]]) :
>>  some methods for “zoo” objects do not work if the index entries in
>> ‘order.by’ are not unique
>> 3: In zoo(rval4[[i]], ix[[i]]) :
>> etc.
>>
>> But it does not give me this error for my Monthly example - even when
>> I introduce a few NAs there.
>>
>>
>> And I get this message:
>> Error in merge.zoo(` Plus` = c(NA, 98L, 95L, 97L, NA, 98L, 97L, 98L, NA,
>>  :
>>  series cannot be merged with non-unique index entries in a series
>> In addition: There were 11 warnings (use warnings() to see them)
>>
>>
>> On Fri, Jul 23, 2010 at 1:41 PM, David Winsemius 
>> wrote:
>>>
>>> On Jul 23, 2010, at 1:39 PM, Dimitri Liakhovitski wrote:
>>>
 Very sorry - I mistunderstood and confused split with index.column -
 totally my fault.
 Ok, now I've run this line:

 z <- read.zoo(OrigData, index.column = 2, split = "Brand")

 And I am getting:
 Error in merge.zoo(` Plus` = c(NA, 98L, 95L, 97L, NA, 98L, 97L, 98L, NA,
  :
  series cannot be merged with non-unique index entries in a series
 In addition: There were 11 warnings (use warnings() to see them)
>>>
>>> I got the warnings but no error:
>>>
 z <- read.zoo(OrigData, split = "Brand", index.column=2)
>>>
>>> There were 11 warnings (use warnings() to see them)

 z
>>>
>>>      Plus agrow chool gress Grib inKid kid omis plet pro romil
>>>  [1,]    NA    NA    NA    NA   NA    NA  NA   NA   NA  NA    NA
>>>  [2,]    98    99    98    97   96    96 100   97   97  99    96
>>>  [3,]    95   100    97    99   92    97 100   97   99 100    99
>>>  [4,]    97    99    94    98   91    95  99   98   98  99    95
>>>  [5,]    NA    NA    NA    NA   NA    NA  NA   NA   NA  NA    NA
>>>  [6,]    98    99    98    97   93    96  99   97   98  99    96
>>>  [7,]    97   100    98    98   95    96  99   98   98 100    97
>>>  [8,]    98    99    94    99   96    96  99   98   98  99    97
>>>  [9,]    NA    NA    NA    NA   NA    NA  NA   NA   NA  NA    NA
>>> [10,]    98    99    98    98   95    96  99   98   98  99    97
>>> [11,]    98    99    98    99   97    96  99   98   97  99    99
>>> [12,]    97   100    96    99   95    95  99   99   97 100    96
>>> [13,]    96   100    96    96   93     0 100   96   97 100    96
>>> [14,]    98    99    98   100   94    96 100   98   97  99    99
>>> [15,]    95   100    98    99   93    95  99   99   99  99    99
>>> [16,]    97    99    96    99   94    95  98   98   90  99    95
>>> [17,]    97   100    97    96   92     0 100   96   98 100    95
>>> [18,]    96    99    98    98   96    97 100   98   99  98    98
>>> [19,]    98   100    98    98   96    97  99   98   99  99    98
>>> [20,]    98   100    97    96   95     0 100   96   98  99    96
>>> [21,]    94   100    98    99   92    97  99   98   98  98    98
>>> [22,]    98    99    98    97   96    96  99   97   98  99    97
>>> [23,]    97   100    96    96   93     0 100   95   97 100    95
>>> [24,]    97   100    98   

Re: [R] Error produced by read.zoo: "bad entries"

2010-07-23 Thread David Winsemius


On Jul 23, 2010, at 1:50 PM, Dimitri Liakhovitski wrote:


I am expecting to see the week names as row labels of z and the
corresponding values (like in the "monthly" example). I am pretty sure
- in order to get it one needs to install the latest version of zoo.
I've done it just a couple of days ago.
I am getting the error - and nothing is produced. Can it have to do
with the fact that I am using the newer version of zoo?
Again, my full code for that OrigData.csv file I sent is:


Yep, updating to the current version of zoo on CRAN, zoo_1.6-4, now  
produces an error where before with the penultimate version,  
zoo_1.6-3, it did not.


--
David.


OrigData<-read.csv("OrigData.csv")
OrigData$Month<-as.character(OrigData$Month)
OrigData$Month<-as.Date(OrigData$Month,"%m/%d/%y")
str(OrigData)

'data.frame':   440 obs. of  3 variables:
$ Brand: Factor w/ 11 levels " Plus","agrow",..: 2 2 2 2 2 2 2 2 2  
2 ...

$ Month:Class 'Date'  num [1:440] 18262 18293 18322 18353 18383 ...
$ Value: int  NA NA NA 100 100 100 100 100 100 99 ...

library(zoo)
z <- read.zoo(OrigData, index.column = 2, split = "Brand")

Error in merge.zoo(` Plus` = c(NA, 98L, 95L, 97L, NA, 98L, 97L, 98L,  
NA,  :

 series cannot be merged with non-unique index entries in a series
In addition: There were 11 warnings (use warnings() to see them)

warnings()
Warning messages:
1: In zoo(rval4[[i]], ix[[i]]) :
 some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique
2: In zoo(rval4[[i]], ix[[i]]) :
 some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique
3: In zoo(rval4[[i]], ix[[i]]) :
etc.

But it does not give me this error for my Monthly example - even when
I introduce a few NAs there.


And I get this message:
Error in merge.zoo(` Plus` = c(NA, 98L, 95L, 97L, NA, 98L, 97L, 98L,  
NA,  :

 series cannot be merged with non-unique index entries in a series
In addition: There were 11 warnings (use warnings() to see them)


On Fri, Jul 23, 2010 at 1:41 PM, David Winsemius > wrote:


On Jul 23, 2010, at 1:39 PM, Dimitri Liakhovitski wrote:


Very sorry - I mistunderstood and confused split with index.column -
totally my fault.
Ok, now I've run this line:

z <- read.zoo(OrigData, index.column = 2, split = "Brand")

And I am getting:
Error in merge.zoo(` Plus` = c(NA, 98L, 95L, 97L, NA, 98L, 97L,  
98L, NA,

 :
 series cannot be merged with non-unique index entries in a series
In addition: There were 11 warnings (use warnings() to see them)


I got the warnings but no error:


z <- read.zoo(OrigData, split = "Brand", index.column=2)

There were 11 warnings (use warnings() to see them)

z

  Plus agrow chool gress Grib inKid kid omis plet pro romil
 [1,]NANANANA   NANA  NA   NA   NA  NANA
 [2,]98999897   9696 100   97   97  9996
 [3,]95   1009799   9297 100   97   99 10099
 [4,]97999498   9195  99   98   98  9995
 [5,]NANANANA   NANA  NA   NA   NA  NANA
 [6,]98999897   9396  99   97   98  9996
 [7,]97   1009898   9596  99   98   98 10097
 [8,]98999499   9696  99   98   98  9997
 [9,]NANANANA   NANA  NA   NA   NA  NANA
[10,]98999898   9596  99   98   98  9997
[11,]98999899   9796  99   98   97  9999
[12,]97   1009699   9595  99   99   97 10096
[13,]96   1009696   93 0 100   96   97 10096
[14,]989998   100   9496 100   98   97  9999
[15,]95   1009899   9395  99   99   99  9999
[16,]97999699   9495  98   98   90  9995
[17,]97   1009796   92 0 100   96   98 10095
[18,]96999898   9697 100   98   99  9898
[19,]98   1009898   9697  99   98   99  9998
[20,]98   1009796   95 0 100   96   98  9996
[21,]94   1009899   9297  99   98   98  9898
[22,]98999897   9696  99   97   98  9997
[23,]97   1009696   93 0 100   95   97 10095
[24,]97   1009897   9396  99   97   98  9795
[25,]98   1009697   9694 100   97   99  9996
[26,]98   1009896   95 0 100   96   98  9995
[27,]98   1009897   9396  96   97   98  9999
[28,]99   1009898   9296 100   98   99  9997
[29,]98   1009795   95 0 100   95   98  9995
[30,]99   10098   100   9898  99  100   99 10099
[31,]97999497   9595  99   97   98  9894
[32,]98999896   95 3 100   96   97  9996
[33,]97999899   9797  99   99   99  9999
[34,]96999596   9494  98   96   96  9893
[35,]98999897   9454 100   97   97  99 

Re: [R] re-ordering bwplot

2010-07-23 Thread Peter Ehlers

On 2010-07-23 11:36, Deepayan Sarkar wrote:

On Fri, Jul 23, 2010 at 10:02 AM, Eck, Bradley J
  wrote:

Dear list:

I'm using bwplot to compare concentrations by location and treatment as in:

# using built in data
bwplot( conc ~ Type : Treatment, data = CO2 )

I would like the order of the plots to be: 3,4,1,2. Â  I can't seem to figure 
this out with index.cond or permc.cond.

Any help is appreciated!


I think the only way is to

(1) explicitly create the interaction variable

(2) re-create the factor using factor() with your desired levels

This should be done before the bwplot() call.

-Deepayan


Deepayan's suggestion is the way to go. But in this
simple example you can just relevel the factors:

 bwplot( conc ~ relevel(Type, ref=2) : Treatment, data = CO2 )

and/or relevel 'Treatment'. This is only trivially
different from applying relevel() before calling bwplot().

(BTW: is your ":" meant to be "|"?)

  -Peter Ehlers

__
R-help@r-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] Survival analysis MLE gives NA or enormous standard errors

2010-07-23 Thread Christopher David Desjardins
Hi,
I am trying to fit the following model:   
 
sr.reg.s4.nore <- survreg(Surv(age_sym4,sym4), as.factor(lifedxm),
data=bip.surv)

Where age_sym4 is the age that a subject develops clinical thought
problems; sym4 is whether they develop clinical thoughts problems (0 or
1); and lifedxm is mother's diagnosis: BIPOLAR, MAJOR DEPRESSION, or
CONTROL.

I am interested in whether or not survival differs by this covariate.

When I run my model, I am getting the following output:

> summary(sr.reg.s4.nore)

Call:
survreg(formula = Surv(age_sym4, sym4) ~ as.factor(lifedxm), 
data = bip.surv)
   Value Std. Error z   p
(Intercept)4.037  0.455  8.86643
0.00755
as.factor(lifedxm)CONTROL 14.844   4707.383  0.00315
0.997484052845082791450
as.factor(lifedxm)MAJOR0.706  0.447  1.58037
0.114022774867277756905
Log(scale)-0.290  0.267 -1.08493
0.277952437474223823521

Scale= 0.748 

Weibull distribution
Loglik(model)= -76.3   Loglik(intercept only)= -82.6
Chisq= 12.73 on 2 degrees of freedom, p= 0.0017 
Number of Newton-Raphson Iterations: 21 
n=186 (6 observations deleted due to missingness)


I am concerned about the p-value of 0.997 and the SE of 4707. I am
curious if it has to do with the fact that the CONTROL group doesn't
have a mixed response, meaning that all my subjects do not develop
clinical levels of thought problems and subsequently 'survive'.

> table(bip.surv$sym4,bip.surv$lifedxm)
   
BIPOLAR CONTROL MAJOR
  0  41  6078
  1   7   0 6

Is there some sort of way that I can overcome this? Is my model
misspecified? Is this better suited to be run as a Bayesian model using
priors to overcome the lack of a mixed response?

Also, please cc me on an email as I am a digest subscriber.
Thanks,
Chris


-- 
Christopher David Desjardins
PhD student, Quantitative Methods in Education
MS student, Statistics
University of Minnesota
192 Education Sciences Building
http://cddesjardins.wordpress.com

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


Re: [R] Error produced by read.zoo: "bad entries"

2010-07-23 Thread Gabor Grothendieck
On Fri, Jul 23, 2010 at 1:39 PM, Dimitri Liakhovitski
 wrote:
> Very sorry - I mistunderstood and confused split with index.column -
> totally my fault.
> Ok, now I've run this line:
>
> z <- read.zoo(OrigData, index.column = 2, split = "Brand")
>
> And I am getting:
> Error in merge.zoo(` Plus` = c(NA, 98L, 95L, 97L, NA, 98L, 97L, 98L, NA,  :
>  series cannot be merged with non-unique index entries in a series
> In addition: There were 11 warnings (use warnings() to see them)
>
> And under warnings() it says:
> 1: In zoo(rval4[[i]], ix[[i]]) :
>  some methods for “zoo” objects do not work if the index entries in
> ‘order.by’ are not unique
>

There may be something wrong with the data.  The warning is an alert
to the fact that we have at least one brand for which there are
duplicate dates.  One would have expected that dates are unique within
brand (or if its ok to have duplicate dates within brand then they
should be aggregated as they are read them in using the aggregate=
argument of read.zoo) .

__
R-help@r-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 produced by read.zoo: "bad entries"

2010-07-23 Thread Dimitri Liakhovitski
I am expecting to see the week names as row labels of z and the
corresponding values (like in the "monthly" example). I am pretty sure
- in order to get it one needs to install the latest version of zoo.
I've done it just a couple of days ago.
I am getting the error - and nothing is produced. Can it have to do
with the fact that I am using the newer version of zoo?
Again, my full code for that OrigData.csv file I sent is:

OrigData<-read.csv("OrigData.csv")
OrigData$Month<-as.character(OrigData$Month)
OrigData$Month<-as.Date(OrigData$Month,"%m/%d/%y")
str(OrigData)

'data.frame':   440 obs. of  3 variables:
 $ Brand: Factor w/ 11 levels " Plus","agrow",..: 2 2 2 2 2 2 2 2 2 2 ...
 $ Month:Class 'Date'  num [1:440] 18262 18293 18322 18353 18383 ...
 $ Value: int  NA NA NA 100 100 100 100 100 100 99 ...

library(zoo)
z <- read.zoo(OrigData, index.column = 2, split = "Brand")

Error in merge.zoo(` Plus` = c(NA, 98L, 95L, 97L, NA, 98L, 97L, 98L, NA,  :
  series cannot be merged with non-unique index entries in a series
In addition: There were 11 warnings (use warnings() to see them)

warnings()
Warning messages:
1: In zoo(rval4[[i]], ix[[i]]) :
  some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique
2: In zoo(rval4[[i]], ix[[i]]) :
  some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique
3: In zoo(rval4[[i]], ix[[i]]) :
etc.

But it does not give me this error for my Monthly example - even when
I introduce a few NAs there.


And I get this message:
Error in merge.zoo(` Plus` = c(NA, 98L, 95L, 97L, NA, 98L, 97L, 98L, NA,  :
  series cannot be merged with non-unique index entries in a series
In addition: There were 11 warnings (use warnings() to see them)


On Fri, Jul 23, 2010 at 1:41 PM, David Winsemius  wrote:
>
> On Jul 23, 2010, at 1:39 PM, Dimitri Liakhovitski wrote:
>
>> Very sorry - I mistunderstood and confused split with index.column -
>> totally my fault.
>> Ok, now I've run this line:
>>
>> z <- read.zoo(OrigData, index.column = 2, split = "Brand")
>>
>> And I am getting:
>> Error in merge.zoo(` Plus` = c(NA, 98L, 95L, 97L, NA, 98L, 97L, 98L, NA,
>>  :
>>  series cannot be merged with non-unique index entries in a series
>> In addition: There were 11 warnings (use warnings() to see them)
>
> I got the warnings but no error:
>
>> z <- read.zoo(OrigData, split = "Brand", index.column=2)
> There were 11 warnings (use warnings() to see them)
>> z
>       Plus agrow chool gress Grib inKid kid omis plet pro romil
>  [1,]    NA    NA    NA    NA   NA    NA  NA   NA   NA  NA    NA
>  [2,]    98    99    98    97   96    96 100   97   97  99    96
>  [3,]    95   100    97    99   92    97 100   97   99 100    99
>  [4,]    97    99    94    98   91    95  99   98   98  99    95
>  [5,]    NA    NA    NA    NA   NA    NA  NA   NA   NA  NA    NA
>  [6,]    98    99    98    97   93    96  99   97   98  99    96
>  [7,]    97   100    98    98   95    96  99   98   98 100    97
>  [8,]    98    99    94    99   96    96  99   98   98  99    97
>  [9,]    NA    NA    NA    NA   NA    NA  NA   NA   NA  NA    NA
> [10,]    98    99    98    98   95    96  99   98   98  99    97
> [11,]    98    99    98    99   97    96  99   98   97  99    99
> [12,]    97   100    96    99   95    95  99   99   97 100    96
> [13,]    96   100    96    96   93     0 100   96   97 100    96
> [14,]    98    99    98   100   94    96 100   98   97  99    99
> [15,]    95   100    98    99   93    95  99   99   99  99    99
> [16,]    97    99    96    99   94    95  98   98   90  99    95
> [17,]    97   100    97    96   92     0 100   96   98 100    95
> [18,]    96    99    98    98   96    97 100   98   99  98    98
> [19,]    98   100    98    98   96    97  99   98   99  99    98
> [20,]    98   100    97    96   95     0 100   96   98  99    96
> [21,]    94   100    98    99   92    97  99   98   98  98    98
> [22,]    98    99    98    97   96    96  99   97   98  99    97
> [23,]    97   100    96    96   93     0 100   95   97 100    95
> [24,]    97   100    98    97   93    96  99   97   98  97    95
> [25,]    98   100    96    97   96    94 100   97   99  99    96
> [26,]    98   100    98    96   95     0 100   96   98  99    95
> [27,]    98   100    98    97   93    96  96   97   98  99    99
> [28,]    99   100    98    98   92    96 100   98   99  99    97
> [29,]    98   100    97    95   95     0 100   95   98  99    95
> [30,]    99   100    98   100   98    98  99  100   99 100    99
> [31,]    97    99    94    97   95    95  99   97   98  98    94
> [32,]    98    99    98    96   95     3 100   96   97  99    96
> [33,]    97    99    98    99   97    97  99   99   99  99    99
> [34,]    96    99    95    96   94    94  98   96   96  98    93
> [35,]    98    99    98    97   94    54 100   97   97  99    96
> [36,]    95   100    97    99   95    95  99   99   98 100    99
> [37,]    98    99    98    98   95    96  99   98  

Re: [R] Error produced by read.zoo: "bad entries"

2010-07-23 Thread David Winsemius


On Jul 23, 2010, at 1:39 PM, Dimitri Liakhovitski wrote:


Very sorry - I mistunderstood and confused split with index.column -
totally my fault.
Ok, now I've run this line:

z <- read.zoo(OrigData, index.column = 2, split = "Brand")

And I am getting:
Error in merge.zoo(` Plus` = c(NA, 98L, 95L, 97L, NA, 98L, 97L, 98L,  
NA,  :

 series cannot be merged with non-unique index entries in a series
In addition: There were 11 warnings (use warnings() to see them)


I got the warnings but no error:

> z <- read.zoo(OrigData, split = "Brand", index.column=2)
There were 11 warnings (use warnings() to see them)
> z
   Plus agrow chool gress Grib inKid kid omis plet pro romil
 [1,]NANANANA   NANA  NA   NA   NA  NANA
 [2,]98999897   9696 100   97   97  9996
 [3,]95   1009799   9297 100   97   99 10099
 [4,]97999498   9195  99   98   98  9995
 [5,]NANANANA   NANA  NA   NA   NA  NANA
 [6,]98999897   9396  99   97   98  9996
 [7,]97   1009898   9596  99   98   98 10097
 [8,]98999499   9696  99   98   98  9997
 [9,]NANANANA   NANA  NA   NA   NA  NANA
[10,]98999898   9596  99   98   98  9997
[11,]98999899   9796  99   98   97  9999
[12,]97   1009699   9595  99   99   97 10096
[13,]96   1009696   93 0 100   96   97 10096
[14,]989998   100   9496 100   98   97  9999
[15,]95   1009899   9395  99   99   99  9999
[16,]97999699   9495  98   98   90  9995
[17,]97   1009796   92 0 100   96   98 10095
[18,]96999898   9697 100   98   99  9898
[19,]98   1009898   9697  99   98   99  9998
[20,]98   1009796   95 0 100   96   98  9996
[21,]94   1009899   9297  99   98   98  9898
[22,]98999897   9696  99   97   98  9997
[23,]97   1009696   93 0 100   95   97 10095
[24,]97   1009897   9396  99   97   98  9795
[25,]98   1009697   9694 100   97   99  9996
[26,]98   1009896   95 0 100   96   98  9995
[27,]98   1009897   9396  96   97   98  9999
[28,]99   1009898   9296 100   98   99  9997
[29,]98   1009795   95 0 100   95   98  9995
[30,]99   10098   100   9898  99  100   99 10099
[31,]97999497   9595  99   97   98  9894
[32,]98999896   95 3 100   96   97  9996
[33,]97999899   9797  99   99   99  9999
[34,]96999596   9494  98   96   96  9893
[35,]98999897   9454 100   97   97  9996
[36,]95   1009799   9595  99   99   98 10099
[37,]98999898   9596  99   98   99  9997
[38,]98999897   9694 100   97   97  9896
[39,]95   10098   100   9597 100   99   99 10099
[40,]97   1009598   9396  99   98   98  9996

Since you didn't say what was expected, I am not in a position to know  
if this is success.




And under warnings() it says:
1: In zoo(rval4[[i]], ix[[i]]) :
 some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique



On Fri, Jul 23, 2010 at 1:13 PM, David Winsemius > wrote:

But, but, but Did you read my message about the need to correctly
specify index columns?


The problem is that read.zoo is reading your first column as an  
index and

it's actually the second column that should be used for that purpose.
--
David.

On Jul 23, 2010, at 1:01 PM, Dimitri Liakhovitski wrote:

Strange, I did attach. Attaching again. Maybe the file just  
doesn't go

through?
I have:

names(OrigData):
[1] "Brand" "Month" "Value"

I read ?read.zoo
According to that index should be the column number.
I thought it should be split = 1 in my case - because I am  
splitting by

Brand.
But neither split = 1 nor split =2 work.
And split ="Brand" does not work either. Why?

D.

On Fri, Jul 23, 2010 at 12:52 PM, David Winsemius
 wrote:


?read.zoo

You didn't specify the index column correctly.
On Jul 23, 2010, at 12:36 PM, Dimitri Liakhovitski wrote:


Hello!

I have a data set similar to the data set "monthly" in the example
below:



monthly<- 
data 
.frame 
(month 
= 
c 
(20090301,20090401,20090501,20100301,20100401,20090301,20090401,20090501,20100301,20100401 
),monthly 
.value=c(100,200,300,101,201,10,20,30,11,21),market=c("Market
A","Market A", "Market A","Market A", "Market A","Market B",  
"Market

B","Market B","Market B", "Market B"))
monthly$month<-as.character(monthly$month)
monthly$month<-as.Date(monthly$month,"%Y%m%d")
(monthly)
str(monthly)


I am trying to

Re: [R] Error produced by read.zoo: "bad entries"

2010-07-23 Thread Dimitri Liakhovitski
Very sorry - I mistunderstood and confused split with index.column -
totally my fault.
Ok, now I've run this line:

z <- read.zoo(OrigData, index.column = 2, split = "Brand")

And I am getting:
Error in merge.zoo(` Plus` = c(NA, 98L, 95L, 97L, NA, 98L, 97L, 98L, NA,  :
  series cannot be merged with non-unique index entries in a series
In addition: There were 11 warnings (use warnings() to see them)

And under warnings() it says:
1: In zoo(rval4[[i]], ix[[i]]) :
  some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique



On Fri, Jul 23, 2010 at 1:13 PM, David Winsemius  wrote:
> But, but, but Did you read my message about the need to correctly
> specify index columns?
>
>
> The problem is that read.zoo is reading your first column as an index and
> it's actually the second column that should be used for that purpose.
> --
> David.
>
> On Jul 23, 2010, at 1:01 PM, Dimitri Liakhovitski wrote:
>
>> Strange, I did attach. Attaching again. Maybe the file just doesn't go
>> through?
>> I have:
>>
>> names(OrigData):
>> [1] "Brand" "Month" "Value"
>>
>> I read ?read.zoo
>> According to that index should be the column number.
>> I thought it should be split = 1 in my case - because I am splitting by
>> Brand.
>> But neither split = 1 nor split =2 work.
>> And split ="Brand" does not work either. Why?
>>
>> D.
>>
>> On Fri, Jul 23, 2010 at 12:52 PM, David Winsemius
>>  wrote:
>>>
>>> ?read.zoo
>>>
>>> You didn't specify the index column correctly.
>>> On Jul 23, 2010, at 12:36 PM, Dimitri Liakhovitski wrote:
>>>
 Hello!

 I have a data set similar to the data set "monthly" in the example
 below:



 monthly<-data.frame(month=c(20090301,20090401,20090501,20100301,20100401,20090301,20090401,20090501,20100301,20100401),monthly.value=c(100,200,300,101,201,10,20,30,11,21),market=c("Market
 A","Market A", "Market A","Market A", "Market A","Market B", "Market
 B","Market B","Market B", "Market B"))
 monthly$month<-as.character(monthly$month)
 monthly$month<-as.Date(monthly$month,"%Y%m%d")
 (monthly)
 str(monthly)


 I am trying to use read.zoo - like in 3 lines below:
 library(zoo)
 z <- read.zoo(monthly, split = "market")
 (z)

 With the artificially produced data set above, it works just fine.
 However, with my data it gives me an error:

 OrigData<-read.csv("OrigData.csv")
 OrigData$Month<-as.character(OrigData$Month)
 OrigData$Month<-as.Date(OrigData$Month,"%m/%d/%y")
 str(OrigData)

 ### The result of str(OrigData) is:
 'data.frame':   440 obs. of  3 variables:
 $ Brand       : Factor w/ 11 levels "aBrand","bBrand",..:
 Month       :Class 'Date'  num [1:440] 13514 13545 13573 13604,...
 Value: int  NA NA NA 100 100 100 100 100 100 99
>>>
>>> ?read.zoo
>>>
>>> You didn't specify the index column correctly. In this case it needs to
>>> be =
>>> 2.
>>>

 Then I try:
 z <- read.zoo(OrigData, split = "Brand")

 And get the error:
 Error in read.zoo(OrigData, split = "Brand") :
  index has 440 bad entries at data rows: 1 2 3 4 5 6 7 8 9 10 11 12 13

 But the structure of my OrigData is exactly the same as of monthly. OK
 - OrigData always has a few NAs in "Value" coming first - but that's
 consistent for all brands.
 Any idea what might be wrong?
 Thanks  a lot!

 Just in case -attaching the actual file.

>>> No. Not  attached.
>>>
>>> --
>>>
>>> David Winsemius, MD
>>> West Hartford, CT
>>>
>>>
>>
>>
>>
>> --
>> Dimitri Liakhovitski
>> Ninah Consulting
>> www.ninah.com
>> 
>
> David Winsemius, MD
> West Hartford, CT
>
>



-- 
Dimitri Liakhovitski
Ninah Consulting
www.ninah.com

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


Re: [R] re-ordering bwplot

2010-07-23 Thread Deepayan Sarkar
On Fri, Jul 23, 2010 at 10:02 AM, Eck, Bradley J
 wrote:
> Dear list:
>
> I'm using bwplot to compare concentrations by location and treatment as in:
>
> # using built in data
> bwplot( conc ~ Type : Treatment, data = CO2 )
>
> I would like the order of the plots to be: 3,4,1,2.   I can't seem to figure 
> this out with index.cond or permc.cond.
>
> Any help is appreciated!

I think the only way is to

(1) explicitly create the interaction variable

(2) re-create the factor using factor() with your desired levels

This should be done before the bwplot() call.

-Deepayan

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


Re: [R] How to import simple java/mathematica expression to R

2010-07-23 Thread Andrey Siver
Hello,

2010/7/23 jim holtman :
> It would be nice if you could post what the data looks like that you
> want to import.  R can import any text file and then you have string
> manipulation that you can do to parse it.  So the basic answer is
> probably yes, but we do need to understand the format of the data to
> give a more precise answer.

I put the target expression to minimize (with some constrains) here:

http://analytic-products4you.com/target.txt

Is it possible to import it as a function to minimize?

>
> What is the problem that you are trying to solve?
>

We solve a problem for parameters estimation with ties.

Thank You for the answer.

-- 
Regards,

   -Andrey

__
R-help@r-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 produced by read.zoo: "bad entries"

2010-07-23 Thread David Winsemius
But, but, but Did you read my message about the need to correctly  
specify index columns?



The problem is that read.zoo is reading your first column as an index  
and it's actually the second column that should be used for that  
purpose.

--
David.

On Jul 23, 2010, at 1:01 PM, Dimitri Liakhovitski wrote:

Strange, I did attach. Attaching again. Maybe the file just doesn't  
go through?

I have:

names(OrigData):
[1] "Brand" "Month" "Value"

I read ?read.zoo
According to that index should be the column number.
I thought it should be split = 1 in my case - because I am splitting  
by Brand.

But neither split = 1 nor split =2 work.
And split ="Brand" does not work either. Why?

D.

On Fri, Jul 23, 2010 at 12:52 PM, David Winsemius
 wrote:

?read.zoo

You didn't specify the index column correctly.
On Jul 23, 2010, at 12:36 PM, Dimitri Liakhovitski wrote:


Hello!

I have a data set similar to the data set "monthly" in the example  
below:



monthly<- 
data 
.frame 
(month 
= 
c 
(20090301,20090401,20090501,20100301,20100401,20090301,20090401,20090501,20100301,20100401 
),monthly 
.value=c(100,200,300,101,201,10,20,30,11,21),market=c("Market

A","Market A", "Market A","Market A", "Market A","Market B", "Market
B","Market B","Market B", "Market B"))
monthly$month<-as.character(monthly$month)
monthly$month<-as.Date(monthly$month,"%Y%m%d")
(monthly)
str(monthly)


I am trying to use read.zoo - like in 3 lines below:
library(zoo)
z <- read.zoo(monthly, split = "market")
(z)

With the artificially produced data set above, it works just fine.
However, with my data it gives me an error:

OrigData<-read.csv("OrigData.csv")
OrigData$Month<-as.character(OrigData$Month)
OrigData$Month<-as.Date(OrigData$Month,"%m/%d/%y")
str(OrigData)

### The result of str(OrigData) is:
'data.frame':   440 obs. of  3 variables:
$ Brand   : Factor w/ 11 levels "aBrand","bBrand",..:
Month   :Class 'Date'  num [1:440] 13514 13545 13573 13604,...
Value: int  NA NA NA 100 100 100 100 100 100 99


?read.zoo

You didn't specify the index column correctly. In this case it  
needs to be =

2.



Then I try:
z <- read.zoo(OrigData, split = "Brand")

And get the error:
Error in read.zoo(OrigData, split = "Brand") :
 index has 440 bad entries at data rows: 1 2 3 4 5 6 7 8 9 10 11  
12 13


But the structure of my OrigData is exactly the same as of  
monthly. OK

- OrigData always has a few NAs in "Value" coming first - but that's
consistent for all brands.
Any idea what might be wrong?
Thanks  a lot!

Just in case -attaching the actual file.


No. Not  attached.

--

David Winsemius, MD
West Hartford, CT






--
Dimitri Liakhovitski
Ninah Consulting
www.ninah.com



David Winsemius, MD
West Hartford, CT

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


[R] re-ordering bwplot

2010-07-23 Thread Eck, Bradley J
Dear list:

I'm using bwplot to compare concentrations by location and treatment as in:

# using built in data
bwplot( conc ~ Type : Treatment, data = CO2 )

I would like the order of the plots to be: 3,4,1,2.   I can't seem to figure 
this out with index.cond or permc.cond.

Any help is appreciated!

Brad Eck


[[alternative HTML version deleted]]

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


Re: [R] Error produced by read.zoo: "bad entries"

2010-07-23 Thread Dimitri Liakhovitski
Strange, I did attach. Attaching again. Maybe the file just doesn't go through?
I have:

names(OrigData):
[1] "Brand" "Month" "Value"

I read ?read.zoo
According to that index should be the column number.
I thought it should be split = 1 in my case - because I am splitting by Brand.
But neither split = 1 nor split =2 work.
And split ="Brand" does not work either. Why?

D.

On Fri, Jul 23, 2010 at 12:52 PM, David Winsemius
 wrote:
> ?read.zoo
>
> You didn't specify the index column correctly.
> On Jul 23, 2010, at 12:36 PM, Dimitri Liakhovitski wrote:
>
>> Hello!
>>
>> I have a data set similar to the data set "monthly" in the example below:
>>
>>
>> monthly<-data.frame(month=c(20090301,20090401,20090501,20100301,20100401,20090301,20090401,20090501,20100301,20100401),monthly.value=c(100,200,300,101,201,10,20,30,11,21),market=c("Market
>> A","Market A", "Market A","Market A", "Market A","Market B", "Market
>> B","Market B","Market B", "Market B"))
>> monthly$month<-as.character(monthly$month)
>> monthly$month<-as.Date(monthly$month,"%Y%m%d")
>> (monthly)
>> str(monthly)
>>
>>
>> I am trying to use read.zoo - like in 3 lines below:
>> library(zoo)
>> z <- read.zoo(monthly, split = "market")
>> (z)
>>
>> With the artificially produced data set above, it works just fine.
>> However, with my data it gives me an error:
>>
>> OrigData<-read.csv("OrigData.csv")
>> OrigData$Month<-as.character(OrigData$Month)
>> OrigData$Month<-as.Date(OrigData$Month,"%m/%d/%y")
>> str(OrigData)
>>
>> ### The result of str(OrigData) is:
>> 'data.frame':   440 obs. of  3 variables:
>> $ Brand       : Factor w/ 11 levels "aBrand","bBrand",..:
>> Month       :Class 'Date'  num [1:440] 13514 13545 13573 13604,...
>> Value: int  NA NA NA 100 100 100 100 100 100 99
>
> ?read.zoo
>
> You didn't specify the index column correctly. In this case it needs to be =
> 2.
>
>>
>> Then I try:
>> z <- read.zoo(OrigData, split = "Brand")
>>
>> And get the error:
>> Error in read.zoo(OrigData, split = "Brand") :
>>  index has 440 bad entries at data rows: 1 2 3 4 5 6 7 8 9 10 11 12 13
>>
>> But the structure of my OrigData is exactly the same as of monthly. OK
>> - OrigData always has a few NAs in "Value" coming first - but that's
>> consistent for all brands.
>> Any idea what might be wrong?
>> Thanks  a lot!
>>
>> Just in case -attaching the actual file.
>>
> No. Not  attached.
>
> --
>
> David Winsemius, MD
> West Hartford, CT
>
>



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


Re: [R] Tutorial Tinn-R

2010-07-23 Thread Bert Gunter
Google on "tinn-r tutorial." However, I believe that you will find that the
answer is no, there isn't anything useful out there. Moreover, TINN-R's help
files are minimal and terrible, even though the package itself is quite
useful (I find). Please Do NOT post further TINN-R questions to this list --
it is for R, not TINN-R. Perhaps someone will be able to tell you where to
post TINN-R questions. I just had to struggle to figure it out and get it
set up; but I use it all the time as a pseudo- IDE.

Bert Gunter
Genentech Nonclinical Statistics


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of suse
> Sent: Friday, July 23, 2010 9:44 AM
> To: r-help@r-project.org
> Subject: [R] Tutorial Tinn-R
> 
> 
> Hi,
> 
> does anyone know a tutorial for Tinn-R? During all my search I only found
> R-Tutorials...
> The problem now is: I would like to make Tinn-R an autosave. But since I
> had
> several questions before concerning Tinn-R (for example, how to have Tinn-
> R
> and R in one window or how do the new versions work), I think it is easier
> to have a tutorial instead of asking here everything.
> 
> Thank you!
> --
> View this message in context: http://r.789695.n4.nabble.com/Tutorial-Tinn-
> R-tp2300451p2300451.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] Error produced by read.zoo: "bad entries"

2010-07-23 Thread David Winsemius

?read.zoo

You didn't specify the index column correctly.
On Jul 23, 2010, at 12:36 PM, Dimitri Liakhovitski wrote:


Hello!

I have a data set similar to the data set "monthly" in the example  
below:


monthly<- 
data 
.frame 
(month 
= 
c 
(20090301,20090401,20090501,20100301,20100401,20090301,20090401,20090501,20100301,20100401 
),monthly.value=c(100,200,300,101,201,10,20,30,11,21),market=c("Market

A","Market A", "Market A","Market A", "Market A","Market B", "Market
B","Market B","Market B", "Market B"))
monthly$month<-as.character(monthly$month)
monthly$month<-as.Date(monthly$month,"%Y%m%d")
(monthly)
str(monthly)


I am trying to use read.zoo - like in 3 lines below:
library(zoo)
z <- read.zoo(monthly, split = "market")
(z)

With the artificially produced data set above, it works just fine.
However, with my data it gives me an error:

OrigData<-read.csv("OrigData.csv")
OrigData$Month<-as.character(OrigData$Month)
OrigData$Month<-as.Date(OrigData$Month,"%m/%d/%y")
str(OrigData)

### The result of str(OrigData) is:
'data.frame':   440 obs. of  3 variables:
$ Brand   : Factor w/ 11 levels "aBrand","bBrand",..:
Month   :Class 'Date'  num [1:440] 13514 13545 13573 13604,...
Value: int  NA NA NA 100 100 100 100 100 100 99


?read.zoo

You didn't specify the index column correctly. In this case it needs  
to be = 2.




Then I try:
z <- read.zoo(OrigData, split = "Brand")

And get the error:
Error in read.zoo(OrigData, split = "Brand") :
 index has 440 bad entries at data rows: 1 2 3 4 5 6 7 8 9 10 11 12 13

But the structure of my OrigData is exactly the same as of monthly. OK
- OrigData always has a few NAs in "Value" coming first - but that's
consistent for all brands.
Any idea what might be wrong?
Thanks  a lot!

Just in case -attaching the actual file.


No. Not  attached.

--

David Winsemius, MD
West Hartford, CT

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


Re: [R] converting a time to nearest half-hour

2010-07-23 Thread Gabor Grothendieck
On Fri, Jul 23, 2010 at 12:35 PM,   wrote:
> David, Stephen,
> You're right - it's the time zone conventions that threw me as well. I tried 
> those round() operations earlier, but inevitably ended up being either an 
> hour behind. Even when I specified my time zone, it didn't make any 
> difference. So there's something else that I'm missing. I'll take a look at 
> your various approaches, and get back to you.

Does your problem really involve time zones?  If not you would likely
be best off using a datetime class that has no time zone so you don't
run into this problem in the first place.  Also its particularly easy
with chron due to the availability of trunc.times() :

   library(chron)
   now <- as.chron(format(Sys.time()))

   trunc(now + as.numeric(times("00:15:00")), "00:30:00")

With POSIXct you could muck with the internals like this (which uses
the fact that there are 1800 seconds in an half hour):

   x <- Sys.time()
   structure(1800 * (as.numeric(x + 900) %/% 1800), class = class(x))

See the article in R News 4/1 for more.

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


Re: [R] How to deal with more than 6GB dataset using R?

2010-07-23 Thread Allan Engelhardt

On 23/07/10 17:36, Duncan Murdoch wrote:

On 23/07/2010 12:10 PM, babyfoxlo...@sina.com wrote:

[...]


You probably won't get much faster than read.table with all of the 
colClasses specified.  It will be a lot slower if you leave that at 
the default NA setting, because then R needs to figure out the types 
by reading them as character and examining all the values.  If the 
file is very consistently structured (e.g. the same number of 
characters in every value in every row) you might be able to write a C 
function to read it faster, but I'd guess the time spent writing that 
would be a lot more than the time saved.


And try the utils::read.fwf() function before you roll your own C code 
for this use case.


If you do write C code, consider writing a converter to .RData format 
which R seems to read quite efficiently.


Hope this helps.

Allan

__
R-help@r-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] Tutorial Tinn-R

2010-07-23 Thread suse

Hi,

does anyone know a tutorial for Tinn-R? During all my search I only found
R-Tutorials...
The problem now is: I would like to make Tinn-R an autosave. But since I had
several questions before concerning Tinn-R (for example, how to have Tinn-R
and R in one window or how do the new versions work), I think it is easier
to have a tutorial instead of asking here everything.

Thank you!
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Tutorial-Tinn-R-tp2300451p2300451.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] class

2010-07-23 Thread schuster

Hi, 

Strange, there seems to be different behavior of "old style" classes and S4 
classes.

This worked just like you expected (but it's not the same thing, no S4 
classes)

f2=function(x,...) UseMethod("fxy")
fxy.default=function(x,...){
print("default")
}
fxy.X=function(x,...) {
print("X")
NextMethod()
}
fxy.Y=function(x,...) {
print("Y")
NextMethod()
}

x <- 1
y <- 2
class(x) <- c("X")
class(y) <- c("X", "Y")
f2(x)
f2(y)

Did you find a solution?

On Thursday 22 July 2010 10:23:37 am Yuan Jian wrote:
> Hello,
> �
> ###� I created two classes "A" and "B". "A" is the superclass of "B".
> �
> setClass("A", representation(s1="numeric"),prototype=prototype(s1=8))
> setClass("B",contains="A",representation(s2="character"),prototype=list(s2=
> "hi")) myA=new("A")
> myB=new("B")
> �
> � I created functions for "A" and "B"
> �
> f1=function(x,...) UseMethod("f")
> f.default=function(x,...){
> ��� print("default")
> �}
> �f.A=function(x,...) {
>  print(paste("x...@s1=", x...@s1, sep=""))
> ��� �NextMethod()
> �}
> �f.B=function(x,...) {
> ��� �print(paste("x...@s2=", x...@s2, sep=""))
>  NextMethod()
> �}
> �
>  when I do
> �f1(myB)
> ## R gave me the result
> [1] "x...@s2=hi"
> [1] "default"
> ## but I think the result should be
> [1] "x...@s2=hi"
> [1] "x...@s1=8"
> [1] "default"
> �
> ## because the the NextMethod() should go to f1.A not directly to
>  f1.default. could you please tell me where I got wrong understanding?
> �
> Yu
> �
> 
> �
> 
> 
> 
>   [[alternative HTML version deleted]]
> 

-- 

Friedrich Schuster
Dompfaffenweg 6
69123 Heidelberg

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


Re: [R] How to deal with more than 6GB dataset using R?

2010-07-23 Thread Allan Engelhardt
read.table is not very inefficient IF you specify the colClasses= 
parameter.  scan (with the what= parameter) is probably a little more 
efficient.  In either case, save the data using save() once you have it 
in the right structure and it will be much more efficient to read it 
next time.  (In fact I often exit R at this stage and re-start it with 
the .RData file before I start the analysis to clear out the memory.)


I did a lot of testing on the types of (large) data structures I 
normally work with and found that options("save.defaults" = 
list(compress="bzip2", compression_level=6, ascii=FALSE)) gave me the 
best trade-off between size and speed.  Your mileage will undoubtedly 
vary, but if you do this a lot it may be worth getting hard data for 
your setup.


Hope this helps a little.

Allan

On 23/07/10 17:10, babyfoxlo...@sina.com wrote:

 Hi there,

Sorry to bother those who are not interested in this problem.

I'm dealing with a large data set, more than 6 GB file, and doing regression 
test with those data. I was wondering are there any efficient ways to read 
those data? Instead of just using read.table()? BTW, I'm using a 64bit version 
desktop and a 64bit version R, and the memory for the desktop is enough for me 
to use.
Thanks.


--Gin

[[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] Error produced by read.zoo: "bad entries"

2010-07-23 Thread Dimitri Liakhovitski
Hello!

I have a data set similar to the data set "monthly" in the example below:

monthly<-data.frame(month=c(20090301,20090401,20090501,20100301,20100401,20090301,20090401,20090501,20100301,20100401),monthly.value=c(100,200,300,101,201,10,20,30,11,21),market=c("Market
A","Market A", "Market A","Market A", "Market A","Market B", "Market
B","Market B","Market B", "Market B"))
monthly$month<-as.character(monthly$month)
monthly$month<-as.Date(monthly$month,"%Y%m%d")
(monthly)
str(monthly)


I am trying to use read.zoo - like in 3 lines below:
library(zoo)
z <- read.zoo(monthly, split = "market")
(z)

With the artificially produced data set above, it works just fine.
However, with my data it gives me an error:

OrigData<-read.csv("OrigData.csv")
OrigData$Month<-as.character(OrigData$Month)
OrigData$Month<-as.Date(OrigData$Month,"%m/%d/%y")
str(OrigData)

### The result of str(OrigData) is:
'data.frame':   440 obs. of  3 variables:
 $ Brand   : Factor w/ 11 levels "aBrand","bBrand",..:
Month   :Class 'Date'  num [1:440] 13514 13545 13573 13604,...
Value: int  NA NA NA 100 100 100 100 100 100 99

Then I try:
z <- read.zoo(OrigData, split = "Brand")

And get the error:
Error in read.zoo(OrigData, split = "Brand") :
  index has 440 bad entries at data rows: 1 2 3 4 5 6 7 8 9 10 11 12 13

But the structure of my OrigData is exactly the same as of monthly. OK
- OrigData always has a few NAs in "Value" coming first - but that's
consistent for all brands.
Any idea what might be wrong?
Thanks  a lot!

Just in case -attaching the actual file.

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


Re: [R] How to deal with more than 6GB dataset using R?

2010-07-23 Thread Duncan Murdoch

On 23/07/2010 12:10 PM, babyfoxlo...@sina.com wrote:

 Hi there,

Sorry to bother those who are not interested in this problem.

I'm dealing with a large data set, more than 6 GB file, and doing regression 
test with those data. I was wondering are there any efficient ways to read 
those data? Instead of just using read.table()? BTW, I'm using a 64bit version 
desktop and a 64bit version R, and the memory for the desktop is enough for me 
to use.
Thanks.
  


You probably won't get much faster than read.table with all of the 
colClasses specified.  It will be a lot slower if you leave that at the 
default NA setting, because then R needs to figure out the types by 
reading them as character and examining all the values.  If the file is 
very consistently structured (e.g. the same number of characters in 
every value in every row) you might be able to write a C function to 
read it faster, but I'd guess the time spent writing that would be a lot 
more than the time saved.


Duncan Murdoch

__
R-help@r-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] converting a time to nearest half-hour

2010-07-23 Thread Murali.Menon
David, Stephen,
You're right - it's the time zone conventions that threw me as well. I tried 
those round() operations earlier, but inevitably ended up being either an hour 
behind. Even when I specified my time zone, it didn't make any difference. So 
there's something else that I'm missing. I'll take a look at your various 
approaches, and get back to you.
Cheers,
Murali

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of David Winsemius
Sent: 23 July 2010 17:15
To: stephen sefick
Cc: r-help@r-project.org
Subject: Re: [R] converting a time to nearest half-hour


On Jul 23, 2010, at 12:04 PM, stephen sefick wrote:

> If you have a zoo series this should work.  If it doesn't then please 
> tell me because I think it works.
>
> snap2min <- function(zoo, min="00:15:00"){
> min15 <- times(min)
> a <- aggregate(zoo, trunc(time(zoo), min15), function(x) mean(x,
> na.rm=TRUE))
> }

This "works" for producing 10 half-hour intervals of EDT times:

as.POSIXct(60*30*( round( as.numeric( Sys.time()+
   60*30*(1:10))/  # the sequence creation
   (60*30))) -   # divide prior to rounding
   5*60*60,# the TZ offset
   origin="1970-01-01" )
  [1] "2010-07-23 12:30:00 EDT" "2010-07-23 13:00:00 EDT"
  [3] "2010-07-23 13:30:00 EDT" "2010-07-23 14:00:00 EDT"
  [5] "2010-07-23 14:30:00 EDT" "2010-07-23 15:00:00 EDT"
  [7] "2010-07-23 15:30:00 EDT" "2010-07-23 16:00:00 EDT"
  [9] "2010-07-23 16:30:00 EDT" "2010-07-23 17:00:00 EDT"

>
> hth
>
> Stephen Sefick
>
> On Fri, Jul 23, 2010 at 11:00 AM, David Winsemius 
>  wrote:
>>
>> On Jul 23, 2010, at 11:35 AM, David Winsemius wrote:
>>
>>>
>>> On Jul 23, 2010, at 11:20 AM,  
>>>  wrote:
>>>
 Hi folks,

 I've got a POSIXct datum as follows:

> Sys.time()

 [1] "2010-07-23 11:29:59 BST"

 I want to convert this to the nearest half-hour, i.e., to
 "2010-07-23
 11:30:00 BST"

 (If the time were "11:59:ss", I want to convert to "12:00:00").

 How to achieve this?
>>>
>>> Couldn't you just coerce to numeric, divide by 60(sec)*30(half-hour 
>>> minutes), round to integer, multiply by 60*30,  coerce to POSIXct?
>>
>> When I tried my method I see that one also needs to add or subtract 
>> the proper number of seconds from Universal Time to get the output 
>> formatting correct. (Probably demonstrates that I do not have the 
>> proper understanding of the right place to employ a TZ 
>> specification.).
>>
>> David Winsemius, MD
>> West Hartford, CT
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide 
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --
> Stephen Sefick
> 
> | Auburn University   |
> | Department of Biological Sciences   |
> | 331 Funchess Hall  |
> | Auburn, Alabama   |
> | 36849|
> |___|
> | sas0...@auburn.edu |
> | http://www.auburn.edu/~sas0025 |
> |___|
>
> Let's not spend our time and resources thinking about things that are 
> so little or so large that all they really do for us is puff us up and 
> make us feel like gods.  We are mammals, and have not exhausted the 
> annoying little problems of being mammals.
>
> -K. Mullis

David Winsemius, MD
West Hartford, CT

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

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


Re: [R] converting a time to nearest half-hour

2010-07-23 Thread Allan Engelhardt
The arithmetic that David describes should work fine (POSIXct is 
internally in UTC) unless you are in the Chatham Islands (which has a 
UTC+12:45 time zone [1]) or Nepal (UTC+05:45 [2]) or some such place 
with a funny idea about when the 1/2 hour mark is.



The formatting of the output may be tricky, if the original poster 
really want the (past/future) time zone as opposed to the current one, 
which is what his text could be read to suggest.


Good test cases would be "2010-03-28 01:46:00 GMT" which should 
(presumably) round to "2010-03-28 03:00:00 BST" and "2010-10-31 02:46 
BST" which probably rounds to "2010-10-31 02:00 GMT".  I can't quite get 
it to work in R, but it should be possible



Allan

[1] https://secure.wikimedia.org/wikipedia/en/wiki/UTC%2B12:45
[2] https://secure.wikimedia.org/wikipedia/en/wiki/UTC%2B05:45

On 23/07/10 16:35, David Winsemius wrote:


On Jul 23, 2010, at 11:20 AM,  
 wrote:



Hi folks,

I've got a POSIXct datum as follows:


Sys.time()

[1] "2010-07-23 11:29:59 BST"

I want to convert this to the nearest half-hour, i.e., to "2010-07-23 
11:30:00 BST"


(If the time were "11:59:ss", I want to convert to "12:00:00").

How to achieve this?


Couldn't you just coerce to numeric, divide by 60(sec)*30(half-hour 
minutes), round to integer, multiply by 60*30,  coerce to POSIXct?


_
David Winsemius, MD
West Hartford, CT



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


Re: [R] converting a time to nearest half-hour

2010-07-23 Thread Jeff Newmiller
This truncates to quarter-hour rather than rounding to half-hour.

"stephen sefick"  wrote:

>If you have a zoo series this should work.  If it doesn't then please
>tell me because I think it works.
>
>snap2min <- function(zoo, min="00:15:00"){
>min15 <- times(min)
>a <- aggregate(zoo, trunc(time(zoo), min15), function(x) mean(x, na.rm=TRUE))
>}
>
>hth
>
>Stephen Sefick
>
>On Fri, Jul 23, 2010 at 11:00 AM, David Winsemius
> wrote:
>>
>> On Jul 23, 2010, at 11:35 AM, David Winsemius wrote:
>>
>>>
>>> On Jul 23, 2010, at 11:20 AM, 
>>>  wrote:
>>>
 Hi folks,

 I've got a POSIXct datum as follows:

> Sys.time()

 [1] "2010-07-23 11:29:59 BST"

 I want to convert this to the nearest half-hour, i.e., to "2010-07-23
 11:30:00 BST"

 (If the time were "11:59:ss", I want to convert to "12:00:00").

 How to achieve this?
>>>
>>> Couldn't you just coerce to numeric, divide by 60(sec)*30(half-hour
>>> minutes), round to integer, multiply by 60*30,  coerce to POSIXct?
>>
>> When I tried my method I see that one also needs to add or subtract the
>> proper number of seconds from Universal Time to get the output formatting
>> correct. (Probably demonstrates that I do not have the proper understanding
>> of the right place to employ a TZ specification.).
>>
>> David Winsemius, MD
>> West Hartford, CT
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
>-- 
>Stephen Sefick
>
>| Auburn University                                   |
>| Department of Biological Sciences           |
>| 331 Funchess Hall                                  |
>| Auburn, Alabama                                   |
>| 36849                                                    |
>|___|
>| sas0...@auburn.edu                             |
>| http://www.auburn.edu/~sas0025             |
>|___|
>
>Let's not spend our time and resources thinking about things that are
>so little or so large that all they really do for us is puff us up and
>make us feel like gods.  We are mammals, and have not exhausted the
>annoying little problems of being mammals.
>
>                                -K. Mullis
>
>__
>R-help@r-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.

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

__
R-help@r-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] converting a time to nearest half-hour

2010-07-23 Thread Jeff Newmiller
By entering "trunc.POSIXt" at the R commandline, you can see the standard 
truncate implementation. Riffing on this, 

roundhalfhour <- function( x ) {
 x <- as.POSIXlt( x + as.difftime( 15, units="mins" ) )
 x$sec <- 0
 x$min <- 30*(x$min %/% 30)
 as.POSIXct(x)
}

The as.double approach ought to work also, but rounding error might be a 
problem.

"David Winsemius"  wrote:

>
>On Jul 23, 2010, at 11:35 AM, David Winsemius wrote:
>
>>
>> On Jul 23, 2010, at 11:20 AM,  
>> > > wrote:
>>
>>> Hi folks,
>>>
>>> I've got a POSIXct datum as follows:
>>>
 Sys.time()
>>> [1] "2010-07-23 11:29:59 BST"
>>>
>>> I want to convert this to the nearest half-hour, i.e., to  
>>> "2010-07-23 11:30:00 BST"
>>>
>>> (If the time were "11:59:ss", I want to convert to "12:00:00").
>>>
>>> How to achieve this?
>>
>> Couldn't you just coerce to numeric, divide by 60(sec)*30(half-hour  
>> minutes), round to integer, multiply by 60*30,  coerce to POSIXct?
>
>When I tried my method I see that one also needs to add or subtract  
>the proper number of seconds from Universal Time to get the output  
>formatting correct. (Probably demonstrates that I do not have the  
>proper understanding of the right place to employ a TZ specification.).
>
>David Winsemius, MD
>West Hartford, CT
>
>__
>R-help@r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

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

__
R-help@r-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] converting a time to nearest half-hour

2010-07-23 Thread David Winsemius


On Jul 23, 2010, at 12:04 PM, stephen sefick wrote:


If you have a zoo series this should work.  If it doesn't then please
tell me because I think it works.

snap2min <- function(zoo, min="00:15:00"){
min15 <- times(min)
a <- aggregate(zoo, trunc(time(zoo), min15), function(x) mean(x,  
na.rm=TRUE))

}


This "works" for producing 10 half-hour intervals of EDT times:

as.POSIXct(60*30*( round( as.numeric( Sys.time()+
  60*30*(1:10))/  # the sequence creation
  (60*30))) -   # divide prior to rounding
  5*60*60,# the TZ offset
  origin="1970-01-01" )
 [1] "2010-07-23 12:30:00 EDT" "2010-07-23 13:00:00 EDT"
 [3] "2010-07-23 13:30:00 EDT" "2010-07-23 14:00:00 EDT"
 [5] "2010-07-23 14:30:00 EDT" "2010-07-23 15:00:00 EDT"
 [7] "2010-07-23 15:30:00 EDT" "2010-07-23 16:00:00 EDT"
 [9] "2010-07-23 16:30:00 EDT" "2010-07-23 17:00:00 EDT"



hth

Stephen Sefick

On Fri, Jul 23, 2010 at 11:00 AM, David Winsemius
 wrote:


On Jul 23, 2010, at 11:35 AM, David Winsemius wrote:



On Jul 23, 2010, at 11:20 AM, 
 wrote:


Hi folks,

I've got a POSIXct datum as follows:


Sys.time()


[1] "2010-07-23 11:29:59 BST"

I want to convert this to the nearest half-hour, i.e., to  
"2010-07-23

11:30:00 BST"

(If the time were "11:59:ss", I want to convert to "12:00:00").

How to achieve this?


Couldn't you just coerce to numeric, divide by 60(sec)*30(half-hour
minutes), round to integer, multiply by 60*30,  coerce to POSIXct?


When I tried my method I see that one also needs to add or subtract  
the
proper number of seconds from Universal Time to get the output  
formatting
correct. (Probably demonstrates that I do not have the proper  
understanding

of the right place to employ a TZ specification.).

David Winsemius, MD
West Hartford, CT

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





--
Stephen Sefick

| Auburn University   |
| Department of Biological Sciences   |
| 331 Funchess Hall  |
| Auburn, Alabama   |
| 36849|
|___|
| sas0...@auburn.edu |
| http://www.auburn.edu/~sas0025 |
|___|

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis


David Winsemius, MD
West Hartford, CT

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


Re: [R] Syntax Highlightning and Editor for Linux

2010-07-23 Thread schuster

Rkward is great. 

If you are a programmer then have a look at the StatET plugin for eclipse 
(Java). Not so simple to set up.


On Friday 23 July 2010 02:17:36 pm Alaios wrote:
> I would like to thank you for your immediate reply.
> Actually I do not like vim and emacs.. I am trying to find an editor with a
>  gui that will work fine in Linux.
> 
> One more question. If I am editing a file using my external text editor is
>  it possible to execute directly one of the functions that are inside the
>  file without executing the source("myfile.R") command first?
> 
> Best Regards
> Alex
> 
> 
> 
> - Original Message 
> From: Duncan Murdoch 
> To: alaios 
> Cc: r-help@r-project.org
> Sent: Fri, July 23, 2010 2:13:48 PM
> Subject: Re: [R] Syntax Highlightning and Editor for Linux
> 
> On 23/07/2010 8:08 AM, alaios wrote:
> >  Hello to the community .
> > First post :)
> > I would like to ask you which text editor do you use in Linux and how did
> > you setup the syntax highlightning?
> 
> I don't use Linux, but I think the most popular editors there are vim and
>  emacs, the latter with ESS.
> 
> > one more question is it possible to debug any program in R by inserting
> > breakpoints?
> 
> Yes, see the setBreakpoint() and trace() functions.
> 
> Duncan Murdoch
> 
> > I would like to thank you in advance for your help
> > Best Regards
> > Alex
> 
> __
> R-help@r-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.
> 

-- 

Friedrich Schuster
Dompfaffenweg 6
69123 Heidelberg

__
R-help@r-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] How to deal with more than 6GB dataset using R?

2010-07-23 Thread babyfoxlove1
 Hi there,

Sorry to bother those who are not interested in this problem.

I'm dealing with a large data set, more than 6 GB file, and doing regression 
test with those data. I was wondering are there any efficient ways to read 
those data? Instead of just using read.table()? BTW, I'm using a 64bit version 
desktop and a 64bit version R, and the memory for the desktop is enough for me 
to use.
Thanks.


--Gin

[[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] decimal seperator

2010-07-23 Thread Jennifer Sabatier
Wow, that's even better!

Thanks to you both.  I know both options will come in handy!

Jen



On Fri, Jul 23, 2010 at 11:58 AM, David Winsemius wrote:

>
> On Jul 23, 2010, at 11:32 AM, Jennifer Sabatier wrote:
>
>  Hi R-List,
>>
>> I have a question regarding R-language formats, I think.  I am producing a
>> series of graphs (using plot, barplot, barchart, and bwplot, using either
>> text or mtext to place values on the graphs) and tables for a Francophone
>> country.  In fact, I have already done so.  However, while they are
>> pleased
>> with the results they've requested I convert all of my decimal points into
>> the French format which uses commas rather than points.
>>
>
> ?options
>
> OutDec: character string containing a single-byte character. The character
> to be used as the decimal point in output conversions, that is in printing,
> plotting and as.character but not deparsing.
>
> --
> DAvid.
>
>  I have no idea how
>> to do this for the graphs, despite searching the help, other than to
>> convert
>> all of my statistics into strings and manually reset the decimal
>> separators,
>> which would take a long time.  Is there some quick and easy way?  It's
>> only
>> the graphs I need assistance with.  For tables I simply output to excel
>> and
>> it's easy to change them there.
>>
>> Here's an example (I'm sure it's crude but I'm still new at R.  To make
>> the
>> graph look right you have to expand the java window...which I'm sure you
>> don't need to do if you know how to do this in a more elegant manner):
>>
>>
>> sites <- c("Kayes", "Kita", "Koulikoro", "Fana", "Sikasso", "Koutiala",
>> "SgFam", "SgHop", "Bla", "Mopti", "Douentz", "Tombc",
>>
>> "Dire","Gao","Ansongo","Kidal","Tessalit","BkoCommI","BkoCommIII","BkoCommV")
>> size <-
>>
>> list(2.91,2.36,5.09,3.21,2.27,4.09,2.31,2.76,1.2,2.03,3.06,0.53,1.43,1.83,1,0.93,0,4.01,4.13,3.47)
>> site_size <- data.frame(cbind(sites, size))
>> newdata <- (sapply(subset(site_size, select=c("size")), as.numeric))
>> rownames(newdata) <- site_size$sites
>>
>> library(grid)
>>
>> plot(newdata, ylab =" ", xlab= " " , axes = FALSE)#, type="h", lwd=16)
>> points(newdata, cex = 10, col = topo.colors(20), bg=topo.colors(20),
>> pch=22)
>> lines(newdata, type="h", lwd=40, col=topo.colors(20))
>> axis(1, at=seq(1, 20, by=1), labels = FALSE)
>> text(seq(1, 20, by=1), par("usr")[3] - 0.2, labels = site2_labels, srt =
>> 45,
>> pos = 1, xpd = TRUE)
>> reg.txt <- as.character(c("Kayes  Koulikoro
>>   SikassoSegou   Mopti
>>Tombouctou  GaoKidal
>>  Bamako"))
>> mtext(paste(reg.txt), side=3, font=4, cex=1, adj=0)#, outer=T)
>> text(0, 5.35, "Region:", cex = 1, font=4, xpd=T)
>> text(0, -.5, "Sites:", cex=1.2, font=1, xpd=T)
>> abline(v=c(2.5, 4.5, 6.5, 9.5, 11.5, 13.5, 15.5, 17.5))
>> axis(2, at=3, labels = FALSE)
>> mtext(paste("VIH Prevalence (%)"), side=2, font=2, cex=1.2)
>> text(1,3, labels=newdata[1], col="white", cex=1.5);text(2,2.45,
>> labels=newdata[2], col="white", cex=1.5)
>> text(3,5.2, labels=newdata[3], col="white", cex=1.5);text(4,3.27,
>> labels=newdata[4], col="white", cex=1.5)
>> text(5,2.35, labels=newdata[5], col="white", cex=1.5);text(6,4.2,
>> labels=newdata[6], col="white", cex=1.5)
>> text(7,2.36, labels=newdata[7], col="black", cex=1.5);text(8,2.85,
>> labels=newdata[8], col="black", cex=1.5)
>> text(9,1.28, labels=newdata[9], col="black", cex=1.5);text(10,2.1,
>> labels=newdata[10], col="black", cex=1.5)
>> text(11,3.13, labels=newdata[11], col="black", cex=1.5);text(12,.6,
>> labels=newdata[12], col="black", cex=1.5)
>> text(13,1.48, labels=newdata[13], col="black", cex=1.5);text(14,1.9,
>> labels=newdata[14], col="black", cex=1.5)
>> text(15,1.05, labels=newdata[15], col="black", cex=1.5);text(16,1,
>> labels=newdata[16], col="black", cex=1.5)
>> text(17,.1, labels=newdata[17], col="black", cex=1.5);text(18,4.1,
>> labels=newdata[18], col="black", cex=1.5)
>> text(19,4.2, labels=newdata[19], col="black", cex=1.5);text(20,3.55,
>> labels=newdata[20], col="black", cex=1.5)
>>
>>
>>
> David Winsemius, MD
> West Hartford, CT
>
>

[[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] converting a time to nearest half-hour

2010-07-23 Thread stephen sefick
If you have a zoo series this should work.  If it doesn't then please
tell me because I think it works.

snap2min <- function(zoo, min="00:15:00"){
min15 <- times(min)
a <- aggregate(zoo, trunc(time(zoo), min15), function(x) mean(x, na.rm=TRUE))
}

hth

Stephen Sefick

On Fri, Jul 23, 2010 at 11:00 AM, David Winsemius
 wrote:
>
> On Jul 23, 2010, at 11:35 AM, David Winsemius wrote:
>
>>
>> On Jul 23, 2010, at 11:20 AM, 
>>  wrote:
>>
>>> Hi folks,
>>>
>>> I've got a POSIXct datum as follows:
>>>
 Sys.time()
>>>
>>> [1] "2010-07-23 11:29:59 BST"
>>>
>>> I want to convert this to the nearest half-hour, i.e., to "2010-07-23
>>> 11:30:00 BST"
>>>
>>> (If the time were "11:59:ss", I want to convert to "12:00:00").
>>>
>>> How to achieve this?
>>
>> Couldn't you just coerce to numeric, divide by 60(sec)*30(half-hour
>> minutes), round to integer, multiply by 60*30,  coerce to POSIXct?
>
> When I tried my method I see that one also needs to add or subtract the
> proper number of seconds from Universal Time to get the output formatting
> correct. (Probably demonstrates that I do not have the proper understanding
> of the right place to employ a TZ specification.).
>
> David Winsemius, MD
> West Hartford, CT
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Stephen Sefick

| Auburn University                                   |
| Department of Biological Sciences           |
| 331 Funchess Hall                                  |
| Auburn, Alabama                                   |
| 36849                                                    |
|___|
| sas0...@auburn.edu                             |
| http://www.auburn.edu/~sas0025             |
|___|

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

                                -K. Mullis

__
R-help@r-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] decimal seperator

2010-07-23 Thread Jennifer Sabatier
Worked like a charm!  Thanks a lot!

Jen



On Fri, Jul 23, 2010 at 11:48 AM, Alain Guillet
wrote:

>  Hi,
>
> I am sure there is a better solution but a possibility is that you use
> sub("\\.",",",as.character(newdata))  instead of newdata in the text calls.
>
> HTH,
> Alain
>
>
>
>
> On 23-Jul-10 17:32, Jennifer Sabatier wrote:
>
>> Hi R-List,
>>
>> I have a question regarding R-language formats, I think.  I am producing a
>> series of graphs (using plot, barplot, barchart, and bwplot, using either
>> text or mtext to place values on the graphs) and tables for a Francophone
>> country.  In fact, I have already done so.  However, while they are
>> pleased
>> with the results they've requested I convert all of my decimal points into
>> the French format which uses commas rather than points.  I have no idea
>> how
>> to do this for the graphs, despite searching the help, other than to
>> convert
>> all of my statistics into strings and manually reset the decimal
>> separators,
>> which would take a long time.  Is there some quick and easy way?  It's
>> only
>> the graphs I need assistance with.  For tables I simply output to excel
>> and
>> it's easy to change them there.
>>
>> Here's an example (I'm sure it's crude but I'm still new at R.  To make
>> the
>> graph look right you have to expand the java window...which I'm sure you
>> don't need to do if you know how to do this in a more elegant manner):
>>
>>
>> sites<- c("Kayes", "Kita", "Koulikoro", "Fana", "Sikasso", "Koutiala",
>> "SgFam", "SgHop", "Bla", "Mopti", "Douentz", "Tombc",
>>
>> "Dire","Gao","Ansongo","Kidal","Tessalit","BkoCommI","BkoCommIII","BkoCommV")
>> size<-
>>
>> list(2.91,2.36,5.09,3.21,2.27,4.09,2.31,2.76,1.2,2.03,3.06,0.53,1.43,1.83,1,0.93,0,4.01,4.13,3.47)
>> site_size<- data.frame(cbind(sites, size))
>> newdata<- (sapply(subset(site_size, select=c("size")), as.numeric))
>> rownames(newdata)<- site_size$sites
>>
>> library(grid)
>>
>> plot(newdata, ylab =" ", xlab= " " , axes = FALSE)#, type="h", lwd=16)
>> points(newdata, cex = 10, col = topo.colors(20), bg=topo.colors(20),
>> pch=22)
>> lines(newdata, type="h", lwd=40, col=topo.colors(20))
>> axis(1, at=seq(1, 20, by=1), labels = FALSE)
>> text(seq(1, 20, by=1), par("usr")[3] - 0.2, labels = site2_labels, srt =
>> 45,
>> pos = 1, xpd = TRUE)
>> reg.txt<- as.character(c("Kayes  Koulikoro
>> SikassoSegou
>> Mopti
>>  Tombouctou  GaoKidal
>>Bamako"))
>> mtext(paste(reg.txt), side=3, font=4, cex=1, adj=0)#, outer=T)
>> text(0, 5.35, "Region:", cex = 1, font=4, xpd=T)
>> text(0, -.5, "Sites:", cex=1.2, font=1, xpd=T)
>> abline(v=c(2.5, 4.5, 6.5, 9.5, 11.5, 13.5, 15.5, 17.5))
>> axis(2, at=3, labels = FALSE)
>> mtext(paste("VIH Prevalence (%)"), side=2, font=2, cex=1.2)
>> text(1,3, labels=newdata[1], col="white", cex=1.5);text(2,2.45,
>> labels=newdata[2], col="white", cex=1.5)
>> text(3,5.2, labels=newdata[3], col="white", cex=1.5);text(4,3.27,
>> labels=newdata[4], col="white", cex=1.5)
>> text(5,2.35, labels=newdata[5], col="white", cex=1.5);text(6,4.2,
>> labels=newdata[6], col="white", cex=1.5)
>> text(7,2.36, labels=newdata[7], col="black", cex=1.5);text(8,2.85,
>> labels=newdata[8], col="black", cex=1.5)
>> text(9,1.28, labels=newdata[9], col="black", cex=1.5);text(10,2.1,
>> labels=newdata[10], col="black", cex=1.5)
>> text(11,3.13, labels=newdata[11], col="black", cex=1.5);text(12,.6,
>> labels=newdata[12], col="black", cex=1.5)
>> text(13,1.48, labels=newdata[13], col="black", cex=1.5);text(14,1.9,
>> labels=newdata[14], col="black", cex=1.5)
>> text(15,1.05, labels=newdata[15], col="black", cex=1.5);text(16,1,
>> labels=newdata[16], col="black", cex=1.5)
>> text(17,.1, labels=newdata[17], col="black", cex=1.5);text(18,4.1,
>> labels=newdata[18], col="black", cex=1.5)
>> text(19,4.2, labels=newdata[19], col="black", cex=1.5);text(20,3.55,
>> labels=newdata[20], col="black", cex=1.5)
>>
>>
>>
>>
>>  Thanks,
>>
>> Jen
>>
>>[[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.
>>
>>
> --
> Alain Guillet
> Statistician and Computer Scientist
>
> SMCS - IMMAQ - Université catholique de Louvain
> Bureau c.316
> Voie du Roman Pays, 20
> B-1348 Louvain-la-Neuve
> Belgium
>
> tel: +32 10 47 30 50
>
>

[[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] converting a time to nearest half-hour

2010-07-23 Thread David Winsemius


On Jul 23, 2010, at 11:35 AM, David Winsemius wrote:



On Jul 23, 2010, at 11:20 AM,  > wrote:



Hi folks,

I've got a POSIXct datum as follows:


Sys.time()

[1] "2010-07-23 11:29:59 BST"

I want to convert this to the nearest half-hour, i.e., to  
"2010-07-23 11:30:00 BST"


(If the time were "11:59:ss", I want to convert to "12:00:00").

How to achieve this?


Couldn't you just coerce to numeric, divide by 60(sec)*30(half-hour  
minutes), round to integer, multiply by 60*30,  coerce to POSIXct?


When I tried my method I see that one also needs to add or subtract  
the proper number of seconds from Universal Time to get the output  
formatting correct. (Probably demonstrates that I do not have the  
proper understanding of the right place to employ a TZ specification.).


David Winsemius, MD
West Hartford, CT

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


Re: [R] decimal seperator

2010-07-23 Thread David Winsemius


On Jul 23, 2010, at 11:32 AM, Jennifer Sabatier wrote:


Hi R-List,

I have a question regarding R-language formats, I think.  I am  
producing a
series of graphs (using plot, barplot, barchart, and bwplot, using  
either
text or mtext to place values on the graphs) and tables for a  
Francophone
country.  In fact, I have already done so.  However, while they are  
pleased
with the results they've requested I convert all of my decimal  
points into

the French format which uses commas rather than points.


?options

OutDec: character string containing a single-byte character. The  
character to be used as the decimal point in output conversions, that  
is in printing, plotting and as.character but not deparsing.


--
DAvid.

I have no idea how
to do this for the graphs, despite searching the help, other than to  
convert
all of my statistics into strings and manually reset the decimal  
separators,
which would take a long time.  Is there some quick and easy way?   
It's only
the graphs I need assistance with.  For tables I simply output to  
excel and

it's easy to change them there.

Here's an example (I'm sure it's crude but I'm still new at R.  To  
make the
graph look right you have to expand the java window...which I'm sure  
you

don't need to do if you know how to do this in a more elegant manner):


sites <- c("Kayes", "Kita", "Koulikoro", "Fana", "Sikasso",  
"Koutiala",

"SgFam", "SgHop", "Bla", "Mopti", "Douentz", "Tombc",
"Dire 
","Gao 
","Ansongo","Kidal","Tessalit","BkoCommI","BkoCommIII","BkoCommV")

size <-
list 
(2.91,2.36,5.09,3.21,2.27,4.09,2.31,2.76,1.2,2.03,3.06,0.53,1.43,1.83,1,0.93,0,4.01,4.13,3.47 
)

site_size <- data.frame(cbind(sites, size))
newdata <- (sapply(subset(site_size, select=c("size")), as.numeric))
rownames(newdata) <- site_size$sites

library(grid)

plot(newdata, ylab =" ", xlab= " " , axes = FALSE)#, type="h", lwd=16)
points(newdata, cex = 10, col = topo.colors(20), bg=topo.colors(20),  
pch=22)

lines(newdata, type="h", lwd=40, col=topo.colors(20))
axis(1, at=seq(1, 20, by=1), labels = FALSE)
text(seq(1, 20, by=1), par("usr")[3] - 0.2, labels = site2_labels,  
srt = 45,

pos = 1, xpd = TRUE)
reg.txt <- as.character(c("Kayes   
Koulikoro
   Sikasso 
Segou   Mopti
Tombouctou  Gao 
Kidal

  Bamako"))
mtext(paste(reg.txt), side=3, font=4, cex=1, adj=0)#, outer=T)
text(0, 5.35, "Region:", cex = 1, font=4, xpd=T)
text(0, -.5, "Sites:", cex=1.2, font=1, xpd=T)
abline(v=c(2.5, 4.5, 6.5, 9.5, 11.5, 13.5, 15.5, 17.5))
axis(2, at=3, labels = FALSE)
mtext(paste("VIH Prevalence (%)"), side=2, font=2, cex=1.2)
text(1,3, labels=newdata[1], col="white", cex=1.5);text(2,2.45,
labels=newdata[2], col="white", cex=1.5)
text(3,5.2, labels=newdata[3], col="white", cex=1.5);text(4,3.27,
labels=newdata[4], col="white", cex=1.5)
text(5,2.35, labels=newdata[5], col="white", cex=1.5);text(6,4.2,
labels=newdata[6], col="white", cex=1.5)
text(7,2.36, labels=newdata[7], col="black", cex=1.5);text(8,2.85,
labels=newdata[8], col="black", cex=1.5)
text(9,1.28, labels=newdata[9], col="black", cex=1.5);text(10,2.1,
labels=newdata[10], col="black", cex=1.5)
text(11,3.13, labels=newdata[11], col="black", cex=1.5);text(12,.6,
labels=newdata[12], col="black", cex=1.5)
text(13,1.48, labels=newdata[13], col="black", cex=1.5);text(14,1.9,
labels=newdata[14], col="black", cex=1.5)
text(15,1.05, labels=newdata[15], col="black", cex=1.5);text(16,1,
labels=newdata[16], col="black", cex=1.5)
text(17,.1, labels=newdata[17], col="black", cex=1.5);text(18,4.1,
labels=newdata[18], col="black", cex=1.5)
text(19,4.2, labels=newdata[19], col="black", cex=1.5);text(20,3.55,
labels=newdata[20], col="black", cex=1.5)




David Winsemius, MD
West Hartford, CT

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


Re: [R] converting a time to nearest half-hour

2010-07-23 Thread David Winsemius


On Jul 23, 2010, at 11:20 AM,  > wrote:



Hi folks,

I've got a POSIXct datum as follows:


Sys.time()

[1] "2010-07-23 11:29:59 BST"

I want to convert this to the nearest half-hour, i.e., to  
"2010-07-23 11:30:00 BST"


(If the time were "11:59:ss", I want to convert to "12:00:00").

How to achieve this?


Couldn't you just coerce to numeric, divide by 60(sec)*30(half-hour  
minutes), round to integer, multiply by 60*30,  coerce to POSIXct?


_
David Winsemius, MD
West Hartford, CT

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


[R] decimal seperator

2010-07-23 Thread Jennifer Sabatier
Hi R-List,

I have a question regarding R-language formats, I think.  I am producing a
series of graphs (using plot, barplot, barchart, and bwplot, using either
text or mtext to place values on the graphs) and tables for a Francophone
country.  In fact, I have already done so.  However, while they are pleased
with the results they've requested I convert all of my decimal points into
the French format which uses commas rather than points.  I have no idea how
to do this for the graphs, despite searching the help, other than to convert
all of my statistics into strings and manually reset the decimal separators,
which would take a long time.  Is there some quick and easy way?  It's only
the graphs I need assistance with.  For tables I simply output to excel and
it's easy to change them there.

Here's an example (I'm sure it's crude but I'm still new at R.  To make the
graph look right you have to expand the java window...which I'm sure you
don't need to do if you know how to do this in a more elegant manner):


sites <- c("Kayes", "Kita", "Koulikoro", "Fana", "Sikasso", "Koutiala",
"SgFam", "SgHop", "Bla", "Mopti", "Douentz", "Tombc",
"Dire","Gao","Ansongo","Kidal","Tessalit","BkoCommI","BkoCommIII","BkoCommV")
size <-
list(2.91,2.36,5.09,3.21,2.27,4.09,2.31,2.76,1.2,2.03,3.06,0.53,1.43,1.83,1,0.93,0,4.01,4.13,3.47)
site_size <- data.frame(cbind(sites, size))
newdata <- (sapply(subset(site_size, select=c("size")), as.numeric))
rownames(newdata) <- site_size$sites

library(grid)

plot(newdata, ylab =" ", xlab= " " , axes = FALSE)#, type="h", lwd=16)
points(newdata, cex = 10, col = topo.colors(20), bg=topo.colors(20), pch=22)
lines(newdata, type="h", lwd=40, col=topo.colors(20))
axis(1, at=seq(1, 20, by=1), labels = FALSE)
text(seq(1, 20, by=1), par("usr")[3] - 0.2, labels = site2_labels, srt = 45,
pos = 1, xpd = TRUE)
reg.txt <- as.character(c("Kayes  Koulikoro
SikassoSegou   Mopti
 Tombouctou  GaoKidal
   Bamako"))
mtext(paste(reg.txt), side=3, font=4, cex=1, adj=0)#, outer=T)
text(0, 5.35, "Region:", cex = 1, font=4, xpd=T)
text(0, -.5, "Sites:", cex=1.2, font=1, xpd=T)
abline(v=c(2.5, 4.5, 6.5, 9.5, 11.5, 13.5, 15.5, 17.5))
axis(2, at=3, labels = FALSE)
mtext(paste("VIH Prevalence (%)"), side=2, font=2, cex=1.2)
text(1,3, labels=newdata[1], col="white", cex=1.5);text(2,2.45,
labels=newdata[2], col="white", cex=1.5)
text(3,5.2, labels=newdata[3], col="white", cex=1.5);text(4,3.27,
labels=newdata[4], col="white", cex=1.5)
text(5,2.35, labels=newdata[5], col="white", cex=1.5);text(6,4.2,
labels=newdata[6], col="white", cex=1.5)
text(7,2.36, labels=newdata[7], col="black", cex=1.5);text(8,2.85,
labels=newdata[8], col="black", cex=1.5)
text(9,1.28, labels=newdata[9], col="black", cex=1.5);text(10,2.1,
labels=newdata[10], col="black", cex=1.5)
text(11,3.13, labels=newdata[11], col="black", cex=1.5);text(12,.6,
labels=newdata[12], col="black", cex=1.5)
text(13,1.48, labels=newdata[13], col="black", cex=1.5);text(14,1.9,
labels=newdata[14], col="black", cex=1.5)
text(15,1.05, labels=newdata[15], col="black", cex=1.5);text(16,1,
labels=newdata[16], col="black", cex=1.5)
text(17,.1, labels=newdata[17], col="black", cex=1.5);text(18,4.1,
labels=newdata[18], col="black", cex=1.5)
text(19,4.2, labels=newdata[19], col="black", cex=1.5);text(20,3.55,
labels=newdata[20], col="black", cex=1.5)




 Thanks,

Jen

[[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] Correct statistical inference for linear regression modelswithout intercept in R

2010-07-23 Thread Setlhare Lekgatlhamang
In addition, there are 'theoretical' reasons for excluding intercept
from the model that must be considered. The reasons related to the
regressor(s) and depend on the phenomenon being modelled. For example,
whereas the intercept can be excluded in a bivariate model on the
expenditure of an individual as determined by income, the same would be
senseless when applying the same model to the population.

Hope this helps a little

Lexi

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Dennis Murphy
Sent: Tuesday, July 20, 2010 12:34 PM
To: StatWM
Cc: r-help@r-project.org
Subject: Re: [R] Correct statistical inference for linear regression
modelswithout intercept in R

Hi:

On Tue, Jul 20, 2010 at 2:41 AM, StatWM  wrote:

>
> Dear R community,
>
> is there a way to get correct t- and p-values and R squared for linear

> regression models specified without an intercept?
>
> example model:
> summary(lm(y ~ 0 + x))
>
> This gives too low p-values and too high R squared. Is there a way to 
> correct it? Or should I specify with intercept to get the correct
values?
>

How do you know that the p-value is too low and R^2 is too high? Too low
or too high compared to what? You've constrained the intercept of the
model to pass through zero, which affects several features of a simple
linear regression model. For example, sum the residuals from your
no-intercept model - I'll bet they don't add to zero. Do you think that
might affect  a few things? Here's an example:

# Generate some data; notice that the true y-intercept is 2 and the true
slope is 2 dd <- data.frame(x = 1:10, y = 2 + 2 * 1:10 + rnorm(10))
plot(y ~ x, data = dd, xlim = c(0, 10), ylim = c(0, 25))
m1 <- lm(y ~ x, data = dd)
abline(coef(m1))
m2 <- lm(y ~ x + 0, data = dd)
abline(c(0, coef(m2)), lty = 'dotted')

# As you noted, the no-intercept model has a higher R^2, # even though
the 'usual' simple linear regression (SLR) # model provided a better
visual fit. Why?
summary(m1)$r.squared
[1] 0.982328
summary(m2)$r.squared
[1] 0.9946863

# The p-value for the F-test on the slope is higher in the #
no-intercept model is lower than in the SLR model. Why?
anova(m1)

Analysis of Variance Table

Response: y
  Df Sum Sq Mean Sq F valuePr(>F)
x  1 385.22  385.22  444.69 2.686e-08 ***
Residuals  8   6.930.87
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

anova(m2)

Analysis of Variance Table

Response: y
  Df  Sum Sq Mean Sq F valuePr(>F)
x  1 2164.07 2164.07  1684.7 1.507e-11 ***
Residuals  9   11.561.28


Look at the differences in sums of squares between the two models, both
in terms of model SS and error SS. What is responsible for those
differences?
Once you understand that, it becomes clear why the apparent anomalies in
R^2 and in the F-test occur by applying the definitions. Also try

sum(m1$resid)
sum(m2$resid)

Why is there a difference? Why dies m2$resid not have to sum to zero?

(Hint: The output in each case is correct, so it's not an R problem. You
need to derive the differences among the various quantities in
regression modeling between the intercept and no-intercept models to
understand the
paradox.)

HTH,
Dennis

Thank you in advance!
>
> Wojtek Musial
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Correct-statistical-inference-for-linear
> -regression-models-without-intercept-in-R-tp2295193p2295193.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]



DISCLAIMER:\ Sample Disclaimer added in a VBScript.\ ...{{dropped:3}}

__
R-help@r-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] randomness using runif

2010-07-23 Thread David Winsemius


On Jul 23, 2010, at 11:16 AM, Brigid Mooney wrote:


I'm  working on a problem where I'm introducing random error and have
been using the built in function runif to provide that random error.
However, I realized that I seem to be getting some unexpected behavior
out of the function and was hoping someone could share some insight.

I don't know the runif algorithm at all, but from the behavior I'm
seeing, it seems that whenever I open a new R console, the function
runif gets "reset" to some initial value.


?set.seed

From the help page for set.seed:

Note
"Initially, there is no seed; a new one is created from the current  
time when one is required. Hence, different sessions started at  
(sufficiently) different times will give different simulation results,  
by default. However, the seed might be restored from a previous  
session if a previously saved workspace is restored."


So you probably have saved a value in your workspace.



--

David.



 For example...

In a NEW R console, enter the following:

x1 <- runif(1000, -1, 1)
x2 <- runif(1000, -1, 1)

x1[1:5]
x2[1:5]

objectsToSave <- c("x1", "x2")
filename <- "C:\\Documents\\x1x2file.Rdata"

save(list=objectsToSave, file=filename, envir = parent.frame())


Then in a different NEW R console, enter this:

x3 <- runif(1000, -1, 1)
x4 <- runif(1000, -1, 1)

x3[1:5]
x4[1:5]
# For me, the values look identical to x1 and x2, but let's check by
loading the x1x2 file and comparing them directly...

filename <- "C:\\Documents\\x1x2file.Rdata"

load(filename)

sum(x1==x3)
sum(x2==x4)


For my results, I get that x1=x3 for all 1000 elements in the vector,
and x2=x4 for all 1000 elements in that vector.

Does anyone have insight into what's going on here?  Am I doing
something wrong here, or is this a quirk of the runif algorithm?  Is
there a better function out there for seeding truly random error?

For what it's worth, here's my R version info:

platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  8.1
year   2008
month  12
day22
svn rev47281
language   R
version.string R version 2.8.1 (2008-12-22)

Thanks for the help,
Brigid

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] randomness using runif

2010-07-23 Thread Duncan Murdoch

On 23/07/2010 11:16 AM, Brigid Mooney wrote:

I'm  working on a problem where I'm introducing random error and have
been using the built in function runif to provide that random error.
However, I realized that I seem to be getting some unexpected behavior
out of the function and was hoping someone could share some insight.

I don't know the runif algorithm at all, but from the behavior I'm
seeing, it seems that whenever I open a new R console, the function
runif gets "reset" to some initial value.  For example...

In a NEW R console, enter the following:

x1 <- runif(1000, -1, 1)
x2 <- runif(1000, -1, 1)

x1[1:5]
x2[1:5]

objectsToSave <- c("x1", "x2")
filename <- "C:\\Documents\\x1x2file.Rdata"

save(list=objectsToSave, file=filename, envir = parent.frame())


Then in a different NEW R console, enter this:

x3 <- runif(1000, -1, 1)
x4 <- runif(1000, -1, 1)

x3[1:5]
x4[1:5]
# For me, the values look identical to x1 and x2, but let's check by
loading the x1x2 file and comparing them directly...

filename <- "C:\\Documents\\x1x2file.Rdata"

load(filename)

sum(x1==x3)
sum(x2==x4)


For my results, I get that x1=x3 for all 1000 elements in the vector,
and x2=x4 for all 1000 elements in that vector.

Does anyone have insight into what's going on here?  Am I doing
something wrong here, or is this a quirk of the runif algorithm?  Is
there a better function out there for seeding truly random error?
  


You are doing something wrong:  At some point in the past, you saved 
your workspace, but more recently, you haven't been saving it.  Your 
workspace contains the key used by all the random number generators, so 
you keep restoring the same old key.


I would advise that you *never* save your workspace, and if you see the 
message:


[Previously saved workspace restored]

you treat that as an error, and try to track down where the old 
workspace came from.  Some other people would advise that you always 
save your workspace.  Both approaches will solve this problem.

For what it's worth, here's my R version info:

platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  8.1
year   2008
month  12
day22
svn rev47281
language   R
version.string R version 2.8.1 (2008-12-22)
  


I'd also suggest upgrading: there have been a lot of bug fixes and new 
features added since 2.8.1.


Duncan Murdoch


Thanks for the help,
Brigid

__
R-help@r-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] converting a time to nearest half-hour

2010-07-23 Thread Murali.Menon
Hi folks,

I've got a POSIXct datum as follows:

> Sys.time()
[1] "2010-07-23 11:29:59 BST"

I want to convert this to the nearest half-hour, i.e., to "2010-07-23 11:30:00 
BST"

(If the time were "11:59:ss", I want to convert to "12:00:00").

How to achieve this? 

Thanks,

Murali
__
R-help@r-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] randomness using runif

2010-07-23 Thread Brigid Mooney
I'm  working on a problem where I'm introducing random error and have
been using the built in function runif to provide that random error.
However, I realized that I seem to be getting some unexpected behavior
out of the function and was hoping someone could share some insight.

I don't know the runif algorithm at all, but from the behavior I'm
seeing, it seems that whenever I open a new R console, the function
runif gets "reset" to some initial value.  For example...

In a NEW R console, enter the following:

x1 <- runif(1000, -1, 1)
x2 <- runif(1000, -1, 1)

x1[1:5]
x2[1:5]

objectsToSave <- c("x1", "x2")
filename <- "C:\\Documents\\x1x2file.Rdata"

save(list=objectsToSave, file=filename, envir = parent.frame())


Then in a different NEW R console, enter this:

x3 <- runif(1000, -1, 1)
x4 <- runif(1000, -1, 1)

x3[1:5]
x4[1:5]
# For me, the values look identical to x1 and x2, but let's check by
loading the x1x2 file and comparing them directly...

filename <- "C:\\Documents\\x1x2file.Rdata"

load(filename)

sum(x1==x3)
sum(x2==x4)


For my results, I get that x1=x3 for all 1000 elements in the vector,
and x2=x4 for all 1000 elements in that vector.

Does anyone have insight into what's going on here?  Am I doing
something wrong here, or is this a quirk of the runif algorithm?  Is
there a better function out there for seeding truly random error?

For what it's worth, here's my R version info:

platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  8.1
year   2008
month  12
day22
svn rev47281
language   R
version.string R version 2.8.1 (2008-12-22)

Thanks for the help,
Brigid

__
R-help@r-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] FW: recoding problem

2010-07-23 Thread Joshua Wiley
Hi Tom,

This seems to work like I'd expect:

HGlt10RawPerc2008 <- read.table(textConnection("
-5
 0
-1
-1
 0
 2
 3
-5
-2
 0
 2
 0
 1
-2
 3
 0
 4
 1
 4
 2
"))

recode(HGlt10RawPerc2008 ,"-100:0.0 = 10; 0:1.0 = 8; 1.001:3.0 = 6;
3.001:4.0 = 4; 4.001:5.0 = 2; else = 0")

I wonder if your data might not be something like 10.001 which
would print as 10, but behave in calculations slightly differently?

Also, the output of this might be informative.

str(HGlt10RawPerc2008)

Cheers,

Josh

On Fri, Jul 23, 2010 at 7:47 AM, Heiman, Thomas J.  wrote:
>
>
> Hi,
>
>
>
> I am trying to recode the output from a matrix(here is a small snippet of it):
>
>
>
> HGlt10RawPerc2008[1:20]
>
>  [1] -5
>
>      0
>
>     -1
>
>     -1
>
>      0
>
>      2
>
>      3
>
>     -5
>
>     -2
>
>      0
>
>      2
>
>      0
>
>      1
>
>     -2
>
>      3
>
>      0
>
>      4
>
>      1
>
>      4
>
>      2
>
>
>
> Here is the code I am using to recode it:
>
>
>
> HGBlt10Points2008 = recode(HGlt10RawPerc ,"-100:0.0=10; 0:1.0=8; 1.001:3.0=6; 
> 3.001:4.0=4; 4.001:5.0=2;else=0 ")
>
>
>
> The output that I am expecting and what I get are:
>
>
> What it should be
>
>     The output of
>          my code
>
> 10
>
> 10
>
> 10
>
> 10
>
> 10
>
> 10
>
> 10
>
> 10
>
> 10
>
> 8*
>
> 6
>
> 6
>
> 6
>
> 4*
>
> 10
>
> 10
>
> 10
>
> 10
>
> 10
>
> 10
>
> 6
>
> 10*
>
> 10
>
> 10
>
> 8
>
> 10*
>
> 10
>
> 10
>
> 6
>
> 6
>
> 10
>
> 8*
>
> 2
>
> 0*
>
> 8
>
> 0*
>
> 2
>
> 6*
>
> 6
>
> 10*
>
>
>
>
> The differences between my output and what I wanted are marked with a "*".. 
> Any ideas on what I am doing wrong?  Thank you!!
>
>
>
> Sincerely,
>
>
>
> tom
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

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


[R] FW: recoding problem

2010-07-23 Thread Heiman, Thomas J.


Hi,



I am trying to recode the output from a matrix(here is a small snippet of it):



HGlt10RawPerc2008[1:20]

 [1] -5

  0

 -1

 -1

  0

  2

  3

 -5

 -2

  0

  2

  0

  1

 -2

  3

  0

  4

  1

  4

  2



Here is the code I am using to recode it:



HGBlt10Points2008 = recode(HGlt10RawPerc ,"-100:0.0=10; 0:1.0=8; 1.001:3.0=6; 
3.001:4.0=4; 4.001:5.0=2;else=0 ")



The output that I am expecting and what I get are:


What it should be

 The output of
  my code

10

10

10

10

10

10

10

10

10

8*

6

6

6

4*

10

10

10

10

10

10

6

10*

10

10

8

10*

10

10

6

6

10

8*

2

0*

8

0*

2

6*

6

10*




The differences between my output and what I wanted are marked with a "*".. Any 
ideas on what I am doing wrong?  Thank you!!



Sincerely,



tom

[[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] recoding problem

2010-07-23 Thread Heiman, Thomas J.
Hi,



I am trying to recode the output from a matrix(here is a small snippet of it):



HGlt10RawPerc2008[1:20]

 [1] -5

  0

 -1

 -1

  0

  2

  3

 -5

 -2

  0

  2

  0

  1

 -2

  3

  0

  4

  1

  4

  2



Here is the code I am using to recode it:



HGBlt10Points2008 = recode(HGlt10RawPerc ,"-100:0.0=10; 0:1.0=8; 1.001:3.0=6; 
3.001:4.0=4; 4.001:5.0=2;else=0 ")



The output that I am expecting and what I get are:


What it should be

 The output of
  my code

10

10

10

10

10

10

10

10

10

8

6

6

6

4

10

10

10

10

10

10

6

10

10

10

8

10

10

10

6

6

10

8

2

0

8

0

2

6

6

10




The differences between my output and what I wanted are bolded.. Any ideas on 
what I am doing wrong?  Thank you!!



Sincerely,



tom

[[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] Regex in an IF statement?

2010-07-23 Thread Allan Engelhardt

help("difftime") is probably what you want.

If not, please post a standalone example

Allan

On 23/07/10 15:18, Jim Hargreaves wrote:

Dear List

I have the POSIX timestamps of two events, A and B respectively. I 
want an expression that tests if A occurs within 4 weeks of B.


Something like:

if (ts_A "is between" ts_B + 4(weeks) and ts_B - 4) ...

Can probably done by regex but the regex docu for R says nothing about 
if statements.


Any help greatly appreciated,

Regards,
Jim Hargreaves

__
R-help@r-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] overriding axis limits in hexbin plot?

2010-07-23 Thread Ben Bolker
 [cc'd to package maintainer]

  This feels like a fairly straightforward question, so I'm surprised
not to have found an answer so far (RSiteSearch, package help,
vignette ...)

  It seems fairly hard (without some fairly serious hacking) to
hard-code the axis limits in a hexbin plot from the hexbin package.
Here's what I've figured out so far:

  * when you do the hexagonal binning in the first place, you can
specify the x and y ranges (xbnds, ybnds). Fine ... but ...

  * the plot method for 'hexbin' objects (which doesn't have 'xlim' or
'ylim' arguments) calls hexViewport as

   hexViewport(x, offset = unit(legend, "inches"))

  * in the absence of explicit 'xbnds'/'ybnds' arguments, hexViewport does

   xyb <- smartBnds(x)
h...@xscale <- xs <- if (is.null(xbnds))
xyb$xr
else xbnds
h...@yscale <- ys <- if (is.null(ybnds))
xyb$yr
else ybnds

  It looks like hexbin:::smartBnds computes x  and y ranges from the
hexagonal cells in
the object, not looking at the xbnds and ybnds slots ...

There are various ways to change this. If left to my own devices I
will probably hack a version
of the plot method that has explicit xlim and ylim arguments, but I
wanted to (1) check that I wasn't
missing anything obvious and (2) see if the package maintainer would
be interested in a patch ...

   I think hexbin is reasonably widely used (or should be) and this
seems like a common requirement,
so (as I said) I'm surprised it hasn't come up.

  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.


[R] Regex in an IF statement?

2010-07-23 Thread Jim Hargreaves

Dear List

I have the POSIX timestamps of two events, A and B respectively. I want 
an expression that tests if A occurs within 4 weeks of B.


Something like:

if (ts_A "is between" ts_B + 4(weeks) and ts_B - 4) ...

Can probably done by regex but the regex docu for R says nothing about 
if statements.


Any help greatly appreciated,

Regards,
Jim Hargreaves

__
R-help@r-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] Midpoint between coordinates

2010-07-23 Thread Mafalda Viana
Dear David and R users,

Thank you very much for the help. There is a function in the suggested
package called "midPoint" which does what I need.

df<- data.frame(lon1=c(-4.568,-4.3980), lat1=c(59.235,56.369),
lon2=c(-5.123,-4.698), lat2=c(60.258,59.197) )

library(geosphere)

 p1 <- matrix(c(df$lon1,df$lat1), ncol=2  )
 p2 <- matrix(c(df$lon2,df$lat2), ncol=2  )

midpoint <- as.data.frame(midPoint(p1,p2) )

For short distances the results are indeed very similar to the arithmetic mean.

Thank you again.
Mafalda


On 23 July 2010 14:12, David Winsemius  wrote:
>
> On Jul 23, 2010, at 8:58 AM, Mafalda Viana wrote:
>
>> The arithmetic mean was my first approach and to nearby points it
>> doesn't make much difference. However, when the distance between the 2
>> points gets bigger this is no longer accurate enough. So yes, I was
>> thinking on spherical geometry, midpoint considering the great circle
>> distance or similar.
>
> Are you "up" for some searching?
>
> require(sos)
>> ???"distance spherical"
> found 65 matches;  retrieving 4 pages
> 2 3 4
>
> On first page of hits the geosphere package says it handles spherical
> geometry. Perhaps the gcIntermediate function:
>
> gcIntermediate {geosphere}
> Get intermediate points on a Great Circle inbetween the two points used to
> define the Great Circle
> Usage
> gcIntermediate(p1, p2, n=50)
> Arguments
> p1  Longitude/latitude of a single point, in degrees; can be a vector of two
> numbers, a matrix of 2 columns (first one is longitude, second is latitude)
> or a SpatialPoints* object
> p2  As above
> n  The requested number of points on the Great Circle
> ---
>
> There is also a geospatial Task View and SIG mailing list that is very
> active.
> --
> David
>>
>> Thank you
>> Mafalda
>>
>> On 23 July 2010 13:30, David Winsemius  wrote:
>>>
>>> On Jul 23, 2010, at 7:13 AM, Mafalda Viana wrote:
>>>
 Dear R users,

 I need to find the coordinates for the point (midpoint) located half
 way between two pairs of coordinates (lon1,lat1 and lon2,lat2)
 assuming a straight line between them. What would be the best way? I
 tried to find an answer in the help archives but without success. I
 would greatly appreciate any help.

 df<- data.frame(lon1=c(-4.568,-4.3980), lat1=c(59.235,56.369),
 lon2=c(-5.123,-4.698), lat2=c(60.258,59.197) )
>>>
>>> Wouldn't that just be the arithmetic average of the values? Or to you
>>> have
>>> some need for a more accurate calculation based on spherical geometry?
>>>  Or
>>> some thing that will handle some other coordinate weirdness?
>>>
 df$midlong <- apply(df[,c(1,3)], 1, mean)
 df$midlat <- apply(df[,c(2,4)], 1, mean)
 df
>>>
>>>   lon1   lat1   lon2   lat2 midlong  midlat
>>> 1 -4.568 59.235 -5.123 60.258 -4.8455 59.7465
>>> 2 -4.398 56.369 -4.698 59.197 -4.5480 57.7830

>>> --
>>>
>>> David Winsemius, MD
>>> West Hartford, CT
>>>
>>>
>>>
>>
>>
>>
>> --
>> Mafalda Viana
>> Department of Zoology
>> School of Natural Sciences
>> Trinity College Dublin
>> Dublin 2
>> Ireland
>>
>> (+353) (0) 872829850
>>
>> via...@tcd.ie
>>
>> http://www.tcd.ie/Zoology/research/research/theoretical
>
> David Winsemius, MD
> West Hartford, CT
>
>
>



-- 
Mafalda Viana
Department of Zoology
School of Natural Sciences
Trinity College Dublin
Dublin 2
Ireland

(+353) (0) 872829850

via...@tcd.ie

http://www.tcd.ie/Zoology/research/research/theoretical

__
R-help@r-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] Syntax Highlightning and Editor for Linux

2010-07-23 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 23/07/2010 15:56, Alaios wrote:
> I would like oto thank everyone for the replies.
> I instaled rkward.. It looks like an editor.. Is it possible to execute
Yes

> also your code from the text editor.
Look into the "Run" menu

> If there is a function call myfunc inside my file test.R
> Is it possible to exectute the function from the rwkard?

How do you mean? You can open an R console in rkward (by pressing the "R
console" button on the bottom. Then you can type there. You can submit
to the R Console via the Run menu or keyboard shortcuts.

Cheers,

Rainer

> 
> Best Regards
> Alex
> 
> 
> *From:* Federico Andreis 
> *To:* Rainer M Krug 
> *Cc:* Alaios ; r-help@r-project.org
> *Sent:* Fri, July 23, 2010 3:46:08 PM
> *Subject:* Re: [R] Syntax Highlightning and Editor for Linux
> 
> I have been trying emacs with ess, Kate, plain gedit..nothing really
> satisfied me..
> but then I found a nice plugin for gedit: Rgedit !
> 
> it supports split screen with R terminal window (you can also
> personalize colour if, like me, do like to
> stick with old habits :) ), moreover gedit has a brackets completion and
> a brackets highlight plugin which are very useful.
> 
> check it out here
> 
> http://www.stattler.com/article/using-gedit-or-rgedit-r
> 
> simple "send
> code to terminal" shortcuts (much simpler than emacs, in my opinion) and
> nice interface..give it a try!
> 
> /federico
> 
> 
> On Fri, Jul 23, 2010 at 2:42 PM, Rainer M Krug  > wrote:
> 
> On 23/07/2010 14:17, Alaios wrote:
>> I would like to thank you for your immediate reply.
>> Actually I do not like vim and emacs.. I am trying to find an
> editor with a gui
>> that will work fine in Linux.
> Well - you are missing out with not using emacs + ess - but it is quite
> a learning curve. Despite this:
> 
> Try rkward - syntax highlighting and many other nice features.
> 
> Another option: eclipse with statet plugin(
> http://www.walware.de/goto/statet)
> 
> Cheers,
> 
> Rainer
> 
>> One more question. If I am editing a file using my external text
> editor is it
>> possible to execute directly one of the functions that are inside
> the file
>> without executing the source("myfile.R") command first?
> 
>> Best Regards
>> Alex
> 
> 
> 
>> - Original Message 
>> From: Duncan Murdoch  >
>> To: alaios mailto:ala...@yahoo.com>>
>> Cc: r-help@r-project.org 
>> Sent: Fri, July 23, 2010 2:13:48 PM
>> Subject: Re: [R] Syntax Highlightning and Editor for Linux
> 
>> On 23/07/2010 8:08 AM, alaios wrote:
>>>  Hello to the community .
>>> First post :)
>>> I would like to ask you which text editor do you use in Linux and
> how did
>>> you setup the syntax highlightning?
>>>
> 
>> I don't use Linux, but I think the most popular editors there are
> vim and emacs,
>> the latter with ESS.
> 
>>> one more question is it possible to debug any program in R by
> inserting
>>> breakpoints?
>>>
>>>
> 
>> Yes, see the setBreakpoint() and trace() functions.
> 
>> Duncan Murdoch
> 
>>> I would like to thank you in advance for your help
>>> Best Regards
>>> Alex
>>>
> 
>> __
>> R-help@r-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.





- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Tel:+33 - (0)9 53 10 27 44
Cell:   +27 - (0)8 39 47 90 42
Fax (SA):   +27 - (0)8 65 16 27 82
Fax (D) :   +49 - (0)3 21 21 25 22 44
Fax (FR):   +33 - (0)9 58 10 27 44
email:  rai...@krugs.de

Skype:  RMkrug
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkxJoq0ACgkQoYgNqgF2egq8sACffnYZQ0bkWm+bL51UxtG/LRAq
YmgAn1qivOiOOcopqk6CD7FTQqtHVc9I
=2wCL
-END PGP SIGNATURE-

__
R-help@r-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] Syntax Highlightning and Editor for Linux

2010-07-23 Thread Alaios
I would like oto thank everyone for the replies.
I instaled rkward.. It looks like an editor.. Is it possible to execute also 
your code from the text editor.
If there is a function call myfunc inside my file test.R
Is it possible to exectute the function from the rwkard?

Best Regards
Alex





From: Federico Andreis 
To: Rainer M Krug 

Sent: Fri, July 23, 2010 3:46:08 PM
Subject: Re: [R] Syntax Highlightning and Editor for Linux

I have been trying emacs with ess, Kate, plain gedit..nothing really satisfied 
me..
[[elided Yahoo spam]]

it supports split screen with R terminal window (you can also personalize 
colour 
if, like me, do like to
stick with old habits :) ), moreover gedit has a brackets completion and a 
brackets highlight plugin which are very useful.


check it out here

http://www.stattler.com/article/using-gedit-or-rgedit-r

simple "send code to terminal" shortcuts (much simpler than emacs, in my 
[[elided Yahoo spam]]

/federico



On Fri, Jul 23, 2010 at 2:42 PM, Rainer M Krug  wrote:

-BEGIN PGP SIGNED MESSAGE-
>Hash: SHA1
>
>
>On 23/07/2010 14:17, Alaios wrote:
>> I would like to thank you for your immediate reply.
>> Actually I do not like vim and emacs.. I am trying to find an editor with a 
>gui
>> that will work fine in Linux.
>Well - you are missing out with not using emacs + ess - but it is quite
>a learning curve. Despite this:
>
>Try rkward - syntax highlighting and many other nice features.
>
>Another option: eclipse with statet plugin(
>http://www.walware.de/goto/statet)
>
>Cheers,
>
>Rainer
>
>>
>> One more question. If I am editing a file using my external text editor is it
>> possible to execute directly one of the functions that are inside the file
>> without executing the source("myfile.R") command first?
>>
>> Best Regards
>> Alex
>>
>>
>>
>> - Original Message 
>> From: Duncan Murdoch 

>> Cc: r-help@r-project.org
>> Sent: Fri, July 23, 2010 2:13:48 PM
>> Subject: Re: [R] Syntax Highlightning and Editor for Linux
>>
>> On 23/07/2010 8:08 AM, alaios wrote:
>>>  Hello to the community .
>>> First post :)
>>> I would like to ask you which text editor do you use in Linux and how did
>>> you setup the syntax highlightning?
>>>
>>
>> I don't use Linux, but I think the most popular editors there are vim and 
>>emacs,
>> the latter with ESS.
>>
>>> one more question is it possible to debug any program in R by inserting
>>> breakpoints?
>>>
>>>
>>
>> Yes, see the setBreakpoint() and trace() functions.
>>
>> Duncan Murdoch
>>
>>> I would like to thank you in advance for your help
>>> Best Regards
>>> Alex
>>>
>>
>> __
>> R-help@r-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.
>
>
>- --
>Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
>Biology, UCT), Dipl. Phys. (Germany)
>
>Centre of Excellence for Invasion Biology
>Natural Sciences Building
>Office Suite 2039
>Stellenbosch University
>Main Campus, Merriman Avenue
>Stellenbosch
>South Africa
>
>Tel:+33 - (0)9 53 10 27 44
>Cell:   +27 - (0)8 39 47 90 42
>Fax (SA):   +27 - (0)8 65 16 27 82
>Fax (D) :   +49 - (0)3 21 21 25 22 44
>Fax (FR):   +33 - (0)9 58 10 27 44
>email:  rai...@krugs.de
>
>Skype:  RMkrug
>-BEGIN PGP SIGNATURE-
>Version: GnuPG v1.4.10 (GNU/Linux)
>Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
>iEYEARECAAYFAkxJjjMACgkQoYgNqgF2egqmgACeK5OXtqsKvAcK1Pyli6zlLpW6
>ttkAoIzeKgwKeo7cj4oH+jSOr8QMgFFP
>=B7JP
>-END PGP SIGNATURE-
>
>
>__
>R-help@r-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] Figures in Latex

2010-07-23 Thread David Winsemius


On Jul 23, 2010, at 9:43 AM, li li wrote:


Hi all,
  I want to add 6 plots in the format of 2 columns and 3 rows as one
figure in latex. The plots are in .eps file.
I know how to add 2 plots side by side, but could not figure out how  
to do

multiple rows.
 I know this may not be the right place to ask such a question. But  
I do

not know who to ask,


http://lmgtfy.com/?q=latex+users+group


so just try my
luck here.
 Thank you in advance.
 Hannah

[[alternative HTML version deleted]]

--

David Winsemius, MD
West Hartford, CT

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


Re: [R] Syntax Highlightning and Editor for Linux

2010-07-23 Thread Federico Andreis
I have been trying emacs with ess, Kate, plain gedit..nothing really
satisfied me..
but then I found a nice plugin for gedit: Rgedit !

it supports split screen with R terminal window (you can also personalize
colour if, like me, do like to
stick with old habits :) ), moreover gedit has a brackets completion and a
brackets highlight plugin which are very useful.

check it out here

http://www.stattler.com/article/using-gedit-or-rgedit-r

simple "send code
to terminal" shortcuts (much simpler than emacs, in my opinion) and nice
interface..give it a try!

/federico


On Fri, Jul 23, 2010 at 2:42 PM, Rainer M Krug  wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> On 23/07/2010 14:17, Alaios wrote:
> > I would like to thank you for your immediate reply.
> > Actually I do not like vim and emacs.. I am trying to find an editor with
> a gui
> > that will work fine in Linux.
> Well - you are missing out with not using emacs + ess - but it is quite
> a learning curve. Despite this:
>
> Try rkward - syntax highlighting and many other nice features.
>
> Another option: eclipse with statet plugin(
> http://www.walware.de/goto/statet)
>
> Cheers,
>
> Rainer
> >
> > One more question. If I am editing a file using my external text editor
> is it
> > possible to execute directly one of the functions that are inside the
> file
> > without executing the source("myfile.R") command first?
> >
> > Best Regards
> > Alex
> >
> >
> >
> > - Original Message 
> > From: Duncan Murdoch 
> > To: alaios 
> > Cc: r-help@r-project.org
> > Sent: Fri, July 23, 2010 2:13:48 PM
> > Subject: Re: [R] Syntax Highlightning and Editor for Linux
> >
> > On 23/07/2010 8:08 AM, alaios wrote:
> >>  Hello to the community .
> >> First post :)
> >> I would like to ask you which text editor do you use in Linux and how
> did
> >> you setup the syntax highlightning?
> >>
> >
> > I don't use Linux, but I think the most popular editors there are vim and
> emacs,
> > the latter with ESS.
> >
> >> one more question is it possible to debug any program in R by inserting
> >> breakpoints?
> >>
> >>
> >
> > Yes, see the setBreakpoint() and trace() functions.
> >
> > Duncan Murdoch
> >
> >> I would like to thank you in advance for your help
> >> Best Regards
> >> Alex
> >>
> >
> > __
> > R-help@r-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.
>
>
> - --
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
> Biology, UCT), Dipl. Phys. (Germany)
>
> Centre of Excellence for Invasion Biology
> Natural Sciences Building
> Office Suite 2039
> Stellenbosch University
> Main Campus, Merriman Avenue
> Stellenbosch
> South Africa
>
> Tel:+33 - (0)9 53 10 27 44
> Cell:   +27 - (0)8 39 47 90 42
> Fax (SA):   +27 - (0)8 65 16 27 82
> Fax (D) :   +49 - (0)3 21 21 25 22 44
> Fax (FR):   +33 - (0)9 58 10 27 44
> email:  rai...@krugs.de
>
> Skype:  RMkrug
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkxJjjMACgkQoYgNqgF2egqmgACeK5OXtqsKvAcK1Pyli6zlLpW6
> ttkAoIzeKgwKeo7cj4oH+jSOr8QMgFFP
> =B7JP
> -END PGP SIGNATURE-
>
> __
> R-help@r-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.


[R] Figures in Latex

2010-07-23 Thread li li
Hi all,
   I want to add 6 plots in the format of 2 columns and 3 rows as one
figure in latex. The plots are in .eps file.
I know how to add 2 plots side by side, but could not figure out how to do
multiple rows.
  I know this may not be the right place to ask such a question. But I do
not know who to ask, so just try my
luck here.
  Thank you in advance.
  Hannah

[[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] legend in R plot

2010-07-23 Thread li li
Thank you all for your kind reply and help.
I changed the legend function  as Mr. Peter Ehlers suggested and
the plots look good.

Thank you again.
 Hannah

2010/7/22 Peter Ehlers 

>  On 2010-07-21 22:06, li li wrote:
>
>> Hi all,
>>   I am have some difficulty with the legend function.
>>   I need to add a legend to describe the different line types in a plot.
>> The
>> legend box is small.
>> It did not include sufficient length of each line type to help distinguish
>> the differnt line types.
>>   Is there a way to fix this.
>>   Thank you
>>  Hannah
>>
>>
> If I understand correctly, you want to have longer
> line segments in your legend. I agree that this is
> sometimes desirable but, with the current code,
> it's not possible - the segment length is hard-coded.
>
> If it matters enough to you, you can easily modify the
> code to achieve your aim: search for the following two
> lines and in each replace the '2' with a greater value,
> say '3'.
>
> First line:
>
>w0 <- w0 + (2 + x.off) * xchar
>
> Second line:
>
>seg.len <- 2
>
> I don't think that this will have any undesirable side
> effects, but I haven't given it much thought. I haven't
> had any problems with this version of legend().
>
>  -Peter Ehlers
>

[[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] start and end times to yes/no in certain intervall

2010-07-23 Thread Allan Engelhardt

I like loops for this kind of thing so here is one:

df<- structure(list(start = c("15:00", "15:00", "15:00", "11:00",
"14:00", "14:00", "15:00", "12:00", "12:00", "12:00", "12:00",
"12:00", "12:00", "12:00", "12:00", "12:00", "12:00", "12:00",
"12:00", "12:00"), end = c("16:00", "16:00", "16:00", "12:00",
"16:00", "15:00", "16:00", "13:00", "13:00", "13:00", "13:00",
"13:00", "13:00", "13:00", "13:00", "13:00", "13:00", "13:00",
"13:00", "13:00")), .Names = c("start", "end"), row.names = c(NA,
20L), class = "data.frame")

duration<- with(df, floor(
  as.numeric(
   difftime(strptime(end, format="%H:%M"),
strptime(start, format="%H:%M"),
units = "hours"

start<- as.integer(substr(df$start, 1, 2))

a<- matrix(FALSE, nrow = NROW(df), ncol = 24,
dimnames = list(1:NROW(df), paste("t", 0:23, sep = "")))
for (i in 1:NROW(df)) {
names<- paste("t", seq(start[i], by = 1L, length.out = duration[i]), sep = 
"")
a[i, names]<- TRUE
}
r<- range(which(apply(a, 2, any)))
a<- a[, r[1]:r[2]]  #  Drop columns we do not need
head(a)
# t11   t12   t13   t14   t15
# 1 FALSE FALSE FALSE FALSE  TRUE
# 2 FALSE FALSE FALSE FALSE  TRUE
# 3 FALSE FALSE FALSE FALSE  TRUE
# 4  TRUE FALSE FALSE FALSE FALSE
# 5 FALSE FALSE FALSE  TRUE  TRUE
# 6 FALSE FALSE FALSE  TRUE FALSE



Hope this helps a little.

Allan


On 23/07/10 11:02, Stefan Uhmann wrote:

Hi List,

I have start and end times of events

structure(list(start = c("15:00", "15:00", "15:00", "11:00",
"14:00", "14:00", "15:00", "12:00", "12:00", "12:00", "12:00",
"12:00", "12:00", "12:00", "12:00", "12:00", "12:00", "12:00",
"12:00", "12:00"), end = c("16:00", "16:00", "16:00", "12:00",
"16:00", "15:00", "16:00", "13:00", "13:00", "13:00", "13:00",
"13:00", "13:00", "13:00", "13:00", "13:00", "13:00", "13:00",
"13:00", "13:00")), .Names = c("start", "end"), row.names = c(NA,
20L), class = "data.frame")

and I would like the data to look like this:


  t9   t10   t11   t12   t13   t14   t15   t16   t17
1  FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
2  FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
3  FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
4  FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
5  FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE
6  FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
7  FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
8  FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
9  FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
10 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE


Which means, that I just get a TRUE for every hour the event was 
taking place. A finishing time of 16:00 means that t16 is FALSE, 
because the event was finished until 16:00; 16:15 as end time would 
result in t16 being TRUE.
It would be nice if the function would add the variables needed (t9 
..) as well and depending on the times put in (no t9 if there is no 
event starting before 10:00).


Thanks for any suggestion,
Stefan

__
R-help@r-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] Midpoint between coordinates

2010-07-23 Thread David Winsemius


On Jul 23, 2010, at 8:58 AM, Mafalda Viana wrote:


The arithmetic mean was my first approach and to nearby points it
doesn't make much difference. However, when the distance between the 2
points gets bigger this is no longer accurate enough. So yes, I was
thinking on spherical geometry, midpoint considering the great circle
distance or similar.


Are you "up" for some searching?

require(sos)
> ???"distance spherical"
found 65 matches;  retrieving 4 pages
2 3 4

On first page of hits the geosphere package says it handles spherical  
geometry. Perhaps the gcIntermediate function:


gcIntermediate {geosphere}
Get intermediate points on a Great Circle inbetween the two points  
used to define the Great Circle

Usage
gcIntermediate(p1, p2, n=50)
Arguments
p1  Longitude/latitude of a single point, in degrees; can be a vector  
of two numbers, a matrix of 2 columns (first one is longitude, second  
is latitude) or a SpatialPoints* object

p2  As above
n  The requested number of points on the Great Circle
---

There is also a geospatial Task View and SIG mailing list that is very  
active.

--
David


Thank you
Mafalda

On 23 July 2010 13:30, David Winsemius  wrote:


On Jul 23, 2010, at 7:13 AM, Mafalda Viana wrote:


Dear R users,

I need to find the coordinates for the point (midpoint) located half
way between two pairs of coordinates (lon1,lat1 and lon2,lat2)
assuming a straight line between them. What would be the best way? I
tried to find an answer in the help archives but without success. I
would greatly appreciate any help.

df<- data.frame(lon1=c(-4.568,-4.3980), lat1=c(59.235,56.369),
lon2=c(-5.123,-4.698), lat2=c(60.258,59.197) )


Wouldn't that just be the arithmetic average of the values? Or to  
you have
some need for a more accurate calculation based on spherical  
geometry?  Or

some thing that will handle some other coordinate weirdness?


df$midlong <- apply(df[,c(1,3)], 1, mean)
df$midlat <- apply(df[,c(2,4)], 1, mean)
df

   lon1   lat1   lon2   lat2 midlong  midlat
1 -4.568 59.235 -5.123 60.258 -4.8455 59.7465
2 -4.398 56.369 -4.698 59.197 -4.5480 57.7830



--

David Winsemius, MD
West Hartford, CT







--
Mafalda Viana
Department of Zoology
School of Natural Sciences
Trinity College Dublin
Dublin 2
Ireland

(+353) (0) 872829850

via...@tcd.ie

http://www.tcd.ie/Zoology/research/research/theoretical


David Winsemius, MD
West Hartford, CT

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


Re: [R] Midpoint between coordinates

2010-07-23 Thread Mafalda Viana
The arithmetic mean was my first approach and to nearby points it
doesn't make much difference. However, when the distance between the 2
points gets bigger this is no longer accurate enough. So yes, I was
thinking on spherical geometry, midpoint considering the great circle
distance or similar.

Thank you
Mafalda

On 23 July 2010 13:30, David Winsemius  wrote:
>
> On Jul 23, 2010, at 7:13 AM, Mafalda Viana wrote:
>
>> Dear R users,
>>
>> I need to find the coordinates for the point (midpoint) located half
>> way between two pairs of coordinates (lon1,lat1 and lon2,lat2)
>> assuming a straight line between them. What would be the best way? I
>> tried to find an answer in the help archives but without success. I
>> would greatly appreciate any help.
>>
>> df<- data.frame(lon1=c(-4.568,-4.3980), lat1=c(59.235,56.369),
>> lon2=c(-5.123,-4.698), lat2=c(60.258,59.197) )
>
> Wouldn't that just be the arithmetic average of the values? Or to you have
> some need for a more accurate calculation based on spherical geometry?  Or
> some thing that will handle some other coordinate weirdness?
>
>> df$midlong <- apply(df[,c(1,3)], 1, mean)
>> df$midlat <- apply(df[,c(2,4)], 1, mean)
>> df
>    lon1   lat1   lon2   lat2 midlong  midlat
> 1 -4.568 59.235 -5.123 60.258 -4.8455 59.7465
> 2 -4.398 56.369 -4.698 59.197 -4.5480 57.7830
>>
> --
>
> David Winsemius, MD
> West Hartford, CT
>
>
>



-- 
Mafalda Viana
Department of Zoology
School of Natural Sciences
Trinity College Dublin
Dublin 2
Ireland

(+353) (0) 872829850

via...@tcd.ie

http://www.tcd.ie/Zoology/research/research/theoretical

__
R-help@r-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] specify heat.colors

2010-07-23 Thread syrvn

Hi,

I use heatmap.2 and heat.colors. Is it possible to specify the colors in
that way that
all values below, for instance, 1.5 should be coloured red, values between
1.5 and 1.7 green
and above 1.7 black?

Many thanks
-- 
View this message in context: 
http://r.789695.n4.nabble.com/specify-heat-colors-tp2300139p2300139.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to get vector of poitions in a vector ?

2010-07-23 Thread Martyn Byng
(1:length(a))[a != 0]

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of vikrant
Sent: 23 July 2010 12:13
To: r-help@r-project.org
Subject: [R] How to get vector of poitions in a vector ?


I have a vector a = c(1,0,0,0,1,0,4,0,0,0)
Now I want to get a vector of positions in a vector a where the value is
non
zero..
How to do it??


-- 
View this message in context:
http://r.789695.n4.nabble.com/How-to-get-vector-of-poitions-in-a-vector-
tp227p227.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.


This e-mail has been scanned for all viruses by Star.\ _...{{dropped:12}}

__
R-help@r-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] Question about a perceived irregularity in R syntax

2010-07-23 Thread Duncan Murdoch

On 23/07/2010 7:14 AM, Duncan Murdoch wrote:

Nordlund, Dan (DSHS/RDA) wrote:
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
>> project.org] On Behalf Of Peter Dalgaard
>> Sent: Thursday, July 22, 2010 3:13 PM
>> To: Pat Schmitz
>> Cc: r-help@r-project.org
>> Subject: Re: [R] Question about a perceived irregularity in R syntax
>>
>> Pat Schmitz wrote:
>> 
>>> Both vector query's can select the values from the data.frame as
>>>   
>> written,
>> 
>>> however in the first form assigning a value to said selected numbers
>>>   
>> fails.
>> 
>>>  Can you explain the reason this fails?

>>>
>>> dat <- data.frame(index = 1:10, Value = c(1:4, NA, 6, NA, 8:10))
>>>
>>> dat$Value[dat$Value == "NA"] <- 1 #Why does this  fails to work,
>>> dat$Value[dat$Value %in% NA] <- 1 #While this does work?
>>>
>>>
>>> #Particularly when str() results in an equivalent class
>>> dat <- data.frame(index = 1:10, Value = c(1:4, NA, 6, NA, 8:10))
>>> str(dat$Value[dat$Value %in% NA])
>>> str(dat$Value[dat$Value == "NA"])
>>>   
>> 1. NA and "NA" are very different things

>> 2. checkout is.na() and its help page
>>
>>
>> 
>
> I also would have suggested is.na to do the replacement.  What surprised me was that 
>
> dat$Value[dat$Value %in% NA] <- 1 
>
> actually worked.  I guess I always assumed that if 
>
>   
>> NA == NA
>> 
> [1] NA

>
> then an attempt to compare NA to elements in a vector would also return NA, 
but not so.
>
>   
>> NA %in% c(1,NA,3)
>> 
> [1] TRUE

>
>
> Learned something new today,

I suspect that's not intentional, though I'm not sure it should be 
fixed.  According to the usual convention the result should be a logical NA.


Oops, not true. The behaviour is clearly documented in ?match:

Exactly what matches what is to some extent a matter of
definition. For all types, ‘NA’ matches ‘NA’ and no other
value. For real and complex values, ‘NaN’ values are regarded
as matching any other ‘NaN’ value, but not matching ‘NA’.

Thanks to Brian Ripley (the author of that paragraph) for pointing this 
out to me. Not sure how I missed it on my first reading, but the fact 
that it preceded my morning coffee might be a contributing factor.


Duncan Murdoch

__
R-help@r-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] model.tables call fails with "Error in inherits(object, "formula")"

2010-07-23 Thread Prof Brian Ripley

The error message actually is

Error in inherits(object, "formula") : object 'frmlc' not found

and it is the omitted-by-you part after the colon that matters: the 
body of model.tables does not have 'frmlc' in its scope.


Here is one approach to using dynamic formulae that works in a lot of 
similar situations:


test <- function(dat) {
frmlc <- as.formula("yield ~ block + Error(N/block)")
aovfit <- eval(substitute(aov(form, dat),list(form=frmlc)))
model.tables(aovfit, "means")
}

written without the pointless empty statements after the semicolons.


On Fri, 23 Jul 2010, Hannes wrote:


Hello,

I noticed that model.tables fails when applied to an aov() fit if called 
inside a function. The problem seems to occur when as.formula is used inside 
a function on a string containing

" + Error( x / y )"

The reason I tried to use as.formula is to generate dynamic calls to aov().
Here is a minimal example illustrating the problem:



## Example

test <- function(dat) {
   frmlb <- "yield ~ block";# WORKS
   aovfit <- aov(as.formula(frmlb), dat);
   print(model.tables(aovfit, "means"));

   frmlc <- "yield ~ block + Error(N/block)";   # DOES NOT WORK
   aovfit <- aov(as.formula(frmlc), dat);
   print(model.tables(aovfit, "means"));
}

utils::data(npk, package="MASS");
frmla <- "yield ~ block + Error(N/block)";   # WORKS
aovfit <- aov(as.formula(frmla), npk);
print(model.tables(aovfit, "means"));
test(npk);

## End of example


Output of sessionInfo():
R version 2.11.1 (2010-05-31)
i386-pc-mingw32

locale:
[1] LC_COLLATE=Finnish_Finland.1252  LC_CTYPE=Finnish_Finland.1252
[3] LC_MONETARY=Finnish_Finland.1252 LC_NUMERIC=C
[5] LC_TIME=Finnish_Finland.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

loaded via a namespace (and not attached):
[1] tools_2.11.1

br Hannes G.

__
R-help@r-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] sink function

2010-07-23 Thread nuncio m
I have the following code to write the output from auto.arima function.  The
issue is not in finding the model but to divert its out put
fit to a file order_fit.txt. code runs but nothing is written to
order_fit.txt
where am I going wrong

library(forecast)
for (i in 1:2) {
filen = paste("file",i,".txt",sep="")
data <- read.table(filen)
dat1 <- data[,1]
xt <- ts(dat1,start=c(1978,11),end=c(2006,12),frequency=12)
#dat1[dat1 == -99.989998] <- NA
if (min(dat1) != max(dat1)){
fit <- auto.arima(xt,D=1)

*sink(file="order_fit.txt")
fit
sink()*

residfit <- residuals(fit)
filenou1 = paste("fileree",i,"_out",".txt",sep="")
residfit
write.table(residfit,filenou1,sep="\t",col.names=FALSE,row.names=FALSE,quote=FALSE)

}else{
*fiit <- "ARIMA(-6,-6,-6)(-6,-6,-6)[12]"
sink(file="order_fit.txt")
fiit
sink()*
filenou1 = paste("fileree",i,"_out",".txt",sep="")
residfit=rep(-99.99,338)
residfit
write.table(residfit,filenou1,sep="\t",col.names=FALSE,row.names=FALSE,quote=FALSE)
rm(data,dat1,residfit,xt)
}
}

-- 
Nuncio.M
Research Scientist
National Center for Antarctic and Ocean research
Head land Sada
Vasco da Gamma
Goa-403804

[[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] Syntax Highlightning and Editor for Linux

2010-07-23 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 23/07/2010 14:17, Alaios wrote:
> I would like to thank you for your immediate reply.
> Actually I do not like vim and emacs.. I am trying to find an editor with a 
> gui 
> that will work fine in Linux.
Well - you are missing out with not using emacs + ess - but it is quite
a learning curve. Despite this:

Try rkward - syntax highlighting and many other nice features.

Another option: eclipse with statet plugin(
http://www.walware.de/goto/statet)

Cheers,

Rainer
> 
> One more question. If I am editing a file using my external text editor is it 
> possible to execute directly one of the functions that are inside the file 
> without executing the source("myfile.R") command first?
> 
> Best Regards
> Alex
> 
> 
> 
> - Original Message 
> From: Duncan Murdoch 
> To: alaios 
> Cc: r-help@r-project.org
> Sent: Fri, July 23, 2010 2:13:48 PM
> Subject: Re: [R] Syntax Highlightning and Editor for Linux
> 
> On 23/07/2010 8:08 AM, alaios wrote:
>>  Hello to the community .
>> First post :)
>> I would like to ask you which text editor do you use in Linux and how did
>> you setup the syntax highlightning?
>>  
> 
> I don't use Linux, but I think the most popular editors there are vim and 
> emacs, 
> the latter with ESS. 
> 
>> one more question is it possible to debug any program in R by inserting
>> breakpoints?
>>
>>  
> 
> Yes, see the setBreakpoint() and trace() functions.
> 
> Duncan Murdoch
> 
>> I would like to thank you in advance for your help
>> Best Regards
>> Alex
>>
> 
> __
> R-help@r-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.


- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Tel:+33 - (0)9 53 10 27 44
Cell:   +27 - (0)8 39 47 90 42
Fax (SA):   +27 - (0)8 65 16 27 82
Fax (D) :   +49 - (0)3 21 21 25 22 44
Fax (FR):   +33 - (0)9 58 10 27 44
email:  rai...@krugs.de

Skype:  RMkrug
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkxJjjMACgkQoYgNqgF2egqmgACeK5OXtqsKvAcK1Pyli6zlLpW6
ttkAoIzeKgwKeo7cj4oH+jSOr8QMgFFP
=B7JP
-END PGP SIGNATURE-

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


Re: [R] How to import simple java/mathematica expression to R

2010-07-23 Thread jim holtman
It would be nice if you could post what the data looks like that you
want to import.  R can import any text file and then you have string
manipulation that you can do to parse it.  So the basic answer is
probably yes, but we do need to understand the format of the data to
give a more precise answer.

On Fri, Jul 23, 2010 at 6:03 AM, Andrey Siver  wrote:
> Hello,
>
> Is it possible to import some (large enough) polynomial expression
> from java (or mathematica) to R as a function?
>
> I found very interesting package rJava but I did not see this feature there.
>
> We used Mathematica as calculation engine for our program with
> statistical calculations and now we want to sell our package to
> customers.
> As we cannot force people to buy the Mathematica only for our program,
> so we are looking for another calculation engine. R is very good
> candidate.
>
> --
> Regards,
>
>    -Andrey
>
> __
> R-help@r-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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@r-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] start and end times to yes/no in certain intervall

2010-07-23 Thread jim holtman
try this:

> char2hr <- function(time){
+ mat <- do.call(rbind, strsplit(time, ":"))
+ mode(mat) <- 'numeric'
+ mat %*% c(1, 1/60)  # convert to hours
+ }
> # convert to hours
> x.hr <- apply(x, 2, char2hr)
> # generate a set of sequences to set values
> x.seq <- apply(x.hr, 1, function(.hr) seq(.hr[1], .hr[2] - 1))
> # create output matrix
> result <- matrix(FALSE, nrow=nrow(x.hr), ncol=max(x.hr) + 1)
> colnames(result) <- sprintf("t%02d", seq(0, length=ncol(result)))
> # set the values
> for (i in seq_along(x.seq)){
+ result[i, x.seq[[i]] + 1] <- TRUE
+ }
> result
t00   t01   t02   t03   t04   t05   t06   t07   t08   t09
t10   t11   t12   t13   t14   t15   t16
 [1,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE FALSE FALSE FALSE  TRUE FALSE
 [2,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE FALSE FALSE FALSE  TRUE FALSE
 [3,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE FALSE FALSE FALSE  TRUE FALSE
 [4,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
 [5,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE
 [6,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
 [7,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE FALSE FALSE FALSE  TRUE FALSE
 [8,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
 [9,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
[10,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
[11,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
[12,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
[13,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
[14,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
[15,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
[16,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
[17,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
[18,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
[19,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
[20,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
>
>
>

you can add the limits for the number of columns that you want.

On Fri, Jul 23, 2010 at 6:02 AM, Stefan Uhmann
 wrote:
> Hi List,
>
> I have start and end times of events
>
> structure(list(start = c("15:00", "15:00", "15:00", "11:00",
> "14:00", "14:00", "15:00", "12:00", "12:00", "12:00", "12:00",
> "12:00", "12:00", "12:00", "12:00", "12:00", "12:00", "12:00",
> "12:00", "12:00"), end = c("16:00", "16:00", "16:00", "12:00",
> "16:00", "15:00", "16:00", "13:00", "13:00", "13:00", "13:00",
> "13:00", "13:00", "13:00", "13:00", "13:00", "13:00", "13:00",
> "13:00", "13:00")), .Names = c("start", "end"), row.names = c(NA,
> 20L), class = "data.frame")
>
> and I would like the data to look like this:
>
>>      t9   t10   t11   t12   t13   t14   t15   t16   t17
>> 1  FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
>> 2  FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
>> 3  FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
>> 4  FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
>> 5  FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE
>> 6  FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
>> 7  FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
>> 8  FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
>> 9  FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
>> 10 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
>
> Which means, that I just get a TRUE for every hour the event was taking
> place. A finishing time of 16:00 means that t16 is FALSE, because the event
> was finished until 16:00; 16:15 as end time would result in t16 being TRUE.
> It would be nice if the function would add the variables needed (t9 ..) as
> well and depending on the times put in (no t9 if there is no event starting
> before 10:00).
>
> Thanks for any suggestion,
> Stefan
>
> __
> R-help@r-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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 51

  1   2   >