[R] [R-pkgs] New version of "catspec" package

2005-04-12 Thread John Hendrickx
I've uploaded a new version of "catspec" to CRAN. Catspec is for
estimating certain "special categorical" models. It also contains
"ctab", a function for creating one-way, two-way, and multi-way
percentage tables (nothing special there really). Ctab can now print
more than one percentage type, as well as table marginals.

The first special model in catspec is "mclgen". Mclgen restructures a
data frame so a multinomial logistic model can be estimated using a
condition logit program. Doing so provides much more flexibility for
imposing restrictions on the response variable.

The second special (set of) models is "sqtab", for estimating
loglinear models for square tables (aka "mobility models") such as
symmetry, quasi-independence. One application can be to specify such
models as multinomial logistic models with covariates, using mclgen.

John Hendrickx

___
R-packages mailing list
[EMAIL PROTECTED]
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Re: how to separate a string

2005-04-12 Thread Rich FitzJohn
To get the first character from a string, use substr(s, 1, 1)

To split strings at a period, use strsplit(s, "\\.") (the period must
be quoted, as "." matches anything in a regular expression).

To get the index for "." in a string, see "?regexpr, but you will not
need to do that if you use strsplit().

Cheers,
Rich

On 4/13/05, Cuichang Zhao <[EMAIL PROTECTED]> wrote:
> hello, 
> i wonder how is string represent in R. if i have a string s= "hello", how
> can i refer to first character in the string s? 
> also if i have s1 = "hello.1", s2 = "ok.1",  how can i separate the s1 into
> "hello" "1" and s2 into "ok" and "1"? I have tried to use the substring
> function, but i don't where i can get the index for "." in the string?
>  
> Thank you so much
>  
> C-Ming
> April 12, 2005
> 
>   
> -
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
> 

-- 
Rich FitzJohn
rich.fitzjohn  gmail.com   |http://homepages.paradise.net.nz/richa183
  You are in a maze of twisty little functions, all alike

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] how to separate a string

2005-04-12 Thread Cuichang Zhao
hello, 
i wonder how is string represent in R. if i have a string s= "hello", how can i 
refer to first character in the string s? 
also if i have s1 = "hello.1", s2 = "ok.1",  how can i separate the s1 into 
"hello" "1" and s2 into "ok" and "1"? I have tried to use the substring 
function, but i don't where i can get the index for "." in the string?
 
Thank you so much
 
C-Ming
April 12, 2005


-


[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] lm() with many responses

2005-04-12 Thread Prof Brian Ripley
On Tue, 12 Apr 2005, John Pitney wrote:
I have one array of predictors, one observation per row, and one array of 
responses, also arranged one observation per row.  I arrange these into a 
data.frame and call lm() with a pasted-together formula.

I would like to call lm() with a number of responses in excess of 100, but 
for some reason, 39 seems to be a limit.  Why do I get an "invalid variable 
names" error from model.frame() when supplying 40 or more responses?
Your expression is too long.  Create the response matrix and pass that to 
the formula, rather than passing an expression.

There is a 500-char internal limit on variable names in 
model.frame.default.  That should be enough 

As a workaround, I can loop through groups of 39 responses in separate 
calls to lm(), but that seems inefficient and possibly version- or 
platform-dependent.

Here is my best effort at a minimal example showing the problem.
It's not easy to cut-and-paste, though.
--- begin pasted R session ---
test.this <- function(n.resp, n.obs, n.pred) {
+ my.resp <- matrix(runif(n.resp * n.obs), nrow=n.obs)
+ my.resp.names <- paste("Response", 1:n.resp, sep=".")
+ my.pred <- matrix(runif(n.pred * n.obs), nrow=n.obs)
+ my.pred.names <- paste("Predictor", 1:n.pred, sep=".")
+ my.formula <- as.formula(paste("cbind(",
+   paste(my.resp.names, collapse=", "), ") ~ ",
+   paste(my.pred.names, collapse=" + ")))
+ d.tmp <- cbind(my.pred, my.resp)
+ d.tmp <- as.data.frame(d.tmp)
+ names(d.tmp) <- c(my.pred.names, my.resp.names)
+ my.lm <- lm(my.formula, data=d.tmp, model=F, qr=F, x=F, y=F,
+   na.action=na.exclude)
+ my.lm
+ }
# Now, try it.  39 response vectors is OK, but 40 causes an error:
m1 <- test.this(40, 10, 2)
Error in model.frame(formula, rownames, variables, varnames, extras, 
extranames,  :
   invalid variable names
m1 <- test.this(39, 10, 2)
# No error for n.resp == 39.
# Also, shouldn't "qr=F" in the call to lm() turn off output of m1$qr?
Only if it were implemented.
# m1$qr exists.  I'd like to save memory and omit it if possible.
str(m1$qr)
List of 5
$ qr   : num [1:10, 1:3] -3.162  0.316  0.316  0.316  0.316 ...
 ..- attr(*, "dimnames")=List of 2
 .. ..$ : chr [1:10] "1" "2" "3" "4" ...
 .. ..$ : chr [1:3] "(Intercept)" "Predictor.1" "Predictor.2"
 ..- attr(*, "assign")= int [1:3] 0 1 2
$ qraux: num [1:3] 1.32 1.34 1.42
$ pivot: int [1:3] 1 2 3
$ tol  : num 1e-07
$ rank : int 3
- attr(*, "class")= chr "qr"
# Here's my version:
version
_
platform i386-pc-mingw32
arch i386
os   mingw32
system   i386, mingw32
status
major2
minor0.1
year 2004
month11
day  15
language R
--- end pasted R session ---
Best regards,
John
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
--
Brian D. Ripley,  [EMAIL PROTECTED]
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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] pstoedit

2005-04-12 Thread Prof Brian Ripley
On Wed, 13 Apr 2005, BORGULYA [iso-8859-2] Gábor wrote:
   Has onyone experience with "pstoedit" (http://www.pstoedit.net/pstoedit)
to convert eps graphs generated by R on Linux to Windows formats (WMF or
EMF)? Does this way work? Is there an other, better way?
You can only do that using pstoedit on Windows.
^^
A much better way on Windows is to run the R code on R for Windows and use 
its win.metafile() device.  Another better way is to use Adobe 
Illustrator.

The ability to generate WMF on Unix is a long-standing wish at
http://developer.r-project.org/WindowsTODO.html
but no one has ever contributed a working device (although it would be no 
harder than say the PDF device).

Note that because of font differences, conversion from EPS to WMF can only 
ever be approximate.

   The fact that the website of pstoedit mentions that a Better Enhanced
Windows Meta Files (EMF) plugin exists for Windows 9x/NT/2K/XP only makes me
expect poor quality. Am I right?
No quality at all unless you are using Windows where it is unnecessary.
--
Brian D. Ripley,  [EMAIL PROTECTED]
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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Re: [R] package submission and binary versions

2005-04-12 Thread Prof Brian Ripley
On Tue, 12 Apr 2005, Peter E. Rossi wrote:
From reading the CRAN web page, it appears that you should not submit
precompiled binary versions of your package, but rather that these
are built for you by someone working with CRAN.  I submitted my
package using R CMD build but without the binary flag on.  I'd like
to have a binary version available for Windows users. Should I submit
a precompiled binary version as well?
No, as it said.  If your package passes its tests on those platforms, 
binary versions for Windows and MacOS X appear automatically (thanks to 
Uwe Ligges and Stefano Iacus).  They even get updated for new R versions 
(and R 2.1.0 is imminent) when otherwise new submissions would be needed.

(You could have asked [EMAIL PROTECTED] about CRAN questions rather than 
the world.)

--
Brian D. Ripley,  [EMAIL PROTECTED]
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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] A suggestion for predict function(s)

2005-04-12 Thread Ross Darnell
Maybe a useful addition to the predict functions would be to return the 
values of the predictor variables. It just (unless there are problems) 
requires an extra line. I have inserted an example below.

"predict.glm" <-
  function (object, newdata = NULL, type = c("link", "response",
  "terms"), se.fit = FALSE, 
dispersion = NULL, terms = NULL,
na.action = na.pass, ...)
{
  type <- match.arg(type)
  na.act <- object$na.action
  object$na.action <- NULL
  if (!se.fit) {
if (missing(newdata)) {
  pred <- switch(type, link = object$linear.predictors,
 response = object$fitted, terms = predict.lm(object,
 se.fit = se.fit, scale 
= 1, type = "terms",
 terms = terms))
  if (!is.null(na.act))
pred <- napredict(na.act, pred)
}
else {
  pred <- predict.lm(object, newdata, se.fit, scale = 1,
 type = ifelse(type == "link", "response", type),
 terms = terms, na.action = na.action)
  switch(type, response = {
pred <- family(object)$linkinv(pred)
  }, link = , terms = )
}
  }
  else {
if (inherits(object, "survreg"))
  dispersion <- 1
if (is.null(dispersion) || dispersion == 0)
  dispersion <- summary(object, dispersion = dispersion)$dispersion
residual.scale <- as.vector(sqrt(dispersion))
pred <- predict.lm(object, newdata, se.fit, scale = residual.scale,
   type = ifelse(type == "link", "response", type),
   terms = terms, na.action = na.action)
fit <- pred$fit
se.fit <- pred$se.fit
switch(type, response = {
  se.fit <- se.fit * abs(family(object)$mu.eta(fit))
  fit <- family(object)$linkinv(fit)
}, link = , terms = )
if (missing(newdata) && !is.null(na.act)) {
  fit <- napredict(na.act, fit)
  se.fit <- napredict(na.act, se.fit)
}
predictors <- if (missing(newdata)) model.matrix(object) else newdata
pred <- list(predictors=predictors,
 fit = fit, se.fit = se.fit,
 residual.scale = residual.scale)
  }
  pred

#__ end of R code

Ross Darnell
--
School of Health and Rehabilitation Sciences
University of Queensland, Brisbane QLD 4072 AUSTRALIA
Email: <[EMAIL PROTECTED]>
Phone: +61 7 3365 6087 Fax: +61 7 3365 4754  Room:822, Therapies Bldg.
http://www.shrs.uq.edu.au/shrs/school_staff/ross_darnell.html
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] Why is 1 a double?

2005-04-12 Thread Mulholland, Tom
I'm not sure that this answers your questions but maybe they partly help.

p. 7 in An introduction to R notes

"For most purposes the user will not be concerned if the "numbers" in a numeric 
vector
are integers, reals or even complex. Internally calculations are done as double 
precision real
numbers, or double precision complex numbers if the input data are complex."

p. 13 of the R Language Definition notes

