Re: [R] Creating the mean using algebra matrix

2011-10-12 Thread Timothy Bates
On Oct 12, 2011, at 12:04 AM, Rolf Turner wrote:
> On 12/10/11 08:31, Timothy Bates wrote:
>> To do matrix multiplication: m x n, the Rows and columns of  m must be equal 
>> to the columns and rows of n, respectively.
> No.  The number of columns of m must equal the number of rows of n,
> that's all.  The number of *rows* of m and the number of *columns* of n
> can be anything you like.
> 


Yes, I don't know how I wrote that.. conflating criteria for conformability 
with the shape of the output,,, 

The easiest way to remember this is to visualize the dimensions of the two 
matrices side by side:

R1 C1 %*% R2 C2

The adjacent numbers must match (C1 & R2)

The resultant matrix will have dimensions of the outside numbers (R1 C2). 

i.e., 
A = matrix(1:4,nrow=1); B = matrix(1:4,ncol=1); A; B; A %*% B; B %*% A
A
 [,1] [,2] [,3] [,4]
[1,]1234
B
 [,1]
[1,]1
[2,]2
[3,]3
[4,]4
A %*% B
 [,1]
[1,]   30
B %*% A
 [,1] [,2] [,3] [,4]
[1,]1234
[2,]2468
[3,]369   12
[4,]48   12   16

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


Re: [R] p adjustment on 4thcorner results

2011-10-12 Thread Christoph Molnar
Hi,

?p.adjust

Christoph

2011/10/12 Cristina Ramalho 

> Hi all,
>
> This is probably a very simple question but I cannot figure out how to do
> it. I run the fourthcorner method with my data and would like to adjust the
> p values for multiple comparisons using Holm correction. When I run the
> fourthcorner I obtain the results in yellow. What do I need to do to be
> able
> to aply the Holm correction to those p values?
>
> > library(ade4)
> > four1 <- fourthcorner(tabR, tabL, tabQ, modeltype = 1, nrepet = 999, tr01
> = FALSE)
> > summary(four1)
> Fourth-corner Statistics
> Permutation method  1  ( 999  permutations)
> ---
>
>  Var. R   Var. QStat. ValueProb.
> RABINT / SPAN   r -0.0478943   0.038 *
> RABINT / TREEr 0   1.000
> RABINT / SHRU   r 0   1.000
> RABINT / HERB   r 0.02618790.340
> RABINT / SEDG   r -0.0320345   0.316
> RABINT / GRAS  r 0.01242630.399
>
> Thank you in advance for your help,
>
> Regards,
>
> C.
>
> --
> Cristina E. Ramalho
> PhD Candidate
> MSc in GIS
>
> Ecosystem Restoration & Intervention Ecology Research Group
> School of Plant Biology (M090)
> The University of Western Australia
> 35 Stirling Highway, Crawley WA 6009 Perth, Australia
> Phone: +61 (08) 6488 4655; Fax: +61 (08) 6488 7461
> www.plants.uwa.edu.au/research/ecosystem_restoration
>
> ---
>
>[[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] goofy class question

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

Here is a really goofy question.

I have some objects which have 2 classes: data.frame and ucr.

Also, the classes will always be in that order.

I have tried all sorts of things, but to no avail.

listucrModels <- function(envir=.GlobalEnv, ...) {
objects <- ls(envir=envir, ...)
if (length(objects) == 0) NULL
else objects[sapply(objects,
   function(.x)  "ucr"==
   (class(eval(parse(text=.x), envir=envir))[2]))]
}

> listucrModels()
 [1] NA   NA   NA   NA   NA   NA   NA   NA
 [9] NA   NA   NA   NA   NA   "jan.df" NA   NA
[17] NA   NA   NA   NA   NA   NA   NA   NA
[25] NA   NA   NA   NA   NA   NA   NA   NA
>
Since most of them do not have the second class attribute.

How do I get rid of the NA's and just get a list, please?

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.


Re: [R] goofy class question

2011-10-12 Thread Joshua Wiley
names(lapply(.GlobalEnv, function(x) inherits(x, "ucr")))

HTH,

Josh

On Wed, Oct 12, 2011 at 12:46 AM, Erin Hodgess  wrote:
> Dear R People:
>
> Here is a really goofy question.
>
> I have some objects which have 2 classes: data.frame and ucr.
>
> Also, the classes will always be in that order.
>
> I have tried all sorts of things, but to no avail.
>
> listucrModels <- function(envir=.GlobalEnv, ...) {
>    objects <- ls(envir=envir, ...)
>    if (length(objects) == 0) NULL
>    else objects[sapply(objects,
>       function(.x)  "ucr"==
>       (class(eval(parse(text=.x), envir=envir))[2]))]
>    }
>
>> listucrModels()
>  [1] NA       NA       NA       NA       NA       NA       NA       NA
>  [9] NA       NA       NA       NA       NA       "jan.df" NA       NA
> [17] NA       NA       NA       NA       NA       NA       NA       NA
> [25] NA       NA       NA       NA       NA       NA       NA       NA
>>
> Since most of them do not have the second class attribute.
>
> How do I get rid of the NA's and just get a list, please?
>
> 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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/

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


Re: [R] Parallel processing for R loop

2011-10-12 Thread Eik Vettorazzi
Hi Sandeep,
still missing an answer? Perhaps you cross check your post with the
rules of the posting guide and find what is missing at all here.

Anyway, depending on your OS, package multicore, snow/snowfall
may fit your needs - but you have to re-formulate your loop using
adequate multicore *apply-functions.

hth

Am 11.10.2011 14:13, schrieb Sandeep Patil:
> I have an R script that consists of a for loop
> that repeats a process for many different files.
> 
> 
> I want to process this parallely on machine with
> multiple cores, is there any package for it ?
> 
> Thanks


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

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

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] goofy class question

2011-10-12 Thread Barry Rowlingson
On Wed, Oct 12, 2011 at 8:46 AM, Erin Hodgess  wrote:
> Dear R People:
>
> Here is a really goofy question.
>
> I have some objects which have 2 classes: data.frame and ucr.
>
> Also, the classes will always be in that order.
>
> I have tried all sorts of things, but to no avail.
>
> listucrModels <- function(envir=.GlobalEnv, ...) {
>    objects <- ls(envir=envir, ...)
>    if (length(objects) == 0) NULL
>    else objects[sapply(objects,
>       function(.x)  "ucr"==
>       (class(eval(parse(text=.x), envir=envir))[2]))]
>    }
>

 Can you get away with just testing inherits(x,"ucr") or "ucr" %in%
