Re: [R] plot legend: combining filled boxes and lines

2007-09-10 Thread Gabor Grothendieck
Check out:
http://tolstoy.newcastle.edu.au/R/e2/help/07/05/16777.html

On 9/10/07, Lauri Nikkinen [EMAIL PROTECTED] wrote:
 Hello,

 I have difficulties combining boxes and lines in plot legend. I
 searched previous R-posts and found this (with no solution):
 http://tolstoy.newcastle.edu.au/R/help/06/07/30248.html. Is there a
 way to avoid boxes behind the line legends?

 x1 - rnorm(100)
 x2 - rnorm(100, 2)
 hist(x1, main = , col = orange,ylab = density, xlab = x, freq
 = F, density = 55,  xlim = c(-2, 5), ylim = c(0, 0.5))
 par(new = T)
 hist(x2, main = , col = green, ylab = , xlab = ,axes = F, xlim
 = c(-2, 5), ylim = c(0, 0.5), density = 45, freq = F)

 abline(v = mean(x1), col = orange, lty = 2, lwd = 2.5)
 abline(v = mean(x2), col = green, lty = 2, lwd = 2.5)
 legend(3, 0.45, legend = c(x1, x2, mean(x1), mean(x2)), col =
 c(orange, green), fill=c(orange,green, 0, 0),  lty = c(0, 0,
 2, 2), merge = T)

 Thanks
 Lauri

 __
 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
 and provide commented, minimal, self-contained, reproducible code.


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] lattice panel.lmline problem

2007-09-10 Thread Frede Aakmann Tøgersen
Why not use the more simple

xyplot(total.fat~x|variable,groups=Group,
   data=tmp1,type=c(p,r))

???

See ?panel.xyplot and especially the type argument of that panel function.




Best regards

Frede Aakmann Tøgersen
Scientist


UNIVERSITY OF AARHUS
Faculty of Agricultural Sciences
Dept. of Genetics and Biotechnology
Blichers Allé 20, P.O. BOX 50
DK-8830 Tjele

Phone:   +45 8999 1900
Direct:  +45 8999 1878

E-mail:  [EMAIL PROTECTED]
Web:   http://www.agrsci.org

This email may contain information that is confidential.
Any use or publication of this email without written permission from Faculty of 
Agricultural Sciences is not allowed.
If you are not the intended recipient, please notify Faculty of Agricultural 
Sciences immediately and delete this email.


 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af Ross Darnell
 Sendt: 10. september 2007 07:55
 Til: r-help@stat.math.ethz.ch
 Emne: [R] lattice panel.lmline problem
 
 I am wanting to generate panels showing scatterplots with the 
 linear fitted line for two groups within each panel superimposed.
 
 I have two conditioning factors, variable and Group and I 
 want separate panels for each level of variable
 
 with different symbols and lmlines for each level of 
 Group. However all observations for a group are missing for 
 some variables so I would still like the points and lmline 
 for the observed group plotted for that variable(panel).
 
  
 
 My attempt is 
 
  
 
 print(xyplot(total.fat~x|variable,data=tmp1,subscripts=TRUE,
 
  
 scales=list(x=list(relation=free)),xlab=,groups=Group,
 
  panel=function(x,y,subscripts,...){
 
panel.superpose(x,y,subscripts,...)
 
if(length(x[subscripts])!=0)
 
  
 {panel.superpose(x,y,panel.groups=panel.lmline,subscripts,...)}}))
 
  
 
 Which gives an error
 
  
 
 Error in lm.fit(x, y, offset = offset, singular.ok = 
 singular.ok, ...) :
 
 
 0 (non-NA) cases
 
  
 
  
 
 Which occurs when the first panel with all values for one 
 group are missing.
 
 The same error is returned if I replace the last line without the if
 statement which obviously means it's ignored.
 
  
 
 Of course I may be taking the wrong tack completely to get 
 the result I need. Any advice would be appreciated
 
   
 
  
 
 Ross Darnell
 
 
   [[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
 and provide commented, minimal, self-contained, reproducible code.


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] plot legend: combining filled boxes and lines

2007-09-10 Thread Lauri Nikkinen
Thanks Gabor, I got it!

For example:
x1 - rnorm(100)
x2 - rnorm(100, 2)
hist(x1, main = , col = orange,ylab = density, xlab = x, freq
= F, density = 55, xlim = c(-2, 5), ylim = c(0, 0.5))
par(new = T)
hist(x2, main = , col = green, ylab = , xlab = ,axes = F, xlim
= c(-2, 5), ylim = c(0, 0.5), density = 45, freq = F)

abline(v = mean(x1), col = orange, lty = 2, lwd = 2.5)
abline(v = mean(x2), col = green, lty = 2, lwd = 2.5)
legend(3, 0.45, legend = c(x1, x2, mean(x1), mean(x2)),
   col = rep(c(orange, green), 2), pch=c(15,15, NA, NA),
   pt.cex=2,
   lty = c(0, 0, 2, 2))

-Lauri



2007/9/10, Gabor Grothendieck [EMAIL PROTECTED]:
 Check out:
 http://tolstoy.newcastle.edu.au/R/e2/help/07/05/16777.html

 On 9/10/07, Lauri Nikkinen [EMAIL PROTECTED] wrote:
  Hello,
 
  I have difficulties combining boxes and lines in plot legend. I
  searched previous R-posts and found this (with no solution):
  http://tolstoy.newcastle.edu.au/R/help/06/07/30248.html. Is there a
  way to avoid boxes behind the line legends?
 
  x1 - rnorm(100)
  x2 - rnorm(100, 2)
  hist(x1, main = , col = orange,ylab = density, xlab = x, freq
  = F, density = 55,  xlim = c(-2, 5), ylim = c(0, 0.5))
  par(new = T)
  hist(x2, main = , col = green, ylab = , xlab = ,axes = F, xlim
  = c(-2, 5), ylim = c(0, 0.5), density = 45, freq = F)
 
  abline(v = mean(x1), col = orange, lty = 2, lwd = 2.5)
  abline(v = mean(x2), col = green, lty = 2, lwd = 2.5)
  legend(3, 0.45, legend = c(x1, x2, mean(x1), mean(x2)), col =
  c(orange, green), fill=c(orange,green, 0, 0),  lty = c(0, 0,
  2, 2), merge = T)
 
  Thanks
  Lauri
 
  __
  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
  and provide commented, minimal, self-contained, reproducible code.
 


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problems with strsplit

2007-09-10 Thread Moshe Olshansky
 unlist(strsplit(bA531F16-rep,\\-))[1]
[1] bA531F16

--- Carlos Morales [EMAIL PROTECTED]
wrote:

 Hello,

   I would like to know what can I do if I use
 strplit with a string and I want to use the middle
 left,I mean I have this:

   strsplit(bA531F16-rep,\\-)
   [[1]]
 [1] bA531F16 rep
   I would like to work just with bA531F16 in another
 variable, what could I do?, Thank you

 

 -
 
 Sé un Mejor Amante del Cine
 ¿Quieres saber cómo? ¡Deja que otras personas te
 ayuden!.
 
   [[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
 and provide commented, minimal, self-contained,
 reproducible code.


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] command to plot variannce of data (like error bar plot)

2007-09-10 Thread Jim Lemon
Yogesh Tiwari wrote:
 Hi,
 
 How to plot a variance over a data point, something like error bar.
 
Hi Yogesh,

The generic method is to use the arrows function, and there are quite 
a few variations on this theme (in alpha order):

brkdn.plot(plotrix)
dispbars(plotrix)
errbar(Hmisc and sfsmisc)
plotCI(gplots and plotrix)
plotMeans (Rcmdr)

and there are surely more error bar functions of which I am unaware.

Jim

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] lattice panel.lmline problem

2007-09-10 Thread Ross Darnell
Thanks Frede

I didn't know about the r type. 

Ross Darnell


-Original Message-
From: Frede Aakmann Tøgersen [mailto:[EMAIL PROTECTED]
Sent: Mon 10-Sep-07 4:45 PM
To: Ross Darnell; r-help@stat.math.ethz.ch
Subject: SV: [R] lattice panel.lmline problem
 
Why not use the more simple

xyplot(total.fat~x|variable,groups=Group,
   data=tmp1,type=c(p,r))

???

See ?panel.xyplot and especially the type argument of that panel function.




Best regards

Frede Aakmann Tøgersen
Scientist


UNIVERSITY OF AARHUS
Faculty of Agricultural Sciences
Dept. of Genetics and Biotechnology
Blichers Allé 20, P.O. BOX 50
DK-8830 Tjele

Phone:   +45 8999 1900
Direct:  +45 8999 1878

E-mail:  [EMAIL PROTECTED]
Web:   http://www.agrsci.org

This email may contain information that is confidential.
Any use or publication of this email without written permission from Faculty of 
Agricultural Sciences is not allowed.
If you are not the intended recipient, please notify Faculty of Agricultural 
Sciences immediately and delete this email.


 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af Ross Darnell
 Sendt: 10. september 2007 07:55
 Til: r-help@stat.math.ethz.ch
 Emne: [R] lattice panel.lmline problem
 
 I am wanting to generate panels showing scatterplots with the 
 linear fitted line for two groups within each panel superimposed.
 
 I have two conditioning factors, variable and Group and I 
 want separate panels for each level of variable
 
 with different symbols and lmlines for each level of 
 Group. However all observations for a group are missing for 
 some variables so I would still like the points and lmline 
 for the observed group plotted for that variable(panel).
 
  
 
 My attempt is 
 
  
 
 print(xyplot(total.fat~x|variable,data=tmp1,subscripts=TRUE,
 
  
 scales=list(x=list(relation=free)),xlab=,groups=Group,
 
  panel=function(x,y,subscripts,...){
 
panel.superpose(x,y,subscripts,...)
 
if(length(x[subscripts])!=0)
 
  
 {panel.superpose(x,y,panel.groups=panel.lmline,subscripts,...)}}))
 
  
 
 Which gives an error
 
  
 
 Error in lm.fit(x, y, offset = offset, singular.ok = 
 singular.ok, ...) :
 
 
 0 (non-NA) cases
 
  
 
  
 
 Which occurs when the first panel with all values for one 
 group are missing.
 
 The same error is returned if I replace the last line without the if
 statement which obviously means it's ignored.
 
  
 
 Of course I may be taking the wrong tack completely to get 
 the result I need. Any advice would be appreciated
 
   
 
  
 
 Ross Darnell
 
 
   [[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
 and provide commented, minimal, self-contained, reproducible code.
 


[[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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] PCA IN R

2007-09-10 Thread Bjørn-Helge Mevik
prcomp() in stats handles matrices with n  p well, IMO.

-- 
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] artificial data matrix with 100000 rows

2007-09-10 Thread Martin Maechler
 PS == Paul Smith [EMAIL PROTECTED]
 on Sun, 9 Sep 2007 12:17:32 +0100 writes:

PS On 9/9/07, kevinchang [EMAIL PROTECTED] wrote:
 I tried to made the matrix with this size by either matrix() or array().
 However, there seems to be default limit of number for rows made. I got 
sort
 of error message from R .To be specific,
 
 m--matrix(ncol=3,nrow=10)
 
 error message:[ reached getOption(max.print) -- omitted 7 rows ]]
 
 or
 
 a-array(dim=c(1,3,10))
 
 error message:reached getOption(max.print) -- omitted 6667 row(s) and 6
 matrix slice(s) ]

PS That is not an error message, I guess. 

Definitely not,
thank you, Paul!

Also, they were not produced by what Kevin showed (namely assignments)
but rather when he *prints* the contents of his huge matrix /
array.

PS When the matrices are huge, R is unable to print them
PS totally on the screen, but all data are present.

Not at all unable !!
R protects you from accidentally overflowing your console with
huge amount of non-sensical output.

As the warning above mentions,
you should look at
  ? getOption
  ? options
and particularly the  'max.print'  option

Is  '' reached  getOption(max.print) '' 
too difficult to read?

You *can* increase the 'max.print' option as much as you like,
and that's why I said 'not at all unable'   above.

Regards,
Martin

PS For instance,

 m[(nrow(m)-10):nrow(m),]
PS [,1] [,2] [,3]
PS [1,]   NA   NA   NA
PS [2,]   NA   NA   NA
PS [3,]   NA   NA   NA
PS [4,]   NA   NA   NA
PS [5,]   NA   NA   NA
PS [6,]   NA   NA   NA
PS [7,]   NA   NA   NA
PS [8,]   NA   NA   NA
PS [9,]   NA   NA   NA
PS [10,]   NA   NA   NA
PS [11,]   NA   NA   NA

or rather just

   tail(m)

or tail(m, 11)
or head(m)

or str(m)

etc etc

PS See

PS ?getOption

yes indeed.
Martin

PS Paul

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help in installing and loading the BradleyTerry add on package in R

2007-09-10 Thread Turner, Heather
However you may also need to install the package brlr, since the
BradleyTerry package depends on this.

For Windows users, it's usually easiest to install packages using the
Packages menu in the RGui - any dependencies are then automatically
installed.

Heather

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jim Lemon
Sent: 10 September 2007 12:07
To: [EMAIL PROTECTED]
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Help in installing and loading the BradleyTerry add on
package in R

Kalyan Roy (DEL/MSG) wrote:
 How do I install and load the BradleyTerry add on package in R 2.5.1
in
 MSWindowsXP environment?
 
Hi Kalyan,
If

R CMD INSTALL

doesn't work, you can use WinZip or Zip Reader to unzip the package to:

C:\Program Files\R-2.5.1\library

or whatever your path to the library directory is, and then hand edit 
the packages.html file in:

C:\Program Files\R-2.5.1\doc\html

to include the new package in your HTML listing. This will allow you to 
access the help files and use the package.

Jim

__
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
and provide commented, minimal, self-contained, reproducible code.

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] artificial data matrix with 100000 rows

2007-09-10 Thread Paul Smith
On 9/10/07, Martin Maechler [EMAIL PROTECTED] wrote:
 PS On 9/9/07, kevinchang [EMAIL PROTECTED] wrote:
  I tried to made the matrix with this size by either matrix() or 
 array().
  However, there seems to be default limit of number for rows made. I 
 got sort
  of error message from R .To be specific,
 
  m--matrix(ncol=3,nrow=10)
 
  error message:[ reached getOption(max.print) -- omitted 7 rows ]]
 
  or
 
  a-array(dim=c(1,3,10))
 
  error message:reached getOption(max.print) -- omitted 6667 row(s) 
 and 6
  matrix slice(s) ]

 PS That is not an error message, I guess.

 Definitely not,
 thank you, Paul!

 Also, they were not produced by what Kevin showed (namely assignments)
 but rather when he *prints* the contents of his huge matrix /
 array.

 PS When the matrices are huge, R is unable to print them
 PS totally on the screen, but all data are present.

 Not at all unable !!
 R protects you from accidentally overflowing your console with
 huge amount of non-sensical output.

 As the warning above mentions,
 you should look at
   ? getOption
   ? options
 and particularly the  'max.print'  option

 Is  '' reached  getOption(max.print) ''
 too difficult to read?

 You *can* increase the 'max.print' option as much as you like,
 and that's why I said 'not at all unable'   above.

 Regards,
 Martin

 PS For instance,

  m[(nrow(m)-10):nrow(m),]
 PS [,1] [,2] [,3]
 PS [1,]   NA   NA   NA
 PS [2,]   NA   NA   NA
 PS [3,]   NA   NA   NA
 PS [4,]   NA   NA   NA
 PS [5,]   NA   NA   NA
 PS [6,]   NA   NA   NA
 PS [7,]   NA   NA   NA
 PS [8,]   NA   NA   NA
 PS [9,]   NA   NA   NA
 PS [10,]   NA   NA   NA
 PS [11,]   NA   NA   NA

 or rather just

tail(m)

 or tail(m, 11)
 or head(m)

 or str(m)

 etc etc

 PS See

 PS ?getOption

 yes indeed.

Thanks, Martin, for your detailed comments. I have learned something from them.

Paul

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help in installing and loading the BradleyTerry add on package in R

2007-09-10 Thread Jim Lemon
Kalyan Roy (DEL/MSG) wrote:
 How do I install and load the BradleyTerry add on package in R 2.5.1 in
 MSWindowsXP environment?
 
Hi Kalyan,
If

R CMD INSTALL

doesn't work, you can use WinZip or Zip Reader to unzip the package to:

C:\Program Files\R-2.5.1\library

or whatever your path to the library directory is, and then hand edit 
the packages.html file in:

C:\Program Files\R-2.5.1\doc\html

to include the new package in your HTML listing. This will allow you to 
access the help files and use the package.

Jim

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] plot legend: combining filled boxes and lines

2007-09-10 Thread Monica Pisica

 
This is not quite what you want but you can try this:
 
legend(3, 0.45, legend = c(x1, x2, mean(x1), mean(x2)), col =
c(orange, green),pch = c(15,15,-1,-1), lty=c(-1,-1,2,2))
 
 
Although pch=22 should draw a filled square with a border - but it draws only 
the border instead 
 

Monica
 
__
Message: 24Date: Mon, 10 Sep 2007 09:05:27 +0300From: Lauri Nikkinen [EMAIL 
PROTECTED]Subject: [R] plot legend: combining filled boxes and linesTo: [EMAIL 
PROTECTED]:[EMAIL PROTECTED]Content-Type: text/plain; charset=ISO-8859-1 
Hello, I have difficulties combining boxes and lines in plot legend. Isearched 
previous R-posts and found this (with no 
solution):http://tolstoy.newcastle.edu.au/R/help/06/07/30248.html. Is there 
away to avoid boxes behind the line legends? x1 - rnorm(100)x2 - rnorm(100, 
2)hist(x1, main = , col = orange,ylab = density, xlab = x, freq= F, 
density = 55, xlim = c(-2, 5), ylim = c(0, 0.5))par(new = T)hist(x2, main = , 
col = green, ylab = , xlab = ,axes = F, xlim= c(-2, 5), ylim = c(0, 0.5), 
density = 45, freq = F) abline(v = mean(x1), col = orange, lty = 2, lwd = 
2.5)abline(v = mean(x2), col = green, lty = 2, lwd = 2.5)legend(3, 0.45, 
legend = c(x1, x2, mean(x1), mean(x2)), col =c(orange, green), 
fill=c(orange,green, 0, 0), lty = c(0, 0,2, 2), merge = T) ThanksLauri 
_
Gear up for Halo® 3 with free downloads and an exclusive offer. It’s our way of 
saying thanks for using Windows Live™.

[[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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] overlay lattice histograms with goodness-of-fit pdfs

2007-09-10 Thread Frede Aakmann Tøgersen

The following is one of the examples in the help page for histogram:

 histogram( ~ height | voice.part, data = singer,
   xlab = Height (inches), type = density,
   panel = function(x, ...) {
   panel.histogram(x, ...)
   panel.mathdensity(dmath = dnorm, col = black,
 args = list(mean=mean(x),sd=sd(x)))
   } )

This should give you some thing to start from.

Also using the subset argument of the lattice functions will make make your 
code more readable. Instead of your code

histogram(~ data | month * station,
data = sta.stack[sta.stack[,type]==precip  
(sta.stack[,month]==Dec | sta.stack[,month]==Jan | 
sta.stack[,month]==Feb),],
xlab = Precipitation (mm))

you can use (not tested because you didn't supply a reproducable example)

histogram(~ data | month * station, data = sta.stack
subset = type==precip  month %in% c(Dec, Jan, Feb),
xlab = Precipitation (mm))


Med venlig hilsen
Frede Aakmann Tøgersen
 

 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af Brad 
 Christoffersen
 Sendt: 10. september 2007 12:08
 Til: R-help@stat.math.ethz.ch
 Emne: [R] overlay lattice histograms with goodness-of-fit pdfs
 
 Hello,
 
 I am new to R exploratory data analysis and plotting.  Is 
 anyone aware of a way to overlay a set of conditional 
 histograms with conditional PDFs?  Below, I generate a 
 lattice plot of precipitation histograms based on different 
 months and stations, given a subset of the dataset:
 
 
 histogram(~ data | month * station,
   data = sta.stack[sta.stack[,type]==precip  
 (sta.stack[,month]==Dec | sta.stack[,month]==Jan | 
 sta.stack[,month]==Feb),],
   xlab = Precipitation (mm))
 
 
 I previously used a combination of the low-level 'lines()' 
 and 'dgamma()'
 functions to overlay a gamma PDF onto a single histogram.  
 Now what I would like to do is to do the same thing, but with 
 a function that allows me to specify a formula similar to 
 that in the histogram function above
 
 [SomeKindOfPDF] ~ [x-range] | month * station
 
 which will plot the PDF with the appropriate factors (month 
 and station).
 
 All I'm looking for is for someone to get me going in the 
 right direction with a useful package or function to use.
 
 Any help is much appreciated!
 Brad Christoffersen
 
 __
 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
 and provide commented, minimal, self-contained, reproducible code.


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] mode or parameters of readBin

2007-09-10 Thread Duncan Murdoch
On 9/10/2007 10:26 AM, Sigbert Klinke wrote:
 Hi,
 
   sapply(formals(readBin), mode)
   con  what n  sizesignedendian
namename numeric logical logicalcall
 
 returns for the mode of size logical. But in the documentation is said 
 that size should be integer. Does anyone know why the mode is logical?

The default value is NA, and the mode of NA is logical.  (It will 
automatically be promoted into another type if included in a vector, 
e.g. c(1:2, NA) promotes it to integer, c(3.14, NA) promotes it to numeric.)

More generally, I'd say reading the man page or the source is a better 
way to find out about the requirements for the arguments of a function.

Duncan Murdoch

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


Re: [R] Problems with strsplit

2007-09-10 Thread xavierab

You could directly use

strsplit(bA531F16-rep,\\-)[[1]][1]
and 
strsplit(bA531F16-rep,\\-)[[1]][2]

Regards


Carlos Morales-2 wrote:
 
 Hello,

   I would like to know what can I do if I use strplit with a string and I
 want to use the middle left,I mean I have this:

   strsplit(bA531F16-rep,\\-)
   [[1]]
 [1] bA531F16 rep
   I would like to work just with bA531F16 in another variable, what could
 I do?, Thank you

 

 -
 
 Sé un Mejor Amante del Cine
 ¿Quieres saber cómo? ¡Deja que otras personas te ayuden!.
 
   [[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
 and provide commented, minimal, self-contained, reproducible code.
 
 

-- 
View this message in context: 
http://www.nabble.com/Problems-with-strsplit-tf4412525.html#a12594380
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] ggplot legend consolidation

2007-09-10 Thread hadley wickham
 I have recently been introduced to the ggplot package by Hadley Wickham
 and must say I am quite impressed so far at how easy it is to make
 attractive plots, but one thing I am struggling over is how to
 consolidate legends.

It's not currently possible to consolidate them (although in the
distant future that would be something nice to have), but you can turn
them off:

hide_colour - scale_colour_continuous()
hide_colour$legend - FALSE

p - ggplot(data = mtcars) +
  geom_point(mapping = aes(x = hp, y = mpg, colour = cyl)) +
  hide_colour

You'll also need to twiddle your viewports a little so that you still
have space for the viewport, since space will not be allocated
automatically anymore.

The next thing is to extract the grob for the legend itself - this is
a little tricker, because there's currently no way to get at the
scales after they have been trained with the
data.  Load get_legends from http://pastie.textmate.org/95755, and
then you can do:

grid.newpage(); grid.draw(get_legends(p))

If you're not familiar enough with grid to stitch all of these pieces
together, please let me know, but this should be enough to get you
started.

Hadley

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] RWinEdt installation problems with Vista