"Numeric calculations whose result is undefined, such as '0/0' produce (on 
most, if not all,
platforms) the value NaN. This exists only in the double type."

p. 164 of the Reference manual notes


"Integer vectors exist so that data can be passed to C or Fortran code which 
expects them, and so that
small integer data can be represented exactly and compactly.
Note that on almost all implementations of R the range of representable 
integers is restricted to
about ±2 × 109: doubles can hold much larger integers exactly."

Tom

> -Original Message-
> From: Vivek Rao [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, 13 April 2005 10:12 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Why is 1 a double?
> 
> 
> Based on examples in R books and the syntax of other
> programming languages, I expected that
> 
> n <- 10
> 
> assigns the integer 10 to n, but typeof(n) is actually
> a double. The subscripting expression x[1] is valid,
> but sprintf("\n %d",1) is not, giving the error
> 
> Error in sprintf("\n %d", 1) : use format %f, %e or %g
> for numeric objects
> 
> One must use instead sprintf("\n %d",as.integer(1)). 
> 
> Two questions:
> 
> (1) When one intends to define an integer variable,
> should a construction such as
> 
> n <- as.integer(10)
> 
> be used? Most examples I have seen don't do this. 
> 
> (2) Why wasn't the S language defined so that 
> typeof(1) is "integer" rather than "double"?
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] package submission and binary versions

2005-04-12 Thread Peter E. Rossi
Dear r-help-

>From reading the CRAN web page, it appears that you should not submit 
precompiled binary versions of your package, but rather that these
are built for you by someone working with CRAN.  I submitted my
package using R CMD build but without the binary flag on.  I'd like
to have a binary version available for Windows users. Should I submit
a precompiled binary version as well?

many thanks!

peter r



 Peter E. Rossi
 Joseph T. Lewis Professor of Marketing and Statistics
 Editor, Quantitative Marketing and Economics
 Rm 360, Graduate School of Business, U of Chicago
 5807 S. Woodlawn Ave, Chicago IL 60637
 Tel: (773) 702-7513   |   Fax: (773) 834-2081

 [EMAIL PROTECTED]
 WWW: http://ChicagoGsb.edu/fac/peter.rossi
SSRN: http://ssrn.com/author=22862
 QME: http://www.kluweronline.com/issn/1570-7156

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Why is 1 a double?

2005-04-12 Thread Vivek Rao
Based on examples in R books and the syntax of other
programming languages, I expected that

n <- 10

assigns the integer 10 to n, but typeof(n) is actually
a double. The subscripting expression x[1] is valid,
but sprintf("\n %d",1) is not, giving the error

Error in sprintf("\n %d", 1) : use format %f, %e or %g
for numeric objects

One must use instead sprintf("\n %d",as.integer(1)). 

Two questions:

(1) When one intends to define an integer variable,
should a construction such as

n <- as.integer(10)

be used? Most examples I have seen don't do this. 

(2) Why wasn't the S language defined so that 
typeof(1) is "integer" rather than "double"?

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Time series misalignment

2005-04-12 Thread Fernando Saldanha
Thanks, Achim,

I managed to do what I wanted, thanks to your suggestion, except for
one thing. When I called ts.intersect I could only provide numerical
arguments (more precisely, objects that can be coerced into time
series, I guess). That means I was not able to pass the original
row.names that I had read into a data frame (those were character
strings). At that point those row.names became misaligned with the
data frame created by the ts.intersect call, whose row names were just
1, 2, 3,  Is there a way to avoid this problem?

I will check the zoo package, but I started with R three days ago, so
it's a bit of information overload right now.

Thanks for the help.

FS

On 4/12/05, Achim Zeileis <[EMAIL PROTECTED]> wrote:
> On Tue, 12 Apr 2005 18:47:21 -0400 Fernando Saldanha wrote:
> 
> > Can one also predetermine a set and then estimate all the models one
> > wants to compare using the zoo package?
> 
> Sure, you can merge() several series first and then pass this as the
> data argument to lm(). See the vignette of the zoo package for more
> examples.
> 
> > Or can that be done only with the tseries package?
> 
> Really, you are *not* using the tseries package here!
> 
> (In the old days, the class "ts" and its methods used to be in the
> package ts, but this was merged into stats long ago. tseries is an
> entirely different package.)
> Z
> 
> > Thanks.
> >
> > FS
> >
> > On 4/12/05, Achim Zeileis <[EMAIL PROTECTED]> wrote:
> > > Fernando:
> > >
> > > > This maybe a basic question, but I have spent several hours
> > > > researching and I could not get an answer, so please bear with me.
> > > > The problem is with time series in the package tseries.
> > >
> > > BTW: the `tseries' package is not involved here.
> > >
> > > > As the example
> > > > below shows, the time series can get misaligned, so that bad
> > > > results are obtained when doing regressions.
> > >
> > > lm() per se has only very limited support for time series
> > > regression. Therefore, there are currently several tools under
> > > development for addressing this issue. In particular, Gabor
> > > Grothendieck and myself are working on different approaches to this
> > > problem.
> > >
> > > 
> > >
> > > > To fix this problem I did the following:
> > > >
> > > > > tsf <- ts.intersect(y1, x1, z1)
> > > >
> > > > Now I can do:
> > > >
> > > > > lm1 <- lm(tsf[,3] ~ tsf[,2])
> > >
> > > It is probably simpler to just do
> > >   lm1 <- lm(z1 ~ x1, data = tsf)
> > >
> > > Another approach is implemented in the zoo package. This implements
> > > an formula dispatch and you can do
> > >   lm1 <- lm(I(z1 ~ x1))
> > > *without* computing tsf first.
> > >
> > > Depending on what you want to do with the fitted models, one of the
> > > two approaches might be easier, currently. In particular, if you
> > > want to fit and compare several models, then I would compute the
> > > intersection first and fit all models of interest on this data set.
> > >
> > > Furthermore, note that the dispatch implementation via I() in zoo is
> > > still under development and likely to change in future versions.
> > > (But this mainly means that improved implementations will become
> > > available soon, stay tuned :-)
> > > Z
> > >
> > >
> >
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] lm() with many responses

2005-04-12 Thread John Pitney
Hi all,
I have one array of predictors, one observation per row, and one array 
of responses, also arranged one observation per row.  I arrange these 
into a data.frame and call lm() with a pasted-together formula.

I would like to call lm() with a number of responses in excess of 100, 
but for some reason, 39 seems to be a limit.  Why do I get an "invalid 
variable names" error from model.frame() when supplying 40 or more 
responses?  As a workaround, I can loop through groups of 39 responses 
in separate calls to lm(), but that seems inefficient and possibly 
version- or platform-dependent.

Here is my best effort at a minimal example showing the problem.
--- begin pasted R session ---
> test.this <- function(n.resp, n.obs, n.pred) {
+ my.resp <- matrix(runif(n.resp * n.obs), nrow=n.obs)
+ my.resp.names <- paste("Response", 1:n.resp, sep=".")
+ my.pred <- matrix(runif(n.pred * n.obs), nrow=n.obs)
+ my.pred.names <- paste("Predictor", 1:n.pred, sep=".")
+ my.formula <- as.formula(paste("cbind(",
+   paste(my.resp.names, collapse=", "), ") ~ ",
+   paste(my.pred.names, collapse=" + ")))
+ d.tmp <- cbind(my.pred, my.resp)
+ d.tmp <- as.data.frame(d.tmp)
+ names(d.tmp) <- c(my.pred.names, my.resp.names)
+ my.lm <- lm(my.formula, data=d.tmp, model=F, qr=F, x=F, y=F,
+   na.action=na.exclude)
+ my.lm
+ }
> # Now, try it.  39 response vectors is OK, but 40 causes an error:
> m1 <- test.this(40, 10, 2)
Error in model.frame(formula, rownames, variables, varnames, extras, 
extranames,  :
invalid variable names
> m1 <- test.this(39, 10, 2)
> # No error for n.resp == 39.
> # Also, shouldn't "qr=F" in the call to lm() turn off output of m1$qr?
> # m1$qr exists.  I'd like to save memory and omit it if possible.
> str(m1$qr)
List of 5
 $ qr   : num [1:10, 1:3] -3.162  0.316  0.316  0.316  0.316 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:10] "1" "2" "3" "4" ...
  .. ..$ : chr [1:3] "(Intercept)" "Predictor.1" "Predictor.2"
  ..- attr(*, "assign")= int [1:3] 0 1 2
 $ qraux: num [1:3] 1.32 1.34 1.42
 $ pivot: int [1:3] 1 2 3
 $ tol  : num 1e-07
 $ rank : int 3
 - attr(*, "class")= chr "qr"
> # Here's my version:
> version
 _
platform i386-pc-mingw32
arch i386
os   mingw32
system   i386, mingw32
status
major2
minor0.1
year 2004
month11
day  15
language R
--- end pasted R session ---

Best regards,
John
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] factors in multinom function (nnet)

2005-04-12 Thread Bill.Venables
Alexandre,

I have a couple of remarks to make, not all of which you might find
immediately helpful, I regret to say.

* The choice between using predictors linearly or in factor versions is
a modelling choice that is in no way specific to multinom.  It is a
general aspect of modelling that has to be faced in a whole variety of
situations.  Indeed the full spectrum of choices is much wider than
this: linear, polynomials, splines, different sorts of splines, harmonic
terms, factors, ...  In fact the idea behind gam's was really to allow
some of this extensive field of choices to be model driven, but I
digress.  Point 1: you need to learn about modelling first and then
apply it to multinom.

* It is curious to me that someone could be interested in multinomial
models per se.  Usually people have a context where multinomial models
might be one approach to describing the situation in a statistically
useful way.  Another could be something like classification trees.  The
context is really what decides what modelling choices of this kind might
be sensible.

* There is an obvious suggestion for one reference, a certain notorious
blue and yellow book for which multinom is part of the support software.
I believe they discuss some of the alternatives as well, like
classification trees, and some of the principles of modelling, but it's
been a while since I read it...

* Frank Harrell recently issued an excellent article on this list on
brain surgery in a hurry to which you may usefully refer.  I believe it
was on April 1.

Bill Venables.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Alexandre Brito
Sent: Wednesday, 13 April 2005 8:20 AM
To: r-help@stat.math.ethz.ch
Subject: [R] factors in multinom function (nnet)


Dear All:

I am interested in multinomial logit models (function multinon, library
nnet) but I'm having troubles in choose whether to define the predictors
as factors or not.

I had posted earlier this example (thanks for the reply ronggui):

worms <- data.frame(year = rep(2000:2004, c(3,3,3,3,3)),
age = rep(1:3, 5), 
mud = c(2,5,0,8,7,7,5,9,14,12,8,7,5,13,11),
sand = c(4,7,13,4,14,13,20,17,15,23,20,9,35,27,18), 
rocks = c(2,6,7,9,3,2,2,10,5,19,13,17,11,20,29))

k <- as.matrix(worms[,3:5])

(mud, sand and rocks are factors;  age and year are predictors)

Now there are several possibilities:

m1 <- multinom(k ~ year+age, data = worms)
m2 <- multinom(k ~ factor(year)+age, data = worms)
m3 <- multinom(k ~ year+factor(age), data = worms)
m4 <- multinom(k ~ factor(year)+factor(age), data = worms)
m5 <- multinom(k ~ year:age, data = worms)
m6 <- multinom(k ~ year*age, data = worms)
m7 <- multinom(k ~ factor(year):age, data=worms)
m8 <- multinom(k ~ year:factor(age), data=worms) 

and so on.

I am far from an expert on this, and I would like to learn more about
the utilization of multinom function in R and the kind of doubts I
described above. So I hope that someone can recommend me some references
in this matter (internet, books...) if any is available. 

Thanks in advance, best wishes 

Alexandre
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Time series misalignment

2005-04-12 Thread Achim Zeileis
On Tue, 12 Apr 2005 18:47:21 -0400 Fernando Saldanha wrote:

> Can one also predetermine a set and then estimate all the models one
> wants to compare using the zoo package?

Sure, you can merge() several series first and then pass this as the
data argument to lm(). See the vignette of the zoo package for more
examples.

> Or can that be done only with the tseries package?

Really, you are *not* using the tseries package here!

(In the old days, the class "ts" and its methods used to be in the
package ts, but this was merged into stats long ago. tseries is an
entirely different package.)
Z

> Thanks.
> 
> FS 
> 
> On 4/12/05, Achim Zeileis <[EMAIL PROTECTED]> wrote:
> > Fernando:
> > 
> > > This maybe a basic question, but I have spent several hours
> > > researching and I could not get an answer, so please bear with me.
> > > The problem is with time series in the package tseries.
> > 
> > BTW: the `tseries' package is not involved here.
> > 
> > > As the example
> > > below shows, the time series can get misaligned, so that bad
> > > results are obtained when doing regressions.
> > 
> > lm() per se has only very limited support for time series
> > regression. Therefore, there are currently several tools under
> > development for addressing this issue. In particular, Gabor
> > Grothendieck and myself are working on different approaches to this
> > problem.
> > 
> > 
> > 
> > > To fix this problem I did the following:
> > >
> > > > tsf <- ts.intersect(y1, x1, z1)
> > >
> > > Now I can do:
> > >
> > > > lm1 <- lm(tsf[,3] ~ tsf[,2])
> > 
> > It is probably simpler to just do
> >   lm1 <- lm(z1 ~ x1, data = tsf)
> > 
> > Another approach is implemented in the zoo package. This implements
> > an formula dispatch and you can do
> >   lm1 <- lm(I(z1 ~ x1))
> > *without* computing tsf first.
> > 
> > Depending on what you want to do with the fitted models, one of the
> > two approaches might be easier, currently. In particular, if you
> > want to fit and compare several models, then I would compute the
> > intersection first and fit all models of interest on this data set.
> > 
> > Furthermore, note that the dispatch implementation via I() in zoo is
> > still under development and likely to change in future versions.
> > (But this mainly means that improved implementations will become
> > available soon, stay tuned :-)
> > Z
> > 
> >
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Time series misalignment

