Re: [R] plot() point names ?

2009-10-13 Thread Daniel Malter
I think you are looking for this:

x=rnorm(6,10,1)
e=rnorm(6,0,1)
y=x+e

plot(y~x,xlim=c(min(x)-2,max(x)+2),ylim=c(min(y)-2,max(y)+2))
text(x,y,pos=1,labels=c(Prof,CEO,Janitor,Admin,Farmer,Fire
Chief))

HTH,
Daniel 


-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im
Auftrag von Robert U
Gesendet: Tuesday, October 13, 2009 1:15 AM
An: r-help@r-project.org
Betreff: [R] plot()  point names ?

Dear R-users,

I am using the simple plot() function and i cannot find a way to add the
point label (i would like to plot the points and up to each point the point
name). I found a way to do it with n.plot but then the point is not plotted,
only the label. Do you know if there is a parameter for the plot() function
that would allow me to specify point names ? (and even more ideally, another
parameter to specify the point label size...)

with regards !

P.P.




  
[[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] How to read plain text documents into a vector?

2009-10-13 Thread Dieter Menne



Richard Liu wrote:
 
 I'm new to R.  I'm working with the text mining package tm.  I have
 several plain text documents in a directory, and I would like to read all
 the files with extension .txt in that directory into a vector, one text
 document per vector element.  That is, v[1] would be the first document,
 v[2] the second, etc.
 
 I know how to read the documents into a tm Corpus, but that's not what I
 want to do.  I would think that this kind of operation should be
 elementary and the first step in any text mining.
 

Reading in a non-structured file is not that common in R, so tm provides
special methods. There is a vignette tm.pdf coming with tm that explains it
on the first page.

Dieter


-- 
View this message in context: 
http://www.nabble.com/How-to-read-plain-text-documents-into-a-vector--tp25867792p25867914.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] crosstabulation and unlist function

2009-10-13 Thread eugen pircalabelu
Thank you! This is what i needed!
I did not realize i could replicate my factor and then tabulate, but it makes 
sense!
Thank you once again!
  

 




- Original Message 
From: William Dunlap wdun...@tibco.com
To: eugen pircalabelu eugen_pircalab...@yahoo.com; r-help@r-project.org
Sent: Mon, October 12, 2009 10:48:36 PM
Subject: RE: [R] crosstabulation and unlist function

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of eugen pircalabelu
 Sent: Monday, October 12, 2009 1:06 PM
 To: David Winsemius
 Cc: R-help
 Subject: Re: [R] crosstabulation and unlist function
 
 Hello,
 First of all, thank you David for your reply, but sadly this 
 is not what i wanted (i am sorry for not being more specific 
 about my problem!)

  aa-c(1:5)
  bb-c(NA,2,NA,4,5)
  cc-c(1,2,NA,4,NA)
  dd-c(A,B,B,A,C)

You forget to say how you made 'df', which I assume is
   df - data.frame(aa,bb,cc,dd)
Having a self-contained way to reproduce your problem
makes much easier to solve!

  table(unlist(df[,1:3]))
 
  df
   aa bb cc dd
 1  1 NA  1  A
 2  2  2  2  B
 3  3 NA NA  B
 4  4  4  4  A
 5  5  5 NA  C
 
 I do not want to get this:
  tapply(apply(df[,1:3],1,sum, na.rm=TRUE), df$dd, sum)
 A  B  C
 14  6 10
 
 but a crosstabulation between  table(unlist(df[,1:3])) and 
 df$dd, which should look something like this:
 
 1   2   3   4  5
 A  2   0   0   3  0
 B  0   3   1   0  0
 C  0   0   0   0  2

Try

 with(df, table(rep(dd,3), c(aa,bb,cc)))

1 2 3 4 5
  A 2 0 0 3 0
  B 0 3 1 0 0
  C 0 0 0 0 2
or
 table(rep(df$dd, 3), unlist(df[,1:3]))

1 2 3 4 5
  A 2 0 0 3 0
  B 0 3 1 0 0
  C 0 0 0 0 2

You need the rep() to show how the 5 elements of dd
should correspond to the 15 elements of aa, bb, and cc.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

 
 meaning that when dd is A 1 appears 2 times, 2 doesn't 
 appear, 3 doesn't appear, 4 appears 3times, 5 doesn't appear; 
 when dd is C only 5 appears 2 times (i am not really 
 interested in the NA occurence).
 Hopefully, this time my question was a lot more clear.
 Thank you very much !
 
  
 
  
 
 
 
 
 - Original Message 
 From: David Winsemius dwinsem...@comcast.net
 To: David Winsemius dwinsem...@comcast.net
 Cc: eugen pircalabelu eugen_pircalab...@yahoo.com; R-help 
 r-h...@stat.math.ethz.ch
 Sent: Mon, October 12, 2009 9:36:39 PM
 Subject: Re: [R] crosstabulation and unlist function
 
 
 On Oct 12, 2009, at 3:25 PM, David Winsemius wrote:
 
  
  On Oct 12, 2009, at 2:36 PM, eugen pircalabelu wrote:
  
  Hello R-users,
  
  My toy example:
  aa-c(1:5)
  bb-c(NA,2,NA,4,5)
  cc-c(1,2,NA,4,NA)
  dd-c(A,B,B,A,C)
  df-data.frame(aa,bb,cc,dd=as.factor(dd))
  table(unlist(df[,1:3]))
  
  Can anyone point me to what function let's me do a 
 crosstabulation between   table(unlist(df[,1:3])) and df$dd?
  I want to find out when dd==A (or B, or C) how many times 
 do the values 1, 2 ,3,..  appear in df[,1:3]?
  Thank you very much!
  
  One way would be to collect the row sums of those columns 
 first, and then sum by index:
  
  tapply(apply(df[,1:3],1,sum, na.rm=TRUE), df$dd, sum)
  A  B  C
  14  9 10
 
 This method is safer than working on table(unlist(df[, 1:3]) 
 since it does not break when an entire row is empty.
 
  aa-c(1,2,NA,4,5)
  bb-c(NA,2,NA,4,5)
  cc-c(1,2,NA,4,NA)
  dd-c(A,B,B,A,C)
  df-data.frame(aa,bb,cc,dd=as.factor(dd))
  table(unlist(df[,1:3]))
 
 1 2 4 5
 2 3 3 2 # missing row willno longer be aligned with dd.
  tapply(table(unlist(df[,1:3])), df$dd, sum)
 Error in tapply(table(unlist(df[, 1:3])), df$dd, sum) :
   arguments must have same length
 
  tapply(apply(df[,1:3],1,sum, na.rm=TRUE), df$dd, sum)
 A  B  C
 14  6 10
 
 
  
  --
  David Winsemius, MD
  Heritage Laboratories
  West Hartford, CT
  
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


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


[R] Creating object referant from argument name

2009-10-13 Thread showa

Hi all. I'd like to define an object within a function based on an argument
to that function.
Specifically, I've got:

do.something-function(input){
id-substring(input,3,3)
j-list1
if(id==2)j-list2
if(id==3)j-list3
if(id==4)j-list4
...}

Instead of all these if() arguments, I was hoping to use something like:
j-paste(list,substring(input,3,3),sep=)
but this just assigns j the value of listx of _character_ mode, instead of
the actual object 'listx'.
Is there any way to get around this?
Thanks.
-- 
View this message in context: 
http://www.nabble.com/Creating-object-referant-from-argument-name-tp25861902p25861902.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] How to read plain text documents into a vector?

2009-10-13 Thread Richard Liu

I'm new to R.  I'm working with the text mining package tm.  I have several
plain text documents in a directory, and I would like to read all the files
with extension .txt in that directory into a vector, one text document per
vector element.  That is, v[1] would be the first document, v[2] the second,
etc.

I know how to read the documents into a tm Corpus, but that's not what I
want to do.  I would think that this kind of operation should be elementary
and the first step in any text mining.

Thanks,
Richard
-- 
View this message in context: 
http://www.nabble.com/How-to-read-plain-text-documents-into-a-vector--tp25867792p25867792.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] stochastic process

2009-10-13 Thread 刘哲
Hi,
 
I'm a student in China, and I never used R before.
 
I'm now wondering how to simulate a sample of Markov chain of ,say 500 
entries with a certain transition matrix. 
 
Thanks a lot.


  ___ 
  好玩贺卡等你发,邮箱贺卡全新上线! 
http://card.mail.cn.yahoo.com/
[[alternative HTML version deleted]]

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


Re: [R] Function to find prime numbers

2009-10-13 Thread Romain Francois

On 10/13/2009 09:59 AM, AJ83 wrote:



I need to create a function to find all the prime numbers in an array. Can
anyone point me in the right direction?
Thank you.
AJ


There is isprime in package gmp.

 data.frame( number = 1:10, is.prime = isprime( 1:10 )  1, 
is.probably.prime = isprime(1:10)  0 )

   number is.prime is.probably.prime
1   1FALSE FALSE
2   2 TRUE  TRUE
3   3 TRUE  TRUE
4   4FALSE FALSE
5   5 TRUE  TRUE
6   6FALSE FALSE
7   7 TRUE  TRUE
8   8FALSE FALSE
9   9FALSE FALSE
10 10FALSE FALSE

See this: http://jostamon.blogspot.com/2009/02/goldbachs-comet.html for 
an example of its use.


Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/BcPw : celebrating R commit #5
|- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc
`- http://tr.im/yw8E : New R package : sos

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


Re: [R] Function to find prime numbers

2009-10-13 Thread Gustaf Rydevik
library(gmp)
?isprime


/Gustaf



On Tue, Oct 13, 2009 at 9:59 AM, AJ83 aljense...@gmail.com wrote:


 I need to create a function to find all the prime numbers in an array. Can
 anyone point me in the right direction?
 Thank you.
 AJ
 --
 View this message in context:
 http://www.nabble.com/Function-to-find-prime-numbers-tp25868633p25868633.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.




-- 
Gustaf Rydevik, M.Sci.
tel: +46(0)703 051 451
address:Essingetorget 40,112 66 Stockholm, SE
skype:gustaf_rydevik

[[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] Use R -- term and logo copyright?

2009-10-13 Thread Achim Zeileis

Marianne:


I would like to start some R workshops at King's College London, and
to do so, I would like to use the Use R! logo at
http://www.agrocampus-ouest.fr/math/useR-2009//useR%21%202008_fichiers/useR-middle.png

Since it seems to be difficult to get a shell account at KCL, I also went
ahead and registered use-r.org.uk and am starting to put together a
website at kcl.use-r.org.uk.

I really like the Use R! slogan, which seems to be used by the R
user conferences and Springer (the latter without the exclamation
mark).


The conference is called useR! and Springer decided to call their series 
Use R! (with exclamation mark) after asking us for permission.



Even more, I really *really* like Use R! logo.  I think it is very
elegant indeed! Kudos to whoever designed it.

However, I'm completely in the dark about copyright issues of the logo
and the slogan.

Can I use (a) the logo and/or (b) the slogan for the KCL R workshops?
I think it is quite clear from my website that this is neither about
the Springer book series nor about an R user conference.


No, sorry, the logo/name should be used exclusively for the Springer 
series and the R User Conferences. For the latter see

  http://www.R-project.org/conferences.html

Hence, the logo of your workshop and preferably also its URL should be 
different. You may use R in the title though and have the usual R logo 
on the workshop page.


Best regards,
Z


I enquired with the agrocampus-ouest.fr website about the logo but was
pointed to r-project.org and the R development core team. I thought in
that case it might be best to ask here to have the answer publicly
available -- sorry if I overlooked the information online somewhere.

Marianne

--
Marianne Promberger PhD, King's College London
http://promberger.info
R version 2.9.2 (2009-08-24)
Ubuntu 9.04

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] How to read plain text documents into a vector?

2009-10-13 Thread Paul Hiemstra

Richard Liu wrote:

I'm new to R.  I'm working with the text mining package tm.  I have several
plain text documents in a directory, and I would like to read all the files
with extension .txt in that directory into a vector, one text document per
vector element.  That is, v[1] would be the first document, v[2] the second,
etc.

I know how to read the documents into a tm Corpus, but that's not what I
want to do.  I would think that this kind of operation should be elementary
and the first step in any text mining.

Thanks,
Richard
  

Hi Richard,

Try somthing along these lines:

file_list = list.files(/where/are/the/files)
obj_list = lapply(file_list, FUN = yourfunction)

yourfunction is probably either read.table or some read function from 
the tm package. So obj_list will become a list of either data.frame's or 
tm objects.


cheers,
Paul

--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 274 3113 Mon-Tue
Phone:  +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul

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


Re: [R] is that possible to graph 4 dimention plot

2009-10-13 Thread Petr PIKAL
Hi

I tried to do similar thing and did get great answer from Alberto Monteiro

http://tolstoy.newcastle.edu.au/R/e4/help/08/01/0682.html 

However I finally managed to do it by slicing space by combination of 
image and contour together with putting numbers on contour. Then I used 
scizors and glue to put everything into 3 dimensions with colour and 
numbers indicating tha values.

Regards
Petr

r-help-boun...@r-project.org napsal dne 12.10.2009 14:40:29:

 I'm basically put off by the question itself. Plotting a 4-dimensional
 graph is rather complicated if the world has only 3 dimensions. A
 4-dimensional representation is typically a movie (with time as the
 4th dimension). You could try to project a heatmap on a 3D surface
 graph, but I doubt this will make things much more clear.
 
 So the standard (and correct) way of solving this problem, is to think
 about a clever way to represent the needed information in less
 dimensions. Ryan gives some nice examples and tips of how to do that,
 but those are dismissed as not helpful.
 
 People on the list answer voluntarily. They do not like to be told
 that you don't think it will really help. Did you actually try it
 out? You certainly don't give that impression. Maybe you should have
 another look at it, and question your own approach to the problem as
 well.
 
 Keep it in mind for next time, you're not making yourself popular this 
way.
 
 Kind regards
 Joris
 
 
 
 On Sat, Oct 10, 2009 at 10:01 PM, Duncan Murdoch murd...@stats.uwo.ca 
wrote:
  On 07/10/2009 5:50 PM, gcheer3 wrote:
 
  Thanks for your reply.
 
  But I don't think it will really help. My problem is as follows:
 
  I have 20 observations
  y - rnorm(N,mean= rep(th[1:2],N/2),sd=th[3])
 
  I have a loglikelihood function for 3 variables mu-(mu1,mu2) and sig
 loglike - function(mu,sig){
 temp-rep(0,length(y))
 for (i in 1:(length(y)))
 {
 
  
temp[i]-log((1/2)*dnorm(y[i],mu[1],sig)+(1/2)*dnorm(y[i],mu[2],sig))}
 return(sum(temp))
  }
 
  for example
 
  mu-c(1,1.5)
  sig-2
  loglike(mu,sig)
 
  [1] -34.1811
 
  I am interested how mu[1], mu[2], and sig changes, will effect the
  loglikelihood surface. At what values of mu and sig will make
  loglikelihood
  the maximum and at what values of mu and sig will make loglikelihood 
has
  local max (smaller hills) and at what values of mu and sig the
  loglikelihood
  is flat , etc.
  I tried contour3d also, seems doesn't work
 
  I haven't seen any replies to this.  One explanation would be that 
everyone
  was turned off (as I was) by the rude remark above.
 
  On this list, before saying that something doesn't work, it's polite 
to
  give a simple, nicely formatted, self-contained reproducible example 
of what
  went wrong, and to ask whether it is your error or an error in the 
package.
   Taking that approach will usually result in someone pointing out your 
error
  (and fixing your code); sometimes it will result in a package author
  agreeing it's a bug, and fixing it.
 
  Duncan Murdoch
 
 
  Thanks for any advice
 
 
  Ryan-50 wrote:
 
  Suppose there are 4 variables
  d is a function of a , b and c
  I want to know how a, b and c change will make d change
  It will be straightforward to see it if we can graph the d surface
 
  if d is only a function of a and b, I can use 'persp' to see the 
surface
  of
  d. I can easily see at what values of a and b, d will get the 
maxium or
  minium or multiple modes, etc
 
  But for 4 dimention graph, is there a way to show the surface of d
  Will use color help
 
  Thanks a lot
 
  Not sure what your data looks like, but you might also consider 
looking
  at a 2 dimensional version.  See ?coplot
  for example:
 
  coplot(lat ~ long | depth * mag, data = quakes)
 
  Or you can make 2 or 3-dimensional plots using the lattice package
  conditioning on some of the variables - e.g. d ~ a | b * c,
  etc.
  If a, b, and c are continuous, you can use equal.count.  Here is
  an uninteresting example, considering a, b, and c as points along
  a grid:
 
  a - b - c - seq(1:10)
  dat - data.frame(expand.grid(a, b, c))
  names(dat) - letters[1:3]
 
  dat$d - with(dat, -(a-5)^2 - (b-5)^2 - (c-5)^2)
 
  library(lattice)
  # 2-d:
  xyplot(d ~ a | equal.count(b)*equal.count(c), data=dat, type=l)
  # etc.
 
  # 3-d:
  contourplot(d ~ a * b | equal.count(c), data=dat)
  wireframe(d ~ a * b | equal.count(c), data=dat)
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/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, 

Re: [R] Lattice barchart-reordered

2009-10-13 Thread Dieter Menne



Veerappa Chetty wrote:
 
 Hi,Can I use reorder function with barchart as in dotchart? Here are
 some
 codes which do not work for  me.
 .. example remove
 

As your example is not self-contained (it should be), I cannot show it with
your data.
My preferred way is to reorder outside, because it enforces consistency when
I do several plots.

Dieter

library(lattice)
barchart(yield ~ variety | site, data = barley,
 groups = year, layout = c(1,6),
 ylab = Barley Yield (bushels/acre),
 scales = list(x = list(abbreviate = TRUE,
   minlength = 5)))
   
levels(barley$site) = c( Waseca,Grand Rapids,Duluth,University
Farm,Morris ,
  Crookston  )
  
barchart(yield ~ variety | site, data = barley,
 groups = year, layout = c(1,6),
 ylab = Barley Yield (bushels/acre),
 scales = list(x = list(abbreviate = TRUE,
   minlength = 5)))
   

-- 
View this message in context: 
http://www.nabble.com/Lattice-barchart-reordered-tp25865201p25867980.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] Function to find prime numbers

2009-10-13 Thread AJ83

I need to create a function to find all the prime numbers in an array. Can
anyone point me in the right direction? 
Thank you.
AJ
-- 
View this message in context: 
http://www.nabble.com/Function-to-find-prime-numbers-tp25868633p25868633.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] svy / weighted regression

2009-10-13 Thread Laust
Dear David,

Thanks again for your input! I realize that I did a bad job of
explaining this in my first email, but the setup is that in Finland
persons who die are sampled with a different probability (1) from
those who live (.5). This was done by the Finnish data protection
authorities to protect individuals against identification. In the rest
of the countries everyone is sampled with a probability of 1. The data
that I am supplying to R is summarized data for each country
stratified by case status. Another way of organizing the data would
be:

# creating data
listc - c(Denmark,Finland,Norway,Sweden)
listw - c(1,2,1,1)
listd - c(1000,1000,1000,2000)
listt - c(755000,505000,905000,191)
list.cwdt - c(listc, listw, listd, listt)
country2 - data.frame(country=listc,weight=listw,deaths=listd,time=listt)

I hope that it is clearer now that for no value of the independent
variable 'country' is the rate going to be zero. I think this was also
not the case in my original example, but this was obscured by my poor
communication-  R-skills. But if data is organized this way then
sampling weight of 2 for Finland should only be applied to the
time-variable that contains person years at risk and *not* to the
number of deaths, which would complicate matters further. I would know
how to get this to work in R or in any other statistical package.
Perhaps it is - as Peter Dalgaard suggested - the estimation of the
dispersion parameter by the survey package that is causing trouble,
not the data example eo ipso. Or perhaps I am just using survey in a
wrong way.

Best
Laust


Post doc. Laust Mortensen, PhD
Epidemiology Unit
University of Southern Denmark

On Mon, Oct 12, 2009 at 3:32 PM, David Winsemius dwinsem...@comcast.net wrote:
 I think you are missing the point. You have 4 zero death counts associated
 with much higher person years of exposure followed by 4 death counts in the
 thousands associated with lower degrees of exposures. It seems unlikely that
 these are real data as there are not cohorts that would exhibit such lower
 death-rates. So it appears that in setting up your test case, you have
 created an impossibly unrealistic test problem.

 --
 David


 On Oct 12, 2009, at 9:12 AM, Laust wrote:

 Dear Peter,

 Thanks for the input. The zero rates in some strata occurs because
 sampling depended on case status: In Finland only 50% of the non-cases
 were sampled, while all others were sampled with 100% probability.

 Best
 Laust

 On Sat, Oct 10, 2009 at 11:02 AM, Peter Dalgaard
 p.dalga...@biostat.ku.dk wrote:

 Sorry, forgot to reply all...

 Laust wrote:

 Dear list,

 I am trying to set up a propensity-weighted regression using the
 survey package. Most of my population is sampled with a sampling
 probability of one (that is, I have the full population). However, for
 a subset of the data I have only a 50% sample of the full population.
 In previous work on the data, I analyzed these data using SAS and
 STATA. In those packages I used a propensity weight of 1/[sampling
 probability] in various generalized linear regression-procedures, but
 I am having trouble setting this up. I bet the solution is simple, but
 I’m a R newbie. Code to illustrate my problem below.

 Hi Laust,

 You probably need the package author to explain fully, but as far as I
 can see, the crux is that a dispersion parameter is being used, based on
 Pearson residuals, even in the Poisson case (i.e. you effectively get
 the same result as with quasipoisson()).

 I don't know what the rationale is for this, but it is clear that with
 your data, an estimated dispersion parameter is going to be large. E.g.
 the data has both 0 cases in 75 person-years and 1000 cases in 5000
 person-years for Denmark, and in your model they are supposed to have
 the same Poisson rate.

 summary.svyglm starts off with

   est.disp - TRUE

 and AFAICS there is no way it can get set to FALSE.  Knowing Thomas,
 there is probably a perfectly good reason not to just set the dispersion
 to 1, but I don't get it either...


 Thanks
 Laust

 # loading survey
 library(survey)

 # creating data
 listc -

 c(Denmark,Finland,Norway,Sweden,Denmark,Finland,Norway,Sweden)
 listw - c(1,2,1,1,1,1,1,1)
 listd - c(0,0,0,0,1000,1000,1000,2000)
 listt - c(75,50,90,190,5000,5000,5000,1)
 list.cwdt - c(listc, listw, listd, listt)
 country -
 data.frame(country=listc,weight=listw,deaths=listd,yrs_at_risk=listt)

 # running a frequency weighted regression to get the correct point
 estimates for comparison
 glm - glm(deaths ~ country + offset(log(yrs_at_risk)),
 weights=weight, data=country, family=poisson())
 summary(glm)
 regTermTest(glm, ~ country)

 # running survey weighted regression
 svy - svydesign(~0,,data=country, weight=~weight)
 svyglm - svyglm(deaths ~ country + offset(log(yrs_at_risk)),
 design=svy, data=country, family=poisson())
 summary(svyglm)
 # point estimates are correct, but standard error is way too large
 regTermTest(svyglm, ~ 

[R] stepwise with F statistics

2009-10-13 Thread Lucas Sevilla García

Hi Community R

I need to make a stepwise using F statistics as a criteria to choose 
variables.I have 3 independant variables and one dependant variable, and I need 
to choose the best model fitting to my data using F statistics. The problem is 
I haven't found any package to do such operation. I have found packages to 
choose variables using significance level like stepback from maSigPro 
package.  However, I haven't found something similar using with F-statistics. I 
tried grasp package as well but the documentation of this package is not clear. 
I read in several messages from the community that it's possible to do a 
stepwise using F statistics as criteria, but they don't specify how to do it, 
so, I would appreciate if anyone can help me with some indication about any 
package that could do what I need. Thanks in advance. 

Lucas
  
_

us contactos? Revisa tu correo mientras conversas con tus amigos. 

[[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] stochastic process

2009-10-13 Thread Bernardo Rangel Tura
On Tue, 2009-10-13 at 14:43 +0800, 刘哲 wrote:
 Hi,
  
 I'm a student in China, and I never used R before.
  
 I'm now wondering how to simulate a sample of Markov chain of ,say 500 
 entries with a certain transition matrix. 
  
 Thanks a lot.

Hi

Well the naive script for you problem is something like this

#
# initial condition
#
initial-matrix(c(300,200,0),nrow=1)
initial
 [,1] [,2] [,3]
[1,]  300  2000

#
# transition matrix (third state is absortive)
#
transition-matrix(c(
.5,.3,.2,
.3,.4,.3,
0,0,1
),nrow=3,byrow=T)
transition
 [,1] [,2] [,3]
[1,]  0.5  0.3  0.2
[2,]  0.3  0.4  0.3
[3,]  0.0  0.0  1.0

#
# first step
#
S1-initial%*%transition
S1
 [,1] [,2] [,3]
[1,]  210  170  120

#
# Second step
#
S2-S1%*%transition
S2
 [,1] [,2] [,3]
[1,]  156  131  213


If you use a large number of step is more pratical use command mtx.exp
of Biodem package, something like this


require(Biodem)
#
# 10th step direct
#
initial%*%mtx.exp(transition,10)


-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] multiple groups with different colors in boxplot

2009-10-13 Thread kennyPA

Can anybody help me on how to boxplot multiple groups with different color?
Say, I have 3 groups of data, each group with 2 boxes, and I'd like to have
the following layout in the boxplot:

red, red, green, green, blue, blue

thanks in advance. 
-- 
View this message in context: 
http://www.nabble.com/multiple-groups-with-different-colors-in-boxplot-tp25867267p25867267.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] GridR

2009-10-13 Thread wesley mathew
Dear All

I was installed GridR package in R. I am trying to execute UCS; it is my
project in client side.
grid.init(service=local,debug=FALSE, localTmpDir=GridRTmp/)
 grid.apply(x,UCS, wait=TRUE,,check=TRUE)
But this shows error, that is given below.
*cannot load local function/variable:  to 'Training_file
 extracted from line:  : no visible binding for '-' assignment to
'Training_file'
*All the globally declared variables show same error.
 How can I solve this problem?
I would be grateful, for any sort of help with this regard.
Kind Regards

-- 
Wesley C Mathew

[[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] plot dates in x-axis

2009-10-13 Thread Lathouri, Maria
Hallo,

I am trying to plot dates in x-axis. The format of my dates are in dd/mm/. 
At first I install zoo package. After R reads my file, I change the default 
format of dates to the format that I have,

myfile-read.csv
DATE-as.Date(DATE,format=%d/%m/%Y)

up till now everything goes ok; when however I go and plot for example
plot(DATE, Discharge)

in the x-axis I only get the years, 1998, 2000, 2002...

How can I see in the x-axis the whole format of the dates that I have e.g. 
29/01/1998?



[[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] Using diff, ifelse on zoo object

2009-10-13 Thread charliegenge

Thanks very much Gabor! Worked like a treat. Good to know that the na's
really mess up the ifelse function.

Thanks again.




Gabor Grothendieck wrote:
 
 The problem is that ifelse does not work the way you might think (see
 value section of ?ifelse) and basically should not be used with three
 zoo objects unless the three arguments to ifelse have the same time
 index.
 
 We can get that effect by using na.pad = TRUE in your diff call:
 
TradedRate - with(x, ifelse(abs(diff(x.POS, na.pad = TRUE))  0,
 ifelse(x.POS != 1, -x, x), NA))
 
 or alternately we can merge them together first:
 
xm - merge(x, dif = abs(diff(x$x.POS)))
TradedRate - with(xm, ifelse(dif  0, ifelse(x.POS != 1, -x, x), NA))
 
 By the way, to ensure that your output is reproducible be sure to use
 set.seed(...) before any call to a random number generator when
 posting.
 
 
 On Mon, Oct 12, 2009 at 5:30 AM, charliegenge charlie.ge...@sc.com
 wrote:

 Hi,

 I'm having an issue when using diff and ifelse on a zoo object.

 x.Date - as.Date(2003-02-01) + c(1, 3, 7, 9, 14) - 1
 x - zoo(rnorm(5), x.Date)
 x.POS - c(0,0,0,1,1)
 x- merge(x,x.POS)
 x
                        x         x.POS
 2003-02-01   -0.1858136     0
 2003-02-03   -1.3188533     0
 2003-02-07    0.2709794      0
 2003-02-09   -1.4915262     1
 2003-02-14    0.5014170      1

 When I create this new zoo object using the previous one (x) I don't get
 exactly what I need..the traded rate is based on the lagged values,
 rather than the present ones...

 TradedRate - ifelse(abs(diff(x[,x.POS],lag= 1))0,ifelse(x[,x.POS]
 !=1,-x[,x],x[,x]),NA)
 x - merge(x, TradedRate, all=TRUE)
 x
                    x x.POS TradedRate
 2003-02-01 -0.1858136     0         NA
 2003-02-03 -1.3188533     0         NA
 2003-02-07  0.2709794     0         NA
 2003-02-09 -1.4915262     1 -0.2709794
 2003-02-14  0.5014170     1         NA

 The value for TradedRate on the 9th Feb should be -1.4945262 instead of
 -0.2709794what am I doing wrong?

 Thanks very much..
 --
 View this message in context:
 http://www.nabble.com/Using-diff%2C-ifelse-on-zoo-object-tp25852822p25852822.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.
 
 

-- 
View this message in context: 
http://www.nabble.com/Using-diff%2C-ifelse-on-zoo-object-tp25852822p25870058.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] using axis.Date with interaction.plot

2009-10-13 Thread North, Bernard V
Dear List

I want to plot multiple time series (several outcomes) with dates at intervals 
on the x axis and a legend.

Is it possible to use axis.Date to get dates, at intervals in  my case, on the 
x axis of a (multiple) time series plot.
The axis.Date in the code below doesn't produce any dates on the x axis. (The 
difference outcome measures are all variable outcome in dataframe speclong and 
the  different groups correspond to different values of the variable time with 
values 1 to 8)

But the same axis.Date command gives x axis Dates perfectly if following an 
ordinary plot command. So I suppose I could do that and add time series for 
successive time series using lines( but then I wouldn't have a legend or I'd 
have to create one manually

Many thanks for any advice

Bernard

speclong
  Date time outcome id
1.1 1998-01-291 8.11879e-13  1
2.1 1998-02-171 9.11297e-13  2
3.1 1998-03-201 4.95558e-13  3
4.1 1998-05-071 4.34171e-13  4
5.1 1998-05-261 2.41658e-13  5
6.1 1998-06-051 4.89529e-13  6

82.8 2005-07-158 2.37023e-11 82
83.8 2005-08-238 3.52766e-11 83
84.8 2005-09-088 1.98099e-11 84
85.8 2005-10-188 2.93576e-11 85
86.8 2005-11-188 6.30531e-11 86
87.8 2005-12-018 5.71245e-11 87
 interaction.plot(speclong$Date,speclong$time,speclong$outcome,log=y,xaxt=n,col=rainbow(8)
  )
 axis.Date(1,at=(as.Date(1998-01-01) +c(0:7)*365.25),format=%d/%m/%y, 
 las=2)

 sessionInfo()
R version 2.9.0 (2009-04-17)
i386-pc-mingw32

locale:
LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United 
Kingdom.1252;LC_MONETARY=English_United 
Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252

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

[[alternative HTML version deleted]]

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


Re: [R] How to read plain text documents into a vector?

2009-10-13 Thread kenhorvath



Paul Hiemstra wrote:
 
 
 file_list = list.files(/where/are/the/files)
 obj_list = lapply(file_list, FUN = yourfunction)
 
 yourfunction is probably either read.table or some read function from 
 the tm package. So obj_list will become a list of either data.frame's or 
 tm objects.
 
 

The read function that most probably should be adequate is readLines(), so
the command would read:

obj_list - lapply(file_list,readLines)

To convert to a vector, do the following:

obj_list - lapply(obj_list,paste,collapse= )
obj_vec - as.vector(obj_list)

Ken

-- 
View this message in context: 
http://www.nabble.com/How-to-read-plain-text-documents-into-a-vector--tp25867792p25870485.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] Adding additional X-axis data to charts, e.g. N values

2009-10-13 Thread spidermonkeydp

Hello All,

Does anyone know if it is possible to add an additional X-axis data to a
chart? 

For example, if I have plotted a bar chart of mean height on the Y-axis and
have male and female on the X-axis. I want to add automatically the number
of samples (N) for males and number of samples for females under their
respective labels on the X-axis. I could do this manually using Power Point
or equivalent software, but was wondering if there were any way of doing
this automatically. 

I have tried in SPSS, Sigma-plot, Excel and cannot see a way of doing this.
Can R provide me with this function?

Thank you for any advice, even if you know of another package that may be
capable of this.

Best,

D.
-- 
View this message in context: 
http://www.nabble.com/Adding-additional-X-axis-data-to-charts%2C-e.g.-N-values-tp25870161p25870161.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] lapply() reccursively

2009-10-13 Thread Kaveh Vakili

Hi all,

I was wondering whether it is possible to use the lapply() function
to alter the value of the input, something in the spirit of :

a1-runif(100)
a2-function(i){
a1[i]-a1[i-1]*a1[i];a1[i]
}
a3-lapply(2:100,a2)

Something akin to a for() loop, but using the lapply() infrastructure.
I haven't been able to get rapply() to do this.

The reason is that the real a2 function is a difficult function that only 
needs to be evaluated if the value of a1[i-1] meets some criteria.

Thanks in advance,

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


Re: [R] multiple groups with different colors in boxplot

2009-10-13 Thread ONKELINX, Thierry
Here is a solution using ggplot2

n - 1000
dataset - data.frame(A = rep(1:6, n), B = rep(gl(3, 2), n))
dataset$C - with(dataset, rnorm(n) * as.numeric(B) + A)
library(ggplot2)
dataset$A - factor(dataset$A)
#with default colours
ggplot(dataset, aes(x = A, y = C, colour = B)) + geom_boxplot()
#with custom colours
ggplot(dataset, aes(x = A, y = C, colour = B)) + geom_boxplot() +
scale_colour_manual(breaks = c(1, 2, 3), values = c(red,
green, blue))

HTH,

Thierry 




ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
thierry.onkel...@inbo.be
www.inbo.be

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

The plural of anecdote is not data.
~ Roger Brinner

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

-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
Namens kennyPA
Verzonden: dinsdag 13 oktober 2009 7:12
Aan: r-help@r-project.org
Onderwerp: [R] multiple groups with different colors in boxplot


Can anybody help me on how to boxplot multiple groups with different
color?
Say, I have 3 groups of data, each group with 2 boxes, and I'd like to
have the following layout in the boxplot:

red, red, green, green, blue, blue

thanks in advance. 
--
View this message in context:
http://www.nabble.com/multiple-groups-with-different-colors-in-boxplot-t
p25867267p25867267.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.

Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed document.

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


Re: [R] plotting points in random but different colors based on condition

2009-10-13 Thread Jonathan Bleyhl

I guess I didn't mention that I'm trying to do this in ggplot2 where I have
my color set up via:

geom_point(aes(colour = Date))

Not sure how to implement your suggestion within the confines of ggplot2.


Jim Lemon-2 wrote:
 
 On 10/10/2009 06:41 PM, Jim Lemon wrote:
 Oops, should be:
 
 gimmeDiffCol-function(oldcol) {
  rgbcomp-col2rgb(oldcol)
  if(rgbcomp[1,1]127) newred-sample(rgbcomp[1,1]:255,1)/255
  else newred-sample(0:rgbcomp[1,1],1)/255
  if(rgbcomp[2,1]127) newgreen-sample(rgbcomp[2,1]:255,1)/255
  else newgreen-sample(0:rgbcomp[2,1],1)/255
   if(rgbcomp[3,1]127) newblue-sample(rgbcomp[3,1]:255,1)/255
  else newblue-sample(0:rgbcomp[3,1],1)/255
  return(rgb(newred,newgreen,newblue))
 }

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

-- 
View this message in context: 
http://www.nabble.com/plotting-points-in-random-but-different-colors-based-on-condition-tp24837716p25858707.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] Installing R on Ubuntu ( 8.10 ) ?

2009-10-13 Thread Robert Wilkins
installing on Ubuntu, how to do it and have people found it to be glitchy?

which is easier , binary install or from source ?

With the source install, are you less likely to have a dependencies issue ?

( Ubuntu does the GCC install seamlessly, but has no mention of R )

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


Re: [R] splitting dataframe, assign to new dataframe, add new rows to new dataframe

2009-10-13 Thread Ista Zahn
I'm sure there's a really cool way to do this with plyr, although I
don't know if my particular plyr version is much better. Anyway here
it is:

cmbine - read.csv(textConnection('names, mass, classes
apple,0.50,1
tiger,100.00,2
pencil,0.01,3
chicken,1.00,2
banana,0.15,1
pear,0.30,1'))

library(plyr)

dfl - list()

for(i in 1:max(cmbine$classes)) {
  dfl[[i]] - ddply(cmbine, .(classes), function(x) {x[i,]})
}

dfl

Hope it helps,
Ista

On Mon, Oct 12, 2009 at 10:02 PM, cls59 ch...@sharpsteen.net wrote:



 wk yeo wrote:


 Hi, all,

 My objective is to split a dataframe named cmbine according to the value
 of classes. After the split, I will take the first instance from each
 class and bin them into a new dataframe, df1. In the 2nd iteration, I
 will take the 2nd available instance and bin them into another new
 dataframe, df2.



 My apologies, I did not read the first lines of your question carefully. Say
 we split the data frame by class using by():

 byClass - by( cmbine, cmbine[['classes']], function( df ){ return(df) } )


 We could then determine the maximum number of rows in all the returned data
 frames:

 maxRows - max(sapply( byClass, nrow ))


 Then, I usually resort to a gratuitous application of lapply() and
 do.call():

 # Loop over each value between 1 and the maximum number of rows, return
 results as a list.
 lapply( 1:maxRow, function(i){

        # Loop over each data frame, extract the ith rows and rbind the
 results
        # together.
        ithRows - do.call(rbind,lapply(byClass,function(df){

          return( df[i,] )

        }))

        # Remove all NA rows
        ithRows - ithRows[ !is.na(ithRows[,1]), ]

        return(ithRows)

 })


 [[1]]
   names  mass classes
 1  apple 5e-01       1
 2  tiger 1e+02       2
 3 pencil 1e-02       3

 [[2]]
    names mass classes
 1  banana 0.15       1
 2 chicken 1.00       2

 [[3]]
  names mass classes
 1  pear  0.3       1


 There's definitely a more elegant way to do this, perhaps using some
 routines in the plyr package.

 Good luck!

 -Charlie

 -
 Charlie Sharpsteen
 Undergraduate
 Environmental Resources Engineering
 Humboldt State University
 --
 View this message in context: 
 http://www.nabble.com/splitting-dataframe%2C-assign-to-new-dataframe%2C-add-new-rows-to-new-dataframe-tp25865409p25866082.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.




-- 
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] Installing R on Ubuntu ( 8.10 ) ?

2009-10-13 Thread Ista Zahn
It's not glitchy, and you install it just like any other program. If
you want the latest version you can follow the instructions here:
http://cran.r-project.org/bin/linux/ubuntu/. Otherwise sudo aptitude
install r-base r-base-dev will do the trick.

On Tue, Oct 13, 2009 at 7:46 AM, Robert Wilkins robst...@gmail.com wrote:
 installing on Ubuntu, how to do it and have people found it to be glitchy?
sudo aptitude update
sudo aptitude install r-base

No.


 which is easier , binary install or from source ?
??? Usually binary is easier (that's kind of the point of binaries...)

 With the source install, are you less likely to have a dependencies issue ?

No, let the apt system handle this for you.


 ( Ubuntu does the GCC install seamlessly, but has no mention of R )

??


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




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


[R] Introduction to mark-recapture analysis in R?

2009-10-13 Thread Anne-Katrin Link
Normal021falsefalse
false
MicrosoftInternetExplorer4  
  

Dear R-helpers,

 I was wondering whether there are any good books and/or website 
links that introduce mark-recapture analysis in R. In particular, I am 
interested in exploratory data analysis of resighting data and how to 
create capture histories from dataframes in R.

Thank you very much for your reply in advance!

 Cheers, 

Anne
-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser

[[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] Adding additional X-axis data to charts, e.g. N values

2009-10-13 Thread John Kane
?mtext  should help.  

--- On Tue, 10/13/09, spidermonkeydp gbabo...@gmail.com wrote:

 From: spidermonkeydp gbabo...@gmail.com
 Subject: [R]  Adding additional X-axis data to charts, e.g. N values
 To: r-help@r-project.org
 Received: Tuesday, October 13, 2009, 6:06 AM
 
 Hello All,
 
 Does anyone know if it is possible to add an additional
 X-axis data to a
 chart? 
 
 For example, if I have plotted a bar chart of mean height
 on the Y-axis and
 have male and female on the X-axis. I want to add
 automatically the number
 of samples (N) for males and number of samples for females
 under their
 respective labels on the X-axis. I could do this manually
 using Power Point
 or equivalent software, but was wondering if there were any
 way of doing
 this automatically. 
 
 I have tried in SPSS, Sigma-plot, Excel and cannot see a
 way of doing this.
 Can R provide me with this function?
 
 Thank you for any advice, even if you know of another
 package that may be
 capable of this.
 
 Best,
 
 D.
 -- 
 View this message in context: 
 http://www.nabble.com/Adding-additional-X-axis-data-to-charts%2C-e.g.-N-values-tp25870161p25870161.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.
 


  __
[[elided Yahoo spam]]

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


Re: [R] stepwise with F statistics

2009-10-13 Thread Frank E Harrell Jr

Lucas Sevilla García wrote:

Hi Community R

I need to make a stepwise using F statistics as a criteria to choose variables.I have 3 independant variables and one dependant variable, and I need to choose the best model fitting to my data using F statistics. The problem is I haven't found any package to do such operation. I have found packages to choose variables using significance level like stepback from maSigPro package.  However, I haven't found something similar using with F-statistics. I tried grasp package as well but the documentation of this package is not clear. I read in several messages from the community that it's possible to do a stepwise using F statistics as criteria, but they don't specify how to do it, so, I would appreciate if anyone can help me with some indication about any package that could do what I need. Thanks in advance. 


Lucas



Why not just postulate a model and fit it?  Why the need for removing 
any of your variables?


Stepwise variable selection requires bootstrapping for validation / 
stability checking.

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

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


[R] Counting

2009-10-13 Thread Ashta
*Hi all,
*

*Assume that I have the following data set  with tow variables and I want
count the number of observation with identical values
*

**

*x1 x2*

* 1   1 *

* 1   0 *

* 0   1*

* 0   1*

* 0   0*

* 1   1*

* 0   1
*


I want the  following output
**

*
*

*n1=3  # number of identical observation between x1 and x2 variables*

*n2=4  # number of different observation*


How do I do it in R?


Thanks a lot




**

[[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] multiple groups with different colors in boxplot

2009-10-13 Thread Henrique Dallazuanna
Try this;

DF - as.data.frame(matrix(rnorm(60), 10))
boxplot(DF, col = rep(seq(ncol(DF)) + 1, each = 2))

On Tue, Oct 13, 2009 at 2:11 AM, kennyPA tao...@yahoo.com wrote:

 Can anybody help me on how to boxplot multiple groups with different color?
 Say, I have 3 groups of data, each group with 2 boxes, and I'd like to have
 the following layout in the boxplot:

 red, red, green, green, blue, blue

 thanks in advance.
 --
 View this message in context: 
 http://www.nabble.com/multiple-groups-with-different-colors-in-boxplot-tp25867267p25867267.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.




-- 
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] Installing R on Ubuntu ( 8.10 ) ?

2009-10-13 Thread Dirk Eddelbuettel

On 13 October 2009 at 07:46, Robert Wilkins wrote:
| installing on Ubuntu, how to do it and have people found it to be glitchy?
| 
| which is easier , binary install or from source ?
| 
| With the source install, are you less likely to have a dependencies issue ?
| 
| ( Ubuntu does the GCC install seamlessly, but has no mention of R )

Really?  R has been part of every Ubuntu release. 

So install it from part of the distribution, or use the (usually more
current) CRAN repository for Ubuntu at

  http://cran.r-project.org/bin/linux/ubuntu/

where a detailed README tells you how to go about this.

Dirk

-- 
Three out of two people have difficulties with fractions.

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


Re: [R] Counting

2009-10-13 Thread Henrique Dallazuanna
Try this:

table(Reduce(`==`, DF))

On Tue, Oct 13, 2009 at 9:20 AM, Ashta sewa...@gmail.com wrote:
 *Hi all,
 *

 *Assume that I have the following data set  with tow variables and I want
 count the number of observation with identical values
 *

 **

 *x1 x2*

 * 1   1 *

 * 1   0 *

 * 0   1*

 * 0   1*

 * 0   0*

 * 1   1*

 * 0   1
 *


 I want the  following output
 **

 *
 *

 *n1=3  # number of identical observation between x1 and x2 variables*

 *n2=4  # number of different observation*


 How do I do it in R?


 Thanks a lot




 **

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

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


Re: [R] Counting

2009-10-13 Thread Julien Grassot
Or try this :

x1=c(1,1,0,0,0,1,0)
x2=c(1,0,1,1,0,1,1)

DF=cbind(x1,x2)

ifelse(DF[,1]==DF[,2],1,0)

your n1 is :
sum(ifelse(DF[,1]==DF[,2],1,0))

your n2 is :
dim(DF)[1]-sum(ifelse(DF[,1]==DF[,2],1,0))

Maybe not an elegant way, but hope this help.


Julien GRASSOT
Data Analysis Department
Flamel Technologies 
FRANCE 




-Message d'origine-
De : r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] De la 
part de Henrique Dallazuanna
Envoyé : mardi 13 octobre 2009 14:41
À : Ashta
Cc : R help
Objet : Re: [R] Counting

Try this:

table(Reduce(`==`, DF))

On Tue, Oct 13, 2009 at 9:20 AM, Ashta sewa...@gmail.com wrote:
 *Hi all,
 *

 *Assume that I have the following data set  with tow variables and I want
 count the number of observation with identical values
 *

 **

 *x1 x2*

 * 1   1 *

 * 1   0 *

 * 0   1*

 * 0   1*

 * 0   0*

 * 1   1*

 * 0   1
 *


 I want the  following output
 **

 *
 *

 *n1=3  # number of identical observation between x1 and x2 variables*

 *n2=4  # number of different observation*


 How do I do it in R?


 Thanks a lot




 **

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

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

2009-10-13 Thread John Kane
library(Hmisc) spss.get may do it but it's been some time since I used it.

--- On Sat, 10/10/09, Orvalho Augusto orvaq...@gmail.com wrote:

 From: Orvalho Augusto orvaq...@gmail.com
 Subject: [R] SPSS long variable names
 To: r-help@r-project.org
 Received: Saturday, October 10, 2009, 12:14 PM
 Hello guys I am new to this list and
 for R too.
 
 I am wondering if there is a patch for the SPSS reading
 code on the
 foreign package, in order to be able to read long variable
 names.
 Right now read.spss() just trunc the names to 8
 characters.
 
 Or if someone could help me on other way:
 I have to process everyday a lot of SPSS Syntax Files and
 Dat files
 that come from one system that can only export data on
 through that
 way.
 
 I use PSPP to generate the spss data file (sav) that I read
 with R.
 From R I can export to MySQL, DBF and STATA to satisfy
 the needs of
 different guys here.
 
 The problem is the limit of 8 characters long on variable
 names.
 
 Can someone help on that?
 
 Caveman
 
 __
 R-help@r-project.org
 mailing list
 https://stat.ethz.ch/mailman/listinfo/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 new Internet Explorer® 8 - Faster, safer, easier.  Optimiz
etexplorer/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 draw more geographical boundaries

2009-10-13 Thread Angela Parenti
Dear R-users,

I am trying to plot in the same map both NUTS 2 (i.e. regional) and NUTS 3 
(i.e. provincial) boundaries for Italy
but I couldn't find how to plot more than one level boundary in the same map.//
//
I have shapefile both for regions and provinces in Italy and I tried to use the 
maptool and maps packages without
success.

Thank you in advance for any help.

Best regards,
Angela Parenti/
/


[[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] lapply / mapply and assignments

2009-10-13 Thread Magnus Torfason

Thank you so much, relist and SIMPLIFY both work.

See more comments below ...

On 10/12/2009 5:35 PM, Charles C. Berry wrote:

On Mon, 12 Oct 2009, Magnus Torfason wrote:

I want to achieve the following:


 l - list( list(a=1,b=2), list(a=3,b=4))
 l[[]][a] - 5:6



See
?relist

something like:

relist( unlist( mapply( [-, l, a, 5:6) ), l )


Yes, this works exactly as needed. I had tried this, but I failed to 
notice that you could supply the skeleton argument separately. Thanks!


I had also tried

mapply( [-, l, a, c(5,6), SIMPLIFY=FALSE)

but failed to put SIMPLIFY in all-caps, and got an error message that I 
did not understand. It seems I was close on both methods, but not close 
enough.


Best,
Magnus

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


Re: [R] Introduction to mark-recapture analysis in R?

2009-10-13 Thread Ben Bolker



  oops, library(sos) after install.packages(sos) and before
findFn(mark-recapture) ...
-- 
View this message in context: 
http://www.nabble.com/Introduction-to-mark-recapture-analysis-in-R--tp25871729p25872847.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] Introduction to mark-recapture analysis in R?

2009-10-13 Thread Ben Bolker



Anne Link wrote:
 
 Normal021falsefalse
 false
 MicrosoftInternetExplorer4  
   
 
 Dear R-helpers,
 
  I was wondering whether there are any good books and/or website 
 links that introduce mark-recapture analysis in R. In particular, I am 
 interested in exploratory data analysis of resighting data and how to 
 create capture histories from dataframes in R.
 
 Thank you very much for your reply in advance!
 
  Cheers, 
 
 Anne
 -- 
 

Don't know about books, web sites, but the excellent new sos package
lists three packages with mark-recapture capabilities: Rcapture,
fishmethods,
and mra (install.packages(sos); findFn(mark-recapture)

-- 
View this message in context: 
http://www.nabble.com/Introduction-to-mark-recapture-analysis-in-R--tp25871729p25872838.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] SPSS long variable names

2009-10-13 Thread Orvalho Augusto
Thanks for the answer.

Hmisc uses read.spss from the foreign package. And so it does not
solve my trouble.

I need to read the long names on the SPSS dataset.

Caveman


On Tue, Oct 13, 2009 at 3:01 PM, John Kane jrkrid...@yahoo.ca wrote:
 library(Hmisc) spss.get may do it but it's been some time since I used it.

 --- On Sat, 10/10/09, Orvalho Augusto orvaq...@gmail.com wrote:

 From: Orvalho Augusto orvaq...@gmail.com
 Subject: [R] SPSS long variable names
 To: r-help@r-project.org
 Received: Saturday, October 10, 2009, 12:14 PM
 Hello guys I am new to this list and
 for R too.

 I am wondering if there is a patch for the SPSS reading
 code on the
 foreign package, in order to be able to read long variable
 names.
 Right now read.spss() just trunc the names to 8
 characters.

 Or if someone could help me on other way:
 I have to process everyday a lot of SPSS Syntax Files and
 Dat files
 that come from one system that can only export data on
 through that
 way.

 I use PSPP to generate the spss data file (sav) that I read
 with R.
 From R I can export to MySQL, DBF and STATA to satisfy
 the needs of
 different guys here.

 The problem is the limit of 8 characters long on variable
 names.

 Can someone help on that?

 Caveman

 __
 R-help@r-project.org
 mailing list
 https://stat.ethz.ch/mailman/listinfo/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 new Internet Explorer® 8 - Faster, safer, easier.  Optimized for Yahoo!  
 Get it Now for Free! at http://downloads.yahoo.com/ca/internetexplorer/


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Identification of variables contributing to differences between factor in adonis

2009-10-13 Thread Paul Dennis

Dear all

I have used permutational multivariate analysis of variance (adonis in package 
vegan) based on Bray-Curtis distances  to assess the signifance of carbon, 
nitrogen and more complex nutrient amendments on soil microbial community 
structure (microbial fatty acids).

I have identified signifant effects of nutrients and would like to know how to 
identify the fatty acids (microbial markers) that are associated with these 
differences.  So far I have used Pierre Legrendre's Dufrene-Legendre Indicator 
Species Analysis duleg in package 'labdsv' to do this (Calculates the 
indicator value (fidelity and relative abundance) of species in 
clusters or types).  However, I am not familiar with the implementation of this 
method and am concerned about the relevance of the output as  the 'indicator 
species' are not probably not based on Bray-Curtis distances.

Is there another way to identify fatty acids contributing to differences 
between my nutrient amendment groups?  For example, the output of the 
permutational multivariate analysis of variance (adonis) has the following 
attributes:

 
aov.tab  6data.frame list   
call2-none-   call   
coefficients74   -none-   numeric
coef.sites   28   -none-  numeric
f.perms 999  -none-  numeric
model.matrix 28   -none-   numeric
terms3 termscall

Can I use the coefficients to select fatty acids that contribute to the 
differences between treatment? 

Thanks

Paul  
_
View your other email accounts from your Hotmail inbox. Add them now.

[[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] RPostgreSQL and needed .dlls

2009-10-13 Thread Uwe Ligges



Josuah Rechtsteiner wrote:

Dear List,

I am trying to connect from R 2.9.2 on Win XP SP3 to a remotely 
installed PostgreSQL DB (8.3.7 on Ubuntu Server 9.04). Everything seems 
to be properly installed, as I can connect to the DB from within Excel 
and RKWard (running on another machine).
But regarding R on the Win XP, I cannot load RPostgreSQL. libpq.dll is 
missing. What can I do now, without having to install PostgreSQL on this 
Windows, where I do not need it as I have my remote DB?


Well, you need libpq.dll for RPostgreSQL in any case since the package 
links dynamically against that library. Or connect with another method 
to your database.


Uwe Ligges





Thanks in advance

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Use R -- term and logo copyright?

2009-10-13 Thread David Winsemius

Perhaps:

Yooze R!

On second thought, probably not quite right for King's College.

Then?

dig R!

--  
David


On Oct 9, 2009, at 3:46 PM, Marianne Promberger wrote:


Dear list,

I would like to start some R workshops at King's College London, and
to do so, I would like to use the Use R! logo at
http://www.agrocampus-ouest.fr/math/useR-2009//useR%21%202008_fichiers/useR-middle.png

Since it seems to be difficult to get a shell account at KCL, I also  
went

ahead and registered use-r.org.uk and am starting to put together a
website at kcl.use-r.org.uk.

I really like the Use R! slogan, which seems to be used by the R
user conferences and Springer (the latter without the exclamation
mark).

Even more, I really *really* like Use R! logo.  I think it is very
elegant indeed! Kudos to whoever designed it.

However, I'm completely in the dark about copyright issues of the logo
and the slogan.

Can I use (a) the logo and/or (b) the slogan for the KCL R workshops?
I think it is quite clear from my website that this is neither about
the Springer book series nor about an R user conference.

I enquired with the agrocampus-ouest.fr website about the logo but was
pointed to r-project.org and the R development core team. I thought in
that case it might be best to ask here to have the answer publicly
available -- sorry if I overlooked the information online somewhere.

Marianne

--
Marianne Promberger PhD, King's College London
http://promberger.info
R version 2.9.2 (2009-08-24)
Ubuntu 9.04

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

2009-10-13 Thread Thomas Lumley

On Tue, 13 Oct 2009, AJ83 wrote:



I need to create a function to find all the prime numbers in an array. Can
anyone point me in the right direction?


It depends a bit on how big the numbers are.  If the array is large but the numbers are not very large the 
fastest approach is probably to create a vector of small primes and use

   my_array %in% smallprimes.

For example, the first 1000 primes are at 
http://primes.utm.edu/lists/small/1000.txt
and the first 1 are on the same site.


  -thomas

Thomas Lumley   Assoc. Professor, Biostatistics
tlum...@u.washington.eduUniversity of Washington, Seattle

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] update.formula drop interaction terms

2009-10-13 Thread Eleni Rapsomaniki
Dear R users,

How do I drop multiplication terms from a formula using update?
e.g.
forml=as.formula(Surv(time, status) ~ x1+x2+A*x3+A*x4+B*x5+strata(sex))

#I would like to drop all instances of variable A (the main effect and its 
interactions). The following:
updated.forml=update(forml, ~ . -A)

#gives me this:
#Surv(time, status) ~ x1 + x2 + x3 + x4 + B + x5 + strata(sex) + A:x3 + A:x4 + 
B:x5

#but I want this:
#updated.forml=as.formula(Surv(time, status) ~ x1+x2+x3+x4+B*x5+strata(sex))

Any ideas?
Thanks in advance

Eleni Rapsomaniki

Research Associate
Strangeways Research Laboratory
Department of Public Health and Primary Care
University of Cambridge
 

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


Re: [R] splitting dataframe, assign to new dataframe, add new rows to new dataframe

2009-10-13 Thread hadley wickham
On Tue, Oct 13, 2009 at 6:57 AM, Ista Zahn istaz...@gmail.com wrote:
 I'm sure there's a really cool way to do this with plyr, although I
 don't know if my particular plyr version is much better. Anyway here
 it is:

 cmbine - read.csv(textConnection('names, mass, classes
 apple,0.50,1
 tiger,100.00,2
 pencil,0.01,3
 chicken,1.00,2
 banana,0.15,1
 pear,0.30,1'))

 library(plyr)

 dfl - list()

 for(i in 1:max(cmbine$classes)) {
  dfl[[i]] - ddply(cmbine, .(classes), function(x) {x[i,]})
 }

Here's another approach:

cmbine - read.csv(textConnection('names, mass, classes
apple,0.50,1
tiger,100.00,2
pencil,0.01,3
chicken,1.00,2
banana,0.15,1
pear,0.30,1'))

cmbine - ddply(cmbine, classes, transform, i = seq_along(names))
dlply(cmbine, i)

Hadley

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


[R] Creating a list of empty lists

2009-10-13 Thread Magnus Torfason
Well here is one more brain-teaser related to assigning stuff into a 
list of list. What if I need to create a new list of empty lists? I have 
actually got a solution to this problem:


l = list(list())
for ( i in sequence(length-1) )
{
l = list(unlist(l,recursive=FALSE), list())
}

But it is not very neat to do this in a loop. Are there any cuter ways 
to do this?


Best,
Magnus

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


Re: [R] svy / weighted regression

2009-10-13 Thread Thomas Lumley


I think there is a much simpler explanation.

The survey design object has eight observations, two per country.   With a sample size of two per 
country it is hardly surprising that country-specific estimates are not very precise. The actual data has 
hundreds of thousands  of observations per country, so it will have more precise estimates.


Grouping the data doesn't make a difference for model-based glm estimation, where it is simply a 
computational convenience. It *does* make a difference for design-based estimation, because it 
changes the design.


 -thomas


On Tue, 13 Oct 2009, Laust wrote:


Dear David,

Thanks again for your input! I realize that I did a bad job of
explaining this in my first email, but the setup is that in Finland
persons who die are sampled with a different probability (1) from
those who live (.5). This was done by the Finnish data protection
authorities to protect individuals against identification. In the rest
of the countries everyone is sampled with a probability of 1. The data
that I am supplying to R is summarized data for each country
stratified by case status. Another way of organizing the data would
be:

# creating data
listc - c(Denmark,Finland,Norway,Sweden)
listw - c(1,2,1,1)
listd - c(1000,1000,1000,2000)
listt - c(755000,505000,905000,191)
list.cwdt - c(listc, listw, listd, listt)
country2 - data.frame(country=listc,weight=listw,deaths=listd,time=listt)

I hope that it is clearer now that for no value of the independent
variable 'country' is the rate going to be zero. I think this was also
not the case in my original example, but this was obscured by my poor
communication-  R-skills. But if data is organized this way then
sampling weight of 2 for Finland should only be applied to the
time-variable that contains person years at risk and *not* to the
number of deaths, which would complicate matters further. I would know
how to get this to work in R or in any other statistical package.
Perhaps it is - as Peter Dalgaard suggested - the estimation of the
dispersion parameter by the survey package that is causing trouble,
not the data example eo ipso. Or perhaps I am just using survey in a
wrong way.

Best
Laust


Post doc. Laust Mortensen, PhD
Epidemiology Unit
University of Southern Denmark

On Mon, Oct 12, 2009 at 3:32 PM, David Winsemius dwinsem...@comcast.net wrote:

I think you are missing the point. You have 4 zero death counts associated
with much higher person years of exposure followed by 4 death counts in the
thousands associated with lower degrees of exposures. It seems unlikely that
these are real data as there are not cohorts that would exhibit such lower
death-rates. So it appears that in setting up your test case, you have
created an impossibly unrealistic test problem.

--
David


On Oct 12, 2009, at 9:12 AM, Laust wrote:


Dear Peter,

Thanks for the input. The zero rates in some strata occurs because
sampling depended on case status: In Finland only 50% of the non-cases
were sampled, while all others were sampled with 100% probability.

Best
Laust

On Sat, Oct 10, 2009 at 11:02 AM, Peter Dalgaard
p.dalga...@biostat.ku.dk wrote:


Sorry, forgot to reply all...

Laust wrote:


Dear list,

I am trying to set up a propensity-weighted regression using the
survey package. Most of my population is sampled with a sampling
probability of one (that is, I have the full population). However, for
a subset of the data I have only a 50% sample of the full population.
In previous work on the data, I analyzed these data using SAS and
STATA. In those packages I used a propensity weight of 1/[sampling
probability] in various generalized linear regression-procedures, but
I am having trouble setting this up. I bet the solution is simple, but
I’m a R newbie. Code to illustrate my problem below.


Hi Laust,

You probably need the package author to explain fully, but as far as I
can see, the crux is that a dispersion parameter is being used, based on
Pearson residuals, even in the Poisson case (i.e. you effectively get
the same result as with quasipoisson()).

I don't know what the rationale is for this, but it is clear that with
your data, an estimated dispersion parameter is going to be large. E.g.
the data has both 0 cases in 75 person-years and 1000 cases in 5000
person-years for Denmark, and in your model they are supposed to have
the same Poisson rate.

summary.svyglm starts off with

  est.disp - TRUE

and AFAICS there is no way it can get set to FALSE.  Knowing Thomas,
there is probably a perfectly good reason not to just set the dispersion
to 1, but I don't get it either...



Thanks
Laust

# loading survey
library(survey)

# creating data
listc -

c(Denmark,Finland,Norway,Sweden,Denmark,Finland,Norway,Sweden)
listw - c(1,2,1,1,1,1,1,1)
listd - c(0,0,0,0,1000,1000,1000,2000)
listt - c(75,50,90,190,5000,5000,5000,1)
list.cwdt - c(listc, listw, listd, listt)
country -

Re: [R] Use R -- term and logo copyright?

2009-10-13 Thread hadley wickham
 Can I use (a) the logo and/or (b) the slogan for the KCL R workshops?
 I think it is quite clear from my website that this is neither about
 the Springer book series nor about an R user conference.

 No, sorry, the logo/name should be used exclusively for the Springer series
 and the R User Conferences. For the latter see
  http://www.R-project.org/conferences.html

 Hence, the logo of your workshop and preferably also its URL should be
 different. You may use R in the title though and have the usual R logo on
 the workshop page.

You can certainly claim copyright on the logo, but through what right
do you claim ownership of the term useR! ?

Hadley

-- 
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] Creating a list of empty lists

2009-10-13 Thread Romain Francois

On 10/13/2009 03:48 PM, Magnus Torfason wrote:

l = list(list())
 for ( i in sequence(length-1) )
 {
 l = list(unlist(l,recursive=FALSE), list())
 }


About this :

 rep( list(list()), 3 )
[[1]]
list()

[[2]]
list()

[[3]]
list()

Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/BcPw : celebrating R commit #5
|- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc
`- http://tr.im/yw8E : New R package : sos

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


Re: [R] Creating a list of empty lists

2009-10-13 Thread Magnus Torfason

Live and learn ...

Thank you!

On 10/13/2009 9:57 AM, Romain Francois wrote:

On 10/13/2009 03:48 PM, Magnus Torfason wrote:

l = list(list())
 for ( i in sequence(length-1) )
 {
 l = list(unlist(l,recursive=FALSE), list())
 }


About this :

  rep( list(list()), 3 )
[[1]]
list()

[[2]]
list()

[[3]]
list()

Romain



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


Re: [R] Creating a list of empty lists

2009-10-13 Thread Henrique Dallazuanna
Try this:

replicate(3, list())

On Tue, Oct 13, 2009 at 10:48 AM, Magnus Torfason
zulutime@gmail.com wrote:
 Well here is one more brain-teaser related to assigning stuff into a list of
 list. What if I need to create a new list of empty lists? I have actually
 got a solution to this problem:

    l = list(list())
    for ( i in sequence(length-1) )
    {
        l = list(unlist(l,recursive=FALSE), list())
    }

 But it is not very neat to do this in a loop. Are there any cuter ways to do
 this?

 Best,
 Magnus

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


[R] How to calculate average correlation coefficient of a correlation matrix ?

2009-10-13 Thread Amit Kumar
Hi! All,
I have large correlation matrix Cor. I wish to calculate average
correlation coefficient for this matrix.
Is there any function in R to do this?
Thanks in advance.

Amit

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


[R] multivariate multiple nonlinear regression

2009-10-13 Thread Yingyun Liu
Hello, 
I have several dataframes of identical structure. Each dataframe has one
dependent variable and several independent variables. Two different
functions are used to describe the relationships among all the
dataframes. Some parameters that are to be obtained from regression are
shared by all dataframes. Is there a way to do the regression
simultaneously with all dataframes in R? Can nls() do this?
Thanks

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


Re: [R] Nelder-Mead with output of simplex vertices

2009-10-13 Thread Ben Bolker


bartjoosen wrote:
 
 Hi,
 
 Is it possible to share the code on this list?
 I'm also interested (and maybe others to)
 Or are you planning to make a package?
 
 Best regards
 
 Bart
 
 
 
 Ted.Harding-2 wrote:
 
 On 12-Oct-09 13:33:17, Ted Harding wrote:
 On 12-Oct-09 13:24:01, Terry Therneau wrote:
 -- begin included 
 Greetings!
 I want to follow the evolution of a Nelder-Mead function
 minimisation (a function of 2 variables). Hence each simplex
 will have 3 vertices.
 
 Therefore I would like to have a function which can output
 the coordinates of the 3 vertices after each new simplex
 is generated. However, there seems to be no way (which I can
 detect) of extracting this information from optim() (the 'trace'
 argument to 'control' does not seem to have provision for this,
 according to '?optim', and I have tried it out without success).
 
 --- end include -
 
  Why not put a cat() statement into fn, the function that you supply
 which optim is calling?  That will give the vertices that it tries one
 by one.
 
 Terry T.
 
 That's neat and simple! It hadn't occurred to me. Thanks!
 Ted.
 
 And, 10 seconds after posting, I realised why it hadn't -- there
 would be no visible association between the vertex and the simplex
 (in this instance the triangle) that it belongs to.
 
 In other words, which two other points in the preceding sequence,
 along with the current one, make up the triangle being tested?
 
 Given the complexity of the Nelder-Mead process, it would be very
 tricky indeed to try to track this through the sequence of vertices
 which cat() would output.
 
 As it happens, Ben Bolker kindly sent me code which he wrote (see
 his earlier mail) which does do this nicely, since it has an output
 option within the Nelder-Mead routine itself -- at which point,
 the routine itself knows what the simplex is.
 
 Ted.
 
 
 E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
 Fax-to-email: +44 (0)870 094 0861
 Date: 12-Oct-09   Time: 14:45:00
 -- XFMail --
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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 reason I haven't shared is that the code is a translation from
_Numerical Recipes in C_.
Therefore I'm uncertain about its redistribution status.  If it were a
straight transcription
rather than a translation, it would be un-redistributable (I feel bound to
honor Press et al's
redistribution policy, even though it's really annoying: see
http://mingus.as.arizona.edu/~bjw/software/boycottnr.html).  Because it's
a translation of their C implementation of a public-domain
algorithm, it's less clear to me whether this is allowed or not (any
intellectual property
lawyers lurking on the list should feel free to chime in here!); my
compromise is that I'm
willing to send the code on request, but won't post it to the list.  

If people really want an R-only implementation of Nelder-Mead, it would
presumably
take someone not very long to translate from an unencumbered source (the
source code
in R, or the source code in GSL, or the description of the original
algorithm) ...

  cheers
Ben Bolker

-- 
View this message in context: 
http://www.nabble.com/Nelder-Mead-with-output-of-simplex-vertices-tp25838572p25874021.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] SPSS long variable names

2009-10-13 Thread joris meys
Sorry to be so blunt, but I cannot believe PSPP can't save a dataset
as a .csv file for example. That should be the prefered format to
transport a dataset to any other statistical package, including R. csv
files are universal.

Cheers
Joris

On Tue, Oct 13, 2009 at 3:30 PM, Orvalho Augusto orvaq...@gmail.com wrote:
 Thanks for the answer.

 Hmisc uses read.spss from the foreign package. And so it does not
 solve my trouble.

 I need to read the long names on the SPSS dataset.

 Caveman


 On Tue, Oct 13, 2009 at 3:01 PM, John Kane jrkrid...@yahoo.ca wrote:
 library(Hmisc) spss.get may do it but it's been some time since I used it.

 --- On Sat, 10/10/09, Orvalho Augusto orvaq...@gmail.com wrote:

 From: Orvalho Augusto orvaq...@gmail.com
 Subject: [R] SPSS long variable names
 To: r-help@r-project.org
 Received: Saturday, October 10, 2009, 12:14 PM
 Hello guys I am new to this list and
 for R too.

 I am wondering if there is a patch for the SPSS reading
 code on the
 foreign package, in order to be able to read long variable
 names.
 Right now read.spss() just trunc the names to 8
 characters.

 Or if someone could help me on other way:
 I have to process everyday a lot of SPSS Syntax Files and
 Dat files
 that come from one system that can only export data on
 through that
 way.

 I use PSPP to generate the spss data file (sav) that I read
 with R.
 From R I can export to MySQL, DBF and STATA to satisfy
 the needs of
 different guys here.

 The problem is the limit of 8 characters long on variable
 names.

 Can someone help on that?

 Caveman

 __
 R-help@r-project.org
 mailing list
 https://stat.ethz.ch/mailman/listinfo/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 new Internet Explorer® 8 - Faster, safer, easier.  Optimized for Yahoo!  
 Get it Now for Free! at http://downloads.yahoo.com/ca/internetexplorer/


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] How to calculate average correlation coefficient of a correlation matrix ?

2009-10-13 Thread Chuck Cleland
On 10/13/2009 10:13 AM, Amit Kumar wrote:
 Hi! All,
 I have large correlation matrix Cor. I wish to calculate average
 correlation coefficient for this matrix.
 Is there any function in R to do this?
 Thanks in advance.

cormat - cor(iris[,1:4])

corlowtri - cormat[lower.tri(cormat)]

corlowtri
[1] -0.1175698  0.8717538  0.8179411 -0.4284401 -0.3661259  0.9628654

mean(corlowtri)
[1] 0.2900708

mean(abs(corlowtri))
[1] 0.594116

avgcor - function(x){mean(abs(x[lower.tri(x)]))}

avgcor(cor(iris[,1:4]))
[1] 0.594116

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

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

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


Re: [R] SPSS long variable names

2009-10-13 Thread Orvalho Augusto
Thanks guys for the greaty ideia!!

I am fool because I did not realize that before.

Caveman


On Tue, Oct 13, 2009 at 4:41 PM, joris meys jorism...@gmail.com wrote:
 Just for clarity : the csv format will solve your problem, as the
 restrictions on the variable names will only depend on the program you
 use to load them. I never experienced problems with variable names
 using csv to switch datasets between SPlus, R, SAS and SPSS.

 Cheers
 Joris

 On Tue, Oct 13, 2009 at 4:35 PM, joris meys jorism...@gmail.com wrote:
 Sorry to be so blunt, but I cannot believe PSPP can't save a dataset
 as a .csv file for example. That should be the prefered format to
 transport a dataset to any other statistical package, including R. csv
 files are universal.

 Cheers
 Joris

 On Tue, Oct 13, 2009 at 3:30 PM, Orvalho Augusto orvaq...@gmail.com wrote:
 Thanks for the answer.

 Hmisc uses read.spss from the foreign package. And so it does not
 solve my trouble.

 I need to read the long names on the SPSS dataset.

 Caveman


 On Tue, Oct 13, 2009 at 3:01 PM, John Kane jrkrid...@yahoo.ca wrote:
 library(Hmisc) spss.get may do it but it's been some time since I used it.

 --- On Sat, 10/10/09, Orvalho Augusto orvaq...@gmail.com wrote:

 From: Orvalho Augusto orvaq...@gmail.com
 Subject: [R] SPSS long variable names
 To: r-help@r-project.org
 Received: Saturday, October 10, 2009, 12:14 PM
 Hello guys I am new to this list and
 for R too.

 I am wondering if there is a patch for the SPSS reading
 code on the
 foreign package, in order to be able to read long variable
 names.
 Right now read.spss() just trunc the names to 8
 characters.

 Or if someone could help me on other way:
 I have to process everyday a lot of SPSS Syntax Files and
 Dat files
 that come from one system that can only export data on
 through that
 way.

 I use PSPP to generate the spss data file (sav) that I read
 with R.
 From R I can export to MySQL, DBF and STATA to satisfy
 the needs of
 different guys here.

 The problem is the limit of 8 characters long on variable
 names.

 Can someone help on that?

 Caveman

 __
 R-help@r-project.org
 mailing list
 https://stat.ethz.ch/mailman/listinfo/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 new Internet Explorer® 8 - Faster, safer, easier.  Optimized for 
 Yahoo!  Get it Now for Free! at 
 http://downloads.yahoo.com/ca/internetexplorer/


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Nelder-Mead with output of simplex vertices

2009-10-13 Thread bartjoosen

Hi,

Is it possible to share the code on this list?
I'm also interested (and maybe others to)
Or are you planning to make a package?

Best regards

Bart



Ted.Harding-2 wrote:
 
 On 12-Oct-09 13:33:17, Ted Harding wrote:
 On 12-Oct-09 13:24:01, Terry Therneau wrote:
 -- begin included 
 Greetings!
 I want to follow the evolution of a Nelder-Mead function
 minimisation (a function of 2 variables). Hence each simplex
 will have 3 vertices.
 
 Therefore I would like to have a function which can output
 the coordinates of the 3 vertices after each new simplex
 is generated. However, there seems to be no way (which I can
 detect) of extracting this information from optim() (the 'trace'
 argument to 'control' does not seem to have provision for this,
 according to '?optim', and I have tried it out without success).
 
 --- end include -
 
  Why not put a cat() statement into fn, the function that you supply
 which optim is calling?  That will give the vertices that it tries one
 by one.
 
 Terry T.
 
 That's neat and simple! It hadn't occurred to me. Thanks!
 Ted.
 
 And, 10 seconds after posting, I realised why it hadn't -- there
 would be no visible association between the vertex and the simplex
 (in this instance the triangle) that it belongs to.
 
 In other words, which two other points in the preceding sequence,
 along with the current one, make up the triangle being tested?
 
 Given the complexity of the Nelder-Mead process, it would be very
 tricky indeed to try to track this through the sequence of vertices
 which cat() would output.
 
 As it happens, Ben Bolker kindly sent me code which he wrote (see
 his earlier mail) which does do this nicely, since it has an output
 option within the Nelder-Mead routine itself -- at which point,
 the routine itself knows what the simplex is.
 
 Ted.
 
 
 E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
 Fax-to-email: +44 (0)870 094 0861
 Date: 12-Oct-09   Time: 14:45:00
 -- XFMail --
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 

-- 
View this message in context: 
http://www.nabble.com/Nelder-Mead-with-output-of-simplex-vertices-tp25838572p25869383.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] SPSS long variable names

2009-10-13 Thread Robert Baer


- Original Message - 
From: Robert Baer rb...@atsu.edu

To: Orvalho Augusto orvaq...@gmail.com
Sent: Tuesday, October 13, 2009 9:52 AM
Subject: Re: [R] SPSS long variable names



I am wondering if there is a patch for the SPSS reading
code on the
foreign package, in order to be able to read long variable
names.
Right now read.spss() just trunc the names to 8
characters.
This sequence seems to access the long filenames for me if I know what you 
are asking for:


library('foreign')
a-read.spss('fil.sav')
lnames - attr(a,variable.labels,exact=FALSE)

Rob




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


Re: [R] svy / weighted regression

2009-10-13 Thread David Winsemius


On Oct 13, 2009, at 6:07 AM, Laust wrote:


Dear David,

Thanks again for your input! I realize that I did a bad job of
explaining this in my first email, but the setup is that in Finland
persons who die are sampled with a different probability (1) from
those who live (.5). This was done by the Finnish data protection
authorities to protect individuals against identification. In the rest
of the countries everyone is sampled with a probability of 1. The data
that I am supplying to R is summarized data for each country
stratified by case status. Another way of organizing the data would
be:

# creating data
listc - c(Denmark,Finland,Norway,Sweden)
listw - c(1,2,1,1)
listd - c(1000,1000,1000,2000)
listt - c(755000,505000,905000,191)
list.cwdt - c(listc, listw, listd, listt)
country2 -  
data.frame(country=listc,weight=listw,deaths=listd,time=listt)


I hope that it is clearer now that for no value of the independent
variable 'country' is the rate going to be zero.


It is clearer now, and I think you were correct in believing that  
should not have been the problem, so please accept my apologies. The  
denominators and numerators should have been properly summed prior to  
estimation.



I think this was also
not the case in my original example, but this was obscured by my poor
communication-  R-skills. But if data is organized this way then
sampling weight of 2 for Finland should only be applied to the
time-variable that contains person years at risk and *not* to the
number of deaths, which would complicate matters further. I would know
how to get this to work in R or in any other statistical package.




Perhaps it is - as Peter Dalgaard suggested - the estimation of the
dispersion parameter by the survey package that is causing trouble,
not the data example eo ipso. Or perhaps I am just using survey in a
wrong way.


I think it is likely that we are now both using it incorrectly, but my  
efforts are also creating nonsense. From the help page I thought that  
the formula in svydesign might be need to be the country variable ...  
wrong. Or that the weights might need to be the inverse of what you  
had used ...wrong. Or that you ought to use quasipoisson for the  
family  wrong again.


Lumley is preparing a book to accompany the package but that is still  
several months away from release. He and Norm Breslow also published a  
paper very recently in the American Journal of Epidemiology on the  
using of survey sampling for analysis of case-cohort designs (of which  
your problem seems to be an exceedingly simple example, albeit only in  
one of the four strata.) I don't have access to the original paper at  
the moment, but perhaps you are in an academic setting where such  
access would be routine.


Or probably even more efficient would be to shoot a letter to Thomas  
Lumley.


--
David



Best
Laust


Post doc. Laust Mortensen, PhD
Epidemiology Unit
University of Southern Denmark

On Mon, Oct 12, 2009 at 3:32 PM, David Winsemius dwinsem...@comcast.net 
 wrote:
I think you are missing the point. You have 4 zero death counts  
associated
with much higher person years of exposure followed by 4 death  
counts in the
thousands associated with lower degrees of exposures. It seems  
unlikely that
these are real data as there are not cohorts that would exhibit  
such lower
death-rates. So it appears that in setting up your test case, you  
have

created an impossibly unrealistic test problem.

--
David


On Oct 12, 2009, at 9:12 AM, Laust wrote:


Dear Peter,

Thanks for the input. The zero rates in some strata occurs because
sampling depended on case status: In Finland only 50% of the non- 
cases

were sampled, while all others were sampled with 100% probability.

Best
Laust

On Sat, Oct 10, 2009 at 11:02 AM, Peter Dalgaard
p.dalga...@biostat.ku.dk wrote:


Sorry, forgot to reply all...

Laust wrote:


Dear list,

I am trying to set up a propensity-weighted regression using the
survey package. Most of my population is sampled with a sampling
probability of one (that is, I have the full population).  
However, for
a subset of the data I have only a 50% sample of the full  
population.

In previous work on the data, I analyzed these data using SAS and
STATA. In those packages I used a propensity weight of 1/[sampling
probability] in various generalized linear regression- 
procedures, but
I am having trouble setting this up. I bet the solution is  
simple, but

I’m a R newbie. Code to illustrate my problem below.


Hi Laust,

You probably need the package author to explain fully, but as far  
as I
can see, the crux is that a dispersion parameter is being used,  
based on
Pearson residuals, even in the Poisson case (i.e. you effectively  
get

the same result as with quasipoisson()).

I don't know what the rationale is for this, but it is clear that  
with
your data, an estimated dispersion parameter is going to be  
large. E.g.
the data has both 0 cases in 75 person-years and 1000 cases  
in 

Re: [R] How to choose a proper smoothing spline in GAM of mgcv package?

2009-10-13 Thread Simon Wood

 I have 5 datasets. I would like to choose a basis spline with same knots in
 GAM function in order to obtain same basis function for 5 datasets.
 Moreover, the basis spline is used to for an interaction of two covarites.
The `knots' argument to `gam' allows you to fix the knot locations used with a 
basis, and thereby obtain the same basis for each analysis. 


 I used cr in one covariate, but it can only smooth w.r.t 1 covariate. Can
 anyone give me some suggestion about how to choose a proper smoothing
 spline (bs='?') and knots for two covariates?
You can use the tp basis. Again use `knots' to supply the same set of knots 
for each dataset. For the tp basis I would pool you samples and take a 
largish (up to 1000) random sample of covariate pairs to use as the `knots'. 
The tp basis does not use the knot locations directly as knots, but rather 
as the starting point point for finding an optimal eigen-basis for the 
smoother (the only exception is if you supply exactly the same number of 
knots as the basis dimension).  

Alternatively use a tensor product of cr smooths for bivariate smoothing: 
see ?te. Again, supplying the same `knots' for all analyses fixes the basis 
used.


Finally, with some loss of computational efficiency, you can just fit all the 
data at once. Simply combine all the data frames, adding a column containing 
a five level factor variable indicating which original data set the data 
relate to (call it set) then something like:

gam(y~s(x,z,by=set)+set)

will produce one smooth for each level of set. They will all use the same 
basis. You can force them to all have the same smoothing parameter as well 
with something like:

gam((y~s(x,z,by=set,id=1)+set)

The same thing works for `te' terms.

best,
Simon



 Thanks a lot.

 Lee

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

-- 
 Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK
 +44 1225 386603  www.maths.bath.ac.uk/~sw283

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


Re: [R] Function to find prime numbers

2009-10-13 Thread Barry Rowlingson
On Tue, Oct 13, 2009 at 2:41 PM, Thomas Lumley tlum...@u.washington.edu wrote:
 On Tue, 13 Oct 2009, AJ83 wrote:


 I need to create a function to find all the prime numbers in an array. Can
 anyone point me in the right direction?

 This almost sounds like a homework problem to me... So here's a
solution that you can happily present to a tutor - if you can explain
how it works, then you deserve full marks!

primer=function(v){
  
return(regexpr(^1$|^(11+?)\\1+$,unlist(lapply(v,function(z){paste(rep(1,z),sep='',collapse='')})),perl=TRUE)
== -1)
}

Test:

  (1:30)[primer(1:30)]
 [1]  2  3  5  7 11 13 17 19 23 29

I'm not sure how big a number this works for

R golf anyone?

Barry

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


Re: [R] lapply() reccursively

2009-10-13 Thread David Winsemius


On Oct 13, 2009, at 7:33 AM, Kaveh Vakili wrote:



Hi all,

I was wondering whether it is possible to use the lapply() function
to alter the value of the input, something in the spirit of :

a1-runif(100)
a2-function(i){
a1[i]-a1[i-1]*a1[i];a1[i]
}
a3-lapply(2:100,a2)


Neither a1 nor 2:100 are lists, so it would seem that sapply would be  
more appropriate.




Something akin to a for() loop, but using the lapply() infrastructure.
I haven't been able to get rapply() to do this.


You did not specify what the correct answer should look like, but I  
get no error after changing the l to an s and the output is a  
vector rather than a list. I got no error with the lapply version so  
it remains unclear  what problem you are experiencing.


 a1-runif(100)
 a2-function(i){
+ a1[i]-a1[i-1]*a1[i];a1[i]
+ }
 a3-sapply(2:100,a2)
 a3
 [1] 2.990506e-01 2.957213e-02 3.343994e-02 7.234998e-01 2.036053e-01  
1.850228e-01 2.355974e-01 3.295134e-01
 [9] 3.206837e-01 1.073884e-02 1.121334e-02 1.368814e-01 1.381827e-01  
3.426581e-01 3.683766e-01 2.096506e-01

snipped



The reason is that the real a2 function is a difficult function  
that only needs to be evaluated if the value of a1[i-1] meets some  
criteria.


Then maybe you should only apply it when those criteria are met?



Thanks in advance,

__

--

David Winsemius, MD
Heritage Laboratories
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] SPSS long variable names