2007-09-10 Thread Stefan Grosse

 Hi,

 I was trying to install the packageRWinEdt in my computer with Vista OS.
 O
Use Tinn-R it works with Vista although has some minor issues (which are
probably system specific).

https://sourceforge.net/projects/tinn-r

Stefan

-=-=-
... Time is an illusion, lunchtime doubly so. (Ford Prefect)

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Are the error messages of ConstrOptim() consisten with each other?

2007-09-10 Thread Duncan Murdoch
Yuchen Luo wrote:
 Dear Friends.
 I found something very puzzling with constOptim(). When I change the
 parameters for ConstrOptim, the error messages do not seem to be
 consistent with each other:

   
 constrOptim(c(0.5,0.3,0.5), f=fit.error, gr=fit.error.grr, ui=ui,ci=ci)
 
 Error in constrOptim(c(0.5, 0.3, 0.5), f = fit.error, gr = fit.error.grr,  :
 initial value not feasible
   
Not feasible means it doesn't satisfy the constraints.
 constrOptim(c(0.5,0.9,0.5), f=fit.error, gr=fit.error.grr, ui=ui,ci=ci)
 
 Error in constrOptim(c(0.5, 0.9, 0.5), f = fit.error, gr = fit.error.grr,  :
 initial value not feasible
   
 constrOptim(c(0.3,0.5,0.5), f=fit.error, gr=fit.error.grr, ui=ui,ci=ci)
 
 Error in f(theta, ...) : argument lambda1 is missing, with no default
   

This time your starting values satisfied the constraints, so your 
objective function was called, but you didn't pass it a value for lambda1.
 I only changed the parameters, how come the lambda1 that is not
 missing in the first 2 cases suddently become missing?

 For your convenience, I put the complete code below:

 Best Wishes
 Yuchen Luo

 
 rm(list = ls())

 mat=5

 rint=c(4.33,4.22,4.27,4.43,4.43,4.44,4.45,4.65,4.77,4.77)
 tot=rep(13319.17,10)
 sh=rep(1553656,10)
 sigmae=c(0.172239074,0.188209271,0.193703774,0.172659891,0.164427247,0.24602361,0.173555309,0.186701165,0.193150456,
 0.1857315601)
 ss=c(56.49,56.39,56.55,57.49,57.37,55.02,56.02,54.35,54.09, 54.67)
 orange=rep(21.25,10)

 apple2=expression(rint*(1.0-rec)*(1.0-(pnorm(-lambda/2.0+log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/lambda)-((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))*pnorm(-lambda/2.0-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/lambda))+(exp(rint*(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)*ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))-sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0*(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/s!
 h*!
  
 1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))+((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(-sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))+sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0*(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))-(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt((lambda*l!
 am!
  bda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*
 1000.0))-sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0*(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))+((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(-sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))+sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0*(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))/((pnorm(-lambda/2.0+log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/lambda)-((ss+(tot/sh*1!
 00!
  
 

Re: [R] Survey package

2007-09-10 Thread Thomas Lumley
On Thu, 6 Sep 2007, eugen pircalabelu wrote:

 Good afternoon!

  I'm trying to use the Survey package for a stratified sample which has 
 4 criteria on which the stratification is based. I would like to get the 
 corrected weights and for every element i get a weight of 1

  E.g: tipping

   design - svydesign (id=~1, strata= ~regiune + size_loc + age_rec_hhh 
 + size_hh, data= tabel)
   and then  weights(design)
  gives me:  1,1,1,1,1,1,1,1,1,1,1,... for each element


There are two problems.  The first is that you have the wrong syntax for 
strata.  If you have one stage of sampling with multiple stratifying 
factors you need to create a single factor representing the strata. One 
way is with interaction()

design - svydesign (id=~1, strata= ~interaction(regiune, size_loc,  
age_rec_hhh, size_hh), data= tabel)

Second, you have not specified either weights or population sizes, so R 
has no way to work out the sampling weights. That's why you get weights of 
1.  You should also get a warning.

-thomas

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


Re: [R] the survey package

2007-09-10 Thread Thomas Lumley
On Thu, 6 Sep 2007, Tobias Verbeke wrote:

 eugen pircalabelu wrote:

   I'm trying to use the survey package to get a better point of view 
 for my data, but i need some piece of advice:

   i have some data from a survey which has been stratified using 2 
 criteria: region(7 values), size of locality(5 values)  Using the 
 survey pakage how can i define in a correct way this design (taking 
 into account all 4 strata not just one as in the Survey example)

snip
 According to ?svydesign, strata is a formula.

 The following should work (untested):

 design - svydesign(ids=~0, strata=~regiune + size_loc, data=tabel)

This would be a two-stage sample, you actually need ~interaction(regiune, 
size_loc).

[this reply is just to make sure it ends up linked in the archives].

-thomas

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


Re: [R] writing complex outputs to table

2007-09-10 Thread Xavier Abulker

Steve,
This example works:

x-TukeyHSD(fm1, tension, ordered = TRUE)
as.table(x$tension)


Steve Powers wrote:
 
 So I've come across a few cases where complex outputs from functions 
 will not write to tables. The most recent case involves the TukeyHSD 
 function in the stats package. If I save the TukeyHSD call and print it, 
 that obviously goes fine, but when I try writing to a table, I get an 
 error message that says cannot coerce class \multicomp\ into 
 dataframe. What does this mean, and how do I work around it? Is there a 
 more fail-safe general method of writing complex outputs to a table? 
 The story here is I want to be able to call certain values from the 
 TukeyHSD results to produce custom summaries.
 
 Using R version 2.4 on Windows XP.---steve
 
 __
 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
 and provide commented, minimal, self-contained, reproducible code.
 
 

-- 
View this message in context: 
http://www.nabble.com/writing-complex-outputs-to-table-tf4407732.html#a12596104
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Are the error messages of ConstrOptim() consisten with each other?

2007-09-10 Thread Thomas Lumley

The error message about the feasible region comes from constrOptim(), 
before your function is called.  The error message about missing lambda1 
comes from calling your function.

-thomas

On Sun, 9 Sep 2007, Yuchen Luo wrote:

 Dear Friends.
 I found something very puzzling with constOptim(). When I change the
 parameters for ConstrOptim, the error messages do not seem to be
 consistent with each other:

 constrOptim(c(0.5,0.3,0.5), f=fit.error, gr=fit.error.grr, ui=ui,ci=ci)
 Error in constrOptim(c(0.5, 0.3, 0.5), f = fit.error, gr = fit.error.grr,  :
initial value not feasible
 constrOptim(c(0.5,0.9,0.5), f=fit.error, gr=fit.error.grr, ui=ui,ci=ci)
 Error in constrOptim(c(0.5, 0.9, 0.5), f = fit.error, gr = fit.error.grr,  :
initial value not feasible
 constrOptim(c(0.3,0.5,0.5), f=fit.error, gr=fit.error.grr, ui=ui,ci=ci)
 Error in f(theta, ...) : argument lambda1 is missing, with no default

 I only changed the parameters, how come the lambda1 that is not
 missing in the first 2 cases suddently become missing?

 For your convenience, I put the complete code below:

 Best Wishes
 Yuchen Luo

 
 rm(list = ls())

 mat=5

 rint=c(4.33,4.22,4.27,4.43,4.43,4.44,4.45,4.65,4.77,4.77)
 tot=rep(13319.17,10)
 sh=rep(1553656,10)
 sigmae=c(0.172239074,0.188209271,0.193703774,0.172659891,0.164427247,0.24602361,0.173555309,0.186701165,0.193150456,
 0.1857315601)
 ss=c(56.49,56.39,56.55,57.49,57.37,55.02,56.02,54.35,54.09, 54.67)
 orange=rep(21.25,10)

 apple2=expression(rint*(1.0-rec)*(1.0-(pnorm(-lambda/2.0+log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/lambda)-((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))*pnorm(-lambda/2.0-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/lambda))+(exp(rint*(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)*ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))-sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0*(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/s!
 h*!
 1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))+((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(-sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))+sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0*(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))-(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt((lambda*la!
 m!
 bda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*
 1000.0))-sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0*(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))+((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(-sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))+sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0*(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))/((pnorm(-lambda/2.0+log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/lambda)-((ss+(tot/sh*1!
 00!
 

Re: [R] Survey package

2007-09-10 Thread Thomas Lumley
On Sun, 9 Sep 2007, eugen pircalabelu wrote:
 A short example:

 stratum id weight nh Nh  y sex
 1  1  3 5 15 23   1
 1  2  3 5 15 25   1
 1  3  3 5 15 27   2
 1  4  3 5 15 21   2
 1  5  3 5 15 22   1
 2  6  4 3 12 33   1
 2  7  4 3 12 27   1
 2  8  4 3 12 29   2

 where nh is size of sample stratum and Nh the corresponding  population 
 value, and  y is  metric variable.

 Now if i let

 design - svydesign( id=~1, data=age, strata=~stratum, fpc=~Nh)
 then weights(design)  gives me 3,3,3,3,3,4,4,4.

 If i then let

 x- postStratify( design, strata=~sex, data.frame(sex=c(1,2), 
 freq=c(10,15)))
 the weights become

 123456
 78
 2.17   2.17   5.35   5.352.171.731.73 
4.28

 If i define

 design - svydesign( id=~1, data=age )
 x- postStratify( design, strata=~sex, data.frame(sex=c(1,2), 
 freq=c(10,15)))
 weights become  2 2 5 5 2 2 2 5

 The question: does poststratify recognize that i have already stratified 
 in the first design by stratum and then it post stratifies by sex? and 
 why is that? (because i don't have the full joint distribution, the 
 sex*stratum crossing, in order to apply correctly the post stratify 
 function) I see that Mr Lumley uses the postStratify function when the 
 design does not include strata (eg from ?poststratify:


This gives you a design stratified by stratum and post-stratified by sex, 
which is not the same as stratifying by stratum*sex or post-stratifying by 
stratum*sex.

In this case you should probably rake() on stratum and sex rather than 
just post-stratifying. Post-stratifying on sex is equivalent to one iteration 
of the iterative proportional fitting algorithm used in raking.

-thomas

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


Re: [R] write.csv / string extraction and field limits

2007-09-10 Thread Xavier Abulker

This example works fine:

test-matrix(c(1,2,'VOICIUNPETITTES',3),ncol=2,nrow=2)
write.csv(test,file='C:/xavier/test.csv')


Could you provide the same small example when it doesn't work?



kwaj wrote:
 
 Hello, 
 
 I have a peculiar problem which I am hoping I can get help on. 
 
 I am using the write.csv command to write a matrix structure to a file,
 which I later read in excel. The command works quite well for most strings
 and numerical values in the matrix structure. 
 
 However, I have found that when a field in the matrix contains a string of
 long length, when the matrix is finally written the file - the field shows
 up as NA. I am assuming write.csv has a limit on the field size? Maybe
 16 characters?
 
 Assuming the above is correct - I tried to extract a portion of the string
 using the 'substring' command and enter the extracted portion into the
 field before using the write.csv command. However I find, that when a
 string is extracted, the output from write.csv generates a NA in the file
 output. 
 
 My questions are:
 
 1) Does write.csv have a limit on the size of strings in the matrix
 fields? Is there anyway to place large strings in the field?
 
 2) Is there anyway to make the substring command or an alternative but
 similar command, compatible with write.csv? I have tried
 'as.character(substring(phrase, min, max)' and that does not seem to work
 
 cheers
 
 
 

-- 
View this message in context: 
http://www.nabble.com/write.csv---string-extraction-and-field-limits-tf4395535.html#a12596551
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] mode or parameters of readBin

2007-09-10 Thread Thomas Lumley
On Mon, 10 Sep 2007, Sigbert Klinke wrote:

 Hi,

  sapply(formals(readBin), mode)
  con  what n  sizesignedendian
   namename numeric logical logicalcall

 returns for the mode of size logical. But in the documentation is said
 that size should be integer. Does anyone know why the mode is logical?


Because NA is a logical constant.

-thomas

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


Re: [R] ggplot legend consolidation

2007-09-10 Thread Te, Kaom
Hi Hadley,

I just tried out your suggestion, but it does not look like the
get_legends function is working correctly. Instead of returning a grob
back to me it returns NULL.

Here is my modified code and the results of running it.

Any help would be appreciated. I believe that once I can get the legend
in grob form then I can figure out how to deconstruct it myself. 

Thanks,
Kaom

 p.legend - get_legends(p)
 grid.draw(p.legend)
Error in grid.draw(p.legend) : no applicable method for grid.draw
 p.legend
NULL


 BEGIN CODE
## Obtained from http://pastie.textmate.org/95755
get_legends - function(plot) {
  if (length(plot$layers) == 0) stop(No layers to plot, call.=FALSE)
  
  # Apply function to layer and matching data
  dlapply - function(f) mapply(f, data, layers, SIMPLIFY=FALSE)

  plot - plot_clone(plot)
  layers - plot$layers
  scales - plot$scales
  facet - plot$facet

  cs - plot$coordinates

  # Evaluate aesthetics
  data - lapply(layers, function(x) x$make_aesthetics(plot))
  
  # Facet
  data - mapply(function(d, p) facet$stamp_data(d), data, layers,
SIMPLIFY=FALSE)
  # Transform scales where possible.  Also need to train so statisics
  # (e.g. stat_smooth) have access to info
  data - dlapply(function(d, p) p$scales_transform(d, scales))
  dlapply(function(d, p) p$scales_train(d, scales))

  # Apply statistics
  data - dlapply(function(d, p) p$calc_statistics(d, scales))
  data - dlapply(function(d, p) p$map_statistics(d, plot))

  # Adjust position before scaling
  data - dlapply(function(d, p) p$adjust_position(d, scales, before))
  # Transform, train and map scales
  # data - dlapply(function(d, p) p$scales_transform(d, scales))
  dlapply(function(d, p) p$scales_train(d, scales, adjust=TRUE))
  data - dlapply(function(d, p) p$scales_map(d, scales))

  # Adjust position after scaling
  data - dlapply(function(d, p) p$adjust_position(d, scales, after))
  scales - scales$minus(plot$scales$get_scales(c(x, y, z)))

  legends(scales, FALSE)
}


library(ggplot2)
data(mtcars)
 
grid.newpage()

hide_colour - scale_colour_continuous()
hide_colour$legend - FALSE

pushViewport(viewport(layout = grid.layout(2, 2)))
 
p - ggplot(data = mtcars) +
  geom_point(mapping = aes(x = hp, y = mpg, colour = cyl)) +
  hide_colour

pushViewport(viewport(layout.pos.col = 1,
  layout.pos.row = 1))
 
print(p, vp = current.viewport())
upViewport()
 
p - ggplot(data = mtcars) +
  geom_point(mapping = aes(x = drat, y = disp, colour = cyl)) +
  hide_colour
 

pushViewport(viewport(layout.pos.col = 2,
  layout.pos.row = 1))
 
print(p, vp = current.viewport())
upViewport()
 
p - ggplot(data = mtcars) +
  geom_point(mapping = aes(x = qsec, y = mpg, colour = cyl)) +
  hide_colour
 
pushViewport(viewport(layout.pos.col = 1,
  layout.pos.row = 2))
 
print(p, vp = current.viewport())
upViewport()

pushViewport(viewport(layout.pos.col = 2,
  layout.pos.row = 2))
grid.rect()

p.legend - get_legends(p)
grid.draw(p.legend) 
--END CODE



-Original Message-
From: hadley wickham [mailto:[EMAIL PROTECTED] 
Sent: Monday, September 10, 2007 7:58 AM
To: Te, Kaom
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] ggplot legend consolidation

 I have recently been introduced to the ggplot package by Hadley 
 Wickham and must say I am quite impressed so far at how easy it is to 
 make attractive plots, but one thing I am struggling over is how to 
 consolidate legends.

It's not currently possible to consolidate them (although in the distant
future that would be something nice to have), but you can turn them off:

hide_colour - scale_colour_continuous() hide_colour$legend - FALSE

p - ggplot(data = mtcars) +
  geom_point(mapping = aes(x = hp, y = mpg, colour = cyl)) +
  hide_colour

You'll also need to twiddle your viewports a little so that you still
have space for the viewport, since space will not be allocated
automatically anymore.

The next thing is to extract the grob for the legend itself - this is a
little tricker, because there's currently no way to get at the scales
after they have been trained with the data.  Load get_legends from
http://pastie.textmate.org/95755, and then you can do:

grid.newpage(); grid.draw(get_legends(p))

If you're not familiar enough with grid to stitch all of these pieces
together, please let me know, but this should be enough to get you
started.

Hadley

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] off-topic: better OS for statistical computing

2007-09-10 Thread Gabor Grothendieck
You want whatever all the people you are working with are using
to make it as easy as possible to work together with them.

On 9/10/07, Wensui Liu [EMAIL PROTECTED] wrote:
 Good morning, everyone,
 I am sorry for this off-topic post but think I can get great answer
 from this list.
 My question is what is the best OS on PC (laptop) for statistical
 computing and why.
 I really appreciate your insight.
 Have a nice day.

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] finding the minimum positive value of some data

2007-09-10 Thread Henrique Dallazuanna
Try this:

min(diff(sort(x))[diff(sort(x))0])


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

On 10/09/2007, dxc13 [EMAIL PROTECTED] wrote:


 useRs,

 I am looking to find the minimum positive value of some data I have.
 Currently, I am able to find the minimum of data after I apply some other
 functions to it:

  x
 [1]  1  0  1  2  3  3  4  5  5  5  6  7  8  8  9  9 10 10

  sort(x)
 [1]  0  1  1  2  3  3  4  5  5  5  6  7  8  8  9  9 10 10

  diff(sort(x))
 [1] 1 0 1 1 0 1 1 0 0 1 1 1 0 1 0 1 0

  min(diff(sort(x)))
 [1] 0

 The minimum is given as zero, which is clearly true, but I am interested
 in
 only the positive minimum, which is 1.  Can I find this by using only 1
 line
 of code, like I have above? Thanks!

 dxc13
 --
 View this message in context:
 http://www.nabble.com/finding-the-minimum-positive-value-of-some-data-tf4417250.html#a12599319
 Sent from the R help mailing list archive at Nabble.com.

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


[[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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] finding the minimum positive value of some data

2007-09-10 Thread Marc Schwartz
On Mon, 2007-09-10 at 11:20 -0700, dxc13 wrote:
 useRs,
 
 I am looking to find the minimum positive value of some data I have. 
 Currently, I am able to find the minimum of data after I apply some other
 functions to it:
 
  x
  [1]  1  0  1  2  3  3  4  5  5  5  6  7  8  8  9  9 10 10
 
  sort(x)
  [1]  0  1  1  2  3  3  4  5  5  5  6  7  8  8  9  9 10 10
 
  diff(sort(x))
  [1] 1 0 1 1 0 1 1 0 0 1 1 1 0 1 0 1 0
 
  min(diff(sort(x)))
 [1] 0
 
 The minimum is given as zero, which is clearly true, but I am interested in
 only the positive minimum, which is 1.  Can I find this by using only 1 line
 of code, like I have above? Thanks!
 
 dxc13

It's not clear to me which vector you wish to get the minimum for, but
the basic premise would be along the lines of:

 x
 [1]  1  0  1  2  3  3  4  5  5  5  6  7  8  8  9  9 10 10


 min(x[which(x  0)])
[1] 1

or

 min(which(diff(sort(x))  0))
[1] 1

See ?which

HTH,

Marc Schwartz

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


Re: [R] ggplot legend consolidation

2007-09-10 Thread hadley wickham
Sorry, I should have mentioned that get_legend won't work on the plots
that you are actually plotting - you have turned their legends off!
You'll need a plot which isn't plotted, but is used to produce the
legends.

Hadley

On 9/10/07, Te, Kaom [EMAIL PROTECTED] wrote:
 Hi Hadley,

 I just tried out your suggestion, but it does not look like the
 get_legends function is working correctly. Instead of returning a grob
 back to me it returns NULL.

 Here is my modified code and the results of running it.

 Any help would be appreciated. I believe that once I can get the legend
 in grob form then I can figure out how to deconstruct it myself.

 Thanks,
 Kaom

  p.legend - get_legends(p)
  grid.draw(p.legend)
 Error in grid.draw(p.legend) : no applicable method for grid.draw
  p.legend
 NULL
 

  BEGIN CODE
 ## Obtained from http://pastie.textmate.org/95755
 get_legends - function(plot) {
   if (length(plot$layers) == 0) stop(No layers to plot, call.=FALSE)

   # Apply function to layer and matching data
   dlapply - function(f) mapply(f, data, layers, SIMPLIFY=FALSE)

   plot - plot_clone(plot)
   layers - plot$layers
   scales - plot$scales
   facet - plot$facet

   cs - plot$coordinates

   # Evaluate aesthetics
   data - lapply(layers, function(x) x$make_aesthetics(plot))

   # Facet
   data - mapply(function(d, p) facet$stamp_data(d), data, layers,
 SIMPLIFY=FALSE)
   # Transform scales where possible.  Also need to train so statisics
   # (e.g. stat_smooth) have access to info
   data - dlapply(function(d, p) p$scales_transform(d, scales))
   dlapply(function(d, p) p$scales_train(d, scales))

   # Apply statistics
   data - dlapply(function(d, p) p$calc_statistics(d, scales))
   data - dlapply(function(d, p) p$map_statistics(d, plot))

   # Adjust position before scaling
   data - dlapply(function(d, p) p$adjust_position(d, scales, before))
   # Transform, train and map scales
   # data - dlapply(function(d, p) p$scales_transform(d, scales))
   dlapply(function(d, p) p$scales_train(d, scales, adjust=TRUE))
   data - dlapply(function(d, p) p$scales_map(d, scales))

   # Adjust position after scaling
   data - dlapply(function(d, p) p$adjust_position(d, scales, after))
   scales - scales$minus(plot$scales$get_scales(c(x, y, z)))

   legends(scales, FALSE)

 }


 library(ggplot2)
 data(mtcars)

 grid.newpage()

 hide_colour - scale_colour_continuous()
 hide_colour$legend - FALSE

 pushViewport(viewport(layout = grid.layout(2, 2)))

 p - ggplot(data = mtcars) +
   geom_point(mapping = aes(x = hp, y = mpg, colour = cyl)) +
   hide_colour

 pushViewport(viewport(layout.pos.col = 1,
   layout.pos.row = 1))

 print(p, vp = current.viewport())
 upViewport()

 p - ggplot(data = mtcars) +
   geom_point(mapping = aes(x = drat, y = disp, colour = cyl)) +
   hide_colour


 pushViewport(viewport(layout.pos.col = 2,
   layout.pos.row = 1))

 print(p, vp = current.viewport())
 upViewport()

 p - ggplot(data = mtcars) +
   geom_point(mapping = aes(x = qsec, y = mpg, colour = cyl)) +
   hide_colour

 pushViewport(viewport(layout.pos.col = 1,
   layout.pos.row = 2))

 print(p, vp = current.viewport())
 upViewport()

 pushViewport(viewport(layout.pos.col = 2,
   layout.pos.row = 2))
 grid.rect()

 p.legend - get_legends(p)
 grid.draw(p.legend)
 --END CODE




 -Original Message-
 From: hadley wickham [mailto:[EMAIL PROTECTED]
 Sent: Monday, September 10, 2007 7:58 AM
 To: Te, Kaom
 Cc: r-help@stat.math.ethz.ch
 Subject: Re: [R] ggplot legend consolidation

  I have recently been introduced to the ggplot package by Hadley
  Wickham and must say I am quite impressed so far at how easy it is to
  make attractive plots, but one thing I am struggling over is how to
  consolidate legends.

 It's not currently possible to consolidate them (although in the distant
 future that would be something nice to have), but you can turn them off:

 hide_colour - scale_colour_continuous() hide_colour$legend - FALSE

 p - ggplot(data = mtcars) +
   geom_point(mapping = aes(x = hp, y = mpg, colour = cyl)) +
   hide_colour

 You'll also need to twiddle your viewports a little so that you still
 have space for the viewport, since space will not be allocated
 automatically anymore.

 The next thing is to extract the grob for the legend itself - this is a
 little tricker, because there's currently no way to get at the scales
 after they have been trained with the data.  Load get_legends from
 http://pastie.textmate.org/95755, and then you can do:

 grid.newpage(); grid.draw(get_legends(p))

 If you're not familiar enough with grid to stitch all of these pieces
 together, please let me know, but this should be enough to get you
 started.

 Hadley



-- 
http://had.co.nz/

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch

Re: [R] S-Plus resample package and associated functions

2007-09-10 Thread Patrick Burns
http://www.burns-stat.com/pages/Tutor/bootstrap_resampling.html

includes a synopsis of R packages that do bootstrapping.
It is brief and incomplete, but hopefully useful.

Patrick Burns
[EMAIL PROTECTED]
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and A Guide for the Unwilling S User)

Robert A. LaBudde wrote:

Are there any packages in R that reproduce the package resample of S-Plus?

The sample() function in R doesn't provide equivalent flexibility of 
bootstrap() and bootstrap2().

Robert A. LaBudde, PhD, PAS, Dpl. ACAFS  e-mail: [EMAIL PROTECTED]
Least Cost Formulations, Ltd.URL: http://lcfltd.com/
824 Timberlake Drive Tel: 757-467-0954
Virginia Beach, VA 23464-3239Fax: 757-467-2947

Vere scire est per causas scire

__
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
and provide commented, minimal, self-contained, reproducible code.


  


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Too many warnings when updating R

2007-09-10 Thread Peter Dalgaard
A Lenzo wrote:
 Hello friends,

 I loaded R 2.4.1 onto a Fedora Core 6 Linux box (taking all defaults).  Then
 I ran these commands from within R:

 options(CRAN=http://cran.stat.ucla.edu;)
 install.packages(CRAN.packages()[,1])

 As a new user of R, I was shocked when I finished loading R and discovered
 the following message:

 There were 50 or more warnings (use warnings() to see the first 50)

   
Let me get this straight: You install last year's R on last year's 
Fedora, then install over 1000 unspecified packages and you are shocked 
that you get warnings?

 In addition to this, I saw errors such as this one:

 ERROR: lazy loading failed for package 'PerformanceAnalytics'

 What is this lazy loading?  More importantly, do I have to worry about all
 these warnings?  I am intimidated by the idea that I have to go back and fix
 each and every one in order to have a clean R update.  Shouldn't the update
 with CRAN just work?  Or is there something really important that I am
 missing?
   
Well, you need to know what you're doing. At the very least, notice what 
the warnings say and decide whether they point to real trouble or are 
just what they say they are: warnings. If you are worried about  
investigating all the packages, maybe install what you really need first.

And no, you can't expect a repository like CRAN to keep track of all 
versions of R on all versions of all OS's. In each individual case, a 
human maintainer is responsible for fixing problems and he/she may or 
may not be around to fix issues.

-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] lattice panel.lmline problem

2007-09-10 Thread Deepayan Sarkar
On 9/10/07, Ross Darnell [EMAIL PROTECTED] wrote:
 Thanks Frede

 I didn't know about the r type.

For the record, this is probably what you wanted:

xyplot(...
   panel = panel.superpose,
   panel.groups = function(x, y, ...) {
   panel.xyplot(x, y, ...)
   if (length(x)  0) panel.lmline(x, y, ...)
   })

x[subscripts] inside the panel function doesn't give anything
meaningful ('x' is already subscripted).

-Deepayan



 Ross Darnell


 -Original Message-
 From: Frede Aakmann Tøgersen [mailto:[EMAIL PROTECTED]
 Sent: Mon 10-Sep-07 4:45 PM
 To: Ross Darnell; r-help@stat.math.ethz.ch
 Subject: SV: [R] lattice panel.lmline problem

 Why not use the more simple

 xyplot(total.fat~x|variable,groups=Group,
data=tmp1,type=c(p,r))

 ???

 See ?panel.xyplot and especially the type argument of that panel function.

[...]

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] off-topic: better OS for statistical computing

2007-09-10 Thread Rolf Turner

On 11/09/2007, at 4:22 AM, Wensui Liu wrote:

 Good morning, everyone,
 I am sorry for this off-topic post but think I can get great answer
 from this list.
 My question is what is the best OS on PC (laptop) for statistical
 computing and why.
 I really appreciate your insight.
 Have a nice day.


Linux.  It's best for ***everything***.

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confidenti...{{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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] off-topic: better OS for statistical computing

2007-09-10 Thread Weiwei Shi
Linux!  Mac OS is ok to me2.

On 9/10/07, Wensui Liu [EMAIL PROTECTED] wrote:
 Good morning, everyone,
 I am sorry for this off-topic post but think I can get great answer
 from this list.
 My question is what is the best OS on PC (laptop) for statistical
 computing and why.
 I really appreciate your insight.
 Have a nice day.

 __
 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
 and provide commented, minimal, self-contained, reproducible code.



-- 
Weiwei Shi, Ph.D
Research Scientist
GeneGO, Inc.

Did you always know?
No, I did not. But I believed...
---Matrix III

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Are the error messages of ConstrOptim() consisten with each other?

2007-09-10 Thread Yuchen Luo
Dear Professor Murdoch.
Thank you for your help!
1. I believe c(0.5,0.3,0.5) satisfies the constrain because I did the
following experiment
ui=-1*ui
ci=-1*ci
constrOptim(c(0.5,0.3,0.5), f=fit.error, gr=fit.error.grr, ui=ui,ci=ci)

The same error message pops up. Any theta ( in this case, c(0.5,0.3,0.5))
cannot violate both ui%*%theta=ci and -ui%*%theta=-ci.

2. There is lambda1 available. The 0.3 in c(0.5,0.3,0.5) is lambda1. If you
plug c(0.5,0.3,0.5) into fit.error and fit.error.grr by
fit.error(0.5,0.3,0.5)
fit.error.grr(0.5,0.3,0.5)
It works.

Best Wishes
Yuchen Luo




On 9/10/07, Duncan Murdoch [EMAIL PROTECTED] wrote:

 Yuchen Luo wrote:
  Dear Friends.
  I found something very puzzling with constOptim(). When I change the
  parameters for ConstrOptim, the error messages do not seem to be
  consistent with each other:
 
 
  constrOptim(c(0.5,0.3,0.5), f=fit.error, gr=fit.error.grr, ui=ui,ci=ci)
 
  Error in constrOptim(c(0.5, 0.3, 0.5), f = fit.error, gr = fit.error.grr
 ,  :
  initial value not feasible
 
 Not feasible means it doesn't satisfy the constraints.
  constrOptim(c(0.5,0.9,0.5), f=fit.error, gr=fit.error.grr, ui=ui,ci=ci)
 
  Error in constrOptim(c(0.5, 0.9, 0.5), f = fit.error, gr = fit.error.grr
 ,  :
  initial value not feasible
 
  constrOptim(c(0.3,0.5,0.5), f=fit.error, gr=fit.error.grr, ui=ui,ci=ci)
 
  Error in f(theta, ...) : argument lambda1 is missing, with no default
 

 This time your starting values satisfied the constraints, so your
 objective function was called, but you didn't pass it a value for lambda1.
  I only changed the parameters, how come the lambda1 that is not
  missing in the first 2 cases suddently become missing?
 
  For your convenience, I put the complete code below:
 
  Best Wishes
  Yuchen Luo
 
  
  rm(list = ls())
 
  mat=5
 
  rint=c(4.33,4.22,4.27,4.43,4.43,4.44,4.45,4.65,4.77,4.77)
  tot=rep(13319.17,10)
  sh=rep(1553656,10)
  sigmae=c(0.172239074,0.188209271,0.193703774,0.172659891,0.164427247,
 0.24602361,0.173555309,0.186701165,0.193150456,
  0.1857315601)
  ss=c(56.49,56.39,56.55,57.49,57.37,55.02,56.02,54.35,54.09, 54.67)
  orange=rep(21.25,10)
 
  apple2=expression(rint*(1.0-rec)*(1.0-
 (pnorm(-lambda/2.0+log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0
 )/lbar*exp(lambda*lambda)))/lambda)-((ss+(tot/sh*1000.0)*lbar)/(tot/sh*
 1000.0)/lbar*exp(lambda*lambda))*pnorm(-lambda/2.0-log(((ss+(tot/sh*1000.0
 )*lbar)/(tot/sh*1000.0
 )/lbar*exp(lambda*lambda)))/lambda))+(exp(rint*(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*
 1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)*ss+(tot/sh*1000.0
 )*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(sqrt(0.25+2.0*rint/
 (sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
 +0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0
 )/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0
 )))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
 )))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))-sqrt(0.25+2.0*rint/
 (sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
 *(sigmae*ss/(ss+lbar*(tot/sh*1000.0
 )))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*!
   1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))+((ss+(tot/sh*1000.0
 )*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(-sqrt(0.25+2.0*rint/
 (sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
 +0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0
 )/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0
 )))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
 )))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))+sqrt(0.25+2.0*rint/
 (sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
 *(sigmae*ss/(ss+lbar*(tot/sh*1000.0
 )))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
 )))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))-(((ss+(tot/sh*1000.0
 )*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(sqrt(0.25+2.0*rint/
 (sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
 +0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0
 )/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0
 )))*sqrt((lambda*lam!
   bda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*
  1000.0))-sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
 )))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0*(sigmae*ss/(ss+lbar*(tot/sh*
 1000.0)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
 )))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))+((ss+(tot/sh*1000.0
 )*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(-sqrt(0.25+2.0*rint/
 (sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
 +0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0
 )/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0
 )))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0
 )))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))+sqrt(0.25+2.0*rint/
 

Re: [R] MLE Function

2007-09-10 Thread Peter Dalgaard
Terence Broderick wrote:
 I am just trying to teach myself how to use the mle function in R because it 
 is much better than what is provided in MATLAB. I am following tutorial 
 material from the internet, however, it gives the following errors, does 
 anybody know what is happening to cause such errors, or does anybody know any 
 better tutorial material on this particular subject.
   
   
 x.gam-rgamma(200,rate=0.5,shape=3.5)
 x-x.gam
 library(stats4)
 ll-function(lambda,alfa){n-200;x-x.gam 
 -n*alfa*log(lambda)+n*log(gamma(alfa))-9alfa-1)*sum(log(x))+lambda*sum(x)}
 
 Error: syntax error, unexpected SYMBOL, expecting '\n' or ';' or '}' in 
 ll-function(lambda,alfa){n-200;x-x.gam 
 -n*alfa*log(lambda)+n*log(gamma(alfa))-9alfa
   
 ll-function(lambda,alfa){n-200;x-x.gam 
 -n*alfa*log(lambda)+n*log(gamma(alfa))-(alfa-1)*sum(log(x))+lambda*sum(x)}
 est-mle(minuslog=ll,start=list(lambda=2,alfa=1))
 
 Error in optim(start, f, method = method, hessian = TRUE, ...) : 
 objective function in optim evaluates to length 200 not 1


   
Er, not what I get. Did your version have that linefeed after x - x.gam 
? If not, then you'll get your negative log-likelihood added to x.gam 
and the resulting likelihood becomes a vector of length 200 instead of 
a scalar.

In general, the first piece of advice for mle() is to check that the 
likelihood function really is what it should be. Otherwise there is no 
telling what the result might mean...

Secondly, watch out for parameter constraints. With your function, it 
very easily happens that alfa tries to go negative in which case the 
gamma function in the likelihood will do crazy things.
A common trick in such cases is to reparametrize by log-parameters, i.e.

ll - function(lambda,alfa){n-200; x-x.gam
-n*alfa*log(lambda)+n*lgamma(alfa)-(alfa-1)*sum(log(x))+lambda*sum(x)}

ll2 - function(llam, lalf) ll(exp(llam),exp(lalf))
est - mle(minuslog=ll2,start=list(llam=log(2),lalf=log(1)))

par(mfrow=c(2,1))
plot(profile(est))

Notice, incidentally, the use of lgamma rather than log(gamma(.)), which 
is prone to overflow.

In fact, you could also write this likelihood directly  as

-sum(dgamma(x, rate=lambda, shape=alfa, log=T))





 audaces fortuna iuvat

 -

   [[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
 and provide commented, minimal, self-contained, reproducible code.
   


-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] off-topic: better OS for statistical computing

2007-09-10 Thread Gabor Grothendieck
My sense is that R users are even split between UNIX and Windows
users so either will do in terms of the larger community.

Some R packages may not be avaliable on every platform or will
be available on one platform before another or there will be
certain platform-specific issues.  So in the end its easiest to
have the same thing everyone else that you work with does.

Also if you run into
problems then you can ask others whereas if you are the lone
person with something different you have no one to turn to.

Also associated software may be, for example, Microsoft Office in
a Microsoft environment and LaTeX in a UNIX environment. And
networking will be simplified in a consistent environment too.
Certainly there is Open Office, Samba and putty but the easiest
is just not to have to worry about getting everything to work
together by just having the same thing in the first place.

Neither Linux nor Windows is superior to the other.  People
making such representations generally know one much better
than the other and its more a reflection of their own experience
than anything else.  I personally have used both UNIX and
Windows since their inception and find that I tend to have a
slight preference for whatever I used last.  Technical merits of
one vs. the other are basically irrelevant for most purposes.

On 9/10/07, Patrick Connolly [EMAIL PROTECTED] wrote:
 On Mon, 10-Sep-2007 at 12:26PM -0400, Gabor Grothendieck wrote:

 | You want whatever all the people you are working with are using
 | to make it as easy as possible to work together with them.

 Assuming you're using R, there is negligible difficulty using a
 different OS from what your colleagues use (apart from the
 inconsistencies you get between different versions of Windows, but
 even that has little effect on R).  The standard .RData binary files
 work with Windows and Linux (and probably OS X).

 The only issue I come across is that Linux can't create WMF files as
 readily as Windows can, and that is more than made up for by the
 greater flexibility that Linux offers.  It's easier in Linux to
 produce Excel files from dataframes and matrices using a perl script
 posted to this list by Marc Schwartz.  Thanks again Marc.

 Best

 Patrick


 |
 | On 9/10/07, Wensui Liu [EMAIL PROTECTED] wrote:
 |  Good morning, everyone,
 |  I am sorry for this off-topic post but think I can get great answer
 |  from this list.
 |  My question is what is the best OS on PC (laptop) for statistical
 |  computing and why.
 |  I really appreciate your insight.
 |  Have a nice day.
 |
 | __
 | 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
 | and provide commented, minimal, self-contained, reproducible code.

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

 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Generating Replicate Datasets (using loops or other means)

2007-09-10 Thread Moshe Olshansky
Hi Jonathan,

What exactly do you mean by replication? 
Do you want to keep a1,b1,c1,... unchanged but have 30
different sets of random numbers?

Regards,

Moshe.

--- VTLT1999 [EMAIL PROTECTED] wrote:

 
 Hello All,
 
 I have searched many help forums, message boards,
 etc. and I just can't
 apply the comments to what I need my program to do. 
 I am running R 2.5.1 on
 an XP system, and my desire is to produce replicate
 datasets for a
 simulation study I am running.  Essentially, I have
 sets of parameters (a's,
 b's, and c's) that define a function which produces
 a decimal value.  This
 value is compared to a random uniform value, and is
 coded a 1 if the
 function is greater than the uniform value, 0 if it
 is = to the uniform
 value.  My code thus far works great, but I just
 need it to run several
 times.Here we go:
 
 library(mvtnorm)
 library(sm)
 library(ltm)
 library(irtoys)
 
 k- 5000
 set.seed(271828)
 t -

rmvnorm(n=k,mean=c(-1,0,1),sigma=matrix(c(1,.8,.5,.8,1,.8,.5,.8,1),3,3))
 
   #Using mv here because of the likely association
 of ability (theta = t)
 across time.
 
 t1-as.matrix(t[,1])
 t2-as.matrix(t[,2])
 t3-as.matrix(t[,3])
 
 set.seed(271828)
 
 #  Population item parameters (n=54)  from which we
 will select relevant
 items
 #  These are the parameters that are used in the
 function
 
 a - c(1.18120, 0.92613, 0.96886, 0.80503, 1.12384, 
0.84073, 0.85544, 0.86801, 1.01054, 0.82278,
1.10353, 0.78865, 0.98421, 1.76071, 0.89603, 
0.84671, 0.89737, 0.74775, 0.32190, 0.69730, 
0.72059, 1.16762, 1.29257, 1.32902, 0.59540, 
0.51022, 0.59259, 0.93951, 0.68568, 0.55649, 
0.88084, 0.52940, 0.45735, 0.57560, 1.11779,
0.96984, 1.19692, 0.99102, 1.25847, 1.62555, 
0.63049, 1.07807, 1.04897, 1.23138, 1.14014, 
1.25230, 1.14844, 0.59287, 0.83143, 0.81723,
0.52141, 0.61980, 0.49945, 1.02749)
 
 b - c(-2.51737, -1.95897, -1.72667, -0.82988,
 -0.36093,
 0.72554,  0.91442,  0.78061,  0.06088, 
 0.75733,
-0.76371,  0.24552, -0.42050,  0.88232,
 -0.81761,
 0.06466, -0.43866, -0.46042,  0.21636,
 -0.73147,
-1.44086, -1.03718,  0.07275, -0.17197, 
 1.53796,
-0.45631, -1.69826, -0.66506,  0.98921, 
 0.30714,
-0.62245,  0.97253,  1.95894,  0.21277, 
 1.96346,
 1.18825,  1.59917, -0.28401, -1.23530,
 -0.09671,
-0.31581, -0.66149, -0.81284, -0.35399,
 -0.07623, 
 1.06442, -0.68559,  1.07591,  0.97458, 
 0.06436,
 1.25622,  1.73954,  1.75052,  2.34088)
 
 c - c(0.0, 0.0, 0.0, 0.0, 0.19648,
0.31302, 0.26454, 0.19714, 0.06813, 0.21344,
0.0, 0.03371, 0.0, 0.16581, 0.11054, 
0.08756, 0.07115, 0.26892, 0.0, 0.06883, 
0.0, 0.14815, 0.32389, 0.19616, 0.17597,
0.0, 0.0, 0.04337, 0.19949, 0.20377, 
0.0, 0.06243, 0.13639, 0.0, 0.18166,
0.15996, 0.20184, 0.08331, 0.24453, 0.26114, 
0.16434, 0.20750, 0.32658, 0.31870, 0.45227,
0.35039, 0.31178, 0.17999, 0.22774, 0.21675,
0.10153, 0.17764, 0.15205, 0.19858)
 
 #  Item parameters for generating 3PL data for all
 five testing occasions:
 #  This selects the relevant parameters for a
 particular data generation run
 #  Only parameters for the first testing occasion
 are shown to save space
 
 a1 - as.matrix(a[c(1:5,15:20,22:24,38:44)])
 b1 - as.matrix(b[c(1:5,15:20,22:24,38:44)])
 c1 - as.matrix(c[c(1:5,15:20,22:24,38:44)])
 
 #  Here is where I would like to begin my
 replications, but don't know how
 to make R do it.
 #  The code below produces a matrix of 0's and 1's
 (which will be used by
 another program)
 #  I would like to nest this in a do loop such
 that, say, 30 replicate
 datasets are produced using the 
 #same parameters. 

N - nrow(t1) # number of examinees
n - nrow(a1) # number of items
d - 1.7
theta - t1  
response - matrix (0,N,n)  
uni - matrix (runif(N*n),nrow = N)
 
for (i in 1:N)
{
  for (j in 1:n) 
  {
   if (
 c1[j]+(1-c1[j])/(1+exp(-d*a1[j]*(theta[i]-b1[j]))) 
 uni[i,j] )
  response[i,j] = 1
else 
  response[i,j] = 0
  }
}
 write.table(response, file=C:/responses.dat, sep=
 ,row.names=FALSE,
 col.names=FALSE)  
 
 I tried earlier nesting this in another for loop,
 but that indexes elements
 of matrices and vectors, and doesn't seem to apply
 to a global loop
 methodology.  I am attempting to use replicate as we
 speak, but
 documentation is sparse (help(replicate) is nested
 in lapply information). 
 Any guidance is greatly appreciated.  
 
 Thanks in advance,
 
 Jonathan Beard
 
 -- 
 View this message in context:

http://www.nabble.com/Generating-Replicate-Datasets-%28using-loops-or-other-means%29-tf4418768.html#a12603580
 Sent from the R help mailing list archive at
 Nabble.com.
 
 __
 R-help@stat.math.ethz.ch mailing list
 

Re: [R] finding the minimum positive value of some data

2007-09-10 Thread Gabor Grothendieck
Here are some solutions each of which
1. has only one line,
2. x only occurs once so you can just plug in a complex expression
3. no temporary variables are left

min(sapply(x, function(z) if (z  0) z else Inf))

(function(z) min(ifelse(z  0, z, Inf))) (x)

with(list(z = x), min(z[z  0]))

local({ z - x; min(z[z  0]) })

On 9/10/07, dxc13 [EMAIL PROTECTED] wrote:

 useRs,

 I am looking to find the minimum positive value of some data I have.
 Currently, I am able to find the minimum of data after I apply some other
 functions to it:

  x
  [1]  1  0  1  2  3  3  4  5  5  5  6  7  8  8  9  9 10 10

  sort(x)
  [1]  0  1  1  2  3  3  4  5  5  5  6  7  8  8  9  9 10 10

  diff(sort(x))
  [1] 1 0 1 1 0 1 1 0 0 1 1 1 0 1 0 1 0

  min(diff(sort(x)))
 [1] 0

 The minimum is given as zero, which is clearly true, but I am interested in
 only the positive minimum, which is 1.  Can I find this by using only 1 line
 of code, like I have above? Thanks!

 dxc13
 --
 View this message in context: 
 http://www.nabble.com/finding-the-minimum-positive-value-of-some-data-tf4417250.html#a12599319
 Sent from the R help mailing list archive at Nabble.com.

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


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] what am I missing

2007-09-10 Thread Gabor Grothendieck
Its a FAQ:

http://hermes.sdu.dk/Rdoc/faq.html#Why%20does%20outer()%20behave%20strangely%20with%20my%20function%3f

On 9/10/07, Jan de Leeuw [EMAIL PROTECTED] wrote:
 x-seq(-1,1,length=10)
 y-seq(-1,1,length=10)
 a-matrix(c(1,2,2,1),2,2)
 b-matrix(c(2,1,1,2),2,2)

 fv-function(x,y) {
m-x*a+y*b
t-m[1,1]+m[2,2]; d-m[1,1]*m[2,2]-m[1,2]^2
return((t-sqrt(t^2-4*d))/2)
 }

 gv-function(x,y) {
t-x*(a[1,1]+a[2,2])+y*(b[1,1]+b[2,2])
d-(x*a[1,1]+y*b[1,1])*(x*a[2,2]+y*b[2,2])-(x*a[1,2]+y*b[1,2])^2
return((t-sqrt(t^2-4*d))/2)
 }


 now outer(x,y,gv) works as expected, outer(x,y,fv) bombs. But

 z-matrix(0,10,10); for (i in 1:10) for (j in 1:10) z[i,j]-fv(x[i],y
 [j])

 works fine. Must be something in outer().

 ==
 Jan de Leeuw, 11667 Steinhoff Rd, Frazier Park, CA 93225, 661-245-1725
 .mac: jdeleeuw ++  aim: deleeuwjan ++ skype: j_deleeuw
 homepages: http://www.cuddyvalley.org and http://gifi.stat.ucla.edu
 ==
A bath when you're born,
   a bath when you die,
how stupid.  (Issa 1763-1827)




[[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
 and provide commented, minimal, self-contained, reproducible code.


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] install packages automatically

2007-09-10 Thread Ross Darnell
Try

?update.packages

Ross Darnell

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Wensui Liu
Sent: Tuesday, 11 September 2007 11:45 AM
To: r-help@stat.math.ethz.ch
Subject: [R] install packages automatically

Dear Listers,
I am a little tired of installing all packages I want every time when
I instill a new version of R.
Say, if I have a list of packages I need to use, is it possible to
tell R to install them all for me automatically rather than I install
them one by one?
Thx.

__
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
and provide commented, minimal, self-contained, reproducible code.

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] overlay lattice histograms with goodness-of-fit pdfs

2007-09-10 Thread Brad Christoffersen

Mange tak!

FYI, this is the way it is able to run (I was going to attach
station.precip.R, but I read that attaching files is not recommended
- let me
know if you would like it)

x - dget(file=C://Documents and Settings/Bradley/My
Documents/Arizona/CourseResources/ATMO529/station.precip.R)
histogram(~ data | month * station, data = sta.stack,
subset = type==precip  month %in% c(Dec,Jan,Feb),
xlab = Precipitation (mm),
type = density,
panel = function(x, ...) {
panel.histogram(x, ...)
panel.mathdensity(dmath = dnorm, col = black,
args = list(mean = 
mean(sta.stack$data), sd = sd(sta.stack$data)))
panel.mathdensity(dmath = dgamma, col = black,
args = list(shape = 
(mean(sta.stack$data))^2 / (stdev(sta.stack$data))^2,
scale = 
(stdev(sta.stack$data))^2 / mean(sta.stack$data)))
})

Now, what would be great is to be able to reference the different calls to
panel.mathdensity() so that the corresponding probability * histogram area ( =
counts) in each bin can be used to compute a simple chi-square
goodness-of-fit.
 I tried calling panel.mathdensity() outside of histogram(), but I don't think
this is right - it returns NULL.  I also looked at chisq.test, but this
doesn't
support trellis formulas.  Any thoughts or leads?

Thanks,
Brad Christoffersen



Quoting Frede Aakmann Tøgersen [EMAIL PROTECTED]:


The following is one of the examples in the help page for histogram:

 histogram( ~ height | voice.part, data = singer,
   xlab = Height (inches), type = density,
   panel = function(x, ...) {
   panel.histogram(x, ...)
   panel.mathdensity(dmath = dnorm, col = black,
 args = list(mean=mean(x),sd=sd(x)))
   } )

This should give you some thing to start from.

Also using the subset argument of the lattice functions will make
make your code more readable. Instead of your code

histogram(~ data | month * station,
data = sta.stack[sta.stack[,type]==precip 
(sta.stack[,month]==Dec | sta.stack[,month]==Jan |
sta.stack[,month]==Feb),],
xlab = Precipitation (mm))

you can use (not tested because you didn't supply a reproducable example)

histogram(~ data | month * station, data = sta.stack
subset = type==precip  month %in% c(Dec, Jan, Feb),
xlab = Precipitation (mm))


Med venlig hilsen
Frede Aakmann Tøgersen





-Oprindelig meddelelse-
Fra: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] På vegne af Brad
Christoffersen
Sendt: 10. september 2007 12:08
Til: R-help@stat.math.ethz.ch
Emne: [R] overlay lattice histograms with goodness-of-fit pdfs

Hello,

I am new to R exploratory data analysis and plotting.  Is
anyone aware of a way to overlay a set of conditional
histograms with conditional PDFs?  Below, I generate a
lattice plot of precipitation histograms based on different
months and stations, given a subset of the dataset:


histogram(~ data | month * station,
data = sta.stack[sta.stack[,type]==precip 
(sta.stack[,month]==Dec | sta.stack[,month]==Jan |
sta.stack[,month]==Feb),],
xlab = Precipitation (mm))


I previously used a combination of the low-level 'lines()'
and 'dgamma()'
functions to overlay a gamma PDF onto a single histogram.
Now what I would like to do is to do the same thing, but with
a function that allows me to specify a formula similar to
that in the histogram function above

[SomeKindOfPDF] ~ [x-range] | month * station

which will plot the PDF with the appropriate factors (month
and station).

All I'm looking for is for someone to get me going in the
right direction with a useful package or function to use.

Any help is much appreciated!
Brad Christoffersen

__
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
and provide commented, minimal, self-contained, reproducible code.




__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] finding the minimum positive value of some data