2005-04-12 Thread Fernando Saldanha
Can one also predetermine a set and then estimate all the models one
wants to compare using the zoo package? Or can that be done only with
the tseries package?

Thanks.

FS 

On 4/12/05, Achim Zeileis <[EMAIL PROTECTED]> wrote:
> Fernando:
> 
> > This maybe a basic question, but I have spent several hours
> > researching and I could not get an answer, so please bear with me. The
> > problem is with time series in the package tseries.
> 
> BTW: the `tseries' package is not involved here.
> 
> > As the example
> > below shows, the time series can get misaligned, so that bad results
> > are obtained when doing regressions.
> 
> lm() per se has only very limited support for time series regression.
> Therefore, there are currently several tools under development for
> addressing this issue. In particular, Gabor Grothendieck and myself are
> working on different approaches to this problem.
> 
> 
> 
> > To fix this problem I did the following:
> >
> > > tsf <- ts.intersect(y1, x1, z1)
> >
> > Now I can do:
> >
> > > lm1 <- lm(tsf[,3] ~ tsf[,2])
> 
> It is probably simpler to just do
>   lm1 <- lm(z1 ~ x1, data = tsf)
> 
> Another approach is implemented in the zoo package. This implements an
> formula dispatch and you can do
>   lm1 <- lm(I(z1 ~ x1))
> *without* computing tsf first.
> 
> Depending on what you want to do with the fitted models, one of the two
> approaches might be easier, currently. In particular, if you want to fit
> and compare several models, then I would compute the intersection first
> and fit all models of interest on this data set.
> 
> Furthermore, note that the dispatch implementation via I() in zoo is
> still under development and likely to change in future versions. (But
> this mainly means that improved implementations will become available
> soon, stay tuned :-)
> Z
> 
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Perhaps Off-topic lme question

2005-04-12 Thread Berton Gunter
A question on lme() :

details: nlme() in R 2.1.0 beta or 2.0.1

The data,y, consisted of 82 data value in 5 groups of sizes   3  9  8 28 34
.

I fit a simple one level random effects model by:

myfit <- lme( y~1, rand = ~1|Group)

The REML estimates of between and within Group effects are .0032 and .53,
respectively; the between group component is essentially zero as is clearly
evident from a plot of the data. So, thus far, no problem.

However, the confidence interval for the between Groups sd that I get from
intervals(myfit) goes from essentially 0 to infinity (6 x 10^13, actually).
I assume that this is because the between component estimate is too close to
the boundary of 0 so that the likelihood approximations with default
control values fail, but I would appreciate a more definitive comment from
someone who knows what they're talking about. 

If anyone cares to try this, the data in group order are below (i.e., first
3 from Group 1, next 9 from Group 2, etc.).

Cheers to all,
Bert Gunter

14.7
15.8
14.6
15.18
15.04
15.23
15.37
15.3
15.13
16.1
15.5
15.53
15.83
15.53
15.61
15.69
16.17
15.27
15.34
15.3
15.48
15.8
15.1
15.15
15.12
15.3
14.88
14.36
15.62
14.61
15.27
16.05
14.93
15.19
15.23
15.62
15.9
15.21
15.01
14.86
16.55
15.75
15.04
15.55
15.54
14.66
15.9
15.24
15.25
15.18
14.83
15.17
15.05
15.37
14.87
15.33
15.55
15.5
15.89
15.67
15.55
15.65
15.8
15.84
16.25
14.71
15.39
16.11
15.64
15.99
16.54
14.46
15.47
15.11
15.59
15.49
15.08
14.6
14.32
13.73
16.61
14.19

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] pstoedit

2005-04-12 Thread BORGULYA Gábor
Hi List!

Has onyone experience with "pstoedit" (http://www.pstoedit.net/pstoedit) 
to convert eps graphs generated by R on Linux to Windows formats (WMF or 
EMF)? Does this way work? Is there an other, better way?
The fact that the website of pstoedit mentions that a Better Enhanced 
Windows Meta Files (EMF) plugin exists for Windows 9x/NT/2K/XP only makes me 
expect poor quality. Am I right?

Gábor

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] factors in multinom function (nnet)

2005-04-12 Thread Alexandre Brito
Dear All:

 

I am interested in multinomial logit models (function multinon, library nnet) 
but I'm having troubles in choose whether to define the predictors as factors 
or not.

 

I had posted earlier this example (thanks for the reply ronggui):

 

worms<- data.frame(year= rep(2000:2004, c(3,3,3,3,3)),age=rep(1:3,5), 
mud=c(2,5,0,8,7,7,5,9,14,12,8,7,5,13,11),sand=c(4,7,13,4,14,13,20,17,15,23,20,9,35,27,18),
 rocks=c(2,6,7,9,3,2,2,10,5,19,13,17,11,20,29))

 

k<- as.matrix(worms[,3:5])

 

(mud, sand and rocks are factors;  age and year are predictors)

 

Now there are several possibilities:

 

m1<- multinom(k~year+age,data=worms)

m2<- multinom(k~factor(year)+age,data=worms)

m3<- multinom(k~year+factor(age),data=worms)

m4<- multinom(k~factor(year)+factor(age),data=worms)

m5<- multinom(k~year:age,data=worms)

m6<- multinom(k~year*age,data=worms)

m7<- multinom(k~factor(year):age,data=worms)

m8<- multinom(k~year:factor(age),data=worms)

 

and so on.

 

 

I am far from an expert on this, and I would like to learn more about the 
utilization of multinom function in R and the kind of doubts I described above. 
So I hope that someone can recommend me some references in this matter 
(internet, books...) if any is available.

 

Thanks in advance, best wishes

 

Alexandre

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Time series misalignment

2005-04-12 Thread Achim Zeileis
Fernando:

> This maybe a basic question, but I have spent several hours
> researching and I could not get an answer, so please bear with me. The
> problem is with time series in the package tseries.

BTW: the `tseries' package is not involved here.

> As the example
> below shows, the time series can get misaligned, so that bad results
> are obtained when doing regressions.

lm() per se has only very limited support for time series regression.
Therefore, there are currently several tools under development for
addressing this issue. In particular, Gabor Grothendieck and myself are
working on different approaches to this problem.



> To fix this problem I did the following:
> 
> > tsf <- ts.intersect(y1, x1, z1)
>
> Now I can do:
> 
> > lm1 <- lm(tsf[,3] ~ tsf[,2])

It is probably simpler to just do
  lm1 <- lm(z1 ~ x1, data = tsf)

Another approach is implemented in the zoo package. This implements an
formula dispatch and you can do
  lm1 <- lm(I(z1 ~ x1))
*without* computing tsf first.

Depending on what you want to do with the fitted models, one of the two
approaches might be easier, currently. In particular, if you want to fit
and compare several models, then I would compute the intersection first
and fit all models of interest on this data set.

Furthermore, note that the dispatch implementation via I() in zoo is
still under development and likely to change in future versions. (But
this mainly means that improved implementations will become available
soon, stay tuned :-)
Z

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] R into stata

2005-04-12 Thread Rich FitzJohn
library(foreign)
?write.dta

Cheers,
Rich