class(x)? Or do you really have to test that "ucr" is the second
element? Do you have objects of class "ucr" that aren't also of class
"data.frame"?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Usng MCMCpack,error is \\\"initial value in vmmin is not finite\\\"

2011-10-12 Thread yiy83102

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

Thanks for the reply, but still the problem exists. When I list the objects
and return the result, they get printed on the console but the objects do
not get created. I am really baffled and clueless as to what the problem is. 

Divya

--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-executing-function-tp3894359p3897092.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] plot probability density function (pdf)

2011-10-12 Thread pigpigmeow
I have 2 series of variables, I want to plot the probability density function
of these 2 variabels (i.e. two curves in one graph), I just want to compare
these two variable distribution.
what should I do?
can I use ggplot2 package?

--
View this message in context: 
http://r.789695.n4.nabble.com/plot-probability-density-function-pdf-tp3897055p3897055.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] Parallel processing for R loop

2011-10-12 Thread Paul Hiemstra
On 10/11/2011 12:13 PM, Sandeep Patil wrote:
> I have an R script that consists of a for loop
> that repeats a process for many different files.
>
>
> I want to process this parallely on machine with
> multiple cores, is there any package for it ?
>
> Thanks

...I mostly use the foreach package...

cheers,
Paul

-- 
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770

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


Re: [R] p adjustment on 4thcorner results

2011-10-12 Thread Christoph Molnar
Hi,

the function fourthcorners() returns a list.  You can access the pvalues
shown in the summary by four1[["tabGProb"]]. This is a matrix containing the
pvalues in the summary.

I did some copy and paste from the summary.4thcorners() function (which is
called, by using summary on your four1 object).  And I changed it a little
bit, so that it doesn't print the summary, but returns you the result as a
data.frame. So you can access the Pvalues in the same way you are used to.


summary_fourth <- function(object){
res  <- matrix(0, nrow(object$tabG) * ncol(object$tabG), 6)
res <- as.data.frame(res)
res[, 1] = format(colnames(object$tabG)[col(as.matrix(object$tabG))],
justify = "right")
res[, 2] = format(rownames(object$tabG)[row(as.matrix(object$tabG))])
res[, 3] = as.vector(outer(object$indexQ, object$indexR))
if (!inherits(object, "4thcorner.rlq")) {
res[res[, 4] == "1", 4] = "r"
res[res[, 4] == "2", 4] = "F"
res[res[, 4] == "4", 4] = "Chi2"
}
else {
res[res[, 4] == "1", 4] = "r^2"
res[res[, 4] == "2", 4] = "Eta^2"
res[res[, 4] == "4", 4] = "Chi2/sum(L)"
}
res[, 4] = as.vector(signif(as.matrix(object$tabG)))
res[, 5] = as.vector(as.matrix(object$tabGProb))
signifpval <- symnum(as.numeric(res[, 5]), corr = FALSE,
na = FALSE, cutpoints = c(0, 0.001, 0.01, 0.05, 0.1,
1), symbols = c("***", "**", "*", ".", " "))
res[, 6] = signifpval
colnames(res) = c("Var. R", "Var. Q", "Stat.", "Value",
"Prob.", " ")
res
}

fourth <- summary_fourth(four1)
p.adjust(fourth$Prob, method="holm")


Christoph



2011/10/12 Cristina Ramalho 

> Hi, probably I didnt formulate my question correctly. I know that to aply
> Holm correction I have to do something like:
>
>  woody=read.table("woody.txt", sep="\t", head=T, row.names = 1)
> woodyadj = p.adjust(woody$p, method = "holm")
>
> My question is how to do the correction directly on the results of
> 4thcorner? Or, another way, how can I convert the 4th corner results in a
> data matrix where I can run the p.adjust function?
>
> Thank you so much. Cheers,
>
> C.
>
> On Wed, Oct 12, 2011 at 3:20 PM, Christoph Molnar <
> christoph.mol...@googlemail.com> wrote:
>
>> Hi,
>>
>> ?p.adjust
>>
>> Christoph
>>
>> 2011/10/12 Cristina Ramalho 
>>
>>>  Hi all,
>>>
>>> This is probably a very simple question but I cannot figure out how to do
>>> it. I run the fourthcorner method with my data and would like to adjust
>>> the
>>> p values for multiple comparisons using Holm correction. When I run the
>>> fourthcorner I obtain the results in yellow. What do I need to do to be
>>> able
>>> to aply the Holm correction to those p values?
>>>
>>> > library(ade4)
>>> > four1 <- fourthcorner(tabR, tabL, tabQ, modeltype = 1, nrepet = 999,
>>> tr01
>>> = FALSE)
>>> > summary(four1)
>>> Fourth-corner Statistics
>>> Permutation method  1  ( 999  permutations)
>>> ---
>>>
>>>  Var. R   Var. QStat. ValueProb.
>>> RABINT / SPAN   r -0.0478943   0.038 *
>>> RABINT / TREEr 0   1.000
>>> RABINT / SHRU   r 0   1.000
>>> RABINT / HERB   r 0.02618790.340
>>> RABINT / SEDG   r -0.0320345   0.316
>>> RABINT / GRAS  r 0.01242630.399
>>>
>>> Thank you in advance for your help,
>>>
>>> Regards,
>>>
>>> C.
>>>
>>> --
>>> Cristina E. Ramalho
>>> PhD Candidate
>>> MSc in GIS
>>>
>>> Ecosystem Restoration & Intervention Ecology Research Group
>>> School of Plant Biology (M090)
>>> The University of Western Australia
>>> 35 Stirling Highway, Crawley WA 6009 Perth, Australia
>>> Phone: +61 (08) 6488 4655; Fax: +61 (08) 6488 7461
>>> www.plants.uwa.edu.au/research/ecosystem_restoration
>>>
>>> ---
>>>
>>>[[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.
>>>
>>
>>
>
>
> --
> Cristina E. Ramalho
> PhD Candidate
> MSc in GIS
>
> Ecosystem Restoration & Intervention Ecology Research Group
> School of Plant Biology (M090)
> The University of Western Australia
> 35 Stirling Highway, Crawley WA 6009 Perth, Australia
> Phone: +61 (08) 6488 4655; Fax: +61 (08) 6488 7461
> www.plants.uwa.edu.au/research/ecosystem_restoration
>
> ---
>
>

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

Re: [R] Problem executing function

2011-10-12 Thread Jim Holtman
show the work you did.  what is happening, probably, is that you are returning 
the values, but not assigning them.

Sent from my iPad

On Oct 12, 2011, at 3:47, Divyam  wrote:

> Hi Michael,
> 
> Thanks for the reply, but still the problem exists. When I list the objects
> and return the result, they get printed on the console but the objects do
> not get created. I am really baffled and clueless as to what the problem is. 
> 
> Divya
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Problem-executing-function-tp3894359p3897092.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] Problem executing function

2011-10-12 Thread Petr PIKAL
> 
> Hi Michael,
> 
> Thanks for the reply, but still the problem exists. When I list the 
objects
> and return the result, they get printed on the console but the objects 
do
> not get created. I am really baffled and clueless as to what the problem 
is. 

I bet you do not understand basic operations in R. See chapter 2.1 in 
R-Intro manual coming with you R installation.

Object any.object does not exist untill you create it or assign a value to 
it.

x <- 1:10
y <- x*5+10+rnorm(10)
any.object <- lm(y~x)

Regards
Petr


> 
> Divya
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Problem-
> executing-function-tp3894359p3897092.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] Append data to vector form a column of a dataframe

