Re: [R] Fast nested List-data.frame

2010-01-05 Thread Greg Hirson

Dieter,

I'd approach this by first making a matrix, then converting to a data 
frame with appropriate types. I'm sure there is a way to do it with 
structure in one step. Operations on matrices are usually faster than on 
dataframes.



len - 10
d - replicate(len, list(pH = 3, marker = TRUE, position = A), FALSE)

toDF - function(alist){
d.matrix - matrix(unlist(alist), ncol = 3, byrow = TRUE)
d.df - as.data.frame(d.matrix)
names(d.df) - c('pH', 'marker', 'position')

d.df$pH - as.numeric(d.df$pH)
d.df$marker - as.logical(d.df$marker)
return(d.df)
}

on my system,
system.time(b-toDF(d))

   user  system elapsed
  0.560   0.033   0.592

and

head(b)

  pH marker position
1  1   TRUEA
2  1   TRUEA
3  1   TRUEA
4  1   TRUEA
5  1   TRUEA
6  1   TRUEA

and

sapply(b, class)

   pHmarker  position
numeric logical  factor


I hope this helps,

Greg

sessionInfo()   ##old, I know.
R version 2.9.0 (2009-04-17)
i386-apple-darwin8.11.1

locale:
en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] cimis_0.1-3 RLastFM_0.1-4   RCurl_0.98-1bitops_1.0-4.1  
XML_2.5-3

[6] lattice_0.17-22

loaded via a namespace (and not attached):
[1] grid_2.9.0



On 1/4/10 11:43 PM, Dieter Menne wrote:

I have very large data sets given in a format similar to d below. Converting
these to a data frame is a bottleneck in my application. My fastest version
is given below, but it look clumsy to me.

Any ideas?

Dieter

# ---
len = 10
d = replicate(len, list(pH = 3,marker = TRUE,position = A),FALSE)
# Data are given as d

# preallocate vectors
pH =rep(0,len)
marker =rep(0,len)
position =rep(0,len)

system.time(
{
 for (i in 1:len)
 {
   d1 = d[[i]]
   #Assign to vectors
   pH[i] = d1[[1]]
   marker[i] = d1[[2]]
   position[i] = d1[[3]]
 }
 # combine vectors
 pHAll = data.frame(pH,marker,position)
}
)


   


--
Greg Hirson
ghir...@ucdavis.edu

Graduate Student
Agricultural and Environmental Chemistry

1106 Robert Mondavi Institute North
One Shields Avenue
Davis, CA 95616

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


Re: [R] Fast nested List-data.frame

2010-01-05 Thread Greg Hirson
The as.numeric(d.df$pH) should have been an 
as.numeric(as.character(d.df$pH)).

Sorry for the confusion.

Greg

On 1/5/10 12:33 AM, Greg Hirson wrote:
 Dieter,

 I'd approach this by first making a matrix, then converting to a data 
 frame with appropriate types. I'm sure there is a way to do it with 
 structure in one step, but here it is:

 a - function() {
 len - 10
 d - replicate(len, list(pH = 3, marker = TRUE, position = A), FALSE)
 d.matrix - matrix(unlist(d), ncol = 3, byrow = TRUE)
 d.df - as.data.frame(d)
 names(d.df) - c('pH', 'marker', 'position')

 #d.df$pH - as.numeric(d.df$pH) #incorrect
d.df$pH - as.numeric(as.character(d.df$pH)) #correct
 d.df$marker - as.logical(d.df$marker)
 return(d.df)
 }

 system.time(a)


 On 1/4/10 11:43 PM, Dieter Menne wrote:
 I have very large data sets given in a format similar to d below. Converting
 these to a data frame is a bottleneck in my application. My fastest version
 is given below, but it look clumsy to me.

 Any ideas?

 Dieter

 # ---
 len = 10
 d = replicate(len, list(pH = 3,marker = TRUE,position = A),FALSE)
 # Data are given as d

 # preallocate vectors
 pH =rep(0,len)
 marker =rep(0,len)
 position =rep(0,len)

 system.time(
 {
  for (i in 1:len)
  {
d1 = d[[i]]
#Assign to vectors
pH[i] = d1[[1]]
marker[i] = d1[[2]]
position[i] = d1[[3]]
  }
  # combine vectors
  pHAll = data.frame(pH,marker,position)
 }
 )




 -- 
 Greg Hirson
 ghir...@ucdavis.edu

 Graduate Student
 Agricultural and Environmental Chemistry

 1106 Robert Mondavi Institute North
 One Shields Avenue
 Davis, CA 95616


-- 
Greg Hirson
ghir...@ucdavis.edu

Graduate Student
Agricultural and Environmental Chemistry

1106 Robert Mondavi Institute North
One Shields Avenue
Davis, CA 95616


[[alternative HTML version deleted]]

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


[R] R-package related to the topic of INARMA models

2010-01-05 Thread Feng Li
Dear R,

I am looking for R-package related to INARMA (Integer-valued ARMA). Can
anyone give me some information? I did not get information from task view.

Many thanks.


Feng

-- 
Feng Li
Department of Statistics
Stockholm University
106 91 Stockholm, Sweden
http://feng.li/