On Apr 13, 2005 8:56 AM, Emre Ozaltin <[EMAIL PROTECTED]> wrote:
> What is to command to change a dataset in R format "X.RData" into stata
> format "X.dta"?
> 
> Thank you,
> 
> 
> ---
> Emre Özaltin
> Epidemiologist
> Harvard Initiative for Global Health (HIGH)
> 104 Mt. Auburn St. 02138 Cambridge, MA
> tel:  1 (617) 495-4884
> fax: 1 (617) 495-8231
> email:  [EMAIL PROTECTED]
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 


-- 
Rich FitzJohn
rich.fitzjohn  gmail.com   |http://homepages.paradise.net.nz/richa183
  You are in a maze of twisty little functions, all alike

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] R into stata

2005-04-12 Thread Emre Ozaltin
What is to command to change a dataset in R format "X.RData" into stata
format "X.dta"?

Thank you,



---
Emre Özaltin
Epidemiologist
Harvard Initiative for Global Health (HIGH)
104 Mt. Auburn St. 02138 Cambridge, MA
tel:  1 (617) 495-4884
fax: 1 (617) 495-8231
email:  [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Time series misalignment

2005-04-12 Thread Fernando Saldanha
This maybe a basic question, but I have spent several hours
researching and I could not get an answer, so please bear with me. The
problem is with time series in the package tseries. As the example
below shows, the time series can get misaligned, so that bad results
are obtained when doing regressions. I found a way to do this
correctly, but I find it rather cumbersome. My question is: is there a
better way to do it?

Thanks for any help.

Suppose I define:

> y1<-ts(c(1,2,3,5,7))
> x1<-diff(y1)
> z1<-ts(c(1,1,2,2))

Then I get:

> x1
Time Series:
Start = 2 
End = 5 
Frequency = 1 
[1] 1 1 2 2

> z1
Time Series:
Start = 1 
End = 4 
Frequency = 1 
[1] 1 1 2 2

Notice that the Start values for x1 and z1 are different.

However, if I regress z1 on z1 I get:

> reg1 <- lm(z1 ~ x1, na.action = NULL)
> reg1

Call:
lm(formula = z1 ~ x1, na.action = NULL)

Coefficients:
(Intercept)   x1  
  01  
  
But this is the wrong answer. The time series z1 and x1 are
misaligned. lm is ignoring the fact that Start = 2 for x1 and Start =
1 for z1.

To fix this problem I did the following:

> tsf <- ts.intersect(y1, x1, z1)
> tsf

Time Series:
Start = 2 
End = 4 
Frequency = 1 
  y1 x1 z1
2  2  1  1
3  3  1  2
4  5  2  2

These versions of z1 and x1 are correctly aligned.

Now I can do:

> lm1 <- lm(tsf[,3] ~ tsf[,2])
> lm1

Call:
lm(formula = tsf[, 3] ~ tsf[, 2])

Coefficients:
(Intercept) tsf[, 2]  
1.0  0.5 

This is the correct answer. However, it is rather cumbersome to refer
to the aligned variables as columns of the time series object tsf.

As an observation, I also called ts.intersect with the option dframe =
t and got exactly the same results.

So my question is: is there a less cumbersome way to keep these time
series aligned?

Thanks again for any help.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] removing characters from a string

2005-04-12 Thread Vivek Rao
Thanks for all the helpful replies to my question
about string handling. I will try to be more careful
in making general comments about R, about which I
still have much to learn.

The string handling I need to do is not that
sophisticated (somewhat contradicting my previous
message) and can be done in Fortran 95 with
"convenience" intrinsic functions such as INDEX, TRIM,
ADJUSTL, SCAN, VERIFY . Figuring out the R equivalents
using the functions cited in the replies will be a
good exercise for me.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] Fitting a mixed negative binomial model

2005-04-12 Thread Ben Bolker
  This is a little bit tricky (nonlinear, mixed, count data ...) Off the 
top of my head, without even looking at the documentation, I think your 
best bet for this problem would be to use the weights statement to allow 
the variance to be proportional to the mean (and add a normal error term 
for individuals) -- this would be close to equivalent to the log-Poisson 
model used by Elston et al. (Parasitology 2001, 122, 563-569, "Analysis of 
aggregation, a worked example: numbers of ticks on red grouse chicks"), 
and might do what you want.

--
620B Bartram Hall[EMAIL PROTECTED]
Zoology Department, University of Floridahttp://www.zoo.ufl.edu/bolker
Box 118525   (ph)  352-392-5697
Gainesville, FL 32611-8525   (fax) 352-392-3704
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Any addtional information on Flexible Discriminant Analysis (fda)

2005-04-12 Thread Joseph Retzer
Hi Everyone,
  I posted a similar, albiet more specific, question a while back and didnt get 
a response so I thought I'd try once more with a more general framing.
 
 Basically I'm wondering if anyone has any code, examples/illustrations, 
documentation (besides the basic R docs on mda/fda) relating to running the 
Tibshirani and Hastie "Flexible Discriminant Analysis" routine that they 
wouldnt mind pointing me to and/or sharing. 
 
  Any information would be greatly appreciated,
 
Many Thanks,
Joe Retzer


-


[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] How to change letters after space into capital letters

2005-04-12 Thread McGehee, Robert
This short function capitalizes the first letter of each word in a
character string, which is what I think you want.

capitalize <- function(x) {
x <- strsplit(x, " ")
for (i in seq(along = x)) {
substr(x[[i]], 1, 1) <- toupper(substr(x[[i]], 1, 1))
}
sapply(x, function(z) paste(z, collapse = " "))
}

Robert

-Original Message-
From: Wolfram Fischer [mailto:[EMAIL PROTECTED] 
Sent: Monday, April 11, 2005 6:22 AM
To: r-help@stat.math.ethz.ch
Subject: [R] How to change letters after space into capital letters


What is the easiest way to change within vector of strings
each letter after a space into a capital letter?

E.g.:
  c( "this is an element of the vector of strings", "second element" )
becomes:
  c( "This Is An Element Of The Vector Of Strings", "Second Element" )

My reason to try to do this is to get more readable abbreviations.
(A suggestion would be to add an option to abbreviate() which changes
letters after space to uppercase letters before executing the
abbreviation
algorithm.)

Thanks - Wolfram

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] R as programming language: references?

2005-04-12 Thread Huntsinger, Reid
As far as predicting the number of copies which R will create during the
execution of some code, that's almost completely implementation dependent;
no language specification (syntax or semantics) would help. You can
investigate this empirically (try several approaches and look at memory
usage) and/or look at the relevant source (packages, the interface code for
.C/.Call/.Fortran etc, the array manipulation routines,...). I should add
that this code is surprisingly clear and modular, so it's much easier to
read than you might think.

Reid Huntsinger


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jan T. Kim
Sent: Tuesday, April 12, 2005 12:54 PM
To: r-help@stat.math.ethz.ch
Subject: Re: [R] R as programming language: references?


On Tue, Apr 12, 2005 at 02:01:04PM +0200, A.J. Rossini wrote:
> On Apr 12, 2005 11:54 AM, Duncan Murdoch <[EMAIL PROTECTED]> wrote:
> 
> > > - Original Message - From: "Federico Calboli"
> > > <[EMAIL PROTECTED]>
> > > To: "r-help" 
> > > Sent: Tuesday, April 12, 2005 5:14 PM
> > > Subject: [R] R as programming language: references?
> > >
> > >
> > >> Hi All,
> > >>
> > >> I am looking for references on R as a programming language (apart
form
> > >> the standard R-lang.pdf and the other manuals), reference that would
> > >> cover _in_depth_ things like loops, code optimisation, debugging
tools
> > >> etc... and is as up-to-date as possible.
> > >>
> > >> Can anyone suggest any book or other reference apart from the "green
> > >> book" and the V&R "S-programming"?
> > 
> > I think you've already got the best references.
> 
> There is always the source.  In a sense, it IS the most in-depth and
> up-to-date description of the intricacies of using the language,
> though it isn't as easy to read as V&R's S Programming.
> 
> In-depth and up-to-date are tradeoffs rather than being complementary.

I don't know what Federico Calboli has in mind, but as for myself, upon
starting with R, I've been looking for an R language reference in the
style of the Python reference (http://docs.python.org/ref/ref.html).
The specification of the grammar and the associated semantics of a
language gives me the kind of in-depth conceptual understanding that I
like to have, and I find this more difficult to accrue for R than for
other languages. For example, I'm still not certain whether I'm able to
correctly predict how many copies of an object are created during the
execution of some code, and consequently, I'm not really confident that
my code is reasonably optimal.

I'd appreciate pointers to any (more or less hidden) gems I may have
overlooked, of course.

Best regards, Jan
-- 
 +- Jan T. Kim ---+
 |*NEW*email: [EMAIL PROTECTED]   |
 |*NEW*WWW:   http://www.cmp.uea.ac.uk/people/jtk |
 *-=<  hierarchical systems are for files, not for humans  >=-*

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Cumulative Points and Confidence Interval Manipulation in barplot2

2005-04-12 Thread Marc Schwartz
On Tue, 2005-04-12 at 10:14 -0500, Bret Collier wrote:
> R-Users,
> I am working with gplots (in gregmisc bundle) plotting some posterior
> probabilities (using barplot2) of harvest bag limits for discrete data
> (x-axis from 0 to 12, data is counts) and I ran into a couple of
> questions whose solutions have evaded me.
> 
> 1)  When I create and include the confidence intervals, the lower bound
> of the confidence intervals for several of the posterior probabilities
> is below zero, and in those specific cases I only want to show the upper
> limit for those CI's so they do not extend below the x-axis (as harvest
> can not be <0).  Also, comments on a better technique for CI
> construction when the data is bounded to be >=0 would be appreciated.
> 
> 2)  I would also like to show the cumulative probability (as say a
> point or line) across the range of the x-axis on the same figure at the
> top, but I have been unable to figure out how to overlay a set of
> cumulative points over the barplot across the same range as the x-axis.
> 
> Below is some example code showing the test data I am working on
> (xzero):
> 
> xzero <- table(factor(WWNEW[HUNTTYPE=="DOVEONLY"], levels=0:12))
> > xzero
> 
>   0   1   2   3   4   5   6   7   8   9  10  11  12 
> 179  20   9   2   2   0   1   0   0   0   0   0   0 
> 
> > n <- sum(xzero)
> > k <- sum(table(xzero))
> > meantheta1 <-((2*xzero + 1)/(2*n + k))
> > vartheta1
> <-((2*(((2*n)+k)-((2*xzero)+1)))*((2*xzero)+1))/2*n)+k)^2)*(((2*n)+k)+2))
> > stderr <- sqrt(vartheta1)
> > cl.l <- meantheta1-(stderr*2)#Fake CI:  Test
> > cl.u <- meantheta1+(stderr*2)#Fake CI: Test
> > barplot2(meantheta1, xlab="WWD HARVEST DOVE ONLY 2001",
> ylab="Probability", ylim=c(0, 1),xpd=F, col="blue", border="black",
> axis.lty=1,plot.ci=TRUE, ci.u = cl.u, ci.l = cl.l)
> > title(main="WHITE WING DOVE HARVEST PROBABILITIES:  DOVE HUNT ONLY")
> 
> 
> I would greatly appreciate any direction or assistance,
> Thanks,
> Bret