2009-10-13 Thread Orvalho Augusto
No!

That is variable labels.

Caveman


On Tue, Oct 13, 2009 at 4:52 PM, Robert  Baer rb...@atsu.edu wrote:
 I am wondering if there is a patch for the SPSS reading
 code on the
 foreign package, in order to be able to read long variable
 names.
 Right now read.spss() just trunc the names to 8
 characters.

 This sequence seems to access the long filenames for me if I know what you
 are asking for:

 library('foreign')
 a-read.spss('fil.sav')
 lnames - attr(a,variable.labels,exact=FALSE)

 Rob




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


Re: [R] Counting

2009-10-13 Thread William Dunlap
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Ashta
 Sent: Tuesday, October 13, 2009 5:20 AM
 To: R help
 Subject: [R] Counting
 
 *Hi all,
 *
 
 *Assume that I have the following data set  with tow 
 variables and I want
 count the number of observation with identical values
 *
 
 **
 
 *x1 x2*
 
 * 1   1 *
 
 * 1   0 *
 
 * 0   1*
 
 * 0   1*
 
 * 0   0*
 
 * 1   1*
 
 * 0   1
 *
 
 
 I want the  following output
 **
 
 *
 *
 
 *n1=3  # number of identical observation between x1 and x2 variables*
 
 *n2=4  # number of different observation*

