Re: [R] Put short string labels vertically near tick marks on bottom axis

2014-05-13 Thread David Winsemius


On May 13, 2014, at 9:19 PM, Hurr wrote:

I got rid of the quotes error by using single apostrophe quotes in  
notepad.


horAxisLims=c(0,7200)
verData 
= 
c 
(1,365,809,1252,1753,2191,2922,3409,3896,4383,4819,5255,5691,6128,6564,7000 
)

#not fussy
horData 
= 
c 
(1,300,800,1200,1700,2100,2900,3400,3800,4300,4800,5200,5600,6100,6500,7000 
)

#not at tics
horTicLocs 
= 
c 
(1,365,809,1252,1753,2191,2922,3409,3896,4383,4819,5255,5691,6128,6564,7000 
)
horLabels 
= 
c 
('1Yr 
','1Da 
','10.8Hr 
','7Hr 
','5Hr 
','4Hr 
','3Hr 
','2.57Hr 
','2.25Hr 
','2Hr','1.82Hr','1.67Hr','1.54Hr','1.43Hr','1.34Hr','1.25Hr')

plot(horData,verData,xaxt='n',xlim=horAxisLims)
axis(1,tick=TRUE,at=horTicLocs,labels=horLabels)

The plotrix error is still there.


You are requested to post the FULL TEXT of any error message. Please  
do read the Posting Guide, and I suspect this is not the first time  
you have been advised to do so. (I do not get any error message and as  
far as I can see there are no plotrix functions being called.  
Furthermore I get no error.)



Hurr




--
David Winsemius, MD
Alameda, CA, USA

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


Re: [R] Merging data.table and data.frame

2014-05-13 Thread Jeff Newmiller
Works for me. Can you make a reproducible example [1] the way the 
footers of all emails on this list ask you to? The str and dput functions 
are very useful tools mentioned in the referenced article.


[1] 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

On Wed, 14 May 2014, Abhinaba Roy wrote:


Hi Peter,

Thanks for your reply, I tried to convert my data.table into a data.frame
and then merging but I am getting the same error. But when I check the
class of my previously data.table object it returns "data.frame".


Any clue as to why this is happening?

Regards


On Tue, May 13, 2014 at 7:13 PM, peter dalgaard  wrote:



On 13 May 2014, at 14:34 , Abhinaba Roy  wrote:


Hi R-helpers,

I am trying the following code in R



merge(x=Master1,y=demo_dtls,by.x=c("ID_CASE","ts"),by.y=c("ID_CASE","TS_EVENT"))


where,

class(demo_dtls$TS_EVENT)
[1] "POSIXct" "POSIXt"
class(Master1$ts)
[1] "POSIXct" "POSIXt"

and


class(Master1)[1] "data.table" "data.frame"> class(demo_dtls)[1]

"data.frame"



But I am getting the following error

Error in merge.data.table(x = Master1, y = demo_dtls, by.x =

c("ID_CASE",  :

 Can not match keys in x and y to automatically determine appropriate
`by` parameter. Please set `by` value explicitly.

Why am I getting this error?


You are using merge.data.frame syntax for merge.data.table. The latter
knows about by=, but not by.x= and by.y= (so presumably you need to rename
variables in x or y).

- Peter



Any help will be appreciated


--
Regards
Abhinaba Roy

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


--
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com





--
Regards
Abhinaba Roy
Statistician
Radix Analytics Pvt. Ltd
Ahmedabad

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



---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k

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

2014-05-13 Thread Frede Aakmann Tøgersen
Don't know if I understand your last comment but I surely don't think that the 
Weibull and Gumbel distributions are the same. See their density function on 
e.g. Wikipedia.

Yours sincerely / Med venlig hilsen


Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
fr...@vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender.

From: eliza botto [mailto:eliza_bo...@hotmail.com]
Sent: 13. maj 2014 21:20
To: Frede Aakmann Tøgersen; r-help@r-project.org
Subject: RE: [R] gumbel distribution

Thankyou very much Frede. It wasn't any home I am just trying to put my grip on 
distribution. Believe it or not, I came to know for the first time that weibull 
and gumbel distributions are same. :(

Eliza

> From: fr...@vestas.com
> To: eliza_bo...@hotmail.com; 
> r-help@r-project.org
> Date: Tue, 13 May 2014 20:08:20 +0200
> Subject: RE: [R] gumbel distribution
>
> Is this a home work problem?
>
> See
>
> Weibull package:stats R Documentation
>
> The Weibull Distribution
>
> Description:
>
> Density, distribution function, quantile function and random
> generation for the Weibull distribution with parameters 'shape'
> and 'scale'.
>
> Usage:
>
> dweibull(x, shape, scale = 1, log = FALSE)
> pweibull(q, shape, scale = 1, lower.tail = TRUE, log.p = FALSE)
> qweibull(p, shape, scale = 1, lower.tail = TRUE, log.p = FALSE)
> rweibull(n, shape, scale = 1)
>
>
> Yours sincerely / Med venlig hilsen
>
>
> Frede Aakmann Tøgersen
> Specialist, M.Sc., Ph.D.
> Plant Performance & Modeling
>
> Technology & Service Solutions
> T +45 9730 5135
> M +45 2547 6050
> fr...@vestas.com
> http://www.vestas.com
>
> Company reg. name: Vestas Wind Systems A/S
> This e-mail is subject to our e-mail disclaimer statement.
> Please refer to 
> www.vestas.com/legal/notice
> If you have received this e-mail in error please contact the sender.
>
>
> > -Original Message-
> > From: r-help-boun...@r-project.org 
> > [mailto:r-help-boun...@r-project.org]
> > On Behalf Of eliza botto
> > Sent: 13. maj 2014 19:57
> > To: r-help@r-project.org
> > Subject: [R] gumbel distribution
> >
> > Dear useRs,
> > I need some examples of gumbel probability plots in R. i'll be extremely
> > grateful if you could share the codes of a working example.
> > Eliza
> >
> >
> > [[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] Package 'compositions' and R-3.1.0

2014-05-13 Thread Prof Brian Ripley

On 13/05/2014 23:18, David Winsemius wrote:


On May 13, 2014, at 2:59 PM, Rolf Turner wrote:


On 14/05/14 09:21, Rich Shepard wrote:

   I just tried to install 'compositions'. It's apparently not yet
available
for R-3.1.0. How can I learn when it might be available?


The compositions package has apparently been archived:


Package ‘compositions’ was removed from the CRAN repository.

Formerly available versions can be obtained from the archive.

Archived on 2014-05-01 as undefined-behaviour errors were not
corrected (and previously archived on 2014-03-07).



You could try retrieving the package from the archive and fixing it yourself.  
Good luck!


There was just a posting on R-devel today that suggested compiling from source 
has a good chance to succeed without even fixes.


Yes, but not giving correct results 

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

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


Re: [R] Merging data.table and data.frame

2014-05-13 Thread Abhinaba Roy
Hi Peter,

Thanks for your reply, I tried to convert my data.table into a data.frame
and then merging but I am getting the same error. But when I check the
class of my previously data.table object it returns "data.frame".


Any clue as to why this is happening?

Regards


On Tue, May 13, 2014 at 7:13 PM, peter dalgaard  wrote:

>
> On 13 May 2014, at 14:34 , Abhinaba Roy  wrote:
>
> > Hi R-helpers,
> >
> > I am trying the following code in R
> >
> >
> merge(x=Master1,y=demo_dtls,by.x=c("ID_CASE","ts"),by.y=c("ID_CASE","TS_EVENT"))
> >
> > where,
> >
> > class(demo_dtls$TS_EVENT)
> > [1] "POSIXct" "POSIXt"
> > class(Master1$ts)
> > [1] "POSIXct" "POSIXt"
> >
> > and
> >
> >> class(Master1)[1] "data.table" "data.frame"> class(demo_dtls)[1]
> "data.frame"
> >
> >
> > But I am getting the following error
> >
> > Error in merge.data.table(x = Master1, y = demo_dtls, by.x =
> c("ID_CASE",  :
> >  Can not match keys in x and y to automatically determine appropriate
> > `by` parameter. Please set `by` value explicitly.
> >
> > Why am I getting this error?
>
> You are using merge.data.frame syntax for merge.data.table. The latter
> knows about by=, but not by.x= and by.y= (so presumably you need to rename
> variables in x or y).
>
> - Peter
>
>
> > Any help will be appreciated
> >
> >
> > --
> > Regards
> > Abhinaba Roy
> >
> >   [[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.
>
> --
> Peter Dalgaard, Professor
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: pd@cbs.dk  Priv: pda...@gmail.com
>
>


-- 
Regards
Abhinaba Roy
Statistician
Radix Analytics Pvt. Ltd
Ahmedabad

[[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 create multi variables

2014-05-13 Thread Jeff Newmiller
Please do the reading I recommended before posting again. My example was 
numeric because your example was numeric. For more complicated data, a list is 
a type of vector that can hold such objects, and you would know this if you had 
read the intro document.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On May 13, 2014 7:22:08 PM PDT, yuanzhi  wrote:
>Thank you for your reply.
>
>Yes, there is a problem according to you suggestion.
>What if the value are not numerical, e.g. I want to use the variable to
>store the results of linear regression.
>can I use
>myvec <- vector( "numeric", 10 )
>for ( i in 1:10 ) {
>  myvec[ i ] <- summary(lm(y~x)) # y and x are different values in each
>loop.
>}
>?
>
>you advice seems only to be available when the function left allocates
>a
>numerical value to the variable, what if the function return other type
>of
>objects?
>
>
>
>
>Jeff Newmiller wrote
>> What is wrong with
>> 
>> myvec <- vector( "numeric", 10 )
>> for ( i in 1:10 ) {
>>   myvec[ i ] <- i
>> }
>> 
>> ?
>> 
>> If you are using assign, IMHO you are probably doing whatever you are
>> doing wrong.
>> 
>> If you want named elements, give the vector names:
>> 
>> names( myvec ) <- paste0( "t", 1:10 )
>> 
>> and you can refer to them
>> 
>> myvec[ "t3" ]
>> 
>> Go read the "Introduction to R" document again... particularly the
>> discussion of indexing.
>>
>---
>> Jeff NewmillerThe .   .  Go
>> Live...
>> DCN:<
>
>> jdnewmil@.ca
>
>> >Basics: ##.#.   ##.#.  Live Go...
>>   Live:   OO#.. Dead: OO#.. 
>Playing
>> Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
>> /Software/Embedded Controllers)   .OO#.   .OO#. 
>> rocks...1k
>>
>---
>
>> Sent from my phone. Please excuse my brevity.
>> 
>> On May 13, 2014 5:47:12 PM PDT, Yuanzhi Li <
>
>> Yuanzhi.Li@
>
>> > wrote:
>>>Hi, everyone
>>>
>>>I want to create a series of variables (e.g. t1, t2..., t10) which
>>>could 
>>>be used in loops. My idea is to use function "assign"
>>>
>>>for (i in 1:10)
>>>{
>>>   assign(paste("t",i,sep=""), FUN) # allocate the value from FUN to 
>>>variable ti
>>>}
>>>
>>>But when I create a vector containing the names of these variables
>and 
>>>want to use the variables according to the subscript, it doesn't
>works.
>>>
>>>t<-noquote(paste("t",1:10,sep=""))
>>>t[1]
>>>t1
>>>it returns only the name of variable t1, but not the value allocated
>to
>>>
>>>t1 by FUN. So what should I do to realize this?
>>>
>>>Or is there any better way to do this?
>>>
>>>Can we define a series of variables which can be used according to
>the 
>>>subscript like
>>>t<-f(t1, t2..., t10),
>>>then we have 10 variables which can be used directly?
>>>for(i in 1:10)
>>>{
>>>  t[i]<-FUN# with the fines variables we can directly assign the
>value 
>>>of FUN to ti
>>>}
>>>These are just my thoughts, I don't know whether there are available
>R 
>>>codes to realized it. I am looking forward any help from you.
>>>
>>>Thanks in advance!
>>>
>>>Yuanzhi
>>>
>>>__
>>>
>
>> R-help@
>
>>  mailing list
>>>https://stat.ethz.ch/mailman/listinfo/r-help
>>>PLEASE do read the posting guide
>>>http://www.R-project.org/posting-guide.html
>>>and provide commented, minimal, self-contained, reproducible code.
>> 
>> __
>
>> R-help@
>
>>  mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/How-to-create-multi-variables-tp4690465p4690470.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, r

Re: [R] Put short string labels vertically near tick marks on bottom axis

2014-05-13 Thread Hurr
I got rid of the quotes error by using single apostrophe quotes in notepad.

horAxisLims=c(0,7200)
verData=c(1,365,809,1252,1753,2191,2922,3409,3896,4383,4819,5255,5691,6128,6564,7000)
#not fussy 
horData=c(1,300,800,1200,1700,2100,2900,3400,3800,4300,4800,5200,5600,6100,6500,7000)
#not at tics 
horTicLocs=c(1,365,809,1252,1753,2191,2922,3409,3896,4383,4819,5255,5691,6128,6564,7000)
horLabels=c('1Yr','1Da','10.8Hr','7Hr','5Hr','4Hr','3Hr','2.57Hr','2.25Hr','2Hr','1.82Hr','1.67Hr','1.54Hr','1.43Hr','1.34Hr','1.25Hr')
plot(horData,verData,xaxt='n',xlim=horAxisLims)
axis(1,tick=TRUE,at=horTicLocs,labels=horLabels) 

The plotrix error is still there.
Hurr




--
View this message in context: 
http://r.789695.n4.nabble.com/Put-short-string-labels-vertically-near-tick-marks-on-bottom-axis-tp4690452p4690478.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] Put short string labels vertically near tick marks on bottom axis

2014-05-13 Thread Jeff Newmiller
No, he captured them in some other place, perhaps his email software.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On May 13, 2014 7:00:11 PM PDT, Jim Lemon  wrote:
>That's a bummer. Apparently Notepad is no longer a straight text 
>editor. I used to rely on it when I had to use Windows.
>
>Jim
>
>On Tue, 13 May 2014 06:37:46 PM David Winsemius wrote:
>> On May 13, 2014, at 5:59 PM, Hurr wrote:
>> > David,
>> > The error I get is:
>> > Error: unexpected input in "horLabels=c(”"
>> > I don't get an error: "Smart quotes"
>> > I use Notepad for editor.
>> 
>> Right. You got an error,...  which you did not post. In my mail
>client 
>the
>> "double quotes" appeared with assymmetric descenders: ”   ... that 
>is what
>> I was calling a "smart quote" because that's what MS-Word calls it. I
>
>was
>> using it as a term of derision.
>> 
>> ... rather than ordinary double quotes: "
>> 
>> I have no experience with "Notepad", but it is apparently not 
>protecting you
>> from quoting with the incorrect characters for use in R. When I used 
>R on a
>> Windows device in the past I used TINN-R
>
>__
>R-help@r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/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] Put short string labels vertically near tick marks on bottom axisis

2014-05-13 Thread Hurr
I get:
> install.packages(plotrix)
Error in install.packages(plotrix) : object 'plotrix' not found
Hurr




--
View this message in context: 
http://r.789695.n4.nabble.com/Put-short-string-labels-vertically-near-tick-marks-on-bottom-axis-tp4690452p4690474.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to create multi variables

2014-05-13 Thread yuanzhi
Thank you for your reply.

Yes, there is a problem according to you suggestion.
What if the value are not numerical, e.g. I want to use the variable to
store the results of linear regression.
can I use
myvec <- vector( "numeric", 10 )
for ( i in 1:10 ) {
  myvec[ i ] <- summary(lm(y~x)) # y and x are different values in each
loop.
}
?

you advice seems only to be available when the function left allocates a
numerical value to the variable, what if the function return other type of
objects?




Jeff Newmiller wrote
> What is wrong with
> 
> myvec <- vector( "numeric", 10 )
> for ( i in 1:10 ) {
>   myvec[ i ] <- i
> }
> 
> ?
> 
> If you are using assign, IMHO you are probably doing whatever you are
> doing wrong.
> 
> If you want named elements, give the vector names:
> 
> names( myvec ) <- paste0( "t", 1:10 )
> 
> and you can refer to them
> 
> myvec[ "t3" ]
> 
> Go read the "Introduction to R" document again... particularly the
> discussion of indexing.
> ---
> Jeff NewmillerThe .   .  Go
> Live...
> DCN:<

> jdnewmil@.ca

> >Basics: ##.#.   ##.#.  Live Go...
>   Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
> /Software/Embedded Controllers)   .OO#.   .OO#. 
> rocks...1k
> --- 
> Sent from my phone. Please excuse my brevity.
> 
> On May 13, 2014 5:47:12 PM PDT, Yuanzhi Li <

> Yuanzhi.Li@

> > wrote:
>>Hi, everyone
>>
>>I want to create a series of variables (e.g. t1, t2..., t10) which
>>could 
>>be used in loops. My idea is to use function "assign"
>>
>>for (i in 1:10)
>>{
>>   assign(paste("t",i,sep=""), FUN) # allocate the value from FUN to 
>>variable ti
>>}
>>
>>But when I create a vector containing the names of these variables and 
>>want to use the variables according to the subscript, it doesn't works.
>>
>>t<-noquote(paste("t",1:10,sep=""))
>>t[1]
>>t1
>>it returns only the name of variable t1, but not the value allocated to
>>
>>t1 by FUN. So what should I do to realize this?
>>
>>Or is there any better way to do this?
>>
>>Can we define a series of variables which can be used according to the 
>>subscript like
>>t<-f(t1, t2..., t10),
>>then we have 10 variables which can be used directly?
>>for(i in 1:10)
>>{
>>  t[i]<-FUN# with the fines variables we can directly assign the value 
>>of FUN to ti
>>}
>>These are just my thoughts, I don't know whether there are available R 
>>codes to realized it. I am looking forward any help from you.
>>
>>Thanks in advance!
>>
>>Yuanzhi
>>
>>__
>>

> R-help@

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

> R-help@

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





--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-create-multi-variables-tp4690465p4690470.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] Raising a vector to the power of elements of another vector

2014-05-13 Thread arun
Hi,
May be this helps:

a <- 1:3
 b <- 2:4
Mnew <- matrix(a^(rep(b, each=length(a))),ncol=3,byrow=TRUE)
identical(M,Mnew)
#[1] TRUE
#or
 M1 <-t(outer(a,b, FUN="^"))
identical(M,M1)
#[1] TRUE
#or
dat <- expand.grid(a,b)
M2 <- matrix(dat[,1]^dat[,2],ncol=3,byrow=TRUE)
identical(M,M2)
#[1] TRUE


A.K.

Hi all,

Suppose I have a vector a<-c(1,2,3) and I want to raise it to the power of 2, 
3, 4 and bind it into a matrix that looks like 
M<-matrix(c(1,1,1,4,8,16,9,27,81),3,3). Let the vector with elements 2,3,4 be 
called b. Can I manipulate a and b to get M without using loops? I have a 
massive data and if I use loops it takes very long time.
So far I have just tried using loops:
Loopy<-lapply(1:3,function(s){
   a^b[s]
})
Loopyfinal<-do.call(rbind,Loopy)
I would appreciate a nicer trick, if there is one.
Thanks,
Delger 


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Put short string labels vertically near tick marks on bottom axis

2014-05-13 Thread Jim Lemon
That's a bummer. Apparently Notepad is no longer a straight text 
editor. I used to rely on it when I had to use Windows.

Jim

On Tue, 13 May 2014 06:37:46 PM David Winsemius wrote:
> On May 13, 2014, at 5:59 PM, Hurr wrote:
> > David,
> > The error I get is:
> > Error: unexpected input in "horLabels=c(”"
> > I don't get an error: "Smart quotes"
> > I use Notepad for editor.
> 
> Right. You got an error,...  which you did not post. In my mail client 
the
> "double quotes" appeared with assymmetric descenders: ”   ... that 
is what
> I was calling a "smart quote" because that's what MS-Word calls it. I 
was
> using it as a term of derision.
> 
> ... rather than ordinary double quotes: "
> 
> I have no experience with "Notepad", but it is apparently not 
protecting you
> from quoting with the incorrect characters for use in R. When I used 
R on a
> Windows device in the past I used TINN-R

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


Re: [R] How to create multi variables

2014-05-13 Thread Jeff Newmiller
What is wrong with

myvec <- vector( "numeric", 10 )
for ( i in 1:10 ) {
  myvec[ i ] <- i
}

?

If you are using assign, IMHO you are probably doing whatever you are doing 
wrong.

If you want named elements, give the vector names:

names( myvec ) <- paste0( "t", 1:10 )

and you can refer to them

myvec[ "t3" ]

Go read the "Introduction to R" document again... particularly the discussion 
of indexing.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On May 13, 2014 5:47:12 PM PDT, Yuanzhi Li  wrote:
>Hi, everyone
>
>I want to create a series of variables (e.g. t1, t2..., t10) which
>could 
>be used in loops. My idea is to use function "assign"
>
>for (i in 1:10)
>{
>   assign(paste("t",i,sep=""), FUN) # allocate the value from FUN to 
>variable ti
>}
>
>But when I create a vector containing the names of these variables and 
>want to use the variables according to the subscript, it doesn't works.
>
>t<-noquote(paste("t",1:10,sep=""))
>t[1]
>t1
>it returns only the name of variable t1, but not the value allocated to
>
>t1 by FUN. So what should I do to realize this?
>
>Or is there any better way to do this?
>
>Can we define a series of variables which can be used according to the 
>subscript like
>t<-f(t1, t2..., t10),
>then we have 10 variables which can be used directly?
>for(i in 1:10)
>{
>  t[i]<-FUN# with the fines variables we can directly assign the value 
>of FUN to ti
>}
>These are just my thoughts, I don't know whether there are available R 
>codes to realized it. I am looking forward any help from you.
>
>Thanks in advance!
>
>Yuanzhi
>
>__
>R-help@r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/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] Put short string labels vertically near tick marks on bottom axis

2014-05-13 Thread David Winsemius

On May 13, 2014, at 5:59 PM, Hurr wrote:

> David,
> The error I get is:
> Error: unexpected input in "horLabels=c(”"
> I don't get an error: "Smart quotes"
> I use Notepad for editor.

Right. You got an error,...  which you did not post. In my mail client the 
"double quotes" appeared with assymmetric descenders: ”   ... that is what I 
was calling a "smart quote" because that's what MS-Word calls it. I was using 
it as a term of derision.

... rather than ordinary double quotes: "

I have no experience with "Notepad", but it is apparently not protecting you 
from quoting with the incorrect characters for use in R. When I used R on a 
Windows device in the past I used TINN-R

-- 

David Winsemius
Alameda, CA, USA

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


Re: [R] Put short string labels vertically near tick marks on bottom axis

2014-05-13 Thread Jim Lemon
On Tue, 13 May 2014 06:11:58 PM Hurr wrote:
> I get the error message:
> "Error in library(plotrix) : there is no package called ‘plotrix’ "
> Hurr
> 
install.packages(plotrix)

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.


[R] How to create multi variables

2014-05-13 Thread Yuanzhi Li

Hi, everyone

I want to create a series of variables (e.g. t1, t2..., t10) which could 
be used in loops. My idea is to use function "assign"


for (i in 1:10)
{
  assign(paste("t",i,sep=""), FUN) # allocate the value from FUN to 
variable ti

}

But when I create a vector containing the names of these variables and 
want to use the variables according to the subscript, it doesn't works.


t<-noquote(paste("t",1:10,sep=""))
t[1]
t1
it returns only the name of variable t1, but not the value allocated to 
t1 by FUN. So what should I do to realize this?


Or is there any better way to do this?

Can we define a series of variables which can be used according to the 
subscript like

t<-f(t1, t2..., t10),
then we have 10 variables which can be used directly?
for(i in 1:10)
{
   t[i]<-FUN# with the fines variables we can directly assign the value 
of FUN to ti

}
These are just my thoughts, I don't know whether there are available R 
codes to realized it. I am looking forward any help from you.


Thanks in advance!

Yuanzhi

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Put short string labels vertically near tick marks on bottom axis

2014-05-13 Thread Hurr
I get the error message:
"Error in library(plotrix) : there is no package called ‘plotrix’ "
Hurr





--
View this message in context: 
http://r.789695.n4.nabble.com/Put-short-string-labels-vertically-near-tick-marks-on-bottom-axis-tp4690452p4690464.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] Put short string labels vertically near tick marks on bottom axis

2014-05-13 Thread Hurr
David,
The error I get is:
Error: unexpected input in "horLabels=c(”"
I don't get an error: "Smart quotes"
I use Notepad for editor.
Hurr



--
View this message in context: 
http://r.789695.n4.nabble.com/Put-short-string-labels-vertically-near-tick-marks-on-bottom-axis-tp4690452p4690463.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] Package 'compositions' and R-3.1.0

2014-05-13 Thread Rich Shepard

On Tue, 13 May 2014, David Winsemius wrote:


The source is in the usual place and there was a solitary posting that
reported success with the usual mechanism for building an R packge:

R CMD build compositions


David,

  Thank you. I found the package home page and downloaded the source from
that.

Rich

--
Richard B. Shepard, Ph.D.| Technically sound and legally defensible
Applied Ecosystem Services, Inc. | ... guaranteed.
www.appl-ecosys.com  Voice: 503-667-4517 Fax: 503-667-8863

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

2014-05-13 Thread David Winsemius

On May 13, 2014, at 3:40 PM, Rich Shepard wrote:

> On Tue, 13 May 2014, David Winsemius wrote:
> 
>> There was just a posting on R-devel today that suggested compiling from
>> source has a good chance to succeed without even fixes.
> 
> David,
> 
>  I'll try to find that thread and the source.

The source is in the usual place and there was a solitary posting that reported 
success with the usual mechanism for building an R packge:

R CMD build compositions

-- 
David

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

2014-05-13 Thread Rich Shepard

On Tue, 13 May 2014, David Winsemius wrote:


There was just a posting on R-devel today that suggested compiling from
source has a good chance to succeed without even fixes.


David,

  I'll try to find that thread and the source.

Thanks,

Rich

--
Richard B. Shepard, Ph.D.| Technically sound and legally defensible
Applied Ecosystem Services, Inc. | ... guaranteed.
www.appl-ecosys.com  Voice: 503-667-4517 Fax: 503-667-8863

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

2014-05-13 Thread Rich Shepard

On Wed, 14 May 2014, Rolf Turner wrote:


The compositions package has apparently been archived:


Package ‘compositions’ was removed from the CRAN repository.

Formerly available versions can be obtained from the archive.

Archived on 2014-05-01 as undefined-behaviour errors were not
corrected (and previously archived on 2014-03-07).


Rolf,

  That's interesting.


You could try retrieving the package from the archive and fixing it
yourself. Good luck!


  I suspect that my knowledge and skills are not up to the task. However,
I'll grab the newest and take a look.

Thanks,

Rich

--
Richard B. Shepard, Ph.D.| Technically sound and legally defensible
Applied Ecosystem Services, Inc. | ... guaranteed.
www.appl-ecosys.com  Voice: 503-667-4517 Fax: 503-667-8863

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Put short string labels vertically near tick marks on bottom axis

2014-05-13 Thread David Winsemius

On May 13, 2014, at 2:52 PM, Hurr wrote:

> A month ago I was considering the forum topic
> “Label axis tick marks with a simple function of axis value”
> and haven’t had time to work much on it.
> Since then I have written a little program that makes 
> period labels for the frequency axis, but I don’t know how to attach them.
> I expected the following code to work.
> Later there will be more requirements like 
> 1) labels should be vertical
> 2) the bottom of the labels should line up with the ticks
> 3) requirements beyond today’s consideration
> 
> horAxisLims=c(0,7200)
> verData=c(1,365,809,1252,1753,2191,2922,3409,3896,4383,4819,5255,5691,6128,6564,7000)
> horData=c(1,300,800,1200,1700,2100,2900,3400,3800,4300,4800,5200,5600,6100,6500,7000)
> #not at tics 
> horTicLocs=c(1,365,809,1252,1753,2191,2922,3409,3896,4383,4819,5255,5691,6128,6564,7000)
> horLabels=c(”1Yr”,”1Da”,”10.8Hr”,”7Hr”,”5Hr”,”4Hr”,”3Hr”,”2.57Hr”,”2.25Hr”,”2Hr”,”1.82Hr”,”1.67Hr”,”1.54Hr”,”1.43Hr”,”1.34Hr”,”1.25Hr”)
> plot(horData, verData,xaxt='n',xlim= horAxisLims)
> axis(1,tick=TRUE,at= horTicLocs, labels= horLabels) 
> 

Yecchh. Pasted code throws an error in the horLabels assignment. "Smart 
quotes". Use a proper text editor.

-- 

David Winsemius
Alameda, CA, USA

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


Re: [R] Package 'compositions' and R-3.1.0

2014-05-13 Thread David Winsemius

On May 13, 2014, at 2:59 PM, Rolf Turner wrote:

> On 14/05/14 09:21, Rich Shepard wrote:
>>   I just tried to install 'compositions'. It's apparently not yet
>> available
>> for R-3.1.0. How can I learn when it might be available?
> 
> The compositions package has apparently been archived:
> 
>> Package ‘compositions’ was removed from the CRAN repository.
>> 
>> Formerly available versions can be obtained from the archive.
>> 
>> Archived on 2014-05-01 as undefined-behaviour errors were not
>> corrected (and previously archived on 2014-03-07).
> 
> 
> You could try retrieving the package from the archive and fixing it yourself. 
>  Good luck!

There was just a posting on R-devel today that suggested compiling from source 
has a good chance to succeed without even fixes.

-- 
David Winsemius
Alameda, CA, USA

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


Re: [R] Put short string labels vertically near tick marks on bottom axis

2014-05-13 Thread Jim Lemon
On Tue, 13 May 2014 02:52:09 PM Hurr wrote:
> A month ago I was considering the forum topic
> “Label axis tick marks with a simple function of axis value”
> and haven’t had time to work much on it.
> Since then I have written a little program that makes
> period labels for the frequency axis, but I don’t know how to attach 
them.
> I expected the following code to work.
> Later there will be more requirements like
> 1) labels should be vertical
> 2) the bottom of the labels should line up with the ticks
> 3) requirements beyond today’s consideration
> 
> horAxisLims=c(0,7200)
> 
verData=c(1,365,809,1252,1753,2191,2922,3409,3896,4383,4819,5255,5691,6128,6
> 564,7000)
> 
horData=c(1,300,800,1200,1700,2100,2900,3400,3800,4300,4800,5200,5600,6100,
> 6500,7000) #not at tics
> 
horTicLocs=c(1,365,809,1252,1753,2191,2922,3409,3896,4383,4819,5255,5691,612
> 8,6564,7000)
> 
horLabels=c(”1Yr”,”1Da”,”10.8Hr”,”7Hr”,”5Hr”,”4Hr”,”3Hr”,”2.57Hr”,”2.25Hr”,
> ”2Hr”,”1.82Hr”,”1.67Hr”,”1.54Hr”,”1.43Hr”,”1.34Hr”,”1.25Hr”) 
plot(horData,
> verData,xaxt='n',xlim= horAxisLims)
> axis(1,tick=TRUE,at= horTicLocs, labels= horLabels)
> 
Hi Hurr,
This might solve questions 1 and 2 for you:

