Re: [R] scoping issues (was help with eval)

2005-05-13 Thread Prof Brian Ripley
You intended quote() rather than expression(), I believe.  If I do
show.a <- function(a) {a}
eval(quote(show.a(a)),envir=my.env)
this works.
R has lexical scoping, so with
show.a <- function() {a}
'a' is looked for in the frame of the function (not defined there) and 
then in the environment of the function.

environment(show.a)

since show.a was defined in the workspace.  The envir arg of eval() is 
used to find the object(s), here `show.a', not to sets its environment.
So my first version works because 'a' is part of the expression.

Perhaps you intended something like
init.env <- function() {
 a <- 200
 show.a <- function() {a}
 environment()
}
my.env <- init.env()
eval(quote(show.a()),envir=my.env)
which works, and is a common R idiom (although via local() or new.env()).
However, you could just do
eval(quote(a), envir=my.env)
[1] 200
eval(expression(a), envir=my.env)
[1] 200
BTW, use typeof() to see the difference here.
On Fri, 13 May 2005, Whit Armstrong wrote:
I've been looking at the help page for eval for a while, but I can't
make sense of why this example does not work.
show.a <- function() {
 a
}
init.env <- function() {
 a <- 200
 environment()
}
my.env <- init.env()
ls(envir=my.env)
# returns this:
# > ls(envir=my.env)
# [1] "a"
# but this does not work:
eval(expression(show.a()),envir=my.env)
# > eval(expression(show.a()),envir=my.env)
# Error in show.a() : Object "a" not found
# >
The help page gives the following:
  'eval' evaluates the expression 'expr' argument in the environment
specified by 'envir' and returns the computed value. If 'envir' is
not specified, then 'sys.frame(sys.parent())', the environment
where the call to 'eval' was made is used.
I would be grateful for any help.
Thanks,
Whit
[[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
--
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] A model package that uses S4 methods and name spaces?

2005-05-13 Thread Prof Brian Ripley
On Fri, 13 May 2005, Douglas Bates wrote:
[EMAIL PROTECTED] wrote:
I'd like to try and rewrite my package to take advantage of S4 methods and
name spaces.  I am presuming that S4 methods and name spaces will help me
write and maintain my package.
Can someone suggest a "model" package that uses best practices for mixing
S3, S4 methods and name spaces?  Preferably a package with multiple R
source files.
It doesn't mix S3 and S4 but the Matrix package is a large package based
on S4 that does show the use of S4 and a NAMESPACE.  On a smaller scale,
the lme4 package also uses S4 and a NAMESPACE.
The stats4 package in the distribution is intended to be a model in the 
sense I think we were asked for.  It is much smaller than Doug's examples.

--
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] multinom(): likelihood of model?

2005-05-13 Thread Prof Brian Ripley
By definition, the deviance is minus twice the maximized log-likelihood 
plus a const.  In any of these models for discrete data, the saturated 
model predicts exactly, so the const is zero.

There are worked examples in MASS4, the book multinom() supports.
On Fri, 13 May 2005, Brooks Miner wrote:
Hi all,
I'm working on a multinomial (or "polytomous") logistic regression using R 
and have made great progress using multinom() from the nnet library.  My 
response variable has three categories, and there are two different possible 
predictors.  I'd like to use the likelihoods of certain models (ie, 
saturated, fitteds, and null) to calculate Nagelkerke R-squared values for 
various fitted models.

My question today is simple: once I have fitted a model using multinom(), how 
do I find the likelihood (or log likelihood) of my fitted model?  I 
understand that this value must be part of the $deviance or $AIC components 
of the fitted model, but my understanding is too limited at this point for me 
to know how to calculate the likelihood of my fitted model from either of 
these outputs.

Thanks in advance to any assistance offered.  I'd be happy to provide an 
example of my data and multinom() entries if that would help.

Gratefully,
- Brooks

Brooks Miner
Research Scientist
Laird Lab
UW Biology
206.616.9385
http://protist.biology.washington.edu/Lairdlab/
__
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] help with eval

2005-05-13 Thread Gabor Grothendieck
The scope of variables within show.a is not affected by the environment
that show.a is called in.  The scope of the variables in show.a
is determined by the lexical scope of show.a although you can change 
this via:

  environment(show.a) <- my.env
  show.a() # 200

If you want to create a function that has dynamic (i.e. scope is the caller), 
rather than lexical scope, do this:

   show2.a <- function() { 
  show2.a <- function() a 
  environment(show2.a) <- parent.frame()
  show2.a()
   }
  evalq(show2.a(), my.env) # 200

or you can create a function which evaluates its body in the parent.frame:

   show3.a <- function() eval.parent(substitute(a))
   evalq(show3.a(), my.env) # 200

Also, depending on what you actually want to do, the proto package
may be applicable.

On 5/13/05, Whit Armstrong <[EMAIL PROTECTED]> wrote:
> I've been looking at the help page for eval for a while, but I can't
> make sense of why this example does not work.
> 
> show.a <- function() {
>  a
> }
> 
> init.env <- function() {
>  a <- 200
>  environment()
> }
> 
> my.env <- init.env()
> 
> ls(envir=my.env)
> 
> # returns this:
> # > ls(envir=my.env)
> # [1] "a"
> 
> # but this does not work:
> eval(expression(show.a()),envir=my.env)
> 
> # > eval(expression(show.a()),envir=my.env)
> # Error in show.a() : Object "a" not found
> # >
> 
> The help page gives the following:
> 
>   'eval' evaluates the expression 'expr' argument in the environment
> specified by 'envir' and returns the computed value. If 'envir' is
> not specified, then 'sys.frame(sys.parent())', the environment
> where the call to 'eval' was made is used.
> 
> I would be grateful for any help.
> 
> Thanks,
> Whit
> 
>[[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


RE: [R] How to convert color to black & white

2005-05-13 Thread OlsenN
Muhammad,
Here's one option:

barplot(1:5,col=gray(seq(0,1,length=5)))

Norm Olsen
Fisheries and Oceans Canada

-Original Message-
From: [EMAIL PROTECTED]
To: R-help@stat.math.ethz.ch
Sent: 5/13/2005 11:40 AM
Subject: [R] How to convert color to black & white

Dear all,
Could someone please explain to me how to convert color to black &
white.
For example:
barplot(1:5,col = rainbow(5))
Because I need to print my plot to save my ink color printer.
I don't want to convert to grayscale, but keep it as an RGB.
I  would be very happy if anyone could help me.
Thank you very much in advance.

Kindly regards,
Muhammad Subianto

__
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 with eval

2005-05-13 Thread Whit Armstrong
I've been looking at the help page for eval for a while, but I can't
make sense of why this example does not work.

show.a <- function() {
  a
}

init.env <- function() {
  a <- 200
  environment()
}

my.env <- init.env()

ls(envir=my.env)

# returns this:
# > ls(envir=my.env)
# [1] "a"


# but this does not work:
eval(expression(show.a()),envir=my.env)

# > eval(expression(show.a()),envir=my.env)
# Error in show.a() : Object "a" not found
# >


The help page gives the following:

   'eval' evaluates the expression 'expr' argument in the environment
 specified by 'envir' and returns the computed value. If 'envir' is
 not specified, then 'sys.frame(sys.parent())', the environment
 where the call to 'eval' was made is used.

I would be grateful for any help.

Thanks,
Whit


[[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] Big matrix memory problem

2005-05-13 Thread Spencer Graves
	  S-Plus 7 advertises facilities for large data sets 
(http://www.insightful.com/products/splus/default.asp#largedata).  Their 
web site says they do this with "New Pipeline Architecture" that 
"streams large data sets through available RAM instead of reading the 
entire data set into memory at once."  It also "includes a new data type 
for dealing with very large data objects".  If you want more than this, 
I suggest you post to "S-News List <[EMAIL PROTECTED]>";  I 
haven't used it.

  hope this helps.
  spencer graves
Gabor Grothendieck wrote:
On 5/13/05, s104100026 <[EMAIL PROTECTED]> wrote:
Hi All,
I want to read 256 1000x1000 matrices into R. I understand that it is unlikely
that I can do this but In the hope that somebody can help me I am mailing this
list.
I have tried increasing my memory size (I understand that it is the minimum of
1024 or the computers RAM in my case 512)
Does anyone think this is possible in R, could it be tried in Splus for
example.

If they are sparse you could try the SparseM package.
__
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] where is aggregateSeries

2005-05-13 Thread Gabor Grothendieck
On 5/13/05, Omar Lakkis <[EMAIL PROTECTED]> wrote:
> What package is aggregateSeries in?
> It is referred to in the fCalendar document but I do not see it in the 
> package.

Don't know but aggregate is available in R with a variety of methods
and the zoo package also supplies a zoo method.

__
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] problem with as.timeSeries()

2005-05-13 Thread Wojtek Slusarski
The matrix I want to convert to timeSeries object looks:
  rp
2003-06-30 -1.0995685137
2003-07-01 -0.7065834677
2003-07-02  0.7661757181
 and so on...
In help it is stated that I should use as.timeSeries function like:
as.timeSeries(x, dimnames = TRUE, format = "")
So I try:
> ts.rp = as.timeSeries(rp, dimnames=TRUE, format="%Y-%m-%d")
Error in "colnames<-"(`*tmp*`, value = character(0)) :
attempt to set colnames on object with less than two dimensions
I don't exactly understand the error as:
> dim(rp)
[1] 249   1
What am I doing wrong?
Best regards,
Wojtek
__
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] without the loop

2005-05-13 Thread Gabor Grothendieck
On 5/13/05, Omar Lakkis <[EMAIL PROTECTED]> wrote:
> Can this be re-implemented to run faster (without the loop) ?
> 
> r <- list()
> n = nrow(prices)
>for (i in (w+1):n) {
>window <- prices[(i-w):(i-1),]
>if (prices[i,]$settle > max(window$high)) r <-
> append(r,  1)
>else if (prices[i,]$settle < min(window$low)) r <-
> append(r, -1)
>}
> 

Given the complex looping it would be better if you provided
documentation with your post and a reproducible example, not
just a code snippet.  See the posting guide.

At any rate, it seems that what you want to do is to append 1
whenever the settle price exceeds the high of the last w
time points and a -1 whenever the settle price is below the low of
the last w time points.

Represent the prices as a zoo series with 3 columns: 
high, low, settle and use the following (untested) loop-free
code:

high <- 1; low <- 2; settle <- 3
W <- w+1
r <- rapply(prices, W, function(x) 
sign(x[W,settle] > max(x[-W,high])) - (x[W,settle] < min(x[-W,low])),
by.column = FALSE, align = "right")
)
r[r!=0]

__
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] multinom(): likelihood of model?

2005-05-13 Thread Brooks Miner
Hi all,
I'm working on a multinomial (or "polytomous") logistic regression 
using R and have made great progress using multinom() from the nnet 
library.  My response variable has three categories, and there are two 
different possible predictors.  I'd like to use the likelihoods of 
certain models (ie, saturated, fitteds, and null) to calculate 
Nagelkerke R-squared values for various fitted models.

My question today is simple: once I have fitted a model using 
multinom(), how do I find the likelihood (or log likelihood) of my 
fitted model?  I understand that this value must be part of the 
$deviance or $AIC components of the fitted model, but my understanding 
is too limited at this point for me to know how to calculate the 
likelihood of my fitted model from either of these outputs.

Thanks in advance to any assistance offered.  I'd be happy to provide 
an example of my data and multinom() entries if that would help.

Gratefully,
- Brooks

Brooks Miner
Research Scientist
Laird Lab
UW Biology
206.616.9385
http://protist.biology.washington.edu/Lairdlab/
__
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] without the loop

2005-05-13 Thread Giovanni Petris

I won't go into the details of your loop, but in general it is usually
better, if possible, to create a list of the appropriate length
upfront.

Giovanni

> Date: Fri, 13 May 2005 16:58:42 -0400
> From: Omar Lakkis <[EMAIL PROTECTED]>
> Sender: [EMAIL PROTECTED]
> Precedence: list
> DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
> 
> Can this be re-implemented to run faster (without the loop) ? 
> 
> r <- list()
> n = nrow(prices)
> for (i in (w+1):n) {   
> window <- prices[(i-w):(i-1),]  
> if (prices[i,]$settle > max(window$high)) r <-
> append(r,  1)
> else if (prices[i,]$settle < min(window$low)) r <-
> append(r, -1)
> }
> 
> __
> 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
> 
> 

-- 

 __
[  ]
[ Giovanni Petris [EMAIL PROTECTED] ]
[ Department of Mathematical Sciences  ]
[ University of Arkansas - Fayetteville, AR 72701  ]
[ Ph: (479) 575-6324, 575-8630 (fax)   ]
[ http://definetti.uark.edu/~gpetris/  ]
[__]

__
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] clustering

2005-05-13 Thread Amir Safari
Hi Every body,
 In order to deal with nonstationary problem in time series, may be  firstly 
clustering algorithms are used to partition time series .Then another algorithm 
is used to predict future value based on  segmented data in the second phase. 
Using clustering algorithms , the "time structure and arrangement" of time 
series is confused. We have some partitions including data unrelated to the 
time at hand. A question which arises here is that: lossing the time 
arrangement of time series is not a new problem?  can we forecast the future 
based on segmented  confused clusters? What am i missing? 
 
Have a nice
Amir


-

[[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] A model package that uses S4 methods and name spaces?

2005-05-13 Thread Douglas Bates
[EMAIL PROTECTED] wrote:
> I'd like to try and rewrite my package to take advantage of S4 methods and
> name spaces.  I am presuming that S4 methods and name spaces will help me
> write and maintain my package.
> 
> Can someone suggest a "model" package that uses best practices for mixing
> S3, S4 methods and name spaces?  Preferably a package with multiple R
> source files.

It doesn't mix S3 and S4 but the Matrix package is a large package based
on S4 that does show the use of S4 and a NAMESPACE.  On a smaller scale,
the lme4 package also uses S4 and a NAMESPACE.

__
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 model package that uses S4 methods and name spaces?

2005-05-13 Thread rlee
I'd like to try and rewrite my package to take advantage of S4 methods and
name spaces.  I am presuming that S4 methods and name spaces will help me
write and maintain my package.

Can someone suggest a "model" package that uses best practices for mixing
S3, S4 methods and name spaces?  Preferably a package with multiple R
source files.

-L

__
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] without the loop

2005-05-13 Thread Omar Lakkis
Can this be re-implemented to run faster (without the loop) ? 

r <- list()
n = nrow(prices)
for (i in (w+1):n) {   
window <- prices[(i-w):(i-1),]  
if (prices[i,]$settle > max(window$high)) r <-
append(r,  1)
else if (prices[i,]$settle < min(window$low)) r <-
append(r, -1)
}

__
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] manipulating dataframe according to the values of some columns

2005-05-13 Thread Francisco J. Zagmutt
Hi Zhihua
Try the following:
dat=data.frame(x=rep(c("T","F"),10),y=(runif(20)))#Creates data frame like 
in your example
newdat=dat[dat$x=="T",] #includes only rows with variable x equal to "T"
newdat=newdat[order(newdat[,"y"], decreasing=FALSE),]# sorts in ascending 
order the newdat #data by the values of y.  Notice that the default is 
order(decreasing=FALSE) but I added that argument so you can see that you 
can also sort descending.

Another alternative to the second line of code is to use the higher level 
function subset() i.e.:
newdat=subset(dat, x=="T",select=c(x,y))#again, the select argument is 
optional in this example but I added it so you can see how you can select 
specific coumns for your subset.

I hope that this helps
Francisco

From: "zhihua li" <[EMAIL PROTECTED]>
To: r-help@stat.math.ethz.ch
Subject: [R] manipulating dataframe according to the values of some columns
Date: Fri, 13 May 2005 15:43:20 +
hi netters,
I'm a newbie to R and there are some very simple problems puzzeled me for 
two days.

I've a dataframe here with several columns different in modes. Two of the 
columns are special for me: column 1 has the mode "factor" and column 2 has 
the mode "numeric vectors".
The values for column 1 are either "T" or "F". I wanna do two things:
Firstly, remove those rows whose values for column 1 are "F";
Secondly,sort the rows in the ascending order of values for column 2.

I believe the code to do these things is simple. But I can't figure it out. 
Please help me!

Thanks a lot!
__
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] Conflict between xtable and Hmisc when using Sweave?

2005-05-13 Thread Sander Oom
Dear Frank,
I have a Sweave document in which I export anova (aov) tables to Latex 
and calculate some summary statistics with summarize{Hmisc} for a graph 
(as in the example below).

I currently use the following code for the aov tables:
<>=
  tmp <- datGrassHC[datGrassHC$Loc > 0 & datGrassHC$Loc < 9 ,]
  tmpAov <- aov(Height~Geology*Altitude*Origin*BinInOut , data=tmp)
  tmpTable <- xtable (tmpAov ,
caption="ANOVA table for vegetation height.",
label="tab:AnovaHeight"
)
  print.xtable(tmpTable, type="latex", floating=TRUE,
table.placement="ht", caption.placement="top",
latex.environments=c("center"))
)
@
I used xtables, because it has a working aov example. I would be happy 
to use an alternative if I knew how! Would you have sample code to 
illustrate how to export an aov table to Latex using latex{Hmisc}.

Thanks very much for your help,
Sander.
Frank E Harrell Jr wrote:
Sander Oom wrote:
Dear R users,
The Sweave code below runs fine, as it is. However, an error occurs 
when the line 'library(xtable)' is uncommented:
Error:  chunk 1
Error in "label<-"(`*tmp*`, value = "month") :
no applicable method for "label<-"

Is anybody aware of this and knows a workaround?
Thanks,
Sander.
***
\documentclass[a4paper]{article}
\title{Sweave Test for summarize}
\author{Sander Oom}
\usepackage{a4wide}
\begin{document}
\maketitle
\begin{figure}[ht]
\begin{center}
<>=
  # library(xtable)
  library(Hmisc)
  set.seed(111)
  dfr <- expand.grid(month=1:12, year=c(1997,1998), reps=1:100)
  month <- dfr$month
  year <- dfr$year
  y <- abs(month-6.5) + 2*runif(length(month)) + year-1997
  s <- summarize(y, llist(month,year), smedian.hilow, conf.int=.5)
  print(xYplot(Cbind(y,Lower,Upper) ~ month, groups=year, data=s,
keys='lines', method='alt', type='b'))
@
\end{center}
\end{figure}
\end{document}


 > version
 _
platform i686-pc-linux-gnu
arch i686
os   linux-gnu
system   i686, linux-gnu
status
major2
minor1.0
year 2005
month04
day  18
language R

I feel this is an xtable problem because Hmisc has being using label and 
label<- since 1991.

Frank
--

Dr. Sander P. Oom
Animal, Plant and Environmental Sciences,
University of the Witwatersrand
Private Bag 3, Wits 2050, South Africa
Tel (work)  +27 (0)11 717 64 04
Tel (home)  +27 (0)18 297 44 51
Fax +27 (0)18 299 24 64
Email   [EMAIL PROTECTED]
Web www.oomvanlieshout.net/sander
__
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] cluster results using fanny

2005-05-13 Thread Barbara Diaz
Hi,

I am using fanny and I have estrange results. I am wondering if
someone out there can help me understand why this happens.

First of all in most of my tries, it gives me a result in which each
object has equal membership in all clusters. I have read that that
means "the clustering is entirely fuzzy". Looking at the graphics it
is really difficult to understand how objects with so different scores
for the variables have the same membership for all the clusters.

I also find estrange the fact that if I set K=3 (three clusters), it
gives membership for all three clusters (0.333 for all of them) and
then when it gives the closest hard clustering they only belong to
cluster 1 or 2, but none of them to cluster three. The plot shows only
two clusters (also the silhouette plot, even if it gives in the
"silhouette plot information" the silhouette width for the three
clusters.

Then, for the same data I set k=4 and surprisingly, it gives
membership for the four of them (this time they are not all the same)
and when it gives the closest hard clustering they only belong to
cluster 1, 2, or 3 but none of them to cluster 4. The plot shows only
three clusters (also the silhouette plot, even if it gives in the
"silhouette plot information" the silhouette width for the four
clusters. why didn't it give this three clusters when I set
k=3??

For k=5 it gives all the information and then it only plots 2 clusters.

This is very confusing. Also, if there is equal membership for all the
clusters, how is it that I have a "closest hard clustering"? and a
"neighbor"?

Thank you in advance,

Barbara

__
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] Conflict between xtable and Hmisc when using Sweave?

2005-05-13 Thread Frank E Harrell Jr
Sander Oom wrote:
Dear R users,
The Sweave code below runs fine, as it is. However, an error occurs when 
the line 'library(xtable)' is uncommented:
Error:  chunk 1
Error in "label<-"(`*tmp*`, value = "month") :
no applicable method for "label<-"

Is anybody aware of this and knows a workaround?
Thanks,
Sander.
***
\documentclass[a4paper]{article}
\title{Sweave Test for summarize}
\author{Sander Oom}
\usepackage{a4wide}
\begin{document}
\maketitle
\begin{figure}[ht]
\begin{center}
<>=
  # library(xtable)
  library(Hmisc)
  set.seed(111)
  dfr <- expand.grid(month=1:12, year=c(1997,1998), reps=1:100)
  month <- dfr$month
  year <- dfr$year
  y <- abs(month-6.5) + 2*runif(length(month)) + year-1997
  s <- summarize(y, llist(month,year), smedian.hilow, conf.int=.5)
  print(xYplot(Cbind(y,Lower,Upper) ~ month, groups=year, data=s,
keys='lines', method='alt', type='b'))
@
\end{center}
\end{figure}
\end{document}


 > version
 _
platform i686-pc-linux-gnu
arch i686
os   linux-gnu
system   i686, linux-gnu
status
major2
minor1.0
year 2005
month04
day  18
language R

I feel this is an xtable problem because Hmisc has being using label and 
label<- since 1991.

Frank
--
Frank E Harrell Jr   Professor and Chair   School of Medicine
 Department of Biostatistics   Vanderbilt University
__
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 convert color to black & white

2005-05-13 Thread Muhammad Subianto
Dear all,
Could someone please explain to me how to convert color to black & white.
For example:
barplot(1:5,col = rainbow(5))
Because I need to print my plot to save my ink color printer.
I don't want to convert to grayscale, but keep it as an RGB.
I  would be very happy if anyone could help me.
Thank you very much in advance.
Kindly regards,
Muhammad Subianto
__
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] where is aggregateSeries

2005-05-13 Thread Omar Lakkis
What package is aggregateSeries in?
It is referred to in the fCalendar document but I do not see it in the package.

__
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] Re: Re: List and Column Names in a Function?

2005-05-13 Thread khobson




The R-Help replies inspired me to try ds(get("ds1"), "Y") which solves my
problem.

What I wanted was to pass string values for both the list name and the
column name.  I had tried several methods before posting.  Thanks for the
replies.

I incorrectly stated that Douglas Grove's solution would not work.  (I had
a typo when I tried it).  It works as he specified but not as I required.
The results below are the expected results which I probably should have
shown to be more clear.   It did get me to a solution though.

I would not post questions if I had not read the posting guide.   I spent
lots of time viewing the R-Help archives prior to posting as well.  Two
other posts of mine had no replies.  If you see those, there is no need to
reply.  With this more simplified example and your responses, I'm now good
to go.


   
   
   
   




> From: [EMAIL PROTECTED]
>
> The solution that Douglas proposed does not work.  Any other ideas?

Then perhaps you could (re-)read the posting guide, and give us more
information on what you mean by "does not work", and exactly what you are
expecting?  Isn't this what you want?


> ds1 <- c(X=list(1:10), Y=list(11:20))
> ds <- function(myds, vec) myds[[vec]] * 2
> ds(ds1, "Y")
 [1] 22 24 26 28 30 32 34 36 38 40

__
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] Problem with data frame when using xYplot?

2005-05-13 Thread Sander Oom
Sorry Deepayan, I forgot that the code moved on while you send your 
reply. Below the simplified version using your suggestion and this time 
based on the generic data used in the xYplot manual!

Maybe this example can be included in the manual, so next time people 
will find the answer there. Or better still, you could provide a high 
level function in 'lattice'. ;-)

dfr <- expand.grid(month=1:12, continent=c('Europe','USA'),
   sex=c('female','male'))
set.seed(1)
dfr$y <- dfr$month/10 + 1*(dfr$sex=='female') +
  2*(dfr$continent=='Europe') + runif(48,-.15,.15)
dfr
dfs <- summarize(dfr$y, llist(dfr$continent,dfr$sex),
  smean.cl.normal)
labs <- unique(dfs$continent)
colnames(dfs) <- list("continent","sex","y","Lower","Upper")
dfs$sexnum <- unclass(dfs$sex)
dfs
xYplot(Cbind(y,Lower,Upper) ~ sexnum|continent, data=dfs, nx=FALSE,
  xlim=levels(dfs$sex),
  ylim=c(min(dfs$Lower)-1,max(dfs$Upper)+1),
  )
dfs$xvar <- rep(1:2, each=2)+rep(c(-0.1,0.1), 2)
dfs
sp <- list(superpose.symbol = list(pch = c(16,1), cex = 1),
  superpose.line = list(col = "grey", lty = 1))
xYplot(Cbind(y,Lower,Upper) ~ xvar, groups=sex,  data=dfs,
  xlim= levels(dfs$continent),
  ylim= c(min(dfs$Lower)-1,max(dfs$Upper)+1),
  xlab="Continent",
  panel=function(x, y, type, ...) {
panel.xYplot(x, y, type="p",...)
lpoints(x, y, pch=16, col="white", cex=2)
panel.superpose(x, y, type="p", ...)
  },
  par.settings= sp,
  auto.key= list(columns=1, x=0.7, y=0.8, corner = c(0,0))
  )
Deepayan Sarkar wrote:
On Friday 13 May 2005 10:36 am, Sander Oom wrote:
Hi Deepayan!
Deepayan Sarkar wrote:
On Friday 13 May 2005 08:07 am, Sander Oom wrote:
An off list response from Mat Soukop (thanks Mat!!) provides an even
more elegant solution (see code below)! I have included the original
code, so people can decide whether to plot in a single panel or in
multiple panels. Now we have a fully functional workaround to get
plotmeans{gplots} for multiple factors using lattice! Great!
Just out of curiousity, does replacing the 'xlim' and 'scales' arguments
above by
xlim = levels(tmp$Position)
do the same thing? It should with xyplot (which also allows the x
variable to be a factor), but xYplot may be bypassing that.
You mean: xlim = levels(tmp$AltGeo)yes it does!? 
No, I meant exactly what I wrote, and my comment followed this piece of code 
(which you have deleted from your reply):

-
tmp$PosNum <- unclass(tmp$Position)
tmp
(labs <- unique(tmp$Position))
# plot factor levels in seperate panels
xYplot(Cbind(Sodium,Lower,Upper) ~ PosNum|AltGeo, data=tmp, nx=FALSE,
   xlim=c(0.5,2.5),
   ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1),
   scales = list(x = list(at=seq(1, 2, by=1), labels = labs)),
   xlab="Position", ylab="Sodium"
   )
--
No clue how one would ever get comfortable with all these options!
By reading the manual, of course :-)
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
--

Dr. Sander P. Oom
Animal, Plant and Environmental Sciences,
University of the Witwatersrand
Private Bag 3, Wits 2050, South Africa
Tel (work)  +27 (0)11 717 64 04
Tel (home)  +27 (0)18 297 44 51
Fax +27 (0)18 299 24 64
Email   [EMAIL PROTECTED]
Web www.oomvanlieshout.net/sander
__
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] randomForest partialPlot x.var through function

2005-05-13 Thread Eric Archer
All,
I'm trying to set up a function which calls the partialPlot function but 
am getting an error that I can't seem to solve.  Here's a simplified 
version of the function and error...

> pplot <- 
function(rf,pred.var){partialPlot(x=rf,pred.data=acoust,x.var=pred.var)}
>
> attach(acoust)
> acoust.rf <- 
randomForest(VocalTF~Cruise+Spot+Spin+Delph+Stripe+Steno+Turs+Gramp+Lags+
+   Lisso+FerPsu+Glob+mixspotspin+mixother+mixed+Size,
+   data=acoust,importance=TRUE,keep.forest=TRUE)
> cruise.pp <- pplot(acoust.rf,Cruise)
Error in "[.data.frame"(pred.data, , xname) :
   undefined columns selected

Here's the traceback call...
> traceback()
6: stop("undefined columns selected")
5: "[.data.frame"(pred.data, , xname)
4: pred.data[, xname]
3: partialPlot.randomForest(x = rf, pred.data = acoust, x.var = pred.var)
2: partialPlot(x = rf, pred.data = acoust, x.var = pred.var)
1: pplot(acoust.rf, Cruise)
From the partialPlot help file, the "pred.data[, xname]" seems to apply 
to the "n.pt" argument which reads, "if 'x.var' is continuous, the 
number of points on the grid for evaluating partial dependence."

It is not clear to me what "xname" is or where it is defined.  If it is 
supposed to be "x.var" where does it get assigned?  I've tried 
help.search("xname") to no useful avail that I could tell.
Second, in my case, "acoust$Cruise" is a factor and the line

> cruise.pp <- partialPlot(acoust.rf,acoust,Cruise)
produces the proper plot.
Which leads me to belive that I'm doing something wrong in how I'm 
passing "Cruise" through "pred.var" in the function call to "x.var", but 
I can't figure out how to properly correct it.

Thanks in advance for any pointers.
e.
--
Eric Archer, Ph.D.
NOAA-SWFSC
8604 La Jolla Shores Dr.
La Jolla, CA 92037
858-546-7121,7003(FAX)
[EMAIL PROTECTED]
"Lighthouses are more helpful than churches."
   - Benjamin Franklin
"Cogita tute" - Think for yourself
__
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] Re: Re: List and Column Names in a Function?

2005-05-13 Thread Liaw, Andy
> From: [EMAIL PROTECTED]
> 
> The solution that Douglas proposed does not work.  Any other ideas?

Then perhaps you could (re-)read the posting guide, and give us more
information on what you mean by "does not work", and exactly what you are
expecting?  Isn't this what you want?


> ds1 <- c(X=list(1:10), Y=list(11:20))
> ds <- function(myds, vec) myds[[vec]] * 2
> ds(ds1, "Y")
 [1] 22 24 26 28 30 32 34 36 38 40

Andy

 
> > In this simple function, how can I pass strings for index and column
> names
> > to the function?  I've posted this type of question before 
> and received
> no
> > response.
> >
> > Maybe this example will be easier to understand and troubleshoot.
> >
> > ds <- function(myds, vec) {myds[[vec]]*2}
> >
> > ds1 <- c(X=list(1:10), Y=list(11:20))
> >
> > ds(get("ds1"),get("Y"))
> 
> You are overusing the get function.  I think you can do what 
> you want as
> 
> ds(ds1, "Y")
> 
> 
> [EMAIL PROTECTED]
> Kenneth Ray Hobson, P.E.
> Oklahoma DOT - QA & IAS Manager
> 
> __
> 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] Re: Re: List and Column Names in a Function?

2005-05-13 Thread Douglas Bates
[EMAIL PROTECTED] wrote:
> 
> 
> 
> The solution that Douglas proposed does not work.  Any other ideas?

In what way does it not work?  I get

> ds <- function(myds, vec) {myds[[vec]]*2}
> ds1 <- c(X=list(1:10), Y=list(11:20))
> ds(ds1, "Y")
 [1] 22 24 26 28 30 32 34 36 38 40

Isn't that what you wanted?

__
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: Re: List and Column Names in a Function?

2005-05-13 Thread khobson




The solution that Douglas proposed does not work.  Any other ideas?

> In this simple function, how can I pass strings for index and column
names
> to the function?  I've posted this type of question before and received
no
> response.
>
> Maybe this example will be easier to understand and troubleshoot.
>
> ds <- function(myds, vec) {myds[[vec]]*2}
>
> ds1 <- c(X=list(1:10), Y=list(11:20))
>
> ds(get("ds1"),get("Y"))

You are overusing the get function.  I think you can do what you want as

ds(ds1, "Y")


[EMAIL PROTECTED]
Kenneth Ray Hobson, P.E.
Oklahoma DOT - QA & IAS Manager

__
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 generate object name automatically?

2005-05-13 Thread Liaw, Andy
The obvious way is to use assign().  The possibly better way is to store the
objects in a list.

Andy

> From: Xiao Shi
> 
> Hi everybody,
> I have a lable vector ,
> raw.labs= paste("file1", 1:20, sep = "")
> And i can i make the content of raw.labs to be a object name.
> eg ,file1=123(use some function on raw.labs to generate the 
> name file1)
> Thanks!
> 
>   [[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


Re: [R] how to generate object name automatically?

2005-05-13 Thread Stefano Calza
What about assign?

assign(raw.labs[1],123)

maybe you're thinking about something like this

(raw.values = vector of values)

for(i in 1:length(raw.labs))
  assign(raw.labs[i],raw.values[i])


Not elegant but works

Stefano


On Fri, May 13, 2005 at 11:24:24PM +0800, Xiao Shi wrote:
Hi everybody,
I have a lable vector ,
raw.labs= paste("file1", 1:20, sep = "")
And i can i make the content of raw.labs to be a object name.
eg ,file1=123(use some function on raw.labs to generate the name file1)
Thanks!

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


Re: [R] Problem with data frame when using xYplot?

2005-05-13 Thread Deepayan Sarkar
On Friday 13 May 2005 10:36 am, Sander Oom wrote:
> Hi Deepayan!
>
> Deepayan Sarkar wrote:
> > On Friday 13 May 2005 08:07 am, Sander Oom wrote:
> >>An off list response from Mat Soukop (thanks Mat!!) provides an even
> >>more elegant solution (see code below)! I have included the original
> >>code, so people can decide whether to plot in a single panel or in
> >>multiple panels. Now we have a fully functional workaround to get
> >>plotmeans{gplots} for multiple factors using lattice! Great!
> >
> > Just out of curiousity, does replacing the 'xlim' and 'scales' arguments
> > above by
> >
> > xlim = levels(tmp$Position)
> >
> > do the same thing? It should with xyplot (which also allows the x
> > variable to be a factor), but xYplot may be bypassing that.
>
> You mean: xlim = levels(tmp$AltGeo)yes it does!? 

No, I meant exactly what I wrote, and my comment followed this piece of code 
(which you have deleted from your reply):

-
tmp$PosNum <- unclass(tmp$Position)
tmp
(labs <- unique(tmp$Position))
# plot factor levels in seperate panels
xYplot(Cbind(Sodium,Lower,Upper) ~ PosNum|AltGeo, data=tmp, nx=FALSE,
   xlim=c(0.5,2.5),
   ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1),
   scales = list(x = list(at=seq(1, 2, by=1), labels = labs)),
   xlab="Position", ylab="Sodium"
   )
--

> No clue how one would ever get comfortable with all these options!

By reading the manual, of course :-)

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] Lattice plot within a "for" loop does not happen?

2005-05-13 Thread Deepayan Sarkar
On Friday 13 May 2005 09:24 am, Barry Rowlingson wrote:
> > BUT, when I stick this in a loop, I get a bunch of blank graphics
> > devices. This happens even if the loop only executes once. I could  just
> > go through and do these one by one, but I was curious if I was
> > overlooking something obvious. Thank you for any advice.
>
>   You're overlooking something like line 800 of the documentation for
> xyplot:

As well as the much much shorter help(Lattice), which has: 

Note:

 High level Lattice functions (like 'xyplot') are different from
 conventional S graphics functions because they don't actually draw
 anything. Instead, they return an object of class ``trellis''
 which has to be then 'print'ed. This often causes confusion when
 the high level functions are called inside another function (most
 often 'source') and hence don't produce any output.

This page is pointed to from every conceivable place, including the 
Description, which says:

Description:   Implementation of Trellis Graphics. See ?Lattice for a
   brief introduction


> [...]
>
>   So wrap your xyplot call in a print() function inside your loop:
>
>   for(i in 1:10){
> print(xyplot(whatever))
>   }
>
>   Its probably in the R-FAQ as well, since my original feeling was that
> this behaviour was chosen in order to confuse people and see how many
> people read the FAQ... :)

No comments on that :)

However, let's say I want to use pseudo-random numbers to study the behaviour 
of sample correlation in uncorrelated observations. To this end, I do:

> cor(rnorm(10), rnorm(10))
[1] 0.3899596

I do it a few more times:

> cor(rnorm(10), rnorm(10))
[1] 0.6481215
> cor(rnorm(10), rnorm(10))
[1] -0.02100718
> cor(rnorm(10), rnorm(10))
[1] -0.01141006

but then I get tired and try:

> for (i in 1:10) {
+   cor(rnorm(10), rnorm(10))
+ }
>
>

resulting in nothing!!! 

Strange how no one ever (or at least any more) complains about this behavour, 
which should be exactly as ``confusing''. 

The upshot, of course, can be summarized by a now famous observation made 
slightly more than a decade ago:

http://groups-beta.google.com/group/comp.sys.next.advocacy/msg/92532d5651e795dc

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


[R] manipulating dataframe according to the values of some columns

2005-05-13 Thread zhihua li
hi netters,
I'm a newbie to R and there are some very simple problems puzzeled me for 
two days.

I've a dataframe here with several columns different in modes. Two of the 
columns are special for me: column 1 has the mode "factor" and column 2 has 
the mode "numeric vectors".
The values for column 1 are either "T" or "F". I wanna do two things:
Firstly, remove those rows whose values for column 1 are "F";
Secondly,sort the rows in the ascending order of values for column 2.

I believe the code to do these things is simple. But I can't figure it out. 
Please help me!

Thanks a lot!
__
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] List and Column Names in a Function?

2005-05-13 Thread Douglas Bates
[EMAIL PROTECTED] wrote:
> 
> 
> 
> In this simple function, how can I pass strings for index and column names
> to the function?  I've posted this type of question before and received no
> response.
> 
> Maybe this example will be easier to understand and troubleshoot.
> 
> ds <- function(myds, vec) {myds[[vec]]*2}
> 
> ds1 <- c(X=list(1:10), Y=list(11:20))
> 
> ds(get("ds1"),get("Y"))

You are overusing the get function.  I think you can do what you want as

ds(ds1, "Y")

__
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] Lowest data level since DateX

2005-05-13 Thread Gabor Grothendieck
On 5/13/05, Lapointe, Pierre <[EMAIL PROTECTED]> wrote:
> Hello,
> 
> I'm dealing with financial time series.  I'm trying to find out X in this
> sentence:
> The most recent close is the lowest level since X(date).
> 
> Here's an example of what I'm looking for:
> 
> library(fBasics)
> data(DowJones30)
> tail(DowJones30[,1:5],n=10)
> 
> I need to come up with a vector that would look like this
> 
> AA AXP  T...
> 2000-12-21 2000-12-20   2000-12-29
> 
> i.e. the last date at which the stocks were trading at a lower level than
> the most recent closing.
> 
> I know it has to do with min/max, pmin/pmax, cummin/cummax or rev(), but I
> can't figure it out.

The following returns the last index whose value is less than the
last entry in vector x (or numeric(0) if none):

> x <- c(1,4,2,6,3)
> tail(which(x < tail(x,1)),1)
[1] 3
> x <- c(1,4,2,6,.5)
> tail(which(x < tail(x,1)),1)
numeric(0)

__
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] Problem with data frame when using xYplot?

2005-05-13 Thread Sander Oom
Hi Deepayan!
Deepayan Sarkar wrote:
On Friday 13 May 2005 08:07 am, Sander Oom wrote:
An off list response from Mat Soukop (thanks Mat!!) provides an even
more elegant solution (see code below)! I have included the original
code, so people can decide whether to plot in a single panel or in
multiple panels. Now we have a fully functional workaround to get
plotmeans{gplots} for multiple factors using lattice! Great!
Just out of curiousity, does replacing the 'xlim' and 'scales' arguments above 
by 

xlim = levels(tmp$Position)
do the same thing? It should with xyplot (which also allows the x variable to 
be a factor), but xYplot may be bypassing that.

You mean: xlim = levels(tmp$AltGeo)yes it does!? No clue how one 
would ever get comfortable with all these options!

library(Hmisc)
library(lattice)
ltheme <- canonical.theme(color = FALSE) ## in-built B&W theme
ltheme$strip.background$col <- "transparent" ## change strip bg
lattice.options(default.theme = ltheme)  ## set as default
tmp <-
structure(list(Position = structure(as.integer(c(1, 2, 1, 2,
1, 2, 1, 2)), .Label = c("Inside", "Outside"), class = "factor"),
AltGeo = structure(as.integer(c(1, 1, 2, 2, 3, 3, 4, 4)), .Label = 
c("Basalt-High",
"Basalt-Low", "Quartz-High", "Quartz-Low"), class = "factor"),
Sodium = c(27.3, 26.9, 25, 18.1,
4.67, 5.56, 10.7, 5.67
), SD = c(5.3851648071345, 2.42097317438899, 20.1618451536560,
15.2679766541317, 5.45435605731786, 8.09492296305393, 10.6183802907976,
8.06225774829855), Nobs = c(9, 9, 9, 9, 9, 9, 9, 9), Lower = 
c(25.5382783976218,
26.0818978307592, 18.2793849487813, 13.0217855597339, 2.84854798089405,
2.85724790120425, 7.12720656973412, 2.97924741723382), Upper = 
c(29.1283882690448,
27.6958799470186, 31.7206150512187, 23.2004366624884, 6.48478535243929,
8.25386320990686, 14.2061267635992, 8.35408591609952)), .Names = 
c("Position",
"AltGeo", "Sodium", "SD", "Nobs", "Lower", "Upper"), row.names = c("1",
"2", "3", "4", "5", "6", "7", "8"), class = "data.frame")
tmp$xvar <- rep(1:4, each=2)+rep(c(-0.1,0.1), 4)
tmp
sp <- list(superpose.symbol = list(pch = c(16,1), cex = 1))
xYplot(Cbind(Sodium,Lower,Upper) ~ xvar, groups=Position,  data=tmp,
  xlim = levels(tmp$AltGeo),
  ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1),
xlab='AltGeo', ylab='Sodium',
panel = function(x, y, type, ...) {
  panel.xYplot(x, y, type="p",...)
  lpoints(x, y, pch=16, col="white", cex=2)
  panel.superpose(x, y, type="p", ...)
},
par.settings = sp,
auto.key=list(columns=1, x=0.7, y=0.8, corner = c(0,0))
)

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

Dr. Sander P. Oom
Animal, Plant and Environmental Sciences,
University of the Witwatersrand
Private Bag 3, Wits 2050, South Africa
Tel (work)  +27 (0)11 717 64 04
Tel (home)  +27 (0)18 297 44 51
Fax +27 (0)18 299 24 64
Email   [EMAIL PROTECTED]
Web www.oomvanlieshout.net/sander
__
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 generate object name automatically?

2005-05-13 Thread Xiao Shi
Hi everybody,
I have a lable vector ,
raw.labs= paste("file1", 1:20, sep = "")
And i can i make the content of raw.labs to be a object name.
eg ,file1=123(use some function on raw.labs to generate the name file1)
Thanks!

[[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] List and Column Names in a Function?

2005-05-13 Thread khobson




In this simple function, how can I pass strings for index and column names
to the function?  I've posted this type of question before and received no
response.

Maybe this example will be easier to understand and troubleshoot.

ds <- function(myds, vec) {myds[[vec]]*2}

ds1 <- c(X=list(1:10), Y=list(11:20))

ds(get("ds1"),get("Y"))


[EMAIL PROTECTED]
Kenneth Ray Hobson, P.E.
Oklahoma DOT - QA & IAS Manager
Oklahoma City, OK  73105-3204

__
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] Problem with data frame when using xYplot?

2005-05-13 Thread Deepayan Sarkar
On Friday 13 May 2005 08:07 am, Sander Oom wrote:
> An off list response from Mat Soukop (thanks Mat!!) provides an even
> more elegant solution (see code below)! I have included the original
> code, so people can decide whether to plot in a single panel or in
> multiple panels. Now we have a fully functional workaround to get
> plotmeans{gplots} for multiple factors using lattice! Great!
>
> 
>
>
> library(Hmisc)
> library(lattice)
> tmp <-
> structure(list(Position = structure(as.integer(c(1, 2, 1, 2,
> 1, 2, 1, 2)), .Label = c("Inside", "Outside"), class = "factor"),
>  AltGeo = structure(as.integer(c(1, 1, 2, 2, 3, 3, 4, 4)), .Label =
> c("Basalt-High",
>  "Basalt-Low", "Quartz-High", "Quartz-Low"), class = "factor"),
>  Sodium = c(27.3, 26.9, 25, 18.1,
>  4.67, 5.56, 10.7, 5.67
>  ), SD = c(5.3851648071345, 2.42097317438899, 20.1618451536560,
>  15.2679766541317, 5.45435605731786, 8.09492296305393,
> 10.6183802907976, 8.06225774829855), Nobs = c(9, 9, 9, 9, 9, 9, 9, 9),
> Lower =
> c(25.5382783976218,
>  26.0818978307592, 18.2793849487813, 13.0217855597339,
> 2.84854798089405, 2.85724790120425, 7.12720656973412, 2.97924741723382),
> Upper = c(29.1283882690448,
>  27.6958799470186, 31.7206150512187, 23.2004366624884,
> 6.48478535243929, 8.25386320990686, 14.2061267635992, 8.35408591609952)),
> .Names = c("Position",
> "AltGeo", "Sodium", "SD", "Nobs", "Lower", "Upper"), row.names = c("1",
> "2", "3", "4", "5", "6", "7", "8"), class = "data.frame")
> tmp$PosNum <- unclass(tmp$Position)
> tmp
> (labs <- unique(tmp$Position))
> # plot factor levels in seperate panels
> xYplot(Cbind(Sodium,Lower,Upper) ~ PosNum|AltGeo, data=tmp, nx=FALSE,
>xlim=c(0.5,2.5),
>ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1),
>scales = list(x = list(at=seq(1, 2, by=1), labels = labs)),
>xlab="Position", ylab="Sodium"
>)

Just out of curiousity, does replacing the 'xlim' and 'scales' arguments above 
by 

xlim = levels(tmp$Position)

do the same thing? It should with xyplot (which also allows the x variable to 
be a factor), but xYplot may be bypassing that.

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] Problem with data frame when using xYplot?

2005-05-13 Thread Sander Oom
I have edited the code (hacked from another graph) to provide more 
control over the different elements of the graph. Now we have a graph at 
publication quality! Slowly the power of R graphics is shining through 
the thick cloud of options! Beautiful.


library(Hmisc)
library(lattice)
ltheme <- canonical.theme(color = FALSE) ## in-built B&W theme
ltheme$strip.background$col <- "transparent" ## change strip bg
lattice.options(default.theme = ltheme)  ## set as default
tmp <-
structure(list(Position = structure(as.integer(c(1, 2, 1, 2,
1, 2, 1, 2)), .Label = c("Inside", "Outside"), class = "factor"),
AltGeo = structure(as.integer(c(1, 1, 2, 2, 3, 3, 4, 4)), .Label = 
c("Basalt-High",
"Basalt-Low", "Quartz-High", "Quartz-Low"), class = "factor"),
Sodium = c(27.3, 26.9, 25, 18.1,
4.67, 5.56, 10.7, 5.67
), SD = c(5.3851648071345, 2.42097317438899, 20.1618451536560,
15.2679766541317, 5.45435605731786, 8.09492296305393, 10.6183802907976,
8.06225774829855), Nobs = c(9, 9, 9, 9, 9, 9, 9, 9), Lower = 
c(25.5382783976218,
26.0818978307592, 18.2793849487813, 13.0217855597339, 2.84854798089405,
2.85724790120425, 7.12720656973412, 2.97924741723382), Upper = 
c(29.1283882690448,
27.6958799470186, 31.7206150512187, 23.2004366624884, 6.48478535243929,
8.25386320990686, 14.2061267635992, 8.35408591609952)), .Names = 
c("Position",
"AltGeo", "Sodium", "SD", "Nobs", "Lower", "Upper"), row.names = c("1",
"2", "3", "4", "5", "6", "7", "8"), class = "data.frame")
tmp$xvar <- rep(1:4, each=2)+rep(c(-.05,.05), 4)
tmp
sp <- list(superpose.symbol = list(pch = c(16,1), cex = 1))
xYplot(Cbind(Sodium,Lower,Upper) ~ xvar, groups=Position,  data=tmp,
scales=list(y='free',x=list(at=1:4, labels=levels(tmp$AltGeo))),
xlim=c(0.5, 4.5), ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1),
xlab='AltGeo', ylab='Sodium',
panel = function(x, y, type, ...) {
  panel.xYplot(x, y, type="p",...)
  lpoints(x, y, pch=16, col="white", cex=2)
  panel.superpose(x, y, type="p", ...)
},
par.settings = sp,
auto.key=list(columns=1, x=0.7, y=0.8, corner = c(0,0))
)


Sander Oom wrote:
An off list response from Mat Soukop (thanks Mat!!) provides an even 
more elegant solution (see code below)! I have included the original 
code, so people can decide whether to plot in a single panel or in 
multiple panels. Now we have a fully functional workaround to get 
plotmeans{gplots} for multiple factors using lattice! Great!


library(Hmisc)
library(lattice)
tmp <-
structure(list(Position = structure(as.integer(c(1, 2, 1, 2,
1, 2, 1, 2)), .Label = c("Inside", "Outside"), class = "factor"),
AltGeo = structure(as.integer(c(1, 1, 2, 2, 3, 3, 4, 4)), .Label = 
c("Basalt-High",
"Basalt-Low", "Quartz-High", "Quartz-Low"), class = "factor"),
Sodium = c(27.3, 26.9, 25, 18.1,
4.67, 5.56, 10.7, 5.67
), SD = c(5.3851648071345, 2.42097317438899, 20.1618451536560,
15.2679766541317, 5.45435605731786, 8.09492296305393, 10.6183802907976,
8.06225774829855), Nobs = c(9, 9, 9, 9, 9, 9, 9, 9), Lower = 
c(25.5382783976218,
26.0818978307592, 18.2793849487813, 13.0217855597339, 2.84854798089405,
2.85724790120425, 7.12720656973412, 2.97924741723382), Upper = 
c(29.1283882690448,
27.6958799470186, 31.7206150512187, 23.2004366624884, 6.48478535243929,
8.25386320990686, 14.2061267635992, 8.35408591609952)), .Names = 
c("Position",
"AltGeo", "Sodium", "SD", "Nobs", "Lower", "Upper"), row.names = c("1",
"2", "3", "4", "5", "6", "7", "8"), class = "data.frame")
tmp$PosNum <- unclass(tmp$Position)
tmp
(labs <- unique(tmp$Position))
# plot factor levels in seperate panels
xYplot(Cbind(Sodium,Lower,Upper) ~ PosNum|AltGeo, data=tmp, nx=FALSE,
  xlim=c(0.5,2.5),
  ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1),
  scales = list(x = list(at=seq(1, 2, by=1), labels = labs)),
  xlab="Position", ylab="Sodium"
  )


new.back <- trellis.par.get("background")
new.back$col <- "white"
newcol <- trellis.par.get("superpose.symbol")
newcol$col <- c('green4','blue','red','black')
newcol$pch <- c(16,1,4,8)
new.line <- trellis.par.get("box.rectangle")
new.line$col <- 'black'
trellis.par.set("background", new.back)
trellis.par.set("superpose.symbol", newcol)
trellis.par.set("box.rectangle", new.line)
# Plot factor levels in one graph
tmp$xvar <- rep(1:4, each=2)+rep(c(-.05,.05), 4)
xYplot(Cbind(Sodium,Lower,Upper) ~ xvar, groups=Position,  data=tmp,
  scales=list(y='free',x=list(at=1:4,
  labels=levels(tmp$AltGeo))),
  xlab='AltGeo', xlim=c(.5, 4.5),
  key=list(points=Rows(trellis.par.get("superpose.symbol"),1:2),
text=list(lab =as.character(levels(tmp$Position)),
col=trellis.par.get("superpose.symbol")$col[1:2]),
columns=2

Re: [R] help with texi2dvi

2005-05-13 Thread Gabor Grothendieck
On 5/13/05, Matthieu Cornec <[EMAIL PROTECTED]> wrote:
> Hello,
> 
> Does anyone know how to write the files created by the call of
> "texi2dvi" in another directory ?

Here are two possibilities:

1. Copy the input files into whatever directory you want using
file.copy and then setwd to that directory and run texi2dvi.
Afterwards delete the copied files using file.remove and setwd
back.  See
?file.copy
?file.remove
?setwd

2. Create a batch file to do the same
thing and then use the texi2dvi= argument of texi2dvi
or set it via options so that the R texi2dvi uses that batch file 
rather than the real texi2dvi.  see ?texi2dvi and ?options

__
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] Lowest data level since DateX

2005-05-13 Thread Lapointe, Pierre
Hello,

I'm dealing with financial time series.  I'm trying to find out X in this
sentence:
The most recent close is the lowest level since X(date).

Here's an example of what I'm looking for:

library(fBasics)
data(DowJones30)
tail(DowJones30[,1:5],n=10)

I need to come up with a vector that would look like this

AA AXP  T...
2000-12-21 2000-12-20   2000-12-29

i.e. the last date at which the stocks were trading at a lower level than
the most recent closing.

I know it has to do with min/max, pmin/pmax, cummin/cummax or rev(), but I
can't figure it out.

Any help?



Regards,

Pierre Lapointe
Assistant Market Strategist



***
 
AVIS DE NON-RESPONSABILITE:\ Ce document transmis par courri...{{dropped}}

__
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] Lattice plot within a "for" loop does not happen?

2005-05-13 Thread Uwe Ligges
Barry Rowlingson wrote:

BUT, when I stick this in a loop, I get a bunch of blank graphics  
devices. This happens even if the loop only executes once. I could  
just go through and do these one by one, but I was curious if I was  
overlooking something obvious. Thank you for any advice.

 You're overlooking something like line 800 of the documentation for 
xyplot:

 Value:
 An object of class ``trellis''. The `update' method can be used to
 update components of the object and the `print' method (usually
 called by default) will plot it on an appropriate plotting device.
 xyplot doesn't actually make any marks on the screen. Oh no. It returns 
an object. You have to make that object make the marks on the screen. 
This happens automatically when you run something interactively, but not 
Baz, actually, printing happens only under two circumstances, AFAIK:
1. by wrapping in print()
2. automatically by evaluating an expression (which might be the object 
name only) in the top level (R_GlobalEnv), but only if no assignment 
takes place.

In particular, automatical (point 2 above) printing happens also in 
non-interactive sessions like
  R CMD BATCH
calls.

The idea of returning an object is very nice, I think. You can calculate 
on the object and print the modified object (well, in fact, I rarely use 
lattice myself, though).

Best,
Uwe

inside a function.
 So wrap your xyplot call in a print() function inside your loop:
 for(i in 1:10){
   print(xyplot(whatever))
 }
 Its probably in the R-FAQ as well, since my original feeling was that 
this behaviour was chosen in order to confuse people and see how many 
people read the FAQ... :)

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
__
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 with texi2dvi

2005-05-13 Thread Matthieu Cornec
Hello,

Does anyone know how to write the files created by the call of
"texi2dvi" in another directory ?

Thanks,

Matthieu

__
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] Lattice plot within a "for" loop does not happen?

2005-05-13 Thread Barry Rowlingson

BUT, when I stick this in a loop, I get a bunch of blank graphics  
devices. This happens even if the loop only executes once. I could  just 
go through and do these one by one, but I was curious if I was  
overlooking something obvious. Thank you for any advice.
 You're overlooking something like line 800 of the documentation for 
xyplot:

 Value:
 An object of class ``trellis''. The `update' method can be used to
 update components of the object and the `print' method (usually
 called by default) will plot it on an appropriate plotting device.
 xyplot doesn't actually make any marks on the screen. Oh no. It 
returns an object. You have to make that object make the marks on the 
screen. This happens automatically when you run something interactively, 
but not inside a function.

 So wrap your xyplot call in a print() function inside your loop:
 for(i in 1:10){
   print(xyplot(whatever))
 }
 Its probably in the R-FAQ as well, since my original feeling was that 
this behaviour was chosen in order to confuse people and see how many 
people read the FAQ... :)

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] Lattice plot within a "for" loop does not happen?

2005-05-13 Thread Petr Pikal
Hi

many times answered. Just enter

lattice loop R

into Google and you are there

Explicite printing lattice object is what you need.

Cheers
Petr


On 13 May 2005 at 10:09, George W. Gilchrist wrote:

> I am trying to do a series of xyplots plots, using a "for" loop to 
> substitute the appropriate variables for each plot. The basic command 
> works fine by itself and produces a nice plot:
> 
>  > i<-3
>  >  trellis.device(theme="col.whitebg")
>  >  xyplot(as.formula(paste(tmp00[2*i], "~ ", tmp00[(2*i)-1],
> + "|Blastomere+Phenotype", sep="")),
> + data=tmp1,
> + panel=function(x,y,...){
> +   panel.xyplot(jitter(x), jitter(y), pch=16, col="red") if
> +   (max(x, na.rm=T)!=0.0) panel.xyplot(x, y, type="r",  
> lwd=2)
> +})
>  >
> 
> BUT, when I stick this in a loop, I get a bunch of blank graphics 
> devices. This happens even if the loop only executes once. I could 
> just go through and do these one by one, but I was curious if I was 
> overlooking something obvious. Thank you for any advice.
> 
> ==
> George W. GilchristEmail #1: [EMAIL PROTECTED]
> Department of Biology, Box 8795  Email #2: [EMAIL PROTECTED]
> College of William & MaryPhone: (757) 221-7751
> Williamsburg, VA 23187-8795Fax: (757) 221-6483
> http://gwgilc.people.wm.edu/
> 
> __
> 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

Petr Pikal
[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] df and gcvpen for parameters selection on projection pursuit regression

2005-05-13 Thread =?iso-8859-1?Q?Jo=E3o_Mendes_Moreira?=
Hello,

I am using projection pursuit regression parameters selection.
Does anyone has experience on the range to test for df parameter (spline 
kernel) and gcvpen (gcvspline kernel)?
I don't find any information about this.

Thanks in advance.

Joao Moreira
 
[[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] Lattice plot within a "for" loop does not happen?

2005-05-13 Thread George W. Gilchrist
I am trying to do a series of xyplots plots, using a "for" loop to  
substitute the appropriate variables for each plot. The basic command  
works fine by itself and produces a nice plot:

> i<-3
>  trellis.device(theme="col.whitebg")
>  xyplot(as.formula(paste(tmp00[2*i], "~ ", tmp00[(2*i)-1],
+ "|Blastomere+Phenotype", sep="")),
+ data=tmp1,
+ panel=function(x,y,...){
+   panel.xyplot(jitter(x), jitter(y), pch=16, col="red")
+   if (max(x, na.rm=T)!=0.0) panel.xyplot(x, y, type="r",  
lwd=2)
+})
>

BUT, when I stick this in a loop, I get a bunch of blank graphics  
devices. This happens even if the loop only executes once. I could  
just go through and do these one by one, but I was curious if I was  
overlooking something obvious. Thank you for any advice.

==
George W. GilchristEmail #1: [EMAIL PROTECTED]
Department of Biology, Box 8795  Email #2: [EMAIL PROTECTED]
College of William & MaryPhone: (757) 221-7751
Williamsburg, VA 23187-8795Fax: (757) 221-6483
http://gwgilc.people.wm.edu/
__
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] retaining source

2005-05-13 Thread Peter E. Rossi
Folks-

I have created a contributed package, bayesm.  I'd like to load it and retain 
the source so that users can see comments in the source.

I load it with library(bayesm,keep.source=TRUE).  When I display the functions 
simply by typing the name at the prompt, I don't see comments and the 
attr(fun_name,"source") returns NULL.

I checked the options for RCMD build and I don't see anything I'm missing.

I'm sure I'm doing something wrong.

Advice?

thanks!

peter r





 Peter E. Rossi
 Joseph T. and Bernice S. 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


Re: [R] error in plot.lmList

2005-05-13 Thread Douglas Bates
[EMAIL PROTECTED] wrote:
> Hello,
> 
> in R-2.1.0 I'm trying to prodice trellis plots from an lmList object as 
> described in the help for plot.lmList. I can generate the plots from the 
> help, but on my own data plotting fails with an error message that I cannot 
> interpret (please see below). Any hints are greatly appreciapted.
> 
>   kind regards,
> 
>   Arne
> 
> 
>>dim(d)
> 
> [1] 575   4
> 
>>d[1:3,]
> 
>   Level_of_Expression SSPos1 SSPos19 Method
> 111.9  G   A   bDNA
> 224.7  T   T   bDNA
> 3 9.8  C   T   bDNA
> 
>>fm <- lmList(Level_of_Expression ~ SSPos1 + SSPos19 | Method, data=d)
>>fm
> 
> Call:
>   Model: Level_of_Expression ~ SSPos1 + SSPos19 | Method 
>Data: d 
> 
> Coefficients:
>(Intercept)   SSPos1CSSPos1G   SSPos1T SSPos19C SSPos19G   
> SSPos19T
> bDNA  25.75211 -6.379701  -9.193304 10.371056 24.32171 24.06107  
> 9.7357724
> Luciferase23.79947  4.905679  -7.747861  8.112779 48.95151 48.15064 
> -0.2646783
> RT-PCR56.08985 -7.352206 -15.896556 -2.712313 19.91967 24.28425 
> -2.2317071
> Western   14.03876  2.777038 -14.113157 -7.804959 24.62684 25.50382  
> 8.3864782
> 
> Degrees of freedom: 575 total; 547 residual
> Residual standard error: 25.39981
> 
>>plot(fm, Level_of_Expression ~ fitted(.))
> 
> Error in plot.lmList(fm, Level_of_Expression ~ fitted(.)) : 
> Object "cF" not found
> 
> what is object cF ...?
> 
> __
> 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

Could you provide us with a traceback or, perhaps better, a copy of the
data frame d (off-list and disguised, if necessary) so we can reproduce
the problem?

P.S. It may be easier to use xyplot directly as in

 xyplot(Level_of_Expression ~ fitted(fm), d)

__
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] Problem with data frame when using xYplot?

2005-05-13 Thread Sander Oom
An off list response from Mat Soukop (thanks Mat!!) provides an even 
more elegant solution (see code below)! I have included the original 
code, so people can decide whether to plot in a single panel or in 
multiple panels. Now we have a fully functional workaround to get 
plotmeans{gplots} for multiple factors using lattice! Great!


library(Hmisc)
library(lattice)
tmp <-
structure(list(Position = structure(as.integer(c(1, 2, 1, 2,
1, 2, 1, 2)), .Label = c("Inside", "Outside"), class = "factor"),
AltGeo = structure(as.integer(c(1, 1, 2, 2, 3, 3, 4, 4)), .Label = 
c("Basalt-High",
"Basalt-Low", "Quartz-High", "Quartz-Low"), class = "factor"),
Sodium = c(27.3, 26.9, 25, 18.1,
4.67, 5.56, 10.7, 5.67
), SD = c(5.3851648071345, 2.42097317438899, 20.1618451536560,
15.2679766541317, 5.45435605731786, 8.09492296305393, 10.6183802907976,
8.06225774829855), Nobs = c(9, 9, 9, 9, 9, 9, 9, 9), Lower = 
c(25.5382783976218,
26.0818978307592, 18.2793849487813, 13.0217855597339, 2.84854798089405,
2.85724790120425, 7.12720656973412, 2.97924741723382), Upper = 
c(29.1283882690448,
27.6958799470186, 31.7206150512187, 23.2004366624884, 6.48478535243929,
8.25386320990686, 14.2061267635992, 8.35408591609952)), .Names = 
c("Position",
"AltGeo", "Sodium", "SD", "Nobs", "Lower", "Upper"), row.names = c("1",
"2", "3", "4", "5", "6", "7", "8"), class = "data.frame")
tmp$PosNum <- unclass(tmp$Position)
tmp
(labs <- unique(tmp$Position))
# plot factor levels in seperate panels
xYplot(Cbind(Sodium,Lower,Upper) ~ PosNum|AltGeo, data=tmp, nx=FALSE,
  xlim=c(0.5,2.5),
  ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1),
  scales = list(x = list(at=seq(1, 2, by=1), labels = labs)),
  xlab="Position", ylab="Sodium"
  )


new.back <- trellis.par.get("background")
new.back$col <- "white"
newcol <- trellis.par.get("superpose.symbol")
newcol$col <- c('green4','blue','red','black')
newcol$pch <- c(16,1,4,8)
new.line <- trellis.par.get("box.rectangle")
new.line$col <- 'black'
trellis.par.set("background", new.back)
trellis.par.set("superpose.symbol", newcol)
trellis.par.set("box.rectangle", new.line)
# Plot factor levels in one graph
tmp$xvar <- rep(1:4, each=2)+rep(c(-.05,.05), 4)
xYplot(Cbind(Sodium,Lower,Upper) ~ xvar, groups=Position,  data=tmp,
  scales=list(y='free',x=list(at=1:4,
  labels=levels(tmp$AltGeo))),
  xlab='AltGeo', xlim=c(.5, 4.5),
  key=list(points=Rows(trellis.par.get("superpose.symbol"),1:2),
text=list(lab =as.character(levels(tmp$Position)),
col=trellis.par.get("superpose.symbol")$col[1:2]),
columns=2, cex=1, title="Position",
cex.title=1.1))

Sander Oom wrote:
Problem solved!
I was so focused on reproducing the plotmeans() functionality with 
xYplot() that I completely overlooked the fact that my data does not 
allow a x-y plot, as only Sodium is a numeric variable while Position 
and AltGeo are factors!

Using unclass() to make Position a numeric variable does the trick:
tmp$Position <- unclass(tmp$Position)
The code below does the trick. Now I only need to figure out how to 
tweak the x axis to pretend I am plotting a factor, i.e. plotting labels 
"Inside" and "Outside".

Cheers,
Sander.
library(Hmisc)
library(Lattice)
tmp <-
structure(list(Position = structure(as.integer(c(1, 2, 1, 2,
1, 2, 1, 2)), .Label = c("Inside", "Outside"), class = "factor"),
AltGeo = structure(as.integer(c(1, 1, 2, 2, 3, 3, 4, 4)), .Label = 
c("Basalt-High",
"Basalt-Low", "Quartz-High", "Quartz-Low"), class = "factor"),
Sodium = c(27.3, 26.9, 25, 18.1,
4.67, 5.56, 10.7, 5.67
), SD = c(5.3851648071345, 2.42097317438899, 20.1618451536560,
15.2679766541317, 5.45435605731786, 8.09492296305393, 10.6183802907976,
8.06225774829855), Nobs = c(9, 9, 9, 9, 9, 9, 9, 9), Lower = 
c(25.5382783976218,
26.0818978307592, 18.2793849487813, 13.0217855597339, 2.84854798089405,
2.85724790120425, 7.12720656973412, 2.97924741723382), Upper = 
c(29.1283882690448,
27.6958799470186, 31.7206150512187, 23.2004366624884, 6.48478535243929,
8.25386320990686, 14.2061267635992, 8.35408591609952)), .Names = 
c("Position",
"AltGeo", "Sodium", "SD", "Nobs", "Lower", "Upper"), row.names = c("1",
"2", "3", "4", "5", "6", "7", "8"), class = "data.frame")
tmp$Position <- unclass(tmp$Position)
xYplot(Cbind(Sodium,Lower,Upper) ~ Position|AltGeo, groups=AltGeo,
  data=tmp, ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1),
  xlab="Position", ylab="Sodium"
  )


Sander Oom wrote:
Dear all,
I am trying to plot means and error bars using xYplot, but I get an 
error message from xYplot which I can not figure out:
 > Error in Summary.factor(..., na.rm = na.rm) :
range not meaningful for factors

The data frame (tmpNa) was created using aggregate. I have used dump 
to created t

Re: [R] Big matrix memory problem

2005-05-13 Thread Gabor Grothendieck
On 5/13/05, s104100026 <[EMAIL PROTECTED]> wrote:
> Hi All,
> 
> I want to read 256 1000x1000 matrices into R. I understand that it is unlikely
> that I can do this but In the hope that somebody can help me I am mailing this
> list.
> 
> I have tried increasing my memory size (I understand that it is the minimum of
> 1024 or the computers RAM in my case 512)
> 
> Does anyone think this is possible in R, could it be tried in Splus for
> example.
> 

If they are sparse you could try the SparseM package.

__
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] Using R to illustrate the Central Limit Theorem

2005-05-13 Thread Ted Harding
On 13-May-05 Bliese, Paul D LTC USAMH wrote:
> Interesting thread. The graphics are great, the only thing that
> might be worth doing for teaching purposes would be to illustrate
> the original distribution that is being averaged 1000 times.
> 
> Below is one option based on Bill Venables code.  Note that to do
> this I had to start with a k of 2.
> 
> N <- 1
>  for(k in 2:20) {
> graphics.off()
> par(mfrow = c(2,2), pty = "s")
> hist(((runif(k))-0.5)*sqrt(12*k),main="Example Distribution 1")
> hist(((runif(k))-0.5)*sqrt(12*k),main="Example Distribution 2")
> m <- replicate(N, (mean(runif(k))-0.5)*sqrt(12*k))
> hist(m, breaks = "FD", xlim = c(-4,4), main = k,
> prob = TRUE, ylim = c(0,0.5), col = "lemonchiffon")
> pu <- par("usr")[1:2]
> x <- seq(pu[1], pu[2], len = 500)
> lines(x, dnorm(x), col = "red")
> qqnorm(m, ylim = c(-4,4), xlim = c(-4,4), pch = ".", col = "blue")
> abline(0, 1, col = "red")
> Sys.sleep(3)
>   }
> 
> By the way, I should probably know this but what is the logic of
> the "sqrt(12*k)" part of the example?  Obviously as k increases
> the mean will approach .5 in a uniform distribution, so
> runif(k)-.5 will be close to zero, and sqrt(12*k) increases as
> k increases.  Why 12, though?

The reason is indeed simple! In demonstrating the convergence
of the distribution of mean(k X's) to a Normal distribution,
the reference (i.e. the limiting distribution) is N(0,1), which
has mean 0 and variance 1. Therefore, in comparing the distribution
of mean(k X's) with N(0,1) it needs to be standardised to itself
have mean 0 and variance 1. As you've already spotted, you
standardise for the mean by subtracting 0.5; to standardise
for the variance you need to divide by sqrt(variance(mean(k X's))).

This is sqrt(variance(X)/k). Finally (and this is where the "12"
comes in), the variance of an X uniformly distributed on (0,1)
is 1/12 (left as an exercise for the reader ... ). Hence 12*k.

Best wishes,
Ted.



E-Mail: (Ted Harding) <[EMAIL PROTECTED]>
Fax-to-email: +44 (0)870 094 0861
Date: 13-May-05   Time: 13:43:54
-- XFMail --

__
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] Big matrix memory problem

2005-05-13 Thread Petr Pikal
Hallo

On 13 May 2005 at 13:38, s104100026 wrote:

> Hi All,
> 
> I want to read 256 1000x1000 matrices into R. I understand that it is
> unlikely that I can do this but In the hope that somebody can help me
> I am mailing this list.

Why do you think that.

I easilly read files from data logging equipment.

> 60min*24h*15days*130variables from text file which has 
[1] 2808000 items

just by read.table() in few whiles on quite old (4 years) and not 
superbly equipped PC (1G memory). 

So you can read your matrices sequentially. But if you want to 
work with all 256 matrices at once it could be problem.

Depends on what you want to do with them.
Cheers
Petr

> 
> I have tried increasing my memory size (I understand that it is the
> minimum of 1024 or the computers RAM in my case 512)
> 
> Does anyone think this is possible in R, could it be tried in Splus
> for example.
> 
> Any help is greatly appreciated.
> 
> Niall Fitzgerald
> Phd Candidate.
> 
> __
> 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

Petr Pikal
[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] Big matrix memory problem

2005-05-13 Thread Prof Brian Ripley
On Fri, 13 May 2005, s104100026 wrote:

> Hi All,
>
> I want to read 256 1000x1000 matrices into R. I understand that it is unlikely
> that I can do this but In the hope that somebody can help me I am mailing this
> list.

What sort of matrix?  If these are real numbers that is 2Gb.

> I have tried increasing my memory size (I understand that it is the minimum of
> 1024 or the computers RAM in my case 512)
>
> Does anyone think this is possible in R, could it be tried in Splus for
> example.

It is possible in R, but you will need a 64-bit version of R.  Since you
don't state your OS, my guess is it is Windows or MacOS, for neither of
which we have a 64-bit port as yet.

-- 
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 272860 (secr)
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] Big matrix memory problem

2005-05-13 Thread Uwe Ligges
s104100026 wrote:
Hi All,
I want to read 256 1000x1000 matrices into R. I understand that it is unlikely 
that I can do this but In the hope that somebody can help me I am mailing this 
list.

I have tried increasing my memory size (I understand that it is the minimum of 
1024 or the computers RAM in my case 512)

Does anyone think this is possible in R, could it be tried in Splus for 
example.

Given the matrices are numeric, you will need 256*1000*1000*8 = 2Gb of 
memory just to hold them in memory, in order to apply calculations, 
objects are frequently doubled ...
So you should really handle those matrices separately, either by getting 
them from a database or by saving them in form of separate Rdata objects.

Uwe Ligges

Any help is greatly appreciated.
Niall Fitzgerald
Phd Candidate.
__
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] Using R to illustrate the Central Limit Theorem

2005-05-13 Thread Kevin E. Thorpe
Thanks. I'd forgotton that detail about ifelse. Also, I was so focused 
on the U[0,1] it totally did not occur to me to go direct from U[-1,1]. 
Your suggestion should obviate the need for a local function at all.

Peter Dalgaard wrote:
"Kevin E. Thorpe" <[EMAIL PROTECTED]> writes:
 

rparab <- function(nn) {
u <- 2*runif(nn) - 1
ifelse(u<0,-(abs(u)^(1/3)),u^(1/3))
}
It seems that in my version of R (2.0.1) on Linux, that calculating the cube
root of a negative number using ^(1/3) returns NaN. I looked at the help in
the arithmetic operators and did help.search("cube root"),
help.search("root")
and help.search("cube") and recognised no alternatives. So I used an
ifelse() to
deal with the negatives. Have I missed something really elementary?
   

Not really. You might have used u <- runif(nn,-1,1) and
sign(u)*abs(u)^(1/3) instead of the ifelse construct (remember that
ifelse generally evaluates both the 'yes' and 'no' parts and on some
architectures the NaN results may be slow to compute).
 


--
Kevin E. Thorpe
Biostatistician/Trialist, Knowledge Translation Program
Assistant Professor, Department of Public Health Sciences
Faculty of Medicine, University of Toronto
email: [EMAIL PROTECTED]  Tel: 416.946.8081  Fax: 416.971.2462
__
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] Big matrix memory problem

2005-05-13 Thread s104100026
Hi All,

I want to read 256 1000x1000 matrices into R. I understand that it is unlikely 
that I can do this but In the hope that somebody can help me I am mailing this 
list.

I have tried increasing my memory size (I understand that it is the minimum of 
1024 or the computers RAM in my case 512)

Does anyone think this is possible in R, could it be tried in Splus for 
example.

Any help is greatly appreciated.

Niall Fitzgerald
Phd Candidate.

__
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] Using R to illustrate the Central Limit Theorem

2005-05-13 Thread Kevin E. Thorpe
The variance of U[0,1] is 1/12. So the variance of the mean of uniforms 
is 1/12k.
Rather than dividing by 1/12k he multiplied by 12k.

Kevin
Bliese, Paul D LTC USAMH wrote:
Interesting thread. The graphics are great, the only thing that might be
worth doing for teaching purposes would be to illustrate the original
distribution that is being averaged 1000 times.
Below is one option based on Bill Venables code.  Note that to do this I
had to start with a k of 2.
N <- 1
for(k in 2:20) {
   graphics.off()
   par(mfrow = c(2,2), pty = "s")
   hist(((runif(k))-0.5)*sqrt(12*k),main="Example Distribution 1")
   hist(((runif(k))-0.5)*sqrt(12*k),main="Example Distribution 2")
   m <- replicate(N, (mean(runif(k))-0.5)*sqrt(12*k))
   hist(m, breaks = "FD", xlim = c(-4,4), main = k,
   prob = TRUE, ylim = c(0,0.5), col = "lemonchiffon")
   pu <- par("usr")[1:2]
   x <- seq(pu[1], pu[2], len = 500)
   lines(x, dnorm(x), col = "red")
   qqnorm(m, ylim = c(-4,4), xlim = c(-4,4), pch = ".", col = "blue")
   abline(0, 1, col = "red")
   Sys.sleep(3)
 }
By the way, I should probably know this but what is the logic of the
"sqrt(12*k)" part of the example?  Obviously as k increases the mean
will approach .5 in a uniform distribution, so runif(k)-.5 will be close
to zero, and sqrt(12*k) increases as k increases.  Why 12, though?
PB
 


--
Kevin E. Thorpe
Biostatistician/Trialist, Knowledge Translation Program
Assistant Professor, Department of Public Health Sciences
Faculty of Medicine, University of Toronto
email: [EMAIL PROTECTED]  Tel: 416.946.8081  Fax: 416.971.2462
__
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] Conflict between xtable and Hmisc when using Sweave?

2005-05-13 Thread Sander Oom
Dear R users,
The Sweave code below runs fine, as it is. However, an error occurs when 
the line 'library(xtable)' is uncommented:
Error:  chunk 1
Error in "label<-"(`*tmp*`, value = "month") :
no applicable method for "label<-"

Is anybody aware of this and knows a workaround?
Thanks,
Sander.
***
\documentclass[a4paper]{article}
\title{Sweave Test for summarize}
\author{Sander Oom}
\usepackage{a4wide}
\begin{document}
\maketitle
\begin{figure}[ht]
\begin{center}
<>=
  # library(xtable)
  library(Hmisc)
  set.seed(111)
  dfr <- expand.grid(month=1:12, year=c(1997,1998), reps=1:100)
  month <- dfr$month
  year <- dfr$year
  y <- abs(month-6.5) + 2*runif(length(month)) + year-1997
  s <- summarize(y, llist(month,year), smedian.hilow, conf.int=.5)
  print(xYplot(Cbind(y,Lower,Upper) ~ month, groups=year, data=s,
keys='lines', method='alt', type='b'))
@
\end{center}
\end{figure}
\end{document}


> version
 _
platform i686-pc-linux-gnu
arch i686
os   linux-gnu
system   i686, linux-gnu
status
major2
minor1.0
year 2005
month04
day  18
language R
--

Dr. Sander P. Oom
Animal, Plant and Environmental Sciences,
University of the Witwatersrand
Private Bag 3, Wits 2050, South Africa
Tel (work)  +27 (0)11 717 64 04
Tel (home)  +27 (0)18 297 44 51
Fax +27 (0)18 299 24 64
Email   [EMAIL PROTECTED]
Web www.oomvanlieshout.net/sander
__
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] error in plot.lmList

2005-05-13 Thread Arne.Muller
Hello,

in R-2.1.0 I'm trying to prodice trellis plots from an lmList object as 
described in the help for plot.lmList. I can generate the plots from the help, 
but on my own data plotting fails with an error message that I cannot interpret 
(please see below). Any hints are greatly appreciapted.

kind regards,

Arne

> dim(d)
[1] 575   4
> d[1:3,]
  Level_of_Expression SSPos1 SSPos19 Method
111.9  G   A   bDNA
224.7  T   T   bDNA
3 9.8  C   T   bDNA
> fm <- lmList(Level_of_Expression ~ SSPos1 + SSPos19 | Method, data=d)
> fm
Call:
  Model: Level_of_Expression ~ SSPos1 + SSPos19 | Method 
   Data: d 

Coefficients:
   (Intercept)   SSPos1CSSPos1G   SSPos1T SSPos19C SSPos19G   
SSPos19T
bDNA  25.75211 -6.379701  -9.193304 10.371056 24.32171 24.06107  
9.7357724
Luciferase23.79947  4.905679  -7.747861  8.112779 48.95151 48.15064 
-0.2646783
RT-PCR56.08985 -7.352206 -15.896556 -2.712313 19.91967 24.28425 
-2.2317071
Western   14.03876  2.777038 -14.113157 -7.804959 24.62684 25.50382  
8.3864782

Degrees of freedom: 575 total; 547 residual
Residual standard error: 25.39981
> plot(fm, Level_of_Expression ~ fitted(.))
Error in plot.lmList(fm, Level_of_Expression ~ fitted(.)) : 
Object "cF" not found

what is object cF ...?

__
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] SVM linear kernel and SV

2005-05-13 Thread David Meyer
> Thank you for your answer,
> but my problem concerns the support vectors. Indeed the two classes
> are well separated and the hyperplane is linear but the support
> vectors aren't aligned in parallel to the hyperplane. And according to
> me,  the support vectors (for each class) should be aligned along the
> linear hyperplane and form the marge (by definition). But it's not the
> case. In fact,  I'd like to understand why they are not aligned. 

Remember the `cost'-penalty controlling for overlapping classes. It has
some effect even in the linearly separable case causing more SVs than
would actually be needed. Try adding e.g. `cost=1000' and you will
obtain a result with only 2 SVs (why not 3? Because 2 SVs here solve the
optimization problem. So in fact the hyperplane in this case is not
uniquely defined, although only in a small range.)

Best,

David

__
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] DEV2bitmap: jpeg with res=400 not enough for CORELDRAW poster A0

2005-05-13 Thread Peter Dalgaard
Uwe Ligges <[EMAIL PROTECTED]> writes:

> Jan Verbesselt wrote:
> 
> > Dear all,
> > When saving a plot with the dev2bitmap command:
> > name<- c("test.jpeg")
> > dev2bitmap(name,type="jpeg",height=8,width=13,res=400)
> > Everything seems to be ok... After importing this picture in
> > CORELDRAW (for
> > a poster A0) format the resolution and colors are not optimal.
> > How can I save pictures (colors/resolution) optimally for import into
> > CorelDraw for an A0 poster?
> > Pdf?/tiff?/bmp?/
> 
> What about PostScript? It's perfectly resizable and CorelDraw (at
> least the outdated version 10) can deal with it.

But not PDF? Notice that this is not really bitmapped either, even
though handled by dev2bitmap. 

Upping the res= is another option, but may be memory intensive. Notice
that A0 is 4 times as big as A4 (~8x12 inches) so you'd need up to 4
times the resolution - but I guess that your plot is not taking up the
whole area...


-- 
   O__   Peter Dalgaard Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics 2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark  Ph: (+45) 35327918
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907

__
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] DEV2bitmap: jpeg with res=400 not enough for CORELDRAW poster A0

2005-05-13 Thread Uwe Ligges
Jan Verbesselt wrote:
Dear all,
When saving a plot with the dev2bitmap command:
name<- c("test.jpeg")
dev2bitmap(name,type="jpeg",height=8,width=13,res=400)
Everything seems to be ok... After importing this picture in CORELDRAW (for
a poster A0) format the resolution and colors are not optimal.
How can I save pictures (colors/resolution) optimally for import into
CorelDraw for an A0 poster?
Pdf?/tiff?/bmp?/
What about PostScript? It's perfectly resizable and CorelDraw (at least 
the outdated version 10) can deal with it.

Uwe Ligges

Thanks,
Jan
___
ir. Jan Verbesselt 
Research Associate 
Lab of Geomatics Engineering K.U. Leuven
Vital Decosterstraat 102. B-3000 Leuven Belgium 
Tel: +32-16-329750   Fax: +32-16-329760
http://gloveg.kuleuven.ac.be/

__
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] Using R to illustrate the Central Limit Theorem

2005-05-13 Thread Bliese, Paul D LTC USAMH
Interesting thread. The graphics are great, the only thing that might be
worth doing for teaching purposes would be to illustrate the original
distribution that is being averaged 1000 times.

Below is one option based on Bill Venables code.  Note that to do this I
had to start with a k of 2.

N <- 1
 for(k in 2:20) {
graphics.off()
par(mfrow = c(2,2), pty = "s")
hist(((runif(k))-0.5)*sqrt(12*k),main="Example Distribution 1")
hist(((runif(k))-0.5)*sqrt(12*k),main="Example Distribution 2")
m <- replicate(N, (mean(runif(k))-0.5)*sqrt(12*k))
hist(m, breaks = "FD", xlim = c(-4,4), main = k,
prob = TRUE, ylim = c(0,0.5), col = "lemonchiffon")
pu <- par("usr")[1:2]
x <- seq(pu[1], pu[2], len = 500)
lines(x, dnorm(x), col = "red")
qqnorm(m, ylim = c(-4,4), xlim = c(-4,4), pch = ".", col = "blue")
abline(0, 1, col = "red")
Sys.sleep(3)
  }

By the way, I should probably know this but what is the logic of the
"sqrt(12*k)" part of the example?  Obviously as k increases the mean
will approach .5 in a uniform distribution, so runif(k)-.5 will be close
to zero, and sqrt(12*k) increases as k increases.  Why 12, though?

PB


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Kevin E. Thorpe
Sent: Friday, May 13, 2005 12:03 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch
Subject: Re: [R] Using R to illustrate the Central Limit Theorem

This thread was very timely for me since I will be teaching an
introductory
biostats course in the fall, including a session on CLT. I have
shamelessly
taken Dr. Venables' slick piece of code and wrapped it in a function so
that
I can vary the maximum sample size at will. I then created functions
based
on the first to sample from the exponential and the
chi-squaredistributions.
Lastly, I created a function to sample from a pdf with a parabolic shape
(confirming in the process just how rusty my calculus is :-) ). My code
is
below for all to do with as they please.

Now, at the risk of asking a really obvious question ...

In my final function, I used the inverse probability integral
transformation
to sample from my parabolic distribution. I create a local function
rparab
shown here:

rparab <- function(nn) {
u <- 2*runif(nn) - 1
ifelse(u<0,-(abs(u)^(1/3)),u^(1/3))
}

It seems that in my version of R (2.0.1) on Linux, that calculating the
cube
root of a negative number using ^(1/3) returns NaN. I looked at the help
in
the arithmetic operators and did help.search("cube root"), 
help.search("root")
and help.search("cube") and recognised no alternatives. So I used an 
ifelse() to
deal with the negatives. Have I missed something really elementary?

Thanks

clt.unif <- function(n=20) {
N <- 1
graphics.off()
par(mfrow = c(1,2), pty = "s")
for(k in 1:n) {
m <- (rowMeans(matrix(runif(N*k), N, k)) - 0.5)*sqrt(12*k)
hist(m, breaks = "FD", xlim = c(-4,4),
main = paste("Uniform(0,1), n = ",k,sep=""),
prob = TRUE, ylim = c(0,0.5), col = "lemonchiffon")
pu <- par("usr")[1:2]
x <- seq(pu[1], pu[2], len = 500)
lines(x, dnorm(x), col = "red")
qqnorm(m, ylim = c(-4,4), xlim = c(-4,4), pch = ".", col = "blue")
abline(0, 1, col = "red")
Sys.sleep(1)
}
}

clt.exp <- function(n=20,theta=1) {
N <- 1
graphics.off()
par(mfrow = c(1,2), pty = "s")
for(k in 1:n) {
m <- (rowMeans(matrix(rexp(N*k,1/theta), N, k)) - theta)/sqrt(theta^2/k)
hist(m, breaks = "FD", xlim = c(-4,4),
main = paste("exp(",theta,"), n = ",k,sep=""),
prob = TRUE, ylim = c(0,0.5), col = "lemonchiffon")
pu <- par("usr")[1:2]
x <- seq(pu[1], pu[2], len = 500)
lines(x, dnorm(x), col = "red")
qqnorm(m, ylim = c(-4,4), xlim = c(-4,4), pch = ".", col = "blue")
abline(0, 1, col = "red")
Sys.sleep(1)
}
}

clt.chisq <- function(n=20,nu=1) {
N <- 1
graphics.off()
par(mfrow = c(1,2), pty = "s")
for(k in 1:n) {
m <- (rowMeans(matrix(rchisq(N*k,nu), N, k)) - nu)/sqrt(2*nu/k)
hist(m, breaks = "FD", xlim = c(-4,4),
main = paste("Chi-Square(",nu,"), n = ",k,sep=""),
prob = TRUE, ylim = c(0,0.5), col = "lemonchiffon")
pu <- par("usr")[1:2]
x <- seq(pu[1], pu[2], len = 500)
lines(x, dnorm(x), col = "red")
qqnorm(m, ylim = c(-4,4), xlim = c(-4,4), pch = ".", col = "blue")
abline(0, 1, col = "red")
Sys.sleep(1)
}
}

clt.parab <- function(n=20) {
rparab <- function(nn) {
u <- 2*runif(nn) - 1
ifelse(u<0,-(abs(u)^(1/3)),u^(1/3))
}
N <- 1
graphics.off()
par(mfrow = c(1,2), pty = "s")
for(k in 1:n) {
m <- (rowMeans(matrix(rparab(N*k), N, k)))/sqrt(3/(5*k))
hist(m, breaks = "FD", xlim = c(-4,4),
main = paste("n = ",k,sep=""),
prob = TRUE, ylim = c(0,0.5), col = "lemonchiffon")
pu <- par("usr")[1:2]
x <- seq(pu[1], pu[2], len = 500)
lines(x, dnorm(x), col = "red")
qqnorm(m, ylim = c(-4,4), xlim = c(-4,4), pch = ".", col = "blue")
abline(0, 1, col = "red")
Sys.sleep(1)
}
}

[EMAIL PROTECTED] wrote:

>Here's a bit of a refinement on Ted's first suggestion.
>
> 
> N <- 1
> graphics.off()
> par(mfrow = c(1,2), pty = "s")
> for(k in 1:2

[R] DEV2bitmap: jpeg with res=400 not enough for CORELDRAW poster A0

2005-05-13 Thread Jan Verbesselt
Dear all,

When saving a plot with the dev2bitmap command:

name<- c("test.jpeg")
dev2bitmap(name,type="jpeg",height=8,width=13,res=400)

Everything seems to be ok... After importing this picture in CORELDRAW (for
a poster A0) format the resolution and colors are not optimal.

How can I save pictures (colors/resolution) optimally for import into
CorelDraw for an A0 poster?

Pdf?/tiff?/bmp?/

Thanks,
Jan


___
ir. Jan Verbesselt 
Research Associate 
Lab of Geomatics Engineering K.U. Leuven
Vital Decosterstraat 102. B-3000 Leuven Belgium 
Tel: +32-16-329750   Fax: +32-16-329760
http://gloveg.kuleuven.ac.be/

__
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] Problem with data frame when using xYplot?

2005-05-13 Thread Sander Oom
Problem solved!
I was so focused on reproducing the plotmeans() functionality with 
xYplot() that I completely overlooked the fact that my data does not 
allow a x-y plot, as only Sodium is a numeric variable while Position 
and AltGeo are factors!

Using unclass() to make Position a numeric variable does the trick:
tmp$Position <- unclass(tmp$Position)
The code below does the trick. Now I only need to figure out how to 
tweak the x axis to pretend I am plotting a factor, i.e. plotting labels 
"Inside" and "Outside".

Cheers,
Sander.
library(Hmisc)
library(Lattice)
tmp <-
structure(list(Position = structure(as.integer(c(1, 2, 1, 2,
1, 2, 1, 2)), .Label = c("Inside", "Outside"), class = "factor"),
AltGeo = structure(as.integer(c(1, 1, 2, 2, 3, 3, 4, 4)), .Label = 
c("Basalt-High",
"Basalt-Low", "Quartz-High", "Quartz-Low"), class = "factor"),
Sodium = c(27.3, 26.9, 25, 18.1,
4.67, 5.56, 10.7, 5.67
), SD = c(5.3851648071345, 2.42097317438899, 20.1618451536560,
15.2679766541317, 5.45435605731786, 8.09492296305393, 10.6183802907976,
8.06225774829855), Nobs = c(9, 9, 9, 9, 9, 9, 9, 9), Lower = 
c(25.5382783976218,
26.0818978307592, 18.2793849487813, 13.0217855597339, 2.84854798089405,
2.85724790120425, 7.12720656973412, 2.97924741723382), Upper = 
c(29.1283882690448,
27.6958799470186, 31.7206150512187, 23.2004366624884, 6.48478535243929,
8.25386320990686, 14.2061267635992, 8.35408591609952)), .Names = 
c("Position",
"AltGeo", "Sodium", "SD", "Nobs", "Lower", "Upper"), row.names = c("1",
"2", "3", "4", "5", "6", "7", "8"), class = "data.frame")
tmp$Position <- unclass(tmp$Position)
xYplot(Cbind(Sodium,Lower,Upper) ~ Position|AltGeo, groups=AltGeo,
  data=tmp, ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1),
  xlab="Position", ylab="Sodium"
  )


Sander Oom wrote:
Dear all,
I am trying to plot means and error bars using xYplot, but I get an 
error message from xYplot which I can not figure out:
 > Error in Summary.factor(..., na.rm = na.rm) :
range not meaningful for factors

The data frame (tmpNa) was created using aggregate. I have used dump to 
created the code below, which generates the same error.

Can anybody tell me what is wrong with the data frame?
Thanks in advance,
Sander.
library(Hmisc)
tmpNa <-
structure(list(Position = structure(as.integer(c(1, 2, 1, 2,
1, 2, 1, 2)), .Label = c("Inside", "Outside"), class = "factor"),
AltGeo = structure(as.integer(c(1, 1, 2, 2, 3, 3, 4, 4)), .Label = 
c("Basalt-High",
"Basalt-Low", "Quartz-High", "Quartz-Low"), class = "factor"),
Sodium = c(27.3, 26.9, 25, 18.1,
4.67, 5.56, 10.7, 5.67
), SD = c(5.3851648071345, 2.42097317438899, 20.1618451536560,
15.2679766541317, 5.45435605731786, 8.09492296305393, 10.6183802907976,
8.06225774829855), Nobs = c(9, 9, 9, 9, 9, 9, 9, 9), Lower = 
c(25.5382783976218,
26.0818978307592, 18.2793849487813, 13.0217855597339, 2.84854798089405,
2.85724790120425, 7.12720656973412, 2.97924741723382), Upper = 
c(29.1283882690448,
27.6958799470186, 31.7206150512187, 23.2004366624884, 6.48478535243929,
8.25386320990686, 14.2061267635992, 8.35408591609952)), .Names = 
c("Position",
"AltGeo", "Sodium", "SD", "Nobs", "Lower", "Upper"), row.names = c("1",
"2", "3", "4", "5", "6", "7", "8"), class = "data.frame")
xYplot(Cbind(Sodium,Lower,Upper) ~ AltGeo, groups=Position,  data=tmpNa)

 > version
 _
platform i686-pc-linux-gnu
arch i686
os   linux-gnu
system   i686, linux-gnu
status
major2
minor1.0
year 2005
month04
day  18
language R
--

Dr. Sander P. Oom
Animal, Plant and Environmental Sciences,
University of the Witwatersrand
Private Bag 3, Wits 2050, South Africa
Tel (work)  +27 (0)11 717 64 04
Tel (home)  +27 (0)18 297 44 51
Fax +27 (0)18 299 24 64
Email   [EMAIL PROTECTED]
Web www.oomvanlieshout.net/sander
__
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] pls -- crossval vs plsr(..., CV=TRUE)

2005-05-13 Thread =?iso-8859-1?q?Bj=F8rn-Helge_Mevik?=
Bjørn-Helge Mevik writes:

> There are two reasons:

Actually, there is a third reason as well. :-)  We've just discovered an
embarrasingly stupid bug in the R2 calculation in mvrCv; it calculates
R (the correlation) instead of R2 (squared correlation).  A patched
version will be released shortly.  Until then, c(R2(NIR.plsCV)$val^2)
should give you the correct values.

-- 
Bjørn-Helge Mevik

__
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