sum() converts TRUE to 1 and FALSE to 0 so the following works
   n1 - sum(x1 == x2)
   n2 - sum(x1 != x2)

You can also use table() to get both numbers in one vector.  In the
following I make table's input a factor (a) to make sure that both the
== and != counts are in the table even if one count is zero and (b)
to put them in the order you asked for, TRUE then FALSE:
  n12 - table(factor(x1==x2, levels=c(TRUE,FALSE)))
  n1 - n12[1]
  n2 - n12[2]

If there may be missing values in the data then you have to decide how
to handle them.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 
 
 How do I do it in R?
 
 
 Thanks a lot
 
 
 
 
 **
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

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


[R] Free Introductory R Course Taught Over the Web

2009-10-13 Thread Paul H Geissler
Free Introductory R Course Taught Over the Web

The course is designed for natural resource managers and is open to all 
who are interested without charge. Audio of the presentations is available 
either using your computer speakers and optional microphone or headset or 
by calling a phone bridge long distance. Live video of the presenter's 
computer screen is available over the web. You can also share your 
computer's screen with other participants when asking a question or making 
a point. An audio and video recording of the presentations and discussion 
will be available on our FTP site after the presentations.  There are no 
specific prerequisites but some knowledge of statistics would be helpful. 
A basic knowledge of computers and the internet will be assumed. 