2011-10-12 Thread behave
Dear R-community,

When doing this:

> test<-data.frame(a=c(1,2,3))
> rbind(test$a, 3)

I expect something like:

> 1
> 2
> 3
> 2

but get:
> [,1] [,2] [,3]
>[1,]123
>[2,]222


the same for:

rbind(test[["a"]], 2)
or
rbind(as.vector(test[["a"]]), 2)
or
rbind(t(as.vector(test[["a"]])), 2)

Why is that and how do I extract the "values" from a dataframe to get the
desired result?

Thank you
Dom








--
View this message in context: 
http://r.789695.n4.nabble.com/Append-data-to-vector-form-a-column-of-a-dataframe-tp3897205p3897205.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] Append data to vector form a column of a dataframe

2011-10-12 Thread Ivan Calandra

Hi Dom,

This is because "3" is recycled. It is necessary because the number of 
columns have to be the same for every row.


Try this instead:
c(test$a, 2)  ## you wrote "3" but meant "2" I guess

HTH,
Ivan

Le 10/12/2011 10:47, behave a écrit :

Dear R-community,

When doing this:


test<-data.frame(a=c(1,2,3))
rbind(test$a, 3)

I expect something like:


1
2
3
2

but get:

 [,1] [,2] [,3]
[1,]123
[2,]222


the same for:

rbind(test[["a"]], 2)
or
rbind(as.vector(test[["a"]]), 2)
or
rbind(t(as.vector(test[["a"]])), 2)

Why is that and how do I extract the "values" from a dataframe to get the
desired result?

Thank you
Dom








--
View this message in context: 
http://r.789695.n4.nabble.com/Append-data-to-vector-form-a-column-of-a-dataframe-tp3897205p3897205.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.



--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Dept. Mammalogy
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

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


Re: [R] extra digits added to data

2011-10-12 Thread Jim Holtman
what are you going to do with the data?  If just for presentation, then keep as 
character.  If you are going to compute on the data, then keep as numeric.  
Since you are using floating point, FAQ 7.31 reminds you that the data "is 
kept" as inputted to the best that can be done with 54 bits of precision.  You 
can always use 'round' or 'sprintf' for output if you want it to 'look' the 
same.  Read the paper pointed to by FAQ 7.31 for an in depth understanding of 
what is happening.  The other solution is to find a package tha works with 
decimal instead of binary; 'bc'?

Sent from my iPad

On Oct 11, 2011, at 11:57, Mark Harrison  wrote:

> Thanks for the quick response.
> 
> Read the FAQ.  If i want to keep the values in R the same as when inputed 
> should i be converting the data to a different type - i.e. Not numeric?
> 
> 
> 
> Sent from my iPhone
> 
> On Oct 11, 2011, at 4:46 AM, Jim Holtman  wrote:
> 
>> FAQ 7.31
>> 
>> Sent from my iPad
>> 
>> On Oct 11, 2011, at 1:07, Mark Harrison  wrote:
>> 
>>> I am having a problem with extra digits being added to my data which I think
>>> is a result of how I am converting my data.frame data to xts.
>>> 
>>> I see the same issue in R v2.13.1 and RStudio version 0.94.106.
>>> 
>>> I am loading historical foreign exchange data in via csv files or from a sql
>>> server database.  In both cases there are no extra digits and the original
>>> data looks like the following:
>>> 
>>>  Date   Open   HighLow  Close
>>> 1 2001-01-03 1.5021 1.5094 1.4883 1.4898
>>> 2 2001-01-04 1.4897 1.5037 1.4882 1.5020
>>> 3 2001-01-05 1.5020 1.5074 1.4952 1.5016
>>> 4 2001-01-08 1.5035 1.5104 1.4931 1.4964
>>> 5 2001-01-09 1.4964 1.4978 1.4873 1.4887
>>> 6 2001-01-10 1.4887 1.4943 1.4856 1.4866
>>> 
>>> So for 2001-01-03 the Open value is 1.5021 with only 4 digits after the
>>> decimal place - i.e. .5021.
>>> 
>>> I then proceed to do the following in R to convert the 'british pound' data
>>> above from data.frame to xts:
>>> 
>>> Require(quantmod)
>>> rownames(gbp) <- gbp$Date
>>> head(gbp)
>>> 
>>>   Open   HighLow  Close
>>> 2001-01-03 1.5021 1.5094 1.4883 1.4898
>>> 2001-01-04 1.4897 1.5037 1.4882 1.5020
>>> 2001-01-05 1.5020 1.5074 1.4952 1.5016
>>> 2001-01-08 1.5035 1.5104 1.4931 1.4964
>>> 2001-01-09 1.4964 1.4978 1.4873 1.4887
>>> 2001-01-10 1.4887 1.4943 1.4856 1.4866
>>> 
>>> gbp<- as.xts(gbp[,2:5])
>>> class(gbp)
>>> 
>>> [1] "xts" "zoo"
>>> 
>>> The data at this point looks ok until you look closer or output the data to
>>> excel at which point you see the following for the 'Open' 2001-01-03:
>>> 1.5020084473
>>> 
>>> It is not just the above 'Open' or the first value but all the data points
>>> contain the extra digits which I think is the original date data and/or row
>>> numbers that are being tacked on.
>>> 
>>> My problem is the extra digits being added or whatever I am doing wrong in R
>>> to cause the extra digits to be added.  I need 1.5021 to be 1.5021 and not
>>> 1.5020084473.
>>> 
>>> Thanks for the help.
>>> 
>>>  [[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] p adjustment on 4thcorner results

2011-10-12 Thread Cristina Ramalho
Hi Christoph,

Thank you soo much, this is great!

All the very best,

Cristina


On Wed, Oct 12, 2011 at 4:52 PM, Christoph Molnar <
christoph.mol...@googlemail.com> wrote:

> Hi,
>
> the function fourthcorners() returns a list.  You can access the pvalues
> shown in the summary by four1[["tabGProb"]]. This is a matrix containing the
> pvalues in the summary.
>
> I did some copy and paste from the summary.4thcorners() function (which is
> called, by using summary on your four1 object).  And I changed it a little
> bit, so that it doesn't print the summary, but returns you the result as a
> data.frame. So you can access the Pvalues in the same way you are used to.
>
>
> summary_fourth <- function(object){
> res  <- matrix(0, nrow(object$tabG) * ncol(object$tabG), 6)
> res <- as.data.frame(res)
> res[, 1] = format(colnames(object$tabG)[col(as.matrix(object$tabG))],
> justify = "right")
> res[, 2] = format(rownames(object$tabG)[row(as.matrix(object$tabG))])
> res[, 3] = as.vector(outer(object$indexQ, object$indexR))
> if (!inherits(object, "4thcorner.rlq")) {
> res[res[, 4] == "1", 4] = "r"
> res[res[, 4] == "2", 4] = "F"
> res[res[, 4] == "4", 4] = "Chi2"
> }
> else {
> res[res[, 4] == "1", 4] = "r^2"
> res[res[, 4] == "2", 4] = "Eta^2"
> res[res[, 4] == "4", 4] = "Chi2/sum(L)"
> }
> res[, 4] = as.vector(signif(as.matrix(object$tabG)))
> res[, 5] = as.vector(as.matrix(object$tabGProb))
> signifpval <- symnum(as.numeric(res[, 5]), corr = FALSE,
> na = FALSE, cutpoints = c(0, 0.001, 0.01, 0.05, 0.1,
> 1), symbols = c("***", "**", "*", ".", " "))
> res[, 6] = signifpval
> colnames(res) = c("Var. R", "Var. Q", "Stat.", "Value",
> "Prob.", " ")
> res
> }
>
> fourth <- summary_fourth(four1)
> p.adjust(fourth$Prob, method="holm")
>
>
> Christoph
>
>
>
> 2011/10/12 Cristina Ramalho 
>
>> Hi, probably I didnt formulate my question correctly. I know that to aply
>> Holm correction I have to do something like:
>>
>>  woody=read.table("woody.txt", sep="\t", head=T, row.names = 1)
>> woodyadj = p.adjust(woody$p, method = "holm")
>>
>> My question is how to do the correction directly on the results of
>> 4thcorner? Or, another way, how can I convert the 4th corner results in a
>> data matrix where I can run the p.adjust function?
>>
>> Thank you so much. Cheers,
>>
>> C.
>>
>> On Wed, Oct 12, 2011 at 3:20 PM, Christoph Molnar <
>> christoph.mol...@googlemail.com> wrote:
>>
>>> Hi,
>>>
>>> ?p.adjust
>>>
>>> Christoph
>>>
>>> 2011/10/12 Cristina Ramalho 
>>>
  Hi all,

 This is probably a very simple question but I cannot figure out how to
 do
 it. I run the fourthcorner method with my data and would like to adjust
 the
 p values for multiple comparisons using Holm correction. When I run the
 fourthcorner I obtain the results in yellow. What do I need to do to be
 able
 to aply the Holm correction to those p values?

 > library(ade4)
 > four1 <- fourthcorner(tabR, tabL, tabQ, modeltype = 1, nrepet = 999,
 tr01
 = FALSE)
 > summary(four1)
 Fourth-corner Statistics
 Permutation method  1  ( 999  permutations)
 ---

  Var. R   Var. QStat. ValueProb.
 RABINT / SPAN   r -0.0478943   0.038 *
 RABINT / TREEr 0   1.000
 RABINT / SHRU   r 0   1.000
 RABINT / HERB   r 0.02618790.340
 RABINT / SEDG   r -0.0320345   0.316
 RABINT / GRAS  r 0.01242630.399

 Thank you in advance for your help,

 Regards,

 C.

 --
 Cristina E. Ramalho
 PhD Candidate
 MSc in GIS

 Ecosystem Restoration & Intervention Ecology Research Group
 School of Plant Biology (M090)
 The University of Western Australia
 35 Stirling Highway, Crawley WA 6009 Perth, Australia
 Phone: +61 (08) 6488 4655; Fax: +61 (08) 6488 7461
 www.plants.uwa.edu.au/research/ecosystem_restoration

 ---

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

>>>
>>>
>>
>>
>> --
>> Cristina E. Ramalho
>> PhD Candidate
>> MSc in GIS
>>
>> Ecosystem Restoration & Intervention Ecology Research Group
>> School of Plant Biology (M090)
>> The University of Western Australia
>> 35 Stirling Highway, Crawley WA 6009 Perth, Australia
>> Phone: +61 (08) 6488 4655; Fax: +61 (08) 6488 7461
>> www.plants.uwa.edu.au/research/ecosystem_restoration
>>
>> -

Re: [R] strsplit question

2011-10-12 Thread Gabor Grothendieck
On Wed, Oct 12, 2011 at 1:20 AM, Erin Hodgess  wrote:
> Dear R People:
>
> I have the following set of data
>> Block[1:5]
> [1] "5600-5699" "6100-6199" "9700-9799" "9400-9499" "8300-8399"
>
> and I want to split at the -
>
>> strsplit(Block[1:5],"-")
> [[1]]
> [1] "5600" "5699"
>
> [[2]]
> [1] "6100" "6199"
>
> [[3]]
> [1] "9700" "9799"
>
> [[4]]
> [1] "9400" "9499"
>
> [[5]]
> [1] "8300" "8399"
>

Try this:

> x <- c("5600-5699", "6100-6199", "9700-9799", "9400-9499", "8300-8399")
> sub("-.*", "", x) # before dash
[1] "5600" "6100" "9700" "9400" "8300"
> sub(".*-", "", x) # after dash
[1] "5699" "6199" "9799" "9499" "8399"

and here is another approach:

> library(gsubfn)
> m <- strapply(x, "\\d+", c, simplify = TRUE)
> m
 [,1]   [,2]   [,3]   [,4]   [,5]
[1,] "5600" "6100" "9700" "9400" "8300"
[2,] "5699" "6199" "9799" "9499" "8399"

Now m[1, ] and m[2, ] are the vectors of digits before and after the
dash.  Note that c in the strapply call can be replaced with
as.numeric if you want a numeric matrix instead.

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

2011-10-12 Thread Jean V Adams
gheine wrote on 10/11/2011 02:31:46 PM:
> 
> 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


You can't simply eliminate the three regions with the fewest respondents 
(3, 6, and 15).  These are the three largest contributors to the 
chi-squared statistic, precisely because fewer people in those regions 
were surveyed than expected.  In addition, more people in regions 1, 5, 
and 9 were surveyed than expected.  This should be clear in a bar chart. 
And the resulting chi-squared test confirms this.

Jean


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

[[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 Wolfgang Wu
The quantmod package might be a good start. 

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


Regards,

 
Wolfgang Wu




- Ursprüngliche Message -
Von: Yves S. Garret 
An: r-help@r-project.org
Cc: 
Gesendet: 2:29 Mittwoch, 12.Oktober 2011 
Betreff: [R] R and Forex

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?

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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Problem with pmax and matrix to calculate row maxima

2011-10-12 Thread 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.


Re: [R] Append data to vector form a column of a dataframe

2011-10-12 Thread Wolfgang Wu
In addition to Ivan, test$a is not a data.frame anymore but a numerical vector.

> class(test$a)
[1] "numeric"
> test$a
[1] 1 2 3

So adding a row to your data.frame would be 

> rbind(test, 2)
  a
1 1
2 2
3 3
4 2


 
Wolfgang Wu


- Ursprüngliche Message -
Von: Ivan Calandra 
An: r-help@r-project.org
Cc: 
Gesendet: 11:19 Mittwoch, 12.Oktober 2011 
Betreff: Re: [R] Append data to vector form a column of a dataframe

Hi Dom,

This is because "3" is recycled. It is necessary because the number of 
columns have to be the same for every row.

Try this instead:
c(test$a, 2)  ## you wrote "3" but meant "2" I guess

HTH,
Ivan

Le 10/12/2011 10:47, behave a écrit :
> Dear R-community,
>
> When doing this:
>
>> test<-data.frame(a=c(1,2,3))
>> rbind(test$a, 3)
> I expect something like:
>
>> 1
>> 2
>> 3
>> 2
> but get:
>>      [,1] [,2] [,3]
>> [1,]    1    2    3
>> [2,]    2    2    2
>
> the same for:
>
> rbind(test[["a"]], 2)
> or
> rbind(as.vector(test[["a"]]), 2)
> or
> rbind(t(as.vector(test[["a"]])), 2)
>
> Why is that and how do I extract the "values" from a dataframe to get the
> desired result?
>
> Thank you
> Dom
>
>
>
>
>
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Append-data-to-vector-form-a-column-of-a-dataframe-tp3897205p3897205.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.
>

-- 
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Dept. Mammalogy
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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
ok. I tested it in two ways. I want to externalise my odbcConnection details
dsn, uid, and pwd. Hence I created a csv file to have these information.
Like I showed in the sample function initially, the order of the steps were
1) loading of the packages,
2) fetching the csv file,
3)assigning the dsn, uid, and pwd separately to values,
4) establish the connection by using these values .

