[R] nls: singular convergeance

2011-10-12 Thread Redding, Matthew
Dear R-experts, 

I have 28 data points that I would like to fit with a non linear
broken-stick -- with three fitted parameters.
When I view trace -- and use the final values as lines on the graph of
data -- it looks pretty good.

Q1. Why am I getting singular convergeance?
Q2. Can you suggest another approach that may prove more satisfying?

I have read previous examples on nls and this sort of error on the list,
but can't find anything completely comparable.
Unfortunately the brocken stick function is a bit lengthy, but I have
cut down my example as much as possible.

Input
t <- c(  0.00,  1.05,  2.13,
3.20,4.27,5.35,6.416667,

7.48,14.016667,15.13,16.18,17.30,18.40,19.47
,20.55,21.616667,22.716667,23.80,30.35,31.43,32.53
,33.616667,34.70,35.78,36.90,38.00,39.08,40.17)

seg_an <-c(
357.0466,360.5417,364.7510,368.8358,373.5498,377.2899,380.8858,385.9601
,420.2834,438.3807,453.9618,473.7764,493.0898,513.0759,531.1967,549.5310
,564.8920,584.8651,670.3014,674.2099,677.9492,680.5667,684.3941,688.2404
,690.7223,693.3406,697.9022,700.6606)


trans <-  13.38
trans2 <- 28.53
estCd <- 1975
estConst1 <- 0.00115689
estExch <- 0.00171680
Cb <- 330.1
Cmin <- 357
Ci <- 101000
R <- 0.001104768
A <- 16
V <- 8


rismod <- nls(seg_an ~ crv5(t, R, exch, trans, trans2, Cd, const1, 
Cmin, Cb, A, V, Ci, Cmin.new), start = list(Cd = estCd, const1 =
estConst1, 
 exch = estExch), lower = c(100, 1e-05, 0), 
 upper = c(5, 1, 0.0359), algorithm = "port", trace=TRUE)