Please forward this notice to those who may be interested.

The course will start Monday, November 9.  There will be presentations on 
Mondays and Wednesdays, and a lab on Tuesdays for two hours.  The times 
will be: Hawaii 9:00-11:00, Alaska 10:00-12:00, Pacific 11:00-1:00, 
Mountain 12:00-2:00, Central 1:00-3:00, Eastern 2:00-4:00, UTC 7:00-9:00. 
The course will continue until we finish the outline: 2-3 weeks if you 
only continue through the GUI interface (menu) portion, perhaps 6-8 weeks 
including more advanced statistical analyses. 

Links:
You can register at 
http://www.fort.usgs.gov/brdscience/courseRegister.aspx
The course website: http://www.fort.usgs.gov/brdscience/learnR.htm
Last year's course website: 
http://www.fort.usgs.gov/brdscience/learnR08.htm

The course is presented by the US Geological Survey, Status and Trends 
Program (Paul Geissler, paul_geiss...@usgs.gov) and the National Park 
Service, Inventory and Monitoring Program (Tom Philippi, 
tom_phili...@nps.gov).  Please contact us for more information.  Comments 
and suggestions will be very welcome. 

Cheers,
Paul
---
Paul H. Geissler, Ph.D.
USGS Status  Trends of Biological Resources Program
Coordinator, National Park Monitoring Project
Assistant Program Coordinator
USGS Fort Collins Science Center
2150 Centre Ave., Building C
Fort Collins, CO 80526-8118
970-226-9482, FAX 970-226-9452
paul_geiss...@usgs.gov (please do NOT send e-mail to Paul E. Geissler 
pgeiss...@usgs.gov)