The sample function I created thus was:

fun <-  function ()
{
# Package load into R;
a <-  c(library("RODBC"),library("e1071"));
b <- read.csv("path of the csv file",   header=TRUE,   sep=",",   
quote="");
c<- b[,1];
d <- b[,2];
e<- b[,3];

rm(b);

# Establishing ODBC connection;
connection <- odbcConnect(c, uid=d, pwd=e);
X<-list(a=a, b=b, c=c,d=d, e=e, connection=connection);
return(X);

}

# function call

> fun()



Error in RegressionAnalytics() : object 'b' not found
In addition: Warning messages:
1: package 'RODBC' was built under R version 2.13.1 
2: package 'e1071' was built under R version 2.13.1 

However, when I simply give the code for fetch directly on the command
prompt, it works.

> b <- read.csv("path of the csv file",   header=TRUE,   sep=",",   
> quote="");

object b gets created under data. I checked the path of the file and its
name. They are correct. So I thought I'll directly give the dsn, uid, and
pwd information in odbcConnection instead of externalizing it to see how the
function responds. This is what I did:


> fun <-  function()
 {
 a <- c(library("RODBC"),library("e1071"));
 connection <- odbcConnect("x",uid="xy",pwd="abcdef");
 X<-list(b=b,connection=connection);
 return(X);
 }

# function call and result

> fun ()
 
$a
 [1]  "e1071" "RODBC" "class" "stats" "graphics" 
 [7] "grDevices" "utils" "datasets"  "methods"   "base" 
[13] "e1071" "RODBC" "class" "stats" "graphics"  "grDevices"
[19] "utils" "datasets"  "methods"   "base"   "e1071"
[25] "RODBC" "class" "stats" "graphics"  "grDevices" "utils"
[31] "datasets"  "methods"   "base" 

$connection
RODBC Connection 4
Details:
  case=nochange
  DSN=x
  Description=test
  UID=xy
  PWD=**
  APP=RStudio
 
when I try to see the connection object by typing in the command prompt it
throws an error saying the object is not found:
> connection
Error: object 'connection' not found

This is what I meant by the function being created, printed but object not
created. I should also mention that these steps run perfectly fine when not
assigned to a function (both the methods). So i guess the code is ok. I am
missing something but am not able to figure that out. By the looks of it I
think I have assigned the values to be returned to some object. Any
thoughts?

Thanks
Divya

--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-executing-function-tp3894359p3897639.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] Problem executing function