plot(t, seg_an)
lines(t, crv5((t, R, 0.00182669, trans, trans2, 1976.6, 0.00115723,
Cmin, Cb, A, V, Ci, Cmin.new))


Output:

> rismod <- nls(seg_an ~ crv5(t, R, exch, trans, trans2, Cd, const1, 
+ Cmin, Cb, A, V, Ci, Cmin.new), start = list(Cd = estCd, const1 =
estConst1, 
+ exch = estExch), lower = c(100, 1e-05, 0), 
+ upper = c(5, 1, 0.0359), algorithm = "port", trace=TRUE)
  0: 15.566264:  1975.00 0.00115689 0.00171680
  1: 15.513993:  1983.53 0.00115234 0.00190479
  2: 15.513949:  1979.94 0.00115487 0.00186440
  3: 15.513949:  1976.35 0.00115739 0.00182390
  4: 15.513946:  1978.15 0.00115613 0.00184450
  5: 15.513946:  1976.35 0.00115739 0.00182418
  6: 15.513946:  1977.25 0.00115676 0.00183432
  7: 15.513946:  1976.80 0.00115707 0.00182908
  8: 15.513946:  1976.58 0.00115723 0.00182669
  9: 15.513946:  1976.58 0.00115723 0.00182669
 10: 15.513946:  1976.58 0.00115723 0.00182669
Error in nls(seg_an ~ crv5(t, R, exch, trans, trans2, Cd, const1, Cmin,
: 
  Convergence failure: singular convergence (7)


crv5 function:


crv5 <- function(t, R, exch, trans, trans2, Cd, const1, Cmin=340,
Cb=325, A=16, V=8, Ci=93000, Cmin.new=NA) {
#function for broken stick nls regression, which joins to the three
#curves as a single function -- native emission rise and native+tracer
gas emission rise
pt1 <-
exp(-(t*(0+const1*A+exch))/V)*(((Ci*0+const1*Cd*A+Cb*exch)
*exp((t*(0+const1*A+exch))/V))/

(0+const1*A+exch)+((Cmin-Ci)*0+(const1*Cmin-const1*Cd)*A+(Cmin-Cb)*exch)
/(0+const1*A+exch))

if(is.na(Cmin.new)){
Cmin.new <- 

exp(-(trans*(0+const1*A+exch))/V)*(((Ci*0+const1*Cd*A+Cb*exch)
*exp((trans*(0+const1*A+exch))/V))/

(0+const1*A+exch)+((Cmin-Ci)*0+(const1*Cmin-const1*Cd)*A+(Cmin-Cb)*exch)
/(0+const1*A+exch))
}
t.new <- t - trans

pt2 <- 

exp(-(t.new*(R+const1*A+exch))/V)*(((Ci*R+const1*Cd*A+Cb*exch)
*exp((t.new*(R+const1*A+exch))/V))/

(R+const1*A+exch)+((Cmin.new-Ci)*R+(const1*Cmin.new-const1*Cd)*A+(Cmin.n
ew-Cb)*exch)/(R+const1*A+exch))

Cmin.new2 <-   

exp(-((trans2-trans)*(R+const1*A+exch))/V)*(((Ci*R+const1*Cd*A+Cb*exch)
*exp(((trans2-trans)*(R+const1*A+exch))/V))/

(R+const1*A+exch)+((Cmin.new-Ci)*R+(const1*Cmin.new-const1*Cd)*A+(Cmin.n
ew-Cb)*exch)/(R+const1*A+exch))

t.new <- t - trans2

pt3 <-
exp(-(t.new*(0+const1*A+exch))/V)*(((Ci*0+const1*Cd*A+Cb*exch)
*exp((t.new*(0+const1*A+exch))/V))/

(0+const1*A+exch)+((Cmin.new2-Ci)*0+(const1*Cmin.new2-const1*Cd)*A+(Cmin
.new2-Cb)*exch)/(0+const1*A+exch))  

res <- pt1*(t <=trans) + pt2 * ((t > trans) &  (t <= trans2)) +
pt3 * (t > trans2)
return(res)

}




Thanks for your help.

Kind regards,



Matt Redding
We're behind the Bid!
GOLD COAST 2018 - XXI COMMONWEALTH GAMES CANDIDATE CITY
www.goldcoast2018bid.com

DISCLAIMER**...{{dropped:15}}

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

2011-10-12 Thread Sasso Kocovski
Hi, hopefully you can help me out - thanks in advance.

I would like to assign variable (or vectors) names dynamically, hence, after
you assign the number of new vectors then they populate for use later in the
algorithm.  Below is an example:

n<-5
for (i in (1:n)) {
vector_i <- c(1:10)
}

Here what I am trying to do is create n=5 vectors (vector_1, vector_2,
vector_3, vector_4, vector_5) that I will use later in my algorithm.  I
don't want to create a matrix because I will use these in a time series
later and the vectors will be of different length, where having '0' will
produce wrong results.  This may not be possible in R, if so you can also
save me time of trying to figure this out on my own.

Thanks for your help,
Sasso

[[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] Simple Effects Analysis for ANOVA

2011-10-12 Thread robcinm
For an ANOVA class assignment, we are doing post-hoc tests for interactions.
For simple effect analysis on an interaction, I went through a really
convoluted process to get my statistics and want to know if there is a more
straightforward way.
 
I have a 3x2 design with self-concept 1:3 (low, moderate, high) and gender
1:2 (male, female). For the assignment, I am checking to see the influence
of interaction on some arbitrary score (the data is all made up for the sake
of the assignment). 

The first step I took was to create my data frame and then do an omnibus
F-test and check to see whether or not interaction is statistically
significant.

summary(aov(srl ~ gender * selfconcept, data=data))

The interaction is statistically significant. I plotted the interaction and
decided to do a simple effect analysis. This is where I was stuck. I am a
first year graduate student and very much an R novice. I am learning as I go
through my statistics classes so even though I am optimistic, this is a
rough to learn. I decided to create subsets of self-concept and test
post-hoc through one a series of one-way ANOVAs.

Low <- subset(data, selfconcept=="low")
Moderate <- subset(data, selfconcept=="moderate")
High <- subset(data, selfconcept=="high")

And then…

summary(aov(srl ~ gender, data=Low))
summary(aov(srl ~ gender, data=Moderate))
summary(aov(srl ~ gender, data=High))

This worked…kind of. It gave me the between groups mean square I needed but
an inaccurate error (for my purposes anyhow). I got the omnibus error term,
calculated the F ratio and used the F-table out of the book to determine
significance.

There is probably a much better and more efficient way of doing this, and I
need the advice of somebody who is much cleverer with R than I.


--
View this message in context: 
http://r.789695.n4.nabble.com/Simple-Effects-Analysis-for-ANOVA-tp3900635p3900635.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] KS test

2011-10-12 Thread anuradha guru
Hi!

how can I do the Kolmogorov Smirnov test for discrepancy between the
estimated and empirical tails?

Regards
Anuradha

[[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 R plots

2011-10-12 Thread Jeff Newmiller
All complete newbies should read the posting guide referenced at the bottom of 
every message. One of the rules mentioned there is that this is not the 
appropriate venue for homework questions, since you have an instructor to get 
you up to speed. When you finish the course and are familiar with the posting 
guide, we will still be here, and you won't need to apologize for being a 
newbie.

Tips: use the question mark shortcut to get help on functions, and read the 
"Introduction to R" pdf carefully.
---
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.

Jonathan Edwin  wrote:

Hi all,

Mind my ignorance and complete newbiness, but I am very new to R and am
currently learning it through my stats course at university.
My question is regarding adding titles to plots. I'll post the code below,
and then explain my issue:

> hist(gender$HeartRate)
> title(Histogram: HeartRate distribution for Temperature Data)

So what R has done, is paste over the title I entered above over the generic
title that was already there. Does anyone know how to remove the old title
so that only the one I want shows? Also help with editting the X and Y axis
titles would be great!

Cheers,
Jonathan
--

[[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] Comparing the components of a data frame without levels interfering

2011-10-12 Thread Jeff Newmiller
Factors include a comprehensive list of all possible values they can assume. 
Your name columns have different numbers of names, so they are really very 
different factors. The best solution for you is to convert those columns to 
character.

You also ought to learn how to use the merge function before you write much 
code like your example.
---
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.

swonder03  wrote:

*Bottom Line: How can I compare the individual components of two data frames
with different row lengths without the levels interfering?*

Example: I have two data frames to those respectively named 'dfCity' and
'dfState' that have the following output:

dfCity

Name City 
1 Bill Detroit 
2 Jody Chicago
3 Frank Memphis 
4 Ron Houston 

dfState

Name State
1 Bill Michigan
2 Frank Tennessee 

I have an if statement that is trying to compare the individual's names and
combine the data from the two different data frames to produce some output: 

for(j in 1:length(row.names(dfState))){
for(k in 1:length(row.names(dfCity))){
if(dfCity[k,1] == dfState[j,1]){
cityState <- paste(dfCity[k,2], ", ", 
dfState[j,2], sep= "") 
print(dfCity[1, j], " is from ", 
cityState)
}
}
}

However, when I run it I get the error /Error in Ops.factor(dfState[2, 1],
dfCity[4, 1]) : level sets of factors are different/ due to the levels in
the data frames. *How can I compare the individual components of the data
frame without the levels interfering? *

--
View this message in context: 
http://r.789695.n4.nabble.com/Comparing-the-components-of-a-data-frame-without-levels-interfering-tp3900502p3900502.html
Sent from the R help mailing list archive at Nabble.com.

_

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


[[alternative HTML version deleted]]

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


Re: [R] Comparing the components of a data frame without levels interfering

2011-10-12 Thread Petr PIKAL
Hi


> *Bottom Line: How can I compare the individual components of two data 
frames
> with different row lengths without the levels interfering?*
> 
> Example: I have two data frames to those respectively named 'dfCity' and
> 'dfState' that have the following output:
> 
> dfCity
> 
>  Name   City 
> 1BillDetroit 
> 2Jody  Chicago
> 3FrankMemphis 
> 4Ron   Houston 
> 
> dfState
> 
>  Name   State
> 1BillMichigan
> 2FrankTennessee 
> 
> I have an if statement that is trying to compare the individual's names 
and
> combine the data from the two different data frames to produce some 
output: 
> 
> for(j in 1:length(row.names(dfState))){
>  for(k in 1:length(row.names(dfCity))){
> if(dfCity[k,1] == dfState[j,1]){
>cityState <- paste(dfCity[k,2], ", ", dfState[j,2], sep= 
"") 
>print(dfCity[1, j], " is from ", cityState)
> }
>  }
>   }

What about first merge two data frames

mergedDF <- merge(dfCity, dfState, all=TRUE)

and after that you can do

cityState <- paste(mergedDF$City, ", ", mergedDF$State, sep= "")

or anything you want.

Regards
Petr

> 
> However, when I run it I get the error /Error in Ops.factor(dfState[2, 
1],
> dfCity[4, 1]) : level sets of factors are different/ due to the levels 
in
> the data frames. *How can I compare the individual components of the 
data
> frame without the levels interfering? *
> 
> --
> View this message in context: 
http://r.789695.n4.nabble.com/Comparing-the-
> 
components-of-a-data-frame-without-levels-interfering-tp3900502p3900502.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] Package snow: is there any way to check if a cluster is "acticve"

2011-10-12 Thread Søren Højsgaard
Is there a 'proper' way of checking if cluster is active. For example, I create 
a cluster called .PBcluster

> str(.PBcluster)
List of 4
 $ :List of 3
  ..$ con :Classes 'sockconn', 'connection'  atomic [1:1] 3
  .. .. ..- attr(*, "conn_id")= 
  ..$ host: chr "localhost"
  ..$ rank: int 1
  ..- attr(*, "class")= chr "SOCKnode"
 $ :List of 3


Then I stop it with 
> stopCluster(.PBcluster)
> .PBcluster
[[1]]
$con
Error in summary.connection(x) : invalid connection

> str(.PBcluster)
List of 4
 $ :List of 3
  ..$ con :Classes 'sockconn', 'connection'  atomic [1:1] 3
  .. .. ..- attr(*, "conn_id")= 
  ..$ host: chr "localhost"
  ..$ rank: int 1
  ..- attr(*, "class")= chr "SOCKnode"

- but is there a way in which I can check if the cluster is active??

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


Re: [R] pass an element in a list() from R to C

2011-10-12 Thread teazrq
so, I did this:

B= list("a" = 1, "b" = 2, "c" = 3)

.C("myfunction", B)


the c code is :

SEXP myfunction(SEXP matrix_temp)
{
Rprintf("this element is %6.3f", REAL(VECTOR_ELT(matrix_temp,1))[0]);
}

but after runing the R code, it says Error: VECTOR_ELT() can only be applied
to a 'list', not a 'NULL'
I guess this is because I did not acturally pass a list to the c function,
but why is that?

--
View this message in context: 
http://r.789695.n4.nabble.com/pass-an-element-in-a-list-from-R-to-C-tp3900221p3900426.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] plot probability density function (pdf)

2011-10-12 Thread pigpigmeow
thank you all of u

--
View this message in context: 
http://r.789695.n4.nabble.com/plot-probability-density-function-pdf-tp3897055p3900396.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] Comparing the components of a data frame without levels interfering

2011-10-12 Thread swonder03
*Bottom Line: How can I compare the individual components of two data frames
with different row lengths without the levels interfering?*

Example: I have two data frames to those respectively named 'dfCity' and
'dfState' that have the following output:

dfCity
 
 Name   City 
1BillDetroit 
2Jody  Chicago
3FrankMemphis 
4Ron   Houston 

dfState

 Name   State
1BillMichigan
2FrankTennessee  

I have an if statement that is trying to compare the individual's names and
combine the data from the two different data frames to produce some output: 
 
for(j in 1:length(row.names(dfState))){
for(k in 1:length(row.names(dfCity))){
if(dfCity[k,1] == dfState[j,1]){
cityState <- paste(dfCity[k,2], ", ", 
dfState[j,2], sep= "") 
print(dfCity[1, j], " is from ", 
cityState)
}
}
}

However, when I run it I get the error /Error in Ops.factor(dfState[2, 1],
dfCity[4, 1]) : level sets of factors are different/ due to the levels in
the data frames. *How can I compare the individual components of the data
frame without the levels interfering? *

--
View this message in context: 
http://r.789695.n4.nabble.com/Comparing-the-components-of-a-data-frame-without-levels-interfering-tp3900502p3900502.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to transfer the variable into function in this code?

2011-10-12 Thread R. Michael Weylandt
As provided, the function you give doesn't actually do anything, it
only defines some subfunctions which are removed upon completion of
the function call. If that were the actual function, you would be
right to be confused, but the provided code doesn't give the proper
context to the problem.

You seem to be interested in the workings of get_quantiles() from the
COSINE package. If you look at the whole code for the function, you'll
see that the subfunctions are only defined at the beginning of
get_quantiles() but are later called directly with specific arguments.
Since the definitions don't require values and only use the name
"vector" as a placeholder, the question of how a value is attained is
actually put off till later in the function. Specifically, line 6
calls my.fun on each column of edges, which is merely a vector, while
line 24 calls node_edge on the variable vector defined immediately
preceeding.

Does this clarify things?

As an aside, I personally think it's not the best practice to use
vector as an argument name, but here it's not a problem.

Michael

On Wed, Oct 12, 2011 at 4:28 PM, xingxing  wrote:
> as shown in the code, four variables input: diff_expr,diff_coex, klist,
> Pop_size, are included in the function. However, within the function,
> another variable "vector" is utilized in some subfunction. How they get its
> value?
>
> thx
>
> get_quantiles <-function(diff_expr,diff_coex,klist,pop_size){
>
> # The function to get the "node_score_term" and "edge_score_term" of a
> sub-network denoted by "vector"
>
> my.fun<-function(vector){
> return(diff_coex[vector[1],vector[2]])
> }
>
> # "vector" is a binary vector with length equal to the size of the whole
> network.
> # An element of value "1" indicates the inclusion of that gene in the
> selected sub-network.
>
>
> node_edge<-function(vector){
>    selected_subset<-which(vector==1)
>    n<-length(selected_subset)
>    node_score<-sum(diff_expr[selected_subset])/sqrt(n)
>    edges<-combn(selected_subset,2)
>    edge_score<-sum(apply(edges,2,my.fun))/sqrt(choose(n,2))
>    return(c(node_score,edge_score))
> }
> }
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/How-to-transfer-the-variable-into-function-in-this-code-tp3899576p3899576.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 and Forex

2011-10-12 Thread Joshua Ulrich
Yves and Michael,

R-devel is the place for programming questions that would be confusing
to most people who follow R-help.  Posting to R-devel would make sense
if you've written socket connections between applications in other
languages and are having trouble sorting out how to do it in R.

If you've never written a socket connection before, R-devel is not the
right place to post.  Skim the posts over the past few weeks to get a
feel for the level of discussion.  That should help you decide if your
question fits.  Stack Overflow is another good resource for that weird
middle-ground between R-help and R-devel.

Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com



On Wed, Oct 12, 2011 at 9:05 PM, R. Michael Weylandt
  wrote:
> To be honest, I don't frequently have occasion to wander over to R-devel and 
> most of what goes on over there is over my level of easy-readability but I'd 
> feel pretty confident that anything involving interface to another program on 
> a socket or lower level is squarely their territory while file-reading and up 
> is R-help, based on what I've seen. The moderators may wish to correct me.
>
> I'm happy to spitball ideas privately and you have my email, but I'm not 
> qualified to make specific feasibility assessments on the record so I'll have 
> to punt if you want official answers.
>
> Michael
>
> On Oct 12, 2011, at 9:49 PM, "Yves S. Garret"  
> wrote:
>
>> I'm a little vague on what constitutes r-help and r-devel lists in terms of 
>> what questions to ask and where.  I read a little bit that this list was 
>> about design and what you could do in R, but coding should be in r-devel.  
>> If I'm wrong, please clarify.
>>
>> On Wed, Oct 12, 2011 at 9:12 PM, R. Michael Weylandt 
>>   wrote:
>> I suppose you could, contingent on the broker end's functionality, and R 
>> does provide some socket support (see ?make.socket and ?connections among 
>> others) but I suspect your question is entering the domain of the R-devel 
>> list where the experts on the nitty gritty could give you better answers 
>> than I can.
>>
>> Michael
>>
>>
>> On Oct 12, 2011, at 8:38 PM, "Yves S. Garret"  
>> wrote:
>>
>>> Don't see myself making 'real-time' trades.  Most likely a few times an 
>>> hour.  Oh, can't you make a socket to another app in R?  That would be my 
>>> first approach.
>>>
>>> On Wed, Oct 12, 2011 at 6:53 PM, R. Michael Weylandt 
>>>  wrote:
>>> Just a comment on the lack of a direct R API for non-IBrokers
>>> brokerages: of course its possible to put something together using
>>> rJava or a direct C interface, but it's not the smoothest thing if
>>> you've never delved into the R internals and it's not quite the
>>> fastest thing in the world if you are doing particularly
>>> time-sensitive work. At lower frequencies, this becomes less of an
>>> issue and simple work-arounds like using a csv file as an intermediate
>>> can make everything much easier.
>>>
>>> On the other end of the trade process, once you start getting into
>>> more HF domains, there's also the inverse problem of real-time
>>> processing: I'm not particularly interested in the question so I
>>> haven't thought much about it, but I don't see a particularly R-ish
>>> way to deal with a live data feed, though it's been dealt with in the
>>> R-SIG-Finance archives a couple of times.
>>>
>>> Michael
>>>
>>> On Wed, Oct 12, 2011 at 5:56 PM, Yves S. Garret
>>>  wrote:
>>> > Also, when you say to do the trading aspect is more difficult, what do you
>>> > mean exactly?  Are there performance issues with the code tasked to do the
>>> > trades?  Lack of API?  Or is it just a pain to put something coherent
>>> > together that will do the trades?
>>> >
>>> > On Wed, Oct 12, 2011 at 3:07 PM, R. Michael Weylandt
>>> >  wrote:
>>> >>
>>> >> As was pointed out to you before, this is really more of an
>>> >> R-SIG-Finance question, but I wouldn't expect too much explanation
>>> >> there either, just people pointing you to the standard R finance tools
>>> >> (quantmod, zoo/xts, TTR, RBloomberg, and the Rmetrics suite; there's
>>> >> also some fantastic tools in development but if you just picked up
>>> >> your first book on R, you probably aren't ready for those yet).
>>> >>
>>> >> You question isn't particularly well-defined either:
>>> >>
>>> >> Do you just want to study currency price series in R? This is simple:
>>> >> just get the data (perhaps from oanda using quantmod::getSymbols or
>>> >> simply by reading in through any of the regular functions) and study
>>> >> it however you like.
>>> >>
>>> >> The actual act of trading, however, is harder to do solely within R:
>>> >> there is a very popular IBrokers API but I haven't used it much. It
>>> >> sounds like you are probably a lone trader so if you don't have a
>>> >> pre-existing relationship with IBrokers you'll probably want to enter
>>> >> trades through whichever broker you currently use. That -- the
>>> >> IBrokers package -- is the complete only solution on th

Re: [R] R and Forex

2011-10-12 Thread R. Michael Weylandt
To be honest, I don't frequently have occasion to wander over to R-devel and 
most of what goes on over there is over my level of easy-readability but I'd 
feel pretty confident that anything involving interface to another program on a 
socket or lower level is squarely their territory while file-reading and up is 
R-help, based on what I've seen. The moderators may wish to correct me. 

I'm happy to spitball ideas privately and you have my email, but I'm not 
qualified to make specific feasibility assessments on the record so I'll have 
to punt if you want official answers. 

Michael

On Oct 12, 2011, at 9:49 PM, "Yves S. Garret"  
wrote:

> I'm a little vague on what constitutes r-help and r-devel lists in terms of 
> what questions to ask and where.  I read a little bit that this list was 
> about design and what you could do in R, but coding should be in r-devel.  If 
> I'm wrong, please clarify.
> 
> On Wed, Oct 12, 2011 at 9:12 PM, R. Michael Weylandt 
>   wrote:
> I suppose you could, contingent on the broker end's functionality, and R does 
> provide some socket support (see ?make.socket and ?connections among others) 
> but I suspect your question is entering the domain of the R-devel list where 
> the experts on the nitty gritty could give you better answers than I can. 
> 
> Michael
> 
> 
> On Oct 12, 2011, at 8:38 PM, "Yves S. Garret"  
> wrote:
> 
>> Don't see myself making 'real-time' trades.  Most likely a few times an 
>> hour.  Oh, can't you make a socket to another app in R?  That would be my 
>> first approach.
>> 
>> On Wed, Oct 12, 2011 at 6:53 PM, R. Michael Weylandt 
>>  wrote:
>> Just a comment on the lack of a direct R API for non-IBrokers
>> brokerages: of course its possible to put something together using
>> rJava or a direct C interface, but it's not the smoothest thing if
>> you've never delved into the R internals and it's not quite the
>> fastest thing in the world if you are doing particularly
>> time-sensitive work. At lower frequencies, this becomes less of an
>> issue and simple work-arounds like using a csv file as an intermediate
>> can make everything much easier.
>> 
>> On the other end of the trade process, once you start getting into
>> more HF domains, there's also the inverse problem of real-time
>> processing: I'm not particularly interested in the question so I
>> haven't thought much about it, but I don't see a particularly R-ish
>> way to deal with a live data feed, though it's been dealt with in the
>> R-SIG-Finance archives a couple of times.
>> 
>> Michael
>> 
>> On Wed, Oct 12, 2011 at 5:56 PM, Yves S. Garret
>>  wrote:
>> > Also, when you say to do the trading aspect is more difficult, what do you
>> > mean exactly?  Are there performance issues with the code tasked to do the
>> > trades?  Lack of API?  Or is it just a pain to put something coherent
>> > together that will do the trades?
>> >
>> > On Wed, Oct 12, 2011 at 3:07 PM, R. Michael Weylandt
>> >  wrote:
>> >>
>> >> As was pointed out to you before, this is really more of an
>> >> R-SIG-Finance question, but I wouldn't expect too much explanation
>> >> there either, just people pointing you to the standard R finance tools
>> >> (quantmod, zoo/xts, TTR, RBloomberg, and the Rmetrics suite; there's
>> >> also some fantastic tools in development but if you just picked up
>> >> your first book on R, you probably aren't ready for those yet).
>> >>
>> >> You question isn't particularly well-defined either:
>> >>
>> >> Do you just want to study currency price series in R? This is simple:
>> >> just get the data (perhaps from oanda using quantmod::getSymbols or
>> >> simply by reading in through any of the regular functions) and study
>> >> it however you like.
>> >>
>> >> The actual act of trading, however, is harder to do solely within R:
>> >> there is a very popular IBrokers API but I haven't used it much. It
>> >> sounds like you are probably a lone trader so if you don't have a
>> >> pre-existing relationship with IBrokers you'll probably want to enter
>> >> trades through whichever broker you currently use. That -- the
>> >> IBrokers package -- is the complete only solution on that end I'm
>> >> aware of, though I'm sure many folks have their own work-arounds.
>> >>
>> >> And as far as experiences go: well, I suppose folks wouldn't be doing
>> >> it if they thought there was no money to be made, now would they?
>> >>
>> >> If you want more to read: check the CRAN task views, as suggested before.
>> >>
>> >> Michael
>> >>
>> >> PS -- A serious note: FX is much closer to a zero-sum game than
>> >> long-equity, I would be remiss if I didn't warn you to tread
>> >> carefully.
>> >>
>> >> On Wed, Oct 12, 2011 at 1:50 PM, Yves S. Garret
>> >>  wrote:
>> >> > Yes, that's what I meant.  Curious what the experiences were of some
>> >> > people
>> >> > and some tips.
>> >> >
>> >> > On Wed, Oct 12, 2011 at 12:31 PM, R. Michael Weylandt
>> >> >  wrote:
>> >> >>
>> >> >> "This" being what exactly?
>> >> >>
>> 

Re: [R] Help with R plots

2011-10-12 Thread Weidong Gu
try

hist(gender$HeartRate,main='Histogram: HeartRate distribution for
Temperature Data')


Weidong Gu

On Wed, Oct 12, 2011 at 8:44 PM, Jonathan Edwin  wrote:
> Hi all,
>
> Mind my ignorance and complete newbiness, but I am very new to R and am
> currently learning it through my stats course at university.
> My question is regarding adding titles to plots. I'll post the code below,
> and then explain my issue:
>
>> hist(gender$HeartRate)
>> title(Histogram: HeartRate distribution for Temperature Data)
>
> So what R has done, is paste over the title I entered above over the generic
> title that was already there. Does anyone know how to remove the old title
> so that only the one I want shows? Also help with editting the X and Y axis
> titles would be great!
>
> Cheers,
> Jonathan
> --
>
>        [[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] R and Forex

2011-10-12 Thread Yves S. Garret
I'm a little vague on what constitutes r-help and r-devel lists in terms of
what questions to ask and where.  I read a little bit that this list was
about design and what you could do in R, but coding should be in r-devel.
 If I'm wrong, please clarify.

On Wed, Oct 12, 2011 at 9:12 PM, R. Michael Weylandt <
michael.weyla...@gmail.com>  wrote:

> I suppose you could, contingent on the broker end's functionality, and R
> does provide some socket support (see ?make.socket and ?connections among
> others) but I suspect your question is entering the domain of the R-devel
> list where the experts on the nitty gritty could give you better answers
> than I can.
>
> Michael
>
>
> On Oct 12, 2011, at 8:38 PM, "Yves S. Garret" 
> wrote:
>
> Don't see myself making 'real-time' trades.  Most likely a few times an
> hour.  Oh, can't you make a socket to another app in R?  That would be my
> first approach.
>
> On Wed, Oct 12, 2011 at 6:53 PM, R. Michael Weylandt <
> michael.weyla...@gmail.com> wrote:
>
>> Just a comment on the lack of a direct R API for non-IBrokers
>> brokerages: of course its possible to put something together using
>> rJava or a direct C interface, but it's not the smoothest thing if
>> you've never delved into the R internals and it's not quite the
>> fastest thing in the world if you are doing particularly
>> time-sensitive work. At lower frequencies, this becomes less of an
>> issue and simple work-arounds like using a csv file as an intermediate
>> can make everything much easier.
>>
>> On the other end of the trade process, once you start getting into
>> more HF domains, there's also the inverse problem of real-time
>> processing: I'm not particularly interested in the question so I
>> haven't thought much about it, but I don't see a particularly R-ish
>> way to deal with a live data feed, though it's been dealt with in the
>> R-SIG-Finance archives a couple of times.
>>
>> Michael
>>
>> On Wed, Oct 12, 2011 at 5:56 PM, Yves S. Garret
>>  wrote:
>> > Also, when you say to do the trading aspect is more difficult, what do
>> you
>> > mean exactly?  Are there performance issues with the code tasked to do
>> the
>> > trades?  Lack of API?  Or is it just a pain to put something coherent
>> > together that will do the trades?
>> >
>> > On Wed, Oct 12, 2011 at 3:07 PM, R. Michael Weylandt
>> >  wrote:
>> >>
>> >> As was pointed out to you before, this is really more of an
>> >> R-SIG-Finance question, but I wouldn't expect too much explanation
>> >> there either, just people pointing you to the standard R finance tools
>> >> (quantmod, zoo/xts, TTR, RBloomberg, and the Rmetrics suite; there's
>> >> also some fantastic tools in development but if you just picked up
>> >> your first book on R, you probably aren't ready for those yet).
>> >>
>> >> You question isn't particularly well-defined either:
>> >>
>> >> Do you just want to study currency price series in R? This is simple:
>> >> just get the data (perhaps from oanda using quantmod::getSymbols or
>> >> simply by reading in through any of the regular functions) and study
>> >> it however you like.
>> >>
>> >> The actual act of trading, however, is harder to do solely within R:
>> >> there is a very popular IBrokers API but I haven't used it much. It
>> >> sounds like you are probably a lone trader so if you don't have a
>> >> pre-existing relationship with IBrokers you'll probably want to enter
>> >> trades through whichever broker you currently use. That -- the
>> >> IBrokers package -- is the complete only solution on that end I'm
>> >> aware of, though I'm sure many folks have their own work-arounds.
>> >>
>> >> And as far as experiences go: well, I suppose folks wouldn't be doing
>> >> it if they thought there was no money to be made, now would they?
>> >>
>> >> If you want more to read: check the CRAN task views, as suggested
>> before.
>> >>
>> >> Michael
>> >>
>> >> PS -- A serious note: FX is much closer to a zero-sum game than
>> >> long-equity, I would be remiss if I didn't warn you to tread
>> >> carefully.
>> >>
>> >> On Wed, Oct 12, 2011 at 1:50 PM, Yves S. Garret
>> >>  wrote:
>> >> > Yes, that's what I meant.  Curious what the experiences were of some
>> >> > people
>> >> > and some tips.
>> >> >
>> >> > On Wed, Oct 12, 2011 at 12:31 PM, R. Michael Weylandt
>> >> >  wrote:
>> >> >>
>> >> >> "This" being what exactly?
>> >> >>
>> >> >> Traded in FX using R? Yes, its done everyday, even as I type
>> >> >>
>> >> >> Michael
>> >> >>
>> >> >> On Wed, Oct 12, 2011 at 8:10 AM, Yves S. Garret
>> >> >>  wrote:
>> >> >> > No, that's not what I meant.  I was curious if anyone has ever
>> done
>> >> >> > this
>> >> >> > before and how well it worked.  Any tips for a novice?
>> >> >> >
>> >> >> > On Wed, Oct 12, 2011 at 12:19 AM, Liviu Andronic
>> >> >> > wrote:
>> >> >> >
>> >> >> >> On Wed, Oct 12, 2011 at 3:29 AM, Yves S. Garret
>> >> >> >>  wrote:
>> >> >> >> > Hi all,
>> >> >> >> >
>> >> >> >> >   I recently started learning about Forex a

[R] Help with R plots

2011-10-12 Thread Jonathan Edwin
Hi all,

Mind my ignorance and complete newbiness, but I am very new to R and am
currently learning it through my stats course at university.
My question is regarding adding titles to plots. I'll post the code below,
and then explain my issue:

> hist(gender$HeartRate)
> title(Histogram: HeartRate distribution for Temperature Data)

So what R has done, is paste over the title I entered above over the generic
title that was already there. Does anyone know how to remove the old title
so that only the one I want shows? Also help with editting the X and Y axis
titles would be great!

Cheers,
Jonathan
--

[[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] US States percentage change plot

2011-10-12 Thread Michael Charles Bailey I
Hi, I would like to make a plot of the US states (or lower 48) that are
colored based upon a percentage change column. Ideally, it would gradually
be more blue the larger the positive change, and more red the more negative
is the change.

The data I have looks like:

   State Percent.Change
1Alabama0.004040547
2 Alaska   -0.000202211
3Arizona   -0.002524567
4   Arkansas   -0.008525333
5 California0.001828754
6   Colorado0.06150

I have read help for the maps library and similar plots online but can't
grasp how to map the percentage.change column to the map. thank in advance,

Michael Bailey

[[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] pass an element in a list() from R to C

2011-10-12 Thread teazrq
Hi all,

I'm new to this "call C from R" so bear with me.
I'v been writing some C code and compile it to .dll files that can be called
from R.
It was successful until today, when I start a new part of this project.
So, my R code passes arguments to this C code, and these arguments including
some integers and matrices.
it looks like this, and it works fine:
.C("Myfunction", as.matrix(dataset), as.integer(dim(dataset)) )
btw, In the C code, I will read the dataset as double *

Now, I have several datasets that in a list(),
you can think of it as 
A = list()
A[[1]] = dataset1
A[[2]] = dataset2

when I run this function again, by using
.C("Myfunction", as.matrix(A[[1]]), as.integer(dim(A[[1]])) )
it does not work anymore. It seems like the C code does not recognize 
"as.matrix(A[[1]])" as a pointer to A[[1]]. Anyone knows why is that?

btw, I did some reading on similar issue, and it seems that people use SEXP
more offen to pass arguments from R to C. I tried some of those by trying to
pass the whole list A to the C code and then use something like
REAL(VECTOR_ELT(A, 1))[0] to read each element from the list, however, it
still does not work... if using SEXP as object type is the currect way to do
it, could anyone give an example of how to extract element from the list in
the c code? and also, when I claim the function in C, should it be 

SEXP myfunction2(SEXP *list)

or 

SEXP myfunction2(SEXP list)  

these things are really confusing me

Thank you for going through this post... Any helps are appreciated.

Ruoqing










--
View this message in context: 
http://r.789695.n4.nabble.com/pass-an-element-in-a-list-from-R-to-C-tp3900221p3900221.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] R and Forex

2011-10-12 Thread Yves S. Garret
Don't see myself making 'real-time' trades.  Most likely a few times an
hour.  Oh, can't you make a socket to another app in R?  That would be my
first approach.

On Wed, Oct 12, 2011 at 6:53 PM, R. Michael Weylandt <
michael.weyla...@gmail.com> wrote:

> Just a comment on the lack of a direct R API for non-IBrokers
> brokerages: of course its possible to put something together using
> rJava or a direct C interface, but it's not the smoothest thing if
> you've never delved into the R internals and it's not quite the
> fastest thing in the world if you are doing particularly
> time-sensitive work. At lower frequencies, this becomes less of an
> issue and simple work-arounds like using a csv file as an intermediate
> can make everything much easier.
>
> On the other end of the trade process, once you start getting into
> more HF domains, there's also the inverse problem of real-time
> processing: I'm not particularly interested in the question so I
> haven't thought much about it, but I don't see a particularly R-ish
> way to deal with a live data feed, though it's been dealt with in the
> R-SIG-Finance archives a couple of times.
>
> Michael
>
> On Wed, Oct 12, 2011 at 5:56 PM, Yves S. Garret
>  wrote:
> > Also, when you say to do the trading aspect is more difficult, what do
> you
> > mean exactly?  Are there performance issues with the code tasked to do
> the
> > trades?  Lack of API?  Or is it just a pain to put something coherent
> > together that will do the trades?
> >
> > On Wed, Oct 12, 2011 at 3:07 PM, R. Michael Weylandt
> >  wrote:
> >>
> >> As was pointed out to you before, this is really more of an
> >> R-SIG-Finance question, but I wouldn't expect too much explanation
> >> there either, just people pointing you to the standard R finance tools
> >> (quantmod, zoo/xts, TTR, RBloomberg, and the Rmetrics suite; there's
> >> also some fantastic tools in development but if you just picked up
> >> your first book on R, you probably aren't ready for those yet).
> >>
> >> You question isn't particularly well-defined either:
> >>
> >> Do you just want to study currency price series in R? This is simple:
> >> just get the data (perhaps from oanda using quantmod::getSymbols or
> >> simply by reading in through any of the regular functions) and study
> >> it however you like.
> >>
> >> The actual act of trading, however, is harder to do solely within R:
> >> there is a very popular IBrokers API but I haven't used it much. It
> >> sounds like you are probably a lone trader so if you don't have a
> >> pre-existing relationship with IBrokers you'll probably want to enter
> >> trades through whichever broker you currently use. That -- the
> >> IBrokers package -- is the complete only solution on that end I'm
> >> aware of, though I'm sure many folks have their own work-arounds.
> >>
> >> And as far as experiences go: well, I suppose folks wouldn't be doing
> >> it if they thought there was no money to be made, now would they?
> >>
> >> If you want more to read: check the CRAN task views, as suggested
> before.
> >>
> >> Michael
> >>
> >> PS -- A serious note: FX is much closer to a zero-sum game than
> >> long-equity, I would be remiss if I didn't warn you to tread
> >> carefully.
> >>
> >> On Wed, Oct 12, 2011 at 1:50 PM, Yves S. Garret
> >>  wrote:
> >> > Yes, that's what I meant.  Curious what the experiences were of some
> >> > people
> >> > and some tips.
> >> >
> >> > On Wed, Oct 12, 2011 at 12:31 PM, R. Michael Weylandt
> >> >  wrote:
> >> >>
> >> >> "This" being what exactly?
> >> >>
> >> >> Traded in FX using R? Yes, its done everyday, even as I type
> >> >>
> >> >> Michael
> >> >>
> >> >> On Wed, Oct 12, 2011 at 8:10 AM, Yves S. Garret
> >> >>  wrote:
> >> >> > No, that's not what I meant.  I was curious if anyone has ever done
> >> >> > this
> >> >> > before and how well it worked.  Any tips for a novice?
> >> >> >
> >> >> > On Wed, Oct 12, 2011 at 12:19 AM, Liviu Andronic
> >> >> > wrote:
> >> >> >
> >> >> >> On Wed, Oct 12, 2011 at 3:29 AM, Yves S. Garret
> >> >> >>  wrote:
> >> >> >> > Hi all,
> >> >> >> >
> >> >> >> >   I recently started learning about Forex and found this
> O'Reilly
> >> >> >> > book in
> >> >> >> > Barnes & Nobles about R.  I bought it out of pure curiosity.  I
> >> >> >> > like
> >> >> >> > what
> >> >> >> I
> >> >> >> > see.  However, I have a question.  Has anyone tried to bring
> these
> >> >> >> > two
> >> >> >> ideas
> >> >> >> > together in a financial and trading sense?  Are there any
> >> >> >> > libraries
> >> >> >> > or
> >> >> >> > modules in R that can aid in this venture?
> >> >> >> >
> >> >> >>
> >> >> >> > fortune('equity')
> >> >> >>
> >> >> >> I have never heard anyone (knowledgable or otherwise) claim that,
> in
> >> >> >> the
> >> >> >> absence of transition costs, SAS is better than R for equity
> >> >> >> modeling.
> >> >> >> If
> >> >> >> you
> >> >> >> come across any such claim, I would be happy to refute it.
> >> >> >>   -- David Kane
> >> >> >> 

Re: [R] R and Forex

2011-10-12 Thread R. Michael Weylandt
I suppose you could, contingent on the broker end's functionality, and R does 
provide some socket support (see ?make.socket and ?connections among others) 
but I suspect your question is entering the domain of the R-devel list where 
the experts on the nitty gritty could give you better answers than I can. 

Michael

On Oct 12, 2011, at 8:38 PM, "Yves S. Garret"  
wrote:

> Don't see myself making 'real-time' trades.  Most likely a few times an hour. 
>  Oh, can't you make a socket to another app in R?  That would be my first 
> approach.
> 
> On Wed, Oct 12, 2011 at 6:53 PM, R. Michael Weylandt 
>  wrote:
> Just a comment on the lack of a direct R API for non-IBrokers
> brokerages: of course its possible to put something together using
> rJava or a direct C interface, but it's not the smoothest thing if
> you've never delved into the R internals and it's not quite the
> fastest thing in the world if you are doing particularly
> time-sensitive work. At lower frequencies, this becomes less of an
> issue and simple work-arounds like using a csv file as an intermediate
> can make everything much easier.
> 
> On the other end of the trade process, once you start getting into
> more HF domains, there's also the inverse problem of real-time
> processing: I'm not particularly interested in the question so I
> haven't thought much about it, but I don't see a particularly R-ish
> way to deal with a live data feed, though it's been dealt with in the
> R-SIG-Finance archives a couple of times.
> 
> Michael
> 
> On Wed, Oct 12, 2011 at 5:56 PM, Yves S. Garret
>  wrote:
> > Also, when you say to do the trading aspect is more difficult, what do you
> > mean exactly?  Are there performance issues with the code tasked to do the
> > trades?  Lack of API?  Or is it just a pain to put something coherent
> > together that will do the trades?
> >
> > On Wed, Oct 12, 2011 at 3:07 PM, R. Michael Weylandt
> >  wrote:
> >>
> >> As was pointed out to you before, this is really more of an
> >> R-SIG-Finance question, but I wouldn't expect too much explanation
> >> there either, just people pointing you to the standard R finance tools
> >> (quantmod, zoo/xts, TTR, RBloomberg, and the Rmetrics suite; there's
> >> also some fantastic tools in development but if you just picked up
> >> your first book on R, you probably aren't ready for those yet).
> >>
> >> You question isn't particularly well-defined either:
> >>
> >> Do you just want to study currency price series in R? This is simple:
> >> just get the data (perhaps from oanda using quantmod::getSymbols or
> >> simply by reading in through any of the regular functions) and study
> >> it however you like.
> >>
> >> The actual act of trading, however, is harder to do solely within R:
> >> there is a very popular IBrokers API but I haven't used it much. It
> >> sounds like you are probably a lone trader so if you don't have a
> >> pre-existing relationship with IBrokers you'll probably want to enter
> >> trades through whichever broker you currently use. That -- the
> >> IBrokers package -- is the complete only solution on that end I'm
> >> aware of, though I'm sure many folks have their own work-arounds.
> >>
> >> And as far as experiences go: well, I suppose folks wouldn't be doing
> >> it if they thought there was no money to be made, now would they?
> >>
> >> If you want more to read: check the CRAN task views, as suggested before.
> >>
> >> Michael
> >>
> >> PS -- A serious note: FX is much closer to a zero-sum game than
> >> long-equity, I would be remiss if I didn't warn you to tread
> >> carefully.
> >>
> >> On Wed, Oct 12, 2011 at 1:50 PM, Yves S. Garret
> >>  wrote:
> >> > Yes, that's what I meant.  Curious what the experiences were of some
> >> > people
> >> > and some tips.
> >> >
> >> > On Wed, Oct 12, 2011 at 12:31 PM, R. Michael Weylandt
> >> >  wrote:
> >> >>
> >> >> "This" being what exactly?
> >> >>
> >> >> Traded in FX using R? Yes, its done everyday, even as I type
> >> >>
> >> >> Michael
> >> >>
> >> >> On Wed, Oct 12, 2011 at 8:10 AM, Yves S. Garret
> >> >>  wrote:
> >> >> > No, that's not what I meant.  I was curious if anyone has ever done
> >> >> > this
> >> >> > before and how well it worked.  Any tips for a novice?
> >> >> >
> >> >> > On Wed, Oct 12, 2011 at 12:19 AM, Liviu Andronic
> >> >> > wrote:
> >> >> >
> >> >> >> On Wed, Oct 12, 2011 at 3:29 AM, Yves S. Garret
> >> >> >>  wrote:
> >> >> >> > Hi all,
> >> >> >> >
> >> >> >> >   I recently started learning about Forex and found this O'Reilly
> >> >> >> > book in
> >> >> >> > Barnes & Nobles about R.  I bought it out of pure curiosity.  I
> >> >> >> > like
> >> >> >> > what
> >> >> >> I
> >> >> >> > see.  However, I have a question.  Has anyone tried to bring these
> >> >> >> > two
> >> >> >> ideas
> >> >> >> > together in a financial and trading sense?  Are there any
> >> >> >> > libraries
> >> >> >> > or
> >> >> >> > modules in R that can aid in this venture?
> >> >> >> >
> >> >> >>
> >> >> >> > fo

Re: [R] getting data associated with coordinates in a spatial data frame

2011-10-12 Thread Sarah Goslee
Hi,

On Wed, Oct 12, 2011 at 3:37 PM, Bailey, Daniel  wrote:
> If I know the specific coordinate in a spatial data frame, how can I access 
> the data at that coordinate?
>
> My coordinates are labeled "x" and "y" in a data.frame "e". The data is in 
> column "leachate".
> I want to say, basically:
> e$leachate@coordinates(2,3).

That's kind of mangled, but what about:

e[e$x == my.x & e$y == my.y, "leachate"]

(Depending on the form of your coordinates, you may also have to
invoke FAQ 7.31.)

Sarah

> Thanks, Daniel
>

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

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


Re: [R] using csv file for stacked bar plot, rows to columns

2011-10-12 Thread Sarah Goslee
Hi,

On Wed, Oct 12, 2011 at 6:11 PM, Davis_fishgirl  wrote:
>
> **NEW TO R**-been trying to teach myself with no prior experience in
> computer languages, so I apologize if I am poor at using technical terms
> Hi, I have perused some of the previous posts on this topic and tried their
> solutions, but am still coming up with error messages(sometimes more than 50
> at a time)
>
> I have:
> a csv file with four columns(that I have read into R, no problem, we will
> call it DATA)
> date, Location1, Location2, total
>
> Dates cover almost a year
> location values are number of fish seen at that location

So your question doesn't have anything to do with CSV files, but
only with making a stacked barplot from a data frame.

> I would like to show a stacked bar plot so someone can see the breakdown for
> total fish seen on any particular day.  I was able to create a simple bar
> plot for total number of fish versus Date, but when I have tried to make a
> stacked graph it creates four bars(one for each column).
>
> Do I have to convert my data so each date has its own column or is there a
> way I can use my data as is?
>
> script I have tried:
>
> barplot(as.matrix(DATA))
>
> barplot(t(DATA),names.arg=DATA$Date)
>
> fish<-table(DATA$Location1,DATA$Location2)
> barplot(fish,names.arg=DATA$Date)

If you read the help for barplot, you'll see that the argument beside
controls whether the bars are next to each other or stacked.

You'll get better answers if you provide a reproducible example (see
posting guide, please), but this may be enough to get you going.

> testdata <- data.frame(Date=1:5, Location1=sample(1:10, 5, replace=TRUE), 
> Location2=sample(1:10, 5, replace=TRUE))
>
> testdata
  Date Location1 Location2
11 310
2210 6
33 2 9
44 410
55 8 2
> barplot(t(testdata[, 2:3]), beside=FALSE, names=testdata$Date)

Sarah

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

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


Re: [R] strange behavior with R.dll

2011-10-12 Thread Joshua Wiley
On Oct 12, 2011, at 17:23, Duncan Murdoch  wrote:

> On 11-10-12 7:54 PM, Joshua Wiley wrote:
>> I regularly have the R.dll removed.  AFAI can tell, it depends partly on how 
>> aggressive a heuristic level you have chosen, in part I think related to the 
>> number of users.  In any case you can restore it and set a rule to have it 
>> ignored.  I suppose you could tell symantec, but it's never been enough of a 
>> nuisance to me to set my own rules to bother trying to contact them.
> 
> From your own builds, or the pre-built binaries?

Pre-built binariesI think, though it seems like it happened from a compiled 
r devel at some point (memory of the exact versions is a bit hazy, and recently 
I am careful to make sure to say the file is safe now).

> 
> Duncan Murdoch
> 
>> Josh
>> 
>> On Oct 12, 2011, at 12:09, Duncan Murdoch  wrote:
>> 
>>> On 12/10/2011 3:03 PM, Erin Hodgess wrote:
 Dear R People:
 
 I am using R-2.13.2 on a Windows 7 machine.
 
 I compiled from source on 32 bit a couple of weeks ago and the R.dll
 got removed by my anti-virus software.
 
 Same thing on 64 bit today.
 
 Is anyone having this problem, please?
 
 I'm using Norton AV.
>>> 
>>> I haven't heard of this particular problem before.  Generally the problems 
>>> we have had have been with other Antivirus programs finding false positives 
>>> in our pre-compiled distributions.
>>> 
>>> Duncan Murdoch
>>> 
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>> 
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 

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


Re: [R] strange behavior with R.dll

2011-10-12 Thread Duncan Murdoch

On 11-10-12 7:54 PM, Joshua Wiley wrote:

I regularly have the R.dll removed.  AFAI can tell, it depends partly on how 
aggressive a heuristic level you have chosen, in part I think related to the 
number of users.  In any case you can restore it and set a rule to have it 
ignored.  I suppose you could tell symantec, but it's never been enough of a 
nuisance to me to set my own rules to bother trying to contact them.


From your own builds, or the pre-built binaries?

Duncan Murdoch


Josh

On Oct 12, 2011, at 12:09, Duncan Murdoch  wrote:


On 12/10/2011 3:03 PM, Erin Hodgess wrote:

Dear R People:

I am using R-2.13.2 on a Windows 7 machine.

I compiled from source on 32 bit a couple of weeks ago and the R.dll
got removed by my anti-virus software.

Same thing on 64 bit today.

Is anyone having this problem, please?

I'm using Norton AV.


I haven't heard of this particular problem before.  Generally the problems we 
have had have been with other Antivirus programs finding false positives in our 
pre-compiled distributions.

Duncan Murdoch

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


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


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


Re: [R] strange behavior with R.dll

2011-10-12 Thread Joshua Wiley
I regularly have the R.dll removed.  AFAI can tell, it depends partly on how 
aggressive a heuristic level you have chosen, in part I think related to the 
number of users.  In any case you can restore it and set a rule to have it 
ignored.  I suppose you could tell symantec, but it's never been enough of a 
nuisance to me to set my own rules to bother trying to contact them.

Josh

On Oct 12, 2011, at 12:09, Duncan Murdoch  wrote:

> On 12/10/2011 3:03 PM, Erin Hodgess wrote:
>> Dear R People:
>> 
>> I am using R-2.13.2 on a Windows 7 machine.
>> 
>> I compiled from source on 32 bit a couple of weeks ago and the R.dll
>> got removed by my anti-virus software.
>> 
>> Same thing on 64 bit today.
>> 
>> Is anyone having this problem, please?
>> 
>> I'm using Norton AV.
> 
> I haven't heard of this particular problem before.  Generally the problems we 
> have had have been with other Antivirus programs finding false positives in 
> our pre-compiled distributions.
> 
> Duncan Murdoch
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] using csv file for stacked bar plot, rows to columns

2011-10-12 Thread Davis_fishgirl

**NEW TO R**-been trying to teach myself with no prior experience in
computer languages, so I apologize if I am poor at using technical terms
Hi, I have perused some of the previous posts on this topic and tried their
solutions, but am still coming up with error messages(sometimes more than 50
at a time)

I have:
a csv file with four columns(that I have read into R, no problem, we will
call it DATA)
date, Location1, Location2, total

Dates cover almost a year
location values are number of fish seen at that location

I would like to show a stacked bar plot so someone can see the breakdown for
total fish seen on any particular day.  I was able to create a simple bar
plot for total number of fish versus Date, but when I have tried to make a
stacked graph it creates four bars(one for each column). 

Do I have to convert my data so each date has its own column or is there a
way I can use my data as is?

script I have tried:

barplot(as.matrix(DATA))

barplot(t(DATA),names.arg=DATA$Date)

fish<-table(DATA$Location1,DATA$Location2)
barplot(fish,names.arg=DATA$Date)

Any help is appreciated.


--
View this message in context: 
http://r.789695.n4.nabble.com/using-csv-file-for-stacked-bar-plot-rows-to-columns-tp3899909p3899909.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] How to transfer the variable into function in this code?

2011-10-12 Thread xingxing
as shown in the code, four variables input: diff_expr,diff_coex, klist,
Pop_size, are included in the function. However, within the function,
another variable "vector" is utilized in some subfunction. How they get its
value?

thx

get_quantiles <-function(diff_expr,diff_coex,klist,pop_size){

# The function to get the "node_score_term" and "edge_score_term" of a 
sub-network denoted by "vector"

my.fun<-function(vector){
return(diff_coex[vector[1],vector[2]])
}

# "vector" is a binary vector with length equal to the size of the whole 
network. 
# An element of value "1" indicates the inclusion of that gene in the 
selected sub-network.


node_edge<-function(vector){
selected_subset<-which(vector==1)
n<-length(selected_subset)
node_score<-sum(diff_expr[selected_subset])/sqrt(n)
edges<-combn(selected_subset,2)
edge_score<-sum(apply(edges,2,my.fun))/sqrt(choose(n,2))
return(c(node_score,edge_score))
}
}

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-transfer-the-variable-into-function-in-this-code-tp3899576p3899576.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] getting data associated with coordinates in a spatial data frame

2011-10-12 Thread Bailey, Daniel
If I know the specific coordinate in a spatial data frame, how can I access the 
data at that coordinate?

My coordinates are labeled "x" and "y" in a data.frame "e". The data is in 
column "leachate".
I want to say, basically:
e$leachate@coordinates(2,3).

Thanks, Daniel

[[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 calculate the statistics of a yearly window with a rolling step as 1 day?

2011-10-12 Thread Gabor Grothendieck
On Wed, Oct 12, 2011 at 9:12 AM, ecoc  wrote:
> This doesn't work becaues the rollappy is non-overlapping. My rolling step is
> 1-day and rolling window is 1-year, so there is 364 days overlapping.
>

Its not the case that rollapply is non-overlapping.  rollapply by
default calls the function on a stretch of data moving ahead by 1 each
time so it does overlap.  Also you can use by= to cause it to move
ahead by some other number if you wish.  Also by setting by=
appropriately you can get it to not overlap at all if you wish.  Also
depending on what your problem is you may be able to handle variations
in the function itself, e.g. removing NAs.

I suggest you give a small reproducible example showing what you have
and what you want in order to clarify.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at 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] R and Forex

2011-10-12 Thread R. Michael Weylandt
Just a comment on the lack of a direct R API for non-IBrokers
brokerages: of course its possible to put something together using
rJava or a direct C interface, but it's not the smoothest thing if
you've never delved into the R internals and it's not quite the
fastest thing in the world if you are doing particularly
time-sensitive work. At lower frequencies, this becomes less of an
issue and simple work-arounds like using a csv file as an intermediate
can make everything much easier.

On the other end of the trade process, once you start getting into
more HF domains, there's also the inverse problem of real-time
processing: I'm not particularly interested in the question so I
haven't thought much about it, but I don't see a particularly R-ish
way to deal with a live data feed, though it's been dealt with in the
R-SIG-Finance archives a couple of times.

Michael

On Wed, Oct 12, 2011 at 5:56 PM, Yves S. Garret
 wrote:
> Also, when you say to do the trading aspect is more difficult, what do you
> mean exactly?  Are there performance issues with the code tasked to do the
> trades?  Lack of API?  Or is it just a pain to put something coherent
> together that will do the trades?
>
> On Wed, Oct 12, 2011 at 3:07 PM, R. Michael Weylandt
>  wrote:
>>
>> As was pointed out to you before, this is really more of an
>> R-SIG-Finance question, but I wouldn't expect too much explanation
>> there either, just people pointing you to the standard R finance tools
>> (quantmod, zoo/xts, TTR, RBloomberg, and the Rmetrics suite; there's
>> also some fantastic tools in development but if you just picked up
>> your first book on R, you probably aren't ready for those yet).
>>
>> You question isn't particularly well-defined either:
>>
>> Do you just want to study currency price series in R? This is simple:
>> just get the data (perhaps from oanda using quantmod::getSymbols or
>> simply by reading in through any of the regular functions) and study
>> it however you like.
>>
>> The actual act of trading, however, is harder to do solely within R:
>> there is a very popular IBrokers API but I haven't used it much. It
>> sounds like you are probably a lone trader so if you don't have a
>> pre-existing relationship with IBrokers you'll probably want to enter
>> trades through whichever broker you currently use. That -- the
>> IBrokers package -- is the complete only solution on that end I'm
>> aware of, though I'm sure many folks have their own work-arounds.
>>
>> And as far as experiences go: well, I suppose folks wouldn't be doing
>> it if they thought there was no money to be made, now would they?
>>
>> If you want more to read: check the CRAN task views, as suggested before.
>>
>> Michael
>>
>> PS -- A serious note: FX is much closer to a zero-sum game than
>> long-equity, I would be remiss if I didn't warn you to tread
>> carefully.
>>
>> On Wed, Oct 12, 2011 at 1:50 PM, Yves S. Garret
>>  wrote:
>> > Yes, that's what I meant.  Curious what the experiences were of some
>> > people
>> > and some tips.
>> >
>> > On Wed, Oct 12, 2011 at 12:31 PM, R. Michael Weylandt
>> >  wrote:
>> >>
>> >> "This" being what exactly?
>> >>
>> >> Traded in FX using R? Yes, its done everyday, even as I type
>> >>
>> >> Michael
>> >>
>> >> On Wed, Oct 12, 2011 at 8:10 AM, Yves S. Garret
>> >>  wrote:
>> >> > No, that's not what I meant.  I was curious if anyone has ever done
>> >> > this
>> >> > before and how well it worked.  Any tips for a novice?
>> >> >
>> >> > On Wed, Oct 12, 2011 at 12:19 AM, Liviu Andronic
>> >> > wrote:
>> >> >
>> >> >> On Wed, Oct 12, 2011 at 3:29 AM, Yves S. Garret
>> >> >>  wrote:
>> >> >> > Hi all,
>> >> >> >
>> >> >> >   I recently started learning about Forex and found this O'Reilly
>> >> >> > book in
>> >> >> > Barnes & Nobles about R.  I bought it out of pure curiosity.  I
>> >> >> > like
>> >> >> > what
>> >> >> I
>> >> >> > see.  However, I have a question.  Has anyone tried to bring these
>> >> >> > two
>> >> >> ideas
>> >> >> > together in a financial and trading sense?  Are there any
>> >> >> > libraries
>> >> >> > or
>> >> >> > modules in R that can aid in this venture?
>> >> >> >
>> >> >>
>> >> >> > fortune('equity')
>> >> >>
>> >> >> I have never heard anyone (knowledgable or otherwise) claim that, in
>> >> >> the
>> >> >> absence of transition costs, SAS is better than R for equity
>> >> >> modeling.
>> >> >> If
>> >> >> you
>> >> >> come across any such claim, I would be happy to refute it.
>> >> >>   -- David Kane
>> >> >>      R-SIG-Finance (December 2004)
>> >> >>
>> >> >>
>> >> >> You may want to address this question to r-sig-finance, and check
>> >> >> out
>> >> >> the Finance Task View [1]. Regards
>> >> >> Liviu
>> >> >>
>> >> >> [1] http://cran.at.r-project.org/web/views/Finance.html
>> >> >>
>> >> >>
>> >> >> > --Yves
>> >> >> >
>> >> >> >        [[alternative HTML version deleted]]
>> >> >> >
>> >> >> > __
>> >> >> > R-help@r-project.org mailing list
>> 

[R] dcc in 'bootRes' package

2011-10-12 Thread Xanthe Walker
Hello,

I am trying to complete a response function analysis using the command dcc
in the package 'bootRes'.
Here is my code:

DC<-read.table("Dalton.txt", header=T)
climate<-read.table("climate.txt", header=T)
dcc.DC<-dcc(DC, climate, method ="response", start = -4, end =9)

My data is formatted correctly for this analysis, with 'DC' being a data
frame that contains tree-ring chronologies and 'climate' being a data frame
with year, month, and climate parameters in columns.

I continue to get the following error:
Error in (start.year + offset):end.year : argument of length 0

Any feedback would be greatly appreciated.

Thanks,
Xanthe

[[alternative HTML version deleted]]

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


Re: [R] R and Forex

2011-10-12 Thread David Winsemius


On Oct 12, 2011, at 10:40 AM, Yves S. Garret wrote:

When can I send stuff to the mailing list without having moderator  
approval?

Is that possible?


If you register (and you are currently registered at that address )  
you can generally avoid moderation. The view available to the  
moderators is very limited and we cannot see anything other than your  
address, so I have no idea when you might have registered, but this  
appears to be the first thread that you started. Your first message  
(and any replies in that thread it seems) gets moderated and if the  
moderator is not sleeping and remembers to clear your moderation flag,  
your chances for subsequent moderation will drop substantially (after  
the server cycles through its administrative cycles  at the end of the  
day ...  I think).


There are still exceptions and addresses from "free" domains do raise  
the probability of future moderation by an amount that is not under  
the control of the moderators. The moderators themselves still  
sometimes get their own postings shunted to the queue, so you should  
not take any of this personally. There is no completely effective  
"whitelist". The spam avoidance efforts do seem peculiar at times, but  
they are mostly effective ... and mostly unobtrusive... to most of the  
audience. The moderators discard all the adverts for Parisian  
apartments and other commercial junk mail. So we keep the ETH IT  
admins happy. And we get free hosting for a very useful service, so we  
are happy.


(The moderators are not looking to expand their workload and we do not  
set the rules. Please do not ask us to change the rules. We don't  
understand all of the rules and can't change them, anyway.)


--

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] Applying function to only numeric variable (plyr package?)

2011-10-12 Thread Dennis Murphy
Hi:

One approach to this problem in plyr is to use the recently developed
mutate() function rather than ddply(). mutate() is a somewhat faster
version of transform(); when used as a standalone function, it doesn't
take a grouping variable as an argument. For this example, one could
use

mutate(df, px = pct(x), py = pct(y))
  c1 c2  x  y   px   py
1  A  Y 0.5234 0.9251 52.3 92.5
2  B  Y 0.6919 0.7616 69.2 76.2
3  C  N 0.2307 0.3624 23.1 36.2
4  C  N 0.1160 0.4462 11.6 44.6

Another option is to use numcolwise() from the plyr package, which
will apply the function of interest to all numeric variables in the
data frame. This is a way to generate the desired outcome for this
example:

f <- numcolwise(pct)
cbind(df[, 1:2], f(df))
  c1 c2xy
1  A  Y 52.3 92.5
2  B  Y 69.2 76.2
3  C  N 23.1 36.2
4  C  N 11.6 44.6

In a data frame with a large number of columns, one could separate out
the non-numeric variables with sapply(), as shown in a previous
response, into one data frame and then cbind() it to the result of
numcolwise().

HTH,
Dennis


On Wed, Oct 12, 2011 at 6:18 AM,   wrote:
>
> My data frame consists of character variables, factors, and proportions,
> something like
>
> c1 <- c("A", "B", "C", "C")
> c2 <- factor(c(1, 1, 2, 2), labels = c("Y","N"))
> x <- c(0.5234, 0.6919, 0.2307, 0.1160)
> y <- c(0.9251, 0.7616, 0.3624, 0.4462)
> df <- data.frame(c1, c2, x, y)
> pct <- function(x) round(100*x, 1)
>
> I want to apply the pct function to only the numeric variables so that the
> proportions are computed to percentages, and retain all the columns:
>
>  c1 c2   x1   x2
> 1  A  Y 52.3 92.5
> 2  B  Y 69.2 76.2
> 3  C  N 23.1 36.2
> 4  C  N 11.6 44.6
>
> I've been approaching it with the ddply and colwise functions from the plyr
> package, but in that case each I need each row to be its own group and
> retain all columns. Am I on the right track? If not, what's the best way to
> do this?
>
> Thanks in advance,
> M. L.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] large numbers

2011-10-12 Thread David Winsemius


On Oct 12, 2011, at 3:16 PM, Veerappa Chetty wrote:


Hi,
When I import an excel "CSV" file, large numbers such as "  
43988014.3" is
imported as "43988014", leaving out the decimal ".4". How to import  
keeping

the fraction?


"Import from Excel" is a vague problem statement. It's also kind of  
odd that you have a leading space iside the quotes in the example.  
Makes me wonder if you got numbers somehow "factorized" because of non- 
numeric entries in the "csv" file. Why not show the code used to do it  
_and_  str() on the object? Or even better dput from a row with a  
"large number"?







--

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] Chi-Square test and survey results

2011-10-12 Thread Greg Snow
The chisq.test function is expecting a contingency table, basically one column 
should have the count of respondents and the other column should have the count 
of non-respondents (yours looks like it is the total instead of the 
non-respondents), so your data is wrong to begin with.  A significant 
chi-square here just means that the proportion responding differs in some of 
the regions, that does not mean that the sample is representative (or not 
representative).  What is more important (and not in the data or standard 
tests) is if there is a relationship between why someone chose to respond and 
the outcomes of interest.

If you are concerned with different proportions responding then you could do 
post-stratification to correct for the inequality when computing other 
summaries or tests (though region 6 will still give you problems, you will need 
to make some assumptions, possibly combine it with another region that is 
similar).

Throwing away data is rarely, if ever, beneficial.

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


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of ghe...@mathnmaps.com
> Sent: Tuesday, October 11, 2011 1:32 PM
> To: r-help@r-project.org
> Subject: [R] Chi-Square test and survey results
> 
> An organization has asked me to comment on the validity of their
> recent all-employee survey.  Survey responses, by geographic region,
> compared
> with the total number of employees in each region, were as follows:
> 
> > ByRegion
>All.Employees Survey.Respondents
> Region_1735142
> Region_2500 83
> Region_3897 78
> Region_4717133
> Region_5167 48
> Region_6309  0
> Region_7806125
> Region_8627122
> Region_9858177
> Region_10   851160
> Region_11   336 52
> Region_12  1823312
> Region_1380  9
> Region_14   774121
> Region_15   561 24
> Region_16   834134
> 
> How well does the survey represent the employee population?
> Chi-square test says, not very well:
> 
> > chisq.test(ByRegion)
> 
>  Pearson's Chi-squared test
> 
> data:  ByRegion
> X-squared = 163.6869, df = 15, p-value < 2.2e-16
> 
> By striking three under-represented regions (3,6, and 15), we get
> a more reasonable, although still not convincing, result:
> 
> > chisq.test(ByRegion[setdiff(1:16,c(3,6,15)),])
> 
>  Pearson's Chi-squared test
> 
> data:  ByRegion[setdiff(1:16, c(3, 6, 15)), ]
> X-squared = 22.5643, df = 12, p-value = 0.03166
> 
> This poses several questions:
> 
> 1)  Looking at a side-by-side barchart (proportion of responses vs.
> proportion of employees, per region), the pattern of survey responses
> appears, visually, to match fairly well the pattern of employees.  Is
> this a case where we trust the numbers and not the picture?
> 
> 2) Part of the problem, ironically, is that there were too many
> responses
> to the survey.  If we had only one-tenth the responses, but in the same
> proportions by region, the chi-square statistic would look much better,
> (though with a warning about possible inaccuracy):
> 
> data:  data.frame(ByRegion$All.Employees, 0.1 *
> (ByRegion$Survey.Respondents))
> X-squared = 17.5912, df = 15, p-value = 0.2848
> 
> Is there a way of reconciling a large response rate with an
> unrepresentative
> response profile?  Or is the bad news that the survey will give very
> precise
> results about a very ill-specified sub-population?
> 
> (Of course, I would put in softer terms, like "you need to assess the
> degree
> of homogeneity across different regions" .)
> 
> 3) Is Chi-squared really the right measure of how representative is the
> survey?
> 
> <<< >
> 
> Thanks for any help you can give - hope these questions make sense -
> 
> George H.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] monotonic factors

2011-10-12 Thread Greg Snow
One approach would be to code dummy variables for your factor levels, have d1 
equal to 0 for 'low' and 1 for 'med' and 'high', then have d2 equal to 1 for 
'high' and 0 otherwise.  For linear regression there are functions that will 
fit a model with all non-negative coefficients, but I don't know of anything 
like that for glms, so one option is to fit with all the dummy variables, then 
if any of the estimated coefficients are negative remove that variable (force 
it to 0) and refit.

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

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Jeffrey Pollock
> Sent: Wednesday, October 12, 2011 6:29 AM
> To: r-help@r-project.org
> Subject: [R] monotonic factors
> 
> Hello all,
> 
> 
> 
> I have an ordered factor that I would like to include in the linear
> predictor of a binomial glm, where the estimated coefficients are
> constrained to be monotonic. Does anyone know how to do this? I've
> tried
> using an ordered factor but this does not have the desired effect, an
> (artificial) example of this follows;
> 
> 
> 
> n <- 100
> 
> strings <- sample(c("low", "med", "high"), n, TRUE)
> 
> 
> 
> x.ordered <- ordered(strings, c("low", "med", "high"))
> 
> x.unordered <- factor(strings)
> 
> 
> 
> pr <- ifelse(strings == "low", 0.4, ifelse(strings == "med", 0.3, 0.2))
> 
> 
> 
> y <- rbinom(n, 1, pr)
> 
> 
> 
> mod.ordered <- glm(y ~ x.ordered, binomial)
> 
> mod.unordered <- glm(y ~ x.unordered, binomial)
> 
> 
> 
> summary(mod.ordered)
> 
> summary(mod.unordered)
> 
> -
> ** Confidentiality: The
> contents of this e-mail and any attachments transmitted with it are
> intended to be confidential to the intended recipient; and may be
> privileged or otherwise protected from disclosure. If you are not an
> intended recipient of this e-mail, do not duplicate or redistribute it
> by any means. Please delete it and any attachments and notify the
> sender that you have received it in error. This e-mail is sent by a
> William Hill PLC group company. The William Hill group companies
> include, among others, William Hill PLC (registered number 4212563),
> William Hill Organization Limited (registered number 278208), William
> Hill Credit Limited (registered number 413846), WHG (International)
> Limited (registered number 99191) and WHG Trading Limited (registered
> number 101439). Each of William Hill PLC, William Hill Organization
> Limited and William Hill Credit Limited is registered in Engl!
> 
>  and and Wales and has its registered office at Greenside House, 50
> Station Road, Wood Green, London N22 7TP. Each of WHG (International)
> Limited and WHG Trading Limited is registered in Gibraltar and has its
> registered office at 6/1 Waterport Place, Gibraltar. Unless
> specifically indicated otherwise, the contents of this e-mail are
> subject to contract; and are not an official statement, and do not
> necessarily represent the views, of William Hill PLC, its subsidiaries
> or affiliated companies. Please note that neither William Hill PLC, nor
> its subsidiaries and affiliated companies can accept any responsibility
> for any viruses contained within this e-mail and it is your
> responsibility to scan any emails and their attachments. William Hill
> PLC, its subsidiaries and affiliated companies may monitor e-mail
> traffic data and also the content of e-mails for effective operation of
> the e-mail system, or for security, purposes.
> *
> 
>   [[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] Mysterious Eclipse / StatET error messages

2011-10-12 Thread Al Roark

All,
 
I'm not sure when this started, but I've noticed that just about any time I add 
to an R script in Eclipse, I get a warning in Eclipse's error log that looks 
like the following:
 
Unhandled/Unknown code of R AST node:
  Code: 0x100
  Node: <- (195, 70)  Line 4 at offset 195 (can be wrong, if out of synch):  
 
All of my code appears to execute fine, but I would like to know what sort of 
problem this refers to. I'm running R-2.13.0 and Eclipse 3.7 in a Windows 32 
bit environment. Any clues are much appreciated.
 
Cheers.   
[[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] reasonable theory?

2011-10-12 Thread Spencer Graves
If you know nothing about the black box except that its domain is 
bounded, then I would random sample uniformly from the domain.  If the 
function is monotonically increasing in all variables, then you only 
need to test the two extreme points.  If you know other things, you may 
be able to use the other logic.  Spencer



On 10/12/2011 1:42 PM, James Cloos wrote:

Before coding this in C, I wanted to test the idea out in R.

But I'm unsure if the theory is well-founded.

I have a (user-supplied) black-box function which takes R^n ->  R^3
and a defined domain for each of the input reals.

I want to send some samples through the box to determine an
approximation of the convex hull of the function's range.
(I'll use the library from http://www.qhull.org to compute
the convex hull from the function's outputs.)

My plan is to use the permutation of the min and max values
for the n inputs along with k-1 samples w/in [min,max], but
I want the adjust the k samples a bit to avoid sampling bias.

To make it simpler, let's set the domain to [0,1].

Then, K = { 1/k, 2/k, ... (k-1)/k }

One reasonably easy possibility is to add to each Kn
a linear RV in, say, [-1/k²,1/k²].

Would a normal RV be better?  Some other bell-shaped RV?

Does adding a bit (but not too much) of randomness to the
input values have reason at all?

-JimC



--
Spencer Graves, PE, PhD
President and Chief Technology Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567
web:  www.structuremonitoring.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] Problem with pmax and matrix to calculate row maxima

2011-10-12 Thread R. Michael Weylandt
I think Enrico's solution is probably better overall and doesn't
require as much ugly behind-the-scenes trickery, but here's another
fun way that seems to run ever-so-marginally faster on my machine.

The vapply call is messy, but it seems to get the job done -- if it's
not clear, the point is to break matRandom into a list where each
element was previously one column in preparation for the do.call();
I'd welcome any insight into a slicker way to do so.

t0 <- system.time(matRandom <- matrix(runif(6000*3000),ncol=3000))
# I have to bump up columns to see any meaningful difference

## Enrico's
t1 <- system.time({ test1 <- matRandom[ ,1L];
 for (i in seq.int(2L, ncol(matRandom)))
   test1 <- pmax(test1, matRandom[ ,i])
})


## Mine
t2 <- system.time({
temp <- vapply(seq.int(ncol(matRandom)), function(i,x) list(x[,i]),
vector("list",1) , matRandom)
test2 <- do.call(pmax, temp)
})

identical(test1, test2)
TRUE

t0
 user  system elapsed
   2.580.102.69

t1
  user  system elapsed
   1.630.001.63
 t2

   user  system elapsed
   1.250.001.25

Michael

PS -- It makes me very happy that building matRandom is the slowest
step. All hail the mighty vectorization of R!

On Wed, Oct 12, 2011 at 9:10 AM, Enrico Schumann
 wrote:
>
> Hi Wolfgang,
>
> how about a loop?
>
> matRandom <- matrix(runif(n=60), ncol=6)
>
> ## variant 1
> system.time(test1 <- pmax(matRandom[,1], matRandom[,2], matRandom[,3],
>                          matRandom[,4], matRandom[,5], matRandom[,6]))
>
> User      System verstrichen
> 0.01        0.00        0.01
>
>
> ## variant 2
> system.time(test2 <- apply(matRandom, 1, max))
>
> User      System verstrichen
> 0.56        0.00        0.56
>
>
> ## variant 3
> system.time({
>  test3 <- matRandom[ ,1L]
>  ## add a check that ncol(matrix) > 1L
>  for (i in 2:ncol(matRandom))
>    test3 <- pmax(test3, matRandom[ ,i])
>
> })
> User      System verstrichen
> 0.01        0.00        0.01
>
>
>
>> all.equal(test1,test2)
> [1] TRUE
>
>> all.equal(test1,test3)
> [1] TRUE
>
>
> Regards,
> Enrico
>
> Am 12.10.2011 13:06, schrieb Wolfgang Wu:
>>
>> I am having the following problem. I want to calculate the maximum of each
>> row in a matrix. If I pass in the matrix split up by each column then this
>> is no problem and works great. However I don't know how many columns I have
>> in advance. In the example below I have 3 columns, but the number of columns
>> is not fix. So how do I do this?
>>
>>
>>     matRandom<- matrix(runif(n=30), ncol=3);
>>     #Does not work
>>     pmax(matRandom)
>>     #Does work
>>     pmax(matRandom[,1], matRandom[,2], matRandom[,3])
>>
>>
>> I am aware that I can do it with the apply function, but the calculation
>> is time sensitive so fast execution is important.
>>
>>
>>     #Apply might be too slow
>>
>>     matRandom<- matrix(runif(n=30), ncol=3);
>>     system.time(test<- pmax(matRandom[,1], matRandom[,2], matRandom[,3]))
>>     system.time(test<- apply(matRandom, 1, max))
>>
>>
>>> matRandom<- matrix(runif(n=30), ncol=3);
>>> system.time(test<- pmax(matRandom[,1], matRandom[,2], matRandom[,3]))
>>
>>    user  system elapsed
>>    0.02    0.00    0.02
>>>
>>> system.time(test<- apply(matRandom, 1, max))
>>>     user  system elapsed
>>
>>    2.37    0.00    2.38
>>
>>
>>
>>
>> Thanks for your help.
>>
>> Regards.
>>
>>
>> Wolfgang Wu
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> --
> Enrico Schumann
> Lucerne, Switzerland
> http://nmof.net/
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] treat NA's as zero when summed up with numbers

2011-10-12 Thread Bert Gunter
How about, more simply:

> mysum <- function(x)sum(x,na.rm = any(!is.na(x)))
> mysum(c(1,NA))
[1] 1
> mysum(c(NA,NA))
[1] NA

-- Bert

On Wed, Oct 12, 2011 at 11:03 AM, David Winsemius wrote:

>
> On Oct 12, 2011, at 1:33 PM, David Winsemius wrote:
>
>
>> On Oct 12, 2011, at 12:45 PM, Samir Benzerfa wrote:
>>
>>  Hello everybody,
>>>
>>>
>>>
>>> is there any way to treat NA's as zero when they are summed up with
>>> numbers,
>>> but to treat them as NA's when summed up only with NA's. Specifically
>>> want
>>> that: 5+NA=5, but NA+NA=NA (and not zero).
>>>
>>>
>> sum(x , na.rm=TRUE)
>>
>
> When I read that a second time I realized my reply was unresponsive.
>
> > if (all( is.na(NA) )) NA else sum( NA, na.rm=TRUE)
> [1] NA
> > if (all( is.na(c(1,NA)) )) NA else sum( c(1,NA), na.rm=TRUE)
> [1] 1
>
>
>
>> --
>> 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.
>>
>
> 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.
>



-- 

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

[[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] reasonable theory?

2011-10-12 Thread James Cloos
Before coding this in C, I wanted to test the idea out in R.

But I'm unsure if the theory is well-founded.

I have a (user-supplied) black-box function which takes R^n -> R^3
and a defined domain for each of the input reals.

I want to send some samples through the box to determine an
approximation of the convex hull of the function's range.
(I'll use the library from http://www.qhull.org to compute
the convex hull from the function's outputs.)

My plan is to use the permutation of the min and max values
for the n inputs along with k-1 samples w/in [min,max], but
I want the adjust the k samples a bit to avoid sampling bias.

To make it simpler, let's set the domain to [0,1].

Then, K = { 1/k, 2/k, ... (k-1)/k }

One reasonably easy possibility is to add to each Kn
a linear RV in, say, [-1/k²,1/k²].

Would a normal RV be better?  Some other bell-shaped RV?

Does adding a bit (but not too much) of randomness to the
input values have reason at all?

-JimC
-- 
James Cloos  OpenPGP: 1024D/ED7DAEA6

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


Re: [R] Generelized Negative Binomial model in R

2011-10-12 Thread Ben Bolker
Steve Lianoglou  gmail.com> writes:

> 
> Hi,
> 
> On Wed, Oct 12, 2011 at 11:23 AM, Akram Khaleghei Ghosheh balagh
>  gmail.com> wrote:
> > Hello;
> >
> > Does anybody knows that R have a function for Generelized Negative Binomial
> > model, something like "gnbreg" in "STATA" where dispersion parameter itself
> > is a function of covaraites ?
> 
> Take a look at the edgeR (and DESeq) package in bioconductor.
> 
> edgeR uses a GLMs w/ negative binomial to assess differential
> expression of genomic regions using count data (aka next generation
> sequencing data).
> 
> http://www.bioconductor.org/packages/release/bioc/html/edgeR.html
> http://www.bioconductor.org/packages/release/bioc/html/DESeq.html
> 

  You could code it fairly easily in mle2, e.g.

mle2(y~dnbinom(exp(logmu),exp(logk)),
   data=..., start=...,
   parameters=list(logmu~...,logk~...)

where the ... within parameters specify linear models for the log-mean
and log-overdispersion parameters.
  You do have to specify your own starting conditions, and it doesn't
do anything clever in terms of special-purpose optimization -- it just
uses the optimizers built into optim() [with a few other choices, e.g.
those from the optimx package]

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


Re: [R] loop function within a loop

2011-10-12 Thread William Dunlap
Is this the result you are after, where the event number
(within a group) are sorted according to the event/prev_event
pairs (prev_event in a row matches event of the previous row)?

> ave(d, d$group,  FUN=function(z) z[ match(tsort(z$prev_event, z$event)[-1], 
> z$event), ])
   event prev_event group
1845  0  5360
2234845  5360
3993234  5360
4153993  5360
5926153  5360
6848926  5360
7234  0  8765
8968234  8765
9545968  8765
10   625111  3334
11   713625  3334
12   227713  3334
13   181227  3334
14   744181  3334
15   913  0  2329
16   355913  2329
17   761355  2329
18   324761  2329
19   119324  2329
20   372119  2329
21   890372  2329
22   189890  2329
23   719189  2329
24   266719  2329

'tsort' is a topological sorting function, like
the Unix tsort.  It is overkill for this application
(and probably could be faster and do some more
error checking) but I had it hanging around:

tsort <- function (before, after) 
{
# topological sort: Kahn's 1962 algorithm, from Wikipedia 
# before and after should be equal-length vectors of the
# same type.
L <- before[0]
S <- setdiff(before, after)
while (length(S) > 0) {
n <- S[1]
S <- S[-1]
L[length(L) + 1] <- n
m <- after[e <- before == n]
after <- after[!e]
before <- before[!e]
S <- c(S, m[!is.element(m, after)])
}
if (length(after) > 0) {
stop("Graph contains a cycle")
}
else {
L
}
}

Your data was

d <- data.frame(
  event = c(845, 926, 993, 234, 848, 153, 234, 968, 545, 625, 744, 181, 
713, 227, 913, 372, 719, 119, 761, 890, 266, 324, 189, 355),
  prev_event = c(0, 153, 234, 845, 926, 993, 0, 234, 968, 111, 181, 227, 625, 
713, 0, 119, 189, 324, 355, 372, 719, 761, 890, 913),
  group = c(5360, 5360, 5360, 5360, 5360, 5360, 8765, 8765, 8765, 3334, 
3334, 3334, 3334, 3334, 2329, 2329, 2329, 2329, 2329, 2329, 2329, 
2329, 2329, 2329))

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 Sally Zhen
> Sent: Wednesday, October 12, 2011 7:56 AM
> To: r-help@r-project.org
> Subject: [R] loop function within a loop
> 
> Hi all,
> 
> I'm working on a loop function for a large dataset which contains 1000
> different groups. I would like to reconstruct the order of events within
> each group by using a loop function in R. (Currently the order of events are
> based on the ascending order of prev_event within the group)
> 
> 
> A demo data frame:
> 
> event   prev_event   group
> 845  0   5360
> 926  1535360
> 993  2345360
> 234  8455360
> 848  9265360
> 153  9935360
> 234  0   8765
> 968  2348765
> 545  9688765
> 625  1113334
> 744  1813334
> 181  2273334
> 713  6253334
> 227  7133334
> 913  0   2329
> 372  1192329
> 719  1892329
> 119  3242329
> 761  3552329
> 890  3722329
> 266  7192329
> 324  7612329
> 189  8902329
> 355  9132329
> 
> 
> Below is what I have written:
> 
> ordering <- vector("list", length(unique(mydata$group)))
> for (j in 1:length(unique(mydata$group))){
> group.j <- mydata[mydata$group == unique(mydata$group)[j], ]
> ordering.j <- c()
> ordering.j[1] <- ifelse(group.j[1, ]$prev_event == 0, group.j[1, ]$event,
> group.j[1, ]$prev_event)
> for (i in 2:nrow(group.j)){
> ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i-1], ]$event}
> ordering[j] <- ordering.j}
> ordering
> 
> What I got is:
> Error in ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i -  :
>   replacement has length zero
> > ordering
> [[1]]
> NULL
> 
> [[2]]
> NULL
> 
> [[3]]
> NULL
> 
> 
> However, when I accidentally put a typo in the loop function, instead of
> ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i-1], ]$event},
> I put
> ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i-1],
> ]$prev_event},
> The output is a list of 1000 entries, each with the first event within the
> group, and I received the following warning messages:
> [[1]]
> [1] 1.000680e+17
> 
> [[2]]
> [1] 1.001390e+17
> 
> [[3]]
> [1] 1.001450e+17
> 
> 49: In ordering[j] <- ordering.j :
>   number of items to replace is not a multiple of replacement length
> 50: In ordering.j[i] <- group.j[group.j$prev_event ==  ... :
>   num

Re: [R] reading large numbers

2011-10-12 Thread R. Michael Weylandt
Like I said on the other thread you started on this same issue, this
is just a print setting, not something with the data.

Consider this:

R>  as.numeric(4398801.3) ==  4398801.3
TRUE

If you want to change this, try

options(digits = 14) # or however many you want to see

And don't jump ship on threads where we've started on a topic, it just
confuses the matter

Michael

On Wed, Oct 12, 2011 at 3:47 PM, Veerappa Chetty  wrote:
> Hi,
> This happens when I read in large numbers;
> 
>> as.numeric(4398801.3)
> [1] 4398801
>
>> as.numeric(439880.3)
> [1] 439880.3
> 
> Please help to read in numbers with more than 8 characters!
> Thanks.
> Chetty
>
> --
> Professor of Family Medicine
> Boston University
> Tel: 617-414-6221, Fax:617-414-3345
> emails: chett...@gmail.com,vche...@bu.edu
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] reading large numbers

2011-10-12 Thread Sarah Goslee
I believe you were already answered.

Nothing is happening to your numbers. The default digits
used to *display* your numbers is too small to show all
the decimal places.

There's nothing to worry about; full precision is being used
for all calculations.

But if for some reason you'd like to see them, you can
change the default digits used for printing:

> as.numeric(4398801.3)
[1] 4398801
> as.numeric(439880.3)
[1] 439880.3
>
> options()$digits
[1] 7
>
> options(digits=14)
>
> as.numeric(4398801.3)
[1] 4398801.3
> as.numeric(439880.3)
[1] 439880.3

Sarah

On Wed, Oct 12, 2011 at 3:47 PM, Veerappa Chetty  wrote:
> Hi,
> This happens when I read in large numbers;
> 
>> as.numeric(4398801.3)
> [1] 4398801
>
>> as.numeric(439880.3)
> [1] 439880.3
> 
> Please help to read in numbers with more than 8 characters!
> Thanks.
> Chetty
>

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

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


Re: [R] large numbers

2011-10-12 Thread R. Michael Weylandt
Well that's different. Can you restart R and get the same error
message? If so, change print() to print.default() to get around the
class error for now.

And I just want to make sure of one thing: you did actually change
"valueFromImport" to whatever you named the output of the read.csv()
call, right? I don't know why what would have lead to the error you
got, but one never knows...

If none of the above works, please reply with the result of dput() on
your data and the results of sessionInfo()

Michael

PS -- It's good practice to cc the list as well.

On Wed, Oct 12, 2011 at 3:33 PM, Veerappa Chetty  wrote:
> Thanks.
> I get this:
> print(valueFromImport - 43988014)
> Error in print(valueFromImport - 43988014) :
>   error in evaluating the argument 'x' in selecting a method for function
> 'print'
>
>
>
>
>
> On Wed, Oct 12, 2011 at 3:20 PM, R. Michael Weylandt
>  wrote:
>>
>> Are you sure its being imported into R without the decimal and that
>> it's not just a print option? I can't off the cuff think of a reason
>> why that would happen...
>>
>> Try print(valueFromImport - 43988014) and see what you get
>>
>> Michael
>>
>> On Wed, Oct 12, 2011 at 3:16 PM, Veerappa Chetty 
>> wrote:
>> > Hi,
>> > When I import an excel "CSV" file, large numbers such as " 43988014.3"
>> > is
>> > imported as "43988014", leaving out the decimal ".4". How to import
>> > keeping
>> > the fraction?
>> > Thanks.
>> > Chetty
>> >
>> > --
>> > Professor of Family Medicine
>> > Boston University
>> > Tel: 617-414-6221, Fax:617-414-3345
>> > emails: chett...@gmail.com,vche...@bu.edu
>> >
>> >        [[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> >
>
>
>
> --
> Professor of Family Medicine
> Boston University
> Tel: 617-414-6221, Fax:617-414-3345
> emails: chett...@gmail.com,vche...@bu.edu
>

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


[R] reading large numbers

2011-10-12 Thread Veerappa Chetty
Hi,
This happens when I read in large numbers;

> as.numeric(4398801.3)
[1] 4398801

> as.numeric(439880.3)
[1] 439880.3

Please help to read in numbers with more than 8 characters!
Thanks.
Chetty

-- 
Professor of Family Medicine
Boston University
Tel: 617-414-6221, Fax:617-414-3345
emails: chett...@gmail.com,vche...@bu.edu

[[alternative HTML version deleted]]

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


Re: [R] large numbers

2011-10-12 Thread R. Michael Weylandt
Are you sure its being imported into R without the decimal and that
it's not just a print option? I can't off the cuff think of a reason
why that would happen...

Try print(valueFromImport - 43988014) and see what you get

Michael

On Wed, Oct 12, 2011 at 3:16 PM, Veerappa Chetty  wrote:
> Hi,
> When I import an excel "CSV" file, large numbers such as " 43988014.3" is
> imported as "43988014", leaving out the decimal ".4". How to import keeping
> the fraction?
> Thanks.
> Chetty
>
> --
> Professor of Family Medicine
> Boston University
> Tel: 617-414-6221, Fax:617-414-3345
> emails: chett...@gmail.com,vche...@bu.edu
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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

2011-10-12 Thread Veerappa Chetty
Hi,
When I import an excel "CSV" file, large numbers such as " 43988014.3" is
imported as "43988014", leaving out the decimal ".4". How to import keeping
the fraction?
Thanks.
Chetty

-- 
Professor of Family Medicine
Boston University
Tel: 617-414-6221, Fax:617-414-3345
emails: chett...@gmail.com,vche...@bu.edu

[[alternative HTML version deleted]]

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


Re: [R] Simple question regarding to specifying model

2011-10-12 Thread BvZ
Tried this, it does not seem to work.  

It is really simple what I am trying to do.  I have a pre-specified best-fit
line, and wish to run some diagnostic tests for goodness of fit.

I will play around with the predict function, thanks a lot David!

--
View this message in context: 
http://r.789695.n4.nabble.com/Simple-question-regarding-to-specifying-model-tp3899049p3899216.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] strange behavior with R.dll

2011-10-12 Thread Duncan Murdoch

On 12/10/2011 3:03 PM, Erin Hodgess wrote:

Dear R People:

I am using R-2.13.2 on a Windows 7 machine.

I compiled from source on 32 bit a couple of weeks ago and the R.dll
got removed by my anti-virus software.

Same thing on 64 bit today.

Is anyone having this problem, please?

I'm using Norton AV.


I haven't heard of this particular problem before.  Generally the 
problems we have had have been with other Antivirus programs finding 
false positives in our pre-compiled distributions.


Duncan Murdoch

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


Re: [R] R and Forex

2011-10-12 Thread R. Michael Weylandt
As was pointed out to you before, this is really more of an
R-SIG-Finance question, but I wouldn't expect too much explanation
there either, just people pointing you to the standard R finance tools
(quantmod, zoo/xts, TTR, RBloomberg, and the Rmetrics suite; there's
also some fantastic tools in development but if you just picked up
your first book on R, you probably aren't ready for those yet).

You question isn't particularly well-defined either:

Do you just want to study currency price series in R? This is simple:
just get the data (perhaps from oanda using quantmod::getSymbols or
simply by reading in through any of the regular functions) and study
it however you like.

The actual act of trading, however, is harder to do solely within R:
there is a very popular IBrokers API but I haven't used it much. It
sounds like you are probably a lone trader so if you don't have a
pre-existing relationship with IBrokers you'll probably want to enter
trades through whichever broker you currently use. That -- the
IBrokers package -- is the complete only solution on that end I'm
aware of, though I'm sure many folks have their own work-arounds.

And as far as experiences go: well, I suppose folks wouldn't be doing
it if they thought there was no money to be made, now would they?

If you want more to read: check the CRAN task views, as suggested before.

Michael

PS -- A serious note: FX is much closer to a zero-sum game than
long-equity, I would be remiss if I didn't warn you to tread
carefully.

On Wed, Oct 12, 2011 at 1:50 PM, Yves S. Garret
 wrote:
> Yes, that's what I meant.  Curious what the experiences were of some people
> and some tips.
>
> On Wed, Oct 12, 2011 at 12:31 PM, R. Michael Weylandt
>  wrote:
>>
>> "This" being what exactly?
>>
>> Traded in FX using R? Yes, its done everyday, even as I type
>>
>> Michael
>>
>> On Wed, Oct 12, 2011 at 8:10 AM, Yves S. Garret
>>  wrote:
>> > No, that's not what I meant.  I was curious if anyone has ever done this
>> > before and how well it worked.  Any tips for a novice?
>> >
>> > On Wed, Oct 12, 2011 at 12:19 AM, Liviu Andronic
>> > wrote:
>> >
>> >> On Wed, Oct 12, 2011 at 3:29 AM, Yves S. Garret
>> >>  wrote:
>> >> > Hi all,
>> >> >
>> >> >   I recently started learning about Forex and found this O'Reilly
>> >> > book in
>> >> > Barnes & Nobles about R.  I bought it out of pure curiosity.  I like
>> >> > what
>> >> I
>> >> > see.  However, I have a question.  Has anyone tried to bring these
>> >> > two
>> >> ideas
>> >> > together in a financial and trading sense?  Are there any libraries
>> >> > or
>> >> > modules in R that can aid in this venture?
>> >> >
>> >>
>> >> > fortune('equity')
>> >>
>> >> I have never heard anyone (knowledgable or otherwise) claim that, in
>> >> the
>> >> absence of transition costs, SAS is better than R for equity modeling.
>> >> If
>> >> you
>> >> come across any such claim, I would be happy to refute it.
>> >>   -- David Kane
>> >>      R-SIG-Finance (December 2004)
>> >>
>> >>
>> >> You may want to address this question to r-sig-finance, and check out
>> >> the Finance Task View [1]. Regards
>> >> Liviu
>> >>
>> >> [1] http://cran.at.r-project.org/web/views/Finance.html
>> >>
>> >>
>> >> > --Yves
>> >> >
>> >> >        [[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.
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> Do you know how to read?
>> >> http://www.alienetworks.com/srtest.cfm
>> >> http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
>> >> Do you know how to write?
>> >> http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
>> >>
>> >
>> >        [[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] Tinn-R change editor background color

2011-10-12 Thread Ben qant
Never mind: option > color preference
Sorry...overlooked that 10 times I guess.

regards


On Wed, Oct 12, 2011 at 12:54 PM, Ben qant  wrote:

> Hello,
>
> Does anyone know how to change the Tinn-R editor background color? White is
> rough on the eyes...
>
> 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] strange behavior with R.dll

2011-10-12 Thread Erin Hodgess
Dear R People:

I am using R-2.13.2 on a Windows 7 machine.

I compiled from source on 32 bit a couple of weeks ago and the R.dll
got removed by my anti-virus software.

Same thing on 64 bit today.

Is anyone having this problem, please?

I'm using Norton AV.

Thanks,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

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


[R] Tinn-R change editor background color

2011-10-12 Thread Ben qant
Hello,

Does anyone know how to change the Tinn-R editor background color? White is
rough on the eyes...

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.


Re: [R] Simple question regarding to specifying model

2011-10-12 Thread David Winsemius


On Oct 12, 2011, at 2:25 PM, BvZ wrote:

I have hunted around but cannot find the command which allows me to  
specify

parameters of a model.

For example,

model.m1 <- nls(y ~ alpha * x1/(beta + x1), data = data, start =  
list(beta =

20, alpha = 120), trace = TRUE)

This will estimate the parameters, which allows to investigate the
residuals.

What I would like to do is fix the parameters to the data that I have
estimated elsewhere, to analyse their residuals. For example,

model.m2 <- y ~ 80 * x1/30 +x1 ??


Wouldn't this just be

resids <- predict(model.m1) - with( data,  80 * x1/30 +x1)

--

David Winsemius, MD
West Hartford, CT

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


Re: [R] How to run Rcmdr with OS 10.4?

2011-10-12 Thread Robert Baer
As the posting guide tells you, the first thing to try is to install the 
latest version of R.



-Original Message- 
From: roche...@free.fr

Sent: Tuesday, October 11, 2011 5:44 AM
To: r-help@r-project.org
Subject: [R] How to run Rcmdr with OS 10.4?


I've installed Rcmdr package and it doesn't run
Here is the error message:


R version 2.9.2 (2009-08-24)
[R.app GUI 1.29 (5464) powerpc-apple-darwin8.11.1]

[Workspace restored from /Users/jfc/Documents/TravauxFR/.RData]

Le chargement a nécessité le package : tcltk
Chargement de Tcl/Tk... terminé
Le chargement a nécessité le package : car
Error in structure(.External("dotTclObjv", objv, PACKAGE = "tcltk"), class = 
"tclObj") :

 [tcl] invalid command name "font".

De plus : Warning message:
In fun(...) : couldn't connect to display ":0"
Error : .onAttach a échoué dans 'attachNamespace'
Erreur : le chargement du package / espace de noms a échoué pour 'Rcmdr'


I've tried another version 2.10.2 and Rcmdr with its dependences and it 
returns the same warnings!
I feel that something lacks on my computer. X11 works and I've installed 
TcTlk 8.5.5-x11.


What else to do?

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


--
Robert W. Baer, Ph.D.
Professor of Physiology
Kirksville College of Osteopathic Medicine
A. T. Still University of Health Sciences
800 W. Jefferson St.
Kirksville, MO 63501
660-626-2322
FAX 660-626-2965

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Simple question regarding to specifying model

2011-10-12 Thread BvZ
I have hunted around but cannot find the command which allows me to specify
parameters of a model.

For example,

model.m1 <- nls(y ~ alpha * x1/(beta + x1), data = data, start = list(beta =
20, alpha = 120), trace = TRUE)

This will estimate the parameters, which allows to investigate the
residuals.

What I would like to do is fix the parameters to the data that I have
estimated elsewhere, to analyse their residuals. For example,

model.m2 <- y ~ 80 * x1/30 +x1 ??

Thanks


--
View this message in context: 
http://r.789695.n4.nabble.com/Simple-question-regarding-to-specifying-model-tp3899049p3899049.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] Minimum cutsets

2011-10-12 Thread malhomidi

 Hi Gabor,

 Thanks for the reply. I'm actually working on directed graphs and using
Windows. Please, send me the windows version of the source code.

 Regards,
Mohammed  

--
View this message in context: 
http://r.789695.n4.nabble.com/Minimum-cutsets-tp885346p3899012.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] Minimization/Optimization under functional constraints

2011-10-12 Thread forget_f1
Hi,

I hope someone can help me with the following issue.

I need find the minimum beta that satisfies the following:

inf{beta>0 | f(x+beta*f(x))*f(x)<=0}

where f() is a function and x is a sample statistic.

Functions such as "nlminb" and "constrOptim" minimize a function and output
the parameter (under parameter constraints).  I need to minimize the
parameter (also constraint) under the functional constraint.  

Obviously,  I can start with a vector for beta (starting from 0) and find
when the switch from >0 to <=0 occurs for the functional argument, but was
wondering if there is a more efficient method/function. 

Thanks!!!

--
View this message in context: 
http://r.789695.n4.nabble.com/Minimization-Optimization-under-functional-constraints-tp3899020p3899020.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] treat NA's as zero when summed up with numbers

2011-10-12 Thread David Winsemius


On Oct 12, 2011, at 1:33 PM, David Winsemius wrote:



On Oct 12, 2011, at 12:45 PM, Samir Benzerfa wrote:


Hello everybody,



is there any way to treat NA's as zero when they are summed up with  
numbers,
but to treat them as NA's when summed up only with NA's.  
Specifically want

that: 5+NA=5, but NA+NA=NA (and not zero).



sum(x , na.rm=TRUE)


When I read that a second time I realized my reply was unresponsive.

> if (all( is.na(NA) )) NA else sum( NA, na.rm=TRUE)
[1] NA
> if (all( is.na(c(1,NA)) )) NA else sum( c(1,NA), na.rm=TRUE)
[1] 1




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


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] loop function within a loop

2011-10-12 Thread David Winsemius


On Oct 12, 2011, at 10:55 AM, Sally Zhen wrote:


Hi all,

I'm working on a loop function for a large dataset which contains 1000
different groups. I would like to reconstruct the order of events  
within

each group by using a loop function in R.


Not generally a good first strategy in R.


(Currently the order of events are
based on the ascending order of prev_event within the group)


Wouldn't this just be:

dfrm[order(dfrm$group, dfrm$event), ]

(Ascending is the default ordering.)
--
David.



A demo data frame:

event   prev_event   group
845  0   5360
926  1535360
993  2345360
234  8455360
848  9265360
153  9935360
234  0   8765
968  2348765
545  9688765
625  1113334
744  1813334
181  2273334
713  6253334
227  7133334
913  0   2329
372  1192329
719  1892329
119  3242329
761  3552329
890  3722329
266  7192329
324  7612329
189  8902329
355  9132329


Below is what I have written:

ordering <- vector("list", length(unique(mydata$group)))
for (j in 1:length(unique(mydata$group))){
group.j <- mydata[mydata$group == unique(mydata$group)[j], ]
ordering.j <- c()
ordering.j[1] <- ifelse(group.j[1, ]$prev_event == 0, group.j[1, ] 
$event,

group.j[1, ]$prev_event)
for (i in 2:nrow(group.j)){
ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i-1], ] 
$event}

ordering[j] <- ordering.j}
ordering

What I got is:
Error in ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i  
-  :

 replacement has length zero

ordering

[[1]]
NULL

[[2]]
NULL

[[3]]
NULL


However, when I accidentally put a typo in the loop function,  
instead of
ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i-1], ] 
$event},

I put
ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i-1],
]$prev_event},
The output is a list of 1000 entries, each with the first event  
within the

group, and I received the following warning messages:
[[1]]
[1] 1.000680e+17

[[2]]
[1] 1.001390e+17

[[3]]
[1] 1.001450e+17

49: In ordering[j] <- ordering.j :
 number of items to replace is not a multiple of replacement length
50: In ordering.j[i] <- group.j[group.j$prev_event ==  ... :
 number of items to replace is not a multiple of replacement length


Why is this happening, and how can I fix it? Any pointer will be  
greatly

appreciated!

[[alternative HTML version deleted]]

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] high and lowest with names

2011-10-12 Thread Ben qant
Hello,

This is my solution. This is pretty fast (tested with a larger data set)! If
you have a more elegant way to do it (of similar speed), please reply.
Thanks for the help!

## get highest and lowest values and names of a matrix
# create sample data
x <- swiss$Education[1:25]
dat = matrix(x,5,5)
colnames(dat) = c('a','b','c','d','e')
rownames(dat) = c('z','y','x','w','v')

#my solution

nms = dimnames(dat) #get matrix row and col names
cnt = 10 # number of max and mins to get

tmp = dat
mxs = list("list",cnt)
mns = list("list",cnt)
for(i in 1:cnt){
  #get maxes
  mx_dims = arrayInd(which.max(tmp), dim(tmp)) # get max dims for entire
matrix note: which.max also removes NA's
  mx_nm = c(nms[[1]][mx_dims[1]],nms[[2]][mx_dims[2]]) #get names
  mx = tmp[mx_dims] # get max value
  mxs[[i]] = c(mx,mx_nm) # add max and dim names to list of maxes
  tmp[mx_dims] = NA #removes last max so new one is found

  #get mins (basically same as above)
  mn_dims = arrayInd(which.min(tmp), dim(tmp))
  mn_nm = c(nms[[1]][mn_dims[1]],nms[[2]][mn_dims[2]])
  mn = tmp[mn_dims]
  mns[[i]] = c(mn,mn_nm)
  tmp[mn_dims] = NA
}

mxs
mns

# end

Regards,

Ben

On Tue, Oct 11, 2011 at 5:32 PM, "Dénes TÓTH"  wrote:

>
> which.max is even faster:
>
> dims <- c(1000,1000)
> tt <- array(rnorm(prod(dims)),dims)
> # which
> system.time(
> replicate(100, which(tt==max(tt), arr.ind=TRUE))
> )
> # which.max (& arrayInd)
> system.time(
> replicate(100, arrayInd(which.max(tt), dims))
> )
>
> Best,
> Denes
>
> > But it's simpler and probably faster to use R's built-in capabilities.
> > ?which ## note the arr.ind argument!)
> >
> > As an example:
> >
> > test <- matrix(rnorm(24), nr = 4)
> > which(test==max(test), arr.ind=TRUE)
> >  row col
> > [1,]   2   6
> >
> > So this gives the row and column indices of the max, from which row and
> > column names can easily be obtained from the dimnames attribute of the
> > matrix.
> >
> > Note: This assumes that the object in question is a matrix, NOT a data
> > frame, for which it would be slightly more complicated.
> >
> > -- Bert
> >
> >
> > On Tue, Oct 11, 2011 at 3:06 PM, Carlos Ortega
> > wrote:
> >
> >> Hi,
> >>
> >> With this code you can find row and col names for the largest value
> >> applied
> >> to your example:
> >>
> >> r.m.tmp<-apply(dat,1,max)
> >> r.max<-names(r.m.tmp)[r.m.tmp==max(r.m.tmp)]
> >>
> >> c.m.tmp<-apply(dat,2,max)
> >> c.max<-names(c.m.tmp)[c.m.tmp==max(c.m.tmp)]
> >>
> >> It's inmediate how to get the same for the smallest and build a function
> >> to
> >> calculate everything and return a list.
> >>
> >>
> >> Regards,
> >> Carlos Ortega
> >> www.qualityexcellence.es
> >>
> >> 2011/10/11 Ben qant 
> >>
> >> > Hello,
> >> >
> >> > I'm looking to get the values, row names and column names of the
> >> largest
> >> > and
> >> > smallest values in a matrix.
> >> >
> >> > Example (except is does not include the names):
> >> >
> >> > > x <- swiss$Education[1:25]
> >> > > dat = matrix(x,5,5)
> >> > > colnames(dat) = c('a','b','c','d','c')
> >> > > rownames(dat) = c('z','y','x','w','v')
> >> > > dat
> >> >   a  b  c  d  c
> >> > z 12  7  6  2 10
> >> > y  9  7 12  8  3
> >> > x  5  8  7 28 12
> >> > w  7  7 12 20  6
> >> > v 15 13  5  9  1
> >> >
> >> > > #top 10
> >> > > sort(dat,partial=n-9:n)[(n-9):n]
> >> >  [1]  9 10 12 12 12 12 13 15 20 28
> >> > > # bottom 10
> >> > > sort(dat,partial=1:10)[1:10]
> >> >  [1] 1 2 3 5 5 6 6 7 7 7
> >> >
> >> > ...except I need the rownames and colnames to go along for the ride
> >> with
> >> > the
> >> > values...because of this, I am guessing the return value will need to
> >> be
> >> a
> >> > list since all of the values have different row and col names (which
> >> is
> >> > fine).
> >> >
> >> > Regards,
> >> >
> >> > 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.
> >>
> >
> >   [[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/listin

Re: [R] treat NA's as zero when summed up with numbers

2011-10-12 Thread David Winsemius


On Oct 12, 2011, at 12:45 PM, Samir Benzerfa wrote:


Hello everybody,



is there any way to treat NA's as zero when they are summed up with  
numbers,
but to treat them as NA's when summed up only with NA's.  
Specifically want

that: 5+NA=5, but NA+NA=NA (and not zero).



sum(x , na.rm=TRUE)

--
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] exclude columns with at least three consecutive zeros

2011-10-12 Thread William Dunlap
First define a function that returns TRUE if a column
should be dropped.  E.g.,

  has3Zeros.1 <- function(x) 
  {
  x <- x[!is.na(x)] == 0 # drop NA's, convert 0's to TRUE, others to FALSE
  if (length(x) < 3) {
  FALSE # you may want to further test short vectors
  } else {
  i <- seq_len(length(x) - 2)
  any(x[i] & x[i + 1] & x[i + 2])
  }
  }

or

  has3Zeros.2 <- function (x) 
  {
  x <- x[!is.na(x)] == 0
  r <- rle(x)
  any(r$lengths[r$values] >= 3)
  }

The use sapply on your data.frame with this function to see which
columns to omit and use [ to omit them:
  > e <- data.frame(Date=1980:1985,
  + A = c(2, 9, 18, 0, 12, 48),
  + B = c(75, NA, 15, 16, 43, 3),
  + C = c(12, 7, 0, 0, 0, 26),
  + D = c(41, 0, 0, NA, 0, 21))
  > e[, !sapply(e, has3Zeros.1), drop=FALSE]
Date  A  B
  1 1980  2 75
  2 1981  9 NA
  3 1982 18 15
  4 1983  0 16
  5 1984 12 43
  6 1985 48  3

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 Samir Benzerfa
> Sent: Wednesday, October 12, 2011 8:35 AM
> To: r-help@r-project.org
> Subject: [R] exclude columns with at least three consecutive zeros
> 
> Hi everyone,
> 
> 
> 
> I have a large data set with about 3'000 columns and I would like to exclude
> all columns which include three or more consecutive zeros (see below
> example). A further issue is that it should just jump NA values if any. How
> can I do this?
> 
> 
> 
> In the below example R should exclude column C and D (since in D jumping the
> NA leaves three consecutive zeros).
> 
> 
> 
> I would appreciate any solutions to this issue.
> 
> 
> 
> Many thanks!
> 
> S.B.
> 
> 
> 
> Date  A B C D
> 
> 1980  2 75   12   41
> 
> 1981  9 NA 7 0
> 
> 1982  18   15   0 0
> 
> 1983  0 16   0 NA
> 
> 1984  12   43   0 0
> 
> 1985  48   3 26   21
> 
> 
> 
> 
>   [[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] loop function within a loop

2011-10-12 Thread Weidong Gu
It's better to avoid loop in this situation. If you want to reorder
subsets of the data based on event, the follow works

df<-read.table('clipboard',header=TRUE)
sp.or<-lapply(split(df,df$group),function(ldf) ldf[order(ldf$event),])
new.df<-do.call('rbind',sp.or)

Weidong Gu

On Wed, Oct 12, 2011 at 10:55 AM, Sally Zhen  wrote:
> Hi all,
>
> I'm working on a loop function for a large dataset which contains 1000
> different groups. I would like to reconstruct the order of events within
> each group by using a loop function in R. (Currently the order of events are
> based on the ascending order of prev_event within the group)
>
>
> A demo data frame:
>
> event       prev_event   group
> 845          0               5360
> 926          153            5360
> 993          234            5360
> 234          845            5360
> 848          926            5360
> 153          993            5360
> 234          0               8765
> 968          234            8765
> 545          968            8765
> 625          111            3334
> 744          181            3334
> 181          227            3334
> 713          625            3334
> 227          713            3334
> 913          0               2329
> 372          119            2329
> 719          189            2329
> 119          324            2329
> 761          355            2329
> 890          372            2329
> 266          719            2329
> 324          761            2329
> 189          890            2329
> 355          913            2329
>
>
> Below is what I have written:
>
> ordering <- vector("list", length(unique(mydata$group)))
> for (j in 1:length(unique(mydata$group))){
> group.j <- mydata[mydata$group == unique(mydata$group)[j], ]
> ordering.j <- c()
> ordering.j[1] <- ifelse(group.j[1, ]$prev_event == 0, group.j[1, ]$event,
> group.j[1, ]$prev_event)
> for (i in 2:nrow(group.j)){
> ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i-1], ]$event}
> ordering[j] <- ordering.j}
> ordering
>
> What I got is:
> Error in ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i -  :
>  replacement has length zero
>> ordering
> [[1]]
> NULL
>
> [[2]]
> NULL
>
> [[3]]
> NULL
>
>
> However, when I accidentally put a typo in the loop function, instead of
> ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i-1], ]$event},
> I put
> ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i-1],
> ]$prev_event},
> The output is a list of 1000 entries, each with the first event within the
> group, and I received the following warning messages:
> [[1]]
> [1] 1.000680e+17
>
> [[2]]
> [1] 1.001390e+17
>
> [[3]]
> [1] 1.001450e+17
>
> 49: In ordering[j] <- ordering.j :
>  number of items to replace is not a multiple of replacement length
> 50: In ordering.j[i] <- group.j[group.j$prev_event ==  ... :
>  number of items to replace is not a multiple of replacement length
>
>
> Why is this happening, and how can I fix it? Any pointer will be greatly
> appreciated!
>
>        [[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] Minimum cutsets

2011-10-12 Thread Gábor Csárdi
Hi Mohammed,

http://igraph.sourceforge.net/doc/R/graph.maxflow.html

For directed graphs, and s-t cuts you need the development version,
from igraph.sf.net. The source code is either here:
http://cran.r-project.org/web/packages/igraph/index.html
or here:
http://code.google.com/p/igraph/downloads/list
or here:
https://code.launchpad.net/igraph/

The development version has some big changes, e.g. vertices and edges
are numbered from 1 instead of 0. Tell me if you need a windows binary
package for the development version.

Best,
Gabor

On Wed, Oct 12, 2011 at 11:14 AM, malhomidi  wrote:
> Hi Gabor,
>
>        I'm looking for minimum cutsets in the igraph manual but I didn't
> find the functions you mentioned above. Also, how can I see their source
> code.
>
> Thanks,
> Mohammed
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Minimum-cutsets-tp885346p3898347.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.
>



-- 
Gabor Csardi      MTA KFKI RMKI

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


Re: [R] Nonlinear regression aborting due to error

2011-10-12 Thread Jean V Adams
Dennis Fisher  wrote on 10/12/2011 08:06:12 AM:
> 
> jean
> 
> initial values:
> INITEMAX   <- -25
> INITEFFECT  <- 25
> INITC50 <- 14
> GAMMA <- INITGAMMA   <- 500
> 
> see below for other issues.
> 
> dennis
> 
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.com
> 
> On Oct 12, 2011, at 5:40 AM, Jean V Adams wrote:
> 
> > It's great that you provided code, data, and error messages for 
> > clarity.  But, without knowing what the starting values are 
> > (INITEMAX, INITEFFECT, INITC50, and INITGAMMA), I can't reproduce 
> > what you're doing. 
> > 
> > I'm also a bit confused about GAMMA.  In your first fit you don't 
> > provide a starting value for GAMMA, so it is being treated as an 
> > independent variable.  But in your second fit, you do provide 
> > starting values for GAMMA, so it is being treated as a parameter to 
> > be estimated.  Which is correct? 
> 
> your assessment is correct.  one approach applies the initial value 
> for GAMMA; the other estimates a value.
> 
> > Finally, I was able to look at the plot of XVAR vs. YVAR, and there 
> > is so much noise that it's not surprising you're having difficulty 
> > fitting a four-parameter non-linear model. 
> 
> i sent only a subset of the data and i added noise (to preserve 
> confidentiality).  the entire dataset looks much better, although 
> somewhat noisy.  in that context, i expected GAMMA to estimated at a
> small value, i.e., a large value for GAMMA would imply a sharp 
> distinction, something not supported by the data.
> 
> 
> > Jean


I can't get convergence either if I try to estimate GAMMA as a parameter 
in the model.  If you have a look at the predicted relations from nls() 
for the different fixed values of GAMMA, you can see that orders of 
magnitude changes in GAMMA have pretty minor effects on the curve.  This 
may or may not be the case with the full non-noised data set, but for this 
subset it certainly seems that a four-parameter sigmoid is overkill.  A 
three-parameter sigmoid does just as good a job (see FIT2 below).

Jean

P.S.  It's a good idea to cc: the list when replying so that the thread of 
conversation is maintained for the benefit of others.


XVAR <- c(26, 31.3, 20.9, 24.8, 22.9, 4.79, 19.6, 18, 19.6, 9.69, 21.7, 
26.6, 27.8, 9.12, 10.5, 20.1, 16.7, 14.1, 10.2, 19.2, 24.7, 34.6, 26.6, 
25.1, 5.98, 13.4, 15.7, 9.59, 7.39, 21.5, 15.7, 12.4, 19.2, 17.8, 19.7, 
27.1, 25.6, 36.4, 22.9, 8.68, 27, 25.9, 33.3, 24.2, 21.4, 31, 19.1, 18.7, 
23.5, 19.4, 10.3, 12.8, 13.9, 18.5, 21, 15.2, 18.9, 9.12, 16.9, 12.9, 
29.5, 15.5, 7.34, 8.97, 8.04, 23.7, 16.3, 37.6, 35.2, 13.7, 28.1, 29.5, 
15.1, 26, 6.52) 

YVAR <- c(-34.2, -84.2, -71.1, -91.9, -104.1, -23.2, -27.2, -13.4, -143.2, 
 24.7, -72.1, -38, 25.2, -8, -34.1, -15.1, -112.6, -93.5, -130.9, -127.8, 
-118.7, -53.5, -29.8, 98, 0, -37.6, -99.4, 57.9, 0.2, -62.2, -27.3, 8.3, 
-51.6, -111.6, -25.6, -51.7, -106.4, -85.1, -63.1, -60.8, -27.7, -20.7, 
22.9, -49.4, -85.7, -90.9, -107,  -20.6, -36.3, -40.2, 39.8, -55, -54.5, 
-103.9, -53.1, -2.3, -72.3, -65.6, -57.8, -64.4, -129.1, 10.4, -9.9, 
-29.6, -40.8, 52, -94, 8.8, -98.8, 28, -16.3, -99.2, -48.5, -111.9, -15.4) 


CONTROL  <- list(maxiter=1000, warnOnly=T) 
FORMULA  <- as.formula(YVAR ~ EMAX - EFFECT / (1 + (C50/XVAR)^GAMMA)) 
START <- list(EMAX=-25, EFFECT=25, C50=14)

GAMMAi <- c(1, 10, 100, 800)
plot(XVAR, YVAR)
for(i in seq(GAMMAi)) {
GAMMA <- GAMMAi[i]
FIT <- nls(FORMULA, start=START, control=CONTROL, trace=T)
points(XVAR, predict(FIT), pch=i, col=i+1)
}

FIT2 <- nls(YVAR ~ b + (a-b)/(1 + 10^(XVAR-c)), start=list(a=-20, b=-60, 
c=10),
control=CONTROL, trace=T) 
points(XVAR, predict(FIT2), pch=16, col="purple")
[[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] Generelized Negative Binomial model in R

2011-10-12 Thread Steve Lianoglou
Hi,

On Wed, Oct 12, 2011 at 11:23 AM, Akram Khaleghei Ghosheh balagh
 wrote:
> Hello;
>
> Does anybody knows that R have a function for Generelized Negative Binomial
> model, something like "gnbreg" in "STATA" where dispersion parameter itself
> is a function of covaraites ?

Take a look at the edgeR (and DESeq) package in bioconductor.

edgeR uses a GLMs w/ negative binomial to assess differential
expression of genomic regions using count data (aka next generation
sequencing data).

http://www.bioconductor.org/packages/release/bioc/html/edgeR.html
http://www.bioconductor.org/packages/release/bioc/html/DESeq.html

HTH,
-steve

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

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


Re: [R] CVbinary - Help

2011-10-12 Thread Weidong Gu
Maybe it was caused by your modeling binary variable using lm rather than glm.

Weidong Gu

On Wed, Oct 12, 2011 at 9:59 AM, anamiguita  wrote:
> Hey,
>
> I need some help.
>
> I want to obtain a cross validation for a regression model (binary response)
> but I got an error with CVbinary. Well I did this:
>
>
> fit <- lm(resp ~ PC1 + PC2 + PC3 + PC4 + PC5 + PC6 + PC7 + PC8 +
> PC9+PC10+PC11+PC12+PC13+PC14+PC15+PC16+PC17+PC18+PC19+PC20+PC21+PC22+PC23+PC24+PC25+PC26+PC27+PC28,
> data = dexp.cp, family=binomial())
>
> CVbinary(fit)
> Error in sample(nfolds, m, replace = TRUE) : invalid 'size' argument
>
> I cannot understand this error, I was googling it, but i didn't find nothing
> really helpfull. Can someone help with is?...It's really important.
>
> Thank you for your time,
>
> Ana Rita
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/CVbinary-Help-tp3898065p3898065.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] SARIMAX as extended AR(I)MAX?

2011-10-12 Thread testrider
I am currently trying to make a forecast based on past observations of the
dependent variable AND external variables at the same time.
I know that ARIMAX allows you to do this, however when I use this function
it fits the model using the last k lags. What i actually want is to decide
on the best model by means of AIC for example that only uses a subset of
those k lags. 
I think that SARIMA allows me to choose lags (but no experience here) but it
does not allow me to include external variables.
So for example instead of using the last 52 lags of my dependent variable I
just want to have a result that would look like lag 1, lag 4 and lag 52 for
the dependant variable, lag 1 to lag 4 for external variable number 1 (A)
and lag 1, lag 12 and lag 52 for external variable number two(B).

I hoped to find a SARIMAX or SARMAX function but i have not succeeded. Does
anyone know if it exists, and if not what would be the recommended way to
include both external variables and ARMA terms? The integrated part is not
that important for me. Though automatic lag selection would be a pre, I may
be able to choose the lags manually.



--
View this message in context: 
http://r.789695.n4.nabble.com/SARIMAX-as-extended-AR-I-MAX-tp3898726p3898726.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] plot probability density function (pdf)

2011-10-12 Thread Bert Gunter
Please -- this is not your personal help advisor. Use R's Help facilities
before posting.

-- Bert

On Wed, Oct 12, 2011 at 8:20 AM, pigpigmeow  wrote:

> x11()
> what does it mean?
>

?x11

>
> if my data has missing value, can I plot the graph?
>

Try it and see.


>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/plot-probability-density-function-pdf-tp3897055p3898362.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] treat NA's as zero when summed up with numbers

2011-10-12 Thread Samir Benzerfa
Hello everybody,

 

is there any way to treat NA's as zero when they are summed up with numbers,
but to treat them as NA's when summed up only with NA's. Specifically want
that: 5+NA=5, but NA+NA=NA (and not zero).

 

Any ideas?

 

Best, S.B.


[[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] ARMA and prediction

2011-10-12 Thread Ritz
Hello,

I am running an ARMA model to run forecast for changes in S&P 500 prices. 
My ARMA calculations look as follows

armacal <- arma( spdata, order = c(0,4), lag = list(ma = c(1,2,4)) )

Output:

Call:
arma(x = spdata, order = c(0, 4), lag = list(ma = c(1, 2, 4)) )

Coefficient(s):
  ma1ma2ma4  intercept  
-0.073868   0.058020  -0.081292   0.007082  

All's bright and sunny till this point...after this it gets stormy

Next, I want to run prediction on these ARMA calculations. So i tried:

prediction <-predict( armacal, n.ahead = 1 )

Output:

Error in UseMethod("predict") : 
  no applicable method for 'predict' applied to an object of class "arma"

How do I get around this?
I cannot use arima() because I need the flexibility of "lag" from arma(),
unless there's a way to include lag in arima().

I have attached the .dat data file. 

Would appreciate any guidance/help.
Thanks!

Cheers,
-Ritz

http://r.789695.n4.nabble.com/file/n3898622/spdata.dat spdata.dat 


--
View this message in context: 
http://r.789695.n4.nabble.com/ARMA-and-prediction-tp3898622p3898622.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] R and Forex

2011-10-12 Thread R. Michael Weylandt
"This" being what exactly?

Traded in FX using R? Yes, its done everyday, even as I type

Michael

On Wed, Oct 12, 2011 at 8:10 AM, Yves S. Garret
 wrote:
> No, that's not what I meant.  I was curious if anyone has ever done this
> before and how well it worked.  Any tips for a novice?
>
> On Wed, Oct 12, 2011 at 12:19 AM, Liviu Andronic 
> wrote:
>
>> On Wed, Oct 12, 2011 at 3:29 AM, Yves S. Garret
>>  wrote:
>> > Hi all,
>> >
>> >   I recently started learning about Forex and found this O'Reilly book in
>> > Barnes & Nobles about R.  I bought it out of pure curiosity.  I like what
>> I
>> > see.  However, I have a question.  Has anyone tried to bring these two
>> ideas
>> > together in a financial and trading sense?  Are there any libraries or
>> > modules in R that can aid in this venture?
>> >
>>
>> > fortune('equity')
>>
>> I have never heard anyone (knowledgable or otherwise) claim that, in the
>> absence of transition costs, SAS is better than R for equity modeling. If
>> you
>> come across any such claim, I would be happy to refute it.
>>   -- David Kane
>>      R-SIG-Finance (December 2004)
>>
>>
>> You may want to address this question to r-sig-finance, and check out
>> the Finance Task View [1]. Regards
>> Liviu
>>
>> [1] http://cran.at.r-project.org/web/views/Finance.html
>>
>>
>> > --Yves
>> >
>> >        [[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.
>> >
>>
>>
>>
>> --
>> Do you know how to read?
>> http://www.alienetworks.com/srtest.cfm
>> http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
>> Do you know how to write?
>> http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
>>
>
>        [[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] Read in cluster files (cdt, atr, gtr)

2011-10-12 Thread Mark Ebbert
Does anyone know if there is a method available to read in cluster files (cdt, 
atr and gtr)? I found one method 
(http://bioinformatics.holstegelab.nl/manuals/R/library/integromicsMethods/html/iMethods.read.tv.html),
 but it doesn't seem to create an object that can be used by "heatmap."

The reason I'd like to read in cluster files rather than cluster within R is 
that we use Cluster 3.0 and each clustering suite behaves differently with 
certain algorithms (e.g. "centroid-linkage" in cluster 3.0 vs "average-linkage" 
in Eisen's Cluster 2.0) as well as the order in which the tree is actually 
printed (doesn't change the meaning, but I prefer to continue with what we have 
been using).

Anyway, if anyone knows a package that will read in cluster files in a format 
that I can use to create a heatmap using the "heatmap" method, I would greatly 
appreciate the info. Or, if anyone know a way to add the equivalent of 
ColSideColors from "heatmap" in Java TreeView, that would be equally helpful.

Thanks!

Mark
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] exclude columns with at least three consecutive zeros

2011-10-12 Thread Samir Benzerfa
Hi everyone,

 

I have a large data set with about 3'000 columns and I would like to exclude
all columns which include three or more consecutive zeros (see below
example). A further issue is that it should just jump NA values if any. How
can I do this?

 

In the below example R should exclude column C and D (since in D jumping the
NA leaves three consecutive zeros).

 

I would appreciate any solutions to this issue.

 

Many thanks!

S.B.

 

Date  A B C D

1980  2 75   12   41

1981  9 NA 7 0

1982  18   15   0 0

1983  0 16   0 NA

1984  12   43   0 0

1985  48   3 26   21

 


[[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] plot probability density function (pdf)

2011-10-12 Thread pigpigmeow
x11() 
what does it mean?

if my data has missing value, can I plot the graph?

--
View this message in context: 
http://r.789695.n4.nabble.com/plot-probability-density-function-pdf-tp3897055p3898362.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] Minimum cutsets

2011-10-12 Thread malhomidi
Hi Gabor,

I'm looking for minimum cutsets in the igraph manual but I didn't
find the functions you mentioned above. Also, how can I see their source
code.

Thanks,
Mohammed

--
View this message in context: 
http://r.789695.n4.nabble.com/Minimum-cutsets-tp885346p3898347.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] Error in Rcpp/inline (Windows XP)

2011-10-12 Thread Prof Brian Ripley
Did you read the posting guide (it says R-help is not for questions 
about compiled code)?


Or the rw-FAQ (it warned you that lots of contributed packages did not 
take account of spaces in path names, so suggested you install R in a 
path without one)?


This is a bug in one of the packages you are using, so you could 
(following the posting guide) discuss it with the package maintainers. 
But it is so common that you would do well to take the defensive 
action recommended in the rw-FAQ.


On Wed, 12 Oct 2011, allenhahaha wrote:


Hi, everyone,

I am just trying to use Rcpp in my computer, and I would like to try a
simple example from website, but R keeps reporting me error. I am using
Windows XP, and has installed Rtools and GSI.

Here is the response:


src = '

+ Rcpp::NumericVector xa(a);
+ Rcpp::NumericVector xb(b);
+ int n_xa = xa.size();
+ int n_xb = xb.size();
+
+ Rcpp::NumericVector xab(n_xa + n_xb - 1);
+
+ for (int i = 0; i < n_xa; i++)
+   for (int j = 0; j < n_xb; j++)
+ xab[i + j] += xa[i] * xb[j];
+
+ return xab;
+ '


fun = cxxfunction(

+signature(a = "numeric", b = "numeric"),
+src, plugin = "Rcpp",verbose=T)
>> setting environment variables:
PKG_LIBS =  C:/Program Files/R/R-2.13.0/library/Rcpp/lib/i386/libRcpp.a

>> LinkingTo : Rcpp
CLINK_CPPFLAGS =  -I"C:/Program Files/R/R-2.13.0/library/Rcpp/include"

>> Program source :

..

Compilation argument:
C:/PROGRA~1/R/R-213~1.0/bin/i386/R CMD SHLIB file6d55374d.cpp 2>
file6d55374d.cpp.err.txt
g++ -I"C:/PROGRA~1/R/R-213~1.0/include"-I"C:/Program
Files/R/R-2.13.0/library/Rcpp/include"  -O2 -Wall  -c file6d55374d.cpp
-o file6d55374d.o
g++ -shared -s -static-libgcc -o file6d55374d.dll tmp.def file6d55374d.o
C:/Program Files/R/R-2.13.0/library/Rcpp/lib/i386/libRcpp.a
-LC:/PROGRA~1/R/R-213~1.0/bin/i386 -lR
cygwin warning:
 MS-DOS style path detected: C:/PROGRA~1/R/R-213~1.0/etc/i386/Makeconf
 Preferred POSIX equivalent is:
/cygdrive/c/PROGRA~1/R/R-213~1.0/etc/i386/Makeconf
 CYGWIN environment variable option "nodosfilewarning" turns off this
warning.
 Consult the user's guide for more details about POSIX paths:
   http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
g++.exe: C:/Program: No such file or directory
g++.exe: Files/R/R-2.13.0/library/Rcpp/lib/i386/libRcpp.a: No such file or
directory

ERROR(s) during compilation: source code errors or compiler configuration
errors!

Program source:
..
Erreur dans compileCode(f, code, language = language, verbose = verbose) :
 Compilation ERROR, function(s)/method(s) not created! cygwin warning:
 MS-DOS style path detected: C:/PROGRA~1/R/R-213~1.0/etc/i386/Makeconf
 Preferred POSIX equivalent is:
/cygdrive/c/PROGRA~1/R/R-213~1.0/etc/i386/Makeconf
 CYGWIN environment variable option "nodosfilewarning" turns off this
warning.
 Consult the user's guide for more details about POSIX paths:
   http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
g++.exe: C:/Program: No such file or directory
g++.exe: Files/R/R-2.13.0/library/Rcpp/lib/i386/libRcpp.a: No such file or
directory


fun(1:3, 1:4)


Also, here is a test by Romain that perhaps useful.


system( "R CMD SHLIB test.c" )

cygwin warning:
 MS-DOS style path detected: C:/PROGRA~1/R/R-213~1.0/etc/i386/Makeconf
 Preferred POSIX equivalent is:
/cygdrive/c/PROGRA~1/R/R-213~1.0/etc/i386/Makeconf
 CYGWIN environment variable option "nodosfilewarning" turns off this
warning.
 Consult the user's guide for more details about POSIX paths:
   http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
gcc -I"C:/PROGRA~1/R/R-213~1.0/include"-I"C:/Program
Files/R/R-2.13.0/library/Rcpp/include"  -O3 -Wall  -std=gnu99 -c test.c
-o test.o
gcc -shared -s -static-libgcc -o test.dll tmp.def test.o C:/Program
Files/R/R-2.13.0/library/Rcpp/lib/i386/libRcpp.a
-LC:/PROGRA~1/R/R-213~1.0/bin/i386 -lR
gcc.exe: C:/Program: No such file or directory
gcc.exe: Files/R/R-2.13.0/library/Rcpp/lib/i386/libRcpp.a: No such file or
directory

dyn.load( "test.so" )

Erreur dans inDL(x, as.logical(local), as.logical(now), ...) :
 impossible de charger l'objet partagé 'C:/Documents and Settings/kangj/Mes
documents/test.so':
 LoadLibrary failure:  Le module spécifié est introuvable.
alide.

.Call( "f" )

Erreur dans .Call("f") :
 point d'entrée C "f" absent de la table de chargement


Thanks so much.

Kent


--
View this message in context: 
http://r.789695.n4.nabble.com/Error-in-Rcpp-inline-Windows-XP-tp3898121p3898121.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.



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 So

Re: [R] plot probability density function (pdf)

2011-10-12 Thread jdospina
x11()
plot(density(a))
lines(density(d))
x11()
plot(density(b))
lines(density(e))

2011/10/12 pigpigmeow [via R] :
> however, if i have an excel file, but there have 6 variables, a,b,c,d,e,f.
>
>
> how to plot the probability density function of a and d in one graph, b and
> e in another graph?
>
>
> 
> If you reply to this email, your message will be added to the discussion
> below:
> http://r.789695.n4.nabble.com/plot-probability-density-function-pdf-tp3897055p3898183.html
> To unsubscribe from plot probability density function (pdf), click here.



-- 
Juan David Ospina Arango


-
Juan David Ospina Arango

School of Statistics
Universidad Nacional de Colombia, Colombia

Laboratoire de Traitement du Signal et de l'Image
Université de Rennes 1, France
--
View this message in context: 
http://r.789695.n4.nabble.com/plot-probability-density-function-pdf-tp3897055p3898284.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

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


[R] loop function within a loop

2011-10-12 Thread Sally Zhen
Hi all,

I'm working on a loop function for a large dataset which contains 1000
different groups. I would like to reconstruct the order of events within
each group by using a loop function in R. (Currently the order of events are
based on the ascending order of prev_event within the group)


A demo data frame:

event   prev_event   group
845  0   5360
926  1535360
993  2345360
234  8455360
848  9265360
153  9935360
234  0   8765
968  2348765
545  9688765
625  1113334
744  1813334
181  2273334
713  6253334
227  7133334
913  0   2329
372  1192329
719  1892329
119  3242329
761  3552329
890  3722329
266  7192329
324  7612329
189  8902329
355  9132329


Below is what I have written:

ordering <- vector("list", length(unique(mydata$group)))
for (j in 1:length(unique(mydata$group))){
group.j <- mydata[mydata$group == unique(mydata$group)[j], ]
ordering.j <- c()
ordering.j[1] <- ifelse(group.j[1, ]$prev_event == 0, group.j[1, ]$event,
group.j[1, ]$prev_event)
for (i in 2:nrow(group.j)){
ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i-1], ]$event}
ordering[j] <- ordering.j}
ordering

What I got is:
Error in ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i -  :
  replacement has length zero
> ordering
[[1]]
NULL

[[2]]
NULL

[[3]]
NULL


However, when I accidentally put a typo in the loop function, instead of
ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i-1], ]$event},
I put
ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i-1],
]$prev_event},
The output is a list of 1000 entries, each with the first event within the
group, and I received the following warning messages:
[[1]]
[1] 1.000680e+17