It is easy to lie with statistics.
It is hard to tell the truth without statistics.
Andrejs Dunkels, quoted by Maindonald  Braun
[[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] lapply() reccursively

2009-10-13 Thread hadley wickham
 Neither a1 nor 2:100 are lists, so it would seem that sapply would be more
 appropriate.

The difference between lapply and sapply is the output, not the input.

Hadley

-- 
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] SPSS long variable names

2009-10-13 Thread Orvalho Augusto
Sadlly exportation to csv or another format is not implemented yet:
http://www.gnu.org/software/pspp/manual/html_node/Not-Implemented.html

Caveman


On Tue, Oct 13, 2009 at 4:41 PM, joris meys jorism...@gmail.com wrote:
 Just for clarity : the csv format will solve your problem, as the
 restrictions on the variable names will only depend on the program you
 use to load them. I never experienced problems with variable names
 using csv to switch datasets between SPlus, R, SAS and SPSS.

 Cheers
 Joris

 On Tue, Oct 13, 2009 at 4:35 PM, joris meys jorism...@gmail.com wrote:
 Sorry to be so blunt, but I cannot believe PSPP can't save a dataset
 as a .csv file for example. That should be the prefered format to
 transport a dataset to any other statistical package, including R. csv
 files are universal.

 Cheers
 Joris

 On Tue, Oct 13, 2009 at 3:30 PM, Orvalho Augusto orvaq...@gmail.com wrote:
 Thanks for the answer.

 Hmisc uses read.spss from the foreign package. And so it does not
 solve my trouble.

 I need to read the long names on the SPSS dataset.

 Caveman


 On Tue, Oct 13, 2009 at 3:01 PM, John Kane jrkrid...@yahoo.ca wrote:
 library(Hmisc) spss.get may do it but it's been some time since I used it.

 --- On Sat, 10/10/09, Orvalho Augusto orvaq...@gmail.com wrote:

 From: Orvalho Augusto orvaq...@gmail.com
 Subject: [R] SPSS long variable names
 To: r-help@r-project.org
 Received: Saturday, October 10, 2009, 12:14 PM
 Hello guys I am new to this list and
 for R too.

 I am wondering if there is a patch for the SPSS reading
 code on the
 foreign package, in order to be able to read long variable
 names.
 Right now read.spss() just trunc the names to 8
 characters.

 Or if someone could help me on other way:
 I have to process everyday a lot of SPSS Syntax Files and
 Dat files
 that come from one system that can only export data on
 through that
 way.

 I use PSPP to generate the spss data file (sav) that I read
 with R.
 From R I can export to MySQL, DBF and STATA to satisfy
 the needs of
 different guys here.

 The problem is the limit of 8 characters long on variable
 names.

 Can someone help on that?

 Caveman

 __
 R-help@r-project.org
 mailing list
 https://stat.ethz.ch/mailman/listinfo/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 new Internet Explorer® 8 - Faster, safer, easier.  Optimized for 
 Yahoo!  Get it Now for Free! at 
 http://downloads.yahoo.com/ca/internetexplorer/


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Introduction to mark-recapture analysis in R?