2007-09-10 Thread Moshe Olshansky
Either
 min(diff(sort(x))[diff(sort(x))0])
or
 min(diff(sort(unique(x


--- dxc13 [EMAIL PROTECTED] wrote:

 
 useRs,
 
 I am looking to find the minimum positive value of
 some data I have. 
 Currently, I am able to find the minimum of data
 after I apply some other
 functions to it:
 
  x
  [1]  1  0  1  2  3  3  4  5  5  5  6  7  8  8  9  9
 10 10
 
  sort(x)
  [1]  0  1  1  2  3  3  4  5  5  5  6  7  8  8  9  9
 10 10
 
  diff(sort(x))
  [1] 1 0 1 1 0 1 1 0 0 1 1 1 0 1 0 1 0
 
  min(diff(sort(x)))
 [1] 0
 
 The minimum is given as zero, which is clearly true,
 but I am interested in
 only the positive minimum, which is 1.  Can I find
 this by using only 1 line
 of code, like I have above? Thanks!
 
 dxc13
 -- 
 View this message in context:

http://www.nabble.com/finding-the-minimum-positive-value-of-some-data-tf4417250.html#a12599319
 Sent from the R help mailing list archive at
 Nabble.com.
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained,
 reproducible code.


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] using bootstrap for tree selection step in rpart

2007-09-10 Thread Christian Schäfer
Fiona Callaghan wrote:
 I was wondering if someone could help me with an rpart problem.  I can see
 that cross-validation is the default for tree selection in rpart -- has a
 bootstrap method been implemented anywhere?  I think this is a different
 thing to 'bagging' or 'boosting' -- I still want 'one' tree at the end, I
 just would like it chosen using a bootstrap method.  Any ideas???

Hi Fiona,

I'm not sure if I understand you correctly.
To get one single rpart tree trained on one bootstrap sample, try 
bagging() from the 'ipred' package and set nbagg=1.

Bye,
Chris

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] artificial data matrix with 100000 rows

2007-09-09 Thread Paul Smith
On 9/9/07, kevinchang [EMAIL PROTECTED] wrote:
 I tried to made the matrix with this size by either matrix() or array().
 However, there seems to be default limit of number for rows made. I got sort
 of error message from R .To be specific,

 m--matrix(ncol=3,nrow=10)

 error message:[ reached getOption(max.print) -- omitted 7 rows ]]

 or

 a-array(dim=c(1,3,10))

 error message:reached getOption(max.print) -- omitted 6667 row(s) and 6
 matrix slice(s) ]

