Re: [R] output without quotes

2010-07-09 Thread AC Del Re
Wonderful, David! Thank you much for your help on this.

AC

On Fri, Jul 9, 2010 at 6:49 PM, David Winsemius wrote:

>
> On Jul 9, 2010, at 7:19 PM, Erik Iverson wrote:
>
>  AC Del Re wrote:
>>
>>> Hi David,
>>> I don't have the function in order yet but the names will be going into
>>> the
>>> formula, e.g.,
>>> in body of function:
>>> {
>>>  ...etc
>>>  out <- lm( y ~ TEMP)  # where TEMP = mod1+mod2 (from previous post)
>>>  return(out)
>>> }
>>>
>>
>> So why not just pass the formula to the function?
>>
>
> Exactly.
>
> ?formula
>
>
> mod1 <- rnorm(20, 10, 2)
> mod2 <- rnorm(20, 5, 1); y=mod1+mod2+rnorm(20)
> dat <- data.frame(y, mod1, mod2)
>
>
> # collapsing the colnames to 'mod1+mod2'
> temp <- paste(names(dat), collapse="+")
> form <- formula(paste("y ~",temp))
>
> newfunc <- function(form, datfrm ) lm(form, data=datfrm)
>
> newfunc(form=form, datfrm=dat)
>
> ### output ###
> Call:
> lm(formula = form, data = datfrm)
>
> Coefficients:
> (Intercept) mod1 mod2
> -2.4721.1571.148
>
>
> --
> 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] interpretation of svm models with the e1071 package

2010-07-09 Thread Noah Silverman

Steve,

Couldn't he also just use the decision.value property to see the 
equivilent of t(x) %*% b for each row?


-N

On 7/9/10 7:11 PM, Steve Lianoglou wrote:

Hi,

On Fri, Jul 9, 2010 at 12:15 PM, manuel.martin
  wrote:
   

Dear all,

after having calibrated a svm model through the svm() command of the e1071
package, is there a way to
i) represent the modeled relationships between the y and X variables
(response variable vs. predictors)?
 

Can you explain a bit more ... how do you want them represented?

   

ii) rank the influence of the predictors used in the model?
 

One technique that's often/sometimes used is to calculate the SVM's W
vector by using the support vectors along with their learned
weights/alphas.

This comes up every now and again. Here's an older post explaining how
you might do that with the svm model from e1071:

http://article.gmane.org/gmane.comp.lang.r.general/158272/match=w+b+vector+svr

Hope that helps.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)

2010-07-09 Thread Ravi Varadhan
Hi,

The absolute function stopping criterion is not meant for any positive 
objective function.  It is meant for functions whose minimum is 0.  Here is 
what David Gay's documentation from PORT says:

"6 - absolute function convergence: |f (x)| <  V(AFCTOL) = V(31). This test is 
only of interest in
problems where f (x) = 0 means a ‘‘perfect fit’’, such as nonlinear 
least-squares problems."

For example, let us try a positive objective function:

> nlminb( obj = function(x) x^2 + 1, start=1, lower=-Inf, upper=Inf, 
> control=list(trace=TRUE)) 
  0: 2.000:  1.0
  1: 1.000:  0.0
  2: 1.000:  0.0
$par
[1] 0

$objective
[1] 1

$convergence
[1] 0

$message
[1] "relative convergence (4)"

$iterations
[1] 2

$evaluations
function gradient 
   32 


Here the absolute function criterion does not kicks in.  


Now let us try a function whose minimum value is 0.

> nlminb( obj = function(x) x^2, start=6, grad=function(x) 2*x, lower=-Inf, 
> upper=Inf, control=list(trace=TRUE) )
  0: 36.00:  6.0
  1: 4.000:  2.0
  2: 4.9303807e-32: 2.22045e-16
$par
[1] 2.220446e-16

$objective
[1] 4.930381e-32

$convergence
[1] 0

$message
[1] "absolute function convergence (6)"

$iterations
[1] 2

$evaluations
function gradient 
   43 

We see that convergence is attained and that the stoppage is due to absolute 
function criterion.  

Suppose, we now set abs.tol=0:

> nlminb( obj = function(x) x^2, start=6, grad=function(x) 2*x, lower=-Inf, 
> upper=Inf, control=list(trace=TRUE, abs.tol=0) )
  0: 36.00:  6.0
  1: 4.000:  2.0
  2: 4.9303807e-32: 2.22045e-16
  3: 2.4308653e-63: -4.93038e-32
  4: 2.9962729e-95: -5.47382e-48
  5:1.4772766e-126: 1.21543e-63
  6:1.8208840e-158: 1.34940e-79
  7:8.9776511e-190: -2.99627e-95
  8:1.1065809e-221: -3.32653e-111
  9:5.4558652e-253: 7.38638e-127
 10:6.7248731e-285: 8.20053e-143
 11:3.3156184e-316: -1.82088e-158
 12: 0.000: -2.02159e-174
 13: 0.000: -2.02159e-174
$par
[1] -2.021587e-174

$objective
[1] 0

$convergence
[1] 0

$message
[1] "X-convergence (3)"

$iterations
[1] 13

$evaluations
function gradient 
  15   13 

>
Now, we see that it takes a while to stop, eventhough it is clear that 
convergence has been attained after 2 iterations.  This demonstrates the need 
for the absolute function criterion for obj functions whose minimum is exactly 
0.  Although, there is nothing wrong with setting abs.tol=0, except for some 
loss of computational efficiency.  

Now, let us get back to Matthew' example:

> nlminb( obj = function(x) x, start=1, lower=-2, upper=2, 
> control=list(trace=TRUE)) 
  0: 1.000:  1.0
  1: 0.000:  0.0
$par
[1] 0

$objective
[1] 0

$convergence
[1] 0

$message
[1] "absolute function convergence (6)"

$iterations
[1] 1

$evaluations
function gradient 
   22 

> nlminb( obj = function(x) x, start=1, lower=-2, upper=2, 
> control=list(trace=TRUE, abs.tol=0)) 
  0: 1.000:  1.0
  1: 0.000:  0.0
  2:-2.000: -2.0
  3:-2.000: -2.0
$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient 
   33 


Thus it is evident that setting abs.tol=0 is a reasonable, general solution for 
functions whose minimum value is non-zero, because it protects against 
premature termination at iteration `n' whenever |f(x_n)| < abs.tol.  The only 
limitation being that of loss of efficiency in problems where f(x*) = 0. where 
x* is the local minimum.

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


- Original Message -
From: Duncan Murdoch 
Date: Friday, July 9, 2010 6:54 pm
Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)
To: Matthew Killeya 
Cc: Peter Ehlers , Ravi Varadhan , 
r-help@r-project.org, ba...@stat.wisc.edu


> On 09/07/2010 6:09 PM, Matthew Killeya wrote:
>  >Yes clearly a bug... there are numerous variations ... problem seems 
> to be
>  >for a linear function whenever the first function valuation is 1.
>  >  
>  
>  Not at all.  You can get the same problem on a quadratic that happens 
> to have a zero at an inconvenient place, e.g.
>  
>  nlminb( obj = function(x) x^2-25, start=6, lower=-Inf, upper=Inf )
>  
>  Ravi's workaround of setting the abs.tol to zero fixes this example, 
> but I think it's pretty clear from the documentation that the whole 
> thing was designed for positive objective functions, so I wouldn't 
> count on his workaround solving all the problems.
>  
>  Duncan Murdoch
>  
>  
>  >e.g. two more examples:
>  > nlminb( obj = function(x) x+1, start=0, lower=-Inf, upper=Inf )
>  > nlminb( obj = fu

Re: [R] Compress string memCompress/Decompress

2010-07-09 Thread Erik Wright
Hi Matt,

This works great, thanks!

At first I got an error message saying BLOB is not implemented in RSQLite.  
When I updated to the latest version it worked.

Is there any reason the string needs to be stored as type BLOB?  It seems to 
work the same when I swap "BLOB" with "TEXT" in the CREATE TABLE command.

Thanks again!,
Erik



On Jul 9, 2010, at 3:21 PM, Matt Shotwell wrote:

> Erik, 
> 
> Can you store the data as a blob? For example:
> 
>> #create string, compress with gzip, convert to SQLite blob string
>> string <- "gzip this string, store as blob in SQLite database"
>> string.gz <- memCompress(string, type="gzip")
>> string.sqlite <- paste("x'",paste(string.gz,collapse=""),"'",sep="")
> 
>> #create database and table with a BLOB column
>> library(RSQLite)
> Loading required package: DBI
>> con <- dbConnect(dbDriver("SQLite"), "compress.sqlite")
>> dbGetQuery(con, "CREATE TABLE Compress (id INTEGER, data BLOB);")
> NULL
> 
>> #insert the string as a blob
>> query <- paste("INSERT INTO Compress (id, data) VALUES (1, ", 
> + string.sqlite, ");", sep="")
>> dbGetQuery(con, query)
> NULL
> 
>> #recover the blob, decompress, and convert back to a string
>> result <- dbGetQuery(con, "SELECT data FROM Compress;")
>> string.gz <- result[[1]][[1]]
>> string <- memDecompress(string.gz, type="gzip")
>> rawToChar(string)
> [1] "gzip this string, store as blob in SQLite database"
> 
> 
> -Matt
> 
> 
> 
> On Fri, 2010-07-09 at 12:51 -0400, Erik Wright wrote:
>> Hello,
>> 
>> I would like to compress a long string (character vector), store the 
>> compressed string in the text field of a SQLite database (using RSQLite), 
>> and then load the text back into memory and decompress it back into the the 
>> original string.  My character vector can be compressed considerably using 
>> standard gzip/bzip2 compression.  In theory it should be much faster for me 
>> to compress/decompress a long string than to write the whole string to the 
>> hard drive and then read it back (not to mention the saved hard drive space).
>> 
>> I have tried accomplishing this task using memCompress() and memDecompress() 
>> without success.  It seems memCompress can only convert a character vector 
>> to raw type which cannot be treated as a string.  Does anyone have ideas on 
>> how I can go about doing this, especially using the standard base packages?
>> 
>> Thanks!,
>> Erik
>> 
>> 
>>> sessionInfo()
>> R version 2.11.0 (2010-04-22) 
>> x86_64-apple-darwin9.8.0 
>> 
>> locale:
>> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>> 
>> attached base packages:
>> [1] stats graphics  grDevices utils datasets  methods   base 
>> 
>> loaded via a namespace (and not attached):
>> [1] tools_2.11.0
>> 
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> -- 
> Matthew S. Shotwell
> Graduate Student
> Division of Biostatistics and Epidemiology
> Medical University of South Carolina
> http://biostatmatt.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] interpretation of svm models with the e1071 package

2010-07-09 Thread Steve Lianoglou
Hi,

On Fri, Jul 9, 2010 at 12:15 PM, manuel.martin
 wrote:
> Dear all,
>
> after having calibrated a svm model through the svm() command of the e1071
> package, is there a way to
> i) represent the modeled relationships between the y and X variables
> (response variable vs. predictors)?

Can you explain a bit more ... how do you want them represented?

> ii) rank the influence of the predictors used in the model?

One technique that's often/sometimes used is to calculate the SVM's W
vector by using the support vectors along with their learned
weights/alphas.

This comes up every now and again. Here's an older post explaining how
you might do that with the svm model from e1071:

http://article.gmane.org/gmane.comp.lang.r.general/158272/match=w+b+vector+svr

Hope that helps.

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Function similar to combine.levels in Hmisc package

2010-07-09 Thread Frank E Harrell Jr

On 07/09/2010 05:33 PM, Saeed Abu Nimeh wrote:

Is there a function similar to combine.levels ( in the Hmisc package)
that combines the levels of factors, but not based on their frequency.
Alternatively, I am looking into using the significance of the dummy
variables of factors based on their Pr(>|t|) value using the linear
model, then deleting the non-significant levels. Any other
suggestions?
Thanks,
Saeed


That is not a valid statistical procedure.  You will not have the 
correct d.f. in the final F test.


Frank

--
Frank E Harrell Jr   Professor and ChairmanSchool of Medicine
 Department of Biostatistics   Vanderbilt University

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] String truncate

2010-07-09 Thread jd6688

Thanks so lot
-- 
View this message in context: 
http://r.789695.n4.nabble.com/String-truncate-tp2284045p2284069.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] String truncate

2010-07-09 Thread jd6688

Thanks this works

On Fri, Jul 9, 2010 at 4:32 PM, Wu Gong [via R] <
ml-node+2284062-824667456-312...@n4.nabble.com
> wrote:

> Do you mean substring?
>
>  sub(".txt","", "mytest.txt")
> A R learner.
>
>
> --
> View message @
> http://r.789695.n4.nabble.com/String-truncate-tp2284045p2284062.html
> To unsubscribe from String truncate, click here< (link removed) =>.
>
>
>

-- 
View this message in context: 
http://r.789695.n4.nabble.com/String-truncate-tp2284045p2284068.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

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


[R] String truncate

2010-07-09 Thread jd6688

one string named as: mytest.txt

how can I remove the .txt and return the mytest only.

i tried split substr, and grep didn't work it out, 

Thanks so lot
-- 
View this message in context: 
http://r.789695.n4.nabble.com/String-truncate-tp2284045p2284045.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] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)

2010-07-09 Thread Matthew Killeya
And further to those two:

nlminb( obj = function(x) 2*(x+3), start=-2, lower=-Inf, upper=Inf )


On 9 July 2010 23:09, Matthew Killeya  wrote:

> Yes clearly a bug... there are numerous variations ... problem seems to be
> for a linear function whenever the first function valuation is 1.
>
> e.g. two more examples:
>  nlminb( obj = function(x) x+1, start=0, lower=-Inf, upper=Inf )
>  nlminb( obj = function(x) x+2, start=-1, lower=-Inf, upper=Inf )
>
> (I wasn't sure where best to report a bug, so emailed the help list)
>
> On 9 July 2010 22:10, Peter Ehlers  wrote:
>
>> Actually, it looks like any value other than 1.0
>> (and in (lower, upper)) for start will work.
>>
>>  -Peter Ehlers
>>
>>
>> On 2010-07-09 14:45, Ravi Varadhan wrote:
>>
>>> Setting abs.tol = 0 works!  This turns-off the absolute function
>>> convergence
>>> criterion.
>>>
>>>
>>>  nlminb( objective=function(x) x, start=1, lower=-2, upper=2,

>>> control=list(abs.tol=0))
>>> $par
>>> [1] -2
>>>
>>> $objective
>>> [1] -2
>>>
>>> $convergence
>>> [1] 0
>>>
>>> $message
>>> [1] "both X-convergence and relative convergence (5)"
>>>
>>> $iterations
>>> [1] 3
>>>
>>> $evaluations
>>> function gradient
>>>33
>>>
>>>
>>> This is clearly a bug.
>>>
>>>
>>> Ravi.
>>>
>>> -Original Message-
>>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
>>> On
>>> Behalf Of Ravi Varadhan
>>> Sent: Friday, July 09, 2010 4:42 PM
>>> To: 'Duncan Murdoch'; 'Matthew Killeya'
>>> Cc: r-help@r-project.org; ba...@stat.wisc.edu
>>> Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version
>>> 2.11.1)
>>>
>>> Duncan, `nlminb' is not intended for non-negative functions only.  There
>>> is
>>> indeed something strange happening in the algorithm!
>>>
>>> start<- 1.0 # converges to wrong minimum
>>>
>>> startp<- 1.0 + .Machine$double.eps  # correct
>>>
>>> startm<- 1.0 - .Machine$double.eps  # correct
>>>
>>>  nlminb( objective=obj, start=start, lower=-2, upper=2)

>>> $par
>>> [1] 0
>>>
>>> $objective
>>> [1] 0
>>>
>>> $convergence
>>> [1] 0
>>>
>>> $message
>>> [1] "absolute function convergence (6)"
>>>
>>> $iterations
>>> [1] 1
>>>
>>> $evaluations
>>> function gradient
>>>22
>>>
>>>
 nlminb( objective=obj, start=startp, lower=-2, upper=2)

>>> $par
>>> [1] -2
>>>
>>> $objective
>>> [1] -2
>>>
>>> $convergence
>>> [1] 0
>>>
>>> $message
>>> [1] "both X-convergence and relative convergence (5)"
>>>
>>> $iterations
>>> [1] 3
>>>
>>> $evaluations
>>> function gradient
>>>33
>>>
>>>
 nlminb( objective=obj, start=startm, lower=-2, upper=2)

