[R] formula parsing, using parts ...

2003-10-27 Thread Russell Senior

I am writing a little abstraction for a series of tests.  For example,
I am running an anova and kruskal.test on a one-factor model.  That
isn't a particular problem, I have an interface like:

 my.function <- function(model,data) {
   print(deparse(substitute(data)))
   a <- anova(lm(formula,data))
   print(a)
   if(a$"Pr(>F)"[1] < 0.05) {
  pairwise.t.test(???)
   }
   b <- kruskal.test(formula,data)
   print(b)
   if ...
 }

I want to run each test, then depending on the resulting p-value, run
pairwise tests.  I am getting into trouble where I put the ??? above.
The pairwise.t.test has a different interface, that seems to want me
to dismember the formula into constituent parts to feed in.  The other
alternative is to give my.function the constituent parts and let it
build the model.  I haven't figured out how to do either one.  Can
someone give me some pointers?

-- 
Russell Senior ``I have nine fingers; you have ten.''
[EMAIL PROTECTED]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] variance component analysis for nested model

2003-10-27 Thread Russell Senior
> "Pascal" == Pascal A Niklaus <[EMAIL PROTECTED]> writes:

Pascal> lme should do the job (r1,r2,r3 are your random factors):
Pascal> library(nlme) y.lme <- lme(y ~ 1,random = ~ 1 | r1/r2/r3)
Pascal> summary(y.lme)

Pascal> This is equivalent to a call to varcomp in S-Plus

Thanks!  This was the clue I needed.

-- 
Russell Senior ``I have nine fingers; you have ten.''
[EMAIL PROTECTED]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] outer function problems

2003-10-27 Thread Scott Norton
I'm pulling my hair (and there's not much left!) on this one. Basically I'm
not getting the same result t when I "step" through the program and evaluate
each element separately than when I use the outer() function in the
FindLikelihood() function below.

 

Here's the functions:

 

Dk<- function(xk,A,B) 

{

n0 *(A*exp(-0.5*(xk/w)^2) + B)

}

 

FindLikelihood <- function(Nk)

{

A <- seq(0.2,3,by=0.2)

B <- seq(0.2,3,by=0.2)

k <-7

L <- outer(A, B, function(A,B) sum( (Nk*log(Dk(seq(-k,k),A,B))) -
Dk(seq(-k,k),A,B) ))

return(L)

}

 

 

where Nk <- c(70 , 67 , 75 , 77 , 74 ,102,  75, 104 , 94 , 74 , 78 , 79 , 83
, 73 , 76)

 

 

Here's an excerpt from my debug session..

 

> Nk

 [1]  70  67  75  77  74 102  75 104  94  74  78  79  83  73  76

> debug(FindLikelihood)

> L<-FindLikelihood(Nk)

debugging in: FindLikelihood(Nk)

debug: {

A <- seq(0.2, 3, by = 0.2)

B <- seq(0.2, 3, by = 0.2)

k <- 7

L <- outer(A, B, function(A, B) sum((Nk * log(Dk(seq(-k, 

k), A, B))) - Dk(seq(-k, k), A, B)))

return(L)

}

Browse[1]> n

debug: A <- seq(0.2, 3, by = 0.2)

Browse[1]> n

debug: B <- seq(0.2, 3, by = 0.2)

Browse[1]> n

debug: k <- 7

Browse[1]> n

debug: L <- outer(A, B, function(A, B) sum((Nk * log(Dk(seq(-k, k), 

A, B))) - Dk(seq(-k, k), A, B)))

Browse[1]> sum((Nk * log(Dk(seq(-k, k),0.2,0.2))) - Dk(seq(-k, k), 0.2,
0.2))  # WHY DOES THIS LINE GIVE ME THE CORRECT RESULT WHEN I SUBSTITUTE
0.2, 0.2 FOR A AND B

[1] 2495.242

Browse[1]> outer(A, B, function(A, B) sum((Nk * log(Dk(seq(-k, k), 

+ A, B))) - Dk(seq(-k, k), A, B)))

  [,1] [,2] [,3] [,4] [,5] [,6] [,7]