That is not an error message, I guess. When the matrices are huge, R
is unable to print them totally on the screen, but all data are
present. For instance,

 m[(nrow(m)-10):nrow(m),]
  [,1] [,2] [,3]
 [1,]   NA   NA   NA
 [2,]   NA   NA   NA
 [3,]   NA   NA   NA
 [4,]   NA   NA   NA
 [5,]   NA   NA   NA
 [6,]   NA   NA   NA
 [7,]   NA   NA   NA
 [8,]   NA   NA   NA
 [9,]   NA   NA   NA
[10,]   NA   NA   NA
[11,]   NA   NA   NA


See

?getOption

Paul

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem in installing packages on linux machine...

2007-09-09 Thread Carsten Jaeger
Your problem is not related to missing file permissions but to a problem
with the linker (ld). As you can see from the error message, ld cannot
find a compatible libR.so so compilation fails. You did not specify
which architecture you're on but in case it is a 64-bit platform, the
following thread might be helpful: 

http://tolstoy.newcastle.edu.au/R/e2/help/07/07/22071.html

BTW, the correct command for running R as root is su -c R or sudo R.
Furthermore, lib is optional and defaults to .libPaths()[1],
see ?install.packages

 tkobayas at indiana.edu writes:

 
 Hi,
 
 Still got the same error message. I did su R when I got the error 
 message for the first time. I have never seen this error message.
I 
 will be googling for solutions as well...
 
 Thank you.
 
 Quoting Henrique Dallazuanna wwwhsd at gmail.com:
 
  Hi, try install packages whit 'sudo'.
 
  $sudo R
 
  --
  Henrique Dallazuanna
  Curitiba-Paraná-Brasil
  25° 25' 40 S 49° 16' 22 O
 
  On 08/09/2007, tkobayas at indiana.edu tkobayas at indiana.edu
wrote:
 
  Hi,
 
  I am trying to install RSQLite package on my Fedora workstation. I
  tried to install other packages as well, but each time I got the
same
  error messages saying compilation error and non zero exit
status.
  Do I have to specify lib=? I never specified the library path
before
  when I was using Fedora Core 6.
 
 
  Warning in install.packages(RSQLite) : argument 'lib' is missing:
  using '/usr/lib/R/library'
  --- Please select a CRAN mirror for use in this session ---
  Loading Tcl/Tk interface ... done
  trying URL