>>> $par
>>> [1] -2
>>>
>>> $objective
>>> [1] -2
>>>
>>> $convergence
>>> [1] 0
>>>
>>> $message
>>> [1] "both X-convergence and relative convergence (5)"
>>>
>>> $iterations
>>> [1] 3
>>>
>>> $evaluations
>>> function gradient
>>>33
>>>
>>>
>>>  From the convergence message the `absolute function convergence' seems
 to

>>> be
>>> the culprit, although I do not understand why that stopping criterion is
>>> becoming effective, when the algorithm is started at x=1, but not at any
>>> other values.  The documentation in IPORT makes it clear that this
>>> criterion
>>> is effective only for functions where f(x*) = 0, where x* is a local
>>> minimum.  In this example, x=0 is not a local minimum for f(x), so that
>>> criterion should not apply.
>>>
>>>
>>> Ravi.
>>>
>>>
>>> -Original Message-
>>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
>>> On
>>> Behalf Of Duncan Murdoch
>>> Sent: Friday, July 09, 2010 3:45 PM
>>> To: Matthew Killeya
>>> Cc: r-help@r-project.org; ba...@stat.wisc.edu
>>> Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version
>>> 2.11.1)
>>>
>>> On 09/07/2010 10:37 AM, Matthew Killeya wrote:
>>>
  nlminb( obj = function(x) x, start=1, lower=-Inf, upper=Inf )


>>> If you read the PORT documentation carefully, you'll see that their
>>> convergence criteria are aimed at minimizing positive functions.  (They
>>> never state this explicitly, as far as I can see.)  So one stopping
>>> criterion is that |f(x)|<  abs.tol, and that's what it found for you.  I
>>> don't know if there's a way to turn this off.
>>>
>>> Doug or Deepayan, do you know if nlminb can be made to work on functions
>>> that go negative?
>>>
>>> Duncan Murdoch
>>>
>>>  $par
 [1] 0

 $objective
 [1] 0

 $convergence
 [1] 0

 $message
 [1] "absolute function convergence (6)"

 $iterations
 [1] 1

 $evaluations
 function gradient
22

[[alternative HTML version deleted]]


>

[[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, sel

Re: [R] stl function

2010-07-09 Thread kateg

Hi there, 

I tried the code that was sent. Thanks a lot.  It doesn't seem to work. 

Here is what I'm working with...


inc<-ts(incdat[,2], start=1968.000, freq=12)
par(mfrow=c(1,2))
plot(stl(log(inc), s.window="periodic"))

-- 
View this message in context: 
http://r.789695.n4.nabble.com/stl-function-tp2283891p2284002.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] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)

2010-07-09 Thread Matthew Killeya
Yes clearly a bug... there are numerous variations ... problem seems to be
for a linear function whenever the first function valuation is 1.

e.g. two more examples:
 nlminb( obj = function(x) x+1, start=0, lower=-Inf, upper=Inf )
 nlminb( obj = function(x) x+2, start=-1, lower=-Inf, upper=Inf )

(I wasn't sure where best to report a bug, so emailed the help list)

On 9 July 2010 22:10, Peter Ehlers  wrote:

> Actually, it looks like any value other than 1.0
> (and in (lower, upper)) for start will work.
>
>  -Peter Ehlers
>
>
> On 2010-07-09 14:45, Ravi Varadhan wrote:
>
>> Setting abs.tol = 0 works!  This turns-off the absolute function
>> convergence
>> criterion.
>>
>>
>>  nlminb( objective=function(x) x, start=1, lower=-2, upper=2,
>>>
>> control=list(abs.tol=0))
>> $par
>> [1] -2
>>
>> $objective
>> [1] -2
>>
>> $convergence
>> [1] 0
>>
>> $message
>> [1] "both X-convergence and relative convergence (5)"
>>
>> $iterations
>> [1] 3
>>
>> $evaluations
>> function gradient
>>33
>>
>>
>> This is clearly a bug.
>>
>>
>> Ravi.
>>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
>> On
>> Behalf Of Ravi Varadhan
>> Sent: Friday, July 09, 2010 4:42 PM
>> To: 'Duncan Murdoch'; 'Matthew Killeya'
>> Cc: r-help@r-project.org; ba...@stat.wisc.edu
>> Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version
>> 2.11.1)
>>
>> Duncan, `nlminb' is not intended for non-negative functions only.  There
>> is
>> indeed something strange happening in the algorithm!
>>
>> start<- 1.0 # converges to wrong minimum
>>
>> startp<- 1.0 + .Machine$double.eps  # correct
>>
>> startm<- 1.0 - .Machine$double.eps  # correct
>>
>>  nlminb( objective=obj, start=start, lower=-2, upper=2)
>>>
>> $par
>> [1] 0
>>
>> $objective
>> [1] 0
>>
>> $convergence
>> [1] 0
>>
>> $message
>> [1] "absolute function convergence (6)"
>>
>> $iterations
>> [1] 1
>>
>> $evaluations
>> function gradient
>>22
>>
>>
>>> nlminb( objective=obj, start=startp, lower=-2, upper=2)
>>>
>> $par
>> [1] -2
>>
>> $objective
>> [1] -2
>>
>> $convergence
>> [1] 0
>>
>> $message
>> [1] "both X-convergence and relative convergence (5)"
>>
>> $iterations
>> [1] 3
>>
>> $evaluations
>> function gradient
>>33
>>
>>
>>> nlminb( objective=obj, start=startm, lower=-2, upper=2)
>>>
>> $par
>> [1] -2
>>
>> $objective
>> [1] -2
>>
>> $convergence
>> [1] 0
>>
>> $message
>> [1] "both X-convergence and relative convergence (5)"
>>
>> $iterations
>> [1] 3
>>
>> $evaluations
>> function gradient
>>33
>>
>>
>>  From the convergence message the `absolute function convergence' seems to
>>>
>> be
>> the culprit, although I do not understand why that stopping criterion is
>> becoming effective, when the algorithm is started at x=1, but not at any
>> other values.  The documentation in IPORT makes it clear that this
>> criterion
>> is effective only for functions where f(x*) = 0, where x* is a local
>> minimum.  In this example, x=0 is not a local minimum for f(x), so that
>> criterion should not apply.
>>
>>
>> Ravi.
>>
>>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
>> On
>> Behalf Of Duncan Murdoch
>> Sent: Friday, July 09, 2010 3:45 PM
>> To: Matthew Killeya
>> Cc: r-help@r-project.org; ba...@stat.wisc.edu
>> Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version
>> 2.11.1)
>>
>> On 09/07/2010 10:37 AM, Matthew Killeya wrote:
>>
>>>  nlminb( obj = function(x) x, start=1, lower=-Inf, upper=Inf )
>>>
>>>
>> If you read the PORT documentation carefully, you'll see that their
>> convergence criteria are aimed at minimizing positive functions.  (They
>> never state this explicitly, as far as I can see.)  So one stopping
>> criterion is that |f(x)|<  abs.tol, and that's what it found for you.  I
>> don't know if there's a way to turn this off.
>>
>> Doug or Deepayan, do you know if nlminb can be made to work on functions
>> that go negative?
>>
>> Duncan Murdoch
>>
>>  $par
>>> [1] 0
>>>
>>> $objective
>>> [1] 0
>>>
>>> $convergence
>>> [1] 0
>>>
>>> $message
>>> [1] "absolute function convergence (6)"
>>>
>>> $iterations
>>> [1] 1
>>>
>>> $evaluations
>>> function gradient
>>>22
>>>
>>>[[alternative HTML version deleted]]
>>>
>>>

[[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] a question about using the sensitivity package

2010-07-09 Thread Jiang, Yueyang
Hi,

I'm using the sensitivity package to calculate the sobol indices. The case is 
that I have 13 parameter and each one has 1000 samples and my model result is a 
vector having 1000 values (based on the 1000 sample simulation).
I just wonder how to use the sobol function, the pdf looks straightforward, but 
actually it is difficult to use. 

In the sobol function, it has X1 and X2, what are they? How can I organize my 
parameter sample matrix (1000 by 13) and model result (1000 by 1) in the sobol 
function? 

Could some one help me for this question?

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


Re: [R] R crashes with large vectors

2010-07-09 Thread Ben Bolker
Jeremie Smaga  4ecap.com> writes:

> 
> Good afternoon,
> 
> I have been experiencing a lot of crashes working with large vectors in R.
> 
> Specifically, I am using XTS of length of minimum 120k elements.
> 
> My problem is that I cannot display the vector (otherwise R crashes), I
> cannot plot it either (otherwise R crashes). That could be solved by
> reducing the amount of points.
> 
> However, I have been performing some statistical opreations on is and even
> sd(myXTS) crashes R.
> 
> By "crashes", I mean shuts down without any warning whatsoever.
> 
> I use R 2.11.1 (64).
> 
> Has anyone had the same kind of problem?
> 
> Can we solve this?


  You need to provide a reproducible example, or as nearly reproducible
as possible.  You need to provide more information about your system
(Windows?) -- the results of sessionInfo() would help.

  For example, I have no problem taking the standard deviation
of a million-element vector:

> set.seed(1001)
> sd(runif(1e6))
[1] 0.2884210
> sessionInfo()
R version 2.11.1 (2010-05-31) 
i486-pc-linux-gnu 

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C  
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C 
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C   

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

  what happens on your system?



  

  sd(

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] apply is slower than for loop?

2010-07-09 Thread Gene Leynes
I should add that I'm using R 2.10.1 on a Windows 7 machine, thanks!

On Fri, Jul 9, 2010 at 3:11 PM, Gene Leynes

> wrote:

> I thought the "apply" functions are faster than for loops, but my most
> recent test shows that apply actually takes a significantly longer than a
> for loop.  Am I missing something?
>
> It doesn't matter much if I do column wise calculations rather than row
> wise
>
> ## Example of how apply is SLOWER than for loop:
>
> #rm(list=ls())
>
> ## DEFINE VARIABLES
> mu=0.05 ; sigma=0.20 ; dt=.25 ; T=50 ; sims=1e5
> timesteps = T/dt
>
> ## MAKE PHI AND DS
> phi = matrix(rnorm(timesteps*sims), nrow=sims, ncol=timesteps)
> ds = mu*dt + sigma * sqrt(dt) * phi
>
> ## USE APPLY TO CALCULATE ROWWISE CUMULATIVE PRODUCT
> system.time(y1 <- apply(1+ds, 1, cumprod))
> ## UNTRANSFORM Y1, BECAUSE ROW APPLY FLIPS THE MATRIX
> y1=t(y1)
>
> ## USE FOR LOOP TO CALCULATE ROWWISE CUMULATIVE PRODUCT
> y2=matrix(NA,nrow(ds),ncol(ds))
> system.time(
> for (i in 1:nrow(ds)){
> y2[i,]<-cumprod(1+ds[i,])
> }
> )
>
> ## COMPARE RESULTS TO MAKE SURE THEY DID THE SAME THING
> str(y1)
> str(y2)
> all(y1==y2)
>
>
>
>
>
>
>
>

[[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] output without quotes

2010-07-09 Thread David Winsemius


On Jul 9, 2010, at 7:19 PM, Erik Iverson wrote:


AC Del Re wrote:

Hi David,
I don't have the function in order yet but the names will be going  
into the

formula, e.g.,
in body of function:
 {
 ...etc
 out <- lm( y ~ TEMP)  # where TEMP = mod1+mod2 (from previous post)
 return(out)
}


So why not just pass the formula to the function?


Exactly.

?formula

mod1 <- rnorm(20, 10, 2)
mod2 <- rnorm(20, 5, 1); y=mod1+mod2+rnorm(20)
dat <- data.frame(y, mod1, mod2)

# collapsing the colnames to 'mod1+mod2'
temp <- paste(names(dat), collapse="+")
form <- formula(paste("y ~",temp))

newfunc <- function(form, datfrm ) lm(form, data=datfrm)

newfunc(form=form, datfrm=dat)

### output ###
Call:
lm(formula = form, data = datfrm)

Coefficients:
(Intercept) mod1 mod2
 -2.4721.1571.148

--
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] output without quotes

2010-07-09 Thread Erik Iverson

AC Del Re wrote:

Hi David,

I don't have the function in order yet but the names will be going into the
formula, e.g.,

in body of function:

  {
  ...etc
  out <- lm( y ~ TEMP)  # where TEMP = mod1+mod2 (from previous post)
  return(out)
}



So why not just pass the formula to the function?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] output without quotes

2010-07-09 Thread AC Del Re
Hi David,

I don't have the function in order yet but the names will be going into the
formula, e.g.,

in body of function:

  {
  ...etc
  out <- lm( y ~ TEMP)  # where TEMP = mod1+mod2 (from previous post)
  return(out)
}


Thanks,

AC

On Fri, Jul 9, 2010 at 3:20 PM, David Winsemius wrote:

>
> On Jul 9, 2010, at 3:51 PM, AC Del Re wrote:
>
>  Hi All,
>>
>> I am interested in printing column names without quotes and am struggling
>> to
>> do it properly. The tough part is that I am interested in using these
>> column
>> names for a function within a function (e.g., lm() within a wrapper
>> function). Therefore, cat() doesnt seem appropriate
>>
>
>  and print() is not what I need. Ideas?
>>
>
> My idea is that you need to show the code you hope to write so that the
> appropriate language elements can be constructed. If it's going into a
> formula there might be one answer whereas if it's going to be used to access
> columns in a subset expression it may be another method.
>
>
>
>> # sample data
>> mod1 <- rnorm(20, 10, 2)
>> mod2 <- rnorm(20, 5, 1)
>> dat <- data.frame(mod1, mod2)
>>
>> # collapsing the colnames to 'mod1+mod2'
>> temp <- paste(names(dat), collapse="+")
>>
>> temp  # this gives quotes
>> print(temp, quote = FALSE)  # no quotes but includes [1]
>>
>> # need the output like this (no quotes & no [1]):mod1+mod2
>>
>
> Which cat _would_ print on the device or file but it not return anything to
> the interpreter for further evaluation.
> --
> 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] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)

2010-07-09 Thread Duncan Murdoch

On 09/07/2010 6:09 PM, Matthew Killeya wrote:

Yes clearly a bug... there are numerous variations ... problem seems to be
for a linear function whenever the first function valuation is 1.
  


Not at all.  You can get the same problem on a quadratic that happens to 
have a zero at an inconvenient place, e.g.


nlminb( obj = function(x) x^2-25, start=6, lower=-Inf, upper=Inf )

Ravi's workaround of setting the abs.tol to zero fixes this example, but 
I think it's pretty clear from the documentation that the whole thing 
was designed for positive objective functions, so I wouldn't count on 
his workaround solving all the problems.


Duncan Murdoch



e.g. two more examples:
 nlminb( obj = function(x) x+1, start=0, lower=-Inf, upper=Inf )
 nlminb( obj = function(x) x+2, start=-1, lower=-Inf, upper=Inf )

(I wasn't sure where best to report a bug, so emailed the help list)

On 9 July 2010 22:10, Peter Ehlers  wrote:

  

Actually, it looks like any value other than 1.0
(and in (lower, upper)) for start will work.

 -Peter Ehlers


On 2010-07-09 14:45, Ravi Varadhan wrote:



Setting abs.tol = 0 works!  This turns-off the absolute function
convergence
criterion.


 nlminb( objective=function(x) x, start=1, lower=-2, upper=2,
  
control=list(abs.tol=0))

$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient
   33


This is clearly a bug.


Ravi.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On
Behalf Of Ravi Varadhan
Sent: Friday, July 09, 2010 4:42 PM
To: 'Duncan Murdoch'; 'Matthew Killeya'
Cc: r-help@r-project.org; ba...@stat.wisc.edu
Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version
2.11.1)

Duncan, `nlminb' is not intended for non-negative functions only.  There
is
indeed something strange happening in the algorithm!

start<- 1.0 # converges to wrong minimum

startp<- 1.0 + .Machine$double.eps  # correct

startm<- 1.0 - .Machine$double.eps  # correct

 nlminb( objective=obj, start=start, lower=-2, upper=2)
  
$par

[1] 0

$objective
[1] 0

$convergence
[1] 0

$message
[1] "absolute function convergence (6)"

$iterations
[1] 1

$evaluations
function gradient
   22


  

nlminb( objective=obj, start=startp, lower=-2, upper=2)



$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient
   33


  

nlminb( objective=obj, start=startm, lower=-2, upper=2)



$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient
   33


 From the convergence message the `absolute function convergence' seems to
  
be

the culprit, although I do not understand why that stopping criterion is
becoming effective, when the algorithm is started at x=1, but not at any
other values.  The documentation in IPORT makes it clear that this
criterion
is effective only for functions where f(x*) = 0, where x* is a local
minimum.  In this example, x=0 is not a local minimum for f(x), so that
criterion should not apply.


Ravi.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On
Behalf Of Duncan Murdoch
Sent: Friday, July 09, 2010 3:45 PM
To: Matthew Killeya
Cc: r-help@r-project.org; ba...@stat.wisc.edu
Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version
2.11.1)

On 09/07/2010 10:37 AM, Matthew Killeya wrote:

  

 nlminb( obj = function(x) x, start=1, lower=-Inf, upper=Inf )




If you read the PORT documentation carefully, you'll see that their
convergence criteria are aimed at minimizing positive functions.  (They
never state this explicitly, as far as I can see.)  So one stopping
criterion is that |f(x)|<  abs.tol, and that's what it found for you.  I
don't know if there's a way to turn this off.

Doug or Deepayan, do you know if nlminb can be made to work on functions
that go negative?

Duncan Murdoch

 $par
  

[1] 0

$objective
[1] 0

$convergence
[1] 0

$message
[1] "absolute function convergence (6)"

$iterations
[1] 1

$evaluations
function gradient
   22

   [[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] Function similar to combine.levels in Hmisc package

2010-07-09 Thread Saeed Abu Nimeh
Is there a function similar to combine.levels ( in the Hmisc package)
that combines the levels of factors, but not based on their frequency.
Alternatively, I am looking into using the significance of the dummy
variables of factors based on their Pr(>|t|) value using the linear
model, then deleting the non-significant levels. Any other
suggestions?
Thanks,
Saeed

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)

2010-07-09 Thread Peter Ehlers

Actually, it looks like any value other than 1.0
(and in (lower, upper)) for start will work.

  -Peter Ehlers

On 2010-07-09 14:45, Ravi Varadhan wrote:

Setting abs.tol = 0 works!  This turns-off the absolute function convergence
criterion.



nlminb( objective=function(x) x, start=1, lower=-2, upper=2,

control=list(abs.tol=0))
$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient
33


This is clearly a bug.


Ravi.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Ravi Varadhan
Sent: Friday, July 09, 2010 4:42 PM
To: 'Duncan Murdoch'; 'Matthew Killeya'
Cc: r-help@r-project.org; ba...@stat.wisc.edu
Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version
2.11.1)

Duncan, `nlminb' is not intended for non-negative functions only.  There is
indeed something strange happening in the algorithm!

start<- 1.0 # converges to wrong minimum

startp<- 1.0 + .Machine$double.eps  # correct

startm<- 1.0 - .Machine$double.eps  # correct


nlminb( objective=obj, start=start, lower=-2, upper=2)

$par
[1] 0

$objective
[1] 0

$convergence
[1] 0

$message
[1] "absolute function convergence (6)"

$iterations
[1] 1

$evaluations
function gradient
22



nlminb( objective=obj, start=startp, lower=-2, upper=2)

$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient
33



nlminb( objective=obj, start=startm, lower=-2, upper=2)

$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient
33



From the convergence message the `absolute function convergence' seems to

be
the culprit, although I do not understand why that stopping criterion is
becoming effective, when the algorithm is started at x=1, but not at any
other values.  The documentation in IPORT makes it clear that this criterion
is effective only for functions where f(x*) = 0, where x* is a local
minimum.  In this example, x=0 is not a local minimum for f(x), so that
criterion should not apply.


Ravi.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Duncan Murdoch
Sent: Friday, July 09, 2010 3:45 PM
To: Matthew Killeya
Cc: r-help@r-project.org; ba...@stat.wisc.edu
Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version
2.11.1)

On 09/07/2010 10:37 AM, Matthew Killeya wrote:

  nlminb( obj = function(x) x, start=1, lower=-Inf, upper=Inf )



If you read the PORT documentation carefully, you'll see that their
convergence criteria are aimed at minimizing positive functions.  (They
never state this explicitly, as far as I can see.)  So one stopping
criterion is that |f(x)|<  abs.tol, and that's what it found for you.  I
don't know if there's a way to turn this off.

Doug or Deepayan, do you know if nlminb can be made to work on functions
that go negative?

Duncan Murdoch


$par
[1] 0

$objective
[1] 0

$convergence
[1] 0

$message
[1] "absolute function convergence (6)"

$iterations
[1] 1

$evaluations
function gradient
22

[[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] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)

2010-07-09 Thread Ravi Varadhan
Let me clarify my statement in the previous email:  by absolute criterion, I
meant |f(x_n)| < tol.

It is ok to use:  |f(x_{n+1}) - f(x_n)| < abs.tol

Although I prefer the hybrid condition in my previous email.  

Ravi.

-Original Message-
From: Ravi Varadhan [mailto:rvarad...@jhmi.edu] 
Sent: Friday, July 09, 2010 5:06 PM
To: 'Ravi Varadhan'; 'Duncan Murdoch'; 'Matthew Killeya'
Cc: r-help@r-project.org; ba...@stat.wisc.edu
Subject: RE: [R] Not nice behaviour of nlminb (windows 32 bit, version
2.11.1)

An absolute criterion should NEVER be used.  For the situation where f(x*) =
0, instead of the PORT criterion (6) we should use the following:

|f(x_{n+1}) - f(x_n)| < (rel.tol * |f(x_n)| + abs.tol)


Ravi.

-Original Message-
From: Ravi Varadhan [mailto:rvarad...@jhmi.edu] 
Sent: Friday, July 09, 2010 4:45 PM
To: 'Ravi Varadhan'; 'Duncan Murdoch'; 'Matthew Killeya'
Cc: r-help@r-project.org; ba...@stat.wisc.edu
Subject: RE: [R] Not nice behaviour of nlminb (windows 32 bit, version
2.11.1)

Setting abs.tol = 0 works!  This turns-off the absolute function convergence
criterion.


> nlminb( objective=function(x) x, start=1, lower=-2, upper=2,
control=list(abs.tol=0))
$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient 
   33 


This is clearly a bug.


Ravi.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Ravi Varadhan
Sent: Friday, July 09, 2010 4:42 PM
To: 'Duncan Murdoch'; 'Matthew Killeya'
Cc: r-help@r-project.org; ba...@stat.wisc.edu
Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version
2.11.1)

Duncan, `nlminb' is not intended for non-negative functions only.  There is
indeed something strange happening in the algorithm!

