Re: [R] Using Sub

2012-06-15 Thread Duncan Murdoch

On 12-06-14 6:23 PM, Lopez, Dan wrote:

Hi,

I have been trying to get the sub function to work but can't for the life of me 
figure it out. I tried looking at ?sub but I think there is something that I am 
just not understanding.

Example failed attempts

sub("\\","/","G:\Compensation Audits_Reports\Step Audit\Steps off Step.accdb")

Error: '\C' is an unrecognized escape in character string starting "G:\C"


This isn't anything to do with sub(), it's the third string that's the 
problem.  When you say "G:\Comp..." it thinks you've escaped the C, but 
there's no such escape.


Duncan Murdoch




sub("\\","/","G:\Compensation Audits_Reports\Step Audit\Steps off 
Step.accdb",fixed=TRUE)

Error: '\C' is an unrecognized escape in character string starting "G:\C"


sub("\\","/","G:\Compensation Audits_Reports\Step Audit\Steps off 
Step.accdb",fixed=FALSE)

Error: '\C' is an unrecognized escape in character string starting "G:\C")


sub("/","\","G:\Compensation Audits_Reports\Step Audit\Steps off Step.accdb")

Error: unexpected symbol in "sub("/","\","G"

Thanks.
Dan

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

2012-06-15 Thread Deepayan Sarkar
On Wed, Jun 13, 2012 at 8:10 PM, David Winsemius  wrote:
>
> On Jun 13, 2012, at 9:55 AM, Powell, Jeff wrote:
>
>>
>> Dear all,
>>
>> I would like to change the "fill" pattern of a histogram using histogram()
>> in the lattice package.  I know how to do so using hist(), but would prefer
>> to stay within lattice.
>>
>> dt1 <- rnorm(100,0,1)
>>
>> hist(dt1, density=3, angle=45)
>>
>
> I get diagonal striping.
>
>
>>
>> library(lattice)
>> histogram(dt1,
>>              xlab = "Histogram of rnorm(0,1)",
>>              type = "count",
>>              breaks = 15,
>>              col = "grey")
>
>
> I seem to remember that the diagonal hatched fills were disabled or not
> brought over to lattice from base S graphics because they were thought to be
> causing cognitive distortions[1,2].

The actual reason it was not originally implemented is simply that
grid did not support it.  Of course, the "bad"-ness of hatching may
have been the reason grid doesn't support it, and why no one has
bothered to change the status quo in so many years.

-Deepayan

> You already seem to be able to specify
> the color of the fill, and it's easy to get alternating colored fills with
> col = c("grey","red") ,  so it's not entirely clear what your unsatisfied
> goals are.



>
> --
> David Winsemius, MD
> West Hartford, CT
>
> 1]
> http://markmail.org/message/pmrrpjynrcnrwhg5?q=list:org%2Er-project%2Er-help+lattice+hatching
> 2]
> http://markmail.org/message/cj23tnsgsobs4mbu?q=list:org%2Er-project%2Er-help+lattice+hatching
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] time zones and the chron to POSIXct conversion

2012-06-15 Thread Jannis

Hey R folks,


i found some strange (to me) behaviour with chron to POSIXct conversion. 
The two lines of code result in two different results, on ewith the 
correct time zone, one without:


library(chron)
as.POSIXct(chron('12/12/2000'), tz = 'UTC')
as.POSIXlt(chron('12/12/2000'), tz = 'UTC')

Only the code below would give me a POSIXct object with the correct time 
zone:


as.POSIXct(as.POSIXlt(chron('12/12/2000'), tz = 'UTC'))


Is this a bug or desired behaviour?



Thanks a lot
Jannis

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


[R] R: Securities earning covariance

2012-06-15 Thread ANGELO.LINARDI

Good morning.

I have a real fuzzy question to ask; we have a calculation engine which
is composed by n virtual machines each of them with a jvm 2GB of memory
on Linux Red Hat each of them with the "R" package which comes along
with the Red Hat Linux distribution.
We have now to increase the number of "nodes" trying to avoid to use new
virtual or physical machines. So my question is: is it possible to
install multiple jvm on the same machine each of them with its
independent instance of R ?
Should I "duplicate" the initial R installation to get different
instances with different libraries ? Is it enough or even in this case
the different instances "share" something so they are not really "fully
independent" ? 
Thanks so much for you help

Angelo Linardi

** Le e-mail provenienti dalla Banca d'Italia sono trasmesse in buona fede e 
non 
comportano alcun vincolo ne' creano obblighi per la Banca stessa, salvo che 
cio' non 
sia espressamente previsto da un accordo scritto.
Questa e-mail e' confidenziale. Qualora l'avesse ricevuta per errore, La 
preghiamo di 
comunicarne via e-mail la ricezione al mittente e di distruggerne il contenuto. 
La 
informiamo inoltre che l'utilizzo non autorizzato del messaggio o dei suoi 
allegati 
potrebbe costituire reato. Grazie per la collaborazione.
-- E-mails from the Bank of Italy are sent in good faith but they are neither 
binding on 
the Bank nor to be understood as creating any obligation on its part except 
where 
provided for in a written agreement. This e-mail is confidential. If you have 
received it 
by mistake, please inform the sender by reply e-mail and delete it from your 
system. 
Please also note that the unauthorized disclosure or use of the message or any 
attachments could be an offence. Thank you for your cooperation. **

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


Re: [R] Using Sub

2012-06-15 Thread Rui Barradas

Hello,

See inline.

Em 15-06-2012 08:03, Duncan Murdoch escreveu:

On 12-06-14 6:23 PM, Lopez, Dan wrote:

Hi,

I have been trying to get the sub function to work but can't for the
life of me figure it out. I tried looking at ?sub but I think there is
something that I am just not understanding.

Example failed attempts

sub("\\","/","G:\Compensation Audits_Reports\Step Audit\Steps off
Step.accdb")

Error: '\C' is an unrecognized escape in character string starting "G:\C"


This isn't anything to do with sub(), it's the third string that's the
problem.  When you say "G:\Comp..." it thinks you've escaped the C, but
there's no such escape.

Duncan Murdoch



This can be seen if we try to assign the second string.

s1 <- "G:\Compensation Audits_Reports\Step Audit\Steps off Step.accdb"
Error: '\C' is an unrecognized escape in character string starting "G:\C"


The right way would be


s2 <- 'G:\\Compensation Audits_Reports\\Step Audit\\Steps off Step.accdb'

pattern <- ''

gsub(pattern, '/', s2)
[1] "G:/Compensation Audits_Reports/Step Audit/Steps off Step.accdb"


Note also the use of 'gsub', Global sub. I believe it's obvious that the 
purpose is to substitute all backslashes by forward ones.


Hope this helps,

Rui Barradas



sub("\\","/","G:\Compensation Audits_Reports\Step Audit\Steps off
Step.accdb",fixed=TRUE)

Error: '\C' is an unrecognized escape in character string starting "G:\C"


sub("\\","/","G:\Compensation Audits_Reports\Step Audit\Steps off
Step.accdb",fixed=FALSE)

Error: '\C' is an unrecognized escape in character string starting
"G:\C")


sub("/","\","G:\Compensation Audits_Reports\Step Audit\Steps off
Step.accdb")

Error: unexpected symbol in "sub("/","\","G"

Thanks.
Dan

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


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


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


Re: [R] Cholesky decomposition error

2012-06-15 Thread Bert Gunter
Follow the posting guide,please: I believe at this point we need
reproducible code and your data to provide you help. See ?dput to post
your matrix.

-- Bert

On Thu, Jun 14, 2012 at 11:30 PM,   wrote:
>
> Thanks for your reply. To my surprise I can find one more strange behavior of 
>  my 15X15 matrix "A", that is if I call the function  chol(A) in the terminal 
> it decompose the matrix fine without any errors or warnings.
> But if I call the function chol() within a function, which I have written in 
> order to call the function (contains formula) for optimization routine 
> "optim()" and also supplied with the same matrix "A" as argument, the error 
> mentioned
>
>> Error in chol.default(M_cov) :
>>  the leading minor of order 10 is not positive definite
>
> is surfaced during the function call by optim.
>
> Why the matrix fulfill the symmetric and positive definite for chol() in one 
> case but fails in other case when the function chol() is called in other 
> function ?
>
> I played around parameters of "optim" function but nothing seems to be 
> working and I am confused and I am looking for some hints to introspect the 
> problem further.
>
> Regards,
> B.Nataraj
>
>
>
>
>
> -Original Message-
> From: Bert Gunter [mailto:gunter.ber...@gene.com]
> Sent: Thursday, June 14, 2012 6:18 PM
> To: Nataraj B (ORLL-Biotech)
> Cc: r-help@r-project.org
> Subject: Re: [R] Cholesky decomposition error
>
> Your matrix is not symmetric, positive definite. If you don't know
> what this means, you shouldn't be using chol()
>
> This may be because it isn't to begin with, or due to numerical error,
> it doesn't behave as one in the decomposition. My relative ignorance
> of numeric methods for linear algebra prevents me from saying more
> than that.
>
> -- Bert
>
> On Thu, Jun 14, 2012 at 4:23 AM,   wrote:
>> Dear friends,
>>
>> When I do Cholesky decomposition for a 15x15 matrix using the function 
>> chol(), I get the following error for which I do not understand the meaning 
>> of the error
>>
>> Error in chol.default(M_cov) :
>>  the leading minor of order 10 is not positive definite
>>
>> When I searched online for similar error reported earlier I could get few 
>> hits but not of much help to resolve my error and one post suggested to use 
>> different function called sechol() from accuracy package but that did not 
>> work and it leads to different errors. So I want to stick to function chol() 
>> itself.
>>
>> Could you please help me to find where things are going wrong in my matrix?
>>
>>
>> Thanks and regards,
>> B.Natarj
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info:
> Phone: 467-7374
> Website:
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
>
>



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

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

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


Re: [R] finite mixture modeling

2012-06-15 Thread Ingmar Visser
[plug to follow]
depmixS4 fits hidden/latent Markov models on (mixed mode) multivariate
longitudinal data (and it can be found on the cluster task view).
hth, Ingmar

On Thu, Jun 14, 2012 at 1:12 PM, ya  wrote:

> Hi all,
>
> I have a question, is there any R package dealing with latent transition
> analysis with both categorical and continuous indicators? So far what I
> found from GOOGLE are only packages dealing with latent class analysis. So
> what about the longitudinal situation? Any way we could look at the
> transition from one class to another across time points?
>
> Thank you very much.
>
>
>
>
> ya
>[[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] Cholesky decomposition error

2012-06-15 Thread nataraj
Thanks for your reply. I am sorry and I am bit hurried up to say before doing a 
proper due diligence, I have found out that during the optimization the 
variables tend to vary the values of the matrix , the function report error at 
some point (in particular iteration step) when the matrix become 
non-decomposable due to not a positive definiteness. This I observed when I 
change the maximum iteration of the optim function set to 1 and upto iteration 
no. 3 it runs , it stuck at iteration 4 and above.

Now, I am trying to find ways to escalate such a condition inside the function 
during the iteration process and if possible please help me to do that.

Regards,
B.Nataraj


-Original Message-
From: Bert Gunter [mailto:gunter.ber...@gene.com]
Sent: Friday, June 15, 2012 1:51 PM
To: Nataraj B (ORLL-Biotech)
Cc: r-help@r-project.org
Subject: Re: [R] Cholesky decomposition error

Follow the posting guide,please: I believe at this point we need
reproducible code and your data to provide you help. See ?dput to post
your matrix.

-- Bert

On Thu, Jun 14, 2012 at 11:30 PM,   wrote:
>
> Thanks for your reply. To my surprise I can find one more strange behavior of 
>  my 15X15 matrix "A", that is if I call the function  chol(A) in the terminal 
> it decompose the matrix fine without any errors or warnings.
> But if I call the function chol() within a function, which I have written in 
> order to call the function (contains formula) for optimization routine 
> "optim()" and also supplied with the same matrix "A" as argument, the error 
> mentioned
>
>> Error in chol.default(M_cov) :
>>  the leading minor of order 10 is not positive definite
>
> is surfaced during the function call by optim.
>
> Why the matrix fulfill the symmetric and positive definite for chol() in one 
> case but fails in other case when the function chol() is called in other 
> function ?
>
> I played around parameters of "optim" function but nothing seems to be 
> working and I am confused and I am looking for some hints to introspect the 
> problem further.
>
> Regards,
> B.Nataraj
>
>
>
>
>
> -Original Message-
> From: Bert Gunter [mailto:gunter.ber...@gene.com]
> Sent: Thursday, June 14, 2012 6:18 PM
> To: Nataraj B (ORLL-Biotech)
> Cc: r-help@r-project.org
> Subject: Re: [R] Cholesky decomposition error
>
> Your matrix is not symmetric, positive definite. If you don't know
> what this means, you shouldn't be using chol()
>
> This may be because it isn't to begin with, or due to numerical error,
> it doesn't behave as one in the decomposition. My relative ignorance
> of numeric methods for linear algebra prevents me from saying more
> than that.
>
> -- Bert
>
> On Thu, Jun 14, 2012 at 4:23 AM,   wrote:
>> Dear friends,
>>
>> When I do Cholesky decomposition for a 15x15 matrix using the function 
>> chol(), I get the following error for which I do not understand the meaning 
>> of the error
>>
>> Error in chol.default(M_cov) :
>>  the leading minor of order 10 is not positive definite
>>
>> When I searched online for similar error reported earlier I could get few 
>> hits but not of much help to resolve my error and one post suggested to use 
>> different function called sechol() from accuracy package but that did not 
>> work and it leads to different errors. So I want to stick to function chol() 
>> itself.
>>
>> Could you please help me to find where things are going wrong in my matrix?
>>
>>
>> Thanks and regards,
>> B.Natarj
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info:
> Phone: 467-7374
> Website:
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
>
>



--

Bert Gunter
Genentech Nonclinical Biostatistics

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

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


[R] Looking for Speed in a Toy Simulation Example

2012-06-15 Thread Simon Knos
Dear List Members



I used to play around with R to answer the following question by
simulation (I am aware there is an easy explicit solution, but this is
intended to serve as instructional example).

Suppose you have a poker game with 6 players and a deck of 52 cards.
Compute the empirical frequencies of having a single-suit hand. The
way I want the result structured is a boolean nosimulation by noplayer
matrix containing true or false
depending whether the specific player was dealt a single-suit hand.
The code itself is quite short: 1 line to "deal the cards", 1 line to
check whether any of the six players has single-suit hand.


I played around with different variants (all found below) and managed
to gain some speed, however, I subjectively still find it quite slow.

I would thus very much appreciate if anybody could point me to
a) speed improvments in general
b) speed improvements using the compiler package: At what level is
cmpfun best used in this particular example?




Thank you very much,


Simon

###Code#

noplayer <- 6
simlength <- 1e+05
decklength <- 5 * noplayer



#
## Variant 1   ##
#



## Initialize matrix to hold results
singlecolor <- matrix(NA, simlength, noplayer)
## construct the deck to sample from
basedeck <- rep(1:4, 13)
## This one uses split to create the individual hands

set.seed()
system.time({
 for (i in 1:simlength) {
   currentdeck <- split(sample(basedeck, decklength), rep(1:noplayer, 5))
   singlecolor[i, ] <- sapply(currentdeck, function(inv) {
length(unique(inv)) == 1 })
 }
})
apply(singlecolor, 2, mean)
mean(apply(singlecolor, 2, mean))



#
## Variant 2   ##
#



## Initialize matrix to hold results
singlecolor <- matrix(NA, simlength, noplayer)

## construct the deck to sample from
basedeck <- rep(10^(1:4), 13)

## This one uses matrix(...,5) to create the individual hands
## comparison by using powers of ten
set.seed()
system.time({
 for (i in 1:simlength) {
   sampledeck <- sample(basedeck, decklength)
   currentdeck <- matrix(sampledeck, nrow = 5)
   singlecolor[i, ] <- apply(currentdeck, 2, function(inv) {
any(sum(inv) == (5 * 10^(1:4))) })
 }
})
apply(singlecolor, 2, mean)
mean(apply(singlecolor, 2, mean))


#
## Variant 3   ##
#


## Initialize matrix to hold results
singlecolor <- matrix(NA, simlength, noplayer)

## construct the deck to sample from
basedeck <- rep(10^(1:4), 13)

## This one uses matrix(...,5) to create the individual hands
## comparison by using %in%
set.seed()
system.time({
 for (i in 1:simlength) {
   sampledeck <- sample(basedeck, decklength)
   currentdeck <- matrix(sampledeck, nrow = 5)
   singlecolor[i, ] <- apply(currentdeck, 2, sum) %in% (5 * 10^(1:4))
 }
})
apply(singlecolor, 2, mean)
mean(apply(singlecolor, 2, mean))


#
## Variant 4   ##
#



## Initialize matrix to hold results
singlecolor <- matrix(NA, simlength, noplayer)

## construct the deck to sample from
basedeck <- rep(1:4, 13)

## This one uses matrix(...,5) to create the individual hands
## comparison by using length(unique(...))
set.seed()
system.time({
 for (i in 1:simlength) {
   sampledeck <- sample(basedeck, decklength)
   currentdeck <- matrix(sampledeck, nrow = 5)
   singlecolor[i, ] <- apply(currentdeck, 2, function(inv) {
length(unique(inv)) == 1 })
 }
})
apply(singlecolor, 2, mean)
mean(apply(singlecolor, 2, mean))

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

2012-06-15 Thread raishilpa
hello,
I am using the following code

>s<-"I am very happy, excited, and optimistic.I am very scared, annoyed, and
irritated.Iraq’s political crisis entered its second week one step closer to
the potential.dissolution of the government, with a call for elections by a
vital coalition partner and a suicide attack that extended the spate of
violence. that has followed the withdrawal.of U.S. troops"

> sentDetect(s, language = "en")
#getting output in the following way

[1] "I am very happy, excited, and optimistic.I am very scared, annoyed, and
irritated.Iraq’s "   
[2] "political crisis entered its second week one step closer to the
potential.dissolution "  
[3] "of the government, with a call for elections by a vital coalition
partner and a suicide attack that extended the spate of violence. "
[4] "that has followed the withdrawal.of "  
  
[5] "U.S. troops" 

I want output in some different way...since sentences [1] [2] [3] [4] [5]
are from " s" I want output in following way

[1] -"I am very happy, excited, and optimistic.I am very scared, annoyed,
and irritated.Iraq’s political crisis entered its second week one step
closer to the potential.dissolution of the government, with a call for
elections by a vital coalition partner and a suicide attack that extended
the spate of violence. that has followed the withdrawal.of U.S. troops"
[1,1]  "I am very happy, excited, and optimistic.I am very scared, annoyed,
and irritated.Iraq’s " 
[1,2]  "political crisis entered its second week one step closer to the
potential.dissolution " 
[1,3] "of the government, with a call for elections by a vital coalition
partner and a suicide attack that extended the spate of violence. "
[1,4] "that has followed the withdrawal.of "
[1,5] "U.S. troops" 

or in some other way that you guys can suggest me...but remember one thing-
under the main paragraph all the sentences should come so that it become
easy to recognize the parent para of the sub-sentences.

thanking you in anticipation
Shilpa Rai
MSc IIT Bombay
.





--
View this message in context: 
http://r.789695.n4.nabble.com/help-in-sentDetect-fuction-tp4633462.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] Apply() on columns

2012-06-15 Thread faelsendoorn
Hi,

I have some trouble with the following: I have a table of 7 rows and
6columns. The columns 1,2,3 have information about the number of employees.
The columns 4,5,6 have information about the number of working hours. Each
row, is corresponding with a week. 
My goal is to make a boxplot, histogram etc. of the columns 4, 5 and 6
(thus, the data of the number of working hours). How can I select by using
the function Apply the weeks i needed for fullfulling my goal?

I already tried something with environment variables but that is a hard
stop.  I think, when I can select the columns I wanted with the
corresponding rows, that it would not be a problem making a histogram etc.

Yours,

Frans Elsendoorn

--
View this message in context: 
http://r.789695.n4.nabble.com/Apply-on-columns-tp4633468.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] Pass parameter to odfWeave

2012-06-15 Thread Frans Marcelissen




OdfWeave is a great way of creating reports and other quality output from R. 
But is there a simple way to pass a parameter to the report? What I mean is:
odfWeave(templatefile,outputfile) creates the report. If would be much more 
flexible if it would be possible to do something like 
odfWeave(templatefile,outputfile, versionnumber) to pass versionnumber to the 
templatefile, or even odfWeave(templatefile,outputfile,parameterfile) to pass 
the name of a file where other variables are stored. Is something like this 
possible? The only way I see is store parameters in a file that is read in 
templatefile.Thank for any suggestionsFrans 
 
[[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] DEoptim example illustrating use of fnMap parameter for enforcement of cardinality constraints

2012-06-15 Thread David-Michael Lincke
Function DEoptim in package DEoptim for differential evolution defines an 
optional parameter fnMap:

fnMap

"an optional function that will be run after each population is created, but 
before the population is passed to the objective function. This allows the user 
to impose integer/cardinality constriants."

Unfortunately, there is no further documentation decribing the kind of 
parameters being passed to this function on invocation or the structure of the 
return value expected. I would very much appreciate it if somebody familiar 
with this package could provide an example illustrating how this interface is 
meant to be used to enforce cardinality constraints.

Thanks,
David


[[alternative HTML version deleted]]

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


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

2012-06-15 Thread Deepayan Sarkar
On Mon, Jun 11, 2012 at 1:10 PM, maxbre  wrote:
> sorry but I can't close this thread with a viable solution other than the
> following one
> (i.e. by defining an user function to add line);
>
> I understand that the problem is related to the fact that:
> mean(log(.)) != log(mean(.)) is
> but for some reason I can't put all that in practice inside the
> panel.abline(...)
>
> I would appreciate if someone can show me how (sorry but at this point I
> must give up...),

I'm not sure why this is difficult. Once you realize that your problem
was in taking mean of the log-transformed values instead of the
original values, all you need to do is transform back to the original
scale, compute mean, and transform back.

dotplot(date_sampl_time_recs ~ lower_b_i | site, data=teq,
scales = list(x = list(log=TRUE)),
xscale.components = xscale.components.logpower,
layout = c(5,1),
panel = function(x,y,...) {
panel.grid(h=53, v=-1, lty="dotted", col="gray")
panel.dotplot(x,y,...)
panel.abline(v = median(x), col.line="red", lty="dotted")
panel.abline(v = log10(mean(10^x)), col.line="blue", lty="dotted")
}
)

-Deepayan

> thank you all for the help
>
>
> # code start
>
> addLine<- function(a=NULL, b=NULL, v = NULL, h = NULL, ..., once=F) {
>  tcL <- trellis.currentLayout()
>  k<-0
>  for(i in 1:nrow(tcL))
>    for(j in 1:ncol(tcL))
>      if (tcL[i,j] > 0) {
>        k<-k+1
>        trellis.focus("panel", j, i, highlight = FALSE)
>        if (once) panel.abline(a=a[k], b=b[k], v=v[k], h=h[k], ...) else
>          panel.abline(a=a, b=b, v=v, h=h, ...)
>        trellis.unfocus()
>      }
> }
>
>
>
> dotplot(date_sampl_time_recs ~ lower_b_i | site, data=teq,
>        scales=list(x=list(log=TRUE)),
>        xscale.components = xscale.components.logpower,
>        layout=c(5,1),
>        panel = function(x,y,...) {
>          panel.grid(h=53, v=-1, lty="dotted", col="gray")
>          panel.dotplot(x,y,...)
>          medians <- median(x)
>          panel.abline(v=medians, col.line="red", lty="dotted")
>          }
>        )
>
> medie<-as.vector(tapply(teq$lower_b_i,teq$site,mean))
>
> addLine(v=log10(medie), once=TRUE, col="blue", lty="dotted")
>
> # code end
>
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-with-log-scale-tp4632513p4632991.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] POSIXlt and trunc

2012-06-15 Thread Rui Barradas

Hello,

It works with me. Problem with R version? OS?

sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=Portuguese_Portugal.1252 
LC_CTYPE=Portuguese_Portugal.1252
[3] LC_MONETARY=Portuguese_Portugal.1252 LC_NUMERIC=C 


[5] LC_TIME=Portuguese_Portugal.1252

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

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

Hope this helps,

Rui Barradas

Em 15-06-2012 06:06, James Long escreveu:

Hi,

I'm having trouble understanding how trunc is operating on vectors of
POSIXlt objects. Why does dates[1:4] in the last line return a bunch of NAs
even though dates look like it has all the right elements? This worries me
that something is off with my use of trunc. Is trunc not suppose to be
vectorized with POSIXlt? If not, then how should I truncate a bunch of
POSIXlt objects? I'm using R 2.11.1 with linux. (easy cut and paste R code
below)



dates <- c("2011-12-30 20:03:18 PST","2012-01-08 19:10:00 PST",

+ "2012-01-15 22:00:10 PST","2012-01-26 20:01:00 PST",
+ "2012-01-27 21:25:01 PST","2012-01-19 20:17:31 PST",
+ "2012-01-31 21:01:00 PST","2012-01-15 21:01:00 PST",
+ "2012-01-04 21:03:00 PST","2012-01-04 20:00:00 PST")

dates = as.POSIXlt(dates)
dates[1:4]

[1] "2011-12-30 20:03:18" "2012-01-08 19:10:00" "2012-01-15 22:00:10"
[4] "2012-01-26 20:01:00"

class(dates)

[1] "POSIXt"  "POSIXlt"

### this all looks normal so far, now for truncating
dates = trunc(dates,units="hours")
class(dates)

[1] "POSIXt"  "POSIXlt"

dates

  [1] "2011-12-30 20:00:00" "2012-01-08 19:00:00" "2012-01-15 22:00:00"
  [4] "2012-01-26 20:00:00" "2012-01-27 21:00:00" "2012-01-19 20:00:00"
  [7] "2012-01-31 21:00:00" "2012-01-15 21:00:00" "2012-01-04 21:00:00"
[10] "2012-01-04 20:00:00"

dates[1:4]

[1] "2011-12-30 20:00:00" NANA
[4] NA

# what?



Easy cut and paste code:

dates <- c("2011-12-30 20:03:18 PST","2012-01-08 19:10:00 PST",
 "2012-01-15 22:00:10 PST","2012-01-26 20:01:00 PST",
 "2012-01-27 21:25:01 PST","2012-01-19 20:17:31 PST",
 "2012-01-31 21:01:00 PST","2012-01-15 21:01:00 PST",
 "2012-01-04 21:03:00 PST","2012-01-04 20:00:00 PST")
dates = as.POSIXlt(dates)
dates[1:4]
class(dates)
dates = trunc(dates,units="hours")
class(dates)
dates
dates[1:4]


Thanks for your help!
James

[[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] histogram fill lattice

2012-06-15 Thread Powell, Jeff
Thank you for your response, I will try to be clearer.  I would like to fill my 
lattice histogram bars using a symbol rather than a color.  If that is not 
possible, then I will use hist() instead.

>From trellis.par.get()
bar.fill only includes "col", so perhaps I'm out of luck?

With regards,
Jeff

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: woensdag 13 juni 2012 16:40
To: Powell, Jeff
Cc: R-help@r-project.org
Subject: Re: [R] histogram fill lattice


On Jun 13, 2012, at 9:55 AM, Powell, Jeff wrote:

>
> Dear all,
>
> I would like to change the "fill" pattern of a histogram using
> histogram() in the lattice package.  I know how to do so using hist(), 
> but would prefer to stay within lattice.
>
> dt1 <- rnorm(100,0,1)
>
> hist(dt1, density=3, angle=45)
>

I get diagonal striping.

>
> library(lattice)
> histogram(dt1,
>   xlab = "Histogram of rnorm(0,1)",
>   type = "count",
>   breaks = 15,
>   col = "grey")

I seem to remember that the diagonal hatched fills were disabled or not brought 
over to lattice from base S graphics because they were thought to be causing 
cognitive distortions[1,2]. You already seem to be able to specify the color of 
the fill, and it's easy to get alternating colored fills with col = 
c("grey","red") ,  so it's not entirely clear what your unsatisfied goals are.

--
David Winsemius, MD
West Hartford, CT

1] 
http://markmail.org/message/pmrrpjynrcnrwhg5?q=list:org%2Er-project%2Er-help+lattice+hatching
2] 
http://markmail.org/message/cj23tnsgsobs4mbu?q=list:org%2Er-project%2Er-help+lattice+hatching

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 add a vertical line for each panel in a lattice dotplot with log scale?

2012-06-15 Thread maxbre
Thanks a lot, Deepayan!

What a great honour hearing from you inside this thread!

Now, at last, I understand where MY problem was 
(but please, don’t laugh – too loudly at least – and, first of all, sorry
for that!)

this was my “poor” wrong attempt (but I did not post this)

means<-mean(exp(x))
panel.abline(v=log10(means), col.line="blue", lty="dotted")

instead of the correct one…

means<-mean(10^x)
panel.abline(v=log10(means), col.line="blue", lty="dotted")

so, I was using the exponential function exp(), e^x, instead of 10^x 
…poor me!

And all that because I simply overlooked the fact that in

scales=list(x=list(log=TRUE))

TRUE is equivalent to 10, as clearly stated in the on-line help!!

…poor me, again!

thank you

max

--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-with-log-scale-tp4632513p4633481.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] Looking for Speed in a Toy Simulation Example