'http://cran.cnr.Berkeley.edu/src/contrib/RSQLite_0.5-6.tar.gz'
  Content type 'application/x-gzip' length 710241 bytes
  opened URL
  ==
  downloaded 693Kb
 
  gcc -std=gnu99 -shared -L/usr/local/lib -o RSQLite.so RS-DBI.o
  RS-SQLite.o sqlite-all.o   -L/usr/lib/R/lib -lR
  /usr/bin/ld: skipping incompatible /usr/lib/R/lib/libR.so when
  searching for -lR
  /usr/bin/ld: cannot find -lR
  collect2: ld returned 1 exit status
  make: *** [RSQLite.so] Error 1
  chmod: cannot access `/usr/lib/R/library/RSQLite/libs/*': No such
file
  or directory
  ERROR: compilation failed for package 'RSQLite'
  ** Removing '/usr/lib/R/library/RSQLite'
 
  The downloaded packages are in
  /tmp/RtmpHQ5Y7C/downloaded_packages
  Warning message:
  installation of package 'RSQLite' had non-zero exit status in:
  install.packages(RSQLite)
 
  I appreciate your help.
 
  Thank you very much
 
  Taka
 
  __
  R-help at 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
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 
 Takatsugu Kobayashi
 PhD Student
 Indiana University, Dept. Geography
 
 __
 R-help at 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
 and provide commented, minimal, self-contained, reproducible code.
 


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] What does it mean by initial value not available?

2007-09-09 Thread Duncan Murdoch
On 09/09/2007 7:01 AM, Yuchen Luo wrote:
 Dear friends.
 I use ConstrOptim( ) and got error message initial value not available.
 My understanding of initial value not available is that one of the
 following 3 cases happens:
 
 1.The objective function is not well defined at the point of the initial
 value.
 2. The differentiation of the objective function is not well defined at the
 point of the initial value.
 3. The initial value violate the constrain of ui %*% theta - ci = 0
 
 But my situation does not belong to any of the above cases.
 
 I have attached my code bellow and could you please help me take a look?

I haven't tried your code, but there's one obvious error:
...
 fit.error=function(rec,lambda,lbar)
 {sum((eval(apple)*1000-orange)^2/(orange^2))
 }

The function optimizes over the elements of the first parameter.  You've 
got two other parameters there, and I think you're trying to optimize 
over them as well.  Put them all into one vector.

The documentation for constrOptim doesn't make this as clear as it 
should; I'll clarify (by copying the docs from ?optim).

Duncan Murdoch

 
 
 fit.error.grr=function(rec,lambda, lbar)
 {drec=sum(eval(D(apple,'rec'))*(eval(apple)*1000-orange)/(orange^2))
 dlambda=sum(eval(D(apple,'lambda'))*(eval(apple)*1000-orange)/(orange^2))
 dlbar=sum(eval(D(apple,'lbar'))*(eval(apple)*1000-orange)/(orange^2))
 c(drec,dlambda,dlbar)
 }
 
 
 rr=c(4.33,4.22,4.27,4.43,4.43,4.44,4.45,4.65,4.77,4.77)
 tot=rep(13319.17,10)
 sh=rep(1553656,10)
 sigmae=c(0.172239074,0.188209271,0.193703774,0.172659891,0.164427247,
 0.24602361,0.173555309,0.186701165,0.193150456)
 ss=c(56.49,56.39,56.55,57.49,57.37,55.02,56.02,54.35,54.09)
 orange=rep(21.25,10)
 
 constrOptim(c(0.5,0.3,0.5), fit.error, fit.error.grr, ui=ui,ci=ci)
 
   [[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
 and provide commented, minimal, self-contained, reproducible code.

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sweave figure aspect ratio

2007-09-09 Thread Duncan Murdoch
On 09/09/2007 7:24 AM, Werner Wernersen wrote:
 Hello,
 
 using Sweave, is there any option to preserve the
 original aspect ratio of plots generated from R code?
 
 Consider this Sweave chunk:
 test,echo=F,fig=T,width=2,height=2=
 x - 1:10
 y - sin(x)
 par(mar=c(4,4,0,4))
 plot(x,y,
  xlab=x label,
  ylab=y label
  )
 @
 
 In Latex, I want to produce a plot of width 2 but
 don't care about the height. If I put the width and
 height like shown on the example, the box isn't square
 any more. But if I put only width or height in the
 Sweave option, then the values then the appearance is
 totally off. 
 
 Is there any option for Sweave or other possibility to
 preserve the ratio of the sides of plots?

The width and height args in the header of the chunk are passed to the 
graphics device (postscript or pdf), but they don't appear in the LaTeX 
output.  To modify the appearance in LaTeX, you need to set a graphicx 
package parameter, e.g. something like

\setkeys{Gin}{width=2in}
test,echo=F,fig=T=
x - 1:10
y - sin(x)
par(mar=c(4,4,0,4))
plot(x,y,
  xlab=x label,
  ylab=y label
  )
@

If you only specify width, then the aspect ratio will be maintained.

The \setkeys{} changes are persistent; as far as I know there's no way 
to say go back to the default afterwards.  So what I'd suggest is to 
define a macro (e.g. \Gwidth) to give the default width, and then call

\setkeys{Gin}{width=\Gwidth}

at the start of your document and after any change like the one above.

Duncan Murdoch

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


Re: [R] stacking data frames with different variables

2007-09-09 Thread hadley wickham
Have a look at rbind.fill in the reshape package.

Hadley

On 9/9/07, Muenchen, Robert A (Bob) [EMAIL PROTECTED] wrote:
 Hi All,

 If I need to stack two data frames, I can use rbind, but it requires
 that all variables exist in both sets. I can make that happen, but other
 stat packages would figure out where the differences were, add the
 missing variables to each, set their values to missing and stack them.
 Is there a more automatic way to do that in R?

 Below is an example program.

 Thanks,
 Bob

 # Top data frame has two variables.
 x - c(1,2)
 y - c(1,2)

 top - data.frame(x,y)
 top

 # Bottom data frame has only one of them.
 x - c(3,4)
 bottom - data.frame(x)
 bottom

 # So rbind won't work.
 rbind(top, bottom)

 # After figuring out where the mismatches are I can
 # make the two DFs the same manually.
 bottom - data.frame( bottom, y=NA)
 bottom

 # Now I get the desired result.
 both - rbind(top,bottom)
 both

 =
 Bob Muenchen (pronounced Min'-chen), Manager
 Statistical Consulting Center
 U of TN Office of Information Technology
 200 Stokely Management Center, Knoxville, TN 37996-0520
 Voice: (865) 974-5230
 FAX: (865) 974-4810
 Email: [EMAIL PROTECTED]
 Web: http://oit.utk.edu/scc,
 News: http://listserv.utk.edu/archives/statnews.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
 and provide commented, minimal, self-contained, reproducible code.



-- 
http://had.co.nz/

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] stacking data frames with different variables

2007-09-09 Thread Muenchen, Robert A (Bob)
Perfect. Thanks Hadley!


 -Original Message-
 From: hadley wickham [mailto:[EMAIL PROTECTED]
 Sent: Sunday, September 09, 2007 10:11 AM
 To: Muenchen, Robert A (Bob)
 Cc: r-help@stat.math.ethz.ch
 Subject: Re: [R] stacking data frames with different variables
 
 Have a look at rbind.fill in the reshape package.
 
 Hadley
 
 On 9/9/07, Muenchen, Robert A (Bob) [EMAIL PROTECTED] wrote:
  Hi All,
 
  If I need to stack two data frames, I can use rbind, but it requires
  that all variables exist in both sets. I can make that happen, but
 other
  stat packages would figure out where the differences were, add the
  missing variables to each, set their values to missing and stack
 them.
  Is there a more automatic way to do that in R?
 
  Below is an example program.
 
  Thanks,
  Bob
 
  # Top data frame has two variables.
  x - c(1,2)
  y - c(1,2)
 
  top - data.frame(x,y)
  top
 
  # Bottom data frame has only one of them.
  x - c(3,4)
  bottom - data.frame(x)
  bottom
 
  # So rbind won't work.
  rbind(top, bottom)
 
  # After figuring out where the mismatches are I can
  # make the two DFs the same manually.
  bottom - data.frame( bottom, y=NA)
  bottom
 
  # Now I get the desired result.
  both - rbind(top,bottom)
  both
 
  =
  Bob Muenchen (pronounced Min'-chen), Manager
  Statistical Consulting Center
  U of TN Office of Information Technology
  200 Stokely Management Center, Knoxville, TN 37996-0520
  Voice: (865) 974-5230
  FAX: (865) 974-4810
  Email: [EMAIL PROTECTED]
  Web: http://oit.utk.edu/scc,
  News: http://listserv.utk.edu/archives/statnews.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
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 --
 http://had.co.nz/

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] confusion matrix - better code?

2007-09-09 Thread Monica Pisica

Wolfgang,
 
This looks great and certainly puts to shame my code .
 
Thanks,
 
Monica
 
 Date: Fri, 7 Sep 2007 21:04:32 +0100 From: [EMAIL PROTECTED] To: [EMAIL 
 PROTECTED] CC: r-help@stat.math.ethz.ch Subject: Re: [R] confusion matrix - 
 better code?  Dear Monica,  try this:  cm = table(tr, pr) cm pr tr 1 
 2 3 1 2 1 0 2 2 1 0 3 0 0 3 4 0 1 0   rowSums(cm) colSums(cm)  Best 
 wishes Wolfgang Huber  Monica Pisica ha scritto:  Hi,I�ve 
 written some code to obtain a confusion matrix when the true classification 
 and the predicted classification are known. Suppose true classification is 
 called �tr� and predicted classification is �pr�. I have 4 classes in 
 tr, but only 3 classes out of 4 are predicted in �pr�. Following is my 
 code, but looks quite �clunky� to me. I wonder if you have any 
 suggestions to improve it.Thanks,Monica
 -tr - c(1,2,2,3,3,3,2,4,1,1)  
 pr-c(1,2,1,3,3,3,1,2,1,2)  dat - data.frame(tr, pr)  class - 
 c(1:length(tr))  m - max(c(length(unique(tr)), length(unique(pr  
 for(i in 1:length(class)) {  class[i] - sub(' 
 ','',paste(dat[i,1],dat[i,2])) }  dat - data.frame(dat, class)  mat - 
 matrix(0, nrow=m, ncol=m)  for (i in 1:m){  for (j in 1:m){  mat[i,j] 
 - sub(' ','',paste(i,j))  }}  cat - matrix(0, nrow=(m+1), ncol=(m+1)) 
  for (i in 1:m){  for(j in 1:m){  cat[i,j]- 
 nrow(dat[dat$class==mat[i,j],])  }}  for (i in 1:m){  
 cat[(m+1),i]-sum(cat[1:m,i])  cat[i,(m+1)]- sum(cat[i,1:m])  
 cat[(m+1),(m+1)] - sum(cat[1:m,(m+1)])  }  cat  [,1] [,2] [,3] [,4] 
 [,5]  [1,] 2 1 0 0 3  [2,] 2 1 0 0 3  [3,] 0 0 3 0 3  [4,] 0 1 0 0 1 
  [5,] 4 3 3 0 10The 5th row / col represents the sum on each row / 
 col respectively.
_
Gear up for Halo® 3 with free downloads and an exclusive offer. It’s our way 
of saying thanks for using Windows Live™.
http://gethalo3gear.com?ocid=SeptemberWLHalo3_WLHMTxt_2
[[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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] loop execution problem

2007-09-09 Thread Duncan Murdoch
On 09/09/2007 1:36 PM, kevinchang wrote:
 This is  bizzare. The for loop I set seems to go infinitly  because the
 hourglass cursor never disappers and I never get the result. But when I
 click on X of the window try to exit R, the execution finishes right after
 I abort exiting when RGui asks me to save the workplace or not.  Please help
 me out.

In Windows you can also abort execution by hitting Esc, or the menu 
entry Misc|Stop current computation.

Duncan Murdoch

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


Re: [R] fitdistr()

2007-09-09 Thread jim holtman
I assume that you want to do the fitdistr on one of the columns of the
dataframe that you have read in. What does 'str(ONES3)' show?  If the
data is in the first column, try:

fitdistr(ONES3[[1]],chi-squared)


On 9/9/07, Terence Broderick [EMAIL PROTECTED] wrote:
 I am trying to fit the chi-squared distribution to a set of data using the 
 fitdistr function found in the MASS4 library, the data set is called ONES3, I 
 have loaded it using the command

  ONES3-read.table(ONES3.pdf,header=TRUE,na=NA)

  I print out the dataset ONES3 to the screen to make sure it has loaded

  Then I try to fit this data using the command fitdistr

   fitdistr(ONES3,chi-squared)

  and it returns the comment

  Error in fitdistr(ONES3, chi-squared) : 'x' must be a non-empty numeric 
 vector

  Can anybody help with this, I imagine it is a common mistake for beginners 
 like myself



 audaces fortuna iuvat

 -

[[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
 and provide commented, minimal, self-contained, reproducible code.



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

What is the problem you are trying to solve?

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] What does it mean by initial value not available?

2007-09-09 Thread Yuchen Luo
Dear Professor Mordoch.
Thank you very much for your help! Your time is highly appreciated!
I do intend to optimize over 3 parameters and the way I did it is
constrOptim(c(0.5,0.3,0.5), fit.error, fit.error.grr, ui=ui,ci=ci).

Also, There is a missing value for both sigmae and ss. (The last 3rd
and 4th line) Please correct them as:
sigmae=c(0.172239074,0.188209271,0.193703774,0.172659891,0.164427247,0.24602361,0.173555309,0.186701165,0.193150456,
0.1857315601)
ss=c(56.49,56.39,56.55,57.49 ,57.37,55.02,56.02,54.35,54.09,54.67)

Best Wishes
Yuchen Luo
 On 9/9/07, Duncan Murdoch [EMAIL PROTECTED] wrote:
  On 09/09/2007 7:01 AM, Yuchen Luo wrote:
   Dear friends.
   I use ConstrOptim( ) and got error message initial value not
 available.
   My understanding of initial value not available is that one of the
   following 3 cases happens:
  
   1.The objective function is not well defined at the point of the initial
   value.
   2. The differentiation of the objective function is not well defined at
  the
   point of the initial value.
   3. The initial value violate the constrain of ui %*% theta - ci = 0
  
   But my situation does not belong to any of the above cases.
  
   I have attached my code bellow and could you please help me take a look?
 
  I haven't tried your code, but there's one obvious error:
  ...
   fit.error=function(rec,lambda,lbar)
   {sum((eval(apple)*1000-orange)^2/(orange^2))
   }
 
  The function optimizes over the elements of the first parameter.  You've
  got two other parameters there, and I think you're trying to optimize
  over them as well.  Put them all into one vector.
 
  The documentation for constrOptim doesn't make this as clear as it
  should; I'll clarify (by copying the docs from ?optim).
 
  Duncan Murdoch
 
  
  
   fit.error.grr=function(rec,lambda, lbar)
   {drec=sum(eval(D(apple,'rec'))*(eval(apple)*1000-orange)/(orange^2))
  
 dlambda=sum(eval(D(apple,'lambda'))*(eval(apple)*1000-orange)/(orange^2))
   dlbar=sum(eval(D(apple,'lbar'))*(eval(apple)*1000-orange)/(orange^2))
   c(drec,dlambda,dlbar)
   }
  
  
   rr=c(4.33,4.22,4.27,4.43,4.43,4.44,4.45,4.65,4.77,4.77)
   tot=rep(13319.17,10)
   sh=rep(1553656,10)
   sigmae=c(0.172239074,0.188209271,0.193703774,0.172659891,0.164427247,
   0.24602361,0.173555309,0.186701165,0.193150456)
   ss=c(56.49,56.39,56.55,57.49,57.37,55.02,56.02,54.35,54.09)
   orange=rep(21.25,10)
  
   constrOptim(c(0.5,0.3,0.5), fit.error, fit.error.grr, ui=ui,ci=ci)
  
 [[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
   and provide commented, minimal, self-contained, reproducible code.
 
 


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sweave figure aspect ratio

2007-09-09 Thread Werner Wernersen
Many thanks for the quick reply, Duncan.

Now I see that something is going wrong in R already.
I overlooked this because the R window was so big. I
have to persuade plotViewport() not to create a square
area but one which takes the different margins into
account.

Best regards,
  Werner

--- Duncan Murdoch [EMAIL PROTECTED] schrieb:

 On 09/09/2007 7:24 AM, Werner Wernersen wrote:
  Hello,
  
  using Sweave, is there any option to preserve the
  original aspect ratio of plots generated from R
 code?
  
  Consider this Sweave chunk:
  test,echo=F,fig=T,width=2,height=2=
  x - 1:10
  y - sin(x)
  par(mar=c(4,4,0,4))
  plot(x,y,
   xlab=x label,
   ylab=y label
   )
  @
  
  In Latex, I want to produce a plot of width 2 but
  don't care about the height. If I put the width
 and
  height like shown on the example, the box isn't
 square
  any more. But if I put only width or height in the
  Sweave option, then the values then the appearance
 is
  totally off. 
  
  Is there any option for Sweave or other
 possibility to
  preserve the ratio of the sides of plots?
 
 The width and height args in the header of the chunk
 are passed to the 
 graphics device (postscript or pdf), but they don't
 appear in the LaTeX 
 output.  To modify the appearance in LaTeX, you need
 to set a graphicx 
 package parameter, e.g. something like
 
 \setkeys{Gin}{width=2in}
 test,echo=F,fig=T=
 x - 1:10
 y - sin(x)
 par(mar=c(4,4,0,4))
 plot(x,y,
   xlab=x label,
   ylab=y label
   )
 @
 
 If you only specify width, then the aspect ratio
 will be maintained.
 
 The \setkeys{} changes are persistent; as far as I
 know there's no way 
 to say go back to the default afterwards.  So what
 I'd suggest is to 
 define a macro (e.g. \Gwidth) to give the default
 width, and then call
 
 \setkeys{Gin}{width=\Gwidth}
 
 at the start of your document and after any change
 like the one above.
 
 Duncan Murdoch


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


Re: [R] NA in AR model residuals

2007-09-09 Thread Nick Chorley
Thanks all!

On 09/09/2007, Nick Chorley [EMAIL PROTECTED] wrote:

 Hi,

 This may be a stupid question, but why when creating an AR model, why does
 R set the first n components of the ar object's resid vector to NA (where n
 is the order of the model)?

 Regards,

 NC


[[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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] SQL like function?

2007-09-08 Thread Takatsugu Kobayashi
Hi Gabor,

Wow, this is awesome although I eventually should learn MySQL for 
integrating it on web-based DB management using PHP or Perl, this is a 
very helpful tool for me to start with!

Thank you very much

Gabor Grothendieck wrote:
 Others have already pointed out %in% but regarding your comment about
 SQL, you can use SQL to manipulate R data frames using the sqldf package
 which provides an interface to lower level RSQLite (and RMySQL in the future)
 routines.  The following examples use SQLite underneath:

 DF - data.frame(observation = c(1,2,3,4,5))
 ID - data.frame(ID = c(1, 3, 4))

 library(sqldf)
 sqldf(select observation, observation in (select * from ID) `ID?` from DF)

 # or

 sqldf(select observation, observation in (1, 3, 4) `ID?` from DF)

 See home page at:

 http://sqldf.googlecode.com


 On 9/7/07, Takatsugu Kobayashi [EMAIL PROTECTED] wrote:
   
 Hi RUsers,

 I am wonder if I can search observations whose IDs matches any of the
 values in another vector, such as in MySQL. While I am learing MySQL for
 future database management, I appreciate if anyone could give me a hint.

 Suppose I have one 5*1 vector containing observation IDs and
 frequencies, and one 3*1 vector containing observation IDs.

 observation-c(1,2,3,4,5)
 ID-c(1,3,4)

 Then, I would like to program a code that returns a results showing
 matched observations like

 result: TRUE FALSE TRUE TRUE FALSE

 I am reading S programming, but I cannot find a way to do this.

 Thank you very much.

 Taka

 __
 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
 and provide commented, minimal, self-contained, reproducible code.



__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] SQL like function?

2007-09-08 Thread Gabor Grothendieck
Great.  Regarding the web, note that there are actually quite a few R
web projects as well:

http://www.lmbe.seu.edu.cn/CRAN/doc/FAQ/R-FAQ.html#R-Web-Interfaces

I have used rpad (www.rpad.org) which has an integrated web server right
in the R package making setup a non-issue.

On 9/8/07, Takatsugu Kobayashi [EMAIL PROTECTED] wrote:
 Hi Gabor,

 Wow, this is awesome although I eventually should learn MySQL for
 integrating it on web-based DB management using PHP or Perl, this is a
 very helpful tool for me to start with!

 Thank you very much

 Gabor Grothendieck wrote:
  Others have already pointed out %in% but regarding your comment about
  SQL, you can use SQL to manipulate R data frames using the sqldf package
  which provides an interface to lower level RSQLite (and RMySQL in the 
  future)
  routines.  The following examples use SQLite underneath:
 
  DF - data.frame(observation = c(1,2,3,4,5))
  ID - data.frame(ID = c(1, 3, 4))
 
  library(sqldf)
  sqldf(select observation, observation in (select * from ID) `ID?` from DF)
 
  # or
 
  sqldf(select observation, observation in (1, 3, 4) `ID?` from DF)
 
  See home page at:
 
  http://sqldf.googlecode.com
 
 
  On 9/7/07, Takatsugu Kobayashi [EMAIL PROTECTED] wrote:
 
  Hi RUsers,
 
  I am wonder if I can search observations whose IDs matches any of the
  values in another vector, such as in MySQL. While I am learing MySQL for
  future database management, I appreciate if anyone could give me a hint.
 
  Suppose I have one 5*1 vector containing observation IDs and
  frequencies, and one 3*1 vector containing observation IDs.
 
  observation-c(1,2,3,4,5)
  ID-c(1,3,4)
 
  Then, I would like to program a code that returns a results showing
  matched observations like
 
  result: TRUE FALSE TRUE TRUE FALSE
 
  I am reading S programming, but I cannot find a way to do this.
 
  Thank you very much.
 
  Taka
 
  __
  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
  and provide commented, minimal, self-contained, reproducible code.
 
 



__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Lisp-like primitives in R

2007-09-08 Thread Peter Dalgaard
François Pinard wrote:
 [Roland Rau]
   
 [François Pinard]
 

   
 I wonder what happened, for R to hide the underlying Scheme so fully, 
 at least at the level of the surface language (despite there are 
 hints).  
   

   
 To further foster portability, we chose to write R in ANSI C
 

 Yes, of course.  Scheme is also (often) implemented in C.  I meant that 
 R might have implemented a Scheme engine (or part of a Scheme engine, 
 extended with appropriate data types) with a surface language (nearly 
 the S language) which is purposely not Scheme, but could have been.

 If the gap is not extreme, one could dare dreaming that the Scheme 
 engine in R be completed, and Scheme offered as an alternate extension 
 language.  If you allow me to continue dreaming awake -- they told me 
 they will let me free as long as I do not get dangerous! :-) -- part 
 of the interest lies in the fact there are excellent Scheme compilers.  
 If we could only find or devise some kind of marriage between a mature 
 Scheme and R, so to speed up the non-vectorisable parts of R scripts...

   
Well, depending on what you want, this is either trivial or 
impossible... The internal storage of R is still pretty much equivalent 
to scheme. E.g. try this:

  r2scheme - function(e) if (!is.recursive(e))
  deparse(e) else c((, unlist(lapply(as.list(e), r2scheme)), ))
  paste(r2scheme(quote(for(i in 1:4)print(i))), collapse= )
[1] ( for i ( : 1 4 ) ( print i ) )

and a parser that parses a similar language to R internal format is  not 
a very hard exercise (some care needed in places). However, replacing 
the front-end is not going to make anything faster, and the evaluation 
engine in R does a couple of tricks which are not done in Scheme, 
notably lazy evaluation, and other forms of non-local evaluation, which 
drives optimizers crazy. Look up the writings of Luke Tierney on the 
matter to learn more.

 If we are lucky and one of the original authors reads this thread they 
 might explain the situation further and better [...].
 

 In r-devel, maybe!  We would be lucky if the authors really had time to 
 read r-help. :-)

   


-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Plotting lines to sets of points

2007-09-08 Thread Jim Price

# Create a matrix of ball locations
# You'd do this using the calls within your points function
balls - matrix(c(0,50,25,-150,-100,-50), ncol=2, byrow=F)


# Draw a line from the origin to each ball location
apply(balls, 1, function(x) lines(c(125, x[1]), c(-210, x[2]), col='red'))



A more complete example might loop over all the unique elements of
framename$hit_traj, and then run this procedure for each value with a
different colour, plotting both ball points and trajectories.



lawnboy34 wrote:
 
 I am using R to plot baseball spray charts from play-by-play data. I have
 used the following command to plot the diamond:
 
 plot (0:250, -250:0, type=n, bg=white)
   lines(c(125,150,125,100,125),c(-210,-180,-150,-180,-210), 
 col=c(black))
 
 I have also plotted different hit locations using commands such as the
 following:
 
 points(subset(framename$hit_x, framename$hit_traj==line_drive),
 subset(-framename$hit_y, framename$hit_traj==line_drive), pch=20,
 col=c(red))
 
 My question: Is there any easy way to plot a line from the origin (home
 plate) to each point on the graph? Preferably the line would share the
 same color as the dot that denotes where the ball landed. I have tried
 searching Google and these forums, and most graphing questions have to do
 with scatterplots or other varieties of graphs I am not using. Thanks very
 much in advance.
 
 -Jason
 

-- 
View this message in context: 
http://www.nabble.com/Plotting-lines-to-sets-of-points-tf4404235.html#a12564959
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] enable object name to be called as object (a dataset)

2007-09-08 Thread Jim Price

a - 1:3
b - 11:13
c - 21:23

names - c('a','b','c')

do.call(data.frame, list(sapply(names, function(x) get(x



runner wrote:
 
 What I am trying to do is as follows:
 
 - I have listed names of all wanted objects (datasets A,B,C... ) in
 current workspace as a vector: 
 
 obj - c('A','B','C')
 
 - then i need to use these objects, say to extract all the 1st columns and
 bind to an existing dataset ('data'): 
  
 for ( i in 1:3){
 newdata - obj[i] 
 data - cbind(data,newdata [[1]] )
 }
 
 Obviously, it doesn't work since obj[i] is just a string of dataset name.
 Here is my question: how to call it as a original dataset? Thanks.
 

-- 
View this message in context: 
http://www.nabble.com/enable-object-name-to-be-called-as-object-%28a-dataset%29-tf4403933.html#a12564175
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] FW: variable format

2007-09-08 Thread Martin Becker
Frank E Harrell Jr wrote:
 Martin Becker wrote:
 Dear Cory,

 I am not familiar with SAS, but is this what you are looking for?

 divisionTable - matrix(c(1, New England,
   2, Middle Atlantic,
   3, East North Central,
   4, West North Central,
   5, South Atlantic,
   6, East South Central,
   7, West South Central,
   8, Mountain,
   9, Pacific),
 ncol=2, byrow=T)

 How about just divisionTable - c('New England', 'Middle Atlantic', 
 ...) then factor(old, 1:9, divisionTable) ?

 Frank


Of course, this solution is more elegant, but my intention was
1. to provide a solution which makes use of the exisiting object 
divisionTable
2. to reproduce the output from the working example (-conversion to 
character)
Maybe I should have emphasized that I was quoting the existing 
definition of divisionTable from the original email (for the sake of 
providing self-contained code) and not introducing a unnecessarily 
complicated new definition of divisionTable.

Regards,

 Martin

 a - NULL
 a$divisionOld - c(0,1,2,3,4,5)
 a$divisionNew - 
 as.character(factor(a$divisionOld,levels=divisionTable[,1],labels=divisionTable[,2]))
  

 a$divisionNew

 [1] NA   New EnglandMiddle Atlantic  [4] 
 East North Central West North Central South Atlantic

 Kind regards,

   Martin


 Cory Nissen schrieb:
 
 Anybody? 

 

 From: Cory Nissen
 Sent: Tue 9/4/2007 9:30 AM
 To: r-help@stat.math.ethz.ch
 Subject: variable format


 Okay, I want to do something similar to SAS proc format.

 I usually do this...

 a - NULL
 a$divisionOld - c(1,2,3,4,5)
 divisionTable - matrix(c(1, New England,
   2, Middle Atlantic,
   3, East North Central,
   4, West North Central,
   5, South Atlantic),
 ncol=2, byrow=T)
 a$divisionNew[match(a$divisionOld, divisionTable[,1])] - 
 divisionTable[,2]

 But how do I handle the case where...
 a$divisionOld - c(0,1,2,3,4,5)   #no format available for 0, this 
 throws an error.
 OR
 divisionTable - matrix(c(1, New England,
   2, Middle Atlantic,
   3, East North Central,
   4, West North Central,
   5, South Atlantic,
   6, East South Central,
   7, West South Central,
   8, Mountain,
   9, Pacific),
 ncol=2, byrow=T)   There are extra formats 
 available... this throws a warning.

 Thanks

 Cory

 [[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
 and provide commented, minimal, self-contained, reproducible code.


 __
 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
 and provide commented, minimal, self-contained, reproducible code.




__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Matlab's lsqnonlin

2007-09-08 Thread Martin Maechler
 KateM == Katharine Mullen [EMAIL PROTECTED]
 on Fri, 7 Sep 2007 20:07:41 +0200 (CEST) writes:

KateM The thread you linked to regarding Levenberg-Marquardt's supposed 
lack of
KateM availability is from 2001; it has been possible to get
KateM to the MINPACK implementation of Levenberg-Marquardt within R via the
KateM package minpack.lm
KateM (http://cran.r-project.org/src/contrib/Descriptions/minpack.lm.html) 
since
KateM 2005.

Thanks a lot, Kate.

I'm wondering about experiences:
Do you know of cases where  minpack.lm's  nls.lm() solved a
(real) problem that nls() would have a problem with ?

Beware however -- one of the main things I learned about this
field from Doug Bates, co-author of Bates_and_Watts and
prinicipal author of S's and R's nls() :
It's a *feature* that nls() does not converge sometimes when
other methods do falsely claim convergence!

Martin Maechler, ETH Zurich

KateM 
KateM Katharine Mullen
KateM mail: Department of Physics and Astronomy, Faculty of Sciences
KateM Vrije Universiteit Amsterdam, de Boelelaan 1081
KateM 1081 HV Amsterdam, The Netherlands
KateM room: T.1.06
KateM tel: +31 205987870
KateM fax: +31 205987992
KateM e-mail: [EMAIL PROTECTED]
KateM homepage: http://www.nat.vu.nl/~kate/


KateM On Fri, 7 Sep 2007, Jose Luis Aznarte M. wrote:

 Hi! I'm translating some code from Matlab to R and I found a problem.
 I need to translate Matlab's function 'lsqnonlin'
 (http://www-ccs.ucsd.edu/matlab/toolbox/optim/lsqnonlin.html) into R,
 and at the beginning I  thought it would be the same as R's 'optim'. But
 then I looked at the definition of 'lsqnonlin' and I don't quite see how
 to make 'optim' to do the same thing. Does anyone have an idea?
 This is apart from the fact that I would like to use the Levenberg
 Marquardt algorithm which is not implemented in R (some discussion about
 this: http://tolstoy.newcastle.edu.au/R/help/00b/2492.html).
 Thank you! All the best,
 
 
 --  --
 Jose Luis Aznarte M.   http://decsai.ugr.es/~jlaznarte
 Department of Computer Science and Artificial Intelligence
 Universidad de Granada   Tel. +34 - 958 - 24 04 67
 GRANADA (Spain)  Fax: +34 - 958 - 24 00 79
 
 __
 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
 and provide commented, minimal, self-contained, reproducible code.
 

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

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] argument 'lib' is missing: using '/usr/lib/R/library'

2007-09-08 Thread Gabor Csardi
Paul, what is the question? If the question is why you get this 
warning message, the reason is that the 'lib' argument is missing
and install.packages is using '/usr/lib/R/library'.

If you want to get rid of the warning supply the 'lib' argument.

Gabor

On Sat, Sep 08, 2007 at 11:26:44AM +0100, Paul Smith wrote:
 Dear All,
 
 When installing packages, I get the following warning:
 
  install.packages(sqldf)
 Warning in install.packages(sqldf) : argument 'lib' is missing:
 using '/usr/lib/R/library'
 
 Any ideas?
 
 The details of my R installation are:
 
  version
_
 platform   i386-redhat-linux-gnu
 arch   i386
 os linux-gnu
 system i386, linux-gnu
 status
 major  2
 minor  5.1
 year   2007
 month  06
 day27
 svn rev42083
 language   R
 version.string R version 2.5.1 (2007-06-27)
 
 
 R is here installed on Fedora 7.
 
 Thanks in advance,
 
 Paul
 
 __
 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
 and provide commented, minimal, self-contained, reproducible code.

-- 
Csardi Gabor [EMAIL PROTECTED]MTA RMKI, ELTE TTK

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R survey package again

2007-09-08 Thread James Reilly

On 7/9/07 11:42 PM, eugen pircalabelu wrote:
I have a sample from a survey where household were interviewed. The 
sample has 4 criteria on which the stratification was based: REGION, 
SIZE OF HOUSEHOLD, SIZE OF LOCALITY, AGE OF HEAD OF HOUSEHOLD. Since i 
don't have the whole information in each cell of the cross 
region*sizehh*sizeloc*age i can't use the postStratify function from 
Survey package. Is that correct? (I think so but i need a competent answer)
 
The only additional info that i have is the size of a cell from a 
2*2 crossing (eg: I know the population size for all the strata defined 
by region*sizehh, region*sizeloc, sizeloc*age) so i have the 
behaviour of the population but in a 2 by 2 cross for each of these 
criteria.


You're right, poststratification can't work from two-way marginal 
distributions, but raking or calibration can.

However it seems odd that you only have this much information, since the 
full joint distribution would have been needed for stratification. 
Usually these details would be documented as part of the sample design. 
Can you get this information from those responsible for the sample 
design? It would also be good to check your understanding of the design. 
A sampling frame listing details of household size and age of household 
head would have been needed to do the four-way stratification you 
mention, but in my experience such frames aren't very common.

James
-- 
James Reilly
Department of Statistics, University of Auckland
Private Bag 92019, Auckland, New Zealand

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Matlab's lsqnonlin

2007-09-08 Thread Katharine Mullen

 I'm wondering about experiences:
 Do you know of cases where  minpack.lm's  nls.lm() solved a
 (real) problem that nls() would have a problem with ?


In short, no.  However, I looked at this question in the limited context
of fitting the parameters of a linear superposition of 2 exponentials with
Gaussian noise.  A simulation study showed nearly identical performance
for the range of parameter values/noise levels that are of practical
interest to us.

Are there problems for which steepest descent gets you in the neighborhood
of a solution whereas GN does not?  If such problems exist then there
would be reason to apply LM instead of GN, but I don't know of any.

 Beware however -- one of the main things I learned about this
 field from Doug Bates, co-author of Bates_and_Watts and
 prinicipal author of S's and R's nls() :
 It's a *feature* that nls() does not converge sometimes when
 other methods do falsely claim convergence!

 Martin Maechler, ETH Zurich

 KateM 
 KateM Katharine Mullen
 KateM mail: Department of Physics and Astronomy, Faculty of Sciences
 KateM Vrije Universiteit Amsterdam, de Boelelaan 1081
 KateM 1081 HV Amsterdam, The Netherlands
 KateM room: T.1.06
 KateM tel: +31 205987870
 KateM fax: +31 205987992
 KateM e-mail: [EMAIL PROTECTED]
 KateM homepage: http://www.nat.vu.nl/~kate/


 KateM On Fri, 7 Sep 2007, Jose Luis Aznarte M. wrote:

  Hi! I'm translating some code from Matlab to R and I found a problem.
  I need to translate Matlab's function 'lsqnonlin'
  (http://www-ccs.ucsd.edu/matlab/toolbox/optim/lsqnonlin.html) into R,
  and at the beginning I  thought it would be the same as R's 'optim'. 
 But
  then I looked at the definition of 'lsqnonlin' and I don't quite see 
 how
  to make 'optim' to do the same thing. Does anyone have an idea?
  This is apart from the fact that I would like to use the Levenberg
  Marquardt algorithm which is not implemented in R (some discussion 
 about
  this: http://tolstoy.newcastle.edu.au/R/help/00b/2492.html).
  Thank you! All the best,
 
 
  --  --
  Jose Luis Aznarte M.   http://decsai.ugr.es/~jlaznarte
  Department of Computer Science and Artificial Intelligence
  Universidad de Granada   Tel. +34 - 958 - 24 04 67
  GRANADA (Spain)  Fax: +34 - 958 - 24 00 79
 
  __
  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
  and provide commented, minimal, self-contained, reproducible code.
 

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


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help with color coded bar graph

2007-09-08 Thread Jim Lemon
Luis Naver wrote:
 I have a list of observations that are -1, 1 or 0.  I would like to  
 represent them in a horizontal bar color coded based on value like a  
 stacked bar graph. I can achieve this in the form of a png with the  
 following code:
 
 A = floor(runif(10)*3) - 1
 
 png(width=100, height=10)
 par(mar=c(0,0,0,0))
 image(matrix(A), col=grey(c(0.1, 0.5, 0.9)))
 dev.off()
 
 However I would like to do this with one of the standard plotting  
 tools (i.e. barplot) to take advantage of labels and multiple  
 series.  Any help would be appreciated.
 
Hi Luis,
I understood your request as wanting a single horizontal bar with 10 
segments, each colored according to the value of A. If this is correct, 
you might want:

library(plotrix)
plot(1,xlim=c(-1,1),ylim=c(-1,1),xlab=,ylab=,type=n,axes=FALSE)
gradient.rect(-1,-0.1,1,0.1,col=grey(c(0.1,0.5,0.9))[A+2])

Jim

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] argument 'lib' is missing: using '/usr/lib/R/library'

2007-09-08 Thread Paul Smith
On 9/8/07, Gabor Csardi [EMAIL PROTECTED] wrote:
 Paul, what is the question? If the question is why you get this
 warning message, the reason is that the 'lib' argument is missing
 and install.packages is using '/usr/lib/R/library'.

 If you want to get rid of the warning supply the 'lib' argument.

Thanks, Gabor. Yes, I want to get rid of the warning message. Since
the warning did not appear before, even without supplying the 'lib'
argument, I thought that something was wrong here.

Paul





 On Sat, Sep 08, 2007 at 11:26:44AM +0100, Paul Smith wrote:
  Dear All,
 
  When installing packages, I get the following warning:
 
   install.packages(sqldf)
  Warning in install.packages(sqldf) : argument 'lib' is missing:
  using '/usr/lib/R/library'
 
  Any ideas?
 
  The details of my R installation are:
 
   version
 _
  platform   i386-redhat-linux-gnu
  arch   i386
  os linux-gnu
  system i386, linux-gnu
  status
  major  2
  minor  5.1
  year   2007
  month  06
  day27
  svn rev42083
  language   R
  version.string R version 2.5.1 (2007-06-27)
  
 
  R is here installed on Fedora 7.
 
  Thanks in advance,
 
  Paul
 
  __
  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
  and provide commented, minimal, self-contained, reproducible code.

 --
 Csardi Gabor [EMAIL PROTECTED]MTA RMKI, ELTE TTK


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] genoud problem

2007-09-08 Thread Jasjeet Singh Sekhon

Hi Shubha,

genoud does not return the initial fit value.  But you could easily
obtain it by passing your starting values to your function directly.
Alternatively, one can have genoud print out the entire initial
population (or the entire population as is evolves), and one can then
decide to report whatever summary of this one would like.  Note that
the best fit in generation zero is printed by default.  See the
project.path and print.level options for details.

Cheers,
Jas.

===
Jasjeet S. Sekhon 
  
Associate Professor 
Travers Department of Political Science
Survey Research Center  
UC Berkeley 

http://sekhon.berkeley.edu/
V: 510-642-9974  F: 617-507-5524
===


Shubha Vishwanath Karanth writes:
  Hi R users,
  
   
  
  genoud function of rgenoud package will optimize my function. If 
  
   
  
  opt = genoud(fn,2,max=TRUE,starting.value=c(1,10),)
  
   
  
  opt$value will give the optimized value of the function, fn. My
  problem is from the same opt, can I get the value of the function at the
  initial parameter values? I need the initial value of the function for
  reporting purposes.
  
   
  
   
  
   
  
  BR, Shubha
  
  
   [[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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Running a PERL script from R

2007-09-08 Thread Paul Hiemstra
Dear Ken.

You could also try and use RSPerl (http://www.omegahat.org/RSPerl/). It 
allows one to use R commands in Perl and vice-versa.

regards,

Paul

Pierce, Ken schreef:
 Is there a way to run a simple perl script from R?
  

 Kenneth B. Pierce Jr.

 Research Ecologist

 Landscape Ecology, Modeling, Mapping and Analysis Team 

 PNW Research Station - USDA-FS 

 3200 SW Jefferson Way,  Corvallis,  OR 97331 

 [EMAIL PROTECTED]

 541 750-7393 

 http://www.fsl.orst.edu/lemma/gnnfire

 http://www.fsl.orst.edu/R_users/index.php

  

   [[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
 and provide commented, minimal, self-contained, reproducible code.
   


-- 
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone: +31302535773
Fax:+31302531145
http://intamap.geo.uu.nl/~paul

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Lisp-like primitives in R

2007-09-08 Thread Gabor Grothendieck
On 9/8/07, Peter Dalgaard [EMAIL PROTECTED] wrote:
 François Pinard wrote:
  [Roland Rau]
 
  [François Pinard]
 
 
 
  I wonder what happened, for R to hide the underlying Scheme so fully,
  at least at the level of the surface language (despite there are
  hints).
 
 
 
  To further foster portability, we chose to write R in ANSI C
 
 
  Yes, of course.  Scheme is also (often) implemented in C.  I meant that
  R might have implemented a Scheme engine (or part of a Scheme engine,
  extended with appropriate data types) with a surface language (nearly
  the S language) which is purposely not Scheme, but could have been.
 
  If the gap is not extreme, one could dare dreaming that the Scheme
  engine in R be completed, and Scheme offered as an alternate extension
  language.  If you allow me to continue dreaming awake -- they told me
  they will let me free as long as I do not get dangerous! :-) -- part
  of the interest lies in the fact there are excellent Scheme compilers.
  If we could only find or devise some kind of marriage between a mature
  Scheme and R, so to speed up the non-vectorisable parts of R scripts...
 
 
 Well, depending on what you want, this is either trivial or
 impossible... The internal storage of R is still pretty much equivalent
 to scheme. E.g. try this:

   r2scheme - function(e) if (!is.recursive(e))
  deparse(e) else c((, unlist(lapply(as.list(e), r2scheme)), ))
   paste(r2scheme(quote(for(i in 1:4)print(i))), collapse= )
 [1] ( for i ( : 1 4 ) ( print i ) )


Also see showTree in codetools:

 library(codetools)
 showTree(quote(for(i in 1:4)print(i)))
(for i (: 1 4) (print i))

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Running a PERL script from R

2007-09-08 Thread Dirk Eddelbuettel

On 7 September 2007 at 14:04, Pierce, Ken wrote:
| I've tried various configurations of .script, system and shell to no
| avail. It seems to pause and run something but then no output is
| created. 

Make sure you read the help page for system, and understand the options. Esp
on Windows, you will need them to display/capture what is happening.

Dirk


| -Original Message-
| From: Dirk Eddelbuettel [mailto:[EMAIL PROTECTED] 
| Sent: Friday, September 07, 2007 1:11 PM
| To: Pierce, Ken
| Cc: r-help
| Subject: Re: [R] Running a PERL script from R
| 
| On Fri, Sep 07, 2007 at 12:15:51PM -0700, Pierce, Ken wrote:
|  Is there a way to run a simple perl script from R?
| 
| ?system
| 
| Hth, Dirk
| 
| --
| Three out of two people have difficulties with fractions.

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

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] confusion matrix - better code?

2007-09-08 Thread Monica Pisica

Michael,
 
Thank you very much. My code is certainly put to shame by yours. I promise to 
read about factor to see how you use it and why ;-))
 
I really appreciate your help.
 
Monica
 Subject: RE: [R] confusion matrix - better code? Date: Fri, 7 Sep 2007 
 15:36:00 -0500 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED]  How about 
 this?   
 tab-table(factor(tr,levels=unique(tr)),factor(pr,levels=unique(tr)))  
 tab-rbind(tab,colSums(tab))  tab-cbind(tab,rowSums(tab))  tab 1 2 3 4 
  1 2 1 0 0 3 2 2 1 0 0 3 3 0 0 3 0 3 4 0 1 0 0 1 4 3 3 0 10   Of 
 course you can add some dimnames for the 5th row and 5th column if you 
 want.  dimnames(tab)[[1]][5]-Total dimnames(tab)[[2]][5]-Total  
 tab 1 2 3 4 Total 1 2 1 0 0 3 2 2 1 0 0 3 3 0 0 3 0 3 4 0 1 0 0 1 Total 
 4 3 3 0 10  Michael Conklin  Chief Methodologist - Advanced Analytics  
   MarketTools, Inc.  6465 Wayzata Blvd. Suite 170  Minneapolis, MN 
 55426   Tel: 952.417.4719 | Mobile:612.201.8978  [EMAIL PROTECTED]
 MarketTools(r) http://www.markettools.comThis e-mail and any 
 attachments may contain privileged, confidential or proprietary information. 
 If you are not the intended recipient, be aware that any review, copying, or 
 distribution of this e-mail or any attachment is strictly prohibited. If you 
 have received this e-mail in error, please return it to the sender 
 immediately, and permanently delete the original and any copies from your 
 system. Thank you for your cooperation.-Original Message- 
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Monica 
 Pisica Sent: Friday, September 07, 2007 2:53 PM To: 
 r-help@stat.math.ethz.ch Subject: [R] confusion matrix - better code? 
 Importance: High   Hi,  I've written some code to obtain a confusion 
 matrix when the true classification and the predicted classification are 
 known. Suppose true classification is called tr and predicted 
 classification is pr. I have 4 classes in tr, but only 3 classes out of 4 
 are predicted in pr. Following is my code, but looks quite clunky to me. 
 I wonder if you have any suggestions to improve it.  Thanks,  Monica  
 -  tr - c(1,2,2,3,3,3,2,4,1,1) 
 pr-c(1,2,1,3,3,3,1,2,1,2) dat - data.frame(tr, pr) class - 
 c(1:length(tr)) m - max(c(length(unique(tr)), length(unique(pr for(i 
 in 1:length(class)) { class[i] - sub(' ','',paste(dat[i,1],dat[i,2])) } 
 dat - data.frame(dat, class) mat - matrix(0, nrow=m, ncol=m) for (i in 
 1:m){ for (j in 1:m){ mat[i,j] - sub(' ','',paste(i,j)) }} cat - 
 matrix(0, nrow=(m+1), ncol=(m+1)) for (i in 1:m){ for(j in 1:m){ 
 cat[i,j]- nrow(dat[dat$class==mat[i,j],]) }} for (i in 1:m){ 
 cat[(m+1),i]-sum(cat[1:m,i]) cat[i,(m+1)]- sum(cat[i,1:m]) 
 cat[(m+1),(m+1)] - sum(cat[1:m,(m+1)]) } cat [,1] [,2] [,3] [,4] [,5] 
 [1,] 2 1 0 0 3 [2,] 2 1 0 0 3 [3,] 0 0 3 0 3 [4,] 0 1 0 0 1 [5,] 4 3 3 0 
 10  The 5th row / col represents the sum on each row / col respectively. 
 _ Gear up 
 for Halo(r) 3 with free downloads and an exclusive offer. It's our way of 
 saying thanks for using Windows Live(tm).  [[alternative HTML version 
 deleted]] 
_

é.

[[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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Lisp-like primitives in R

2007-09-08 Thread François Pinard
[Peter Dalgaard]
[François Pinard]

I meant that R might have implemented a Scheme engine [...] with 
a surface language [...] which is purposely not Scheme, but could have 
been.  [...] one could dare dreaming that the Scheme engine in R be 
completed, and Scheme offered as an alternate extension language.  
[...] there are excellent Scheme compilers.  [...]

Well, depending on what you want, this is either trivial or 
impossible...

I'm more leaning on the impossible side :-).

The internal storage of R is still pretty much equivalent to scheme.

R needs a few supplementary data types, and it motivated the R authors 
into re-implementing their own Scheme engine instead of relying on an 
existing implementation of a Scheme system.

  r2scheme - function(e) [...]

Nice exercise! :-)

a parser that parses a similar language to R internal format is  not 
a very hard exercise (some care needed in places). However, replacing 
the front-end is not going to make anything faster,

Of course.  The idea is nothing more than to please people starving to 
use Scheme instead of S as a surface language, here and there in 
scripts.  I merely thought that if the gap is small enough (so to not 
require an extraordinary effort), it would be worth the leap.  One 
immediate difficulty to foresee is the name clashes between R and RnRS.
There might also be missing things in R (like continuations, say).

To make anything faster, and this is a totally different idea, one might 
consider replacing the back-end, not the front-end.  Writing good 
optimizing Scheme compilers is quite an undertaking, and if one only 
considers type inference (as a subproblem), this still is an active 
research area.  The Scheme engine in R was written as to quickly get 
a working S (non-obstant lexical scoping and some library issues).
My ramble was about switching this quick base of R to some solid Scheme 
implementation, than to re-address separately compiling issues for R.

and the evaluation engine in R does a couple of tricks which are not 
done in Scheme, notably lazy evaluation,

Promises?  Aren't they already part of Scheme?  The main difference 
I saw is their systematic use in R argument passing.  All aspects of 
mere argument passing would require a lot of thought.  As you wrote, 
variable scope is another difficulty.  Offering a compatible C API, and 
library interface in general, might be a frightening but necessary 
challenge.  It's all more of a dream than a thought, actually... :-)

Look up the writings of Luke Tierney on the matter to learn more.

Thanks for this interesting reference.

-- 
François Pinard   http://pinard.progiciels-bpi.ca

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R first.id last.id function error

2007-09-08 Thread Gerard Smits
Hi Jim,

Thanks for going to the trouble of writing the function. I'll copy and try it.

Gerard



At 06:30 PM 9/7/2007, jim holtman wrote:
This function should do it for you:


  file1 - read.table(textConnection(   id rx week dv1
+ 1   1  11   1
+ 2   1  12   1
+ 3   1  13   2
+ 4   2  11   3
+ 5   2  12   4
+ 6   2  13   1
+ 7   3  11   2
+ 8   3  12   3
+ 9   3  13   4
+ 10  4  11   2
+ 11  4  12   6
+ 12  4  13   5
+ 13  5  21   7
+ 14  5  22   8
+ 15  5  23   5
+ 16  6  21   2
+ 17  6  22   4
+ 18  6  23   6
+ 19  7  21   7
+ 20  7  22   8
+ 21  8  21   9
+ 22  9  21   4
+ 23  9  22   5), header=TRUE)
 
  mark.function -
+ function(df){
+ df - df[order(df$id, df$week),]
+ # create 'diff' of 'id' to determine where the breaks are
+ breaks - diff(df$id)
+ # the first entry will be TRUE, and then every occurance of
non-zero in breaks
+ df$first.id - c(TRUE, breaks != 0)
+ # the last entry is TRUE and every non-zero breaks
+ df$last.id - c(breaks != 0, TRUE)
+ df
+ }
 
  mark.function(file1)
id rx week dv1 first.id last.id
1   1  11   1 TRUE   FALSE
2   1  12   1FALSE   FALSE
3   1  13   2FALSETRUE
4   2  11   3 TRUE   FALSE
5   2  12   4FALSE   FALSE
6   2  13   1FALSETRUE
7   3  11   2 TRUE   FALSE
8   3  12   3FALSE   FALSE
9   3  13   4FALSETRUE
10  4  11   2 TRUE   FALSE
11  4  12   6FALSE   FALSE
12  4  13   5FALSETRUE
13  5  21   7 TRUE   FALSE
14  5  22   8FALSE   FALSE
15  5  23   5FALSETRUE
16  6  21   2 TRUE   FALSE
17  6  22   4FALSE   FALSE
18  6  23   6FALSETRUE
19  7  21   7 TRUE   FALSE
20  7  22   8FALSETRUE
21  8  21   9 TRUETRUE
22  9  21   4 TRUE   FALSE
23  9  22   5FALSETRUE
 
 


On 9/7/07, Gerard Smits [EMAIL PROTECTED] wrote:
  Hi R users,
 
  I have a test dataframe (file1, shown below) for which I am trying
  to create a flag for the first and last ID record (equivalent to SAS
  first.id and last.id variables.
 
  Dump of file1:
 
file1
 id rx week dv1
  1   1  11   1
  2   1  12   1
  3   1  13   2
  4   2  11   3
  5   2  12   4
  6   2  13   1
  7   3  11   2
  8   3  12   3
  9   3  13   4
  10  4  11   2
  11  4  12   6
  12  4  13   5
  13  5  21   7
  14  5  22   8
  15  5  23   5
  16  6  21   2
  17  6  22   4
  18  6  23   6
  19  7  21   7
  20  7  22   8
  21  8  21   9
  22  9  21   4
  23  9  22   5
 
  I have written code that correctly assigns the first.id and 
 last.id variabes:
 
  require(Hmisc)  #for Lags
  #ascending order to define first dot
  file1- file1[order(file1$id, file1$week),]
  file1$first.id - (Lag(file1$id) != file1$id)
  file1$first.id[1]-TRUE  #force NA to TRUE
 
  #descending order to define last dot
  file1- file1[order(-file1$id,-file1$week),]
  file1$last.id  - (Lag(file1$id) != file1$id)
  file1$last.id[1]-TRUE   #force NA to TRUE
 
  #resort to original order
  file1- file1[order(file1$id,file1$week),]
 
 
 
  I am now trying to get the above code to work as a function, and am
  clearly doing something wrong:
 
first.last - function (df, idvar, sortvars1, sortvars2)
  +   {
  +   #sort in ascending order to define first dot
  +   df- df[order(sortvars1),]
  +   df$first.idvar - (Lag(df$idvar) != df$idvar)
  +   #force first record NA to TRUE
  +   df$first.idvar[1]-TRUE
  +
  +   #sort in descending order to define last dot
  +   df- df[order(-sortvars2),]
  +   df$last.idvar  - (Lag(df$idvar) != df$idvar)
  +   #force last record NA to TRUE
  +   df$last.idvar[1]-TRUE
  +
  +   #resort to original order
  +   df- df[order(sortvars1),]
  +   }
   
 
  Function call:
 
first.last(df=file1, idvar=file1$id,
  sortvars1=c(file1$id,file1$week), sortvars2=c(-file1$id,-file1$week))
 
  R Error:
 
  Error in as.vector(x, mode) : invalid argument 'mode'
   
 
  I am not sure about the passing of the sort strings.  Perhaps this is
  were things are off.  Any help greatly appreciated.
 
  Thanks,
 
  Gerard
 [[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
  and provide commented, minimal, self-contained, reproducible code.
 


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

What is the problem you are trying to solve?

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

Re: [R] Suppress 'x' when appending to a csv file

2007-09-08 Thread Marc Schwartz
On Sat, 2007-09-08 at 11:41 -0400, John Kane wrote:
 Is there any convenient way to supress the x that
 appears in csv export files?  I would like to be able
 to export a file and add a comment to it yet still be
 able to read it back into R.  I don't see any way to
 get rid of the x that seperates the different appended
 parts.
 
 Thanks
 
 EXAMPLE
 
 x
 1
 2
 3
 4
 5
 x
 #Results from file SSS.r
 
 R.2.5.1 Windows XP

John,

Try this:

 write.table(head(iris), sep = ,, 
  row.names = FALSE, col.names = FALSE)
5.1,3.5,1.4,0.2,setosa
4.9,3,1.4,0.2,setosa
4.7,3.2,1.3,0.2,setosa
4.6,3.1,1.5,0.2,setosa
5,3.6,1.4,0.2,setosa
5.4,3.9,1.7,0.4,setosa


You may need to explicitly adjust other arguments that are otherwise set
to defaults when using write.csv().

HTH,

Marc Schwartz

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


Re: [R] Using clustering functions

2007-09-08 Thread Uwe Ligges


uv wrote:
 Hi. I need to use a few different clustering functions. I managed to run the
 kmeans() one which is in my stats library, but I can't use any function,
 such as agnes(), that is in my cluster library. Any idea how to access
 other libraries? 
 Thanks!


Both stats and cluster are packages, not libraries.
You need to call library(cluster) in order to load package cluster 
from your library before using agnes() and her friends.


Uwe Ligges

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem in installing packages on linux machine...

2007-09-08 Thread tkobayas
Hi,

I am trying to install RSQLite package on my Fedora workstation. I 
tried to install other packages as well, but each time I got the same 
error messages saying compilation error and non zero exit status. 
Do I have to specify lib=? I never specified the library path before 
when I was using Fedora Core 6.


Warning in install.packages(RSQLite) : argument 'lib' is missing: 
using '/usr/lib/R/library'
--- Please select a CRAN mirror for use in this session ---
Loading Tcl/Tk interface ... done
trying URL 'http://cran.cnr.Berkeley.edu/src/contrib/RSQLite_0.5-6.tar.gz'
Content type 'application/x-gzip' length 710241 bytes
opened URL
==
downloaded 693Kb

gcc -std=gnu99 -shared -L/usr/local/lib -o RSQLite.so RS-DBI.o 
RS-SQLite.o sqlite-all.o   -L/usr/lib/R/lib -lR
/usr/bin/ld: skipping incompatible /usr/lib/R/lib/libR.so when 
searching for -lR
/usr/bin/ld: cannot find -lR
collect2: ld returned 1 exit status
make: *** [RSQLite.so] Error 1
chmod: cannot access `/usr/lib/R/library/RSQLite/libs/*': No such file 
or directory
ERROR: compilation failed for package 'RSQLite'
** Removing '/usr/lib/R/library/RSQLite'

The downloaded packages are in
/tmp/RtmpHQ5Y7C/downloaded_packages
Warning message:
installation of package 'RSQLite' had non-zero exit status in: 
install.packages(RSQLite)

I appreciate your help.

Thank you very much

Taka

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem in installing packages on linux machine...

2007-09-08 Thread Henrique Dallazuanna
Hi, try install packages whit 'sudo'.

$sudo R

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

On 08/09/2007, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 Hi,

 I am trying to install RSQLite package on my Fedora workstation. I
 tried to install other packages as well, but each time I got the same
 error messages saying compilation error and non zero exit status.
 Do I have to specify lib=? I never specified the library path before
 when I was using Fedora Core 6.


 Warning in install.packages(RSQLite) : argument 'lib' is missing:
 using '/usr/lib/R/library'
 --- Please select a CRAN mirror for use in this session ---
 Loading Tcl/Tk interface ... done
 trying URL 'http://cran.cnr.Berkeley.edu/src/contrib/RSQLite_0.5-6.tar.gz'
 Content type 'application/x-gzip' length 710241 bytes
 opened URL
 ==
 downloaded 693Kb

 gcc -std=gnu99 -shared -L/usr/local/lib -o RSQLite.so RS-DBI.o
 RS-SQLite.o sqlite-all.o   -L/usr/lib/R/lib -lR
 /usr/bin/ld: skipping incompatible /usr/lib/R/lib/libR.so when
 searching for -lR
 /usr/bin/ld: cannot find -lR
 collect2: ld returned 1 exit status
 make: *** [RSQLite.so] Error 1
 chmod: cannot access `/usr/lib/R/library/RSQLite/libs/*': No such file
 or directory
 ERROR: compilation failed for package 'RSQLite'
 ** Removing '/usr/lib/R/library/RSQLite'

 The downloaded packages are in
 /tmp/RtmpHQ5Y7C/downloaded_packages
 Warning message:
 installation of package 'RSQLite' had non-zero exit status in:
 install.packages(RSQLite)

 I appreciate your help.

 Thank you very much

 Taka

 __
 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
 and provide commented, minimal, self-contained, reproducible code.


[[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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem in installing packages on linux machine...

2007-09-08 Thread tkobayas
Hi,

Still got the same error message. I did su R when I got the error 
message for the first time. I have never seen this error message. I 
will be googling for solutions as well...

Thank you.

Quoting Henrique Dallazuanna [EMAIL PROTECTED]:

 Hi, try install packages whit 'sudo'.

 $sudo R

 --
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O

 On 08/09/2007, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 Hi,

 I am trying to install RSQLite package on my Fedora workstation. I
 tried to install other packages as well, but each time I got the same
 error messages saying compilation error and non zero exit status.
 Do I have to specify lib=? I never specified the library path before
 when I was using Fedora Core 6.


 Warning in install.packages(RSQLite) : argument 'lib' is missing:
 using '/usr/lib/R/library'
 --- Please select a CRAN mirror for use in this session ---
 Loading Tcl/Tk interface ... done
 trying URL 'http://cran.cnr.Berkeley.edu/src/contrib/RSQLite_0.5-6.tar.gz'
 Content type 'application/x-gzip' length 710241 bytes
 opened URL
 ==
 downloaded 693Kb

 gcc -std=gnu99 -shared -L/usr/local/lib -o RSQLite.so RS-DBI.o
 RS-SQLite.o sqlite-all.o   -L/usr/lib/R/lib -lR
 /usr/bin/ld: skipping incompatible /usr/lib/R/lib/libR.so when
 searching for -lR
 /usr/bin/ld: cannot find -lR
 collect2: ld returned 1 exit status
 make: *** [RSQLite.so] Error 1
 chmod: cannot access `/usr/lib/R/library/RSQLite/libs/*': No such file
 or directory
 ERROR: compilation failed for package 'RSQLite'
 ** Removing '/usr/lib/R/library/RSQLite'

 The downloaded packages are in
 /tmp/RtmpHQ5Y7C/downloaded_packages
 Warning message:
 installation of package 'RSQLite' had non-zero exit status in:
 install.packages(RSQLite)

 I appreciate your help.

 Thank you very much

 Taka

 __
 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
 and provide commented, minimal, self-contained, reproducible code.






Takatsugu Kobayashi
PhD Student
Indiana University, Dept. Geography

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Suppress 'x' when appending to a csv file

2007-09-08 Thread John Kane
Thanks Marc. It works.  I had not thought of using
col.names = FALSE as I wanted to keep the colnames. I
see that I will just have to do another write.table
command to do this.  Humm, actually it took a a bit of
juggling to do the names but it's looking fine now.



--- Marc Schwartz [EMAIL PROTECTED] wrote:

 On Sat, 2007-09-08 at 11:41 -0400, John Kane wrote:
  Is there any convenient way to supress the x that
  appears in csv export files?  I would like to be
 able
  to export a file and add a comment to it yet still
 be
  able to read it back into R.  I don't see any way
 to
  get rid of the x that seperates the different
 appended
  parts.
  
  Thanks
  
  EXAMPLE
  
  x
  1
  2
  3
  4
  5
  x
  #Results from file SSS.r
  
  R.2.5.1 Windows XP
 
 John,
 
 Try this:
 
  write.table(head(iris), sep = ,, 
   row.names = FALSE, col.names = FALSE)
 5.1,3.5,1.4,0.2,setosa
 4.9,3,1.4,0.2,setosa
 4.7,3.2,1.3,0.2,setosa
 4.6,3.1,1.5,0.2,setosa
 5,3.6,1.4,0.2,setosa
 5.4,3.9,1.7,0.4,setosa
 
 
 You may need to explicitly adjust other arguments
 that are otherwise set
 to defaults when using write.csv().
 
 HTH,
 
 Marc Schwartz
 
 


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


Re: [R] 'initial value not feasible' in constrOptim

2007-09-08 Thread Ingmar Visser
Hi,

On Sep 7, 2007, at 11:00 PM, Yuchen Luo wrote:
 constrOptim(c(0.5,0.3,0.5), fit.error, fit.error.grr,  
 ui=-1*ui,ci=-1*ci)

 and I am confronted with error message initial value not feasible

 I plug in the initial value of (0.5,0.3,0.5) to function fit.error and
 fit.error.grr and have pretty reasonable result.

That doesn't mean the constraint is satisfied, which depends on the  
values of ui and ci
but they are not provided so it's hard to tell where the problem is.

hth, Ingmar

 I inequality ui %*% theta
 - ci = 0 as suggested in the R manual and it is satisfied. In  
 case that
 this is a typo of the manual, I let ui=-ui and ci=-ci and try  
 constrOptim
 again but the same warning message pops up.
 Could you please point me a way out of this?

 I am actually trying to translate a fortran code to R and the  
 function I
 want to replace is DBCPOL, which used 'the complex method  
 described in
 Nelder and Mead (1965) and Gill et al. (1981). I believe contrOptim is
 better than it because it is newer, is it?

 Best Wishes
 Yuchen Luo

   [[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
 and provide commented, minimal, self-contained, reproducible code.

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] 'singular gradient matrix? when using nls() and how to make the program skip nls( ) and run on

2007-09-07 Thread Joerg van den Hoff
On Wed, Sep 05, 2007 at 04:43:19PM -0700, Yuchen Luo wrote:
 Dear friends.
 
 I use nls() and encounter the following puzzling problem:
 
 
 
 I have a function f(a,b,c,x), I have a data vector of x and a vectory  y of
 realized value of f.
 
 
 
 Case1
 
 I tried to estimate  c with (a=0.3, b=0.5) fixed:
 
 nls(y~f(a,b,c,x), control=list(maxiter = 10, minFactor=0.5
 ^2048),start=list(c=0.5)).
 
 The error message is: number of iterations exceeded maximum of 10
 
 
 
 Case2
 
 I then think maybe the value of a and be are not reasonable. So, I let nls()
 estimate (a,b,c) altogether:
 
 nls(y~f(a,b,c,x), control=list(maxiter = 10, minFactor=0.5
 ^2048),start=list(a=0.3,b=0.5,c=0.5)).
 
 The error message is:
 
 singular gradient matrix at initial parameter estimates.
 
 
 
 This is what puzzles me, if the initial parameter of (a=0.3,b=0.5,c=0.5) can
 create 'singular gradient matrix', then why doesn't this 'singular gradient
 matrix' appear in Case1?
 
 
 
 I have tried to change the initial value of (a,b,c) around but the problem
 persists. I am wondering if there is a way out.
 
 
 
 My another question is, I need to run 220 of  nls() in my program with
 different y and x. When one of the nls() encounter a problem, the whole
 program stops.  In my case, the 3rd nls() runs into a problem.  I would
 still need the program to run the remaining 217 nls( )! Is there a way to
 make the program skip the problematic nls() and complete the ramaining
 nls()'s?

?try

 
 
 
 Your help will be highly appreciated!
 
 Yuchen Luo
 
   [[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
 and provide commented, minimal, self-contained, reproducible code.

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] negative value for AIC and BIC

2007-09-07 Thread John Sorkin
Oliver,
I am attaching an HTML document in which I have plotted -2Log(x) vs. x. If you 
examine the plot you will see that -2Log(x) can be negative. Since -2Log(x) is 
part of AIC and BIC, AIC and BIC can be negative.
John

John Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
Baltimore VA Medical Center GRECC,
University of Maryland School of Medicine Claude D. Pepper OAIC,
University of Maryland Clinical Nutrition Research Unit, and
Baltimore VA Center Stroke of Excellence

University of Maryland School of Medicine
Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524

(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
[EMAIL PROTECTED]

 Hannu Kahra [EMAIL PROTECTED] 09/07/07 4:32 AM 
Olivier,

type ?AIC and have a look at the description

Description:

 Generic function calculating the Akaike information criterion for
 one or several fitted model objects for which a log-likelihood
 value can be obtained, according to the formula -2*log-likelihood
 + k*npar, where npar represents the number of parameters in the
 fitted model, and k = 2 for the usual AIC, or k = log(n) (n the
 number of observations) for the so-called BIC or SBC (Schwarz's
 Bayesian criterion).

AIC = -2*log-likelihood + k*npar can be negative as SBC, too.

Hannu

On 9/7/07, Olivier MARTIN [EMAIL PROTECTED] wrote:

 Hi all,


 I obtained negative values for AIC and BIC criteria for a particular
 model that I have
 developped...

 I don't remember to have negative values for these crietria for others
 applications, so I am a
 little suprised... Could anyone tell me if something is wrong or his
 conclusion concerning my model?

 Best regards,
 Olivier.

 __
 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 
 and provide commented, minimal, self-contained, reproducible code.


[[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 
and provide commented, minimal, self-contained, reproducible code.

Confidentiality Statement:
This email message, including any attachments, is for the sole use of the 
intended recipient(s) and may contain confidential and privileged information.  
Any unauthorized use, disclosure or distribution is prohibited.  If you are not 
the intended recipient, please contact the sender by reply email and destroy 
all copies of the original message. 

   y = -2Log[x]

   Out[20]=

   -2 Log[x]

   In[22]:=

   RowBox[{Plot,  [, RowBox[{y, ,, RowBox[{{, RowBox[{x, ,, 0.01, ,, 4}],
   }}], ,, AxesLabel#62754; {x, -2Log[x]}}], ]}]

   [Graphics:HTMLFiles/-2Log_10.gif]

   Out[22]=

   -Graphics-

   __

   Created by [1]Mathematica  (September 7, 2007)

References

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


Re: [R] Running geeglm unstructured corstr

2007-09-07 Thread Ulrich Halekoh
Dear Niccolo,
 

a) your example program
works for me 
and on a Pentium 4, 3 Ghz, 1GB ram, The model fit uses
   user  system elapsed 
 146.920.76  143.32 
 
library(geepack)
set.seed(299)
header - rep.int(seq(1:615),sample(seq(1:19),size=615,replace=T))
inr - rlnorm(length(header),0.8434359,0.3268392)
group_cod - sample(c(0,1),size=length(header),replace=T)
inside - sample(c(0,1),size=length(header),replace=T)
gee.frame - data.frame(header,inr,group_cod,inside)
 
geeglm.model- geeglm(inside~group_cod,family=binomial, data=gee.frame
,id=header,corstr=unstructured)
 
 
 

Version of_   
platform   i386-pc-mingw32 
arch   i386
os mingw32 
system i386, mingw32   
status 
major  2   
minor  5.1 
year   2007
month  06  
day27  
svn rev42083   
language   R   
version.string R version 2.5.1 (2007-06-27)
 

b)

for costr= ar1
 
In my dataset I also have a variable weeks, that I use to specify
waves in
the geeglm. When I use this, the output for an autoregressive gee model
gives me only the estimates, when I don't use it everything's alright.
The
problem's that I have unbalanced observations, so the use of waves could
take this into account while estimating parameters. Is this a conflict
between these options, or what?

 
The argument waves should work in conjunction with the ar1 working
correlation.
Make sure that the observations are orderd  wrt. cluster-id as it is
said in ?geeglm for the 'id' argument
 
 
 
c) if you build your own fixed-working correlation then  there are two
issues:
 
 1) you must leave out  clusters of size 1 in the construction of the
zcor matrix:
 
 if the other clusters have the same size you can use geeglm with that
zcor matrix
   Example:
 
# using corstr=fixed the cluster with only 1 observation must be
# left out from the construction of the zcor-vector. 
# the following example is for the case where clusters of size larger
then 1
# have no missing observations and are of the same size
 
library(geepack)
data(seizure)
## Diggle, Liang, and Zeger (1994) pp166-168, compare Table 8.10
seiz.l - reshape(seizure,
  varying=list(c(base,y1, y2, y3, y4)),
  v.names=y, times=0:4, direction=long)
seiz.l - seiz.l[order(seiz.l$id, seiz.l$time),]
seiz.l$t - ifelse(seiz.l$time == 0, 8, 2)
seiz.l$x - ifelse(seiz.l$time == 0, 0, 1)
 
 
 
## defining fixed correlation matrix
cor.fixed - matrix(c(1, 0.5, 0.25, 0.125, 0.125,
  0.5, 1, 0.25, 0.125, 0.125,
  0.25, 0.25, 1, 0.5, 0.125,
  0.125, 0.125, 0.5, 1, 0.125,
  0.125, 0.125, 0.125, 0.125, 1), 5, 5)
 
zcor - rep(cor.fixed[lower.tri(cor.fixed)], 59)
g1 - geeglm(y ~ offset(log(t)) + x + trt + x:trt, id = id,
data = seiz.l, family = poisson,
corstr = fixed, zcor = zcor)
 
#reducing clusters 1 ,3 and 58 to only one observation 
seiz.reduc-subset(seiz.l,!( (id==1 | id==3 | id==58)  time0))
 
# zcor is only constructed for clusters with size larger than 1
n.larger.one-sum(table(seiz.reduc$id)1)
zcor -c( rep(cor.fixed[lower.tri(cor.fixed)], n.larger.one))
 

g2- geeglm(y ~ offset(log(t)) + x + trt + x:trt, id = id,
data = seiz.reduc, family = poisson,
corstr = fixed, zcor = zcor)
 
 
 

2) if the clusters have different size than you must construct the
zcor-matrix according to the missing structure,
 the usage of the wave-argument to specify the missing structure does
not work.
 

Example:
 

# using corstr=fixed the  for clusters with unbalanced number of
observations
# the wave argument does not work, the zcor-matrix must be constructed
'by-hand'
library(geepack)
data(seizure)
## Diggle, Liang, and Zeger (1994) pp166-168, compare Table 8.10
seiz.l - reshape(seizure,
  varying=list(c(base,y1, y2, y3, y4)),
  v.names=y, times=0:4, direction=long)
seiz.l - seiz.l[order(seiz.l$id, seiz.l$time),]
seiz.l$t - ifelse(seiz.l$time == 0, 8, 2)
seiz.l$x - ifelse(seiz.l$time == 0, 0, 1)
 
# transform time such that the initial time is 1 
seiz.l$time-seiz.l$time+1
 

#taking only a subset of the data such the data are unbalanced wrt
cluster -size
set.seed(88)
seiz-subset(seiz.l,!( (id==1 | id==3 | id==58)  time2))
 
## Construction of  a  fixed correlation matrix
cor.fixed - matrix(c(1, 0.7, 0.5, 0.25, 0.12,
  0.7, 1, 0.71, 0.125, 0.125,
  0.5, 0.71, 1, 0.29, 0.123,
  0.25, 0.125, 0.29, 1, 0.119,
  0.120, 0.125, 0.123, 0.119, 1), 5, 5)
 
# The zcor-vector is constructed only for times which exist in the data

Re: [R] SQL like function?

2007-09-07 Thread Gabor Grothendieck
Others have already pointed out %in% but regarding your comment about
SQL, you can use SQL to manipulate R data frames using the sqldf package
which provides an interface to lower level RSQLite (and RMySQL in the future)
routines.  The following examples use SQLite underneath:

DF - data.frame(observation = c(1,2,3,4,5))
ID - data.frame(ID = c(1, 3, 4))

library(sqldf)
sqldf(select observation, observation in (select * from ID) `ID?` from DF)

# or

sqldf(select observation, observation in (1, 3, 4) `ID?` from DF)

See home page at:

http://sqldf.googlecode.com


On 9/7/07, Takatsugu Kobayashi [EMAIL PROTECTED] wrote:
 Hi RUsers,

 I am wonder if I can search observations whose IDs matches any of the
 values in another vector, such as in MySQL. While I am learing MySQL for
 future database management, I appreciate if anyone could give me a hint.

 Suppose I have one 5*1 vector containing observation IDs and
 frequencies, and one 3*1 vector containing observation IDs.

 observation-c(1,2,3,4,5)
 ID-c(1,3,4)

 Then, I would like to program a code that returns a results showing
 matched observations like

 result: TRUE FALSE TRUE TRUE FALSE

 I am reading S programming, but I cannot find a way to do this.

 Thank you very much.

 Taka

 __
 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
 and provide commented, minimal, self-contained, reproducible code.


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] text in boxplots

2007-09-07 Thread Yves Moisan

Hi Greg,

Actually, I'm using the scatterplot function in the car namespace.  My
understanding is that the scatterplot is turned into a boxplot when the x
variable is a factor, but I can't see that in the code of the function. 
I've successfully modified the function to output regression stats (R^^2,
etc.) with the method 'text', but I can't seem to get any text printed when
the result of a call to scatterplot is a bunch of boxplots.  

I don't know how boxplots end up being generated (I like it though) in a
call to car:scatterplot.  The same data in ggobi would show the standard
scatterplot with data aligned vertically in lines along the values of the x
(factor) variable but car:scatterplot draws nice boxes around the data as a
bonus.  I guess I'll need to follow with some debugging tool.  I find it odd
that mtext works though.  Or maybe some graphics parameter is set such that
text doesn't show.

Thanx Greg.
-- 
View this message in context: 
http://www.nabble.com/text-in-boxplots-tf4394528.html#a12553104
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] help on replacing values

2007-09-07 Thread Gabor Grothendieck
Your columns are factors, not character strings.  Use as.is = TRUE as
an argument to read.table.   Also its a bit dangerous to use T although
not wrong.  Its safer to use TRUE.

On 9/7/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Dear List,

 I have a newbie question. I have read in a data.frame as follows:

  data = read.table(table.txt, header = T)
  data
  X1 X2 X3 X4
 A AB AC AB AC
 B AB AC AA AB
 C AA AB AA AB
 D AA AB AB AC
 E AB AA AA AB
 F AB AA AB AC
 B AB AC AB AA

 I would like to replace AA values by BB in column X2. I have tried
 using replace() with no success, although I am not sure this is the
 right function. This is the code I have used:

 data$X2 - replace(data$X2, data$X2 ==AA,BB)
 Warning message:
 invalid factor level, NAs generated in: `[-.factor`(`*tmp*`, list,
 value = BB)

 What is wrong with the code? How can I get this done? how about
 changing AA values by BB in all 4 columns simultaneously? Actually
 this is a small example dataframe, the real one would have about 1000
 columns.

 Extendind this, I found a similar thread dated July 2006 that used
 replace() on iris dataset, but I have tried reproducing it obtaining
 same warning message

  iris$Species - replace(iris$Species, iris$Species
 == setosa,NewName)
 Warning message:
 invalid factor level, NAs generated in: `[-.factor`(`*tmp*`, list,
 value = NewName)

 Thanks in advance your help,

 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
 and provide commented, minimal, self-contained, reproducible code.


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] variable format

2007-09-07 Thread Gabor Grothendieck
A matrix is for situations where every element is of the same class
but your columns have different classes so use a data frame:

DF - data.frame(a = 11:15, b = letters[1:5], stringsAsFactors = FALSE)
subset(DF, a %in% 11:13)
subset(DF, a %in% c(0, 11:13)) # same

Suggest you review the Introduction to R manual and look at ?data.frame,
?subset and ?%in%

On 9/4/07, Cory Nissen [EMAIL PROTECTED] wrote:
 Okay, I want to do something similar to SAS proc format.

 I usually do this...

 a - NULL
 a$divisionOld - c(1,2,3,4,5)
 divisionTable - matrix(c(1, New England,
  2, Middle Atlantic,
  3, East North Central,
  4, West North Central,
  5, South Atlantic),
ncol=2, byrow=T)
 a$divisionNew[match(a$divisionOld, divisionTable[,1])] - divisionTable[,2]

 But how do I handle the case where...
 a$divisionOld - c(0,1,2,3,4,5)   #no format available for 0, this throws an 
 error.
 OR
 divisionTable - matrix(c(1, New England,
  2, Middle Atlantic,
  3, East North Central,
  4, West North Central,
  5, South Atlantic,
  6, East South Central,
  7, West South Central,
  8, Mountain,
  9, Pacific),
ncol=2, byrow=T)
 There are extra formats available... this throws a warning.

 Thanks

 Cory

[[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
 and provide commented, minimal, self-contained, reproducible code.


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Finding convex hull? [Broadcast]

2007-09-07 Thread Liaw, Andy
From: Dong-hyun Oh
 Dear UseRs,
 
 I would like to know which function is the most efficient in finding  
 convex hull of points in 3(or 2)-dimensional case?
 
 Functions for finding convex hull is the following:
 convex.hull (tripack), chull (grDevices), in.chull (sgeostat),  
 convhulln (geometry), convexhull.xy (spatstat), calcConvexHull  
 (PBSmapping).
 
 I also would like to know if there is a function that can be 
 used for  
 finding convex hull in multi-dimensional case, that is more than 3- 
 dimension.

If you had look a bit more carefully, you should have seen that 
convhulln (geometry) will handle more than 3 dimensions.

Andy

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


--
Notice:  This e-mail message, together with any attachments,...{{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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] ploting missing data

2007-09-07 Thread Gabor Grothendieck
Try this:

library(zoo)
plot(na.approx(zoo(as.matrix(data[-1]), data[,1])), plot.type = single)

See ?na.approx, ?plot.zoo, ?xyplot.zoo and vignette(zoo)

On 9/7/07, Markus Schmidberger [EMAIL PROTECTED] wrote:
 Hello,

 I have this kind of dataframe and have to plot it.

 data - data.frame(sw= c(1,2,3,4,5,6,7,8,9,10,11,12,15),
zehn =
 c(33.44,20.67,18.20,18.19,17.89,19.65,20.05,19.87,20.55,22.53,NA,NA,NA),
 zwanzig =
 c(61.42,NA,26.60,23.28,NA,24.90,24.47,24.53,26.41,28.26,NA,29.80,35.49),
 fuenfzig =
 c(162.51,66.08,49.55,43.40,NA,37.77,35.53,36.46,37.25,37.66,NA,42.29,47.80)
 )

 The plot should have lines:
 lines(fuenfzig~sw, data=data)
 lines(zwanzig~sw, data=data)

 But now I have holes in my lines for the missing values (NA). How to
 plot the lines without the holes?
 The missing values should be interpolated or the left and right point
 directly connected. The function approx interpolates the whole dataset.
 Thats not my goal!
 Is there no plotting function to do this directly?

 Best
 Markus

 --
 Dipl.-Tech. Math. Markus Schmidberger

 Ludwig-Maximilians-Universität München
 IBE - Institut für medizinische Informationsverarbeitung,
 Biometrie und Epidemiologie
 Marchioninistr. 15, D-81377 Muenchen
 URL: http://ibe.web.med.uni-muenchen.de
 Mail: Markus.Schmidberger [at] ibe.med.uni-muenchen.de

 __
 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
 and provide commented, minimal, self-contained, reproducible code.


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help on replacing values

2007-09-07 Thread darteta001
Thanks a lot Gabor, that was very helpful. All sorted now!

Best

David

 Your columns are factors, not character strings.  Use as.is = TRUE as
 an argument to read.table.   Also its a bit dangerous to use T 
although
 not wrong.  Its safer to use TRUE.
 
 On 9/7/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
  Dear List,
 
  I have a newbie question. I have read in a data.frame as follows:
 
   data = read.table(table.txt, header = T)
   data
   X1 X2 X3 X4
  A AB AC AB AC
  B AB AC AA AB
  C AA AB AA AB
  D AA AB AB AC
  E AB AA AA AB
  F AB AA AB AC
  B AB AC AB AA
 
  I would like to replace AA values by BB in column X2. I have tried
  using replace() with no success, although I am not sure this is the
  right function. This is the code I have used:
 
  data$X2 - replace(data$X2, data$X2 ==AA,BB)
  Warning message:
  invalid factor level, NAs generated in: `[-.factor`(`*tmp*`, list,
  value = BB)
 
  What is wrong with the code? How can I get this done? how about
  changing AA values by BB in all 4 columns simultaneously? Actually
  this is a small example dataframe, the real one would have about 
1000
  columns.
 
  Extendind this, I found a similar thread dated July 2006 that used
  replace() on iris dataset, but I have tried reproducing it 
obtaining
  same warning message
 
   iris$Species - replace(iris$Species, iris$Species
  == setosa,NewName)
  Warning message:
  invalid factor level, NAs generated in: `[-.factor`(`*tmp*`, list,
  value = NewName)
 
  Thanks in advance your help,
 
  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
  and provide commented, minimal, self-contained, reproducible code.
 


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] text in boxplots

2007-09-07 Thread Greg Snow
The posting guide (a link at the bottom of every e-mail from the list)
suggests including a small example of what you are trying to do.
Without an example, we have to guess at what you are trying to do.

I am still guessing since you still did not include an example.  It
appears that part of the problem may be that the scatterplot function
from the car package does not leave the user coordinate system in a
state that matches intuitively with the data.  Your call to text is
probably placing the text outside of the plotting region where it is not
visible (possibly even in someone elses cubicle/office).  The mtext
function is not affected as much by this since it uses a different
coordinate system (based on the margins rather than the user
coordinates).

To place text on the plot, you need to find the cooresponding
coordinates.  There are a few different ways to do this:

1. use par('usr') to find out what the current user coordinates are and
compute your coordinates based on that.
2. use par(usr=c(...)) to set the user coordinates to match where you
want to plot.
3. use the locator function to interactively choose the locations and
use the resulting coordinates.
4. use the cnvrt.coords function from the TeachingDemos package to
convert from figure or device coordinates to the current user coordinate
system.
5. contact the author of the function and ask him to set the user
coordinates to something more intuitive before exiting and wait for the
change.

Look at the help for par for more information, specifically look at the
'usr' entry and possibly the 'xpd' entry if you want to add text to the
marginal boxplots.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Yves Moisan
 Sent: Friday, September 07, 2007 5:05 AM
 To: r-help@stat.math.ethz.ch
 Subject: Re: [R] text in boxplots
 
 
 Hi Greg,
 
 Actually, I'm using the scatterplot function in the car 
 namespace.  My understanding is that the scatterplot is 
 turned into a boxplot when the x variable is a factor, but I 
 can't see that in the code of the function. 
 I've successfully modified the function to output regression 
 stats (R^^2,
 etc.) with the method 'text', but I can't seem to get any 
 text printed when the result of a call to scatterplot is a 
 bunch of boxplots.  
 
 I don't know how boxplots end up being generated (I like it 
 though) in a call to car:scatterplot.  The same data in ggobi 
 would show the standard
 scatterplot with data aligned vertically in lines along the 
 values of the x
 (factor) variable but car:scatterplot draws nice boxes around 
 the data as a bonus.  I guess I'll need to follow with some 
 debugging tool.  I find it odd that mtext works though.  Or 
 maybe some graphics parameter is set such that text doesn't show.
 
 Thanx Greg.
 --
 View this message in context: 
 http://www.nabble.com/text-in-boxplots-tf4394528.html#a12553104
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] ploting missing data

2007-09-07 Thread Peter Dalgaard
Markus Schmidberger wrote:
 Hello,

 I have this kind of dataframe and have to plot it.

 data - data.frame(sw= c(1,2,3,4,5,6,7,8,9,10,11,12,15),
 zehn = 
 c(33.44,20.67,18.20,18.19,17.89,19.65,20.05,19.87,20.55,22.53,NA,NA,NA),
  zwanzig = 
 c(61.42,NA,26.60,23.28,NA,24.90,24.47,24.53,26.41,28.26,NA,29.80,35.49),
  fuenfzig =
 c(162.51,66.08,49.55,43.40,NA,37.77,35.53,36.46,37.25,37.66,NA,42.29,47.80) 
 )

 The plot should have lines:
 lines(fuenfzig~sw, data=data)
 lines(zwanzig~sw, data=data)

 But now I have holes in my lines for the missing values (NA). How to 
 plot the lines without the holes?
 The missing values should be interpolated or the left and right point 
 directly connected. The function approx interpolates the whole dataset. 
 Thats not my goal!
 Is there no plotting function to do this directly?

   
Just get rid of the NAs:

lines(fuenfzig~sw, data=data, subset=!is.na(fuenfzig))

-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] computing distance in miles or km between 2 street

2007-09-07 Thread Monica Pisica

 
Phil,
 
If you have only a list of addresses and nothing else - i have to recognize i 
am lost. But if you have more info you can use a GIS software and it will 
calculate your distance automatically for all your addresses. To have your 
distance in miles or Km you need to have a projection in your data which will 
establish your units.
 
The very basic principle is that for each address you have a set of 
coordinates, x, y and you actually use these to calculate distances. If your 
file is for exaple a point shape file (standard for ESRI ArcGIS products) you 
can very simply perform this task using either shortest driving route or as 
the crow flies - again depending on what other info you have in the file. A 
shape file is actually a group of files with with data attributes, projection 
info and so on - so even if you don't see xy coordinates, they actually are 
imbeded in the file.
 
I suspect Mapquest or any other mapping web product has a database with all 
those addresses with xy coordinates. The user needs to know only the address 
and behind doors there is an sql process which selects particular addresses 
together with all the other attributes attached to it and calculate distances 
because it knows coordinates, a network of roads and so on.
 
I am not sure this helps but at least maybe gives you some ideas where to look 
next.
Monica
 

Message: 53Date: Thu, 06 Sep 2007 14:42:32 -0400From: Philip James Smith 
[EMAIL PROTECTED]Subject: [R] computing distance in miles or km between 2 
streetaddressesTo: [EMAIL PROTECTED]: [EMAIL PROTECTED]Content-Type: 
text/plain; charset=ISO-8859-1; format=flowed Hi R-ers: I need to compute the 
distance between 2 street addresses in either km or miles. I do not care if the 
distance is a shortest driving route or if it is as the crow flies. Does 
anybody know how to do this? Can it be done in R? I have thousands of 
addresses, so I think that Mapquest is out of the question! Please rely to: 
[EMAIL PROTECTED] Thank you!Phil Smith  
_

 Hotmail®. NOW with 5GB storage.

ration_HM_mini_5G_0907
[[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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] text in boxplots

2007-09-07 Thread Yves Moisan



6. set the reset.par argument to FALSE in calling scatterplot as it
states in the documentation for scatterplot.  (still look at the help on
'xpd' argment to par if you want to add text to the margins).

Hi Greg,

That seems to have done it partly.  I set it to false once and then I could
see some text afterwards, even with reset.par set to TRUE.  

About my not following posting guidelines, I'm sorry but I thought my
question didn't require me to post code.  I suspected graphics parameter to
be off, so the question was why a difference between mtext and text.  Also,
I mentioned earlier that I had succeeded in writing text to the plot for
regression stats (in the reg function of scatterplot.formula) where I did
use what seem to be the normal tricks [e.g. par(usr)].  I couldn't figure
out why setting new graph variables in the main scatterplot.formula function
in the form of 

usrGlobal - par(usr) 

then calling

text(usrGlobal[2]-50,usrGlobal[4]-50,paste(Moyenne = ,r ...)

did not show any text whereas it did in the reg function.

But of course, pasting code could have been shorter for people to read ;-).

Thanx for your help.  
-- 
View this message in context: 
http://www.nabble.com/text-in-boxplots-tf4394528.html#a12558160
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] FW: variable format

2007-09-07 Thread Martin Becker
Dear Cory,

I am not familiar with SAS, but is this what you are looking for?

divisionTable - matrix(c(1, New England,
  2, Middle Atlantic,
  3, East North Central,
  4, West North Central,
  5, South Atlantic,
  6, East South Central,
  7, West South Central,
  8, Mountain,
  9, Pacific),
ncol=2, byrow=T)
a - NULL
a$divisionOld - c(0,1,2,3,4,5)
a$divisionNew - 
as.character(factor(a$divisionOld,levels=divisionTable[,1],labels=divisionTable[,2]))
a$divisionNew

[1] NA   New EnglandMiddle Atlantic  
[4] East North Central West North Central South Atlantic 


Kind regards,

  Martin


Cory Nissen schrieb:


 Anybody?  


 

 From: Cory Nissen
 Sent: Tue 9/4/2007 9:30 AM
 To: r-help@stat.math.ethz.ch
 Subject: variable format


 Okay, I want to do something similar to SAS proc format.

 I usually do this...

 a - NULL
 a$divisionOld - c(1,2,3,4,5)
 divisionTable - matrix(c(1, New England,
   2, Middle Atlantic,
   3, East North Central,
   4, West North Central,
   5, South Atlantic),
 ncol=2, byrow=T)
 a$divisionNew[match(a$divisionOld, divisionTable[,1])] - divisionTable[,2]

 But how do I handle the case where...
 a$divisionOld - c(0,1,2,3,4,5)   #no format available for 0, this throws an 
 error.
 OR
 divisionTable - matrix(c(1, New England,
   2, Middle Atlantic,
   3, East North Central,
   4, West North Central,
   5, South Atlantic,
   6, East South Central,
   7, West South Central,
   8, Mountain,
   9, Pacific),
 ncol=2, byrow=T)   
 There are extra formats available... this throws a warning.

 Thanks

 Cory

   [[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
 and provide commented, minimal, self-contained, reproducible code.


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] text in boxplots

2007-09-07 Thread Greg Snow

Looking at the help for scatterplot, it looks like there is a 6th option
(which is probably the preferred method):

6. set the reset.par argument to FALSE in calling scatterplot as it
states in the documentation for scatterplot.  (still look at the help on
'xpd' argment to par if you want to add text to the margins).

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Greg Snow
 Sent: Friday, September 07, 2007 9:01 AM
 To: Yves Moisan; r-help@stat.math.ethz.ch
 Subject: Re: [R] text in boxplots
 
 The posting guide (a link at the bottom of every e-mail from 
 the list) suggests including a small example of what you are 
 trying to do.
 Without an example, we have to guess at what you are trying to do.
 
 I am still guessing since you still did not include an 
 example.  It appears that part of the problem may be that the 
 scatterplot function from the car package does not leave the 
 user coordinate system in a state that matches intuitively 
 with the data.  Your call to text is probably placing the 
 text outside of the plotting region where it is not visible 
 (possibly even in someone elses cubicle/office).  The mtext 
 function is not affected as much by this since it uses a 
 different coordinate system (based on the margins rather than 
 the user coordinates).
 
 To place text on the plot, you need to find the cooresponding 
 coordinates.  There are a few different ways to do this:
 
 1. use par('usr') to find out what the current user 
 coordinates are and compute your coordinates based on that.
 2. use par(usr=c(...)) to set the user coordinates to match 
 where you want to plot.
 3. use the locator function to interactively choose the 
 locations and use the resulting coordinates.
 4. use the cnvrt.coords function from the TeachingDemos 
 package to convert from figure or device coordinates to the 
 current user coordinate system.
 5. contact the author of the function and ask him to set the 
 user coordinates to something more intuitive before exiting 
 and wait for the change.
 
 Look at the help for par for more information, specifically 
 look at the 'usr' entry and possibly the 'xpd' entry if you 
 want to add text to the marginal boxplots.
 
 --
 Gregory (Greg) L. Snow Ph.D.
 Statistical Data Center
 Intermountain Healthcare
 [EMAIL PROTECTED]
 (801) 408-8111
  
  
 
  -Original Message-
  From: [EMAIL PROTECTED] 
  [mailto:[EMAIL PROTECTED] On Behalf Of Yves Moisan
  Sent: Friday, September 07, 2007 5:05 AM
  To: r-help@stat.math.ethz.ch
  Subject: Re: [R] text in boxplots
  
  
  Hi Greg,
  
  Actually, I'm using the scatterplot function in the car 
 namespace.  My 
  understanding is that the scatterplot is turned into a boxplot when 
  the x variable is a factor, but I can't see that in the code of the 
  function.
  I've successfully modified the function to output regression stats 
  (R^^2,
  etc.) with the method 'text', but I can't seem to get any 
 text printed 
  when the result of a call to scatterplot is a bunch of boxplots.
  
  I don't know how boxplots end up being generated (I like it
  though) in a call to car:scatterplot.  The same data in ggobi would 
  show the standard
  scatterplot with data aligned vertically in lines along the 
 values of 
  the x
  (factor) variable but car:scatterplot draws nice boxes 
 around the data 
  as a bonus.  I guess I'll need to follow with some 
 debugging tool.  I 
  find it odd that mtext works though.  Or maybe some 
 graphics parameter 
  is set such that text doesn't show.
  
  Thanx Greg.
  --
  View this message in context: 
  http://www.nabble.com/text-in-boxplots-tf4394528.html#a12553104
  Sent from the R help mailing list archive at Nabble.com.
  
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 __
 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
 and provide commented, minimal, self-contained, reproducible code.


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Delete query in sqldf?

2007-09-07 Thread Gabor Grothendieck
Yes but delete does not return anything so its not useful.  In the devel
version of sqldf you can pass multiple command so try this using the
builtin data frame BOD noting that the record with demand = 8.3 was
removed:

 library(sqldf)
Loading required package: RSQLite
Loading required package: DBI
Loading required package: gsubfn
Loading required package: proto
 # overwrite with devel version of the sqldf.R file
 source(http://sqldf.googlecode.com/svn/trunk/R/sqldf.R;)
 sqldf(c(delete from BOD where demand = 8.3, select * from BOD))
  Time__1 demand
1   2   10.3
2   3   19.0
3   4   16.0
4   5   15.6
5   7   19.8


On 9/7/07, Paul Smith [EMAIL PROTECTED] wrote:
 Dear All,

 Is sqldf equipped with delete queries? I have tried delete queries but
 with no success.

 Thanks in advance,

 Paul

 __
 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
 and provide commented, minimal, self-contained, reproducible code.


__
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
and provide commented, minimal, self-contained, reproducible code.


  1   2   3   4   5   6   7   8   9   10   >