2011-10-12 Thread Divyam
sorry correction in the first and result hence received code:

ok. I tested it in two ways. I want to externalise my odbcConnection details
dsn, uid, and pwd. Hence I created a csv file to have these information.
Like I showed in the sample function initially, the order of the steps were
1) loading of the packages,
2) fetching the csv file,
3)assigning the dsn, uid, and pwd separately to values,
4) establish the connection by using these values .

The sample function I created thus was:

fun <-  function ()
{
# Package load into R;
a <-  c(library("RODBC"),library("e1071"));
b <- read.csv("path of the csv file",   header=TRUE,   sep=",",   
quote="");
c<- b[,1];
d <- b[,2];
e<- b[,3];


# Establishing ODBC connection;
connection <- odbcConnect(c, uid=d, pwd=e);
X<-list(a=a, b=b, c=c,d=d, e=e, connection=connection);
return(X);

}

# function call

> fun()

$a
 [1] "RODBC" "class" "stats" "graphics"  "grDevices" "utils"
 [7] "datasets"  "methods"   "base"  "e1071" "RODBC" "class"
[13] "stats" "graphics"  "grDevices" "utils" "datasets"  "methods"  
[19] "base"   "e1071" "RODBC" "class" "stats"
[25] "graphics"  "grDevices" "utils" "datasets"  "methods"   "base" 

$b
  DSN uid   pwd
1 x xy   abcdef

$c
[1] x
Levels: x

$d
[1] xy
Levels: xy

$e
[1] abcdef
Levels: abcdef

$connection
RODBC Connection 1
Details:
  case=nochange
  DSN=x
  Description=test
  UID=xy
  PWD=**
  APP=RStudio
 
Warning messages:
1: package 'RODBC' was built under R version 2.13.1 
2: package 'e1071' was built under R version 2.13.1 
3: package 'dummies' was built under R version 2.13.2 

To see if the objects were created, I typed
 > b
Error: object 'b' not found

>connection
Error: object 'connection' not found

However, when I simply give the code for fetch directly on the command
prompt, it works.

> b <- read.csv("path of the csv file",   header=TRUE,   sep=",",   
> quote="");

object b gets created under data. I checked the path of the file and its
name. They are correct. So I thought I'll directly give the dsn, uid, and
pwd information in odbcConnection instead of externalizing it to see how the
function responds. This is what I did:


> fun <-  function()
 {
 a <- c(library("RODBC"),library("e1071"));
 connection <- odbcConnect("x",uid="xy",pwd="abcdef");
 X<-list(b=b,connection=connection);
 return(X);
 }

# function call and result

> fun ()
 
$a
 [1]  "e1071" "RODBC" "class" "stats" "graphics"
 [7] "grDevices" "utils" "datasets"  "methods"   "base"
[13] "e1071" "RODBC" "class" "stats" "graphics"  "grDevices"
[19] "utils" "datasets"  "methods"   "base"   "e1071"
[25] "RODBC" "class" "stats" "graphics"  "grDevices" "utils"
[31] "datasets"  "methods"   "base"

$connection
RODBC Connection 4
Details:
  case=nochange
  DSN=x
  Description=test
  UID=xy
  PWD=**
  APP=RStudio
 
when I try to see the connection object by typing in the command prompt it
throws an error saying the object is not found:
> connection
Error: object 'connection' not found

This is what I meant by the function being created, printed but object not
created. I should also mention that these steps run perfectly fine when not
assigned to a function (both the methods). So i guess the code is ok. I am
missing something but am not able to figure that out. By the looks of it I
think I have assigned the values to be returned to some object. Any
thoughts?

Thanks
Divya 

--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-executing-function-tp3894359p3897696.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 jdospina
x=rnorm(100,1,0.8) # A series.
y=rnorm(100,0,0.5) # Another series with different mean and variance.

plot(density(x),ylim=c(0,1))
lines(density(y),col="red")

Remember that density() is a nonparametric estimator. You should properly
choose the bandwith.

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

2011-10-12 Thread Jeffrey Pollock
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] Cross posting (was "Restricted Cubic Splines within survfit.cph)

2011-10-12 Thread Terry Therneau
You wrote:
  "It may be best to either write to the package maintainer (me, as you
did) or post to the group but not both."

This is just a note that I disagree wrt my own packages:
I go on vacation or trips, or have other projects so won't always
answer
Other folks on the list often have good ideas that I'd miss

 My preferred standard is  "ask the list, with a copy to Therneau as an
additional courtesy".  Of course if it's an out and out bug you've
found, that no one else but me can deal with, then one can skip the
list.

Terry T.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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/11/2011 07:20:35 PM:
> 
> Colleagues,
> 
> I am fitting an Emax model using nls.  The code is:
>START <- list(EMAX=INITEMAX, EFFECT=INITEFFECT, C50=INITC50)
>CONTROL  <- list(maxiter=1000, warnOnly=T)
>#FORMULA  <- as.formula(YVAR ~ EMAX - EFFECT * XVAR^GAMMA / 
> (XVAR^GAMMA + C50^GAMMA))   ## alternate version of formula
>FORMULA  <- as.formula(YVAR ~ EMAX - EFFECT / (1 + 
(C50/XVAR)^GAMMA))
>FIT<- nls(FORMULA, start=START, control=CONTROL, trace=T)
> 
> If GAMMA equals 10-80, nls converges successfully and the fit tracks
> the fit from a smoother (Supersmoother).  However, if I attempt to 
> estimate GAMMA using:
>START <- list(EMAX=INITEMAX, EFFECT=INITEFFECT, 
> C50=INITC50, GAMMA=INITGAMMA)
> GAMMA increases rapidly to > 500 and nls terminates with:
>Error in chol2inv(object$m$Rmat()) : 
>  element (4, 4) is zero, so the inverse cannot be computed
>In addition: Warning message:
>In nls(FORMULA, start = START, control = CONTROL, trace = T) :
>  singular gradient
> 
> I also tried fixing GAMMA to > 1000 and I get a similar error message:
>Error in chol2inv(object$m$Rmat())
> : element (2, 2) is zero, so the inverse cannot be computed 
>In addition: Warning message: 
>In nls(FORMULA, start = START, control = CONTROL, trace = T)
> : singular gradient 
> 
> The data do not suggest a very large value for GAMMA so I am 
> surprised that the estimate is increasing so rapidly.  I attempted 
> to use the port algorithm with an upper bound on GAMMA but the upper
> bound is reached rapidly, suggesting that the data support a large 
> value for GAMMA.
> 
> A subset of the data (with added noise) is shown below.  A GAMMA 
> value of 1280 triggers the error with this subset
> 
> 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)
> 
> I suspect that I am making a conceptual error in the use of nls. 
> Any help would be appreciated.  If a different function to fit 
> nonlinear regression would work better, please direct me.
> 
> 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


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?

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.