start <- 1.0 # converges to wrong minimum

startp <- 1.0 + .Machine$double.eps  # correct

startm <- 1.0 - .Machine$double.eps  # correct

> nlminb( objective=obj, start=start, lower=-2, upper=2)
$par
[1] 0

$objective
[1] 0

$convergence
[1] 0

$message
[1] "absolute function convergence (6)"

$iterations
[1] 1

$evaluations
function gradient 
   22 

> 
> nlminb( objective=obj, start=startp, lower=-2, upper=2)
$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient 
   33 

> 
> nlminb( objective=obj, start=startm, lower=-2, upper=2)
$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient 
   33 


>From the convergence message the `absolute function convergence' seems to
be
the culprit, although I do not understand why that stopping criterion is
becoming effective, when the algorithm is started at x=1, but not at any
other values.  The documentation in IPORT makes it clear that this criterion
is effective only for functions where f(x*) = 0, where x* is a local
minimum.  In this example, x=0 is not a local minimum for f(x), so that
criterion should not apply.

 
Ravi.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Duncan Murdoch
Sent: Friday, July 09, 2010 3:45 PM
To: Matthew Killeya
Cc: r-help@r-project.org; ba...@stat.wisc.edu
Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version
2.11.1)

On 09/07/2010 10:37 AM, Matthew Killeya wrote:
>  nlminb( obj = function(x) x, start=1, lower=-Inf, upper=Inf )
>   

If you read the PORT documentation carefully, you'll see that their 
convergence criteria are aimed at minimizing positive functions.  (They 
never state this explicitly, as far as I can see.)  So one stopping 
criterion is that |f(x)| < abs.tol, and that's what it found for you.  I 
don't know if there's a way to turn this off.

Doug or Deepayan, do you know if nlminb can be made to work on functions 
that go negative?

Duncan Murdoch

> $par
> [1] 0
>
> $objective
> [1] 0
>
> $convergence
> [1] 0
>
> $message
> [1] "absolute function convergence (6)"
>
> $iterations
> [1] 1
>
> $evaluations
> function gradient
>22
>
>   [[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/mail

Re: [R] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)

2010-07-09 Thread Ravi Varadhan
An absolute criterion should NEVER be used.  For the situation where f(x*) =
0, instead of the PORT criterion (6) we should use the following:

|f(x_{n+1}) - f(x_n)| < (rel.tol * |f(x_n)| + abs.tol)


Ravi.

-Original Message-
From: Ravi Varadhan [mailto:rvarad...@jhmi.edu] 
Sent: Friday, July 09, 2010 4:45 PM
To: 'Ravi Varadhan'; 'Duncan Murdoch'; 'Matthew Killeya'
Cc: r-help@r-project.org; ba...@stat.wisc.edu
Subject: RE: [R] Not nice behaviour of nlminb (windows 32 bit, version
2.11.1)

Setting abs.tol = 0 works!  This turns-off the absolute function convergence
criterion.


> nlminb( objective=function(x) x, start=1, lower=-2, upper=2,
control=list(abs.tol=0))
$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient 
   33 


This is clearly a bug.


Ravi.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Ravi Varadhan
Sent: Friday, July 09, 2010 4:42 PM
To: 'Duncan Murdoch'; 'Matthew Killeya'
Cc: r-help@r-project.org; ba...@stat.wisc.edu
Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version
2.11.1)

Duncan, `nlminb' is not intended for non-negative functions only.  There is
indeed something strange happening in the algorithm!

start <- 1.0 # converges to wrong minimum

startp <- 1.0 + .Machine$double.eps  # correct

startm <- 1.0 - .Machine$double.eps  # correct

> nlminb( objective=obj, start=start, lower=-2, upper=2)
$par
[1] 0

$objective
[1] 0

$convergence
[1] 0

$message
[1] "absolute function convergence (6)"

$iterations
[1] 1

$evaluations
function gradient 
   22 

> 
> nlminb( objective=obj, start=startp, lower=-2, upper=2)
$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient 
   33 

> 
> nlminb( objective=obj, start=startm, lower=-2, upper=2)
$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient 
   33 


>From the convergence message the `absolute function convergence' seems to
be
the culprit, although I do not understand why that stopping criterion is
becoming effective, when the algorithm is started at x=1, but not at any
other values.  The documentation in IPORT makes it clear that this criterion
is effective only for functions where f(x*) = 0, where x* is a local
minimum.  In this example, x=0 is not a local minimum for f(x), so that
criterion should not apply.

 
Ravi.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Duncan Murdoch
Sent: Friday, July 09, 2010 3:45 PM
To: Matthew Killeya
Cc: r-help@r-project.org; ba...@stat.wisc.edu
Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version
2.11.1)

On 09/07/2010 10:37 AM, Matthew Killeya wrote:
>  nlminb( obj = function(x) x, start=1, lower=-Inf, upper=Inf )
>   

If you read the PORT documentation carefully, you'll see that their 
convergence criteria are aimed at minimizing positive functions.  (They 
never state this explicitly, as far as I can see.)  So one stopping 
criterion is that |f(x)| < abs.tol, and that's what it found for you.  I 
don't know if there's a way to turn this off.

Doug or Deepayan, do you know if nlminb can be made to work on functions 
that go negative?

Duncan Murdoch

> $par
> [1] 0
>
> $objective
> [1] 0
>
> $convergence
> [1] 0
>
> $message
> [1] "absolute function convergence (6)"
>
> $iterations
> [1] 1
>
> $evaluations
> function gradient
>22
>
>   [[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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)

2010-07-09 Thread Ravi Varadhan
Setting abs.tol = 0 works!  This turns-off the absolute function convergence
criterion.


> nlminb( objective=function(x) x, start=1, lower=-2, upper=2,
control=list(abs.tol=0))
$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient 
   33 


This is clearly a bug.


Ravi.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Ravi Varadhan
Sent: Friday, July 09, 2010 4:42 PM
To: 'Duncan Murdoch'; 'Matthew Killeya'
Cc: r-help@r-project.org; ba...@stat.wisc.edu
Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version
2.11.1)

Duncan, `nlminb' is not intended for non-negative functions only.  There is
indeed something strange happening in the algorithm!

start <- 1.0 # converges to wrong minimum

startp <- 1.0 + .Machine$double.eps  # correct

startm <- 1.0 - .Machine$double.eps  # correct

> nlminb( objective=obj, start=start, lower=-2, upper=2)
$par
[1] 0

$objective
[1] 0

$convergence
[1] 0

$message
[1] "absolute function convergence (6)"

$iterations
[1] 1

$evaluations
function gradient 
   22 

> 
> nlminb( objective=obj, start=startp, lower=-2, upper=2)
$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient 
   33 

> 
> nlminb( objective=obj, start=startm, lower=-2, upper=2)
$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient 
   33 


>From the convergence message the `absolute function convergence' seems to
be
the culprit, although I do not understand why that stopping criterion is
becoming effective, when the algorithm is started at x=1, but not at any
other values.  The documentation in IPORT makes it clear that this criterion
is effective only for functions where f(x*) = 0, where x* is a local
minimum.  In this example, x=0 is not a local minimum for f(x), so that
criterion should not apply.

 
Ravi.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Duncan Murdoch
Sent: Friday, July 09, 2010 3:45 PM
To: Matthew Killeya
Cc: r-help@r-project.org; ba...@stat.wisc.edu
Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version
2.11.1)

On 09/07/2010 10:37 AM, Matthew Killeya wrote:
>  nlminb( obj = function(x) x, start=1, lower=-Inf, upper=Inf )
>   

If you read the PORT documentation carefully, you'll see that their 
convergence criteria are aimed at minimizing positive functions.  (They 
never state this explicitly, as far as I can see.)  So one stopping 
criterion is that |f(x)| < abs.tol, and that's what it found for you.  I 
don't know if there's a way to turn this off.

Doug or Deepayan, do you know if nlminb can be made to work on functions 
that go negative?

Duncan Murdoch

> $par
> [1] 0
>
> $objective
> [1] 0
>
> $convergence
> [1] 0
>
> $message
> [1] "absolute function convergence (6)"
>
> $iterations
> [1] 1
>
> $evaluations
> function gradient
>22
>
>   [[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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)

2010-07-09 Thread Ravi Varadhan
Duncan, `nlminb' is not intended for non-negative functions only.  There is
indeed something strange happening in the algorithm!

start <- 1.0 # converges to wrong minimum

startp <- 1.0 + .Machine$double.eps  # correct

startm <- 1.0 - .Machine$double.eps  # correct

> nlminb( objective=obj, start=start, lower=-2, upper=2)
$par
[1] 0

$objective
[1] 0

$convergence
[1] 0

$message
[1] "absolute function convergence (6)"

$iterations
[1] 1

$evaluations
function gradient 
   22 

> 
> nlminb( objective=obj, start=startp, lower=-2, upper=2)
$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient 
   33 

> 
> nlminb( objective=obj, start=startm, lower=-2, upper=2)
$par
[1] -2

$objective
[1] -2

$convergence
[1] 0

$message
[1] "both X-convergence and relative convergence (5)"

$iterations
[1] 3

$evaluations
function gradient 
   33 