[,8]

 [1,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48
58389.48# BUT ELEMENT (1,1) WHICH SHOULD ALSO BE (A,B) = (0.2, 0.2),
GIVES THE INCORRECT RESULT

 [2,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48
58389.48

 [3,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48
58389.48

 [4,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48
58389.48

 [5,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48
58389.48

 [6,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48
58389.48

 [7,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48
58389.48

 [8,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48
58389.48

 [9,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48
58389.48

[10,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48
58389.48

[11,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48
58389.48

[12,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48
58389.48

[13,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48
58389.48

[14,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48
58389.48

[15,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48
58389.48

  [,9][,10][,11][,12][,13][,14][,15]

 [1,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48

 [2,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48

 [3,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48

 [4,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48

 [5,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48

 [6,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48

 [7,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48

 [8,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48

 [9,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48

[10,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48

[11,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48

[12,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48

[13,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48

[14,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48

[15,] 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48 58389.48

Browse[1]>

 

As "commented" above, when I evaluate a single A,B element (i.e. A=0.2,
B=0.2) I get a different result than when I use OUTER() which should also be
evaluating at A=0.2, B=0.2??

 

Any help appreciated.  I know I'm probably doing something overlooking
something simple, but can anyone point it out???

 

Thanks!

-Scott

 

Scott Norton, Ph.D.

Engineering Manager

Nanoplex Technologies, Inc.

2375 Garcia Ave.

Mountain View, CA 94043

www.nanoplextech.com

 


[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] stacking histograms

2003-10-27 Thread Liaw, Andy
The hist() function expects to be given data, not the counts in the bins.
It sounded like you are giving hist() the counts.

One thing you may try is by constructing an object of class "histogram" by
hand (see the "Value" section of ?hist), and just plot() it.  However,
beware that by default hist() tries to create a true density; i.e., the
total area of the bars should sum to one.  If you just plot the counts and
the bins do not have contant width, then your plot will look a bit strange.

For "stacking", your barplot() approach is probably easiest, but again be
careful how you read the resulting graph.

HTH,
Andy

> -Original Message-
> From: Rajarshi Guha [mailto:[EMAIL PROTECTED] 
> Sent: Monday, October 27, 2003 9:33 PM
> To: [EMAIL PROTECTED]
> Subject: [R] stacking histograms
> 
> 
> Hi,
>   I have a set of observations which are divided into two 
> sets A and B. I have some code that bins the dataset into 10 
> bins based on the max and min of the observed values. 
> 
> I would like to make a histogram of A & B using my calculated 
> bins but plot the distribution of B on top of A (like a 
> stacked barplot). This is possible since both sets A & B are 
> binned using the same bin ranges.
> 
> I have my data in the format:
> 
> -4.00 -3.453000 23
> -3.453000 -2.906000 1
> -2.906000 -2.359000 5
> -2.359000 -1.812000 5
> -1.812000 -1.265000 5
> -1.265000 -0.718000 13
> -0.718000 -0.171000 21
> -0.171000 0.376000 49
> 0.376000 0.923000 26
> 0.923000 2.017000 13
> 
> where the first column is the lower value for the bin, the 
> second column the upper value for the bin and the last column 
> is the frequency for that bin
> 
> When I call the hist() function I get
> 
> > depv <- scan('depv.txt') # a vector of observed values
> >
> > # the bin boundaries described above
> > breakvals <- read.table('bindata.txt')
> >
> > hist(depvt, breaks=breakvals$V1)
> >
> Error in hist.default(depvt, breaks = br$V1) :
> some `x' not counted; maybe `breaks' do not span range of `x'
> 
> I get the same error when I specify breakvals$V2. 
> 
> Some of my observed values lie beyond the lower boundary of 
> the last bin (last item of column 1) or below the upper 
> boundary of my first bin (first row of column 2). Is this the 
> reason why this error occurs?
> 
> How should I specify the breaks?
> 
> In addition is there any way I can plot the two histograms on 
> top of each other?
> 
> I have tried using the barplot() function but when it comes 
> to marking the x axis I'm not sure a to how to proceed. What 
> I have been doing is to calculate the mid point of each bin 
> and use that as the label for each column - is this a valid 
> way to represent the histogram? (This way it is easy for me 
> to plot the histograms for the two sets together)
> 
> Thanks
> 
> ---
> Rajarshi Guha <[EMAIL PROTECTED]> 
> GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
> ---
> "A fractal is by definition a set for which the Hausdorff 
> Besicovitch dimension strictly exceeds the topological dimension."
> -- Mandelbrot, "The Fractal Geometry of Nature"
> 
> __
> [EMAIL PROTECTED] mailing list 
> https://www.stat.math.ethz.ch/mailman/listinfo> /r-help
>

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] stacking histograms

2003-10-27 Thread Rajarshi Guha
Hi,
  I have a set of observations which are divided into two sets A and B.
I have some code that bins the dataset into 10 bins based on the max and
min of the observed values. 

I would like to make a histogram of A & B using my calculated bins but
plot the distribution of B on top of A (like a stacked barplot). This is
possible since both sets A & B are binned using the same bin ranges.

I have my data in the format:

-4.00 -3.453000 23
-3.453000 -2.906000 1
-2.906000 -2.359000 5
-2.359000 -1.812000 5
-1.812000 -1.265000 5
-1.265000 -0.718000 13
-0.718000 -0.171000 21
-0.171000 0.376000 49
0.376000 0.923000 26
0.923000 2.017000 13

where the first column is the lower value for the bin, the second column
the upper value for the bin and the last column is the frequency for
that bin

When I call the hist() function I get

> depv <- scan('depv.txt') # a vector of observed values
>
> # the bin boundaries described above
> breakvals <- read.table('bindata.txt') 
>
> hist(depvt, breaks=breakvals$V1)
>
Error in hist.default(depvt, breaks = br$V1) :
some `x' not counted; maybe `breaks' do not span range of `x'

I get the same error when I specify breakvals$V2. 

Some of my observed values lie beyond the lower boundary of the last bin
(last item of column 1) or below the upper boundary of my first bin
(first row of column 2). Is this the reason why this error occurs?

How should I specify the breaks?

In addition is there any way I can plot the two histograms on top of
each other?

I have tried using the barplot() function but when it comes to marking
the x axis I'm not sure a to how to proceed. What I have been doing is
to calculate the mid point of each bin and use that as the label for
each column - is this a valid way to represent the histogram? (This way
it is easy for me to plot the histograms for the two sets together)

Thanks

---
Rajarshi Guha <[EMAIL PROTECTED]> 
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
---
"A fractal is by definition a set for which the Hausdorff Besicovitch
dimension strictly exceeds the topological dimension."
-- Mandelbrot, "The Fractal Geometry of Nature"

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Error in validityMethod(object): No slot of name "phenoLabels" for this object o

2003-10-27 Thread Suresh Kumar Karanam
Hi,
I was using the affy package in R for sometime. I reinstalled the R 
environment lately due to some other issues and now I get errors when I use 
the function ReadAffy. The error is reproduced here:

Error in validityMethod(object): No slot of name "phenoLabels" for this 
object of class "phenoData"

I don't know what's wrong. Any help appreciated.
thanks,
suresh
_
Never get a busy signal because you are always connected  with high-speed 
Internet access. Click here to comparison-shop providers.  
https://broadband.msn.com

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] New User Question regarding simulations

2003-10-27 Thread Jeff Laake
The book by Borcher's et al Estimating Animal Abundance provides R/S+
code that you may find useful for your work.

Jeff Laake

Bret Collier wrote:
> 
> >R-Users,
> 
> Everyone, I am a new user of R and I was wondering if anyone could point me
> to a reference (book or article) that discusses writing population
> simulations in R (or S).
> 
> Thanks in advance,
> 
> Bret A. Collier
> Arkansas Cooperative Fish and Wildlife Research Unit
> Department of Biological Sciences  SCEN 513
> University of Arkansas
> Fayetteville, AR  72701
> (479) 575-4720
> [EMAIL PROTECTED]
> 
> __
> [EMAIL PROTECTED] mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] New User Question regarding simulations

2003-10-27 Thread Bret Collier

R-Users,
Everyone, I am a new user of R and I was wondering if anyone could point me 
to a reference (book or article) that discusses writing population 
simulations in R (or S).

Thanks in advance,

Bret A. Collier
Arkansas Cooperative Fish and Wildlife Research Unit
Department of Biological Sciences  SCEN 513
University of Arkansas
Fayetteville, AR  72701
(479) 575-4720
[EMAIL PROTECTED]
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] how to set missing values in R

2003-10-27 Thread RBaskin
One way:

x<-c(1,3,-1,0,4)
> x[x>0]<-NA
> x
[1] NA NA -1  0 NA
>

bob


-Original Message-
From: Yulei He [mailto:[EMAIL PROTECTED] 
Sent: Monday, October 27, 2003 4:05 PM
To: [EMAIL PROTECTED]
Subject: [R] how to set missing values in R

Hi, there.

Can I ask how to set up missing values in R? Suppose I want to assign the
missing value to the elements in vector which is greater than zero like
this:

x<-c(1,3,-1,0,4);

after the missing value assignment, x becomes (NA,NA,-1,0,NA).

Thanks!

Yulei


$$$
Yulei He
1586 Murfin Ave. Apt 37
Ann Arbor, MI 48105-3135
[EMAIL PROTECTED]
734-647-0305(H)
734-763-0421(O)
734-763-0427(O)
734-764-8263(fax)
$$

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] how to set missing values in R

2003-10-27 Thread James MacDonald
x[x>0] <- NA



James W. MacDonald
Affymetrix and cDNA Microarray Core
University of Michigan Cancer Center
1500 E. Medical Center Drive
7410 CCGC
Ann Arbor MI 48109
734-647-5623

>>> Yulei He <[EMAIL PROTECTED]> 10/27/03 04:05PM >>>
Hi, there.

Can I ask how to set up missing values in R? Suppose I want to assign
the
missing value to the elements in vector which is greater than zero
like
this:

x<-c(1,3,-1,0,4);

after the missing value assignment, x becomes (NA,NA,-1,0,NA).

Thanks!

Yulei


$$$
Yulei He
1586 Murfin Ave. Apt 37
Ann Arbor, MI 48105-3135
[EMAIL PROTECTED] 
734-647-0305(H)
734-763-0421(O)
734-763-0427(O)
734-764-8263(fax)
$$

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] how to set missing values in R

2003-10-27 Thread Douglas Bates
See the recent discussion about is.na() on this list.  You can do what
you want as

> x<-c(1,3,-1,0,4)
> is.na(x) = x > 0
> x
[1] NA NA -1  0 NA

Yulei He <[EMAIL PROTECTED]> writes:

> Hi, there.
> 
> Can I ask how to set up missing values in R? Suppose I want to assign the
> missing value to the elements in vector which is greater than zero like
> this:
> 
> x<-c(1,3,-1,0,4);
> 
> after the missing value assignment, x becomes (NA,NA,-1,0,NA).

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] how to set missing values in R

2003-10-27 Thread Yulei He
Hi, there.

Can I ask how to set up missing values in R? Suppose I want to assign the
missing value to the elements in vector which is greater than zero like
this:

x<-c(1,3,-1,0,4);

after the missing value assignment, x becomes (NA,NA,-1,0,NA).

Thanks!

Yulei


$$$
Yulei He
1586 Murfin Ave. Apt 37
Ann Arbor, MI 48105-3135
[EMAIL PROTECTED]
734-647-0305(H)
734-763-0421(O)
734-763-0427(O)
734-764-8263(fax)
$$

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] \mathcal symbols in R?

2003-10-27 Thread Paul Murrell
Hi

Michael Grottke wrote:
Hello,

Some time ago, I discovered the possibility of using mathematical 
symbols for axis labels etc. In order ensure consistency between text 
and graphics of some paper, I would like to include the calligraphic H 
(obtained in LaTeX via \mathcal{H}) in several diagrams. Is there any 
way to do so? Is it in general possible to use further mathematical 
fonts like \mathbb and \mathbf in R?


Mostly no.  I don't suppose the Hershey script font is close enough?  e.g.,

plot.new()
text(.5, .5, "F", vfont=c("script", "plain"))
On some devices, it is possible to set a custom font family (e.g., you 
may be able to produce a postscript file with a Type 1 version of the 
mathcal font), but this is only per-file if at all (e.g., it would make 
all text in the file mathcal).  An exception is the windows device -- 
extra fonts can be set up (see the file $RHOME/etc/devga) and accessed 
via the "font" parameter.  e.g.,

plot(1:20, type="n")
text(1:20, 1:20, "F", font=1:20)
In this case, if you can get a True Type version of the mathcal font, 
and set it up properly, then you should be able to do just the text you 
want.

Greater flexibility in the specification of fonts is in the pipeline, 
but is at least an R version away.

HTH

Paul
--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[EMAIL PROTECTED]
http://www.stat.auckland.ac.nz/~paul/
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] how to remove NaN columns ?

2003-10-27 Thread ryszard . czerminski
I received a lot of good advice how to remove NaN columns - thank you all 
!!!
The simplest mechanism to center/scale and remove NaN columns seems to be

> xdata <- data.frame(A = 3:1, B = 1:3, rep(9, 3))
> xs <- scale(xdata)
> mask <- sapply(as.data.frame(xs), function(x) all(is.nan(x)))
> scaled.centered.x <- as.data.frame(xs)[!mask]
> scaled.centered.x
   A  B
1  1 -1
2  0  0
3 -1  1

Note that as.data.frame(xs) is important, because apparently xs from 
scale() function
is not a data frame and if as.data.frame() is omitted in the code fragment 
above we get something like this

> mask <- sapply(xs,  function(x) all(is.nan(x)))
> xs[!mask]
   123   
   10   -1   -101
 

Maybe somebody more knowledgeable could give some explanation for this 
behavior.

Ryszard
[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] expanding factor with NA

2003-10-27 Thread Prof Brian Ripley
On Mon, 27 Oct 2003, Liaw, Andy wrote:

> [OK, it's not so strange: na.action is not a documented argument for
> model.matrix, and the call to model.frame in model.matrix.default does not
> have ..., but shouldn't it?]


o, as it documented as for arguments to other methods.
-- 
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

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] expanding factor with NA

2003-10-27 Thread Liaw, Andy
Strangely (to me), just passing na.action=na.pass to model.matrix doesn't
work:

> f <- factor(rep(letters[1:3], 5))
> is.na(f[sample(15, 3)]) <- TRUE
> model.matrix(~f, data=model.frame(~f, na.action=na.pass))
   (Intercept) fb fc
11  0  0
21  1  0
31  0  1
41  0  0
51 NA NA
61  0  1
71  0  0
81 NA NA
91  0  1
10   1  0  0
11   1  1  0
12   1  0  1
13   1 NA NA
14   1  1  0
15   1  0  1
attr(,"assign")
[1] 0 1 1
attr(,"contrasts")
attr(,"contrasts")$f
[1] "contr.treatment"

> model.matrix(~f, na.action=na.pass)
   (Intercept) fb fc
11  0  0
21  1  0
31  0  1
41  0  0
61  0  1
71  0  0
91  0  1
10   1  0  0
11   1  1  0
12   1  0  1
14   1  1  0
15   1  0  1
attr(,"assign")
[1] 0 1 1
attr(,"contrasts")
attr(,"contrasts")$f
[1] "contr.treatment"

[OK, it's not so strange: na.action is not a documented argument for
model.matrix, and the call to model.frame in model.matrix.default does not
have ..., but shouldn't it?]

Andy

> -Original Message-
> From: Thomas W Blackwell [mailto:[EMAIL PROTECTED] 
> Sent: Monday, October 27, 2003 3:08 PM
> To: J.R. Lockwood
> Cc: [EMAIL PROTECTED]
> Subject: Re: [R] expanding factor with NA
> 
> 
> Perhaps a much simpler method (just thought of it) would be to set
> 
> options(na.action="na.pass")
> 
> before you start.  Or use  na.action=na.pass()  as an 
> argument in the call to  model.frame(), since that's where 
> the problem begins. See  help("na.omit"),  help("model.frame").
> 
> -  tom blackwell  -  u michigan medical school  -  ann arbor  -
> 
> On Mon, 27 Oct 2003, J.R. Lockwood wrote:
> 
> > I have a factor (with "n" observations and "k" levels), with only 
> > "nobs" < n of the observations not missing.  I would like 
> to produce a 
> > (n x k) model matrix with treatment contrasts for this factor, with 
> > rows of NAs placeholding the missing observations.  If I use
> > model.matrix() I get back a (nobs x k) matrix.  Is there an 
> easy way 
> > to get the (n x k) without carrying along a row ID and merging? 
> > Thanks.
> >
> > J.R. Lockwood
> > 412-683-2300 x4941
> > [EMAIL PROTECTED] 
> > http://www.rand.org/methodology/stat/members/lockwood/
> 
> __
> [EMAIL PROTECTED] mailing list 
> https://www.stat.math.ethz.ch/mailman/listinfo> /r-help
>

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] expanding factor with NA

2003-10-27 Thread Thomas W Blackwell
Perhaps a much simpler method (just thought of it) would be to set

options(na.action="na.pass")

before you start.  Or use  na.action=na.pass()  as an argument in
the call to  model.frame(), since that's where the problem begins.
See  help("na.omit"),  help("model.frame").

-  tom blackwell  -  u michigan medical school  -  ann arbor  -

On Mon, 27 Oct 2003, J.R. Lockwood wrote:

> I have a factor (with "n" observations and "k" levels), with only
> "nobs" < n of the observations not missing.  I would like to produce a
> (n x k) model matrix with treatment contrasts for this factor, with
> rows of NAs placeholding the missing observations.  If I use
> model.matrix() I get back a (nobs x k) matrix.  Is there an easy way
> to get the (n x k) without carrying along a row ID and merging?
> Thanks.
>
> J.R. Lockwood
> 412-683-2300 x4941
> [EMAIL PROTECTED]
> http://www.rand.org/methodology/stat/members/lockwood/

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] expanding factor with NA

2003-10-27 Thread Thomas W Blackwell

I would re-expand the model matrix by indexing its (nobs) rows
with a longer vector (of length n) containing the correspondence.
If there is only one term (say "Z") in the formula which contains
the problematic NAs, I would do (roughly)

ff  <- Y ~ Z#  following the example in ?model.matrix
mat <- model.matrix(ff, model.frame(ff, data))[cumsum(!is.na(Z)), ]
mat[is.na(Z), ] <- NA

The second line above creates an  n x k  matrix in which each row
where Z has NA simply duplicates the last preceding non-NA row.
The third line above blanks out those duplicate rows by filling
them with NAs instead.  This simple strategy fails if Z[1] is NA.
I haven't time to think up a solution for that case, other than
permuting rows in the entire data set so that it doesn't happen.

HTH  -  tom blackwell  -  u michigan medical school  -  ann arbor  -

On Mon, 27 Oct 2003, J.R. Lockwood wrote:

> I have a factor (with "n" observations and "k" levels), with only
> "nobs" < n of the observations not missing.  I would like to produce a
> (n x k) model matrix with treatment contrasts for this factor, with
> rows of NAs placeholding the missing observations.  If I use
> model.matrix() I get back a (nobs x k) matrix.  Is there an easy way
> to get the (n x k) without carrying along a row ID and merging?
> Thanks.
>
> J.R. Lockwood
> 412-683-2300 x4941
> [EMAIL PROTECTED]
> http://www.rand.org/methodology/stat/members/lockwood/

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] problem using do.call and substitute for predict.glm using poly()

2003-10-27 Thread Gavin Simpson
Dear Thomas,

Thank you for you reply and solution - it works perfectly! It hadn't 
occurred to me that a 1 column subset of a data frame was still a data 
frame and that therefore I didn't need to use data.frame() at all!

To the list as well, please ignore my second mail on this thread. I was 
trying to clarify my particular problem by focussing on what the problem 
actually was, without all the confusing information in the first post. 
It was not my intention to 'hassle' the list until someone provided me 
with an answer. As always, peoples' time and effort that goes into 
helping posters to this list solve their R-related problems is very much 
appreciated, and I for one am extremely grateful for the help I have 
received from the list over the past few years.

Many thanks,

Gav

Thomas Lumley wrote:

On Mon, 27 Oct 2003, Gavin Simpson wrote:


But R throws up the following error:

Error in poly(Alk1, degree = 2, coefs = structure(list(alpha =
c(37.7515662650602,  :
Object "Alk1" not found
When trying to evaluate the following code:

pAsgn <- paste("predList[[i]][[n]] <- try(predict(resList$Y$X, newdata
=   data.frame(X = predData$X), type = 'response', se = TRUE))")
pAsgn <- parse(text = pAsgn)[[1]]
for (i in namY) {
for (n in namX) {
TAsgn <- do.call("substitute", list(pAsgn, list(n = n, i
= i, X  = as.name(n), Y = as.name(i
eval(TAsgn)
}
}
Alk1 is used above as an example, all 23 predictors are 'not found'
depending on which part of the loop I'm in. Investigation of the
predList object after this has run shows for example:
$Unk.nown$NCR
[1] "Error in poly(NCR, degree = 2, coefs = structure(list(alpha =
c(218.156626506024,  : \nObject \"NCR\" not found\n"
attr(,"class")
[1] "try-error"
pAsgn contains a parsed R expression:

predList[[i]][[n]] <- try(predict(resList$Y$X, newdata =
data.frame(X =  predData$X), type = "response", se = TRUE))
I think I have narrowed the problem down to the fact that the first X in
newdata = data.frame(X = predData$X)... is not being substitute with the
variable in question, where as all the other X and Y's are being
substituted:


Yes, that's right.


(n and i would be supplied by for loops (see above) so I have
substituted  two values below as if they had been in the loop)
> do.call("substitute", list(pAsgn, list(n = namX[1], i =
namY[1], X =as.name(n), Y = as.name(i
predList[["Acr.harp"]][["Alk1"]] <- try(predict(resList$Unk.nown$NCR,
newdata = data.frame(X = predData$NCR), type = "response",
se = TRUE))^^ problem here
If i supply the values I want for one of the runs, such as:

> predList[[1]][[1]] <- try(predict(resList$Acr.harp$Alk1, newdata =
data.frame(Alk1 = predData$Alk1), type = "response", se = TRUE))
Then this works, so the question is, how to I get X to be substituted in
the above call? Perhaps this is not the cause of the error, so if anyone
else has other suggestions.


You should be able to use
   newdata=predData[n]
which would substitute to
   newdata=predData["Alk1"]
or even just
   newdata=predData
If you actually needed to substitute the tags you would (I think) need to
work with the parsed expression directly, which is possible but icky:

names(pAsgn[[3]][[2]][[3]])[2]<-"Alk1"
pAsgn
predList[[i]][[n]] <- try(predict(resList$Y$X, newdata = data.frame(Alk1 = 
predData$X),
type = "response", se = TRUE))
	-thomas


--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson [T] +44 (0)20 7679 5522
ENSIS Research Fellow [F] +44 (0)20 7679 7565
ENSIS Ltd. & ECRC [E] [EMAIL PROTECTED]
UCL Department of Geography   [W] http://www.ucl.ac.uk/~ucfagls/cv/
26 Bedford Way[W] http://www.ucl.ac.uk/~ucfagls/
London.  WC1H 0AP.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] problem using do.call and substitute for predict.glm using poly()

2003-10-27 Thread Gavin Simpson
Dear List,

I think I have found the source of my problem in a reply from Thomas 
Lumley to a previous question on R-Help: 
http://www.r-project.org/nocvs/mail/r-help/2002/0586.html

My code is not working because substitute() does not substitute formal 
arguments to functions, and I guess the first X in data.frame(X = 
predData$X) is a formal argument to data.frame().

The recommended options are to use formals() or parse(deparse()) to 
achieve the required effect, but here I get a somewhat stuck.

I was wondering if anyone on the list could show my how to modify my 
existing code:

pAsgn <- paste("predList[[i]][[n]] <- try(predict(resList$Y$X, newdata 
= 	data.frame(X = predData$X), type = 'response', se = TRUE))")
pAsgn <- parse(text = pAsgn)[[1]]
for (i in namY) {
for (n in namX) {
TAsgn <- do.call("substitute", list(pAsgn, list(n = n, i = i, X
		= as.name(n), Y = as.name(i
eval(TAsgn)
}
}

so that data.frame(X = predData$X) is replaced with the value of X such 
that the output from do.call in the loop is something like:

predList[["Acr.harp"]][["Alk1"]] <- try(predict(resList$Acr.harp$Alk1,
newdata = data.frame(Alk1 = predData$Alk1), type = "response",
se = TRUE))
If anyone could point me in the right direction it would be most 
appreciated.

All the best

Gav

Gavin Simpson wrote:

Hi

I am having a particular problem with some glm models I am running. I 
have been adapting code from Bill Venables 'Programmers niche' in RNews 
Vol 2/2 to fit ca. 1000 glm models to a combination of species 0/1 data 
(as Y) and related physicochemical data (X), to automate the process of 
fitting this many models. I have successfully managed to fit all the 
models and have stored the results in a list, each list has 47 main 
'branches' (one for each species) and each branch has 23 'leaves' that 
each contain a glm object

But R throws up the following error:

Error in poly(Alk1, degree = 2, coefs = structure(list(alpha = 
c(37.7515662650602,  :
Object "Alk1" not found

When trying to evaluate the following code:

pAsgn <- paste("predList[[i]][[n]] <- try(predict(resList$Y$X, newdata 
= data.frame(X = predData$X), type = 'response', se = TRUE))")
pAsgn <- parse(text = pAsgn)[[1]]
for (i in namY) {
for (n in namX) {
TAsgn <- do.call("substitute", list(pAsgn, list(n = n, i = i, 
X = as.name(n), Y = as.name(i
eval(TAsgn)
}
}

Alk1 is used above as an example, all 23 predictors are 'not found' 
depending on which part of the loop I'm in. Investigation of the 
predList object after this has run shows for example:

$Unk.nown$NCR
[1] "Error in poly(NCR, degree = 2, coefs = structure(list(alpha = 
c(218.156626506024,  : \nObject \"NCR\" not found\n"
attr(,"class")
[1] "try-error"

pAsgn contains a parsed R expression:

predList[[i]][[n]] <- try(predict(resList$Y$X, newdata = data.frame(X 
= predData$X), type = "response", se = TRUE))

I think I have narrowed the problem down to the fact that the first X in 
newdata = data.frame(X = predData$X)... is not being substitute with the 
variable in question, where as all the other X and Y's are being 
substituted:
(n and i would be supplied by for loops (see above) so I have 
substituted  two values below as if they had been in the loop)

 > do.call("substitute", list(pAsgn, list(n = namX[1], i = namY[1], X 
= as.name(n), Y = as.name(i
predList[["Acr.harp"]][["Alk1"]] <- try(predict(resList$Unk.nown$NCR,
newdata = data.frame(X = predData$NCR), type = "response",
se = TRUE))^^ problem here

If i supply the values I want for one of the runs, such as:

 > predList[[1]][[1]] <- try(predict(resList$Acr.harp$Alk1, newdata = 
data.frame(Alk1 = predData$Alk1), type = "response", se = TRUE))

Then this works, so the question is, how to I get X to be substituted in 
the above call? Perhaps this is not the cause of the error, so if anyone 
else has other suggestions.

Thank you for help.

Gav

ps: version
platform i386-pc-mingw32
arch i386
os   mingw32
system   i386, mingw32
status
major1
minor8.0
year 2003
month10
day  08
language R
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson [T] +44 (0)20 7679 5522
ENSIS Research Fellow [F] +44 (0)20 7679 7565
ENSIS Ltd. & ECRC [E] [EMAIL PROTECTED]
UCL Department of Geography   [W] http://www.ucl.ac.uk/~ucfagls/cv/
26 Bedford Way[W] http://www.ucl.ac.uk/~ucfagls/
London.  WC1H 0AP.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] problem using do.call and substitute for predict.glm using poly()

2003-10-27 Thread Thomas Lumley
On Mon, 27 Oct 2003, Gavin Simpson wrote:

>
> But R throws up the following error:
>
> Error in poly(Alk1, degree = 2, coefs = structure(list(alpha =
> c(37.7515662650602,  :
>  Object "Alk1" not found
>
> When trying to evaluate the following code:
>
> pAsgn <- paste("predList[[i]][[n]] <- try(predict(resList$Y$X, newdata
> = data.frame(X = predData$X), type = 'response', se = TRUE))")
> pAsgn <- parse(text = pAsgn)[[1]]
> for (i in namY) {
>  for (n in namX) {
>  TAsgn <- do.call("substitute", list(pAsgn, list(n = n, i
> = i, X= as.name(n), Y = as.name(i
>  eval(TAsgn)
>  }
> }
>
> Alk1 is used above as an example, all 23 predictors are 'not found'
> depending on which part of the loop I'm in. Investigation of the
> predList object after this has run shows for example:
>
> $Unk.nown$NCR
> [1] "Error in poly(NCR, degree = 2, coefs = structure(list(alpha =
> c(218.156626506024,  : \nObject \"NCR\" not found\n"
> attr(,"class")
> [1] "try-error"
>
> pAsgn contains a parsed R expression:
>
> predList[[i]][[n]] <- try(predict(resList$Y$X, newdata =
> data.frame(X =predData$X), type = "response", se = TRUE))
>
> I think I have narrowed the problem down to the fact that the first X in
> newdata = data.frame(X = predData$X)... is not being substitute with the
> variable in question, where as all the other X and Y's are being
> substituted:

Yes, that's right.

> (n and i would be supplied by for loops (see above) so I have
> substituted  two values below as if they had been in the loop)
>
>  > do.call("substitute", list(pAsgn, list(n = namX[1], i =
> namY[1], X =  as.name(n), Y = as.name(i
> predList[["Acr.harp"]][["Alk1"]] <- try(predict(resList$Unk.nown$NCR,
>  newdata = data.frame(X = predData$NCR), type = "response",
>  se = TRUE))^^ problem here
>
> If i supply the values I want for one of the runs, such as:
>
>  > predList[[1]][[1]] <- try(predict(resList$Acr.harp$Alk1, newdata =
> data.frame(Alk1 = predData$Alk1), type = "response", se = TRUE))
>
> Then this works, so the question is, how to I get X to be substituted in
> the above call? Perhaps this is not the cause of the error, so if anyone
> else has other suggestions.


You should be able to use
   newdata=predData[n]
which would substitute to
   newdata=predData["Alk1"]
or even just
   newdata=predData

If you actually needed to substitute the tags you would (I think) need to
work with the parsed expression directly, which is possible but icky:

> names(pAsgn[[3]][[2]][[3]])[2]<-"Alk1"
> pAsgn
predList[[i]][[n]] <- try(predict(resList$Y$X, newdata = data.frame(Alk1 = predData$X),
type = "response", se = TRUE))


-thomas

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] expanding factor with NA

2003-10-27 Thread J.R. Lockwood
I have a factor (with "n" observations and "k" levels), with only
"nobs" < n of the observations not missing.  I would like to produce a
(n x k) model matrix with treatment contrasts for this factor, with
rows of NAs placeholding the missing observations.  If I use
model.matrix() I get back a (nobs x k) matrix.  Is there an easy way
to get the (n x k) without carrying along a row ID and merging?
Thanks.

J.R. Lockwood
412-683-2300 x4941
[EMAIL PROTECTED]
http://www.rand.org/methodology/stat/members/lockwood/

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Re: assign a constant to a different column for each row

2003-10-27 Thread uaca

Hi again

Thanks all for your fast! reply

regards

Ulisses

Debian GNU/Linux: a dream come true
-
"Computers are useless. They can only give answers."Pablo Picasso

--->Visita http://www.valux.org/ para saber acerca de la<---
--->Asociación Valenciana de Usuarios de Linux  <---

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] assign a constant to a different column for each row

2003-10-27 Thread Prof Brian Ripley
m[1:5 + nrow(m)*c(2,3,1,2,1)] <- 0 if m is a matrix.  Remember you can 
index a matrix as a vector.

If m is a data frame (you didn't say what it is)  I would loop over 
columns (not rows) explicitly, since the code is going to do that 
implicitly.

On Mon, 27 Oct 2003 [EMAIL PROTECTED] wrote:

> 
> Hi all
> 
> I want to assign a constant to a different column for each row
> 
> eg:
> 
> m[1,2] <- 0;
> m[2,3] <- 0;
> m[3,1] <- 0;
> m[4,2] <- 0;
> m[5,1] <- 0;
> ...
> 
> etc...
>   
> i've tried apply/tapply with no luck
> 
> and also the following
> 
> coefs <- rtt.abs[,5:8];
> coefs.i <- coefs[] == 1;
> coefs[coefs.i] <- 0;
> 
> wich results in
> 
> "matrix subscripts not allowed in replacement" 
> 
> error message, for wich I have not found any workaround
> 
> a trivial for() loop is not fast enough
> 
> any help would be greatly appreciated, (maybe a gun too) I'm disperated :-\

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

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] assign a constant to a different column for each row

2003-10-27 Thread M.Kondrin
[EMAIL PROTECTED] wrote:
Hi all

I want to assign a constant to a different column for each row

eg:

m[1,2] <- 0;
m[2,3] <- 0;
m[3,1] <- 0;
m[4,2] <- 0;
m[5,1] <- 0;
...
etc...
  
i've tried apply/tapply with no luck

and also the following

coefs <- rtt.abs[,5:8];
coefs.i <- coefs[] == 1;
coefs[coefs.i] <- 0;
wich results in

"matrix subscripts not allowed in replacement" 

error message, for wich I have not found any workaround

a trivial for() loop is not fast enough

any help would be greatly appreciated, (maybe a gun too) I'm disperated :-\

Thanks in advance

	Ulisses

Debian GNU/Linux: a dream come true
-
"Computers are useless. They can only give answers."Pablo Picasso
---> Visita http://www.valux.org/ para saber acerca de la<---
---> Asociación Valenciana de Usuarios de Linux  <---
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

> cbind(c(1,2,3),c(4,5,6),c(6,7,8))->l
> l
 [,1] [,2] [,3]
[1,]146
[2,]257
[3,]368
> l[1:2,1:3]<-4
> l
 [,1] [,2] [,3]
[1,]444
[2,]444
[3,]368
>
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] assign a constant to a different column for each row

2003-10-27 Thread uaca

Hi all

I want to assign a constant to a different column for each row

eg:

m[1,2] <- 0;
m[2,3] <- 0;
m[3,1] <- 0;
m[4,2] <- 0;
m[5,1] <- 0;
...

etc...
  
i've tried apply/tapply with no luck

and also the following

coefs <- rtt.abs[,5:8];
coefs.i <- coefs[] == 1;
coefs[coefs.i] <- 0;

wich results in

"matrix subscripts not allowed in replacement" 

error message, for wich I have not found any workaround

a trivial for() loop is not fast enough

any help would be greatly appreciated, (maybe a gun too) I'm disperated :-\

Thanks in advance

Ulisses


Debian GNU/Linux: a dream come true
-
"Computers are useless. They can only give answers."Pablo Picasso

--->Visita http://www.valux.org/ para saber acerca de la<---
--->Asociación Valenciana de Usuarios de Linux  <---

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] how to select random rows ?

2003-10-27 Thread Henrik Bengtsson
rowIdx <- sample(nrow(a), size=nbrOfSamples)
a[rowIdx,]

and/or

colIdx <- sample(ncol(a), size=nbrOfSamples)
a[,colIdx]

/Henrik Bengtsson

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> [EMAIL PROTECTED]
> Sent: den 27 oktober 2003 16:26
> To: [EMAIL PROTECTED]
> Subject: [R] how to select random rows ?
> 
> 
> How can I select random subsets (rows!) from a data set ?
> 
> If I generate simple data set
> 
> > a <- data.frame(x=1:2, y = NaN, z = 2:1)
> > a
>   x   y z
> 1 1 NaN 2
> 2 2 NaN 1
> 
> I can select random subsets (colums) very easily using sample 
> function:
> 
> > sample(a, 2)
>   z   y
> 1 2 NaN
> 2 1 NaN
> 
> I expected that using transpose of a would do the same for 
> rows, but I am 
> getting
> rather unexpected outcome
> 
> > sample(t(a), 1)
> 
>1
> 
> R
> 
>   [[alternative HTML version deleted]]
> 
> __
> [EMAIL PROTECTED] mailing list 
> https://www.stat.math.ethz.ch/mailma> n/listinfo/r-help
> 
>

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] neural networks

2003-10-27 Thread Pauline Gu
Thanks so much, Martin and Andy for your help.  I understand it now.

Pauline

At 03:00 PM 10/25/2003 +0200, Martin Maechler wrote:
> "Pauline" == Pauline Gu <[EMAIL PROTECTED]>
> on Fri, 24 Oct 2003 10:03:23 -0700 writes:
Pauline> Hello, experts, Does the number of input for
Pauline> training set need to be the same as the number of
Pauline> input for the data set that I am trying to predict
Pauline> from the nnet result of the training?
If `` the number of input '' is what we usually call
   "number of (explanatory) variables",
then
   the answer is "yes".
If instead, you mean "number of cases", "number of
   observations", or "number of (ex|s)amples"
the answer is "no".
Martin Maechler <[EMAIL PROTECTED]>http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16Leonhardstr. 27
ETH (Federal Inst. Technology)  8092 Zurich SWITZERLAND
phone: x-41-1-632-3408  fax: ...-1228   <><
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] problem using do.call and substitute for predict.glm using poly()

2003-10-27 Thread Gavin Simpson
Hi

I am having a particular problem with some glm models I am running. I 
have been adapting code from Bill Venables 'Programmers niche' in RNews 
Vol 2/2 to fit ca. 1000 glm models to a combination of species 0/1 data 
(as Y) and related physicochemical data (X), to automate the process of 
fitting this many models. I have successfully managed to fit all the 
models and have stored the results in a list, each list has 47 main 
'branches' (one for each species) and each branch has 23 'leaves' that 
each contain a glm object

But R throws up the following error:

Error in poly(Alk1, degree = 2, coefs = structure(list(alpha = 
c(37.7515662650602,  :
Object "Alk1" not found

When trying to evaluate the following code:

pAsgn <- paste("predList[[i]][[n]] <- try(predict(resList$Y$X, newdata 
= 	data.frame(X = predData$X), type = 'response', se = TRUE))")
pAsgn <- parse(text = pAsgn)[[1]]
for (i in namY) {
for (n in namX) {
TAsgn <- do.call("substitute", list(pAsgn, list(n = n, i 
= i, X 			= as.name(n), Y = as.name(i
eval(TAsgn)
}
}

Alk1 is used above as an example, all 23 predictors are 'not found' 
depending on which part of the loop I'm in. Investigation of the 
predList object after this has run shows for example:

$Unk.nown$NCR
[1] "Error in poly(NCR, degree = 2, coefs = structure(list(alpha = 
c(218.156626506024,  : \nObject \"NCR\" not found\n"
attr(,"class")
[1] "try-error"

pAsgn contains a parsed R expression:

predList[[i]][[n]] <- try(predict(resList$Y$X, newdata = 
data.frame(X = 		predData$X), type = "response", se = TRUE))

I think I have narrowed the problem down to the fact that the first X in 
newdata = data.frame(X = predData$X)... is not being substitute with the 
variable in question, where as all the other X and Y's are being 
substituted:
(n and i would be supplied by for loops (see above) so I have 
substituted  two values below as if they had been in the loop)

> do.call("substitute", list(pAsgn, list(n = namX[1], i = 
namY[1], X = 			as.name(n), Y = as.name(i
predList[["Acr.harp"]][["Alk1"]] <- try(predict(resList$Unk.nown$NCR,
newdata = data.frame(X = predData$NCR), type = "response",
se = TRUE))^^ problem here

If i supply the values I want for one of the runs, such as:

> predList[[1]][[1]] <- try(predict(resList$Acr.harp$Alk1, newdata = 
data.frame(Alk1 = predData$Alk1), type = "response", se = TRUE))

Then this works, so the question is, how to I get X to be substituted in 
the above call? Perhaps this is not the cause of the error, so if anyone 
else has other suggestions.

Thank you for help.

Gav

ps: version
platform i386-pc-mingw32
arch i386
os   mingw32
system   i386, mingw32
status
major1
minor8.0
year 2003
month10
day  08
language R
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson [T] +44 (0)20 7679 5522
ENSIS Research Fellow [F] +44 (0)20 7679 7565
ENSIS Ltd. & ECRC [E] [EMAIL PROTECTED]
UCL Department of Geography   [W] http://www.ucl.ac.uk/~ucfagls/cv/
26 Bedford Way[W] http://www.ucl.ac.uk/~ucfagls/
London.  WC1H 0AP.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] how to select random rows ?

2003-10-27 Thread Liaw, Andy
Like this:

a.subset <- a[sample(nrow(a), how.many.I.want), ]

HTH,
Andy

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] 
> Sent: Monday, October 27, 2003 10:26 AM
> To: [EMAIL PROTECTED]
> Subject: [R] how to select random rows ?
> 
> 
> How can I select random subsets (rows!) from a data set ?
> 
> If I generate simple data set
> 
> > a <- data.frame(x=1:2, y = NaN, z = 2:1)
> > a
>   x   y z
> 1 1 NaN 2
> 2 2 NaN 1
> 
> I can select random subsets (colums) very easily using sample 
> function:
> 
> > sample(a, 2)
>   z   y
> 1 2 NaN
> 2 1 NaN
> 
> I expected that using transpose of a would do the same for 
> rows, but I am 
> getting
> rather unexpected outcome
> 
> > sample(t(a), 1)
> 
>1
> 
> R
> 
>   [[alternative HTML version deleted]]
> 
> __
> [EMAIL PROTECTED] mailing list 
> https://www.stat.math.ethz.ch/mailman/listinfo> /r-help
>

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] how to select random rows ?

2003-10-27 Thread ryszard . czerminski
How can I select random subsets (rows!) from a data set ?

If I generate simple data set

> a <- data.frame(x=1:2, y = NaN, z = 2:1)
> a
  x   y z
1 1 NaN 2
2 2 NaN 1

I can select random subsets (colums) very easily using sample function:

> sample(a, 2)
  z   y
1 2 NaN
2 1 NaN

I expected that using transpose of a would do the same for rows, but I am 
getting
rather unexpected outcome

> sample(t(a), 1)

   1

R

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Rpy Import Error

2003-10-27 Thread Dirk Eddelbuettel
On Mon, Oct 27, 2003 at 06:57:08AM -0800, Brett Magill wrote:
> I am trying to install Rpy to test it out as an R
> interface for a project that I am working on. 
> However, I get the following error.  Any clues as to
> what might be going on? I have alo tried RSPython, but
> I gave up due to errors.  RSPython segfaults when
> started from R and gives an error message I can;t
> remember from python.  Thanks, Brett
> 
>  >>> import rpy
>   Traceback (most recent call last):
> File "", line 1, in ?
> File "/usr/lib/python2.2/site-packages/rpy.py",
> line 24, in ?
>   import _rpy
>   ImportError:
> /usr/lib/python2.2/site-packages/_rpymodule.so: 
>   undefined symbol: jump_now
>   >>>

RPy has not been updated to keep up with changes in R.

--- rpy-0.3.1.orig/src/RPy.h
+++ rpy-0.3.1/src/RPy.h
@@ -90,7 +90,8 @@
 PyOS_sighandler_t python_sigint;
 
 /* R function for jumping to toplevel context */
-extern void jump_now(void);
+/* extern void jump_now(void); */
+extern void Rf_onintr(void); 
 
 /* Global interpreter */
 PyInterpreterState *my_interp;
--- rpy-0.3.1.orig/src/R_eval.c
+++ rpy-0.3.1/src/R_eval.c
@@ -65,7 +65,8 @@
 void interrupt_R(int signum)
 {
   interrupted = 1;
-  jump_now();
+  /* jump_now(); */
+  Rf_onintr();
 }
 
 

I have not tested this extensively, though.

Dirk

-- 
Those are my principles, and if you don't like them... well, I have others.
-- Groucho Marx

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] How can strheight be calculated in lattice/grid?

2003-10-27 Thread Deepayan Sarkar

On Monday 27 October 2003 03:50, Wolfram Fischer wrote:
> If I have drawn a string with ``ltext( x, y, labels="first string" )''
> how can a draw a second string just one line (or strheight("X")
> below the first string regardless of the size and scales of the panel?

No reliable (that is, documented and guaranteed not to change) way I can think 
of. But in this situation you should directly use grid.text instead. e.g., 

xyplot(1 ~ 1,
   panel = function(x, y, ...) {
   grid.text("first string", unit(x, "native"), unit(y, "native"))
   grid.text("second string", unit(x, "native"),
 unit(y, "native") - unit(1, "lines"))
   })

There are several other useful 'unit' systems you can use concurrently in 
grid, see ?unit for details.

(In the default scenario, you can replace the first grid.text call by ltext, 
but they could potentially be different because ltext honours some trellis 
settings which grid.text doesn't.)

Deepayan

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Starting and Terminating the JVM for package SJava

2003-10-27 Thread ZABALZA-MEZGHANI Isabelle
Hello,

I would like to know if there is a possibility to open an R session via Java
(using the SJava package), then to terminate it, and re-run another.
It seems not to be possible. If this is the case, I would like to understand
where is the problem or the limitation (is it due to the SJava
implementation, to the Java behavior, or to the R application).
In fact, I am interesting in re-starting new R sessions during a same Java
session to manage memory problems in R with large datasets and numerous
commands through SJava interface (just to "clean" memory).

Waiting for your help,

Regards,

Isabelle.


Isabelle Zabalza-Mezghani
IFP - Reservoir Engineering Department
Rueil-Malmaison / France
Tel : +33 1 47 52 61 99

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Lattice: no grid name space

2003-10-27 Thread Deepayan Sarkar
On Monday 27 October 2003 04:19, Prof Brian Ripley wrote:
> On Mon, 27 Oct 2003, Edzer J. Pebesma wrote:
> > The following now occurs to me when I try to
> >
> > load lattice (R 1.7.1, debian stable):
> > > library(lattice)
> >
> > Error in loadNamespace(i, c(lib.loc, .libPaths()), keep.source) :
> > package `grid' does not have a name space
> > Error in library(lattice) : package/namespace load failed
> >
> > I did an update.packages() as root recently.
> > Any idea what's wrong?
>
> Yes, the current lattice requires 1.8.0.  Its Depends line is
>
> Depends: R (>= 1.7.0), grid (>= 1.8.0), modreg

Yes, I now realize it was somewhat stupid of me to do this. Sorry about that.

Deepayan

> but only versions of R are checked by INSTALL (and that should be R
> (>=1.8.0) as grid is no longer available separately from R).
>
> Time to upgrade to R 1.8.0?  If not, you need to find lattice_0.7.x in
> CRAN's Archive section.

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Rpy Import Error

2003-10-27 Thread Brett Magill
I am trying to install Rpy to test it out as an R
interface for a project that I am working on. 
However, I get the following error.  Any clues as to
what might be going on? I have alo tried RSPython, but
I gave up due to errors.  RSPython segfaults when
started from R and gives an error message I can;t
remember from python.  Thanks, Brett

 >>> import rpy
  Traceback (most recent call last):
File "", line 1, in ?
File "/usr/lib/python2.2/site-packages/rpy.py",
line 24, in ?
  import _rpy
  ImportError:
/usr/lib/python2.2/site-packages/_rpymodule.so: 
  undefined symbol: jump_now
  >>>

I have R-1.8.0 installed as a shared library on a
linux 2.4.22 (slackware 9.1) system, compiled on my
machine with GCC 3.2.3.  I have the most recent
version (0.3.1) of Rpy and python 2.3.1.

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Bioassays Yielding concentration-Mortality data

2003-10-27 Thread Thomas Lumley
On Mon, 27 Oct 2003, Ing. Michael Rost wrote:

> Dear all, I'm trying reproduce an example of bioassays Yielding
> Concentration-Mortality Data particularly control - adjustment model
> from book Bioassay of Entomopathogenic Microbes and Nematodes chapter 7
> with R.
>
> I used glm with family=binomial and link=probit, but I do not know how
> to implement parameter gamma (control mortality - mortality of the
> untreated control insect in this exaple) into model formula.
>
> Model in book:
> pi(x)=gamma+(1-gamma)F(alpha+beta log(x))

This is a generalised linear model but isn't one of the built-in link
functions.  You would have to modify one of the glm family objects to use
this link function, changing the components
linkfun:  the link function
linkinv: the inverse of the link function
mu.eta: the derivative of the inverse of the link function

As a starting point you probably want the family object returned by
binomial(link=probit).

-thomas

> Fcumulative probability distribution function
> data:
> x=concentration
> n=number of insect at each run
> y=number of death among n in given batch run at given concentration
>
>
> Xmat<-data.frame(x=rep(c(0.01,0.1,1,10,100),2),n=rep(100,10),y=c(19,20,21,45,80,25,25,27,56,91))
>
>
>
> Reults from book (obtained from SAS) are
>
> intercept  -1.6597 , beta =0.5586, control mortality --- gamma =0.2172
>
> Thanks for any advice.
> Michael
>
> ---
> Odchozí zpráva neobsahuje viry.
> Zkontrolováno antivirovým systémem AVG (http://www.grisoft.cz).
> Verze: 6.0.530 / Virová báze: 325 - datum vydání: 22.10.2003
>
>   [[alternative HTML version deleted]]
>
> __
> [EMAIL PROTECTED] mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>

Thomas Lumley   Assoc. Professor, Biostatistics
[EMAIL PROTECTED]   University of Washington, Seattle

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] commenting demos

2003-10-27 Thread Spencer Graves
Could one use "cat" for comments, as: 

 cat("this is a comment that may survive 'source'\n")

??
hope this helps.  spencer graves
Martin Maechler wrote:

"Olivia" == Olivia Lau <[EMAIL PROTECTED]>
   on Sun, 26 Oct 2003 00:49:45 -0400 writes:
   

   Olivia> Hi, Is there a way to make demo() print comments
   Olivia> along with the code and output?
not so easily.  The same applies to  example(.).
Both demo(.) and example(.) end up calling source(.) which
itself relies on
1)  parse(...)
2)  eval(...)
parse(.) in R (currently) drops all comments, so they are "lost"
very early in source() and hence everything else that calls source().
Many have wanted a version of source() {and hence demo() and
example() and } that would be able to echo all comments; but
this is not really easy: Somehow you need a version of parse()
{think of multiline statements!} to do this properly.
   Olivia> For example, if I use something like
   Olivia> readline("..."), demo prints both readline("...")
   Olivia> and ...; as far as I can tell, this is also true of
   Olivia> print() and cat().  I just want students to stop and
   Olivia> think about every command in my demo scripts.
One way, not using demo() would be to ask them to read the R
script (e.g. in winedt or emacs) and *send* the commands to a
running R themselves.
But's that's a quite different approach {than demo()}.
Martin
Martin Maechler <[EMAIL PROTECTED]>   http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16Leonhardstr. 27
ETH (Federal Inst. Technology)  8092 Zurich SWITZERLAND
phone: x-41-1-632-3408  fax: ...-1228   <><
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
 

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] commenting demos

2003-10-27 Thread Martin Maechler
> "Olivia" == Olivia Lau <[EMAIL PROTECTED]>
> on Sun, 26 Oct 2003 00:49:45 -0400 writes:

Olivia> Hi, Is there a way to make demo() print comments
Olivia> along with the code and output?

not so easily.  The same applies to  example(.).
Both demo(.) and example(.) end up calling source(.) which
itself relies on
 1)  parse(...)
 2)  eval(...)

parse(.) in R (currently) drops all comments, so they are "lost"
very early in source() and hence everything else that calls source().

Many have wanted a version of source() {and hence demo() and
example() and } that would be able to echo all comments; but
this is not really easy: Somehow you need a version of parse()
{think of multiline statements!} to do this properly.

Olivia> For example, if I use something like
Olivia> readline("..."), demo prints both readline("...")
Olivia> and ...; as far as I can tell, this is also true of
Olivia> print() and cat().  I just want students to stop and
Olivia> think about every command in my demo scripts.

One way, not using demo() would be to ask them to read the R
script (e.g. in winedt or emacs) and *send* the commands to a
running R themselves.

But's that's a quite different approach {than demo()}.
Martin

Martin Maechler <[EMAIL PROTECTED]> http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16Leonhardstr. 27
ETH (Federal Inst. Technology)  8092 Zurich SWITZERLAND
phone: x-41-1-632-3408  fax: ...-1228   <><

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Bioassays Yielding concentration-Mortality data

2003-10-27 Thread Ing. Michael Rost
Dear all,
I'm trying reproduce an example of bioassays Yielding Concentration-Mortality Data 
particularly control - adjustment model from book Bioassay of Entomopathogenic 
Microbes and Nematodes chapter 7 with R.

I used glm with family=binomial and link=probit, but I do not know how to implement 
parameter gamma (control mortality - mortality of the untreated control insect in this 
exaple) into model formula.

Model in book:
pi(x)=gamma+(1-gamma)F(alpha+beta log(x))

Fcumulative probability distribution function 
data:
x=concentration
n=number of insect at each run
y=number of death among n in given batch run at given concentration 


Xmat<-data.frame(x=rep(c(0.01,0.1,1,10,100),2),n=rep(100,10),y=c(19,20,21,45,80,25,25,27,56,91))



Reults from book (obtained from SAS) are

intercept  -1.6597 , beta =0.5586, control mortality --- gamma =0.2172

Thanks for any advice.
Michael

---
Odchozí zpráva neobsahuje viry.
Zkontrolováno antivirovým systémem AVG (http://www.grisoft.cz).
Verze: 6.0.530 / Virová báze: 325 - datum vydání: 22.10.2003

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


AW: [R] Query: IRR Confidence Intervals

2003-10-27 Thread RINNER Heinrich
Hi Cristian,

I don't know about a R routine for exact CIs, but I found a function called
"ageadjust" using a gamma distribution approximation some time ago -take a
look at http://medepi.org/epitools/rfunctions/index.html.
That Webpage seems a bit outdated now, but the calculations given in the
ageadjust functions should still work, I think.

Maybe this helps;
regards
Heinrich.


> -Ursprüngliche Nachricht-
> Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
> Gesendet: Montag, 27. Oktober 2003 14:02
> An: [EMAIL PROTECTED]
> Betreff: [R] Query: IRR Confidence Intervals
> 
> 
> 
> Does anybody know a R routine to calculate exact Confidence 
> Intervals for
> Incidence Rate Ratio?
> 
> Thanks
> Cristian
> 
> 
> -
> Biometria - biometria.univr.it
> 
> __
> [EMAIL PROTECTED] mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Query: IRR Confidence Intervals

2003-10-27 Thread cristian

Does anybody know a R routine to calculate exact Confidence Intervals for
Incidence Rate Ratio?

Thanks
Cristian


-
Biometria - biometria.univr.it

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] (on) first value from nlm (non-finit value supplied by nlm)

2003-10-27 Thread Thomas Bock
Dear R-helpers,

if someone is interested in (last night I dreamed):
 ...
SH <- -3.8
fn.2 <- function(p){
   for (i1 in ilong){
 ex[i1] <- (1E-19*p[1]*n*L*voigt(u,v,f[i1],foN,p[2],p[3])[[1]])
   }
sum((log(tt)-ex)^2)
}
out.2 <-nlm(fn.2, p = c(SH,GG,GL), hessian = TRUE,
  steptol = 1e-6, iterlim = 1000,print.level=2)
SN <-  out.2$estimate[1]*(1E-19)
GGN <- out.2$estimate[2]
GLN <-  out.2$estimate[3]
...
which works:
 ...
iteration = 10
Parameter:
[1] -3.83499  0.005181922  0.006242639
Function Value
[1] 1.068854
Gradient:
[1] -0.01561930  0.02665086 -0.01232618
Successive iterates within tolerance.
Current iterate is probably solution.
...
Another thing: 
Since I receive the R-help digest
I have this in my ~/.emacs:
(custom-set-faces
'(font-lock-string-face ((t (:foreground "green3"
'(font-lock-keyword-face ((t (:foreground "#f939ff"
)
(defun highlight-R-help ()
 (interactive)
 (highlight-regexp "Message:" 'font-lock-keyword-face)
 (highlight-regexp "Date:" 'font-lock-string-face)
 (highlight-regexp "Subject:" 'font-lock-string-face)
 (highlight-regexp "From:" 'font-lock-string-face))

(defun unhighlight-R-help ()
 (interactive)
 (unhighlight-regexp  "Message:" )
 (unhighlight-regexp  "Date:" )
 (unhighlight-regexp  "Subject:")
 (unhighlight-regexp  "From:"))
;;;
regards
Thomas
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] I am looking for the barplot version of histbackback( Hmisc library ) TIA

2003-10-27 Thread parrinel

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Oracle fetch problems

2003-10-27 Thread Prof Brian Ripley
Could you at least tell us which R package(s) and versions you are using 
here?

You can access Oracle databases by ROracle and RODBC and perhaps other
ways.  If this is ROracle, it would be better to use the R-sig-DB list
(see https://www.stat.math.ethz.ch/mailman/listinfo) or talk directly to
the author.

On Mon, 27 Oct 2003, Joerg Schaber wrote:

> relating to my former messages concerning the strange fetch problems I 
> have, I found out that 'fetch' fetches only every second row of the 
> 'native' SQL-results and fills up the rest of the rows with zeros.
> Here a draft for the native SQL-query:
> 
> 12:43:07 SQL>  SELECT OBS_DAY, OBS_YEAR, STAT_ID FROM WILD_PHENO_OBS 
> WHERE PHASE_ID=7 AND OBS_YEAR BETWEEN 1951 AND 2000 order by stat_id, 
> obs_year, obs_day;
> PLEASE HIT RETURN TO CONTINUE
> 
>OBS_DAY   OBS_YEARSTAT_ID
> -- -- --
>133   1954   
>140   1955   
>147   1956   
>133   1957   
>146   1958   
>118   1959   
>132   1960   
>120   1961   
>138   1962   
>144   1963   
> 
> Here what fetches R:
> 
>  >  DBres <- dbSendQuery(DBcon, "SELECT OBS_DAY, OBS_YEAR, STAT_ID FROM 
> WILD_PHENO_OBS WHERE PHASE_ID=7 AND OBS_YEAR BETWEEN 1951 AND 2000 order 
> by stat_id, obs_year, obs_day")
>  >  fetch(DBres,n=10)
>   OBS_DAY OBS_YEAR  STAT_ID
> 0 140 1955 
> 1 133 1957 
> 2 118 1959 
> 3 120 1961 
> 4 144 1963 
> 5   00 
> 6   00 
> 7   00 
> 8   00 
> 9   00 
>  >
> 
> Any idea what's the problem here?
> 
> __
> [EMAIL PROTECTED] mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 
> 

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

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] using variables in obj$model

2003-10-27 Thread Prof Brian Ripley
Model frames do not contain interactions, they contain variables.
`a:b' is not the name of a variable whereas A is.

On Mon, 27 Oct 2003, Vito Muggeo wrote:

> dear all,
> for some reason I am intersted in updating a glm taking variables from its
> model argument, namely:
> 
> > dati<-data.frame(y=runif(10),x=1:10)
> > obj<-glm(y~x,data=dati)
> > obj$model[,c("A","a:b")]<-cbind(rnorm(10),runif(10))
> > names(obj$model)
> [1] "y"   "x"   "A"   "a:b"
> > update(obj,.~.+A,data=obj$model) #it works
> 
> Call:  glm(formula = y ~ x + A, data = obj$model)
> [SNIP]
> 
> > update(obj,.~.+A+a:b,data=obj$model) #it does not work
> Error in eval(expr, envir, enclos) : Object "a" not found

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

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Oracle fetch problems

2003-10-27 Thread Joerg Schaber
relating to my former messages concerning the strange fetch problems I 
have, I found out that 'fetch' fetches only every second row of the 
'native' SQL-results and fills up the rest of the rows with zeros.
Here a draft for the native SQL-query:

12:43:07 SQL>  SELECT OBS_DAY, OBS_YEAR, STAT_ID FROM WILD_PHENO_OBS 
WHERE PHASE_ID=7 AND OBS_YEAR BETWEEN 1951 AND 2000 order by stat_id, 
obs_year, obs_day;
PLEASE HIT RETURN TO CONTINUE

  OBS_DAY   OBS_YEARSTAT_ID
-- -- --
  133   1954   
  140   1955   
  147   1956   
  133   1957   
  146   1958   
  118   1959   
  132   1960   
  120   1961   
  138   1962   
  144   1963   
Here what fetches R:

>  DBres <- dbSendQuery(DBcon, "SELECT OBS_DAY, OBS_YEAR, STAT_ID FROM 
WILD_PHENO_OBS WHERE PHASE_ID=7 AND OBS_YEAR BETWEEN 1951 AND 2000 order 
by stat_id, obs_year, obs_day")
>  fetch(DBres,n=10)
 OBS_DAY OBS_YEAR  STAT_ID
0 140 1955 
1 133 1957 
2 118 1959 
3 120 1961 
4 144 1963 
5   00 
6   00 
7   00 
8   00 
9   00 
>

Any idea what's the problem here?

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Whitehead's group sequential procedures

2003-10-27 Thread Emmanuel Charpentier
Dear List,

I would like to know if there exist some R implementation of John 
Whitehead's procedures for the planning and analysis of group sequential 
clinical trials. His book is enlightenig but somewhat frustrating : it 
has a good basic exposition of his framework, but the technical details 
are sparse, and leave much work to do when one plans to reuimplement 
part of the procedures. For example, one has to work out the computation 
of test regions in non-trivial cases, the P-value and  confidence 
interval building, etc ... Given my abilities, I'd rather *not* do this ...

Did someone implement these procedures in R ? I am aware of a 
(commercial) implementation in S+, but Googling for an R implementation 
(and looking in the r-help archive) was ... well ... frustrating.

If no one did, and there is some interest, I might try to derive the 
necessary steps and reimplement this.

Sincerely,

	Emmanuel Charpentier

PS : please Cc: me your answers, since I'm not on the list and reading 
it through the archives.
--
Emmanuel Charpentier			Tel : +33-(0)1 40 27 35 98
Secrétariat Scientifique du CEDIT	Fax : +33-(0)1 40 27 55 65
Assistance Publique - Hôpitaux de Paris
3, Avenue Victoria, F-75100 Paris RP - France

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] using variables in obj$model

2003-10-27 Thread Vito Muggeo
dear all,
for some reason I am intersted in updating a glm taking variables from its
model argument, namely:

> dati<-data.frame(y=runif(10),x=1:10)
> obj<-glm(y~x,data=dati)
> obj$model[,c("A","a:b")]<-cbind(rnorm(10),runif(10))
> names(obj$model)
[1] "y"   "x"   "A"   "a:b"
> update(obj,.~.+A,data=obj$model) #it works

Call:  glm(formula = y ~ x + A, data = obj$model)
[SNIP]

> update(obj,.~.+A+a:b,data=obj$model) #it does not work
Error in eval(expr, envir, enclos) : Object "a" not found


Please, how can I solve this problem?
many thanks in avance,
best,
vito

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Lattice: no grid name space

2003-10-27 Thread Martin Maechler
> "Edzer" == Edzer J Pebesma <[EMAIL PROTECTED]>
> on Mon, 27 Oct 2003 10:56:57 +0100 writes:

Edzer> The following now occurs to me when I try to load
Edzer> lattice (R 1.7.1, debian stable):

>> library(lattice)
Edzer> Error in loadNamespace(i, c(lib.loc, .libPaths()),
Edzer> keep.source) : package `grid' does not have a name
Edzer> space Error in library(lattice) : package/namespace
Edzer> load failed

Edzer> I did an update.packages() as root recently.  Any
Edzer> idea what's wrong?  -- Edzer

I guess you have a too recent version of lattice for your "old"
version of R.

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Lattice: no grid name space

2003-10-27 Thread Prof Brian Ripley
On Mon, 27 Oct 2003, Edzer J. Pebesma wrote:

> The following now occurs to me when I try to
> load lattice (R 1.7.1, debian stable):
> 
> > library(lattice)
> Error in loadNamespace(i, c(lib.loc, .libPaths()), keep.source) :
> package `grid' does not have a name space
> Error in library(lattice) : package/namespace load failed
> 
> I did an update.packages() as root recently.
> Any idea what's wrong?

Yes, the current lattice requires 1.8.0.  Its Depends line is

Depends: R (>= 1.7.0), grid (>= 1.8.0), modreg

but only versions of R are checked by INSTALL (and that should be R 
(>=1.8.0) as grid is no longer available separately from R).

Time to upgrade to R 1.8.0?  If not, you need to find lattice_0.7.x in
CRAN's Archive section.

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

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Lattice: no grid name space

2003-10-27 Thread Uwe Ligges
Edzer J. Pebesma wrote:

The following now occurs to me when I try to
load lattice (R 1.7.1, debian stable):
library(lattice)
Error in loadNamespace(i, c(lib.loc, .libPaths()), keep.source) :
   package `grid' does not have a name space
Error in library(lattice) : package/namespace load failed
I did an update.packages() as root recently.
Any idea what's wrong?
--
Edzer
Yes. You got a version of lattice that is supposed to work with the grid 
version shipped with R-1.8.0 (and that one has got a namespace).

Uwe Ligges

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Lattice: no grid name space

2003-10-27 Thread Edzer J. Pebesma
The following now occurs to me when I try to
load lattice (R 1.7.1, debian stable):
library(lattice)
Error in loadNamespace(i, c(lib.loc, .libPaths()), keep.source) :
   package `grid' does not have a name space
Error in library(lattice) : package/namespace load failed
I did an update.packages() as root recently.
Any idea what's wrong?
--
Edzer
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] How can strheight be calculated in lattice/grid?

2003-10-27 Thread Wolfram Fischer
If I have drawn a string with ``ltext( x, y, labels="first string" )''
how can a draw a second string just one line (or strheight("X")
below the first string regardless of the size and scales of the panel?

Thanks
Wolfram

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] variance component analysis for nested model

2003-10-27 Thread Prof Brian Ripley
On 26 Oct 2003, Russell Senior wrote:

> 
> Given a set of data:
> 
> > names(data)
> [1] "city" "house" "visit""value"
> 
> I am looking for a way to compute the variance components of the
> nested model (ie, visit 1 at house 2 at city 3 isn't related to visit
> 1 and house 2 at city 4), but different houses in the same city may be
> related, and different visits to the same house are probably related.
> I want to be able to compute how much of the total variance of "value"
> is explained by each of these.  How can I do that in R?

With lme or (if balanced) aov with an Error term.

There are lots of examples about, e.g. in the MASS and nlme scripts from 
the associated books.

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

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] variance component analysis for nested model

2003-10-27 Thread Pascal A. Niklaus
lme should do the job (r1,r2,r3 are your random factors):

   library(nlme)
   y.lme <- lme(y ~ 1,random = ~ 1 | r1/r2/r3)
   summary(y.lme)
This is equivalent to a call to varcomp in S-Plus

Pascal

--

Dr. Pascal A. Niklaus
Institute of Botany
University of Basel
Schönbeinstrasse 6
CH-4056 Basel / Switzerland
Russell Senior wrote:

Given a set of data:

 

names(data)
   

[1] "city" "house" "visit""value"

I am looking for a way to compute the variance components of the
nested model (ie, visit 1 at house 2 at city 3 isn't related to visit
1 and house 2 at city 4), but different houses in the same city may be
related, and different visits to the same house are probably related.
I want to be able to compute how much of the total variance of "value"
is explained by each of these.  How can I do that in R?
Thanks!

 

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] Difficulties with R.oo (static fields, etc.)

2003-10-27 Thread Henrik Bengtsson
This is not really an rhelp question. I'll get back to you later today
with answers related to R.oo.

Henrik Bengtsson
The R.oo author

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> Gabriel Baud-Bovy
> Sent: den 27 oktober 2003 01:56
> To: [EMAIL PROTECTED]
> Subject: [R] Difficulties with R.oo (static fields, etc.)
> 
> 
> I would like to use R.oo and tcltk to implement a Turtle 
> World. I have 
> encountered
> many problems because:
> 
> 1) I am not sure how to implement static fields with R.oo
> 2) I am not sure how to implement a constructor that would
>  call a function only for the first instance of a class (i.e., to 
> initialize
>  value of static fields only once)
> 3) I am not sure how to remove/delete cleanly existing instances. In 
> particular,
>  I don't know how to reset tcktk when the last instance 
> is deleted.
> 
> Here is the sort of behavior I would like to get:
> 
> t1<-TurtleBasic()   # a window (the Turtle world) with a 
> turtle appears
> forward(t1,50)   #  the turtle moves (turtle's state is 
> also updated)
> turn(t1,pi/2)
> forward(t1,50)
> t2<-TurtleBasic()  # a second turtle in the Turtle world appears
> turn(t2,pi/2)  # second turtle moves
> forward(t1,50)
> delete(t1) # first turtle disappears
> delete(t2) # second turtle and the world disappears
> 
> If possible, I would like to keep this syntax. In fact, I am 
> using R.oo to create mutable objects so as to avoid syntax 
> like  tu<-forward(tu,10) which would be more typical of a 
> functional language like R. From the doc/help 
> files of R.oo,
> I believe that one could do it but I don't find many examples 
> to guide me.
> 
> I pasted my current code with comments below. Thank you for your help.
> 
> Gabriel Baud-Bovy
> 
> #-
> 
> 
> Description of Turtle Basic Class:
> 
> private fields:
>.x, .y, .a (turtle position and heading)
>.turtle: ID of canvas item representing turtle
> static fields:
>.canvas: tcltk canvas widget
>.top: tcktk toplevel widget
> methods:
> TurtleBasic: constructor
> plot: display turtle in Turtle World
> forward, turn: move turtle
> delete: delete turtle (not implemented)
> 
> Note: My current code is very buggy:
>   - Can't see turtle movements
>   - Does not define method to delete turtles
>   - I get an tcltk error when I try to recreate a turtle 
> world after having 
> tried to destroy it
> (for the moment, I need to detach tcltk to reset it)
> 
> #-
> 
> 
> library("R.oo")
> 
> setConstructorS3("TurtleBasic",function() {
>new<-extend(Object(),"TurtleBasic",.x=100,.y=100,.a=0,.turtle=NA)
>## Create a new Turtle World if necessary
>require(tcltk) || stop("tcl/ library not available")
>if(!is.tkwin(new$.canvas)) { # check to see if it is first 
> instance or not
>  cat("Create Turtle World\n")
>  top <- tktoplevel()
>  tktitle(top) <- "Turtle World"
>  canvas <- tkcanvas(top, relief="raised", width=200, height=200)
>  tkpack(canvas, side="top", fill="both",expand="1")
>  new$.canvas<-canvas  # store 
> canvas widget in static field
>  new$.top<-top
>}
>plot.TurtleBasic(new)  
> # plot Turtle
>new
> })
> 
> setMethodS3("plot","TurtleBasic",function(turtle) {
>  ## delete old item (if it exists)
>  if(is.tkwin(turtle$.canvas) && is.tclObj(turtle$.turtle)) 
> tkdelete(turtle$.canvas,turtle$.turtle)
>  ## a new canvas item representing the turtle is created
>  ## (note: it's necessary to make new item because 
> turtle's heading can 
> change)
>  x <- c(-10,10)
>  y <- c(-10,10)
>  aux<-   cos(turtle$.a)*x+sin(turtle$.a)*y + turtle$.x
>  y  <-  -sin(turtle$.a)*x+cos(turtle$.a)*y + turtle$.y
>  x  <- aux
>  turtle$.turtle <- tkcreate(turtle$.canvas, "line", 
> x[1],-y[1],x[2],-y[2],width=1)
> })
> 
> setMethodS3("forward","TurtleBasic",function(turtle,length){
>aux   <- turtle$.x + length*cos(turtle$.a)
>turtle$.y <- turtle$.y + length*sin(turtle$.a)
>turtle$.x <- aux
>plot(turtle)
> })
> 
> setMethodS3("turn","TurtleBasic",function(turtle,angle){
> turtle$.a<-turtle$.a+angle
> plot(turtle)
> })
> 
> 
> if(0) {
> 
> t1<-TurtleBasic()  # a window (the Turtle world) with a turtle appears
> forward(t1,50)
> turn(t1,pi/2)
> forward(t1,50)
> t2<-TurtleBasic()  # a second turtle in the Turtle world
> turn(t2,pi/2)
> 
> # manually destroy first turtle (would be great to define 
> some sort of 
> method for it)
> tkdelete(t1$.canvas,t1$.turtle)
> rm(t1)
> # destroy second turtle and world
> tkdelete(t2$.canvas,t2$.turtle)
> tkdestroy(t2$.top)
> rm(t2)
> 
> }
> ---