axis(1,tick=TRUE,at= horTicLocs,labels=rep("",length(horLabels)))
library(plotrix)
staxlab(1,at=horTicLocs,labels=horLabels,srt=90,adj=c(1,0))

As for question 3, I'll have to pass as I make no claims to prophecy.

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] Package 'compositions' and R-3.1.0

2014-05-13 Thread Rolf Turner

On 14/05/14 09:21, Rich Shepard wrote:

   I just tried to install 'compositions'. It's apparently not yet
available
for R-3.1.0. How can I learn when it might be available?


The compositions package has apparently been archived:


Package ‘compositions’ was removed from the CRAN repository.

Formerly available versions can be obtained from the archive.

Archived on 2014-05-01 as undefined-behaviour errors were not
corrected (and previously archived on 2014-03-07).



You could try retrieving the package from the archive and fixing it 
yourself.  Good luck!



Rolf Turner

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

2014-05-13 Thread Bill Anderegg

Hi, I am trying to construct a correlelogram plot but plot partial correlation
coefficients, rather than normal coefficients. I've been using the
corrgram() and ggm() libraries to do correlelograms and partial correlation
analysis respectively, but I can't figure out how to combine them. Here is
my code (my dataset is "climvar4" and is a matrix with 11 climate variables 
with 51
observations per variable. so in each cell of the correlelogram I want to 
display the partial correlation between variable x and variable y, while 
accounting for all
other variables):