2009-10-13 Thread David Winsemius


On Oct 13, 2009, at 8:00 AM, Anne-Katrin Link wrote:


 I was wondering whether there are any good books and/or  
website

links that introduce mark-recapture analysis in R. In particular, I am
interested in exploratory data analysis of resighting data and how to
create capture histories from dataframes in R.

Thank you very much for your reply in advance!


Have you looked at the citations you get in the package that come back  
from the obvious search strategy?


http://search.r-project.org/cgi-bin/namazu.cgi?query=%22capture-recapture%22max=100result=normalsort=scoreidxname=functionsidxname=Rhelp08idxname=views

And I thought I remembered a posting from the author of:

 Ecological Models and Data in R (Hardcover) by Benjamin M. Bolker

 saying that such methods were discussed and exemplified. But I  
cannot find the link to confirm my memory on this point. (And now that  
I check to see if more knowledgeable persons might have already  
answered this, I see that Bolker himself says he doesn't know about  
books, so my memory may have been manufactured.


http://finzi.psych.upenn.edu/R/library/Rcapture/doc/RcaptureJSS.pdf

And I am not a biologist so have no experience on what would be the  
best book.



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


[R] time grid for survfit Survival function outputs

2009-10-13 Thread Muhtar Osman
Dear All,

Maybe it is a silly question. But I wasn't able to find it from manual
or R site search.
I was wondering what is the corresponding time axis for survival
function outputs in survfit. I think it is survfit(...)$time,
but not 100% sure.
If it is, is it possible we could make survival function outputs on
the pre-specified time grid with fixed increment and fixed length.

Thank you so much.

Regards,

MJO

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


Re: [R] SPSS long variable names

2009-10-13 Thread Frank E Harrell Jr

Orvalho Augusto wrote:

Sadlly exportation to csv or another format is not implemented yet:
http://www.gnu.org/software/pspp/manual/html_node/Not-Implemented.html

Caveman


That would not solve the problem anyway because you would not get labels 
and other variable attributes.


Frank




On Tue, Oct 13, 2009 at 4:41 PM, joris meys jorism...@gmail.com wrote:

Just for clarity : the csv format will solve your problem, as the
restrictions on the variable names will only depend on the program you
use to load them. I never experienced problems with variable names
using csv to switch datasets between SPlus, R, SAS and SPSS.

Cheers
Joris

On Tue, Oct 13, 2009 at 4:35 PM, joris meys jorism...@gmail.com wrote:

Sorry to be so blunt, but I cannot believe PSPP can't save a dataset
as a .csv file for example. That should be the prefered format to
transport a dataset to any other statistical package, including R. csv
files are universal.

Cheers
Joris

On Tue, Oct 13, 2009 at 3:30 PM, Orvalho Augusto orvaq...@gmail.com wrote:

Thanks for the answer.

Hmisc uses read.spss from the foreign package. And so it does not
solve my trouble.

I need to read the long names on the SPSS dataset.

Caveman


On Tue, Oct 13, 2009 at 3:01 PM, John Kane jrkrid...@yahoo.ca wrote:

library(Hmisc) spss.get may do it but it's been some time since I used it.

--- On Sat, 10/10/09, Orvalho Augusto orvaq...@gmail.com wrote:


From: Orvalho Augusto orvaq...@gmail.com
Subject: [R] SPSS long variable names
To: r-help@r-project.org
Received: Saturday, October 10, 2009, 12:14 PM
Hello guys I am new to this list and
for R too.

I am wondering if there is a patch for the SPSS reading
code on the
foreign package, in order to be able to read long variable
names.
Right now read.spss() just trunc the names to 8
characters.

Or if someone could help me on other way:
I have to process everyday a lot of SPSS Syntax Files and
Dat files
that come from one system that can only export data on
through that
way.

I use PSPP to generate the spss data file (sav) that I read
with R.
From R I can export to MySQL, DBF and STATA to satisfy
the needs of
different guys here.

The problem is the limit of 8 characters long on variable
names.

Can someone help on that?

Caveman

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





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

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


[R] how to have tkchooseDirectory resize in windows?

2009-10-13 Thread David Gattrell
R-2.8.0  / tcltk8.5
In windows, Rgui.exe has a directory browser that can be resized, but when I
call
tkchooseDirectory(), it is a fixed size.  In linux, when I call
tkchooseDirectory() it
can be resized.
How do I get a windows version that I can resize?

[[alternative HTML version deleted]]

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


Re: [R] how to output profile plots for groups using lattice package

2009-10-13 Thread George Kalema
A million thanks Peter, subsetting fixed it.
George

On Mon, Oct 12, 2009 at 11:51 PM, Peter Ehlers ehl...@ucalgary.ca wrote:

 Hi George,

 Your problem is not with xyplot, but with the NA occurrences in
 your data. Try adding

  subset = {!is.na(MSE)},

 to your xyplot call, or (better), subset the data before
 calling xyplot.

  -Peter Ehlers


 George Kalema wrote:

 Hi Peter (and anyone else willing to help me out),
 Many thanks for your help. Having used your code plus a few other
 modifications, I only get the points plotted but without the two lines. I
 just cannot figure out what the problem is.

 My code is as follows:

 library(lattice)
 datos2 - subset(datos, samplesize != 10  parm != Theta0)
 unq - sort(unique(datos2$samplesize))
 datos2$fsamplesize - factor(datos2$samplesize, labels = paste(Sample
 size =, unq))
 datos2$parm - factor(datos2$parm, levels = c(Intercept, time,
 trt, time*trt))
 tp1.sim - xyplot(MSE ~ ntimes | fsamplesize + parm, group = group, data
 = datos2,
type = b, lty = 1:2, pch = 1:2,
scales = list(x = list(at = c(2, 4, 8, 16)), alternating = 1),
as.table = TRUE, key = list(text = list(c(GNA, PNA)), points =
 list(pch = 1:2))
 )
 plot(tp1.sim)

 I have attached my real dataset (called datos) as well.

 Kind appreciations to your efforts.

 George


 On Wed, Oct 7, 2009 at 9:20 AM, Peter Ehlers ehl...@ucalgary.ca wrote:

  see below

 George Kalema wrote:

  Dear R users,
 I am trying to have an xyplot of a data set which has the following
 variables:
 case (n=10,20,30)
 parameter (parm=a,b)
 group (grp=g1,g2)
 y (y values)
 x (x=2,4,8)

 My plot should be parameter by case such that I have 2 rows (each row=
 each
 parameter) and 3 columns (each column=each case). My R-code is as
 follows
 but I am not able to get what I want to:

 tp1.sim - xyplot(y~ x | case + parm , group=group, data = data, lty =
 1:4
 ,
 pch = 1:4)
 print(tp1.sim)

 How can I have two lines (for g1 and g2) in each plot (each box)?

  include the type=b argument

  How do I label the x-axis with only values 2, 4, 8?
 include the scales= argument or make x a factor

  How do I label each column with the corresponding case number?
 make 'case' a factor

 The following should do what you want:

 xyplot(y ~ x | factor(case) + parm, group=group, data=data,
   type='b', lty=1:2, pch=1:2,
   scales=list(x=list(at=c(2,4,8)))
 )

 I don't understand why you want 4 line types/point chars.

  -Peter Ehlers


  My hypothetical data set is as follows:

 parm x case y group
 a 2 10 0.03 g1
 b 2 10 0.02 g1
 a 4 10 0.03 g1
 b 4 10 0.02 g1
 a 8 10 0.03 g1
 b 8 10 0.02 g1
 a 2 20 0.03 g1
 b 2 20 0.02 g1
 a 4 20 0.03 g1
 b 4 20 0.02 g1
 a 8 20 0.03 g1
 b 8 20 0.02 g1
 a 2 30 0.03 g1
 b 2 30 0.02 g1
 a 4 30 0.03 g1
 b 4 30 0.02 g1
 a 8 30 0.03 g1
 b 8 30 0.02 g1
 a 2 10 0.13 g2
 b 2 10 0.12 g2
 a 4 10 0.13 g2
 b 4 10 0.12 g2
 a 8 10 0.13 g2
 b 8 10 0.12 g2
 a 2 20 0.13 g2
 b 2 20 0.12 g2
 a 4 20 0.13 g2
 b 4 20 0.12 g2
 a 8 20 0.13 g2
 b 8 20 0.12 g2
 a 2 30 0.13 g2
 b 2 30 0.12 g2
 a 4 30 0.13 g2
 b 4 30 0.12 g2
 a 8 30 0.13 g2
 b 8 30 0.12 g2

 Many thanks in advance for your response.

 George

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








-- 

George Williams KALEMA,

Schapenstraat 37/282,
3000 Leuven,
Belgium.

Cell: +32 495 33 13 02


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

2009-10-13 Thread Dmitry Gospodaryov

Dear R developers,How I can build a histogram from matrix:

0 0.5 1

0.25 34 43 65
1 23 35 54
4 22 29 42
10 21 22 29
20 15 17 20

(first string is represented names of columns,
first column is represented names of rows)
where names of columns should be x-axis labels; respectively
to this, I want to have three groups of bars (5 bars in each group)?
Y values should be represented by values given in the core of
matrix. Names of the rows should be in a legend, and should
represent the each of 5 bars (in group) name.
I would also try to build filled contour, however, i can't
ask the program to consider column and rownames like
true values, not only like labels. So, column names should
be the y-values, while row names should be the x-values.
Values placed in the core of matrix should be z-values.

With regard, Dmitry.

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

2009-10-13 Thread Dmitry Gospodaryov

How I can obtain graphics for response surface design,
basing on data:
x: 0.25, 1, 4, 10, 20.
y: 0, 0.5, 1
z1 (for y = 0): 45, 35, 25, 15, 10.
z2 (for y = 0.5): 50, 45, 36, 21, 17.
z3 (for y = 1): 37, 34, 22, 17, 11?
z-values should be scaled in colour (e. g. from red to blue).
I consider to use packages rsm and graphics
(with grDevices). I suggest to use Box-Behnken design
in rsm and filled.contour in graphics. However,
I do not know how I can combain these two opportunities.
I am not familiar in response surface analysis, and able
to be wrong in the selection of the model. Thank you
for any reply. With regard, Dmitry.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] can anybody give suggestion on how to use survreg with 3-parameter weibull