[[2]]
[1] 1.001390e+17

[[3]]
[1] 1.001450e+17

49: In ordering[j] <- ordering.j :
  number of items to replace is not a multiple of replacement length
50: In ordering.j[i] <- group.j[group.j$prev_event ==  ... :
  number of items to replace is not a multiple of replacement length


Why is this happening, and how can I fix it? Any pointer will be greatly
appreciated!

[[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] plot probability density function (pdf)

2011-10-12 Thread R. Michael Weylandt
Assuming you mean you want them on the same device:

layout(1:2)
plot(density(a))
lines(density(d),col=2)
plot(density(b))
lines(density(e),col=2)

Getting your data into R is more of a challenge, but if you want my
unsolicited advice, you can do far worse than saving as CSV and using
read.csv()

Michael


On Wed, Oct 12, 2011 at 10:31 AM, pigpigmeow  wrote:
> however, if i have an excel file, but there have 6 variables, a,b,c,d,e,f.
>
>
> how to plot the probability density function of a and d in one graph, b and
> e in another graph?
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/plot-probability-density-function-pdf-tp3897055p3898183.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] plot probability density function (pdf)

2011-10-12 Thread pigpigmeow
i want to plot probability density function,predictvalue has missing value
and observevalue has not missing value, I tried ..

attach(test) #test is the name of the data file
names(test)

plot(density(predictvalue,na.rm=TRUE))
lines(density(observevalue))

is it correct?


--
View this message in context: 
http://r.789695.n4.nabble.com/plot-probability-density-function-pdf-tp3897055p3898605.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] CVbinary - Help

2011-10-12 Thread anamiguita
Hey,

I need some help. 

I want to obtain a cross validation for a regression model (binary response)
but I got an error with CVbinary. Well I did this:


fit <- lm(resp ~ PC1 + PC2 + PC3 + PC4 + PC5 + PC6 + PC7 + PC8 +
PC9+PC10+PC11+PC12+PC13+PC14+PC15+PC16+PC17+PC18+PC19+PC20+PC21+PC22+PC23+PC24+PC25+PC26+PC27+PC28,
data = dexp.cp, family=binomial())

CVbinary(fit)
Error in sample(nfolds, m, replace = TRUE) : invalid 'size' argument

I cannot understand this error, I was googling it, but i didn't find nothing
really helpfull. Can someone help with is?...It's really important.

Thank you for your time,

Ana Rita

--
View this message in context: 
http://r.789695.n4.nabble.com/CVbinary-Help-tp3898065p3898065.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] R loop within a loop

2011-10-12 Thread saliluna
I've also tried to make the function work for one particular group, then
apply the same function to the whole data frame with all groups using by()
or lapply() as follow. But I'm still receiving error messages. Could someone
please explain what is happening here?

dfdfdf <- function(localdata){
ordering <- c()
ordering[1] <- ifelse(localdata[1, ]$prev_event == 0, localdata$event,
localdata[1, ]$prev_event)
for (i in 2:nrow(localdata)){
ordering[i] <- localdata[localdata$prev_event == ordering[i-1], ]$event}
}

by(mydata, INDICES = mydata$group, FUN = dfdfdf)
lapply(mydata, FUN = dfdfdf)

Error in ordering[i] <- localdata[localdata$prev_event == ordering[i -  : 
  replacement has length zero
In addition: Warning message:
In ordering[i] <- localdata[localdata$prev_event == ordering[i -  :
  number of items to replace is not a multiple of replacement length


Thanks a lot!!



--
View this message in context: 
http://r.789695.n4.nabble.com/R-loop-within-a-loop-tp3898001p3898300.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] labels in a boxplot

2011-10-12 Thread Andrés Aragón
Francesco,

Try cex.axis=0.6

Regards,

Andrés AM

2011/10/12, Francesco Sarracino :
> Dear R-listers,
>
> I have a little problem with a boxplot and I hope you can help me figuring
> it out.
> I'll try to make up some data to illustrate the issue. Sorry, if my
> procedures look naive, but these are my first steps in R. Any comments
> and/or suggestions are very welcome.
>
> let's create a vector var1:
> var1 <- rnorm(100)
>
> and 5 five logical vectors. In this case the vectors don't mean anything, I
> just need 5 vectors to illustrate my problem. Each of the 5 vectors
> identifies a geographic area of my interest.
> med <- var1 < -0.7275
> anglo <- var1 > -0.7275 & var1 < -0.09402
> scand <- var1 > -0.09402
> ceast <- var1 < -0.7275 & var1 > -4.10500
> seast <- var1 < 2.5 & var1 > 0.49
>
> and let's put all the vectors together in a data frame:
> data <- data.frame(anglo, med, scand, seast, ceast, var1)
>
> I wish to compare the samples of each region with respect to variable var1.
> Therefore I run:
>
> boxplot(var1[med==1], var1[anglo==1], var1[scand==1], var1[ceast==1],
> var1[seast==1])
>
> Let's make the chart clearer and let's add meaningful labels to the x-axis.
> Hence, I create a new vector containing a label for each of my 5 dummies:
>
>  vec <-
> c("Mediterranean","Anglo-Saxon","Scandinavian","Centre-East","South-East")
>
> Now the boxplot is:
> boxplot(var1[med==1], var1[anglo==1], var1[scand==1], var1[ceast==1],
> var1[seast==1], names = vec)
>
> As you can see, some of the labels disappear because of the size of the
> chart (I suppose). I tried to solve the problem by changing the orientation
> of the labels with the las = 3 option (see below):
> boxplot(var1[med==1], var1[anglo==1], var1[scand==1], var1[ceast==1],
> var1[seast==1], names = vec, las = 3)
>
> but the problem is not solved: the names are too long and stand partially
> out of the figure.
> How could I solve this problem? I have been longly google-ing and looking
> into reference manuals, but with no success. In Stata a simple way could be
> just bending each label by 45 degrees, but it seems boxplot does not allow
> such a solution. Furthermore I did not manage to enlarge my figure to place
> everything in.
> Thanks a lot in advance for all your support.
> Best wishes,
> f.
>
>   [[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] R and Forex

2011-10-12 Thread Yves S. Garret
When can I send stuff to the mailing list without having moderator approval?
 Is that possible?

On Wed, Oct 12, 2011 at 12:19 AM, Liviu Andronic wrote:

> On Wed, Oct 12, 2011 at 3:29 AM, Yves S. Garret
>  wrote:
> > Hi all,
> >
> >   I recently started learning about Forex and found this O'Reilly book in
> > Barnes & Nobles about R.  I bought it out of pure curiosity.  I like what
> I
> > see.  However, I have a question.  Has anyone tried to bring these two
> ideas
> > together in a financial and trading sense?  Are there any libraries or
> > modules in R that can aid in this venture?
> >
>
> > fortune('equity')
>
> I have never heard anyone (knowledgable or otherwise) claim that, in the
> absence of transition costs, SAS is better than R for equity modeling. If
> you
> come across any such claim, I would be happy to refute it.
>   -- David Kane
>  R-SIG-Finance (December 2004)
>
>
> You may want to address this question to r-sig-finance, and check out
> the Finance Task View [1]. Regards
> Liviu
>
> [1] http://cran.at.r-project.org/web/views/Finance.html
>
>
> > --Yves
> >
> >[[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.
> >
>
>
>
> --
> Do you know how to read?
> http://www.alienetworks.com/srtest.cfm
> http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
> Do you know how to write?
> http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
>

[[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] Problem executing function

2011-10-12 Thread Divyam
Thanks a lot Duncan! It works fine now.

Divya

--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-executing-function-tp3894359p3898054.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] Error in Rcpp/inline (Windows XP)

2011-10-12 Thread allenhahaha
Hi, everyone,

I am just trying to use Rcpp in my computer, and I would like to try a
simple example from website, but R keeps reporting me error. I am using
Windows XP, and has installed Rtools and GSI.

Here is the response: 

> src = '
+ Rcpp::NumericVector xa(a);
+ Rcpp::NumericVector xb(b);
+ int n_xa = xa.size();
+ int n_xb = xb.size();
+  
+ Rcpp::NumericVector xab(n_xa + n_xb - 1);
+ 
+ for (int i = 0; i < n_xa; i++)
+   for (int j = 0; j < n_xb; j++)
+ xab[i + j] += xa[i] * xb[j];
+  
+ return xab;
+ '
>  
> fun = cxxfunction(
+signature(a = "numeric", b = "numeric"), 
+src, plugin = "Rcpp",verbose=T)
 >> setting environment variables: 
PKG_LIBS =  C:/Program Files/R/R-2.13.0/library/Rcpp/lib/i386/libRcpp.a

 >> LinkingTo : Rcpp
CLINK_CPPFLAGS =  -I"C:/Program Files/R/R-2.13.0/library/Rcpp/include" 

 >> Program source :

 ..

Compilation argument:
 C:/PROGRA~1/R/R-213~1.0/bin/i386/R CMD SHLIB file6d55374d.cpp 2>
file6d55374d.cpp.err.txt 
g++ -I"C:/PROGRA~1/R/R-213~1.0/include"-I"C:/Program
Files/R/R-2.13.0/library/Rcpp/include"  -O2 -Wall  -c file6d55374d.cpp
-o file6d55374d.o
g++ -shared -s -static-libgcc -o file6d55374d.dll tmp.def file6d55374d.o
C:/Program Files/R/R-2.13.0/library/Rcpp/lib/i386/libRcpp.a
-LC:/PROGRA~1/R/R-213~1.0/bin/i386 -lR
cygwin warning:
  MS-DOS style path detected: C:/PROGRA~1/R/R-213~1.0/etc/i386/Makeconf
  Preferred POSIX equivalent is:
/cygdrive/c/PROGRA~1/R/R-213~1.0/etc/i386/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this
warning.
  Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
g++.exe: C:/Program: No such file or directory
g++.exe: Files/R/R-2.13.0/library/Rcpp/lib/i386/libRcpp.a: No such file or
directory

ERROR(s) during compilation: source code errors or compiler configuration
errors!

Program source:
..
Erreur dans compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! cygwin warning:
  MS-DOS style path detected: C:/PROGRA~1/R/R-213~1.0/etc/i386/Makeconf
  Preferred POSIX equivalent is:
/cygdrive/c/PROGRA~1/R/R-213~1.0/etc/i386/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this
warning.
  Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
g++.exe: C:/Program: No such file or directory
g++.exe: Files/R/R-2.13.0/library/Rcpp/lib/i386/libRcpp.a: No such file or
directory
>  
> fun(1:3, 1:4)

Also, here is a test by Romain that perhaps useful.

> system( "R CMD SHLIB test.c" ) 
cygwin warning:
  MS-DOS style path detected: C:/PROGRA~1/R/R-213~1.0/etc/i386/Makeconf
  Preferred POSIX equivalent is:
/cygdrive/c/PROGRA~1/R/R-213~1.0/etc/i386/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this
warning.
  Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
gcc -I"C:/PROGRA~1/R/R-213~1.0/include"-I"C:/Program
Files/R/R-2.13.0/library/Rcpp/include"  -O3 -Wall  -std=gnu99 -c test.c
-o test.o
gcc -shared -s -static-libgcc -o test.dll tmp.def test.o C:/Program
Files/R/R-2.13.0/library/Rcpp/lib/i386/libRcpp.a
-LC:/PROGRA~1/R/R-213~1.0/bin/i386 -lR
gcc.exe: C:/Program: No such file or directory
gcc.exe: Files/R/R-2.13.0/library/Rcpp/lib/i386/libRcpp.a: No such file or
directory
> dyn.load( "test.so" ) 
Erreur dans inDL(x, as.logical(local), as.logical(now), ...) : 
  impossible de charger l'objet partagé 'C:/Documents and Settings/kangj/Mes
documents/test.so':
  LoadLibrary failure:  Le module spécifié est introuvable.
alide.
> .Call( "f" ) 
Erreur dans .Call("f") : 
  point d'entrée C "f" absent de la table de chargement


Thanks so much.

Kent


--
View this message in context: 
http://r.789695.n4.nabble.com/Error-in-Rcpp-inline-Windows-XP-tp3898121p3898121.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 loop within a loop

2011-10-12 Thread saliluna
Hi,

I'm working on a loop function for a large dataset which contains 1000
different groups. I would like to reconstruct the order of events within
each group by using a loop function in R. (Currently the order of events are
based on the ascending order of prev_event within the group)


A demo data frame:

event   prev_event   group
845  0   5360
926  1535360
993  2345360
234  8455360
848  9265360
153  9935360
234  0   8765
968  2348765
545  9688765
625  1113334
744  1813334
181  2273334
713  6253334
227  7133334
913  0   2329
372  1192329
719  1892329
119  3242329
761  3552329
890  3722329
266  7192329
324  7612329
189  8902329
355  9132329


Below is what I have written:

ordering <- vector("list", length(unique(mydata$group)))
for (j in 1:length(unique(mydata$group))){
group.j <- mydata[mydata$group == unique(mydata$group)[j], ]
ordering.j <- c()
ordering.j[1] <- ifelse(group.j[1, ]$prev_event == 0, group.j[1, ]$event,
group.j[1, ]$prev_event)
for (i in 2:nrow(group.j)){
ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i-1], ]$event}
ordering[j] <- ordering.j}
ordering

What I got is:
Error in ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i -  : 
  replacement has length zero
> ordering
[[1]]
NULL

[[2]]
NULL

[[3]]
NULL


However, when I accidentally put a typo in the loop function, instead of
ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i-1], ]$event},
I put
ordering.j[i] <- group.j[group.j$prev_event == ordering.j[i-1],
]$prev_event},
The output is a list of 1000 entries, each with the first event within the
group, and I received the following warning messages:
[[1]]
[1] 1.000680e+17

[[2]]
[1] 1.001390e+17

[[3]]
[1] 1.001450e+17

49: In ordering[j] <- ordering.j :
  number of items to replace is not a multiple of replacement length
50: In ordering.j[i] <- group.j[group.j$prev_event ==  ... :
  number of items to replace is not a multiple of replacement length


Why is this happening, and how can I fix it? Any pointer will be greatly
appreciated!

--
View this message in context: 
http://r.789695.n4.nabble.com/R-loop-within-a-loop-tp3898001p3898001.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] R and Forex

2011-10-12 Thread Yves S. Garret
No, that's not what I meant.  I was curious if anyone has ever done this
before and how well it worked.  Any tips for a novice?

On Wed, Oct 12, 2011 at 12:19 AM, Liviu Andronic wrote:

> On Wed, Oct 12, 2011 at 3:29 AM, Yves S. Garret
>  wrote:
> > Hi all,
> >
> >   I recently started learning about Forex and found this O'Reilly book in
> > Barnes & Nobles about R.  I bought it out of pure curiosity.  I like what
> I
> > see.  However, I have a question.  Has anyone tried to bring these two
> ideas
> > together in a financial and trading sense?  Are there any libraries or
> > modules in R that can aid in this venture?
> >
>
> > fortune('equity')
>
> I have never heard anyone (knowledgable or otherwise) claim that, in the
> absence of transition costs, SAS is better than R for equity modeling. If
> you
> come across any such claim, I would be happy to refute it.
>   -- David Kane
>  R-SIG-Finance (December 2004)
>
>
> You may want to address this question to r-sig-finance, and check out
> the Finance Task View [1]. Regards
> Liviu
>
> [1] http://cran.at.r-project.org/web/views/Finance.html
>
>
> > --Yves
> >
> >[[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.
> >
>
>
>
> --
> Do you know how to read?
> http://www.alienetworks.com/srtest.cfm
> http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
> Do you know how to write?
> http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
>

[[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 calculate the statistics of a yearly window with a rolling step as 1 day?

2011-10-12 Thread ecoc
This doesn't work becaues the rollappy is non-overlapping. My rolling step is
1-day and rolling window is 1-year, so there is 364 days overlapping.

--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-calculate-the-statistics-of-a-yearly-window-with-a-rolling-step-as-1-day-tp3891404p3897922.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] Generelized Negative Binomial model in R

2011-10-12 Thread Akram Khaleghei Ghosheh balagh
Hello;

Does anybody knows that R have a function for Generelized Negative Binomial
model, something like "gnbreg" in "STATA" where dispersion parameter itself
is a function of covaraites ?

Thanks;

[[alternative HTML version deleted]]

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


Re: [R] plot probability density function (pdf)

2011-10-12 Thread pigpigmeow
however, if i have an excel file, but there have 6 variables, a,b,c,d,e,f.


how to plot the probability density function of a and d in one graph, b and
e in another graph?


--
View this message in context: 
http://r.789695.n4.nabble.com/plot-probability-density-function-pdf-tp3897055p3898183.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] Labels in ICLUST

2011-10-12 Thread William Revelle

On Oct 11, 2011, at 2:28 AM, Steve Powell wrote:

> Dear all,
> I can't get the labels slot in ICLUST to accept a character vector.
> library(psych)
> test.data <- Harman74.cor$cov
> ic.out <- ICLUST(test.data,nclusters
> =4,labels=letters[1:ncol(test.data)]) ## Error in !labels : invalid
> argument type
> ic.out <- ICLUST(test.data,nclusters =4,labels=1:ncol(test.data)) ## OK
> 
> Any ideas?
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Steve,
That is a bug in ICLUST.  It is now fixed (as of reading your email) and the 
updated version should be released this weekend.

In the meantime, a workaround, is to label the columns with the labels you want.

> colnames(test.data ) <- letters[1:ncol(test.data)]
> ic.out <- ICLUST(test.data,4)

Bill



William Revellehttp://personality-project.org/revelle.html
Professor  http://personality-project.org
Department of Psychology   http://www.wcas.northwestern.edu/psych/
Northwestern Universityhttp://www.northwestern.edu/
Use R for psychology http://personality-project.org/r
It is 6 minutes to midnighthttp://www.thebulletin.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] labels in a boxplot

2011-10-12 Thread Francesco Sarracino
Hi Petr,
thanks a lot for your reply. Unfortunately, your suggestion does not work
for me.
I even tried larger boxes such as 15,15 , but the result does not change.
Is there some setting that I am missing?
However, once more thanks a lot for your help.
f.

On 12 October 2011 15:58, Petr PIKAL  wrote:

> >
> > Dear R-listers,
> >
> > I have a little problem with a boxplot and I hope you can help me
> figuring
> > it out.
> > I'll try to make up some data to illustrate the issue. Sorry, if my
> > procedures look naive, but these are my first steps in R. Any comments
> > and/or suggestions are very welcome.
> >
> > let's create a vector var1:
> > var1 <- rnorm(100)
> >
> > and 5 five logical vectors. In this case the vectors don't mean
> anything, I
> > just need 5 vectors to illustrate my problem. Each of the 5 vectors
> > identifies a geographic area of my interest.
> > med <- var1 < -0.7275
> > anglo <- var1 > -0.7275 & var1 < -0.09402
> > scand <- var1 > -0.09402
> > ceast <- var1 < -0.7275 & var1 > -4.10500
> > seast <- var1 < 2.5 & var1 > 0.49
> >
> > and let's put all the vectors together in a data frame:
> > data <- data.frame(anglo, med, scand, seast, ceast, var1)
> >
> > I wish to compare the samples of each region with respect to variable
> var1.
> > Therefore I run:
> >
> > boxplot(var1[med==1], var1[anglo==1], var1[scand==1], var1[ceast==1],
> > var1[seast==1])
> >
> > Let's make the chart clearer and let's add meaningful labels to the
> x-axis.
> > Hence, I create a new vector containing a label for each of my 5
> dummies:
> >
> >  vec <-
> >
> c("Mediterranean","Anglo-Saxon","Scandinavian","Centre-East","South-East")
> >
> > Now the boxplot is:
> > boxplot(var1[med==1], var1[anglo==1], var1[scand==1], var1[ceast==1],
> > var1[seast==1], names = vec)
>
> This gives me output with all labels
> pdf("test.pdf", 8,8)
> boxplot(var1[med==1], var1[anglo==1], var1[scand==1], var1[ceast==1],
> + var1[seast==1], names = vec)
> dev.off()
>
> If you want labels to rotate in let say 45 degrees you need to use srt
> parameter to text and allow text to be written to outer margin on defined
> places. Maybe some package can do it itself (try plotrix) or go through
> http://addictedtor.free.fr/graphiques/, maybe you find some solution.
>
> Regards
> Petr
>
>
> >
> > As you can see, some of the labels disappear because of the size of the
> > chart (I suppose). I tried to solve the problem by changing the
> orientation
> > of the labels with the las = 3 option (see below):
> > boxplot(var1[med==1], var1[anglo==1], var1[scand==1], var1[ceast==1],
> > var1[seast==1], names = vec, las = 3)
> >
> > but the problem is not solved: the names are too long and stand
> partially
> > out of the figure.
> > How could I solve this problem? I have been longly google-ing and
> looking
> > into reference manuals, but with no success. In Stata a simple way could
> be
> > just bending each label by 45 degrees, but it seems boxplot does not
> allow
> > such a solution. Furthermore I did not manage to enlarge my figure to
> place
> > everything in.
> > Thanks a lot in advance for all your support.
> > Best wishes,
> > f.
> >
> >[[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] labels in a boxplot

2011-10-12 Thread Francesco Sarracino
Thanks a lot Andrés.
It was easier than I expected.
f.

2011/10/12 Andrés Aragón 

> Francesco,
>
> Try cex.axis=0.6
>
> Regards,
>
> Andrés AM
>
> 2011/10/12, Francesco Sarracino :
> > Dear R-listers,
> >
> > I have a little problem with a boxplot and I hope you can help me
> figuring
> > it out.
> > I'll try to make up some data to illustrate the issue. Sorry, if my
> > procedures look naive, but these are my first steps in R. Any comments
> > and/or suggestions are very welcome.
> >
> > let's create a vector var1:
> > var1 <- rnorm(100)
> >
> > and 5 five logical vectors. In this case the vectors don't mean anything,
> I
> > just need 5 vectors to illustrate my problem. Each of the 5 vectors
> > identifies a geographic area of my interest.
> > med <- var1 < -0.7275
> > anglo <- var1 > -0.7275 & var1 < -0.09402
> > scand <- var1 > -0.09402
> > ceast <- var1 < -0.7275 & var1 > -4.10500
> > seast <- var1 < 2.5 & var1 > 0.49
> >
> > and let's put all the vectors together in a data frame:
> > data <- data.frame(anglo, med, scand, seast, ceast, var1)
> >
> > I wish to compare the samples of each region with respect to variable
> var1.
> > Therefore I run:
> >
> > boxplot(var1[med==1], var1[anglo==1], var1[scand==1], var1[ceast==1],
> > var1[seast==1])
> >
> > Let's make the chart clearer and let's add meaningful labels to the
> x-axis.
> > Hence, I create a new vector containing a label for each of my 5 dummies:
> >
> >  vec <-
> >
> c("Mediterranean","Anglo-Saxon","Scandinavian","Centre-East","South-East")
> >
> > Now the boxplot is:
> > boxplot(var1[med==1], var1[anglo==1], var1[scand==1], var1[ceast==1],
> > var1[seast==1], names = vec)
> >
> > As you can see, some of the labels disappear because of the size of the
> > chart (I suppose). I tried to solve the problem by changing the
> orientation
> > of the labels with the las = 3 option (see below):
> > boxplot(var1[med==1], var1[anglo==1], var1[scand==1], var1[ceast==1],
> > var1[seast==1], names = vec, las = 3)
> >
> > but the problem is not solved: the names are too long and stand partially
> > out of the figure.
> > How could I solve this problem? I have been longly google-ing and looking
> > into reference manuals, but with no success. In Stata a simple way could
> be
> > just bending each label by 45 degrees, but it seems boxplot does not
> allow
> > such a solution. Furthermore I did not manage to enlarge my figure to
> place
> > everything in.
> > Thanks a lot in advance for all your support.
> > Best wishes,
> > f.
> >
> >   [[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.


[R] Odp: labels in a boxplot

2011-10-12 Thread Petr PIKAL
> 
> Dear R-listers,
> 
> I have a little problem with a boxplot and I hope you can help me 
figuring
> it out.
> I'll try to make up some data to illustrate the issue. Sorry, if my
> procedures look naive, but these are my first steps in R. Any comments
> and/or suggestions are very welcome.
> 
> let's create a vector var1:
> var1 <- rnorm(100)
> 
> and 5 five logical vectors. In this case the vectors don't mean 
anything, I
> just need 5 vectors to illustrate my problem. Each of the 5 vectors
> identifies a geographic area of my interest.
> med <- var1 < -0.7275
> anglo <- var1 > -0.7275 & var1 < -0.09402
> scand <- var1 > -0.09402
> ceast <- var1 < -0.7275 & var1 > -4.10500
> seast <- var1 < 2.5 & var1 > 0.49
> 
> and let's put all the vectors together in a data frame:
> data <- data.frame(anglo, med, scand, seast, ceast, var1)
> 
> I wish to compare the samples of each region with respect to variable 
var1.
> Therefore I run:
> 
> boxplot(var1[med==1], var1[anglo==1], var1[scand==1], var1[ceast==1],
> var1[seast==1])
> 
> Let's make the chart clearer and let's add meaningful labels to the 
x-axis.
> Hence, I create a new vector containing a label for each of my 5 
dummies:
> 
>  vec <-
> 
c("Mediterranean","Anglo-Saxon","Scandinavian","Centre-East","South-East")
> 
> Now the boxplot is:
> boxplot(var1[med==1], var1[anglo==1], var1[scand==1], var1[ceast==1],
> var1[seast==1], names = vec)

This gives me output with all labels
pdf("test.pdf", 8,8)
boxplot(var1[med==1], var1[anglo==1], var1[scand==1], var1[ceast==1],
+ var1[seast==1], names = vec)
dev.off()

If you want labels to rotate in let say 45 degrees you need to use srt 
parameter to text and allow text to be written to outer margin on defined 
places. Maybe some package can do it itself (try plotrix) or go through 
http://addictedtor.free.fr/graphiques/, maybe you find some solution.

Regards
Petr


> 
> As you can see, some of the labels disappear because of the size of the
> chart (I suppose). I tried to solve the problem by changing the 
orientation
> of the labels with the las = 3 option (see below):
> boxplot(var1[med==1], var1[anglo==1], var1[scand==1], var1[ceast==1],
> var1[seast==1], names = vec, las = 3)
> 
> but the problem is not solved: the names are too long and stand 
partially
> out of the figure.
> How could I solve this problem? I have been longly google-ing and 
looking
> into reference manuals, but with no success. In Stata a simple way could 
be
> just bending each label by 45 degrees, but it seems boxplot does not 
allow
> such a solution. Furthermore I did not manage to enlarge my figure to 
place
> everything in.
> Thanks a lot in advance for all your support.
> Best wishes,
> f.
> 
>[[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.


  1   2   >