library(ggm)
library(corrgram)
panel.shadeNtextP <- function (x, y, corr = NULL, col.regions, ...)
{
  corr <- pcor(x, y, var(climvar4))  
  results <- pcor.test(corr,10,51)
  est <- results$p.value
  stars <- ifelse(est < 5e-4, "***",
  ifelse(est < 5e-3, "**",
 ifelse(est < 5e-2, "*", "")))
  ncol <- 14
  pal <- col.regions(ncol)
  col.ind <- as.numeric(cut(corr, breaks = seq(from = -1, to = 1,
   length = ncol + 1),
include.lowest = TRUE))
  usr <- par("usr")
  rect(usr[1], usr[3], usr[2], usr[4], col = pal[col.ind],
   border = NA)
  box(col = "lightgray")
  on.exit(par(usr))
  par(usr = c(0, 1, 0, 1))
  r <- formatC(corr, digits = 2, format = "f")
  cex.cor <- .8/strwidth("-X.xx")
  fonts <- ifelse(stars != "", 2,1)
  # option 1: stars:
  text(0.5, 0.4, paste0(r,"\n", stars), cex = cex.cor)
  # option 2: bolding:
  #text(0.5, 0.5, r, cex = cex.cor, font=fonts)
}
corrgram(climvar4, type="data", order=F, lower.panel=panel.shadeNtextP,
upper.panel=NULL, cex=1.3)

Thanks so much in advance!

Bill

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Put short string labels vertically near tick marks on bottom axis

2014-05-13 Thread Hurr
A month ago I was considering the forum topic
“Label axis tick marks with a simple function of axis value”
and haven’t had time to work much on it.
Since then I have written a little program that makes 
period labels for the frequency axis, but I don’t know how to attach them.
I expected the following code to work.
Later there will be more requirements like 
1) labels should be vertical
2) the bottom of the labels should line up with the ticks
3) requirements beyond today’s consideration

horAxisLims=c(0,7200)
verData=c(1,365,809,1252,1753,2191,2922,3409,3896,4383,4819,5255,5691,6128,6564,7000)
horData=c(1,300,800,1200,1700,2100,2900,3400,3800,4300,4800,5200,5600,6100,6500,7000)
#not at tics 
horTicLocs=c(1,365,809,1252,1753,2191,2922,3409,3896,4383,4819,5255,5691,6128,6564,7000)
horLabels=c(”1Yr”,”1Da”,”10.8Hr”,”7Hr”,”5Hr”,”4Hr”,”3Hr”,”2.57Hr”,”2.25Hr”,”2Hr”,”1.82Hr”,”1.67Hr”,”1.54Hr”,”1.43Hr”,”1.34Hr”,”1.25Hr”)
plot(horData, verData,xaxt='n',xlim= horAxisLims)
axis(1,tick=TRUE,at= horTicLocs, labels= horLabels) 




--
View this message in context: 
http://r.789695.n4.nabble.com/Put-short-string-labels-vertically-near-tick-marks-on-bottom-axis-tp4690452.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] Package 'compositions' and R-3.1.0

2014-05-13 Thread Rich Shepard

  I just tried to install 'compositions'. It's apparently not yet available
for R-3.1.0. How can I learn when it might be available?

TIA,

Rich

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

2014-05-13 Thread David Winsemius

On May 13, 2014, at 7:49 AM, Baba Bukar wrote:

> Dear all,
> 
> I am new to R and have some problem computing transition probabilities. My
> problem goes like this;
> 
> data_set <-
> c(2,0,45,6,78,3,0,2,6,0,5,8,0,2,8,9,12,212,22,4,1,0,3,5,88,5,69,12,4,0,0,0,0,4,87,6,99,104,22,7)
> 
> observations greater than, say 3, is considered as useful (denoted as 1)
> while less than 3 are not useful (denoted as 1). Am trying to calculate the
> transition in these count data such as P_1,1=prob from useful to useful,
> P_1,0=prob from useful to not useful, P_0,1=prob from not useful to useful
> and P_0,0=prob from not useful to not useful.
> 

The rle function (run length encoding) might be helpful here:

> rle( data_set >= 3 )$lengths
 [1] 2 4 2 1 1 2 2 6 2 7 4 7
> rle( data_set >= 3 )$values
 [1] FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE

> Thank you much as you respond soonest
> 
> Kind regards
> Zakir
> 
>   [[alternative HTML version deleted]]

This is a plain text mailing list.

-- 
David Winsemius
Alameda, CA, USA

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


[R] nls() help please

2014-05-13 Thread Andras Farkas
Dear All,
 
please help with writing the function for the following:
 
we have data frame "raw"
 
D1 <-c(2, 2, 2, 2, 2, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 
50, 50, 50, 50, 50)
D2 <-c(0.2, 0.5, 1, 2, 5, 0.2, 0.5, 1, 2, 5, 0.2, 0.5, 1, 2, 5, 0.2, 0.5, 1, 2, 
5, 0.2, 0.5, 1, 2, 5)
E <-c(76.3, 48.8, 44.5, 15.5, 3.21, 56.7, 47.5, 26.8, 16.9, 3.25, 46.7, 35.6, 
21.5, 11.1, 2.94, 24.8, 21.6, 17.3, 7.78, 1.84, 13.6, 11.1, 6.43, 3.34, 0.89)
 
raw <-data.frame(D1,D2,E)
 
reasonable starting parameters for nls (to the best of my knowledge):
 
start <-c(p1=8,p2=80,p3=-0.7,p4=-2.5,p5=0.3,p6=0.7)
 
I would like to fit this model:
 
1 = 
D1/(p1*((E/(p2-E))^(1/p3)))+D2/(p6*((E/(p2-E))^(1/p4)))+(p5*D1*D2)/(p1*p6*((E/(p2-E))^(0.5/p3+0.5/p4)))
 
 
to the data in "raw" using nls(). The weighting of the fit in this case should 
be done using the inverse of the variance of raw$E. Having the model equal to 1 
makes it quiet difficult for me to see or understand how this can be done 
(versus the "usual" nls(y~p1*x+p2,...)) using the software.
 