>From the convergence message the `absolute function convergence' seems to be
the culprit, although I do not understand why that stopping criterion is
becoming effective, when the algorithm is started at x=1, but not at any
other values.  The documentation in IPORT makes it clear that this criterion
is effective only for functions where f(x*) = 0, where x* is a local
minimum.  In this example, x=0 is not a local minimum for f(x), so that
criterion should not apply.

 
Ravi.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Duncan Murdoch
Sent: Friday, July 09, 2010 3:45 PM
To: Matthew Killeya
Cc: r-help@r-project.org; ba...@stat.wisc.edu
Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version
2.11.1)

On 09/07/2010 10:37 AM, Matthew Killeya wrote:
>  nlminb( obj = function(x) x, start=1, lower=-Inf, upper=Inf )
>   

If you read the PORT documentation carefully, you'll see that their 
convergence criteria are aimed at minimizing positive functions.  (They 
never state this explicitly, as far as I can see.)  So one stopping 
criterion is that |f(x)| < abs.tol, and that's what it found for you.  I 
don't know if there's a way to turn this off.

Doug or Deepayan, do you know if nlminb can be made to work on functions 
that go negative?

Duncan Murdoch

> $par
> [1] 0
>
> $objective
> [1] 0
>
> $convergence
> [1] 0
>
> $message
> [1] "absolute function convergence (6)"
>
> $iterations
> [1] 1
>
> $evaluations
> function gradient
>22
>
>   [[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.


Re: [R] String truncate

2010-07-09 Thread Wu Gong

Do you mean substring?

 sub(".txt","", "mytest.txt")

-
A R learner.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/String-truncate-tp2284045p2284062.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] nls error regarding numerics vs logicals

2010-07-09 Thread Peter Ehlers

On 2010-07-09 13:29, Duncan Murdoch wrote:

On 09/07/2010 2:36 PM, Jim Bouldin wrote:

> 1. The expression you gave us is clearly not the one that produced
the > error: it involved "ring.area" and "ba.beg".
> > 2. You don't tell us what x and y are, so we can't reproduce
anything.

Sorry, I guess that was unclear. I changed the response and independent
variable names to y and x respectively, in hopes that would be clearer.
Both are numeric variables.


When I make up my own numeric variables I don't get the error you got.
So I still can't reproduce anything.

Duncan Murdoch



Two possibilities, although neither of them caused problems
for me with made-up data:

1. do you have T defined as some object?
   If so, remove it or (better) use TRUE.

2. did you put 'trace=T' inside your start list?

Also, it seems that you might want a model of the type

 y ~ A * ( 1 - exp( B * x) )

which would be a bit simpler.

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


Re: [R] output without quotes

2010-07-09 Thread David Winsemius


On Jul 9, 2010, at 3:51 PM, AC Del Re wrote:


Hi All,

I am interested in printing column names without quotes and am  
struggling to
do it properly. The tough part is that I am interested in using  
these column

names for a function within a function (e.g., lm() within a wrapper
function). Therefore, cat() doesnt seem appropriate



and print() is not what I need. Ideas?


My idea is that you need to show the code you hope to write so that  
the appropriate language elements can be constructed. If it's going  
into a formula there might be one answer whereas if it's going to be  
used to access columns in a subset expression it may be another method.




# sample data
mod1 <- rnorm(20, 10, 2)
mod2 <- rnorm(20, 5, 1)
dat <- data.frame(mod1, mod2)

# collapsing the colnames to 'mod1+mod2'
temp <- paste(names(dat), collapse="+")

temp  # this gives quotes
print(temp, quote = FALSE)  # no quotes but includes [1]

# need the output like this (no quotes & no [1]):mod1+mod2


Which cat _would_ print on the device or file but it not return  
anything to the interpreter for further evaluation.

--
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] Compress string memCompress/Decompress

2010-07-09 Thread Matt Shotwell
Erik, 

Can you store the data as a blob? For example:

> #create string, compress with gzip, convert to SQLite blob string
> string <- "gzip this string, store as blob in SQLite database"
> string.gz <- memCompress(string, type="gzip")
> string.sqlite <- paste("x'",paste(string.gz,collapse=""),"'",sep="")

> #create database and table with a BLOB column
> library(RSQLite)
Loading required package: DBI
> con <- dbConnect(dbDriver("SQLite"), "compress.sqlite")
> dbGetQuery(con, "CREATE TABLE Compress (id INTEGER, data BLOB);")
NULL

> #insert the string as a blob
> query <- paste("INSERT INTO Compress (id, data) VALUES (1, ", 
+ string.sqlite, ");", sep="")
> dbGetQuery(con, query)
NULL

> #recover the blob, decompress, and convert back to a string
> result <- dbGetQuery(con, "SELECT data FROM Compress;")
> string.gz <- result[[1]][[1]]
> string <- memDecompress(string.gz, type="gzip")
> rawToChar(string)
[1] "gzip this string, store as blob in SQLite database"


-Matt



On Fri, 2010-07-09 at 12:51 -0400, Erik Wright wrote:
> Hello,
> 
> I would like to compress a long string (character vector), store the 
> compressed string in the text field of a SQLite database (using RSQLite), and 
> then load the text back into memory and decompress it back into the the 
> original string.  My character vector can be compressed considerably using 
> standard gzip/bzip2 compression.  In theory it should be much faster for me 
> to compress/decompress a long string than to write the whole string to the 
> hard drive and then read it back (not to mention the saved hard drive space).
> 
> I have tried accomplishing this task using memCompress() and memDecompress() 
> without success.  It seems memCompress can only convert a character vector to 
> raw type which cannot be treated as a string.  Does anyone have ideas on how 
> I can go about doing this, especially using the standard base packages?
> 
> Thanks!,
> Erik
> 
> 
> > sessionInfo()
> R version 2.11.0 (2010-04-22) 
> x86_64-apple-darwin9.8.0 
> 
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
> 
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base 
> 
> loaded via a namespace (and not attached):
> [1] tools_2.11.0
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
-- 
Matthew S. Shotwell
Graduate Student
Division of Biostatistics and Epidemiology
Medical University of South Carolina
http://biostatmatt.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] apply is slower than for loop?

2010-07-09 Thread Duncan Murdoch

On 09/07/2010 4:11 PM, Gene Leynes wrote:

I thought the "apply" functions are faster than for loops, but my most
recent test shows that apply actually takes a significantly longer than a
for loop.  Am I missing something?
  


Probably not.  apply() needs to figure out the shape of the results it 
gets from each row in order to put them into the final result matrix.  
You know that in advance, and set up the result to hold them, so your 
calculation would be more efficient.


The *apply functions are designed to be convenient and clear to read, 
not necessarily fast.


Duncan Murdoch


It doesn't matter much if I do column wise calculations rather than row wise

## Example of how apply is SLOWER than for loop:

#rm(list=ls())

## DEFINE VARIABLES
mu=0.05 ; sigma=0.20 ; dt=.25 ; T=50 ; sims=1e5
timesteps = T/dt

## MAKE PHI AND DS
phi = matrix(rnorm(timesteps*sims), nrow=sims, ncol=timesteps)
ds = mu*dt + sigma * sqrt(dt) * phi

## USE APPLY TO CALCULATE ROWWISE CUMULATIVE PRODUCT
system.time(y1 <- apply(1+ds, 1, cumprod))
## UNTRANSFORM Y1, BECAUSE ROW APPLY FLIPS THE MATRIX
y1=t(y1)

## USE FOR LOOP TO CALCULATE ROWWISE CUMULATIVE PRODUCT
y2=matrix(NA,nrow(ds),ncol(ds))
system.time(
for (i in 1:nrow(ds)){
y2[i,]<-cumprod(1+ds[i,])
}
)

## COMPARE RESULTS TO MAKE SURE THEY DID THE SAME THING
str(y1)
str(y2)
all(y1==y2)

[[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] S: Book for time series analysis with R

2010-07-09 Thread David Winsemius


On Jul 9, 2010, at 3:37 PM, soeren.vo...@eawag.ch wrote:


Hello

Could you recommend a printed/electronic book that teaches time  
series analysis (using R) for students? I am searching for something  
similar to the MASS book, with a level lower but close, for TSA.  
Easy examples would be fine to understand deeper statistical  
procedures. Functions, results, and their practical interpretation  
should be explained next to the R code.


Thanks for help and/or suggestions!


Have you looked at the "Books" listing of the main R-project webpage?  
Each has a blurb outlining the topics covered.


[11] Paul S. P. Cowpertwait and Andrew Metcalfe. Introductory Time  
Series with R. Springer Series in Statistics. Springer, 2009. ISBN:  
978-0-387-88697-8.


[41] Jonathan D. Cryer and Kung-Sik Chan. Time Series Analysis With  
Applications in R. Springer, New York, 2008. ISBN 978-0-387-75958-6.


[59] Robert H. Shumway and David S. Stoffer. Time Series Analysis and  
Its Applications With R Examples. Springer, New York, 2006. ISBN  
978-0-387-29317-2.




Sören

--
Sören Vogel, Dipl.-Psych. (Univ.), PhD-Student, Eawag, Dept. SIAM
+41 76 233 3637, http://www.eawag.ch, http://sozmod.eawag.ch

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


David Winsemius, MD
West Hartford, CT

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


[R] apply is slower than for loop?

2010-07-09 Thread Gene Leynes
I thought the "apply" functions are faster than for loops, but my most
recent test shows that apply actually takes a significantly longer than a
for loop.  Am I missing something?

It doesn't matter much if I do column wise calculations rather than row wise

## Example of how apply is SLOWER than for loop:

#rm(list=ls())

## DEFINE VARIABLES
mu=0.05 ; sigma=0.20 ; dt=.25 ; T=50 ; sims=1e5
timesteps = T/dt

## MAKE PHI AND DS
phi = matrix(rnorm(timesteps*sims), nrow=sims, ncol=timesteps)
ds = mu*dt + sigma * sqrt(dt) * phi

## USE APPLY TO CALCULATE ROWWISE CUMULATIVE PRODUCT
system.time(y1 <- apply(1+ds, 1, cumprod))
## UNTRANSFORM Y1, BECAUSE ROW APPLY FLIPS THE MATRIX
y1=t(y1)

## USE FOR LOOP TO CALCULATE ROWWISE CUMULATIVE PRODUCT
y2=matrix(NA,nrow(ds),ncol(ds))
system.time(
for (i in 1:nrow(ds)){
y2[i,]<-cumprod(1+ds[i,])
}
)

## COMPARE RESULTS TO MAKE SURE THEY DID THE SAME THING
str(y1)
str(y2)
all(y1==y2)

[[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] output without quotes

2010-07-09 Thread AC Del Re
Hi All,

I am interested in printing column names without quotes and am struggling to
do it properly. The tough part is that I am interested in using these column
names for a function within a function (e.g., lm() within a wrapper
function). Therefore, cat() doesnt seem appropriate and print() is not what
I need. Ideas?

# sample data
mod1 <- rnorm(20, 10, 2)
mod2 <- rnorm(20, 5, 1)
dat <- data.frame(mod1, mod2)

# collapsing the colnames to 'mod1+mod2'
temp <- paste(names(dat), collapse="+")

temp  # this gives quotes
print(temp, quote = FALSE)  # no quotes but includes [1]

# need the output like this (no quotes & no [1]):mod1+mod2

Thanks,

AC

[[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] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)

2010-07-09 Thread Duncan Murdoch

On 09/07/2010 10:37 AM, Matthew Killeya wrote:

 nlminb( obj = function(x) x, start=1, lower=-Inf, upper=Inf )
  


If you read the PORT documentation carefully, you'll see that their 
convergence criteria are aimed at minimizing positive functions.  (They 
never state this explicitly, as far as I can see.)  So one stopping 
criterion is that |f(x)| < abs.tol, and that's what it found for you.  I 
don't know if there's a way to turn this off.


Doug or Deepayan, do you know if nlminb can be made to work on functions 
that go negative?


Duncan Murdoch


$par
[1] 0

$objective
[1] 0

$convergence
[1] 0

$message
[1] "absolute function convergence (6)"

$iterations
[1] 1

$evaluations
function gradient
   22

[[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] S: Book for time series analysis with R

2010-07-09 Thread soeren . vogel
Hello

Could you recommend a printed/electronic book that teaches time series analysis 
(using R) for students? I am searching for something similar to the MASS book, 
with a level lower but close, for TSA. Easy examples would be fine to 
understand deeper statistical procedures. Functions, results, and their 
practical interpretation should be explained next to the R code.

Thanks for help and/or suggestions!

Sören

-- 
Sören Vogel, Dipl.-Psych. (Univ.), PhD-Student, Eawag, Dept. SIAM
+41 76 233 3637, http://www.eawag.ch, http://sozmod.eawag.ch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] nls error regarding numerics vs logicals

2010-07-09 Thread Duncan Murdoch

On 09/07/2010 2:36 PM, Jim Bouldin wrote:
> 1.  The expression you gave us is clearly not the one that produced the 
> error:  it involved "ring.area" and "ba.beg".
> 
> 2.  You don't tell us what x and y are, so we can't reproduce anything.


Sorry, I guess that was unclear.  I changed the response and independent
variable names to y and x respectively, in hopes that would be clearer.
Both are numeric variables.


When I make up my own numeric variables I don't get the error you got.  
So I still can't reproduce anything.


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] hide scatter points

2010-07-09 Thread Roy Mendelssohn
Try changing the plot call to:

> plot(x2, y2, type ="n")

look at:

?plot

-Roy


On Jul 9, 2010, at 12:20 PM, Marlin Keith Cox wrote:

> I need to hide scatter points and just leave the linear regression
> line.  I have tried to color the points "white", but that does not
> work.
> 
> A working example, I need the green plotted points to be transparent or 
> hidden.
> 
> x2 <- seq(1,200,.5)
> y2 <- seq(5,204,.5)
> plot(x2, y2, pch=16, col="green")
> model<-lm(y2~x2)
> abline(model, lty=3, lwd=4, col="black")
> 
> Thanks ahead of time,
> 
> keith
> 
> -- 
> M. Keith Cox, Ph.D.
> Alaska NOAA Fisheries, National Marine Fisheries Service
> Auke Bay Laboratories
> 17109 Pt. Lena Loop Rd.
> Juneau, AK 99801
> keith@noaa.gov
> marlink...@gmail.com
> U.S. (907) 789-6603
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

**
"The contents of this message do not reflect any position of the U.S. 
Government or NOAA."
**
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
1352 Lighthouse Avenue
Pacific Grove, CA 93950-2097

e-mail: roy.mendelss...@noaa.gov (Note new e-mail address)
voice: (831)-648-9029
fax: (831)-648-8440
www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected"

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] hide scatter points

2010-07-09 Thread Sarah Goslee
plot(x2, y2, pch=16, type="n")

On Fri, Jul 9, 2010 at 3:20 PM, Marlin Keith Cox  wrote:
> I need to hide scatter points and just leave the linear regression
> line.  I have tried to color the points "white", but that does not
> work.
>
> A working example, I need the green plotted points to be transparent or 
> hidden.
>
> x2 <- seq(1,200,.5)
> y2 <- seq(5,204,.5)
> plot(x2, y2, pch=16, col="green")
> model<-lm(y2~x2)
> abline(model, lty=3, lwd=4, col="black")
>
> Thanks ahead of time,
>
> keith
>
> --


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] hide scatter points

2010-07-09 Thread Marlin Keith Cox
I need to hide scatter points and just leave the linear regression
line.  I have tried to color the points "white", but that does not
work.

A working example, I need the green plotted points to be transparent or hidden.

x2 <- seq(1,200,.5)
y2 <- seq(5,204,.5)
plot(x2, y2, pch=16, col="green")
model<-lm(y2~x2)
abline(model, lty=3, lwd=4, col="black")

Thanks ahead of time,

keith

-- 
M. Keith Cox, Ph.D.
Alaska NOAA Fisheries, National Marine Fisheries Service
Auke Bay Laboratories
17109 Pt. Lena Loop Rd.
Juneau, AK 99801
keith@noaa.gov
marlink...@gmail.com
U.S. (907) 789-6603

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Mover Stayer Models

2010-07-09 Thread Ingmar Visser
depmixS4 can fit such models as a constrained latent markov mdoel,
best, Ingmar

On Fri, Jul 9, 2010 at 7:52 PM, Katherine Sanders <
sanders@buckeyemail.osu.edu> wrote:

> Does anyone know how to program mover stayer models in R?  They are a type
> of Markov chain model where there is a group of people who stays in the same
> place, a group who always moves, and a group who does both.
>
> Thanks.
>
> Leanne Sanders
> sanders@osu.edu
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] Ctree Question

2010-07-09 Thread Achim Zeileis

On Fri, 9 Jul 2010, steve_fried...@nps.gov wrote:



Hello,

I've been using ctree and have developed a 55 node - 28 terminal solution.
As can be imagined, the plot is difficult to travel down each of the major
branches.

I've read the help files for ctree I saw where terminal nodes can be color
coded.

plot(airct, type = "simple")

plot(airct, terminal_panel = node_boxplot(airct, col = "blue",  + fill =

hsv(2/3, 0.5, 1)))

Here is my question:

Since my model has 55 nodes and 28 terminal nodes,(ie many branches)  is it
feasible to color code the each of the major branches and track the paths
down the decision tree?


I'm not sure what exactly you want: Is it to plot Node XY in a certain 
color, say blue, and also have all branches that lead to that node in 
blue?


If so, you could in principle write a panel function for that but it 
wouldn't be easy, I'm afraid.


Sorry,
Z


R 2.11.1, Windox XP


Thanks
Steve



Steve Friedman Ph. D.
Spatial Statistical Analyst
Everglades and Dry Tortugas National Park
950 N Krome Ave (3rd Floor)
Homestead, Florida 33034

steve_fried...@nps.gov
Office (305) 224 - 4282
Fax (305) 224 - 4147

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] stl function

2010-07-09 Thread Achim Zeileis

On Fri, 9 Jul 2010, kateg wrote:



Hi all,

I'm working on decomposition and comparison of several time series. I'm
interested in extracting the trend components for each time series using the
stl function and overlaying them on one another.

I'm not sure how to plot the trend function alone and to do the overlay
using some kind of loop. If anyone has any insight that would be great!


stl(...)$time.series

is a "ts" series containing seasonal/trend/remainder. Thus, the trend can 
be extracted via


stl(...)$time.series[, "trend"]

See ?stl for more details.
Z


thanks,

Katie
--
View this message in context: 
http://r.789695.n4.nabble.com/stl-function-tp2283891p2283891.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] select columns from dataframe

2010-07-09 Thread Erik Iverson



Jonathan Flowers wrote:

Hi,

I would like to extract columns from a dataframe using a vector of desired
column names.

The following working example uses the select argument in the subset
function to accomplish what I am trying to do.  Is there a better solution?


This is very much "Introduction to R" stuff.

A word of warning: both 'data' and 'colnames' are built-in functions, so 
 you may not want to call your variables those things to avoid confusion.


After your definitions below, try:

> data[colnames]
> data$col1
> data$col3
> data[["col1"]]
> data[["col3"]]

compare the previous two with:

> data["col1"]
> data["col3"]



Thanks.

#my data
data <- data.frame("col1"=c(1,2,3),"col2"=c("A","B","C"),"col3"=c(4,5,6))

#names of desired columns
colnames <- c("col1","col3")

fun <- function(colname,dframe){
nframe <- subset(dframe,select=colname)
vec <- nframe[,1]
return(vec)
}

fun(colnames[1],data)
fun(colnames[2],data)

[[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] nls error regarding numerics vs logicals

2010-07-09 Thread Jim Bouldin

> 1.  The expression you gave us is clearly not the one that produced the 
> error:  it involved "ring.area" and "ba.beg".
> 
> 2.  You don't tell us what x and y are, so we can't reproduce anything.

Sorry, I guess that was unclear.  I changed the response and independent
variable names to y and x respectively, in hopes that would be clearer.
Both are numeric variables.
Jim

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


Re: [R] eval and assign in loop problem

2010-07-09 Thread Erik Iverson




for (i in 0:3)
   {
   r = runif(1)
   assign(paste('b',i,sep=''),r)
   }


for (i in 1:4)
   {

assign(paste('b',i,sep=''),eval(parse(text=paste('b',i-1,sep=''
   }



First, b1 is set to b0
Then,  b2 is set to b1 (which was just set to b0)
Then,  b3 is set to b2 (which was just set to b1, which was just set to b0)

...

All b[i] are set to b0

If this is all you're trying to accomplish, it's much better to keep the 
common objects in a vector (or list if they are more complicated) and 
use sapply/lapply and vectorized functions to perform the manipulations. 
You've managed to use three seldom-needed methods in 2 lines of R code 
:) (for loops, assign, and eval(parse(text=)))


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


Re: [R] select columns from vector of column names

2010-07-09 Thread MacQueen, Don
How about

  data[ , colnames]
Or
  data[ , colnames[1]]
  data[ , colnames[2]]

-Don


On 7/9/10 11:27 AM, "Jonathan Flowers"  wrote:

> Hi
> 
> I want to extract columns from a data frame using a vector with the desired
> column names.
> 
> This short example uses the select argument in the subset function to
> accomplish what I am trying to do.  Is there a better solution?
> 
> #names of desired columns
> colnames <- c("col1","col3")
> 
> #my data
> data <- data.frame("col1"=c(1,2,3),"col2"=c("A","B","C"),"col3"=c(4,5,6))
> 
> fun <- function(colname,dframe){
> nframe <- subset(dframe,select=colname)
> vec <- nframe[,1]
> return(vec)
> }
> 
> fun(colnames[1],data)
> fun(colnames[2],data)
> 
> [[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.
> 

-- 
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
925 423-1062

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Mover Stayer Models

2010-07-09 Thread Katherine Sanders
Does anyone know how to program mover stayer models in R?  They are a type of 
Markov chain model where there is a group of people who stays in the same 
place, a group who always moves, and a group who does both.

Thanks.

Leanne Sanders
sanders@osu.edu

[[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] stl function

2010-07-09 Thread kateg

Hi all, 

I'm working on decomposition and comparison of several time series. I'm
interested in extracting the trend components for each time series using the
stl function and overlaying them on one another.  

I'm not sure how to plot the trend function alone and to do the overlay
using some kind of loop. If anyone has any insight that would be great!

thanks, 

Katie
-- 
View this message in context: 
http://r.789695.n4.nabble.com/stl-function-tp2283891p2283891.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 finding valid permutations

2010-07-09 Thread Michael D
So I have an array A of length n with multiple attributes and for a
selected attribute y I need to list all valid permutations where a
valid permutation is of the form:
A[1,y] != A[n,y]
A[i,y] != A[i+1,y]

I've tried using the 'combinat' package, but with the vector lengths
I'm using the permn function fails with the vector("list", gamma(n +
1)) assignment.


For example:
13 cards from a standard 52 card deck. attributes facevalue and suit.
A = (9C, 9H, 9D, 8C, 7C, 6C, 6S, 5C, 4C, 4H, 3C, 2C, 2D)

And I want to find all possible arrangements where the facevalue of
each consecutive card is different but the orders are unique because
of the suit.

Also, I need to consider the case where the suit of each consecutive
case is different but the orders are unique because of the facevalue.

For A above, note that there are 8 clubs out of 13 cards so 3 of the
clubs must be dropped from the draw an all valid of ten of the cards
must be found (5 same suit, 5 off suit)


I hope this is clear. Thanks.

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


[R] Compress string memCompress/Decompress

2010-07-09 Thread Erik Wright
Hello,

I would like to compress a long string (character vector), store the compressed 
string in the text field of a SQLite database (using RSQLite), and then load 
the text back into memory and decompress it back into the the original string.  
My character vector can be compressed considerably using standard gzip/bzip2 
compression.  In theory it should be much faster for me to compress/decompress 
a long string than to write the whole string to the hard drive and then read it 
back (not to mention the saved hard drive space).

I have tried accomplishing this task using memCompress() and memDecompress() 
without success.  It seems memCompress can only convert a character vector to 
raw type which cannot be treated as a string.  Does anyone have ideas on how I 
can go about doing this, especially using the standard base packages?

Thanks!,
Erik


> sessionInfo()
R version 2.11.0 (2010-04-22) 
x86_64-apple-darwin9.8.0 

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] syntax for highlighting table rows and columns using R plugin for spss

2010-07-09 Thread Anderson, Chris
I am using  the R plug-in for spss 18, and would like to know if there is any R 
code that will highlight and bold rows (particularly the "Totals" row) within 
an spss table. The current option that spss has is to use a python plug-in 
which doesn't seem to work on my windows 7 machine.

Chris Anderson
Data Analyst
Medical Affairs
wk: 925-677-4870
cell: 707-315-8486
Fax:925-677-4670


This electronic message transmission, including any attachments, 
contains information which may be confidential, privileged and/or otherwise 
exempt from disclosure under applicable law. The information is intended to 
be for the use of the individual(s) or entity named above. If you are not 
the intended recipient or the employee or agent responsible for delivering 
the message to the intended recipient, you are hereby notified that any 
disclosure, copying, distribution or use of the contents of this 
information is strictly prohibited.  If you have received this electronic 
transmission in error, please notify the sender immediately by telephone 
(800-676-6777) or by a "reply to sender only" message and destroy all 
electronic and hard copies of the communication, including attachments.  
Thank you.For more information on Paradigm Management Services, LLC, 
please visit http://www.paradigmcorp.com 

[[alternative HTML version deleted]]

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


[R] July BaselR Meeting

2010-07-09 Thread Sarah Lewis
BaselR meeting July 2010

Thank you to everyone who supported our inaugural BaselR meeting on April 
28th; we were fortunate to have three excellent presentations which prompted 
lively discussion - our thanks go to Andreas Krause, Yann Abraham and Charles 
Roosen for their presentations, details of which are available here

The next BaselR meeting is Wednesday 28th July 2010

Venue:
transBARent
Viaduktstrasse 3
CH-4051 Basel
Tel. 061 222 21 31
Fax 061 222 21 32
i...@transbarent.ch

http://transbarent.sv-group.ch/de.html  

Agenda:

* Introduction - Charles Roosen, Mango Solutions AG
* Desktop Publishing with Sweave - Andrew Ellis, ETH Zurich
* Professional Reporting with RExcel - Dominik Locher, THETA AG
* R Generator Tool for Google Motion Charts - Sebastian Pérez Saaibi, ETH Zurich

If you would like to join the BaselR mailing list and receive details of all 
BaselR meetings please email us at bas...@mango-solutions.com 

What is BaselR?

Similar to the well-known LondonR, this informal meeting is intended to serve 
as a platform for all local (and regional) R users to present and exchange 
their experiences and ideas around the usage of R. 

Mango Solutions aims to host such meetings about every quarter. A typical 
BaselR meeting will consist of 3-4 talks of about 20-25 min to give plenty of 
room for sharing your R experiences, discussions and exchange of ideas.

How to contribute? 

We are always looking for volunteers to present at subsequent meetings. If you 
think you have something interesting to present or know of someone who has, 
please contact us.

For ideas on presentations, take a look at previous presentations given at 
LondonR (here).

For more information about Mango Solutions please contact us or visit our 
website www.mango-solutions.ch

Sarah Lewis

Hadley Wickham, Creator of ggplot2 - first time teaching in the UK. 1st - 2nd  
November 2010. 
To book your seat please go to http://mango-solutions.com/news.html 

T: +44 (0)1249 767700 Ext: 200
F: +44 (0)1249 767707
M: +44 (0)7746 224226
www.mango-solutions.com
Unit 2 Greenways Business Park 
Bellinger Close
Chippenham
Wilts
SN15 1BN
UK 

LEGAL NOTICE\ This message is intended for the use of th...{{dropped:22}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] eval and assign in loop problem

2010-07-09 Thread S.Nicholas
deaR useRs,

I am trying to assign different values to different objects in a for loop.
The following is a toy example of the part that has been giving me a hard
time.

The first "for loop" generates four objects, b0, b1, b2, b3 with random
numbers.
And, the second "for loop" is equivalent to
b1 = b0
b2 = b1
b3 = b2
b4 = b3

But, when I run this code, the result is equivalent to
b1 = b0
b2 = b0
b3 = b0
b4 = b0

So, the increment does not seem to be properly working for the second part
of the "assign" function.
Why would this be?

for (i in 0:3)
   {
   r = runif(1)
   assign(paste('b',i,sep=''),r)
   }


for (i in 1:4)
   {

assign(paste('b',i,sep=''),eval(parse(text=paste('b',i-1,sep=''
   }

Thank you.

Nic

[[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] split with list

2010-07-09 Thread Ista Zahn
"n.via...@libero.it"  writes:
Hi,

> Dear List I would like to ask you something concenting a better print of the 
> R output:
> I have a bit data frame which has the following structure:
> CFISCALE  RAGSOCBANNO   VAR1VAR2.
> 9853312 astra 2005   6
>45
>
> 9853312 astra 2006  78
>   45
>
>
> 9853312 astra 2007   55   
>76
>
>
> 9653421  geox 2005   35   
>   89
>
>
>
> 9653421 geox 200624   
> 33
>
> 9653421  geox 2007   54   
>55
>
>
> The first thing I did is to split my data frame for CFISCALE. The result is 
> that R has transformed my data frame into a list. The second step was to 
> transpose each element of my list. 
> repo=split(rep,rep$CFISCALE)
> repor=lapply(repo,function(x){
> t(x)})
>
>
> When I print my list the format is the following 
> $9853312
>1   2  
>   3
>
> CFISCALE"9853312" "9853312" "9853312"   
>
> RAGSOCB"astra"   "astra""astra"
>
> ANNO   "2005""2006"  
> "2007"
>
> VAR1   6 78   
>55
>
> VAR2   4545   
>   76
>

So far so good.

>
> There is a way to remove the  first row I mean 1, 2 , 3 and to have just one 
> CFISCALE and RAGSOCB???
> For the second problem I tried to use unique but it seems that it
> doesnt work for list. So what I would like to get is: 

Well I'm not sure what the first problem is. But if I understand the
"second problem", you can do something like this:

dup.null <- function(mat) {
  mat["CFISCALE", duplicated(mat["CFISCALE",])] <- NA
  mat["RAGSOCB", duplicated(mat["RAGSOCB",])] <- NA
  return(mat)
  }

repor <- lapply(repor, dup.null)


Best,
Ista

> $9853312
>
>   
> 
>
>
> CFISCALE"9853312" 
>
>
> RAGSOCB"astra"  
> ANNO   "2005""2006"  
> "2007"
>
> VAR1   6 78   
>55
>
> VAR2   4545   
>   76
>
>
> This is because I next run xtable on my list in order to get a table in 
> Latex, which I woud like to be in a nice format.
> Thanks a lot for your attention!
>
>
>
>
>
>   [[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] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)

2010-07-09 Thread Matthew Killeya
 nlminb( obj = function(x) x, start=1, lower=-Inf, upper=Inf )
$par
[1] 0

$objective
[1] 0

$convergence
[1] 0

$message
[1] "absolute function convergence (6)"

$iterations
[1] 1

$evaluations
function gradient
   22

[[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] select columns from vector of column names

2010-07-09 Thread Horace Tso
How about

data[,colnames(data)%in%colnames] 


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Jonathan Flowers
Sent: Friday, July 09, 2010 11:27 AM
To: r-help@r-project.org
Subject: [R] select columns from vector of column names

Hi

I want to extract columns from a data frame using a vector with the desired
column names.

This short example uses the select argument in the subset function to
accomplish what I am trying to do.  Is there a better solution?

#names of desired columns
colnames <- c("col1","col3")

#my data
data <- data.frame("col1"=c(1,2,3),"col2"=c("A","B","C"),"col3"=c(4,5,6))

fun <- function(colname,dframe){
nframe <- subset(dframe,select=colname)
vec <- nframe[,1]
return(vec)
}

fun(colnames[1],data)
fun(colnames[2],data)

[[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] Ctree Question

2010-07-09 Thread Horace Tso
Steve, I'm not sure if your task could be accomplished with a ready-made 
function in party. But, if you could manage to convert your tree structure to a 
dendrogram, then it's straightforward using dendrapply. In fact, there is an 
example in dendrapply help page showing how leaves are colored. 

?dendrapply

HTH.

H

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of steve_fried...@nps.gov
Sent: Friday, July 09, 2010 10:22 AM
To: r-help@r-project.org
Subject: [R] Ctree Question


Hello,

I've been using ctree and have developed a 55 node - 28 terminal solution.
As can be imagined, the plot is difficult to travel down each of the major
branches.

I've read the help files for ctree I saw where terminal nodes can be color
coded.

 plot(airct, type = "simple")
> plot(airct, terminal_panel = node_boxplot(airct, col = "blue",  + fill =
hsv(2/3, 0.5, 1)))

Here is my question:

Since my model has 55 nodes and 28 terminal nodes,(ie many branches)  is it
feasible to color code the each of the major branches and track the paths
down the decision tree?

 R 2.11.1, Windox XP


Thanks
Steve



Steve Friedman Ph. D.
Spatial Statistical Analyst
Everglades and Dry Tortugas National Park
950 N Krome Ave (3rd Floor)
Homestead, Florida 33034

steve_fried...@nps.gov
Office (305) 224 - 4282
Fax (305) 224 - 4147

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] select columns from dataframe

2010-07-09 Thread Jonathan Flowers
Hi,

I would like to extract columns from a dataframe using a vector of desired
column names.

The following working example uses the select argument in the subset
function to accomplish what I am trying to do.  Is there a better solution?

Thanks.

#my data
data <- data.frame("col1"=c(1,2,3),"col2"=c("A","B","C"),"col3"=c(4,5,6))

#names of desired columns
colnames <- c("col1","col3")

fun <- function(colname,dframe){
nframe <- subset(dframe,select=colname)
vec <- nframe[,1]
return(vec)
}

fun(colnames[1],data)
fun(colnames[2],data)

[[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] Calling Gnuplot from R

2010-07-09 Thread Tal Galili
Dear Greg,

I keep on being amazed at the abundance of functions you have packed into
the TeachingDemos package - thank you!

Tal



Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Fri, Jul 9, 2010 at 8:18 PM, Greg Snow  wrote:

> There is a basic interface between R and gnuplot in the TeachingDemos
> package, see ?gp.open
>
> Not much interest has been shown in this, so it is still pretty alpha
> level, but you can send your R data to gnuplot and have it create a basic
> plot.
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.s...@imail.org
> 801.408.8111
>
>
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> > project.org] On Behalf Of Christopher Desjardins
> > Sent: Thursday, July 08, 2010 9:22 AM
> > To: r-help@r-project.org
> > Subject: [R] Calling Gnuplot from R
> >
> > Hi,
> > I am wondering if there is a way to call Gnuplot from R and/or if
> > anyone can
> > recommend a package on CRAN capable of doing this?
> > Thanks,
> > Chris
> > PS - Please cc me on the response.
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-
> > guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] select columns from vector of column names

2010-07-09 Thread Jonathan Flowers
Hi

I want to extract columns from a data frame using a vector with the desired
column names.

This short example uses the select argument in the subset function to
accomplish what I am trying to do.  Is there a better solution?

#names of desired columns
colnames <- c("col1","col3")

#my data
data <- data.frame("col1"=c(1,2,3),"col2"=c("A","B","C"),"col3"=c(4,5,6))

fun <- function(colname,dframe){
nframe <- subset(dframe,select=colname)
vec <- nframe[,1]
return(vec)
}

fun(colnames[1],data)
fun(colnames[2],data)

[[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] nls error regarding numerics vs logicals

2010-07-09 Thread Duncan Murdoch

On 09/07/2010 1:51 PM, Jim Bouldin wrote:

I am trying to perform an nls for a valid negative exponential function:

zz=nls(y~constant+a.est*2.7183^(b.est*x),start=list(constant=4.0,a.est=-4,b.est
= -.005),trace=T)

and am getting a number of different error messages, the most problematic
of  which is "Error in nls(ring.area ~ constant + a.est * 2.7183^(b.est *
ba.beg), start = list(constant = 4,  : 
  REAL() can only be applied to a 'numeric', not a 'logical'"


I can't see where there are any "logicals" in this equation to cause this
problem.  Any help appreciated. Thank you.


1.  The expression you gave us is clearly not the one that produced the 
error:  it involved "ring.area" and "ba.beg".


2.  You don't tell us what x and y are, so we can't reproduce anything.

We can't help you if you don't tell us what the problem is.

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] R crashes with large vectors

2010-07-09 Thread Tengfei Yin
Hi Jeremie,

Maybe you can take a look at the bigmemory  package.
 If you have multi core or have access to clusters, you may want to use any
parallel computing strategy.

For plotting of large data, if you are using basic R graphics, first try to
use "line" instead of using 'point',

if this still doesn't working, you may want to try an alternative way by
using qtinterface (R-forge project), install qtbase and qtpaint, they are
still under development, but painting in QT interface is a lot faster for
large data set.

Best

Tengfei

On Fri, Jul 9, 2010 at 2:42 AM, Jeremie Smaga  wrote:

> Good afternoon,
>
> I have been experiencing a lot of crashes working with large vectors in R.
>
> Specifically, I am using XTS of length of minimum 120k elements.
>
> My problem is that I cannot display the vector (otherwise R crashes), I
> cannot plot it either (otherwise R crashes). That could be solved by
> reducing the amount of points.
>
> However, I have been performing some statistical opreations on is and even
> sd(myXTS) crashes R.
>
> By "crashes", I mean shuts down without any warning whatsoever.
>
> I use R 2.11.1 (64).
>
> Has anyone had the same kind of problem?
>
> Can we solve this?
>
> Best,
>
>
> --
> Jeremie
>
>[[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.
>



-- 
Tengfei Yin
MCDB PhD student
1620 Howe Hall, 2274,
Iowa State University
Ames, IA,50011-2274
Homepage: www.tengfei.name

[[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] nls error regarding numerics vs logicals

2010-07-09 Thread Jim Bouldin

I am trying to perform an nls for a valid negative exponential function:

zz=nls(y~constant+a.est*2.7183^(b.est*x),start=list(constant=4.0,a.est=-4,b.est
= -.005),trace=T)

and am getting a number of different error messages, the most problematic
of  which is "Error in nls(ring.area ~ constant + a.est * 2.7183^(b.est *
ba.beg), start = list(constant = 4,  : 
  REAL() can only be applied to a 'numeric', not a 'logical'"

I can't see where there are any "logicals" in this equation to cause this
problem.  Any help appreciated. Thank you.

Jim Bouldin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 plot two histograms overlapped in the same planecoordinate

2010-07-09 Thread Bert Gunter
Don't do this. The overlapping will confuse.

Plot them in a lattice display with one group above the other on the same
horizontal scale. See ?histogram.

Bert Gunter
Genentech Nonclinical Biostatistics
 
 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Barry Rowlingson
Sent: Friday, July 09, 2010 9:47 AM
To: Mao Jianfeng
Cc: r-help@r-project.org
Subject: Re: [R] how to plot two histograms overlapped in the same
planecoordinate

On Fri, Jul 9, 2010 at 2:29 PM, Mao Jianfeng  wrote:
> Dear R-help listers,
>
> I am new. I just want to get helps on how to plot two histograms
> overlapped in the same plane coordinate. What I did is very ugly.
> Could you please help me to improve it? I want to got a plot with semi-
> transparent overlapping region. And, I want to know how to specify the
> filled colors of the different histograms.
>
> I also prefer other solutions other than ggplot2.
>
> Many thanks to you.
>
>
> What I have done:
>
> library(ggplot2)
>
> age<-c(rnorm(100, 1.5, 1), rnorm(100, 5, 1))
> sex<-c(rep("F",100), rep("M", 100))
> mydata<-cbind(age, sex)
> mydata<-as.data.frame(mydata)
> head(mydata)
>

 Tried setting xlim with hist?

 par(mfrow=c(2,1))
 hist(age[sex=="M"],xlim=range(age))
 hist(age[sex=="F"],xlim=range(age))

Barry

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

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


Re: [R] Plotting text in existing plot?

2010-07-09 Thread Greg Snow
Others pointed you to the text function for the base graphics system.  But if 
what you want to do is use text, but have a simple way of specifying the center 
of the plot without computing the user coordinates by hand of the center, then 
look at the grconvertX and grconvertY functions.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Ralf B
> Sent: Friday, July 09, 2010 3:52 AM
> To: r-help@r-project.org
> Subject: [R] Plotting text in existing plot?
> 
> I would like to plot some text in a existing plot graph. Is there a
> very simple way to do that. It does not need to be pretty at all (just
> maybe a way to center it or define a position within the plot). ( ? )
> 
> Ralf
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Ctree Question

2010-07-09 Thread Steve_Friedman

Hello,

I've been using ctree and have developed a 55 node - 28 terminal solution.
As can be imagined, the plot is difficult to travel down each of the major
branches.

I've read the help files for ctree I saw where terminal nodes can be color
coded.

 plot(airct, type = "simple")
> plot(airct, terminal_panel = node_boxplot(airct, col = "blue",  + fill =
hsv(2/3, 0.5, 1)))

Here is my question:

Since my model has 55 nodes and 28 terminal nodes,(ie many branches)  is it
feasible to color code the each of the major branches and track the paths
down the decision tree?

 R 2.11.1, Windox XP


Thanks
Steve



Steve Friedman Ph. D.
Spatial Statistical Analyst
Everglades and Dry Tortugas National Park
950 N Krome Ave (3rd Floor)
Homestead, Florida 33034

steve_fried...@nps.gov
Office (305) 224 - 4282
Fax (305) 224 - 4147

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Calling Gnuplot from R

2010-07-09 Thread Greg Snow
There is a basic interface between R and gnuplot in the TeachingDemos package, 
see ?gp.open

Not much interest has been shown in this, so it is still pretty alpha level, 
but you can send your R data to gnuplot and have it create a basic plot.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Christopher Desjardins
> Sent: Thursday, July 08, 2010 9:22 AM
> To: r-help@r-project.org
> Subject: [R] Calling Gnuplot from R
> 
> Hi,
> I am wondering if there is a way to call Gnuplot from R and/or if
> anyone can
> recommend a package on CRAN capable of doing this?
> Thanks,
> Chris
> PS - Please cc me on the response.
> 
>   [[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] Query about using timestamps returned by SQL as 'factor' forsplit

2010-07-09 Thread Matthew Dowle
Hi Ted,

Well since you mentioned data.table (!) ...

If risk_input is a data.table consisting of 3 columns (m_id, sale_date, 
return_date) where the dates
are of class IDate (recently added to data.table by Tom) then try :

   risk_input[, fitdistr(return_date-sale_date,"normal"), by=list(m_id, 
year(sale_date), week(sale_date))]

Notice that the 'by' can contain expressions of columns, and lets you group 
by more than one expression.
You don't have to repeat the 'group by' expressions in the select, as you 
would do in SQL. data.table returns
those group columns automatically in the result, alongside the result of the 
j expression applied to each group.

If you need to aggregate by m_id, year and month rather than week another 
way is :

   risk_input[, fitdistr(return_date-sale_date,"normal"), by=list(m_id, 
round(sale_date,"month"))]

plyr and sqldf can do this task too by the way, and I'd highly recommend you 
take a look at those packages.

There are also many excellent datetime classes around which you could also 
consider.

The reason we need IDate in data.table is because data.table uses radix 
sorting, see ?sort.list. That is ultra fast for
integers. Again radix is something Tom added to data.table. The radix 
algorithm (see wikipedia) is specifically
designed to sort integers only. We would use Date, but that is stored as 
numeric. IDate is the same as Date
but stored as integer.

HTH,
Matthew


"Ted Byers"  wrote in message 
news:aanlktinchf3tfzkndcwolrwsxekgpfpjes3f8m5tq...@mail.gmail.com...
>I have a simple query as follows:
>
> "SELECT
> m_id,sale_date,YEAR(sale_date),WEEK(sale_date),return_type,DATEDIFF(return_date,sale_date)
> AS elapsed_time FROM risk_input"
>
> I can get, and view, all the data that that query returns.  The question 
> is,
> sale_date is a timestamp, and I need to call split to group this data by
> m_id and the week in which the sale occurred.  Obviously, I would normally
> need both YEAR and WEEK so that data from April this year is not combined
> with that from last year (the system is non-autonomous).  And then I need 
> to
> use lapply to apply fitdistr to each subsample.
>
> Obviously, I can handle all this data in either a data.frame or in a
> data.table.
>
> There are two aspects of the question.
>
> 1) Is there a function (or package) that will let me group (or regroup) 
> time
> series data into the week in which the data apply, properly taking into
> account the year that applies, in a single call passing sale_date as the
> argument?  If I can, then I can reduce the amount of data I draw from my
> MySQL server and the computational load it bears.
>
> 2) The example provided for split splits only according to a single 
> variable
> (*g <- airquality$Month;l <- split(airquality, g)*).  How would that 
> example
> be changed if there were two or more columns in the data.frame that are
> needed to define the groups?  I.E. in my example, I'd need to group by 
> m_id,
> and the year and week values that can be computed from sale_date.
>
> Thanks
>
> Ted
>
> [[alternative HTML version deleted]]
>

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


Re: [R] how to plot two histograms overlapped in the same plane coordinate

2010-07-09 Thread Barry Rowlingson
On Fri, Jul 9, 2010 at 2:29 PM, Mao Jianfeng  wrote:
> Dear R-help listers,
>
> I am new. I just want to get helps on how to plot two histograms
> overlapped in the same plane coordinate. What I did is very ugly.
> Could you please help me to improve it? I want to got a plot with semi-
> transparent overlapping region. And, I want to know how to specify the
> filled colors of the different histograms.
>
> I also prefer other solutions other than ggplot2.
>
> Many thanks to you.
>
>
> What I have done:
>
> library(ggplot2)
>
> age<-c(rnorm(100, 1.5, 1), rnorm(100, 5, 1))
> sex<-c(rep("F",100), rep("M", 100))
> mydata<-cbind(age, sex)
> mydata<-as.data.frame(mydata)
> head(mydata)
>

 Tried setting xlim with hist?

 par(mfrow=c(2,1))
 hist(age[sex=="M"],xlim=range(age))
 hist(age[sex=="F"],xlim=range(age))

Barry

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


Re: [R] how to plot two histograms overlapped in the same plane coordinate

2010-07-09 Thread Frank E Harrell Jr
Empirical CDFs are much better for this purpose, and allow 
superpositioning (see e.g. the Ecdf function in the Hmisc package). 
Otherwise look at histbackback in Hmisc.


Frank

On 07/09/2010 11:40 AM, Andrew Miles wrote:



I'm not sure what you are trying to do. Do you want one histogram for
males and one for females on the same graph? If so, the simplest way to
put two histograms together is to simply use the add parameter:

age.males=age[which(sex=="M")]
age.females=age[which(sex=="F")]

hist(age.males, col="blue")
hist(age.females, add=T)

The only problem is that the hist() function does not do
semi-transparency. I am not sure if other packages do. The code above
will give you a blue histogram for males, and clear histogram for
females on top of it. You'll probably have to manually alter the axes of
the histogram to give the histograms for males and females the same
break points (i.e. where one bar stops and another begins). See ?hist
for more information about that.

Andrew Miles
Department of Sociology
Duke University

On Jul 9, 2010, at 9:29 AM, Mao Jianfeng wrote:


Dear R-help listers,

I am new. I just want to get helps on how to plot two histograms
overlapped in the same plane coordinate. What I did is very ugly.
Could you please help me to improve it? I want to got a plot with semi-
transparent overlapping region. And, I want to know how to specify the
filled colors of the different histograms.

I also prefer other solutions other than ggplot2.

Many thanks to you.


What I have done:

library(ggplot2)

age<-c(rnorm(100, 1.5, 1), rnorm(100, 5, 1))
sex<-c(rep("F",100), rep("M", 100))
mydata<-cbind(age, sex)
mydata<-as.data.frame(mydata)
head(mydata)


qplot(age, data=mydata, geom="histogram", fill=sex, xlab="age",
ylab="count", alpha=I(0.5))


Best,


Mao J-F

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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.




--
Frank E Harrell Jr   Professor and ChairmanSchool of Medicine
 Department of Biostatistics   Vanderbilt University

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 plot two histograms overlapped in the same plane coordinate

2010-07-09 Thread Andrew Miles



I'm not sure what you are trying to do.  Do you want one histogram for  
males and one for females on the same graph? If so, the simplest way  
to put two histograms together is to simply use the add parameter:


age.males=age[which(sex=="M")]
age.females=age[which(sex=="F")]

hist(age.males, col="blue")
hist(age.females, add=T)

The only problem is that the hist() function does not do semi- 
transparency.  I am not sure if other packages do.  The code above  
will give you a blue histogram for males, and clear histogram for  
females on top of it.  You'll probably have to manually alter the axes  
of the histogram to give the histograms for males and females the same  
break points (i.e. where one bar stops and another begins).  See ?hist  
for more information about that.


Andrew Miles
Department of Sociology
Duke University

On Jul 9, 2010, at 9:29 AM, Mao Jianfeng wrote:


Dear R-help listers,

I am new. I just want to get helps on how to plot two histograms
overlapped in the same plane coordinate. What I did is very ugly.
Could you please help me to improve it? I want to got a plot with  
semi-

transparent overlapping region. And, I want to know how to specify the
filled colors of the different histograms.

I also prefer other solutions other than ggplot2.

Many thanks to you.


What I have done:

library(ggplot2)

age<-c(rnorm(100, 1.5, 1), rnorm(100, 5, 1))
sex<-c(rep("F",100), rep("M", 100))
mydata<-cbind(age, sex)
mydata<-as.data.frame(mydata)
head(mydata)


qplot(age, data=mydata, geom="histogram", fill=sex, xlab="age",
ylab="count", alpha=I(0.5))


Best,


Mao J-F

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


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


Re: [R] how can achive step by step execution of the script

2010-07-09 Thread Bert Gunter
No - devAskNewPage is not what the OP asked for.


1. The following are, but probably only work when R is in interactive mode
(?interactive), e.g. in the GUI:

2. ?winDialog   ?file.choose  ?choose.files  ?select.list  ?readline
and friends
 and for keyboard: ?getGraphicsEvent


Bert Gunter
Genentech Nonclinical Biostatistics
 
 
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Allan Engelhardt
Sent: Friday, July 09, 2010 8:43 AM
To: vijaysheegi
Cc: r-help@r-project.org
Subject: Re: [R] how can achive step by step execution of the script

Sounds like you want devAskNewPage(TRUE) or the related 
options("device.ask.default").  See help("devAskNewPage", 
package="grDevices").

Hope this helps.

Allan

On 09/07/10 13:54, vijaysheegi wrote:
> Hi R Experts,
> I have certain code ,i want to achive interactive execution .
> For ex:
> 1. as part of input ,it should ask file name  or table name as input.
> 2.in script so many graphs i need to draw,it should wait till certain key
is
> pressed .
> 3:i am using windows R,rscript  is not working.
>
>
>
> Please some one help me.
>
> Thanks Experts in advance
>
>
>

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

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


[R] interpretation of svm models with the e1071 package

2010-07-09 Thread manuel.martin

Dear all,

after having calibrated a svm model through the svm() command of the 
e1071 package, is there a way to
i) represent the modeled relationships between the y and X variables 
(response variable vs. predictors)?

ii) rank the influence of the predictors used in the model?

Right now I am more interested in regression models, but I guess this 
would be useful for classification too.


Thank you in advance,  manuel


--


INRA - InfoSol
Centre de recherche d'Orléans
2163 Avenue de la Pomme de Pin
CS 40001 ARDON
45075 ORLEANS Cedex 2
tel : (33) (0)2 38 41 48 21
fax : (33) (0)2 38 41 78 69
http://www.gissol.fr
http://bdat.orleans.inra.fr
00--

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 can i draw a graph with high and low data points

2010-07-09 Thread Tal Galili
Hi Nathaniel ,

Could you give us a simple example of your data using the
?dput
Function?

Basically you might want to draw the axis yourself, and connect the lines is
possible through using points(..., type = "l")
But I'd rather try and answer this with simple example data to be sure I
understand what you mean.



Tal


Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Fri, Jul 9, 2010 at 1:39 PM, Nathaniel Saxe wrote:

>
> Hi Tal, Thanks for your help.
>
>
> I've had a look at the site, and what i wanted to do was to plot X and Y
> where X is a characters and Y is numeric. The problem I'm having now is
> that
> the X axis isn't characters but just numbers from 1 onwards and when i plot
> it, the data i have is in descending order which isn't shown on the graph.
>
> I have this at the moment:
>
> plot(1:nrow(dat),dat$Mean,type="b",xaxt="n",
>ylim=c(min(dat$lci),max(dat$uci)),
>xlab="",ylab="HR",)
>
> It gives me sort of what I want. It has the Y values in descending order,
> but it doesn't give me the text on the x axis and I was also thinking of
> plotting the upper and lower confidence intervals with a line connecting
> the
> two. I can add in the upper and lower CI values separately, but I don't
> know
> how to join the two together.
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/How-can-i-draw-a-graph-with-high-and-low-data-points-tp2282524p2283194.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] Plotting text in existing plot?

2010-07-09 Thread Tal Galili
Possible fortune.

:)



Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Fri, Jul 9, 2010 at 6:22 PM, Bert Gunter  wrote:

>
>  Original poster wanted a simple way to do it, but when R has three
> graphics systems, four OO systems, and a zillion helpful people
> there's never a simple way :)
>
> -- Rather, I'd say it has a zillion simple ways. :)
>Bert
>
>
>
> Barry
>
> --
> blog: http://geospaced.blogspot.com/
> web: http://www.maths.lancs.ac.uk/~rowlings
> web: http://www.rowlingson.com/
> twitter: http://twitter.com/geospacedman
> pics: http://www.flickr.com/photos/spacedman
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] how can achive step by step execution of the script

2010-07-09 Thread Allan Engelhardt
Sounds like you want devAskNewPage(TRUE) or the related 
options("device.ask.default").  See help("devAskNewPage", 
package="grDevices").


Hope this helps.

Allan

On 09/07/10 13:54, vijaysheegi wrote:

Hi R Experts,
I have certain code ,i want to achive interactive execution .
For ex:
1. as part of input ,it should ask file name  or table name as input.
2.in script so many graphs i need to draw,it should wait till certain key is
pressed .
3:i am using windows R,rscript  is not working.



Please some one help me.

Thanks Experts in advance





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


Re: [R] Data Frame Manipulation using function

2010-07-09 Thread David Winsemius
Really? I don't usually think of Vectorize as a performance  
enhancement, probably because my use of with a complex function then  
gets applied to 4.5 million records. I need to go out, get a cup of  
coffee, and leave it alone for about half an hour. I tried  recently  
to figure out how I can do the matrix look-up and function application  
without the Vectorize route but gave up after a couple of hours after  
realizing that I had a method that worked and I had spent way more  
time on it than just doing it would have.

Glad it helped.
David.

On Jul 9, 2010, at 11:01 AM, harsh yadav wrote:

> Hi,
>
> Thanks a lot.
> The Vectorize method worked and its much faster than looping through  
> the data frame.
>
> Regards,
> Harsh Yadav
>
> On Thu, Jul 8, 2010 at 11:06 PM, David Winsemius  > wrote:
>
> On Jul 8, 2010, at 10:33 PM, Erik Iverson wrote:
>
>
> I have a data frame:
> id  
> url urlType
> 1 1  www.yahoo.com  www.yahoo.com>1
> 2 2  www.google.com/?search=  search=> 2
> 3 3  www.google.com  www.google.com>   1
> 4 4  www.yahoo.com/?query=  query=>   2
> 5 5  www.gmail.com  www.gmail.com> 1
>
> This is not output from ?dput, which means more work to read it in.
>
>
> Yeah it was kind of pain, but ...
>
> dta <- read.table(textConnection(' id  
> url urlType
>
> 1 1  "www.yahoo.com "  1
> 2 2  "www.google.com/?search=  search=>" 2
> 3 3  "www.google.com " 1
> 4 4  "www.yahoo.com/?query=  query=>"   2
> 5 5  "www.gmail.com " 1') )
>
>
>
>
> Here is the definition for WHITELIST:-
> WHITELIST = "[?]query=, [?]search="
> WHITELIST <- unlist(trim(strsplit(trim(WHITELIST), ",")))
>
> What is the 'trim' function?  I do not have that defined.
>
> Perhaps David's answer will work for you...
>
> Seems to ... after I fixed my incorrect cmd-V paste of the function  
> name and guessing that trim was the one in gdata:
>
> > require(gdata)
>
> > checkBaseLine <- function(s){
> + for (listItem in WHITELIST){
> + if(regexpr(as.character(listItem), s)[1] > -1){
> + return(TRUE)
> + }
> + }
> + return(FALSE)
> + }
> >
> > #Here is the definition for WHITELIST:-
>
> >
> > WHITELIST = "[?]query=, [?]search="
> > WHITELIST <- unlist(trim(strsplit(trim(WHITELIST), ",")))
> > vcheck <- Vectorize(checkBaseLine)
> >
> > vcheck <- Vectorize(checkBaseLine)
> >
> > dta[ dta$urlType != 1 & vcheck(dta$url) , "url" ]
> [1] www.google.com/?search=  
> www.yahoo.com/?query= 
>  
> 5 Levels: www.gmail.com  www.google.com 
>  > ... www.yahoo.com/?query= 
>
> -- 
> David.
>

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] Plotting text in existing plot?

2010-07-09 Thread Bert Gunter

 Original poster wanted a simple way to do it, but when R has three
graphics systems, four OO systems, and a zillion helpful people
there's never a simple way :)

-- Rather, I'd say it has a zillion simple ways. :)
   Bert



Barry

-- 
blog: http://geospaced.blogspot.com/
web: http://www.maths.lancs.ac.uk/~rowlings
web: http://www.rowlingson.com/
twitter: http://twitter.com/geospacedman
pics: http://www.flickr.com/photos/spacedman

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] print.xtable suppress my row.names

2010-07-09 Thread n.via...@libero.it
Dear list,
someone knows why the print.xtable doesnt print row.names? I dident do 
anything with the options.may depends on the size of my table???
This is my code:

\documentclass[a4paper]{article}
\title{SCHEMA DI BILANCIO PER SINGOLE AZIENDE}
\begin{document}
\maketitle
\hline
<>=
library(xtable)
library(plyr)
rep=Bilanci
rep$SPA<-as.numeric(NA)
rep$SPP<-as.numeric(NA)
rep$CE<-as.numeric(NA)
rep$IN<-as.numeric(NA)
rep$VA<-as.numeric(NA)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,PROD=EC01+EC02+EC03)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,VP=rev(rev(PROD)*c(rev(PROD ^ 
(-1)),0)[-1]))
rep$CTOT<-Bilanci$AA01+Bilanci$AA03+Bilanci$AA04
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,CIRCOL=c(NA,rev(rev(AA03)*0.
5+c(rev(AA03)*0.5,NA)[-1])[-1])+c(NA,rev(rev(AA04)*0.5+c(rev(AA04)*0.5,NA)[-1])
[-1])+c(NA,rev(rev(AL04)*0.5+c(rev(AL04)*0.5,NA)[-1])[-1]))
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,IE01=(EC04-EC05)/PROD*100)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,IE02=EC06/PROD*100)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,IE03=EC07/PROD*100)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,IE07=(EC11A+EC11C)/PROD*100)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,MOL=100+IE07-IE01-IE02-IE03)
rep$IR<-as.numeric(NA)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,ROI=((PROD-EC04+EC05-EC06-
EC07+EC11C+EC11A-EC08)*c(NA,(rev(rev(CTOT)*0.5+c(rev(CTOT)*0.5,NA)[-1])^(-1))
[-1])*100))
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,RNC=((EC12)*c(NA,(rev(rev
(CTOT)*0.5+c(rev(CTOT)*0.5,NA)[-1])^(-1))[-1])*100))
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,EBIT=ROI+RNC)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,RF=((EC10-EC09)*c(NA,(rev(rev
(CTOT)*0.5+c(rev(CTOT)*0.5,NA)[-1])^(-1))[-1])*100))
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,ROE=((EC14)*c(NA,(rev(rev
(AL01)*0.5+c(rev(AL01)*0.5,NA)[-1])^(-1))[-1])*100))
rep$CC<-as.numeric(NA)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,IC01=(CIRCOL/PROD)*100)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,IC02=c(NA,rev(rev(AA03)*0.5+c
(rev(AA03)*0.5,NA)[-1])[-1])/PROD*365)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,IC03=c(NA,rev(rev(AA04)*0.5+c
(rev(AA04)*0.5,NA)[-1])[-1])/EC01*365)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,IC04=c(NA,rev(rev(AL04)*0.5+c
(rev(AL04)*0.5,NA)[-1])[-1])/(EC04+EC06)*365)
rep$ES<-as.numeric(NA)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,IF04=(EC14+EC08)/PROD*100)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,IN03=c(NA,rev(rev(AA01)*0.5+c
(rev(AA01)*0.5,NA)[-1])[-1])/PROD*100)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,IN04=c(NA,rev(rev(CTOT)*0.5+c
(rev(CTOT)*0.5,NA)[-1])[-1])/PROD*100)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,IN05=AA02/AA07*100)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,IN07=AL01/AL06*100)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,IN08=AL05/AL06*100)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,IN09=IN08/IN07)
rep<-ddply(rep,c("CFISCALE","RAGSOCB"),transform,IN10=((EC09)*c(NA,(rev(rev
(AL05)*0.5+c(rev(AL05)*0.5,NA)[-1])^(-1))[-1])*100))
rep1=subset(rep,select=c(RAGSOCB,CFISCALE,ANNO,SPA,AA01,AA01I,AA01M,AA02,AA02B,
AA02L,AA03,AA04,AA05,AA06,AA07,SPP,AL01,AL02,AL03,AL04,AL04A,AL04B,AL05,AL05B,
AL05L,AL99,AL06,CE,EC01,EC02,EC03,EC04,EC05,EC06,EC07,EC08,EC08A,EC08B,EC09,
EC10,EC11,EC11A,EC11C,EC12,EC13,EC14,EC15,EC16,IN,VA,PROD,CTOT,CIRCOL,MOL,IR,
ROI,RNC,EBIT,RF,ROE,CC,IC01,IC02,IC03,IC04,ES,IF04,IN03,IN04,IN05,IN07,IN08,
IN09,IN10))
mynames<-names(rep1)
mynames[mynames=="SPA"]<-"STATO_PATRIMONIALE_ATTIVO"
mynames[mynames=="AA01"]<-"Immobilizzazioni_tecniche_nette"
mynames[mynames=="AA01I"]<-"Immobilizzazioni_imm_nette"
mynames[mynames=="AA01M"]<-"Immobilizzazioni_mat_nette"
mynames[mynames=="AA02"]<-"Partecipazioni e crediti fin"
mynames[mynames=="AA02B"]<-"Attivita fin a breve"
mynames[mynames=="AA02L"]<-"Immobilizzazioni finan"
mynames[mynames=="AA03"]<-"Magazzino"
mynames[mynames=="AA04"]<-"Crediti commerciali"
mynames[mynames=="AA05"]<-"Liquidita"
mynames[mynames=="AA06"]<-"Altre attivita"
mynames[mynames=="AA07"]<-"Tot attivita"
mynames[mynames=="SPP"]<-"STATO PATRIMONIALE PASSIVO"
mynames[mynames=="AL01"]<-"Capitale netto"
mynames[mynames=="AL02"]<-"Fondo tfr"
mynames[mynames=="AL03"]<-"Altri fondi"
mynames[mynames=="AL04"]<-"Debiti commerciali"
mynames[mynames=="AL04A"]<-"Anticipi di clienti"
mynames[mynames=="AL04B"]<-"Debiti vs fornitori"
mynames[mynames=="AL05"]<-"Debiti fin tot"
mynames[mynames=="AL05B"]<-"Debiti fin a breve"
mynames[mynames=="AL05L"]<-"Debiti fin a medio lungo"
mynames[mynames=="AL99"]<-"Altre passivita"
mynames[mynames=="AL06"]<-"Tot passivita"
mynames[mynames=="CE"]<-"CONTO ECONOMICO"
mynames[mynames=="EC01"]<-"Ricavi netti"
mynames[mynames=="EC02"]<-"Produzione int capitalizzate"
mynames[mynames=="EC03"]<-"Variazione scorte prod finiti"
mynames[mynames=="EC04"]<-"Acquisti"
mynames[mynames=="EC05"]<-"Variazioni scorte mat prime"
mynames[mynames=="EC06"]<-"Costi per servizi god beni terz

Re: [R] Function on columns of a dataframe

2010-07-09 Thread Eik Vettorazzi
just to satisfy my curiousity,
aggregate(bla, list(bla$cat), max)

works for me and resulted in

  Group.1  x  catv1v2v3v4
1cat1  5 cat1 0.6337076 0.2887081 0.3629962 0.5328683
2cat2 10 cat2 0.5519426 0.6076447 0.4593770 0.9632341
3cat3 11 cat3 0.6094089 0.6152059 0.5670835 0.9084917
4cat4  8 cat4 0.4772603 0.2149017 0.4534723 0.7824375
5cat5  9 cat5 0.6582466 0.3150096 0.5512863 1.3524582
6cat6 12 cat6 0.4632893 0.4498425 0.3926193 0.8023014

so, what didn't work for you, except for the "extra" columns? (taking
for granted, that random numbers aren't the same)

Am 09.07.2010 16:47, schrieb David Winsemius:
>
> On Jul 9, 2010, at 10:26 AM, Eik Vettorazzi wrote:
>
>> you are right. But maybe "aggregate" is close to the desired result?
>>
>> aggregate(bla, list(bla$cat), max)
>
> Right. I couldn't get it to work until I removed the first two columns:
>
> aggregate(bla[,-(1:2)], list(bla$cat), max)
>
> Then I got pretty much the same dataframe as I would have with :
>
> as.data.frame(lapply( bla[, -(1:2)], function(x) tapply(x, bla$cat,
> max) ))
> v1v2v3v4
> cat1 0.4634519 0.5274645 0.6051479 0.7586322
> cat2 0.4062700 0.4282639 0.4443707 0.8419526
> cat3 0.4816403 0.4996033 0.3538144 0.9456385
> cat4 0.6354560 0.3558259 0.3646292 0.1907295
> cat5 0.6663811 0.2154201 0.5059900 0.7573575
> cat6 0.5260832 0.3934063 0.3545962 0.6412563
>
> Except that aggregate version returns it with a "Group.1" column of
> "cat"s while the other version returned it with the "cat" names in the
> rownames. A matter of taste?
>

-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] random sample from arrays

2010-07-09 Thread Joris Meys
Could you elaborate?

Both

 x <- 1:4
 set <- matrix(nrow = 50, ncol = 11)
  for(i in c(1:11)){
set[,i] <-sample(x,50)
print(c(i,"->", set), quote = FALSE)
   }

and

 x <- 1:4
 set <- matrix(nrow = 50, ncol = 11)
 for(i in c(1:50)){
   set[i,] <-sample(x,11)
   print(c(i,"->", set), quote = FALSE)
  }

run perfectly fine on my computer.
Cheers


On Fri, Jul 9, 2010 at 3:10 PM, Assa Yeroslaviz  wrote:
> Hi Joris,
> I guess i did it wrong again.
> but your example didn't work either. I still get the error massage.
>
> but replicate function just fine. I can even replicate the whole array
> lines.
>
> THX
>
> Assa
>
> On Thu, Jul 8, 2010 at 15:20, Joris Meys  wrote:
>>
>> Don't know what exactly you're trying to do, but you make a matrix
>> with 11 columns and 50 rows, then treat it as a vector. On top of
>> that, you try to fill 50 rows/columns with 50 values. Off course that
>> doesn't work. Did you check the warning messages when running the
>> code?
>>
>> Either do :
>>
>>  for(i in c(1:11)){
>>    set[,i] <-sample(x,50)
>>    print(c(i,"->", set), quote = FALSE)
>>   }
>>
>> or
>>
>>  for(i in c(1:50)){
>>    set[i,] <-sample(x,11)
>>    print(c(i,"->", set), quote = FALSE)
>>   }
>>
>> Or just forget about the loop altogether and do :
>>
>> set <- replicate(11,sample(x,50))
>> or
>> set <- t(replicate(50,sample(x,11)))
>>
>> cheers
>>
>> On Thu, Jul 8, 2010 at 8:04 AM, Assa Yeroslaviz  wrote:
>> > Hello R users,
>> >
>> > I'm trying to extract random samples from a big array I have.
>> >
>> > I have a data frame of over 40k lines and would like to produce around
>> > 50
>> > random sample of around 200 lines each from this array.
>> >
>> > this is the matrix
>> >          ID xxx_1c xxx__2c xxx__3c xxx__4c xxx__5T xxx__6T xxx__7T
>> > xxx__8T
>> > yyy_1c yyy_1c _2c
>> > 1 A_512  2.150295  2.681759  2.177138  2.142790  2.115344  2.013047
>> > 2.115634  2.189372  1.643328  1.563523
>> > 2 A_134 12.832488 12.596373 12.882581 12.987091 11.956149 11.994779
>> > 11.650336 11.995504 13.024494 12.776322
>> > 3 A_152  2.063276  2.160961  2.067549  2.059732  2.656416  2.075775
>> > 2.033982  2.111937  1.606340  1.548940
>> > 4 A_163  9.570761 10.448615  9.432859  9.732615 10.354234 10.993279
>> > 9.160038  9.104121 10.079177  9.828757
>> > 5 A_184  3.574271  4.680859  4.517047  4.047096  3.623668  3.021356
>> > 3.559434  3.156093  4.308437  4.045098
>> > 6 A_199  7.593952  7.454087  7.513013  7.449552  7.345718  7.367068
>> > 7.410085  7.022582  7.668616  7.953706
>> > ...
>> >
>> > I tried to do it with a for loop:
>> >
>> > genelist <- read.delim("/user/R/raw_data.txt")
>> > rownames(genelist) <- genelist[,1]
>> > genes <- rownames(genelist)
>> >
>> > x <- 1:4
>> > set <- matrix(nrow = 50, ncol = 11)
>> >
>> > for(i in c(1:50)){
>> >    set[i] <-sample(x,50)
>> >    print(c(i,"->", set), quote = FALSE)
>> >    }
>> >
>> > which basically do the trick, but I just can't save the results outside
>> > the
>> > loop.
>> > After having the random sets of lines it wasn't a problem to extract the
>> > line from the arrays using subset.
>> >
>> > genSet1 <-sample(x,50)
>> > random1 <- genes %in% genSet1
>> > subsetGenelist <- subset(genelist, random1)
>> >
>> >
>> > is there a different way of creating these random vectors or saving the
>> > loop
>> > results outside tjhe loop so I cn work with them?
>> >
>> > Thanks a lot
>> >
>> > Assa
>> >
>> >        [[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.
>> >
>>
>>
>>
>> --
>> Joris Meys
>> Statistical consultant
>>
>> Ghent University
>> Faculty of Bioscience Engineering
>> Department of Applied mathematics, biometrics and process control
>>
>> tel : +32 9 264 59 87
>> joris.m...@ugent.be
>> ---
>> Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
>
>



-- 
Joris Meys
Statistical consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

tel : +32 9 264 59 87
joris.m...@ugent.be
---
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Data Frame Manipulation using function

2010-07-09 Thread harsh yadav
Hi,

Thanks a lot.
The Vectorize method worked and its much faster than looping through the
data frame.

Regards,
Harsh Yadav

On Thu, Jul 8, 2010 at 11:06 PM, David Winsemius wrote:

>
> On Jul 8, 2010, at 10:33 PM, Erik Iverson wrote:
>
>
>>  I have a data frame:
>>> id url
>>> urlType
>>> 1 1  www.yahoo.com 
>>>  1
>>> 2 2  www.google.com/?search= 
>>>   2
>>> 3 3  www.google.com 
>>>   1
>>> 4 4  www.yahoo.com/?query= 
>>> 2
>>> 5 5  www.gmail.com 
>>>   1
>>>
>>
>> This is not output from ?dput, which means more work to read it in.
>>
>>
> Yeah it was kind of pain, but ...
>
> dta <- read.table(textConnection(' id url
>   urlType
>
> 1 1  "www.yahoo.com "  1
> 2 2  "www.google.com/?search= " 2
> 3 3  "www.google.com " 1
> 4 4  "www.yahoo.com/?query= "   2
> 5 5  "www.gmail.com " 1') )
>
>
>
>
>>  Here is the definition for WHITELIST:-
>>> WHITELIST = "[?]query=, [?]search="
>>> WHITELIST <- unlist(trim(strsplit(trim(WHITELIST), ",")))
>>>
>>
>> What is the 'trim' function?  I do not have that defined.
>>
>> Perhaps David's answer will work for you...
>>
>
> Seems to ... after I fixed my incorrect cmd-V paste of the function name
> and guessing that trim was the one in gdata:
>
> > require(gdata)
>
> > checkBaseLine <- function(s){
> + for (listItem in WHITELIST){
> + if(regexpr(as.character(listItem), s)[1] > -1){
> + return(TRUE)
> + }
> + }
> + return(FALSE)
> + }
> >
> > #Here is the definition for WHITELIST:-
>
> >
> > WHITELIST = "[?]query=, [?]search="
> > WHITELIST <- unlist(trim(strsplit(trim(WHITELIST), ",")))
> > vcheck <- Vectorize(checkBaseLine)
> >
> > vcheck <- Vectorize(checkBaseLine)
> >
> > dta[ dta$urlType != 1 & vcheck(dta$url) , "url" ]
> [1] www.google.com/?search= 
> www.yahoo.com/?query= 
> 5 Levels: www.gmail.com  www.google.com <
> http://www.google.com> ... www.yahoo.com/?query= <
> http://www.yahoo.com/?query=>
>
> --
> David.
>

[[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] distributing a value for a given month across the number of weeks in that month

2010-07-09 Thread Dimitri Liakhovitski
Wow, Gabor - that's amazing - thank you so much!
Dimitri

On Fri, Jul 9, 2010 at 10:22 AM, Gabor Grothendieck
 wrote:
> On Fri, Jul 9, 2010 at 9:35 AM, Dimitri Liakhovitski
>  wrote:
>> Hello!
>>
>> Any hint would be greatly appreciated.
>> I have a data frame that contains (a) monthly dates and (b) a value
>> that corresponds to each month - see the data frame "monthly" below:
>>
>> monthly<-data.frame(month=c(20100301,20100401,20100501),monthly.value=c(100,200,300))
>> monthly$month<-as.character(monthly$month)
>> monthly$month<-as.Date(monthly$month,"%Y%m%d")
>> (monthly)
>>
>> I need to split each month into weeks, e.g., weeks that start on
>> Monday (it could as well be Sunday - it does not really matter) and
>> distribute the monthly value evenly across weeks. So, if a month has 5
>> Mondays, then the monthly value should be dividied by 5, but if a
>> month has only 4 weeks, then the monthly value should be divided by 4.
>>
>> The output I need is like this:
>>
>> week          weekly.value
>> 2010-03-01   20
>> 2010-03-08   20
>> 2010-03-15   20
>> 2010-03-22   20
>> 2010-03-29   20
>> 2010-04-05   50
>> 2010-04-12   50
>> 2010-04-19   50
>> 2010-04-26   50
>> 2010-05-03   60
>> 2010-05-10   60
>> 2010-05-17   60
>> 2010-05-24   60
>> 2010-05-31   60
>>
>
>
> There is new functionality in na.locf in the development version
> of zoo that makes it particularly convenient to do this.
>
> First create a zoo object z from monthly and get a vector of all
> the mondays.  Then use na.locf to place the monthly value in each
> monday and ave to distribute them out.
>
>
> library(zoo)
>
> # pull in development version of na.locf.zoo
> source("http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/zoo/R/na.locf.R?revision=725&root=zoo";)
>
> # convert to zoo
> z <- with(monthly, zoo(monthly.value, month))
>
> # get sequence of all dates and from that get mondays
> all.dates <- seq(start(z), as.Date(as.yearmon(end(z)), frac = 1), by = "day")
> mondays <- all.dates[weekdays(all.dates) == "Monday"]
>
> # use na.locf to fill in mondays and ave to distribute them
> weeks <- na.locf(z, xout = mondays)
> weeks[] <- ave(weeks, as.yearmon(mondays), FUN = function(x) x[1]/length(x))
>
> # show output in a few different formats
> weeks
> as.data.frame(weeks)
> data.frame(Monday = as.Date(time(weeks)), value = weeks)
> data.frame(Monday = as.Date(time(weeks)), value = weeks, row.names = NULL)
> plot(weeks)
>
> The output looks like this:
>
>> weeks
> 2010-03-01 2010-03-08 2010-03-15 2010-03-22 2010-03-29 2010-04-05 2010-04-12
>        20         20         20         20         20         50         50
> 2010-04-19 2010-04-26 2010-05-03 2010-05-10 2010-05-17 2010-05-24 2010-05-31
>        50         50         60         60         60         60         60
>> as.data.frame(weeks)
>           weeks
> 2010-03-01    20
> 2010-03-08    20
> 2010-03-15    20
> 2010-03-22    20
> 2010-03-29    20
> 2010-04-05    50
> 2010-04-12    50
> 2010-04-19    50
> 2010-04-26    50
> 2010-05-03    60
> 2010-05-10    60
> 2010-05-17    60
> 2010-05-24    60
> 2010-05-31    60
>
>
>  data.frame(Monday = as.Date(time(weeks)), value = weeks, row.names = NULL)
>       Monday value
> 1  2010-03-01    20
> 2  2010-03-08    20
> 3  2010-03-15    20
> 4  2010-03-22    20
> 5  2010-03-29    20
> 6  2010-04-05    50
> 7  2010-04-12    50
> 8  2010-04-19    50
> 9  2010-04-26    50
> 10 2010-05-03    60
> 11 2010-05-10    60
> 12 2010-05-17    60
> 13 2010-05-24    60
> 14 2010-05-31    60
>



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


[R] print.trellis draw.in - plaintext (gmail mishap)

2010-07-09 Thread Mark Connolly
I am attempting to plot a trellis object on a grid.

vplayout = viewport(layout.pos.row=x, layout.pos.col=y)

grid.newpage()
pushViewport(viewport(layout=grid.layout(2,2)))

g1 = ggplot() ...
g2 = ggplot() ...
g3 = ggplot() ...
p = xyplot() ...

# works as expected
print(g1, vp=vplayout(1,1))
print(g2, vp=vplayout(1,2))
print(g3, vp=vplayout(2,1))

# does not work
print(  p,
 newpage=FALSE,
 draw.in=vplayout(2,2)$name)

Error in grid.Call.graphics("L_downviewport", name$name, strict) :
  Viewport 'GRID.VP.112' was not found


What am I doing wrong?

Thanks!

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


Re: [R] Function on columns of a dataframe

2010-07-09 Thread David Winsemius


On Jul 9, 2010, at 10:26 AM, Eik Vettorazzi wrote:


you are right. But maybe "aggregate" is close to the desired result?

aggregate(bla, list(bla$cat), max)


Right. I couldn't get it to work until I removed the first two columns:

aggregate(bla[,-(1:2)], list(bla$cat), max)

Then I got pretty much the same dataframe as I would have with :

as.data.frame(lapply( bla[, -(1:2)], function(x) tapply(x, bla$cat,  
max) ))

v1v2v3v4
cat1 0.4634519 0.5274645 0.6051479 0.7586322
cat2 0.4062700 0.4282639 0.4443707 0.8419526
cat3 0.4816403 0.4996033 0.3538144 0.9456385
cat4 0.6354560 0.3558259 0.3646292 0.1907295
cat5 0.6663811 0.2154201 0.5059900 0.7573575
cat6 0.5260832 0.3934063 0.3545962 0.6412563

Except that aggregate version returns it with a "Group.1" column of  
"cat"s while the other version returned it with the "cat" names in the  
rownames. A matter of taste?


--
David.


Am 09.07.2010 16:01, schrieb David Winsemius:


On Jul 9, 2010, at 9:46 AM, Eik Vettorazzi wrote:


Hi Nils,
have a look at
?tapply
hth.


Perhaps this will be part way there (I couldn't really figure out the
desired structure of the final object):

lapply( bla[, -(1:2)], function(x) tapply(x, bla$cat, max) )

$v1
cat1  cat2  cat3  cat4  cat5  cat6
0.4634519 0.4062700 0.4816403 0.6354560 0.6663811 0.5260832

$v2
cat1  cat2  cat3  cat4  cat5  cat6
0.5274645 0.4282639 0.4996033 0.3558259 0.2154201 0.3934063

$v3
cat1  cat2  cat3  cat4  cat5  cat6
0.6051479 0.4443707 0.3538144 0.3646292 0.5059900 0.3545962

$v4
cat1  cat2  cat3  cat4  cat5  cat6
0.7586322 0.8419526 0.9456385 0.1907295 0.7573575 0.6412563




Am 09.07.2010 15:37, schrieb LogLord:

Hi,

I would like to assign the largest value of a column to a specific
category
and repeat this for each column (v1 - v4).



x=c(1:12)
cat 
= 
c 
("cat1 
","cat5 
","cat2 
","cat2","cat1","cat5","cat3","cat4","cat5","cat2","cat3","cat6")


v1=rnorm(12,0.5,0.1)
v2=rnorm(12,0.3,0.2)
v3=rnorm(12,0.4,0.1)
v4=rnorm(12,0.6,0.3)
bla=data.frame(x,cat,v1,v2,v3,v4)
bla


  x  catv1 v2v3 v4
1   1 cat1 0.4013144 0.54839317 0.3946393  0.8679266
2   2 cat5 0.4595873 0.45788906 0.4030078  0.5919596
3   3 cat2 0.4542865 0.21516928 0.2777649  0.6112099
4   4 cat2 0.4787950 0.06252512 0.5095611  0.6450795
5   5 cat1 0.4910746 0.56591049 0.5151813  0.8465181
6   6 cat5 0.4194397 0.16592579 0.4361643  0.6415192
7   7 cat3 0.6148564 0.32240342 0.2690108  0.7114133
8   8 cat4 0.6174652 0.28076152 0.4577064 -0.2567284
9   9 cat5 0.4775395 0.28611768 0.4660210  0.4634120
10 10 cat2 0.4802962 0.03715569 0.4506361  1.0063235
11 11 cat3 0.6495094 0.33303172 0.3352933  1.4390324
12 12 cat6 0.4891481 0.45355589 0.3880739  0.7831656



I can assign this by the sqldf() command for each column but I  
would

like to
automate this as I have many columns.



select=sqldf("select cat, max(v1) FROM bla GROUP BY cat")
select


 cat   max(v1)
1 cat1 0.4910746
2 cat2 0.4802962
3 cat3 0.6495094
4 cat4 0.6174652
5 cat5 0.4775395
6 cat6 0.4891481




Finally, I would like to have a dataframe where where the cat is
followed by
each column maximum.

Thanks for your help!



--
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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



--
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] strange floor rounding

2010-07-09 Thread Duncan Murdoch

On 09/07/2010 10:27 AM, Trafim Vanishek wrote:

Thanks everybody for referring me to FAQ 7.31 but I don't see how to solve
it.
I am giving a concrete number and I need to get 58 not 57. Seems, there is
no way?
  
You aren't giving a "concrete number".  You're giving a string of three 
characters, which R interprets as a number that's a little bit less than 
0.58, because
there is no way to represent the number 0.58 in the floating point 
format that R uses.  So it is calculating the right answer.


If you want to work with exact 2 decimal place values, you should not 
use floating point storage.  One alternative is to work with integers 
equal to 100 times the value you want, and then divide by 100 at the 
very end of the operation for printing.


Duncan Murdoch

On Fri, Jul 9, 2010 at 4:05 PM, David Winsemius wrote:

>
> On Jul 9, 2010, at 9:46 AM, Trafim Vanishek wrote:
>
>  Dear all,
>>
>> might seem and easy question but I cannot figure it out.
>>
>> floor(100*(.58))
>> [1] 57
>>
>> where is the trick here?
>>
>
> FAQ 7.31
>
>
> And how can I end up with the right answer?
>>
>
> Define right, please. (There have been several questions in the last week
> for which FAQ 7.31 was the answer and some of the responses had useful
> links.)
>
> --
> 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.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] strange floor rounding

2010-07-09 Thread Peter Ehlers

On 2010-07-09 8:27, Trafim Vanishek wrote:

Thanks everybody for referring me to FAQ 7.31 but I don't see how to solve
it.
I am giving a concrete number and I need to get 58 not 57. Seems, there is
no way?


Sure there is: round(100*0.58).

  -Peter Ehlers



On Fri, Jul 9, 2010 at 4:05 PM, David Winsemiuswrote:



On Jul 9, 2010, at 9:46 AM, Trafim Vanishek wrote:

  Dear all,


might seem and easy question but I cannot figure it out.

floor(100*(.58))
[1] 57

where is the trick here?



FAQ 7.31


And how can I end up with the right answer?




Define right, please. (There have been several questions in the last week
for which FAQ 7.31 was the answer and some of the responses had useful
links.)

--
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] Current script name from R

2010-07-09 Thread Allan Engelhardt

On 09/07/10 12:18, Ralf B wrote:

I am using RGUI, the  command line or the StatET Eclipse environment.
Should this not all be the same?
   


No, there is no particular reason why they should.

Allan


Ralf

On Fri, Jul 9, 2010 at 7:11 AM, Allan Engelhardt  wrote:
   

I'm assuming you are using Rscript (please provide self-contained examples
when posting) in which case you could look for the element in
(base|R.utils)::commandArgs() that begin with the string "--file=" - the
rest is the file name.  See the asValues= parameter in help("commandArgs",
package="R.utils") for a nice way to get the parameter.

For an invocation of the form R<  foo.R you'd need to inspect your system's
process table (so don't do that).

Hope this helps.

Allan

On 09/07/10 10:48, Ralf B wrote:
 

Is there a way for a script to find out about its own name ?

Ralf

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] strange floor rounding

2010-07-09 Thread David Winsemius


On Jul 9, 2010, at 10:27 AM, Trafim Vanishek wrote:

Thanks everybody for referring me to FAQ 7.31 but I don't see how to  
solve

it.
I am giving a concrete number and I need to get 58 not 57. Seems,  
there is

no way?

Building on an example on the help page for as.integer,  this seems to  
be working:


> trnc2 <- function(x) trunc(x) + (trunc(x) < x)*sign(x)*(abs(x -  
trunc(x)) < .Machine$double.eps^0.5)


> trnc2(0.01*100)
[1] 1
> trnc2(seq(0, 1, by=0.01)*100)
  [1]   0   1   2   3   4   5   6   8   8   9  10  11  12  13  15   
15  16  17  18  19
 [21]  20  21  22  23  24  25  26  27  29  28  30  31  32  33  34   
35  36  37  38  39
 [41]  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54   
56  57  58  57  59
 [61]  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74   
75  76  77  78  79
 [81]  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94   
95  96  97  98  99

[101] 100
> trnc2(-seq(0, 1, by=0.01)*100)
  [1]0   -1   -2   -3   -4   -5   -6   -7   -8   -9  -10  -11   
-12  -13  -14  -15
 [17]  -16  -17  -18  -19  -20  -21  -22  -23  -24  -25  -26  -27   
-28  -28  -30  -31
 [33]  -32  -33  -34  -35  -36  -37  -38  -39  -40  -41  -42  -43   
-44  -45  -46  -47
 [49]  -48  -49  -50  -51  -52  -53  -54  -55  -56  -57  -57  -59   
-60  -61  -62  -63
 [65]  -64  -65  -66  -67  -68  -69  -70  -71  -72  -73  -74  -75   
-76  -77  -78  -79
 [81]  -80  -81  -82  -83  -84  -85  -86  -87  -88  -89  -90  -91   
-92  -93  -94  -95

 [97]  -96  -97  -98  -99 -100

And after looking at that a bit I came up with a shorter alternate  
that seems to work as well:


trnc3 <- function(x) trunc(x+sign(x)* .Machine$double.eps^0.5)

See also  ?all.equal

--
David.
On Fri, Jul 9, 2010 at 4:05 PM, David Winsemius >wrote:




On Jul 9, 2010, at 9:46 AM, Trafim Vanishek wrote:

Dear all,


might seem and easy question but I cannot figure it out.

floor(100*(.58))
[1] 57

where is the trick here?



FAQ 7.31


And how can I end up with the right answer?




Define right, please. (There have been several questions in the  
last week
for which FAQ 7.31 was the answer and some of the responses had  
useful

links.)

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


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] installing packages over ssh without X forwarding

2010-07-09 Thread Duncan Murdoch

On 09/07/2010 7:37 AM, p...@orbit.umbr.cas.cz wrote:

Hi,
Is it possible to install packages without the testing if installed
package can be loaded?
I need to install bunch of packages on multiple computers over ssh. Some
packages witch interact with X11 display cannot be installed in this way.
for example after:
> install.packages('cairoDevice',dep=T)
I get
(...)
*** installing help indices
** building package indices ...
** testing if installed package can be loaded
Error : .onLoad failed in loadNamespace() for 'cairoDevice', details:
  call: fun(...)
  error: GDK display not found - please make sure X11 is running
ERROR: loading failed
* removing ‘/usr/local/lib64/R/library/cairoDevice’
* restoring previous ‘/usr/local/lib64/R/library/cairoDevice’

The downloaded packages are in
‘/tmp/Rtmpk1XxTl/downloaded_packages’
Updating HTML index of packages in '.Library'
Warning message:
In install.packages("cairoDevice", dep = T) :
  installation of package 'cairoDevice' had non-zero exit status

When I connect with remote computer using ssh -X r...@nod1 to enable X11
forwarding then installation works without problems. This would however
require manually connect with each administred computer a do the
installation. cssh which I use now to install packages on multiple
computers does not enable X11 forwarding. I have also tested installation
using R CMD INSTALL with --no-test-load options but the packages are
loaded unsuccesfully anyway. So is it possible to turn of package testing?
Petr


Yes, use the "--no-test-load" option to R CMD INSTALL, which you can 
pass through the INSTALL_opts argument to install.packages().


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.


[R] print.trellis draw.in

2010-07-09 Thread Mark Connolly
I am attempting to plot a trellis object on a grid.

vplayout = viewport(layout.pos.row=x, layout.pos.col=y)

grid.newpage()
pushViewport(viewport(layout=grid.layout(2,2)))

g1 = ggplot() ...
g2 = ggplot() ...
g3 = ggplot() ...
p = xyplot() ...

# works as expected
print(g1, vp=vplayout(1,1))
print(g2, vp=vplayout(1,2))
print(g3, vp=vplayout(2,1))

# does not work
print(  p,
 newpage=FALSE,
 draw.in=vplayout(2,2)$name)

Error in grid.Call.graphics("L_downviewport", name$name, strict) :
  Viewport 'GRID.VP.112' was not found


What am I doing wrong?

Thanks!

[[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] strange floor rounding

2010-07-09 Thread Trafim Vanishek
Thanks everybody for referring me to FAQ 7.31 but I don't see how to solve
it.
I am giving a concrete number and I need to get 58 not 57. Seems, there is
no way?

On Fri, Jul 9, 2010 at 4:05 PM, David Winsemius wrote:

>
> On Jul 9, 2010, at 9:46 AM, Trafim Vanishek wrote:
>
>  Dear all,
>>
>> might seem and easy question but I cannot figure it out.
>>
>> floor(100*(.58))
>> [1] 57
>>
>> where is the trick here?
>>
>
> FAQ 7.31
>
>
> And how can I end up with the right answer?
>>
>
> Define right, please. (There have been several questions in the last week
> for which FAQ 7.31 was the answer and some of the responses had useful
> links.)
>
> --
> 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] Function on columns of a dataframe

2010-07-09 Thread Eik Vettorazzi
you are right. But maybe "aggregate" is close to the desired result?

aggregate(bla, list(bla$cat), max)

Am 09.07.2010 16:01, schrieb David Winsemius:
>
> On Jul 9, 2010, at 9:46 AM, Eik Vettorazzi wrote:
>
>> Hi Nils,
>> have a look at
>> ?tapply
>> hth.
>
> Perhaps this will be part way there (I couldn't really figure out the
> desired structure of the final object):
> > lapply( bla[, -(1:2)], function(x) tapply(x, bla$cat, max) )
> $v1
>  cat1  cat2  cat3  cat4  cat5  cat6
> 0.4634519 0.4062700 0.4816403 0.6354560 0.6663811 0.5260832
>
> $v2
>  cat1  cat2  cat3  cat4  cat5  cat6
> 0.5274645 0.4282639 0.4996033 0.3558259 0.2154201 0.3934063
>
> $v3
>  cat1  cat2  cat3  cat4  cat5  cat6
> 0.6051479 0.4443707 0.3538144 0.3646292 0.5059900 0.3545962
>
> $v4
>  cat1  cat2  cat3  cat4  cat5  cat6
> 0.7586322 0.8419526 0.9456385 0.1907295 0.7573575 0.6412563
>
>
>>
>> Am 09.07.2010 15:37, schrieb LogLord:
>>> Hi,
>>>
>>> I would like to assign the largest value of a column to a specific
>>> category
>>> and repeat this for each column (v1 - v4).
>>>
>>>
 x=c(1:12)
 cat=c("cat1","cat5","cat2","cat2","cat1","cat5","cat3","cat4","cat5","cat2","cat3","cat6")

 v1=rnorm(12,0.5,0.1)
 v2=rnorm(12,0.3,0.2)
 v3=rnorm(12,0.4,0.1)
 v4=rnorm(12,0.6,0.3)
 bla=data.frame(x,cat,v1,v2,v3,v4)
 bla

>>>x  catv1 v2v3 v4
>>> 1   1 cat1 0.4013144 0.54839317 0.3946393  0.8679266
>>> 2   2 cat5 0.4595873 0.45788906 0.4030078  0.5919596
>>> 3   3 cat2 0.4542865 0.21516928 0.2777649  0.6112099
>>> 4   4 cat2 0.4787950 0.06252512 0.5095611  0.6450795
>>> 5   5 cat1 0.4910746 0.56591049 0.5151813  0.8465181
>>> 6   6 cat5 0.4194397 0.16592579 0.4361643  0.6415192
>>> 7   7 cat3 0.6148564 0.32240342 0.2690108  0.7114133
>>> 8   8 cat4 0.6174652 0.28076152 0.4577064 -0.2567284
>>> 9   9 cat5 0.4775395 0.28611768 0.4660210  0.4634120
>>> 10 10 cat2 0.4802962 0.03715569 0.4506361  1.0063235
>>> 11 11 cat3 0.6495094 0.33303172 0.3352933  1.4390324
>>> 12 12 cat6 0.4891481 0.45355589 0.3880739  0.7831656
>>>

>>> I can assign this by the sqldf() command for each column but I would
>>> like to
>>> automate this as I have many columns.
>>>
>>>
 select=sqldf("select cat, max(v1) FROM bla GROUP BY cat")
 select

>>>   cat   max(v1)
>>> 1 cat1 0.4910746
>>> 2 cat2 0.4802962
>>> 3 cat3 0.6495094
>>> 4 cat4 0.6174652
>>> 5 cat5 0.4775395
>>> 6 cat6 0.4891481
>>>

>>> Finally, I would like to have a dataframe where where the cat is
>>> followed by
>>> each column maximum.
>>>
>>> Thanks for your help!
>>>
>>
>> -- 
>> Eik Vettorazzi
>> Institut für Medizinische Biometrie und Epidemiologie
>> Universitätsklinikum Hamburg-Eppendorf
>>
>> Martinistr. 52
>> 20246 Hamburg
>>
>> T ++49/40/7410-58243
>> F ++49/40/7410-57790
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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
>

-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 can achive step by step execution of the script

2010-07-09 Thread vijaysheegi

Hi R Experts,
I have certain code ,i want to achive interactive execution .
For ex:
1. as part of input ,it should ask file name  or table name as input.
2.in script so many graphs i need to draw,it should wait till certain key is
pressed .
3:i am using windows R,rscript  is not working.



Please some one help me.

Thanks Experts in advance


-- 
View this message in context: 
http://r.789695.n4.nabble.com/how-can-achive-step-by-step-execution-of-the-script-tp2283207p2283209.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] ttrTests issue in cReturns

2010-07-09 Thread Raghu
cr<-cReturns(spData,ttr="MACD")
Error in ind[t - k] <- pos[t - k + 1] - pos[t - k] :
  replacement has length zero
> cr<-cReturns(spData,ttr="macd4")


Why is the above error coming? macd4 works alright ( which is a custom
function built by the ttrTests author) while MACD doesnt work.

Thanks
-- 
'Raghu'

[[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] distributing a value for a given month across the number of weeks in that month

2010-07-09 Thread Gabor Grothendieck
On Fri, Jul 9, 2010 at 9:35 AM, Dimitri Liakhovitski
 wrote:
> Hello!
>
> Any hint would be greatly appreciated.
> I have a data frame that contains (a) monthly dates and (b) a value
> that corresponds to each month - see the data frame "monthly" below:
>
> monthly<-data.frame(month=c(20100301,20100401,20100501),monthly.value=c(100,200,300))
> monthly$month<-as.character(monthly$month)
> monthly$month<-as.Date(monthly$month,"%Y%m%d")
> (monthly)
>
> I need to split each month into weeks, e.g., weeks that start on
> Monday (it could as well be Sunday - it does not really matter) and
> distribute the monthly value evenly across weeks. So, if a month has 5
> Mondays, then the monthly value should be dividied by 5, but if a
> month has only 4 weeks, then the monthly value should be divided by 4.
>
> The output I need is like this:
>
> week          weekly.value
> 2010-03-01   20
> 2010-03-08   20
> 2010-03-15   20
> 2010-03-22   20
> 2010-03-29   20
> 2010-04-05   50
> 2010-04-12   50
> 2010-04-19   50
> 2010-04-26   50
> 2010-05-03   60
> 2010-05-10   60
> 2010-05-17   60
> 2010-05-24   60
> 2010-05-31   60
>


There is new functionality in na.locf in the development version
of zoo that makes it particularly convenient to do this.

First create a zoo object z from monthly and get a vector of all
the mondays.  Then use na.locf to place the monthly value in each
monday and ave to distribute them out.


library(zoo)

# pull in development version of na.locf.zoo
source("http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/zoo/R/na.locf.R?revision=725&root=zoo";)

# convert to zoo
z <- with(monthly, zoo(monthly.value, month))

# get sequence of all dates and from that get mondays
all.dates <- seq(start(z), as.Date(as.yearmon(end(z)), frac = 1), by = "day")
mondays <- all.dates[weekdays(all.dates) == "Monday"]

# use na.locf to fill in mondays and ave to distribute them
weeks <- na.locf(z, xout = mondays)
weeks[] <- ave(weeks, as.yearmon(mondays), FUN = function(x) x[1]/length(x))

# show output in a few different formats
weeks
as.data.frame(weeks)
data.frame(Monday = as.Date(time(weeks)), value = weeks)
data.frame(Monday = as.Date(time(weeks)), value = weeks, row.names = NULL)
plot(weeks)

The output looks like this:

> weeks
2010-03-01 2010-03-08 2010-03-15 2010-03-22 2010-03-29 2010-04-05 2010-04-12
20 20 20 20 20 50 50
2010-04-19 2010-04-26 2010-05-03 2010-05-10 2010-05-17 2010-05-24 2010-05-31
50 50 60 60 60 60 60
> as.data.frame(weeks)
   weeks
2010-03-0120
2010-03-0820
2010-03-1520
2010-03-2220
2010-03-2920
2010-04-0550
2010-04-1250
2010-04-1950
2010-04-2650
2010-05-0360
2010-05-1060
2010-05-1760
2010-05-2460
2010-05-3160


 data.frame(Monday = as.Date(time(weeks)), value = weeks, row.names = NULL)
   Monday value
1  2010-03-0120
2  2010-03-0820
3  2010-03-1520
4  2010-03-2220
5  2010-03-2920
6  2010-04-0550
7  2010-04-1250
8  2010-04-1950
9  2010-04-2650
10 2010-05-0360
11 2010-05-1060
12 2010-05-1760
13 2010-05-2460
14 2010-05-3160

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] installing packages over ssh without X forwarding

2010-07-09 Thread petr
Hi,
Is it possible to install packages without the testing if installed
package can be loaded?
I need to install bunch of packages on multiple computers over ssh. Some
packages witch interact with X11 display cannot be installed in this way.
for example after:
> install.packages('cairoDevice',dep=T)
I get
(...)
*** installing help indices
** building package indices ...
** testing if installed package can be loaded
Error : .onLoad failed in loadNamespace() for 'cairoDevice', details:
  call: fun(...)
  error: GDK display not found - please make sure X11 is running
ERROR: loading failed
* removing ‘/usr/local/lib64/R/library/cairoDevice’
* restoring previous ‘/usr/local/lib64/R/library/cairoDevice’

The downloaded packages are in
‘/tmp/Rtmpk1XxTl/downloaded_packages’
Updating HTML index of packages in '.Library'
Warning message:
In install.packages("cairoDevice", dep = T) :
  installation of package 'cairoDevice' had non-zero exit status

When I connect with remote computer using ssh -X r...@nod1 to enable X11
forwarding then installation works without problems. This would however
require manually connect with each administred computer a do the
installation. cssh which I use now to install packages on multiple
computers does not enable X11 forwarding. I have also tested installation
using R CMD INSTALL with --no-test-load options but the packages are
loaded unsuccesfully anyway. So is it possible to turn of package testing?
Petr

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 can i draw a graph with high and low data points

2010-07-09 Thread Nathaniel Saxe

Hi Tal, Thanks for your help.


I've had a look at the site, and what i wanted to do was to plot X and Y
where X is a characters and Y is numeric. The problem I'm having now is that
the X axis isn't characters but just numbers from 1 onwards and when i plot
it, the data i have is in descending order which isn't shown on the graph.

I have this at the moment:

plot(1:nrow(dat),dat$Mean,type="b",xaxt="n",
ylim=c(min(dat$lci),max(dat$uci)),
xlab="",ylab="HR",)

It gives me sort of what I want. It has the Y values in descending order,
but it doesn't give me the text on the x axis and I was also thinking of
plotting the upper and lower confidence intervals with a line connecting the
two. I can add in the upper and lower CI values separately, but I don't know
how to join the two together.



-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-can-i-draw-a-graph-with-high-and-low-data-points-tp2282524p2283194.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 can achive step by step execution of the script

2010-07-09 Thread vijaysheegi


-- 
View this message in context: 
http://r.789695.n4.nabble.com/how-can-achive-step-by-step-execution-of-the-script-tp2283207p2283207.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] split with list

2010-07-09 Thread Joris Meys
One  solution is  to put these unwanted entries to ""

repor$9853312 [1:2,2:3] <- ""

Cheers
Joris

On Fri, Jul 9, 2010 at 12:18 PM, n.via...@libero.it  wrote:
>
> Dear List I would like to ask you something concenting a better print of the 
> R output:
> I have a bit data frame which has the following structure:
> CFISCALE              RAGSOCB            ANNO       VAR1        VAR2.
> 9853312                     astra                 2005           6            
>    45
>
> 9853312                     astra                 2006          78            
>   45
>
>
> 9853312                     astra                 2007           55           
>    76
>
>
> 9653421                      geox                 2005           35           
>   89
>
>
>
> 9653421                     geox                 2006            24           
>     33
>
> 9653421                      geox                 2007           54           
>    55
>
>
> The first thing I did is to split my data frame for CFISCALE. The result is 
> that R has transformed my data frame into a list. The second step was to 
> transpose each element of my list.
> repo=split(rep,rep$CFISCALE)
> repor=lapply(repo,function(x){
> t(x)})
>
>
> When I print my list the format is the following
> $9853312
>                                   1                           2               
>          3
>
> CFISCALE            "9853312"         "9853312"             "9853312"
>
> RAGSOCB            "astra"               "astra"                    "astra"
>
> ANNO                   "2005"                "2006"                      
> "2007"
>
> VAR1                       6                         78                       
>        55
>
> VAR2                       45                        45                       
>       76
>
>
> There is a way to remove the  first row I mean 1, 2 , 3 and to have just one 
> CFISCALE and RAGSOCB???
> For the second problem I tried to use unique but it seems that it doesnt work 
> for list. So what I would like to get is:
> $9853312
>
>
>
>
> CFISCALE            "9853312"
>
>
> RAGSOCB            "astra"
> ANNO                   "2005"                "2006"                      
> "2007"
>
> VAR1                       6                         78                       
>        55
>
> VAR2                       45                        45                       
>       76
>
>
> This is because I next run xtable on my list in order to get a table in 
> Latex, which I woud like to be in a nice format.
> Thanks a lot for your attention!
>
>
>
>
>
>        [[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.
>



-- 
Joris Meys
Statistical consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

tel : +32 9 264 59 87
joris.m...@ugent.be
---
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

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


  1   2   >