2009-10-13 Thread Josephine Sari
Hi,

 

I am a beginner in R. I would like to know if there is any trick in using
survreg with 3-parameter weibull?

I would like to do survival analysis of failure time but not using the
2-parameter weibull which is available as one of the options in the survreg
but instead I would like to see the result when it is modelled with
3-parameter weibull.

I don't find the syntax. May be I miss the manual/explanation.

 

Thank you in advanced.

 

Best regards,

Josephine Sari


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

2009-10-13 Thread Rosa Manrique
Hi:
I do not know why the function decostand is not found in my vegan library, I 
have downloaded the package recently, and it seems to work well..Do you have 
any suggestion?
Rosa.
[[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] Introduction to mark-recapture analysis in R?

2009-10-13 Thread Jeff Laake
Another package that is not on CRAN or other R depository is RMark.  It 
works with the software MARK which does the computation.  You can find 
RMark at  http://www.phidot.org/software/mark/rmark/

and MARK from http://www.phidot.org/software/mark/index.html
From the same site you'll find a very comprehensive electronic book 
(that describes how to use MARK 
(http://www.phidot.org/software/mark/docs/book/) and it has an appendix 
(http://www.phidot.org/software/mark/docs/book/pdf/app_3.pdf)that 
describes use of RMark.  You may also want to look at the RMark workshop 
notes 
(http://www.phidot.org/software/mark/rmark/RMarkWorkshopNotes.pdf). 
http://www.phidot.org/software/mark/rmark/RMarkWorkshopNotes.pdf


RMark does contain some routines that do CJS and JS models solely in R 
(see ?cjs and ?js) but they are experimental at this point.  RMark was 
not put on CRAN because with the above exceptions it does require MARK 
which is a separate piece of FORTRAN software that runs only in WINDOWS, 
although it possible to obtain a LINUX version with some work.  MARK is 
freely available software as an executable but is not open-source per 
se.  Source for RMark is available from the above sites.


With regard to creating capture histories in R, that is easily 
accomplished with the table function.  For example, if x is a dataframe 
of capture/recapture events with fields ID (unique identifier) and 
Occasion  is a  factor variable for the capture occasion then


chmat=with (x, table(ID,Occasion))

will create a count of captures by ID and Occasion.  If an animal can be 
caught more than once per occasion then add:


chmat[chmat0]=1

Then you can change to capture history strings with:

apply(chmat,1,paste,sep=)

Here is a simple example (with nonsense data)

x=data.frame(ID=floor(10*runif(100))+1,Occasion=floor(5*runif(100))+1)
chmat=with (x, table(ID,Occasion))
chmat[chmat0]=1
ch=apply(chmat,1,paste,collapse=)
table(ch)

If you wanted to include individual covariates you would not use the 
last table(ch) statement but would tie back to any individual data.


regards --jeff






Anne-Katrin Link wrote:
Normal021falsefalse
false
MicrosoftInternetExplorer4  
  

Dear R-helpers,

 I was wondering whether there are any good books and/or website 
links that introduce mark-recapture analysis in R. In particular, I am 
interested in exploratory data analysis of resighting data and how to 
create capture histories from dataframes in R.

Thank you very much for your reply in advance!

 Cheers, 

Anne
  



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Introduction to mark-recapture analysis in R?

2009-10-13 Thread Kingsford Jones
see

https://stat.ethz.ch/pipermail/r-sig-ecology/2008-May/000160.html


hth,
Kingsford

On Tue, Oct 13, 2009 at 6:00 AM, Anne-Katrin Link anne.l...@gmx.de wrote:
 Normal        0        21                        false        false
 false
 MicrosoftInternetExplorer4


 Dear R-helpers,

          I was wondering whether there are any good books and/or website
 links that introduce mark-recapture analysis in R. In particular, I am
 interested in exploratory data analysis of resighting data and how to
 create capture histories from dataframes in R.

 Thank you very much for your reply in advance!

          Cheers,

 Anne
 --
 Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
 sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser

        [[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] lapply() reccursively

2009-10-13 Thread Charles C. Berry

On Tue, 13 Oct 2009, Kaveh Vakili wrote:



Hi all,

I was wondering whether it is possible to use the lapply() function
to alter the value of the input, something in the spirit of :

a1-runif(100)
a2-function(i){
a1[i]-a1[i-1]*a1[i];a1[i]
}
a3-lapply(2:100,a2)

Something akin to a for() loop, but using the lapply() infrastructure.
I haven't been able to get rapply() to do this.


Maybe you want to check out

?Reduce

For the example above, something like

a3 -  Reduce( *, a1, accumulate = TRUE )


HTH,

Chuck



The reason is that the real a2 function is a difficult function that only 
needs to be evaluated if the value of a1[i-1] meets some criteria.

Thanks in advance,

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

2009-10-13 Thread Dieter Menne



PDXRugger wrote:
 
 II just want to create a new object with the first two numerals of the
 data. Not sure why this isnt working, consider the following:
 
 EmpEst$naics=c(238321, 624410, 484121 ,238911, 81, 531110, 621399,
 541613,
 524210 ,236115 ,811121 ,236115 ,236115 ,621610 ,814110 ,812320)
 
 
 EmpEst$naics2-formatC(EmpEst$naics %% 1e2, width=2, flag=, mode
 =integer)
 #RESULT:Warning message:
 #In Ops.factor(EmpEst$naics, 100) : %% not meaningful for factors
 
 

It always good to make a complete example; the above code does not run. If I
do a guess how it could have looked like, there is no warning.

Dieter

# what is empest?
EmpEst = data.frame(x=1:16)
EmpEst$naics=c(238321, 624410, 484121 ,238911, 81, 531110, 621399,
541613,
524210 ,236115 ,811121 ,236115 ,236115 ,621610 ,814110 ,812320)

EmpEst$naics2-formatC(EmpEst$naics %% 1e2, width=2, flag=, mode
=integer)
# no warning

-- 
View this message in context: 
http://www.nabble.com/Selecting-initial-numerals-tp25876664p25876826.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] replacing period with a space

2009-10-13 Thread Dimitri Liakhovitski
Dear R-ers!

I have x as a variable in a data frame x.

x-data.frame(x=c(aa.bb,cc.dd.ee))
x$x-as.character(x$x)
x

I am sorry for such a simple question - but how can I replace all
periods in x$x with spaces?

sub('.', ' ', x$x) - removes all letters to the left of each period...

Thanks a lot for your advice!

-- 
Dimitri Liakhovitski
Ninah.com
dimitri.liakhovit...@ninah.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] replacing period with a space

2009-10-13 Thread Sarah Goslee
As you've discovered, the . means something special in regular
expressions (and R's version of them). You need to escape it with \\:

 x-data.frame(x=c(aa.bb,cc.dd.ee))
 x$x-as.character(x$x)
 x
 x
1aa.bb
2 cc.dd.ee
 sub(\\.,  , x$x)
[1] aa bbcc dd.ee
 gsub(\\.,  , x$x)
[1] aa bbcc dd ee

And to change all, you need gsub() rather than sub().

Sarah

On Tue, Oct 13, 2009 at 1:26 PM, Dimitri Liakhovitski ld7...@gmail.com wrote:
 Dear R-ers!

 I have x as a variable in a data frame x.

 x-data.frame(x=c(aa.bb,cc.dd.ee))
 x$x-as.character(x$x)
 x

 I am sorry for such a simple question - but how can I replace all
 periods in x$x with spaces?

 sub('.', ' ', x$x) - removes all letters to the left of each period...

 Thanks a lot for your advice!




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

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


Re: [R] replacing period with a space

2009-10-13 Thread Henrique Dallazuanna
You need escape the period:

gsub(\\.,  , x$x)

On Tue, Oct 13, 2009 at 2:26 PM, Dimitri Liakhovitski ld7...@gmail.com wrote:
 Dear R-ers!

 I have x as a variable in a data frame x.

 x-data.frame(x=c(aa.bb,cc.dd.ee))
 x$x-as.character(x$x)
 x

 I am sorry for such a simple question - but how can I replace all
 periods in x$x with spaces?

 sub('.', ' ', x$x) - removes all letters to the left of each period...

 Thanks a lot for your advice!

 --
 Dimitri Liakhovitski
 Ninah.com
 dimitri.liakhovit...@ninah.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.




-- 
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] replacing period with a space

2009-10-13 Thread Dimitri Liakhovitski
Thanks a lot for your help, Henrique and Sarah!
Dimitri

On Tue, Oct 13, 2009 at 1:37 PM, Sarah Goslee sarah.gos...@gmail.com wrote:
 As you've discovered, the . means something special in regular
 expressions (and R's version of them). You need to escape it with \\:

 x-data.frame(x=c(aa.bb,cc.dd.ee))
 x$x-as.character(x$x)
 x
         x
 1    aa.bb
 2 cc.dd.ee
 sub(\\.,  , x$x)
 [1] aa bb    cc dd.ee
 gsub(\\.,  , x$x)
 [1] aa bb    cc dd ee

 And to change all, you need gsub() rather than sub().

 Sarah

 On Tue, Oct 13, 2009 at 1:26 PM, Dimitri Liakhovitski ld7...@gmail.com 
 wrote:
 Dear R-ers!

 I have x as a variable in a data frame x.

 x-data.frame(x=c(aa.bb,cc.dd.ee))
 x$x-as.character(x$x)
 x

 I am sorry for such a simple question - but how can I replace all
 periods in x$x with spaces?

 sub('.', ' ', x$x) - removes all letters to the left of each period...

 Thanks a lot for your advice!




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




-- 
Dimitri Liakhovitski
Ninah.com
dimitri.liakhovit...@ninah.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] decostand

2009-10-13 Thread Jorge Ivan Velez
Hi Rosa,
It works for me on an R-fresh session:

 require(vegan)
Loading required package: vegan
This is vegan 1.15-4
 ?decostand
 sessionInfo()
R version 2.9.2 RC (2009-08-23 r49375)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

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

other attached packages:
[1] vegan_1.15-4

Perhaps if you told us your OS and  vegan package's version we might be of
more help.

Best,
Jorge


On Tue, Oct 13, 2009 at 11:06 AM, Rosa Manrique  wrote:

 Hi:
 I do not know why the function decostand is not found in my vegan library,
 I have downloaded the package recently, and it seems to work well..Do you
 have any suggestion?
 Rosa.
[[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] lapply() reccursively

2009-10-13 Thread Kaveh Vakili

Thanks, Chuck's answer is the closest to what i want (gives the same result as 
cumprod()) ...but using this function seems actually slower than the loop (is 
it normal ?):

a1-runif(10)
cadd-function(x) Reduce(*, x, accumulate = TRUE)
looop-function(a1){
j-length(a1)
for(i in 2:j){
a1[i]-a1[i-1]*a1[i]
}
a1
}
 
 system.time(cadd(a1))
   user  system elapsed 
  1.344   0.004   1.353 
 system.time(cumprod(a1))
   user  system elapsed 
  0.004   0.000   0.002 
 system.time(looop(a1))
   user  system elapsed 
  0.772   0.000   0.775 
 


On Tue, 13 Oct 2009, Kaveh Vakili wrote:


 Hi all,

 I was wondering whether it is possible to use the lapply() function
 to alter the value of the input, something in the spirit of :

 a1-runif(100)
 a2-function(i){
 a1[i]-a1[i-1]*a1[i];a1[i]
 }
 a3-lapply(2:100,a2)

 Something akin to a for() loop, but using the lapply() infrastructure.
 I haven't been able to get rapply() to do this.

Maybe you want to check out

  ?Reduce

For the example above, something like

a3 -  Reduce( *, a1, accumulate = TRUE )


HTH,

Chuck


 The reason is that the real a2 function is a difficult function that only 
 needs to be evaluated if the value of a1[i-1] meets some criteria.

 Thanks in advance,

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


[R] How to specify an ARMA(1, [1,4]) model?

2009-10-13 Thread Len Vir
Hi,

I'm trying to model an ARMA(1,[1,4]),
i.e. I want only lags 1 and 4 of the Moving Average part.
It's the '[1,4]' part that is giving me a problem.

I've tried different arma's and arima's in different packages, namely:
packages tseries, fArma, FinTS, timeSeries, TSA, Zelig, ds1, forecast


For example, with package FinTS:

 ( ARIMA(y, order=c(1,0,c(1,4)))  )
Error in arima(x = x, order = order, seasonal = seasonal, xreg = xreg,  :
  'order' must be a non-negative numeric vector of length 3

Using ARIMA(1,0,1) with a seasonal argument for lag 4
does not get me any further.


With package Zelig I got:

 (  zelig(Diff(lppi,1) ~ one + lag.y(1) + lag.eps(1) + lag.eps(4) ,
model=arima  , data=Q)  )
Error in model.frame.default(mf$formula, data) :
  invalid type (list) for variable 'lag.eps(1)'

I get basically the same kind of answers with other packages
and with different configurations.

Thanks for any advice,

len

[[alternative HTML version deleted]]

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


Re: [R] How to specify an ARMA(1, [1,4]) model?

2009-10-13 Thread Duncan Murdoch

On 10/13/2009 2:35 PM, Len Vir wrote:

Hi,

I'm trying to model an ARMA(1,[1,4]),
i.e. I want only lags 1 and 4 of the Moving Average part.
It's the '[1,4]' part that is giving me a problem.

I've tried different arma's and arima's in different packages, namely:
packages tseries, fArma, FinTS, timeSeries, TSA, Zelig, ds1, forecast


For example, with package FinTS:


( ARIMA(y, order=c(1,0,c(1,4)))  )

Error in arima(x = x, order = order, seasonal = seasonal, xreg = xreg,  :
  'order' must be a non-negative numeric vector of length 3

Using ARIMA(1,0,1) with a seasonal argument for lag 4
does not get me any further.


What's wrong with

arima(x, order=c(1,0,1), seasonal=list(order=c(0,0,1), period=4))

using stats::arima?

Duncan Murdoch




With package Zelig I got:


(  zelig(Diff(lppi,1) ~ one + lag.y(1) + lag.eps(1) + lag.eps(4) ,

model=arima  , data=Q)  )
Error in model.frame.default(mf$formula, data) :
  invalid type (list) for variable 'lag.eps(1)'

I get basically the same kind of answers with other packages
and with different configurations.

Thanks for any advice,

len

[[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] replacing period with a space

2009-10-13 Thread Jason Rupert
Here is one more that works:
gsub(., ,Start.Time, fixed = TRUE)

fixed = TRUE really helps in a lot of instances for removing specific 
characters without accidently angering the regular expression gods. 

Enjoy. 



--- On Tue, 10/13/09, Dimitri Liakhovitski ld7...@gmail.com wrote:

 From: Dimitri Liakhovitski ld7...@gmail.com
 Subject: [R] replacing period with a space
 To: R-Help List r-h...@stat.math.ethz.ch
 Date: Tuesday, October 13, 2009, 12:26 PM
 Dear R-ers!
 
 I have x as a variable in a data frame x.
 
 x-data.frame(x=c(aa.bb,cc.dd.ee))
 x$x-as.character(x$x)
 x
 
 I am sorry for such a simple question - but how can I
 replace all
 periods in x$x with spaces?
 
 sub('.', ' ', x$x) - removes all letters to the left of
 each period...
 
 Thanks a lot for your advice!
 
 -- 
 Dimitri Liakhovitski
 Ninah.com
 dimitri.liakhovit...@ninah.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] time grid for survfit Survival function outputs

2009-10-13 Thread David Winsemius


On Oct 13, 2009, at 12:03 PM, Muhtar Osman wrote:


Dear All,

Maybe it is a silly question. But I wasn't able to find it from manual
or R site search.


After library(survival) , the description of survfit objects will be  
found with:


?survfit.object


I was wondering what is the corresponding time axis for survival
function outputs in survfit. I think it is survfit(...)$time,
but not 100% sure.


What makes you doubt this?


If it is, is it possible we could make survival function outputs on
the pre-specified time grid with fixed increment and fixed length.


With the appropriate supply of a dataset, it should be possible   
for various meanings of pre-specified and fixed increment and  
fixed length, all of which at the moment are ambiguous at the  
moment. That is why the Posting Guide strongly suggests both an R  
encoded example and a clear specification of the desired output.




Thank you so much.

Regards,

MJO


--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


[R] Greater than less than in ifelse

2009-10-13 Thread Richardson, Patrick
I'm trying to categorize a continuous variable (yes, I know that's horrible, 
but I'm trying to reproduce some exercises from a textbook) and don't really 
know an efficient way to do this.

I have a data frame that looks like:

   surv_time relapse sex log_WBC rx
1 35   0   11.45  0
2 34   0   11.47  0
3 32   0   12.20  0
4 32   0   12.53  0

And I'm trying to categorize log_WBC into:

(0-2.30) = low
(2.31-3.00)= medium
(3.00) = high

I've used an ifelse statement such as:

anderson$log_WBC - ifelse(anderson$log_WBC2.30,low,anderson$log_WBC)

Is there a way to use greater than less than syntax within the context of 
an ifelse statement? Or can someone point me to a function that will do this 
easier.

Many Thanks,

Patrick

This email message, including any attachments, is for th...{{dropped:6}}

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


Re: [R] Greater than less than in ifelse

2009-10-13 Thread Jorge Ivan Velez
Dear Patrick,
Take a look at ?cut for some ideas.

HTH,
Jorge


On Tue, Oct 13, 2009 at 3:37 PM, Richardson, Patrick  wrote:

 I'm trying to categorize a continuous variable (yes, I know that's
 horrible, but I'm trying to reproduce some exercises from a textbook) and
 don't really know an efficient way to do this.

 I have a data frame that looks like:

   surv_time relapse sex log_WBC rx
 1 35   0   11.45  0
 2 34   0   11.47  0
 3 32   0   12.20  0
 4 32   0   12.53  0

 And I'm trying to categorize log_WBC into:

 (0-2.30) = low
 (2.31-3.00)= medium
 (3.00) = high

 I've used an ifelse statement such as:

 anderson$log_WBC - ifelse(anderson$log_WBC2.30,low,anderson$log_WBC)

 Is there a way to use greater than less than syntax within the context
 of an ifelse statement? Or can someone point me to a function that will do
 this easier.

 Many Thanks,

 Patrick

 This email message, including any attachments, is for ...{{dropped:13}}

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


Re: [R] Greater than less than in ifelse

2009-10-13 Thread Henrique Dallazuanna
Try this:

with(anderson, cut(log_WBC, c(0, 2.3, 3, max(log_WBC)), labels =
c('low', 'medium', 'high')))

On Tue, Oct 13, 2009 at 4:37 PM, Richardson, Patrick
patrick.richard...@vai.org wrote:
 I'm trying to categorize a continuous variable (yes, I know that's horrible, 
 but I'm trying to reproduce some exercises from a textbook) and don't really 
 know an efficient way to do this.

 I have a data frame that looks like:

   surv_time relapse sex log_WBC rx
 1         35       0   1    1.45  0
 2         34       0   1    1.47  0
 3         32       0   1    2.20  0
 4         32       0   1    2.53  0

 And I'm trying to categorize log_WBC into:

 (0-2.30) = low
 (2.31-3.00)= medium
 (3.00) = high

 I've used an ifelse statement such as:

 anderson$log_WBC - ifelse(anderson$log_WBC2.30,low,anderson$log_WBC)

 Is there a way to use greater than less than syntax within the context of 
 an ifelse statement? Or can someone point me to a function that will do this 
 easier.

 Many Thanks,

 Patrick

 This email message, including any attachments, is for th...{{dropped:6}}

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] vis.gam() contour plots

2009-10-13 Thread Gavin Simpson
On Mon, 2009-10-12 at 22:20 -0400, David Winsemius wrote:
 On Oct 12, 2009, at 8:20 PM, Jason Gasper wrote:
snip /
 # contour examples vis.gam(g,  
 view=c(x1,x2),plot.type=contour,color=heat, nlevels=20)
 Warning messages:
 1: In plot.window(...) : nlevels is not a graphical parameter
 2: In plot.xy(xy, type, ...) : nlevels is not a graphical parameter
 3: In axis(side = side, at = at, labels = labels, ...) :
nlevels is not a graphical parameter
 4: In axis(side = side, at = at, labels = labels, ...) :
nlevels is not a graphical parameter
 5: In box(...) : nlevels is not a graphical parameter
 6: In title(...) : nlevels is not a graphical parameter
 
 # This does result in warnings that do not seem correct (since nlevels  
 is listed as a graphics parameter in the help page of contour)

They are correct for a certain definition of graphical parameter, and
'nlevels' is an argument to contour. IIRC this really refers to things
in ?par and is a common issue that I have come across when coding
function that pass some arguments in '...' to other functions and some
to plotting functions. There are ways around this, but I don't have the
details to hand - Prof. Ripley suggested one solution that is used
within base R to get round this problem, and which we subsequently used
in the vegan package.

HTH

G

  but the  
 desired effect seems to be occurring. I have seen such warnings many  
 times before an have learned to ignore them. Whether that is the  
 correct posture to assume, I am not sure.
  Thanks
 
 --
 
 David Winsemius, MD
 Heritage Laboratories
 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.
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

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


Re: [R] decostand

2009-10-13 Thread Gavin Simpson
On Tue, 2009-10-13 at 17:06 +0200, Rosa Manrique wrote:
 Hi:
 I do not know why the function decostand is not found in my vegan
 library, I have downloaded the package recently, and it seems to work
 well..Do you have any suggestion?

Did you load it in your session for use?

Try

library(vegan)

and if that works without error, then try

?decostand

G

 Rosa.
   [[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.
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

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


  1   2   >