Re: [R] Tapply.

2010-04-27 Thread Petr PIKAL
Hi

steven mosher  napsal dne 27.04.2010 17:04:04:

> Thanks,
> 
>  I had been wondering what Drop did. That makes it more clear.
>  
> While I have code that loops and does the problem correctly, I wanted to
> do things the R way and be fast and terse. hehe.
> 
> So:
> ID   dy  jan  ...
> 11264402000 1 1987  NA  NA  NA  NA  NA 218  NA  NA 235 243 240 
 NA
>  11264402000 3 1987  NA  NA  NA  NA  NA 218  NA  NA 235 243 240 
 NA
> 
> in words : for each id, for each year return
>  the max of jan,feb,.over d
>  the min of jan, feb  over d
>  the mean of jan,feb.. over d
>  the (max+min)/2 of jan, feb...over d
>  the count of d for jan.feb..
>  the results of a function called with all elements of this id
> 

something like

aggregate(data[, months], list(id, d), my.summary)

where my.summary is a function computing all required values and returning 
them in appropriate form.

in words : split selected data to chunks according to list of indices, use 
required function to each chunk and return result.

Regards
Petr



> Anyway, your kind attention has been greatly appreciated.
> 
>  
>  
> 
> 

> On Tue, Apr 27, 2010 at 2:40 AM, Petr PIKAL  
wrote:
> Hi
> r-help-boun...@r-project.org napsal dne 26.04.2010 17:05:54:
> 
> > I guess my problem was seeing a bunch of examples where they pulled a
> > variable from a dataframe..
> >
> >   tapply(df$data, index=list(..

> df$data results in vector so as eg. df[,5] unless you use drop=FALSE
> option
> 
> >
> > and I
> > assumed that the df$data was just generalizable to a collection of
> vectors
> > a vector of vector being a vector

> df[,1:15] is not a vector of vectors. R sometimes can give you nasty
> surprise with object types and modes but changing a type of object 
merely
> by selecting some part of it wold be quite problematic.
> 
> see
> 
> str(df$data)
> str(df[, 1])
> str(df[,1, drop=FALSE])
> str(df[,1:15])
> 
> Regards
> Petr
> 
> 
> 
> >
> > Thanks.
> >
> > On Mon, Apr 26, 2010 at 2:43 AM, Petr PIKAL 
> wrote:
> >
> > > Hi
> > >
> > >
> > > steven mosher  napsal dne 26.04.2010 
10:21:37:
> > >
> > > > That fails:
> > > >
> > > > The manual says:
> > > >
> > > > tapply(X, INDEX, FUN = NULL, ..., simplify = TRUE)
> > >
> > > > Arguments
> > > >
> > > > X
> > > >
> > > > an atomic object, typically a vector.
> > > >
> > > > INDEX
> > > >
> > > > list of factors, each of same length as X. The elements are 
coerced
> to
> > > factors by
> > > > as.factor.
> > > >
> > > > my error says:
> > >
> > > >
> > > > Error in tapply(DF[, 1:15], DF$Year, mean, na.rm = T) :
> > > >
> > > >   arguments must have same length
> > > >
> > > > The issue that I have is I dont understand what the requirements 
for
> the
> > > list of factors
> > > > are. In my example DF$Years is  a sequence of
> > > years..1979,1980,1982,1983, 1987..
> > > > like that with missing years: so when the manual say: list of
> factors
> > > each the same
> > > > length as X? what does that mean? I could have a DF with 20 rows 
and
> > > only two
> > > > different years. or 20 rows and 20 different years.
> > > >
> > > > Suppose:
> > > >
> > > > a<- c(1,2,3,4)
> > > > > b<-c(2,3,4,5)
> > > > > df=data.frame(a,b)
> > > > > length(df)
> > >
> > > data frame is not vector nor atomic but list hence length(df) gives
> you
> > > number of columns. It is similar to length of a list
> > >
> > > > lll<-list(a=1, b=2, c=3)
> > > > length(lll)
> > > [1] 3
> > > >
> > >
> > > If you accept that the first argument of tapply has to be vector you
> can
> > > not put data frame there.
> > >
> > > Next second argument has to be list of factors so you can put there
> > > several factors, each of the same length as first argument (a 
vector).
> > >
> > > If you want to perform aggregating operation on whole data frame you
> shall
> > > consider
> > >
> > > ?by or ?aggregate
> > >
> > > Other options are plyr or doBy packages.
> > >
> > > Syntax for aggregate is quite similar to tapply, only first argument
> can
> > > be data frame.
> > >
> > > Regards
> > > Petr
> > >
> > >
> > > >
> > > > The length of DF is 2.
> > > > Does that mean the "list of factors, each of same length as X."
> would
> > > have to be
> > > > 2? that doesnt seem to make sense.
> > > >
> > > >
> > > >
> > > > On Mon, Apr 26, 2010 at 12:26 AM, Petr PIKAL
> 
> > > wrote:
> > > > Hi
> > > >
> > > > r-help-boun...@r-project.org napsal dne 26.04.2010 06:52:55:
> > > >
> > > > > Having some difficulties with understanding how tapply works and
> > > getting
> > > > > return values I expect
> > > > >
> > > > > Data: dataframe. DF  DF$Id $D $Year...
> > > > >
> > > > >  Id  D  Year Jan Feb Mar Apr May Jun Jul
> Aug
> > > Sep
> > > > Oct
> > > > > Nov Dec
> > > > >  11264402000 1 1980  NA  NA  NA  NA  NA 212 203 209 228
> 237
> > >  NA
> > > > NA
> > > > >  11264402000 0 1981  NA  NA 243 244  NA  NA  NA  NA 225 
NA
> > > 231
> > > > 

Re: [R] R GUI

2010-04-27 Thread Amitoj S. Chopra

Hey do you know a good guide for traitr to learn from? Is this okay? Ive been
trying it but it is difficult for me to learn. Thanks.

Amitoj

http://cran.r-project.org/web/packages/traitr/vignettes/traitr.pdf
-- 
View this message in context: 
http://r.789695.n4.nabble.com/R-GUI-tp1837662p2068626.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] Traitr

2010-04-27 Thread Amitoj S. Chopra

Does anyone know how to use Traitr, or a guide to learn Traitr package for R?
I am trying to learn right now, and trying to get a graphical interface
(GUI) for my script that I developed. Thanks, I am pretty new at R, so more
basic, the better. Thank you!

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

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


Re: [R] How to create R package

2010-04-27 Thread Sharpie


Dinh Diep wrote:
> 
> Hi,
> 
>  Can you tell me how to create R package in Windows, and give me an
> example that works ? Thanks.
> 

Hi Dinh,

Check out the help page for the package.skeleton() function- it will create
the outline of a package for you.  The "Writing R Extensions" manual will
tell you, with examples, how to flesh it out- you can find a copy online at:

  http://cran.r-project.org/doc/manuals/R-exts.html

Hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-create-R-package-tp2068592p2068646.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] Robust ANOVA functions in R?

2010-04-27 Thread jinyan fan
Hello,
 
Anyone familiar with robust ANOVA in R? Please help. 
 
I am conducting a between-between-within (2 X 2 X 2) ANOVA, with the focus 
on the significance of the three-way interaction. Because of very uneven sample 
sizes, and the violation of covariance homogeneity, I need to use some sort of 
robust ANOVA method, and I prefer bootstrap. I am aware of Rand Wilcox's robust 
package that can be run in R, but although it has the bootstrap functions for 
between-within ANOVA. it does not contain the bootstrap functions for 
between-between-within ANOVA. Thanks a lot. 
 
Fan
 

Jinyan Fan

Assistant Professor 
Department of Psychology 
Hofstra University 
Hempstead, NY 11550 
Work: 516-463-6349


  
[[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] -network- package in R: removing nodes

2010-04-27 Thread Rick L
Dear all, 

If you have experience with the -network- package, can you show me how to 
remove nodes based on their degrees? For instance, removing all nodes with an 
out-degree or in-degree of 1? 

Thank you very much for your help!

Rick

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


[R] How to create R package

2010-04-27 Thread Dinh Diep
Hi,

 Can you tell me how to create R package in Windows, and give me an
example that works ? 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.


[R] Finding the max correlation coefficient value using CCF function

2010-04-27 Thread vikrant

Hi All,
 Suppose I have 2 time series 
 a = 1:20
 b = 5:15

and I am finding the cross correlation between these two time series using
CCF function.

c = ccf(a,b)
print(c)

Autocorrelations of series ‘X’, by lag

-7 -6 -5 -4 -3 -2 -1  0  1  2  3
 
4  5  6  7 
-0.358 -0.255 -0.110  0.070  0.278  0.507  0.750  1.000  0.750  0.507  0.278 
0.070 -0.110 -0.255 -0.358 

it will give me the correlation coefficient (r) with corrsponding lags.
My Question is how to find the value of maximum correlation coefficient 
with the corrsponding lag.
here in this case its r = 0.75 with lag = 0

how to get this valus in a vector or variable?

 

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Finding-the-max-correlation-coefficient-value-using-CCF-function-tp2068580p2068580.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] some QCA questions

2010-04-27 Thread Wincent
I didn't see any response, so I pick it up.

I don't think there is exact method to calculate the RAM use. Given
that you have a data set, QCA and R, you can just try to run the model
and see if it can hanlde it.
My hunch is that if you don't use remainders in the boolean
minimization process, it might work. Otherwise, it is really hard to
say.
QCA has implemented mvQCA. Not sure about fsQCA, maybe soon.

Besides QCA, you can try QCA3 (http://asrr.r-forge.r-project.org/).
fs_tt can construct truthTable which can be passed to QCA::eqmcc. QCA3
offers functions for csQCA, mvQCA and fsQCA. The developed version
also can handle TQAC discussed in  Ragin, Charles C. and Sarah Ilene
Strand (2008). However, I have to admit that QCA3 is a bit slower than
QCA.

Regards
Ronggui

On 28 July 2009 23:38, Suzanne van der Post  wrote:
> Dear Adrian Dusa, others,
>
> I've recently started to learn R in order to use the QCA package because
> i think it might offer what other QCA packages don't: possibilities for
> quite a few conditions and large n. However, can someone tell me approx.
> how much RAM i need to run QCA on set of  +/- 400.000 cases and +/- 15
> conditions? (or differently: how much time will it take with RAM of a
> certain size?)
> Also I'm very keen on hearing any news on the fuzzy and multivalue
> options for R...How's that comming along?
>
> Thanks a lot for any information you can provide!
> And of course major thanks for all the information you've already
> provided for me in existing manuals, R-fora etc. Great work!
>
> Greetings,
> Suzan van der Post
>
>
>
>
>
>
>        [[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.
>



-- 
Wincent Rong-gui HUANG
Doctoral Candidate
Dept of Public and Social Administration
City University of Hong Kong
http://asrr.r-forge.r-project.org/rghuang.html

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


Re: [R] suggestion on method dispatch

2010-04-27 Thread Gabor Grothendieck
You can pass it:

NextMethod("fn", x = uniqueFoo2, common = common)

On Tue, Apr 27, 2010 at 10:42 PM, Wincent  wrote:
> Thanks Gabor.
>
> Still, there is one problem. If the common argument is
> common=c("opt1","opt2") and I want to use match.arg(common) in side
> fn.foo1, then an error is encountered.
>
> fn <- function(x,...) UseMethod("fn")
>
> fn.default <-
>
> fn.foo1 <- function(x, common=c("opt1","opt2"), ...) {
>       match.arg(common)
>       print("fn.foo1 is called.")
> }
>
> fn.foo2 <- function(x, uniqueFoo2, common=c("opt1","opt2"), ...){
>
>       NextMethod("fn", x = uniqueFoo2)
>
> }
>
> y <-  "y"; class(y) <- "foo2"
> fn(x=y, "unique argument")
> ## Error in match.arg(common) : 'arg' should be one of “opt1”, “opt2”
> fn(x=y, uni="unique argument")
> ## works only when the second argument is named.
>
> It seems that I need to align every argument of fn.foo1 into
> NextMethod, then uniqueFoo2 will become part of list(...) in fn.foo1.
> Otherwise, the unamed argument of uniqueFoo2 will be messed up.
> Right?
>
> Best
>
> On 27 April 2010 23:14, Gabor Grothendieck  wrote:
>> Define fn.default as a synonym to fn.foo1 (or just rename fn.foo1 as
>> fn.default) and then use NextMethod as shown:
>>
>> fn <- function(x,...) UseMethod("fn")
>>
>> fn.default <-
>> fn.foo1 <- function(x, commonA=1, ...) {
>>        print("fn.foo1 is called.")
>> }
>>
>> fn.foo2 <- function(x, uniqueFoo2, common=1, ...){
>>        NextMethod("fn", x = uniqueFoo2)
>> }
>>
>> y <-  "y"; class(y) <- "foo2"
>> fn(x=y, "unique argument")
>>
>> On Tue, Apr 27, 2010 at 10:40 AM, Wincent  wrote:
>>> Dear all, I have define a function  and its methods as follows:
>>>
>>>  beginning of code
>>> fn <- function(x,...){
>>> UseMethod("fn")
>>> }
>>>
>>> fn.foo1 <- function(x, commonA=1, ...){
>>> print("fn.foo1 is called.")
>>> }
>>>
>>> fn.foo2 <- function(x, uniqueFoo2, common=1, ...){
>>> ## uniqueFoo2 is a unique argument in fn.foo2
>>> x <- uniqueFoo2; class(x) <- "foo1"
>>> ## use uniqueFoo2 to generate a object of class foo1
>>> dots <- list(...)
>>> do.call(fn.foo1, c(list(x=x,common=common),dots)
>>> ## pass x, commonA and other arguments from ... to fn.foo1
>>> }
>>>
>>> y <-  "y"; class(y) <- "foo2"
>>> fn(x=y, "unique argument")
>>>
>>>  end of code
>>>
>>> They works as expected. I call fn.foo1 because I don't want to
>>> duplicate the same piece of code.
>>> Yet, I wonder if here is any official way to do the same thing without
>>> directly call fn.foo1 via do.call.
>>> To directly call a method is not a good coding style, right?
>>>
>>> Thanks very much for your suggestion in advance.
>>>
>>> --
>>> Wincent Rong-gui HUANG
>>> Doctoral Candidate
>>> Dept of Public and Social Administration
>>> City University of Hong Kong
>>> http://asrr.r-forge.r-project.org/rghuang.html
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>
>
>
> --
> Wincent Rong-gui HUANG
> Doctoral Candidate
> Dept of Public and Social Administration
> City University of Hong Kong
> http://asrr.r-forge.r-project.org/rghuang.html
>

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


Re: [R] suggestion on method dispatch

2010-04-27 Thread Wincent
Thanks Gabor.

Still, there is one problem. If the common argument is
common=c("opt1","opt2") and I want to use match.arg(common) in side
fn.foo1, then an error is encountered.

fn <- function(x,...) UseMethod("fn")

fn.default <-

fn.foo1 <- function(x, common=c("opt1","opt2"), ...) {
   match.arg(common)
   print("fn.foo1 is called.")
}

fn.foo2 <- function(x, uniqueFoo2, common=c("opt1","opt2"), ...){

   NextMethod("fn", x = uniqueFoo2)

}

y <-  "y"; class(y) <- "foo2"
fn(x=y, "unique argument")
## Error in match.arg(common) : 'arg' should be one of “opt1”, “opt2”
fn(x=y, uni="unique argument")
## works only when the second argument is named.

It seems that I need to align every argument of fn.foo1 into
NextMethod, then uniqueFoo2 will become part of list(...) in fn.foo1.
Otherwise, the unamed argument of uniqueFoo2 will be messed up.
Right?

Best

On 27 April 2010 23:14, Gabor Grothendieck  wrote:
> Define fn.default as a synonym to fn.foo1 (or just rename fn.foo1 as
> fn.default) and then use NextMethod as shown:
>
> fn <- function(x,...) UseMethod("fn")
>
> fn.default <-
> fn.foo1 <- function(x, commonA=1, ...) {
>        print("fn.foo1 is called.")
> }
>
> fn.foo2 <- function(x, uniqueFoo2, common=1, ...){
>        NextMethod("fn", x = uniqueFoo2)
> }
>
> y <-  "y"; class(y) <- "foo2"
> fn(x=y, "unique argument")
>
> On Tue, Apr 27, 2010 at 10:40 AM, Wincent  wrote:
>> Dear all, I have define a function  and its methods as follows:
>>
>>  beginning of code
>> fn <- function(x,...){
>> UseMethod("fn")
>> }
>>
>> fn.foo1 <- function(x, commonA=1, ...){
>> print("fn.foo1 is called.")
>> }
>>
>> fn.foo2 <- function(x, uniqueFoo2, common=1, ...){
>> ## uniqueFoo2 is a unique argument in fn.foo2
>> x <- uniqueFoo2; class(x) <- "foo1"
>> ## use uniqueFoo2 to generate a object of class foo1
>> dots <- list(...)
>> do.call(fn.foo1, c(list(x=x,common=common),dots)
>> ## pass x, commonA and other arguments from ... to fn.foo1
>> }
>>
>> y <-  "y"; class(y) <- "foo2"
>> fn(x=y, "unique argument")
>>
>>  end of code
>>
>> They works as expected. I call fn.foo1 because I don't want to
>> duplicate the same piece of code.
>> Yet, I wonder if here is any official way to do the same thing without
>> directly call fn.foo1 via do.call.
>> To directly call a method is not a good coding style, right?
>>
>> Thanks very much for your suggestion in advance.
>>
>> --
>> Wincent Rong-gui HUANG
>> Doctoral Candidate
>> Dept of Public and Social Administration
>> City University of Hong Kong
>> http://asrr.r-forge.r-project.org/rghuang.html
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>



-- 
Wincent Rong-gui HUANG
Doctoral Candidate
Dept of Public and Social Administration
City University of Hong Kong
http://asrr.r-forge.r-project.org/rghuang.html

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


Re: [R] Selecting rows based on contents of string

2010-04-27 Thread Peter Alspach
Tena koe Alexis

?regexpr

yourDataFrame[regexpr('G', yourDataFrame$Flags)>0,]

HTH ...

Peter Alspach

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Alexis Champsaur
> Sent: Wednesday, 28 April 2010 11:49 a.m.
> To: r-h...@stat.math.ethz.ch
> Subject: [R] Selecting rows based on contents of string
> 
> Hi there,
> I have a data frame with a column named "Flags", whose contents are
> strings
> containing any of the following characters, multiple characters
> allowed:
> A,B,C,D,E,F,G.
> 
> Here is the head:
> GeocodeID PlaceID CountyCode CBSACode StateProvCode
> PropertyTypeGroupID
> Flags
> 1   0   000
> AK   1  ABC
> 2   0   000
> AK   2  AC
> 3   0   000
> AK   3  BC
> 4   0   000
> AK   4  CD
> 5   0   000
> AK  14 CD
> 6   0   000
> AK  15 ACDE
> 7   0   000
> AL   1
> 
> I want to select only the rows whose "Flag" element contains the
> character
> G. Is there a simple way to do this, or should I perhaps come up with
a
> different system of flags, which is totally up to me?
> 
> Thanks,
> 
> Alex
> 
>   [[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] when setting environment: target of assignment expands to non-language object

2010-04-27 Thread Gabor Grothendieck
The environment of your function, as written, is the global
environment which means that free variables in it are looked up there
but you want it so that those free variables are looked up in the nlme
namespace first so set its environment as shown:

library(nlme)
nlme <- asNamespace("nlme")
unlockBinding("coef<-.corSpatial", nlme)
`coef<-.corSpatial` <- ... your function ...
environment(`coef<-.corSpatial`) <- nlme  ###
assignInNamespace("coef<-.corSpatial", `coef<-.corSpatial`, nlme)
lockBinding("coef<-.corSpatial", nlme)
mymodel <- lme(fixed = e ~ a,random= ~ 1 |
g,data=df,correlation=corExp(c(1,.5),form= ~ x + y | g,
nugget=TRUE),control=list(msVerbose=TRUE,opt="nlminb"))



On Tue, Apr 27, 2010 at 8:19 PM, Michael Steven Rooney
 wrote:
> Thanks for your help. I am making great progress, but there are still some
> things that are puzzling me.
>
> In the code below, I add a cat() statement to `coef<-.corExp`. Sure enough,
> when I run lme(), it prints. (awesome!) However, the function does not seem
> to be able to find the C script "spatial_factList". I find that if I replace
> "spatial_factList" with "nlme:::spatial_factList" it works, but I am
> confused by why it cannot be found in the first case.
>
> Mike
>
>> set.seed(444)
>> N <- 100
>> x <- round(sin(rep(1:23/2,length.out=N)),digits=2)+1:N*2/N
>> y <- round(cos(rep(1:23/2,length.out=N)),digits=2)+1:N*2/N
>> g <- rep(1:5,each=N/5)
>> a <- round(runif(N,0,10))
>> t <- 1:N
>> r <- runif(N,0,5)
>> e <- 5*sin(4*x) +
> +  5*cos(4*y) +
> +  5*sin(t) +
> +  2*g +
> +  a +
> +  r
>> e <- round(e)
>>
>> df <- data.frame(x,y,g,a,t,r,e)
>> df <- df[-c(22,23,67),]
>>
>> library(nlme)
>> unlockBinding("coef<-.corSpatial",asNamespace("nlme"))
>> assignInNamespace("coef<-.corSpatial",
> + `coef<-.corSpatial` <- function (object, ..., value)
> + {
> + cat("coef<-.corExp\n")
> + if (length(value) != length(object)) {
> + stop("Cannot change the length of the parameter after
> initialization")
> + }
> + object[] <- value
> + corD <- attr(object, "Dim")
> + aux <- .C(spatial_factList, as.double(as.vector(object)),
> + as.integer(attr(object, "nugget")),
> as.double(unlist(getCovariate(object))),
> + as.integer(unlist(corD)), as.double(attr(object, "minD")),
> + factor = double(corD[["sumLenSq"]]), logDet =
> double(1))[c("factor",
> + "logDet")]
> + attr(object, "factor") <- aux[["factor"]]
> + attr(object, "logDet") <- -aux[["logDet"]]
> + object
> + },
> + asNamespace("nlme"))
>> lockBinding("coef<-.corSpatial",asNamespace("nlme"))
>> mymodel <- lme(fixed = e ~ a,random= ~ 1 |
>> g,data=df,correlation=corExp(c(1,.5),form= ~ x + y | g,
>> nugget=TRUE),control=list(msVerbose=TRUE,opt="nlminb"))
> coef<-.corExp
> Error in `coef<-.corSpatial`(`*tmp*`, value = c(0, 0)) :
>   object 'spatial_factList' not found
>
> On Tue, Apr 27, 2010 at 4:59 PM, Gabor Grothendieck
>  wrote:
>>
>> You did change it. Try nlme:::corExp
>>
>> Also note that asNamespace("nlme") is a nicer way to refer to it.
>>
>> On Tue, Apr 27, 2010 at 4:32 PM, Michael Steven Rooney
>>  wrote:
>> > Sorry, I am still not understanding this. I tried using the unlock
>> > binding
>> > function, but the function remains unchanged after I attempt an
>> > assignment:
>> >
>> >> library(nlme)
>> >> bindingIsLocked("corExp",environment(corExp))
>> > [1] TRUE
>> >> unlockBinding("corExp",environment(corExp))
>> >> bindingIsLocked("corExp",environment(corExp))
>> > [1] FALSE
>> >> assignInNamespace("corExp",
>> > + function (value = numeric(0), form = ~1, nugget = FALSE, metric =
>> > c("euclidean",
>> > + "maximum", "manhattan"), fixed = FALSE)
>> > + {
>> > + cat("corExp\n")  ## SLIGHTLY CHANGE FUNCTION BY ADDING THIS LINE
>> > + attr(value, "formula") <- form
>> > + attr(value, "nugget") <- nugget
>> > + attr(value, "metric") <- match.arg(metric)
>> > + attr(value, "fixed") <- fixed
>> > + class(value) <- c("corExp", "corSpatial", "corStruct")
>> > + value
>> > + },
>> > + environment(corExp))
>> >> corExp
>> > function (value = numeric(0), form = ~1, nugget = FALSE, metric =
>> > c("euclidean",
>> >     "maximum", "manhattan"), fixed = FALSE)
>> > {
>> >     attr(value, "formula") <- form
>> >     attr(value, "nugget") <- nugget
>> >     attr(value, "metric") <- match.arg(metric)
>> >     attr(value, "fixed") <- fixed
>> >     class(value) <- c("corExp", "corSpatial", "corStruct")
>> >     value
>> > }
>> > 
>> >
>> > On Mon, Apr 26, 2010 at 11:25 PM, Gabor Grothendieck
>> >  wrote:
>> >>
>> >> See ?lockBinding
>> >>
>> >> On Mon, Apr 26, 2010 at 11:20 PM, Michael Steven Rooney
>> >>  wrote:
>> >> > I tried editing the corExp function (added a line) within the nlme
>> >> > environment with the following code, but it looks like my declaration
>> >> > did
>> >> > not have any effect. I am guessing it is locked some how. Is there an
>> >> > easy
>> >> > way to do this or am I treading in

Re: [R] when setting environment: target of assignment expands to non-language object

2010-04-27 Thread Michael Steven Rooney
Thanks for your help. I am making great progress, but there are still some
things that are puzzling me.

In the code below, I add a cat() statement to `coef<-.corExp`. Sure enough,
when I run lme(), it prints. (awesome!) However, the function does not seem
to be able to find the C script "spatial_factList". I find that if I replace
"spatial_factList" with "nlme:::spatial_factList" it works, but I am
confused by why it cannot be found in the first case.

Mike

> set.seed(444)
> N <- 100
> x <- round(sin(rep(1:23/2,length.out=N)),digits=2)+1:N*2/N
> y <- round(cos(rep(1:23/2,length.out=N)),digits=2)+1:N*2/N
> g <- rep(1:5,each=N/5)
> a <- round(runif(N,0,10))
> t <- 1:N
> r <- runif(N,0,5)
> e <- 5*sin(4*x) +
+  5*cos(4*y) +
+  5*sin(t) +
+  2*g +
+  a +
+  r
> e <- round(e)
>
> df <- data.frame(x,y,g,a,t,r,e)
> df <- df[-c(22,23,67),]
>
> library(nlme)
> unlockBinding("coef<-.corSpatial",asNamespace("nlme"))
> assignInNamespace("coef<-.corSpatial",
+ `coef<-.corSpatial` <- function (object, ..., value)
+ {
+ cat("coef<-.corExp\n")
+ if (length(value) != length(object)) {
+ stop("Cannot change the length of the parameter after
initialization")
+ }
+ object[] <- value
+ corD <- attr(object, "Dim")
+ aux <- .C(spatial_factList, as.double(as.vector(object)),
+ as.integer(attr(object, "nugget")),
as.double(unlist(getCovariate(object))),
+ as.integer(unlist(corD)), as.double(attr(object, "minD")),
+ factor = double(corD[["sumLenSq"]]), logDet =
double(1))[c("factor",
+ "logDet")]
+ attr(object, "factor") <- aux[["factor"]]
+ attr(object, "logDet") <- -aux[["logDet"]]
+ object
+ },
+ asNamespace("nlme"))
> lockBinding("coef<-.corSpatial",asNamespace("nlme"))
> mymodel <- lme(fixed = e ~ a,random= ~ 1 |
g,data=df,correlation=corExp(c(1,.5),form= ~ x + y | g,
nugget=TRUE),control=list(msVerbose=TRUE,opt="nlminb"))
coef<-.corExp
Error in `coef<-.corSpatial`(`*tmp*`, value = c(0, 0)) :
  object 'spatial_factList' not found

On Tue, Apr 27, 2010 at 4:59 PM, Gabor Grothendieck  wrote:

> You did change it. Try nlme:::corExp
>
> Also note that asNamespace("nlme") is a nicer way to refer to it.
>
> On Tue, Apr 27, 2010 at 4:32 PM, Michael Steven Rooney
>  wrote:
> > Sorry, I am still not understanding this. I tried using the unlock
> binding
> > function, but the function remains unchanged after I attempt an
> assignment:
> >
> >> library(nlme)
> >> bindingIsLocked("corExp",environment(corExp))
> > [1] TRUE
> >> unlockBinding("corExp",environment(corExp))
> >> bindingIsLocked("corExp",environment(corExp))
> > [1] FALSE
> >> assignInNamespace("corExp",
> > + function (value = numeric(0), form = ~1, nugget = FALSE, metric =
> > c("euclidean",
> > + "maximum", "manhattan"), fixed = FALSE)
> > + {
> > + cat("corExp\n")  ## SLIGHTLY CHANGE FUNCTION BY ADDING THIS LINE
> > + attr(value, "formula") <- form
> > + attr(value, "nugget") <- nugget
> > + attr(value, "metric") <- match.arg(metric)
> > + attr(value, "fixed") <- fixed
> > + class(value) <- c("corExp", "corSpatial", "corStruct")
> > + value
> > + },
> > + environment(corExp))
> >> corExp
> > function (value = numeric(0), form = ~1, nugget = FALSE, metric =
> > c("euclidean",
> > "maximum", "manhattan"), fixed = FALSE)
> > {
> > attr(value, "formula") <- form
> > attr(value, "nugget") <- nugget
> > attr(value, "metric") <- match.arg(metric)
> > attr(value, "fixed") <- fixed
> > class(value) <- c("corExp", "corSpatial", "corStruct")
> > value
> > }
> > 
> >
> > On Mon, Apr 26, 2010 at 11:25 PM, Gabor Grothendieck
> >  wrote:
> >>
> >> See ?lockBinding
> >>
> >> On Mon, Apr 26, 2010 at 11:20 PM, Michael Steven Rooney
> >>  wrote:
> >> > I tried editing the corExp function (added a line) within the nlme
> >> > environment with the following code, but it looks like my declaration
> >> > did
> >> > not have any effect. I am guessing it is locked some how. Is there an
> >> > easy
> >> > way to do this or am I treading into complicated waters? (I just
> picked
> >> > up R
> >> > a year ago, and I don't have any experience in development. Willing to
> >> > learn.)
> >> >
> >> >> assignInNamespace("corExp",
> >> > + function (value = numeric(0), form = ~1, nugget = FALSE, metric =
> >> > c("euclidean",
> >> > + "maximum", "manhattan"), fixed = FALSE)
> >> > + {
> >> > + cat("corExp\n")   # I ADDED THIS LINE HERE
> >> > + attr(value, "formula") <- form
> >> > + attr(value, "nugget") <- nugget
> >> > + attr(value, "metric") <- match.arg(metric)
> >> > + attr(value, "fixed") <- fixed
> >> > + class(value) <- c("corExp", "corSpatial", "corStruct")
> >> > + value
> >> > + },
> >> > + environment(corExp))
> >> >> corExp
> >> > function (value = numeric(0), form = ~1, nugget = FALSE, metric =
> >> > c("euclidean",
> >> > "maximum", "manhattan"), fixed = FALSE)
> >> > {
> >> > attr(value, "formul

Re: [R] How to work out 3-way probabilities

2010-04-27 Thread Jeff Brown

If you're willing to assume independence, multiplication is the way to go:

Pr( a beats b & a beats c) = Pr( a beats b ) * Pr( a beats c )

If you're not willing to assume independence, things can get very weird:
http://en.wikipedia.org/wiki/Arrow's_impossibility_theorem
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-work-out-3-way-probabilities-tp2067034p2068457.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] ASYMMETRIC DCC MGARCH

2010-04-27 Thread 莊忠柱
Dear James, Hello,
  Where can I get  any existiong code on R of an Asymmetric (in volatility) DCC 
MGARCH?
Thanks
Best Regards
C C Chuang


[[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] ASYMMETRIC DCC MGARCH

2010-04-27 Thread 莊忠柱

[[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 with command line

2010-04-27 Thread Duncan Murdoch

On 27/04/2010 6:15 PM, Duke wrote:

Hi all,

I am testing R by trying R on command line (ie without opening R 
console) on a Mac Pro with 10.6. So I created a file plot.R:


x11(width=5,height=3.5)
plot(1:10,1:10)

So I have two questions below (please forgive me if the questions have 
been asked already)


1. What is the different between *R CMD BATCH infile.R* and *R --vanilla 
--slave < infile.R*?
  


Those are quite similar.  A couple of differences are:

--vanilla changes the startup options.  You'll use fewer of the profile 
etc. files.  See ?Startup for the details.


 R CMD BATCH sets up an output file to collect the output.  It would 
likely be called infile.Rout.  It would also have a proc.time() call 
added at the end.


2. When I ran plot.R with one of the above methods, the plot showed up 
for like a second and disappear. What should I do to keep the plot there 
until the user closes it?
  


If you have a user involved, you should be running interactively, not in 
batch mode. You can automatically run your infile.R ahead of starting 
the session by setting an environment variable named R_PROFILE_USER 
pointing to that file; e.g.


R R_PROFILE_USER=infile.R

(which sets the variable temporarily, only for that session).

Thanks,

D.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Selecting rows based on contents of string

2010-04-27 Thread Alexis Champsaur
Hi there,
I have a data frame with a column named "Flags", whose contents are strings
containing any of the following characters, multiple characters allowed:
A,B,C,D,E,F,G.

Here is the head:
GeocodeID PlaceID CountyCode CBSACode StateProvCode PropertyTypeGroupID
Flags
1   0   000
AK   1  ABC
2   0   000
AK   2  AC
3   0   000
AK   3  BC
4   0   000
AK   4  CD
5   0   000
AK  14 CD
6   0   000
AK  15 ACDE
7   0   000
AL   1

I want to select only the rows whose "Flag" element contains the character
G. Is there a simple way to do this, or should I perhaps come up with a
different system of flags, which is totally up to me?

Thanks,

Alex

[[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] classification tree

2010-04-27 Thread Sabariah Saharan
Hi, 

I've a problem with growing a classification tree. I have 26427 observations 
and divided into 4 groups. 
A=17866
B=6873
C=1556
D=132

The problems is when I want to plot the tree, the result appear there is no 
splitnodes for the tree. What should I do now? Is there any ideas how to build 
a tree with this data?
Could you please help me with this? Thanks.

Cheers,
-- 
Saba

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


Re: [R] write.csv size limit in R 2.11.0 -- crashes

2010-04-27 Thread N Klepeis
The latest patched build 51822 fixed the write.csv problem:  
http://cran.r-project.org/bin/windows/base/rpatched.html



On 4/26/2010 2:10 PM, Duncan Murdoch wrote:

On 26/04/2010 4:25 PM, N Klepeis wrote:

Hi,

I just installed R 2.11.0 Win32 and tried to use write.csv (or 
write.table) to write a 121000x26 data frame. This crashes R.


The dataframe was written OK in R 2.10.1.

I tried up to 108000 rows and the file was written OK.  But then 
going to 109000 causes the crash.


Anyone else see this?   I'll gather some more info before reporting a 
bug.


Please try R 2.11.0 patched.  There was a problem in the date/time 
formatting routines which I fixed a few days ago in revision 51811 
that could be involved here.  (You may need to wait a few days:
CRAN is offline, and the mirrors I checked hadn't updated to this 
version yet.)


You could also try an R-devel build; it never had the bug.

Duncan Murdoch

P.S. Bug discussions are generally better in R-devel rather than R-help


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


Re: [R] ShortRead with BWA

2010-04-27 Thread mtmorgan

Hi Duke --

Quoting Duke :


Dear folks,

Please welcome a newbie both to R and the mailing list :). I am
currently working on a sequencing project, and heard about R as well as
some of its packages for next gen sequencing, and decided to give it a
try. Starting with ShortRead, I found a document
(http://www.bioconductor.org/packages/2.5/bioc/vignettes/ShortRead/inst/doc/ShortRead_and_HilbertVis.pdf) which does mention that readAligned was extended to support SAM format (for example,   
BWA

output).

So I tried readAligned with

BWAAln <- readAligned(BWAFile, type = "BWA")

but then I got error:


BWAAln <- readAligned(BWAFile, type = "BWA")

Error: UserArgumentMismatch
  arugment 'type' had value 'BWA' allowable values: 'SolexaExport'
'SolexaAlign' 'SolexaPrealign' 'SolexaRealign' 'SolexaResult'
'MAQMap' 'MAQMapShort' 'MAQMapview' 'Bowtie' 'SOAP'

It looks like ShortRead does not support BWA. Am I right, or what am I
doing wrong? Anybody has any idea?


Welcome to R!

But actually, I should be saying 'welcome to Bioconductor!' and you  
should be on the Bioconductor (or Bioc-sig-seq) mailing list


  http://bioconductor.org/docs/mailList.html

because ShortRead is a Bioconductor package.

BWA produces SAM files, and SAM files can be processed, using  
samtools, to (sorted, indexed) BAM files. And BAM files can be read in  
using readAligned in the just released Bioconductor 2.6 packages. It's  
worth getting your data into BAM files anyway, e.g., for viewing with  
the IGV.


I mentioned 'just released', and although you didn't provide the output of

  sessionInfo()

(basically essential for any post) I can see that, although you're a  
new-comer, it's time to update your R to version 2.11, and update  
Bioconductor to the corresponding version 2.6. You might look at


  http://bioconductor.org/docs/install/

While google and trial and error are one way of getting help, you  
might as well get the vignettes from the package you have installed


  browseVignettes("ShortRead")

and discover the R help system

  help.start()
  library(ShortRead)
  help(package="ShortRead")
  ?readAligned

It'll be more effective in the long run.

Martin


Thanks,

D.

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

2010-04-27 Thread Abhishek Pratap
Hi Duke

While your mails are most welcome to this mailing list. You may find
the following mailing list more useful as it caters to the
Bioconductor and Next Generation Sequencing stuff.

Bioc-sig-sequencing mailing list
> bioc-sig-sequenc...@r-project.org
> https://stat.ethz.ch/mailman/listinfo/bioc-sig-sequencing

best,
-Abhi

On Tue, Apr 27, 2010 at 6:07 PM, Duke  wrote:
> Dear folks,
>
> Please welcome a newbie both to R and the mailing list :). I am currently
> working on a sequencing project, and heard about R as well as some of its
> packages for next gen sequencing, and decided to give it a try. Starting
> with ShortRead, I found a document
> (http://www.bioconductor.org/packages/2.5/bioc/vignettes/ShortRead/inst/doc/ShortRead_and_HilbertVis.pdf)
> which does mention that readAligned was extended to support SAM format (for
> example, BWA output).
>
> So I tried readAligned with
>
> BWAAln <- readAligned(BWAFile, type = "BWA")
>
> but then I got error:
>
>> BWAAln <- readAligned(BWAFile, type = "BWA")
> Error: UserArgumentMismatch
>  arugment 'type' had value 'BWA' allowable values: 'SolexaExport'
>    'SolexaAlign' 'SolexaPrealign' 'SolexaRealign' 'SolexaResult'
>    'MAQMap' 'MAQMapShort' 'MAQMapview' 'Bowtie' 'SOAP'
>
> It looks like ShortRead does not support BWA. Am I right, or what am I doing
> wrong? Anybody has any idea?
>
> Thanks,
>
> D.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] TikzDevice and texi2dvi

2010-04-27 Thread Sharpie


Lorenzo Isella wrote:
> 
> I think I solved my problems by resorting to the Ubuntu packages at
> 
> http://bit.ly/c8izKy
> 
> Cheers
> 
> Lorenzo
> 
> 
> Dear All,
> I am starting to use the tikzDevice package, but I am experiencing some
> (minor problems).
> If I try to run the script at the end of the email, I get the following
> error
> 
> 
> Error in tools::texi2dvi("normal.tex", pdf = T) :
>   Running 'texi2dvi' on 'normal.tex' failed.
> Messages:
> sh: /usr/bin/texi2dvi: not found
> 
> How do I install the missing texi2dvi?
> 
> I found some reference to it at
> http://bit.ly/bSYbxk
> but I have not understood well whether it is should already be part of
> my R base installation or not.
> I am running R 2.11 on Ubuntu 9.10.
> Many thanks
> 
> Lorenzo
> 

Hi Lorenzo,

It appears you are missing the texi2dvi program- this is a tool provided by
TeX or TeXinfo distributions, not R or tikzDevice.

In order to use the tikzDevice, you will need to install a TeX distribution
on your machine.  As you are running Linux, I highly recommend the TeXlive
distribution, which you can get from:

  http://www.tug.org/texlive/

I recommend using the net installer at:

  http://www.tug.org/texlive/acquire-netinstall.html

I would advise this over Debian packages, as it has been my experience that
the packages can be horribly out of data- for example the Ubuntu package
repository lists a build based on TeXlive 2007 as being available for 9.10.

The tikzDevice requires PGF/TikZ 2.00 to function properly which in turn
requires TeXlive 2008 or later.

Hope this helps!

-Charlie


-
Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://r.789695.n4.nabble.com/TikzDevice-and-texi2dvi-tp2067230p2068350.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] R with command line

2010-04-27 Thread Duke

Hi all,

I am testing R by trying R on command line (ie without opening R 
console) on a Mac Pro with 10.6. So I created a file plot.R:


x11(width=5,height=3.5)
plot(1:10,1:10)

So I have two questions below (please forgive me if the questions have 
been asked already)


1. What is the different between *R CMD BATCH infile.R* and *R --vanilla 
--slave < infile.R*?


2. When I ran plot.R with one of the above methods, the plot showed up 
for like a second and disappear. What should I do to keep the plot there 
until the user closes it?


Thanks,

D.

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


Re: [R] Maps: Country coding

2010-04-27 Thread Kjetil Halvorsen
have a look at the cran pacvkage countrycode!

Kjetil

On Tue, Apr 27, 2010 at 5:30 PM, Ray Brownrigg
 wrote:
> On Wed, 28 Apr 2010, Berthold Stegemann wrote:
>> Hello,
>>
>> I am using the maps library for plotting maps.
>>
>> To build new geograhical sets such as Europe I use
>>
>> europe = c('Germany','Netherlands',...)
>>
>> Is there a list of county codes used by the map function.
>>
>> Thanks,
>> Berthold
>
> If you mean the names of the countries, have a look at the file:
> ${R_HOME}/library/maps/mapdata/world.N which lists the name associated with 
> every polygon.
>
> Note that the maps database is historical, for example Czechoslovakia is one 
> country.
>
> Hope this helps,
> Ray Brownrigg
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] ShortRead with BWA

2010-04-27 Thread Duke

Dear folks,

Please welcome a newbie both to R and the mailing list :). I am 
currently working on a sequencing project, and heard about R as well as 
some of its packages for next gen sequencing, and decided to give it a 
try. Starting with ShortRead, I found a document 
(http://www.bioconductor.org/packages/2.5/bioc/vignettes/ShortRead/inst/doc/ShortRead_and_HilbertVis.pdf) 
which does mention that readAligned was extended to support SAM format 
(for example, BWA output).


So I tried readAligned with

BWAAln <- readAligned(BWAFile, type = "BWA")

but then I got error:

> BWAAln <- readAligned(BWAFile, type = "BWA")
Error: UserArgumentMismatch
  arugment 'type' had value 'BWA' allowable values: 'SolexaExport'
'SolexaAlign' 'SolexaPrealign' 'SolexaRealign' 'SolexaResult'
'MAQMap' 'MAQMapShort' 'MAQMapview' 'Bowtie' 'SOAP'

It looks like ShortRead does not support BWA. Am I right, or what am I 
doing wrong? Anybody has any idea?


Thanks,

D.

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


Re: [R] Matrix package + mfcol/mfrow

2010-04-27 Thread Sharpie


Gildas Mazo wrote:
> 
> Hi,
> 
> When I load the "Matrix" package, I cannot get the par(mfrow=c(..,..))
> to work, that is, I cannot get to display several images at a time. How
> can I fix this problem ?
> 
> Thanks in advance,
> 
> Gildas Mazo
> 

Hmm, the following:

  require(Matrix)
  par(mfrow=c(1,2))
  plot(1,1,main='first')
  plot(1,1,main='second')

Is working fine for me on R 2.10.0, Windows XP.  Could you provide the
following:

  * The version of R you are using

  * The operating system you are using it on

  * Example code that reproduces the problem on your computer

-Charlie


-
Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Matrix-package-mfcol-mfrow-tp2067879p2068331.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] get means of elements of 5 matrices in a list

2010-04-27 Thread David Freedman

thanks very much for the help - all of these suggestions were much better
than what I was doing
-- 
View this message in context: 
http://r.789695.n4.nabble.com/get-means-of-elements-of-5-matrices-in-a-list-tp2067722p2068329.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] Merging files

2010-04-27 Thread David Winsemius


On Apr 27, 2010, at 4:23 PM, Alex Jameson wrote:


David,

merg12

displays the files
with this message at the bottom

[reached getOption("max.print") -- omitted 321526 rows]]

str(merg12) displays the following message

'data.frame' : 329218 obs. of 13 variables

$ patientid:
$ Name:
$ Age:

but no file is created in the folder mydata

i would expect a file to be created, which is not happening


R is not SPSS. R does its work in memory and has particular functions  
to export or save data (which are two different processes). All this  
would be explained in any introductory text for R. I think you need to  
go back to the "Introduction to R" and the other introductory texts to  
get a better handle on the basics. I had checked it to see if merge  
were describe there and it was not, so I assumed you might have read  
it, but it seems not. You seem to have missed quite a few of its  
important lessons.


Perhaps unlike the SPSS equivalent (however it might be organized by  
IBM at the moment) the R-help mailing list is _not_ set up to be a  
tutoring facility. You are asked to study on your own the large amount  
of free introductory material, work through the examples ... on your  
own, ... and then and only then,  compose detailed questions with full  
code and complete example datasets. I did previously suggest that you  
read the Posting Guide. I now also repeat that suggestion. You might  
also read through the R-FAQ as well.


--
David.




Thank you

Alex


On Tue, Apr 27, 2010 at 4:41 PM, David Winsemius >wrote:




On Apr 27, 2010, at 4:23 PM, Alex Jameson wrote:

Hi David,


I have executed

data1 <- read.table("c:\\mydata\\file1.txt")
data2 <- read.table("c:\\mydata\\file2.txt")

merg12 <- merge(data1, data2)

but am not sure, if it has merged them,
ideally, i would want a new file name for the merged data, based  
on the

identical IDs,



That is what you should have gotten. what happens when you type

merg12

??

and i would need to eliminate some column names (fields) which are  
not

required



That can be don easily. Show us:

str(merg12)


-- David.




Alex



On Tue, Apr 27, 2010 at 2:51 PM, David Winsemius 
wrote:




On Apr 27, 2010, at 1:19 PM, Alex Jameson wrote:

This is a more detailed description of the problem,



I have written the following lines of code to read the files

data1=("c:\\mydata\\file1.txt")
data2=("c:\\mydata\\file2.txt")



NONONO. Read the manual again. Perhaps:

data1 <- read.table("c:\\mydata\\file1.txt")
data2 <- read.table("c:\\mydata\\file2.txt")


file 1 has fields like patientID, Name which are common in file2,  
however

not all fields are common

i would like to create file3.txt with the merged data fields,



And what might happen happened when you tried:

merg12 <- merge(data1, data2)

??? ...  by default it would merge on the field names (actually  
column

names in R-parlance) that were shared by the two dataframes.

--
David


i hope this is clear, and i thank everyone, who has responded so  
far.



Alex Jameson
Student,
University of Colorado

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



David Winsemius, MD
West Hartford, CT




[[alternative HTML version deleted]]

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


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


Re: [R] Merging files

2010-04-27 Thread Sharpie


Alex Jameson wrote:
> 
> David,
> 
> merg12
> 
> displays the files
> with this message at the bottom
> 
> [reached getOption("max.print") -- omitted 321526 rows]]
> 
> str(merg12) displays the following message
> 
> 'data.frame' : 329218 obs. of 13 variables
> 
> $ patientid:
> $ Name:
> $ Age:
> 
> but no file is created in the folder mydata
> 
> i would expect a file to be created, which is not happening
> 
> Thank you
> 
> Alex
> 

Why would you expect a file to be created?  The help page for merge contains
no mention of output to files as part of the function's execution. 
Generally, if the effect you are thinking of is not described in the help
page for a function, then that function does not cause the effect.  If a
function does cause an effect that is not described in the help page, then
the author of the help page did a poor job writing it.

Since you mentioned that you are new to R, I would recommend spending some
time studying the manuals.  First, the "Introduction to R" which gives a
good overview of the R language and describes the various objects you are
trying to work with- specifically data.frame objects.  A copy was probably
included with your installation of R and you can access it online at:

  http://cran.r-project.org/doc/manuals/R-intro.html

Second, you may want to look at the "R Data Import/Export" manual- this will
help clarify how R interacts with files and the functions you need to
execute to do so.  A copy can be found online at:

  http://cran.r-project.org/doc/manuals/R-data.html

Hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Merging-files-tp2067796p2068316.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] Maps: Country coding

2010-04-27 Thread Ray Brownrigg
On Wed, 28 Apr 2010, Berthold Stegemann wrote:
> Hello,
>
> I am using the maps library for plotting maps.
>
> To build new geograhical sets such as Europe I use
>
> europe = c('Germany','Netherlands',...)
>
> Is there a list of county codes used by the map function.
>
> Thanks,
> Berthold

If you mean the names of the countries, have a look at the file:
${R_HOME}/library/maps/mapdata/world.N which lists the name associated with 
every polygon.

Note that the maps database is historical, for example Czechoslovakia is one 
country.

Hope this helps,
Ray Brownrigg

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


Re: [R] Merging files

2010-04-27 Thread Abhishek Pratap
Hi Alex

merge wont write a file automatically. You need to use something which
can direct the output to a file.

write.table(merge12, file = "output.data" ) should do the trick.

Read more at ?write.table

-Abhi


On Tue, Apr 27, 2010 at 5:23 PM, Alex Jameson  wrote:
> David,
>
> merg12
>
> displays the files
> with this message at the bottom
>
> [reached getOption("max.print") -- omitted 321526 rows]]
>
> str(merg12) displays the following message
>
> 'data.frame' : 329218 obs. of 13 variables
>
> $ patientid:
> $ Name:
> $ Age:
>
> but no file is created in the folder mydata
>
> i would expect a file to be created, which is not happening
>
> Thank you
>
> Alex
>
>
> On Tue, Apr 27, 2010 at 4:41 PM, David Winsemius 
> wrote:
>
>>
>> On Apr 27, 2010, at 4:23 PM, Alex Jameson wrote:
>>
>> Hi David,
>>>
>>> I have executed
>>>
>>> data1 <- read.table("c:\\mydata\\file1.txt")
>>> data2 <- read.table("c:\\mydata\\file2.txt")
>>>
>>> merg12 <- merge(data1, data2)
>>>
>>> but am not sure, if it has merged them,
>>> ideally, i would want a new file name for the merged data, based on the
>>> identical IDs,
>>>
>>
>> That is what you should have gotten. what happens when you type
>>
>> merg12
>>
>> ??
>>
>> and i would need to eliminate some column names (fields) which are not
>>> required
>>>
>>
>> That can be don easily. Show us:
>>
>> str(merg12)
>>
>>
>> -- David.
>>
>>
>>>
>>> Alex
>>>
>>>
>>>
>>> On Tue, Apr 27, 2010 at 2:51 PM, David Winsemius >> >wrote:
>>>
>>>
 On Apr 27, 2010, at 1:19 PM, Alex Jameson wrote:

 This is a more detailed description of the problem,

>
> I have written the following lines of code to read the files
>
> data1=("c:\\mydata\\file1.txt")
> data2=("c:\\mydata\\file2.txt")
>
>
 NONONO. Read the manual again. Perhaps:

 data1 <- read.table("c:\\mydata\\file1.txt")
 data2 <- read.table("c:\\mydata\\file2.txt")


 file 1 has fields like patientID, Name which are common in file2, however
> not all fields are common
>
> i would like to create file3.txt with the merged data fields,
>
>
 And what might happen happened when you tried:

 merg12 <- merge(data1, data2)

 ??? ...  by default it would merge on the field names (actually column
 names in R-parlance) that were shared by the two dataframes.

 --
 David


> i hope this is clear, and i thank everyone, who has responded so far.
>
>
> Alex Jameson
> Student,
> University of Colorado
>
>      [[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.
>>>
>>
>>  David Winsemius, MD
>> West Hartford, CT
>>
>>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] Merging files

2010-04-27 Thread Alex Jameson
David,

merg12

displays the files
with this message at the bottom

[reached getOption("max.print") -- omitted 321526 rows]]

str(merg12) displays the following message

'data.frame' : 329218 obs. of 13 variables

$ patientid:
$ Name:
$ Age:

but no file is created in the folder mydata

i would expect a file to be created, which is not happening

Thank you

Alex


On Tue, Apr 27, 2010 at 4:41 PM, David Winsemius wrote:

>
> On Apr 27, 2010, at 4:23 PM, Alex Jameson wrote:
>
> Hi David,
>>
>> I have executed
>>
>> data1 <- read.table("c:\\mydata\\file1.txt")
>> data2 <- read.table("c:\\mydata\\file2.txt")
>>
>> merg12 <- merge(data1, data2)
>>
>> but am not sure, if it has merged them,
>> ideally, i would want a new file name for the merged data, based on the
>> identical IDs,
>>
>
> That is what you should have gotten. what happens when you type
>
> merg12
>
> ??
>
> and i would need to eliminate some column names (fields) which are not
>> required
>>
>
> That can be don easily. Show us:
>
> str(merg12)
>
>
> -- David.
>
>
>>
>> Alex
>>
>>
>>
>> On Tue, Apr 27, 2010 at 2:51 PM, David Winsemius > >wrote:
>>
>>
>>> On Apr 27, 2010, at 1:19 PM, Alex Jameson wrote:
>>>
>>> This is a more detailed description of the problem,
>>>

 I have written the following lines of code to read the files

 data1=("c:\\mydata\\file1.txt")
 data2=("c:\\mydata\\file2.txt")


>>> NONONO. Read the manual again. Perhaps:
>>>
>>> data1 <- read.table("c:\\mydata\\file1.txt")
>>> data2 <- read.table("c:\\mydata\\file2.txt")
>>>
>>>
>>> file 1 has fields like patientID, Name which are common in file2, however
 not all fields are common

 i would like to create file3.txt with the merged data fields,


>>> And what might happen happened when you tried:
>>>
>>> merg12 <- merge(data1, data2)
>>>
>>> ??? ...  by default it would merge on the field names (actually column
>>> names in R-parlance) that were shared by the two dataframes.
>>>
>>> --
>>> David
>>>
>>>
 i hope this is clear, and i thank everyone, who has responded so far.


 Alex Jameson
 Student,
 University of Colorado

  [[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.
>>
>
>  David Winsemius, MD
> West Hartford, CT
>
>

[[alternative HTML version deleted]]

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


Re: [R] coda sweave

2010-04-27 Thread Brian Diggs

On 4/27/2010 1:42 PM, Randall Wrong wrote:

Thank you so much Ista.

I have problems with pictures too.

\begin{figure}
\centering
<>=
xyplot( mcmc(x) )
@
\end{figure}

Why doesn't this work ? Sorry for posting all these questions :-(

Best,
Randall


Check out FAQ 7.22.  You need to use

print(xyplot(mcmc(x)))

since inside an Sweave evaluation, you are not at the command line and 
it does not print by default.



2010/4/27 Ista Zahn


Hi Randall,

Sounds like you need to make friends with the str() function, and
perhaps read the documentation about data types in R. For your
particular problem:

library(coda)
m1<- matrix(runif(100), nrow=10)
m1.sum<- summary(mcmc(m1))
str(m1.sum)

library(xtable)
xtable(m1.sum$statistics)
xtable(m1.sum$quantiles)

Best,
Ista

On Tue, Apr 27, 2010 at 12:22 PM, Randall Wrong
wrote:

This is the kind of output I get with summary(mcmc(x)). I would like it

in

LaTeX. There are two tables.

Iterations = 1:10
Thinning interval = 1
Number of chains = 1
Sample size per chain = 10
1. Empirical mean and standard deviation for each variable,
   plus standard error of the mean:
MeanSD Naive SE Time-series SE
[1,]  0.7237 3.3741.067  1.252
[2,] -1.7883 4.3171.365  1.644
[3,]  0.8384 3.4221.082  1.047
[4,]  1.0750 3.1951.010  1.087
2. Quantiles for each variable:
2.5%  25% 50% 75% 97.5%
var1 -1.5408 -0.91681 -0.1798  0.7134 7.929
var2 -4.1454 -3.89975 -3.5207 -2.1781 7.706
var3 -2.0412 -0.79606  0.3247  1.0445 7.999
var4 -0.9809 -0.08847  0.1895  0.4980 8.015

Thank you very much for any help,
Randall

2010/4/27 Randall Wrong


I forgot to say that the coda package is loaded.

Randall

2010/4/27 Randall Wrong

  Dear R users,


I have a matrix x of simulated values. Each column corresponds to one
variable.

summary(mcmc(x)) works fine

I would like however to transform the ouput into a nice LaTeX code.

xtable( summary(mcmc(x)) ) does not work.

Thanks
Randall







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





  --
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



[[alternative HTML version deleted]]



--
Brian Diggs
Senior Research Associate, Department of Surgery, Oregon Health & 
Science 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] when setting environment: target of assignment expands to non-language object

2010-04-27 Thread Gabor Grothendieck
You did change it. Try nlme:::corExp

Also note that asNamespace("nlme") is a nicer way to refer to it.

On Tue, Apr 27, 2010 at 4:32 PM, Michael Steven Rooney
 wrote:
> Sorry, I am still not understanding this. I tried using the unlock binding
> function, but the function remains unchanged after I attempt an assignment:
>
>> library(nlme)
>> bindingIsLocked("corExp",environment(corExp))
> [1] TRUE
>> unlockBinding("corExp",environment(corExp))
>> bindingIsLocked("corExp",environment(corExp))
> [1] FALSE
>> assignInNamespace("corExp",
> + function (value = numeric(0), form = ~1, nugget = FALSE, metric =
> c("euclidean",
> + "maximum", "manhattan"), fixed = FALSE)
> + {
> + cat("corExp\n")  ## SLIGHTLY CHANGE FUNCTION BY ADDING THIS LINE
> + attr(value, "formula") <- form
> + attr(value, "nugget") <- nugget
> + attr(value, "metric") <- match.arg(metric)
> + attr(value, "fixed") <- fixed
> + class(value) <- c("corExp", "corSpatial", "corStruct")
> + value
> + },
> + environment(corExp))
>> corExp
> function (value = numeric(0), form = ~1, nugget = FALSE, metric =
> c("euclidean",
>     "maximum", "manhattan"), fixed = FALSE)
> {
>     attr(value, "formula") <- form
>     attr(value, "nugget") <- nugget
>     attr(value, "metric") <- match.arg(metric)
>     attr(value, "fixed") <- fixed
>     class(value) <- c("corExp", "corSpatial", "corStruct")
>     value
> }
> 
>
> On Mon, Apr 26, 2010 at 11:25 PM, Gabor Grothendieck
>  wrote:
>>
>> See ?lockBinding
>>
>> On Mon, Apr 26, 2010 at 11:20 PM, Michael Steven Rooney
>>  wrote:
>> > I tried editing the corExp function (added a line) within the nlme
>> > environment with the following code, but it looks like my declaration
>> > did
>> > not have any effect. I am guessing it is locked some how. Is there an
>> > easy
>> > way to do this or am I treading into complicated waters? (I just picked
>> > up R
>> > a year ago, and I don't have any experience in development. Willing to
>> > learn.)
>> >
>> >> assignInNamespace("corExp",
>> > + function (value = numeric(0), form = ~1, nugget = FALSE, metric =
>> > c("euclidean",
>> > + "maximum", "manhattan"), fixed = FALSE)
>> > + {
>> > + cat("corExp\n")   # I ADDED THIS LINE HERE
>> > + attr(value, "formula") <- form
>> > + attr(value, "nugget") <- nugget
>> > + attr(value, "metric") <- match.arg(metric)
>> > + attr(value, "fixed") <- fixed
>> > + class(value) <- c("corExp", "corSpatial", "corStruct")
>> > + value
>> > + },
>> > + environment(corExp))
>> >> corExp
>> > function (value = numeric(0), form = ~1, nugget = FALSE, metric =
>> > c("euclidean",
>> >     "maximum", "manhattan"), fixed = FALSE)
>> > {
>> >     attr(value, "formula") <- form
>> >     attr(value, "nugget") <- nugget
>> >     attr(value, "metric") <- match.arg(metric)
>> >     attr(value, "fixed") <- fixed
>> >     class(value) <- c("corExp", "corSpatial", "corStruct")
>> >     value
>> > }
>> > 
>> >
>> >
>> > On Mon, Apr 26, 2010 at 10:46 PM, Michael Steven Rooney
>> >  wrote:
>> >>
>> >> Thanks.
>> >>
>> >> How do I make my function visible to others? Will assignInNamespace do
>> >> that?
>> >>
>> >> On Mon, Apr 26, 2010 at 10:23 PM, Gabor Grothendieck
>> >>  wrote:
>> >>>
>> >>> See ?assignInNamespace
>> >>>
>> >>> On Mon, Apr 26, 2010 at 9:49 PM, Michael Steven Rooney
>> >>>  wrote:
>> >>> > Hi,
>> >>> >
>> >>> > I am trying to place my own functions in the nlme environment:
>> >>> >
>> >>> > The following statement works:
>> >>> >
>> >>> > environment(coef.corSPT) <-
>> >>> > environment(getS3method("coef","corSpatial"))
>> >>> >
>> >>> > but this one returns an error:
>> >>> >
>> >>> > environment(get("coef<-.corSPT")) <-
>> >>> > environment(getS3method("coef<-","corSpatial"))
>> >>> > Error in environment(get("coef<-.corSPT")) <-
>> >>> > environment(getS3method("coef<-",  :
>> >>> >  target of assignment expands to non-language object
>> >>> >
>> >>> > What should I do?
>> >>> >
>> >>> > Thanks.
>> >>> >
>> >>> > Mike
>> >>> >
>> >>> >        [[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] coda sweave

2010-04-27 Thread Randall Wrong
Thank you so much Ista.

I have problems with pictures too.

\begin{figure}
\centering
<>=
xyplot( mcmc(x) )
@
\end{figure}

Why doesn't this work ? Sorry for posting all these questions :-(

Best,
Randall

2010/4/27 Ista Zahn 

> Hi Randall,
>
> Sounds like you need to make friends with the str() function, and
> perhaps read the documentation about data types in R. For your
> particular problem:
>
> library(coda)
> m1 <- matrix(runif(100), nrow=10)
> m1.sum <- summary(mcmc(m1))
> str(m1.sum)
>
> library(xtable)
> xtable(m1.sum$statistics)
> xtable(m1.sum$quantiles)
>
> Best,
> Ista
>
> On Tue, Apr 27, 2010 at 12:22 PM, Randall Wrong 
> wrote:
> > This is the kind of output I get with summary(mcmc(x)). I would like it
> in
> > LaTeX. There are two tables.
> >
> > Iterations = 1:10
> > Thinning interval = 1
> > Number of chains = 1
> > Sample size per chain = 10
> > 1. Empirical mean and standard deviation for each variable,
> >   plus standard error of the mean:
> >MeanSD Naive SE Time-series SE
> > [1,]  0.7237 3.3741.067  1.252
> > [2,] -1.7883 4.3171.365  1.644
> > [3,]  0.8384 3.4221.082  1.047
> > [4,]  1.0750 3.1951.010  1.087
> > 2. Quantiles for each variable:
> >2.5%  25% 50% 75% 97.5%
> > var1 -1.5408 -0.91681 -0.1798  0.7134 7.929
> > var2 -4.1454 -3.89975 -3.5207 -2.1781 7.706
> > var3 -2.0412 -0.79606  0.3247  1.0445 7.999
> > var4 -0.9809 -0.08847  0.1895  0.4980 8.015
> >
> > Thank you very much for any help,
> > Randall
> >
> > 2010/4/27 Randall Wrong 
> >
> >> I forgot to say that the coda package is loaded.
> >>
> >> Randall
> >>
> >> 2010/4/27 Randall Wrong 
> >>
> >>  Dear R users,
> >>>
> >>> I have a matrix x of simulated values. Each column corresponds to one
> >>> variable.
> >>>
> >>> summary(mcmc(x)) works fine
> >>>
> >>> I would like however to transform the ouput into a nice LaTeX code.
> >>>
> >>> xtable( summary(mcmc(x)) ) does not work.
> >>>
> >>> Thanks
> >>> Randall
> >>>
> >>>
> >>
> >>
> >
> >[[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.
> >
>
>
>
>  --
> Ista Zahn
> Graduate student
> University of Rochester
> Department of Clinical and Social Psychology
> http://yourpsyche.org
>

[[alternative HTML version deleted]]

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


Re: [R] Merging files

2010-04-27 Thread David Winsemius


On Apr 27, 2010, at 4:23 PM, Alex Jameson wrote:


Hi David,

I have executed

data1 <- read.table("c:\\mydata\\file1.txt")
data2 <- read.table("c:\\mydata\\file2.txt")

merg12 <- merge(data1, data2)

but am not sure, if it has merged them,
ideally, i would want a new file name for the merged data, based on  
the

identical IDs,


That is what you should have gotten. what happens when you type

merg12

??

and i would need to eliminate some column names (fields) which are not
required


That can be don easily. Show us:

str(merg12)


-- David.




Alex



On Tue, Apr 27, 2010 at 2:51 PM, David Winsemius >wrote:




On Apr 27, 2010, at 1:19 PM, Alex Jameson wrote:

This is a more detailed description of the problem,


I have written the following lines of code to read the files

data1=("c:\\mydata\\file1.txt")
data2=("c:\\mydata\\file2.txt")



NONONO. Read the manual again. Perhaps:

data1 <- read.table("c:\\mydata\\file1.txt")
data2 <- read.table("c:\\mydata\\file2.txt")


file 1 has fields like patientID, Name which are common in file2,  
however

not all fields are common

i would like to create file3.txt with the merged data fields,



And what might happen happened when you tried:

merg12 <- merge(data1, data2)

??? ...  by default it would merge on the field names (actually  
column

names in R-parlance) that were shared by the two dataframes.

--
David



i hope this is clear, and i thank everyone, who has responded so  
far.



Alex Jameson
Student,
University of Colorado

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


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] Symbols in biplot

2010-04-27 Thread Tobias Verbeke

Hi Ara,

Ara Kooser wrote:

   I just started in on R today. I am at the point where I am trying  
to distinguish different groups of data (hydrochemical data) in  
biplot. I search and found a post about converting the sample number  
in biplot to a symbol like x or +


"> temp <- matrix(runif(50), nrow=10)
 > temp.pca <- princomp(temp)
 > biplot(temp.pca, xlabs=c("A", "A", "B", "B", "B", "C", "C", "C",  
"D", "D"))"


When I try this:
 > biplot(pca,xlabs=c("X"))
Error in dimnames(x) <- list(xlabs, dimnames(x)[[2L]]) :
   length of 'dimnames' [1] not equal to array extent

I guess I am not understanding fully what xlabs is doing and what the  
array extent is. 


You need to add as many symbols (i.e. a character vector
with as many elements) as there are rows in your dataset

biplot(temp.pca, xlabs= rep("X", 10), col = c("blue", "darkgrey"))

should work, similarly to the 10 symbols ("A", "A", "B", etc.)
you used in your call above.

I was wondering if someone could clarify for me how

to change the sample numbers to a symbol?

Also is there a way to color a group of data (i.e. samples 1-50) in  
biplot?


From the help page of biplot.default, it seems the col argument can
be used only to specify the two colors for the two sets of points
which are drawn on the biplot.

Once you get familiar with R graphics, however, it should be relatively
straightforward to work out your own biplot function.

When looking through the code of biplot.default using

getAnywhere("biplot.default")

you will see places where the col argument is used
(look for col[1L] and col[2L]).

HTH,
Tobias

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


Re: [R] Curve Fitting/Regression with Multiple Observations

2010-04-27 Thread Kyeong Soo (Joseph) Kim
Frankly speaking, I am not looking for such a framework.

The system I'm studying is a communication network (like M/M/1 queue,
but way too complicated to mathematically analyze it using classical
queueing theory) and the conclusion I want to make is qualitative
rather than quantatitive -- a high-level comparative study of various
network architectures based on the "equivalence principle" (a concept
specific to netwokring, not in the general sense).

What l want in this regard is a smooth, non-decreasing (hence
one-to-one) function built out of simulation data because later in my
processing, I need an inverse function of the said curve to find out
an x value given the y value. That was, in fact, the reason I used the
exponential (i.e., non-decreasing function) curve fiting.

Even though I don't need a statistical inference framework for my
work, I want to make sure that my use of regression/curve fitting
techniques with my simulation data (as a tool for getting the
mentioned curve) is proper and a usual practice among experts like
you.

To get answer to my question, I digged a lot through the Internet but
found no clear explanation so far.

Your suggestions and providing examples (always!) are much
appreciated, but I am still not sure the use of those regression
procedures with the kind of data I described is a right way to do.

Again, many thanks for your prompt and kind answers,
Joseph


On Tue, Apr 27, 2010 at 8:46 PM, Gabor Grothendieck
 wrote:
> If you are looking for a framework for statistical inference you could
> look at additive models as in the mgcv package which has  a book
> associated with it if you need more info. e.g.
>
> library(mgcv)
> fm <- gam(dist ~ s(speed), data = cars)
> summary(fm)
> plot(dist ~ speed, cars, pch = 20)
> fm.ci <- with(predict(fm, se = TRUE), cbind(0, -2*se.fit, 2*se.fit) + c(fit))
> matlines(cars$speed, fm.ci, lty = c(1, 2, 2), col = c(1, 2, 2))
>
>
> On Tue, Apr 27, 2010 at 3:07 PM, Kyeong Soo (Joseph) Kim
>  wrote:
>> Hello Gabor,
>>
>> Many thanks for providing actual examples for the problem!
>>
>> In fact I know how to apply and generate plots using various R
>> functions including loess, lowess, and smooth.spline procedures.
>>
>> My question, however, is whether applying those procedures directly on
>> the data with multiple observations/duplicate points(?) is on the
>> sound basis or not.
>>
>> Before asking my question to the list, I checked smooth.spline manual
>> pages and found the mentioning of "cv" option related with duplicate
>> points, but I'm not sure "duplicate points" in the manual has the same
>> meaning as "multiple observations" in my case. To me, the manual seems
>> a bit unclear in this regard.
>>
>> Looking at "car" data, I found it has multiple points with the same
>> "speed" but different "dist", which is exactly what I mean by multiple
>> observations, but am still not sure.
>>
>> Regards,
>> Joseph
>>
>>
>> On Tue, Apr 27, 2010 at 7:35 PM, Gabor Grothendieck
>>  wrote:
>>> This will compute a loess curve and plot it:
>>>
>>> example(loess)
>>> plot(dist ~ speed, cars, pch = 20)
>>> lines(cars$speed, fitted(cars.lo))
>>>
>>> Also this directly plots it but does not give you the values of the
>>> curve separately:
>>>
>>> library(lattice)
>>> xyplot(dist ~ speed, cars, type = c("p", "smooth"))
>>>
>>>
>>>
>>> On Tue, Apr 27, 2010 at 1:30 PM, Kyeong Soo (Joseph) Kim
>>>  wrote:
 I recently came to realize the true power of R for statistical
 analysis -- mainly for post-processing of data from large-scale
 simulations -- and have been converting many of existing Python(SciPy)
 scripts to those based on R and/or Perl.

 In the middle of this conversion, I revisited the problem of curve
 fitting for simulation data with multiple observations resulting from
 repetitions.

 In the past, I first processed simulation data (i.e., multiple y's
 from repetitions) to get a mean with a confidence interval for a given
 value of x (independent variable) and then applied spline procedure
 for those mean values only (i.e., unique pairs of (x_i, y_i) for i=1,
 2, ...) to get a smoothed curve. Because of rather large confidence
 intervals, however, the resulting curves were hardly smooth enough for
 my purpose, I had to fix the function to exponential and used least
 square methods to fit its parameters for data.

 >From a plot with confidence intervals, it's rather easy for one to
 visually and manually(?) figure out a smoothed curve for it.
 So I'm thinking right now of directly applying spline (or whatever
 regression procedures for this purpose) to the simulation data with
 repetitions rather than means. The simulation data in this case looks
 like this (assuming three repetitions):

 # x    y
 1      1.2
 1      0.9
 1      1.3
 2      2.2
 2      1.7
 2      2.0
 ...      

 So my idea is to let spline procedu

Re: [R] when setting environment: target of assignment expands to non-language object

2010-04-27 Thread Michael Steven Rooney
Sorry, I am still not understanding this. I tried using the unlock binding
function, but the function remains unchanged after I attempt an assignment:

> library(nlme)
> bindingIsLocked("corExp",environment(corExp))
[1] TRUE
> unlockBinding("corExp",environment(corExp))
> bindingIsLocked("corExp",environment(corExp))
[1] FALSE
> assignInNamespace("corExp",
+ function (value = numeric(0), form = ~1, nugget = FALSE, metric =
c("euclidean",
+ "maximum", "manhattan"), fixed = FALSE)
+ {
+ cat("corExp\n")  ## SLIGHTLY CHANGE FUNCTION BY ADDING THIS LINE
+ attr(value, "formula") <- form
+ attr(value, "nugget") <- nugget
+ attr(value, "metric") <- match.arg(metric)
+ attr(value, "fixed") <- fixed
+ class(value) <- c("corExp", "corSpatial", "corStruct")
+ value
+ },
+ environment(corExp))
> corExp
function (value = numeric(0), form = ~1, nugget = FALSE, metric =
c("euclidean",
"maximum", "manhattan"), fixed = FALSE)
{
attr(value, "formula") <- form
attr(value, "nugget") <- nugget
attr(value, "metric") <- match.arg(metric)
attr(value, "fixed") <- fixed
class(value) <- c("corExp", "corSpatial", "corStruct")
value
}


On Mon, Apr 26, 2010 at 11:25 PM, Gabor Grothendieck <
ggrothendi...@gmail.com> wrote:

> See ?lockBinding
>
> On Mon, Apr 26, 2010 at 11:20 PM, Michael Steven Rooney
>  wrote:
> > I tried editing the corExp function (added a line) within the nlme
> > environment with the following code, but it looks like my declaration did
> > not have any effect. I am guessing it is locked some how. Is there an
> easy
> > way to do this or am I treading into complicated waters? (I just picked
> up R
> > a year ago, and I don't have any experience in development. Willing to
> > learn.)
> >
> >> assignInNamespace("corExp",
> > + function (value = numeric(0), form = ~1, nugget = FALSE, metric =
> > c("euclidean",
> > + "maximum", "manhattan"), fixed = FALSE)
> > + {
> > + cat("corExp\n")   # I ADDED THIS LINE HERE
> > + attr(value, "formula") <- form
> > + attr(value, "nugget") <- nugget
> > + attr(value, "metric") <- match.arg(metric)
> > + attr(value, "fixed") <- fixed
> > + class(value) <- c("corExp", "corSpatial", "corStruct")
> > + value
> > + },
> > + environment(corExp))
> >> corExp
> > function (value = numeric(0), form = ~1, nugget = FALSE, metric =
> > c("euclidean",
> > "maximum", "manhattan"), fixed = FALSE)
> > {
> > attr(value, "formula") <- form
> > attr(value, "nugget") <- nugget
> > attr(value, "metric") <- match.arg(metric)
> > attr(value, "fixed") <- fixed
> > class(value) <- c("corExp", "corSpatial", "corStruct")
> > value
> > }
> > 
> >
> >
> > On Mon, Apr 26, 2010 at 10:46 PM, Michael Steven Rooney
> >  wrote:
> >>
> >> Thanks.
> >>
> >> How do I make my function visible to others? Will assignInNamespace do
> >> that?
> >>
> >> On Mon, Apr 26, 2010 at 10:23 PM, Gabor Grothendieck
> >>  wrote:
> >>>
> >>> See ?assignInNamespace
> >>>
> >>> On Mon, Apr 26, 2010 at 9:49 PM, Michael Steven Rooney
> >>>  wrote:
> >>> > Hi,
> >>> >
> >>> > I am trying to place my own functions in the nlme environment:
> >>> >
> >>> > The following statement works:
> >>> >
> >>> > environment(coef.corSPT) <-
> >>> > environment(getS3method("coef","corSpatial"))
> >>> >
> >>> > but this one returns an error:
> >>> >
> >>> > environment(get("coef<-.corSPT")) <-
> >>> > environment(getS3method("coef<-","corSpatial"))
> >>> > Error in environment(get("coef<-.corSPT")) <-
> >>> > environment(getS3method("coef<-",  :
> >>> >  target of assignment expands to non-language object
> >>> >
> >>> > What should I do?
> >>> >
> >>> > Thanks.
> >>> >
> >>> > Mike
> >>> >
> >>> >[[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] Merging files

2010-04-27 Thread Alex Jameson
Hi David,

I have executed

data1 <- read.table("c:\\mydata\\file1.txt")
data2 <- read.table("c:\\mydata\\file2.txt")

merg12 <- merge(data1, data2)

but am not sure, if it has merged them,
ideally, i would want a new file name for the merged data, based on the
identical IDs,
and i would need to eliminate some column names (fields) which are not
required


Alex



On Tue, Apr 27, 2010 at 2:51 PM, David Winsemius wrote:

>
> On Apr 27, 2010, at 1:19 PM, Alex Jameson wrote:
>
> This is a more detailed description of the problem,
>>
>> I have written the following lines of code to read the files
>>
>> data1=("c:\\mydata\\file1.txt")
>> data2=("c:\\mydata\\file2.txt")
>>
>
> NONONO. Read the manual again. Perhaps:
>
> data1 <- read.table("c:\\mydata\\file1.txt")
> data2 <- read.table("c:\\mydata\\file2.txt")
>
>
>> file 1 has fields like patientID, Name which are common in file2, however
>> not all fields are common
>>
>> i would like to create file3.txt with the merged data fields,
>>
>
> And what might happen happened when you tried:
>
> merg12 <- merge(data1, data2)
>
> ??? ...  by default it would merge on the field names (actually column
> names in R-parlance) that were shared by the two dataframes.
>
> --
> David
>
>>
>> i hope this is clear, and i thank everyone, who has responded so far.
>>
>>
>> Alex Jameson
>> Student,
>> University of Colorado
>>
>>[[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] R-help Digest, Vol 86, Issue 28

2010-04-27 Thread Marshall Feldman

On 4/26/10 21:45:55 R P Herrold wrote:

Date: Mon, 26 Apr 2010 21:45:55 -0400 (EDT)
From: R P Herrold
To: Marshall Feldman
Cc:r-help@r-project.org
Subject: [R] Upgrading R using the "global library folder" strategy -,
what do you think about it?
Message-ID:
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed

On Mon, 26 Apr 2010, Marshall Feldman wrote:

   

>  So why not have the appropriate
>  scripts ask a few questions upon the first installation of R (e.g., "Do you
>  want to configure R with a "global" library for packages to make future
>  upgrading easier?") and at upgrade time ("Your previous version of R has a
>  "global" library; do you want the new version to use it?). I'd even go so far
>  as to have the shell script automatically call an R script to run
>  update.packages().
 

There is a large body of literature on this -- interactive
questions of non-root users are useless; root user actiuons
need to be scripted into the package management system
acessible to automation to be scaleable, and to attain the
needed administrator level permissions to make changed

   

>  The point is that most users just want to upgrade, and the upgrade procedure
>  can and should (a) make this as seamless as possible and (b) allow those who
>  may want to run specialized versions of R opt out of the automatic procedure.
 

and computers in a environment that has to conform to a
hard specification (think: pharma research for FDA report
preparation; financial service firms) that the IT department
manages, cannot tolerate such diversity

There is no easy answer here, as 'one size cannot fit all'

-- Russ herrold
   


Y'know, I hadn't thought of multi-user machines, network installs, and 
all that. It's been so long since I've worked on a system like that.


Still, this raises some questions. On multi-user installations is there 
a single library shared by all users or does each user have his/her own 
library? If the latter, then the question is moot because installation 
and library configuration are separate things. If the former, then would 
having a standard arrangement that a root user could modify/override work?


Also, assuming a large number of R installations are on machines used by 
a single user (and perhaps others in a relatively unsophisticated 
arrangement, such as a home computer shared by family members), do you 
think having scripts along the lines I suggested would work for a large 
portion of such users?


One could also have switches on an installation command line. I'm not 
trying to impose a one-size-fits-all model, but sometimes 
standardization is good.


The point is that no matter what the nature of the system, suggestions 
as to best practices and automations to accomplish them should be 
present if at all possible. One can always deviate, but it's good to do 
so consciously.


-- Marsh Feldman

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


Re: [R] Curve Fitting/Regression with Multiple Observations

2010-04-27 Thread Gabor Grothendieck
If you are looking for a framework for statistical inference you could
look at additive models as in the mgcv package which has  a book
associated with it if you need more info. e.g.

library(mgcv)
fm <- gam(dist ~ s(speed), data = cars)
summary(fm)
plot(dist ~ speed, cars, pch = 20)
fm.ci <- with(predict(fm, se = TRUE), cbind(0, -2*se.fit, 2*se.fit) + c(fit))
matlines(cars$speed, fm.ci, lty = c(1, 2, 2), col = c(1, 2, 2))


On Tue, Apr 27, 2010 at 3:07 PM, Kyeong Soo (Joseph) Kim
 wrote:
> Hello Gabor,
>
> Many thanks for providing actual examples for the problem!
>
> In fact I know how to apply and generate plots using various R
> functions including loess, lowess, and smooth.spline procedures.
>
> My question, however, is whether applying those procedures directly on
> the data with multiple observations/duplicate points(?) is on the
> sound basis or not.
>
> Before asking my question to the list, I checked smooth.spline manual
> pages and found the mentioning of "cv" option related with duplicate
> points, but I'm not sure "duplicate points" in the manual has the same
> meaning as "multiple observations" in my case. To me, the manual seems
> a bit unclear in this regard.
>
> Looking at "car" data, I found it has multiple points with the same
> "speed" but different "dist", which is exactly what I mean by multiple
> observations, but am still not sure.
>
> Regards,
> Joseph
>
>
> On Tue, Apr 27, 2010 at 7:35 PM, Gabor Grothendieck
>  wrote:
>> This will compute a loess curve and plot it:
>>
>> example(loess)
>> plot(dist ~ speed, cars, pch = 20)
>> lines(cars$speed, fitted(cars.lo))
>>
>> Also this directly plots it but does not give you the values of the
>> curve separately:
>>
>> library(lattice)
>> xyplot(dist ~ speed, cars, type = c("p", "smooth"))
>>
>>
>>
>> On Tue, Apr 27, 2010 at 1:30 PM, Kyeong Soo (Joseph) Kim
>>  wrote:
>>> I recently came to realize the true power of R for statistical
>>> analysis -- mainly for post-processing of data from large-scale
>>> simulations -- and have been converting many of existing Python(SciPy)
>>> scripts to those based on R and/or Perl.
>>>
>>> In the middle of this conversion, I revisited the problem of curve
>>> fitting for simulation data with multiple observations resulting from
>>> repetitions.
>>>
>>> In the past, I first processed simulation data (i.e., multiple y's
>>> from repetitions) to get a mean with a confidence interval for a given
>>> value of x (independent variable) and then applied spline procedure
>>> for those mean values only (i.e., unique pairs of (x_i, y_i) for i=1,
>>> 2, ...) to get a smoothed curve. Because of rather large confidence
>>> intervals, however, the resulting curves were hardly smooth enough for
>>> my purpose, I had to fix the function to exponential and used least
>>> square methods to fit its parameters for data.
>>>
>>> >From a plot with confidence intervals, it's rather easy for one to
>>> visually and manually(?) figure out a smoothed curve for it.
>>> So I'm thinking right now of directly applying spline (or whatever
>>> regression procedures for this purpose) to the simulation data with
>>> repetitions rather than means. The simulation data in this case looks
>>> like this (assuming three repetitions):
>>>
>>> # x    y
>>> 1      1.2
>>> 1      0.9
>>> 1      1.3
>>> 2      2.2
>>> 2      1.7
>>> 2      2.0
>>> ...      
>>>
>>> So my idea is to let spline procedure handle the fluctuations in the
>>> data (i.e., in repetitions) by itself.
>>> But I wonder whether this direct application of spline procedures for
>>> data with multiple observations makes sense from the statistical
>>> analysis (i.e., theoretical) point of view.
>>>
>>> It may be a stupid question and quite obvious to many, but personally
>>> I don't know where to start.
>>> It would be greatly appreciated if anyone can shed a light on this in
>>> this regard.
>>>
>>> Many thanks in advance,
>>> Joseph
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/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] Passing values to a function when using apply

2010-04-27 Thread Abhishek Pratap
Makes sense.

Thanks guys for your quick reverts!
-Abhi

On Tue, Apr 27, 2010 at 3:34 PM, Erik Iverson  wrote:
>
>
> Abhishek Pratap wrote:
>>
>> Hi Guys
>>
>> Thank you for clearing something I dint know. Just wondering the
>> reason of putting the word function(x)  in the apply function when we
>> have already declared stats function separately.
>>
>> I better understand how the arguments are passed.
>>
>> Thanks!
>> -Abhi
>>
>
> That's creating a *new* function, one without a name, that basically "breaks
> up" the x argument into two values, and passes those along with the third
> argument and passes these to your stats function.  You either have to write
> stats to accept two arguments, or leave stats accepting three arguments and
> use this method.
>

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


Re: [R] Passing values to a function when using apply

2010-04-27 Thread Erik Iverson



Abhishek Pratap wrote:

Hi Guys

Thank you for clearing something I dint know. Just wondering the
reason of putting the word function(x)  in the apply function when we
have already declared stats function separately.

I better understand how the arguments are passed.

Thanks!
-Abhi



That's creating a *new* function, one without a name, that basically 
"breaks up" the x argument into two values, and passes those along with 
the third argument and passes these to your stats function.  You either 
have to write stats to accept two arguments, or leave stats accepting 
three arguments and use this method.


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


Re: [R] Passing values to a function when using apply

2010-04-27 Thread Abhishek Pratap
Hi Guys

Thank you for clearing something I dint know. Just wondering the
reason of putting the word function(x)  in the apply function when we
have already declared stats function separately.

I better understand how the arguments are passed.

Thanks!
-Abhi

On Tue, Apr 27, 2010 at 2:46 PM, Erik Iverson  wrote:
>
>
> Henrique Dallazuanna wrote:
>>
>> try this:
>>
>> apply(veh_drg_animal1[ ,c("readCount","gene_length")] ,1,
>> function(x)stats(x[1], x[2], total=5500))
>>
>
> I agree with this, that was my point in my original reply.  Apply is *not*
> passing 2 arguments simply because you are selecting two columns of the
> input object, it's passing *one argument*, which is the *entire row* of the
> input object.  You can then access them individually within the stats
> function, as Henrique shows.
>

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


Re: [R] Merging files

2010-04-27 Thread Alex Jameson
This is a more detailed description of the problem,

I have written the following lines of code to read the files

data1=("c:\\mydata\\file1.txt")
data2=("c:\\mydata\\file2.txt")

file 1 has fields like patientID, Name which are common in file2, however
not all fields are common

i would like to create file3.txt with the merged data fields,

i hope this is clear, and i thank everyone, who has responded so far.


Alex Jameson
Student,
University of Colorado

[[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] Curve Fitting/Regression with Multiple Observations

2010-04-27 Thread Kyeong Soo (Joseph) Kim
Hello Gabor,

Many thanks for providing actual examples for the problem!

In fact I know how to apply and generate plots using various R
functions including loess, lowess, and smooth.spline procedures.

My question, however, is whether applying those procedures directly on
the data with multiple observations/duplicate points(?) is on the
sound basis or not.

Before asking my question to the list, I checked smooth.spline manual
pages and found the mentioning of "cv" option related with duplicate
points, but I'm not sure "duplicate points" in the manual has the same
meaning as "multiple observations" in my case. To me, the manual seems
a bit unclear in this regard.

Looking at "car" data, I found it has multiple points with the same
"speed" but different "dist", which is exactly what I mean by multiple
observations, but am still not sure.

Regards,
Joseph


On Tue, Apr 27, 2010 at 7:35 PM, Gabor Grothendieck
 wrote:
> This will compute a loess curve and plot it:
>
> example(loess)
> plot(dist ~ speed, cars, pch = 20)
> lines(cars$speed, fitted(cars.lo))
>
> Also this directly plots it but does not give you the values of the
> curve separately:
>
> library(lattice)
> xyplot(dist ~ speed, cars, type = c("p", "smooth"))
>
>
>
> On Tue, Apr 27, 2010 at 1:30 PM, Kyeong Soo (Joseph) Kim
>  wrote:
>> I recently came to realize the true power of R for statistical
>> analysis -- mainly for post-processing of data from large-scale
>> simulations -- and have been converting many of existing Python(SciPy)
>> scripts to those based on R and/or Perl.
>>
>> In the middle of this conversion, I revisited the problem of curve
>> fitting for simulation data with multiple observations resulting from
>> repetitions.
>>
>> In the past, I first processed simulation data (i.e., multiple y's
>> from repetitions) to get a mean with a confidence interval for a given
>> value of x (independent variable) and then applied spline procedure
>> for those mean values only (i.e., unique pairs of (x_i, y_i) for i=1,
>> 2, ...) to get a smoothed curve. Because of rather large confidence
>> intervals, however, the resulting curves were hardly smooth enough for
>> my purpose, I had to fix the function to exponential and used least
>> square methods to fit its parameters for data.
>>
>> >From a plot with confidence intervals, it's rather easy for one to
>> visually and manually(?) figure out a smoothed curve for it.
>> So I'm thinking right now of directly applying spline (or whatever
>> regression procedures for this purpose) to the simulation data with
>> repetitions rather than means. The simulation data in this case looks
>> like this (assuming three repetitions):
>>
>> # x    y
>> 1      1.2
>> 1      0.9
>> 1      1.3
>> 2      2.2
>> 2      1.7
>> 2      2.0
>> ...      
>>
>> So my idea is to let spline procedure handle the fluctuations in the
>> data (i.e., in repetitions) by itself.
>> But I wonder whether this direct application of spline procedures for
>> data with multiple observations makes sense from the statistical
>> analysis (i.e., theoretical) point of view.
>>
>> It may be a stupid question and quite obvious to many, but personally
>> I don't know where to start.
>> It would be greatly appreciated if anyone can shed a light on this in
>> this regard.
>>
>> Many thanks in advance,
>> Joseph
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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] Symbols in biplot

2010-04-27 Thread Ara Kooser
Hello all,

   I just started in on R today. I am at the point where I am trying  
to distinguish different groups of data (hydrochemical data) in  
biplot. I search and found a post about converting the sample number  
in biplot to a symbol like x or +

"> temp <- matrix(runif(50), nrow=10)
 > temp.pca <- princomp(temp)
 > biplot(temp.pca, xlabs=c("A", "A", "B", "B", "B", "C", "C", "C",  
"D", "D"))"

When I try this:
 > biplot(pca,xlabs=c("X"))
Error in dimnames(x) <- list(xlabs, dimnames(x)[[2L]]) :
   length of 'dimnames' [1] not equal to array extent

I guess I am not understanding fully what xlabs is doing and what the  
array extent is. I was wondering if someone could clarify for me how  
to change the sample numbers to a symbol?

Also is there a way to color a group of data (i.e. samples 1-50) in  
biplot?

Thank you for your time and help,
ara


[[alternative HTML version deleted]]

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


Re: [R] Merging files

2010-04-27 Thread David Winsemius


On Apr 27, 2010, at 1:19 PM, Alex Jameson wrote:


This is a more detailed description of the problem,

I have written the following lines of code to read the files

data1=("c:\\mydata\\file1.txt")
data2=("c:\\mydata\\file2.txt")


NONONO. Read the manual again. Perhaps:

data1 <- read.table("c:\\mydata\\file1.txt")
data2 <- read.table("c:\\mydata\\file2.txt")


file 1 has fields like patientID, Name which are common in file2,  
however

not all fields are common

i would like to create file3.txt with the merged data fields,


And what might happen happened when you tried:

merg12 <- merge(data1, data2)

??? ...  by default it would merge on the field names (actually column  
names in R-parlance) that were shared by the two dataframes.


--
David


i hope this is clear, and i thank everyone, who has responded so far.


Alex Jameson
Student,
University of Colorado

[[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] Passing values to a function when using apply

2010-04-27 Thread Erik Iverson



Henrique Dallazuanna wrote:

try this:

apply(veh_drg_animal1[ ,c("readCount","gene_length")] ,1,
function(x)stats(x[1], x[2], total=5500))



I agree with this, that was my point in my original reply.  Apply is 
*not* passing 2 arguments simply because you are selecting two columns 
of the input object, it's passing *one argument*, which is the *entire 
row* of the input object.  You can then access them individually within 
the stats function, as Henrique shows.


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


Re: [R] Merging files

2010-04-27 Thread Ista Zahn
On Tue, Apr 27, 2010 at 2:31 PM, Alex Jameson  wrote:
> Stephen,
>
> ?merge and ?intersect have been suggested, unfortunately, i have browsed
> through the documentation,
> and there is no live example to demonstrate how this can be used.

Sure there is. Try example(intersect) and example(merge). Or, try
?merge and read the examples section...

The
> documentation is not very descriptive.

It does take some getting used to. Hang in there, you'll get better at
reading the documentation with practice.

>
> Am quite new to R, although i have used SPSS and SAS before.

OK, one of the first things you might want to do is learn how to
properly formulate a request for help. If you provide a reproducible
example I am sure you will get a more helpful response.

Best,
Ista
>
> thanks
>
> Alex
>
> On Tue, Apr 27, 2010 at 2:22 PM, stephen sefick  wrote:
>
>> ?merge
>>
>>
>>
>> --
>> Stephen Sefick
>>
>> Let's not spend our time and resources thinking about things that are
>> so little or so large that all they really do for us is puff us up and
>> make us feel like gods.  We are mammals, and have not exhausted the
>> annoying little problems of being mammals.
>>
>>                                                                -K. Mullis
>>
>
>        [[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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.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] Curve Fitting/Regression with Multiple Observations

2010-04-27 Thread Gabor Grothendieck
This will compute a loess curve and plot it:

example(loess)
plot(dist ~ speed, cars, pch = 20)
lines(cars$speed, fitted(cars.lo))

Also this directly plots it but does not give you the values of the
curve separately:

library(lattice)
xyplot(dist ~ speed, cars, type = c("p", "smooth"))



On Tue, Apr 27, 2010 at 1:30 PM, Kyeong Soo (Joseph) Kim
 wrote:
> I recently came to realize the true power of R for statistical
> analysis -- mainly for post-processing of data from large-scale
> simulations -- and have been converting many of existing Python(SciPy)
> scripts to those based on R and/or Perl.
>
> In the middle of this conversion, I revisited the problem of curve
> fitting for simulation data with multiple observations resulting from
> repetitions.
>
> In the past, I first processed simulation data (i.e., multiple y's
> from repetitions) to get a mean with a confidence interval for a given
> value of x (independent variable) and then applied spline procedure
> for those mean values only (i.e., unique pairs of (x_i, y_i) for i=1,
> 2, ...) to get a smoothed curve. Because of rather large confidence
> intervals, however, the resulting curves were hardly smooth enough for
> my purpose, I had to fix the function to exponential and used least
> square methods to fit its parameters for data.
>
> >From a plot with confidence intervals, it's rather easy for one to
> visually and manually(?) figure out a smoothed curve for it.
> So I'm thinking right now of directly applying spline (or whatever
> regression procedures for this purpose) to the simulation data with
> repetitions rather than means. The simulation data in this case looks
> like this (assuming three repetitions):
>
> # x    y
> 1      1.2
> 1      0.9
> 1      1.3
> 2      2.2
> 2      1.7
> 2      2.0
> ...      
>
> So my idea is to let spline procedure handle the fluctuations in the
> data (i.e., in repetitions) by itself.
> But I wonder whether this direct application of spline procedures for
> data with multiple observations makes sense from the statistical
> analysis (i.e., theoretical) point of view.
>
> It may be a stupid question and quite obvious to many, but personally
> I don't know where to start.
> It would be greatly appreciated if anyone can shed a light on this in
> this regard.
>
> Many thanks in advance,
> Joseph
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] coda sweave

2010-04-27 Thread Ista Zahn
Hi Randall,

Sounds like you need to make friends with the str() function, and
perhaps read the documentation about data types in R. For your
particular problem:

library(coda)
m1 <- matrix(runif(100), nrow=10)
m1.sum <- summary(mcmc(m1))
str(m1.sum)

library(xtable)
xtable(m1.sum$statistics)
xtable(m1.sum$quantiles)

Best,
Ista

On Tue, Apr 27, 2010 at 12:22 PM, Randall Wrong  wrote:
> This is the kind of output I get with summary(mcmc(x)). I would like it in
> LaTeX. There are two tables.
>
> Iterations = 1:10
> Thinning interval = 1
> Number of chains = 1
> Sample size per chain = 10
> 1. Empirical mean and standard deviation for each variable,
>   plus standard error of the mean:
>        Mean    SD Naive SE Time-series SE
> [1,]  0.7237 3.374    1.067          1.252
> [2,] -1.7883 4.317    1.365          1.644
> [3,]  0.8384 3.422    1.082          1.047
> [4,]  1.0750 3.195    1.010          1.087
> 2. Quantiles for each variable:
>        2.5%      25%     50%     75% 97.5%
> var1 -1.5408 -0.91681 -0.1798  0.7134 7.929
> var2 -4.1454 -3.89975 -3.5207 -2.1781 7.706
> var3 -2.0412 -0.79606  0.3247  1.0445 7.999
> var4 -0.9809 -0.08847  0.1895  0.4980 8.015
>
> Thank you very much for any help,
> Randall
>
> 2010/4/27 Randall Wrong 
>
>> I forgot to say that the coda package is loaded.
>>
>> Randall
>>
>> 2010/4/27 Randall Wrong 
>>
>>  Dear R users,
>>>
>>> I have a matrix x of simulated values. Each column corresponds to one
>>> variable.
>>>
>>> summary(mcmc(x)) works fine
>>>
>>> I would like however to transform the ouput into a nice LaTeX code.
>>>
>>> xtable( summary(mcmc(x)) ) does not work.
>>>
>>> Thanks
>>> Randall
>>>
>>>
>>
>>
>
>        [[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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.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] Merging files

2010-04-27 Thread Alex Jameson
Stephen,

?merge and ?intersect have been suggested, unfortunately, i have browsed
through the documentation,
and there is no live example to demonstrate how this can be used. The
documentation is not very descriptive.

Am quite new to R, although i have used SPSS and SAS before.

thanks

Alex

On Tue, Apr 27, 2010 at 2:22 PM, stephen sefick  wrote:

> ?merge
>
>
>
> --
> Stephen Sefick
>
> Let's not spend our time and resources thinking about things that are
> so little or so large that all they really do for us is puff us up and
> make us feel like gods.  We are mammals, and have not exhausted the
> annoying little problems of being mammals.
>
>-K. Mullis
>

[[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] Passing values to a function when using apply

2010-04-27 Thread Henrique Dallazuanna
try this:

apply(veh_drg_animal1[ ,c("readCount","gene_length")] ,1,
function(x)stats(x[1], x[2], total=5500))


On Tue, Apr 27, 2010 at 3:24 PM, Abhishek Pratap wrote:

> Hi Henrique and Erik
>
> I still get a error. See below.
>
> apply(veh_drg_animal1[ ,c("readCount","gene_length")] ,1,  stats,
> total=5500)
>
> Error in FUN(newX[, i], ...) :
>  element 1 is empty;
>   the part of the args list of '(' being evaluated was:
>   (length_gene)
>
>
> stats<- function(count,length_gene,total) {
>  ( count/( total * (length_gene ) ) ) * ( 10^9)
> }
>
> Thanks!
> -Abhi
>
> On Tue, Apr 27, 2010 at 2:18 PM, Henrique Dallazuanna 
> wrote:
> > Try this:
> >
> > apply( veh_drg_animal1[ , c("readCount","gene_length")] ,1,  stats, agr3
> =
> > your_constant)
> >
> >
> > On Tue, Apr 27, 2010 at 3:10 PM, Abhishek Pratap  >
> > wrote:
> >>
> >> Hi All
> >>
> >> Slightly lost on how should I pass values to a function I am calling
> >> using apply.
> >>
> >>
> >> apply( veh_drg_animal1[ , c("readCount","gene_length")] ,1,  stats() )
> >>
> >> here stats is a custom function where I want to pass two parameters
> >> from data frame as shown and a third argument which is constant per
> >> instance of apply.
> >>
> >>
> >> stats <- function ( arg1,agr2,agr3) {
> >> ## computation using three parameters
> >> }
> >>
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >
> >
> >
> > --
> > Henrique Dallazuanna
> > Curitiba-Paraná-Brasil
> > 25° 25' 40" S 49° 16' 22" O
> >
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] Passing values to a function when using apply

2010-04-27 Thread Abhishek Pratap
Hi Henrique and Erik

I still get a error. See below.

apply(veh_drg_animal1[ ,c("readCount","gene_length")] ,1,  stats,
total=5500)

Error in FUN(newX[, i], ...) :
  element 1 is empty;
   the part of the args list of '(' being evaluated was:
   (length_gene)


stats<- function(count,length_gene,total) {
 ( count/( total * (length_gene ) ) ) * ( 10^9)
}

Thanks!
-Abhi

On Tue, Apr 27, 2010 at 2:18 PM, Henrique Dallazuanna  wrote:
> Try this:
>
> apply( veh_drg_animal1[ , c("readCount","gene_length")] ,1,  stats, agr3 =
> your_constant)
>
>
> On Tue, Apr 27, 2010 at 3:10 PM, Abhishek Pratap 
> wrote:
>>
>> Hi All
>>
>> Slightly lost on how should I pass values to a function I am calling
>> using apply.
>>
>>
>> apply( veh_drg_animal1[ , c("readCount","gene_length")] ,1,  stats() )
>>
>> here stats is a custom function where I want to pass two parameters
>> from data frame as shown and a third argument which is constant per
>> instance of apply.
>>
>>
>> stats <- function ( arg1,agr2,agr3) {
>> ## computation using three parameters
>> }
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>

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


Re: [R] Merging files

2010-04-27 Thread stephen sefick
?merge

On Tue, Apr 27, 2010 at 1:19 PM, Alex Jameson  wrote:
> This is a more detailed description of the problem,
>
> I have written the following lines of code to read the files
>
> data1=("c:\\mydata\\file1.txt")
> data2=("c:\\mydata\\file2.txt")
>
> file 1 has fields like patientID, Name which are common in file2, however
> not all fields are common
>
> i would like to create file3.txt with the merged data fields,
>
> i hope this is clear, and i thank everyone, who has responded so far.
>
>
> Alex Jameson
> Student,
> University of Colorado
>
>        [[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.
>



-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

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


Re: [R] Merging files

2010-04-27 Thread Alex Jameson
This is a more detailed description of the problem,

I have written the following lines of code to read the files

data1=("c:\\mydata\\file1.txt")
data2=("c:\\mydata\\file2.txt")

file 1 has fields like patientID, Name which are common in file2, however
not all fields are common

i would like to create file3.txt with the merged data fields,

i hope this is clear, and i thank everyone, who has responded so far.


Alex Jameson
Student,
University of Colorado

[[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] Passing values to a function when using apply

2010-04-27 Thread Henrique Dallazuanna
Try this:

apply( veh_drg_animal1[ , c("readCount","gene_length")] ,1,  stats, agr3 =
your_constant)


On Tue, Apr 27, 2010 at 3:10 PM, Abhishek Pratap wrote:

> Hi All
>
> Slightly lost on how should I pass values to a function I am calling
> using apply.
>
>
> apply( veh_drg_animal1[ , c("readCount","gene_length")] ,1,  stats() )
>
> here stats is a custom function where I want to pass two parameters
> from data frame as shown and a third argument which is constant per
> instance of apply.
>
>
> stats <- function ( arg1,agr2,agr3) {
> ## computation using three parameters
> }
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] Passing values to a function when using apply

2010-04-27 Thread Erik Iverson

This is not a reproducible example. You might simply want:

apply(veh_drg_animal1[, c("readCount", "gene_length")], 1, stats, arg2, 
arg3)


But your "two parameters" from the data.frame are really going to be 
passed as one vector, and then within the stats function you can access 
them individually.  I'm guessing you really want a 2-parameter stats 
function call, but it's hard to tell without a real example.


Abhishek Pratap wrote:

Hi All

Slightly lost on how should I pass values to a function I am calling
using apply.


apply( veh_drg_animal1[ , c("readCount","gene_length")] ,1,  stats() )

here stats is a custom function where I want to pass two parameters
from data frame as shown and a third argument which is constant per
instance of apply.


stats <- function ( arg1,agr2,agr3) {
## computation using three parameters
}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Curve Fitting/Regression with Multiple Observations

2010-04-27 Thread Bert Gunter
Joseph:

I believe you need to stop inventing your own statistical methods and
consult a professional statistician. I do not think this list is the proper
place to look for a statistics tutorial when your statistical background
appears to be so inadequate for the task.

Sorry to be so direct -- perhaps I am wrong in my assessment. But if I am
even close, would you like an accountant to fix your car or an auto mechanic
to do your taxes?

Cheers,
Bert

Bert Gunter
Genentech Nonclinical Biostatistics
 
 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Kyeong Soo (Joseph) Kim
Sent: Tuesday, April 27, 2010 10:31 AM
To: r-help@r-project.org
Subject: [R] Curve Fitting/Regression with Multiple Observations

I recently came to realize the true power of R for statistical
analysis -- mainly for post-processing of data from large-scale
simulations -- and have been converting many of existing Python(SciPy)
scripts to those based on R and/or Perl.

In the middle of this conversion, I revisited the problem of curve
fitting for simulation data with multiple observations resulting from
repetitions.

In the past, I first processed simulation data (i.e., multiple y's
from repetitions) to get a mean with a confidence interval for a given
value of x (independent variable) and then applied spline procedure
for those mean values only (i.e., unique pairs of (x_i, y_i) for i=1,
2, ...) to get a smoothed curve. Because of rather large confidence
intervals, however, the resulting curves were hardly smooth enough for
my purpose, I had to fix the function to exponential and used least
square methods to fit its parameters for data.

>From a plot with confidence intervals, it's rather easy for one to
visually and manually(?) figure out a smoothed curve for it.
So I'm thinking right now of directly applying spline (or whatever
regression procedures for this purpose) to the simulation data with
repetitions rather than means. The simulation data in this case looks
like this (assuming three repetitions):

# xy
1  1.2
1  0.9
1  1.3
2  2.2
2  1.7
2  2.0
...  

So my idea is to let spline procedure handle the fluctuations in the
data (i.e., in repetitions) by itself.
But I wonder whether this direct application of spline procedures for
data with multiple observations makes sense from the statistical
analysis (i.e., theoretical) point of view.

It may be a stupid question and quite obvious to many, but personally
I don't know where to start.
It would be greatly appreciated if anyone can shed a light on this in
this regard.

Many thanks in advance,
Joseph

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Passing values to a function when using apply

2010-04-27 Thread Abhishek Pratap
Hi All

Slightly lost on how should I pass values to a function I am calling
using apply.


apply( veh_drg_animal1[ , c("readCount","gene_length")] ,1,  stats() )

here stats is a custom function where I want to pass two parameters
from data frame as shown and a third argument which is constant per
instance of apply.


stats <- function ( arg1,agr2,agr3) {
## computation using three parameters
}

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


Re: [R] Changing Y Axis of Plot

2010-04-27 Thread Henrique Dallazuanna
Try this;

axis(2, at=z, labels=sprintf('%d%%', z * 100), col.axis = "blue",
cex.axis=0.7)


On Tue, Apr 27, 2010 at 1:02 PM, Jeevan Duggempudi wrote:

> Hello,
>
>
>
> I have used plot function to graph two variables and would like to change
> the Y axis labels to % format. So a 0.2 on Y Axis needs to be represented
> as
> 20%. I tried to use the following but am getting a syntax error. could you
> point me to the mistake in this?
>
>
>
> axis(2, at=z, labels=format(z,”%”), col.axis = "blue", cex.axis=0.7)
>
>
>
> Thanks,
>
> Jeevan
>
>[[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.
>
>


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] Histogram not plotting correct breaks

2010-04-27 Thread Greg Snow
What do you expect to happen to values that fall exactly on the boundary?  I 
have seen questions similar to yours that come about because the user expects 
different from what the computer does.  Look at the 'right' argument to the 
hist function for a way to change this and see if that helps.

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


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of burgundy
> Sent: Monday, April 26, 2010 8:04 PM
> To: r-help@r-project.org
> Subject: [R] Histogram not plotting correct breaks
> 
> 
> Hi,
> 
> I'm using the hist function to plot the frequency of 21 variables, but
> it
> keeps starting the x-axis from 0 and adding variables 1 and 2 together
> (all
> other vairables have the correct frequencies). I suspect it adds 1 and
> 2
> together so that 0 can fit in with demarcations at intervals of 5.
> Using
> "xlim=c(1,21)" to specify that i don't want to include 0 and using the
> "breaks" command to specify 21 breaks doesn't help. Any advice?
> Thank you!!
> --
> View this message in context: http://r.789695.n4.nabble.com/Histogram-
> not-plotting-correct-breaks-tp2066057p2066057.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 calculating multiple regressions on a data frame.

2010-04-27 Thread Luis Sisamon
Gabor Grothendieck  gmail.com> writes:
> 
> Replace lm(...) with try(lm(...))
> 

Thanks for all the replies. I managed to make it work with the try() trick, 
I actually padded the lm() on 
two levels of try() and is working now Sharpsteen approach.

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

2010-04-27 Thread Jeevan Duggempudi
Hello,



I have used plot function to graph two variables and would like to change
the Y axis labels to % format. So a 0.2 on Y Axis needs to be represented as
20%. I tried to use the following but am getting a syntax error. could you
point me to the mistake in this?



axis(2, at=z, labels=format(z,”%”), col.axis = "blue", cex.axis=0.7)



Thanks,

Jeevan

[[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] Curve Fitting/Regression with Multiple Observations

2010-04-27 Thread Kyeong Soo (Joseph) Kim
I recently came to realize the true power of R for statistical
analysis -- mainly for post-processing of data from large-scale
simulations -- and have been converting many of existing Python(SciPy)
scripts to those based on R and/or Perl.

In the middle of this conversion, I revisited the problem of curve
fitting for simulation data with multiple observations resulting from
repetitions.

In the past, I first processed simulation data (i.e., multiple y's
from repetitions) to get a mean with a confidence interval for a given
value of x (independent variable) and then applied spline procedure
for those mean values only (i.e., unique pairs of (x_i, y_i) for i=1,
2, ...) to get a smoothed curve. Because of rather large confidence
intervals, however, the resulting curves were hardly smooth enough for
my purpose, I had to fix the function to exponential and used least
square methods to fit its parameters for data.

>From a plot with confidence intervals, it's rather easy for one to
visually and manually(?) figure out a smoothed curve for it.
So I'm thinking right now of directly applying spline (or whatever
regression procedures for this purpose) to the simulation data with
repetitions rather than means. The simulation data in this case looks
like this (assuming three repetitions):

# xy
1  1.2
1  0.9
1  1.3
2  2.2
2  1.7
2  2.0
...  

So my idea is to let spline procedure handle the fluctuations in the
data (i.e., in repetitions) by itself.
But I wonder whether this direct application of spline procedures for
data with multiple observations makes sense from the statistical
analysis (i.e., theoretical) point of view.

It may be a stupid question and quite obvious to many, but personally
I don't know where to start.
It would be greatly appreciated if anyone can shed a light on this in
this regard.

Many thanks in advance,
Joseph

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

2010-04-27 Thread Héloïse Gauvin
Hi!

I am having a few problems with coxph function, I had the same problem with
the use of survfit. Here it is:

when calling 'M22<-coxphw(Surv(V1,V2,V4)~V5, data=XTDV, id=XTDV$V3, *
prentice*= ~V5, robust=TRUE, censcorr=TRUE)'

knowning that my data is:
> XTDV[1:10,1:3]
   V1   V2   V3 V4V5
1   0 36.39706   36  1  343.2224
2   0 36.39706  943  0  161.5931
3   0 36.39706   45  0  790.3714

I get this message: "Error in w[i] <- w[i] * w.sorted[fit$time ==
obj$resp[i, 2]] : replacement has length zero". When I perform a debug I
find that the problem is that the time returned by obj$resp[i,2] is for a
certain i different from fit$time so all the vector is falsebut in fact
the difference is minimal and it doesn't do that with precedent values...

Browse[2]> w.sorted[fit$time==obj$resp[2051,2]]
numeric(0)
Browse[2]> obj$resp[2051,2]
[1] 49.53238
Browse[2]> fit$time[23]
[1] 49.53238
Browse[2]> obj$resp[2051,2]-fit$time[23]
[1] -7.105427e-15

maybe it's because the time I use is not integer? Like I said, I had the
same problem using results from survfit but I fixed it by rounding values
before comparing them. Is there a way to change the function coxphw?

Thank you.

[[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] Identifying breakpoints/inflection points?

2010-04-27 Thread Bert Gunter
... but you should be warned that this is an inherently difficult issue. You
are trying to estimate a second derivative from noisy data. The result is
likely to be **very** dependent on the fitting methods and parameters chosen
(e.g. "span" of a kernel smoother), even if the fit itself is fairly robust.

I suggest you try some sensitivity analyses and/or bootstrapping of your
results if the software does not already provide uncertainty estimates.

Cheers,
Bert

Bert Gunter
Genentech Nonclinical Biostatistics
 
 
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Clint Bowman
Sent: Tuesday, April 27, 2010 9:32 AM
To: Charlotte Chang
Cc: r-help@r-project.org
Subject: Re: [R] Identifying breakpoints/inflection points?

Charlotte,

Try:

library(msProcess)  # you may have to install msProcess
year[peaks(birds.pr$fit)]

-- 
Clint BowmanINTERNET:   cl...@ecy.wa.gov
Air Quality Modeler INTERNET:   cl...@math.utah.edu
Department of Ecology   VOICE:  (360) 407-6815
PO Box 47600FAX:(360) 407-7534
Olympia, WA 98504-7600

On Mon, 26 Apr 2010, Charlotte Chang wrote:

> Hi Clint,
>
> Thank you for your help with the code. The span recommendation really
> improved the fit of my LOESS curve. I appreciate your thoughtful
> assistance!
>
> My remaining question is how could I go about identifying the
> inflection points for the LOESS curve? I was thinking about trying to
> find the 2nd derivative and then using the uniroot function.
>
> My code is here (but it's buggy and doesn't work):
>
> birds.lo<-loess.smooth(x,y,span=0.45)
> d2 <- function(x) {
>   predict(birds.lo, x, deriv=2)$y
> }
> x<-year
> y<-piproute
>
>> d2(x)
> Error in predict(birds.lo, x, deriv = 2)$y :
>  $ operator is invalid for atomic vectors
>
> #Desired next step:
> uniroot(d2,c(7,10))
>
> Any ideas about this would be profoundly appreciated! I'm hitting a dead
end.
>
> Yours,
>
> Charlotte
>
> On Mon, Apr 26, 2010 at 3:32 PM, Clint Bowman  wrote:
>> Charlotte,
>>
>> Try:
>>
>> birds.lo <- loess(piproute~year,span=.25)
>> # play with span to see your desired pattern
>> birds.pr<-predict(birds.lo, data.frame(year = seq(1967, 2009, 1)), se =
>> FALSE)
>> #
>> plot($year,birds.pr$fit,ylim=c(0,5))
>> par(new=T)
>> plot(year,birds.pr$fit,pch="+",col=2,ylim=c(0,5))
>>
>>
>> --
>> Clint Bowman                    INTERNET:       cl...@ecy.wa.gov
>> Air Quality Modeler             INTERNET:       cl...@math.utah.edu
>> Department of Ecology           VOICE:          (360) 407-6815
>> PO Box 47600                    FAX:            (360) 407-7534
>> Olympia, WA 98504-7600
>>
>> On Mon, 26 Apr 2010, Charlotte Chang wrote:
>>
>>> Hello!
>>> I have a dataset with the following two vectors:
>>>
>>>
>>>
year<-c(1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,198
0,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995
,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009)
>>>
>>>
>>>
piproute<-c(0.7,0.945945946,1.886363636,1.607843137,4.245614035,3.17
5675676,2.169014085,2,2.136363636,2.65625,2.080645161,2.114754098,2.09090909
1,3.012195122,2.935897436,2.592105263,1.075757576,1.210526316,1,1.1875,1.903
614458,1.385542169,1.788990826,1.163793103,1.558558559,1.595238095,1.758
33,1.858267717,2.169117647,1.403225806,2.859375,3.236220472,2.054263566,3.85
417,1.812080537,2.708029197,2.75862069,2.625954198,4.540740741,3.6865671
64,2.8,2.968253968,3.517730496)
>>>
>>> Pipits is the response variable (it is the number of birds counted at
>>> each survey site in each year) and year is the independent variable.
>>> If you plot it in R (plot(year,piproute,pch=19)), you'll see that the
>>> relationship looks like a quintic polynomial.
>>>
>>> Initially I was trying to fit this curve using an iterative equation,
>>> but it's not working. I suspect that the curve-fitting equation itself
>>> is inappropriate (it's a modified version of the logistic growth
>>> equation). Now what I'd like to do is identify the 3 break/inflection
>>> points in the population trend. That way, I can make an argument that
>>> the break points corresponded to shifts in government policy with
>>> respect to land use management. I've been looking at the segmented
>>> package, and initially I looked at change.pt test in the circ.stats
>>> package (which is inappropriate b/c my data is not amenable to
>>> circular statistical analysis). Any ideas on what I could do would be
>>> appreciated!
>>>
>>> Thank you!
>>>
>>> -Charlotte
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/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-proj

Re: [R] R for Ubuntu 10.04?

2010-04-27 Thread Tengfei Yin
Hi Jeff,

Thanks for elucidating and suggestions, I realized I should email the debian
mailing list right after I posted here in 'help', sorry for that, then I did
get quick response on that mailing list, they told me the distro for Ubuntu
10.04 will be released in couple days, right now, I could upgrade my R to
2.11 and then upgrade my system to Lucid.

Thanks again for your suggestions!

Best

Tengfei


On Tue, Apr 27, 2010 at 11:20 AM, Jeff Newmiller
wrote:

> Tengfei Yin wrote:
>
>> Hi dear all
>>
>> I am currently using Ubuntu 9.10 (karmic) and R 2.10, I can find a R
>> release
>> that support "karmic" in cran under ubuntu directory, I plan to update my
>> laptop to Ubuntu 10.04 after April 30, since I have to use some new
>> features
>> or new version in it, e.g. QT 4.6,  I don't know if there is going to be a
>> R
>> release that will support this newly released Ubuntu?
>>
>> Thanks
>>
>> Best wishes
>>
>> Tengfei
>>
>>
> a) Applications don't "support" distros... it is the other way around. A
> distro may introduce improvements, but it is generally considered a bug for
> POSIX-compliant distros to upgrade in a manner that leaves existing
> application software unable to run (though it may in some cases need to be
> recompiled).
>
> b) Since the quality of support depends on users like you trying it out and
> reporting bugs and/or patches, your best bet is to try it and report any
> problems you encounter. (I often upgrade by loading the new OS into a
> separate partition... but that is more as assurance that the OS itself will
> be stable, rather than due to concern about existing applications.)
>
> c) This mailing list topic is on using the R software. The correct forum
> for helping (or observing progress of others) with Debian packages of R
> (used on Ubuntu distro) is
>
> https://stat.ethz.ch/mailman/listinfo/r-sig-debian
>
>
>


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

[[alternative HTML version deleted]]

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


Re: [R] Identifying breakpoints/inflection points?

2010-04-27 Thread Clint Bowman

Charlotte,

Try:

library(msProcess)  # you may have to install msProcess
year[peaks(birds.pr$fit)]

--
Clint BowmanINTERNET:   cl...@ecy.wa.gov
Air Quality Modeler INTERNET:   cl...@math.utah.edu
Department of Ecology   VOICE:  (360) 407-6815
PO Box 47600FAX:(360) 407-7534
Olympia, WA 98504-7600

On Mon, 26 Apr 2010, Charlotte Chang wrote:


Hi Clint,

Thank you for your help with the code. The span recommendation really
improved the fit of my LOESS curve. I appreciate your thoughtful
assistance!

My remaining question is how could I go about identifying the
inflection points for the LOESS curve? I was thinking about trying to
find the 2nd derivative and then using the uniroot function.

My code is here (but it's buggy and doesn't work):

birds.lo<-loess.smooth(x,y,span=0.45)
d2 <- function(x) {
predict(birds.lo, x, deriv=2)$y
}
x<-year
y<-piproute


d2(x)

Error in predict(birds.lo, x, deriv = 2)$y :
 $ operator is invalid for atomic vectors

#Desired next step:
uniroot(d2,c(7,10))

Any ideas about this would be profoundly appreciated! I'm hitting a dead end.

Yours,

Charlotte

On Mon, Apr 26, 2010 at 3:32 PM, Clint Bowman  wrote:

Charlotte,

Try:

birds.lo <- loess(piproute~year,span=.25)
# play with span to see your desired pattern
birds.pr<-predict(birds.lo, data.frame(year = seq(1967, 2009, 1)), se =
FALSE)
#
plot($year,birds.pr$fit,ylim=c(0,5))
par(new=T)
plot(year,birds.pr$fit,pch="+",col=2,ylim=c(0,5))


--
Clint Bowman                    INTERNET:       cl...@ecy.wa.gov
Air Quality Modeler             INTERNET:       cl...@math.utah.edu
Department of Ecology           VOICE:          (360) 407-6815
PO Box 47600                    FAX:            (360) 407-7534
Olympia, WA 98504-7600

On Mon, 26 Apr 2010, Charlotte Chang wrote:


Hello!
I have a dataset with the following two vectors:


year<-c(1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009)


piproute<-c(0.7,0.945945946,1.886363636,1.607843137,4.245614035,3.175675676,2.169014085,2,2.136363636,2.65625,2.080645161,2.114754098,2.090909091,3.012195122,2.935897436,2.592105263,1.075757576,1.210526316,1,1.1875,1.903614458,1.385542169,1.788990826,1.163793103,1.558558559,1.595238095,1.75833,1.858267717,2.169117647,1.403225806,2.859375,3.236220472,2.054263566,3.85417,1.812080537,2.708029197,2.75862069,2.625954198,4.540740741,3.686567164,2.8,2.968253968,3.517730496)

Pipits is the response variable (it is the number of birds counted at
each survey site in each year) and year is the independent variable.
If you plot it in R (plot(year,piproute,pch=19)), you'll see that the
relationship looks like a quintic polynomial.

Initially I was trying to fit this curve using an iterative equation,
but it's not working. I suspect that the curve-fitting equation itself
is inappropriate (it's a modified version of the logistic growth
equation). Now what I'd like to do is identify the 3 break/inflection
points in the population trend. That way, I can make an argument that
the break points corresponded to shifts in government policy with
respect to land use management. I've been looking at the segmented
package, and initially I looked at change.pt test in the circ.stats
package (which is inappropriate b/c my data is not amenable to
circular statistical analysis). Any ideas on what I could do would be
appreciated!

Thank you!

-Charlotte

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

2010-04-27 Thread Randall Wrong
This is the kind of output I get with summary(mcmc(x)). I would like it in
LaTeX. There are two tables.

Iterations = 1:10
Thinning interval = 1
Number of chains = 1
Sample size per chain = 10
1. Empirical mean and standard deviation for each variable,
   plus standard error of the mean:
MeanSD Naive SE Time-series SE
[1,]  0.7237 3.3741.067  1.252
[2,] -1.7883 4.3171.365  1.644
[3,]  0.8384 3.4221.082  1.047
[4,]  1.0750 3.1951.010  1.087
2. Quantiles for each variable:
2.5%  25% 50% 75% 97.5%
var1 -1.5408 -0.91681 -0.1798  0.7134 7.929
var2 -4.1454 -3.89975 -3.5207 -2.1781 7.706
var3 -2.0412 -0.79606  0.3247  1.0445 7.999
var4 -0.9809 -0.08847  0.1895  0.4980 8.015

Thank you very much for any help,
Randall

2010/4/27 Randall Wrong 

> I forgot to say that the coda package is loaded.
>
> Randall
>
> 2010/4/27 Randall Wrong 
>
>  Dear R users,
>>
>> I have a matrix x of simulated values. Each column corresponds to one
>> variable.
>>
>> summary(mcmc(x)) works fine
>>
>> I would like however to transform the ouput into a nice LaTeX code.
>>
>> xtable( summary(mcmc(x)) ) does not work.
>>
>> Thanks
>> Randall
>>
>>
>
>

[[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 for Ubuntu 10.04?

2010-04-27 Thread Jeff Newmiller

Tengfei Yin wrote:

Hi dear all

I am currently using Ubuntu 9.10 (karmic) and R 2.10, I can find a R release
that support "karmic" in cran under ubuntu directory, I plan to update my
laptop to Ubuntu 10.04 after April 30, since I have to use some new features
or new version in it, e.g. QT 4.6,  I don't know if there is going to be a R
release that will support this newly released Ubuntu?

Thanks

Best wishes

Tengfei
  
a) Applications don't "support" distros... it is the other way around. A 
distro may introduce improvements, but it is generally considered a bug 
for POSIX-compliant distros to upgrade in a manner that leaves existing 
application software unable to run (though it may in some cases need to 
be recompiled).


b) Since the quality of support depends on users like you trying it out 
and reporting bugs and/or patches, your best bet is to try it and report 
any problems you encounter. (I often upgrade by loading the new OS into 
a separate partition... but that is more as assurance that the OS itself 
will be stable, rather than due to concern about existing applications.)


c) This mailing list topic is on using the R software. The correct forum 
for helping (or observing progress of others) with Debian packages of R 
(used on Ubuntu distro) is


https://stat.ethz.ch/mailman/listinfo/r-sig-debian

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

2010-04-27 Thread Gildas Mazo
Hi,

When I load the "Matrix" package, I cannot get the par(mfrow=c(..,..))
to work, that is, I cannot get to display several images at a time. How
can I fix this problem ?

Thanks in advance,

Gildas Mazo

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


Re: [R] what package/model should I use when response variable is binary and predictor variables are categorical?

2010-04-27 Thread David Winsemius


On Apr 27, 2010, at 12:07 PM, Xiaokuan Wei wrote:


Dear List,

what package/model should I use when response variable is binary and  
predictor variables are categorical?
If there is any example for such analysis you can pointed it out,  
that would be very helpful.


https://home.comcast.net/~lthompson221/Splusdiscrete2.pdf



Thanks.

Xiaokuan



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] Matrix package + mfcol/mfrow

2010-04-27 Thread Uwe Ligges

The fol,owing works for me, so what did you try?

library("Matrix")
par(mfrow=c(2,2))
replicate(4, plot(1))

Uwe Ligges




On 27.04.2010 17:51, Gildas Mazo wrote:

Hi,

When I load the "Matrix" package, I cannot get the par(mfrow=c(..,..))
to work, that is, I cannot get to display several images at a time. How
can I fix this problem ?

Thanks in advance,

Gildas Mazo

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] what package/model should I use when response variable is binary and predictor variables are categorical?

2010-04-27 Thread Xiaokuan Wei
Dear List,

what package/model should I use when response variable is binary and predictor 
variables are categorical?
If there is any example for such analysis you can pointed it out, that would be 
very helpful.

Thanks.

Xiaokuan


  
[[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] get means of elements of 5 matrices in a list

2010-04-27 Thread Peter Ehlers

On 2010-04-27 9:05, David Freedman wrote:


I've got a list of 5 matrices that are each 5 x 6.  I'd like to end up with a
5 x 6 matrix that contains the mean value of the 5 original matrices.  I can
do this by brute force, but there must be a better way than making each
matrix into a vector and then remaking a matrix

thanks very much for any help
david freedman

ll=list(structure(c(9.7, 17.6, 20.8, 24.1, 33.8, 14.5, 25.7, 29.8,
33.6, 44.8, 21.8, 32.6, 37.5, 40.9, 53.3, 16.7, 26.1, 29.5, 32.7,
42.6, 26.2, 34.3, 37, 39.8, 47.1, 31.9, 40.3, 43.3, 46.2, 54.1
), .Dim = 5:6), structure(c(9.4, 17.7, 20.7, 24.1, 33.7, 14.5,
25.7, 29.8, 33.6, 44.8, 21.8, 32.7, 37.5, 40.9, 53.1, 16, 26,
29.5, 32.7, 42.7, 25.6, 34.1, 37, 39.8, 47.1, 31.9, 40.3, 43.3,
46.1, 54.1), .Dim = 5:6), structure(c(9.6, 17.7, 20.8, 24.4,
34.3, 14.5, 25.7, 29.8, 33.6, 44.8, 21.8, 32.6, 37.5, 40.9, 53.2,
16.7, 26.1, 29.5, 32.8, 42.8, 26.2, 34.2, 36.8, 39.9, 47.1, 31.9,
40.3, 43.3, 46.1, 54.8), .Dim = 5:6), structure(c(9.7, 17.6,
20.7, 24.1, 33.8, 14.5, 25.7, 29.8, 33.6, 44.8, 21.8, 32.6, 37.5,
41.1, 52.6, 16.7, 26.1, 29.5, 32.8, 42.8, 26.1, 34.3, 37, 40,
47.1, 31.9, 40.3, 43.3, 46.2, 54.9), .Dim = 5:6), structure(c(8.6,
17.6, 20.7, 24.1, 33.8, 14.5, 25.6, 29.8, 33.6, 44.8, 21.8, 32.6,
37.5, 40.9, 52.5, 16, 26, 29.4, 32.8, 42.8, 25.6, 34.2, 37, 40.1,
47.1, 31.9, 40.3, 43.1, 46.1, 54.1), .Dim = 5:6))

ll
x=rbind(as.vector(ll[[1]]),as.vector(ll[[2]]),as.vector(ll[[3]]),as.vector(ll[[4]]),as.vector(ll[[5]]));
x
x2=apply(x,2,mean); matrix(x2,byrow=F,nrow=5);



Here is one more way: create a 3-dim array, then apply mean():

za <- array(unlist(ll), dim = c(5,6,5))
mn <- apply(za, c(1,2), mean)

--
Peter Ehlers
University of Calgary

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

2010-04-27 Thread Gildas Mazo
Hi,

When I load the "Matrix" package, I cannot get the par(mfrow=c(..,..))
to work, that is, I cannot get to display several images at a time. How
can I fix this problem ?

Thanks in advance,

Gildas Mazo

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

2010-04-27 Thread Charles C. Berry

On Tue, 27 Apr 2010, Dimitrij Kudriavcev wrote:


Hello.

I have a quick question.

I try to use logit regression, to work out probabilities in the sport event.
I have work out probabilities for group of 2 players:

p1 - probability, what player1 will beat player2
p2 - probability, what player2 will beat player1
pt - tie probability, p1 <- 1 - p1 - p2;

Now i want to work out probabilities for group of 3 players, like:

pg1 - probability, what player1 will beat player2 and player3
pg2 - probability, what player2 will beat player1 and player3
pg3 - probability, what player3 will beat player1 and player2

I have probabilities for every pair of players in that group. Is there a
function in R, what can simply convert this 2-way probabilities in to the
3-way (or more)? Or can some body suggest, how to do it manually? I have try
to work it out, buy just multiply corresponding probabilities, but it seems
a bad way.


So each player gets a score and the highest wins?

And your two-way probabilities are just the probability that player1 
scores higher than player2, etc? Or that player1 won over player2 given 
that player3 did not win?


Or you have a bunch of one-on-one competitions and you want to predict 
what will happen in a three way competition?


Have a Google at 'McFadden conditional logit'. There is a literature that 
should point you in the right direction.


Once you have a sense of what goes in conditional logit models you may 
find survival::clogit() to be of assistance.


HTH,

Chuck




Cheers,
Dmitrij.

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



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

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


Re: [R] Merging files

2010-04-27 Thread David Winsemius


On Apr 27, 2010, at 11:34 AM, Alex Jameson wrote:


Hi, any one with experience in merging files

i have different files, some of the files, have the same fields, so  
i would

like to merge them

*File 1:*

field a,b,c,d,e,f

*File 2:*

field a, c, e, m, n

*merged file*

field a, c, e (ie only the common fields)


?intersect





thanks


Alex

[[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] get means of elements of 5 matrices in a list

2010-04-27 Thread David Winsemius


On Apr 27, 2010, at 11:05 AM, David Freedman wrote:



I've got a list of 5 matrices that are each 5 x 6.  I'd like to end  
up with a
5 x 6 matrix that contains the mean value of the 5 original  
matrices.  I can
do this by brute force, but there must be a better way than making  
each

matrix into a vector and then remaking a matrix

thanks very much for any help
david freedman

ll=list(structure(c(9.7, 17.6, 20.8, 24.1, 33.8, 14.5, 25.7, 29.8,
33.6, 44.8, 21.8, 32.6, 37.5, 40.9, 53.3, 16.7, 26.1, 29.5, 32.7,
42.6, 26.2, 34.3, 37, 39.8, 47.1, 31.9, 40.3, 43.3, 46.2, 54.1
), .Dim = 5:6), structure(c(9.4, 17.7, 20.7, 24.1, 33.7, 14.5,
25.7, 29.8, 33.6, 44.8, 21.8, 32.7, 37.5, 40.9, 53.1, 16, 26,
29.5, 32.7, 42.7, 25.6, 34.1, 37, 39.8, 47.1, 31.9, 40.3, 43.3,
46.1, 54.1), .Dim = 5:6), structure(c(9.6, 17.7, 20.8, 24.4,
34.3, 14.5, 25.7, 29.8, 33.6, 44.8, 21.8, 32.6, 37.5, 40.9, 53.2,
16.7, 26.1, 29.5, 32.8, 42.8, 26.2, 34.2, 36.8, 39.9, 47.1, 31.9,
40.3, 43.3, 46.1, 54.8), .Dim = 5:6), structure(c(9.7, 17.6,
20.7, 24.1, 33.8, 14.5, 25.7, 29.8, 33.6, 44.8, 21.8, 32.6, 37.5,
41.1, 52.6, 16.7, 26.1, 29.5, 32.8, 42.8, 26.1, 34.3, 37, 40,
47.1, 31.9, 40.3, 43.3, 46.2, 54.9), .Dim = 5:6), structure(c(8.6,
17.6, 20.7, 24.1, 33.8, 14.5, 25.6, 29.8, 33.6, 44.8, 21.8, 32.6,
37.5, 40.9, 52.5, 16, 26, 29.4, 32.8, 42.8, 25.6, 34.2, 37, 40.1,
47.1, 31.9, 40.3, 43.1, 46.1, 54.1), .Dim = 5:6))

ll
x 
= 
rbind 
(as 
.vector 
(ll 
[[1 
]]),as 
.vector 
(ll[[2]]),as.vector(ll[[3]]),as.vector(ll[[4]]),as.vector(ll[[5]]));

x
x2=apply(x,2,mean); matrix(x2,byrow=F,nrow=5);


> Reduce("+", ll)   # the element-wise sum
  [,1]  [,2]  [,3]  [,4]  [,5]  [,6]
[1,]  47.0  72.5 109.0  82.1 129.7 159.5
[2,]  88.2 128.4 163.1 130.3 171.1 201.5
[3,] 103.7 149.0 187.5 147.4 184.8 216.3
[4,] 120.8 168.0 204.7 163.8 199.6 230.7
[5,] 169.4 224.0 264.7 213.7 235.5 272.0
> Reduce("+", ll)/length(ll)   #and the means
  [,1]  [,2]  [,3]  [,4]  [,5]  [,6]
[1,]  9.40 14.50 21.80 16.42 25.94 31.90
[2,] 17.64 25.68 32.62 26.06 34.22 40.30
[3,] 20.74 29.80 37.50 29.48 36.96 43.26
[4,] 24.16 33.60 40.94 32.76 39.92 46.14
[5,] 33.88 44.80 52.94 42.74 47.10 54.40



--
View this message in context: 
http://r.789695.n4.nabble.com/get-means-of-elements-of-5-matrices-in-a-list-tp2067722p2067722.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.


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] get means of elements of 5 matrices in a list

2010-04-27 Thread Marc Schwartz
On Apr 27, 2010, at 10:19 AM, Marc Schwartz wrote:

> On Apr 27, 2010, at 10:05 AM, David Freedman wrote:
> 
>> 
>> I've got a list of 5 matrices that are each 5 x 6.  I'd like to end up with a
>> 5 x 6 matrix that contains the mean value of the 5 original matrices.  I can
>> do this by brute force, but there must be a better way than making each
>> matrix into a vector and then remaking a matrix
>> 
>> thanks very much for any help
>> david freedman
>> 
>> ll=list(structure(c(9.7, 17.6, 20.8, 24.1, 33.8, 14.5, 25.7, 29.8, 
>> 33.6, 44.8, 21.8, 32.6, 37.5, 40.9, 53.3, 16.7, 26.1, 29.5, 32.7, 
>> 42.6, 26.2, 34.3, 37, 39.8, 47.1, 31.9, 40.3, 43.3, 46.2, 54.1
>> ), .Dim = 5:6), structure(c(9.4, 17.7, 20.7, 24.1, 33.7, 14.5, 
>> 25.7, 29.8, 33.6, 44.8, 21.8, 32.7, 37.5, 40.9, 53.1, 16, 26, 
>> 29.5, 32.7, 42.7, 25.6, 34.1, 37, 39.8, 47.1, 31.9, 40.3, 43.3, 
>> 46.1, 54.1), .Dim = 5:6), structure(c(9.6, 17.7, 20.8, 24.4, 
>> 34.3, 14.5, 25.7, 29.8, 33.6, 44.8, 21.8, 32.6, 37.5, 40.9, 53.2, 
>> 16.7, 26.1, 29.5, 32.8, 42.8, 26.2, 34.2, 36.8, 39.9, 47.1, 31.9, 
>> 40.3, 43.3, 46.1, 54.8), .Dim = 5:6), structure(c(9.7, 17.6, 
>> 20.7, 24.1, 33.8, 14.5, 25.7, 29.8, 33.6, 44.8, 21.8, 32.6, 37.5, 
>> 41.1, 52.6, 16.7, 26.1, 29.5, 32.8, 42.8, 26.1, 34.3, 37, 40, 
>> 47.1, 31.9, 40.3, 43.3, 46.2, 54.9), .Dim = 5:6), structure(c(8.6, 
>> 17.6, 20.7, 24.1, 33.8, 14.5, 25.6, 29.8, 33.6, 44.8, 21.8, 32.6, 
>> 37.5, 40.9, 52.5, 16, 26, 29.4, 32.8, 42.8, 25.6, 34.2, 37, 40.1, 
>> 47.1, 31.9, 40.3, 43.1, 46.1, 54.1), .Dim = 5:6))
>> 
>> ll
>> x=rbind(as.vector(ll[[1]]),as.vector(ll[[2]]),as.vector(ll[[3]]),as.vector(ll[[4]]),as.vector(ll[[5]]));
>> x
>> x2=apply(x,2,mean); matrix(x2,byrow=F,nrow=5); 
> 
> 
> How about:
> 
>> matrix(rowMeans(sapply(ll, unlist)), nrow = length(ll))
>  [,1]  [,2]  [,3]  [,4]  [,5]  [,6]
> [1,]  9.40 14.50 21.80 16.42 25.94 31.90
> [2,] 17.64 25.68 32.62 26.06 34.22 40.30
> [3,] 20.74 29.80 37.50 29.48 36.96 43.26
> [4,] 24.16 33.60 40.94 32.76 39.92 46.14
> [5,] 33.88 44.80 52.94 42.74 47.10 54.40


In the interest of correctness, unlist() is not really needed here and 
as.vector() should be used instead:

> matrix(rowMeans(sapply(ll, as.vector)), nrow = length(ll))
  [,1]  [,2]  [,3]  [,4]  [,5]  [,6]
[1,]  9.40 14.50 21.80 16.42 25.94 31.90
[2,] 17.64 25.68 32.62 26.06 34.22 40.30
[3,] 20.74 29.80 37.50 29.48 36.96 43.26
[4,] 24.16 33.60 40.94 32.76 39.92 46.14
[5,] 33.88 44.80 52.94 42.74 47.10 54.40


Marc

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

2010-04-27 Thread Simon Kiss

Hello all,
I'm having difficulty getting one particular variable into R from SPSS  
v. 16.0 for mac.  R version is 2.10.1.  I saved the relevant variables  
from SPSS into a .csv file and then read them into R.  All the  
variables worked fine, except for one (enviro_spending). In the SPSS  
file it is correctly coded as a nominal variable and there is nothing  
that I can tell that distinguishes it from the others.


I have tried to include a good representation of reproduceable code  
below along with the results I am obtaining.


Yours, Simon

The variables are as follows:

educ =c("university", "university")
trade_off =c("*this cell is blank*", "disagree")
age=c(45,43)
gender_1=c("female", "female")
eviro_spending=c("Less/Same", "Less/Same")
carbon_tax_agg=c("agree", "disagree")
y=data.frame(educ, trade_off, age, gender_1, enviro_spending,  
carbon_tax_agg)


#The following are the original commands I used to read the .csv file  
into R.

y=read.csv(file.choose(), header=TRUE)

#When I do the following, all the variable names are correct

names(y)

#When I do the following, all the data in the dataframe are correct.
y

#But when I do the following, I get the following results
y$enviro_spending
#NULL
is.character(y$enviro_spending)
#FALSE
is.factor(y$enviro_spending)
#FALSE

#I tried to save the single problematic variable from my spss file to  
a .csv file as and then read that into R.

z=read.csv(file.choose(), header=TRUE)
#Just as before, calling the dataframe gives the data exactly as it  
should

z
#less/same
#more
#less/same
#more
#more

#But when I call the specific variable, I get #NULL
z$enviro_spending
#NULL
*
Simon J. Kiss, PhD
SSHRC and DAAD Post-Doctoral Fellow
John F. Kennedy Institute of North America Studies
Free University of Berlin
Lansstraße 7-9
14195 Berlin, Germany
Cell: +49 (0)1525-300-2812,
Web: http://www.jfki.fu-berlin.de/index.html

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


Re: [R] R for Engineering (Mechanical, Industrial , Civil, etc.)

2010-04-27 Thread Rob Goedman
Harsh,

Not in an educational setting, but I use R a lot in 1 branch of mechanical 
engineering: finite element method, as in Przemieniecki's recent book.

R prepares the input for multiple runs of a fortran based FEM routine and 
searches for an optimal solution (position of a bottom hole assembly in a 
deviated bore hole based on a set of constraints). The fortran routine in turn 
generates R source code/data which is then read in by R and used to formulate 
the input for the next run (set of FE iterations) and, once a 
converged/compliant solution is obtained, for graphing the results.

I started off with a version just in R but that turned out to be too slow and 
redid the FEM part in fortran (It should be said it was my 1st serious attempt 
to use S4 and I'm sure I could have improved the R-only performance, in a 
future version I will likely return an S4 class definition/object).

The ability to include fortran, C, etc., R's graphical capabilities, including 
3D, and R's capabilities/libraries (e.g. different interpolation models) to 
generate the input files based on survey data and revising the input during 
iterations were key for me.

Regards,
Rob

On Apr 25, 2010, at 2:53 PM, Harsh wrote:

> Hi useRs,
> In trying to take R to engineering undergraduate students, I have been
> looking for context that would make R more accessible to the said
> audience. Though R is primarily a statistical tool, I would want to
> demonstrate the use of R for certain engineering courses (Design of
> Machine Elements - gear design, ball bearings, etc.) which would
> generate interest in it and provide students a way to extend its use
> to more "statistically" oriented courses like Quality Control (control
> charts, t-tests, drawing normal probability plots, etc.).
> 
> For example: Engineering Design has a topic that requires the solving
> of a set of equations to arrive at the appropriate parameters of a
> feasible gear design (diameter, number of teeth, material
> specification etc.). This would require the set of equations and other
> information to be available in a package, with added functionality to
> plot machine elements, reliability curves for various materials (steel
> of different carbon compositions, and such) and other
> visualisations/computations that are required for such studies.
> 
> If any R user has employed R to teach engineering courses (which do
> not require much statistics), I would highly appreciate your feedback
> and insights gained from such an undertaking.
> I am not trying to dilute R's primary focus in being a statistical
> tool, but I would like to make R available to an audience who do not
> deal with a lot of statistics.
> 
> Of course, there are other tools for engineering drawing, circuitry
> design and such others, but maybe there is a niche area (somewhere in
> between core engineering and statistics) which is yet untapped, and R
> "might" be of help there.
> 
> Thank you.
> 
> Regards
> Harsh Singhal
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] ggplot2 - help with intervals in geom plot

2010-04-27 Thread hadley wickham
> The problem is that I want HCount and HProbCount to use custom
> gradients. i.e. a colour for 0-10, next shade for 10-30, next for 30-70
> etc.

Use cut to create factor with those levels, and then scale_fill_manual
to match values to colours.

> Due to some magic done on the data, one uses intervals 0,50,100,150 and
> the other 0,20,40 etc. - not important but I would be interested to know
> why. My plots are created by;

The breaks on the legend are just labels - it really is an underlying
smooth gradient.  If you want to ensure that the limits of the scale
are the same for both plots, use the limits argument.

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

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


Re: [R] Compilation error with maptools

2010-04-27 Thread Jean Eid


Uwe Dippel  uniten.edu.my> writes:

> 
> I had downloaded and installed a number of packages, successfully, when 
> I ran into some problem with maptools: It would eat up CPU and most of 
> all memory.
> I rebooted, and tried again, only running the terminal after the reboot; 
> with the same result:
> 
> " sp2WB text html latex example
> sp2tmap text html latex example
> spCbind-methods text html latex example
> Out of memory!
> ERROR: building help failed for package ‘maptools’
> * Removing ‘/usr/local/lib/R/site-library/maptools’
> 
> The downloaded packages are in
> ‘/tmp/RtmpG9Vj1D/downloaded_packages’
> Warning message:
> In install.packages("maptools") :
> installation of package 'maptools' had non-zero exit status"
> 
> I did install it then, using
> sudo apt-get install r-cran-maptools
> without problem; it also works.
> 
> (I am on Ubuntu Karmic; sp and Hmisc, however, install without any problem.)
> 
> My RAM is 4GB, my swap likewise.
> 
> Uwe
> 
> Uwe
> 
> 


I just run into this problem. The issue is with the help file for spRbind
particularly the code in the \note{...} I just took out the \enumerate and \item
commands so typeset the note without the "original formating" and it will
install fine. I do not know much of .Rd files but I know latex and I do not see
why latex would have issue with the original code. If you want to get maptools
working download it to your current directory 
download.packages("maptools", ".")
go to your surrent directory and untar the file 
tar xzf maptools... 
cd maptools/man
and replace the code of the note with  


\note{
In addition to the \code{spRbind}-methods, there are also 
\code{rbind}-methods for Spatial* objects. The differences are:


\code{spRbind}-methods can bind 2 objects, whereas \code{rbind}-methods 
 can bind multiple object


   some \code{rbind} can accept objects with duplicated IDs, for all 
 \code{spRbind}-methods these have to be modified explicitly, e.g. by 
 calling \code{\link[sp]{spChFIDs-methods}}
}



save the file and go back to your directory where you saved maptools (cd ../../)
and issue a 

R CMD INSTALL maptools 


This should install it without problems and you will not lose any information
from the help files,

Hope this helps

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


[R] Question according on new package installation test in R 2.11

2010-04-27 Thread Jochen Knaus

Hi all,

the package load test in R 2.11.0 is nice, but not disablable with 
function install.packages().


This is a problem for me, as I install many (>100) global packages with 
an R script as root in a multiuser environment for each new R version on 
the machines in our institute.


As root is not allowed to start several services, so several packages 
cannot be loaded correctly as root itself (e.g. "Rmpi" installs 
correctly, but cannot be loaded as root, as root is not allowed to start 
a cluster). This would not be dramatic if there would not been a 
"00LOCK" folder left in the site-dir afterwards preventing further 
packages to install and has to be removed manually.


On the command line the "R CMD INSTALL" script has an option 
"--no-test-load", which disables the feature of testing (but is using 
the internal function "tools:::.install_packages" for installing 
packages). It seems this behavior is not accessible through the function 
"install.packages", as this functions API didn't change and in the 
depending R source nothing is found.


Is there a way to disable the new load-test with an "install.packages" 
call or another way around the problem? Or a method which does at least 
not produce that 00LOCK file?


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


[R] Merging files

2010-04-27 Thread Alex Jameson
Hi, any one with experience in merging files

i have different files, some of the files, have the same fields, so i would
like to merge them

*File 1:*

field a,b,c,d,e,f

*File 2:*

field a, c, e, m, n

*merged file*

field a, c, e (ie only the common fields)


thanks


Alex

[[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] ggplot2 - help with intervals in geom plot

2010-04-27 Thread Dennis Gascoigne
Hi;

 

I have created a geom_tile plot which does roughly what I want but I
have a small tweak I cannot sort out.

 

I have a dataframe binL, binR, HCount, HProbCount where HCount and
HProbCount have values ranging from 1-150. I plot binL and binR on the
axes respectively and create two charts with the fill being represented
by HCount and HProbCount respectively.

 

The problem is that I want HCount and HProbCount to use custom
gradients. i.e. a colour for 0-10, next shade for 10-30, next for 30-70
etc.

 

Due to some magic done on the data, one uses intervals 0,50,100,150 and
the other 0,20,40 etc. - not important but I would be interested to know
why. My plots are created by;

ggplot(DiffMod,aes(binL,binR,fill=HProbCount)) + geom_tile() +
theme_bw() + scale_fill_gradient(low="white",high="red")

ggplot(DiffMod,aes(binL,binR,fill= HCount)) + geom_tile() + theme_bw() +
scale_fill_gradient(low="white",high="red")

 

I can get the intervals right in the legend using;

ggplot(DiffMod,aes(binL,binR,fill=HProbCount)) + geom_tile() +
theme_bw() +
scale_fill_gradient(low="white",high="red",breaks=c(0,50,100,150))

 

but this has no impact on the gradients used to colour the plots;

 

Cheers

Dennis

 

 


[[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] Cairo package failure to load backend

2010-04-27 Thread Daniel Alcock
Sorry,

It appears ,as usual, that I've been an idiot. Turns out you need to use
the Cairo command from the package cairoDevice instead of the package
Cairo, ie:

> Cairo_pdf(filename, width = 7, height = 7, pointsize = 10)

Which seems to work ok

Sorry for any time I wasted

Dan

Daniel Alcock
Malaria Genetics (T112)
Wellcome Trust Sanger Institute
Cambridge
CB10 1SA
UK
+44 (0)1223 834244 ext. 4994
"The most exciting phrase to hear in science, the one that heralds new
discoveries, is not Eureka! But rather, "hmm that's funny" --
Isaac Asimov


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Daniel Alcock
Sent: 27 April 2010 15:48
To: r-help@r-project.org
Subject: [R] Cairo package failure to load backend

Hi R friends,

I've been attempting to create plots with multiple alpha values using
Cairo to save them on a windows (32b XP) platform as it doesn't support
more than 3 alpha values. This worked well until I wanted a postscript
file (unsupported) and as a attempted work around I installed RGtk2. So
far so good, however now when I try to use a 

>CairoPDF("alpha.pdf", 6, 6, bg="transparent")
Or any
>Cairo()
Or
>CairoXXX(...)

Command I get (variations of):

>Error in Cairo(width, height, file, "pdf", pointsize = pointsize, bg =
bg,  : 
  Failed to create Cairo backend!

Can someone suggest a reason/solution please

Cheers

Dan

Daniel Alcock
Malaria Genetics (T112)
Wellcome Trust Sanger Institute
Cambridge
CB10 1SA
UK
+44 (0)1223 834244 ext. 4994
"The most exciting phrase to hear in science, the one that heralds new
discoveries, is not Eureka! But rather, "hmm that's funny" --
Isaac Asimov




-- 
 The Wellcome Trust Sanger Institute is operated by Genome Research 
 Limited, a charity registered in England with number 1021457 and a 
 company registered in England with number 2742969, whose registered 
 office is 215 Euston Road, London, NW1 2BE.

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


-- 
 The Wellcome Trust Sanger Institute is operated by Genome Research 
 Limited, a charity registered in England with number 1021457 and a 
 company registered in England with number 2742969, whose registered 
 office is 215 Euston Road, London, NW1 2BE.

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


Re: [R] sprintf() and return() oddity

2010-04-27 Thread Albert-Jan Roskam
Hi Jeremy,
 
Ok, that makes sense, thank you! Slightly more typing then, but still way more 
readable code than print(paste( )) or cat()

Cheers!!
Albert-Jan

~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a fresh water system, and public health, what have 
the Romans ever done for us?
~~

--- On Tue, 4/27/10, Raw, Jeremy, P.E.  wrote:


From: Raw, Jeremy, P.E. 
Subject: RE: [R] sprintf() and return() oddity
To: "Albert-Jan Roskam" , "R Mailing List" 

Date: Tuesday, April 27, 2010, 3:45 PM


It's not a bug.  It's the intended behavior.

Sprintf by itself returns a formatted character string and doesn't print 
anything.  Without the return statement, the function returns the string, which 
the interactive processor then prints (since that's what it does when you 
simply present it with an object).

To get the same behavior inside the function and still return the value 'a', 
just do this:

x <- function() { a <- 888
+ print(sprintf("xxx %s", a) )
+ return(a) }

That just makes explicit what the combination of function + interaction is 
doing implicitly.

Good luck!

-- 
Jeremy Raw, PE, AICP 
Senior Modeling Systems Analyst 
Virginia DOT, Transportation and Mobility Planning 
jeremy@vdot.virginia.gov / 804-786-0998

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Albert-Jan Roskam
Sent: Tuesday, April 27, 2010 09:29 AM
To: R Mailing List
Subject: [R] sprintf() and return() oddity

Hi,
 
If I use sprintf and return inside a function, sprintf doesn't print anything 
anymore. See the non-sense example below.
 
> x <- function() { a <- 888
+ sprintf("xxx %s", a) }
> x()
[1] "xxx 888"
> x <- function() { a <- 888
+ sprintf("xxx %s", a) 
+ return(a) }
> x()
[1] 888

Is this a bug?

Cheers!!
Albert-Jan

~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a fresh water system, and public health, what have 
the Romans ever done for us?
~~


      
    [[alternative HTML version deleted]]




  
[[alternative HTML version deleted]]

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


Re: [R] get means of elements of 5 matrices in a list

2010-04-27 Thread Marc Schwartz
On Apr 27, 2010, at 10:05 AM, David Freedman wrote:

> 
> I've got a list of 5 matrices that are each 5 x 6.  I'd like to end up with a
> 5 x 6 matrix that contains the mean value of the 5 original matrices.  I can
> do this by brute force, but there must be a better way than making each
> matrix into a vector and then remaking a matrix
> 
> thanks very much for any help
> david freedman
> 
> ll=list(structure(c(9.7, 17.6, 20.8, 24.1, 33.8, 14.5, 25.7, 29.8, 
> 33.6, 44.8, 21.8, 32.6, 37.5, 40.9, 53.3, 16.7, 26.1, 29.5, 32.7, 
> 42.6, 26.2, 34.3, 37, 39.8, 47.1, 31.9, 40.3, 43.3, 46.2, 54.1
> ), .Dim = 5:6), structure(c(9.4, 17.7, 20.7, 24.1, 33.7, 14.5, 
> 25.7, 29.8, 33.6, 44.8, 21.8, 32.7, 37.5, 40.9, 53.1, 16, 26, 
> 29.5, 32.7, 42.7, 25.6, 34.1, 37, 39.8, 47.1, 31.9, 40.3, 43.3, 
> 46.1, 54.1), .Dim = 5:6), structure(c(9.6, 17.7, 20.8, 24.4, 
> 34.3, 14.5, 25.7, 29.8, 33.6, 44.8, 21.8, 32.6, 37.5, 40.9, 53.2, 
> 16.7, 26.1, 29.5, 32.8, 42.8, 26.2, 34.2, 36.8, 39.9, 47.1, 31.9, 
> 40.3, 43.3, 46.1, 54.8), .Dim = 5:6), structure(c(9.7, 17.6, 
> 20.7, 24.1, 33.8, 14.5, 25.7, 29.8, 33.6, 44.8, 21.8, 32.6, 37.5, 
> 41.1, 52.6, 16.7, 26.1, 29.5, 32.8, 42.8, 26.1, 34.3, 37, 40, 
> 47.1, 31.9, 40.3, 43.3, 46.2, 54.9), .Dim = 5:6), structure(c(8.6, 
> 17.6, 20.7, 24.1, 33.8, 14.5, 25.6, 29.8, 33.6, 44.8, 21.8, 32.6, 
> 37.5, 40.9, 52.5, 16, 26, 29.4, 32.8, 42.8, 25.6, 34.2, 37, 40.1, 
> 47.1, 31.9, 40.3, 43.1, 46.1, 54.1), .Dim = 5:6))
> 
> ll
> x=rbind(as.vector(ll[[1]]),as.vector(ll[[2]]),as.vector(ll[[3]]),as.vector(ll[[4]]),as.vector(ll[[5]]));
> x
> x2=apply(x,2,mean); matrix(x2,byrow=F,nrow=5); 


How about:

> matrix(rowMeans(sapply(ll, unlist)), nrow = length(ll))
  [,1]  [,2]  [,3]  [,4]  [,5]  [,6]
[1,]  9.40 14.50 21.80 16.42 25.94 31.90
[2,] 17.64 25.68 32.62 26.06 34.22 40.30
[3,] 20.74 29.80 37.50 29.48 36.96 43.26
[4,] 24.16 33.60 40.94 32.76 39.92 46.14
[5,] 33.88 44.80 52.94 42.74 47.10 54.40


HTH,

Marc Schwartz

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


Re: [R] get means of elements of 5 matrices in a list

2010-04-27 Thread Jorge Ivan Velez
Hi David,

Here is a suggestion:

matrix(colMeans(do.call(rbind, lapply(ll, function(x) as.vector(x, nrow
= length(ll))

HTH,
Jorge


On Tue, Apr 27, 2010 at 11:05 AM, David Freedman <3.14da...@gmail.com>wrote:

>
> I've got a list of 5 matrices that are each 5 x 6.  I'd like to end up with
> a
> 5 x 6 matrix that contains the mean value of the 5 original matrices.  I
> can
> do this by brute force, but there must be a better way than making each
> matrix into a vector and then remaking a matrix
>
> thanks very much for any help
> david freedman
>
> ll=list(structure(c(9.7, 17.6, 20.8, 24.1, 33.8, 14.5, 25.7, 29.8,
> 33.6, 44.8, 21.8, 32.6, 37.5, 40.9, 53.3, 16.7, 26.1, 29.5, 32.7,
> 42.6, 26.2, 34.3, 37, 39.8, 47.1, 31.9, 40.3, 43.3, 46.2, 54.1
> ), .Dim = 5:6), structure(c(9.4, 17.7, 20.7, 24.1, 33.7, 14.5,
> 25.7, 29.8, 33.6, 44.8, 21.8, 32.7, 37.5, 40.9, 53.1, 16, 26,
> 29.5, 32.7, 42.7, 25.6, 34.1, 37, 39.8, 47.1, 31.9, 40.3, 43.3,
> 46.1, 54.1), .Dim = 5:6), structure(c(9.6, 17.7, 20.8, 24.4,
> 34.3, 14.5, 25.7, 29.8, 33.6, 44.8, 21.8, 32.6, 37.5, 40.9, 53.2,
> 16.7, 26.1, 29.5, 32.8, 42.8, 26.2, 34.2, 36.8, 39.9, 47.1, 31.9,
> 40.3, 43.3, 46.1, 54.8), .Dim = 5:6), structure(c(9.7, 17.6,
> 20.7, 24.1, 33.8, 14.5, 25.7, 29.8, 33.6, 44.8, 21.8, 32.6, 37.5,
> 41.1, 52.6, 16.7, 26.1, 29.5, 32.8, 42.8, 26.1, 34.3, 37, 40,
> 47.1, 31.9, 40.3, 43.3, 46.2, 54.9), .Dim = 5:6), structure(c(8.6,
> 17.6, 20.7, 24.1, 33.8, 14.5, 25.6, 29.8, 33.6, 44.8, 21.8, 32.6,
> 37.5, 40.9, 52.5, 16, 26, 29.4, 32.8, 42.8, 25.6, 34.2, 37, 40.1,
> 47.1, 31.9, 40.3, 43.1, 46.1, 54.1), .Dim = 5:6))
>
> ll
>
> x=rbind(as.vector(ll[[1]]),as.vector(ll[[2]]),as.vector(ll[[3]]),as.vector(ll[[4]]),as.vector(ll[[5]]));
> x
> x2=apply(x,2,mean); matrix(x2,byrow=F,nrow=5);
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/get-means-of-elements-of-5-matrices-in-a-list-tp2067722p2067722.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] suggestion on method dispatch

2010-04-27 Thread Gabor Grothendieck
Define fn.default as a synonym to fn.foo1 (or just rename fn.foo1 as
fn.default) and then use NextMethod as shown:

fn <- function(x,...) UseMethod("fn")

fn.default <-
fn.foo1 <- function(x, commonA=1, ...) {
print("fn.foo1 is called.")
}

fn.foo2 <- function(x, uniqueFoo2, common=1, ...){
NextMethod("fn", x = uniqueFoo2)
}

y <-  "y"; class(y) <- "foo2"
fn(x=y, "unique argument")

On Tue, Apr 27, 2010 at 10:40 AM, Wincent  wrote:
> Dear all, I have define a function  and its methods as follows:
>
>  beginning of code
> fn <- function(x,...){
> UseMethod("fn")
> }
>
> fn.foo1 <- function(x, commonA=1, ...){
> print("fn.foo1 is called.")
> }
>
> fn.foo2 <- function(x, uniqueFoo2, common=1, ...){
> ## uniqueFoo2 is a unique argument in fn.foo2
> x <- uniqueFoo2; class(x) <- "foo1"
> ## use uniqueFoo2 to generate a object of class foo1
> dots <- list(...)
> do.call(fn.foo1, c(list(x=x,common=common),dots)
> ## pass x, commonA and other arguments from ... to fn.foo1
> }
>
> y <-  "y"; class(y) <- "foo2"
> fn(x=y, "unique argument")
>
>  end of code
>
> They works as expected. I call fn.foo1 because I don't want to
> duplicate the same piece of code.
> Yet, I wonder if here is any official way to do the same thing without
> directly call fn.foo1 via do.call.
> To directly call a method is not a good coding style, right?
>
> Thanks very much for your suggestion in advance.
>
> --
> Wincent Rong-gui HUANG
> Doctoral Candidate
> Dept of Public and Social Administration
> City University of Hong Kong
> http://asrr.r-forge.r-project.org/rghuang.html
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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

2010-04-27 Thread Tengfei Yin
Hi dear all

I am currently using Ubuntu 9.10 (karmic) and R 2.10, I can find a R release
that support "karmic" in cran under ubuntu directory, I plan to update my
laptop to Ubuntu 10.04 after April 30, since I have to use some new features
or new version in it, e.g. QT 4.6,  I don't know if there is going to be a R
release that will support this newly released Ubuntu?

Thanks

Best wishes

Tengfei

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

[[alternative HTML version deleted]]

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


[R] get means of elements of 5 matrices in a list

2010-04-27 Thread David Freedman

I've got a list of 5 matrices that are each 5 x 6.  I'd like to end up with a
5 x 6 matrix that contains the mean value of the 5 original matrices.  I can
do this by brute force, but there must be a better way than making each
matrix into a vector and then remaking a matrix

thanks very much for any help
david freedman

ll=list(structure(c(9.7, 17.6, 20.8, 24.1, 33.8, 14.5, 25.7, 29.8, 
33.6, 44.8, 21.8, 32.6, 37.5, 40.9, 53.3, 16.7, 26.1, 29.5, 32.7, 
42.6, 26.2, 34.3, 37, 39.8, 47.1, 31.9, 40.3, 43.3, 46.2, 54.1
), .Dim = 5:6), structure(c(9.4, 17.7, 20.7, 24.1, 33.7, 14.5, 
25.7, 29.8, 33.6, 44.8, 21.8, 32.7, 37.5, 40.9, 53.1, 16, 26, 
29.5, 32.7, 42.7, 25.6, 34.1, 37, 39.8, 47.1, 31.9, 40.3, 43.3, 
46.1, 54.1), .Dim = 5:6), structure(c(9.6, 17.7, 20.8, 24.4, 
34.3, 14.5, 25.7, 29.8, 33.6, 44.8, 21.8, 32.6, 37.5, 40.9, 53.2, 
16.7, 26.1, 29.5, 32.8, 42.8, 26.2, 34.2, 36.8, 39.9, 47.1, 31.9, 
40.3, 43.3, 46.1, 54.8), .Dim = 5:6), structure(c(9.7, 17.6, 
20.7, 24.1, 33.8, 14.5, 25.7, 29.8, 33.6, 44.8, 21.8, 32.6, 37.5, 
41.1, 52.6, 16.7, 26.1, 29.5, 32.8, 42.8, 26.1, 34.3, 37, 40, 
47.1, 31.9, 40.3, 43.3, 46.2, 54.9), .Dim = 5:6), structure(c(8.6, 
17.6, 20.7, 24.1, 33.8, 14.5, 25.6, 29.8, 33.6, 44.8, 21.8, 32.6, 
37.5, 40.9, 52.5, 16, 26, 29.4, 32.8, 42.8, 25.6, 34.2, 37, 40.1, 
47.1, 31.9, 40.3, 43.1, 46.1, 54.1), .Dim = 5:6))

ll
x=rbind(as.vector(ll[[1]]),as.vector(ll[[2]]),as.vector(ll[[3]]),as.vector(ll[[4]]),as.vector(ll[[5]]));
x
x2=apply(x,2,mean); matrix(x2,byrow=F,nrow=5); 

-- 
View this message in context: 
http://r.789695.n4.nabble.com/get-means-of-elements-of-5-matrices-in-a-list-tp2067722p2067722.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] Tapply.

2010-04-27 Thread steven mosher
Thanks,

 I had been wondering what Drop did. That makes it more clear.

While I have code that loops and does the problem correctly, I wanted to
do things the R way and be fast and terse. hehe.

So:
ID   dy  jan  ...
11264402000 1 1987  NA  NA  NA  NA  NA 218  NA  NA 235 243 240  NA
 11264402000 3 1987  NA  NA  NA  NA  NA 218  NA  NA 235 243 240  NA

in words : for each id, for each year return
 the max of jan,feb,.over d
 the min of jan, feb  over d
 the mean of jan,feb.. over d
 the (max+min)/2 of jan, feb...over d
 the count of d for jan.feb..
 the results of a function called with all elements of this id

Anyway, your kind attention has been greatly appreciated.






On Tue, Apr 27, 2010 at 2:40 AM, Petr PIKAL  wrote:

> Hi
> r-help-boun...@r-project.org napsal dne 26.04.2010 17:05:54:
>
> > I guess my problem was seeing a bunch of examples where they pulled a
> > variable from a dataframe..
> >
> >   tapply(df$data, index=list(..
>
> df$data results in vector so as eg. df[,5] unless you use drop=FALSE
> option
>
> >
> > and I
> > assumed that the df$data was just generalizable to a collection of
> vectors
> > a vector of vector being a vector
>
> df[,1:15] is not a vector of vectors. R sometimes can give you nasty
> surprise with object types and modes but changing a type of object merely
> by selecting some part of it wold be quite problematic.
>
> see
>
> str(df$data)
> str(df[, 1])
> str(df[,1, drop=FALSE])
> str(df[,1:15])
>
> Regards
> Petr
>
>
>
> >
> > Thanks.
> >
> > On Mon, Apr 26, 2010 at 2:43 AM, Petr PIKAL 
> wrote:
> >
> > > Hi
> > >
> > >
> > > steven mosher  napsal dne 26.04.2010 10:21:37:
> > >
> > > > That fails:
> > > >
> > > > The manual says:
> > > >
> > > > tapply(X, INDEX, FUN = NULL, ..., simplify = TRUE)
> > >
> > > > Arguments
> > > >
> > > > X
> > > >
> > > > an atomic object, typically a vector.
> > > >
> > > > INDEX
> > > >
> > > > list of factors, each of same length as X. The elements are coerced
> to
> > > factors by
> > > > as.factor.
> > > >
> > > > my error says:
> > >
> > > >
> > > > Error in tapply(DF[, 1:15], DF$Year, mean, na.rm = T) :
> > > >
> > > >   arguments must have same length
> > > >
> > > > The issue that I have is I dont understand what the requirements for
> the
> > > list of factors
> > > > are. In my example DF$Years is  a sequence of
> > > years..1979,1980,1982,1983, 1987..
> > > > like that with missing years: so when the manual say: list of
> factors
> > > each the same
> > > > length as X? what does that mean? I could have a DF with 20 rows and
> > > only two
> > > > different years. or 20 rows and 20 different years.
> > > >
> > > > Suppose:
> > > >
> > > > a<- c(1,2,3,4)
> > > > > b<-c(2,3,4,5)
> > > > > df=data.frame(a,b)
> > > > > length(df)
> > >
> > > data frame is not vector nor atomic but list hence length(df) gives
> you
> > > number of columns. It is similar to length of a list
> > >
> > > > lll<-list(a=1, b=2, c=3)
> > > > length(lll)
> > > [1] 3
> > > >
> > >
> > > If you accept that the first argument of tapply has to be vector you
> can
> > > not put data frame there.
> > >
> > > Next second argument has to be list of factors so you can put there
> > > several factors, each of the same length as first argument (a vector).
> > >
> > > If you want to perform aggregating operation on whole data frame you
> shall
> > > consider
> > >
> > > ?by or ?aggregate
> > >
> > > Other options are plyr or doBy packages.
> > >
> > > Syntax for aggregate is quite similar to tapply, only first argument
> can
> > > be data frame.
> > >
> > > Regards
> > > Petr
> > >
> > >
> > > >
> > > > The length of DF is 2.
> > > > Does that mean the "list of factors, each of same length as X."
> would
> > > have to be
> > > > 2? that doesnt seem to make sense.
> > > >
> > > >
> > > >
> > > > On Mon, Apr 26, 2010 at 12:26 AM, Petr PIKAL
> 
> > > wrote:
> > > > Hi
> > > >
> > > > r-help-boun...@r-project.org napsal dne 26.04.2010 06:52:55:
> > > >
> > > > > Having some difficulties with understanding how tapply works and
> > > getting
> > > > > return values I expect
> > > > >
> > > > > Data: dataframe. DF  DF$Id $D $Year...
> > > > >
> > > > >  Id  D  Year Jan Feb Mar Apr May Jun Jul
> Aug
> > > Sep
> > > > Oct
> > > > > Nov Dec
> > > > >  11264402000 1 1980  NA  NA  NA  NA  NA 212 203 209 228
> 237
> > >  NA
> > > > NA
> > > > >  11264402000 0 1981  NA  NA 243 244  NA  NA  NA  NA 225 NA
> > > 231
> > > > NA
> > > > >  11264402000 1 1981  NA 251  NA 248 241  NA  NA  NA 235 NA
> > >  NA
> > > > 245
> > > > >  11264402000 0 1982 236 237 242 240 242 205 199  NA  NA NA
> > >  NA
> > > > NA
> > > > >  11264402000 1 1982 236  NA  NA 240 242  NA  NA  NA  NA NA
> > >  NA
> > > > NA
> > > > >  11264402000 0 1983  NA 247  NA  NA  NA  NA  NA 205  NA NA
> > >  NA
> > > > NA
> > > > >  11264402000 1 1983  NA 247  N

  1   2   >