2012-06-15 Thread Rui Barradas

Hello,

Will a factor of 4 do?
This is variant 3, revised.

#
## Variant 3.b ##
#


## Initialize matrix to hold results
singlecolor <- matrix(NA, simlength, noplayer)

## construct the deck to sample from
basedeck <- rep(10^(1:4), 13)
## Pre-compute this vector, don't re-compute inside a loop
pow10x5 <- 5*10^(1:4)

## This one uses matrix(...,5) to create the individual hands
## but it's created in advance
currentdeck <- matrix(nrow = 5, ncol=noplayer)

## comparison by using %in%
set.seed()
system.time({
 singlecolor[] <- sapply(1:simlength, function(i){
   currentdeck[] <- sample(basedeck, decklength)
   colSums(currentdeck) %in% pow10x5
 })
})
apply(singlecolor, 2, mean)  ## colMeans()
mean(apply(singlecolor, 2, mean))


Note that the real speed gain is in colSums, all the rest gave me around 
1.5 secs or 5% only.


Rui Barradas

Em 15-06-2012 09:40, Simon Knos escreveu:

Dear List Members



I used to play around with R to answer the following question by
simulation (I am aware there is an easy explicit solution, but this is
intended to serve as instructional example).

Suppose you have a poker game with 6 players and a deck of 52 cards.
Compute the empirical frequencies of having a single-suit hand. The
way I want the result structured is a boolean nosimulation by noplayer
matrix containing true or false
depending whether the specific player was dealt a single-suit hand.
The code itself is quite short: 1 line to "deal the cards", 1 line to
check whether any of the six players has single-suit hand.


I played around with different variants (all found below) and managed
to gain some speed, however, I subjectively still find it quite slow.

I would thus very much appreciate if anybody could point me to
a) speed improvments in general
b) speed improvements using the compiler package: At what level is
cmpfun best used in this particular example?




Thank you very much,


Simon

###Code#

noplayer <- 6
simlength <- 1e+05
decklength <- 5 * noplayer



#
## Variant 1   ##
#



## Initialize matrix to hold results
singlecolor <- matrix(NA, simlength, noplayer)
## construct the deck to sample from
basedeck <- rep(1:4, 13)
## This one uses split to create the individual hands

set.seed()
system.time({
  for (i in 1:simlength) {
currentdeck <- split(sample(basedeck, decklength), rep(1:noplayer, 5))
singlecolor[i, ] <- sapply(currentdeck, function(inv) {
length(unique(inv)) == 1 })
  }
})
apply(singlecolor, 2, mean)
mean(apply(singlecolor, 2, mean))



#
## Variant 2   ##
#



## Initialize matrix to hold results
singlecolor <- matrix(NA, simlength, noplayer)

## construct the deck to sample from
basedeck <- rep(10^(1:4), 13)

## This one uses matrix(...,5) to create the individual hands
## comparison by using powers of ten
set.seed()
system.time({
  for (i in 1:simlength) {
sampledeck <- sample(basedeck, decklength)
currentdeck <- matrix(sampledeck, nrow = 5)
singlecolor[i, ] <- apply(currentdeck, 2, function(inv) {
any(sum(inv) == (5 * 10^(1:4))) })
  }
})
apply(singlecolor, 2, mean)
mean(apply(singlecolor, 2, mean))


#
## Variant 3   ##
#


## Initialize matrix to hold results
singlecolor <- matrix(NA, simlength, noplayer)

## construct the deck to sample from
basedeck <- rep(10^(1:4), 13)

## This one uses matrix(...,5) to create the individual hands
## comparison by using %in%
set.seed()
system.time({
  for (i in 1:simlength) {
sampledeck <- sample(basedeck, decklength)
currentdeck <- matrix(sampledeck, nrow = 5)
singlecolor[i, ] <- apply(currentdeck, 2, sum) %in% (5 * 10^(1:4))
  }
})
apply(singlecolor, 2, mean)
mean(apply(singlecolor, 2, mean))


#
## Variant 4   ##
#



## Initialize matrix to hold results
singlecolor <- matrix(NA, simlength, noplayer)

## construct the deck to sample from
basedeck <- rep(1:4, 13)

## This one uses matrix(...,5) to create the individual hands
## comparison by using length(unique(...))
set.seed()
system.time({
  for (i in 1:simlength) {
sampledeck <- sample(basedeck, decklength)
currentdeck <- matrix(sampledeck, nrow = 5)
singlecolor[i, ] <- apply(currentdeck, 2, function(inv) {
length(unique(inv)) == 1 })
  }
})
apply(singlecolor, 2, mean)
mean(apply(singlecolor, 2, mean))

__

[R] Help with Sequential Differencing

2012-06-15 Thread Lekgatlhamang, lexi Setlhare


Dear R Users,

I have struggled with the following problem for days, which I thought was 
simple, although it would likely be basic to most of you.
I am working with time series data. 
In my script, my intention is to create first differences of the variables in 
the file so that I end up estimating an equation of the form:
DCred(t) =c + 
DCred(t-1)+DCred(t-2)+...+DBoB(t)+DBoB(t-1)+DBoB(t-2)+...+Drvr(t)+Drvr(t-1)+Drvr(t-2)+...+e(t)

Where D at the beginning of each variable represents 'change', for first 
difference and e(t) is the error term.
Now I am trying to use loops to calculate 5 lagged first-differences of each 
variable in the dataset - e.g., DCred(t-1), DCred(t-2), ..., DCred(t-5).
Example:
# Differences of Cred
DCred<- diff(Cred, difference=1)
DCred
for(i in 1:5){
print(DCred[i]<- diff(DCred, lag=i, difference=1))
}
After I calculated the contemporaneous first difference DCred, this loop is 
meant to compute the subsequent first differences of the same variable; i.e., 
DCred(t-1) and call it DCred1, DCred(t-2) and call it DCred2, ... and 
DCred(t-5) and call it DCred5.
The loop works, at least I think so. But now after the loop has executed, when 
I type DCred1[1] (which I thought would give me the first value in the series 
for DCred(t-1)), called DCred1, I get a message "object 'DCred1' not found". 
Similarly typing Dcred1[2] (which I thought would give the second value of 
DCred(t-1)), ie., the second value of DCred1, gives "object DCred1[2] not 
found", etc.
A copy of the commands and error messages is below:
> DCred1[1]
Error: object 'DCred1' not found
> DCred1[2]
Error: object 'DCred1' not found