Bret,

If you replace the lower bound of your confidence intervals as follows,
you can get just the upper bound plotted:

cl.l.new <- ifelse(cl.l >= 0, cl.l, meantheta1)

This will set the lower bound to meantheta1 in those cases, thus
plotting the upper portion and you can remove the 'xpd=F' argument. Use
'ci.l = cl.l.new' here:

barplot2(meantheta1, xlab="WWD HARVEST DOVE ONLY 2001",
 ylab="Probability", ylim=c(0, 1), col="blue", 
 border="black", axis.lty=1,plot.ci=TRUE, 
 ci.u = cl.u, ci.l = cl.l.new)

I would defer to others with more Bayesian experience on alternatives
for calculating bounded CI's for the PP's.

With respect to the cumulative probabilities, if I am picturing the same
thing you are, you can use the cumsum() function and then add points
and/or a line as follows:

  points(cumsum(meantheta1), pch = 19)

  lines(cumsum(meantheta1), lty = "solid")

See ?cumsum, ?points and ?lines for more information.

BTW, some strategically placed spaces would help make your code a bit
more readable for folks.

HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] R as programming language: references?

2005-04-12 Thread Jan T. Kim
On Tue, Apr 12, 2005 at 02:01:04PM +0200, A.J. Rossini wrote:
> On Apr 12, 2005 11:54 AM, Duncan Murdoch <[EMAIL PROTECTED]> wrote:
> 
> > > - Original Message - From: "Federico Calboli"
> > > <[EMAIL PROTECTED]>
> > > To: "r-help" 
> > > Sent: Tuesday, April 12, 2005 5:14 PM
> > > Subject: [R] R as programming language: references?
> > >
> > >
> > >> Hi All,
> > >>
> > >> I am looking for references on R as a programming language (apart form
> > >> the standard R-lang.pdf and the other manuals), reference that would
> > >> cover _in_depth_ things like loops, code optimisation, debugging tools
> > >> etc... and is as up-to-date as possible.
> > >>
> > >> Can anyone suggest any book or other reference apart from the "green
> > >> book" and the V&R "S-programming"?
> > 
> > I think you've already got the best references.
> 
> There is always the source.  In a sense, it IS the most in-depth and
> up-to-date description of the intricacies of using the language,
> though it isn't as easy to read as V&R's S Programming.
> 
> In-depth and up-to-date are tradeoffs rather than being complementary.

I don't know what Federico Calboli has in mind, but as for myself, upon
starting with R, I've been looking for an R language reference in the
style of the Python reference (http://docs.python.org/ref/ref.html).
The specification of the grammar and the associated semantics of a
language gives me the kind of in-depth conceptual understanding that I
like to have, and I find this more difficult to accrue for R than for
other languages. For example, I'm still not certain whether I'm able to
correctly predict how many copies of an object are created during the
execution of some code, and consequently, I'm not really confident that
my code is reasonably optimal.

I'd appreciate pointers to any (more or less hidden) gems I may have
overlooked, of course.

Best regards, Jan
-- 
 +- Jan T. Kim ---+
 |*NEW*email: [EMAIL PROTECTED]   |
 |*NEW*WWW:   http://www.cmp.uea.ac.uk/people/jtk |
 *-=<  hierarchical systems are for files, not for humans  >=-*

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] functions(t.test) on variables by groups

2005-04-12 Thread Hai Lin
Dear R users,

I have a data frame with categorical Vars. "Groups"
and a couple  columns of numeric Vars. I am trying to
make two-sample t.test on each variable(s01-s03) by
Groups.

A data generated as following:

zot <- data.frame(Groups=rep(letters[1:2], each=4),
s01=rnorm(8), s02=rnorm(8), s03=rnorm(8))

I have written a piece with a for loop. 
for (i in 1:(length(zot)-1)) {
print(t.test(zot[,i+1]~zot[,1]))
}

I wish something can be easier extracted or can save
it within for loop, or not even using for loop.  

Thanks in advance for your help.

Kevin

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] not plotting when non-existent

2005-04-12 Thread Achim Zeileis
On Tue, 12 Apr 2005 16:08:54 +0100 Luis Ridao Cruz wrote:

> R-help,
> 
> I'm trying to plot the following:
> 
>  year  lgd
> 1  1986 136.97479
> 2  1987  69.10377
> 3  1988  67.66744
> 4  1989  71.60316
> 5  1990  62.06897
> 6  1992   6.25000
> 7  1993  27.72021
> 8  1995  23.83648
> 9  1996  10.29412
> 10 1997  95.67487
> 11 1998  82.09367
> 12 1999  56.60401
> 13 2000  29.80864
> 14 2001  23.77535
> 15 2002  48.30378
> 16 2003  83.47571
> 17 2004  74.58711
> 
> There are 2 missing years 1991 and 1994.
> Is it possible to plot this simple data set so that there is not
> "line" connection between
> 1990-1992 and 1993-1995?

I would store the data as a "ts" object with NAs in it. If x is the
"data.frame" above, you could do

## create regular time scale
y <- data.frame(year = 1986:2004)
## merge data
lgd <- merge(x, y, by = "year", all = TRUE)[,2]
## create ts object
lgd <- ts(lgd, start = 1986)
## plot
plot(lgd, type = "o", pch = 16)

hth,
Z

> I currently use 'plot(, type = "o", pch = 16)' 
> 
> I could as well plot 'pieces' of the vectors with "lines" but I was
> wondering wether there is a simple function to achieve this.
> 
> I run on Windows XP
> 
> > version
>  _  
> platform i386-pc-mingw32
> arch i386   
> os   mingw32
> system   i386, mingw32  
> status  
> major2  
> minor0.1
> year 2004   
> month11 
> day  15 
> language R  
> 
> Thank you in advance
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Cumulative Points and Confidence Interval Manipulation in barplot2

2005-04-12 Thread Bret Collier
R-Users,
I am working with gplots (in gregmisc bundle) plotting some posterior
probabilities (using barplot2) of harvest bag limits for discrete data
(x-axis from 0 to 12, data is counts) and I ran into a couple of
questions whose solutions have evaded me.

1)  When I create and include the confidence intervals, the lower bound
of the confidence intervals for several of the posterior probabilities
is below zero, and in those specific cases I only want to show the upper
limit for those CI's so they do not extend below the x-axis (as harvest
can not be <0).  Also, comments on a better technique for CI
construction when the data is bounded to be >=0 would be appreciated.

2)  I would also like to show the cumulative probability (as say a
point or line) across the range of the x-axis on the same figure at the
top, but I have been unable to figure out how to overlay a set of
cumulative points over the barplot across the same range as the x-axis.

Below is some example code showing the test data I am working on
(xzero):

xzero <- table(factor(WWNEW[HUNTTYPE=="DOVEONLY"], levels=0:12))
> xzero

  0   1   2   3   4   5   6   7   8   9  10  11  12 
179  20   9   2   2   0   1   0   0   0   0   0   0 

> n <- sum(xzero)
> k <- sum(table(xzero))
> meantheta1 <-((2*xzero + 1)/(2*n + k))
> vartheta1
<-((2*(((2*n)+k)-((2*xzero)+1)))*((2*xzero)+1))/2*n)+k)^2)*(((2*n)+k)+2))
> stderr <- sqrt(vartheta1)
> cl.l <- meantheta1-(stderr*2)#Fake CI:  Test
> cl.u <- meantheta1+(stderr*2)#Fake CI: Test
> barplot2(meantheta1, xlab="WWD HARVEST DOVE ONLY 2001",
ylab="Probability", ylim=c(0, 1),xpd=F, col="blue", border="black",
axis.lty=1,plot.ci=TRUE, ci.u = cl.u, ci.l = cl.l)
> title(main="WHITE WING DOVE HARVEST PROBABILITIES:  DOVE HUNT ONLY")


I would greatly appreciate any direction or assistance,
Thanks,
Bret


platform i386-pc-mingw32
arch i386   
os   mingw32
system   i386, mingw32  
status  
major2  
minor0.1
year 2004   
month11 
day  15 
language R  
*Note:  I am working in Exmacs

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] not plotting when non-existent

2005-04-12 Thread Sundar Dorai-Raj

Luis Ridao Cruz wrote on 4/12/2005 10:08 AM:
R-help,
I'm trying to plot the following:
 year  lgd
1  1986 136.97479
2  1987  69.10377
3  1988  67.66744
4  1989  71.60316
5  1990  62.06897
6  1992   6.25000
7  1993  27.72021
8  1995  23.83648
9  1996  10.29412
10 1997  95.67487
11 1998  82.09367
12 1999  56.60401
13 2000  29.80864
14 2001  23.77535
15 2002  48.30378
16 2003  83.47571
17 2004  74.58711
There are 2 missing years 1991 and 1994.
Is it possible to plot this simple data set so that there is not "line"
connection between
1990-1992 and 1993-1995?
I currently use 'plot(, type = "o", pch = 16)' 

I could as well plot 'pieces' of the vectors with "lines" but I was
wondering wether there is a simple function to achieve this.
I run on Windows XP

version
 _  
platform i386-pc-mingw32
arch i386   
os   mingw32
system   i386, mingw32  
status  
major2  
minor0.1
year 2004   
month11 
day  15 
language R  

Thank you in advance

Luis,
Place an NA for 1991 and 1994.
missingData <- data.frame(year = c(1991, 1994), lgd = rep(NA, 2))
newData <- rbind(oldData, missingData)
newData <- newData[order(newData$year), ]
plot(lgd ~ year, newData, type = "o")
HTH,
--sundar
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] not plotting when non-existent

2005-04-12 Thread Luis Ridao Cruz
R-help,

I'm trying to plot the following:

 year  lgd
1  1986 136.97479
2  1987  69.10377
3  1988  67.66744
4  1989  71.60316
5  1990  62.06897
6  1992   6.25000
7  1993  27.72021
8  1995  23.83648
9  1996  10.29412
10 1997  95.67487
11 1998  82.09367
12 1999  56.60401
13 2000  29.80864
14 2001  23.77535
15 2002  48.30378
16 2003  83.47571
17 2004  74.58711