As always, your help is greatly appreciated.  
 
Sincerely,
 
Andras 

[[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] Calculating transition probabilties

2014-05-13 Thread Suzen, Mehmet
This looks like this is your homework about Markov chains. not an R
question actually.
But have a look at the markovchain package from CRAN:
http://cran.r-project.org/web/packages/markovchain/vignettes/an_introduction_to_markovchain_package.pdf

On 13 May 2014 16:49, Baba Bukar  wrote:
> Dear all,
>
> I am new to R and have some problem computing transition probabilities. My
> problem goes like this;
>
> data_set <-
> c(2,0,45,6,78,3,0,2,6,0,5,8,0,2,8,9,12,212,22,4,1,0,3,5,88,5,69,12,4,0,0,0,0,4,87,6,99,104,22,7)
>
> observations greater than, say 3, is considered as useful (denoted as 1)
> while less than 3 are not useful (denoted as 1). Am trying to calculate the
> transition in these count data such as P_1,1=prob from useful to useful,
> P_1,0=prob from useful to not useful, P_0,1=prob from not useful to useful
> and P_0,0=prob from not useful to not useful.
>
> Thank you much as you respond soonest
>
> Kind regards
> Zakir
>
> [[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] stop a function

2014-05-13 Thread n omranian
Hi,
Another problem arised now. I got this error:
Error in match(x, table, nomatch = 0L) : reached CPU time limit

I googled it  but nothing could help me to get rid of this error. Any comments, 
help or hints?

Thanks a lot,
NO


On Tuesday, May 13, 2014 2:36 PM, "ONKELINX, Thierry" 
 wrote:
 
Have a look at evalWithTimeout() from the R.utils package

Best regards,

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and 
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
thierry.onkel...@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than 
asking him to perform a post-mortem examination: he may be able to say what the 
experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure 
that a reasonable answer can be extracted from a given body of data.
~ John Tukey



-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens 
n omranian
Verzonden: dinsdag 13 mei 2014 14:15
Aan: r-packages-ow...@r-project.org; r-help@r-project.org; 
r-help-requ...@r-project.org
Onderwerp: [R] stop a function

Hi all,

If I use a function in R which takes some parameters as an input, how can I 
stop this function in the while loop and try another parameter in case the 
function takes long time or could not converge.

Actually, I'm using "penalized" function in a loop for some fixed lambdas 
(pre-calculated), for some of them the function converged, but for some not. 
Now I decide to proceed in this way that if it takes longer than 3 mins, stop 
the "penalized" function and try the other lambdas.

I need to do it in the loop since the loop is in the big program and I can't 
manually stop and begin again.

Looking forward to your reply.
NO

        [[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.
* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en 
binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is 
door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the 
writer and may not be regarded as stating an official position of INBO, as long 
as the message is not confirmed by a duly signed document.
[[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] gumbel distribution

2014-05-13 Thread eliza botto
Thankyou very much Frede. It wasn't any home I am just trying to put my grip on 
distribution. Believe it or not, I came to know for the first time that weibull 
and gumbel distributions are same. :(

Eliza


> From: fr...@vestas.com
> To: eliza_bo...@hotmail.com; r-help@r-project.org
> Date: Tue, 13 May 2014 20:08:20 +0200
> Subject: RE: [R] gumbel distribution
> 
> Is this a home work problem?
> 
> See
> 
> Weibull package:stats  R Documentation
> 
> The Weibull Distribution
> 
> Description:
> 
>  Density, distribution function, quantile function and random
>  generation for the Weibull distribution with parameters 'shape'
>  and 'scale'.
> 
> Usage:
> 
>  dweibull(x, shape, scale = 1, log = FALSE)
>  pweibull(q, shape, scale = 1, lower.tail = TRUE, log.p = FALSE)
>  qweibull(p, shape, scale = 1, lower.tail = TRUE, log.p = FALSE)
>  rweibull(n, shape, scale = 1)
>  
> 
> Yours sincerely / Med venlig hilsen
> 
> 
> Frede Aakmann Tøgersen
> Specialist, M.Sc., Ph.D.
> Plant Performance & Modeling
> 
> Technology & Service Solutions
> T +45 9730 5135
> M +45 2547 6050
> fr...@vestas.com
> http://www.vestas.com
> 
> Company reg. name: Vestas Wind Systems A/S
> This e-mail is subject to our e-mail disclaimer statement.
> Please refer to www.vestas.com/legal/notice
> If you have received this e-mail in error please contact the sender. 
> 
> 
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> > On Behalf Of eliza botto
> > Sent: 13. maj 2014 19:57
> > To: r-help@r-project.org
> > Subject: [R] gumbel distribution
> > 
> > Dear useRs,
> > I need some examples of gumbel probability plots in R. i'll be extremely
> > grateful if you could share the codes of a working example.
> > Eliza
> > 
> > 
> > [[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] gumbel distribution

2014-05-13 Thread Frede Aakmann Tøgersen
Is this a home work problem?

See

Weibull package:stats  R Documentation

The Weibull Distribution

Description:

 Density, distribution function, quantile function and random
 generation for the Weibull distribution with parameters 'shape'
 and 'scale'.

Usage:

 dweibull(x, shape, scale = 1, log = FALSE)
 pweibull(q, shape, scale = 1, lower.tail = TRUE, log.p = FALSE)
 qweibull(p, shape, scale = 1, lower.tail = TRUE, log.p = FALSE)
 rweibull(n, shape, scale = 1)
 

Yours sincerely / Med venlig hilsen


Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
fr...@vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender. 


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of eliza botto
> Sent: 13. maj 2014 19:57
> To: r-help@r-project.org
> Subject: [R] gumbel distribution
> 
> Dear useRs,
> I need some examples of gumbel probability plots in R. i'll be extremely
> grateful if you could share the codes of a working example.
> Eliza
> 
> 
>   [[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] gumbel distribution

2014-05-13 Thread eliza botto
Dear useRs,
I need some examples of gumbel probability plots in R. i'll be extremely 
grateful if you could share the codes of a working example.
Eliza

  
[[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] decision curve analysis

2014-05-13 Thread Liisa Marianna
Dear all,

I'm a beginner with R, and I am facing a problem in which I haven't found
help in any FAQs or manuals.

Decision curve analysis published by A. Vickers in 2006 seems appropriate
to my data. There is no R package for decision curve analysis in CRAN, but
I found a project concerning it in R-Forge.

Anyhow, R code for decision curve analysis is provided in the website
www.mskcc.org/research/epidemiology-biostatistics/health-outcomes/decision-curve-analysis.
I followed the turorial provided and saved the R code (dca.R)
and sourced it with R 3.1.0.

source("C:\\Users\\Liisa\\Downloads\\dca-r\\dca.R")

Then I loaded my data.

data1<-read.csv(file.choose(), header=T, sep=";")

and checked it was there by fix(data1) and names(data1).

Then I was trying to tell R to perform the analysis ( I already have the
predicted probabilities made for ROC curve in other software)
dca(data=data1, outcome="OutcomeMACCE",
predictors=c("RiskmodelES2MACCE","RiskmodelES2preTnTMACCE","RiskmodelES2postTnTMACCE")

As a result I only get an error message "unusued arguments"

I also tried renaming the variables (by the command all<-data1$ModelAll,
for each variable), but that did not help.

Is there a problem with that particular R code, or is there a simple error
of mine?

Best regards,
 Liisa

[[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] Calculating transition probabilties

2014-05-13 Thread Baba Bukar
Dear all,

I am new to R and have some problem computing transition probabilities. My
problem goes like this;

data_set <-
c(2,0,45,6,78,3,0,2,6,0,5,8,0,2,8,9,12,212,22,4,1,0,3,5,88,5,69,12,4,0,0,0,0,4,87,6,99,104,22,7)

observations greater than, say 3, is considered as useful (denoted as 1)
while less than 3 are not useful (denoted as 1). Am trying to calculate the
transition in these count data such as P_1,1=prob from useful to useful,
P_1,0=prob from useful to not useful, P_0,1=prob from not useful to useful
and P_0,0=prob from not useful to not useful.

Thank you much as you respond soonest

Kind regards
Zakir

[[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] Help conduction Egger's test

2014-05-13 Thread Michael Dewey

At 19:02 12/05/2014, Sultan Malik wrote:

Hi,

I am currently conducting a meta analyses and wish to carry out 
Egger's test. I was just wondering, does the weighted linear 
regression model proposed by Egger et al correspond to the "weighted 
regression with multiplicative dispersion" option in Metafor?


Dear Sultan

One thing I would suggest is to also use the ranktest function. In my 
experience they can give different results. You also need to look at 
the funnel plot of course and bear in mind that none of these methods 
is very satisfactory unless you have quite a number of fairly 
homogenous studies to synthesise.



Many thanks

Sultan


Michael Dewey
i...@aghmed.fsnet.co.uk
http://www.aghmed.fsnet.co.uk/home.html

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

2014-05-13 Thread Bert Gunter
Did you work your way through the package vignette? If not, you should
certainly do so. Otherwise, I cannot be of any help.

Cheers,
Bert

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
H. Gilbert Welch




On Tue, May 13, 2014 at 9:03 AM, Jesper Hybel Pedersen
 wrote:
> I'm trying to learn how to use the dse-package. Doing a stabilitytest on a 
> model.
> I run the test on two models that are identical except for
>
> Model 1: TREND=0
> Model 2: TREND=NULL
>
> and find the following difference in output unexpected:
>
> library(dse)
> AR=array(c(1,-0.8,-0.15),c(3,1,1))
> model=ARMA(A=AR,B=1,TREND=0)
> stability(model)
> #> Distinct roots of det(A(L)) and moduli are:
> #>   [,1]  [,2]
> #>[1,]  1.000 1.000
> #>[2,]  1.0451762 1.0451762
> #>[3,] -6.3785096 6.3785096
> #>Trend not taken into account: The system is NOT stable.
> #>[1] FALSE
> #>attr(,"roots")
>  #>Inverse of distinct roots of det(A(L))moduli
> #>[1,]  1.000 1.000
> #>[2,]  0.9567764 0.9567764
> #>[3,] -0.1567764 0.1567764
> #>Advarselsbesked:
> #>In roots.ARMA(obj, fuzz = fuzz, randomize = FALSE) :
>  #> Unit roots may need to be added for non-zero trend elements.
>
> AR=array(c(1,-0.8,-0.15),c(3,1,1))
> model=ARMA(A=AR,B=1,TREND=NULL)
> stability(model)
>
> #>Distinct roots of det(A(L)) and moduli are:
> #>   [,1]  [,2]
> #>[1,]  1.0451762 1.0451762
> #>[2,] -6.3785096 6.3785096
> #>The system is stable.
> #>[1] TRUE
> #>attr(,"roots")
> #> Inverse of distinct roots of det(A(L))moduli
> #>[1,]  0.9567764 0.9567764
> #>[2,] -0.1567764 0.1567764
>
>
> I am using:
> R version 3.0.3 (2014-03-06) "Warm Puppy"
>
> Best Regards
> Jesper Hybel Pedersen
> Denmark
>
>
> [[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] stabilitytest dse package

2014-05-13 Thread Jesper Hybel Pedersen
I'm trying to learn how to use the dse-package. Doing a stabilitytest on a 
model.
I run the test on two models that are identical except for 

Model 1: TREND=0
Model 2: TREND=NULL

and find the following difference in output unexpected:

library(dse)
AR=array(c(1,-0.8,-0.15),c(3,1,1))
model=ARMA(A=AR,B=1,TREND=0)
stability(model)
#> Distinct roots of det(A(L)) and moduli are:
#>   [,1]  [,2]
#>[1,]  1.000 1.000
#>[2,]  1.0451762 1.0451762
#>[3,] -6.3785096 6.3785096
#>Trend not taken into account: The system is NOT stable.
#>[1] FALSE
#>attr(,"roots")
 #>Inverse of distinct roots of det(A(L))moduli
#>[1,]  1.000 1.000
#>[2,]  0.9567764 0.9567764
#>[3,] -0.1567764 0.1567764
#>Advarselsbesked:
#>In roots.ARMA(obj, fuzz = fuzz, randomize = FALSE) :
 #> Unit roots may need to be added for non-zero trend elements.

AR=array(c(1,-0.8,-0.15),c(3,1,1))
model=ARMA(A=AR,B=1,TREND=NULL)
stability(model)

#>Distinct roots of det(A(L)) and moduli are:
#>   [,1]  [,2]
#>[1,]  1.0451762 1.0451762
#>[2,] -6.3785096 6.3785096
#>The system is stable.
#>[1] TRUE
#>attr(,"roots")
#> Inverse of distinct roots of det(A(L))moduli
#>[1,]  0.9567764 0.9567764
#>[2,] -0.1567764 0.1567764


I am using:
R version 3.0.3 (2014-03-06) "Warm Puppy"

Best Regards 
Jesper Hybel Pedersen
Denmark

  
[[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] interrogating webdatapage

2014-05-13 Thread Jeff Newmiller
There are a variety of options, but they do generally require that you 
understand how that particular web form interacts with your browser because 
there are multiple ways to design them. Firefox has some powerful plugins such 
as FireBug for studying how web pages work that can inform how you set up your 
scrape. Google for "web scraping R" to get started, and look at the Web 
Technologies task view at CRAN.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On May 13, 2014 3:42:55 PM PDT, Vincenzo Landi  wrote:
>Hello,
>please there is some script that can interrogating a web database (like
>
>this 
>http://pra-incecca.tragsatec.es/pra-incecca/caballos/fichaProducto.xhtml)
>following 
>a list of items and download the response into my local pc?
>Thank you in advance for any help

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

2014-05-13 Thread Rich Shepard

On Tue, 13 May 2014, Cade, Brian wrote:


Your use of the term MANOVA suggests a multivariate response (Y).
If what you really have is multiple factors (predictors), then this is a
different modeling construct (multiple regression) and it would seem
nonpartest() is not appropriate.


Brian,

  You are, of course, correct. I've not before had occasion to think of
MANOVA as a tool so I was ignorant until Don and you educated me. That's
much appreciated.


I've been analyzing water quality constituents (one at a time as a
univariate response) with multiple predictors (I'm using years, seasons
within years, stream flow, location within watershed but anything you
might include in a regression model could be included) in linear quantile
regression (quantreg package). This is a semiparametric approach in the
sense that I don't have to make any assumption about a particular
distributional form of the error distribution since estimating the
quantiles is estimating the inverse of an empirical cumulative
distribution, but all the predictors have parameters associated with them.
You can include contrasts for categorical predictors, interactions, etc.
You also could relax the linear additive model by using smoothing
functions (e.g., b-splines) on the predictors.


  Late yesterday I realized that what I really need is some form of
regression model. Your comments above are very helpful and I will now head
down this path.

Thanks very much,

Rich

--
Richard B. Shepard, Ph.D.| Technically sound and legally defensible
Applied Ecosystem Services, Inc. | ... guaranteed.
www.appl-ecosys.com  Voice: 503-667-4517 Fax: 503-667-8863

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

2014-05-13 Thread Cade, Brian
Rich:  Your use of the term MANOVA suggests a multivariate response (Y).
 If what you really have is multiple factors (predictors), then this is a
different modeling construct (multiple regression) and it would seem
nonpartest() is not appropriate.  I've been analyzing water quality
constituents (one at a time as a univariate response) with multiple
predictors (I'm using years, seasons within years, stream flow, location
within watershed but anything you might include in a regression model could
be included) in linear quantile regression (quantreg package).  This is a
semiparametric approach in the sense that I don't have to make any
assumption about a particular distributional form of the error distribution
since estimating the quantiles is estimating the inverse of an empirical
cumulative distribution, but all the predictors have parameters associated
with them.  You can include contrasts for categorical predictors,
interactions, etc.  You also could relax the linear additive model by using
smoothing functions (e.g., b-splines) on the predictors.

Brian

Brian S. Cade, PhD

U. S. Geological Survey
Fort Collins Science Center
2150 Centre Ave., Bldg. C
Fort Collins, CO  80526-8818

email:  ca...@usgs.gov 
tel:  970 226-9326



On Mon, May 12, 2014 at 5:03 PM, Rich Shepard wrote:

>   I read a short thread on this topic from last June on stackoverflow.com.
> Both Bryan Hanson and Ben Bolker suggested looking for such functions using
> the sos package. I did this; the nonpartest function in npmv does not look
> to me like it does what I need. Since that thread did not reach a
> definitive
> conclusion (no response by the original poster) I would like to continue my
> search here.
>
>   Context: water quality constituent concentrations measured multiple times
> from each of several monitoring wells with the latter in two groups: up-
> and
> down-gradient from a site of potential ground water contamination.
>
>   To compare variation within individual monitoring wells with variation
> between the wells I'd use the Kruskal-Wallis test. That would also be
> appropriate to compare variation within each group (up-gradient and
> down-gradient) with variation between the two groups. My understanding of
> multiple analysis of variance is this would allow multiple sources of
> variability (intra-well and between wells) as explanatory variables for the
> response variable of a specified chemical constituent.
>
>   The help page for nonpartest() tells me that it analyzes one-way
> multivariate data. Perhaps my understanding of this is poor, but the help
> page tells me that nonpartest() formula has a single explanatory variable
> and multiple response variables. In the context above, I have a single
> response variable (a chemical constituent concentration) and multiple
> explanatory variables (at least date, well, and location).
>
>   Please confirm that my understanding of nonpartest() is correct and
> suggest an appropriate R protocol to analyze concentration variability
> within monitoring wells and between two well locations (up- and
> down-gradient).
>
> TIA,
>
> Rich
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] File coding problem: how to read a windows-1252 encoded file

2014-05-13 Thread Bob O'Hara
Ah, thanks. Now I understand a bit more what's happening (and also a bit
more about connections: I have managed to avoid having to understand them).

Right, now I can read my meta-data, I'll start on trying to read the data...

Bob


On 13 May 2014 16:10, peter dalgaard  wrote:

> Hi Bob, Long time no see.
>
> The following works for me. In general, I think it is tricky to rely on
> encodings to be passed on to the appropriate agent, so try to be as
> specific as possible about it.
>
> con <- url("
> ftp://ftpext.usgs.gov/pub/er/md/laurel/BBS/DataFiles/SpeciesList.txt";,
>  encoding="Latin1")
> SpCodes=read.fwf(con,
> widths=c(7,6,51,51), skip=6, n=5, header=F,
> stringsAsFactors=F)
>
> AFAICT, the root cause is that encoding= is passed by read.fwf() to
> read.table(), once the columns are split out, but not to the file
> connection used to get the data for splitting.
>
> It also worked to get the whole enchilada using readLines, convert with
> iconv() and then use read.fwf on a textConnection to the converted lines.
>
> And, BTW, even though encoding names vary between platforms, "ISO-8859" is
> almost surely wrong, because there is "ISO-8859-1", "ISO-8859-2", ...
>
> - Peter
>
>
> On 13 May 2014, at 15:35 , Bob O'Hara  wrote:
>
> > I'm trying to read a text file (actually the ftp file in command below),
> > and I'm getting an error:
> >
> >> SpCodes=read.fwf("
> > ftp://ftpext.usgs.gov/pub/er/md/laurel/BBS/DataFiles/SpeciesList.txt";,
> > +  widths=c(7,6,51,51), skip=6, n=5, header=F,
> > stringsAsFactors=F)
> > Error in substring(x, first, last) :
> >  invalid multibyte string at ' vent'
> >
> > The problem is caused by"Dendrocygne à ventre noir", which has a French
> > character which seems to be causing the problems: there are more
> throughout
> > the file (and I want to read the whole file: I'm picking uot bits above
> to
> > make it easier), so I can't manually delete this. The file is apparently
> in
> > the ISO-8859 format (or it might be windows-1252), but using that in
> either
> > encoding= or fileEncoding= doesn't work:
> >
> > SpCodes=read.fwf("
> > ftp://ftpext.usgs.gov/pub/er/md/laurel/BBS/DataFiles/SpeciesList.txt";,
> > widths=c(7,6,51,51), skip=6, n=5, header=F,
> > stringsAsFactors=F, fileEncoding="ISO-8859")
> >
> > Can anyone suggest a solution? In case it helps, here's my session info:
> >> sessionInfo()
> > R version 3.1.0 (2014-04-10)
> > Platform: x86_64-pc-linux-gnu (64-bit)
> >
> > locale:
> > [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
> > LC_TIME=en_GB.UTF-8LC_COLLATE=en_US.UTF-8
> > [5] LC_MONETARY=en_GB.UTF-8LC_MESSAGES=en_US.UTF-8
> > LC_PAPER=en_GB.UTF-8   LC_NAME=C
> > [9] LC_ADDRESS=C   LC_TELEPHONE=C
> > LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
> >
> > attached base packages:
> > [1] stats graphics  grDevices utils datasets  methods   base
> >
> > loaded via a namespace (and not attached):
> > [1] tools_3.1.0
> >>
> >
> >
> > --
> > Bob O'Hara
> >
> > Biodiversity and Climate Research Centre
> > Senckenberganlage 25
> > D-60325 Frankfurt am Main,
> > Germany
> >
> > Tel: +49 69 798 40226
> > Mobile: +49 1515 888 5440
> > WWW:   http://www.bik-f.de/root/index.php?page_id=219
> > Blog: http://occamstypewriter.org/boboh/
> > Journal of Negative Results - EEB: www.jnr-eeb.org
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> --
> Peter Dalgaard, Professor
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: pd@cbs.dk  Priv: pda...@gmail.com
>
>


-- 
Bob O'Hara

Biodiversity and Climate Research Centre
Senckenberganlage 25
D-60325 Frankfurt am Main,
Germany

Tel: +49 69 798 40226
Mobile: +49 1515 888 5440
WWW:   http://www.bik-f.de/root/index.php?page_id=219
Blog: http://occamstypewriter.org/boboh/
Journal of Negative Results - EEB: www.jnr-eeb.org

[[alternative HTML version deleted]]

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


Re: [R] File coding problem: how to read a windows-1252 encoded file

2014-05-13 Thread peter dalgaard
Hi Bob, Long time no see.

The following works for me. In general, I think it is tricky to rely on 
encodings to be passed on to the appropriate agent, so try to be as specific as 
possible about it.

con <- 
url("ftp://ftpext.usgs.gov/pub/er/md/laurel/BBS/DataFiles/SpeciesList.txt";,
 encoding="Latin1")
SpCodes=read.fwf(con,
widths=c(7,6,51,51), skip=6, n=5, header=F,
stringsAsFactors=F)

AFAICT, the root cause is that encoding= is passed by read.fwf() to 
read.table(), once the columns are split out, but not to the file connection 
used to get the data for splitting.

It also worked to get the whole enchilada using readLines, convert with iconv() 
and then use read.fwf on a textConnection to the converted lines.

And, BTW, even though encoding names vary between platforms, "ISO-8859" is 
almost surely wrong, because there is "ISO-8859-1", "ISO-8859-2", ...

- Peter


On 13 May 2014, at 15:35 , Bob O'Hara  wrote:

> I'm trying to read a text file (actually the ftp file in command below),
> and I'm getting an error:
> 
>> SpCodes=read.fwf("
> ftp://ftpext.usgs.gov/pub/er/md/laurel/BBS/DataFiles/SpeciesList.txt";,
> +  widths=c(7,6,51,51), skip=6, n=5, header=F,
> stringsAsFactors=F)
> Error in substring(x, first, last) :
>  invalid multibyte string at ' vent'
> 
> The problem is caused by"Dendrocygne à ventre noir", which has a French
> character which seems to be causing the problems: there are more throughout
> the file (and I want to read the whole file: I'm picking uot bits above to
> make it easier), so I can't manually delete this. The file is apparently in
> the ISO-8859 format (or it might be windows-1252), but using that in either
> encoding= or fileEncoding= doesn't work:
> 
> SpCodes=read.fwf("
> ftp://ftpext.usgs.gov/pub/er/md/laurel/BBS/DataFiles/SpeciesList.txt";,
> widths=c(7,6,51,51), skip=6, n=5, header=F,
> stringsAsFactors=F, fileEncoding="ISO-8859")
> 
> Can anyone suggest a solution? In case it helps, here's my session info:
>> sessionInfo()
> R version 3.1.0 (2014-04-10)
> Platform: x86_64-pc-linux-gnu (64-bit)
> 
> locale:
> [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
> LC_TIME=en_GB.UTF-8LC_COLLATE=en_US.UTF-8
> [5] LC_MONETARY=en_GB.UTF-8LC_MESSAGES=en_US.UTF-8
> LC_PAPER=en_GB.UTF-8   LC_NAME=C
> [9] LC_ADDRESS=C   LC_TELEPHONE=C
> LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
> 
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
> 
> loaded via a namespace (and not attached):
> [1] tools_3.1.0
>> 
> 
> 
> -- 
> Bob O'Hara
> 
> Biodiversity and Climate Research Centre
> Senckenberganlage 25
> D-60325 Frankfurt am Main,
> Germany
> 
> Tel: +49 69 798 40226
> Mobile: +49 1515 888 5440
> WWW:   http://www.bik-f.de/root/index.php?page_id=219
> Blog: http://occamstypewriter.org/boboh/
> Journal of Negative Results - EEB: www.jnr-eeb.org
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [R] File coding problem: how to read a windows-1252 encoded file

2014-05-13 Thread Prof Brian Ripley

On 13/05/2014 14:35, Bob O'Hara wrote:

I'm trying to read a text file (actually the ftp file in command below),
and I'm getting an error:


SpCodes=read.fwf("

ftp://ftpext.usgs.gov/pub/er/md/laurel/BBS/DataFiles/SpeciesList.txt";,
+  widths=c(7,6,51,51), skip=6, n=5, header=F,
stringsAsFactors=F)
Error in substring(x, first, last) :
   invalid multibyte string at ' vent'

The problem is caused by"Dendrocygne à ventre noir", which has a French
character which seems to be causing the problems: there are more throughout
the file (and I want to read the whole file: I'm picking uot bits above to
make it easier), so I can't manually delete this. The file is apparently in
the ISO-8859 format (or it might be windows-1252), but using that in either
encoding= or fileEncoding= doesn't work:


Why do you expect them to?  read.fwf reads the file (not read.table) and 
it does not have those arguments.  You need to give a file/url 
connection with specified encoding.


> con <- 
url("ftp://ftpext.usgs.gov/pub/er/md/laurel/BBS/DataFiles/SpeciesList.txt";, 
encoding = "cp1252")

> read.fwf(con, widths=c(7,6,51,51), skip=6, n=5, header=F)
> close(con)



SpCodes=read.fwf("
ftp://ftpext.usgs.gov/pub/er/md/laurel/BBS/DataFiles/SpeciesList.txt";,
  widths=c(7,6,51,51), skip=6, n=5, header=F,
stringsAsFactors=F, fileEncoding="ISO-8859")


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

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


Re: [R] Merging data.table and data.frame

2014-05-13 Thread peter dalgaard

On 13 May 2014, at 14:34 , Abhinaba Roy  wrote:

> Hi R-helpers,
> 
> I am trying the following code in R
> 
> merge(x=Master1,y=demo_dtls,by.x=c("ID_CASE","ts"),by.y=c("ID_CASE","TS_EVENT"))
> 
> where,
> 
> class(demo_dtls$TS_EVENT)
> [1] "POSIXct" "POSIXt"
> class(Master1$ts)
> [1] "POSIXct" "POSIXt"
> 
> and
> 
>> class(Master1)[1] "data.table" "data.frame"> class(demo_dtls)[1] "data.frame"
> 
> 
> But I am getting the following error
> 
> Error in merge.data.table(x = Master1, y = demo_dtls, by.x = c("ID_CASE",  :
>  Can not match keys in x and y to automatically determine appropriate
> `by` parameter. Please set `by` value explicitly.
> 
> Why am I getting this error?

You are using merge.data.frame syntax for merge.data.table. The latter knows 
about by=, but not by.x= and by.y= (so presumably you need to rename variables 
in x or y).

- Peter


> Any help will be appreciated
> 
> 
> -- 
> Regards
> Abhinaba Roy
> 
>   [[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.

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


[R] interrogating webdatapage

2014-05-13 Thread Vincenzo Landi

Hello,
please there is some script that can interrogating a web database (like 
this 
http://pra-incecca.tragsatec.es/pra-incecca/caballos/fichaProducto.xhtml) following 
a list of items and download the response into my local pc?

Thank you in advance for any help

--
*
Vincenzo Landi, Phd
Laboratorio de Genética Molecular Aplicada
Departamento de Genética, Universidad de Córdoba
Edificio Gregor Mendel, Planta Baja
Campus Universitario de Rabanales
14071-Córdoba (Spain)
Tf: +34957218708, +34630639439
FAX: +34957218706
www.biolabo.es


---
Este mensaje no contiene virus ni malware porque la protección de avast! 
Antivirus está activa.
http://www.avast.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] File coding problem: how to read a windows-1252 encoded file

2014-05-13 Thread Bob O'Hara
I'm trying to read a text file (actually the ftp file in command below),
and I'm getting an error:

> SpCodes=read.fwf("
ftp://ftpext.usgs.gov/pub/er/md/laurel/BBS/DataFiles/SpeciesList.txt";,
+  widths=c(7,6,51,51), skip=6, n=5, header=F,
stringsAsFactors=F)
Error in substring(x, first, last) :
  invalid multibyte string at ' vent'

The problem is caused by"Dendrocygne à ventre noir", which has a French
character which seems to be causing the problems: there are more throughout
the file (and I want to read the whole file: I'm picking uot bits above to
make it easier), so I can't manually delete this. The file is apparently in
the ISO-8859 format (or it might be windows-1252), but using that in either
encoding= or fileEncoding= doesn't work:

SpCodes=read.fwf("
ftp://ftpext.usgs.gov/pub/er/md/laurel/BBS/DataFiles/SpeciesList.txt";,
 widths=c(7,6,51,51), skip=6, n=5, header=F,
stringsAsFactors=F, fileEncoding="ISO-8859")

Can anyone suggest a solution? In case it helps, here's my session info:
> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-pc-linux-gnu (64-bit)

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

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

loaded via a namespace (and not attached):
[1] tools_3.1.0
>


-- 
Bob O'Hara

Biodiversity and Climate Research Centre
Senckenberganlage 25
D-60325 Frankfurt am Main,
Germany

Tel: +49 69 798 40226
Mobile: +49 1515 888 5440
WWW:   http://www.bik-f.de/root/index.php?page_id=219
Blog: http://occamstypewriter.org/boboh/
Journal of Negative Results - EEB: www.jnr-eeb.org

[[alternative HTML version deleted]]

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


Re: [R] Merging data.table and data.frame

2014-05-13 Thread Jeff Newmiller
Because merge.data.table expects both objects to be data.table objects?
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On May 13, 2014 5:34:32 AM PDT, Abhinaba Roy  wrote:
>Hi R-helpers,
>
>I am trying the following code in R
>
>merge(x=Master1,y=demo_dtls,by.x=c("ID_CASE","ts"),by.y=c("ID_CASE","TS_EVENT"))
>
>where,
>
>class(demo_dtls$TS_EVENT)
>[1] "POSIXct" "POSIXt"
>class(Master1$ts)
>[1] "POSIXct" "POSIXt"
>
>and
>
>> class(Master1)[1] "data.table" "data.frame"> class(demo_dtls)[1]
>"data.frame"
>
>
>But I am getting the following error
>
>Error in merge.data.table(x = Master1, y = demo_dtls, by.x =
>c("ID_CASE",  :
>  Can not match keys in x and y to automatically determine appropriate
>`by` parameter. Please set `by` value explicitly.
>
>Why am I getting this error?
>Any help will be appreciated

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


Re: [R] stop a function

2014-05-13 Thread n omranian
It' great function :)
Thank you so much.
Best,
NO


On Tuesday, May 13, 2014 2:36 PM, "ONKELINX, Thierry" 
 wrote:
 
Have a look at evalWithTimeout() from the R.utils package

Best regards,

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and 
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
thierry.onkel...@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than 
asking him to perform a post-mortem examination: he may be able to say what the 
experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure 
that a reasonable answer can be extracted from a given body of data.
~ John Tukey



-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens 
n omranian
Verzonden: dinsdag 13 mei 2014 14:15
Aan: r-packages-ow...@r-project.org; r-help@r-project.org; 
r-help-requ...@r-project.org
Onderwerp: [R] stop a function

Hi all,

If I use a function in R which takes some parameters as an input, how can I 
stop this function in the while loop and try another parameter in case the 
function takes long time or could not converge.

Actually, I'm using "penalized" function in a loop for some fixed lambdas 
(pre-calculated), for some of them the function converged, but for some not. 
Now I decide to proceed in this way that if it takes longer than 3 mins, stop 
the "penalized" function and try the other lambdas.

I need to do it in the loop since the loop is in the big program and I can't 
manually stop and begin again.

Looking forward to your reply.
NO

        [[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.
* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en 
binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is 
door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the 
writer and may not be regarded as stating an official position of INBO, as long 
as the message is not confirmed by a duly signed document.
[[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] package to plot mean and standard deviation directly on data

2014-05-13 Thread Luigi Marongiu
 Dear Jim,
I have use the brkdn.plot as you suggested and I quite like it since
it is easy to use. Would be possible to overlap the confidence bars
(SD) with the mean value points? The implemetation leaves a small
space as you can see in this figure. I tired with a pch=list(type="o",
pch=c(16, 1, 15)) but it did not work.
In addition: what are the code, if applicable, for let's say:

mean / standard deviation
median / min-max
mean / 95% confidence interval

Here the implemetation is standard error.
Compliments for the development of this nice function,
Regards
luigi

# code::
my.data<-structure(list(
group = c(
0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2),
sample = c(
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1),
copy = c(
626.01, 584.37, 568.5, 154.76, 146.47, 155.83,
297.64, 291.56, 272.16, 414.19, 402.94, 402.94,
351.11, 274.04, 291.56, 66.82, 39.06, 83.87,
16.98, 45.76, 15, 1.39, 98.25, 13.62, 181.32,
142.49, 108.94, 4.95, 5.92, 4.72, 25.14, 31.12,
40.15, 34.27, 26.93, 24.8)),
 row.names = c(NA, -36L),  class = "data.frame")
my.data$sample<-factor(my.data$sample, levels = c(0,1))
 levels(my.data$sample)<-c("first", "second")

brkdn.plot(copy~group+sample,data=my.data, mct="mean", md="std.error",
stagger=NA, dispbar=TRUE,
type="p", pch=c(16, 1, 15),
main="Breakdown plot", xlab="sample",ylab="value", xaxlab=c("first", "second"))

On Mon, May 12, 2014 at 10:36 PM, Jim Lemon  wrote:
> On Mon, 12 May 2014 06:50:29 PM Luigi Marongiu wrote:
>>  Dear all,
>> is there a package, preferably not ggplot, to draw the lines for the
>> standard deviation just by providing the vector with the data? more
> or
>> less as it happens with the boxplot function.
>> the procedure i implemented herein requires the calculation of the
>> means, standard deviations, limits (mean+/-SD) and the horizontal
> bars
>> as well, everything plotted individually. the packages i have seen on
>> google they all require to calculate the mean/SD prior to the plot.
>> best wishes,
>> luigi
>>
>>
>> # in case you are interested this is the code, which is faulty for the
>> factor of the variable "sample"
>>
>> my.data<-structure(list(
>> group = c(
>> 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0,
>> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
>> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2),
>> sample = c(
>> 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
>> 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
>> 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1),
>> copy = c(
>> 626.01, 584.37, 568.5, 154.76, 146.47, 155.83,
>> 297.64, 291.56, 272.16, 414.19, 402.94, 402.94,
>> 351.11, 274.04, 291.56, 66.82, 39.06, 83.87,
>> 16.98, 45.76, 15, 1.39, 98.25, 13.62, 181.32,
>> 142.49, 108.94, 4.95, 5.92, 4.72, 25.14, 31.12,
>> 40.15, 34.27, 26.93, 24.8)),
>>  row.names = c(NA, -36L),  class = "data.frame")
>> # define subset
>> A<-subset(my.data, group==0)
>> # define average and standard deviation
>> avg.A<-aggregate(copy ~ sample, A, mean)
>> names(avg.A)<-c("samp.", "avg")
>> sd.A<-aggregate(copy ~ sample, A, sd)
>> names(sd.A)<-c("Samp", "sd")
>> A.bound<-merge(avg.A, sd.A, by.x="samp.", by.y="Samp")
>> # define limits
>> min.A<-A.bound$avg - A.bound$sd
>> max.A<-A.bound$avg + A.bound$sd
>> # plot
>> plot(avg  ~ samp., data=avg.A,  pch=16, ylim=c(-10, 600),
>> las=3, cex.lab=1.5, cex.main=1.8, col="black",
>> ylab=expression(bold("copy")),
>> xlab=expression(bold("sample")),
>> main="Mean and std dev")
>> # add limit segments
>> segments(seq(length(avg.A$sample)), max.A,
> seq(length(avg.A$sample)),
>> min.A) segments(seq(length(avg.B$sample)), max.B,
>> seq(length(avg.B$sample)),  min.B) # add notch
>> notch<-0.02  # define end of bar extension
>> segments(seq(length(avg.A$sample))-notch, max.A,
>> seq(length(avg.A$sample))+notch,  max.A)
>> segments(seq(length(avg.A$sample))-notch, min.A,
>> seq(length(avg.A$sample))+notch,  min.A)
>>
> Hi Luigi,
> Have a look at brkdn.plot in the plotrix package.
>
> 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.


[R] Getting data s from "Think or Swim " platform through R.

2014-05-13 Thread Ashis Deb
Hi  all ,


Is   it  possible  to  get   datas   from  "Think or Swim "  database
like  we  do  in  Yahoo.finance   through  Quantmod package  like

getSymbol  .

We  know  they  aretaking money  for  datas.

Than  You

ASHIS dEB

[[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] stop a function

2014-05-13 Thread ONKELINX, Thierry
Have a look at evalWithTimeout() from the R.utils package

Best regards,

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and 
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
thierry.onkel...@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than 
asking him to perform a post-mortem examination: he may be able to say what the 
experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure 
that a reasonable answer can be extracted from a given body of data.
~ John Tukey


-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens 
n omranian
Verzonden: dinsdag 13 mei 2014 14:15
Aan: r-packages-ow...@r-project.org; r-help@r-project.org; 
r-help-requ...@r-project.org
Onderwerp: [R] stop a function

Hi all,

If I use a function in R which takes some parameters as an input, how can I 
stop this function in the while loop and try another parameter in case the 
function takes long time or could not converge.

Actually, I'm using "penalized" function in a loop for some fixed lambdas 
(pre-calculated), for some of them the function converged, but for some not. 
Now I decide to proceed in this way that if it takes longer than 3 mins, stop 
the "penalized" function and try the other lambdas.

I need to do it in the loop since the loop is in the big program and I can't 
manually stop and begin again.

Looking forward to your reply.
NO

[[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.
* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en 
binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is 
door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the 
writer and may not be regarded as stating an official position of INBO, as long 
as the message is not confirmed by a duly signed document.

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

2014-05-13 Thread Abhinaba Roy
Hi R-helpers,

I am trying the following code in R

merge(x=Master1,y=demo_dtls,by.x=c("ID_CASE","ts"),by.y=c("ID_CASE","TS_EVENT"))

where,

class(demo_dtls$TS_EVENT)
[1] "POSIXct" "POSIXt"
class(Master1$ts)
[1] "POSIXct" "POSIXt"

and

> class(Master1)[1] "data.table" "data.frame"> class(demo_dtls)[1] "data.frame"


But I am getting the following error

Error in merge.data.table(x = Master1, y = demo_dtls, by.x = c("ID_CASE",  :
  Can not match keys in x and y to automatically determine appropriate
`by` parameter. Please set `by` value explicitly.

Why am I getting this error?
Any help will be appreciated


-- 
Regards
Abhinaba Roy

[[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] stop a function

2014-05-13 Thread n omranian
Hi all,

If I use a function in R which takes some parameters as an input, how can I 
stop this function in the while loop and try another parameter in case the 
function takes long time or could not converge.

Actually, I'm using "penalized" function in a loop for some fixed lambdas 
(pre-calculated), for some of them the function converged, but for some not. 
Now I decide to proceed in this way that if it takes longer than 3 mins, stop 
the "penalized" function and try the other lambdas.

I need to do it in the loop since the loop is in the big program and I can't 
manually stop and begin again.

Looking forward to your reply.
NO

[[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] package to plot mean and standard deviation directly on data

2014-05-13 Thread Luigi Marongiu
 Dear Duncan and Jim,
thank you fo ryour reply. Please do not worry about the code: it was
just an example of the lenghty procedure I have to apply to plot the
standard deviation lines; the actual code is then shaped according to
the data at hand.
I will have a look at the packages you have suggested.
Best regards
Luigi


On Tue, May 13, 2014 at 1:13 AM, Duncan Mackay  wrote:
> Hi Luigi
>
> I have not got time at the moment to look at you question but see
>
> library(xyplot)
> demo(intervals)
>
> Duncan
>
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home: mac...@northnet.com.au
>
>
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf Of Luigi Marongiu
> Sent: Tuesday, 13 May 2014 03:50
> To: r-help@r-project.org
> Subject: [R] package to plot mean and standard deviation directly on data
>
>  Dear all,
> is there a package, preferably not ggplot, to draw the lines for the
> standard deviation just by providing the vector with the data? more or
> less as it happens with the boxplot function.
> the procedure i implemented herein requires the calculation of the
> means, standard deviations, limits (mean+/-SD) and the horizontal bars
> as well, everything plotted individually. the packages i have seen on
> google they all require to calculate the mean/SD prior to the plot.
> best wishes,
> luigi
>
>
> # in case you are interested this is the code, which is faulty for the
> factor of the variable "sample"
>
> my.data<-structure(list(
> group = c(
> 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0,
> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2),
> sample = c(
> 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
> 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
> 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1),
> copy = c(
> 626.01, 584.37, 568.5, 154.76, 146.47, 155.83,
> 297.64, 291.56, 272.16, 414.19, 402.94, 402.94,
> 351.11, 274.04, 291.56, 66.82, 39.06, 83.87,
> 16.98, 45.76, 15, 1.39, 98.25, 13.62, 181.32,
> 142.49, 108.94, 4.95, 5.92, 4.72, 25.14, 31.12,
> 40.15, 34.27, 26.93, 24.8)),
>  row.names = c(NA, -36L),  class = "data.frame")
> # define subset
> A<-subset(my.data, group==0)
> # define average and standard deviation
> avg.A<-aggregate(copy ~ sample, A, mean)
> names(avg.A)<-c("samp.", "avg")
> sd.A<-aggregate(copy ~ sample, A, sd)
> names(sd.A)<-c("Samp", "sd")
> A.bound<-merge(avg.A, sd.A, by.x="samp.", by.y="Samp")
> # define limits
> min.A<-A.bound$avg - A.bound$sd
> max.A<-A.bound$avg + A.bound$sd
> # plot
> plot(avg  ~ samp., data=avg.A,  pch=16, ylim=c(-10, 600),
> las=3, cex.lab=1.5, cex.main=1.8, col="black",
> ylab=expression(bold("copy")),
> xlab=expression(bold("sample")),
> main="Mean and std dev")
> # add limit segments
> segments(seq(length(avg.A$sample)), max.A, seq(length(avg.A$sample)),
> min.A)
> segments(seq(length(avg.B$sample)), max.B, seq(length(avg.B$sample)),
> min.B)
> # add notch
> notch<-0.02  # define end of bar extension
> segments(seq(length(avg.A$sample))-notch, max.A,
> seq(length(avg.A$sample))+notch,  max.A)
> segments(seq(length(avg.A$sample))-notch, min.A,
> seq(length(avg.A$sample))+notch,  min.A)
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] implementation for genetic algorithm

2014-05-13 Thread Carlos Ortega
Hello,

The first two references of this query:

http://www.rseek.org/?cx=010923144343702598753%3Aboaz1reyxd4&q=genetic+algorithm&sa=Search+functions%2C+lists%2C+and+more&cof=FORID%3A11&siteurl=rseek.org%2F&ref=&ss=3792j1503136j17

provides a package (genalg) and an example of what you are looking for.

Regards,
Carlos Ortega
www.qualityexcellence.es


2014-05-12 11:31 GMT+02:00 nourhan iyte :

> Dear All,
> I am a beginner for R programming
> Do you an example for implementation for genetic algorithm
> or how to use it in distance between cities algorithm
>
> Thanks in advanced
> Regards
> MAYA
>
> [[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.
>



-- 
Saludos,
Carlos Ortega
www.qualityexcellence.es

[[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] WG: vars or plm package? bivariate VAR

2014-05-13 Thread Katharina Mersmann
 

Hello R-Community,

 

I actually don´t know how to implement the following: 

 

I have quartaly Panel- Data and want to run a Granger- Test. I´ve already
done a univariate autoregression with grangertest() from package lmtest.

Because  the Granger test is designed to handle pairs of variables, and may
produce misleading results when the true relationship involves three or more
variables, 

a similar test involving more variables can be applied with vector
autoregression. 
And a bivariate (panel-)VAR(1) model seems appropriate to me.

( I have read Chapter2 of B.Pfaffs book “Analysis of integrated and
cointegrated Time Series in R and the application in package ‘vars’, because
didn´t find it in Panel-Context)

 

But I guess it should be possible to run my estimation with the tools of the
vars-package in consideration of (group)correlated Residuals? 

Is the usage of vars-package a good idea? Or do I need o run a dynamic panel
model with pgmm from plm-package?

 

 

Because I can´t give you an reproduceable example, I try to give you a
formal idea of my model:

The formal Model of the bivariate VAR(1) as extension from the Basismodel
looks like this:


[R(i,t) ; 

C(I,t)] 

=  

[a(1,i); 

a(2,i)]

+[b1* R(i,t-1); 

b2*R(i,t-1)]

+[d1* C(i,t-1); 

d2*C(i,t-1)]  

+[ß1* X(i,t); 
ß2*X(i,t)]

+[e1(i,t); 
e2(i,t)]

 

 

Where

t= time dimension,

i= Country

[a(1,i); a(2,i)] = Vector of individual constants

[b1* R(i,t-1); b2R(i,t-1)] +[d1* C(i,t-1); d2C(i,t-1)]   = Vectors
of lagged endogeneous

[ß1* X(i,t); ß2X(i,t)]= Vector with other exogeneous Variables  (not lagged)

[e1(i,t); e2(i,t)]= Vector of residuals

 

And the question is if R(i,t) granger cause C(I,t) and the other way around.

 

The Realization in R of the simultaneous regression and afterwards the Wald
–test  is a big question to me.

 

 

Thanks for your time and your hints! 

Katie

 

 

 


[[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] Freeing up memory in R

2014-05-13 Thread Jeff Newmiller
Perhaps ?read.fwf might help 
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On May 12, 2014 3:01:49 PM PDT, Zilefac Elvis  wrote:
>Hi,
>I will like to free up memory in R and make my program execute faster.
>At the moment, MY PROGRAM IS VERY SLOW probably due to memory issues.
>Here is sample data (Rcode is found at the end) from one simulation(I
>have 1000 such files to process): 
>
>
>
>list(c("1971 1 1GGG1  0.00 -3.68 -0.29", "1971 1 1GGG2  0.00 -8.31 
>0.81", 
>"1971 1 1GGG3  0.00-10.69  5.69", "1971 1 1GGG4  1.78 -6.96 -2.20", 
>"1971 1 1GGG5  2.64 -9.48  9.20", "1971 1 1GGG6  0.00 -9.74  3.73", 
>"1971 1 1GGG7  0.00 -8.49  3.58", "1971 1 1GGG8  0.00 -2.78 -2.92", 
>"1971 1 1GGG9  0.00 -9.30  0.63", "1971 1 1GG10  4.87 -5.59  3.11", 
>"1971 1 1GG11  0.10-12.04 10.80", "1971 1 1GG12  0.00 -5.24 -0.43", 
>"1971 1 1GG13  0.00 -8.82  2.88", "1971 1 1GG14  0.00-11.10 14.50", 
>"1971 1 1GG15  0.00 -5.54 10.12", "1971 1 1GG16  0.00 -4.54 10.48", 
>"1971 1 1GG17  0.00  1.68 17.28", "1971 1 1GG18  0.00 -5.79  6.64", 
>"1971 1 1GG19  0.00 -5.27 14.29", "1971 1 1GG20  0.00 -8.93  9.60", 
>"1971 1 1GG21  5.29  1.30 15.62", "1971 1 1GG22  0.00 -2.50 19.20", 
>"1971 1 1GG23  0.00 -7.04 15.73", "1971 1 1GG24  0.00 -8.53 11.60", 
>"1971 1 1GG25  0.00 -0.82 10.33", "1971 1 1GG26  0.00 -6.28 21.58", 
>"1971 1 1GG27  0.00 -4.73 20.56", "1971 1 1GG28  9.15 -4.38 11.70", 
>"1971 1 1GG29  0.00  2.91  6.94", "1971 1 1GG30  0.00 -7.27 -4.96", 
>"1971 1 1GG31  0.00  2.27  8.05", "1971 1 1GG32  0.00 -3.56  0.66", 
>"1971 1 1GG33  0.00 -0.75  5.10", "1971 1 1GG34  1.81  2.82 -1.50", 
>"1971 1 1GG35  0.00 -9.33 -5.15", "1971 1 1GG36  0.45 -0.41  1.59", 
>"1971 1 1GG37  0.00  0.54  3.06", "1971 1 1GG38  0.00  1.85  0.87", 
>"1971 1 1GG39  0.00  0.41 -5.11", "1971 1 1GG40  3.38 -8.04-10.43", 
>"1971 1 1GG41  0.00 -7.00  3.22", "1971 1 1GG42  0.00  1.44  0.52", 
>"1971 1 1GG43  0.00 -5.16 -4.01", "1971 1 1GG44  0.00 -0.73 -4.24", 
>"1971 1 1GG45  8.63 -9.15  1.35", "1971 1 1GG46  0.00-10.04  6.62", 
>"1971 1 1GG47  0.00 -9.67  8.25", "1971 1 1GG48  0.00-11.63  2.14", 
>"1971 1 1GG49  0.00-10.33  6.68", "1971 1 1GG50  0.00-12.78  3.26", 
>"1971 1 1GG51  9.71 -9.00  4.21", "1971 1 1GG52  2.87-11.94  6.01", 
>"1971 1 1GG53  0.00-13.34  4.57", "1971 1 1GG54  0.71-12.14  9.01", 
>"1971 1 1GG55  2.15 -9.84  1.37", "1971 1 1GG56  0.00-10.11 10.45", 
>"1971 1 1GG57  0.00-10.06  0.97", "1971 1 1GG58  0.00-13.06  6.45", 
>"1971 1 1GG59  0.00-13.17  4.48", "1971 1 1GG60  0.00-11.05  6.79", 
>"1971 1 1GG61  0.00-11.11  1.11", "1971 1 1GG62  0.00 -8.17 10.90", 
>"1971 1 1GG63  0.00-10.98  2.10", "1971 1 1GG64  0.00-12.82  6.07", 
>"1971 1 1GG65  0.00 -8.65  4.32", "1971 1 1GG66  0.00-11.13  3.06", 
>"1971 1 1GG67  0.00 -9.84  1.38", "1971 1 1GG68  1.48-13.17 -4.12", 
>"1971 1 1GG69  0.00-10.64  6.51", "1971 1 1GG70  0.00-12.74  1.47", 
>"1971 1 1GG71  0.00-12.14  9.21", "1971 1 1GG72  0.00-13.07  6.01", 
>"1971 1 1GG73  0.00-11.02  3.18", "1971 1 1GG74  0.00-13.81  3.39", 
>"1971 1 1GG75  0.00-11.53  3.23", "1971 1 1GG76  0.00-11.74  0.52", 
>"1971 1 1GG77  0.00 -9.95 -1.56", "1971 1 1GG78  0.00-12.34 -4.90", 
>"1971 1 1GG79  0.44-12.93 -3.38", "1971 1 1GG80  0.00 -7.25  1.21", 
>"1971 1 1GG81  0.00 -6.69 -2.24", "1971 1 1GG82  0.00 -9.39 -4.35", 
>"1971 1 1GG83  0.00-12.34  2.54", "1971 1 1GG84  0.00 -3.51  2.19", 
>"1971 1 1GG85  0.00-12.03  6.77", "1971 1 1GG86  0.00 -3.54  1.12", 
>"1971 1 1GG87  0.00 -8.15 -0.70", "1971 1 1GG88  0.00 -7.02 -0.51", 
>"1971 1 1GG89  0.00-11.05  2.15", "1971 1 1GG90  0.00-11.44  7.73", 
>"1971 1 1GG91  0.11-11.22  7.26", "1971 1 1GG92  0.00 -4.54  9.87", 
>"1971 1 1GG93  0.00 -4.72 10.68", "1971 1 1GG94  0.00 -8.55  9.54", 
>"1971 1 1GG95  0.19 -0.79 12.46", "1971 1 1GG96  0.00 -4.79 11.92", 
>"1971 1 1GG97  0.00 -5.09 10.64", "1971 1 1GG98  0.00 -4.22 15.50", 
>"1971 1 1GG99  0.00 -7.64 11.21", "1971 1 1G100  0.00 -2.79 11.64", 
>"1971 1 1G101  0.00 -1.62 13.53", "1971 1 1G102  0.00 -4.37  7.94", 
>"1971 1 1G103 13.88 -6.72  5.49", "1971 1 1G104  0.00 -5.19  6.39", 
>"1971 1 1G105 15.04 -2.39  6.86", "1971 1 1G106  0.00-12.08 -1.34", 
>"1971 1 1G107  0.00 -5.80  9.32", "1971 1 1G108  0.00-12.17 10.07", 
>"1971 1 1G109  0.00 -5.83 10.43", "1971 1 1G110  0.00 -6.29  7.37", 
>"1971 1 1G111  0.00-10.59  7.34", "1971 1 1G112  0.00 -3.20  9.05", 
>"1971 1 1G113  0.00 -7.02 11.55", "1971 1 1G114  1.21 -9.86 -2.75", 
>"1971 1 1G115  0.00-14.74  1.11", "1971 1 1G116  0.00 -5.25 -7.93", 
>"1971 1 1G117  0.00 -5.38 -4.76", "1971 

Re: [R] Freeing up memory in R

2014-05-13 Thread Martin Maechler
> Zilefac Elvis 
> on Mon, 12 May 2014 15:01:49 -0700 writes:

> Hi,
> I will like to free up memory in R and make my program execute faster. At 
the moment, MY PROGRAM IS VERY SLOW probably due to memory issues. Here is 
sample data (Rcode is found at the end) from one simulation(I have 1000 such 
files to process): 



> list(c("1971 1 1GGG1  0.00 -3.68 -0.29", "1971 1 1GGG2  0.00 -8.31  
0.81", 
> "1971 1 1GGG3  0.00-10.69  5.69", "1971 1 1GGG4  1.78 -6.96 -2.20", 
> "1971 1 1GGG5  2.64 -9.48  9.20", "1971 1 1GGG6  0.00 -9.74  3.73", 
> "1971 1 1GGG7  0.00 -8.49  3.58", "1971 1 1GGG8  0.00 -2.78 -2.92", 
> "1971 1 1GGG9  0.00 -9.30  0.63", "1971 1 1GG10  4.87 -5.59  3.11", 
> "1971 1 1GG11  0.10-12.04 10.80", "1971 1 1GG12  0.00 -5.24 -0.43", 
> "1971 1 1GG13  0.00 -8.82  2.88", "1971 1 1GG14  0.00-11.10 14.50", 
> "1971 1 1GG15  0.00 -5.54 10.12", "1971 1 1GG16  0.00 -4.54 10.48", 
> "1971 1 1GG17  0.00  1.68 17.28", "1971 1 1GG18  0.00 -5.79  6.64", 
> "1971 1 1GG19  0.00 -5.27 14.29", "1971 1 1GG20  0.00 -8.93  9.60", 
> "1971 1 1GG21  5.29  1.30 15.62", "1971 1 1GG22  0.00 -2.50 19.20", 
> "1971 1 1GG23  0.00 -7.04 15.73", "1971 1 1GG24  0.00 -8.53 11.60", 
> "1971 1 1GG25  0.00 -0.82 10.33", "1971 1 1GG26  0.00 -6.28 21.58", 
[.]
> ))



> Here is a code for processing a thousand of these kind of files:
> 
#===
> lst1Sub <- data_above

> lst2 <- lapply(lst1Sub,function(x) {dateSite <- 
gsub("(.*G.{3}).*","\\1",x); 
>                                     dat1 <- 
data.frame(Year=as.numeric(substr(dateSite,1,4)), 
Month=as.numeric(substr(dateSite,5,6)),Day=as.numeric(substr(dateSite,7,8)),Site=substr(dateSite,9,12),stringsAsFactors=FALSE);
 
>                                     Sims <- 
str_trim(gsub(".*G.{3}\\s?(.*)","\\1",x));Sims[grep("\\d+-",Sims)] <- 
gsub("(.*)([- ][0-9]+\\.[0-9]+)","\\1 \\2",gsub("^([0-9]+\\.[0-9]+)(.*)","\\1 
\\2", Sims[grep("\\d+-",Sims)])); 
>                                     Sims1 <- 
read.table(text=Sims,header=FALSE); names(Sims1) <- c("Precipitation", "Tmin", 
"Tmax");dat2 <- cbind(dat1,Sims1)}) 
> 
#=

> 1) Please use this code to free up memory considering that I am working 
on 1000 files, so I am in for speed.
> 2) Is there a faster way of doing the same task as above? My data files 
are simulated in FORTRAN and read as:

> data.frame(Day=as.numeric(substr(rain.data,7,8)), 
>                          Month=as.numeric(substr(rain.data,5,6)), 
>                          Year=as.numeric(substr(rain.data,1,4)), 
>                          Site=substr(rain.data,9,12), 
>                         Precip=as.numeric(substr(rain.data,13,18)), 
>                         Tmin=as.numeric(substr(rain.data,19,24)), 
>                         Tmax=as.numeric(substr(rain.data,25,30))) 
>  Day occupies position 7 and 8, Month occupies position 5 and 6, Year 
occupies position 1 to 4 and so on for site, precip, tmin and tmax

Given that your data file has things  "at position ",
I think you should use

read.fwf()  instead  of  read.table()  
and then you might not need all the string manipulations you do
above.

Martin


> Thanks for your great help.
> Zilefac.

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

2014-05-13 Thread Jeff Newmiller
Not sure this approach yields meaningful data, but as a demonstration of 
vectorization I got a factor of 10 speedup.


sine.approx3 <- function( tmin, tmax ) {
  B <- (2*pi)/24  # period = 24 hours
  C <- pi/2 # horizontal shift
  tmin <- t( tmin )
  tmax <- t( tmax )
  idx <- seq.int(  24 * 4 * nrow( tmax ) - 12 * 4 )
  xout <- ( idx - 1 ) * 0.25
  cycles <- sin( B * xout - C )
  mag <- matrix( NA, ncol=ncol( tmax ), nrow=length( idx ) )
  idxup <- 2 * seq.int( nrow( tmax ) ) - 1
  idxdn <- idxup[ -1 ] - 1
  idxups <- rep( seq.int( nrow( tmax ) ), each=48 )
  idxdns <- rep( seq.int( nrow( tmax ) - 1 ), each=48 )
  idxupm <- c( outer( 1:48, 48*( idxup - 1 ), FUN="+" ) )
  idxdnm <- c( outer( 1:48, 48*( idxdn - 1 ), FUN="+" ) )
  mag[ idxupm, ] <- ( tmax - tmin )[ idxups,  ] / 2
  mag[ idxdnm, ] <- ( tmax[ -nrow( tmax ), ]
- tmin[ -1, ] )[ idxdns, ] / 2
  mag <- mag * rep( cycles, times=ncol( mag ) )
  mag[ idxupm, ] <- mag[ idxupm, ] + ( tmax + tmin )[ idxups, ] / 2
  mag[ idxdnm, ] <- mag[ idxdnm, ] + ( tmax[ -nrow( tmax ), ]
 + tmin[ -1, ] )[ idxdns, ] / 2
  t( mag )
}


On Tue, 13 May 2014, Ortiz-Bobea, Ariel wrote:


Hello,

I'm trying to fit a sine curve over successive temperature readings (i.e. 
minimum and maximum temperature) over several days and for many locations. The 
code below shows a hypothetical example of 5000 locations with  7 days of 
temperature data. Not very efficient when you have many more locations and days.

The linear interpolation takes 0.7 seconds, and the sine interpolations take 2 
to 4 seconds depending on the approach.

Any ideas on how to speed this up? Thanks in advance.

Ariel

### R Code ##

# 1- Prepare data fake data
 days<- 7
 n <- 5000*days
 tmin <- matrix(rnorm(n, mean=0) , ncol=days, nrow=5000)
 tmax <- matrix(rnorm(n, mean=10), ncol=days, nrow=5000)
 m <- matrix(NA, ncol=days*2, nrow=5000)
 m[,seq(1,ncol(m),2)]  <- tmin
 m[,seq(2,ncol(m)+1,2)]<- tmax
 # check first row
 plot(1:ncol(m), m[1,], type="l")

# 2 -linear interpolation: 0.66 seconds
 xout <- seq(0,ncol(m),0.25/24*2)[-1] # time step = 0.25 hours or 15 minutes
 system.time( m1 <- t(apply(m,1, function(y) approx(x=1:ncol(m), y=y, xout=xout, 
method="linear")$y)) )
 # Check first row
 plot(1:ncol(m), m[1,], type="l")
 points(xout, m1[1,], col="red", cex=1)


# 3- sine interpolation
 sine.approx1 <- function(index, tmin, tmax) {
   b <- (2*pi)/24  # period = 24 hours
   c <- pi/2 # horizontal shift
   xout <- seq(0,24,0.25)[-1]
   yhat <- apply(cbind(tmin[index,],tmax[index,]), 1, function(z) diff(z)/2 * 
sin(b*xout-c) + mean(z))
   #yhat <- yhat[-nrow(yhat),]
   yhat <- c(yhat)
   #plot(yhat, type="l")
 }
 sine.approx2 <- function(index, tmin, tmax) {
   b <- (2*pi)/24  # period = 24 hours
   c <- pi/2 # horizontal shift
   xout1 <- seq(0 ,12,0.25)
   xout2 <- seq(12,24,0.25)[-1]
   xout2 <- xout2[-length(xout2)]
   yhat1 <- apply(cbind(tmin[index,]   ,tmax[index,]), 
1, function(z) diff(z)/2 * sin(b*xout1-c) + mean(z))
   yhat2 <- apply(cbind(tmax[index,][-length(tmax[index,])],tmin[index,][-1]), 
1, function(z) diff(z)/2 * sin(b*xout2+c) + mean(z))
   yhat2 <- cbind(yhat2,NA)
   yhat3 <- rbind(yhat1,yhat2)
   #yhat3 <- yhat3[-nrow(yhat3),]
   yhat3 <- c(yhat3)
   yhat <- yhat3
   #plot(c(yhat1))
   #plot(c(yhat2))
   #plot(yhat, type="l")
 }

 # Single sine: 2.23 seconds
 system.time( m2 <- t(sapply(1:nrow(m), function(i) sine.approx1(i, tmin=tmin, 
tmax=tmax))) )

 # Double sine: 4.03 seconds
 system.time( m3 <- t(sapply(1:nrow(m), function(i) sine.approx2(i, tmin=tmin, 
tmax=tmax))) )

 # take a look at approach 1
 plot(seq(-1,ncol(m)-1,1)[-1], m[1,], type="l")
 points(xout, m2[1,], col="red", cex=1)

 # take a look at approach 2
 plot(seq(-1,ncol(m)-1,1)[-1], m[1,], type="l")
 points(xout, m3[1,], col="blue", cex=1)


---
Ariel Ortiz-Bobea
Fellow
Resources for the Future
1616 P Street, N.W.
Washington, DC 20036
202-328-5173


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



---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k

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