Jean
[[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] labels in a boxplot

2011-10-12 Thread 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.


Re: [R] Cross posting (was "Restricted Cubic Splines within survfit.cph)

2011-10-12 Thread Frank Harrell
Terry I would just add that if someone contacts the maintainer and does 
not follow the advice of the maintainer, still has problems, and posts a 
message to the list, then some time is wasted.


Frank

On 10/12/2011 07:38 AM, Terry Therneau wrote:

You wrote:
   "It may be best to either write to the package maintainer (me, as you
did) or post to the group but not both."

This is just a note that I disagree wrt my own packages:
 I go on vacation or trips, or have other projects so won't always
answer
 Other folks on the list often have good ideas that I'd miss

  My preferred standard is  "ask the list, with a copy to Therneau as an
additional courtesy".  Of course if it's an out and out bug you've
found, that no one else but me can deal with, then one can skip the
list.

Terry T.






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

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


Re: [R] Problem with pmax and matrix to calculate row maxima

2011-10-12 Thread Enrico Schumann


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


## variant 2
system.time(test2 <- apply(matRandom, 1, max))

User  System verstrichen
0.560.000.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.010.000.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.020.000.02

system.time(test<- apply(matRandom, 1, max))
 user  system elapsed

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


Re: [R] stop()

2011-10-12 Thread Doran, Harold
Thank you, Greg. This indeed works well for this purpose.

> -Original Message-
> From: Greg Snow [mailto:greg.s...@imail.org]
> Sent: Tuesday, October 11, 2011 4:27 PM
> To: Doran, Harold; r-help@r-project.org
> Subject: RE: stop()
> 
> Replace "stop()" with "break" to see if that does what you want.  (you may
> also want to include "cat()" or "warn()" to indicate the early stopping.
> 
> --
> 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 Doran, Harold
> > Sent: Tuesday, October 11, 2011 11:32 AM
> > To: r-help@r-project.org
> > Subject: [R] stop()
> >
> > Suppose I have a function, such as the toy example below:
> >
> > myFun <- function(x, max.iter = 5) {
> >for(i in 1:10){
> >result <- x + i
> >iter <- i
> >if(iter == max.iter) stop('Max reached')
> >}
> >result
> >}
> >
> > I can of course do this:
> > myFun(10, max.iter = 11)
> >
> > However, if I reach the maximum number of iterations before my
> > "algorithm" has finished (in my real application there are EM steps for
> > a mixed model), I actually want the function to return the value of
> > "result" up to that point. Currently using stop(), I would get
> >
> > > myFun(10, max.iter = 4)
> > Error in myFun(10, max.iter = 4) : Max reached
> >
> > But, in this toy case the function should return the value of "result"
> > up to iteration 4.
> >
> > Not sure how I can adjust this.
> >
> > Thanks,
> > Harold
> >
> >
> >
> > [[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] Applying function to only numeric variable (plyr package?)

2011-10-12 Thread Michael . Laviolette

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.


Re: [R] Problem executing function

2011-10-12 Thread Duncan Murdoch

Comments inline below.

On 12/10/2011 7:47 AM, Divyam wrote:

sorry correction in the first and result hence received code:

ok. I tested it in two ways. I want to externalise my odbcConnection details
dsn, uid, and pwd. Hence I created a csv file to have these information.
Like I showed in the sample function initially, the order of the steps were
1) loading of the packages,
2) fetching the csv file,
3)assigning the dsn, uid, and pwd separately to values,
4) establish the connection by using these values .

The sample function I created thus was:

fun<-  function ()
{
# Package load into R;
a<-  c(library("RODBC"),library("e1071"));
b<- read.csv("path of the csv file",   header=TRUE,   sep=",",
quote="");
c<- b[,1];
d<- b[,2];
e<- b[,3];


# Establishing ODBC connection;
connection<- odbcConnect(c, uid=d, pwd=e);
X<-list(a=a, b=b, c=c,d=d, e=e, connection=connection);
return(X);

}
# function call

>  fun()


This creates the 6 objects a,b,c,d,e and connection, and stores them in 
the list.  Then R prints the list, but you didn't save it anywhere

$a
  [1] "RODBC" "class" "stats" "graphics"  "grDevices" "utils"
  [7] "datasets"  "methods"   "base"  "e1071" "RODBC" "class"
[13] "stats" "graphics"  "grDevices" "utils" "datasets"  "methods"
[19] "base"   "e1071" "RODBC" "class" "stats"
[25] "graphics"  "grDevices" "utils" "datasets"  "methods"   "base"

$b
   DSN uid   pwd
1 x xy   abcdef

$c
[1] x
Levels: x

$d
[1] xy
Levels: xy

$e
[1] abcdef
Levels: abcdef

$connection
RODBC Connection 1
Details:
   case=nochange
   DSN=x
   Description=test
   UID=xy
   PWD=**
   APP=RStudio

Warning messages:
1: package 'RODBC' was built under R version 2.13.1
2: package 'e1071' was built under R version 2.13.1
3: package 'dummies' was built under R version 2.13.2

To see if the objects were created, I typed
  >  b
Error: object 'b' not found


You need to study "scoping" in R.  The variable named "b" was local to 
your function call.  You copied it's value into X, and returned that, 
but the variable b does not live beyond the function call.


If you had done

value <- fun()

then you could retrieve the copy as

value$b

Duncan Murdoch


>connection
Error: object 'connection' not found

However, when I simply give the code for fetch directly on the command
prompt, it works.

>  b<- read.csv("path of the csv file",   header=TRUE,   sep=",",
>  quote="");

object b gets created under data. I checked the path of the file and its
name. They are correct. So I thought I'll directly give the dsn, uid, and
pwd information in odbcConnection instead of externalizing it to see how the
function responds. This is what I did:


>  fun<-  function()
  {
  a<- c(library("RODBC"),library("e1071"));
  connection<- odbcConnect("x",uid="xy",pwd="abcdef");
  X<-list(b=b,connection=connection);
  return(X);
  }

# function call and result

>  fun ()

$a
  [1]  "e1071" "RODBC" "class" "stats" "graphics"
  [7] "grDevices" "utils" "datasets"  "methods"   "base"
[13] "e1071" "RODBC" "class" "stats" "graphics"  "grDevices"
[19] "utils" "datasets"  "methods"   "base"   "e1071"
[25] "RODBC" "class" "stats" "graphics"  "grDevices" "utils"
[31] "datasets"  "methods"   "base"

$connection
RODBC Connection 4
Details:
   case=nochange
   DSN=x
   Description=test
   UID=xy
   PWD=**
   APP=RStudio

when I try to see the connection object by typing in the command prompt it
throws an error saying the object is not found:
>  connection
Error: object 'connection' not found

This is what I meant by the function being created, printed but object not
created. I should also mention that these steps run perfectly fine when not
assigned to a function (both the methods). So i guess the code is ok. I am
missing something but am not able to figure that out. By the looks of it I
think I have assigned the values to be returned to some object. Any
thoughts?

Thanks
Divya

--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-executing-function-tp3894359p3897696.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] Chi-Square test and survey results

2011-10-12 Thread Jan van der Laan

George,

Perhaps the site of the RISQ project (Representativity indicators for  
Survey Quality) might be of use: http://www.risq-project.eu/ . They  
also provide R-code to calculate their indicators.


HTH,
Jan



Quoting ghe...@mathnmaps.com:


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

2011-10-12 Thread Christoph Molnar
Hi,

if the rows in your data.frame are numeric, this solution will work.

(numeric.index <- unlist(lapply(df, is.numeric)))
df[, numeric.index] <- apply(df[,numeric.index], 2, pct)
This does not work for the example you gave, unless you coerce the columns
with the your numerics to numeric:
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)


df$y <- as.numeric(df$y)
df$x <- as.numeric(df$x)

pct <- function(x) round(100*x, 1)
(numeric.index <- unlist(lapply(df, is.numeric)))
df[, numeric.index] <- apply(df[,numeric.index], 2, pct)

Christoph


2011/10/12 

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

[[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] Mean or mode imputation fro missing values

2011-10-12 Thread Petr PIKAL
Hi

> 
> Yes thank you Gu…
> I am just trying to do this as a rough step and will try other
> imputation methods which are more appropriate later.
> I am just learning R, and was trying to do the for loop and
> f-statement by hand but something is going wrong…
> 
> This is what I have until now:
> 
> *fake array:
> age<- c(5,8,10,12,NA)
> a<- factor(c("aa", "bb", NA, "cc", "cc"))
> b<- c("banana", "apple", "pear", "grape", NA)
> df_test <- data.frame(age=age, a=a, b=b)
> df_test$b<- as.character(df_test$b)
> 
> for (var in 1:ncol(df_test)) {
>if (class(df_test$var)=="numeric") {

var goes from 1 to 3, above you actually use df_test$1 which is not what 
you intend.
you shall use [] selection operator. However your Mode function does not 
correctly assign values 

for (var in 1:ncol(df_test)) {
 if (class(df_test[,var])=="numeric") {
 df_test[is.na(df_test[,var]), var] <- 
mean(df_test[,var], na.rm = TRUE)
 } else if 
(class(df_test[,var])=="character") {
 Mode(df_test[is.na(df_test[,var]),var], 
na.rm = TRUE)
 }
}

Warning message:
In max(xtab) : no non-missing arguments to max; returning -Inf

You shall use debug(Mode] to see what is going on. I have no time to 
inspect it and do not see any obvious flaw.

Regards
Petr



>   df_test$var[is.na(df_test$var)] <- mean(df_test$var, na.rm = TRUE)
>   } else if (class(df_test$var)=="character") {
>   Mode(df_test$var[is.na(df_test$var)], na.rm = TRUE)
>   }
> }
> 
> Where 'Mode' is the function:
> 
> function (x, na.rm)
> {
> xtab <- table(x)
> xmode <- names(which(xtab == max(xtab)))
> if (length(xmode) > 1)
> xmode <- ">1 mode"
> return(xmode)
> }
> 
> 
> It seems as it is just ignoring the statements though, without giving
> any error…Does anybody have any idea what is going on?
> 
> Thank you very much for all the great help!
> -f
> 
> 2011/10/11 Weidong Gu :
> > In your case, it may not be sensible to simply fill missing values by
> > mean or mode as multiple imputation becomes the norm this day. For
> > your specific question, na.roughfix in randomForest package would do
> > the work.
> >
> > Weidong Gu
> >
> > On Tue, Oct 11, 2011 at 8:11 AM, francesca casalino
> >  wrote:
> >> Dear R experts,
> >>
> >> I have a large database made up of mixed data types (numeric,
> >> character, factor, ordinal factor) with missing values, and I am
> >> looking for a package that would help me impute the missing values
> >> using  either the mean if numerical or the mode if character/factor.
> >>
> >> I maybe could use replace like this:
> >> df$var[is.na(df$var)] <- mean(df$var, na.rm = TRUE)
> >> And go through all the many different variables of the datasets using
> >> mean or mode for each, but I was wondering if there was a faster way,
> >> or if a package existed to automate this (by doing 'mode' if it is a
> >> factor or character or 'mean' if it is numeric)?
> >>
> >> I have tried the package "dprep" because I wanted to use the function
> >> "ce.mimp", btu unfortunately it is not available anymore.
> >>
> >> Thank you for your help,
> >> -francy
> >>
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/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] Applying function to only numeric variable (plyr package?)

2011-10-12 Thread Jan van der Laan


plyr isn't necessary in this case. You can use the following:

cols <- sapply(df, is.numeric)
df[, cols] <- pct(df[,cols])


round (and therefore pct) accepts a data.frame and returns a  
data.frame with the same dimensions. If that hadn't been the case  
colwise might have been of help:


library(plyr)
pct.colwise <- colwise(pct)
df[, cols] <- pct.colwise(df[,colwise])

HTH,

Jan



Quoting michael.laviole...@dhhs.state.nh.us:



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.


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


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.


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


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


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.


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


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


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.


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


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


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.


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


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


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


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


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


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


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


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


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


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.


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


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


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.


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


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


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


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


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


  1   2   >