There are 2 missing years 1991 and 1994.
Is it possible to plot this simple data set so that there is not "line"
connection between
1990-1992 and 1993-1995?

I currently use 'plot(, type = "o", pch = 16)' 

I could as well plot 'pieces' of the vectors with "lines" but I was
wondering wether there is a simple function to achieve this.

I run on Windows XP

> version
 _  
platform i386-pc-mingw32
arch i386   
os   mingw32
system   i386, mingw32  
status  
major2  
minor0.1
year 2004   
month11 
day  15 
language R  

Thank you in advance

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] lme problem

2005-04-12 Thread Milos Zarkovic
Sorry for the long letter!
I have recently started using R. For the start I have tried to
repeat examples from Milliken &  Johnson "Analysis of
Messy Data - Analysis of Covariance", but I can not replicate
it in R. The example is chocolate chip experiment. Response
variable vas time to dissolve chocolate chip in seconds (time),
covariate was time to dissolve butterscotch chip (bstime), and
type was a type of chocolate chip. Problem is that I obtain
different degrees of freedom compared to one in the book.
Could it be sum of squares problem (type III vs. type I)?
Milliken & Johnson use SAS for calculations and this
is program the used:
proc mixed data=mmacov method=type3; class type;
model time=type bstime*type/solution noint.
My R code is:
LME.1=lme(time~bstime:type+type-1,data=CCE,random=~1|type)
and summary is:
 Value Std.Error DF 
t-valuep-value
 typeBlue M&M18.0 18.5 0 0.97 
NaN
 typeButton21.6 14.1 0 1.53 
NaN
 typeChoc Chip 16.9 17.7 0 0.96 
NaN
 typeRed M&M26.6 16.0 0 1.66 
NaN
 typeSmall M&M  22.2 30.5 0 0.73 
NaN
 typeSnow Cap 8.7   13.1 0 0.67 
NaN
 bstime:typeBlue M&M 1.1   0.6 24 1.72 
0.098
 bstime:typeButton 1.3   0.4 24 3.57 
0.002
 bstime:typeChoc Chip  1.2   0.7 24 1.60 
0.123
 bstime:typeRed M&M 0.5   0.6 24 0.95 
0.350
 bstime:typeSmall M&M   0.2  1.0  24 0.19 
0.848
 bstime:typeSnow Cap  0.9  0.4  24 2.25 
0.034

However in Milliken & Johnson all df are 23. Values (estimates) are almost 
identical, but there are some small differences in SE and t.

Using
anova(LME.1)
I obtain
   numDF denDF   F-value p-value
type6  0 18.19 NaN
bstime:type 624   4.04  0.0061
but in the book it is:

   numDF denDF  F-value p-value
type6 23   2.00 
0.1075
bstime:type 6 23   4.04  0.0066

Data are at the end of the letter.
I am not sure what I did wrong.
Sincerely,
Milos Zarkovic

**
Milos Zarkovic MD, Ph.D.
Associate Professor of Internal Medicine
Institute of Endocrinology
Dr Subotica 13
11000 Beograd
Serbia
Tel +381-63-202-925
Fax +381-11-685-357
Email [EMAIL PROTECTED]
**












type,person,bstime,time
Button,1,27,53
Choc Chip,2,17,36
Blue M&M,3,28,60
Blue M&M,4,30,45
Red M&M,5,20,30
Choc Chip,6,29,51
Small M&M,7,30,25
Button,8,16,47
Small M&M,9,32,25
Blue M&M,10,19,38
Blue M&M,11,33,48
Button,12,19,39
Snow Cap,13,15,20
Blue M&M,14,19,34
Choc Chip,15,20,40
Blue M&M,16,24,42
Snow Cap,17,21,29
Button,18,35,90
Red M&M,19,35,45
Small M&M,20,30,33
Button,21,34,65
Button,22,40,58
Small M&M,23,22,26
Snow Cap,24,16,23
Button,25,28,72
Blue M&M,26,25,48
Choc Chip,27,14,34
Button,28,23,45
Snow Cap,28,40,44
Blue M&M,30,28,48
Snow Cap,31,19,26
Snow Cap,32,21,29
Small M&M,33,32,30
Red M&M,34,16,32
Red M&M,35,19,47
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] calling svydesign function that uses model.frame

2005-04-12 Thread Thomas Lumley
On Mon, 11 Apr 2005, Richard Valliant wrote:
I need help on calling the svydesign function in the survey package
(although this error appears not to be specific to svydesign). I am
passing parameters incorrectly but am not sure how to correct the
problem.
## Call the main function PS.sim (one of mine).  The dots are
parameters I omitted to simplify the question.
## y.col, str.col, clus.id, and PS.col are names of columns in the
object pop.
PS.sim(pop=small, y.col="NOTCOV",
...,str.col="new.str", clus.id="new.psu",
PS.col="PS.var", ...)
## A data.frame called sam.dat is generated by PS.sim.  Its first 3
lines are:
ID new.str PS.var new.psu NOTCOV   wts
213   1  32 2  37.7
236   1  32 2  37.7
286   1  22 2  37.7

I need to call svydesign with the parms I use to invoke the main
function PS.sim, i.e., ~clus.id and ~str.col.
How do I do that?
Two possibilities
1/ construct a formula with as.formula and paste
svydesign(id=as.formula(paste("~",new.psu)), 
strata=as.formula(paste("~",str.col)),...)
For a working example
data(api)
psu<-"dnum"
svydesign(id=as.formula(paste("~",psu)), weight=~pw,data=apiclus1)
1 - level Cluster Sampling design
With (15) clusters.
svydesign(id = as.formula(paste("~", psu)), weight = ~pw, data = apiclus1)
2/ use substitute()
A working example:
psu<-"dnum"
eval(substitute(svydesign(id=~id,weight=~pw, data=apiclus1),
  list(id=as.name(psu
1 - level Cluster Sampling design
With (15) clusters.
svydesign(id = ~dnum, weight = ~pw, data = apiclus1)
As you can see, the second option is probably more cumbersome but has the 
advantage of producing a prettier-looking call.

-thomas
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] removing characters from a string

2005-04-12 Thread Duncan Murdoch
Martin Maechler wrote:
"Vivek" == Vivek Rao <[EMAIL PROTECTED]>
   on Tue, 12 Apr 2005 05:54:55 -0700 (PDT) writes:

Vivek> Is there a simple way in R to remove all characters
Vivek> from a string other than those in a specified set? For
Vivek> example, I want to keep only the digits 0-9 in a
Vivek> string.
Vivek> In general, I have found the string handling abilities
Vivek> of R a bit limited. (Of course it's great for stats in
Vivek> general). Is there a good reference on this? Or should
Vivek> R programmers dump their output to a text file and use
Vivek> something like Perl or Python for sophisticated text
Vivek> processing?
Vivek> I am familiar with the basic functions such as nchar,
Vivek> substring, as.integer, print, cat, sprintf etc.
It depends on your "etc":
The above is pretty trivial using gsub(),
but since you sound sophisticated enough to proclaim missing R
abilities, I leave the exercise to you.
Part of the problem here is our help system.  gsub is documented within 
the grep topic, so when you look at the keyword==character topics, you 
don't see it explicitly.  (You do see "pattern matching and 
replacement", which should have been a hint.)  And if you were looking 
for "string handling" under the programming category, you're completely 
out of luck.

Another reason some people might see R's string handling as limited is 
that it is sometimes more cumbersome to manipulate strings in R than in 
other languages.  For example, I vaguely recall that there's a good 
reason why R doesn't use "+" to concatenate strings, but I can't 
remember what it is.  And sometimes I'd like to strip whitespace or pad 
things to a given width; I generally need to define my own functions to 
do that each time.  R is capable of concatenation, stripping and 
padding, but is sometimes a little obscure in how it does them.

Duncan Murdoch
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] where is internal function of sample()?

2005-04-12 Thread Thomas Lumley
On Mon, 11 Apr 2005, Marc Schwartz wrote:
A general pattern for C .Internal functions is to use a prefix of "do_"
in conjunction with the R function name. So in this case, the C function
is called do_sample and begins at line 391 (for 2.0.1 patched) in the
aforementioned C source file.
and in the case of the few exceptions to this rule you can look in names.c 
for a complete table.

-thomas
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] removing characters from a string

2005-04-12 Thread Prof Brian Ripley
Using help.start() and searching on keyword "character" or using
help.search(keyword="character") will show you what you have missed.
As others have pointed out, you have missed the power of regular 
expressions (despite that being how these things are done in Perl).
Also, strsplit() can be very powerful.

On Tue, 12 Apr 2005, Vivek Rao wrote:
Is there a simple way in R to remove all characters
from a string other than those in a specified set? For
example, I want to keep only the digits 0-9 in a
string.
In general, I have found the string handling abilities
of R a bit limited.
Your exploration of them seems more than a bit limited.
(Of course it's great for stats in general). Is there a good reference 
on this? Or should R programmers dump their output to a text file and 
use something like Perl or Python for sophisticated text processing?

I am familiar with the basic functions such as nchar,
substring, as.integer, print, cat, sprintf etc.

--
Brian D. Ripley,  [EMAIL PROTECTED]
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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Re: residuals in VGAM

2005-04-12 Thread Ferdinand Alimadhi
Try  [EMAIL PROTECTED]

-- 
Ferdinand Alimadhi
Programmer / Analyst
Harvard University
The Institute for Quantitative Social Science
(617) 496-0187
[EMAIL PROTECTED]
www.iq.harvard.edu


[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] removing characters from a string

2005-04-12 Thread Robin Hankin
Hi
Try
 gsub("[^0-9]","","af-456utaDFasswe34534%^&%*$h567890ersdfg")
[1] "45634534567890"

HTH
rksh

On Apr 12, 2005, at 01:54 pm, Vivek Rao wrote:
Is there a simple way in R to remove all characters
from a string other than those in a specified set? For
example, I want to keep only the digits 0-9 in a
string.
In general, I have found the string handling abilities
of R a bit limited. (Of course it's great for stats in
general). Is there a good reference on this? Or should
R programmers dump their output to a text file and use
something like Perl or Python for sophisticated text
processing?
I am familiar with the basic functions such as nchar,
substring, as.integer, print, cat, sprintf etc.
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html


--
Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
European Way, Southampton SO14 3ZH, UK
 tel  023-8059-7743
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] removing characters from a string

2005-04-12 Thread Martin Maechler
> "Vivek" == Vivek Rao <[EMAIL PROTECTED]>
> on Tue, 12 Apr 2005 05:54:55 -0700 (PDT) writes:

Vivek> Is there a simple way in R to remove all characters
Vivek> from a string other than those in a specified set? For
Vivek> example, I want to keep only the digits 0-9 in a
Vivek> string.

Vivek> In general, I have found the string handling abilities
Vivek> of R a bit limited. (Of course it's great for stats in
Vivek> general). Is there a good reference on this? Or should
Vivek> R programmers dump their output to a text file and use
Vivek> something like Perl or Python for sophisticated text
Vivek> processing?

Vivek> I am familiar with the basic functions such as nchar,
Vivek> substring, as.integer, print, cat, sprintf etc.

It depends on your "etc":

The above is pretty trivial using gsub(),
but since you sound sophisticated enough to proclaim missing R
abilities, I leave the exercise to you.

Martin

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] removing characters from a string