[[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] Fast nested List-data.frame

2010-01-05 Thread Dieter Menne


Greg Hirson wrote:
 
 I'd approach this by first making a matrix, then converting to a data 
 frame with appropriate types. 

Well, I knew that matrixes are faster for numerics, but I also knew that the
required conversion to character would be a show-stopper. My second wisdom
was bogus. Your version is 30% faster on my computer.

Dieter

-- 
View this message in context: 
http://n4.nabble.com/Fast-nested-List-data-frame-tp998871p998897.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] Fast nested List-data.frame

2010-01-05 Thread Dieter Menne

This is better by a factor of 4:

len = 10
d = replicate(len, list(pH = 3,marker = TRUE,position = A),FALSE)
system.time(
{
pHAll = data.frame(
  pH = unlist(lapply(d,[[,1)),
  pH = unlist(lapply(d,[[,2)),
  pH = unlist(lapply(d,[[,3)))
}
)

Dieter

-- 
View this message in context: 
http://n4.nabble.com/Fast-nested-List-data-frame-tp998871p998902.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] R-package related to the topic of INARMA models

2010-01-05 Thread Prof Brian Ripley

On Tue, 5 Jan 2010, Feng Li wrote:


Dear R,

I am looking for R-package related to INARMA (Integer-valued ARMA). Can
anyone give me some information? I did not get information from task view.


That's a very specialized topic, and you have not said what you want 
to do with such processes.  I suggest you approach the handful of 
authors of papers on the subject (often called discrete-valued ARMA) 
-- quite possibly none of them work with R.




Many thanks.


Feng

--
Feng Li
Department of Statistics
Stockholm University
106 91 Stockholm, Sweden
http://feng.li/

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



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


Re: [R] xyplot - help with multiple Y's vs. X of a member data in multiple panels

2010-01-05 Thread Santosh
Thanks for your email.. Yes, I am looking for lattice version of matplot...
Attached are some codes for simplicity for rapid testing..Any suggestions
would be highly appreciated...

library(lattice)
dat - data.frame(x = rep(1:10,2),
  y1 = rnorm(20),
  y2=rnorm(20,sd=1.3),
  y3=rnorm(20,sd=0.3),
  gp1 = rep(letters[1:8],each=10),
  gp2=rep(LETTERS[1:4],each=20),
  gp3=rep(c(P,Q),each=40))

pset - simpleTheme(lty = c(0,1,2), col=c(blue,red,green))
xyplot(y1+y2+y3~x|factor(gp3)+factor(gp2),
data=dat,
groups=gp1,
allow.multiple=T,
panel=panel.superpose,
distribute.type=T,
type=c(b,l,l),
par.settings=pset,
strip=strip.custom(strip.names=F,strip.levels=T))

Thanks..
Santosh


On Mon, Jan 4, 2010 at 11:16 PM, Dennis Murphy djmu...@gmail.com wrote:

 Hi:

 I think Santosh wants a Lattice version of matplot. I didn't find anything
 with help.search(), though...

 Dennis


 On Mon, Jan 4, 2010 at 8:14 PM, Santosh santosh2...@gmail.com wrote:

 Hi,
 Thanks for your email..

 Each panel (in a multiple panel) is identified by DS1, DS2  DS3 in the
 dataset sent earlier. I would like an overlay of Y1, Y2  Y3 (each by
 different lines) for each ID in the group. Each ID in the group is
 represented by a color.

 Regards  Thanks,
 Santosh

 On Mon, Jan 4, 2010 at 5:07 PM, Peter Ehlers ehl...@ucalgary.ca wrote:

  Can you clarify how many curves you want in each panel?
  You have 3 Ys and your original email indicated at least
  7 ID values. Do you really want 21 curves in each panel?
  Or do you want separate panels for the Ys?
 
  Re your code: note that, regarding a formula of the
  type y1 + y2 ~ x, ?xyplot says:
 
  This feature cannot be used in conjunction with
  the groups argument.
 
   -Peter Ehlers
 
  Santosh wrote:
 
  Hi Jim and others,
 
  I tried suggestions and somehow the graphs do not seem to be aligned on
  X-axis (i.e. they appear to be shifted on x-axis).. I guess
 panel.xyplot
  or
  panel.superpose is needed? I am not sure what the group variable be
  panel.xyplot, whether it is the ID or the newFactor. I tried
  panel.xyplot(x,y,) with group=ID and group=newFactor and it did not
  work.
 
  Your suggestions would be highly appreciated!!
 
  Regards,
  Santosh
 
  On Thu, Dec 31, 2009 at 6:59 PM, jim holtman jholt...@gmail.com
 wrote:
 
   I am not too sure if this is what you are after, but I just created a
 new
  factor for the panel:
 
  # create a new factor
  d1$newFactor - factor(paste(d1$DS1, +, d1$DS2, +, d1$DS3))
  xyplot(Y1+Y2+Y3~X1|newFactor,data=d1,group=ID)
 
 
  On Thu, Dec 31, 2009 at 6:25 AM, Santosh santosh2...@gmail.com
 wrote:
 
   Dear R experts,
  Wish you all a HAPPY NEW YEAR!
 
  How do I go about plotting (using lattice) overlays of an ID
 (group=ID)
  observed, fitted data in each panel of a multiple panel plot (each
 panel
  identified by DS1 + DS2 + DS3)? x variable is X1 in the
 accompanying
  section of a dataset. each individual is identified by color and Y's
 are
  identified by pch or lty.
 
  I guess the code goes something like the one below, but could not get
  the
  proper use of panel functions
 
  xyplot(Y1+Y2+Y3~X1|DS1+DS2+DS3,data=d1,group=ID,...)...
[[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
  http://www.r-project.org/posting-guide.html
 
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
  --
  Jim Holtman
  Cincinnati, OH
  +1 513 646 9390
 
  What is the problem that you are trying to solve?
 
 
 [[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.
 
 
 
  --
  Peter Ehlers
  University of Calgary
  403.202.3921
 

[[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] Checking for normality and homogeneity of variance

2010-01-05 Thread Alain Zuur


Haiyang AI wrote:
 
 Dear all,
 
 I'm a beginner of R and I need to carry out some three-way mixed ANOVAs.
 Following examples at http://personality-project.org/r/r.anova.html, I
 managed to get the ANOVA part, but I don't know how can I check data
 normality and homogeneity of variance in R (since they're the required
 assumptions of ANOVA analysis).
 
 


No..normality and homogeneity of the data it is not an assumption! It is
normality and homogeneity of the residuals!

See also:
http://www3.interscience.wiley.com/cgi-bin/fulltext/122683826/PDFSTART


Alain



-
Dr. Alain F. Zuur
First author of:

1. Analysing Ecological Data (2007).
Zuur, AF, Ieno, EN and Smith, GM. Springer. 680 p.
URL: www.springer.com/0-387-45967-7


2. Mixed effects models and extensions in ecology with R. (2009).
Zuur, AF, Ieno, EN, Walker, N, Saveliev, AA, and Smith, GM. Springer.
http://www.springer.com/life+sci/ecology/book/978-0-387-87457-9


3. A Beginner's Guide to R (2009).
Zuur, AF, Ieno, EN, Meesters, EHWG. Springer
http://www.springer.com/statistics/computational/book/978-0-387-93836-3


Other books: http://www.highstat.com/books.htm


Statistical consultancy, courses, data analysis and software
Highland Statistics Ltd.
6 Laverock road
UK - AB41 6FN Newburgh
Tel: 0044 1358 788177
Email: highs...@highstat.com
URL: www.highstat.com
URL: www.brodgar.com


-- 
View this message in context: 
http://n4.nabble.com/Checking-for-normality-and-homogeneity-of-variance-tp998821p998923.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] Tranpose and Aggregate Data - now Reshape - cast

2010-01-05 Thread Noli Sicad
library(reshape)

names(harvest.dat) = c(CROP_ID, CROPTYPE, PERIOD,CUT_AGE)

harvest -cast(harvest.dat, CROP_ID + CROPTYPE ~ PERIOD)

It seems that I am getting the frequencies instead of the individual values.

Output
~
   CROP_ID CROPTYPE 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
1 1  OTO 2 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
2 1 SORI 4 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
3 2  OTO 0 6 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
4 2 SORI 0 3 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
5 2 SORM 0 1 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
6 3  OTO 0 0 2 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
7 3 OTRM 0 0 1 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
8 3 SORI 0 0 1 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
9 3 SORM 0 0 1 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
~


Desired table

CROP_ID CROPTYPE P1P2P3P4   P5P6
 P7  P8P9P10
 83  SORI31
 84  SORI32
 85  SORI33
 86  SORI34
 82  SORI28
 83  SORI29
 84  SORI30
 93  SORM35
 62  OTRM30
 82  SORI27
 3   SORM35
 82  SORI26
 4   SORM34
 5   OTRI25
 5   OTRM29
 5   SORM32
 5   SORM33
 5   SORM35
 6   OTRI22
 6   OTRI23
 6   OTRI24
 6   OTRM26
 6   OTRM27
 6   OTRM28
 7   OTRM26
 8   OTRM26

How do I do this properly.

Thanks in advance. Noli

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


Re: [R] xyplot - help with multiple Y's vs. X of a member data in multiple panels

2010-01-05 Thread Felix Andrews
You should reshape the data into a long format, and an easy way to do
that is to use the 'reshape' package:

library(reshape)
mdat - melt(dat, measure.vars = c(y1, y2, y3))

I'm still not sure what you want in the plot. Confusingly, your last
example dropped the ID you referred to earlier, and appears to use
grp1 in the same role.

Maybe something like this:

xyplot(value ~ x | paste(gp2, gp3), mdat,
   groups = paste(variable, gp1), type = l,
   auto.key = list(lines = TRUE, columns = 3),
   par.settings = simpleTheme(col = 1:8, lty = rep(1:3, each = 8)))



2010/1/5 Santosh santosh2...@gmail.com:
 Thanks for your email.. Yes, I am looking for lattice version of matplot...
 Attached are some codes for simplicity for rapid testing..Any suggestions
 would be highly appreciated...

 library(lattice)
 dat - data.frame(x = rep(1:10,2),
                  y1 = rnorm(20),
                  y2=rnorm(20,sd=1.3),
                  y3=rnorm(20,sd=0.3),
                  gp1 = rep(letters[1:8],each=10),
                  gp2=rep(LETTERS[1:4],each=20),
                  gp3=rep(c(P,Q),each=40))

 pset - simpleTheme(lty = c(0,1,2), col=c(blue,red,green))
 xyplot(y1+y2+y3~x|factor(gp3)+factor(gp2),
        data=dat,
        groups=gp1,
        allow.multiple=T,
        panel=panel.superpose,
        distribute.type=T,
        type=c(b,l,l),
        par.settings=pset,
        strip=strip.custom(strip.names=F,strip.levels=T))

 Thanks..
 Santosh


 On Mon, Jan 4, 2010 at 11:16 PM, Dennis Murphy djmu...@gmail.com wrote:

 Hi:

 I think Santosh wants a Lattice version of matplot. I didn't find anything
 with help.search(), though...

 Dennis


 On Mon, Jan 4, 2010 at 8:14 PM, Santosh santosh2...@gmail.com wrote:

 Hi,
 Thanks for your email..

 Each panel (in a multiple panel) is identified by DS1, DS2  DS3 in the
 dataset sent earlier. I would like an overlay of Y1, Y2  Y3 (each by
 different lines) for each ID in the group. Each ID in the group is
 represented by a color.

 Regards  Thanks,
 Santosh

 On Mon, Jan 4, 2010 at 5:07 PM, Peter Ehlers ehl...@ucalgary.ca wrote:

  Can you clarify how many curves you want in each panel?
  You have 3 Ys and your original email indicated at least
  7 ID values. Do you really want 21 curves in each panel?
  Or do you want separate panels for the Ys?
 
  Re your code: note that, regarding a formula of the
  type y1 + y2 ~ x, ?xyplot says:
 
  This feature cannot be used in conjunction with
  the groups argument.
 
   -Peter Ehlers
 
  Santosh wrote:
 
  Hi Jim and others,
 
  I tried suggestions and somehow the graphs do not seem to be aligned on
  X-axis (i.e. they appear to be shifted on x-axis).. I guess
 panel.xyplot
  or
  panel.superpose is needed? I am not sure what the group variable be
  panel.xyplot, whether it is the ID or the newFactor. I tried
  panel.xyplot(x,y,) with group=ID and group=newFactor and it did not
  work.
 
  Your suggestions would be highly appreciated!!
 
  Regards,
  Santosh
 
  On Thu, Dec 31, 2009 at 6:59 PM, jim holtman jholt...@gmail.com
 wrote:
 
   I am not too sure if this is what you are after, but I just created a
 new
  factor for the panel:
 
  # create a new factor
  d1$newFactor - factor(paste(d1$DS1, +, d1$DS2, +, d1$DS3))
  xyplot(Y1+Y2+Y3~X1|newFactor,data=d1,group=ID)
 
 
  On Thu, Dec 31, 2009 at 6:25 AM, Santosh santosh2...@gmail.com
 wrote:
 
   Dear R experts,
  Wish you all a HAPPY NEW YEAR!
 
  How do I go about plotting (using lattice) overlays of an ID
 (group=ID)
  observed, fitted data in each panel of a multiple panel plot (each
 panel
  identified by DS1 + DS2 + DS3)? x variable is X1 in the
 accompanying
  section of a dataset. each individual is identified by color and Y's
 are
  identified by pch or lty.
 
  I guess the code goes something like the one below, but could not get
  the
  proper use of panel functions
 
  xyplot(Y1+Y2+Y3~X1|DS1+DS2+DS3,data=d1,group=ID,...)...
        [[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
  http://www.r-project.org/posting-guide.html
 
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
  --
  Jim Holtman
  Cincinnati, OH
  +1 513 646 9390
 
  What is the problem that you are trying to solve?
 
 
         [[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.
 
 
 
  --
  Peter Ehlers
  University of Calgary
  403.202.3921
 

        [[alternative HTML version deleted]]

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

Re: [R] importing data from BUGS format to R?

2010-01-05 Thread Pseudomonas


Martyn Plummer-2 wrote:
 
 I wrote a function called bugs2jags, which you will find in the coda
 package, for converting WinBUGS data files into the data format used by
 JAGS which is, by no coincidence, the format used by the R function
 dump().
 

First of all excuse me for reviving this very old thread - if it is the
preferred way in this forum/ mailinglist, I will start a new one instead.
I'm a computational biologist programming in C++ and I'm actually not
familiar with R. But I wrote a small program to analyse Win-/OpenBugs output
(CODA) according to this paper:
http://dx.doi.org/10.1016/j.anbehav.2004.08.011 . As I'm working with Mac
and Linux (Kubuntu 9.10 „Karmic Koala“ at the moment) and WINbugs only runs
on Windows natively (as it's name says), I want to switch to JAGS instead.
Now I have the problem to change the WinBugs formatted model and data into
JAGS/R formatted ones, which is quite difficult without knowing the actual
differences between R and S(-PLUS) programming languages. (The latter one
seems to be the basis of WinBugs' format.) I'm not completely sure whether
bugs2jags can be applied to this case, but when I tried to execute it with
the main example from the above mentioned paper (see attachment), it showed
this error message:

 library(coda)
Lade nötiges Paket: lattice
 bugs2jags(WinBugs.txt,Jags.txt)
Fehler in parse(file = file) :
  WinBugs.txt:19:9: Unerwartetes Symbol
18: list(individuals = 5, dyads = 9)
19: ind1[ ] ind2
^


Thank you in anticipation
Sascha Siemann

http://n4.nabble.com/file/n998943/WinBugs.txt WinBugs.txt 
-- 
View this message in context: 
http://n4.nabble.com/importing-data-from-BUGS-format-to-R-tp794525p998943.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] by function ??

2010-01-05 Thread Matthew Dowle

I wrote :
 (some may return vectors, others may return vectors)
Its been pointed out there was a typo, and wasn't very clear anyway. It 
should read '(some may return vectors, others may return scalars)'. I've 
been asked for further explanation so here goes ...

The point I was trying to make is that the following expression is very 
natural to write.  It takes a bit of getting used to though. A reminder of 
the 2 column Dataset (containing a group of 4 rows and a group of 3 rows) 
then the R expression and then the output :

LEAID  ratio
6307 0.720
6307 0.7623810
6307 0.860
6307 0.920
8300 0.5678462
8300 0.770
8300 0.830

the syntax :
Dataset = data.table(Dataset)

Dataset[,DT(ratio,scaled=abs(ratio-median(ratio)),sum=sum(ratio)),by=LEAID]

and the 4 column output :

LEAID  ratio   scaled sum
6307 0.720 0.0911905 3.262381
6307 0.7623810 0.0488095 3.262381
6307 0.860 0.0488095 3.262381
6307 0.920 0.1088095 3.262381
8300 0.5678462 0.2021538 2.167846
8300 0.770 0.000 2.167846
8300 0.830 0.060 2.167846

The 2nd argument (the call to DT()) contains 3 expressions, which are 
executed for each subset of the Dataset grouped by LEAID.  The row order is 
maintained for each subset, and these expressions operate on ordered vectors 
as usual in R. We can use column names as variable names directly (like an 
implicit ?with).  Note that Dataset doesn't have to be ordered by LEAID, but 
it just happens to be in this example.

A comment on each of the 3 expressions (the 3 arguments passed to DT() 
above) is perhaps useful :

ratio :   just repeats the ratio vector as is. You don't have to include 
this but I wanted to keep the input data in the output to demonstrate.

abs(ratio-median(ratio))  :   median() returns a scalar, subtracted from 
each element from ratio, and returns a vector. abs() takes a vector, and 
returns a vector. Standard R and basic stuff. Any R expresssion can be used, 
so its more powerful than SQL in thats sense because SQL is restricted to a 
small set of functions (avg, min, max, etc),  which has been said before and 
been true about R for a long time.  Its the overall syntax of the single 
'query' that I'm trying to demonstrate.

sum(ratio) :  returns a scalar aggregate on the vector input. Thats what I 
meant by others may return scalars.  Notice the the value of sum(ratio) is 
repeated in the final column of the output.  The reason is because at least 
one of the other expressions return vectors, and standard R silent 
repetition rules are coming into play inside DT().

Then the 2 data.table's (one for each of the 2 groups) are combined and a 
single data.table is returned. Very similar to SQL really and some other 
ways to aggregate in R, but more compact, more natural, easier and more 
convenient (and therefore quicker) to write, debug and maintain.


Matthew Dowle mdo...@mdowle.plus.com wrote in message 
news:hgnjev$3h...@ger.gmane.org...
 or if Dataset is a data.table :

 Dataset = data.table(Dataset)
 Dataset[,abs(ratio-median(ratio)),by=LEAID]
 LEAIDV1
 [1,]  6307 0.0911905
 [2,]  6307 0.0488095
 [3,]  6307 0.0488095
 [4,]  6307 0.1088095
 [5,]  8300 0.2021538
 [6,]  8300 0.000
 [7,]  8300 0.060
 rather than :
 Dataset$abs - with(Dataset, ave(ratio, LEAID, 
 FUN=function(x)abs(x-median(x

 This is less code and more natural (to me anyway) e.g. it doesn't require 
 use of function() or ave(). data.table knows that if the j expression 
 returns a vector it should silently repeat the groups to match the length 
 of the j result (which it is doing here).   If the j expression returns a 
 scalar you would just get 2 rows in this example.  Note that the 'by' 
 expression must evaluation to integer, or a list of integer vectors,  so 
 in this case LEAID must either be integer already or coerced to integer 
 using by=as.integer(LEAID).

 To give the aggregate expression a name, just wrap with the DT function. 
 This is also how to return multiple aggregate functions from each subset 
 (some may return vectors, others may return vectors) by listing them 
 inside DT() :

 Dataset[,DT(ratio,scaled=abs(ratio-median(ratio)),sum=sum(ratio)),by=LEAID]
 LEAID ratioscaled  sum
 [1,]  6307 0.720 0.0911905 3.262381
 [2,]  6307 0.7623810 0.0488095 3.262381
 [3,]  6307 0.860 0.0488095 3.262381
 [4,]  6307 0.920 0.1088095 3.262381
 [5,]  8300 0.5678462 0.2021538 2.167846
 [6,]  8300 0.770 0.000 2.167846
 [7,]  8300 0.830 0.060 2.167846


 William Dunlap wdun...@tibco.com wrote in message 
 news:77eb52c6dd32ba4d87471dcd70c8d7000243c...@na-pa-vbe03.na.tibco.com...
 -Original Message-
 From: r-help-boun...@r-project.org
 [mailto:r-help-boun...@r-project.org] On Behalf Of L.A.
 Sent: 

[R] Data Frame Transpose

2010-01-05 Thread Noli Sicad
Hi,

forests - read.csv(C:\\Down2\\R_forestmgt\\forest_cut-Age.csv)

m - forests

fn - function(x) {
  y - t(x[,2])
  data.frame( Croptype=x[1,1], Period =x[1,2], name=colnames(x)[2],
x01=y[,1])x01=y[,1], x02=y[,2], x03=y[,3] } ---Problem
here

m - do.call( rbind, lapply(split(m,list(m$Period,m$Croptype)),fn) )

m - m[order(m$Period,m$Croptype),]


I think I having a problem in here: x01=y[,1])x01=y[,1], x02=y[,2],
x03=y[,3]. how to address with my data. I have variable Period.

based on this http://www.mail-archive.com/r-h...@stat.math.ethz.ch/msg09264.html

P_ID Croptype  Period  Ini_Age  Area_Cut
83  SORI1   31  528.2465512
84  SORI1   32  74.55179899
85  SORI1   33  72.45778618
86  SORI1   34  139.5272947
82  SORI2   28  1.711642933
83  SORI2   29  2.50071
84  SORI2   30  432.5139327
93  ORM2   35  316.8422545
62  OTRM3   30  64.60526438
82  SORI3   27  26.93674606
3   SORM3   35  223.3658345
82  SORI4   26  2.50071
4   SORM4   34  1008.643
5   OTRI5   25  32.42603214
5   OTRM5   29  65.9031344
5   SORM5   32  223.1489321
5   SORM5   33  72.59203041
5   SORM5   35  222.8402746
6   OTRI6   22  2.49851
6   OTRI6   23  3.374626509
6   OTRI6   24  96.13462257
6   OTRM6   26  830.7463641
6   OTRM6   27  731.6228643
6   OTRM6   28  16.3519762
7   OTRM7   26  1636.5693
8   OTRM8   26  553.0050146
9   OTRM9   26  894.414033
10  OTRM10  24  38.72597099
10  OTRM10  25  308.6452707
10  OTRM10  26  786.1761969
10  SORM10  31  235.8360136

To this.

P_ID Croptype P1P2P3P4   P5P6P7
  P8P9P10
83  SORI31
84  SORI32
85  SORI33
86  SORI34
82  SORI28
83  SORI29
84  SORI30
93  SORM35
62  OTRM30
82  SORI27
3   SORM35
82  SORI26
4   SORM34
5   OTRI25
5   OTRM29
5   SORM32
5   SORM33
5   SORM35
6   OTRI22
6   OTRI23
6   OTRI24
6   OTRM26
6   OTRM27
6   OTRM28
7   OTRM26
8   OTRM26
9   OTRM

Thanks in advance. Noli

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Is the Intercept Term always in First Position?

2010-01-05 Thread Viechtbauer Wolfgang (STAT)
Dear All,

I have a question about formulas and model.matrix(). If one specifies a model 
via a formula, the corresponding design matrix can be obtained with the 
model.matrix() function. For example:

x1 - c(1,4,2,3,5)
x2 - c(1,1,2,2,2)
myformula - ~ x1 + factor(x2)
model.matrix(myformula)

My question is: If an intercept term is in the model (like in the example 
above), is it always the first column in resulting design matrix?

For example, if I add the intercept explicitly as the last term in the formula, 
it still ends up in the first column:

myformula - ~ x1 + factor(x2) + 1
model.matrix(myformula)

So, is this always true or is it in principle possible that the intercept 
column ends up somewhere else?

Best,

--
Wolfgang Viechtbauerhttp://www.wvbauer.com/
Department of Methodology and StatisticsTel: +31 (0)43 388-2277
School for Public Health and Primary Care   Office Location:
Maastricht University, P.O. Box 616 Room B2.01 (second floor)
6200 MD Maastricht, The Netherlands Debyeplein 1 (Randwyck)

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

2010-01-05 Thread FMH
Dear All,

Let mod2 and mod3 are two regression equations representing two distinct lines 
and i'm keen to find the intreception point between these two lines 
and the following are part of the codes.

 
     m1 - as.matrix(rbind(coef(mod2), coef(mod3)))
 a - cbind(c(1,1), -m1[, 2])
 b - m1[,1]
     c - solve(a=a,b=b)

 Unfortunately, there is an error message given as stated below and i don't 
understand what it meants for.


' Error in drop(.Call(La_dgesv, a, as.matrix(b), tol, PACKAGE = base)) : 
system is computationally singular: reciprocal condition number = 1.14557e-16'


Could anybody advice me on this matter?

Thank you
Fir




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


Re: [R] Interception point between two lines

2010-01-05 Thread Uwe Ligges



On 05.01.2010 14:37, FMH wrote:

Dear All,

Let mod2 and mod3 are two regression equations representing two distinct lines 
and i'm keen to find the intreception point between these two lines and the 
following are part of the codes.


  m1- as.matrix(rbind(coef(mod2), coef(mod3)))
  a- cbind(c(1,1), -m1[, 2])
  b- m1[,1]
  c- solve(a=a,b=b)

  Unfortunately, there is an error message given as stated below and i don't 
understand what it meants for.


' Error in drop(.Call(La_dgesv, a, as.matrix(b), tol, PACKAGE = base)) :
system is computationally singular: reciprocal condition number = 1.14557e-16'


Could anybody advice me on this matter?


Yes, you cannot compute the intersection if it is (numerically) non 
existant, i.e. coef(mod2), coef(mod3) are almost linear dependent and 
the regression lines are almost parallel.



Uwe Ligges





Thank you
Fir




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Align two protein sequences using BLAST

2010-01-05 Thread Alla Bulashevska

Dear R users,
I would like to align two protein sequences using BLAST
(bl2seq). The question is whether this programm have been
implemented in R.
Thank you for your help,
Alla.

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


Re: [R] R matching lat/lon pairs from two datasets?

2010-01-05 Thread Matthew Dowle
Or if there is a requirement for speed or shorter more convenient syntax 
then there is a data.table join.
Basically setkey(data1,V1,V2) and setkey(data2,V1,V2),  then data1[data2] 
does the merge very quickly. You probably then want to do something with the 
merged data set,  which you just add in like this data1[data2,something] 
or like this data1[data2][,something].  The columns in the key need to 
be either integers, or factors (which are internally integer),  so it would 
be a bit of extra work in this case to store the lat/lon as integer, if 
multiplying by 100 is ok.  Another option for you anyway.

jim holtman jholt...@gmail.com wrote in message 
news:644e1f321001041828n2f2a160etd597ba7a8bf76...@mail.gmail.com...
 couple of approaches:

 merge(data1, data2, by.x=c(V1, V2), by.y=c(V2, V1))
 V1  V2 V3
 1 47.82 -123.75 11
 2 47.82 -123.76  8
 library(sqldf)
 sqldf(select * from data2 x2, data1 x1 where x2.V1=x1.V2 and
 x2.V2=x1.V1)
   V1V2 V3  V1V2
 1 -123.76 47.82  8 -123.76 47.82
 2 -123.75 47.82 11 -123.75 47.82



 On Mon, Jan 4, 2010 at 7:37 PM, Douglas M. Hultstrand
 dmhul...@metstat.comwrote:

 Hello,

 I am trying to match lat/lon from one dataset with the lat/lon from a
 second dataset and use that rows data for calculations.  I am using 
 match,
 but this is finding the first match and not comparing the pair, how can I
 determine if the lat/lon are the same?  See example below.  Is there a
 better way to determine to a matching pair of lat/lon values?

 Example Datasets:
  data2
  V1V2 V3
 1 -123.76 47.82  8
 2 -123.75 47.82 11

  data[1:2]
 V1  V2
 1  47.82 -123.76
 2  47.82 -123.75
 3  47.82 -123.74
 4  47.82 -123.73

 #Subset of current R code :
 lat - data$V1
 lon - data$V2
 yrs - c(1,2,5,10,25,50,100,200,500,1000)
 lon2 - data2$V1
 lat2 - data2$V2
 ppt2 - data2$V3

 for(i in 1:length(lat2)) {
   loc - match(lat2[i],lat)
   loc2 - match(lon2[i], lon)
   print(loc); print(loc2)

   #Need to test to make sure loc equals loc2
   freq_ppt -
 c(data[i,4],data[i,6],data[i,8],data[i,10],data[i,12],data[i,14],data[i,16],data[i,18],data[i,20],data[i,22])
   print(freq_ppt)
   return_value - approx(freq_ppt,yrs,xout=data2[i,3])
   print(return_value)
 }


 Thanks for your help,
 Doug

 --
 -
 Douglas M. Hultstrand, MS
 Senior Hydrometeorologist
 Metstat, Inc. Windsor, Colorado
 voice: 970.686.1253
 email: dmhul...@metstat.com
 web: http://www.metstat.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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




 -- 
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390

 What is the problem that you are trying to solve?

 [[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] Data replacement

2010-01-05 Thread Lisa

Dear all,

I have a question and need your help.

I have a dataset that looks like this: 

 data
 idcode1code2 
1 114 
2 123 
3 244 
4 315 
5 324 
6 411 
7 434 
8 643 
9 622 
10752 
11114 
12132 
13344 
14414 
15432 
16511 
17543 
18714 
19723 
20811 

I want to change some numbers in the columns of “code1” and “code2” based on
“indx” as below

 indx
[[1]]
code 
1  1 
2  3 
3  4 
4  6 
5  8 
[[2]]
code 
1  1 
2  2 
3  4 
4  6 

For example,  for the first ten records (rows) of my dataset, I want to
change 2 to 3, 3 to 4, 4 to 6, and 5 to 8 in both “code1” and “code2”, while
for the last ten records, I want to change 3 to 4 and 4 to 6.

Can anybody please help how to get this done? Thanks a lot in advance

Lisa

-- 
View this message in context: 
http://n4.nabble.com/Data-replacement-tp999060p999060.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] Is the Intercept Term always in First Position?

2010-01-05 Thread Prof Brian Ripley

On Tue, 5 Jan 2010, Viechtbauer Wolfgang (STAT) wrote:


Dear All,

I have a question about formulas and model.matrix(). If one specifies a model 
via a formula, the corresponding design matrix can be obtained with the 
model.matrix() function. For example:

x1 - c(1,4,2,3,5)
x2 - c(1,1,2,2,2)
myformula - ~ x1 + factor(x2)
model.matrix(myformula)

My question is: If an intercept term is in the model (like in the 
example above), is it always the first column in resulting design 
matrix?


For example, if I add the intercept explicitly as the last term in 
the formula, it still ends up in the first column:


myformula - ~ x1 + factor(x2) + 1
model.matrix(myformula)


So, is this always true or is it in principle possible that the 
intercept column ends up somewhere else?


Not in the current implementation, since


terms(~ x1 + factor(x2) + 1)

~ x1 + factor(x2) + 1
attr(,variables)
list(x1, factor(x2))
attr(,factors)
   x1 factor(x2)
x1  1  0
factor(x2)  0  1
attr(,term.labels)
[1] x1 factor(x2)
attr(,order)
[1] 1 1
attr(,intercept)
[1] 1
attr(,response)
[1] 0

it is the intercept attribute which controls the generation of the 
intercept (see ?terms.object).


I can't imagine anyone wanting to change this implementation.

--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] solving cubic/quartic equations non-iteratively

2010-01-05 Thread Mads Jeppe Tarp-Johansen

To R-helpers,

R offers the polyroot function for solving mentioned equations 
iteratively.


However, Dr Math and Mathworld (and other places) show in detail how to
solve mentioned equations non-iteratively.

Do implementations for R that are non-iterative and that solve mentioned 
equations exists?


Regards, Mads Jeppe

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


Re: [R] Align two protein sequences using BLAST

2010-01-05 Thread Tony Chiang
You should send this note to the biconductor mailing list rather than the
R-help. As to your question, please look at the Biostrings bioconductor
package.

On Tue, Jan 5, 2010 at 6:09 AM, Alla Bulashevska 
alla.bullashev...@fdm.uni-freiburg.de wrote:


 Dear R users,
 I would like to align two protein sequences using BLAST
 (bl2seq). The question is whether this programm have been
 implemented in R.
 Thank you for your help,
 Alla.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Align two protein sequences using BLAST

2010-01-05 Thread David Winsemius


On Jan 5, 2010, at 10:46 AM, Tony Chiang wrote:

You should send this note to the biconductor mailing list rather  
than the
R-help. As to your question, please look at the Biostrings  
bioconductor

package.


The BioC webpages give a link to the Gmane archive for searching. A  
search on blast protein sequences produced 15 hits and this one seemed  
to be potentially relevant:


http://article.gmane.org/gmane.science.biology.informatics.conductor/26460/match=blast+protein+sequences

There may be other postings in that group of fifteen with relevant  
material. I just wanted to get you going in the right location, which  
is not this list.


--
David


On Tue, Jan 5, 2010 at 6:09 AM, Alla Bulashevska 
alla.bullashev...@fdm.uni-freiburg.de wrote:



Dear R users,
I would like to align two protein sequences using BLAST
(bl2seq). The question is whether this programm have been
implemented in R.
Thank you for your help,
Alla.

__






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] Data Frame Transpose

2010-01-05 Thread John Kane
Well, if nothing else, you have missing comma.  :)

x01=y[,1]), x01=y[,1], x02=y[,2], x03=y[,3]
  --
 
 fn - function(x) {
   y - t(x[,2])
   data.frame( Croptype=x[1,1], Period =x[1,2],
 name=colnames(x)[2],
 x01=y[,1])x01=y[,1], x02=y[,2], x03=y[,3] }
 ---Problem
 here
 
 m - do.call( rbind,
 lapply(split(m,list(m$Period,m$Croptype)),fn) )
 
 m - m[order(m$Period,m$Croptype),]
 
 
 I think I having a problem in here: x01=y[,1])x01=y[,1],
 x02=y[,2],
 x03=y[,3]. how to address with my data. I have variable
 Period.
 
 based on this 
 http://www.mail-archive.com/r-h...@stat.math.ethz.ch/msg09264.html
 
 P_ID Croptype  Period  Ini_Age  Area_Cut
 83      SORI    1   
    31      528.2465512
 84      SORI    1   
    32      74.55179899
 85      SORI    1   
    33      72.45778618
 86      SORI    1   
    34      139.5272947
 82      SORI    2   
    28      1.711642933
 83      SORI    2   
    29      2.50071
 84      SORI    2   
    30      432.5139327
 93      ORM    2   
    35      316.8422545
 62      OTRM    3   
    30      64.60526438
 82      SORI    3   
    27      26.93674606
 3       SORM    3 
      35      223.3658345
 82      SORI    4   
    26      2.50071
 4       SORM    4 
      34      1008.643
 5       OTRI    5 
      25      32.42603214
 5       OTRM    5 
      29      65.9031344
 5       SORM    5 
      32      223.1489321
 5       SORM    5 
      33      72.59203041
 5       SORM    5 
      35      222.8402746
 6       OTRI    6 
      22      2.49851
 6       OTRI    6 
      23      3.374626509
 6       OTRI    6 
      24      96.13462257
 6       OTRM    6 
      26      830.7463641
 6       OTRM    6 
      27      731.6228643
 6       OTRM    6 
      28      16.3519762
 7       OTRM    7 
      26      1636.5693
 8       OTRM    8 
      26      553.0050146
 9       OTRM    9 
      26      894.414033
 10      OTRM    10   
   24      38.72597099
 10      OTRM    10   
   25      308.6452707
 10      OTRM    10   
   26      786.1761969
 10      SORM    10   
   31      235.8360136
 
 To this.
 
 P_ID Croptype P1        P2   
     P3        P4   
    P5        P6 
   P7
   P8        P9     
   P10
 83      SORI    31
 84      SORI    32
 85      SORI    33
 86      SORI    34
 82      SORI       
     28
 83      SORI       
     29
 84      SORI       
     30
 93      SORM       
     35
 62      OTRM       
             30
 82      SORI       
             27
 3       SORM     
               35
 82      SORI       
                
     26
 4       SORM     
                
       34
 5       OTRI     
                
               25
 5       OTRM     
                
               29
 5       SORM     
                
               32
 5       SORM     
                
               33
 5       SORM     
                
               35
 6       OTRI     
                
                
       22
 6       OTRI     
                
                
       23
 6       OTRI     
                
                
       24
 6       OTRM     
                
                
       26
 6       OTRM     
                
                
       27
 6       OTRM     
                
                
       28
 7       OTRM     
                
                
               26
 8       OTRM     
                
                
                
       26
 9       OTRM
 
 Thanks in advance. Noli
 
 __
 R-help@r-project.org
 mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained,
 reproducible code.
 


  __
Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your 
favourite sites. Download it now
http://ca.toolbar.yahoo.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] solving cubic/quartic equations non-iteratively

2010-01-05 Thread Stavros Macrakis
There are certainly formulas for solving polynomials numerically up to 4th
degree non-iteratively, but you will almost certainly get better results
using iterative methods.

Even the much more trivial formula for the 2nd degree (quadratic) is tricky
to implement correctly and accurately, see:

* George Forsythe, How do you solve a quadratic equation?
* Yves Nievergelt, How (Not) to Solve Quadratic Equations

Hope this helps.

   -s

On Tue, Jan 5, 2010 at 10:11 AM, Mads Jeppe Tarp-Johansen 
s02m...@math.ku.dk wrote:

 To R-helpers,

 R offers the polyroot function for solving mentioned equations iteratively.

 However, Dr Math and Mathworld (and other places) show in detail how to
 solve mentioned equations non-iteratively.

 Do implementations for R that are non-iterative and that solve mentioned
 equations exists?

 Regards, Mads Jeppe

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] solving cubic/quartic equations non-iteratively

2010-01-05 Thread Peter Dalgaard
Mads Jeppe Tarp-Johansen wrote:
 To R-helpers,
 
 R offers the polyroot function for solving mentioned equations iteratively.
 
 However, Dr Math and Mathworld (and other places) show in detail how to
 solve mentioned equations non-iteratively.
 
 Do implementations for R that are non-iterative and that solve mentioned
 equations exists?

As far as I know, we don't even have the quadratic...

They can't be hard to implement, though. However, you may need to take
care that non-iterative solutions are not necessarily more precise or
even faster than iterative ones. There may be cancellation issues and
the closed-form expressions can be complicated and involve slow function
calls.


-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

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


Re: [R] Bar plots with stacked and grouped (juxtaposed) bars together

2010-01-05 Thread John Kane
I have the feeling that you can do this with ggplot2 but why?

You are likely to be much better off using a dotchart.  
?dotchart

--- On Mon, 1/4/10, Elmer Wix elmer.cabekaziruronometu@gmail.com wrote:

 From: Elmer Wix elmer.cabekaziruronometu@gmail.com
 Subject: [R] Bar plots with stacked and grouped (juxtaposed) bars together
 To: r-help@r-project.org
 Received: Monday, January 4, 2010, 10:00 PM
 Using barplot, I can generate stacked
 bars if I pass beside=FALSE.
 
 I can generate grouped (juxtaposed) bars if I pass
 beside=TRUE.
 
 How can I generate stacked and grouped bars together?
 
 __
 R-help@r-project.org
 mailing list
 https://stat.ethz.ch/mailman/listinfo/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] solving cubic/quartic equations non-iteratively

2010-01-05 Thread spencerg

standard square root computation requires an iteration.  Spencer

Peter Dalgaard wrote:

Mads Jeppe Tarp-Johansen wrote:
  

To R-helpers,

R offers the polyroot function for solving mentioned equations iteratively.

However, Dr Math and Mathworld (and other places) show in detail how to
solve mentioned equations non-iteratively.

Do implementations for R that are non-iterative and that solve mentioned
equations exists?



As far as I know, we don't even have the quadratic...

They can't be hard to implement, though. However, you may need to take
care that non-iterative solutions are not necessarily more precise or
even faster than iterative ones. There may be cancellation issues and
the closed-form expressions can be complicated and involve slow function
calls.





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] The output of script is hidden in console

2010-01-05 Thread vtvdung

Hi everyone,
I execute a script with
source(filename)
The script has effect but i don't see the output on console screen.Why?
I'm a newbie. Thanks :handshake:
-- 
View this message in context: 
http://n4.nabble.com/The-output-of-script-is-hidden-in-console-tp999095p999095.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] R session in Compstat' 2010

2010-01-05 Thread Francois Husson

Dear members of the R user community,

I am pleased to inform you that the Compstat'2010 conference (19th 
conference on Computational statistics) will take place in Paris from 
the 22 to the 27th of august.
An R session can be organized during this conference. People have to 
submit a full paper before the 10th of January or a single abstract 
before 23rd of May (you can indicate that you want to be in the R session).
For more information, you can visit the website : 
http://www.compstat2010.fr/


Francois Husson

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


Re: [R] The output of script is hidden in console

2010-01-05 Thread Tom Fletcher
There are probably numerous ways, but one is to add print() to the
functions that you wish to display in the console. 

For example, in your source file, 

Instead of 
summary(x) 

try

print(summary(x))

This should do the trick. 

Tom Fletcher



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of vtvdung
Sent: Tuesday, January 05, 2010 9:42 AM
To: r-help@r-project.org
Subject: [R] The output of script is hidden in console


Hi everyone,
I execute a script with
source(filename)
The script has effect but i don't see the output on console screen.Why?
I'm a newbie. Thanks :handshake:
-- 
View this message in context:
http://n4.nabble.com/The-output-of-script-is-hidden-in-console-tp999095p
999095.html
Sent from the R help mailing list archive at Nabble.com.

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

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


Re: [R] Data replacement

2010-01-05 Thread Dieter Menne



Lisa wrote:
 
 I have a dataset that looks like this: 
 
 data
  idcode1code2 
 1 114 
 2 123 
 3 244 
 ..
 
 I want to change some numbers in the columns of “code1” and “code2” based
 on “indx” as below
 
 indx
 [[1]]
 code 
 1  1 
 2  3 
 3  4 
 For example,  for the first ten records (rows) of my dataset, I want to
 change 2 to 3, 3 to 4, 4 to 6, and 5 to 8 in both “code1” and “code2”,
 while for the last ten records, I want to change 3 to 4 and 4 to 6.
 
 

You might check for recode, for example in package car, or for
transform. You could also do it the quick and dirty way, good to learn
indexing. Be careful if you have NA in your data, or data out of the recode
range.

Dieter


data = data.frame(code1=sample(1:5,10,TRUE),code2=sample(1:5,10,TRUE))
data =
rbind(data,data.frame(code1=sample(1:4,10,TRUE),code2=sample(1:4,10,TRUE)))

# The recode table as  in your example
#indx = list(data.frame(code=c(1,3,4,6,8)),data.frame(code=c(1,2,4,6)))

#easier to read
recode1 = c(1,3,4,6,8)
recode2 = c(1,2,4,6)

data$code1T[1:10] = recode1[data$code1[1:10]]
data$code2T[1:10] = recode1[data$code2[1:10]]

data$code1T[11:20] = recode2[data$code1[11:20]]
data$code2T[11:20] = recode2[data$code2[11:20]]




-- 
View this message in context: 
http://n4.nabble.com/Data-replacement-tp999060p999176.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] Negative binomial

2010-01-05 Thread David Winsemius


On Jan 5, 2010, at 9:38 AM, Stefani Mallia wrote:


Hi,

I'm trying to fit a glm with a negative binomial error distribution  
and a log link, using the example found in the paper Stochastic  
Claims Reserving In General Insurance by England and Verrall.


I am attaching a pdf since it is more difficult to write equations  
in here. So to hopefully explain myself better I wrote a pdf, where  
I'm explaining what I need to do and where I got stuck. (I tried to  
be clear as possible).


In your attachment you suggest (I think) that the ordering of levels  
of the dev factor may be the problem. The methods of rearranging those  
levels in R has always been a bit of a mystery to me, but you may get  
useful information with:


levels(mack$dev)

and you may need to do something like:

mack$dev - relevel(mack$dev, ref=dev1)




Thanks in advance for any help

Stefani


Microsoft Word - Negative Binomial.pdf



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] Negative binomial

2010-01-05 Thread David Winsemius


On Jan 5, 2010, at 12:20 PM, David Winsemius wrote:



On Jan 5, 2010, at 9:38 AM, Stefani Mallia wrote:


Hi,

I'm trying to fit a glm with a negative binomial error distribution  
and a log link, using the example found in the paper Stochastic  
Claims Reserving In General Insurance by England and Verrall.


I am attaching a pdf since it is more difficult to write equations  
in here. So to hopefully explain myself better I wrote a pdf, where  
I'm explaining what I need to do and where I got stuck. (I tried to  
be clear as possible).


In your attachment you suggest (I think) that the ordering of levels  
of the dev factor may be the problem. The methods of rearranging  
those levels in R has always been a bit of a mystery to me, but you  
may get useful information with:


levels(mack$dev)

and you may need to do something like:

mack$dev - relevel(mack$dev, ref=dev1)


Actually that is probably wrong, since I was reading the level label  
off the output of the model which is not how htat factor is  
constructed. So it is more likely to work correctly with:


 mack$dev - relevel(mack$dev, ref=1)  # still untested

--
David






Thanks in advance for any help

Stefani


Microsoft Word - Negative Binomial.pdf



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] mean for subset

2010-01-05 Thread Geoffrey Smith
Hello, does anyone know how to take the mean for a subset of observations?
For example, suppose my data looks like this:

OBS NAME   SCORE
1  Tom   92
2  Tom   88
3  Tom   56
4  James85
5  James75
6  James32
7  Dawn 56
8  Dawn 91
9  Clara 95
10Clara 84

Is there a way to get the mean of the SCORE variable by NAME but only when
the number of observations is equal to 3?  In other words, is there a way to
get the mean of the SCORE variable for Tom and James, but not for Dawn and
Clara?  Thank you.

-- 
Geoffrey Smith
Visiting Assistant Professor
Department of Finance
W. P. Carey School of Business
Arizona State University

[[alternative HTML version deleted]]

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


Re: [R] mean for subset

2010-01-05 Thread Gabor Grothendieck
Have a look at this post and the rest of that thread:

https://stat.ethz.ch/pipermail/r-help/2010-January/223420.html

On Tue, Jan 5, 2010 at 1:29 PM, Geoffrey Smith g...@asu.edu wrote:
 Hello, does anyone know how to take the mean for a subset of observations?
 For example, suppose my data looks like this:

 OBS     NAME   SCORE
 1          Tom       92
 2          Tom       88
 3          Tom       56
 4          James    85
 5          James    75
 6          James    32
 7          Dawn     56
 8          Dawn     91
 9          Clara     95
 10        Clara     84

 Is there a way to get the mean of the SCORE variable by NAME but only when
 the number of observations is equal to 3?  In other words, is there a way to
 get the mean of the SCORE variable for Tom and James, but not for Dawn and
 Clara?  Thank you.

 --
 Geoffrey Smith
 Visiting Assistant Professor
 Department of Finance
 W. P. Carey School of Business
 Arizona State University

        [[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] mean for subset

2010-01-05 Thread Duncan Murdoch

On 05/01/2010 1:29 PM, Geoffrey Smith wrote:

Hello, does anyone know how to take the mean for a subset of observations?
For example, suppose my data looks like this:

OBS NAME   SCORE
1  Tom   92
2  Tom   88
3  Tom   56
4  James85
5  James75
6  James32
7  Dawn 56
8  Dawn 91
9  Clara 95
10Clara 84

Is there a way to get the mean of the SCORE variable by NAME but only when
the number of observations is equal to 3?  In other words, is there a way to
get the mean of the SCORE variable for Tom and James, but not for Dawn and
Clara?  Thank you.
  


You probably want to do it in two steps:  first, find which names have 3 
observations, and take that subset of the dataset; then do the mean on 
all groups.  This is one way:


 counts - table(dataset$NAME)
 keep - names(counts)[counts == 3]
 subset - dataset[ dataset$NAME %in% keep,]
 tapply(subset$SCORE, subset$NAME, mean)
  Clara DawnJames  Tom
 NA   NA 64.0 78.7

Duncan Murdoch

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


Re: [R] mean for subset

2010-01-05 Thread Achim Zeileis

On Tue, 5 Jan 2010, Geoffrey Smith wrote:


Hello, does anyone know how to take the mean for a subset of observations?
For example, suppose my data looks like this:

OBS NAME   SCORE
1  Tom   92
2  Tom   88
3  Tom   56
4  James85
5  James75
6  James32
7  Dawn 56
8  Dawn 91
9  Clara 95
10Clara 84

Is there a way to get the mean of the SCORE variable by NAME but only when
the number of observations is equal to 3?  In other words, is there a way to
get the mean of the SCORE variable for Tom and James, but not for Dawn and
Clara?  Thank you.


You can use tapply() together with a custom function that returns NA if 
the condition is not satisfied, e.g.


## read data
dat - read.table(textConnection(
OBS NAME   SCORE
1  Tom   92
2  Tom   88
3  Tom   56
4  James85
5  James75
6  James32
7  Dawn 56
8  Dawn 91
9  Clara 95
10Clara 84
), header = TRUE)

## use tapply() with custom function
with(dat,
  tapply(SCORE, NAME, function(x) if(length(x) == 3) mean(x) else NA)
)

Alternatively you could look at

mymean -   with(dat, tapply(SCORE, NAME, mean))
mylength - with(dat, tapply(SCORE, NAME, length))
mymean[mylength == 3]

etc.

hth,
Z


--
Geoffrey Smith
Visiting Assistant Professor
Department of Finance
W. P. Carey School of Business
Arizona State University

[[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] Weigths in lm and kruskal_test

2010-01-05 Thread Armin Goralczyk
Is it correct that the weights argument in lm and kruskal_test from
package coin have different meanings?

Example:

library(coin)

set.seed(29)
x - gl(3, 10)
y - rnorm(length(x), mean = c(0, 0, 1)[x])
d - data.frame(y = y, x = x)
w - rep(2, nrow(d)) ### double each obs

### all the same
kruskal_test(y ~ x, data = rbind(d, d))
kruskal_test(y ~ x, data = d[rep(1:nrow(d), w),])
kruskal_test(y ~ x, data = d, weights = ~ w)

anova(lm(y ~ x, data = d[rep(1:nrow(d), w),]))
anova(lm(y ~ x, data = d, weights = w))

-- 
Armin Goralczyk
--
http://www.gwdg.de/~agoralc

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


Re: [R] mean for subset

2010-01-05 Thread Gabor Grothendieck
Here is the solution using sqldf which can do it in one statement:

 # read in data
 Lines - OBS NAME   SCORE
+ 1  Tom   92
+ 2  Tom   88
+ 3  Tom   56
+ 4  James85
+ 5  James75
+ 6  James32
+ 7  Dawn 56
+ 8  Dawn 91
+ 9  Clara 95
+ 10Clara 84

 DF - read.table(textConnection(Lines), header = TRUE)

 # run
 library(sqldf)
 sqldf(select NAME, avg(SCORE) from DF group by NAME having count(*) = 3)
   NAME avg(SCORE)
1 James   64.0
2   Tom   78.7


On Tue, Jan 5, 2010 at 2:03 PM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 Have a look at this post and the rest of that thread:

 https://stat.ethz.ch/pipermail/r-help/2010-January/223420.html

 On Tue, Jan 5, 2010 at 1:29 PM, Geoffrey Smith g...@asu.edu wrote:
 Hello, does anyone know how to take the mean for a subset of observations?
 For example, suppose my data looks like this:

 OBS     NAME   SCORE
 1          Tom       92
 2          Tom       88
 3          Tom       56
 4          James    85
 5          James    75
 6          James    32
 7          Dawn     56
 8          Dawn     91
 9          Clara     95
 10        Clara     84

 Is there a way to get the mean of the SCORE variable by NAME but only when
 the number of observations is equal to 3?  In other words, is there a way to
 get the mean of the SCORE variable for Tom and James, but not for Dawn and
 Clara?  Thank you.

 --
 Geoffrey Smith
 Visiting Assistant Professor
 Department of Finance
 W. P. Carey School of Business
 Arizona State University

        [[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] mean for subset

2010-01-05 Thread Henrique Dallazuanna
Try this:

with(split(DF, with(DF, ave(SCORE, NAME, FUN = length)))[['3']],
tapply(SCORE, NAME[,drop = TRUE], FUN = mean))

Or:

 with(DF, tapply(SCORE, NAME, mean))[table(DF$NAME) == 3]

On Tue, Jan 5, 2010 at 4:29 PM, Geoffrey Smith g...@asu.edu wrote:
 Hello, does anyone know how to take the mean for a subset of observations?
 For example, suppose my data looks like this:

 OBS     NAME   SCORE
 1          Tom       92
 2          Tom       88
 3          Tom       56
 4          James    85
 5          James    75
 6          James    32
 7          Dawn     56
 8          Dawn     91
 9          Clara     95
 10        Clara     84

 Is there a way to get the mean of the SCORE variable by NAME but only when
 the number of observations is equal to 3?  In other words, is there a way to
 get the mean of the SCORE variable for Tom and James, but not for Dawn and
 Clara?  Thank you.

 --
 Geoffrey Smith
 Visiting Assistant Professor
 Department of Finance
 W. P. Carey School of Business
 Arizona State University

        [[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] variable three dimensional array

2010-01-05 Thread Fahim Md
I am using R for my bioinformatics research. I am dealing with a graph in
which I need to find all possible path. I was looking for some package that
solve my purpose
but all in vain. There are available algorithms but most of them find
shortest path that ignore other paths So I decided to write my own from
scratch.


I need to create a two dimensional matrix of size nXn.
The element of each entry may contain (node,edge) pair in the form of
bit-vector.

eg. (mat is the matrix)
mat[1,1] = NULL
mat[1,2] = {1, 1100}  #first entry is node vector and second
entry is edge vector
mat[1,3] = {{01000, 01001000}, {00100, 0110}} #Here there are two
node-edge pair. There can be more also, so it is variable.

In other sense it can be said that, the matrix is a 3-d matrix with a
variable third dimension.

I tried the problem with list but I was partially succesful.

Any suggestion in this regard will be highly appreciated.
thanks


---Fahim
Louisville, KY, USA

[[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] Usage of weights in kruskal_test from package coin

2010-01-05 Thread Armin Goralczyk
With this email I will be following up on this (some months old) post:

http://tolstoy.newcastle.edu.au/R/e7/help/09/06/0799.html

From this I would assume that the following is also valid:

set.seed(29)
x - gl(3, 10)
y - rnorm(length(x), mean = c(0, 0, 1)[x])
d - data.frame(y = y, x = x)
# w - rep(2, nrow(d)) ### double each obs
w - rep(c(1,5), nrow(d)/2)

kruskal_test(y ~ x, data = d[rep(1:nrow(d), w),]) # should be the same as
kruskal_test(y ~ x, data = d, weights = ~ w)

But the tests are not the same. Am I wrong somewhere here?

-- 
Armin Goralczyk
--
http://www.gwdg.de/~agoralc

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


Re: [R] Unwanted association between a function and a namespace

2010-01-05 Thread Patrick Connolly
On Thu, 24-Dec-2009 at 02:14PM +1300, Patrick Connolly wrote:

ly way I found to get round the problem was to make an
| additional function Summarize in the same place.  It involves editing
| any old scripts/functions before they work, but work they do.

In case anyone was following this thread, I solved the problem by
overwriting the summarize function with the Summarize function.

summarize - Summarize

Then copied that to the appropriate directory.  Now all my previous
code still works unmodified.  End of problem -- though I'm still
mystified as to how it arose in the first place.


-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~}   Great minds discuss ideas
 _( Y )_ Average minds discuss events 
(:_~*~_:)  Small minds discuss people  
 (_)-(_)  . Eleanor Roosevelt
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

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


Re: [R] The output of script is hidden in console

2010-01-05 Thread Bert Gunter
R FAQ 7.16. 

R Newbies should read this first (+the FAQ for Windows, if appropriate)
_before_ posting questions to the list.

Bert Gunter
Genentech Nonclinical Biostatistics
 
 
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Tom Fletcher
Sent: Tuesday, January 05, 2010 9:15 AM
To: vtvdung; r-help@r-project.org
Subject: Re: [R] The output of script is hidden in console

There are probably numerous ways, but one is to add print() to the
functions that you wish to display in the console. 

For example, in your source file, 

Instead of 
summary(x) 

try

print(summary(x))

This should do the trick. 

Tom Fletcher



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of vtvdung
Sent: Tuesday, January 05, 2010 9:42 AM
To: r-help@r-project.org
Subject: [R] The output of script is hidden in console


Hi everyone,
I execute a script with
source(filename)
The script has effect but i don't see the output on console screen.Why?
I'm a newbie. Thanks :handshake:
-- 
View this message in context:
http://n4.nabble.com/The-output-of-script-is-hidden-in-console-tp999095p
999095.html
Sent from the R help mailing list archive at Nabble.com.

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

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Naming functions for the purpose of profiling

2010-01-05 Thread Magnus Torfason

Hi all,

I have some long-running code that I'm trying to profile. I am seeing a 
lot of time spent inside the Anonymous function. Of course, this can 
in fact be any of several functions, but I am unable to see how I could 
use the information from Rprof.out to discern which function is taking 
the most time. An example line from my Rprof.out is:


rbernoulli Anonymous runOneRound FUN lapply sfLapply doTryCatch 
tryCatchOne tryCatchList tryCatch try eval.with.vis eval.with.vis source


In my case, the Anonymous functions seem to be any of several 
work-horse functions, that are part of a list, and different cases are 
dispatched to different functions. I could of course get them all out of 
the list and rewrite the dispatch code, but that does not seem like a 
neat way do address this. So I am wondering if there is any way to 
explicitly set the name of a function in a way that leads to it being 
picked up by the profiler?


The same problem seems to apply to Anonymous functions that are 
generated on the fly in an apply call or elsewhere.


Of course, having source files and line numbers included in the 
profiling output would solve this issue, but it seems to me that R 
probably does not have any awareness of where a function was written 
down (and of course, even the text of a function can be constructed 
dynamically within a program). So I guess that is not a viable approach.


Thanks in advance for any help on this, and any pointers on the best 
references for advanced profiling issues would be appreciated as well (I 
know of summaryRprof of course, but it can be difficult to get the full 
picture from the summaryRprof output if the calling structure is 
complicated).


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] Data replacement

2010-01-05 Thread Lisa

Thank you for your kind help. Your R script works well.

Lisa



Dieter Menne wrote:
 
 
 
 Lisa wrote:
 
 I have a dataset that looks like this: 
 
 data
  idcode1code2 
 1 114 
 2 123 
 3 244 
 ..
 
 I want to change some numbers in the columns of “code1” and “code2” based
 on “indx” as below
 
 indx
 [[1]]
 code 
 1  1 
 2  3 
 3  4 
 For example,  for the first ten records (rows) of my dataset, I want to
 change 2 to 3, 3 to 4, 4 to 6, and 5 to 8 in both “code1” and “code2”,
 while for the last ten records, I want to change 3 to 4 and 4 to 6.
 
 
 
 You might check for recode, for example in package car, or for
 transform. You could also do it the quick and dirty way, good to learn
 indexing. Be careful if you have NA in your data, or data out of the
 recode range.
 
 Dieter
 
 
 data = data.frame(code1=sample(1:5,10,TRUE),code2=sample(1:5,10,TRUE))
 data =
 rbind(data,data.frame(code1=sample(1:4,10,TRUE),code2=sample(1:4,10,TRUE)))
 
 # The recode table as  in your example
 #indx = list(data.frame(code=c(1,3,4,6,8)),data.frame(code=c(1,2,4,6)))
 
 #easier to read
 recode1 = c(1,3,4,6,8)
 recode2 = c(1,2,4,6)
 
 data$code1T[1:10] = recode1[data$code1[1:10]]
 data$code2T[1:10] = recode1[data$code2[1:10]]
 
 data$code1T[11:20] = recode2[data$code1[11:20]]
 data$code2T[11:20] = recode2[data$code2[11:20]]
 
 
 
 
 

-- 
View this message in context: 
http://n4.nabble.com/Data-replacement-tp999060p999342.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Multivariate Poisson GLM??

2010-01-05 Thread Corey Sparks
Dear R Users,
I'm working on a problem where I have a multivariate response vector of
counts and a continuous predictor.
 I've thought about doing this the same way you would do a Multvariate
regression model with normally distributed data, but since these data are
counts, they are probably better modeled with a Poisson distribution.

For example
y1-rpois(100,3.5)
y2-rpois(100,1.5)
y3-rpois(100,.09)
x-rnorm(100, mean=25, sd=10)
dat-data.frame(y1, y2, y3, x)

#Get the Multivariate linear model assuming normality
fit-lm(cbind(y1,y2,y3)~x, data=dat)
fit.0-update(fit, ~1)
#Calculate Pillai's trace for global model test
anova(fit, fit.0)

But, if I try this approach with glm() instead of lm(), I get the error
indicating that a multivariate response vector isn't allowed in glm

fit.pois-glm(cbind(y1,y2,y3)~x, data=dat, family=poisson)
Error: (subscript) logical subscript too long

If anyone has experience with a multivariate Poisson response vector I would
gladly appreciate any suggestions.
Corey Sparks

-- 
Corey Sparks
Assistant Professor
Department of Demography and Organization Studies
University of Texas at San Antonio
501 West Durango Blvd
Monterey Building 2.270C
San Antonio, TX 78207
210-458-3166
corey.sparks 'at' utsa.edu
https://rowdyspace.utsa.edu/users/ozd504/www/index.htm

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


[R] why is object.size is more for constant numeric vector?

2010-01-05 Thread Utkarsh Singhal
Hi All,

I ran the following lines in R:

print(object.size(a - rep(1,10^6)),units=Mb)
print(object.size(a - rep(3.542,10^6)),units=Mb)

print(object.size(b - rep(x,10^6)),units=Mb)
print(object.size(b - rep(xyzxyz xyz,10^6)),units=Mb)
print(object.size(b - 1:10^6),units=Mb)
print(object.size(b - rep(1:10,each=10^5)),units=Mb)
print(object.size(b - rep(TRUE,10^6)),units=Mb)

The object size from first two lines is 7.6 MB, but from the last five it is
3.8 MB, although the length of vector is same.

Apparently, the size of any vector of a given length is twice if the vector
is numeric constant than if it is not.

Why is it so? Is my observation wrong? Or, is there some catch with
'object.size'?

Thanks in advance.
Regards
Utkarsh

[[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] why is object.size is more for constant numeric vector?

2010-01-05 Thread Gabor Grothendieck
Note this:

 class(rep(1, 3))
[1] numeric
 class(1:3)
[1] integer


On Tue, Jan 5, 2010 at 3:16 PM, Utkarsh Singhal utkarsh@gmail.com wrote:
 Hi All,

 I ran the following lines in R:

 print(object.size(a - rep(1,10^6)),units=Mb)
 print(object.size(a - rep(3.542,10^6)),units=Mb)

 print(object.size(b - rep(x,10^6)),units=Mb)
 print(object.size(b - rep(xyzxyz xyz,10^6)),units=Mb)
 print(object.size(b - 1:10^6),units=Mb)
 print(object.size(b - rep(1:10,each=10^5)),units=Mb)
 print(object.size(b - rep(TRUE,10^6)),units=Mb)

 The object size from first two lines is 7.6 MB, but from the last five it is
 3.8 MB, although the length of vector is same.

 Apparently, the size of any vector of a given length is twice if the vector
 is numeric constant than if it is not.

 Why is it so? Is my observation wrong? Or, is there some catch with
 'object.size'?

 Thanks in advance.
 Regards
 Utkarsh

        [[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] solving cubic/quartic equations non-iteratively

2010-01-05 Thread Carl Witthoft

quote:
There are certainly formulas for solving polynomials numerically up to 
4th degree non-iteratively, but you will almost certainly get better 
results using iterative methods.

endquote

I must be missing something here.  Why not use the analytic formulas for 
polynomials below 5th degree?  Once you do so, your answer is as precise 
as the level of precision you enter for the coefficients.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] bootstrapping a matrix and calculating Pearson's correlation coefficient

2010-01-05 Thread Lee William
Hi All,
I have got matrix 'data' of dimension 22000x600. I want to make 50
independent samples of dimension 22000x300 from the original matrix 'data'.
And then want to calculate pearsons CC for each of the obtained 50 matrices.
It seems it is possible to do this using 'boot' function from library boot
but I am not able to figure out how? I am really stuck. Please help!

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


Re: [R] model simplification using Crawley as a guide

2010-01-05 Thread hpdutra

So here is some information that I hope gets criticized by the
higher-intelligences that posted on this topic. Beware that I'm not a
statistician and I'm just saying about what I think is correct.

First, before fitting any model, check the distribution of your data, in
some cases a simple anova is way better than a very complicated model, after
you tried some data transformations or simply realizing that you can't fit
the model because it has a unique distribution then you might consider more
complicates options such as general linear models or mixed models, in that
case Hadley's information comes handy, check your residuals, plot your
models and see what kind of insight you get from it, this way you can move
to more complicated models. After you find a model that fits your data then
you can start thinking about simplifying it. Crawley's approach of
simplifying your model by dropping the non-significant interactions has been
slammed here but quite honestly it is still used (I'm not saying it is
correct though) and I don't see how drop1 from Peter Dalgaard is much better
(again I'm not saying that it isn't but I just lack the knowledge to explain
the benefits). 
Ben Bolker et al wrote a very good paper on how to make model simplication
(check Trends in Ecology Evolution 24:3). At least in ecology AIC seems to
be the most used methodology for model simplication. Meaning that people
simplify their overparameterized models (with all co-variables they could
get)  just looking at AIC and then report the p-values. How is that any
different from a stepwise approach I don't know and probably that is the
reason why Crawley's approach is heavily criticized.  

Often times people mix the AIC approach with the traditional frequentist
approach (p values). If I get it right from the workshop that I took with
David Anderson this approach is considered to be wrong and if you decide to
simplify your models based on AIC then you should use model averaging
instead of just reporting what was significant. 

My impression is that you are usually better off using a simple analysis
that you understand what is going on have enough scientific background to
support your statistical inference than using a super elaborated model with
lots of variables and fancy stats that you don't master all the shortcomings
of analysis. Sometimes less is more, but hey studying harder (especially
stats) can pay off (better publications). 

PS: I wish there was a book on Ecological Experiments (I am sure there is)
explaining more modern approaches to analyze factorial experiments,
Crawley's book is a good start but it is too simplistic sometimes, I haven't
seen Bolker's book yet so I'm not sure it cover's experiments, it certainly
would be awesome if he made his course on Modeling Ecological data available
on the youtube. 




Jim Lemon wrote:
 
 Peter Dalgaard wrote:
 ...
 That'll be anti-hist()-amine, I presume?
 
 I would think p-necillin a more appropriate treatment.
 
 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://n4.nabble.com/model-simplification-using-Crawley-as-a-guide-tp858580p999459.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] zero-fill absent data

2010-01-05 Thread Dan Kortschak
Hello,

I have a set of data frames, generated by an SQL query that I am working
with. Because of the way the query was written, zero values for the
dependent variable (V2 in the example) are not recorded. Up until now
this has not been a problem.

I would like to be able to fill all absent data with 0. 

Current state of data (e.g.):
 frame-as.data.frame(cbind(c(1:2,5:7),c(0.5,0.2,1,1.6,2)))
 frame
  V1  V2
1  1 0.5
2  2 0.2
3  5 1.0
4  6 1.6
5  7 2.0

So that frame returns:

  V1  V2
1  1 0.5
2  2 0.2
3  3 0.0
4  4 0.0
5  5 1.0
6  6 1.6
7  7 2.0


Since absent data may be beyond the last recorded point I'd like to be
able to use a terminating 0 

 frame-as.data.frame(cbind(c(1:2,5:7,10),c(0.5,0.2,1,1.6,2,0)))
 frame
  V1  V2
1  1 0.5
2  2 0.2
3  5 1.0
4  6 1.6
5  7 2.0
6 10 0.0

So that values 7V110 are zero filled.

Can anyone suggest a method to do this?

thank you for your time.
Dan

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


Re: [R] xyplot - help with multiple Y's vs. X of a member data in multiple panels

2010-01-05 Thread Santosh
Hi.. thanks for the tips.. that variation works. How can I control pch,
lty and col for each member (gp1) in the group (paste(gp2, gp3))?
Regards,Santosh

On Tue, Jan 5, 2010 at 2:15 AM, Felix Andrews fe...@nfrac.org wrote:

 You should reshape the data into a long format, and an easy way to do
 that is to use the 'reshape' package:

 library(reshape)
 mdat - melt(dat, measure.vars = c(y1, y2, y3))

 I'm still not sure what you want in the plot. Confusingly, your last
 example dropped the ID you referred to earlier, and appears to use
 grp1 in the same role.

 Maybe something like this:

 xyplot(value ~ x | paste(gp2, gp3), mdat,
   groups = paste(variable, gp1), type = l,
   auto.key = list(lines = TRUE, columns = 3),
   par.settings = simpleTheme(col = 1:8, lty = rep(1:3, each = 8)))



 2010/1/5 Santosh santosh2...@gmail.com:
  Thanks for your email.. Yes, I am looking for lattice version of
 matplot...
  Attached are some codes for simplicity for rapid testing..Any suggestions
  would be highly appreciated...
 
  library(lattice)
  dat - data.frame(x = rep(1:10,2),
   y1 = rnorm(20),
   y2=rnorm(20,sd=1.3),
   y3=rnorm(20,sd=0.3),
   gp1 = rep(letters[1:8],each=10),
   gp2=rep(LETTERS[1:4],each=20),
   gp3=rep(c(P,Q),each=40))
 
  pset - simpleTheme(lty = c(0,1,2), col=c(blue,red,green))
  xyplot(y1+y2+y3~x|factor(gp3)+factor(gp2),
 data=dat,
 groups=gp1,
 allow.multiple=T,
 panel=panel.superpose,
 distribute.type=T,
 type=c(b,l,l),
 par.settings=pset,
 strip=strip.custom(strip.names=F,strip.levels=T))
 
  Thanks..
  Santosh
 
 
  On Mon, Jan 4, 2010 at 11:16 PM, Dennis Murphy djmu...@gmail.com
 wrote:
 
  Hi:
 
  I think Santosh wants a Lattice version of matplot. I didn't find
 anything
  with help.search(), though...
 
  Dennis
 
 
  On Mon, Jan 4, 2010 at 8:14 PM, Santosh santosh2...@gmail.com wrote:
 
  Hi,
  Thanks for your email..
 
  Each panel (in a multiple panel) is identified by DS1, DS2  DS3 in
 the
  dataset sent earlier. I would like an overlay of Y1, Y2  Y3 (each by
  different lines) for each ID in the group. Each ID in the group is
  represented by a color.
 
  Regards  Thanks,
  Santosh
 
  On Mon, Jan 4, 2010 at 5:07 PM, Peter Ehlers ehl...@ucalgary.ca
 wrote:
 
   Can you clarify how many curves you want in each panel?
   You have 3 Ys and your original email indicated at least
   7 ID values. Do you really want 21 curves in each panel?
   Or do you want separate panels for the Ys?
  
   Re your code: note that, regarding a formula of the
   type y1 + y2 ~ x, ?xyplot says:
  
   This feature cannot be used in conjunction with
   the groups argument.
  
-Peter Ehlers
  
   Santosh wrote:
  
   Hi Jim and others,
  
   I tried suggestions and somehow the graphs do not seem to be aligned
 on
   X-axis (i.e. they appear to be shifted on x-axis).. I guess
  panel.xyplot
   or
   panel.superpose is needed? I am not sure what the group variable
 be
   panel.xyplot, whether it is the ID or the newFactor. I tried
   panel.xyplot(x,y,) with group=ID and group=newFactor and it did
 not
   work.
  
   Your suggestions would be highly appreciated!!
  
   Regards,
   Santosh
  
   On Thu, Dec 31, 2009 at 6:59 PM, jim holtman jholt...@gmail.com
  wrote:
  
I am not too sure if this is what you are after, but I just created
 a
  new
   factor for the panel:
  
   # create a new factor
   d1$newFactor - factor(paste(d1$DS1, +, d1$DS2, +, d1$DS3))
   xyplot(Y1+Y2+Y3~X1|newFactor,data=d1,group=ID)
  
  
   On Thu, Dec 31, 2009 at 6:25 AM, Santosh santosh2...@gmail.com
  wrote:
  
Dear R experts,
   Wish you all a HAPPY NEW YEAR!
  
   How do I go about plotting (using lattice) overlays of an ID
  (group=ID)
   observed, fitted data in each panel of a multiple panel plot (each
  panel
   identified by DS1 + DS2 + DS3)? x variable is X1 in the
  accompanying
   section of a dataset. each individual is identified by color and
 Y's
  are
   identified by pch or lty.
  
   I guess the code goes something like the one below, but could not
 get
   the
   proper use of panel functions
  
   xyplot(Y1+Y2+Y3~X1|DS1+DS2+DS3,data=d1,group=ID,...)...
 [[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
   http://www.r-project.org/posting-guide.html
  
   and provide commented, minimal, self-contained, reproducible code.
  
  
  
   --
   Jim Holtman
   Cincinnati, OH
   +1 513 646 9390
  
   What is the problem that you are trying to solve?
  
  
  [[alternative HTML version deleted]]
  
   __
   R-help@r-project.org mailing list
   

Re: [R] bootstrapping a matrix and calculating Pearson's correlation coefficient

2010-01-05 Thread Liviu Andronic
Hello

On 1/5/10, Lee William leeon...@gmail.com wrote:
  I have got matrix 'data' of dimension 22000x600. I want to make 50
  independent samples of dimension 22000x300 from the original matrix 'data'.
  And then want to calculate pearsons CC for each of the obtained 50 matrices.
  It seems it is possible to do this using 'boot' function from library boot
  but I am not able to figure out how? I am really stuck. Please help!

Initially consider constructing the bootstrap function on a much
smaller scale, with dummy data. For a dummy example on bootstrapping,
see one of my old posts [1]. Also, check this Quick-R page [2] and the
links at the bottom of the page for various explanations on the
procedure.
Liviu

[1] http://www.mail-archive.com/r-help@r-project.org/msg65667.html
[2] http://www.statmethods.net/advstats/bootstrapping.html

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


Re: [R] zero-fill absent data

2010-01-05 Thread Peter Alspach
Tena koe Dan

On approach - create a fullFrame with all your observations and merge
with the frame:

 frame - as.data.frame(cbind(c(1:2,5:7,10),c(0.5,0.2,1,1.6,2,0)))
 fullFrame - as.data.frame(min(frame[,1]):max(frame[,1])) # Create
fullFrame
 fullFrame
   min(frame[, 1]):max(frame[, 1])
11
22
33
44
55
66
77
88
99
10  10
 fullFrame - merge(fullFrame, frame, by=1, all.x=T) # Merge with frame
 fullFrame[is.na(fullFrame[,2]),2] - 0 # Replace NAs with 0s
 fullFrame
   min(frame[, 1]):max(frame[, 1])  V2
11 0.5
22 0.2
33 0.0
44 0.0
55 1.0
66 1.6
77 2.0
88 0.0
99 0.0
10  10 0.0
  
HTH ...

Peter Alspach

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Dan Kortschak
 Sent: Wednesday, 6 January 2010 11:40 a.m.
 To: r-help@r-project.org
 Subject: [R] zero-fill absent data
 
 Hello,
 
 I have a set of data frames, generated by an SQL query that I 
 am working with. Because of the way the query was written, 
 zero values for the dependent variable (V2 in the example) 
 are not recorded. Up until now this has not been a problem.
 
 I would like to be able to fill all absent data with 0. 
 
 Current state of data (e.g.):
  frame-as.data.frame(cbind(c(1:2,5:7),c(0.5,0.2,1,1.6,2)))
  frame
   V1  V2
 1  1 0.5
 2  2 0.2
 3  5 1.0
 4  6 1.6
 5  7 2.0
 
 So that frame returns:
 
   V1  V2
 1  1 0.5
 2  2 0.2
 3  3 0.0
 4  4 0.0
 5  5 1.0
 6  6 1.6
 7  7 2.0
 
 
 Since absent data may be beyond the last recorded point I'd 
 like to be able to use a terminating 0 
 
  frame-as.data.frame(cbind(c(1:2,5:7,10),c(0.5,0.2,1,1.6,2,0)))
  frame
   V1  V2
 1  1 0.5
 2  2 0.2
 3  5 1.0
 4  6 1.6
 5  7 2.0
 6 10 0.0
 
 So that values 7V110 are zero filled.
 
 Can anyone suggest a method to do this?
 
 thank you for your time.
 Dan
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

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


Re: [R] zero-fill absent data

2010-01-05 Thread Gabor Grothendieck
The zoo package's merge.zoo routines has a fill=0 argument so:  create
an expanded index, ix, and then in the next line create zoo objects
from the data and the expanded index and merge them together.  Finally
in the last line convert back to a data frame.

library(zoo)
ix - with(frame, seq(min(V1), max(V1)))
z - with(frame, merge(zoo(V2, V1), zoo(, ix), fill = 0))
data.frame(V1 = time(z), V2 = coredata(z))


On Tue, Jan 5, 2010 at 5:39 PM, Dan Kortschak
dan.kortsc...@adelaide.edu.au wrote:
 Hello,

 I have a set of data frames, generated by an SQL query that I am working
 with. Because of the way the query was written, zero values for the
 dependent variable (V2 in the example) are not recorded. Up until now
 this has not been a problem.

 I would like to be able to fill all absent data with 0.

 Current state of data (e.g.):
 frame-as.data.frame(cbind(c(1:2,5:7),c(0.5,0.2,1,1.6,2)))
 frame
  V1  V2
 1  1 0.5
 2  2 0.2
 3  5 1.0
 4  6 1.6
 5  7 2.0

 So that frame returns:

  V1  V2
 1  1 0.5
 2  2 0.2
 3  3 0.0
 4  4 0.0
 5  5 1.0
 6  6 1.6
 7  7 2.0


 Since absent data may be beyond the last recorded point I'd like to be
 able to use a terminating 0

 frame-as.data.frame(cbind(c(1:2,5:7,10),c(0.5,0.2,1,1.6,2,0)))
 frame
  V1  V2
 1  1 0.5
 2  2 0.2
 3  5 1.0
 4  6 1.6
 5  7 2.0
 6 10 0.0

 So that values 7V110 are zero filled.

 Can anyone suggest a method to do this?

 thank you for your time.
 Dan

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


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


[R] prefixing values in a table

2010-01-05 Thread laura . hug

Hi,

 I have generated a table of counts, and now need to add a prefix to  
the counts.


#count KO occurrences
KO_occur = table(groupKOIDs) #where groupKOIDs is a vector of characters

e.g.,

if groupKOIDs = c(A, A, B, A)
then
KO_occur would look like this:

A  B
3  1

and I need to add a W to the front of the counts:

A  B
W3  W1

If anyone has ideas for me as to how to approach this, I'd be very grateful!

cheers,
Laura

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


Re: [R] xyplot: problems with column names legend

2010-01-05 Thread Jay
Anybody? Frustrating to be unable to solve this silly little
problem...

On Jan 3, 12:48 pm, Jay josip.2...@gmail.com wrote:
 Thanks, the backtickes got the code working. However, now I cant get
 it to draw the legend/key.
 For example, look at this 
 figure:http://osiris.sunderland.ac.uk/~cs0her/Statistics/xyplot5.png
 My graph is similar, but instead of 1,2,...,8 as the names of the
 series I want it to say Data one (a string with spaces) and so on.

 On Jan 3, 10:58 am, baptiste auguie baptiste.aug...@googlemail.com
 wrote:



  Hi,

  Using backticks might work to some extent,

  library(lattice)
  `my variable` = 1:10
  y=rnorm(10)
  xyplot(`my variable` ~ y)

  but if your data is in a data.frame the names should have been converted,

  make.names('my variable')
  [1] my.variable

  HTH,

  baptiste

  2010/1/3 Jay josip.2...@gmail.com:

   Hello!

   one more question about xyplot. If I have data which have space in the
   column names, say xyz 123. How do I create a working graph where
   this text is displayed in the legend key?

   Now when I try something like xyplot(xyz 123 ~ variable1, data =
   mydata, ...) I get nothing.
   Also, is it possible to genrate the graph with xyplot(mydata[,1] ~
   variable1, data = mydata, ...) and then later in the code specify
   the names that should be displayed in the legend?

   Thank you!

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

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

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

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


Re: [R] Multivariate Poisson GLM??

2010-01-05 Thread Kjetil Halvorsen
You could have a look at the VGAM (vector glm /gam models) at CRAN.

Kjetil

On Tue, Jan 5, 2010 at 5:59 PM, Corey Sparks corey.spa...@utsa.edu wrote:
 Dear R Users,
 I'm working on a problem where I have a multivariate response vector of
 counts and a continuous predictor.
  I've thought about doing this the same way you would do a Multvariate
 regression model with normally distributed data, but since these data are
 counts, they are probably better modeled with a Poisson distribution.

 For example
 y1-rpois(100,3.5)
 y2-rpois(100,1.5)
 y3-rpois(100,.09)
 x-rnorm(100, mean=25, sd=10)
 dat-data.frame(y1, y2, y3, x)

 #Get the Multivariate linear model assuming normality
 fit-lm(cbind(y1,y2,y3)~x, data=dat)
 fit.0-update(fit, ~1)
 #Calculate Pillai's trace for global model test
 anova(fit, fit.0)

 But, if I try this approach with glm() instead of lm(), I get the error
 indicating that a multivariate response vector isn't allowed in glm

 fit.pois-glm(cbind(y1,y2,y3)~x, data=dat, family=poisson)
 Error: (subscript) logical subscript too long

 If anyone has experience with a multivariate Poisson response vector I would
 gladly appreciate any suggestions.
 Corey Sparks

 --
 Corey Sparks
 Assistant Professor
 Department of Demography and Organization Studies
 University of Texas at San Antonio
 501 West Durango Blvd
 Monterey Building 2.270C
 San Antonio, TX 78207
 210-458-3166
 corey.sparks 'at' utsa.edu
 https://rowdyspace.utsa.edu/users/ozd504/www/index.htm

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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Anybody can suggest a better method to build a package while ignoring some functions

2010-01-05 Thread rusers.sh
Hi,
 Say i have three functions in a new package, a,b and c. I only want the one
function a to be exported for use. b and  c are not very stable.
  If i specify to export all the three functions in the NAMESPACE file
(export(a,b,c)), no errors appeared after checking the package. And i am
sure there should be no errors.
  But if i only export the one function a by specifying it in the
NAMESPACE file(export(a)), one error appeared.
  See below.
 Error ###
* checking examples ... ERROR
Running examples in 's-Ex.R' failed.
The error most likely occurred in:
 ### * b

 flush(stderr()); flush(stdout())

 ### Name: b
 ### Title: Compute inverse cosine with angle given in degrees
 ### Aliases: ab
 ### Keywords: array

 ### ** Examples
 b(theta=30)
Error: could not find function acos_d
Execution halted
  Anybody knows where the problem is and how to solve this? Is there better
method to obtain what i want?
  Thanks

-- 
-
Jane Chang
Queen's

[[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] chi-squared test

2010-01-05 Thread Xanthe Walker
I would like to do a chi-squared test on the following matrix:

CP-matrix(c(26,17,9,27,8,9,9,8,29,9,6,17,81,7,43,36,2,4,3,0,5,1,0,12,29,9,12,19,0,0),nrow=3)

dimnames(CP) -
list(c(less10,bt10and50,more50),c(T10,T9,T8,T7,T6,T5,T4,T3,T2,T1))


I want to set the expected values as 26, 17, 9 (ie. the data from T10).

How do assign expected values and complete the Chi-squared test?


Cheers

[[alternative HTML version deleted]]

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


Re: [R] The output of script is hidden in console

2010-01-05 Thread Noli Sicad
If you are using windows, In windows console.

Rgui.exe filename.R -The command does not work at all.

You have open Rgui.exe first, retrieve filename.R then run the script.

Noli

On 1/5/10, vtvdung vtvdung.in...@yahoo.com wrote:

 Hi everyone,
 I execute a script with
 source(filename)
 The script has effect but i don't see the output on console screen.Why?
 I'm a newbie. Thanks :handshake:

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


Re: [R] Data Frame Transpose

2010-01-05 Thread Noli Sicad
Hi John

Thanks for your reply. I think I was posting properly the problem.

Here are the error, R script and console errors below.

Thanks. Noli

~~~
The error:
~~
Error in data.frame(CROP_ID = x[1, 1], CROPTYPE = x[1, 2], name =
colnames(x)[4:5],  :
 subscript out of bounds
~~~

I have a dynamic subscripts for the Period, as result of linear
programming (LP) model run. How I generalise this line. Right now it
has 3 index only.

x01=y[,1], x02=y[,2], x03=y[,3])

This is sample the data.

PERIOD
1
1
1
1
2
2
2
2
3
3
3
4
4
5
5
5
5
5
6
6
6
6
6
6
7
8
9
10
10
10
10



R  script:

harvest.dat - read.dbf('C:\\Down2\\R_forestmgt\\Carbon\\forest_cut_m.dbf')

names(harvest.dat) = c(CROP_ID, CROPTYPE, PERIOD,CUT_AGE, AREA_CUT)

# Transpose 5 columns

fn - function(x) {
 y - t(x[,4:5])
 data.frame( CROP_ID=x[1,1], CROPTYPE=x[1,2], name=colnames(x)[4:5],
x01=y[,1], x02=y[,2], x03=y[,3])
 }

harvest.dat - do.call( rbind,
lapply(split(harvest.dat,list(harvest.dat$CROP_ID,harvest.dat$CROPTYPE)),fn)
)

write.csv(harvest.dat, forest_cut3.csv)
 ~

Scite console with r package
~
Rscript --vanilla --slave 
C:\Down2\R_forestmgt\Carbon\ForestCarbon_1_F_Clean7_transpose.R
[1] C:/Down2/R_forestmgt/Carbon
Loading required package: foreign
Loading required package: sp
Loading required package: methods
Loading required package: lattice
Warning messages:
1: package 'maptools' was built under R version 2.10.1
2: package 'foreign' was built under R version 2.10.1
3: package 'sp' was built under R version 2.10.1
Error in data.frame(CROP_ID = x[1, 1], CROPTYPE = x[1, 2], name =
colnames(x)[4:5],  :
 subscript out of bounds
Calls: do.call - lapply - FUN - data.frame
Execution halted
Exit code: 1Time: 2.128
~

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


Re: [R] svm

2010-01-05 Thread Steve Lianoglou
Hi,

On Tue, Jan 5, 2010 at 7:01 PM, Amy Hessen amy_4_5...@hotmail.com wrote:

 Hi,

 I understand from help pages that in order to use a data set with svm, I have 
 to divide it into two files: one for the dataset without the class label and 
 the other file contains the class label as the following code:-

This isn't exactly correct ... look at the examples in the ?svm
documentation a bit closer.

 library(e1071)
 x- read.delim(mydataset_except-class-label.txt)
 y- read.delim(mydataset_class-labell.txt)
 model - svm(x, y, cross=5)
 summary(model)

 but I couldn’t understand how I add “formula” parameter to it? Does formula 
 contain the class label too??

Using the first example in ?svm

attach(iris)
model - svm(Species ~ ., data = iris)

The first argument in the function call is the formula. The Species
column is the class label.

`iris` is a data.frame ... you can see that it has the label *in it*,
look at the output of head(iris)

 and what I have to do to use testing set when I don’t use “cross” parameter.

Just follow the example in ?svm some more, you'll see training a model
and then testing it on data. The example happens to be the same data
the model trained on. To use new data, you'll just need a data
matrix/data.frame with as many columns as your original data, and as
many rows as you have observations.

The first step separates the labels from the data (you can do the same
in  your data -- you don't have to have separate test and train files
that are different -- just remove the labels from it in R):

attach(iris)
x - subset(iris, select = -Species)
y - Species
model - svm(x, y)

# test with train data
pred - predict(model, x)

Hope that helps,
-steve

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

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


Re: [R] xyplot: problems with column names legend

2010-01-05 Thread Felix Andrews
You have not said what the problem is, i.e. what you have tried and
what you expect. Please post a small, reproducible example if you want
help.

Regards
-Felix

2010/1/6 Jay josip.2...@gmail.com:
 Anybody? Frustrating to be unable to solve this silly little
 problem...

 On Jan 3, 12:48 pm, Jay josip.2...@gmail.com wrote:
 Thanks, the backtickes got the code working. However, now I cant get
 it to draw the legend/key.
 For example, look at this 
 figure:http://osiris.sunderland.ac.uk/~cs0her/Statistics/xyplot5.png
 My graph is similar, but instead of 1,2,...,8 as the names of the
 series I want it to say Data one (a string with spaces) and so on.

 On Jan 3, 10:58 am, baptiste auguie baptiste.aug...@googlemail.com
 wrote:



  Hi,

  Using backticks might work to some extent,

  library(lattice)
  `my variable` = 1:10
  y=rnorm(10)
  xyplot(`my variable` ~ y)

  but if your data is in a data.frame the names should have been converted,

  make.names('my variable')
  [1] my.variable

  HTH,

  baptiste

  2010/1/3 Jay josip.2...@gmail.com:

   Hello!

   one more question about xyplot. If I have data which have space in the
   column names, say xyz 123. How do I create a working graph where
   this text is displayed in the legend key?

   Now when I try something like xyplot(xyz 123 ~ variable1, data =
   mydata, ...) I get nothing.
   Also, is it possible to genrate the graph with xyplot(mydata[,1] ~
   variable1, data = mydata, ...) and then later in the code specify
   the names that should be displayed in the legend?

   Thank you!

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

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

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

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




-- 
Felix Andrews / 安福立
Postdoctoral Fellow
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 61 2 6125 4670
E: felix.andr...@anu.edu.au
CRICOS Provider No. 00120C
-- 
http://www.neurofractal.org/felix/

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


Re: [R] prefixing values in a table

2010-01-05 Thread jim holtman
try this:

 x -  c(A, A, B, A)
 x.t - table(x)
 x.t
x
A B
3 1
 x.tw - paste(W, x.t, sep='')
 names(x.tw) - names(x.t)
 x.tw
   AB
W3 W1



On Tue, Jan 5, 2010 at 6:38 PM, laura@utoronto.ca wrote:

 Hi,

  I have generated a table of counts, and now need to add a prefix to the
 counts.

 #count KO occurrences
 KO_occur = table(groupKOIDs) #where groupKOIDs is a vector of characters

 e.g.,

 if groupKOIDs = c(A, A, B, A)
 then
 KO_occur would look like this:

 A  B
 3  1

 and I need to add a W to the front of the counts:

 A  B
 W3  W1

 If anyone has ideas for me as to how to approach this, I'd be very
 grateful!

 cheers,
 Laura

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




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[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] chi-squared test

2010-01-05 Thread David Winsemius


On Jan 5, 2010, at 8:53 PM, Xanthe Walker wrote:


I would like to do a chi-squared test on the following matrix:

CP- 
matrix 
(c 
(26,17,9,27,8,9,9,8,29,9,6,17,81,7,43,36,2,4,3,0,5,1,0,12,29,9,12,19,0,0 
),nrow=3)


dimnames(CP) -
list 
(c 
(less10 
,bt10and50 
,more50),c(T10,T9,T8,T7,T6,T5,T4,T3,T2,T1))



I want to set the expected values as 26, 17, 9 (ie. the data from  
T10).


How do assign expected values and complete the Chi-squared test?


You ought to look (more closely?)  at the examples in chisq.test.



Cheers


--


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] xyplot: adjusting the scale (min, max tick)

2010-01-05 Thread Jay
Hi,

I'm terribly sorry but it seems it cannot figure this one out by
myself so, please, if somebody could help I would be very grateful.
So, when I plot with xyplot() I get an y-axis that is very ugly...
starting from a random number and having so many ticks that it becomes
unreadable.

How do I tell xyplot how to draw the axis? E.g., start from 100, end
at 200 with 25 units between ticks/labels?
Can somebody give me an example?

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.


[R] debugging package

2010-01-05 Thread Markus Weisner
I am trying to debug a package to submit it to CRAN and am getting a bunch
of error messages.  Most of the errors are because of the Rd files which
were automatically populated by the package.skeleton function.  I find the
section on documentation to be pretty confusion in the R Extensions manual.
Any help on getting these errors fixed would be hugely appreciated.  Thanks.
--Markus

* checking for working pdflatex ... OK
* using log directory '/Users/markus/Dropbox/NFIRS_S4/NFIRS.Rcheck'
* using R version 2.9.2 Patched (2009-09-24 r50179)
* using session charset: UTF-8
* checking for file 'NFIRS/DESCRIPTION' ... OK
* checking extension type ... Package
* this is package 'NFIRS' version '1.0'
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking for executable files ... OK
* checking whether package 'NFIRS' can be installed ... WARNING
Found the following significant warnings:
   missing link(s):  ~~fun~~ CLASSNAME-class
See '/Users/markus/Dropbox/NFIRS_S4/NFIRS.Rcheck/00install.out' for details.
* checking package directory ... OK
* checking for portable file names ... OK
* checking for sufficient/correct file permissions ... OK
* checking DESCRIPTION meta-information ... OK
* checking top-level files ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking R files for non-ASCII characters ... OK
* checking R files for syntax errors ... OK
* checking whether the package can be loaded ... OK
* checking whether the package can be loaded with stated dependencies ... OK
* checking for unstated dependencies in R code ... OK
* checking S3 generic/method consistency ... OK
* checking replacement functions ... OK
* checking foreign function calls ... OK
* checking R code for possible problems ... OK
* checking Rd files ... ERROR
Rd files with likely Rd problems:
Unaccounted top-level text in file 'NFIRS-class.Rd':
Following section 'note':
\n\n ~Make other sections like Warning with \\section{Warning }{}
~\n\n

Unaccounted top-level text in file 'NFIRS-package.Rd':
Following section 'references':
\n~~ Optionally other standard keywords, one per line, from file KEYWORDS
in the R documentation directory ~~\n

Rd files with missing or empty '\title':
  NFIRS.summary.Rd
  read.NFIRS.Rd

Rd files without 'description':
  NFIRS.summary.Rd
  read.NFIRS.Rd
Rd files without 'title':
  NFIRS.summary.Rd
  read.NFIRS.Rd
These entries are required in an Rd file.

Rd files with non-standard keywords:
  as.data.frame-methods.Rd: ~~ other possible keyword(s)
  head-methods.Rd: ~~ other possible keyword(s)
  NFIRS.summary.Rd: ~kwd1 ~kwd2
  read.NFIRS.Rd: ~kwd1 ~kwd2
  summary-methods.Rd: ~~ other possible keyword(s)
  tail-methods.Rd: ~~ other possible keyword(s)
Each '\keyword' entry should specify one of the standard keywords (as
listed in file 'KEYWORDS' in the R documentation directory).

Rd files with duplicated alias 'as.data.frame,NFIRS-method':
  as.data.frame-methods.Rd NFIRS-class.Rd
Rd files with duplicated alias 'head,NFIRS-method':
  head-methods.Rd NFIRS-class.Rd
Rd files with duplicated alias 'summary,NFIRS-method':
  NFIRS-class.Rd summary-methods.Rd
Rd files with duplicated alias 'tail,NFIRS-method':
  NFIRS-class.Rd tail-methods.Rd

See the chapter 'Writing R documentation files' in manual 'Writing R
Extensions'.

[[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] xyplot: problems with column names legend

2010-01-05 Thread Peter Ehlers

Jay,

I don't recall the details of your original post so the
following may be entirely off the mark; nevertheless, here
goes:

thetext - paste('Data', 1:8)
# or: thetext - paste('Data', c('one', 'two', 'three', etc))
xyplot(decrease ~ treatment, OrchardSprays, groups = rowpos,
   type = a,
   auto.key =
  list(text= thetext,
 space = right,
points = FALSE,
 lines = TRUE))


 -Peter Ehlers

Jay wrote:

Anybody? Frustrating to be unable to solve this silly little
problem...

On Jan 3, 12:48 pm, Jay josip.2...@gmail.com wrote:

Thanks, the backtickes got the code working. However, now I cant get
it to draw the legend/key.
For example, look at this 
figure:http://osiris.sunderland.ac.uk/~cs0her/Statistics/xyplot5.png
My graph is similar, but instead of 1,2,...,8 as the names of the
series I want it to say Data one (a string with spaces) and so on.

On Jan 3, 10:58 am, baptiste auguie baptiste.aug...@googlemail.com
wrote:




Hi,
Using backticks might work to some extent,
library(lattice)
`my variable` = 1:10
y=rnorm(10)
xyplot(`my variable` ~ y)
but if your data is in a data.frame the names should have been converted,
make.names('my variable')
[1] my.variable
HTH,
baptiste
2010/1/3 Jay josip.2...@gmail.com:

Hello!
one more question about xyplot. If I have data which have space in the
column names, say xyz 123. How do I create a working graph where
this text is displayed in the legend key?
Now when I try something like xyplot(xyz 123 ~ variable1, data =
mydata, ...) I get nothing.
Also, is it possible to genrate the graph with xyplot(mydata[,1] ~
variable1, data = mydata, ...) and then later in the code specify
the names that should be displayed in the legend?
Thank you!
__
r-h...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

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

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


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




--
Peter Ehlers
University of Calgary
403.202.3921

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

2010-01-05 Thread faridamsb
Hello All,

I would like to remove the entire row, if there is any negative element in  
that row. What is the best way to do that?

For example,

x-matrix(c(2,-1,-2,3,5,6,-3,7,4,2,1,0), 4, 3)

the returning matrix should look like

[,1] [,2] [,3]
[1,] 2 5 4
[2,] 3 7 0


Thank you in advance,

FM

[[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] xyplot: adjusting the scale (min, max tick)

2010-01-05 Thread Peter Ehlers

Have a look at the 'scales' argument. For example:

# default plot
xyplot(Sepal.Length ~ Petal.Length | Species, data = iris)

# modified plot
xyplot(Sepal.Length ~ Petal.Length | Species, data = iris,
scales=list(y=list(at=c(-5,0,5,10), limits=c(-5,10

 -Peter Ehlers

Jay wrote:

Hi,

I'm terribly sorry but it seems it cannot figure this one out by
myself so, please, if somebody could help I would be very grateful.
So, when I plot with xyplot() I get an y-axis that is very ugly...
starting from a random number and having so many ticks that it becomes
unreadable.

How do I tell xyplot how to draw the axis? E.g., start from 100, end
at 200 with 25 units between ticks/labels?
Can somebody give me an example?

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.




--
Peter Ehlers
University of Calgary
403.202.3921

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


Re: [R] removing the rows with negative elements

2010-01-05 Thread Simon Blomberg
 x[-which(x  0, arr.ind=TRUE)[,1],]

but I'm sure someone will suggest an easier way.

Simon.

On Wed, 2010-01-06 at 05:13 +, farida...@gmail.com wrote:
 Hello All,
 
 I would like to remove the entire row, if there is any negative element in  
 that row. What is the best way to do that?
 
 For example,
 
 x-matrix(c(2,-1,-2,3,5,6,-3,7,4,2,1,0), 4, 3)
 
 the returning matrix should look like
 
 [,1] [,2] [,3]
 [1,] 2 5 4
 [2,] 3 7 0
 
 
 Thank you in advance,
 
 FM
 
   [[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 Blomberg, BSc (Hons), PhD, MAppStat. 
Lecturer and Consultant Statistician 
School of Biological Sciences
The University of Queensland 
St. Lucia Queensland 4072 
Australia
Room 320 Goddard Building (8)
T: +61 7 3365 2506
http://www.uq.edu.au/~uqsblomb
email: S.Blomberg1_at_uq.edu.au

Policies:
1.  I will NOT analyse your data for you.
2.  Your deadline is your problem.

Statistics is the grammar of science - Karl Pearson

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


Re: [R] removing the rows with negative elements

2010-01-05 Thread Peter Ehlers

x[apply(x,1,function(x)all(x=0)),]

 -Peter Ehlers

Simon Blomberg wrote:

 x[-which(x  0, arr.ind=TRUE)[,1],]

but I'm sure someone will suggest an easier way.

Simon.

On Wed, 2010-01-06 at 05:13 +, farida...@gmail.com wrote:

Hello All,

I would like to remove the entire row, if there is any negative element in  
that row. What is the best way to do that?


For example,

x-matrix(c(2,-1,-2,3,5,6,-3,7,4,2,1,0), 4, 3)

the returning matrix should look like

[,1] [,2] [,3]
[1,] 2 5 4
[2,] 3 7 0


Thank you in advance,

FM

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




--
Peter Ehlers
University of Calgary
403.202.3921

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


Re: [R] removing the rows with negative elements

2010-01-05 Thread faridamsb
Thank you!

On Jan 6, 2010 12:31am, Peter Ehlers ehl...@ucalgary.ca wrote:
 x[apply(x,1,function(x)all(x=0)),]



 -Peter Ehlers



 Simon Blomberg wrote:


 x[-which(x


 but I'm sure someone will suggest an easier way.



 Simon.



 On Wed, 2010-01-06 at 05:13 +, farida...@gmail.com wrote:


 Hello All,



 I would like to remove the entire row, if there is any negative element  
 in that row. What is the best way to do that?



 For example,



 x7,4,2,1,0), 4, 3)



 the returning matrix should look like



 [,1] [,2] [,3]

 [1,] 2 5 4

 [2,] 3 7 0





 Thank you in advance,



 FM



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







 --

 Peter Ehlers

 University of Calgary

 403.202.3921


[[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] seewave package:spectrogram resonance contour

2010-01-05 Thread rajesh j
Hi,

I'd like to plot resonance contours on my spectrogram in the seewave
package. Is this possible?

-- 
Rajesh.J

[[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] why is object.size is more for constant numeric vector?

2010-01-05 Thread Prof Brian Ripley

On Wed, 6 Jan 2010, Utkarsh Singhal wrote:


Hi All,

I ran the following lines in R:

print(object.size(a - rep(1,10^6)),units=Mb)
print(object.size(a - rep(3.542,10^6)),units=Mb)

print(object.size(b - rep(x,10^6)),units=Mb)
print(object.size(b - rep(xyzxyz xyz,10^6)),units=Mb)
print(object.size(b - 1:10^6),units=Mb)
print(object.size(b - rep(1:10,each=10^5)),units=Mb)
print(object.size(b - rep(TRUE,10^6)),units=Mb)

The object size from first two lines is 7.6 MB, but from the last five it is
3.8 MB, although the length of vector is same.

Apparently, the size of any vector of a given length is twice if the vector
is numeric constant than if it is not.

Why is it so? Is my observation wrong? Or, is there some catch with
'object.size'?


Your observation is faulty.  The first two are type double, and a C 
double takes 8 bytes.  The last three are type integer or logical 
with values stored in C int, 4 bytes each.  Character strings are 
harder to compute storage for as identical strings share storage.  On 
a 32-bit machine identical strings take an extra 4 bytes per string, 
on a 64-bit machine an extra 8 bytes.  If you look at the values in 
bytes you will see that 'twice' is an approximation.


So

- the storage needed depends on the type of the vector as well as the 
length.


- for character vectors it depends on the architecture and the 
content.


Please do consult the R manuals rather than expect others to read them 
for you: this is all in the 'R Internals' manual.




Thanks in advance.
Regards
Utkarsh

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



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] MacOS X binary of package cairoDevice

2010-01-05 Thread wenjun zheng
Dear Michael and all R users,

I find that there's no MacOS X binary of package cairoDevice on CRAN now.

Can you or anybody else give me an older MacOS X edition for cairoDevice.

Thank you.

-- 
Wenjun

[[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] removing the rows with negative elements

2010-01-05 Thread Dimitris Rizopoulos

try also this:

x - matrix(c(2,-1,-2,3,5,6,-3,7,4,2,1,0), 4, 3)
x[!rowSums(x  0), ]


Best,
Dimitris


farida...@gmail.com wrote:

Hello All,

I would like to remove the entire row, if there is any negative element in  
that row. What is the best way to do that?


For example,

x-matrix(c(2,-1,-2,3,5,6,-3,7,4,2,1,0), 4, 3)

the returning matrix should look like

[,1] [,2] [,3]
[1,] 2 5 4
[2,] 3 7 0


Thank you in advance,

FM

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



--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

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


Re: [R] removing the rows with negative elements

2010-01-05 Thread Petr PIKAL
Another option is

 x[rowSums(x0)==0, ]

but beware of  floating point if your numbers can be near zero. 

Regards
Petr


r-help-boun...@r-project.org napsal dne 06.01.2010 06:52:48:

 Thank you!
 
 On Jan 6, 2010 12:31am, Peter Ehlers ehl...@ucalgary.ca wrote:
  x[apply(x,1,function(x)all(x=0)),]
 
 
 
  -Peter Ehlers
 
 
 
  Simon Blomberg wrote:
 
 
  x[-which(x
 
 
  but I'm sure someone will suggest an easier way.
 
 
 
  Simon.
 
 
 
  On Wed, 2010-01-06 at 05:13 +, farida...@gmail.com wrote:
 
 
  Hello All,
 
 
 
  I would like to remove the entire row, if there is any negative 
element 
  in that row. What is the best way to do that?
 
 
 
  For example,
 
 
 
  x7,4,2,1,0), 4, 3)
 
 
 
  the returning matrix should look like
 
 
 
  [,1] [,2] [,3]
 
  [1,] 2 5 4
 
  [2,] 3 7 0
 
 
 
 
 
  Thank you in advance,
 
 
 
  FM
 
 
 
  [[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.
 
 
 
 
 
 
 
  --
 
  Peter Ehlers
 
  University of Calgary
 
  403.202.3921
 
 
[[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.