How can I solve this problem? Thank you kindly for your time.
[[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] Rename output file in Swaeve and Tex

2012-06-15 Thread Manish Gupta
HI, 

I am working on R and Latex.

R CMD Sweave Test.Rnw  (this generates Rnw.Tex file )

R CMD pdflatex Test.tex  (It generated Test.pdf)

Is there any way to change the name of of output file (Test.pdf).  I want it
to pass the output file name as parameter. 

R CMD Sweave Test.Rnw  Output_File

R CMD pdflatex Output_File.tex 

So output file name will be Output_File.pdf 

Regards



--
View this message in context: 
http://r.789695.n4.nabble.com/Rename-output-file-in-Swaeve-and-Tex-tp4633479.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] Help with Sequential Differencing

2012-06-15 Thread Lekgatlhamang, lexi Setlhare
Dear R Users,
Sorry for what seems like I am re-posting. When I was typing my initial 
posting, I intended to copy and paste the commands from my script, but ended up 
forgetting. I am now pasting the commands in this email.NB: Below is a copy of 
'all' the relevant commands in my script
 
 ##
data<- read.table("C:\\myfiles\\from drive D\\myfiles 080208\\An R Test 
folder\\Dataset2a.csv", head=TRUE, sep=",")
str(data)
data
 
# Extract the variables in data, rename and difference them
 
Cred <- ts(data[, 2], frequency=12, start=c(2001, 1)) # Cred denotes Credit
 
# Differences of Cred
DCred<- diff(Cred, difference=1)
DCred
for(i in 1:5){
print(DCred[i]<- diff(DCred, lag=i, difference=1))
 
} 
 
DCred[1]
 
 DCred[2]
 
 DCred[3]
 
 
Thanks Lexi




To: "r-help@r-project.org"  
Sent: Friday, June 15, 2012 11:39 AM
Subject: Help with Sequential Differencing




Dear R Users,

I have struggled with the following problem for days, which I thought was 
simple, although it would likely be basic to most of you.
I am working with time series data. 
In my script, my intention is to create first differences of the variables in 
the file so that I end up estimating an equation of the form:
DCred(t) =c + 
DCred(t-1)+DCred(t-2)+...+DBoB(t)+DBoB(t-1)+DBoB(t-2)+...+Drvr(t)+Drvr(t-1)+Drvr(t-2)+...+e(t)

Where D at the beginning of each variable represents 'change', for first 
difference and e(t) is the error term.
Now I am trying to use loops to calculate 5 lagged first-differences of each 
variable in the dataset - e.g., DCred(t-1), DCred(t-2), ..., DCred(t-5).
Example:
# Differences of Cred
DCred<- diff(Cred, difference=1)
DCred
for(i in 1:5){
print(DCred[i]<- diff(DCred, lag=i, difference=1))
}
After I calculated the contemporaneous first difference DCred, this loop is 
meant to compute the subsequent first differences of the same variable; i.e., 
DCred(t-1) and call it DCred1, DCred(t-2) and call it DCred2, ... and 
DCred(t-5) and call it DCred5.
The loop works, at least I think so. But now after the loop has executed, when 
I type DCred1[1] (which I thought would give me the first value in the series 
for DCred(t-1)), called DCred1, I get a message "object 'DCred1' not found". 
Similarly typing Dcred1[2] (which I thought would give the second value of 
DCred(t-1)), ie., the second value of DCred1, gives "object DCred1[2] not 
found", etc.
A copy of the commands and error messages is below:
> DCred1[1]
Error: object 'DCred1' not found
> DCred1[2]
Error: object 'DCred1' not found

How can I solve this problem? Thank you kindly for your time.
[[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 with Sequential Differencing

2012-06-15 Thread Sarah Goslee
If you really want DCred1, DCred2, etc, you'll need to use assign() and
paste() within your loop. But he's a more R-ish way:

# Differences of Cred

DCred <- list()
for(i in 1:5){
print(DCred[[i]]<- diff(DCred, lag=i, difference=1))

}

DCred[[1]]

Sarah

On Friday, June 15, 2012, Lekgatlhamang, lexi Setlhare wrote:

> Dear R Users,
> Sorry for what seems like I am re-posting. When I was typing my initial
> posting, I intended to copy and paste the commands from my script, but
> ended up forgetting. I am now pasting the commands in this email.NB: Below
> is a copy of 'all' the relevant commands in my script
>
>  ##
> data<- read.table("C:\\myfiles\\from drive D\\myfiles 080208\\An R Test
> folder\\Dataset2a.csv", head=TRUE, sep=",")
> str(data)
> data
>
> # Extract the variables in data, rename and difference them
>
> Cred <- ts(data[, 2], frequency=12, start=c(2001, 1)) # Cred denotes Credit
>
> # Differences of Cred
> DCred<- diff(Cred, difference=1)
> DCred
> for(i in 1:5){
> print(DCred[i]<- diff(DCred, lag=i, difference=1))
>
> }
>
> DCred[1]
>
>  DCred[2]
>
>  DCred[3]
>
>  
> Thanks Lexi
>
>
> 
>
> To: "r-help@r-project.org " 
> >
> Sent: Friday, June 15, 2012 11:39 AM
> Subject: Help with Sequential Differencing
>
>
>
>
> Dear R Users,
>
> I have struggled with the following problem for days, which I thought was
> simple, although it would likely be basic to most of you.
> I am working with time series data.
> In my script, my intention is to create first differences of the variables
> in the file so that I end up estimating an equation of the form:
> DCred(t) =c +
> DCred(t-1)+DCred(t-2)+...+DBoB(t)+DBoB(t-1)+DBoB(t-2)+...+Drvr(t)+Drvr(t-1)+Drvr(t-2)+...+e(t)
>
> Where D at the beginning of each variable represents 'change', for first
> difference and e(t) is the error term.
> Now I am trying to use loops to calculate 5 lagged first-differences of
> each variable in the dataset - e.g., DCred(t-1), DCred(t-2), ...,
> DCred(t-5).
> Example:
> # Differences of Cred
> DCred<- diff(Cred, difference=1)
> DCred
> for(i in 1:5){
> print(DCred[i]<- diff(DCred, lag=i, difference=1))
> }
> After I calculated the contemporaneous first difference DCred, this loop
> is meant to compute the subsequent first differences of the same variable;
> i.e., DCred(t-1) and call it DCred1, DCred(t-2) and call it DCred2, ... and
> DCred(t-5) and call it DCred5.
> The loop works, at least I think so. But now after the loop has executed,
> when I type DCred1[1] (which I thought would give me the first value in the
> series for DCred(t-1)), called DCred1, I get a message "object 'DCred1' not
> found". Similarly typing Dcred1[2] (which I thought would give the second
> value of DCred(t-1)), ie., the second value of DCred1, gives "object
> DCred1[2] not found", etc.
> A copy of the commands and error messages is below:
> > DCred1[1]
> Error: object 'DCred1' not found
> > DCred1[2]
> Error: object 'DCred1' not found
>
> How can I solve this problem? Thank you kindly for your time.
>[[alternative HTML version deleted]]
>
>

-- 
Sarah Goslee
http://www.stringpage.com
http://www.sarahgoslee.com
http://www.functionaldiversity.org

[[alternative HTML version deleted]]

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


Re: [R] spelling correction using R

2012-06-15 Thread Oliver Ruebenacker
 Hello,

On Fri, Jun 15, 2012 at 1:10 AM, raishilpa  wrote:
> I want a code which can correct the spelling mistakes  as well as
> grammatical mistakes in the sentences...that is if I am writing following
> sentence:
>
> I want too meet my frnd bt due to hectic shcedule I cant
>
> I want output in following way:
>
> I want to met my friend but due to hectic schedule I can't.

  In general, you would build a dictionary, look up for every word in
the input whether it is in the dictionary, and if not, which is the
most similar word using some string metric.

  You will, however, face problems:

  - No dictionary is ever complete
  - Some wrong words are equally similar to multiple correct words
(e.g. should "bt" be "bit" or "but" or "bat"?)
  - Not all errors lead to wrong words (e.g. "Sum errors will will nut
bee fond because they happen to leed two sentence consisting of reel
word")

  It is therefore doubtful that spell-correction can be done non-interactively.

 Take care
 Oliver

-- 
Oliver Ruebenacker
Bioinformatics Consultant (http://www.knowomics.com/wiki/Oliver_Ruebenacker)
Knowomics, The Bioinformatics Network (http://www.knowomics.com)
SBPAX: Turning Bio Knowledge into Math Models (http://www.sbpax.org)

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


[R] moving from loops to apply

2012-06-15 Thread Schumacher, G.
Dear subscribers,

I have made a simulation using loops rather than apply, simply because the loop 
function seems more natural to me. However, the current simulation takes 
forever and I have decided - finally - to learn how to use apply, but - as many 
other people before me - I am having a hard time changing habits. My current 
problem is:

My current code for the loop is:
distances <- matrix(NA, 1000, 5)
distancer <- function(x, y){-(abs(x-y))}
x <- as.matrix(rnorm(1000, 5, 1.67))
y <- rnorm(5, 5, 1.67)

for (v in 1:1000){
distances[v,] <- distancer(x[v,], y)
}

The goal is to calculate the distances between the preferences of each voter 
(X) and all parties (Y). This gives a 1000 by 5 matrix (distances).

If I want to transform this to apply, what would be the best way to go? More 
specifically, I am not sure what to put into the X part of the apply function.

Sorry, for asking this question that is already much debated, I just don't seem 
to be able to apply to my own case. Many thanks in advance.

Kind regards,

Gijs Schumacher

[[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] moving from loops to apply

2012-06-15 Thread Rui Barradas

Hello,

Simple question with reproducible example code.
The best way to go is to know to what dimension you want to apply the 
function, the 1st, and to write the function in such a way as to have 
the passed rows as the first argument. If it has other arguments, they 
go after. Since your function is already written like this, there's 
little left to be done.


d2 <- apply(x, 1, distancer, y)  # note the other arg.
dim(d2)
all.equal(distances, t(d2))

Why this transpose? Because apply is passing _row_vectors_ and the 
function's return values are vectors, in R, _columns_.
Were it applying the function to columns and the return value would be 
with the right dims. Like this just assign


d2 <- t(d2) # or d2 <- t(apply(...etc...))

Hope this helps,

Rui Barradas


Em 15-06-2012 12:27, Schumacher, G. escreveu:

Dear subscribers,

I have made a simulation using loops rather than apply, simply because the loop 
function seems more natural to me. However, the current simulation takes 
forever and I have decided - finally - to learn how to use apply, but - as many 
other people before me - I am having a hard time changing habits. My current 
problem is:

My current code for the loop is:
distances <- matrix(NA, 1000, 5)
distancer <- function(x, y){-(abs(x-y))}
x <- as.matrix(rnorm(1000, 5, 1.67))
y <- rnorm(5, 5, 1.67)

for (v in 1:1000){
distances[v,] <- distancer(x[v,], y)
}

The goal is to calculate the distances between the preferences of each voter 
(X) and all parties (Y). This gives a 1000 by 5 matrix (distances).

If I want to transform this to apply, what would be the best way to go? More 
specifically, I am not sure what to put into the X part of the apply function.

Sorry, for asking this question that is already much debated, I just don't seem 
to be able to apply to my own case. Many thanks in advance.

Kind regards,

Gijs Schumacher

[[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] moving from loops to apply

2012-06-15 Thread Schumacher, G.
Yes, it does thanks. Before your explanation I didn't understand that I had to 
separate distancer and y with a comma...great!


From: Rui Barradas [ruipbarra...@sapo.pt]
Sent: Friday, June 15, 2012 1:49 PM
To: Schumacher, G.
Cc: r-help@r-project.org
Subject: Re: [R] moving from loops to apply

Hello,

Simple question with reproducible example code.
The best way to go is to know to what dimension you want to apply the
function, the 1st, and to write the function in such a way as to have
the passed rows as the first argument. If it has other arguments, they
go after. Since your function is already written like this, there's
little left to be done.

d2 <- apply(x, 1, distancer, y)  # note the other arg.
dim(d2)
all.equal(distances, t(d2))

Why this transpose? Because apply is passing _row_vectors_ and the
function's return values are vectors, in R, _columns_.
Were it applying the function to columns and the return value would be
with the right dims. Like this just assign

d2 <- t(d2) # or d2 <- t(apply(...etc...))

Hope this helps,

Rui Barradas


Em 15-06-2012 12:27, Schumacher, G. escreveu:
> Dear subscribers,
>
> I have made a simulation using loops rather than apply, simply because the 
> loop function seems more natural to me. However, the current simulation takes 
> forever and I have decided - finally - to learn how to use apply, but - as 
> many other people before me - I am having a hard time changing habits. My 
> current problem is:
>
> My current code for the loop is:
> distances <- matrix(NA, 1000, 5)
> distancer <- function(x, y){-(abs(x-y))}
> x <- as.matrix(rnorm(1000, 5, 1.67))
> y <- rnorm(5, 5, 1.67)
>
> for (v in 1:1000){
> distances[v,] <- distancer(x[v,], y)
> }
>
> The goal is to calculate the distances between the preferences of each voter 
> (X) and all parties (Y). This gives a 1000 by 5 matrix (distances).
>
> If I want to transform this to apply, what would be the best way to go? More 
> specifically, I am not sure what to put into the X part of the apply function.
>
> Sorry, for asking this question that is already much debated, I just don't 
> seem to be able to apply to my own case. Many thanks in advance.
>
> Kind regards,
>
> Gijs Schumacher
>
>   [[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] moving from loops to apply

2012-06-15 Thread Petr Savicky
On Fri, Jun 15, 2012 at 11:27:44AM +, Schumacher, G. wrote:
> Dear subscribers,
> 
> I have made a simulation using loops rather than apply, simply because the 
> loop function seems more natural to me. However, the current simulation takes 
> forever and I have decided - finally - to learn how to use apply, but - as 
> many other people before me - I am having a hard time changing habits. My 
> current problem is:
> 
> My current code for the loop is:
> distances <- matrix(NA, 1000, 5)
> distancer <- function(x, y){-(abs(x-y))}
> x <- as.matrix(rnorm(1000, 5, 1.67))
> y <- rnorm(5, 5, 1.67)
> 
> for (v in 1:1000){
> distances[v,] <- distancer(x[v,], y)
> }
> 
> The goal is to calculate the distances between the preferences of each voter 
> (X) and all parties (Y). This gives a 1000 by 5 matrix (distances).
> 
> If I want to transform this to apply, what would be the best way to go? More 
> specifically, I am not sure what to put into the X part of the apply function.

Hi.

There are also other ways to eliminate loops than apply-type functions.
Try, for example

  distances <- matrix(NA, 1000, 5)
  distancer <- function(x, y){-(abs(x-y))}
  x <- as.matrix(rnorm(1000, 5, 1.67))
  y <- rnorm(5, 5, 1.67)
 
  for (v in 1:1000){
  distances[v,] <- distancer(x[v,], y)
  }
 
  dst1 <- outer(c(x), y, FUN=distancer)
 
  identical(distances, dst1)

  [1] TRUE
 
  xm <- matrix(x, nrow=nrow(x), ncol=length(y))
  ym <- matrix(y, nrow=nrow(x), ncol=length(y), byrow=TRUE)
  dst2 <- -abs(xm - ym)
 
  identical(distances, dst2)

  [1] TRUE

Apply uses a loop internally, so it need not significantly improve efficiency.

Petr Savicky.

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


[R] Sugeestion about tuning of SVM

2012-06-15 Thread Guido Leoni
Dear list
I've a generic question about how to tune an SVM
I'm trying to classify  with caret package some population data from a
case-control study . In each column of my matrix there are the SNP
genotypes , in each row there are the individuals.
I correctly splitted my total dataset in training(132 individuals) and test
(50 individuals) (respecting the total observed genotypic frequencies and
the % of cases and controls)
After training (with radial RBF function)  I have an accuracy of the best
model of 76% but applying the model to my test dataset the accuracy
decreases to 52%.
Obviously i expected the decrease but this appear to be quite big in my
opinion.
I manually checked the predictions for my test dataset and some cases that
have no risk allele are not well classified. Similar cases in my training
dataset are well recognized.
Please could you suggest to me which parameters modify  in order to improve
the classification for the test dataset? or better which could be the
causes that could originate this big discrepancy?
I know that my question is very generic but i'm very newbie to this kind of
analysis so please any suggestion is the welcome
thank you very much
Guido

-- 
Guido Leoni
National Research Institute on Food and Nutrition
(I.N.R.A.N.)
via Ardeatina 546
00178 Rome
Italy

tel + 39 06 51 49 41 (operator)
+ 39 06 51 49 4498 (direct)

[[alternative HTML version deleted]]

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


Re: [R] How to convert month-day-year to Julian data number?

2012-06-15 Thread Jean V Adams
?julian


Paloma Moya  wrote on 06/15/2012 01:13:04 AM:

> Hello,
> I am trying to convert calendar dates (Month, Day, Year) into Julian 
Days
> 
> Product code Bureau of Meteorology station number Month Day Year 
> Date_mdy Date 
> 4102001 70014 1 1 1939 1/01/1939 1/01/1939 
> 4102001 70014 1 2 1939 1/02/1939 2/01/1939 
> 4102001 70014 1 3 1939 1/03/1939 3/01/1939 
> 4102001 70014 1 4 1939 1/04/1939 4/01/1939 
> 4102001 70014 1 5 1939 1/05/1939 5/01/1939 
> 4102001 70014 1 6 1939 1/06/1939 6/01/1939 
> 4102001 70014 1 7 1939 1/07/1939 7/01/1939 
> 
> These are the type of data that I have
> 
> 
> I am trying to get the output as
> 
> Product code Bureau of Meteorology station number Month Day Year 
> Date_mdy Date JD 
> 4102001 70014 1 1 1939   215421 
> 4102001 70014 1 2 1939   215422 
> 4102001 70014 1 3 1939   215423 
> 4102001 70014 1 4 1939   215424 
> 4102001 70014 1 5 1939   215425 
> 4102001 70014 1 6 1939   215426 
> 4102001 70014 1 7 1939   215427 
> 
> (these JDs are fictions) 
> 
> I have tried to apply strftime, mdy.date etc â?¦ etcâ?¦
> But I couldnâ??tâ?¦ could you help me, please?
> 
> Thank you very much,
> Paloma

[[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] Apply() on columns

2012-06-15 Thread Jean V Adams
Frans,

I'm not sure I understand what you're after.

I suggest that you share a small example data set, using dput().
Then give an example of what you want the output to look like.

Jean


faelsendoorn  wrote on 06/15/2012 03:09:41 AM:

> Hi,
> 
> I have some trouble with the following: I have a table of 7 rows and
> 6columns. The columns 1,2,3 have information about the number of 
employees.
> The columns 4,5,6 have information about the number of working hours. 
Each
> row, is corresponding with a week. 
> My goal is to make a boxplot, histogram etc. of the columns 4, 5 and 6
> (thus, the data of the number of working hours). How can I select by 
using
> the function Apply the weeks i needed for fullfulling my goal?
> 
> I already tried something with environment variables but that is a hard
> stop.  I think, when I can select the columns I wanted with the
> corresponding rows, that it would not be a problem making a histogram 
etc.
> 
> Yours,
> 
> Frans Elsendoorn

[[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] Sugeestion about tuning of SVM

2012-06-15 Thread Mark Leeds
Hi: I don't know anything about gentoypes but it sounds like you overfitted
the training set so you should try using regularization. In standard
svm-classification algorithms, that can be done by decreasing the parameter
C which decreases the objective functional penalty for mis-classifying. (
allows the margin to increase by allowing  the
algorithm to mis-classify more often ) But you're using caret rather than
one of the svm packages directly so the parameter might be called something
else rather than C.

There are so many books on support vector machines but a nice intro from an
R perspective is "Support Vector Machines in R" in the Journal of
Statistical Software. ( it's free at www.jstatsoft.com )










On Fri, Jun 15, 2012 at 8:19 AM, Guido Leoni  wrote:

> Dear list
> I've a generic question about how to tune an SVM
> I'm trying to classify  with caret package some population data from a
> case-control study . In each column of my matrix there are the SNP
> genotypes , in each row there are the individuals.
> I correctly splitted my total dataset in training(132 individuals) and test
> (50 individuals) (respecting the total observed genotypic frequencies and
> the % of cases and controls)
> After training (with radial RBF function)  I have an accuracy of the best
> model of 76% but applying the model to my test dataset the accuracy
> decreases to 52%.
> Obviously i expected the decrease but this appear to be quite big in my
> opinion.
> I manually checked the predictions for my test dataset and some cases that
> have no risk allele are not well classified. Similar cases in my training
> dataset are well recognized.
> Please could you suggest to me which parameters modify  in order to improve
> the classification for the test dataset? or better which could be the
> causes that could originate this big discrepancy?
> I know that my question is very generic but i'm very newbie to this kind of
> analysis so please any suggestion is the welcome
> thank you very much
> Guido
>
> --
> Guido Leoni
> National Research Institute on Food and Nutrition
> (I.N.R.A.N.)
> via Ardeatina 546
> 00178 Rome
> Italy
>
> tel + 39 06 51 49 41 (operator)
>+ 39 06 51 49 4498 (direct)
>
>[[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] Customizing a Plot in Correspondence Analysis

2012-06-15 Thread Milan Bouchet-Valat
Le jeudi 14 juin 2012 à 20:32 -0400, Salvador Ramirez a écrit :
> Hello,
> 
> Using the Correspondence Analysis package (ca), I wonder if there is a way
> to further customize the plot beyond the options given in plot.ca provided
> by the mentioned package.
> 
> The correspondence analysis I am doing consists of two datasets sharing
> only the rows, so the plot draw the total of columns (from both datasets)
> in the graph and the rows as expected. However, as in my case the number
> of columns in one dataset is huge, I would like to omit those points and
> labels in the plot. The list of parameters of plot.ca does not allow me to
> do this so I wonder if there is a way to force this in R.
> 
> An example to see what I want is the following:
> 
> library(ca)
> data(author)
> plot(ca(author), arrows=c(FALSE,TRUE))
> 
> The object "author" is composed of two datasets, I would like to omit the
> points corresponding to columns from a-m, while still maintaining the
> points in the second datasets, i.e. columns from n-z.
> 
> Any help is more than appreciated.
This is not possible with the standard plot.ca() function. I have
written small functions in my package[1] that return a ca object with
only the rows or columns you specified. This is an ugly hack, but it
works as long as you plot the result directly. These functions are:

# Restrain CA to a subset of rows (only for plotting!)
rowSubsetCa <- function(ca, indices) {
ret <- ca
for (i in 4:7) {
ret[[i]] <- list()
ret[[i]] <- ca[[i]][indices]
}
del <- which(!(1:nrow(ca$rowcoord) %in% indices))
ret$rowsup <- as.numeric(sapply(ca$rowsup[ca$rowsup %in% indices],
function(x) x - sum(del < x)))
ret$rowcoord <- matrix()
ret$rowcoord <- ca$rowcoord[indices,,drop=FALSE]
ret$rownames <- ca$rownames[indices]
ret
}

# Restrain CA to a subset of columns (only for plotting!)
colSubsetCa <- function(ca, indices) {
ret <- ca
for (i in 9:12) {
ret[[i]] <- list()
ret[[i]] <- ca[[i]][indices]
}
ret$colsup <- ret$colsup[ret$colsup %in% indices]
ret$colsup <- as.numeric(lapply(ca$colsup, function(x) x - sum(indices < 
x)))
ret$colcoord <- matrix()
ret$colcoord <- ca$colcoord[indices,,drop=FALSE]
ret$colnames <- ca$colnames[indices]
ret
}

In you case, you can do something like
plot(colSubsetCa(ca(author), 1:13))


Hope this helps


1:
https://r-forge.r-project.org/scm/viewvc.php/pkg/rcmdr-tms/R/showCorpusCa.R?view=markup&root=rcmdr-tms

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


Re: [R] spelling correction using R

2012-06-15 Thread R. Michael Weylandt
Grammar is quite complicated, but for spelling you might try this
wonderful article by Peter Norvig:

http://norvig.com/spell-correct.html

Michael

On Fri, Jun 15, 2012 at 12:10 AM, raishilpa  wrote:
> hello
>
> I want a code which can correct the spelling mistakes  as well as
> grammatical mistakes in the sentences...that is if I am writing following
> sentence:
>
> I want too meet my frnd bt due to hectic shcedule I cant
>
> I want output in following way:
>
> I want to met my friend but due to hectic schedule I can't.
>
> Thanks in advance
>
> Shilpa Rai
> MSc
> IIT Bomaby
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/spelling-correction-using-R-tp4633454.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Looking for Speed in a Toy Simulation Example

2012-06-15 Thread Simon Knos
Rui, thank you very much.

I keep forgetting about the rowSum and friends. (precalculating the
powers just slipped my attention).

And, yes, a factor of will of course do. Do you see a further
improvement in this case?


Best,

Simon

On Fri, Jun 15, 2012 at 12:25 PM, Rui Barradas  wrote:
> Hello,
>
> Will a factor of 4 do?
> This is variant 3, revised.
>
> #
> ## Variant 3.b                                 ##
>
> #
>
>
> ## Initialize matrix to hold results
> singlecolor <- matrix(NA, simlength, noplayer)
>
> ## construct the deck to sample from
> basedeck <- rep(10^(1:4), 13)
> ## Pre-compute this vector, don't re-compute inside a loop
> pow10x5 <- 5*10^(1:4)
>
>
> ## This one uses matrix(...,5) to create the individual hands
> ## but it's created in advance
> currentdeck <- matrix(nrow = 5, ncol=noplayer)
>
>
> ## comparison by using %in%
> set.seed()
> system.time({
>  singlecolor[] <- sapply(1:simlength, function(i){
>   currentdeck[] <- sample(basedeck, decklength)
>   colSums(currentdeck) %in% pow10x5
>  })
> })
> apply(singlecolor, 2, mean)  ## colMeans()
> mean(apply(singlecolor, 2, mean))
>
>
> Note that the real speed gain is in colSums, all the rest gave me around 1.5
> secs or 5% only.
>
> Rui Barradas
>
> Em 15-06-2012 09:40, Simon Knos escreveu:
>>
>> Dear List Members
>>
>>
>>
>> I used to play around with R to answer the following question by
>> simulation (I am aware there is an easy explicit solution, but this is
>> intended to serve as instructional example).
>>
>> Suppose you have a poker game with 6 players and a deck of 52 cards.
>> Compute the empirical frequencies of having a single-suit hand. The
>> way I want the result structured is a boolean nosimulation by noplayer
>> matrix containing true or false
>> depending whether the specific player was dealt a single-suit hand.
>> The code itself is quite short: 1 line to "deal the cards", 1 line to
>> check whether any of the six players has single-suit hand.
>>
>>
>> I played around with different variants (all found below) and managed
>> to gain some speed, however, I subjectively still find it quite slow.
>>
>> I would thus very much appreciate if anybody could point me to
>> a) speed improvments in general
>> b) speed improvements using the compiler package: At what level is
>> cmpfun best used in this particular example?
>>
>>
>>
>>
>> Thank you very much,
>>
>>
>> Simon
>>
>>
>> ###Code#
>>
>> noplayer <- 6
>> simlength <- 1e+05
>> decklength <- 5 * noplayer
>>
>>
>>
>> #
>> ## Variant 1                                   ##
>> #
>>
>>
>>
>> ## Initialize matrix to hold results
>> singlecolor <- matrix(NA, simlength, noplayer)
>> ## construct the deck to sample from
>> basedeck <- rep(1:4, 13)
>> ## This one uses split to create the individual hands
>>
>> set.seed()
>> system.time({
>>  for (i in 1:simlength) {
>>    currentdeck <- split(sample(basedeck, decklength), rep(1:noplayer, 5))
>>    singlecolor[i, ] <- sapply(currentdeck, function(inv) {
>> length(unique(inv)) == 1 })
>>  }
>> })
>> apply(singlecolor, 2, mean)
>> mean(apply(singlecolor, 2, mean))
>>
>>
>>
>> #
>> ## Variant 2                                   ##
>> #
>>
>>
>>
>> ## Initialize matrix to hold results
>> singlecolor <- matrix(NA, simlength, noplayer)
>>
>> ## construct the deck to sample from
>> basedeck <- rep(10^(1:4), 13)
>>
>> ## This one uses matrix(...,5) to create the individual hands
>> ## comparison by using powers of ten
>> set.seed()
>> system.time({
>>  for (i in 1:simlength) {
>>    sampledeck <- sample(basedeck, decklength)
>>    currentdeck <- matrix(sampledeck, nrow = 5)
>>    singlecolor[i, ] <- apply(currentdeck, 2, function(inv) {
>> any(sum(inv) == (5 * 10^(1:4))) })
>>  }
>> })
>> apply(singlecolor, 2, mean)
>> mean(apply(singlecolor, 2, mean))
>>
>>
>> #
>> ## Variant 3                                   ##
>> #
>>
>>
>> ## Initialize matrix to hold results
>> singlecolor <- matrix(NA, simlength, noplayer)
>>
>> ## construct the deck to sample from
>> basedeck <- rep(10^(1:4), 13)
>>
>> ## This one uses matrix(...,5) to create the individual hands
>> ## comparison by using %in%
>> set.seed()
>> system.time({
>>  for (i in 1:simlength) {
>>    sampledeck <- sample(basedeck, decklength)
>>    currentdeck <- matrix(sampledeck, nrow = 5)
>>    singlecolor[i, ] <- apply(currentdeck, 2, sum) %in% (5 * 10^(1:4))
>>  }
>> })
>> apply(singlecolor, 2, mean)
>> mean(apply(singlecolor, 2, mean))
>>
>>
>> #
>> ## Variant 4                

Re: [R] Apply() on columns

2012-06-15 Thread R. Michael Weylandt
Just to take a stab at it, I'd suggest you don't actually need apply()
and could simply get what you need with

hist(DATA[,4:6])

if your data is as described.

Michael

On Fri, Jun 15, 2012 at 7:23 AM, Jean V Adams  wrote:
> Frans,
>
> I'm not sure I understand what you're after.
>
> I suggest that you share a small example data set, using dput().
> Then give an example of what you want the output to look like.
>
> Jean
>
>
> faelsendoorn  wrote on 06/15/2012 03:09:41 AM:
>
>> Hi,
>>
>> I have some trouble with the following: I have a table of 7 rows and
>> 6columns. The columns 1,2,3 have information about the number of
> employees.
>> The columns 4,5,6 have information about the number of working hours.
> Each
>> row, is corresponding with a week.
>> My goal is to make a boxplot, histogram etc. of the columns 4, 5 and 6
>> (thus, the data of the number of working hours). How can I select by
> using
>> the function Apply the weeks i needed for fullfulling my goal?
>>
>> I already tried something with environment variables but that is a hard
>> stop.  I think, when I can select the columns I wanted with the
>> corresponding rows, that it would not be a problem making a histogram
> etc.
>>
>> Yours,
>>
>> Frans Elsendoorn
>
>        [[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] Help with Sequential Differencing

2012-06-15 Thread Sarah Goslee
I missed something in my original reply:

You intended a recursive approach, I think, but that wasn't clear in
your code, and I simply repeated your actual code rather than your
intended code in my response. If that's what you want, you need
something more like:

DCred<- list()
DCred[[1]] <- diff(Cred, difference=1)

for(i in 2:5){
  print(DCred[[i]]<- diff(DCred[[i-1]], lag=i, difference=1))
}

Doing it with separately-named files will be much more complicated,
something like

DCred1 <- diff(Cred, difference=1)

for(i in 2:5){
  print(assign(paste("DCred", i, sep=""), diff(get(paste("DCred", i-1,
sep="")), lag=i, difference=1))
}

(both are untested)

You might also benefit from reading Intro to R, which covers list structures.

Sarah

On Fri, Jun 15, 2012 at 9:22 AM, Lekgatlhamang, lexi Setlhare
 wrote:
> Hi Sarah,
>
> Sorry for taking more of your time. I thought that before investigating the
> use of assign and paste, I should first understand the approach of using
> 'list()'. However, it seems to me that the use of list does not work very
> well, unless I have wrongly implemented your suggestion. I implemented your
> suggestion as follows:
> DCred<- list()
> for(i in 1:5){
> print(DCred[[i]]<- diff(DCred, lag=i, difference=1))
> }
> Upon execution of the loop, the following was printed out:
> list()
> list()
> list()
> list()
> list()
> After the loop I tried to access the values for DCred1, DCred2, etc but to
> no avail. See my commands and the associated output below:
>
>> DCred[[1]]
> list()
>> DCred[[i]]
> list()
>> DCred[1]
> [[1]]
> list()
> Anyway, I then calculate DCred in order to see if the regression
>
> DCred <-lm(DCred~DCred1+DCred2)
>
> will work.
> But it did not. Instead I got an error message - see below.
>
>> model<- lm(DCred~DCred[1]+DCred[2], drop.unused.levels = TRUE)
> Error in model.frame.default(formula = DCred ~ DCred[1] + DCred[2],
> drop.unused.levels = TRUE) :
>   variable lengths differ (found for 'DCred[1]')
>
> I then modified the right-hand-side of the equation, but still it did not
> work:
>
>> model <- lm(DCred~DCred[[1]])
> Error in model.frame.default(formula = DCred ~ DCred[[1]],
> drop.unused.levels = TRUE) :
>   variable lengths differ (found for 'DCred[[1]]')
>
> I will remain reading up on the assign and paste commands.
> Thanks. Lexi
> From: Sarah Goslee 
> To: "Lekgatlhamang, lexi Setlhare" 
> Cc: "r-help@r-project.org" 
> Sent: Friday, June 15, 2012 12:54 PM
> Subject: Re: [R] Help with Sequential Differencing
>
> If you really want DCred1, DCred2, etc, you'll need to use assign() and
> paste() within your loop. But he's a more R-ish way:
>
> # Differences of Cred
>
> DCred <- list()
> for(i in 1:5){
> print(DCred[[i]]<- diff(DCred, lag=i, difference=1))
>
> }
>
> DCred[[1]]
>
> Sarah
>
> On Friday, June 15, 2012, Lekgatlhamang, lexi Setlhare wrote:
>
> Dear R Users,
> Sorry for what seems like I am re-posting. When I was typing my initial
> posting, I intended to copy and paste the commands from my script, but ended
> up forgetting. I am now pasting the commands in this email.NB: Below is a
> copy of 'all' the relevant commands in my script
>
>  ##
> data<- read.table("C:\\myfiles\\from drive D\\myfiles 080208\\An R Test
> folder\\Dataset2a.csv", head=TRUE, sep=",")
> str(data)
> data
>
> # Extract the variables in data, rename and difference them
>
> Cred <- ts(data[, 2], frequency=12, start=c(2001, 1)) # Cred denotes Credit
>
> # Differences of Cred
> DCred<- diff(Cred, difference=1)
> DCred
> for(i in 1:5){
> print(DCred[i]<- diff(DCred, lag=i, difference=1))
>
> }
>
> DCred[1]
>
>  DCred[2]
>
>  DCred[3]
>
>  
> Thanks Lexi
>
>
> 
>
> To: "r-help@r-project.org" 
> Sent: Friday, June 15, 2012 11:39 AM
> Subject: Help with Sequential Differencing
>
>
>
>
> Dear R Users,
>
> I have struggled with the following problem for days, which I thought was
> simple, although it would likely be basic to most of you.
> I am working with time series data.
> In my script, my intention is to create first differences of the variables
> in the file so that I end up estimating an equation of the form:
> DCred(t) =c +
> DCred(t-1)+DCred(t-2)+...+DBoB(t)+DBoB(t-1)+DBoB(t-2)+...+Drvr(t)+Drvr(t-1)+Drvr(t-2)+...+e(t)
>
> Where D at the beginning of each variable represents 'change', for first
> difference and e(t) is the error term.
> Now I am trying to use loops to calculate 5 lagged first-differences of each
> variable in the dataset - e.g., DCred(t-1), DCred(t-2), ..., DCred(t-5).
> Example:
> # Differences of Cred
> DCred<- diff(Cred, difference=1)
> DCred
> for(i in 1:5){
> print(DCred[i]<- diff(DCred, lag=i, difference=1))
> }
> After I calculated the contemporaneous first difference DCred, this loop is
> meant to compute the subsequent first differences of the same variable;
> i.e., DCred(t-1) and call it DCred1, DCred(t-2) and call it DCred2, .

Re: [R] moving from loops to apply

2012-06-15 Thread Petr Savicky
On Fri, Jun 15, 2012 at 02:08:13PM +0200, Petr Savicky wrote:
> On Fri, Jun 15, 2012 at 11:27:44AM +, Schumacher, G. wrote:
> > Dear subscribers,
> > 
> > I have made a simulation using loops rather than apply, simply because the 
> > loop function seems more natural to me. However, the current simulation 
> > takes forever and I have decided - finally - to learn how to use apply, but 
> > - as many other people before me - I am having a hard time changing habits. 
> > My current problem is:
> > 
> > My current code for the loop is:
> > distances <- matrix(NA, 1000, 5)
> > distancer <- function(x, y){-(abs(x-y))}
> > x <- as.matrix(rnorm(1000, 5, 1.67))
> > y <- rnorm(5, 5, 1.67)
> > 
> > for (v in 1:1000){
> > distances[v,] <- distancer(x[v,], y)
> > }
> > 
> > The goal is to calculate the distances between the preferences of each 
> > voter (X) and all parties (Y). This gives a 1000 by 5 matrix (distances).
> > 
> > If I want to transform this to apply, what would be the best way to go? 
> > More specifically, I am not sure what to put into the X part of the apply 
> > function.
> 
[...]
> 
> Apply uses a loop internally, so it need not significantly improve efficiency.

Hi.

Let me include an example of the situation, when a vectorized code is
more efficient than a code using apply(), although the apply() code
is significantly simpler.

  n <- 1

  x <- matrix(runif(3*n), nrow=n, ncol=3)

  t1 <- system.time( {
  y <- t(apply(x, 1, sort))
  } )

  # use a vectorized bubble sort, which is efficient on 3 elements
  t2 <- system.time( {
  x[, 1:2] <- cbind(pmin(x[, 1], x[, 2]), pmax(x[, 1], x[, 2]))
  x[, 2:3] <- cbind(pmin(x[, 2], x[, 3]), pmax(x[, 2], x[, 3]))
  x[, 1:2] <- cbind(pmin(x[, 1], x[, 2]), pmax(x[, 1], x[, 2]))
  } )

  print(identical(x, y))

  [1] TRUE
   
  print(rbind(t1, t2))

 user.self sys.self elapsed user.child sys.child
  t1 0.4780   0.477  0 0
  t2 0.0040   0.004  0 0

Hope this helps.

Petr Savicky.

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


Re: [R] POSIXlt and trunc

2012-06-15 Thread R. Michael Weylandt
General rule of thumb: use POSIXct rather than POSIXlt for such things
and only convert to POSIXlt (losslessly) at the end of your
calculations when you need it for display reasons. Internally, POSIXct
is just a double, so it is nice to do calculations on, while POSIXlt
is a list-like object which tries to handle the book-keeping of all
sorts of different time elements. See RNews 4/1 for more detail.

Not sure if this is immediately the problem at hand, but I've found it
to be good practice.

Best,
Michael

On Fri, Jun 15, 2012 at 12:06 AM, James Long  wrote:
> Hi,
>
> I'm having trouble understanding how trunc is operating on vectors of
> POSIXlt objects. Why does dates[1:4] in the last line return a bunch of NAs
> even though dates look like it has all the right elements? This worries me
> that something is off with my use of trunc. Is trunc not suppose to be
> vectorized with POSIXlt? If not, then how should I truncate a bunch of
> POSIXlt objects? I'm using R 2.11.1 with linux. (easy cut and paste R code
> below)
>
>
>> dates <- c("2011-12-30 20:03:18 PST","2012-01-08 19:10:00 PST",
> +             "2012-01-15 22:00:10 PST","2012-01-26 20:01:00 PST",
> +             "2012-01-27 21:25:01 PST","2012-01-19 20:17:31 PST",
> +             "2012-01-31 21:01:00 PST","2012-01-15 21:01:00 PST",
> +             "2012-01-04 21:03:00 PST","2012-01-04 20:00:00 PST")
>> dates = as.POSIXlt(dates)
>> dates[1:4]
> [1] "2011-12-30 20:03:18" "2012-01-08 19:10:00" "2012-01-15 22:00:10"
> [4] "2012-01-26 20:01:00"
>> class(dates)
> [1] "POSIXt"  "POSIXlt"
>> ### this all looks normal so far, now for truncating
>> dates = trunc(dates,units="hours")
>> class(dates)
> [1] "POSIXt"  "POSIXlt"
>> dates
>  [1] "2011-12-30 20:00:00" "2012-01-08 19:00:00" "2012-01-15 22:00:00"
>  [4] "2012-01-26 20:00:00" "2012-01-27 21:00:00" "2012-01-19 20:00:00"
>  [7] "2012-01-31 21:00:00" "2012-01-15 21:00:00" "2012-01-04 21:00:00"
> [10] "2012-01-04 20:00:00"
>> dates[1:4]
> [1] "2011-12-30 20:00:00" NA                    NA
> [4] NA
>> # what?
>
>
> Easy cut and paste code:
>
> dates <- c("2011-12-30 20:03:18 PST","2012-01-08 19:10:00 PST",
>            "2012-01-15 22:00:10 PST","2012-01-26 20:01:00 PST",
>            "2012-01-27 21:25:01 PST","2012-01-19 20:17:31 PST",
>            "2012-01-31 21:01:00 PST","2012-01-15 21:01:00 PST",
>            "2012-01-04 21:03:00 PST","2012-01-04 20:00:00 PST")
> dates = as.POSIXlt(dates)
> dates[1:4]
> class(dates)
> dates = trunc(dates,units="hours")
> class(dates)
> dates
> dates[1:4]
>
>
> Thanks for your help!
> James
>
>        [[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] histogram fill lattice

2012-06-15 Thread David Winsemius


On Jun 15, 2012, at 5:40 AM, Powell, Jeff wrote:

Thank you for your response, I will try to be clearer.  I would like  
to fill my lattice histogram bars using a symbol rather than a  
color.  If that is not possible, then I will use hist() instead.


From trellis.par.get()
bar.fill only includes "col", so perhaps I'm out of luck?


Why didn't you say so ... here ya' go.

?grid.pattern

--
David


With regards,
Jeff

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net]
Sent: woensdag 13 juni 2012 16:40
To: Powell, Jeff
Cc: R-help@r-project.org
Subject: Re: [R] histogram fill lattice


On Jun 13, 2012, at 9:55 AM, Powell, Jeff wrote:



Dear all,

I would like to change the "fill" pattern of a histogram using
histogram() in the lattice package.  I know how to do so using  
hist(),

but would prefer to stay within lattice.

dt1 <- rnorm(100,0,1)

hist(dt1, density=3, angle=45)



I get diagonal striping.



library(lattice)
histogram(dt1,
 xlab = "Histogram of rnorm(0,1)",
 type = "count",
 breaks = 15,
 col = "grey")


I seem to remember that the diagonal hatched fills were disabled or  
not brought over to lattice from base S graphics because they were  
thought to be causing cognitive distortions[1,2]. You already seem  
to be able to specify the color of the fill, and it's easy to get  
alternating colored fills with col = c("grey","red") ,  so it's not  
entirely clear what your unsatisfied goals are.


--
David Winsemius, MD
West Hartford, CT

1] 
http://markmail.org/message/pmrrpjynrcnrwhg5?q=list:org%2Er-project%2Er-help+lattice+hatching
2] 
http://markmail.org/message/cj23tnsgsobs4mbu?q=list:org%2Er-project%2Er-help+lattice+hatching







David Winsemius, MD
West Hartford, CT

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


Re: [R] Divide all rows of a data frame by the first row.

2012-06-15 Thread Keith Weintraub
Jeff,
  Thanks. I was able to easily get rid of the do.call code and use the t( 
t(...)) construct.

In terms of the dates I have tried your suggestion and I am having an odd 
problem.

The dates I included in my previous message were only a subset of the actual 
dates I am using.

My dates were imported from Excel via RExcel. Here are 3 of them in various 
formats:

Displayed in Excel via one type of formatting: 12/1/2023, 1/1/2024, 2/1/2024

As integers from the "epoch" (which is only day based): 45261, 45292, 45323

In R imported from Excel via RExcel (a little more context here):  
  "2023-11-30 23:00:00 EST" 
  "2023-12-31 23:00:00 EST" 
  "2024-01-31 23:00:00 EST" 
  "2024-02-29 23:00:00 EST" 
  "2024-04-01 00:00:00 EDT" 
  "2024-05-01 00:00:00 EDT" 
  "2024-06-01 00:00:00 EDT" 
  "2024-07-01 00:00:00 EDT" 
  "2024-08-01 00:00:00 EDT" 
  "2024-09-01 00:00:00 EDT"
 
Notice how March 2024 is skipped. Also notice how the conversion process gives 
some dates an EDT and some an EST tag. I assume that is what you were warning 
me about timezones.

In addition when I convert using just the function year (lubridate) the result 
is:
   2023 2023 2024 2024 2024 2024 2024 2024 2024 2024

Where I was expecting (based on the Excel dates):
   2023 2024 2024 2024 2024 2024 2024 2024 2024 2024

Any help on how to do this the "right" way would be greatly appreciated.

I know that Excel has "issues" with regards to dates and there may even be 
issues using RExcel for this type of conversion.

Any help would is appreciated.

Thanks again,
KW

PS Here is a dput of the last 10 dates:

someDates<-structure(c(1701403200, 1704081600, 170676, 1709265600, 
1711944000, 
1714536000, 1717214400, 1719806400, 1722484800, 1725163200), class = 
c("POSIXct", 
"POSIXt"))


On Jun 15, 2012, at 1:48 AM, Jeff Newmiller wrote:

> a) Avoid mixing Date objects and POSIXt objects. The timezones will mess you 
> up in the conversions. Just eliminate the as.Date conversion entirely.
> 
> b) By the time you reach the do.call function call, amortsByYears is a 
> matrix. While a data.frame is a special kind of list, a matrix is not. Hence, 
> the error message.
> 
> You can replace the do.call with
> 
> t( t( amortsByYears )/amortsByYears[1,] )
> 
> which is rather more efficient than do.call anyway.
> ---
> 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.
> 
> Keith Weintraub  wrote:
> 
>> Folks,
>> 
>> I call the function calcAmorts like so:
>>  calcAmorts(prevAm, amort, myDates)
>> 
>> Note that I use the package lubridate.
>> 
>> The last line where do.call is called to first divide all the rows by
>> the first row and then rbind gives the following error:
>> Error in do.call("rbind", apply(amortsByYears, 1, "/", amortsByYears[, 
>> : 
>>   second argument must be a list
>> 
>> By contrast if I run 
>> do.call('rbind', apply(amortsByYears, 1, "/", amortsByYears[,1]))
>> 
>> On its own with any kind of numeric data.frame the call works fine.
>> That is it divides every row in the data.frame by the first row.
>> 
>> Thanks so much for your time,
>> KW
>> 
>> _
>> My data:
>> 
>> myDates<-structure(c(1338523200, 1341115200, 1343793600, 1346472000,
>> 1349064000, 
>> 1351742400, 1354334400, 1357012800, 1359691200, 1362110400, 1364788800,
>> 
>> 1367380800, 1370059200, 1372651200, 1375329600, 1378008000, 138060,
>> 
>> 1383278400, 1385870400), class = c("POSIXct", "POSIXt"))
>> 
>> 
>> 
>> amort<-structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0333, 
>> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0333, 
>> 0, 0, 0.0333, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
>> 0, 0, 0.0333, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
>> 0, 0, 0.0333, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
>> 0.0357142857142857, 
>> 0, 0, 0, 0, 0.0333, 0, 0, 0.0333, 0, 0, 0.0357142857142857, 0, 
>> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0333, 0, 0, 0, 0, 
>> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0333, 0, 0, 0, 0, 
>> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0357142857142857, 0, 0, 0, 0, 0.0333, 
>> 0, 0, 0.0333, 0, 0, 0.0357142857142857, 0, 0, 0, 0, 0, 0, 0, 
>> 0, 0, 0, 0, 0, 0, 0, 0, 0.0333, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
>> 0, 0, 0, 0), .Dim = c(10L, 19L))
>> 
>> prevAm<-c(0, 0, 0, 0.0666, 0, 0.0666, 0.0666, 0, 0, 0)
>> 
>> calcAmorts<-function(prevAmort,  currAmorts, dates) {
>>  yrs<-year(as.Date(dates))
>>  currAmorts<-data.frame(yrs,t(currAmorts))
>> amortsByYears<-aggregate(x = currAmorts, by = list(yrs), FUN =
>> "sum")[,-

Re: [R] R: Securities earning covariance

2012-06-15 Thread R. Michael Weylandt
I'm somewhat confused:

i) What does this have to do with your subject line?

ii) There does not exist -- to my knowledge -- an implementation of R
which runs on the JVM.

iii) Have you simply looked into R's native parallel computing
options? That seems to be (maybe?) what you are trying to do.

Incidentally, thanks to the in-memory model, it is possible to spawn
multiple R processes which use the same package libraries [the package
is the thing in the library, which is tied to the filesystem] on the
same machine (I'm thinking real, but this shouldn't be a problem with
a reasonable VM setup either)

Michael

On Fri, Jun 15, 2012 at 3:05 AM,   wrote:
>
> Good morning.
>
> I have a real fuzzy question to ask; we have a calculation engine which
> is composed by n virtual machines each of them with a jvm 2GB of memory
> on Linux Red Hat each of them with the "R" package which comes along
> with the Red Hat Linux distribution.
> We have now to increase the number of "nodes" trying to avoid to use new
> virtual or physical machines. So my question is: is it possible to
> install multiple jvm on the same machine each of them with its
> independent instance of R ?
> Should I "duplicate" the initial R installation to get different
> instances with different libraries ? Is it enough or even in this case
> the different instances "share" something so they are not really "fully
> independent" ?
> Thanks so much for you help
>
> Angelo Linardi
>
> ** Le e-mail provenienti dalla Banca d'Italia sono trasmesse in buona fede e 
> non
> comportano alcun vincolo ne' creano obblighi per la Banca stessa, salvo che 
> cio' non
> sia espressamente previsto da un accordo scritto.
> Questa e-mail e' confidenziale. Qualora l'avesse ricevuta per errore, La 
> preghiamo di
> comunicarne via e-mail la ricezione al mittente e di distruggerne il 
> contenuto. La
> informiamo inoltre che l'utilizzo non autorizzato del messaggio o dei suoi 
> allegati
> potrebbe costituire reato. Grazie per la collaborazione.
> -- E-mails from the Bank of Italy are sent in good faith but they are neither 
> binding on
> the Bank nor to be understood as creating any obligation on its part except 
> where
> provided for in a written agreement. This e-mail is confidential. If you have 
> received it
> by mistake, please inform the sender by reply e-mail and delete it from your 
> system.
> Please also note that the unauthorized disclosure or use of the message or any
> attachments could be an offence. Thank you for your cooperation. **
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] help in sentDetect() fuction

2012-06-15 Thread R. Michael Weylandt
On Fri, Jun 15, 2012 at 1:48 AM, raishilpa  wrote:
> hello,
> I am using the following code
>
>>s<-"I am very happy, excited, and optimistic.I am very scared, annoyed, and
> irritated.Iraq’s political crisis entered its second week one step closer to
> the potential.dissolution of the government, with a call for elections by a
> vital coalition partner and a suicide attack that extended the spate of
> violence. that has followed the withdrawal.of U.S. troops"
>
>> sentDetect(s, language = "en")
> #getting output in the following way
>
> [1] "I am very happy, excited, and optimistic.I am very scared, annoyed, and
> irritated.Iraq’s "
> [2] "political crisis entered its second week one step closer to the
> potential.dissolution "
> [3] "of the government, with a call for elections by a vital coalition
> partner and a suicide attack that extended the spate of violence. "
> [4] "that has followed the withdrawal.of "
> [5] "U.S. troops"
>
> I want output in some different way...since sentences [1] [2] [3] [4] [5]
> are from " s" I want output in following way
>
> [1] -"I am very happy, excited, and optimistic.I am very scared, annoyed,
> and irritated.Iraq’s political crisis entered its second week one step
> closer to the potential.dissolution of the government, with a call for
> elections by a vital coalition partner and a suicide attack that extended
> the spate of violence. that has followed the withdrawal.of U.S. troops"
> [1,1]  "I am very happy, excited, and optimistic.I am very scared, annoyed,
> and irritated.Iraq’s "
> [1,2]  "political crisis entered its second week one step closer to the
> potential.dissolution "
> [1,3] "of the government, with a call for elections by a vital coalition
> partner and a suicide attack that extended the spate of violence. "
> [1,4] "that has followed the withdrawal.of "
> [1,5] "U.S. troops"
>
> or in some other way that you guys can suggest me...but remember one thing-
> under the main paragraph all the sentences should come so that it become
> easy to recognize the parent para of the sub-sentences.

Unfortunately, the structure you're asking for doesn't immediately
lend it self to one of R's main data-structures. Where I'd think of
wedging this in would be in a print method, but I'm not sure if that
fits your particular use case.

Something like this [un-tested]:

print.sentiment <- function(x, ...){
   for(i in NROW(x)){
  cat(paste(x[i,]), "\n")
  print(x[i,])
   }
}

with appropriate constructor.

Hopefully this will get you started,
Michael

>
> thanking you in anticipation
> Shilpa Rai
> MSc IIT Bombay
> .
>
>
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/help-in-sentDetect-fuction-tp4633462.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] R under JVM

2012-06-15 Thread ANGELO.LINARDI
Dear all,

 

first of all I apologize for not having changed the object.

I just re-used an old email I sent some time ago.

The let us go into the question.

Our architecture is the following:

 

A (set of) java programs running under a jvm that passes data and instructions 
to an R instance via RNI 

and at the end of the process extracts calculated data from R.

 

 

The question is: can I define a new JVM with a new instance of R on the same 
machine ?

How can I spawn multiple R independent instances using the same package 
libraries ? 

Should I instead "duplicate" the initial R installation to get different

instances with different libraries ? Is it enough or even in this case

the different instances "share" something so they are not really "fully

independent" ?

 

Thanks again

 

Angelo

-Messaggio originale-
Da: R. Michael Weylandt [mailto:michael.weyla...@gmail.com] 
Inviato: venerdì 15 giugno 2012 16.16
A: LINARDI ANGELO
Cc: r-help@r-project.org
Oggetto: Re: [R] R: Securities earning covariance

 

I'm somewhat confused:

 

i) What does this have to do with your subject line?

 

ii) There does not exist -- to my knowledge -- an implementation of R

which runs on the JVM.

 

iii) Have you simply looked into R's native parallel computing

options? That seems to be (maybe?) what you are trying to do.

 

Incidentally, thanks to the in-memory model, it is possible to spawn

multiple R processes which use the same package libraries [the package

is the thing in the library, which is tied to the filesystem] on the

same machine (I'm thinking real, but this shouldn't be a problem with

a reasonable VM setup either)

 

Michael

 

On Fri, Jun 15, 2012 at 3:05 AM,   wrote:

> 

> Good morning.

> 

> I have a real fuzzy question to ask; we have a calculation engine which

> is composed by n virtual machines each of them with a jvm 2GB of memory

> on Linux Red Hat each of them with the "R" package which comes along

> with the Red Hat Linux distribution.

> We have now to increase the number of "nodes" trying to avoid to use new

> virtual or physical machines. So my question is: is it possible to

> install multiple jvm on the same machine each of them with its

> independent instance of R ?

> Should I "duplicate" the initial R installation to get different

> instances with different libraries ? Is it enough or even in this case

> the different instances "share" something so they are not really "fully

> independent" ?

> Thanks so much for you help

> 

> Angelo Linardi

> 

> ** Le e-mail provenienti dalla Banca d'Italia sono trasmesse in buona fede e 
> non

> comportano alcun vincolo ne' creano obblighi per la Banca stessa, salvo che 
> cio' non

> sia espressamente previsto da un accordo scritto.

> Questa e-mail e' confidenziale. Qualora l'avesse ricevuta per errore, La 
> preghiamo di

> comunicarne via e-mail la ricezione al mittente e di distruggerne il 
> contenuto. La

> informiamo inoltre che l'utilizzo non autorizzato del messaggio o dei suoi 
> allegati

> potrebbe costituire reato. Grazie per la collaborazione.

> -- E-mails from the Bank of Italy are sent in good faith but they are neither 
> binding on

> the Bank nor to be understood as creating any obligation on its part except 
> where

> provided for in a written agreement. This e-mail is confidential. If you have 
> received it

> by mistake, please inform the sender by reply e-mail and delete it from your 
> system.

> Please also note that the unauthorized disclosure or use of the message or any

> attachments could be an offence. Thank you for your cooperation. **

> 

> __

> R-help@r-project.org mailing list

> https://stat.ethz.ch/mailman/listinfo/r-help

> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html

> and provide commented, minimal, self-contained, reproducible code.


** Le e-mail provenienti dalla Banca d'Italia sono trasmesse in buona fede e 
non 
comportano alcun vincolo ne' creano obblighi per la Banca stessa, salvo che 
cio' non 
sia espressamente previsto da un accordo scritto.
Questa e-mail e' confidenziale. Qualora l'avesse ricevuta per errore, La 
preghiamo di 
comunicarne via e-mail la ricezione al mittente e di distruggerne il contenuto. 
La 
informiamo inoltre che l'utilizzo non autorizzato del messaggio o dei suoi 
allegati 
potrebbe costituire reato. Grazie per la collaborazione.
-- E-mails from the Bank of Italy are sent in good faith but they are neither 
binding on 
the Bank nor to be understood as creating any obligation on its part except 
where 
provided for in a written agreement. This e-mail is confidential. If you have 
received it 
by mistake, please inform the sender by reply e-mail and delete it from your 
system. 
Please also note that the unauthorized disclosure or use of the message or any 
attachments could be an offence. Thank you for your cooperation. **
[[alternative HTML version dele

Re: [R] spelling correction using R

2012-06-15 Thread R. Michael Weylandt
On Fri, Jun 15, 2012 at 8:24 AM, shilpa rai  wrote:
> thanks to all :)

Unless I suddenly became plural, I believe you meant to hit reply-all.

>
> I have found a code on nets , please visit the following link
>
> http://anrprogrammer.wordpress.com/2012/02/08/a-spell-checker-in-r/
>
> when I am running this code I am getting following error
>
>  Correct("speling", dtm = counts)
> Error in out[i] <- paste(word[-i], collapse = "") : object of type 'closure'
> is not subsettable

Running the code on that link, I don't get that particular error, but
one that's perhaps similar. The problem with the linked code is that
it doesn't define out before using it.

I might suggest you actually read the entire page -- the fix is
already posted there.

Michael

>
> I am unable to remove the error...can anyone help in removing the error...?
>
>
> On Fri, Jun 15, 2012 at 6:40 PM, R. Michael Weylandt
>  wrote:
>>
>> Grammar is quite complicated, but for spelling you might try this
>> wonderful article by Peter Norvig:
>>
>> http://norvig.com/spell-correct.html
>>
>> Michael
>>
>> On Fri, Jun 15, 2012 at 12:10 AM, raishilpa 
>> wrote:
>> > hello
>> >
>> > I want a code which can correct the spelling mistakes  as well as
>> > grammatical mistakes in the sentences...that is if I am writing
>> > following
>> > sentence:
>> >
>> > I want too meet my frnd bt due to hectic shcedule I cant
>> >
>> > I want output in following way:
>> >
>> > I want to met my friend but due to hectic schedule I can't.
>> >
>> > Thanks in advance
>> >
>> > Shilpa Rai

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


Re: [R] Looking for Speed in a Toy Simulation Example

2012-06-15 Thread R. Michael Weylandt
As of recent versions of R, you can actually go for what are
officially recognized as "ultimate speed" functions .rowSums() and
friends.

You might also use the compiler() package to byte-compile that inner
loop. [The function going to sapply] It won't be massive, but perhaps
another 3 or 4x

Michael

On Fri, Jun 15, 2012 at 8:13 AM, Simon Knos
 wrote:
> Rui, thank you very much.
>
> I keep forgetting about the rowSum and friends. (precalculating the
> powers just slipped my attention).
>
> And, yes, a factor of will of course do. Do you see a further
> improvement in this case?
>
>
> Best,
>
> Simon
>
> On Fri, Jun 15, 2012 at 12:25 PM, Rui Barradas  wrote:
>> Hello,
>>
>> Will a factor of 4 do?
>> This is variant 3, revised.
>>
>> #
>> ## Variant 3.b                                 ##
>>
>> #
>>
>>
>> ## Initialize matrix to hold results
>> singlecolor <- matrix(NA, simlength, noplayer)
>>
>> ## construct the deck to sample from
>> basedeck <- rep(10^(1:4), 13)
>> ## Pre-compute this vector, don't re-compute inside a loop
>> pow10x5 <- 5*10^(1:4)
>>
>>
>> ## This one uses matrix(...,5) to create the individual hands
>> ## but it's created in advance
>> currentdeck <- matrix(nrow = 5, ncol=noplayer)
>>
>>
>> ## comparison by using %in%
>> set.seed()
>> system.time({
>>  singlecolor[] <- sapply(1:simlength, function(i){
>>   currentdeck[] <- sample(basedeck, decklength)
>>   colSums(currentdeck) %in% pow10x5
>>  })
>> })
>> apply(singlecolor, 2, mean)  ## colMeans()
>> mean(apply(singlecolor, 2, mean))
>>
>>
>> Note that the real speed gain is in colSums, all the rest gave me around 1.5
>> secs or 5% only.
>>
>> Rui Barradas
>>
>> Em 15-06-2012 09:40, Simon Knos escreveu:
>>>
>>> Dear List Members
>>>
>>>
>>>
>>> I used to play around with R to answer the following question by
>>> simulation (I am aware there is an easy explicit solution, but this is
>>> intended to serve as instructional example).
>>>
>>> Suppose you have a poker game with 6 players and a deck of 52 cards.
>>> Compute the empirical frequencies of having a single-suit hand. The
>>> way I want the result structured is a boolean nosimulation by noplayer
>>> matrix containing true or false
>>> depending whether the specific player was dealt a single-suit hand.
>>> The code itself is quite short: 1 line to "deal the cards", 1 line to
>>> check whether any of the six players has single-suit hand.
>>>
>>>
>>> I played around with different variants (all found below) and managed
>>> to gain some speed, however, I subjectively still find it quite slow.
>>>
>>> I would thus very much appreciate if anybody could point me to
>>> a) speed improvments in general
>>> b) speed improvements using the compiler package: At what level is
>>> cmpfun best used in this particular example?
>>>
>>>
>>>
>>>
>>> Thank you very much,
>>>
>>>
>>> Simon
>>>
>>>
>>> ###Code#
>>>
>>> noplayer <- 6
>>> simlength <- 1e+05
>>> decklength <- 5 * noplayer
>>>
>>>
>>>
>>> #
>>> ## Variant 1                                   ##
>>> #
>>>
>>>
>>>
>>> ## Initialize matrix to hold results
>>> singlecolor <- matrix(NA, simlength, noplayer)
>>> ## construct the deck to sample from
>>> basedeck <- rep(1:4, 13)
>>> ## This one uses split to create the individual hands
>>>
>>> set.seed()
>>> system.time({
>>>  for (i in 1:simlength) {
>>>    currentdeck <- split(sample(basedeck, decklength), rep(1:noplayer, 5))
>>>    singlecolor[i, ] <- sapply(currentdeck, function(inv) {
>>> length(unique(inv)) == 1 })
>>>  }
>>> })
>>> apply(singlecolor, 2, mean)
>>> mean(apply(singlecolor, 2, mean))
>>>
>>>
>>>
>>> #
>>> ## Variant 2                                   ##
>>> #
>>>
>>>
>>>
>>> ## Initialize matrix to hold results
>>> singlecolor <- matrix(NA, simlength, noplayer)
>>>
>>> ## construct the deck to sample from
>>> basedeck <- rep(10^(1:4), 13)
>>>
>>> ## This one uses matrix(...,5) to create the individual hands
>>> ## comparison by using powers of ten
>>> set.seed()
>>> system.time({
>>>  for (i in 1:simlength) {
>>>    sampledeck <- sample(basedeck, decklength)
>>>    currentdeck <- matrix(sampledeck, nrow = 5)
>>>    singlecolor[i, ] <- apply(currentdeck, 2, function(inv) {
>>> any(sum(inv) == (5 * 10^(1:4))) })
>>>  }
>>> })
>>> apply(singlecolor, 2, mean)
>>> mean(apply(singlecolor, 2, mean))
>>>
>>>
>>> #
>>> ## Variant 3                                   ##
>>> #
>>>
>>>
>>> ## Initialize matrix to hold results
>>> singlecolor <- matrix(NA, simlength, noplayer)
>>>
>>> ## construct the deck to sample from
>>> basedeck <

Re: [R] Looking for Speed in a Toy Simulation Example

2012-06-15 Thread R. Michael Weylandt
On Fri, Jun 15, 2012 at 9:48 AM, R. Michael Weylandt
 wrote:
> As of recent versions of R, you can actually go for what are
> officially recognized as "ultimate speed" functions .rowSums() and
> friends.

Sorry, perhaps that wasn't totally clear. Regarding .rowSums() note
that leading period. You pass this a slightly different set of
arguments (including matrix dims) but it goes straight down to C with
no code in R so it will be faster.

>
> You might also use the compiler() package to byte-compile that inner

Also, shouldn't have put parens after compiler.

Best,
Michael

> loop. [The function going to sapply] It won't be massive, but perhaps
> another 3 or 4x
>
> Michael
>
> On Fri, Jun 15, 2012 at 8:13 AM, Simon Knos
>  wrote:
>> Rui, thank you very much.
>>
>> I keep forgetting about the rowSum and friends. (precalculating the
>> powers just slipped my attention).
>>
>> And, yes, a factor of will of course do. Do you see a further
>> improvement in this case?
>>
>>
>> Best,
>>
>> Simon
>>
>> On Fri, Jun 15, 2012 at 12:25 PM, Rui Barradas  wrote:
>>> Hello,
>>>
>>> Will a factor of 4 do?
>>> This is variant 3, revised.
>>>
>>> #
>>> ## Variant 3.b                                 ##
>>>
>>> #
>>>
>>>
>>> ## Initialize matrix to hold results
>>> singlecolor <- matrix(NA, simlength, noplayer)
>>>
>>> ## construct the deck to sample from
>>> basedeck <- rep(10^(1:4), 13)
>>> ## Pre-compute this vector, don't re-compute inside a loop
>>> pow10x5 <- 5*10^(1:4)
>>>
>>>
>>> ## This one uses matrix(...,5) to create the individual hands
>>> ## but it's created in advance
>>> currentdeck <- matrix(nrow = 5, ncol=noplayer)
>>>
>>>
>>> ## comparison by using %in%
>>> set.seed()
>>> system.time({
>>>  singlecolor[] <- sapply(1:simlength, function(i){
>>>   currentdeck[] <- sample(basedeck, decklength)
>>>   colSums(currentdeck) %in% pow10x5
>>>  })
>>> })
>>> apply(singlecolor, 2, mean)  ## colMeans()
>>> mean(apply(singlecolor, 2, mean))
>>>
>>>
>>> Note that the real speed gain is in colSums, all the rest gave me around 1.5
>>> secs or 5% only.
>>>
>>> Rui Barradas
>>>
>>> Em 15-06-2012 09:40, Simon Knos escreveu:

 Dear List Members



 I used to play around with R to answer the following question by
 simulation (I am aware there is an easy explicit solution, but this is
 intended to serve as instructional example).

 Suppose you have a poker game with 6 players and a deck of 52 cards.
 Compute the empirical frequencies of having a single-suit hand. The
 way I want the result structured is a boolean nosimulation by noplayer
 matrix containing true or false
 depending whether the specific player was dealt a single-suit hand.
 The code itself is quite short: 1 line to "deal the cards", 1 line to
 check whether any of the six players has single-suit hand.


 I played around with different variants (all found below) and managed
 to gain some speed, however, I subjectively still find it quite slow.

 I would thus very much appreciate if anybody could point me to
 a) speed improvments in general
 b) speed improvements using the compiler package: At what level is
 cmpfun best used in this particular example?




 Thank you very much,


 Simon


 ###Code#

 noplayer <- 6
 simlength <- 1e+05
 decklength <- 5 * noplayer



 #
 ## Variant 1                                   ##
 #



 ## Initialize matrix to hold results
 singlecolor <- matrix(NA, simlength, noplayer)
 ## construct the deck to sample from
 basedeck <- rep(1:4, 13)
 ## This one uses split to create the individual hands

 set.seed()
 system.time({
  for (i in 1:simlength) {
    currentdeck <- split(sample(basedeck, decklength), rep(1:noplayer, 5))
    singlecolor[i, ] <- sapply(currentdeck, function(inv) {
 length(unique(inv)) == 1 })
  }
 })
 apply(singlecolor, 2, mean)
 mean(apply(singlecolor, 2, mean))



 #
 ## Variant 2                                   ##
 #



 ## Initialize matrix to hold results
 singlecolor <- matrix(NA, simlength, noplayer)

 ## construct the deck to sample from
 basedeck <- rep(10^(1:4), 13)

 ## This one uses matrix(...,5) to create the individual hands
 ## comparison by using powers of ten
 set.seed()
 system.time({
  for (i in 1:simlength) {
    sampledeck <- sample(basedeck, decklength)
    currentdeck <- matrix(sampledeck

Re: [R] Divide all rows of a data frame by the first row.

2012-06-15 Thread R. Michael Weylandt
Honestly, given what a pain dates are in Excel, I might simply import
them as strings and do the conversion on the R side of things. Also,
I'd recommend you use Date objects rather than POSIXct to cut out the
unnecessary complexity of timezones, DST, etc. [See Gabor's article in
RNews 4/1 for a fuller treatment]

Best,
Michael

On Fri, Jun 15, 2012 at 9:08 AM, Keith Weintraub  wrote:
> Jeff,
>  Thanks. I was able to easily get rid of the do.call code and use the t( 
> t(...)) construct.
>
> In terms of the dates I have tried your suggestion and I am having an odd 
> problem.
>
> The dates I included in my previous message were only a subset of the actual 
> dates I am using.
>
> My dates were imported from Excel via RExcel. Here are 3 of them in various 
> formats:
>
> Displayed in Excel via one type of formatting: 12/1/2023, 1/1/2024, 2/1/2024
>
> As integers from the "epoch" (which is only day based): 45261, 45292, 45323
>
> In R imported from Excel via RExcel (a little more context here):
>  "2023-11-30 23:00:00 EST"
>  "2023-12-31 23:00:00 EST"
>  "2024-01-31 23:00:00 EST"
>  "2024-02-29 23:00:00 EST"
>  "2024-04-01 00:00:00 EDT"
>  "2024-05-01 00:00:00 EDT"
>  "2024-06-01 00:00:00 EDT"
>  "2024-07-01 00:00:00 EDT"
>  "2024-08-01 00:00:00 EDT"
>  "2024-09-01 00:00:00 EDT"
>
> Notice how March 2024 is skipped. Also notice how the conversion process 
> gives some dates an EDT and some an EST tag. I assume that is what you were 
> warning me about timezones.
>
> In addition when I convert using just the function year (lubridate) the 
> result is:
>   2023 2023 2024 2024 2024 2024 2024 2024 2024 2024
>
> Where I was expecting (based on the Excel dates):
>   2023 2024 2024 2024 2024 2024 2024 2024 2024 2024
>
> Any help on how to do this the "right" way would be greatly appreciated.
>
> I know that Excel has "issues" with regards to dates and there may even be 
> issues using RExcel for this type of conversion.
>
> Any help would is appreciated.
>
> Thanks again,
> KW
>
> PS Here is a dput of the last 10 dates:
>
> someDates<-structure(c(1701403200, 1704081600, 170676, 1709265600, 
> 1711944000,
> 1714536000, 1717214400, 1719806400, 1722484800, 1725163200), class = 
> c("POSIXct",
> "POSIXt"))
>
>
> On Jun 15, 2012, at 1:48 AM, Jeff Newmiller wrote:
>
>> a) Avoid mixing Date objects and POSIXt objects. The timezones will mess you 
>> up in the conversions. Just eliminate the as.Date conversion entirely.
>>
>> b) By the time you reach the do.call function call, amortsByYears is a 
>> matrix. While a data.frame is a special kind of list, a matrix is not. 
>> Hence, the error message.
>>
>> You can replace the do.call with
>>
>> t( t( amortsByYears )/amortsByYears[1,] )
>>
>> which is rather more efficient than do.call anyway.
>> ---
>> Jeff Newmiller                        The     .       .  Go Live...
>> DCN:        Basics: ##.#.       ##.#.  Live Go...
>>                                      Live:   OO#.. Dead: OO#..  Playing
>> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
>> /Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
>> ---
>> Sent from my phone. Please excuse my brevity.
>>
>> Keith Weintraub  wrote:
>>
>>> Folks,
>>>
>>> I call the function calcAmorts like so:
>>>      calcAmorts(prevAm, amort, myDates)
>>>
>>> Note that I use the package lubridate.
>>>
>>> The last line where do.call is called to first divide all the rows by
>>> the first row and then rbind gives the following error:
>>> Error in do.call("rbind", apply(amortsByYears, 1, "/", amortsByYears[,
>>> :
>>>   second argument must be a list
>>>
>>> By contrast if I run
>>> do.call('rbind', apply(amortsByYears, 1, "/", amortsByYears[,1]))
>>>
>>> On its own with any kind of numeric data.frame the call works fine.
>>> That is it divides every row in the data.frame by the first row.
>>>
>>> Thanks so much for your time,
>>> KW
>>>
>>> _
>>> My data:
>>>
>>> myDates<-structure(c(1338523200, 1341115200, 1343793600, 1346472000,
>>> 1349064000,
>>> 1351742400, 1354334400, 1357012800, 1359691200, 1362110400, 1364788800,
>>>
>>> 1367380800, 1370059200, 1372651200, 1375329600, 1378008000, 138060,
>>>
>>> 1383278400, 1385870400), class = c("POSIXct", "POSIXt"))
>>>
>>>
>>>
>>> amort<-structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0333,
>>> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0333,
>>> 0, 0, 0.0333, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
>>> 0, 0, 0.0333, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
>>> 0, 0, 0.0333, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
>>> 0.0357142857142857,
>>> 0, 0, 0, 0, 0.0333, 0, 0, 0.0333, 0, 0, 0.0357142857142857, 0,
>>> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0333, 0, 0, 0, 0,
>>> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0333, 0, 0, 0, 0,
>>> 0, 0, 0, 0, 

Re: [R] Rename output file in Swaeve and Tex

2012-06-15 Thread Yihui Xie
I do not think it is possible with the 'R CMD Sweave' interface, but
you can always use the 'R -e' approach, e.g. R -e 'Sweave("foo.Rnw");
file.rename("foo.tex", "foo-bar.tex"); tools::texi2dvi('foo-bar.tex')'
(not tested, but idea is there)

To make this more natural, you can try the knitr package which allows
you to specify the output filename, e.g. library(knitr);
knit('foo.Rnw', output = 'foo-bar.tex')

Regards,
Yihui
--
Yihui Xie 
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA


On Fri, Jun 15, 2012 at 4:40 AM, Manish Gupta  wrote:
> HI,
>
> I am working on R and Latex.
>
> R CMD Sweave Test.Rnw  (this generates Rnw.Tex file )
>
> R CMD pdflatex Test.tex  (It generated Test.pdf)
>
> Is there any way to change the name of of output file (Test.pdf).  I want it
> to pass the output file name as parameter.
>
> R CMD Sweave Test.Rnw  Output_File
>
> R CMD pdflatex Output_File.tex
>
> So output file name will be Output_File.pdf
>
> Regards
>

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


Re: [R] R under JVM

2012-06-15 Thread R. Michael Weylandt
On Fri, Jun 15, 2012 at 9:36 AM,   wrote:
> Dear all,
>
>
>
> first of all I apologize for not having changed the object.

Subject you mean. Linguistically, it is perhaps a little arbitrary,
but that's the name the email gods chose long ago and I tend to agree
with them. I tend to think more "subject" as in "subject matter" than
"subject of a sentence" here.

>
> I just re-used an old email I sent some time ago.
>
> The let us go into the question.
>
> Our architecture is the following:
>
>

This photo didn't make it past the mailing list servers [which also
don't like HTML] Going on what you sent me privately though, I'm
still not sure why you have R in the JVM box or why the JVM box is so
much bigger than the Java box. Pending correction [as often happens],
I'm pretty sure that R on the JVM just doesn't exit. I think that
would require almost an entire rewrite of the system.

If I understand your architecture correctly, I'd imagine something
more like this: [ASCII art time!]

---  JVM ---

     JAVA  

  JDBC
   |
   |
Algoritmo
   |
 JAVA 
---  JVM ---
  |
   RNI
  |
 R

and you want something like

---  JVM ---

     JAVA  

  JDBC
   |
   |
Algoritmo
   |
 JAVA 
---  JVM ---
  |
   RNI
   /  |  \
 R  R R

I'd really like to draw RNI right on the JVM border, but my skills are
rather limited in this particular undertaking.

>
> A (set of) java programs running under a jvm that passes data and 
> instructions to an R instance via RNI
>
> and at the end of the process extracts calculated data from R.
>
>
>
>
>
> The question is: can I define a new JVM with a new instance of R on the same 
> machine ?

See remark above regarding R. It should be possible to have multiple
JVMs on a single server.

>
> How can I spawn multiple R independent instances using the same package 
> libraries ?

If you are using the regular (CRAN-build) interpreter [though on RHEL
you might not be -- I don't know who does that build, but it shouldn't
be relevant] simply starting two processes "the old fashioned way"
_does_ create independent instances. As I said before, everything is
"in-memory" for R, so as long as you don't write to the package
library or the data sets, they will be totally independent. (Even the
RNGs will be independent by default)

>
> Should I instead "duplicate" the initial R installation to get different
>
> instances with different libraries ? Is it enough or even in this case
>
> the different instances "share" something so they are not really "fully
>
> independent" ?

As noted above, they both read the same package library but because
they are in-memory, they should be independent unless you go out of
your way to mess things up.

Incidentally, you may wish to look at Simon Urbanek's fantastic work
on rJava which allows both-way connectivity and probably places nicer
with R than proprietary windows projects.

Best,
Michael

>
>
>
> Thanks again
>
>
>
> Angelo
>
> -Messaggio originale-
> Da: R. Michael Weylandt [mailto:michael.weyla...@gmail.com]
> Inviato: venerdě 15 giugno 2012 16.16
> A: LINARDI ANGELO
> Cc: r-help@r-project.org
> Oggetto: Re: [R] R: Securities earning covariance
>
>
>
> I'm somewhat confused:
>
>
>
> i) What does this have to do with your subject line?
>
>
>
> ii) There does not exist -- to my knowledge -- an implementation of R
>
> which runs on the JVM.
>
>
>
> iii) Have you simply looked into R's native parallel computing
>
> options? That seems to be (maybe?) what you are trying to do.
>
>
>
> Incidentally, thanks to the in-memory model, it is possible to spawn
>
> multiple R processes which use the same package libraries [the package
>
> is the thing in the library, which is tied to the filesystem] on the
>
> same machine (I'm thinking real, but this shouldn't be a problem with
>
> a reasonable VM setup either)
>
>
>
> Michael
>
>
>
> On Fri, Jun 15, 2012 at 3:05 AM,   wrote:
>
>>
>
>> Good morning.
>
>>
>
>> I have a real fuzzy question to ask; we have a calculation engine which
>
>> is composed by n virtual machines each of them with a jvm 2GB of memory
>
>> on Linux Red Hat each of them with the "R" package which comes along
>
>> with the Red Hat Linux distribution.
>
>> We have now to increase the number of "nodes" trying to avoid to use new
>
>> virtual or physical machines. So my question is: is it possible to
>
>> install multiple jvm on the same machine each of them with its
>
>> independent instance of R ?
>
>> Should I "duplicate" the initial R installation to get different
>
>> instances with different libraries ? Is it enough or even in this case
>
>> the different instances "share" something so they are not really "fully
>
>> independent" ?
>
>> Thanks so much for you help
>
>>
>
>> Angelo Lina

[R] Replication of linear model/autoregressive model

2012-06-15 Thread Al Ehan
Hi,

I would like to make a replication of 10 of a linear, first order
Autoregressive function, with respect to the replication of its innovation,
e. for example:

#where e is a random variables of innovation (from GEV distribution-that
explains the rgev)
#by using the arima.sim model from TSA package, I try to produce Y
replicates, with respect to every replicates of e,
#means for e[,1], I want to have say Y[,1].

The code:

e=replicate(10,rgev(20,xi=0.2,mu= 931.1512,sigma= 168.2702 ))
Y=replicate(10,ts(arima.sim(list(ar=0.775),n=20,innov=e,start.innov=e)))

what I get is the same random variables for every replicates of Y.

Can somebody help me in giving tips for the right way to simulate 'Y'
replicates, with respect to the 'e' sets generated ?

Thanks in advance,
aen

Below is the result for both e and Y

e is:
   [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]
 [,8]  [,9] [,10]
 [1,] 1004.6556 1052.4383 1182.9386  740.7879  917.9408 1068.8516  939.3510
 767.9687 1404.9391  887.2097
 [2,]  976.1445 2065.3058 1375.2125  771.4417  813.0629  752.6230  855.2689
 783.9922 1040.5202 1021.9163
 [3,]  806.4278 1093.6128 1105.2453  961.5645 2680.4879 1223.3578 1016.8091
1328.9994 1069.0436  770.2141
 [4,]  941.7239  835.8723 1281.5915  758.4810 1157.0755  989.6987 1374.7398
 819.5419 2145.2202  912.0083
 [5,] 1278.2288 1230.8805  950.0978 1020.4950 1176.2052  917.6511  938.0180
1134.2910  948.9680 1239.7596
 [6,] 1370.5071 1152.9871  918.1371 1206.5982 1031.8577 1055.5165 1058.2840
 992.4400 1385.1229  860.9707
 [7,]  792.2280 1088.3310  843.1889  850.0649 1090.4600 1063.3509  849.8213
 857.7559  918.9895  924.3551
 [8,] 1342.4464  986.0477 1150.8336  876.8476  736.7059  874.5117  791.1349
1221.8736 1274.5753 1251.5058
 [9,]  855.5112  679.0765  896.8450 1035.9713  887.1466  966.9135 1097.9867
 698.7444 1037.1916  925.6284
[10,]  896.1308 1390.8897 1226.0070  940.0661 1122.1520 1282.2764 1100.4923
1028.7810  769.0136 1164.6884
[11,] 1395.6821 1714.6703 1120.4880  957.8550  823.9834  890.8857  688.2862
1337.0698 1068.7425  979.0459
[12,] 1000.8848  965.1944 1312.5296  780.4713  797.3911 1258.8812  768.1990
 780.7888 1308. 1429.7170
[13,]  923.6432 1736.6128 1744.1737  911.3581  986.5247  840.6579 1094.8875
1088.8576 1571.3999 1534.5975
[14,] 1436.3669 1256.7590  835.3184 1233.7610  799.4020  906.7561  858.1808
 774.7084  909.1261 1080.8908
[15,] 1013.2007 1705.9792 1560.2684 1214.5330 1075.3175  946.8204 1002.4946
1096.0830 1254.5292 1186.1904
[16,] 1234.8287 1127.0824  979.2170  867.8832 1326.6990  723.8658 1025.6396
 707.3958 1033.7781 1182.6379
[17,] 1289.7771 1083.7075  854.0004 1077.5405 1646.2762  743.7637 1132.9710
1004.6940  993.6281 1062.2983
[18,]  985.4911 1023.1982 1115.5055 1274.4555  882.3684  949.3805 1092.2195
2973.9311  949.8960 1314.0438
[19,]  965.2564  955.7152 1333.8170 1216.1322  758.6732 1224.0608  830.8886
1463.0854 1073.4099  865.2163
[20,]  939.8106  840.0662  911.5299  678.0191  766.2572 1119.6836  719.0916
1068.7629  891.5782 1195.1606


Y:.
  [,1] [,2] [,3] [,4] [,5] [,6] [,7]
[,8] [,9][,10]
 [1,] 5021.075 5021.075 5021.075 5021.075 5021.075 5021.075 5021.075
5021.075 5021.075 5021.075
 [2,] 4867.478 4867.478 4867.478 4867.478 4867.478 4867.478 4867.478
4867.478 4867.478 4867.478
 [3,] 4578.723 4578.723 4578.723 4578.723 4578.723 4578.723 4578.723
4578.723 4578.723 4578.723
 [4,] 4490.234 4490.234 4490.234 4490.234 4490.234 4490.234 4490.234
4490.234 4490.234 4490.234
 [5,] 4758.160 4758.160 4758.160 4758.160 4758.160 4758.160 4758.160
4758.160 4758.160 4758.160
 [6,] 5058.081 5058.081 5058.081 5058.081 5058.081 5058.081 5058.081
5058.081 5058.081 5058.081
 [7,] 4712.241 4712.241 4712.241 4712.241 4712.241 4712.241 4712.241
4712.241 4712.241 4712.241
 [8,] 4994.433 4994.433 4994.433 4994.433 4994.433 4994.433 4994.433
4994.433 4994.433 4994.433
 [9,] 4726.197 4726.197 4726.197 4726.197 4726.197 4726.197 4726.197
4726.197 4726.197 4726.197
[10,] 4558.934 4558.934 4558.934 4558.934 4558.934 4558.934 4558.934
4558.934 4558.934 4558.934
[11,] 4928.856 4928.856 4928.856 4928.856 4928.856 4928.856 4928.856
4928.856 4928.856 4928.856
[12,] 4820.748 4820.748 4820.748 4820.748 4820.748 4820.748 4820.748
4820.748 4820.748 4820.748
[13,] 4659.723 4659.723 4659.723 4659.723 4659.723 4659.723 4659.723
4659.723 4659.723 4659.723
[14,] 5047.652 5047.652 5047.652 5047.652 5047.652 5047.652 5047.652
5047.652 5047.652 5047.652
[15,] 4925.131 4925.131 4925.131 4925.131 4925.131 4925.131 4925.131
4925.131 4925.131 4925.131
[16,] 5051.805 5051.805 5051.805 5051.805 5051.805 5051.805 5051.805
5051.805 5051.805 5051.805
[17,] 5204.926 5204.926 5204.926 5204.926 5204.926 5204.926 5204.926
5204.926 5204.926 5204.926
[18,] 5019.309 5019.309 5019.309 5019.309 5019.309 5019.309 5019.309
5019.309 5019.309 5019.309
[19,] 4855.221 4855.221 4855.221 4855.221 4855.221 4855.221 4855.221
4855.221 4855.221 4855.221
[20,] 4702.607 4702.607 4

Re: [R] wgcna

2012-06-15 Thread Ingezz
Dear Peter,

I am trying to apply the WGCNA meta-analysis for two (or more) microarray
datasets-tutorial to my own data. 

> mp=modulePreservation(multiExpr,multiColor,referenceNetworks=1,verbose=3,networkType="signed",
>  
> nPermutations=30,maxGoldModuleSize=100,maxModuleSize=400)

However, the error I am getting is: 

Error in .checkExpr(multiData, verbose, indent) : 
  The submitted 'multiExpr' data contain genes or samples
   with zero variance or excessive counts of missing entries.
   Please use the function goodSamplesGenes on each set to filter out the
problematic
   genes and samples before running modulePreservation.

Seems pretty clear, but applying goodSamplesGenes function results in no
exclusions for both arrays. 

>  GM2 <- goodSamplesGenes(M2, minFraction = 1/2, minNSamples =8, minNGenes
> =20) 

What could be the issue here? Should I increase the stringency? What
stringency should be used with goodsamplegenes for modulepreservation to
work? 

Many thanks in advance! 

Kind regards,
Inge 

--
View this message in context: 
http://r.789695.n4.nabble.com/wgcna-tp3649354p4633514.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] R start screen

2012-06-15 Thread Rossenu, Stefaan

After installation of R on windows machine and starting the R program, I only 
see the R-console but not the RGUI screen... Do I need to re-install or change 
some settings?

Tx!

Notice:  This e-mail message, together with any attachme...{{dropped:14}}

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


Re: [R] plot cdf

2012-06-15 Thread MSousa
Thanks

--
View this message in context: 
http://r.789695.n4.nabble.com/plot-cdf-tp4633349p4633515.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] Multivariate Normal and loops

2012-06-15 Thread Cassie
Hi,
i'm not english and i'm not very familiar to R, and i'm asking if you can
help me.
I'm wondering how to create a multivariate normal an then repeat this for a
sample of T=1000, and the save this result.
Thank you very much for your helping

--
View this message in context: 
http://r.789695.n4.nabble.com/Multivariate-Normal-and-loops-tp4633504.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] Binary Quadratic Opt?

2012-06-15 Thread Anup Bhatkar
Hello,

I have to solve Binary Quadratic Optimization problem i.e the objective 
function is quadratic, constraints are linear and variable are binary. I 
checked the "quadprog" package but it does not seem to be right choice for the 
problem.

Can any one suggest what would be the best package to solve the Binary 
Quadratic opt.

Thanks in advance

Regards
Khris.

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

2012-06-15 Thread Lekgatlhamang, lexi Setlhare
Dear Sarah,

Thanks very much for the assistance. I will go through what you have suggested 
to understand.

Lexi

- Original Message -
From: Sarah Goslee 
To: "Lekgatlhamang, lexi Setlhare" 
Cc: "r-help@r-project.org" 
Sent: Friday, June 15, 2012 3:58 PM
Subject: Re: [R] Help with Sequential Differencing

I missed something in my original reply:

You intended a recursive approach, I think, but that wasn't clear in
your code, and I simply repeated your actual code rather than your
intended code in my response. If that's what you want, you need
something more like:

DCred<- list()
DCred[[1]] <- diff(Cred, difference=1)

for(i in 2:5){
  print(DCred[[i]]<- diff(DCred[[i-1]], lag=i, difference=1))
}

Doing it with separately-named files will be much more complicated,
something like

DCred1 <- diff(Cred, difference=1)

for(i in 2:5){
  print(assign(paste("DCred", i, sep=""), diff(get(paste("DCred", i-1,
sep="")), lag=i, difference=1))
}

(both are untested)

You might also benefit from reading Intro to R, which covers list structures.

Sarah

On Fri, Jun 15, 2012 at 9:22 AM, Lekgatlhamang, lexi Setlhare
 wrote:
> Hi Sarah,
>
> Sorry for taking more of your time. I thought that before investigating the
> use of assign and paste, I should first understand the approach of using
> 'list()'. However, it seems to me that the use of list does not work very
> well, unless I have wrongly implemented your suggestion. I implemented your
> suggestion as follows:
> DCred<- list()
> for(i in 1:5){
> print(DCred[[i]]<- diff(DCred, lag=i, difference=1))
> }
> Upon execution of the loop, the following was printed out:
> list()
> list()
> list()
> list()
> list()
> After the loop I tried to access the values for DCred1, DCred2, etc but to
> no avail. See my commands and the associated output below:
>
>> DCred[[1]]
> list()
>> DCred[[i]]
> list()
>> DCred[1]
> [[1]]
> list()
> Anyway, I then calculate DCred in order to see if the regression
>
> DCred <-lm(DCred~DCred1+DCred2)
>
> will work.
> But it did not. Instead I got an error message - see below.
>
>> model<- lm(DCred~DCred[1]+DCred[2], drop.unused.levels = TRUE)
> Error in model.frame.default(formula = DCred ~ DCred[1] + DCred[2],
> drop.unused.levels = TRUE) :
>   variable lengths differ (found for 'DCred[1]')
>
> I then modified the right-hand-side of the equation, but still it did not
> work:
>
>> model <- lm(DCred~DCred[[1]])
> Error in model.frame.default(formula = DCred ~ DCred[[1]],
> drop.unused.levels = TRUE) :
>   variable lengths differ (found for 'DCred[[1]]')
>
> I will remain reading up on the assign and paste commands.
> Thanks. Lexi
> From: Sarah Goslee 
> To: "Lekgatlhamang, lexi Setlhare" 
> Cc: "r-help@r-project.org" 
> Sent: Friday, June 15, 2012 12:54 PM
> Subject: Re: [R] Help with Sequential Differencing
>
> If you really want DCred1, DCred2, etc, you'll need to use assign() and
> paste() within your loop. But he's a more R-ish way:
>
> # Differences of Cred
>
> DCred <- list()
> for(i in 1:5){
> print(DCred[[i]]<- diff(DCred, lag=i, difference=1))
>
> }
>
> DCred[[1]]
>
> Sarah
>
> On Friday, June 15, 2012, Lekgatlhamang, lexi Setlhare wrote:
>
> Dear R Users,
> Sorry for what seems like I am re-posting. When I was typing my initial
> posting, I intended to copy and paste the commands from my script, but ended
> up forgetting. I am now pasting the commands in this email.NB: Below is a
> copy of 'all' the relevant commands in my script
>
>  ##
> data<- read.table("C:\\myfiles\\from drive D\\myfiles 080208\\An R Test
> folder\\Dataset2a.csv", head=TRUE, sep=",")
> str(data)
> data
>
> # Extract the variables in data, rename and difference them
>
> Cred <- ts(data[, 2], frequency=12, start=c(2001, 1)) # Cred denotes Credit
>
> # Differences of Cred
> DCred<- diff(Cred, difference=1)
> DCred
> for(i in 1:5){
> print(DCred[i]<- diff(DCred, lag=i, difference=1))
>
> }
>
> DCred[1]
>
>  DCred[2]
>
>  DCred[3]
>
>  
> Thanks Lexi
>
>
> 
>
> To: "r-help@r-project.org" 
> Sent: Friday, June 15, 2012 11:39 AM
> Subject: Help with Sequential Differencing
>
>
>
>
> Dear R Users,
>
> I have struggled with the following problem for days, which I thought was
> simple, although it would likely be basic to most of you.
> I am working with time series data.
> In my script, my intention is to create first differences of the variables
> in the file so that I end up estimating an equation of the form:
> DCred(t) =c +
> DCred(t-1)+DCred(t-2)+...+DBoB(t)+DBoB(t-1)+DBoB(t-2)+...+Drvr(t)+Drvr(t-1)+Drvr(t-2)+...+e(t)
>
> Where D at the beginning of each variable represents 'change', for first
> difference and e(t) is the error term.
> Now I am trying to use loops to calculate 5 lagged first-differences of each
> variable in the dataset - e.g., DCred(t-1), DCred(t-2), ..., DCred(t-5).
> Example:
> # Differences of Cred
> DCred<- diff(Cred, dif

Re: [R] How to convert month-day-year to Julian data number?

2012-06-15 Thread arun
Hi,

Try:
?library(chron)
julian()

 x<-c(1:5) #month
 d<-c(10:14) #day
 y<-1970 #year



julian(x,d,y,origin=c(month=2,day=1,year=1970))


[1] -22  10  39  71 102


A.K.

- Original Message -
From: Paloma Moya 
To: "r-help@r-project.org" 
Cc: 
Sent: Friday, June 15, 2012 2:13 AM
Subject: [R] How to convert month-day-year to Julian data number?

Hello,
I am trying to convert calendar dates (Month, Day, Year) into Julian Days

Product code Bureau of Meteorology station number Month Day Year Date_mdy Date 
4102001 70014 1 1 1939 1/01/1939 1/01/1939 
4102001 70014 1 2 1939 1/02/1939 2/01/1939 
4102001 70014 1 3 1939 1/03/1939 3/01/1939 
4102001 70014 1 4 1939 1/04/1939 4/01/1939 
4102001 70014 1 5 1939 1/05/1939 5/01/1939 
4102001 70014 1 6 1939 1/06/1939 6/01/1939 
4102001 70014 1 7 1939 1/07/1939 7/01/1939 

These are the type of data that I have


I am trying to get the output as

Product code Bureau of Meteorology station number Month Day Year Date_mdy Date 
JD 
4102001 70014 1 1 1939   215421 
4102001 70014 1 2 1939   215422 
4102001 70014 1 3 1939   215423 
4102001 70014 1 4 1939   215424 
4102001 70014 1 5 1939   215425 
4102001 70014 1 6 1939   215426 
4102001 70014 1 7 1939   215427 

(these JDs are fictions) 

I have tried to apply strftime, mdy.date etc … etc…
But I couldn’t… could you help me, please?

Thank you very much,
Paloma
    [[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] Help with Sequential Differencing

2012-06-15 Thread Lekgatlhamang, lexi Setlhare
Thanks Sarah,
 
Yes, I really want DCred1, DCred2, etc. I will check and understand your answer.
I appreciate your time and help.
 
Lexi



From: Sarah Goslee 

Cc: "r-help@r-project.org"  
Sent: Friday, June 15, 2012 12:54 PM
Subject: Re: [R] Help with Sequential Differencing


If you really want DCred1, DCred2, etc, you'll need to use assign() and paste() 
within your loop. But he's a more R-ish way:
 
# Differences of Cred

DCred <- list()
for(i in 1:5){
print(DCred[[i]]<- diff(DCred, lag=i, difference=1))
 
}
  
DCred[[1]]

Sarah

On Friday, June 15, 2012, Lekgatlhamang, lexi Setlhare wrote:

Dear R Users,
>Sorry for what seems like I am re-posting. When I was typing my initial 
>posting, I intended to copy and paste the commands from my script, but ended 
>up forgetting. I am now pasting the commands in this email.NB: Below is a copy 
>of 'all' the relevant commands in my script
> 
> ##
>data<- read.table("C:\\myfiles\\from drive D\\myfiles 080208\\An R Test 
>folder\\Dataset2a.csv", head=TRUE, sep=",")
>str(data)
>data
> 
># Extract the variables in data, rename and difference them
> 
>Cred <- ts(data[, 2], frequency=12, start=c(2001, 1)) # Cred denotes Credit
> 
># Differences of Cred
>DCred<- diff(Cred, difference=1)
>DCred
>for(i in 1:5){
>print(DCred[i]<- diff(DCred, lag=i, difference=1))
> 
>}
> 
>DCred[1]
> 
> DCred[2]
> 
> DCred[3]
> 
> 
>Thanks Lexi
>
>
>
>
>To: "r-help@r-project.org" 
>Sent: Friday, June 15, 2012 11:39 AM
>Subject: Help with Sequential Differencing
>
>
>
>
>Dear R Users,
>
>I have struggled with the following problem for days, which I thought was 
>simple, although it would likely be basic to most of you.
>I am working with time series data.
>In my script, my intention is to create first differences of the variables in 
>the file so that I end up estimating an equation of the form:
>DCred(t) =c + 
>DCred(t-1)+DCred(t-2)+...+DBoB(t)+DBoB(t-1)+DBoB(t-2)+...+Drvr(t)+Drvr(t-1)+Drvr(t-2)+...+e(t)
>
>Where D at the beginning of each variable represents 'change', for first 
>difference and e(t) is the error term.
>Now I am trying to use loops to calculate 5 lagged first-differences of each 
>variable in the dataset - e.g., DCred(t-1), DCred(t-2), ..., DCred(t-5).
>Example:
># Differences of Cred
>DCred<- diff(Cred, difference=1)
>DCred
>for(i in 1:5){
>print(DCred[i]<- diff(DCred, lag=i, difference=1))
>}
>After I calculated the contemporaneous first difference DCred, this loop is 
>meant to compute the subsequent first differences of the same variable; i.e., 
>DCred(t-1) and call it DCred1, DCred(t-2) and call it DCred2, ... and 
>DCred(t-5) and call it DCred5.
>The loop works, at least I think so. But now after the loop has executed, when 
>I type DCred1[1] (which I thought would give me the first value in the series 
>for DCred(t-1)), called DCred1, I get a message "object 'DCred1' not found". 
>Similarly typing Dcred1[2] (which I thought would give the second value of 
>DCred(t-1)), ie., the second value of DCred1, gives "object DCred1[2] not 
>found", etc.
>A copy of the commands and error messages is below:
>> DCred1[1]
>Error: object 'DCred1' not found
>> DCred1[2]
>Error: object 'DCred1' not found
>
>How can I solve this problem? Thank you kindly for your time.
>       [[alternative HTML version deleted]]
>
>

-- 
Sarah Goslee
http://www.stringpage.com/
http://www.sarahgoslee.com/
http://www.functionaldiversity.org/
[[alternative HTML version deleted]]

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


Re: [R] Multivariate Normal and loops

2012-06-15 Thread R. Michael Weylandt
I don't think you need loops at all actually :-) [The main thing to
working with R vs. C is "vectorization" -- embrace it now and life
will be much better]

You could do something like this:

library(MASS) # Provides a multivariate normal distribution

mvrnorm(100, c(1,5), matrix(c(2,1,1,2), ncol = 2))

This gives you 100 samples of a multivariate normal with mean vector
(1,5) and covariance matrix

(2, 1,
 1, 2)

Feel free to tweak as necessary and type ?mvrnorm to see more documentation.

Hopefully this gets you started.

For more on vectorization, see the "Introduction to R" that comes with
R. You can get it by typing help.start() at your command prompt.

Hope this helps,
Michael

On Fri, Jun 15, 2012 at 9:26 AM, Cassie  wrote:
> Hi,
> i'm not english and i'm not very familiar to R, and i'm asking if you can
> help me.
> I'm wondering how to create a multivariate normal an then repeat this for a
> sample of T=1000, and the save this result.
> Thank you very much for your helping
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Multivariate-Normal-and-loops-tp4633504.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Divide all rows of a data frame by the first row.

2012-06-15 Thread Jeff Newmiller
Since RExcel imports date/time columns as POSIXt, sticking with that is 
probably simpler in this case.

The key I have found that makes the use of POSIXt types relatively 
straightforward is to set the TZ environment variable using Sys.setenv() to a 
value that is compatible with the timezone of the data you are planning to read 
in and work with. In particular, the "Etc/GMT+n" zones (- for Eastern 
hemisphere) that avoid daylight savings complications are usually quite 
straightforward for Excel data.

Also, avoid the use of POSIXlt unless you have a specific need for its 
capabilities. In particular I try to avoid putting POSIXlt into data frames.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

"R. Michael Weylandt"  wrote:

>Honestly, given what a pain dates are in Excel, I might simply import
>them as strings and do the conversion on the R side of things. Also,
>I'd recommend you use Date objects rather than POSIXct to cut out the
>unnecessary complexity of timezones, DST, etc. [See Gabor's article in
>RNews 4/1 for a fuller treatment]
>
>Best,
>Michael
>
>On Fri, Jun 15, 2012 at 9:08 AM, Keith Weintraub 
>wrote:
>> Jeff,
>>  Thanks. I was able to easily get rid of the do.call code and use the
>t( t(...)) construct.
>>
>> In terms of the dates I have tried your suggestion and I am having an
>odd problem.
>>
>> The dates I included in my previous message were only a subset of the
>actual dates I am using.
>>
>> My dates were imported from Excel via RExcel. Here are 3 of them in
>various formats:
>>
>> Displayed in Excel via one type of formatting: 12/1/2023, 1/1/2024,
>2/1/2024
>>
>> As integers from the "epoch" (which is only day based): 45261, 45292,
>45323
>>
>> In R imported from Excel via RExcel (a little more context here):
>>  "2023-11-30 23:00:00 EST"
>>  "2023-12-31 23:00:00 EST"
>>  "2024-01-31 23:00:00 EST"
>>  "2024-02-29 23:00:00 EST"
>>  "2024-04-01 00:00:00 EDT"
>>  "2024-05-01 00:00:00 EDT"
>>  "2024-06-01 00:00:00 EDT"
>>  "2024-07-01 00:00:00 EDT"
>>  "2024-08-01 00:00:00 EDT"
>>  "2024-09-01 00:00:00 EDT"
>>
>> Notice how March 2024 is skipped. Also notice how the conversion
>process gives some dates an EDT and some an EST tag. I assume that is
>what you were warning me about timezones.
>>
>> In addition when I convert using just the function year (lubridate)
>the result is:
>>   2023 2023 2024 2024 2024 2024 2024 2024 2024 2024
>>
>> Where I was expecting (based on the Excel dates):
>>   2023 2024 2024 2024 2024 2024 2024 2024 2024 2024
>>
>> Any help on how to do this the "right" way would be greatly
>appreciated.
>>
>> I know that Excel has "issues" with regards to dates and there may
>even be issues using RExcel for this type of conversion.
>>
>> Any help would is appreciated.
>>
>> Thanks again,
>> KW
>>
>> PS Here is a dput of the last 10 dates:
>>
>> someDates<-structure(c(1701403200, 1704081600, 170676,
>1709265600, 1711944000,
>> 1714536000, 1717214400, 1719806400, 1722484800, 1725163200), class =
>c("POSIXct",
>> "POSIXt"))
>>
>>
>> On Jun 15, 2012, at 1:48 AM, Jeff Newmiller wrote:
>>
>>> a) Avoid mixing Date objects and POSIXt objects. The timezones will
>mess you up in the conversions. Just eliminate the as.Date conversion
>entirely.
>>>
>>> b) By the time you reach the do.call function call, amortsByYears is
>a matrix. While a data.frame is a special kind of list, a matrix is
>not. Hence, the error message.
>>>
>>> You can replace the do.call with
>>>
>>> t( t( amortsByYears )/amortsByYears[1,] )
>>>
>>> which is rather more efficient than do.call anyway.
>>>
>---
>>> Jeff Newmiller                        The     .       .  Go
>Live...
>>> DCN:        Basics: ##.#.       ##.#.
> Live Go...
>>>                                      Live:   OO#.. Dead: OO#..
> Playing
>>> Research Engineer (Solar/Batteries            O.O#.       #.O#.
> with
>>> /Software/Embedded Controllers)               .OO#.       .OO#.
> rocks...1k
>>>
>---
>>> Sent from my phone. Please excuse my brevity.
>>>
>>> Keith Weintraub  wrote:
>>>
 Folks,

 I call the function calcAmorts like so:
      calcAmorts(prevAm, amort, myDates)

 Note that I use the package lubridate.

 The last line where do.call is called to first divide all the rows
>by
 the first row and then rbind gives the following error:
 Error in do.call("rbi

Re: [R] Help with Sequential Differencing

2012-06-15 Thread Lekgatlhamang, lexi Setlhare
Hi Sarah,
 
Sorry for taking more of your time. I thought that before investigating the use 
of assign and paste, I should first understand the approach of using 'list()'. 
However, it seems to me that the use of list does not work very well, unless I 
have wrongly implemented your suggestion. I implemented your suggestion as 
follows:
DCred<- list()
for(i in 1:5){
print(DCred[[i]]<- diff(DCred, lag=i, difference=1))
}
Upon execution of the loop, the following was printed out:
list()
list()
list()
list()
list()

After the loop I tried to access the values for DCred1, DCred2, etc but to no 
avail. See my commands and the associated output below:
 
> DCred[[1]]
list()
> DCred[[i]]
list()
> DCred[1]
[[1]]
list()

Anyway, I then calculate DCred in order to see if the regression
 
DCred <-lm(DCred~DCred1+DCred2)
 
will work.
But it did not. Instead I got an error message - see below.
 
> model<- lm(DCred~DCred[1]+DCred[2], drop.unused.levels = TRUE)
Error in model.frame.default(formula = DCred ~ DCred[1] + DCred[2], 
drop.unused.levels = TRUE) : 
  variable lengths differ (found for 'DCred[1]')
 
I then modified the right-hand-side of the equation, but still it did not work:
 
> model <- lm(DCred~DCred[[1]])
Error in model.frame.default(formula = DCred ~ DCred[[1]], drop.unused.levels = 
TRUE) : 
  variable lengths differ (found for 'DCred[[1]]')
 
I will remain reading up on the assign and paste commands.
Thanks. Lexi


From: Sarah Goslee 

Cc: "r-help@r-project.org"  
Sent: Friday, June 15, 2012 12:54 PM
Subject: Re: [R] Help with Sequential Differencing


If you really want DCred1, DCred2, etc, you'll need to use assign() and paste() 
within your loop. But he's a more R-ish way:
 
# Differences of Cred

DCred <- list()
for(i in 1:5){
print(DCred[[i]]<- diff(DCred, lag=i, difference=1))
 
}
  
DCred[[1]]

Sarah

On Friday, June 15, 2012, Lekgatlhamang, lexi Setlhare wrote:

Dear R Users,
>Sorry for what seems like I am re-posting. When I was typing my initial 
>posting, I intended to copy and paste the commands from my script, but ended 
>up forgetting. I am now pasting the commands in this email.NB: Below is a copy 
>of 'all' the relevant commands in my script
> 
> ##
>data<- read.table("C:\\myfiles\\from drive D\\myfiles 080208\\An R Test 
>folder\\Dataset2a.csv", head=TRUE, sep=",")
>str(data)
>data
> 
># Extract the variables in data, rename and difference them
> 
>Cred <- ts(data[, 2], frequency=12, start=c(2001, 1)) # Cred denotes Credit
> 
># Differences of Cred
>DCred<- diff(Cred, difference=1)
>DCred
>for(i in 1:5){
>print(DCred[i]<- diff(DCred, lag=i, difference=1))
> 
>}
> 
>DCred[1]
> 
> DCred[2]
> 
> DCred[3]
> 
> 
>Thanks Lexi
>
>
>
>
>To: "r-help@r-project.org" 
>Sent: Friday, June 15, 2012 11:39 AM
>Subject: Help with Sequential Differencing
>
>
>
>
>Dear R Users,
>
>I have struggled with the following problem for days, which I thought was 
>simple, although it would likely be basic to most of you.
>I am working with time series data.
>In my script, my intention is to create first differences of the variables in 
>the file so that I end up estimating an equation of the form:
>DCred(t) =c + 
>DCred(t-1)+DCred(t-2)+...+DBoB(t)+DBoB(t-1)+DBoB(t-2)+...+Drvr(t)+Drvr(t-1)+Drvr(t-2)+...+e(t)
>
>Where D at the beginning of each variable represents 'change', for first 
>difference and e(t) is the error term.
>Now I am trying to use loops to calculate 5 lagged first-differences of each 
>variable in the dataset - e.g., DCred(t-1), DCred(t-2), ..., DCred(t-5).
>Example:
># Differences of Cred
>DCred<- diff(Cred, difference=1)
>DCred
>for(i in 1:5){
>print(DCred[i]<- diff(DCred, lag=i, difference=1))
>}
>After I calculated the contemporaneous first difference DCred, this loop is 
>meant to compute the subsequent first differences of the same variable; i.e., 
>DCred(t-1) and call it DCred1, DCred(t-2) and call it DCred2, ... and 
>DCred(t-5) and call it DCred5.
>The loop works, at least I think so. But now after the loop has executed, when 
>I type DCred1[1] (which I thought would give me the first value in the series 
>for DCred(t-1)), called DCred1, I get a message "object 'DCred1' not found". 
>Similarly typing Dcred1[2] (which I thought would give the second value of 
>DCred(t-1)), ie., the second value of DCred1, gives "object DCred1[2] not 
>found", etc.
>A copy of the commands and error messages is below:
>> DCred1[1]
>Error: object 'DCred1' not found
>> DCred1[2]
>Error: object 'DCred1' not found
>
>How can I solve this problem? Thank you kindly for your time.
>       [[alternative HTML version deleted]]
>
>

-- 
Sarah Goslee
http://www.stringpage.com/
http://www.sarahgoslee.com/
http://www.functionaldiversity.org/
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
h

[R] R: R: Securities earning covariance

2012-06-15 Thread ANGELO.LINARDI
Hello,

first of all tank to both of you for your fast response.
Going back to Michael's wonderful ASCII art masterpiece, what we have now is 
something like this:

---  JVM ---

     JAVA  

  JDBC
   |
   |
Algorithm
   |
 JAVA 
---  JVM ---
  |
   RNI
  |
 R

What we want is something like the following (on the same virtual machine):

---  JVM1 ---   ---  JVM2 ---

     JAVA     JAVA  

  JDBC  JDBC
   ||
   ||
Algorithm   Algorithm   
   ||
 JAVA    JAVA   
---  JVM1 ---   ---  JVM2 ---
  | |
   RNI   RNI
  | |
 R(1)   R(2)

My question is: is that possible ? How can I address R(1) from JVM1 and R(2) 
from JVM2 ? Is data calculated in R(1) and R(2) completely independent or the 2 
instances "share" something in memory ?
Thanks again for you kindness and help.

Angelo  

-Messaggio originale-
Da: Oliver Ruebenacker [mailto:cur...@gmail.com] 
Inviato: venerdì 15 giugno 2012 17.36
A: R. Michael Weylandt
Cc: LINARDI ANGELO; r-help@r-project.org
Oggetto: Re: [R] R: Securities earning covariance


 Hello,

On Fri, Jun 15, 2012 at 10:15 AM, R. Michael Weylandt
 wrote:
> ii) There does not exist -- to my knowledge -- an implementation of R
> which runs on the JVM.

  I think he means driving the R framework from Java via JNI. I think
the questions boils down to whether you can open multiple independent
R sessions on the same system and then address them separately via JNI
(I don't know, but I would assume you can do that without multiplying
the installation).

 Take care
 Oliver

-- 
Oliver Ruebenacker
Bioinformatics Consultant (http://www.knowomics.com/wiki/Oliver_Ruebenacker)
Knowomics, The Bioinformatics Network (http://www.knowomics.com)
SBPAX: Turning Bio Knowledge into Math Models (http://www.sbpax.org)

** Le e-mail provenienti dalla Banca d'Italia sono trasmesse in buona fede e 
non 
comportano alcun vincolo ne' creano obblighi per la Banca stessa, salvo che 
cio' non 
sia espressamente previsto da un accordo scritto.
Questa e-mail e' confidenziale. Qualora l'avesse ricevuta per errore, La 
preghiamo di 
comunicarne via e-mail la ricezione al mittente e di distruggerne il contenuto. 
La 
informiamo inoltre che l'utilizzo non autorizzato del messaggio o dei suoi 
allegati 
potrebbe costituire reato. Grazie per la collaborazione.
-- E-mails from the Bank of Italy are sent in good faith but they are neither 
binding on 
the Bank nor to be understood as creating any obligation on its part except 
where 
provided for in a written agreement. This e-mail is confidential. If you have 
received it 
by mistake, please inform the sender by reply e-mail and delete it from your 
system. 
Please also note that the unauthorized disclosure or use of the message or any 
attachments could be an offence. Thank you for your cooperation. **

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


Re: [R] R: Securities earning covariance

2012-06-15 Thread Oliver Ruebenacker
 Hello,

On Fri, Jun 15, 2012 at 10:15 AM, R. Michael Weylandt
 wrote:
> ii) There does not exist -- to my knowledge -- an implementation of R
> which runs on the JVM.

  I think he means driving the R framework from Java via JNI. I think
the questions boils down to whether you can open multiple independent
R sessions on the same system and then address them separately via JNI
(I don't know, but I would assume you can do that without multiplying
the installation).

 Take care
 Oliver

-- 
Oliver Ruebenacker
Bioinformatics Consultant (http://www.knowomics.com/wiki/Oliver_Ruebenacker)
Knowomics, The Bioinformatics Network (http://www.knowomics.com)
SBPAX: Turning Bio Knowledge into Math Models (http://www.sbpax.org)

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


Re: [R] R start screen

2012-06-15 Thread Duncan Murdoch

On 12-06-15 9:04 AM, Rossenu, Stefaan wrote:


After installation of R on windows machine and starting the R program, I only 
see the R-console but not the RGUI screen... Do I need to re-install or change 
some settings?


R is a short form for Rterm, so that's what should start.  If you want 
the gui, run Rgui.


Duncan Murdoch



Tx!

Notice:  This e-mail message, together with any attachme...{{dropped:14}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] some help to improve "hist to plot relative frequencies"

2012-06-15 Thread gianni lavaredo
Dear Researches,

sorry for disturb. I wish to improve my figure in R plotting the relative
frequencies of my data set.

library(lattice)
a <- c(0,0,0,1,1,2,4,5,6,7,7,7,7,7,8,8,8,8,9,9,9,9,10,10,11)
histogram(a, xlab="myData")

what i wish to do is:

1) invert the order of X and Y (eg: Precent of Total on X-axis and "MyData"
on X-axis)
2) plot not the bar of histogram but a line (i tried with
"lines(density(a))" but the result is not what i wish)

Great Thanks for any helps
Gianni

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

2012-06-15 Thread ANGELO.LINARDI
Hello,

first of all thanks to both of you for your fast response.
Going back to Michael's wonderful ASCII art masterpiece, what we have now is 
something like this:

---  JVM ---

     JAVA  

  JDBC
   |
   |
Algorithm
   |
 JAVA 
---  JVM ---
  |
   RNI
  |
 R

What we want is something like the following (on the same virtual machine):

---  JVM1 ---   ---  JVM2 ---

     JAVA     JAVA  

  JDBC  JDBC
   ||
   ||
Algorithm   Algorithm   
   ||
 JAVA    JAVA   
---  JVM1 ---   ---  JVM2 ---
  | |
   RNI   RNI
  | |
 R(1)   R(2)

My question is: is that possible ? How can I address R(1) from JVM1 and R(2) 
from JVM2 ? Is data calculated in R(1) and R(2) completely independent or the 2 
instances "share" something in memory ?
Thanks again for you kindness and help.

Angelo  

-Messaggio originale-
Da: Oliver Ruebenacker [mailto:cur...@gmail.com] 
Inviato: venerdì 15 giugno 2012 17.36
A: R. Michael Weylandt
Cc: LINARDI ANGELO; r-help@r-project.org
Oggetto: Re: [R] R: Securities earning covariance


 Hello,

On Fri, Jun 15, 2012 at 10:15 AM, R. Michael Weylandt
 wrote:
> ii) There does not exist -- to my knowledge -- an implementation of R
> which runs on the JVM.

  I think he means driving the R framework from Java via JNI. I think
the questions boils down to whether you can open multiple independent
R sessions on the same system and then address them separately via JNI
(I don't know, but I would assume you can do that without multiplying
the installation).

 Take care
 Oliver

-- 
Oliver Ruebenacker
Bioinformatics Consultant (http://www.knowomics.com/wiki/Oliver_Ruebenacker)
Knowomics, The Bioinformatics Network (http://www.knowomics.com)
SBPAX: Turning Bio Knowledge into Math Models (http://www.sbpax.org)

** Le e-mail provenienti dalla Banca d'Italia sono trasmesse in buona fede e 
non 
comportano alcun vincolo ne' creano obblighi per la Banca stessa, salvo che 
cio' non 
sia espressamente previsto da un accordo scritto.
Questa e-mail e' confidenziale. Qualora l'avesse ricevuta per errore, La 
preghiamo di 
comunicarne via e-mail la ricezione al mittente e di distruggerne il contenuto. 
La 
informiamo inoltre che l'utilizzo non autorizzato del messaggio o dei suoi 
allegati 
potrebbe costituire reato. Grazie per la collaborazione.
-- E-mails from the Bank of Italy are sent in good faith but they are neither 
binding on 
the Bank nor to be understood as creating any obligation on its part except 
where 
provided for in a written agreement. This e-mail is confidential. If you have 
received it 
by mistake, please inform the sender by reply e-mail and delete it from your 
system. 
Please also note that the unauthorized disclosure or use of the message or any 
attachments could be an offence. Thank you for your cooperation. **

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


Re: [R] R <--> JVM

2012-06-15 Thread R. Michael Weylandt
On Fri, Jun 15, 2012 at 11:03 AM,   wrote:
> Hello,
>
> first of all thanks to both of you for your fast response.
> Going back to Michael's wonderful ASCII art masterpiece, what we have now is 
> something like this:
>
> ---  JVM ---
>
>     JAVA  
>
>          JDBC
>               |
>               |
>        Algorithm
>               |
>     JAVA 
> ---  JVM ---
>              |
>           RNI
>              |
>             R
>
> What we want is something like the following (on the same virtual machine):
>
> ---  JVM1 ---                       ---  JVM2 ---
>
>     JAVA                                 JAVA  
>
>          JDBC                                          JDBC
>               |                                                |
>               |                                                |
>        Algorithm                                       Algorithm
>               |                                                |
>     JAVA                                JAVA 
> ---  JVM1 ---                       ---  JVM2 ---
>              |                                         |
>           RNI                                       RNI
>              |                                         |
>             R(1)                                               R(2)
>
> My question is: is that possible ? How can I address R(1) from JVM1 and R(2) 
> from JVM2 ? Is data calculated in R(1) and R(2) completely independent or the 
> 2 instances "share" something in memory ?

Best I understand it (and RNI seems Windows-only so I can't verify)
you have nothing to worry about. As long as you start 2 R processes
(which seems to be the only thing that could happen with two JVMs) the
memory should be kept independently. The only exception I can think of
is that if you choose to install a new package on one R process it
might be available to the other as a read-only resource (but I'm not
sure even this would happen depending on how your VM handles that bit)
but data integrity should be guaranteed.

Michael

> Thanks again for you kindness and help.
>
> Angelo
>
> -Messaggio originale-
> Da: Oliver Ruebenacker [mailto:cur...@gmail.com]
> Inviato: venerdì 15 giugno 2012 17.36
> A: R. Michael Weylandt
> Cc: LINARDI ANGELO; r-help@r-project.org
> Oggetto: Re: [R] R: Securities earning covariance
>
>
>     Hello,
>
> On Fri, Jun 15, 2012 at 10:15 AM, R. Michael Weylandt
>  wrote:
>> ii) There does not exist -- to my knowledge -- an implementation of R
>> which runs on the JVM.
>
>  I think he means driving the R framework from Java via JNI. I think
> the questions boils down to whether you can open multiple independent
> R sessions on the same system and then address them separately via JNI
> (I don't know, but I would assume you can do that without multiplying
> the installation).
>
>     Take care
>     Oliver
>
> --
> Oliver Ruebenacker
> Bioinformatics Consultant (http://www.knowomics.com/wiki/Oliver_Ruebenacker)
> Knowomics, The Bioinformatics Network (http://www.knowomics.com)
> SBPAX: Turning Bio Knowledge into Math Models (http://www.sbpax.org)
>
> ** Le e-mail provenienti dalla Banca d'Italia sono trasmesse in buona fede e 
> non
> comportano alcun vincolo ne' creano obblighi per la Banca stessa, salvo che 
> cio' non
> sia espressamente previsto da un accordo scritto.
> Questa e-mail e' confidenziale. Qualora l'avesse ricevuta per errore, La 
> preghiamo di
> comunicarne via e-mail la ricezione al mittente e di distruggerne il 
> contenuto. La
> informiamo inoltre che l'utilizzo non autorizzato del messaggio o dei suoi 
> allegati
> potrebbe costituire reato. Grazie per la collaborazione.
> -- E-mails from the Bank of Italy are sent in good faith but they are neither 
> binding on
> the Bank nor to be understood as creating any obligation on its part except 
> where
> provided for in a written agreement. This e-mail is confidential. If you have 
> received it
> by mistake, please inform the sender by reply e-mail and delete it from your 
> system.
> Please also note that the unauthorized disclosure or use of the message or any
> attachments could be an offence. Thank you for your cooperation. **
>

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


Re: [R] R: Securities earning covariance

2012-06-15 Thread R. Michael Weylandt
On Fri, Jun 15, 2012 at 10:35 AM, Oliver Ruebenacker  wrote:
>     Hello,
>
> On Fri, Jun 15, 2012 at 10:15 AM, R. Michael Weylandt
>  wrote:
>> ii) There does not exist -- to my knowledge -- an implementation of R
>> which runs on the JVM.
>
>  I think he means driving the R framework from Java via JNI. I think
> the questions boils down to whether you can open multiple independent
> R sessions on the same system and then address them separately via JNI
> (I don't know, but I would assume you can do that without multiplying
> the installation).

Yes, that seems to be the issue at play and best I understand the
set-up you get this "for free" from the in-memory model. You shouldn't
need two R installations any more than you need to install the JVM
twice to run two JVMs on one box.

Best,
Michael

>
>     Take care
>     Oliver
>
> --
> Oliver Ruebenacker
> Bioinformatics Consultant (http://www.knowomics.com/wiki/Oliver_Ruebenacker)
> Knowomics, The Bioinformatics Network (http://www.knowomics.com)
> SBPAX: Turning Bio Knowledge into Math Models (http://www.sbpax.org)

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


Re: [R] remove leading slash

2012-06-15 Thread Spencer Graves
How about an alternative:


**|install.packages("sos", repos="http://R-Forge.R-project.org";)|**
library(sos)


(x <- back2ForwardSlash())
\002 \001 \102


(xs <- strsplit(x, '/')[[1]][-1])

nch <- nchar(xs)
while(any((nch2 <- nchar(xs <- gsub('^0', '', xs))) Yes, I've been messing with that. I've also been using the hexView package.
> Reading as characters first is just helping me figure out the structure of
> this binary file. In this situation it really helped. For example:
> È \001 \002
>   20012
>
> This probably isn't how I'll do it in my final draft.
>
> I'm now looking for a date or series of dates in the binary file... I'm
> guessing the dates will be represented as 3 integers one for month, day,
> and year.  Any help on strategy help here would be great...  I'm reading a
> file with a dbs extension if that helps.
>
> Thanks!
>
> ben
>
> On Fri, Jun 8, 2012 at 12:44 PM, William Dunlap  wrote:
>
>>   When reading binary files, it is usually best to use readBin's
>>
>> what=, size=, signed=, and endian= arguments to get what you want.
>>
>> Reading as characters and then converting them as you are doing
>>
>> is a very hard way to do things (and this particular conversion doesn't***
>> *
>>
>> make much sense).
>>
>> ** **
>>
>> Bill Dunlap
>>
>> Spotfire, TIBCO Software
>>
>> wdunlap tibco.com
>>
>> ** **
>>
>> *From:* Ben quant [mailto:ccqu...@gmail.com]
>> *Sent:* Friday, June 08, 2012 11:40 AM
>> *To:* William Dunlap
>>
>> *Cc:*r-help@r-project.org
>> *Subject:* Re: [R] remove leading slash
>>
>>   ** **
>>
>> Okay, Bill smelt something wrong, so I must revise.
>>
>> This works for large numbers:
>>
>> prds = sapply(sapply(cnt_str,charToRaw),as.integer)
>>
>> PS - this also solves an issue I've been having elsewhere...
>> PPS- Bill - I'm reading binary files...and learning.
>>
>> thanks!
>> ben
>>
>> 
>>
>> On Fri, Jun 8, 2012 at 12:16 PM, William Dunlap  wrote:
>> 
>>
>> Can you tell us why you are interested in this mapping?
>> I.e., how did the "\001" and "\102" arise and why do you
>> want to convert them to the integers 1 and 102?
>>
>> Bill Dunlap
>> Spotfire, TIBCO Software
>> wdunlap tibco.com
>>
>>
>>
>>> -Original Message-
>>> From:r-help-boun...@r-project.org  [mailto:r-help-boun...@r-project.org]
>> On Behalf
>>> Of Ben quant
>>> Sent: Friday, June 08, 2012 11:00 AM
>>> To: Duncan Murdoch
>>> Cc:r-help@r-project.org
>>> Subject: Re: [R] remove leading slash
>>>
>>> Thanks for all your help.  I did it this way:
>>>
 x = sapply(cnt_str,deparse)
 x
>>> \002\001\002
>>> "\"\\002\"" "\"\\001\"" "\"\\102\""
 as.numeric(substr(x,3,5))
>>> [1]   2   1 102
>>>
>>> ...which is a bit of a hack, but gets me where I want to go.
>>>
>>> Thanks,
>>> Ben
>>>
>>> On Fri, Jun 8, 2012 at 11:56 AM, Duncan Murdoch<
>> murdoch.dun...@gmail.com>wrote:
 On 08/06/2012 1:50 PM, Peter Langfelder wrote:

> On Fri, Jun 8, 2012 at 10:25 AM, David
>>> Winsemius>
>   wrote:
>>   On Jun 8, 2012, at 1:11 PM, Ben quant wrote:
>>
>>>   Hello,
>>>
>>>   How do I change this:
   cnt_str
>>>   [1] "\002" "\001" "\102"
>>>
>>>   ...to this:
   cnt_str
>>>   [1] "2" "1" "102"
>>>
>>>   Having trouble because of this:
   nchar(cnt_str[1])
>>>   [1] 1
>>   "\001" is ASCII cntrl-A, a single character.
>>
>>   ?Quotes   # not the first, second or third place I looked but I
>> knew I
> had
>>   seen it before.
> If you still want to obtain the actual codes, you will be able to get
> the number using utf8ToInt from package base or AsciiToInt from
> package sfsmisc. By default, the integer codes will be printed in base
> 10, though.
>
 You could use
 
> as.octmode(as.integer(**charToRaw("\102")))
 [1] "102"

 if you really want the octal versions.  Doesn't work so well on "\1022"
 though (because that's two characters long).

 Duncan Murdoch


> A roundabout way, assuming your are on a *nix system, would be to
> dump() cnt_str into a file, say tmp.txt, then run in a shell (or using
> system() ) something like
>
> sed --in-place 's/\\//g' tmp.txt
>
> to remove the slashes, then use
>
> cnt_str_new = read.table("tmp.txt")
>
> in R to get the codes back in. I'll let you iron out the details.
>
> Peter
> 
> __**
> R-help@r-project.org  mailing list
> https://stat.ethz.ch/mailman/**listinfo/r-
>>> help
> PLEASE do read the posting guidehttp://www.R-project.org/**
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
 
 __**
 R-help@r-

Re: [R] Apply() on columns

2012-06-15 Thread Peter Ehlers

On 2012-06-15 01:09, faelsendoorn wrote:

Hi,

I have some trouble with the following: I have a table of 7 rows and
6columns. The columns 1,2,3 have information about the number of employees.
The columns 4,5,6 have information about the number of working hours. Each
row, is corresponding with a week.
My goal is to make a boxplot, histogram etc. of the columns 4, 5 and 6


I don't know what the "etc" is, but I strongly suggest that you NOT
make boxplots or histograms for data consisting of 7 values.
Consider stripchart().

Peter Ehlers


(thus, the data of the number of working hours). How can I select by using
the function Apply the weeks i needed for fullfulling my goal?

I already tried something with environment variables but that is a hard
stop.  I think, when I can select the columns I wanted with the
corresponding rows, that it would not be a problem making a histogram etc.

Yours,

Frans Elsendoorn

--
View this message in context: 
http://r.789695.n4.nabble.com/Apply-on-columns-tp4633468.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] R <--> JVM

2012-06-15 Thread Oliver Ruebenacker
 Hello,

  By RNI, do you mean the Microsoft Raw Native Interface or the
Rengine R Native Interface?

 Take care
 Oliver

On Fri, Jun 15, 2012 at 12:03 PM,   wrote:
> Hello,
>
> first of all thanks to both of you for your fast response.
> Going back to Michael's wonderful ASCII art masterpiece, what we have now is 
> something like this:
>
> ---  JVM ---
>
>     JAVA  
>
>          JDBC
>               |
>               |
>        Algorithm
>               |
>     JAVA 
> ---  JVM ---
>              |
>           RNI
>              |
>             R
>
> What we want is something like the following (on the same virtual machine):
>
> ---  JVM1 ---                       ---  JVM2 ---
>
>     JAVA                                 JAVA  
>
>          JDBC                                          JDBC
>               |                                                |
>               |                                                |
>        Algorithm                                       Algorithm
>               |                                                |
>     JAVA                                JAVA 
> ---  JVM1 ---                       ---  JVM2 ---
>              |                                         |
>           RNI                                       RNI
>              |                                         |
>             R(1)                                               R(2)
>
> My question is: is that possible ? How can I address R(1) from JVM1 and R(2) 
> from JVM2 ? Is data calculated in R(1) and R(2) completely independent or the 
> 2 instances "share" something in memory ?
> Thanks again for you kindness and help.
>
> Angelo
>
> -Messaggio originale-
> Da: Oliver Ruebenacker [mailto:cur...@gmail.com]
> Inviato: venerdì 15 giugno 2012 17.36
> A: R. Michael Weylandt
> Cc: LINARDI ANGELO; r-help@r-project.org
> Oggetto: Re: [R] R: Securities earning covariance
>
>
>     Hello,
>
> On Fri, Jun 15, 2012 at 10:15 AM, R. Michael Weylandt
>  wrote:
>> ii) There does not exist -- to my knowledge -- an implementation of R
>> which runs on the JVM.
>
>  I think he means driving the R framework from Java via JNI. I think
> the questions boils down to whether you can open multiple independent
> R sessions on the same system and then address them separately via JNI
> (I don't know, but I would assume you can do that without multiplying
> the installation).
>
>     Take care
>     Oliver
>
> --
> Oliver Ruebenacker
> Bioinformatics Consultant (http://www.knowomics.com/wiki/Oliver_Ruebenacker)
> Knowomics, The Bioinformatics Network (http://www.knowomics.com)
> SBPAX: Turning Bio Knowledge into Math Models (http://www.sbpax.org)
>
> ** Le e-mail provenienti dalla Banca d'Italia sono trasmesse in buona fede e 
> non
> comportano alcun vincolo ne' creano obblighi per la Banca stessa, salvo che 
> cio' non
> sia espressamente previsto da un accordo scritto.
> Questa e-mail e' confidenziale. Qualora l'avesse ricevuta per errore, La 
> preghiamo di
> comunicarne via e-mail la ricezione al mittente e di distruggerne il 
> contenuto. La
> informiamo inoltre che l'utilizzo non autorizzato del messaggio o dei suoi 
> allegati
> potrebbe costituire reato. Grazie per la collaborazione.
> -- E-mails from the Bank of Italy are sent in good faith but they are neither 
> binding on
> the Bank nor to be understood as creating any obligation on its part except 
> where
> provided for in a written agreement. This e-mail is confidential. If you have 
> received it
> by mistake, please inform the sender by reply e-mail and delete it from your 
> system.
> Please also note that the unauthorized disclosure or use of the message or any
> attachments could be an offence. Thank you for your cooperation. **
>



-- 
Oliver Ruebenacker
Bioinformatics Consultant (http://www.knowomics.com/wiki/Oliver_Ruebenacker)
Knowomics, The Bioinformatics Network (http://www.knowomics.com)
SBPAX: Turning Bio Knowledge into Math Models (http://www.sbpax.org)

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


[R] Wrong computation of time differenze in POSIXct - additional digits

2012-06-15 Thread Julia
Hello, 

I wanted to compute the time differenze between to times:

first =as.POSIXct( "2012-06-15 16:32:39.0025 CEST")
second  = as.POSIXct("2012-06-15 16:32:39.0086 CEST")
second - first

The result is
Time difference of 0.006099939 secs

instead of just 0.0061 secs
So R adds aditional  numbers after the result. 
I know I could round it in this case.
But I am working with a large data set and need to always get the 
correct result. 

difftime() does not work correct either. 

Has anybody a suggestion how to get the correct result?

Thank you
Julia

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


Re: [R] Binary Quadratic Opt?

2012-06-15 Thread Petr Savicky
On Fri, Jun 15, 2012 at 05:17:36PM +0530, Anup Bhatkar wrote:
> Hello,
> 
> I have to solve Binary Quadratic Optimization problem i.e the objective 
> function is quadratic, constraints are linear and variable are binary. I 
> checked the "quadprog" package but it does not seem to be right choice for 
> the problem.
> 
> Can any one suggest what would be the best package to solve the Binary 
> Quadratic opt.

Hello:

I do not know, whether there is a package directly suitable for binary
quadratic optimization. However, one can try the following.

A quadratic problem with binary variables may be reformulated as a linear
problem with additional binary variables. Linear problem with binary
variables may be solved using lpSolve package

  http://cran.at.r-project.org/web/packages/lpSolve/index.html

The transformation can be done as follows. For every product x_1*x_2, add
a new variable y, use it instead of x_1*x_2 to make the objective function
linear and add the constraints

  0 <= x_1 + x_2 - 2*y <= 1

If x_1, x_2, y are all {0, 1}, then these constraints are equivalent
to the constraint

  y = x_1 * x_2

This transformation may increase the number of variables significantly, so
it is not guaranteed that the problem is solvable. However, it can be.

Hope this helps.

Petr Savicky.

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


Re: [R] Wrong computation of time differenze in POSIXct - additional digits

2012-06-15 Thread David Winsemius


On Jun 15, 2012, at 12:49 PM, Julia wrote:


Hello,

I wanted to compute the time differenze between to times:

first =as.POSIXct( "2012-06-15 16:32:39.0025 CEST")
second  = as.POSIXct("2012-06-15 16:32:39.0086 CEST")
second - first

The result is
Time difference of 0.006099939 secs

instead of just 0.0061 secs
So R adds aditional  numbers after the result.


It's a floating point representation issue.  You don't really want to  
change that value, but are asking to see something different:


> round ( second - first, 4)
Time difference of 0.0061 secs


I know I could round it in this case.
But I am working with a large data set and need to always get the
correct result.

difftime() does not work correct either.

Has anybody a suggestion how to get the correct result?


Use a computer system that runs on exact arithmetic?

Read FAQ 7.31
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

(And expect to read about 4-6 similar messages in the next hour.)



Thank you
Julia

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] Cholesky decomposition error

2012-06-15 Thread Kjetil Halvorsen
see inline.

On Fri, Jun 15, 2012 at 4:33 AM,   wrote:
> Thanks for your reply. I am sorry and I am bit hurried up to say before doing 
> a proper due diligence, I have found out that during the optimization the 
> variables tend to vary the values of the matrix , the function report error 
> at some point (in particular iteration step) when the matrix become 
> non-decomposable due to not a positive definiteness.

¿What are you trying to optimize? If the objective function depends on
a matrix argument
which has to be a positive definite function, you must parametrize the
matrix such that the matrix
inside the optimizer always is positive definite. So if your positive
definite matrix is A, then, for example, represent it as
its cholesky decomposition A= L L^T where L is lower triangular with
positive diagonal. Here the stricly
upper diagonal part varies freely, but the diagonal not, so represent
the diagonal as exp( l_i)
where now the l_i varies freely. This is called the log-Cholesky
parametrization. For other ideas along this lines, see the paper by
Douglas Bates:  "Unconstrained Parameterizations for
Variance-Covariance Matrices  "
which you can find by googling.

Kjetil


 This I observed when I change the maximum iteration of the optim
function set to 1 and upto iteration no. 3 it runs , it stuck at
iteration 4 and above.
>
> Now, I am trying to find ways to escalate such a condition inside the 
> function during the iteration process and if possible please help me to do 
> that.
>
> Regards,
> B.Nataraj
>
>
> -Original Message-
> From: Bert Gunter [mailto:gunter.ber...@gene.com]
> Sent: Friday, June 15, 2012 1:51 PM
> To: Nataraj B (ORLL-Biotech)
> Cc: r-help@r-project.org
> Subject: Re: [R] Cholesky decomposition error
>
> Follow the posting guide,please: I believe at this point we need
> reproducible code and your data to provide you help. See ?dput to post
> your matrix.
>
> -- Bert
>
> On Thu, Jun 14, 2012 at 11:30 PM,   wrote:
>>
>> Thanks for your reply. To my surprise I can find one more strange behavior 
>> of  my 15X15 matrix "A", that is if I call the function  chol(A) in the 
>> terminal it decompose the matrix fine without any errors or warnings.
>> But if I call the function chol() within a function, which I have written in 
>> order to call the function (contains formula) for optimization routine 
>> "optim()" and also supplied with the same matrix "A" as argument, the error 
>> mentioned
>>
>>> Error in chol.default(M_cov) :
>>>  the leading minor of order 10 is not positive definite
>>
>> is surfaced during the function call by optim.
>>
>> Why the matrix fulfill the symmetric and positive definite for chol() in one 
>> case but fails in other case when the function chol() is called in other 
>> function ?
>>
>> I played around parameters of "optim" function but nothing seems to be 
>> working and I am confused and I am looking for some hints to introspect the 
>> problem further.
>>
>> Regards,
>> B.Nataraj
>>
>>
>>
>>
>>
>> -Original Message-
>> From: Bert Gunter [mailto:gunter.ber...@gene.com]
>> Sent: Thursday, June 14, 2012 6:18 PM
>> To: Nataraj B (ORLL-Biotech)
>> Cc: r-help@r-project.org
>> Subject: Re: [R] Cholesky decomposition error
>>
>> Your matrix is not symmetric, positive definite. If you don't know
>> what this means, you shouldn't be using chol()
>>
>> This may be because it isn't to begin with, or due to numerical error,
>> it doesn't behave as one in the decomposition. My relative ignorance
>> of numeric methods for linear algebra prevents me from saying more
>> than that.
>>
>> -- Bert
>>
>> On Thu, Jun 14, 2012 at 4:23 AM,   wrote:
>>> Dear friends,
>>>
>>> When I do Cholesky decomposition for a 15x15 matrix using the function 
>>> chol(), I get the following error for which I do not understand the meaning 
>>> of the error
>>>
>>> Error in chol.default(M_cov) :
>>>  the leading minor of order 10 is not positive definite
>>>
>>> When I searched online for similar error reported earlier I could get few 
>>> hits but not of much help to resolve my error and one post suggested to use 
>>> different function called sechol() from accuracy package but that did not 
>>> work and it leads to different errors. So I want to stick to function 
>>> chol() itself.
>>>
>>> Could you please help me to find where things are going wrong in my matrix?
>>>
>>>
>>> Thanks and regards,
>>> B.Natarj
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>> --
>>
>> Bert Gunter
>> Genentech Nonclinical Biostatistics
>>
>> Internal Contact Info:
>> Phone: 467-7374
>> Website:
>> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
>>
>>
>
>
>
> --
>
> Bert Gunter
> Genentech Nonc

Re: [R] R start screen

2012-06-15 Thread David L Carlson
It can also be affected by the MDI setting in your Rconsole file. If you
have

MDI = yes

Then the RGui runs with the console inside it and the menu bar is on RGui.
If you have

MDI = no

Then you get one the Rconsole and the menu bar is on Rconsole. 
The default is generally MDI=yes, but if you have installed R Commander, 
for example you were instructed to change it to MDI = No.

--
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Duncan Murdoch
> Sent: Friday, June 15, 2012 11:05 AM
> To: Rossenu, Stefaan
> Cc: r-h...@lists.r-project.org
> Subject: Re: [R] R start screen
> 
> On 12-06-15 9:04 AM, Rossenu, Stefaan wrote:
> >
> > After installation of R on windows machine and starting the R
> program, I only see the R-console but not the RGUI screen... Do I need
> to re-install or change some settings?
> 
> R is a short form for Rterm, so that's what should start.  If you want
> the gui, run Rgui.
> 
> Duncan Murdoch
> 
> >
> > Tx!
> >
> > Notice:  This e-mail message, together with any
> attachme...{{dropped:14}}
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Wrong computation of time differenze in POSIXct - additional digits

2012-06-15 Thread Rui Barradas

Hello,

A classic of floating-point accuracy is

> 3/5 - 3/5
[1] 0
> 3/5 - (2/5 + 1/5)
[1] -1.110223e-16
> 3/5 - 2/5 - 1/5
[1] -5.551115e-17

Rui Barradas

Em 15-06-2012 18:18, David Winsemius escreveu:


On Jun 15, 2012, at 12:49 PM, Julia wrote:


Hello,

I wanted to compute the time differenze between to times:

first =as.POSIXct( "2012-06-15 16:32:39.0025 CEST")
second  = as.POSIXct("2012-06-15 16:32:39.0086 CEST")
second - first

The result is
Time difference of 0.006099939 secs

instead of just 0.0061 secs
So R adds aditional  numbers after the result.


It's a floating point representation issue.  You don't really want to
change that value, but are asking to see something different:

 > round ( second - first, 4)
Time difference of 0.0061 secs


I know I could round it in this case.
But I am working with a large data set and need to always get the
correct result.

difftime() does not work correct either.

Has anybody a suggestion how to get the correct result?


Use a computer system that runs on exact arithmetic?

Read FAQ 7.31
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f


(And expect to read about 4-6 similar messages in the next hour.)



Thank you
Julia

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


David Winsemius, MD
West Hartford, CT

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


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


[R] How do anova() and Anova(type="III") handle incomplete designs?

2012-06-15 Thread Justin Montemarano
Hello all:

I am confused about the output from a lm() model with an incomplete 
design/missing level.

I have two categorical predictors and a continuous covariate (day) that 
I am using to model larval mass (l.mass):

leaf.species has three levels - map, syc, and oak

cond.time has two levels - 30 and 150.

There are no response values for Map-150, so that entire, two-way, level 
is missing.

When running anova() on the model with Type I SS, the full factorial 
design does not return errors; however, using package:car Anova() and 
Type III SS, I receive an singularity error unless I used the argument 
'singular.ok = T' (it is defaulted to F).

So, why don't I receive an error with anova() when I do with Anova(type 
= "III")?  How do anova() and Anova() handle incomplete designs, and how 
can interactions of variables with missing levels be interpreted?

I realize these are fairly broad questions, but any insight would be 
helpful. Thanks, all.

Below is code to illustrate my question(s):

 > lmMass <- lm(log(l.mass) ~ day*leaf.species + cond.time, data =
growth.data) #lm() without cond.time interactions
 > lmMassInt <- lm(log(l.mass) ~ day*leaf.species*cond.time, data =
growth.data) #lm() with cond.time interactions
 > anova(lmMass); anova(lmMassInt) #ANOVA summary of both models
with Type I SS
Analysis of Variance Table

Response: log(l.mass)
   Df  Sum Sq Mean Sq F valuePr(>F)
day1  51.373  51.373 75.7451 2.073e-15
leaf.species   2   0.340   0.170  0.25060.7786
cond.time  1   0.161   0.161  0.23690.6271
day:leaf.species   2   1.296   0.648  0.95510.3867
Residuals179 121.404   0.678
Analysis of Variance Table

Response: log(l.mass)
 Df  Sum Sq Mean Sq F value  Pr(>F)
day  1  51.373  51.373 76.5651 1.693e-15
leaf.species 2   0.340   0.170  0.2533 0.77654
cond.time1   0.161   0.161  0.2394 0.62523
day:leaf.species 2   1.296   0.648  0.9655 0.38281
day:cond.time1   0.080   0.080  0.1198 0.72965
leaf.species:cond.time   1   1.318   1.318  1.9642 0.16282
day:leaf.species:cond.time   1   1.915   1.915  2.8539 0.09293
Residuals  176 118.091   0.671
 > Anova(lmMass, type = 'III'); Anova(lmMassInt, type = 'III')
#ANOVA summary of both models with Type III SS
Anova Table (Type III tests)

Response: log(l.mass)
   Sum Sq  Df F value   Pr(>F)
(Intercept)   39.789   1 58.6653 1.13e-12
day3.278   1  4.8336  0.02919
leaf.species   0.934   2  0.6888  0.50352
cond.time  0.168   1  0.2472  0.61968
day:leaf.species   1.296   2  0.9551  0.38672
Residuals121.404 179
Error in Anova.III.lm(mod, error, singular.ok = singular.ok, ...) :
   there are aliased coefficients in the model
 > Anova(lmMassInt, type = 'III', singular.ok = T) #Given the error
in Anova() above, set singular.ok = T
Anova Table (Type III tests)

Response: log(l.mass)
 Sum Sq  Df F value  Pr(>F)
(Intercept) 39.789   1 59.3004 9.402e-13
day  3.278   1  4.8860   0.02837
leaf.species 1.356   2  1.0103   0.36623
cond.time0.124   1  0.1843   0.66822
day:leaf.species 2.783   2  2.0738   0.12877
day:cond.time0.805   1  1.1994   0.27493
leaf.species:cond.time   0.568   1  0.8462   0.35888
day:leaf.species:cond.time   1.915   1  2.8539   0.09293
Residuals  118.091 176
 >



-
Justin Montemarano
Graduate Student
Kent State University - Biological Sciences

http://www.montegraphia.com

-- 
Justin Montemarano
Graduate Student
Kent State University - Biological Sciences

http://www.montegraphia.com


[[alternative HTML version deleted]]

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


Re: [R] Looking for Speed in a Toy Simulation Example

2012-06-15 Thread Rui Barradas

Hello,

With Michael's sugestions (I keep forgeting package compiler)


t0 <- system.time({ ... variant 3.b ...

#
## Variant 3.c ##
#

install.packages("compiler")
library(compiler)

basedeck <- rep(10^(1:4), 13)
pow10x5 <- 5*10^(1:4)
currentdeck <- matrix(nrow = 5, ncol=noplayer)

singlecolor1 <- matrix(NA, simlength, noplayer)
singlecolor2 <- matrix(NA, simlength, noplayer)

## sum by .colSums
f1 <- function(){
 sapply(1:simlength, function(i){
   currentdeck[] <- sample(basedeck, decklength)
   .colSums(currentdeck, 5, noplayer) %in% pow10x5
 })
}

f2 <- cmpfun(f1)  # cmpfun: compile function
is.function(f2)   # TRUE

set.seed()
t1 <- system.time( singlecolor1[] <- f1() )

set.seed()
t2 <- system.time( singlecolor2[] <- f2() )

identical(singlecolor1, singlecolor2)
rbind(v3.b=t0, v3.c.1=t1, v3.c.2=t2, factor=t0/t2)


Not another 3 or 4x but faster.

Rui Barradas

Em 15-06-2012 15:50, R. Michael Weylandt escreveu:

On Fri, Jun 15, 2012 at 9:48 AM, R. Michael Weylandt
 wrote:

As of recent versions of R, you can actually go for what are
officially recognized as "ultimate speed" functions .rowSums() and
friends.


Sorry, perhaps that wasn't totally clear. Regarding .rowSums() note
that leading period. You pass this a slightly different set of
arguments (including matrix dims) but it goes straight down to C with
no code in R so it will be faster.



You might also use the compiler() package to byte-compile that inner


Also, shouldn't have put parens after compiler.

Best,
Michael


loop. [The function going to sapply] It won't be massive, but perhaps
another 3 or 4x

Michael

On Fri, Jun 15, 2012 at 8:13 AM, Simon Knos
 wrote:

Rui, thank you very much.

I keep forgetting about the rowSum and friends. (precalculating the
powers just slipped my attention).

And, yes, a factor of will of course do. Do you see a further
improvement in this case?


Best,

Simon

On Fri, Jun 15, 2012 at 12:25 PM, Rui Barradas  wrote:

Hello,

Will a factor of 4 do?
This is variant 3, revised.

#
## Variant 3.b ##

#


## Initialize matrix to hold results
singlecolor <- matrix(NA, simlength, noplayer)

## construct the deck to sample from
basedeck <- rep(10^(1:4), 13)
## Pre-compute this vector, don't re-compute inside a loop
pow10x5 <- 5*10^(1:4)


## This one uses matrix(...,5) to create the individual hands
## but it's created in advance
currentdeck <- matrix(nrow = 5, ncol=noplayer)


## comparison by using %in%
set.seed()
system.time({
  singlecolor[] <- sapply(1:simlength, function(i){
   currentdeck[] <- sample(basedeck, decklength)
   colSums(currentdeck) %in% pow10x5
  })
})
apply(singlecolor, 2, mean)  ## colMeans()
mean(apply(singlecolor, 2, mean))


Note that the real speed gain is in colSums, all the rest gave me around 1.5
secs or 5% only.

Rui Barradas

Em 15-06-2012 09:40, Simon Knos escreveu:


Dear List Members



I used to play around with R to answer the following question by
simulation (I am aware there is an easy explicit solution, but this is
intended to serve as instructional example).

Suppose you have a poker game with 6 players and a deck of 52 cards.
Compute the empirical frequencies of having a single-suit hand. The
way I want the result structured is a boolean nosimulation by noplayer
matrix containing true or false
depending whether the specific player was dealt a single-suit hand.
The code itself is quite short: 1 line to "deal the cards", 1 line to
check whether any of the six players has single-suit hand.


I played around with different variants (all found below) and managed
to gain some speed, however, I subjectively still find it quite slow.

I would thus very much appreciate if anybody could point me to
a) speed improvments in general
b) speed improvements using the compiler package: At what level is
cmpfun best used in this particular example?




Thank you very much,


Simon


###Code#

noplayer <- 6
simlength <- 1e+05
decklength <- 5 * noplayer



#
## Variant 1   ##
#



## Initialize matrix to hold results
singlecolor <- matrix(NA, simlength, noplayer)
## construct the deck to sample from
basedeck <- rep(1:4, 13)
## This one uses split to create the individual hands

set.seed()
system.time({
  for (i in 1:simlength) {
currentdeck <- split(sample(basedeck, decklength), rep(1:noplayer, 5))
singlecolor[i, ] <- sapply(currentdeck, function(inv) {
length(unique(inv)) == 1 })
  }
})
apply(singlecolor, 2, mean)
mean(apply(singlecolor, 2, mean))



#
## Variant 2

Re: [R] wgcna

2012-06-15 Thread Peter Langfelder
On Fri, Jun 15, 2012 at 8:04 AM, Ingezz  wrote:
> Dear Peter,
>
> I am trying to apply the WGCNA meta-analysis for two (or more) microarray
> datasets-tutorial to my own data.
>
>> mp=modulePreservation(multiExpr,multiColor,referenceNetworks=1,verbose=3,networkType="signed",
>> nPermutations=30,maxGoldModuleSize=100,maxModuleSize=400)
>
> However, the error I am getting is:
>
> Error in .checkExpr(multiData, verbose, indent) :
>  The submitted 'multiExpr' data contain genes or samples
>   with zero variance or excessive counts of missing entries.
>   Please use the function goodSamplesGenes on each set to filter out the
> problematic
>   genes and samples before running modulePreservation.
>
> Seems pretty clear, but applying goodSamplesGenes function results in no
> exclusions for both arrays.
>
>>  GM2 <- goodSamplesGenes(M2, minFraction = 1/2, minNSamples =8, minNGenes
>> =20)
>
> What could be the issue here? Should I increase the stringency? What
> stringency should be used with goodsamplegenes for modulepreservation to
> work?

Hi Inge,

first, I suggest that in the future you contact me directly, since
others on this list probably have no idea what we're talking about.

It is difficult to diagnose the problem without the data. I suggest
you specify the verbose argument to both functions with a high value
(e.g., 5) which should produce more informative output.

I assume you are aware of the fact that the function goodSamplesGenes
returns a list whose component allOK determines whether any genes or
samples should be removed. Other components in the list specify which
genes and/or samples should be removed. The actual removal needs to be
done by you (I haven't written a function to do that yet but may do so
in the future to make it more convenient). In this sense the error
message is a bit misleading and I will change that as well.

HTH,

Peter

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


Re: [R] phyloclim help

2012-06-15 Thread Brent Hendrixson

Hi David -

> Looking at the package documentation I see this:
>
> maxent: A list containing the location of the MAXENT application and
> its input files (see
> details).
>
> Maybe I was wrong about 'spec' and the malformed argument is 'maxent'.
> If I had been constructing it I would have created a _named_ list:
>
> maxent <- list( app =app,
> samples =samples,
> background, # cannot tell if a csv file meets the
> requiremtn
> # "The path to a SWD-formatted file with
> background points."
> projections =projections) # that value .../R looks
> pretty suspicious, too.
>

Your advice definitely helped - THANK YOU!  However, I'm now getting another 
error that seems to be tied to the maxent java program itself.  Here's the 
syntax I have used for the niche.equivalency.test (recall that it consists of 4 
elements: spec, n, maxent, mx=2000)

spec <- c("aphonopelma_mojave", "aphonopelma_newmojave")

app <- file.path("C:\\Documents and Settings\\hendrb\\Desktop\\R\\maxent.jar")

samples <- file.path("C:\\Documents and 
Settings\\hendrb\\Desktop\\R\\samples.csv")

background <- file.path("C:\\Documents and 
Settings\\hendrb\\Desktop\\R\\background.csv")

projections <- file.path("C:\\Documents and Settings\\hendrb\\Desktop\\R")

maxent <- list(app=app, samples=samples, background=background, 
projections=projections)

After I defined each of those, I tried to execute the command as follows:

niche.equivalency.test(spec, n=100, maxent, mx=2000)

And here was the message I received:

Unable to access jarfile C:\Documents
Error in file(file, "r") : cannot open the connection
In addition: Warning messages:
1: running command 'java -mx2000m -jar C:\Documents and 
Settings\hendrb\Desktop\R\maxent.jar -e R.phyloclim.temp/background.csv -s 
R.phyloclim.temp/samples.csv -j C:\Documents and Settings\hendrb\Desktop\R -o 
R.phyloclim.temp/out -r removeduplicates nopictures outputformat=raw autorun' 
had status 1 
2: In file(file, "r") :
  cannot open file 'aphonopelma_mojave_C:\Documents and 
Settings\hendrb\Desktop\R.asc': Invalid argument

Like I mentioned, it seems that this particular error is unrelated to R code 
but I'm unsure why the jarfile (maxent.jar) cannot be accessed.  

Any thoughts?

The above command did produce a new file that serves as the input for the 
jarfile.

Thanks again for your help!

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


Re: [R] dumpMethods (was: How to build a large identity matrix faster?)

2012-06-15 Thread Spencer Graves




dumpMethods('diag', file='diag.R')
readLines('diag.R')

character(0)



  I appreciate the alternative suggested by Ceci Tam, but is this 
result a feature or a bug?



 More generally, what do you recommend I read to learn about S4 
generics?  I've read fair portions of Chambers (1998, 2008). 
Unfortunately, these produced more frustration than enlightenment for 
me.  Initially, I did not have access to a version of R with any S4 
capabilities.  After R acquired those features, there were differences 
between the R implementation and Chambers (1998) that I never overcame. 
 After Chambers (2008) appeared, I found many cases in that book as 
well where I could not reproduce the results claimed.  I finally gave up 
after substantial effort.



	I mention this, because it may be related to issues with profound 
implications for the future of R.  Recently, Jim Ramsay and I added 
support for Matrix-class matrices to the "fda" package.  In Matlab, that 
addition was fairly trivial, Ramsay told me.  In R it was surprisingly 
difficult, because the Matrix-class objects returned by many of our 
revised "fda" generated many errors with existing code that worked fine 
with standard dense matrices.  To avoid breaking existing code, we added 
an argument returnMatrix to many functions with the default being FALSE. 
 Now if you want to use Matrix-class matrices with "fda", you must 
explicitly say "returnMatrix = TRUE" for all the functions with that 
argument.



	  I mention these two together, if many others had experiences with S4 
similar to mine, it could help explain why using the Matrix package is 
still not transparent to the users, unlike similar features of Matlab.



 Thanks,
 Spencer

On 6/11/2012 2:45 AM, Ceci Tam wrote:

diag(n) is alright when n = 5e3, it took 0.7 sec on my machine for
diag(5e3). However, it's slow when n = 23000, diag(23000) took 15 sec

On 11 June 2012 17:43, Ceci Tam  wrote:


diag(n) is alright when n = 5e3, it took 0.7 sec on my machine for
diag(5e3). However, it's slow when n = 23000, diag(23000) took 15 sec

On 9 June 2012 06:32, R. Michael Weylandtwrote:


On Fri, Jun 8, 2012 at 5:31 PM, R. Michael Weylandt
  wrote:

For the matter and hand, you can probably get to it by simply trying
base:::diag. In this case, it's not too hard because what you're
seeing is the S4 generic that the Matrix package is defining _over_
the regular base function generic.

Sorry -- the regular base function is not a generic in this case.
Everything else still holds though. (Same tricks to find things work
with print which becomes both an S3 and S4 generic on loading Matrix)


More generally, going down the rabbit hole of S4:

As it suggests, first try

showMethods("diag")

and you'll see a long list of types. The parallel to the *.default
method is the one with signature "ANY" so you can try that:

getMethod("diag", "ANY")

which gets you where you need to be.

Hope this helps,
Michael

On Fri, Jun 8, 2012 at 5:11 PM, Spencer Graves
  wrote:

  How can one get the source code for diag?  I tried the following:



diag

standardGeneric for "diag" defined from package "base"

function (x = 1, nrow, ncol)
standardGeneric("diag")

Methods may be defined for arguments: x, nrow, ncol
Use  showMethods("diag")  for currently available ones.


  How can I look at the code past the methods dispatch?



methods('diag')

[1] diag.panel.splom
Warning message:
In methods("diag") : function 'diag' appears not to be generic


  So "diag" is an S4 generic.  I tried the following:



dumpMethods('diag', file='diag.R')
readLines('diag.R')

character(0)


  More generally, what do you recommend I read to learn about S4
generics?  I've read fair portions of Chambers (1998, 2008), which

produced

more frustration than enlightenment for me.


  Thanks,
  Spencer


On 6/8/2012 12:07 PM, Uwe Ligges wrote:

I quickly looked at it, and the difference comes from:

n<- 5e3
system.time(x<- array(0, c(n, n))) # from diag()
system.time(x<- matrix(0, n, n))   # from Rdiag()

Replaced in R-devel.

Best,
Uwe Ligges



On 07.06.2012 12:11, Spencer Graves wrote:

On 6/7/2012 2:27 AM, Rui Barradas wrote:

Hello,

To my great surprise, on my system, Windows 7, R 15.0, 32 bits, an R
version is faster!


I was also surprised, Windows 7, R 2.15.0, 64-bit



rbind(diag=t1, Rdiag=t2, ratio=t1/t2)

user.self sys.self elapsed user.child sys.child
diag 0.72 0.08 0.81 NA NA
Rdiag 0.09 0.03 0.12 NA NA
ratio 8.00 2.67 6.75 NA NA

sessionInfo()

R version 2.15.0 (2012-03-30)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

other attached packages:
[1] fda_2.2.9 Matrix_1.0-6 lattice_0.20-6 zoo_1.7-7

loaded via a namespace (

[R] strings concatenation and organization (fast)

2012-06-15 Thread Ben quant
Hello,

What is the fastest way to do this? I has to be done quite a few times.
Basically I have sets of 3 numbers (as characters) and sets of 3 dashes and
I have to store them in named columns. The order of the sets and the column
name they fall under is important. The actual numbers and the pattern/order
of the sets should be considered random/unpredictable.

Sample data:
vec = c("1","2","3","-","-","-","4","5","6","1","2","3","-","-","-")
rep_vec = rep(vec,times=20)
nms = c("A","B","C","D")

I need to get this:
  A B C D
"123" "---" "456" "123"
"---" "123" "---" "456"
"123" "---" "123" "---"
"456" "123" "---" "123"
"---" "456" "123" "---"

Note: a matrix of 4 columns and 5 rows of concatenated string sets.

Thanks!!

Ben

[[alternative HTML version deleted]]

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


[R] argument "x" is missing, with no default - Please help find argument x

2012-06-15 Thread dunner
R programming question, not machine learning, although that's the content.

Apologies to all for whom the following code is eye-burning. I am using
foreach() to run a simulation on a randomForest model (actually conditional
randomForest ... "party" package). The simulation is in two dimensions.
examining how "mtry" and "ntrees" are related in terms of predictive
accuracy in ten-fold cross validation.
My problem is one of functional programming. The "loops" for simulation are
functionalised so they can be passed to foreach and bundled of to my 4
cores. However, I'm making a mess of passing in arguments - I think. I get
the following error message :

Error in toploop(ntrees = ntrees, ml.frame = ml.frame) : 
  task 2 failed - "argument "x" is missing, with no default"

as if it couldn't see the arguments.

Long segment of actual code below.

Thank you for your time and patience.

Ross



bottomloop<-function(i=i, mtry=mtry, rownumber=rownumber, ntrees=ntrees,
shuffled=shuffled) {
  require(party)
  require(epiR)
  test<-rownumber[[i]]
  train<-shuffled[shuffled!=test]
  cv.train <- ml.frame[train,]
  cv.evaluate <- ml.frame[test,]
  cv.model <- cforest(as.factor(remitter)~., data=cv.train,
control=cforest_control(mtry=mtry, ntree=ntrees, mincriterion=0.95))
  cv.evaluate$prediction <- predict(cv.model, newdata=cv.evaluate)
  obj.pred<-predict(cv.model)
  pred.table<-table(cv.evaluate$prediction,  cv.evaluate$remitter)
  
  truepos<-pred.table[1,1]
  trueneg<-pred.table[2,2]
  falsepos<-pred.table[2,1]
  falseneg<-pred.table[1,2]
  sumvar<-epi.tests(c(truepos,  falsepos , falseneg, trueneg), verbose=T)
  epi.tests(c(truepos,  falsepos , falseneg, trueneg), verbose=F)
  # Calculate the overall accuracy.
  cv.evaluate$correct <- cv.evaluate$prediction == cv.evaluate$remitter
  mymean<-mean(cv.evaluate$correct)
  retlist<-data.frame(mtry, sumvar$se, sumvar$sp, mean(cv.evaluate$correct))
  return(retlist)
}

subloop<- function(mtry=mtry, ml.frame=ml.frame, ntrees=ntrees) {
  nfolds<- 10
  # shuffle the numbers and divide into 10 groups
  numberOfRows<-dim(ml.frame)[1]
  lengthOfDiv<-numberOfRows/nfolds
  shuffled<-sample(c(1:numberOfRows), numberOfRows, replace=F)
  rownumber<-split(shuffled, 1:nfolds)
  #combine mymean into my vec
  myvec<-foreach (i = 1:length(rownumber), .combine="rbind") %dopar%
bottomloop(i, mtry = mtry, rownumber=rownumber, ntrees=ntrees,
shuffled=shuffled)
  #print(myvec)
  return(myvec)
}

toploop <- function (ntrees=ntrees, ml.frame=ml.frame) {
  require(foreach)
  require(ggplot2)
  require(reshape)
  require(foreign)
  mtry = c(5:25)
  ddd<-foreach(mtry, .combine="rbind")  %dopar% subloop (mtry=mtry,
ml.frame=ml.frame, ntrees=10)
  ddd<-as.data.frame(ddd)
  mdd<-melt(ddd, id="mtry")
  g <- ggplot(mdd, aes(mtry, value))
  pdf(file=paste(ntrees, "-trees.pdf"))
  g + geom_point(aes(colour=as.factor(variable))) + 
geom_smooth(aes(group=as.factor(mdd$variable),
colour=as.factor(mdd$variable)), size=1.2)
  dev.off()
  write.csv(file=paste(ntrees, "-trees.csv"))
} 

ntrees=c(1,2,3)
foreach(ntrees, .combine="cbind" )  %dopar% toploop (ntrees=ntrees,
ml.frame=ml.frame)



> foreach(ntrees, .combine="cbind" )  %dopar% toploop (ntrees=ntrees,
> ml.frame=ml.frame)

bottomloop<-function(i=i, mtry=mtry, rownumber=rownumber, ntrees=ntrees,
shuffled=shuffled) {
  require(party)
  require(epiR)
  test<-rownumber[[i]]
  train<-shuffled[shuffled!=test]
  cv.train <- ml.frame[train,]
  cv.evaluate <- ml.frame[test,]
  cv.model <- cforest(as.factor(remitter)~., data=cv.train,
control=cforest_control(mtry=mtry, ntree=ntrees, mincriterion=0.95))
  cv.evaluate$prediction <- predict(cv.model, newdata=cv.evaluate)
  obj.pred<-predict(cv.model)
  pred.table<-table(cv.evaluate$prediction,  cv.evaluate$remitter)
  
  truepos<-pred.table[1,1]
  trueneg<-pred.table[2,2]
  falsepos<-pred.table[2,1]
  falseneg<-pred.table[1,2]
  sumvar<-epi.tests(c(truepos,  falsepos , falseneg, trueneg), verbose=T)
  epi.tests(c(truepos,  falsepos , falseneg, trueneg), verbose=F)
  # Calculate the overall accuracy.
  cv.evaluate$correct <- cv.evaluate$prediction == cv.evaluate$remitter
  mymean<-mean(cv.evaluate$correct)
  retlist<-data.frame(mtry, sumvar$se, sumvar$sp, mean(cv.evaluate$correct))
  return(retlist)
}

subloop<- function(mtry=mtry, ml.frame=ml.frame, ntrees=ntrees) {
  nfolds<- 10
  # shuffle the numbers and divide into 10 groups
  numberOfRows<-dim(ml.frame)[1]
  lengthOfDiv<-numberOfRows/nfolds
  shuffled<-sample(c(1:numberOfRows), numberOfRows, replace=F)
  rownumber<-split(shuffled, 1:nfolds)
  #combine mymean into my vec
  myvec<-foreach (i = 1:length(rownumber), .combine="rbind") %dopar%
bottomloop(i, mtry = mtry, rownumber=rownumber, ntrees=ntrees,
shuffled=shuffled)
  #print(myvec)
  return(myvec)
}

toploop <- function (ntrees=ntrees, ml.frame=ml.frame) {
  require(foreach)
  require(ggplot2)
  require(reshape)
  require(foreign)
  mtry = c(5:25)
  ddd<-foreach(mtry, .combine="rbind")  %dopar% subloop (

Re: [R] strings concatenation and organization (fast)

2012-06-15 Thread Phil Spector

Ben -
   There are most likely faster ways, but

matrix(apply(matrix(rep_vec,ncol=3,byrow=TRUE),1,paste,collapse=''),
   ncol=4,byrow=TRUE,dimnames=list(NULL,nms))

seems reasonably fast.   (Do you really mean 4 columns and *5* rows?
With rep_vec = rep(vec,times=20), I get 25 rows.)

- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu


On Fri, 15 Jun 2012, Ben quant wrote:


Hello,

What is the fastest way to do this? I has to be done quite a few times.
Basically I have sets of 3 numbers (as characters) and sets of 3 dashes and
I have to store them in named columns. The order of the sets and the column
name they fall under is important. The actual numbers and the pattern/order
of the sets should be considered random/unpredictable.

Sample data:
vec = c("1","2","3","-","-","-","4","5","6","1","2","3","-","-","-")
rep_vec = rep(vec,times=20)
nms = c("A","B","C","D")

I need to get this:
 A B C D
"123" "---" "456" "123"
"---" "123" "---" "456"
"123" "---" "123" "---"
"456" "123" "---" "123"
"---" "456" "123" "---"

Note: a matrix of 4 columns and 5 rows of concatenated string sets.

Thanks!!

Ben

[[alternative HTML version deleted]]

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



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


Re: [R] phyloclim help

2012-06-15 Thread David Winsemius


On Jun 15, 2012, at 3:43 PM, Brent Hendrixson wrote:



Hi David -


Looking at the package documentation I see this:

maxent: A list containing the location of the MAXENT application and
its input files (see
details).

Maybe I was wrong about 'spec' and the malformed argument is  
'maxent'.

If I had been constructing it I would have created a _named_ list:

maxent <- list( app =app,
samples =samples,
background, # cannot tell if a csv file meets the
requiremtn
# "The path to a SWD-formatted file with
background points."
projections =projections) # that value .../R looks
pretty suspicious, too.



Your advice definitely helped - THANK YOU!  However, I'm now getting  
another error that seems to be tied to the maxent java program  
itself.  Here's the syntax I have used for the  
niche.equivalency.test (recall that it consists of 4 elements: spec,  
n, maxent, mx=2000)


spec <- c("aphonopelma_mojave", "aphonopelma_newmojave")

app <- file.path("C:\\Documents and Settings\\hendrb\\Desktop\\R\ 
\maxent.jar")


samples <- file.path("C:\\Documents and Settings\\hendrb\\Desktop\\R\ 
\samples.csv")


background <- file.path("C:\\Documents and Settings\\hendrb\\Desktop\ 
\R\\background.csv")


projections <- file.path("C:\\Documents and Settings\\hendrb\\Desktop 
\\R")


maxent <- list(app=app, samples=samples, background=background,  
projections=projections)


After I defined each of those, I tried to execute the command as  
follows:


niche.equivalency.test(spec, n=100, maxent, mx=2000)

And here was the message I received:

Unable to access jarfile C:\Documents


That hanging "Documents" being listed as the file target makes me  
think that the file specification is creating errors due to spaces in  
Windows directories. In Windows it is often the case that backslashes  
need to be doubled or replaced with forward slashes.I see that you  
already know that, but would have tried the forward slash gambit as  
well. (I am not sure why you are passing hte results of file.path(...)  
when you already have a complete file name. I would also try just  
giving it a file specification with just a character argument.)




Error in file(file, "r") : cannot open the connection
In addition: Warning messages:
1: running command 'java -mx2000m -jar C:\Documents and Settings 
\hendrb\Desktop\R\maxent.jar -e R.phyloclim.temp/background.csv -s  
R.phyloclim.temp/samples.csv -j C:\Documents and Settings\hendrb 
\Desktop\R -o R.phyloclim.temp/out -r removeduplicates nopictures  
outputformat=raw autorun' had status 1

2: In file(file, "r") :
  cannot open file 'aphonopelma_mojave_C:\Documents and Settings 
\hendrb\Desktop\R.asc': Invalid argument


Like I mentioned, it seems that this particular error is unrelated  
to R code but I'm unsure why the jarfile (maxent.jar) cannot be  
accessed.


Any thoughts?

The above command did produce a new file that serves as the input  
for the jarfile.


Thanks again for your help!

Brent



David Winsemius, MD
West Hartford, CT

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


Re: [R] strings concatenation and organization (fast)

2012-06-15 Thread Rui Barradas

Hello,

Try


vec = c("1","2","3","-","-","-","4","5","6","1","2","3","-","-","-")
nms = c("A","B","C","D")
rep_vec <- rep(sapply(split(vec, cumsum(rep(c(1, 0, 0), 5))), paste, 
collapse=""), 4)

mat <- matrix(rep_vec, nrow=5, byrow=TRUE, dimnames=list(NULL,nms))
mat


Hope this helps,

Rui Barradas

Em 15-06-2012 21:11, Ben quant escreveu:

Hello,

What is the fastest way to do this? I has to be done quite a few times.
Basically I have sets of 3 numbers (as characters) and sets of 3 dashes and
I have to store them in named columns. The order of the sets and the column
name they fall under is important. The actual numbers and the pattern/order
of the sets should be considered random/unpredictable.

Sample data:
vec = c("1","2","3","-","-","-","4","5","6","1","2","3","-","-","-")
rep_vec = rep(vec,times=20)
nms = c("A","B","C","D")

I need to get this:
   A B C D
"123" "---" "456" "123"
"---" "123" "---" "456"
"123" "---" "123" "---"
"456" "123" "---" "123"
"---" "456" "123" "---"

Note: a matrix of 4 columns and 5 rows of concatenated string sets.

Thanks!!

Ben

[[alternative HTML version deleted]]

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



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


Re: [R] Wrong computation of time differenze in POSIXct - additional digits

2012-06-15 Thread peter dalgaard

On Jun 15, 2012, at 20:33 , Rui Barradas wrote:

> Hello,
> 
> A classic of floating-point accuracy is
> 
> > 3/5 - 3/5
> [1] 0
> > 3/5 - (2/5 + 1/5)
> [1] -1.110223e-16
> > 3/5 - 2/5 - 1/5
> [1] -5.551115e-17
> 
> Rui Barradas
> 

Yes. There are only about 16 significant digits in (64 bit) floating point. One 
further point is that times are stored internally as seconds since Jan 1 1970, 
of which there has been quite a few by now:

> unclass(Sys.time())
[1] 1339793894

with already 10 digits before the decimal point, you can only expect fractional 
seconds to be accurate to about 6 digits.

-pd


> Em 15-06-2012 18:18, David Winsemius escreveu:
>> 
>> On Jun 15, 2012, at 12:49 PM, Julia wrote:
>> 
>>> Hello,
>>> 
>>> I wanted to compute the time differenze between to times:
>>> 
>>> first =as.POSIXct( "2012-06-15 16:32:39.0025 CEST")
>>> second  = as.POSIXct("2012-06-15 16:32:39.0086 CEST")
>>> second - first
>>> 
>>> The result is
>>> Time difference of 0.006099939 secs
>>> 
>>> instead of just 0.0061 secs
>>> So R adds aditional  numbers after the result.
>> 
>> It's a floating point representation issue.  You don't really want to
>> change that value, but are asking to see something different:
>> 
>> > round ( second - first, 4)
>> Time difference of 0.0061 secs
>> 
>>> I know I could round it in this case.
>>> But I am working with a large data set and need to always get the
>>> correct result.
>>> 
>>> difftime() does not work correct either.
>>> 
>>> Has anybody a suggestion how to get the correct result?
>> 
>> Use a computer system that runs on exact arithmetic?
>> 
>> Read FAQ 7.31
>> http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f
>> 
>> 
>> (And expect to read about 4-6 similar messages in the next hour.)
>> 
>>> 
>>> Thank you
>>> Julia
>>> 
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>> 
>> David Winsemius, MD
>> West Hartford, CT
>> 
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
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] Trouble with .bat files upon installation of 15.0

2012-06-15 Thread Sarah Henderson
Thanks for your help -- you were absolutely correct.  And I apologize
for the poor nomenclature -- when referring to versions I always just
say 'fifteen' or 'twelve point one', so it is too easy to forget the
leading '2.' when typing.  Careless of me.

Cheers,

Sarah

> - Until June 8th I was running R 12.1

There never was an R 12.1 (nor 15.0). My guess is you mean R-2.12.1.

> - The same thing happened each day until yesterday when I broke down
> and re-installed R 12.1 again and changed the path back (C:\Program
> Files\R\R-2.12.1\bin\x64)
> - Everything ran perfectly smoothly this morning

Probably the scheduler runs under another user account / security level?
Please ask the vendor of that software.

Uwe Ligges



> I confess that I am baffled.  As far as I am aware the System
> Scheduler should simply act as a double-click on the .bat file at a
> specific time, but there is obviously something more to it than that.
> What have I missed?  I would like to get this sorted out, as I don't
> want to have this stuff tied to 12.1 indefinitely, especially as I am
> developing all new code in 15.0.
>
> Thanks for any help you can offer,
>
> Sarah

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


Re: [R] strings concatenation and organization (fast)

2012-06-15 Thread Ben quant
I'm checking out Phil's solution...so far so good.  Thanks! Yes, 25 not 5
rows, sorry about that.

Rui - I can't modify rep_vec...that's just sample data. I have to start
with rep_vec and go from there.

have a good weekend all...

Ben

On Fri, Jun 15, 2012 at 2:51 PM, Rui Barradas  wrote:

> Hello,
>
> Try
>
>
>
> vec = c("1","2","3","-","-","-","4",**"5","6","1","2","3","-","-","-**")
> nms = c("A","B","C","D")
> rep_vec <- rep(sapply(split(vec, cumsum(rep(c(1, 0, 0), 5))), paste,
> collapse=""), 4)
> mat <- matrix(rep_vec, nrow=5, byrow=TRUE, dimnames=list(NULL,nms))
> mat
>
>
> Hope this helps,
>
> Rui Barradas
>
> Em 15-06-2012 21:11, Ben quant escreveu:
>
>> Hello,
>>
>> What is the fastest way to do this? I has to be done quite a few times.
>> Basically I have sets of 3 numbers (as characters) and sets of 3 dashes
>> and
>> I have to store them in named columns. The order of the sets and the
>> column
>> name they fall under is important. The actual numbers and the
>> pattern/order
>> of the sets should be considered random/unpredictable.
>>
>> Sample data:
>> vec = c("1","2","3","-","-","-","4",**"5","6","1","2","3","-","-","-**")
>> rep_vec = rep(vec,times=20)
>> nms = c("A","B","C","D")
>>
>> I need to get this:
>>   A B C D
>> "123" "---" "456" "123"
>> "---" "123" "---" "456"
>> "123" "---" "123" "---"
>> "456" "123" "---" "123"
>> "---" "456" "123" "---"
>>
>> Note: a matrix of 4 columns and 5 rows of concatenated string sets.
>>
>> Thanks!!
>>
>> Ben
>>
>>[[alternative HTML version deleted]]
>>
>> __**
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/**
>> posting-guide.html 
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>

[[alternative HTML version deleted]]

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


Re: [R] phyloclim help

2012-06-15 Thread Brent Hendrixson

David -

You have been a tremendous help.  This solved my problems.  It's working now!  

I switched to forward slashes and changed the directory to "C:/R".  I tweaked 
the memory available to maxent and VOILA!

Thank you!!! 


> CC: r-help@r-project.org
> From: dwinsem...@comcast.net
> To: behendrix...@hotmail.com
> Subject: Re: [R] phyloclim help
> Date: Fri, 15 Jun 2012 16:45:51 -0400
>
>
> On Jun 15, 2012, at 3:43 PM, Brent Hendrixson wrote:
>
> >
> > Hi David -
> >
> >> Looking at the package documentation I see this:
> >>
> >> maxent: A list containing the location of the MAXENT application and
> >> its input files (see
> >> details).
> >>
> >> Maybe I was wrong about 'spec' and the malformed argument is
> >> 'maxent'.
> >> If I had been constructing it I would have created a _named_ list:
> >>
> >> maxent <- list( app =app,
> >> samples =samples,
> >> background, # cannot tell if a csv file meets the
> >> requiremtn
> >> # "The path to a SWD-formatted file with
> >> background points."
> >> projections =projections) # that value .../R looks
> >> pretty suspicious, too.
> >>
> >
> > Your advice definitely helped - THANK YOU! However, I'm now getting
> > another error that seems to be tied to the maxent java program
> > itself. Here's the syntax I have used for the
> > niche.equivalency.test (recall that it consists of 4 elements: spec,
> > n, maxent, mx=2000)
> >
> > spec <- c("aphonopelma_mojave", "aphonopelma_newmojave")
> >
> > app <- file.path("C:\\Documents and Settings\\hendrb\\Desktop\\R\
> > \maxent.jar")
> >
> > samples <- file.path("C:\\Documents and Settings\\hendrb\\Desktop\\R\
> > \samples.csv")
> >
> > background <- file.path("C:\\Documents and Settings\\hendrb\\Desktop\
> > \R\\background.csv")
> >
> > projections <- file.path("C:\\Documents and Settings\\hendrb\\Desktop
> > \\R")
> >
> > maxent <- list(app=app, samples=samples, background=background,
> > projections=projections)
> >
> > After I defined each of those, I tried to execute the command as
> > follows:
> >
> > niche.equivalency.test(spec, n=100, maxent, mx=2000)
> >
> > And here was the message I received:
> >
> > Unable to access jarfile C:\Documents
>
> That hanging "Documents" being listed as the file target makes me
> think that the file specification is creating errors due to spaces in
> Windows directories. In Windows it is often the case that backslashes
> need to be doubled or replaced with forward slashes.I see that you
> already know that, but would have tried the forward slash gambit as
> well. (I am not sure why you are passing hte results of file.path(...)
> when you already have a complete file name. I would also try just
> giving it a file specification with just a character argument.)
>
>
> > Error in file(file, "r") : cannot open the connection
> > In addition: Warning messages:
> > 1: running command 'java -mx2000m -jar C:\Documents and Settings
> > \hendrb\Desktop\R\maxent.jar -e R.phyloclim.temp/background.csv -s
> > R.phyloclim.temp/samples.csv -j C:\Documents and Settings\hendrb
> > \Desktop\R -o R.phyloclim.temp/out -r removeduplicates nopictures
> > outputformat=raw autorun' had status 1
> > 2: In file(file, "r") :
> > cannot open file 'aphonopelma_mojave_C:\Documents and Settings
> > \hendrb\Desktop\R.asc': Invalid argument
> >
> > Like I mentioned, it seems that this particular error is unrelated
> > to R code but I'm unsure why the jarfile (maxent.jar) cannot be
> > accessed.
> >
> > Any thoughts?
> >
> > The above command did produce a new file that serves as the input
> > for the jarfile.
> >
> > Thanks again for your help!
> >
> > Brent
> >
>
> David Winsemius, MD
> West Hartford, CT
>
  
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] strings concatenation and organization (fast)

2012-06-15 Thread Rui Barradas

Hello,

I didn't know rep_vec couldn't be modified, I thought vec was the main 
vector.

Revised.

vec = c("1","2","3","-","-","-","4","5","6","1","2","3","-","-","-")
rep_vec = rep(vec,times=20)
nms = c("A","B","C","D")
rv <- sapply(split(rep_vec, cumsum(rep(c(1, 0, 0), length(rep_vec)/3))), 
paste, collapse="")

mat <- matrix(rv, ncol=length(nms), byrow=TRUE, dimnames=list(NULL, nms))
mat

Rui Barradas

Em 15-06-2012 22:36, Ben quant escreveu:

I'm checking out Phil's solution...so far so good.  Thanks! Yes, 25 not
5 rows, sorry about that.

Rui - I can't modify rep_vec...that's just sample data. I have to start
with rep_vec and go from there.

have a good weekend all...

Ben

On Fri, Jun 15, 2012 at 2:51 PM, Rui Barradas mailto:ruipbarra...@sapo.pt>> wrote:

Hello,

Try



vec = c("1","2","3","-","-","-","4",__"5","6","1","2","3","-","-","-__")
nms = c("A","B","C","D")
rep_vec <- rep(sapply(split(vec, cumsum(rep(c(1, 0, 0), 5))), paste,
collapse=""), 4)
mat <- matrix(rep_vec, nrow=5, byrow=TRUE, dimnames=list(NULL,nms))
mat


Hope this helps,

Rui Barradas

Em 15-06-2012 21:11, Ben quant escreveu:

Hello,

What is the fastest way to do this? I has to be done quite a few
times.
Basically I have sets of 3 numbers (as characters) and sets of 3
dashes and
I have to store them in named columns. The order of the sets and
the column
name they fall under is important. The actual numbers and the
pattern/order
of the sets should be considered random/unpredictable.

Sample data:
vec =
c("1","2","3","-","-","-","4",__"5","6","1","2","3","-","-","-__")
rep_vec = rep(vec,times=20)
nms = c("A","B","C","D")

I need to get this:
   A B C D
"123" "---" "456" "123"
"---" "123" "---" "456"
"123" "---" "123" "---"
"456" "123" "---" "123"
"---" "456" "123" "---"

Note: a matrix of 4 columns and 5 rows of concatenated string sets.

Thanks!!

Ben

[[alternative HTML version deleted]]


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

PLEASE do read the posting guide
http://www.R-project.org/__posting-guide.html

and provide commented, minimal, self-contained, reproducible code.





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Save multiple plots in a single pdf file when the plots are generated by a single plot command

2012-06-15 Thread Debs Majumdar
Hi,

I am trying to save multiple plots in a single pdf file when  the plots are 
generated by a single plot command. I am using the "lordif" package which 
generates multiple plots with one command.

pdf("education.pdf") 
plot.lordif(ed_dif, labels = c("White", "African American"))
dev.off()

And this is not working at all. Thanks for your help.

Debs

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


Re: [R] Save multiple plots in a single pdf file when the plots are generated by a single plot command

2012-06-15 Thread R. Michael Weylandt
On Fri, Jun 15, 2012 at 4:39 PM, Debs Majumdar  wrote:
> Hi,
>
> I am trying to save multiple plots in a single pdf file when  the plots are 
> generated by a single plot command. I am using the "lordif" package which 
> generates multiple plots with one command.
>
> pdf("education.pdf")
> plot.lordif(ed_dif, labels = c("White", "African American"))
> dev.off()
>
> And this is not working at all. Thanks for your help.

What do you mean by this? Is it the file not being created? Or its
blank? Or you get the wrong output? Does it work to print to a screen
device but not a pdf? Etc.

Running the example in ?lordif, this works for me:

pdf("test.pdf")
plot(age.DIF)
dev.off()

What OS are you on and what version of R?

In short, happy to help, but we need (much) more information.

Michael

>
> Debs
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Save multiple plots in a single pdf file when the plots are generated by a single plot command

2012-06-15 Thread Debs Majumdar
I am using R 2.15.0 on Windows 7.

It shows the plots on the screen. I can page-up and page-down to look at the 
different plots. It's when I want to save the plot, I get a blank pdf file (0 
kb).

#
> pdf("education.pdf")
> plot(ed_dif, labels = c("White", "African American"))
> dev.off()
pdf 
  2 
> 
  




- Original Message -
From: R. Michael Weylandt 
To: Debs Majumdar 
Cc: "r-help@r-project.org" 
Sent: Friday, June 15, 2012 3:48 PM
Subject: Re: [R] Save multiple plots in a single pdf file when the plots are 
generated by a single plot command

On Fri, Jun 15, 2012 at 4:39 PM, Debs Majumdar  wrote:
> Hi,
>
> I am trying to save multiple plots in a single pdf file when  the plots are 
> generated by a single plot command. I am using the "lordif" package which 
> generates multiple plots with one command.
>
> pdf("education.pdf")
> plot.lordif(ed_dif, labels = c("White", "African American"))
> dev.off()
>
> And this is not working at all. Thanks for your help.

What do you mean by this? Is it the file not being created? Or its
blank? Or you get the wrong output? Does it work to print to a screen
device but not a pdf? Etc.

Running the example in ?lordif, this works for me:

pdf("test.pdf")
plot(age.DIF)
dev.off()

What OS are you on and what version of R?

In short, happy to help, but we need (much) more information.

Michael

>
> Debs
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Save multiple plots in a single pdf file when the plots are generated by a single plot command

2012-06-15 Thread R. Michael Weylandt
It looks like you have one too many pdf objects open. The "pdf 2" that
is printed indicates control was returned to another pdf device. Keep
doing dev.off() until you get the message "null device 1" and then try
it once again.

Best,
Michael

On Fri, Jun 15, 2012 at 6:06 PM, Debs Majumdar  wrote:
> I am using R 2.15.0 on Windows 7.
>
> It shows the plots on the screen. I can page-up and page-down to look at the 
> different plots. It's when I want to save the plot, I get a blank pdf file (0 
> kb).
>
> #
>> pdf("education.pdf")
>> plot(ed_dif, labels = c("White", "African American"))
>> dev.off()
> pdf
>   2
>>
> 
>
>
>
>
> - Original Message -
> From: R. Michael Weylandt 
> To: Debs Majumdar 
> Cc: "r-help@r-project.org" 
> Sent: Friday, June 15, 2012 3:48 PM
> Subject: Re: [R] Save multiple plots in a single pdf file when the plots are 
> generated by a single plot command
>
> On Fri, Jun 15, 2012 at 4:39 PM, Debs Majumdar  wrote:
>> Hi,
>>
>> I am trying to save multiple plots in a single pdf file when  the plots are 
>> generated by a single plot command. I am using the "lordif" package which 
>> generates multiple plots with one command.
>>
>> pdf("education.pdf")
>> plot.lordif(ed_dif, labels = c("White", "African American"))
>> dev.off()
>>
>> And this is not working at all. Thanks for your help.
>
> What do you mean by this? Is it the file not being created? Or its
> blank? Or you get the wrong output? Does it work to print to a screen
> device but not a pdf? Etc.
>
> Running the example in ?lordif, this works for me:
>
> pdf("test.pdf")
> plot(age.DIF)
> dev.off()
>
> What OS are you on and what version of R?
>
> In short, happy to help, but we need (much) more information.
>
> Michael
>
>>
>> Debs
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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] Save multiple plots in a single pdf file when the plots are generated by a single plot command

2012-06-15 Thread Debs Majumdar
I thought that might be the case and did a couple of dev.off() even though I 
started a new R session. Each time I try to use the plot, it comes up with "pdf 
2".



- Original Message -
From: R. Michael Weylandt 
To: Debs Majumdar 
Cc: "r-help@r-project.org" 
Sent: Friday, June 15, 2012 4:10 PM
Subject: Re: [R] Save multiple plots in a single pdf file when the plots are 
generated by a single plot command

It looks like you have one too many pdf objects open. The "pdf 2" that
is printed indicates control was returned to another pdf device. Keep
doing dev.off() until you get the message "null device 1" and then try
it once again.

Best,
Michael

On Fri, Jun 15, 2012 at 6:06 PM, Debs Majumdar  wrote:
> I am using R 2.15.0 on Windows 7.
>
> It shows the plots on the screen. I can page-up and page-down to look at the 
> different plots. It's when I want to save the plot, I get a blank pdf file (0 
> kb).
>
> #
>> pdf("education.pdf")
>> plot(ed_dif, labels = c("White", "African American"))
>> dev.off()
> pdf
>   2
>>
> 
>
>
>
>
> - Original Message -
> From: R. Michael Weylandt 
> To: Debs Majumdar 
> Cc: "r-help@r-project.org" 
> Sent: Friday, June 15, 2012 3:48 PM
> Subject: Re: [R] Save multiple plots in a single pdf file when the plots are 
> generated by a single plot command
>
> On Fri, Jun 15, 2012 at 4:39 PM, Debs Majumdar  wrote:
>> Hi,
>>
>> I am trying to save multiple plots in a single pdf file when  the plots are 
>> generated by a single plot command. I am using the "lordif" package which 
>> generates multiple plots with one command.
>>
>> pdf("education.pdf")
>> plot.lordif(ed_dif, labels = c("White", "African American"))
>> dev.off()
>>
>> And this is not working at all. Thanks for your help.
>
> What do you mean by this? Is it the file not being created? Or its
> blank? Or you get the wrong output? Does it work to print to a screen
> device but not a pdf? Etc.
>
> Running the example in ?lordif, this works for me:
>
> pdf("test.pdf")
> plot(age.DIF)
> dev.off()
>
> What OS are you on and what version of R?
>
> In short, happy to help, but we need (much) more information.
>
> Michael
>
>>
>> Debs
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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] (no subject)

2012-06-15 Thread Michael Sumner
Very sorry, this was just clumsy fingers on the bike/phone.

No email was intended, please excuse my noise.

Cheers, Mike


On Friday, June 15, 2012, Michael Sumner wrote:

> --
> Michael Sumner
> Hobart, Australia
> e-mail: mdsum...@gmail.com 
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org  mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Michael Sumner
Hobart, Australia
e-mail: mdsum...@gmail.com

[[alternative HTML version deleted]]

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


Re: [R] DEoptim example illustrating use of fnMap parameter for enforcement of cardinality constraints

2012-06-15 Thread Joshua Ulrich
Hi David,

I apologize for the lack of documentation.  I added it quickly and
didn't have adequate time to document it.

The function below works with the objective function in the
"Large-scale portfolio optimization with DEoptim" vignette.
Also, I just committed the full example
(pkg/DEoptim/sandbox/slimLargeN_map.R) to the DEoptim repository on
R-forge: https://r-forge.r-project.org/projects/deoptim/

mappingFun <- function(x) {
  x[which(order(x) < 6)] <- 0
  x <- round(x,2) # produce some dups
  x/sum(x)
}
set.seed(1234)
out <- DEoptim(fn=obj, lower=lower,
  upper=upper, control=controlDE, fnMap=mappingFun)

Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com


On Fri, Jun 15, 2012 at 3:24 AM, David-Michael Lincke
 wrote:
> Function DEoptim in package DEoptim for differential evolution defines an 
> optional parameter fnMap:
>
> fnMap
>
> "an optional function that will be run after each population is created, but 
> before the population is passed to the objective function. This allows the 
> user to impose integer/cardinality constriants."
>
> Unfortunately, there is no further documentation decribing the kind of 
> parameters being passed to this function on invocation or the structure of 
> the return value expected. I would very much appreciate it if somebody 
> familiar with this package could provide an example illustrating how this 
> interface is meant to be used to enforce cardinality constraints.
>
> Thanks,
> David
>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Save multiple plots in a single pdf file when the plots are generated by a single plot command

2012-06-15 Thread Jim Holtman
the other command to use is

graphics.off()

Sent from my iPad

On Jun 15, 2012, at 19:14, Debs Majumdar  wrote:

> I thought that might be the case and did a couple of dev.off() even though I 
> started a new R session. Each time I try to use the plot, it comes up with 
> "pdf 2".
> 
> 
> 
> - Original Message -
> From: R. Michael Weylandt 
> To: Debs Majumdar 
> Cc: "r-help@r-project.org" 
> Sent: Friday, June 15, 2012 4:10 PM
> Subject: Re: [R] Save multiple plots in a single pdf file when the plots are 
> generated by a single plot command
> 
> It looks like you have one too many pdf objects open. The "pdf 2" that
> is printed indicates control was returned to another pdf device. Keep
> doing dev.off() until you get the message "null device 1" and then try
> it once again.
> 
> Best,
> Michael
> 
> On Fri, Jun 15, 2012 at 6:06 PM, Debs Majumdar  wrote:
>> I am using R 2.15.0 on Windows 7.
>> 
>> It shows the plots on the screen. I can page-up and page-down to look at the 
>> different plots. It's when I want to save the plot, I get a blank pdf file 
>> (0 kb).
>> 
>> #
>>> pdf("education.pdf")
>>> plot(ed_dif, labels = c("White", "African American"))
>>> dev.off()
>> pdf
>>   2
>>> 
>> 
>> 
>> 
>> 
>> 
>> - Original Message -
>> From: R. Michael Weylandt 
>> To: Debs Majumdar 
>> Cc: "r-help@r-project.org" 
>> Sent: Friday, June 15, 2012 3:48 PM
>> Subject: Re: [R] Save multiple plots in a single pdf file when the plots are 
>> generated by a single plot command
>> 
>> On Fri, Jun 15, 2012 at 4:39 PM, Debs Majumdar  wrote:
>>> Hi,
>>> 
>>> I am trying to save multiple plots in a single pdf file when  the plots are 
>>> generated by a single plot command. I am using the "lordif" package which 
>>> generates multiple plots with one command.
>>> 
>>> pdf("education.pdf")
>>> plot.lordif(ed_dif, labels = c("White", "African American"))
>>> dev.off()
>>> 
>>> And this is not working at all. Thanks for your help.
>> 
>> What do you mean by this? Is it the file not being created? Or its
>> blank? Or you get the wrong output? Does it work to print to a screen
>> device but not a pdf? Etc.
>> 
>> Running the example in ?lordif, this works for me:
>> 
>> pdf("test.pdf")
>> plot(age.DIF)
>> dev.off()
>> 
>> What OS are you on and what version of R?
>> 
>> In short, happy to help, but we need (much) more information.
>> 
>> Michael
>> 
>>> 
>>> Debs
>>> 
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>> 
> 
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


  1   2   >