2005-04-12 Thread Bill West
gsub("[^0-9]","","ab9c81")

HTH
--Bill

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Liaw, Andy
Sent: Tuesday, April 12, 2005 9:03 AM
To: 'Vivek Rao'; r-help@stat.math.ethz.ch
Subject: RE: [R] removing characters from a string

Just gsub() non-numerics with ""; e.g.:

> gsub("[a-zA-Z]", "", "aB9c81")
[1] "981"

[I'm really bad in regular expressions, and don't know how to construct
"non-numerics".]

Andy

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] removing characters from a string

2005-04-12 Thread Barry Rowlingson
Liaw, Andy wrote:
Just gsub() non-numerics with ""; e.g.:

gsub("[a-zA-Z]", "", "aB9c81")
[1] "981"
[I'm really bad in regular expressions, and don't know how to construct
"non-numerics".]
 Use a ^ to negate a character range:
> gsub("[^0-9]", "", "aB9c81")
[1] "981"
Baz
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] removing characters from a string

2005-04-12 Thread John Fox
Dear Vivek,

Actually, I think R has reasonably good facilities for manipulating strings.
See ?gsub etc.; for example:

gsub("[^0-9]", "", "XKa0&*1jk2")
[1] "012"

I hope this helps,
 John


John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Vivek Rao
> Sent: Tuesday, April 12, 2005 7:55 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] removing characters from a string
> 
> Is there a simple way in R to remove all characters from a 
> string other than those in a specified set? For example, I 
> want to keep only the digits 0-9 in a string.
> 
> In general, I have found the string handling abilities of R a 
> bit limited. (Of course it's great for stats in general). Is 
> there a good reference on this? Or should R programmers dump 
> their output to a text file and use something like Perl or 
> Python for sophisticated text processing?
> 
> I am familiar with the basic functions such as nchar, 
> substring, as.integer, print, cat, sprintf etc.
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] removing characters from a string

2005-04-12 Thread Marc Schwartz
On Tue, 2005-04-12 at 05:54 -0700, Vivek Rao wrote:
> Is there a simple way in R to remove all characters
> from a string other than those in a specified set? For
> example, I want to keep only the digits 0-9 in a
> string.
> 
> In general, I have found the string handling abilities
> of R a bit limited. (Of course it's great for stats in
> general). Is there a good reference on this? Or should
> R programmers dump their output to a text file and use
> something like Perl or Python for sophisticated text
> processing?
> 
> I am familiar with the basic functions such as nchar,
> substring, as.integer, print, cat, sprintf etc.

Something like the following should work:

> x <- paste(sample(c(letters, LETTERS, 0:9), 50, replace = TRUE),
 collapse = "")

> x
[1] "QvuuAlSJYUFpUpwJomtCir8TfvNQyV6O7W7TlXSXlLHocCdtnV"

> gsub("[^0-9]", "", x)
[1] "8677"

The use of gsub() here replaces any characters NOT in 0:9 with a "",
therefore leaving only the digits.

See ?gsub for more information.

HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] removing characters from a string

2005-04-12 Thread Dimitris Rizopoulos
look at "?gsub()", e.g.,
string <- "ab03def10-523rtf"
string
gsub("[^0-9]", "", string)
gsub("[0-9]", "", string)
I hope it helps.
Best,
Dimitris

Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
- Original Message - 
From: "Vivek Rao" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, April 12, 2005 2:54 PM
Subject: [R] removing characters from a string


Is there a simple way in R to remove all characters
from a string other than those in a specified set? For
example, I want to keep only the digits 0-9 in a
string.
In general, I have found the string handling abilities
of R a bit limited. (Of course it's great for stats in
general). Is there a good reference on this? Or should
R programmers dump their output to a text file and use
something like Perl or Python for sophisticated text
processing?
I am familiar with the basic functions such as nchar,
substring, as.integer, print, cat, sprintf etc.
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] removing characters from a string

2005-04-12 Thread Deepayan Sarkar
On Tuesday 12 April 2005 08:03, Liaw, Andy wrote:
> Just gsub() non-numerics with ""; e.g.:
> > gsub("[a-zA-Z]", "", "aB9c81")
>
> [1] "981"
>
> [I'm really bad in regular expressions, and don't know how to
> construct "non-numerics".]

(So am I, but) perhaps "[^0-9]".

Deepayan

>
> Andy
>
> > From: Vivek Rao
> >
> > Is there a simple way in R to remove all characters
> > from a string other than those in a specified set? For
> > example, I want to keep only the digits 0-9 in a
> > string.
> >
> > In general, I have found the string handling abilities
> > of R a bit limited. (Of course it's great for stats in
> > general). Is there a good reference on this? Or should
> > R programmers dump their output to a text file and use
> > something like Perl or Python for sophisticated text
> > processing?
> >
> > I am familiar with the basic functions such as nchar,
> > substring, as.integer, print, cat, sprintf etc.
> >
> > __
> > R-help@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] abline() with xyplot()

2005-04-12 Thread Deepayan Sarkar
On Tuesday 12 April 2005 07:38, Chloe ARCHINARD wrote:
> Hello all,
> I'm a new user on R, and I used the abline function to draw a line on
> my graph but it doesn't work with xyplot(). With the plot function,
> abline() is ok but with plot it doesn't make what I want. Maybe it's
> a little thing to change in plot() but I don't find what! With xyplot
> I write this :
> Xyplot(m~ordered(l,levels=1),
> type="b",xlab="lagdist",ylab="Moran'I",lty=1,lwd=2,cex=1.5,pch=pch)
> Abline(h=0,lty=2)

I'm not aware of anything called 'Xyplot' or 'Abline' (note that R is 
case sensitive).

> There's no error message but no line too.
> If someone see my error or know how to do, thanks in advance.

'xyplot' is part of a graphics system that is different from standard R 
graphics. If you want to use it, you first need to learn how. 
help(Lattice) has some pointers that should get you started. 

In this case, you probably want something like

xyplot(m ~ ordered(l, levels=1),
   type="b", xlab="lagdist",
   ylab="Moran'I", lty=1, lwd=2, 
   cex=1.5, pch=pch, 
   panel = function(...) {
   panel.abline(h = 0, lty = 2)
   panel.xyplot(...)
   })

-Deepayan

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] removing characters from a string

2005-04-12 Thread Liaw, Andy
Just gsub() non-numerics with ""; e.g.:

> gsub("[a-zA-Z]", "", "aB9c81")
[1] "981"

[I'm really bad in regular expressions, and don't know how to construct
"non-numerics".]

Andy


> From: Vivek Rao
> 
> Is there a simple way in R to remove all characters
> from a string other than those in a specified set? For
> example, I want to keep only the digits 0-9 in a
> string.
> 
> In general, I have found the string handling abilities
> of R a bit limited. (Of course it's great for stats in
> general). Is there a good reference on this? Or should
> R programmers dump their output to a text file and use
> something like Perl or Python for sophisticated text
> processing?
> 
> I am familiar with the basic functions such as nchar,
> substring, as.integer, print, cat, sprintf etc.
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
> 
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] removing characters from a string

2005-04-12 Thread Vivek Rao
Is there a simple way in R to remove all characters
from a string other than those in a specified set? For
example, I want to keep only the digits 0-9 in a
string.

In general, I have found the string handling abilities
of R a bit limited. (Of course it's great for stats in
general). Is there a good reference on this? Or should
R programmers dump their output to a text file and use
something like Perl or Python for sophisticated text
processing?

I am familiar with the basic functions such as nchar,
substring, as.integer, print, cat, sprintf etc.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] abline() with xyplot()

2005-04-12 Thread Dimitris Rizopoulos
probably you want to look at this: help(panel.abline, 
package="lattice")

I hope it helps.
Best,
Dimitris

Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
- Original Message - 
From: "Chloe ARCHINARD" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, April 12, 2005 2:38 PM
Subject: [R] abline() with xyplot()

Hello all,
I'm a new user on R, and I used the abline function to draw a line on 
my graph but it doesn't work with xyplot(). With the plot function, 
abline() is ok but with plot it doesn't make what I want. Maybe it's a 
little thing to change in plot() but I don't find what!
With xyplot I write this :
Xyplot(m~ordered(l,levels=1), 
type="b",xlab="lagdist",ylab="Moran'I",lty=1,lwd=2,cex=1.5,pch=pch)
Abline(h=0,lty=2)
There's no error message but no line too.
If someone see my error or know how to do, thanks in advance.

Chloé Archinard
CEFE-CNRS
1919 Route de Mende
34293 Montpellier, Cedex 5, France
--
passerelle antivirus du campus CNRS de Montpellier
--

[[alternative HTML version deleted]]
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] abline() with xyplot()

2005-04-12 Thread Chloe ARCHINARD
Hello all,
I'm a new user on R, and I used the abline function to draw a line on my graph 
but it doesn't work with xyplot(). With the plot function, abline() is ok but 
with plot it doesn't make what I want. Maybe it's a little thing to change in 
plot() but I don't find what!
With xyplot I write this :
Xyplot(m~ordered(l,levels=1), 
type="b",xlab="lagdist",ylab="Moran'I",lty=1,lwd=2,cex=1.5,pch=pch)
Abline(h=0,lty=2)
There's no error message but no line too.
If someone see my error or know how to do, thanks in advance.

Chloé Archinard
CEFE-CNRS 
1919 Route de Mende 
34293 Montpellier, Cedex 5, France

-- 
passerelle antivirus du campus CNRS de Montpellier
--



[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] R as programming language: references?

2005-04-12 Thread A.J. Rossini
On Apr 12, 2005 11:54 AM, Duncan Murdoch <[EMAIL PROTECTED]> wrote:

> > - Original Message - From: "Federico Calboli"
> > <[EMAIL PROTECTED]>
> > To: "r-help" 
> > Sent: Tuesday, April 12, 2005 5:14 PM
> > Subject: [R] R as programming language: references?
> >
> >
> >> Hi All,
> >>
> >> I am looking for references on R as a programming language (apart form
> >> the standard R-lang.pdf and the other manuals), reference that would
> >> cover _in_depth_ things like loops, code optimisation, debugging tools
> >> etc... and is as up-to-date as possible.
> >>
> >> Can anyone suggest any book or other reference apart from the "green
> >> book" and the V&R "S-programming"?
> 
> I think you've already got the best references.

There is always the source.  In a sense, it IS the most in-depth and
up-to-date description of the intricacies of using the language,
though it isn't as easy to read as V&R's S Programming.

In-depth and up-to-date are tradeoffs rather than being complementary.

best,
-tony

"Commit early,commit often, and commit in a repository from which we can easily
roll-back your mistakes" (AJR, 4Jan05).

A.J. Rossini
[EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] persp plot

2005-04-12 Thread Uwe Ligges
Dan Gerrard wrote:
Is there a way to mark specific tick points on x, y and z axes? 
 
Also, I'm trying to overlay a persp plot using the command lines(..) but it doesn't appear to work, does anyone know why?
See the examples of ?persp how to add elements to an existing persp() 
plot, in particular the function trans3d() given in the examples.

I'm also trying to rotate the persp plot using rotation but this doesn't work either? I get the error
 
parameter "rotation" couldn't be set in high-level plot() function 
 
does anyone know why?

Because it does not exist. See ?persp.
Uwe Ligges
Thanks for any help.

Send instant messages to your online friends http://uk.messenger.yahoo.com 
	[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] persp plot

2005-04-12 Thread Dan Gerrard
Is there a way to mark specific tick points on x, y and z axes? 
 
Also, I'm trying to overlay a persp plot using the command lines(..) but it 
doesn't appear to work, does anyone know why?
 
I'm also trying to rotate the persp plot using rotation but this doesn't work 
either? I get the error
 
parameter "rotation" couldn't be set in high-level plot() function 
 
does anyone know why?
 
Thanks for any help.



Send instant messages to your online friends http://uk.messenger.yahoo.com 
[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] R as programming language: references?

2005-04-12 Thread Duncan Murdoch
Feng Chen wrote:
> Maybe you can try this:
> http://cran.r-project.org/doc/manuals/fullrefman.pdf

No, that's just documentation for the standard library functions.

> - Original Message - From: "Federico Calboli" 
> <[EMAIL PROTECTED]>
> To: "r-help" 
> Sent: Tuesday, April 12, 2005 5:14 PM
> Subject: [R] R as programming language: references?
> 
> 
>> Hi All,
>>
>> I am looking for references on R as a programming language (apart form
>> the standard R-lang.pdf and the other manuals), reference that would
>> cover _in_depth_ things like loops, code optimisation, debugging tools
>> etc... and is as up-to-date as possible.
>>
>> Can anyone suggest any book or other reference apart from the "green
>> book" and the V&R "S-programming"?

I think you've already got the best references.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] R as programming language: references?

2005-04-12 Thread Federico Calboli
On Tue, 2005-04-12 at 17:45 +0800, Feng Chen wrote:
> Maybe you can try this:
> http://cran.r-project.org/doc/manuals/fullrefman.pdf

I was thinking of something that would not limit itself to defining all
possible functions and that I do not have already on my HD...


F
-- 
Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St Mary's Campus
Norfolk Place, London W2 1PG

Tel  +44 (0)20 7594 1602 Fax (+44) 020 7594 3193

f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] R as programming language: references?

2005-04-12 Thread Feng Chen
Maybe you can try this:
http://cran.r-project.org/doc/manuals/fullrefman.pdf
- Original Message - 
From: "Federico Calboli" <[EMAIL PROTECTED]>
To: "r-help" 
Sent: Tuesday, April 12, 2005 5:14 PM
Subject: [R] R as programming language: references?


Hi All,
I am looking for references on R as a programming language (apart form
the standard R-lang.pdf and the other manuals), reference that would
cover _in_depth_ things like loops, code optimisation, debugging tools
etc... and is as up-to-date as possible.
Can anyone suggest any book or other reference apart from the "green
book" and the V&R "S-programming"?
Cheers,
Federico Calboli
--
Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St Mary's Campus
Norfolk Place, London W2 1PG
Tel  +44 (0)20 7594 1602 Fax (+44) 020 7594 3193
f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] R as programming language: references?

2005-04-12 Thread Federico Calboli
Hi All,

I am looking for references on R as a programming language (apart form
the standard R-lang.pdf and the other manuals), reference that would
cover _in_depth_ things like loops, code optimisation, debugging tools
etc... and is as up-to-date as possible. 

Can anyone suggest any book or other reference apart from the "green
book" and the V&R "S-programming"?

Cheers,

Federico Calboli

-- 
Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St Mary's Campus
Norfolk Place, London W2 1PG

Tel  +44 (0)20 7594 1602 Fax (+44) 020 7594 3193

f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] TSeries GARCH Estimates accuracy

2005-04-12 Thread Patrick Burns
GARCH models are notoriously hard to optimize, so I'm not terribly
surprised.
The first thing is to make sure that your reference results are really 
better
than what you are getting in R.  Perhaps they have improved it, but the
last time I looked at garch in S-PLUS, it did not necessarily give good
results.  I don't know anything about the SAS routine.

The first-aid approach to getting better estimates is to start the 
optimization
at various locations and pick the best one you get.  One starting point 
might
be near to (.05, .9) -- that is, .9 times the lagging conditional 
variance. 
Another would be to restart from where the routine ended.  From the help
file for 'garch' it says that the default starting point is with values 
close to
zero -- that is not a very good starting point.

A more involved approach would be to change the routine so that the 
intercept
is derived from the desired asymptotic variance (usually the unconditional
variance) and the other parameter estimates.  Optimizers tend to be much
happier with this problem.

The R-sig-finance list is a more likely spot for a discussion like this.
Patrick Burns
Burns Statistics
[EMAIL PROTECTED]
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")
Sanjay Kumar Singh wrote:
Hi,
I am trying to fit a GARCH(1,1) model to a financial timeseries using the 'garch' function in the tseries package. However the parameter estimates obtained sometimes match with those obtained using SAS or S-Plus (Finmetrics) and sometimes show a completely different result. I understand that this could be due to the way optimization of MLEs are done, however, I would appreciate any help to obtain consistent results using R. 

Also is there any garch simulation function available other than garchSim from 
fseries package?
Thanks in advance,
Sanjay
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

 

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] install own packages

2005-04-12 Thread Uwe Ligges
Christian Hoffmann wrote:
Hi,
Soory, if I missed relevant help pages.
Yes, you missed quite a lot
 - the "R Installation and Administration" manual
 - the help ?install.packages which points you to
 - ?INSTALL
 - and there's also an article on package management
   in the R Help Desk of R-News 3/3
Uwe Ligges

I have developed several packages myself and want to give them to a 
collegue in *.tar.gz form (Unix, Solaris).

What is the proper function to install them? install.packages() with a 
path pointing to the local temp instead of to CRAN?
>
Thanks for help.
Christian
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] R Package: mmlcr and/or flexmix

2005-04-12 Thread Friedrich . Leisch
> On Tue, 12 Apr 2005 00:44:17 -0400,
> Geller, Scott (IHG) (GS() wrote:

  > Greetings 
  > I'm a relatively new R user and I'm trying to build a latent class model.
  > I've used the 'R Site Search' and it appears there's not much dialogue on
  > these packages

[...]


  > libray(flexmix)

  > m1<-flexmix(nts ~ first_brand_HOLIDAY+ perc_zone1+ perc_Group_nights+
  > perc_num_asian+  DaysBetweenStays+ CROStays+ DaysSinceLastStay+
  > wghtmean_median_age_pop100+ perc_num_white+ perc_num_hispanic+
  > perc_CROStays+ numMonthsActive+ WEBStays+ property_loyalty+ perc_NoZone+
  > rho+ PCR_Dummy_class+ ltgold1+ ltgold3+ p_hat_PCR, data = data, k = 2, model
  > = FLXglm(family = "poisson"))

  > rm1<-refit(m1)

  > summary(rm1)

 

[ Scott sent me in private a subset of the data ]

For me this seems to work fine:

R> set.seed(123)
R> m1<-flexmix(nts ~ first_brand_HOLIDAY+ perc_zone1+ perc_Group_nights+
+ perc_num_asian+  DaysBetweenStays+ CROStays+ DaysSinceLastStay+
+ wghtmean_median_age_pop100+ perc_num_white+ perc_num_hispanic+
+ perc_CROStays+ numMonthsActive+ WEBStays+ property_loyalty+ perc_NoZone+
+ rho+ PCR_Dummy_class+ ltgold1+ ltgold3+ p_hat_PCR, data = data, k = 2, model
+ = FLXglm(family = "poisson"))
R> m1

Call:
flexmix(formula = nts ~ first_brand_HOLIDAY + perc_zone1 + perc_Group_nights +
perc_num_asian + DaysBetweenStays + CROStays + DaysSinceLastStay +
wghtmean_median_age_pop100 + perc_num_white + perc_num_hispanic +
perc_CROStays + numMonthsActive + WEBStays + property_loyalty +
perc_NoZone + rho + PCR_Dummy_class + ltgold1 + ltgold3 +
p_hat_PCR, data = data, k = 2, model = FLXglm(family = "poisson"))

Cluster sizes:
  1   2
 93 906

convergence after 49 iterations


R> rm1<-refit(m1)
R>
R> summary(rm1)

Call:
refit(m1)

Component 1 :
  Estimate  Std. Error z value  Pr(>|z|)
(Intercept) 1.0108e+00  6.4399e-01  1.5696 0.1164971
first_brand_HOLIDAY-9.3504e-01  4.6151e-01 -2.0261 0.0427594
perc_zone1  1.3936e-01  7.4383e-01  0.1874 0.8513845
...

-
Component 2 :
  Estimate  Std. Error z value  Pr(>|z|)
(Intercept) 1.00799714  0.39133294  2.5758   0.01000
first_brand_HOLIDAY-0.07928984  0.15935997 -0.4976   0.61880
perc_zone1  0.01208886  0.42596711  0.0284   0.97736
...


So I cannot reproduce the problem. Is maybo one cluster in your
solution empty? The EM algorithm can end up in a local optimum with
one cluster empty ... either run flexmix() several times by hand or
use stepFlexmix() to do so automatically.

HTH,

-- 
---
Friedrich Leisch 
Institut für Statistik Tel: (+43 1) 58801 10715
Technische Universität WienFax: (+43 1) 58801 10798
Wiedner Hauptstraße 8-10/1071
A-1040 Wien, Austria http://www.ci.tuwien.ac.at/~leisch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html