[R] zerinfl() vs. Stata's zinb

2010-04-12 Thread David Fortunato
Hello,

I am working with zero inflated models for a current project and I am
getting wildly different results from R's zeroinfl(y ~ x, dist=negbin)
command and Stata's zinb command. Does anyone know why this may be? I find
it odd considering that zeroinfl(y ~ x, dist=poisson) gives identical to
output to Stata's zip function.

Thanks,

--david

[[alternative HTML version deleted]]

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


[R] source(,echo=T) doesn't echo final comments

2010-04-12 Thread Kuhn, Alexandre (NIH/NIA/IRP) [V]
Hi,

source(file,echo=T) will not echo the last comment in file if it is the last 
line in the file.
For instance, when sourcing a file containing the following lines

#comment 1
a-1
#comment 2

R will echo

 #comment 1
 a-1

What is the solution to have R echo all of the comment lines?

Specific context:
This problem arises e.g. in the context of help files (.Rd) whose example 
section contains only code that is not to be run (\dontrun markup). Running the 
function example() (that itself calls source(,echo=TRUE)) on such a file will 
not display anything (because the code is commented out in the corersponding 
files in R-ex). Is that the desired behavior of example() or is there a 
workaround (i.e. to be able write help files with only dontrun code but that 
will nevertheless echo the examples)?

Thank you,
Alexandre Kuhn



 sessionInfo()
R version 2.10.1 (2009-12-14) 
i386-apple-darwin9.8.0 

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Error using reshape method

2010-04-12 Thread shmy

To be fair I don't really understand what the error is telling me so I don't
know how to correct it. 

I'm trying to reshape my data so that I do repeated measures ANOVA on it. 

The warning message: Error in d[, timevar] - times[1L] : subscript out of
bounds


The program:

library(QRMlib)
library(Hmisc)

  ss-5
  mu- c(0,2,3,12)
  mu2- c(0,2,10,20)
  dims- 4
  co-  c(.3,.4,.5,.4,.3,.2)
  replis- 3
  stdev-c(1,2,5,10)

   #1st set
  corrmat - matrix(1, dims, dims)
  corrmat[upper.tri(corrmat)]-co
  selectlow - lower.tri(corrmat)
  corrmat[selectlow] - t(corrmat)[selectlow]
  sigma- diag(stdev) %*% corrmat %*% diag(stdev)
  simu1-rmnorm(n=ss, Sigma=sigma, mu=mu, d=dims, rho=co)
  simu11-cbind(simu1,data.grp=1)
  #2nd set
  corrmat2 - matrix(1, dims, dims)
  corrmat2[upper.tri(corrmat2)]-co
  selectlow2 - lower.tri(corrmat2)
  corrmat2[selectlow2] - t(corrmat2)[selectlow2]
  sigma2- diag(stdev) %*% corrmat2 %*% diag(stdev)
  simu2-rmnorm(n=ss, Sigma=sigma2, mu=mu2, d=dims, rho=co)
  
  simu22-cbind( simu2,data.grp=2)
 
  data.all-rbind(simu11,simu22)
  new.data.all-rbind(data.all)
  
  data.all-rbind(data.all)
  
  data.frame(data.all)

  Y-cbind(data.all[,1], data.all[,2], data.all[,3], data.all[,4])

  rmlong.data-reshape(data.all,  varying=list(names(data.all)),
direction=long ) # Part that's giving me trouble.

Thank you for your help!
-- 
View this message in context: 
http://n4.nabble.com/Error-using-reshape-method-tp1837911p1837911.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] checking frequency in xts and zoo objects

2010-04-12 Thread Erin Hodgess
Dear R People:

When I have a time series, I can get the frequency of the series via tsp(x)[3].

Is there a similar function for xts and zoo objects, please?

Thanks,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

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


Re: [R] checking frequency in xts and zoo objects

2010-04-12 Thread Gabor Grothendieck
Note that the preferred way of doing this with ts series is to use the
frequency() function rather than using tsp.   That function also works
for zoo objects.

On Mon, Apr 12, 2010 at 11:20 PM, Erin Hodgess erinm.hodg...@gmail.com wrote:
 Dear R People:

 When I have a time series, I can get the frequency of the series via 
 tsp(x)[3].

 Is there a similar function for xts and zoo objects, please?

 Thanks,
 Erin


 --
 Erin Hodgess
 Associate Professor
 Department of Computer and Mathematical Sciences
 University of Houston - Downtown
 mailto: erinm.hodg...@gmail.com

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


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


Re: [R] checking frequency in xts and zoo objects

2010-04-12 Thread Erin Hodgess
Thank you!

Here is something that I just ran into.  I have a business day series,
spc, which I obtained using get.hist.quote.

When I tried frequency(spc), I got 1.


 str(spc)
‘zoo’ series from 1998-01-02 to 2010-04-09
  Data: num [1:3086, 1] 975 977 967 964 956 ...
 - attr(*, dimnames)=List of 2
  ..$ : NULL
  ..$ : chr Close
  Index: Class 'Date'  num [1:3086] 10228 10231 10232 10233 10234 ...
 frequency(spc)
[1] 1


Am I doing something wrong(high probability) or maybe frequency does
not work the same with business day data, please?

Thanks,
Erin



On Mon, Apr 12, 2010 at 10:29 PM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 Note that the preferred way of doing this with ts series is to use the
 frequency() function rather than using tsp.   That function also works
 for zoo objects.

 On Mon, Apr 12, 2010 at 11:20 PM, Erin Hodgess erinm.hodg...@gmail.com 
 wrote:
 Dear R People:

 When I have a time series, I can get the frequency of the series via 
 tsp(x)[3].

 Is there a similar function for xts and zoo objects, please?

 Thanks,
 Erin


 --
 Erin Hodgess
 Associate Professor
 Department of Computer and Mathematical Sciences
 University of Houston - Downtown
 mailto: erinm.hodg...@gmail.com

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





-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

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


Re: [R] checking frequency in xts and zoo objects

2010-04-12 Thread Gabor Grothendieck
1 is the correct answer.  The difference between successive time
values, deltat, is 1 or a multiple of 1 and frequency is the
reciprocal of deltat.

On Mon, Apr 12, 2010 at 11:46 PM, Erin Hodgess erinm.hodg...@gmail.com wrote:
 Thank you!

 Here is something that I just ran into.  I have a business day series,
 spc, which I obtained using get.hist.quote.

 When I tried frequency(spc), I got 1.


 str(spc)
 ‘zoo’ series from 1998-01-02 to 2010-04-09
  Data: num [1:3086, 1] 975 977 967 964 956 ...
  - attr(*, dimnames)=List of 2
  ..$ : NULL
  ..$ : chr Close
  Index: Class 'Date'  num [1:3086] 10228 10231 10232 10233 10234 ...
 frequency(spc)
 [1] 1


 Am I doing something wrong(high probability) or maybe frequency does
 not work the same with business day data, please?

 Thanks,
 Erin



 On Mon, Apr 12, 2010 at 10:29 PM, Gabor Grothendieck
 ggrothendi...@gmail.com wrote:
 Note that the preferred way of doing this with ts series is to use the
 frequency() function rather than using tsp.   That function also works
 for zoo objects.

 On Mon, Apr 12, 2010 at 11:20 PM, Erin Hodgess erinm.hodg...@gmail.com 
 wrote:
 Dear R People:

 When I have a time series, I can get the frequency of the series via 
 tsp(x)[3].

 Is there a similar function for xts and zoo objects, please?

 Thanks,
 Erin


 --
 Erin Hodgess
 Associate Professor
 Department of Computer and Mathematical Sciences
 University of Houston - Downtown
 mailto: erinm.hodg...@gmail.com

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





 --
 Erin Hodgess
 Associate Professor
 Department of Computer and Mathematical Sciences
 University of Houston - Downtown
 mailto: erinm.hodg...@gmail.com


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


Re: [R] Binning Question

2010-04-12 Thread David Winsemius


On Apr 12, 2010, at 9:07 PM, Noah Silverman wrote:


Hi,

I'm trying to setup some complicated binning with statistics and could
use a little help.

I've found the bin2 function from the ash package, but it doesn't do
everything I need.  My intention is to copy some of their code and  
then

modify as needed.

I have a vector of two columns:

head(data)
 r1  r2
[1,]  0.03516559  0.03102128
[2,]  0.02162539  0.14847034
[3,]  0.02210339  0.06539623
[4,] -0.07547792 -0.08859678
[5,]  0.03655620  0.05412436
[6,]  0.06513828  0.06053050


I'd like to create a 2 dimension list of bins with the frequency  
counts

for each bin.  The bin2 function does this.  Then it gets interesting.

I'd like to add a column to my vector that has the bin label for the
bin that row would belong to.  (I can see how to do this with lots of
nasty loops and greater-than, less-than calculations, but that gets
messy.)  There must be an easier way.


Lets say you used the example in bin2:

dat - as.data.frame(matrix( rnorm(200), 100 , 2)) # bivariate normal  
n=100


ab - matrix( c(-5,-5,5,5), 2, 2) # interval [-5,5) x [-5,5)
nbin - c( 20, 20) # 400 bins
bins - bin2(dat, ab, nbin) # bin counts,ab,nskip

dat$r1.cat - cut(dat[,1],  breaks=seq(ab[1,1], ab[1,2],  
length.out=nbin[1]+1 ) )
dat$r2.cat - cut(dat[,2], breaks=seq(ab[1,1], ab[1,2],  
length.out=nbin[1]+1))
dat$bicat - with(dat, paste( as.numeric(r1.cat), as.numeric(r2.cat),  
sep=.))


Or leave off the as.numeric if you want the labels to be more cut- 
like.





So, If I made 10 bins for each column (r1,r2), I'd have 100 bins.
(bin1, bin2, bin3, etc.)  I want to label each ROW in my data set with
the bin it would belong to.  (I intend to do more work with them after
this, but this starts.  Each row gets transformed depending on the bin
it belongs to, etc..)

Thanks,

-N

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


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


[R] Help required with png graphic production as text has shadows?

2010-04-12 Thread Alice Johnstone
I have produced a series of graphs with the png command, however when I have 
finally printed these out the black text appears to have a colour shadow with 
blue or red on either side of the letter.
I tried increasing my res to 1200 and this improved it somewhat, but the text 
is still not sharp and occassionally these shadows will still print.

I initially thought this was an issue with the printer.. But I can produce a 
pdf image and it is sharp.  However as I have 50+ images I want to include in a 
word document the pdf files are much too large and was the reason I was using 
png.

I am using an older version of R, but didn't want to upgrade as this may cause 
issues with my completed analyses and the potential changes to other functions.

Can someone suggest what it is I have missed?
Thank you very much.

Alice Johnstone

Example code:
Png(volcano.png,units=cm,height=15,width=15,res=1200,pointsize=12)
Volcano2(fit2.eb,coef=2,highlight=5,xlab=log fold change,ylab=log 
odds,pch=16,cex=0.5, main=Volcano Plot,xlim=c(-2,2))
Dev.off()


 sessionInfo()
R version 2.8.0 (2008-10-20)
i386-pc-mingw32

locale:
LC_COLLATE=English_New Zealand.1252;LC_CTYPE=English_New 
Zealand.1252;LC_MONETARY=English_New 
Zealand.1252;LC_NUMERIC=C;LC_TIME=English_New Zealand.1252

attached base packages:
 [1] grid  splines   tools stats graphics  grDevices utils
 [8] datasets  methods   base

other attached packages:
 [1] affyQCReport_1.20.0   arrayQualityMetrics_1.8.1
 [3] marray_1.20.0 beadarray_1.10.0
 [5] hwriter_0.93  latticeExtra_0.5-4
 [7] simpleaffy_2.18.0 affyPLM_1.18.0
 [9] preprocessCore_1.4.0  RColorBrewer_1.0-2
[11] vsn_3.8.0 genefilter_1.22.0
[13] survival_2.34-1   geneplotter_1.20.0
[15] annotate_1.20.0   xtable_1.5-4
[17] lattice_0.17-15   sma_0.5.15
[19] rat2302probe_2.3.0rat2302cdf_2.3.0
[21] rat2302.db_2.2.5  RSQLite_0.7-1
[23] DBI_0.2-4 AnnotationDbi_1.4.0
[25] MASS_7.2-44   gcrma_2.14.0
[27] matchprobes_1.14.0affy_1.20.0
[29] Biobase_2.2.0 limma_2.16.2
[31] gplots_2.6.0  gdata_2.4.2
[33] gtools_2.5.0

loaded via a namespace (and not attached):
[1] affyio_1.10.0  KernSmooth_2.22-22

P Think before you print
This e-mail transmission and any attachments that accompany it may contain 
information that is privileged, confidential or otherwise exempt from 
disclosure under applicable law and is intended solely for the use of the 
individual(s) to whom it was intended to be addressed.
If you have received this e-mail by mistake, or you are not the intended 
recipient, any disclosure, dissemination, distribution, copying or other use or 
retention of this communication or its substance is prohibited. If you have 
received this communication in error, please immediately reply to the author 
via e-mail that you received this message by mistake and also permanently 
delete the original and all copies of this e-mail and any attachments from your 
computer. Thank you.

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


Re: [R] Binning Question

2010-04-12 Thread Noah Silverman

David,

That helps me a lot.  Thanks!!!

-N



On 4/12/10 9:06 PM, David Winsemius wrote:
dat - as.data.frame(matrix( rnorm(200), 100 , 2)) # bivariate normal 
n=100


ab - matrix( c(-5,-5,5,5), 2, 2) # interval [-5,5) x [-5,5)
nbin - c( 20, 20) # 400 bins
bins - bin2(dat, ab, nbin) # bin counts,ab,nskip

dat$r1.cat - cut(dat[,1],  breaks=seq(ab[1,1], ab[1,2], 
length.out=nbin[1]+1 ) )
dat$r2.cat - cut(dat[,2], breaks=seq(ab[1,1], ab[1,2], 
length.out=nbin[1]+1))
dat$bicat - with(dat, paste( as.numeric(r1.cat), as.numeric(r2.cat), 
sep=.)) 


That's great, however something isn't coming out right.

I pasted your code into R and it looks like I'm getting different 
numbers bicat.  Should


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


[R] gnls for negative autocorrelation?

2010-04-12 Thread Seth

Hi,

I have data with negative spatial autocorrelation at short lags.  It is well
described by a spherical model, but flipped upside from what is normally
seen.  It seems that gnls will work with this correlated residual type IF
one parameter in the spherical model can be negative (it is usually
positive).  Does anyone know if this parameter is constrained to be
positive? -seth
-- 
View this message in context: 
http://n4.nabble.com/gnls-for-negative-autocorrelation-tp1838023p1838023.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] can not execute two functions - env() and profile()

2010-04-12 Thread Mao Jianfeng
Dear R-helpers

I want to express my respect and thankfulness to all of you.

When I tried to follow a draft book on lme4 authored by Prof. Doug.
Bates (http://lme4.r-forge.r-project.org/book/) to learn how to fit
mixed-effects model, I found I can not execute two functions which
listed in the book chapters.


For example, in the Chapter 1 of that book there are two lines of R
code, which are:

env(fm1ML)$Lambda # page 14

pr1 - profile(fm1ML) # page 16

I got

there is no env function in R and

error: UseMethod(profile) : profile can not find the available
methods for the object mer

I need to know how can I execute these functions properly in my PC.
Thanks for your helps and advice in advance.

Following is my system info.

 R.version
   _
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  10.1
year   2009
month  12
day14
svn rev50720
language   R
version.string R version 2.10.1 (2009-12-14)


Jian-Feng, Mao
the Institute of Botany, CAS
Beijing, China

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


Re: [R] MCMC results into LaTeX

2010-04-12 Thread Dieter Menne


Shige Song wrote:
 
 
 What is the preferred way to get Bayesian analysis results (such as
 those from MCMCpacki, MCMCglmm, and DPpackage) into LaTeX table
 automatically?
 

It depends on what you want as output. Let's assume the summary of an
MCMCpack function:
First direct it to a variable, and check the available data frames. Then
output these with latex.

If you do this very often: latex is a generic, so you could write a simple
function that creates customized output for a class summary.mcmc. For
example, it could output both statistics and quantiles together, and do
reasonable rounding based on the standard errors.

Dieter


library(MCMCpack)
library(Hmisc)
x-rep(1:10,5)
y-rnorm(50,mean=x)
qreg - summary(MCMCquantreg(y~x))
str(qreg)
#List of 6
# $ statistics: num [1:3, 1:4] 0.3479 0.9029 0.3413 0.2602 0.0391 ...
#  ..- attr(*, dimnames)=List of 2
#  .. ..$ : chr [1:3] (Intercept) x sigma
#  .. ..$ : chr [1:4] Mean SD Naive SE Time-series SE
# $ quantiles : num [1:3, 1:5] -0.139 0.825 0.257 0.168 0.878 ...
#  ..- attr(*, dimnames)=List of 2
#  .. ..$ : chr [1:3] (Intercept) x sigma
#  .. ..$ : chr [1:5] 2.5% 25% 50% 75% ...
...
# - attr(*, class)= chr summary.mcmc

latex(qreg$statistics,file=)
latex(qreg$quantiles,file=)

-- 
View this message in context: 
http://n4.nabble.com/MCMC-results-into-LaTeX-tp1836393p1836723.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] two problems on R in Ubuntu linux

2010-04-12 Thread Mao Jianfeng
Dear R-helpers

I want to express my respect and thankfulness to all of you.

I just switch from windows xp to Ubuntu linux platform. I am facing
two problems when I run R in Ubuntu.

I need your helps and advice, thanks in advance.

---
1. JGR() can not be loaded in R session properly

when I load JGR package in R, I got:
--
 library(JGR)
Loading required package: rJava
Loading required package: JavaGD
Loading required package: iplots
Error in .jnew(org/rosuda/iplots/Framework) :
  java.awt.AWTError: Cannot load AWT toolkit: gnu.java.awt.peer.gtk.GtkToolkit
Error: package 'iplots' could not be loaded

note: Tcl/Tk interface can be loaded by R automatically.

Loading Tcl/Tk interface ... done

--
2. demo() just can return a blank window-board

when I execute demo(graphics) and hit Return, I just got a blank prompt.
---
 demo(graphics)


demo(graphics)
 

Type  Return   to start :

 require(datasets)

 require(grDevices); require(graphics)

 ## Here is some code which illustrates some of the differences between
 ## R and S graphics capabilities.  Note that colors are generally specified
 ## by a character string name (taken from the X11 rgb.txt file) and that line
 ## textures are given similarly.  The parameter bg sets the background
 ## parameter for the plot and there is also an fg parameter which sets
 ## the foreground color.


 x - stats::rnorm(50)

 opar - par(bg = white)

 plot(x, ann = FALSE, type = n)
Hit Return to see next plot:
Error in plot.new() : attempt to plot on null device
-

Yours,

Jian-Feng, Mao
the Institute of Botany, CAS
Beijing, China

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


[R] make.groups function of laatice is not working?

2010-04-12 Thread newbie_2010

I almost wasted 3 hours to make lattice functions work. :(. Phew!

I installed package lattice, lattice extra and other supportive packages to
use functions 
1.make.groups 2.forplot 3.xyplot.
I also tried local installing. They are installing very well but not
working? Any one have any idea why R is giving me hard time! thanx in
advance.


I'm getting the following errors
Error: could not find function make.groups
Error: could not find function xyplot
Error: could not find function forplot
-- 
View this message in context: 
http://n4.nabble.com/make-groups-function-of-laatice-is-not-working-tp1836726p1836726.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] simple question about contrasts, lm and factors

2010-04-12 Thread Dieter Menne


David.Epstein wrote:
 
 I have a data frame with two variables that are factors. One is actually a
 TRUE/FALSE factor, and I have coded it as 1/0, a continuous variable, but
 I could turn it back into a factor. The second is an ordered factor and
 consists of five timepoints. There are several continuous variables as
 well. Now I want to fit a linear model to my data, using lm (or another R
 procedure if recommended).
 
 Question: should I use polynomial contrasts? My timepoints are very far
 from being evenly spaced, so ordinary R contrasts seem more natural. 
 

My first choice would be to use time as continuous, and do a plot(lm(...))
of the simple linear regression to check if the residuals are reasonable. In
the majority of case (in medicine/biology), variance is so large with 5 data
points that the linearity assumption is reasonable.


David.Epstein wrote:
 
 I also want to choose my base value. In the first call to lm, I want to
 choose base value equal to FirstTimePoint.
 In my second call to lm, I want to choose base value to be the interaction
 term FirstTimePoint:FALSE or FirstTimePoint:0.
 

If you have something like a growth curve of a plant that starts near zero,
and zero has a useful meaning in the context, use the original data.
Interpretation is easier.

If you have data of patients in the age range of 50 to 80, age zero makes no
sense, and using the original data can lead to nasty correlations between
estimates of slope an intercept. You could use age-median(age) or
age-mean(age) as the new variable. Since the assumption is not very
critical, I tend to use a nearby nice value instead; so if the median is 63
year, use 65, which give the (Intercept) a nice-to-remember meaning.

Dieter








-- 
View this message in context: 
http://n4.nabble.com/simple-question-about-contrasts-lm-and-factors-tp1835964p1836729.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] N'th of month working day problem

2010-04-12 Thread Research
Dear Gabor,

Thanks for your reply. however:

  tail(DJd)
^DJI.Close
2010-04-01   10927.07
2010-04-05   10973.55
2010-04-06   10969.99
2010-04-07   10897.52
2010-04-08   10927.07
*2010-04-09   10997.35*
  tail(ag)

2009-11-30 10344.84
2009-12-31 10428.05
2010-01-31 10067.33
2010-02-28 10325.26
2010-03-31 10856.63
*2010-04-30 10997.35
*
It seems the script makes up dates (?)

Best,
Costas

On 09/04/2010 14:55, Gabor Grothendieck wrote:
 The function seems to be working properly.  You are asking for a day
 of the month which does not exist. I assume this was written a very
 long time ago since there are easier ways to do this now.  yearmon
 class gives an object representing the year and month of a date and if
 ym is such an object then as.Date(ym) gives the first of the month and
 as.Date(ym, frac = 1) gives the last of the month so:

 # nth day of month or last day of month if less
 nth.of.month- function(date, n) {
   ym- as.yearmon(date)
   pmin(as.Date(ym) + n - 1, as.Date(ym, frac = 1))
 }

 ag- aggregate(DJd, nth.of.month(time(DJd), 31), tail, 1)



 On Fri, Apr 9, 2010 at 7:01 AM, Researchrisk2...@ath.forthnet.gr  wrote:

 Dear all,

 Some time ago I received some very kind  help (special thanks to Gabor) to
 construct a function that isolates the n'th   working day of each month for
 zoo object (time series) to create monthly data from daily observations.

 I found out that the code works fine except for the 29 till 31st dates of
 each month as it skips some months (February for example).

 If  you could help me isolate the problem I would be grateful as I can not
 find a way to explain to R to keep the last  working day of month if I
 choose the 29th, 30th or 31st dates...

 I enclose  a working version of the function and a script for demo purposes.

 Many thanks in advance,
 Costas

 library(fImport)
 library(zoo)
 DJ-yahooSeries(^DJI, frequency=daily, nDaysBack=1)
 DJd-as.zoo(DJ[,4])

 ### Choose number of day for month

 chooseday-function(z, day)

 {

 # z.na is same as z but with missing days added using NAs
 # Its formed by merging z with a zoo-width series containing all days.

 rng- range(time(z))
 z.na- merge(z, zoo(, seq(rng[1], rng[2], by = day)))

 # form a series that has NAs wherever z.na does but has 1, 2, 3, ...
 # instead of z.na's data values and then use na.locf to fill in NAs

 idx- na.locf(seq_along(z.na) + (0 * z.na))

 # pick off elements of z.na corresponding to i'th of month

 noofday- paste(day)

 if (day10) noofday-paste(0,day, sep=)

 tempdata-z.na[idx[format(time(z.na), %d) == noofday]]

 return(tempdata)

 }

 length(chooseday(DJd,1))
 length(chooseday(DJd,2))
 length(chooseday(DJd,31))
 length(chooseday(DJd,30))
 length(chooseday(DJd,29))
 length(chooseday(DJd,28))
 tail(chooseday(DJd,31))







  



[[alternative HTML version deleted]]

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


Re: [R] make.groups function of laatice is not working?

2010-04-12 Thread David Winsemius


On Apr 12, 2010, at 1:35 AM, newbie_2010 wrote:



I almost wasted 3 hours to make lattice functions work. :(. Phew!

I installed package lattice, lattice extra and other supportive  
packages to

use functions


I thought lattice was now part of the default installation? It's not  
lattice extra, it's latticeExtra. Other packages? Learn to  
communicate with greater precision.




1.make.groups 2.forplot 3.xyplot.
I also tried local installing. They are installing very well but not
working? Any one have any idea why R is giving me hard time! thanx in
advance.


I'm getting the following errors
Error: could not find function make.groups
Error: could not find function xyplot
Error: could not find function forplot


From the console did you also do one of these two methods of loading  
the package:


require(lattice)
library(lattice)


???
--
David


--
View this message in context: 
http://n4.nabble.com/make-groups-function-of-laatice-is-not-working-tp1836726p1836726.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] how to calculate a table

2010-04-12 Thread Dieter Menne


Bernd Dittmann wrote:
 
 (Sample boot code see below)
 ...
 So far so good. But how can I bring it into table-form whereby the
 combination of all 10 different weights (setting steps as 1) and their
 respective bootstrapped means are printed:
 
 weights   mean.boot
 1 
 2 
 ...   
 10
 
 

Divide et impera.

Dieter

x - rnorm(100, mean=100, sd=4)
y - rnorm(100, mean=120, sd=10)

# Step 1: use a variables instead of  constants
n1 = 8
maxn = 10
portfolio - c(rep(x, n1), rep(y, maxn-n1))
mean.boot - function(z){
  mean(sapply(lapply(1:20, function(i)sample(z, replace=F, size=30)),mean))}
mean.boot(portfolio)


# Step 2 : Wrap it in a function and test it
meanBoot - function(n1) {
  portfolio - c(rep(x, n1), rep(y, 10-n1))
  mean.boot - function(z){
mean(sapply(lapply(1:20, function(i)sample(z, replace=F,
size=30)),mean))}
  mean.boot(portfolio)
}
# Test it
meanBoot(8)

# Step 3: The c-programmer's way
res = data.frame()
n1s =  1:(maxn-1)
for (n1 in n1s) {
  res - rbind(res,data.frame(n1 = n1, mean =meanBoot(n1)))
}  
res


# Room for improvement here: use one of the Xapply functions here, or 
# pre-allocate res if you have many data
lapply(n1s, meanBoot)
# ugly output, let's simplify
sapply(n1s, meanBoot)
# looks better, decorate it!
data.frame(n= n1s, mean=sapply(n1s, meanBoot))

-- 
View this message in context: 
http://n4.nabble.com/how-to-calculate-a-table-tp1836676p1836743.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] two problems on R in Ubuntu linux

2010-04-12 Thread Henrik Bengtsson
Always provide sessionInfo() and traceback() when reporting errors. /Henrik

On Mon, Apr 12, 2010 at 8:34 AM, Mao Jianfeng jianfeng@gmail.com wrote:
 Dear R-helpers

 I want to express my respect and thankfulness to all of you.

 I just switch from windows xp to Ubuntu linux platform. I am facing
 two problems when I run R in Ubuntu.

 I need your helps and advice, thanks in advance.

 ---
 1. JGR() can not be loaded in R session properly

 when I load JGR package in R, I got:
 --
 library(JGR)
 Loading required package: rJava
 Loading required package: JavaGD
 Loading required package: iplots
 Error in .jnew(org/rosuda/iplots/Framework) :
  java.awt.AWTError: Cannot load AWT toolkit: gnu.java.awt.peer.gtk.GtkToolkit
 Error: package 'iplots' could not be loaded

 note: Tcl/Tk interface can be loaded by R automatically.

 Loading Tcl/Tk interface ... done

 --
 2. demo() just can return a blank window-board

 when I execute demo(graphics) and hit Return, I just got a blank prompt.
 ---
 demo(graphics)


        demo(graphics)
         

 Type  Return   to start :

 require(datasets)

 require(grDevices); require(graphics)

 ## Here is some code which illustrates some of the differences between
 ## R and S graphics capabilities.  Note that colors are generally specified
 ## by a character string name (taken from the X11 rgb.txt file) and that line
 ## textures are given similarly.  The parameter bg sets the background
 ## parameter for the plot and there is also an fg parameter which sets
 ## the foreground color.


 x - stats::rnorm(50)

 opar - par(bg = white)

 plot(x, ann = FALSE, type = n)
 Hit Return to see next plot:
 Error in plot.new() : attempt to plot on null device
 -

 Yours,

 Jian-Feng, Mao
 the Institute of Botany, CAS
 Beijing, China

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


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


Re: [R] make.groups function of laatice is not working?

2010-04-12 Thread newbie_2010

 require(lattice) 
Loading required package: lattice
Error in library(package, lib.loc = lib.loc, character.only = TRUE,
logical.return = TRUE,  : 
  'lattice' is not a valid installed package
 library(lattice) 
Error in library(lattice) : 'lattice' is not a valid installed package
 


I got these errors after trying them
-- 
View this message in context: 
http://n4.nabble.com/make-groups-function-of-laatice-is-not-working-tp1836726p1836746.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to run Shapiro-Wilk test for each grouped variable?

2010-04-12 Thread Yvonnick Noel

Dear Iurie,


I want to run Shapiro-Wilk test for each variable in my dataset, each
grouped by variable groupFactor.

Note that, at least on a single dependent variable with a grouping variable, a 
possible simplification may arise when homogeneity of variances is assumed and 
reasonable. You may want to do a single normality test on group-centered data :

shapiro.test(residuals(lm(data[,1]~groupFactor)))


HTH,

Yvonnick Noel
University of Brittany, Rennes 2
France

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


Re: [R] using double loops and saving the data

2010-04-12 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 12.04.2010 07:14:14:

 
 
 David Winsemius wrote:
  
  
  
 I am guessing that the first time through when i= 5200 that i+1 is 
 indexing an entry that does not exist. What does str( Price[[1]] 
 [5200+1] ) return? What about str(Ca)?
  
  
 So what is supposed to happen when you try Ca[5200+1] - ... 
anything?
  
 Really?   I thought you said you had 5200 entries in Price?
  
  I am sorry, I should mention it earlier that there are initial numbers 
for
  Ca, Sh, Po and Price. Which means there are totally 5200+1 entries for
  each of them.
  I can get the answer that I want from str(Price[[1]][5200+1]) 
  but str(Ca) gave me all zeros  num [1:5201] 0 0 0 0 0 0 0 0 0 0 ...
  Ca[5200+1] = 0

You did not tell much more about your data and procedures. Each object 
type has some distinct way of indexing and you can not mix them up. 

x-1:10
 x[5]
[1] 5
 x[[5]]
[1] 5
 x[5,]
Error in x[5, ] : incorrect number of dimensions

 x-list(1:10)
 x[1]
[[1]]
 [1]  1  2  3  4  5  6  7  8  9 10

 x[5]
[[1]]
NULL

 x[[5]]
Error in x[[5]] : subscript out of bounds

 x[1][5]
[[1]]
NULL

 x[[1]][5]
[1] 5

Nobody except you has your data available, so without providing more clues 
you can not expect mor relevant answers.

Try str(your.objects) and maybe you could use debug to see how they are 
operating and changing through a cycle.

Regards
Petr
 
  
 You need to read the error message. And you need to offer better 
 information about the objects you are working with.
  
  -- 
 David.
  
   View this message in context:
  
http://n4.nabble.com/using-double-loops-and-saving-the-data-tp1836591p1836591.html

  Sent from the R help mailing list archive at Nabble.com.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
  
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
  
  
 
 -- 
 View this message in context: 
http://n4.nabble.com/using-double-loops-and-
 saving-the-data-tp1836591p1836690.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] make.groups function of laatice is not working?

2010-04-12 Thread David Winsemius


On Apr 12, 2010, at 2:20 AM, newbie_2010 wrote:




require(lattice)

Loading required package: lattice
Error in library(package, lib.loc = lib.loc, character.only = TRUE,
logical.return = TRUE,  :
 'lattice' is not a valid installed package

library(lattice)

Error in library(lattice) : 'lattice' is not a valid installed package


You will need to provide the information described in the Posting  
Guide as well as copying the commands used to make the failed  
installation.


--
David.





I got these errors after trying them
--
View this message in context: 
http://n4.nabble.com/make-groups-function-of-laatice-is-not-working-tp1836726p1836746.html
Sent from the R help mailing list archive at Nabble.com.

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


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


[R] graphical data representation after glmm, glmer

2010-04-12 Thread Kay Cichini

hello,

i ran a glmer for binomial data, with one (ordered) between and one within
subjects factor. now i was thinking of how to plot my dependent. 
i plotted the probablities (p=X(incidents)/n(observations)) for each group
of the between factor in a line chart, with its corresponding standard
deviations. these are huge. my model though yielded good effects, due to
regarding the between factor. now i wondered if it's the best solution to
show the sd's which might be somewhat misleading for represantation of data
analysed with a mixed model allowing for within subjects random factors.
is there a recommended way for represantation of data in such context.

tahnks a lot for any advise,
kay  
-- 
View this message in context: 
http://n4.nabble.com/graphical-data-representation-after-glmm-glmer-tp1836819p1836819.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] problems on JGR package and demo() function in Ubuntu linux

2010-04-12 Thread Mao Jianfeng
Dear R-helpers

I want to express my respect and thankfulness to all of you. I have
ever ask this question about one hour ago. Following Mr. Henrik
Bengtsson's advice I re-submit this query here.

I just switch from windows xp to Ubuntu linux platform. I am facingtwo
problems when I run R in Ubuntu.

I need your helps and advice, thanks in advance.

1. R session info
---
 sessionInfo()
R version 2.10.1 (2009-12-14)
i486-pc-linux-gnu

locale:
[1] en_US.UTF-8

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

other attached packages:
[1] JavaGD_0.5-2 rJava_0.8-3

loaded via a namespace (and not attached):
[1] tcltk_2.10.1 tools_2.10.1

2. problem 1: JGR package can not be loaded in R session properly
---
 library(JGR)
Loading required package: rJava
Loading required package: JavaGD
Loading required package: iplots
Error in .jnew(org/rosuda/iplots/Framework) :
 java.awt.AWTError: Cannot load AWT toolkit: gnu.java.awt.peer.gtk.GtkToolkit
Error: package 'iplots' could not be loaded
 traceback()
3: stop(gettextf(package '%s' could not be loaded, pkg), call. = FALSE,
  domain = NA)
2: .getRequiredPackages2(pkgInfo)
1: library(JGR)

3. problem 2: demo() just can return a blank window-board
---
 demo(graphics)


   demo(graphics)
    

Type  Return   to start :

 require(datasets)

 require(grDevices); require(graphics)

 ## Here is some code which illustrates some of the differences between
 ## R and S graphics capabilities.  Note that colors are generally specified
 ## by a character string name (taken from the X11 rgb.txt file) and that line
 ## textures are given similarly.  The parameter bg sets the background
 ## parameter for the plot and there is also an fg parameter which sets
 ## the foreground color.


 x - stats::rnorm(50)

 opar - par(bg = white)

 plot(x, ann = FALSE, type = n)
Hit Return to see next plot:
Error in plot.new() : attempt to plot on null device
 traceback()
7: plot.new()
6: plot.default(x, ann = FALSE, type = n)
5: plot(x, ann = FALSE, type = n)
4: eval.with.vis(expr, envir, enclos)
3: eval.with.vis(ei, envir)
2: source(available, echo = echo, max.deparse.length = Inf, keep.source = TRUE)
1: demo(graphics)
---


Yours,

Jian-Feng, Mao
the Institute of Botany, CAS
Beijing, China

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


[R] Interpreting factor*numeric interaction coefficients

2010-04-12 Thread Matthew Carroll
Dear all,
I am a relative novice with R, so please forgive any terrible errors...

I am working with a GLM that describes a response variable as a function of
a categorical variable with three levels and a continuous variable. These
two predictor variables are believed to interact.
An example of such a model follows at the bottom of this message, but here
is a section of its summary table:

   Estimate Std. Error z value Pr(|z|)  
(Intercept)1.220186 0.539475   2.262   0.0237 *
var1   0.028182 0.050850   0.554   0.5794  
cat2   -0.112454  0.781137  -0.144   0.8855  
cat3   0.339589   0.672828   0.505   0.6138  
var1:cat2  0.007091   0.068072   0.104   0.9170  
var1:cat3  -0.027248  0.064468  -0.423   0.6725  

I am having trouble interpreting this output.
I think I understand that:

# the 'var1' value refers to the slope of the relationship within the first
factor level

# the 'cat2' and 'cat3' values refer to the difference in intercept from
'cat1'

# the interaction terms describe the difference in slope between the
relationship in 'cat1' and that in 'cat2' and 'cat3' respectively

Therefore, if I wanted a single value to describe the slope in either cat2
or cat3, I would sum the interaction value with that of var1.

However, if I wanted to report a standard error for the slope in 'cat2', how
would I go about doing this? Is the reported standard error that for the
overall slope for that factor level, or is the actual standard error a
function of the standard error of var1 and that of the interaction?

Any help with this would be much appreciated,

Matthew Carroll


### example code

resp - rpois(30, 5)
cat - factor(rep(c(1:3), 10))
var1 - rnorm(30, 10, 3)

mod - glm(resp ~ var1 * cat, family=poisson)
summary(mod)

Call:
glm(formula = resp ~ var1 * cat, family = poisson)

Deviance Residuals: 
 Min1QMedian3Q   Max  
-1.80269  -0.54107  -0.06169   0.51819   1.58169  

Coefficients:
   Estimate Std. Error z value Pr(|z|)  
(Intercept)1.220186 0.539475   2.262   0.0237 *
var1   0.028182 0.050850   0.554   0.5794  
cat2   -0.112454  0.781137  -0.144   0.8855  
cat3   0.339589   0.672828   0.505   0.6138  
var1:cat2  0.007091   0.068072   0.104   0.9170  
var1:cat3  -0.027248  0.064468  -0.423   0.6725  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

(Dispersion parameter for poisson family taken to be 1)

Null deviance: 23.222  on 29  degrees of freedom Residual deviance:
22.192  on 24  degrees of freedom
AIC: 133.75

Number of Fisher Scoring iterations: 5



--
Matthew Carroll
E-mail: mjc...@york.ac.uk

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


[R] Problem writing netcdf data with Rclim

2010-04-12 Thread zow...@ncst.go.ke
Dear Users:
I am able to read the file precip.nc (CMAP monthly precip) using the Rclim 
package. How ever, when I try to write the data in a netcdf file, I get the 
following error about the missing value attribute:

 pcpmon-netcdfread(precip.nc,lon,lat,time,precip,unpack=T)

 
netcdfwrite(pcpmon$lon,pcpmon$lat,pcpmon$data,pcpmon.nc,pcpmon$time,mv=-99
9)
Error: Found NAs but no missing value attribute

I can't figure out the error in the missing value attribute. 

How ca I fix the error?

Thanks

ZABLONE OWITI
 GRADUATE STUDENT
Nanjing University of Information, Science and Technology
College of International Education
Add: 219 Ning Liu Rd, Nanjing, Jiangsu, 21004, P.R. China
Tel: +86-25-58731402
Fax: +86-25-58731456 
Mob. 15077895632
Website: www.nuist.edu.cn

 

[[alternative HTML version deleted]]

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


[R] rpart: Writing values of the leaves to a dateset

2010-04-12 Thread hhafner
I'm fitting a regression tree with rpart and I want to write the values 
for every leaf in a dataset. As an example take the variable turnover. 
Let's suppose my tree for turnover has 30 leaves and I want to have 30 
datasets with dataset 1 containing the turnover values of the units in 
leaf 1, dataset 2 containing turnover values for the observations in leaf 
2 and so on. How can I do this? 

Best regards,
Hans-Peter Hafner

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


Re: [R] Interpreting factor*numeric interaction coefficients

2010-04-12 Thread ONKELINX, Thierry
Dear Matthew,

The easiest way the get the estimates (and their standard error) for the
different slopes it to reparametrise your model. Use resp ~ var1 : cat +
0 instead of resp ~ var1 * cat

HTH,

Thierry



ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie  Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium

Research Institute for Nature and Forest
team Biometrics  Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium

tel. + 32 54/436 185
thierry.onkel...@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey
  

 -Oorspronkelijk bericht-
 Van: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] Namens Matthew Carroll
 Verzonden: maandag 12 april 2010 11:16
 Aan: r-help@r-project.org
 Onderwerp: [R] Interpreting factor*numeric interaction coefficients
 
 Dear all,
 I am a relative novice with R, so please forgive any terrible 
 errors...
 
 I am working with a GLM that describes a response variable as 
 a function of a categorical variable with three levels and a 
 continuous variable. These two predictor variables are 
 believed to interact.
 An example of such a model follows at the bottom of this 
 message, but here is a section of its summary table:
 
Estimate   Std. Error z value Pr(|z|)  
 (Intercept)1.220186   0.539475   2.262   0.0237 *
 var1   0.028182   0.050850   0.554   0.5794  
 cat2   -0.112454  0.781137  -0.144   0.8855  
 cat3   0.339589   0.672828   0.505   0.6138  
 var1:cat2  0.007091   0.068072   0.104   0.9170  
 var1:cat3  -0.027248  0.064468  -0.423   0.6725  
 
 I am having trouble interpreting this output.
 I think I understand that:
 
 # the 'var1' value refers to the slope of the relationship 
 within the first factor level
 
 # the 'cat2' and 'cat3' values refer to the difference in 
 intercept from 'cat1'
 
 # the interaction terms describe the difference in slope 
 between the relationship in 'cat1' and that in 'cat2' and 
 'cat3' respectively
 
 Therefore, if I wanted a single value to describe the slope 
 in either cat2 or cat3, I would sum the interaction value 
 with that of var1.
 
 However, if I wanted to report a standard error for the slope 
 in 'cat2', how would I go about doing this? Is the reported 
 standard error that for the overall slope for that factor 
 level, or is the actual standard error a function of the 
 standard error of var1 and that of the interaction?
 
 Any help with this would be much appreciated,
 
 Matthew Carroll
 
 
 ### example code
 
 resp - rpois(30, 5)
 cat - factor(rep(c(1:3), 10))
 var1 - rnorm(30, 10, 3)
 
 mod - glm(resp ~ var1 * cat, family=poisson)
 summary(mod)
 
 Call:
 glm(formula = resp ~ var1 * cat, family = poisson)
 
 Deviance Residuals: 
  Min1QMedian3Q   Max  
 -1.80269  -0.54107  -0.06169   0.51819   1.58169  
 
 Coefficients:
Estimate   Std. Error z value Pr(|z|)  
 (Intercept)1.220186   0.539475   2.262   0.0237 *
 var1   0.028182   0.050850   0.554   0.5794  
 cat2   -0.112454  0.781137  -0.144   0.8855  
 cat3   0.339589   0.672828   0.505   0.6138  
 var1:cat2  0.007091   0.068072   0.104   0.9170  
 var1:cat3  -0.027248  0.064468  -0.423   0.6725  
 ---
 Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
 
 (Dispersion parameter for poisson family taken to be 1)
 
 Null deviance: 23.222  on 29  degrees of freedom Residual 
 deviance:
 22.192  on 24  degrees of freedom
 AIC: 133.75
 
 Number of Fisher Scoring iterations: 5
 
 
 
 --
 Matthew Carroll
 E-mail: mjc...@york.ac.uk
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed document.

__

Re: [R] Interpreting factor*numeric interaction coefficients

2010-04-12 Thread Peter Ehlers

On 2010-04-12 3:15, Matthew Carroll wrote:

Dear all,
I am a relative novice with R, so please forgive any terrible errors...

I am working with a GLM that describes a response variable as a function of
a categorical variable with three levels and a continuous variable. These
two predictor variables are believed to interact.
An example of such a model follows at the bottom of this message, but here
is a section of its summary table:

EstimateStd. Error z value Pr(|z|)
(Intercept)1.220186 0.539475   2.262   0.0237 *
var1   0.028182 0.050850   0.554   0.5794
cat2   -0.112454  0.781137  -0.144   0.8855
cat3   0.339589   0.672828   0.505   0.6138
var1:cat2  0.007091   0.068072   0.104   0.9170
var1:cat3  -0.027248  0.064468  -0.423   0.6725

I am having trouble interpreting this output.
I think I understand that:

# the 'var1' value refers to the slope of the relationship within the first
factor level

# the 'cat2' and 'cat3' values refer to the difference in intercept from
'cat1'

# the interaction terms describe the difference in slope between the
relationship in 'cat1' and that in 'cat2' and 'cat3' respectively

Therefore, if I wanted a single value to describe the slope in either cat2
or cat3, I would sum the interaction value with that of var1.

However, if I wanted to report a standard error for the slope in 'cat2', how
would I go about doing this? Is the reported standard error that for the
overall slope for that factor level, or is the actual standard error a
function of the standard error of var1 and that of the interaction?



You can relevel your factor variable:

 mod - glm(resp ~ var1 * relevel(cat, ref=2), family=poisson)

Or, to do this for all levels, you can specify the model as:

 mod - glm(resp ~ cat/var1 + 0, family=poisson)

which will give the regressions resp ~ var1 within each level of 'cat'.

Or you can calculate the SE from the covariance matrix given
by summary(mod)$cov.unscaled, using the formula for the variance
of a linear combination of random variables.

 -Peter Ehlers


Any help with this would be much appreciated,

Matthew Carroll


### example code

resp- rpois(30, 5)
cat- factor(rep(c(1:3), 10))
var1- rnorm(30, 10, 3)

mod- glm(resp ~ var1 * cat, family=poisson)
summary(mod)

Call:
glm(formula = resp ~ var1 * cat, family = poisson)

Deviance Residuals:
  Min1QMedian3Q   Max
-1.80269  -0.54107  -0.06169   0.51819   1.58169

Coefficients:
EstimateStd. Error z value Pr(|z|)
(Intercept)1.220186 0.539475   2.262   0.0237 *
var1   0.028182 0.050850   0.554   0.5794
cat2   -0.112454  0.781137  -0.144   0.8855
cat3   0.339589   0.672828   0.505   0.6138
var1:cat2  0.007091   0.068072   0.104   0.9170
var1:cat3  -0.027248  0.064468  -0.423   0.6725
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for poisson family taken to be 1)

 Null deviance: 23.222  on 29  degrees of freedom Residual deviance:
22.192  on 24  degrees of freedom
AIC: 133.75

Number of Fisher Scoring iterations: 5



--
Matthew Carroll
E-mail: mjc...@york.ac.uk

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




--
Peter Ehlers
University of Calgary

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


Re: [R] using double loops and saving the data

2010-04-12 Thread ChinChin


Petr Pikal wrote:
 
 
 You did not tell much more about your data and procedures. Each object 
 type has some distinct way of indexing and you can not mix them up. 
 
 x-1:10
 x[5]
 [1] 5
 x[[5]]
 [1] 5
 x[5,]
 Error in x[5, ] : incorrect number of dimensions
 
 x-list(1:10)
 x[1]
 [[1]]
  [1]  1  2  3  4  5  6  7  8  9 10
 
 x[5]
 [[1]]
 NULL
 
 x[[5]]
 Error in x[[5]] : subscript out of bounds
 
 x[1][5]
 [[1]]
 NULL
 
 x[[1]][5]
 [1] 5
 
 Nobody except you has your data available, so without providing more clues 
 you can not expect mor relevant answers.
 
 Try str(your.objects) and maybe you could use debug to see how they are 
 operating and changing through a cycle.
 
 
I think I got what you mean, so that I can't use the 
Wealth1[[s]][i] - Ca[i+1]+Po[i+1]
in the last line of loops.

Is there any code I can use the store the data?
I aim to store the data like :
a - x1 x2 x3 x4 ...
and in each entry of a
x1 - 1  2  3  4  5  6  7  ...
the entries in x1 are the wealth that I want estimate.
Please tell me the code to store these type of data. Thanks. :)

actually I can create the Price[[i]] by coding Price = list() before I
simulate the price
 


-- 
View this message in context: 
http://n4.nabble.com/using-double-loops-and-saving-the-data-tp1836591p1836938.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] SAS like Macro variable substituion?

2010-04-12 Thread David Young
I'd like to use a string to refer to an R object with the end
objective of going through a loop and saving various files of the same
name with different contents using a numbered suffix.

# This will be the loop counter and file suffix.
master.i - 1

# This is the generic file name.
unislopes - c(1,2,3)

# This assigns the data to the correct file name unislopes1.
assign(paste(unislopes,master.i,sep=),unislopes)

# This is the problem.  The first parameter of the save function
requires an R object which I'm not sure how to reference using the
suffix 1.  The second part requires text so it can use the
paste function.
save((paste(unislopes,master.i,sep=),file=paste(unislopes,master.i,.Rdata,sep=))

Any ideas?





-- 
Best regards,

David Young
Marketing and Statistical Consultant
Madrid, Spain
+34 913 540 381
http://www.linkedin.com/in/europedavidyoung

  mailto:dyo...@telefonica.net

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


Re: [R] Peculiar behaviour with MatchIt and a function

2010-04-12 Thread Peter Ehlers

On 2010-04-11 14:27, Ajay Shah wrote:

Folks,

I have a strange situation where:

   library(MatchIt)
   f- function(d) {
 m- matchit(treatment ~ lsales + major.industry,
  data=d, method=nearest, discard=hull.treat)
 treatmentfirms- match.data(m, group=treat)
 list(m=m, treatmentfirms=treatmentfirms)
   }
   res- f(ex)

does not work at the match.data() call, while the identical lines within f() --

   m- matchit(treatment ~ lsales + major.industry,
data=ex, method=nearest, discard=hull.treat)
   treatmentfirms- match.data(m, group=treat)

work fine for the same data object.

The messages are:

 res- f(ex)
   Loading required package: WhatIf
   Loading required package: lpSolve
   ##  WhatIf (Version 1.5-5, built 2009-03-03)
   [1] Preprocessing data ...
   [1] Performing convex hull test ...
   [1] Calculating distances 
   [1] Note:  range of at least one variable equals zero
   [1] Calculating the geometric variance...
   [1] Calculating cumulative frequencies ...
   [1] Finishing up ...
   Error in eval(expr, envir, enclos) : object 'd' not found
   Calls: f -  match.data -  eval -  eval
   Execution halted

This seems rather strange to me: code that breaks only when you embed
it into a function.


Not so strange. The error message gives a clue: match.data()
can't find 'd'. It's looking in .GlobalEnv.

The first line of match.data() is

 data - eval(object$call$data)

Those who know more about environments will give you a more
definitive solution, but this works:

Make a copy of the function (rename it) and replace that
line with:

 data - eval(object$call$data, envir = parent.frame())

Then call your new function instead of match.data.

 -Peter Ehlers



The object ex follows:

ex- structure(list(treatment = c(FALSE, FALSE, FALSE, FALSE, TRUE,
FALSE, FALSE, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE,
TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE),
lsales = c(5.20384183832515, 1.37624402526639, 2.81480973767374,
5.71903226986308, 6.29885733086709, 3.08831145484708,
5.32904053919088, 5.40033229195477, 4.35939751661352,
-0.415515443961666, 2.63476240533238, 2.82137888640921,
4.6872108963243, 4.34782331333238, 3.43237299913060, 4.26927778123189,
5.62003848122324, -1.04982212449868, 4.43378856923247,
6.08748356653522, 6.86218243368738, 5.39235400847442,
5.98085850132076, -3.50655789731998, 5.12824053617052,
7.1604809332373, 3.61818871349117, 6.8765672836593, 5.36677009218248,
5.16724010294109, 3.24259235148552, 6.81891313625405,
5.47407576620032, 6.67389197588638, 3.56416620994030,
6.61972647976091, 2.65394594210901, 5.06132840841177,
7.05999556373764, 4.44064925381964, 3.14931136148229, 2.8142103969306,
5.7288977621346, 6.60762268613979, 3.56359963768718, 6.29395517958832,
3.89222837809997, 3.83189696094886, 6.66961229653402,
6.05067640673983, 5.62905892846026, 5.19567537457616,
6.40653339135884, 7.43230035913876, 8.38195291090277, 4.3892504797632,
3.69411572090918, 3.55620483720940, 9.09292414403762,
3.60848251704191, 5.35469769998414, 6.54049594607501,
2.74791173452734, 4.74013804639858, 4.03282370557385,
3.78168650370014, 4.1293899039649, 6.07617327503494, 5.52545293913178,
4.77457535084882, 4.00878667386045, 5.39098770138934, 5.6250638899448,
4.83095025862343, 6.16695029289265, 6.39422600364183,
5.69403512320132, 6.2385199184685, 6.47216080589246, 4.06782945656635,
5.07866770448808, 6.27081828505901, 5.35983570652645,
5.15490878325268, 5.50728085428841, 4.14630430115281, 6.2271491299165,
7.47595129411925, 3.64571095871256, 6.4379596281074, 5.37184659983615,
4.59249013283072, 7.09518045678513, 4.56611745872439,
5.00609165404638, 5.945917867152, 3.35060559554610, 4.49602473872729,
3.60032142713214, 6.20776473594018, 4.9152984472697, 3.61145830714535,
7.11999156172429, 5.42899469018965, 2.75684036527164,
4.57026813397883, 4.40146154731249, 0.932164081030445,
3.15870110183213, 6.8897847723275, 4.1568497675735, 5.44410459861402,
5.04516553699308, 5.6335388212676, 8.15003491746266, 6.45397139558334,
5.07779537593878, 4.89925670611287, 5.98883609575429,
5.82688467179018, 1.17557332980424, 7.70958196126712,
7.37534349346089, 5.07072644030655, 4.62556087563583), major.industry
= structure(c(12L, 12L, 11L, 4L, 5L, 4L, 12L, 1L, 7L, 9L, 5L, 11L, 5L,

Re: [R] SAS like Macro variable substituion?

2010-04-12 Thread Benilton Carvalho
save(list=paste(unislopes, master.i, sep=),
file=paste(unislopes,master.i,.Rdata,sep=))

On Mon, Apr 12, 2010 at 12:06 PM, David Young dyo...@telefonica.net wrote:
 I'd like to use a string to refer to an R object with the end
 objective of going through a loop and saving various files of the same
 name with different contents using a numbered suffix.

 # This will be the loop counter and file suffix.
 master.i - 1

 # This is the generic file name.
 unislopes - c(1,2,3)

 # This assigns the data to the correct file name unislopes1.
 assign(paste(unislopes,master.i,sep=),unislopes)

 # This is the problem.  The first parameter of the save function
 requires an R object which I'm not sure how to reference using the
 suffix 1.  The second part requires text so it can use the
 paste function.
 save((paste(unislopes,master.i,sep=),file=paste(unislopes,master.i,.Rdata,sep=))

 Any ideas?





 --
 Best regards,

 David Young
 Marketing and Statistical Consultant
 Madrid, Spain
 +34 913 540 381
 http://www.linkedin.com/in/europedavidyoung

                          mailto:dyo...@telefonica.net

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


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


Re: [R] SAS like Macro variable substituion?

2010-04-12 Thread Peter Ehlers

?get

On 2010-04-12 5:06, David Young wrote:

I'd like to use a string to refer to an R object with the end
objective of going through a loop and saving various files of the same
name with different contents using a numbered suffix.

# This will be the loop counter and file suffix.
master.i- 1

# This is the generic file name.
unislopes- c(1,2,3)

# This assigns the data to the correct file name unislopes1.
assign(paste(unislopes,master.i,sep=),unislopes)

# This is the problem.  The first parameter of the save function
requires an R object which I'm not sure how to reference using the
suffix 1.  The second part requires text so it can use the
paste function.
save((paste(unislopes,master.i,sep=),file=paste(unislopes,master.i,.Rdata,sep=))

Any ideas?







--
Peter Ehlers
University of Calgary

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


Re: [R] MCMC results into LaTeX

2010-04-12 Thread Shige Song
Dear Dieter,

That sounds like a good solution, thanks.

Shige

On Mon, Apr 12, 2010 at 2:27 AM, Dieter Menne
dieter.me...@menne-biomed.de wrote:


 Shige Song wrote:


 What is the preferred way to get Bayesian analysis results (such as
 those from MCMCpacki, MCMCglmm, and DPpackage) into LaTeX table
 automatically?


 It depends on what you want as output. Let's assume the summary of an
 MCMCpack function:
 First direct it to a variable, and check the available data frames. Then
 output these with latex.

 If you do this very often: latex is a generic, so you could write a simple
 function that creates customized output for a class summary.mcmc. For
 example, it could output both statistics and quantiles together, and do
 reasonable rounding based on the standard errors.

 Dieter


 library(MCMCpack)
 library(Hmisc)
 x-rep(1:10,5)
 y-rnorm(50,mean=x)
 qreg - summary(MCMCquantreg(y~x))
 str(qreg)
 #List of 6
 # $ statistics: num [1:3, 1:4] 0.3479 0.9029 0.3413 0.2602 0.0391 ...
 #  ..- attr(*, dimnames)=List of 2
 #  .. ..$ : chr [1:3] (Intercept) x sigma
 #  .. ..$ : chr [1:4] Mean SD Naive SE Time-series SE
 # $ quantiles : num [1:3, 1:5] -0.139 0.825 0.257 0.168 0.878 ...
 #  ..- attr(*, dimnames)=List of 2
 #  .. ..$ : chr [1:3] (Intercept) x sigma
 #  .. ..$ : chr [1:5] 2.5% 25% 50% 75% ...
 ...
 # - attr(*, class)= chr summary.mcmc

 latex(qreg$statistics,file=)
 latex(qreg$quantiles,file=)

 --
 View this message in context: 
 http://n4.nabble.com/MCMC-results-into-LaTeX-tp1836393p1836723.html
 Sent from the R help mailing list archive at Nabble.com.

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


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


[R] Matrix is not symmetric under lme4

2010-04-12 Thread Wkoef Slknfd









Dear all,
After I run package lme4 and function glmer, I got the error message as the 
following.
 Matrix is not symmetric under lme4 
 
Is it possiable to avoid this error when my data is huge? Or use the other 
package? Thank you.



  
[[alternative HTML version deleted]]

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


[R] Local R Training

2010-04-12 Thread Dominik Riva
Hello List,
 
I am new to R and statistics in general.
My two colleges and I would like to get some training in the proper
usage of R.
 
A quick internet search provided no results for the region of Basel in
Switzerland.
 
Does some one on this list knows of any trainers or schools in the
region in question or where to look next?
 
Regards,
 
 
Dominik Riva
Universitätsspital Basel
Med. Querschnittsfunktionen
Pathologie
Schoenbeinstrasse 40
CH-4031 Basel
Telefon 061 556 53 67
Cordless65367
E-Mail ri...@uhbs.ch

[[alternative HTML version deleted]]

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


Re: [R] N'th of month working day problem

2010-04-12 Thread Gabor Grothendieck
I assume what you want is not the last data value in each month
labelled with the nth day of the month (or the last day of the month
if there are fewer than n days) but the last day in the data that is
on or prior to the nth of the month.  If that is what you want then
try this.

nth.of.month - function(x, n = 31) {
tt - as.Date(time(x))
ix - as.numeric(format(tt, %d)) = n
last.ix - c(tapply(seq_along(ix), as.yearmon(tt), tail, 1))
if (length(dim(x)) == 2) x[last.ix,] else x[last.ix]
}
out - nth.of.month(DJd)

After converting to Date class ix is set to the be the logical vector
which is TRUE on or before the nth of the month and FALSE otherwise.
tapply is used to pick off the index of the last of these in each
month giving last.ix.  This is then used to subscript x.

Note that if there are no data points in a month on or prior to day n
of the month then no data for that month will appear.

On Mon, Apr 12, 2010 at 2:53 AM, Research risk2...@ath.forthnet.gr wrote:
 Dear Gabor,

 Thanks for your reply. however:

 tail(DJd)
    ^DJI.Close
 2010-04-01   10927.07
 2010-04-05   10973.55
 2010-04-06   10969.99
 2010-04-07   10897.52
 2010-04-08   10927.07
 2010-04-09   10997.35
 tail(ag)

 2009-11-30 10344.84
 2009-12-31 10428.05
 2010-01-31 10067.33
 2010-02-28 10325.26
 2010-03-31 10856.63
 2010-04-30 10997.35

 It seems the script makes up dates (?)

 Best,
 Costas

 On 09/04/2010 14:55, Gabor Grothendieck wrote:

 The function seems to be working properly.  You are asking for a day
 of the month which does not exist. I assume this was written a very
 long time ago since there are easier ways to do this now.  yearmon
 class gives an object representing the year and month of a date and if
 ym is such an object then as.Date(ym) gives the first of the month and
 as.Date(ym, frac = 1) gives the last of the month so:

 # nth day of month or last day of month if less
 nth.of.month - function(date, n) {
   ym - as.yearmon(date)
   pmin(as.Date(ym) + n - 1, as.Date(ym, frac = 1))
 }

 ag - aggregate(DJd, nth.of.month(time(DJd), 31), tail, 1)



 On Fri, Apr 9, 2010 at 7:01 AM, Research risk2...@ath.forthnet.gr wrote:


 Dear all,

 Some time ago I received some very kind  help (special thanks to Gabor) to
 construct a function that isolates the n'th   working day of each month for
 zoo object (time series) to create monthly data from daily observations.

 I found out that the code works fine except for the 29 till 31st dates of
 each month as it skips some months (February for example).

 If  you could help me isolate the problem I would be grateful as I can not
 find a way to explain to R to keep the last  working day of month if I
 choose the 29th, 30th or 31st dates...

 I enclose  a working version of the function and a script for demo purposes.

 Many thanks in advance,
 Costas

 library(fImport)
 library(zoo)
 DJ-yahooSeries(^DJI, frequency=daily, nDaysBack=1)
 DJd-as.zoo(DJ[,4])

 ### Choose number of day for month

 chooseday-function(z, day)

    {

    # z.na is same as z but with missing days added using NAs
    # Its formed by merging z with a zoo-width series containing all days.

    rng - range(time(z))
    z.na - merge(z, zoo(, seq(rng[1], rng[2], by = day)))

    # form a series that has NAs wherever z.na does but has 1, 2, 3, ...
    # instead of z.na's data values and then use na.locf to fill in NAs

    idx - na.locf(seq_along(z.na) + (0 * z.na))

    # pick off elements of z.na corresponding to i'th of month

    noofday - paste(day)

    if (day10) noofday-paste(0,day, sep=)

    tempdata-z.na[idx[format(time(z.na), %d) == noofday]]

    return(tempdata)

    }

 length(chooseday(DJd,1))
 length(chooseday(DJd,2))
 length(chooseday(DJd,31))
 length(chooseday(DJd,30))
 length(chooseday(DJd,29))
 length(chooseday(DJd,28))
 tail(chooseday(DJd,31))












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


[R] rGraphviz: Changing edge label font size

2010-04-12 Thread nick harding

Dear all,
Using rGraphviz, I would like to make my edge labels a smaller size than 
the node labels, but I am unable to change the font size of edge labels 
independently of node labels. The edge labels always seem to use the 
font size defined for nodes.
I have searched the archives and found a similar query, but it received 
no replies.  http://www.mail-archive.com/r-help@r-project.org/msg45413.html


Thanks in advance for any help. Or would this query be better suited to 
a graphviz mailing list?


Nick

Sample code follows.

#code
##Test Code to illustrate edge labels code
MAT-matrix(0,8,8)
MAT[1,2]-1
MAT[2,3]-1
MAT[2,4]-1
MAT[3,5]-1
MAT[5,1]-1
MAT[7,5]-1
MAT[6,5]-1
MAT[8,5]-1
MAT-MAT+t(MAT)

library(Rgraphviz)
g1-new(graphAM, MAT,undirected)
g1-as(g1,graphNEL)  #convert to graphNEL
nodes(g1) - letters[1:8]

nAttrs - list()
eAttrs - list()

nodeLabels-letters[1:8]
names(nodeLabels)=nodes(g1)

#Define node attributes
nAttrs$label-nodeLabels

##Define Edge Attributes
x-length(edgeNames(g1))
edgeLabels - signif(runif(x, 0, 1),1)
names(edgeLabels)-edgeNames(g1)
eAttrs$label -edgeLabels

##Define general attributes
attrs - list(node = list(shape = box, fixedsize = FALSE))
attrs$edge$fontsize-8
attrs$node$fontsize-32
#colour can be changed
attrs$node$fontcolor-blue
attrs$edge$fontcolor-red

##Plot
plot(g1,nodeAttrs = nAttrs, edgeAttrs = eAttrs, attrs = attrs,neato)

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


Re: [R] using double loops and saving the data

2010-04-12 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 12.04.2010 12:51:24:

 
 
 Petr Pikal wrote:
  
  

snip

  
  Nobody except you has your data available, so without providing more 
clues 
  you can not expect mor relevant answers.
  
  Try str(your.objects) and maybe you could use debug to see how they 
are 
  operating and changing through a cycle.
  
  
 I think I got what you mean, so that I can't use the 
 Wealth1[[s]][i] - Ca[i+1]+Po[i+1]
 in the last line of loops.
 
 Is there any code I can use the store the data?
 I aim to store the data like :
 a - x1 x2 x3 x4 ...

What is x1, x2, ? If they are just character constants a can be 
character vector.

 and in each entry of a
 x1 - 1  2  3  4  5  6  7  ...

and the same applies here. x1 can be numeric vector.

I do not see any problem.

 the entries in x1 are the wealth that I want estimate.
 Please tell me the code to store these type of data. Thanks. :)

What type of data? You did not tell us anything useful about structure of 
data. Please provide at least output from

str(your.data.objects.you.want.to.put.together)

as Leonard da Quirm would say

Regards
Petr

 
 actually I can create the Price[[i]] by coding Price = list() before I
 simulate the price
 
 
 
 -- 
 View this message in context: 
http://n4.nabble.com/using-double-loops-and-
 saving-the-data-tp1836591p1836938.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Local R Training

2010-04-12 Thread Charles Roosen
Dear Dominik,

Mango Solutions is a long-established R training and consulting company based 
in the UK.  In February we started Mango Solutions AG based right here in 
Basel, Switzerland.

We have an Introduction to R course in Basel on May 17th to 18th.  Here's a 
list of the other courses planned for Switzerland, Germany, and Austria this 
year:

Introduction to R 17th - 18th May, Basel Switzerland
Introduction to R 25th - 26th May, Munich Germany
R for Pharmacometrics at Page 7th - 8th June, Berlin Germany
R for Microarrays 21st - 22nd June, Basel Switzerland
Introduction to R 5th - 6th July, Frankfurt Germany
R for Actuaries 13th - 14th September, Munich Germany
R Graphics 20th - 21st September, Basel Switzerland
R for Finance 4th - 5th October, Frankfurt Germany
Validation of R 15th - 16th November, Basel Switzerland

Details are available at:

http://mango-solutions.com/services/rtraining/r_schedule.html

We also do on-site training courses.

I'd be happy to discuss our courses with you individually, but thought I'd take 
the opportunity to inform the rest of R-help since we haven't had the Basel 
office open long enough to pop up on Google.

Best regards / Mit freundlichen Gruessen,
Charlie Roosen


Charles Roosen, PhD
Technical Director
 
mangosolutions
data analysis that delivers
 
T: +41 (0)61 206 92 91
M: +41 (0)79 248 70 71
F: +41 (0) 61 206 92 99

www.mango-solutions.com
 
Mango Solutions AG
Aeschenvorstadt 36
4051 Basel
Switzerland


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Dominik Riva
Sent: 12 April 2010 12:53
To: r-help@r-project.org
Subject: [R] Local R Training

Hello List,
 
I am new to R and statistics in general.
My two colleges and I would like to get some training in the proper
usage of R.
 
A quick internet search provided no results for the region of Basel in
Switzerland.
 
Does some one on this list knows of any trainers or schools in the
region in question or where to look next?
 
Regards,
 
 
Dominik Riva
Universitätsspital Basel
Med. Querschnittsfunktionen
Pathologie
Schoenbeinstrasse 40
CH-4031 Basel
Telefon 061 556 53 67
Cordless65367
E-Mail ri...@uhbs.ch

[[alternative HTML version deleted]]

LEGAL NOTICE
This message is intended for the use o...{{dropped:9}}

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


Re: [R] rpart: Writing values of the leaves to a dateset

2010-04-12 Thread Terry Therneau

-- begin inclusion --

I'm fitting a regression tree with rpart and I want to write the values 
for every leaf in a dataset. As an example take the variable turnover. 
Let's suppose my tree for turnover has 30 leaves and I want to have 30 
datasets with dataset 1 containing the turnover values of the units in 
leaf 1, dataset 2 containing turnover values for the observations in
leaf 
2 and so on. How can I do this? 

-- end inclusion --

fit - rpart(y ~ ...,data=mydata)
parts - tapply(mydata$y, predict(fit), c)

Then parts will be a list with one element per branch of the tree, each
containing the values of y found in that branch.

An alternative is
  indices - tapply(1:nrow(y), predict(fit), c)
which will give a list containing row numbers.

Terry T.

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


[R] multilevel (3-level) Hausman-Taylor estimator

2010-04-12 Thread Gerry Cress
Dear R users,

I have a question on multilevel modeling with R when there is endogenous
regressor(s) involved. As far as my economics background concerned, I
understand that Hausman-Taylor estimator (via Generalized Least Square)
deals with this situation and the package plm does the trick. Unfortunately,
plm is created for the conventional 2-level, that is, panel or logitudinal
data structure. On the other hand, both lme/lmer (in nlme and lme4 package
respectively) are advanced packages for multilevel modeling (via Maximum
Likelihood estimators) but I haven't found any option to tackle the
potential endogeneity problems.

I'm wondering if any one knows a package that handles this type of problem,
i.e., multilevel (3-level) with endogenous regresssor. In particular, I'd
appreciate it if you can point me to any resource that invokes the HT
approach in a multilevel setting.

Thanks in advance!

Regards,
Gerry

[[alternative HTML version deleted]]

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


Re: [R] Expectation of E(x^1/2)

2010-04-12 Thread JLucke
Ben, Ravi, Chuck, and Haneef,

Note that the standard normal density can be written (in pseudo-TeX) as
1/sqrt(2*pi) * exp[- ( x/sqrt(2) )^2]. 

The exponential on the right is a special case of the stretched 
exponential function 
exp[- (x/sqrt(tau))^beta]. 

The stretched exponential function has a nontrivial density and 
distribution.  However, the nth  moment of this density is 
 tau^(n)/beta * Gamma[(n)/beta]. 

The  substitution of n=3/2 (not 1/2), tau=sqrt(2), and beta=2, and 
multiplying by 1/sqrt(2*pi)  yields the Mathematica result below.

See http://en.wikipedia.org/wiki/Stretched_exponential_function. The use 
of n=3/2 rather than 1/2 is required because the stretched exponential 
function is already a function for the first moment.

Joe




Ben Bolker bol...@ufl.edu 
Sent by: r-help-boun...@r-project.org
04/11/2010 01:09 AM

To
Ravi Varadhan rvarad...@jhmi.edu
cc
r-h...@stat.math.ethz.ch r-h...@stat.math.ethz.ch
Subject
Re: [R] Expectation of E(x^1/2)






  And Mathematica says

In[2]:= 1/Sqrt[2 Pi] Integrate[Exp[-x^2/2] Sqrt[x],{x,0,Infinity}]

3
  Gamma[-]
4
Out[2]= -
 3/4
2Sqrt[Pi]

(I suppose there's probably a change-of-variables trick to do this ...)

in R:

 gamma(3/4)/(2^(3/4)*sqrt(pi))
[1] 0.4110895


Ravi Varadhan wrote:
 Chuck showed how to do this:
 
 fn - function(x) sqrt(x) * dnorm(x)
 
 integrate(fn, 0, Inf)
 0.4110895 with absolute error  4.7e-05
 
 So the (almost) exact answer is  0.4110895 + 1i * 0.4110895 


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


[[alternative HTML version deleted]]

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


[R] Strange results from Multivariate Normal Density

2010-04-12 Thread Downey, Patrick
Hello,

I'm using dmnorm from the package {mnormt} and getting strange results.

First, according to the documentation, dmnorm should return a vector of
densities, and I'm only getting one value returned (which is what I would
expect). I've been interpreting this as the joint density of all values in
the x vector (which is what I want). Should a vector of densities be
returned, and if so, to what do they correspond?

Second, and far more concerning, when I enter the following:

varcov1 - array(0,dim=c(2,2))
  varcov1[1,1] - 0.4891125
  varcov1[2,2] - 0.4891125
  varcov1[1,2] - 0.5
  varcov1[2,1] - 0.5
varcov1
dmnorm(c(0.930315,-0.8706811),mean=c(1.109568,6.648583),varcov1)

The result is an infinite density, which seems unlikely. For instance, the
second value is more than 7 standard deviations from the mean.

Thanks in advance for any comments and suggestions.

-Mitch

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


[R] How to derive function for parameters in Self start model in nls

2010-04-12 Thread Asif Wazir
Dear all
i want to fit the self start model in nls. i have two question. i have a
function,
(asfr ~ I(((a*b)/c))+ ((c/age)^3/2)+ exp((-b^2)*(c/age)+(age/c)-2)
i am wondering how to build the selfstart model. there is lost of example,
(i.e. SSgompertz, SSmicman, SSweibull, etc). my question is, how to derive
the function of parameters. and also which model to use for get
the initials values. In the following example's the red color coding
requires the explanation??

thanks

SSgompertz
function (x, Asym, b2, b3)
{
.expr2 - b3^x
.expr4 - exp(-b2 * .expr2)
.value - Asym * .expr4
.actualArgs - as.list(match.call()[c(Asym, b2, b3)])
if (all(unlist(lapply(.actualArgs, is.name {
.grad - array(0, c(length(.value), 3L), list(NULL, c(Asym,
b2, b3)))
.grad[, Asym] - .expr4
.grad[, b2] - -Asym * (.expr4 * .expr2)
.grad[, b3] - -Asym * (.expr4 * (b2 * (b3^(x - 1) *
x)))
dimnames(.grad) - list(NULL, .actualArgs)
attr(.value, gradient) - .grad
}
.value

attr(,initial)
function (mCall, data, LHS)
{
xy - sortedXyData(mCall[[x]], LHS, data)
if (nrow(xy)  4) {
stop(too few distinct input values to fit the Gompertz model)
}
xyL - xy
xyL$y - log(abs(xyL$y))
pars - NLSstAsymptotic(xyL)
pars - coef(nls(y ~ exp(-b2 * b3^x), data = xy, algorithm = plinear,
start = c(b2 = pars[[b1]], b3 = exp(-exp(pars[[lrc]])
val - pars[c(3, 1, 2)]
names(val) - mCall[c(Asym, b2, b3)]
val
}

Cheers
-- 
Muhammad Asif Wazir
Ph.D student
Institut für Statistik und Decision Support Systems (ISDS).
University of Vienna, Austria
cell: 00436509092298

[[alternative HTML version deleted]]

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


[R] Sweave and multiple figures from an R source file

2010-04-12 Thread michele donato
Hi,
I am trying to get figures from multiple source files in Sweave. My test
file is as follows

\documentclass{article}
\usepackage{Sweave}
\begin{document}
\begin{section}{notitle}
  This is a simple Sweave test
gethypergraphs_rhea,fig=TRUE,echo=F=
source(./testfig.r)
@
\\
End of the simple sweave test
\end{section}
\end{document}

where testfig.r is as simple as

plot(1:20)
plot(1:5)

The figures are correctly generated in the folder, as a .pdf/.eps with
two pages, each page a plot

the resulting tex file is

\documentclass{article}

\usepackage{Sweave}

\begin{document}
\begin{section}{notitle}
  This is a simple Sweave test
\includegraphics{coupling_images_report-gethypergraphs_rhea}
\\
End of the simple sweave test
\end{section}
\end{document}

When I compile the .tex file, however, the figures are overlapped one on
top of the other.
I tried to search for a solution, but found none...

Thanks,
Michele

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


Re: [R] Rsge: recursive parallelization

2010-04-12 Thread Peter Danenberg
Quoth Martin Morgan on Boomtime, the 29th of Discord:
 It seems like it would be hard to think about the tasks that are
 being executed, how many processes there are, how load balancing
 works, etc.

A flat representation of our nested data is, alas, too large to
contain in memory; and dynamically re-establishing context for an
arbitrary subset of it is expensive.

Parallel recursion isn't unheard of [1]; and I was hoping SGE would
worry about the load balancing, etc. for me.

Barring that, though, we might have to get creatively iterative.


Footnotes: 
[1]  
http://journals.cambridge.org/action/displayAbstract?fromPage=onlineaid=44263

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


Re: [R] library sets: A EMPTY does not work; gset_intersection(A,EMPTY) works

2010-04-12 Thread Czerminski, Ryszard
Hi David,

Thanks! I just tried it with new sets version (1.0-6) and it works great!
Thanks again for a very nice package.

Best regards,
Ryszard


--
Confidentiality Notice: This message is private and may contain confidential 
and proprietary information. If you have received this message in error, please 
notify us and remove it from your system and note that you must not copy, 
distribute or take any action in reliance on it. Any unauthorized use or 
disclosure of the contents of this message is not permitted and may be unlawful.

-Original Message-
From: David Meyer [mailto:david.me...@wu.ac.at] 
Sent: Sunday, April 11, 2010 5:12 PM
To: Czerminski, Ryszard
Cc: Peter Ehlers; R-help@R-project.org
Subject: Re: [R] library sets: A  EMPTY does not work; 
gset_intersection(A,EMPTY) works

Peter, Ryszard,

I just put a new version on CRAN (1.0-6) which fixes the problem 
occuring with operators and mixed classes, so, e.g.,

  gset(1,2)  set()
{}

now works. I also made sure that X == X is always TRUE, and fixed the 
all.equal-bug:

  gset(1, 0.5 - 0.3) == gset(1, 0.3 - 0.1)
[1] FALSE
  all.equal(gset(1, 0.5 - 0.3), gset(1, 0.3 - 0.1))
[1] TRUE

Best
David



Czerminski, Ryszard wrote:
 Hi Peter,
 
 This looks like another one: gset_is_equal(X,X) and X == X evaluate to 
 FALSE ?
 
 uv - c('a', 'b', 'c'); s - gset(uv, runif(length(uv)))
 s
 {a [0.0811552], b [0.3552998], c [0.996772]}
 gset_is_equal(s, s)
 [1] FALSE
 s == s
 [1] FALSE
 class(s)
 [1] gset cset
 
 Best regards,
 Ryszard
 
 
 --
 Confidentiality Notice: This message is private and may contain confidential 
 and proprietary information. If you have received this message in error, 
 please notify us and remove it from your system and note that you must not 
 copy, distribute or take any action in reliance on it. Any unauthorized use 
 or disclosure of the contents of this message is not permitted and may be 
 unlawful.
  
 -Original Message-
 From: Peter Ehlers [mailto:ehl...@ucalgary.ca] 
 Sent: Wednesday, March 31, 2010 2:03 PM
 To: Czerminski, Ryszard
 Cc: R-help@r-project.org; David Meyer
 Subject: Re: [R] library sets: A  EMPTY does not work; 
 gset_intersection(A,EMPTY) works
 
 Ryszard,
 
 You've made me take a closer look and now I do think that
 you've found a bug.
 
 After a quick look at the package vignette, I see that the
 authors have indeed overloaded  and so it should work for
 your example. The problem seems to be the order of the class
 attribute which is used to call the relevant 'Ops' function:
 
 class(A)
 #[1] gset cset
 
 class(B)
 #[1] gset cset
 
 class(E - A - A)
 #[1] set  gset cset
 
 If you re-order the class vector, function Ops.gset will be called
 to handle A and E:
 
 class(E) - class(E)[c(2,3,1)]
 A  E
 #{}
 
 I've cc'd David Meyer.
 
   -Peter Ehlers
 
 On 2010-03-31 10:11, Czerminski, Ryszard wrote:
 It seems that A  B works the same way as gset_intersection(A,B)
 as long as A and B are not empty...
 see below:

 fuzzy_logic(Yager, p=2)
 support- universe- c('a','b','c','d')
 A- gset(support=support, memberships=c(0.2, 0.2, 0.9, 0),
 universe=universe)
 B- gset(support=support, memberships=c(0.211, 0.222, 0.999, 0),
 universe=universe)
 A
 B
 A  B
 gset_intersection(A,B)
 E- A - A
 A  E
 gset_intersection(A,E)

 fuzzy_logic(Yager, p=2)
 support- universe- c('a','b','c','d')
 A- gset(support=support, memberships=c(0.2, 0.2, 0.9, 0),
 universe=universe)
 B- gset(support=support, memberships=c(0.211, 0.222, 0.999, 0),
 universe=universe)
 A
 {a [0.2], b [0.2], c [0.9]}
 B
 {a [0.211], b [0.222], c [0.999]}
 A  B
 {c [0.85]}
 gset_intersection(A,B)
 {c [0.85]}
 E- A - A
 A  E
 Error in A  E :
operations are possible only for numeric or logical types
 In addition: Warning message:
 Incompatible methods (Ops.gset, Ops.set) for 
 gset_intersection(A,E)
 {}


 --
 Confidentiality Notice: This message is private and may contain confidential 
 and proprietary information. If you have received this message in error, 
 please notify us and remove it from your system and note that you must not 
 copy, distribute or take any action in reliance on it. Any unauthorized use 
 or disclosure of the contents of this message is not permitted and may be 
 unlawful.

 -Original Message-
 From: Peter Ehlers [mailto:ehl...@ucalgary.ca]
 Sent: Wednesday, March 31, 2010 11:43 AM
 To: Czerminski, Ryszard
 Cc: R-help@r-project.org
 Subject: Re: [R] library sets: A  EMPTY does not work;
 gset_intersection(A,EMPTY) works

 On 2010-03-31 9:30, Peter Ehlers wrote:
 Unless I'm missing something, I don't see any method
 in pkg:sets for intersection other than gset_intersection.
 Whoops, a bit quick on the draw.
 There are of course also set_intersection and cset_intersection,
 but not AFAICS any 

Re: [R] Sweave and multiple figures from an R source file

2010-04-12 Thread Duncan Murdoch

On 12/04/2010 12:08 PM, michele donato wrote:

Hi,
I am trying to get figures from multiple source files in Sweave. My test
file is as follows

\documentclass{article}
\usepackage{Sweave}
\begin{document}
\begin{section}{notitle}
  This is a simple Sweave test
gethypergraphs_rhea,fig=TRUE,echo=F=
source(./testfig.r)
@
\\
End of the simple sweave test
\end{section}
\end{document}

where testfig.r is as simple as

plot(1:20)
plot(1:5)

The figures are correctly generated in the folder, as a .pdf/.eps with
two pages, each page a plot

the resulting tex file is

\documentclass{article}

\usepackage{Sweave}

\begin{document}
\begin{section}{notitle}
  This is a simple Sweave test
\includegraphics{coupling_images_report-gethypergraphs_rhea}
\\
End of the simple sweave test
\end{section}
\end{document}

When I compile the .tex file, however, the figures are overlapped one on
top of the other.
I tried to search for a solution, but found none...


This doesn't really have to do with source() or even Sweave:  
\includegraphics wants just one figure per file.  In Sweave, that means 
you need to put separate figures in separate code chunks (or use 
par(mfrow= ...) or something to allow both to be plotted on the same page).


Duncan Murdoch

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


[R] lattice garphs: combining multiple scatterplots and adding legend

2010-04-12 Thread Jannis
Dear List members,


its me again, fighting with lattice graphics. I am trying to plot a world map, 
add some points on different locations with different colors and add a legend, 
but did not succeed yet with the legend. Here is my code:


library(fields)

# Data for demonstration

data_x = c(0,50,60)
data_y = c(0,0,0)
cols   = c(1,2,3)
data(world.dat)

#print map
all=xyplot(world.dat$y  ~ world.dat$x,
   type=c('l'),col=black,xlab=,ylab=,
   ylim=c(-55,80),xlim=c(-170,175),pch=20,cex=0.2,
   auto.key = list(x=0,y=0,text=c('test1','test2','test3')))
print(all,position=c(0,0,1,.7),more=T)

#add points
trellis.focus(highlight=FALSE)
lpoints(data_x,data_y,pch=20,col=cols)
update(all,auto.key = list(x=0,y=0,text=c('test1','test2','test3')))


The plots are produced correctly, but the legend is still missing. Could anyone 
give me some hints?
There is probably a much more elegant way how to combine the two plots but i 
did not manage to understand the usage of these different panel functions. 
There is most probably no way around the Trellis book, but I could not yet buy 
it


Thanks for your help
Jannis


__
Do You Yahoo!?
Sie sind S
ssenmails. 
http://mail.yahoo.com

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


Re: [R] lattice garphs: combining multiple scatterplots and addinglegend

2010-04-12 Thread Bert Gunter
There us no groups argument in your xyplot call, so how is auto.key
supposed to define a legend? (and note that auto.key should be a logical not
a list).

Please re-read the auto.key section in the xyplot man page.

Bert Gunter
Genentech Nonclinical Biostatistics
 
 -Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Jannis
Sent: Monday, April 12, 2010 10:20 AM
To: R-help@r-project.org
Subject: [R] lattice garphs: combining multiple scatterplots and
addinglegend

Dear List members,


its me again, fighting with lattice graphics. I am trying to plot a world
map, add some points on different locations with different colors and add a
legend, but did not succeed yet with the legend. Here is my code:


library(fields)

# Data for demonstration

data_x = c(0,50,60)
data_y = c(0,0,0)
cols   = c(1,2,3)
data(world.dat)

#print map
all=xyplot(world.dat$y  ~ world.dat$x,
   type=c('l'),col=black,xlab=,ylab=,
   ylim=c(-55,80),xlim=c(-170,175),pch=20,cex=0.2,
   auto.key = list(x=0,y=0,text=c('test1','test2','test3')))
print(all,position=c(0,0,1,.7),more=T)

#add points
trellis.focus(highlight=FALSE)
lpoints(data_x,data_y,pch=20,col=cols)
update(all,auto.key = list(x=0,y=0,text=c('test1','test2','test3')))


The plots are produced correctly, but the legend is still missing. Could
anyone give me some hints?
There is probably a much more elegant way how to combine the two plots but i
did not manage to understand the usage of these different panel functions.
There is most probably no way around the Trellis book, but I could not yet
buy it


Thanks for your help
Jannis


__
Do You Yahoo!?
Sie sind S
ssenmails. 
http://mail.yahoo.com

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

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


[R] rgdal package: save multiband image in tiff file

2010-04-12 Thread Niceman_64

Hello all,

I am trying to save a multiband matrix in a tiff file with writeGDAL() from
the rgdal package.
The code below only saves the first band of the matrix StockMat.
Do you have any suggestion to correct my code?

Thanks a lot.

nbRow=nrow(StockMat)
nbCol=ncol(StockMat)
StockMat_GridTopo=GridTopology(cellcentre.offset = c(nbRow, nbCol,
ncol(Data)),cellsize = c(1, 1, 1), cells.dim = dim(StockMat))
StockMat_SGDF=SpatialGridDataFrame(StockMat_GridTopo, data.frame(depth =
as.vector(StockMat)))
writeGDAL(StockMat_SGDF, fname=T:/Masses_QB.tiff, drivername = GTiff,
type = Float32, mvFlag = NA)

-- 
View this message in context: 
http://n4.nabble.com/rgdal-package-save-multiband-image-in-tiff-file-tp1837476p1837476.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Data Synchronization -- detecting time differences in multi-source data

2010-04-12 Thread Ralf B
Hi R enthusiasts,

I am dealing with logging data from different sources that contain
data from user activities. The data is all timelined with one column
containing Epoch time and two columns containing data (x and y
coordinates of mouse movements) = three columns for each source. I
have up to 10 such sources and with 10s of log entries.

Here the header:

timestamp1, x1, y1, timestamp2, x2, y2, .

Since data is recorded from different sources, I have time differences
in the measurements between source 1 and source 2. Sometimes these
time differences are regular (e.g. source 1 is always 10 ms off source
2) but they can also be dynamic (e.g. based on some network latency
issues, differences can increase or decrease at any time). The x and y
value measurements always match, but since they are screen coordinates
they may repeat in various places. Some sources start earlier than
others, which means time lined entries do not match on each line.

I am looking for a pointer to some general statistical methods that
allows me to automatically detect time differences in such data sets.
Methods that detect blocks of measurements across sources and compare
their time line and flag those cases where they divert. Which field of
stats deals with this? What R packages are specialized on such
problems?

Thanks a lot,
Ralf

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


[R] read.socket and timeout

2010-04-12 Thread Sean Davis
I have an external process that is listening to and responding on a
port.  This is working fine.  If the external service is not running,
though, read.socket does not return and I do not see a way to
interrupt it.  Is there a general way to deal with this situation to
have a timeout or of testing a socket connection?

Thanks,
Sean

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


[R] glmer with non integer weights

2010-04-12 Thread Kay Cichini

hello,

i'd appreciate help with my glmer.
i have a dependent which is an index (MH.index) ranging from 0-1. this index
can also be considered as a propability. as i have a fixed factor (stage)
and a nested random factor (site) i tried to model with glmer. i read that
it's possible to use a quasibinomial distribution, for this kind of data,
which i than actually did - but firstly 

(1) i'm not quite sure if that's appropiate for my data, secondly 
(2) i wondered if the model can be correct when variance of then main and
nested factor are zero.
(3) also i could not yield p-values for that model.

here's data, call and output:

##
#call:
##

glmer(MH~stage+(1|stage/site),family=quasibinomial)

##
#output:
##
#Generalized linear mixed model fit by the Laplace approximation 
#Formula: MH ~ stage + (1 | stage/site) 
#  AIC   BIC logLik deviance
# 66.03 86.47 -26.0152.03
#Random effects:
# Groups NameVariance Std.Dev.
# site:stage (Intercept) 0.00 0.000   
# stage  (Intercept) 0.00 0.000   
# Residual   0.076175 0.276   
# Number of obs: 137, groups: site:stage, 39; stage, 4

#Fixed effects:
#Estimate Std. Error t value
#(Intercept)  0.392050.09009   4.352
#stageB  -0.872140.12498  -6.978
#stageC  -0.361530.12202  -2.963
#stageD  -0.098840.19811  -0.499

#Correlation of Fixed Effects:
#   (Intr) stageB stageC
#stageB -0.721  
#stageC -0.738  0.532   
#stageD -0.455  0.328  0.336
##
#my data:
##
similarity-data.frame(list(structure(list(stage = structure(c(1L, 1L, 1L,
1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L), .Label = c(A, B, C, D), class = factor), site =
structure(c(1L,
1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 6L, 6L,
6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 10L, 10L,
10L, 10L, 11L, 11L, 12L, 12L, 12L, 13L, 13L, 13L, 14L, 14L, 14L,
14L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 18L,
18L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L,
22L, 22L, 22L, 22L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 25L, 25L,
25L, 25L, 26L, 26L, 26L, 26L, 27L, 27L, 27L, 27L, 28L, 28L, 28L,
28L, 29L, 29L, 29L, 30L, 30L, 30L, 30L, 31L, 31L, 32L, 32L, 32L,
32L, 33L, 33L, 33L, 33L, 34L, 34L, 34L, 34L, 35L, 35L, 35L, 35L,
36L, 36L, 36L, 36L, 37L, 37L, 38L, 38L, 38L, 38L, 39L, 39L, 39L
), .Label = c(A11, A12, A14, A15, A16, A17, A18,
A19, A20, A5, A7, A8, B1, B12, B13, B14, B15,
B17, B18, B2, B4, B7, B8, B9, C1, C10, C11,
C15, C17, C18, C19, C2, C20, C3, C4, C6, D1,
D4, D7), class = factor), MH.Index = c(0.392156863, 0.602434077,
0.576923077, 0.647482014, 0.989010989, 0.857142857, 1, 1, 1,
0, 1, 0.378378378, 0.839087948, 0.252915554, 1, 0.22556391, 0.510366826,
0.476190476, 0.555819477, 0.961538462, 0.7, 0.089285714,
0.923076923, 0.571428571, 0, 0.923076923, 0.617647059, 0.599423631,
0, 0.727272727, 0.998112812, 0, 0, 0, 1, 0.565656566, 0.75, 0.923076923,
0.654545455, 0.14084507, 0.617647059, 0.315789474, 0.179347826,
0.583468021, 0.165525114, 0.817438692, 0.41457, 0.49548886,
0.556127703, 0.707431246, 0.506757551, 0.689655172, 0.241433511,
0.379232506, 0.241935484, 0, 0.30848329, 0.530973451, 0.148148148,
0, 0.976744186, 0.550218341, 0.542168675, 0.769230769, 0.153310105,
0, 0, 0.380569406, 0.742174733, 0.2, 0.046925432, 0,
0.068076328, 0.772727273, 0.830039526, 0.503458415, 0.863910822,
0.39401263, 0.081818182, 0.368421053, 0.088607595, 0, 0.575499851,
0.605657238, 0.714854232, 0.855881172, 0.815689401, 0.552207228,
0.81708081, 0.583228133, 0.334466349, 0.259477365, 0.194711538,
0.278916707, 0.636304805, 0.593715432, 0.661016949, 0.626865672,
0.420219245, 0.453535143, 0.471243706, 0.462427746, 0.56980057,
0.453821155, 0.052828527, 0.926829268, 0.51988266, 0.472200264,
0.351219512, 0.290030211, 0.765258974, 0.564894108, 0.789699571,
0.863378215, 0.525181559, 0.803061458, 0.260164645, 0.477265792,
0.265889379, 0.317791411, 0.107623318, 0.279181709, 0.471953363,
0.463724265, 0.241966696, 0.403647213, 0.693087992, 0.494259925,
0.68904453, 0.39329147, 0.498161213, 0.376225983, 0.407001046,
0.825016633, 0.718991658, 0.662995912)), .Names = c(stage,
site, MH.Index), 

[R] Antw: RE: Local R Training

2010-04-12 Thread Dominik Riva
Dear Charles,
 
this sounds perfect.
I knew I would find the information on this list.
 
Thanks to all that answered my question.
 
Regards,
 
Dominik Riva
Universitätsspital Basel
Med. Querschnittsfunktionen
Pathologie
Schoenbeinstrasse 40
CH-4031 Basel
Telefon 061 556 53 67
Cordless65367
E-Mail ri...@uhbs.ch 


 Charles Roosen croo...@mango-solutions.com 04/12/10 2:37 pm

Dear Dominik,

Mango Solutions is a long-established R training and consulting company
based in the UK.  In February we started Mango Solutions AG based right
here in Basel, Switzerland.

We have an Introduction to R course in Basel on May 17th to 18th. 
Here's a list of the other courses planned for Switzerland, Germany, and
Austria this year:

Introduction to R 17th - 18th May, Basel Switzerland
Introduction to R 25th - 26th May, Munich Germany
R for Pharmacometrics at Page 7th - 8th June, Berlin Germany
R for Microarrays 21st - 22nd June, Basel Switzerland
Introduction to R 5th - 6th July, Frankfurt Germany
R for Actuaries 13th - 14th September, Munich Germany
R Graphics 20th - 21st September, Basel Switzerland
R for Finance 4th - 5th October, Frankfurt Germany
Validation of R 15th - 16th November, Basel Switzerland

Details are available at:

http://mango-solutions.com/services/rtraining/r_schedule.html 

We also do on-site training courses.

I'd be happy to discuss our courses with you individually, but thought
I'd take the opportunity to inform the rest of R-help since we haven't
had the Basel office open long enough to pop up on Google.

Best regards / Mit freundlichen Gruessen,
Charlie Roosen


Charles Roosen, PhD
Technical Director

mangosolutions
data analysis that delivers

T: +41 (0)61 206 92 91
M: +41 (0)79 248 70 71
F: +41 (0) 61 206 92 99

www.mango-solutions.com 

Mango Solutions AG
Aeschenvorstadt 36
4051 Basel
Switzerland


-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Dominik Riva
Sent: 12 April 2010 12:53
To: r-help@r-project.org 
Subject: [R] Local R Training

Hello List,

I am new to R and statistics in general.
My two colleges and I would like to get some training in the proper
usage of R.

A quick internet search provided no results for the region of Basel in
Switzerland.

Does some one on this list knows of any trainers or schools in the
region in question or where to look next?

Regards,


Dominik Riva
Universitätsspital Basel
Med. Querschnittsfunktionen
Pathologie
Schoenbeinstrasse 40
CH-4031 Basel
Telefon 061 556 53 67
Cordless65367
E-Mail ri...@uhbs.ch 

[[alternative HTML version deleted]]

LEGAL NOTICE\ This message is intended for the use of th...{{dropped:15}}

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


[R] Excel date to R format

2010-04-12 Thread ManInMoon

I have searched and tried to read before posting but can find nothing to
accomplish change Excel dates in double format to R

Can someone please help

I have a vector of double like this from Excel.

39965.0004549653

and I want to put them in R such that I can display them in any Date and
Time format.

as.Date does it ALMOST but chops off the fractional seconds. POSIXct doesn't
appear to do what I need.
-- 
View this message in context: 
http://n4.nabble.com/Excel-date-to-R-format-tp1837208p1837208.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] simple question about contrasts, lm and factors

2010-04-12 Thread friendpine

If one of your variable is discrete,such as 1/0, the logistic regression is
better.Try the glm() function.
-- 
View this message in context: 
http://n4.nabble.com/simple-question-about-contrasts-lm-and-factors-tp1835964p1837091.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Excel date to R format

2010-04-12 Thread ManInMoon

I mean I want to convert them to whatever is the standard R DateTime class.
-- 
View this message in context: 
http://n4.nabble.com/Excel-date-to-R-format-tp1837208p1837280.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] [R-pkgs] New package mvngGrAd

2010-04-12 Thread F Te

Dear useRs,

I am glad to announce that that my package mvngGrAd (read: moving 
grid) is now available on CRAN.


The package implements moving grid adjustment, which is a spatial method 
used in (unreplicated) plant breeding trials to adjust phenotypic values 
for environmental effects. The adjustment is done by using phenotypic 
information from nearest neighbors (NN) as a covariate. Unlike in other  
NN methods,  the NN in the moving grid adjustment are not determined by 
a measure of distance but by inclusion in a grid of certain size and shape.


If you're interested,  please see the included vignette for more details 
on moving grid adjustment and the package.


Best regards

Frank.

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

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


Re: [R] lattice garphs: combining multiple scatterplots and addinglegend

2010-04-12 Thread Peter Ehlers

Actually, Bert, auto.key can be used. See below.

On 2010-04-12 11:41, Bert Gunter wrote:

There us no groups argument in your xyplot call, so how is auto.key
supposed to define a legend? (and note that auto.key should be a logical not
a list).

Please re-read the auto.key section in the xyplot man page.

Bert Gunter
Genentech Nonclinical Biostatistics

  -Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Jannis
Sent: Monday, April 12, 2010 10:20 AM
To: R-help@r-project.org
Subject: [R] lattice garphs: combining multiple scatterplots and
addinglegend

Dear List members,


its me again, fighting with lattice graphics. I am trying to plot a world
map, add some points on different locations with different colors and add a
legend, but did not succeed yet with the legend. Here is my code:


library(fields)

# Data for demonstration

data_x = c(0,50,60)
data_y = c(0,0,0)
cols   = c(1,2,3)
data(world.dat)

#print map
all=xyplot(world.dat$y  ~ world.dat$x,
type=c('l'),col=black,xlab=,ylab=,
ylim=c(-55,80),xlim=c(-170,175),pch=20,cex=0.2,
auto.key = list(x=0,y=0,text=c('test1','test2','test3')))
print(all,position=c(0,0,1,.7),more=T)

#add points
trellis.focus(highlight=FALSE)
lpoints(data_x,data_y,pch=20,col=cols)
update(all,auto.key = list(x=0,y=0,text=c('test1','test2','test3')))


The plots are produced correctly, but the legend is still missing. Could
anyone give me some hints?
There is probably a much more elegant way how to combine the two plots but i
did not manage to understand the usage of these different panel functions.
There is most probably no way around the Trellis book, but I could not yet
buy it



(Well, yes, you should buy it.)
I wouldn't bother with the trellis.focus bit - just put your
lpoints() into an appropriate panel function.

all - xyplot(world.dat$y  ~ world.dat$x,
   type=c('l'),col=black,xlab=,ylab=,
   ylim=c(-55,80),xlim=c(-170,175),
   panel = function(x, y, ...){
 panel.xyplot(x, y, ...)
 lpoints(data_x, data_y, pch=20, col=cols, cex=1.2)
   },
   ## the next line is just to control the points symbol
   ## in the key.
   par.settings = list(superpose.symbol =
list(pch=20, cex=1.2, col=cols)),
   auto.key = list(space=right,
   text=c('test1','test2','test3'),
   points=TRUE)
)
print(all, position=c(0,0,1,.7))

Or, for possibly more flexibility, use 'key' (and you won't
need the par.settings):

all - xyplot(world.dat$y  ~ world.dat$x,
   type=c('l'),col=black,xlab=,ylab=,
   ylim=c(-55,80),xlim=c(-170,175),
   panel=function(x,y,...){
 panel.xyplot(x,y,...)
 lpoints(data_x, data_y, pch=20, col=cols, cex=1.2)
   },
   key = list(space=right,
  text=list(labels=c('test1','test2','test3')),
  points=list(pch=20, cex=1.2, col=cols))
)
print(all, position=c(0,0,1,.7))

 -Peter Ehlers



Thanks for your help
Jannis


__
Do You Yahoo!?
Sie sind S
ssenmails.
http://mail.yahoo.com

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

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




--
Peter Ehlers
University of Calgary

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


Re: [R] How to run Shapiro-Wilk test for each grouped variable?

2010-04-12 Thread Iurie Malai
Noel, thanks a lot. This will help me someday. But I have a question.
When we run Shapiro-Wilk test, the homogenity of variances is a
mandatory condition?


2010/4/12 Yvonnick Noel yvonnick.n...@uhb.fr:
 Dear Iurie,

 I want to run Shapiro-Wilk test for each variable in my dataset, each
 grouped by variable groupFactor.

 Note that, at least on a single dependent variable with a grouping variable,
 a possible simplification may arise when homogeneity of variances is assumed
 and reasonable. You may want to do a single normality test on group-centered
 data :

 shapiro.test(residuals(lm(data[,1]~groupFactor)))


 HTH,

 Yvonnick Noel
 University of Brittany, Rennes 2
 France


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


[R] R GUI

2010-04-12 Thread Amitoj S. Chopra

I am really new with R Graphical user interfacefunctions. I am developing a
software package to calculate pKa (biochemistry) but I want to make it look
aesthetically pleasing and make it user friendly. I have heard that R has
some GUI (Graphical user interface) and you can do some really cool stuff
out there. What are the limitations and what are some resources for help. I
have found a couple of sources but I was wondering someone with more
experience in the subject can guide me. Thanks!
-- 
View this message in context: http://n4.nabble.com/R-GUI-tp1837662p1837662.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Figures within tables [slightly off-topic]

2010-04-12 Thread Peter Jepsen
Dear R-listers

 

I am writing a manuscript for a scientific journal in clinical medicine.
I have three groups of patients, and I present a 10*3 table of their
characteristics in Table 1. Some of their characteristics, e.g. their
age, are on a continuous scale, others are dichotomous. I am thinking of
presenting the age distribution in each group as miniature graphs, each
of which must fit in one table cell. I am hoping that someone can answer
these questions:

 

1. Has anybody ever seen something like this published anywhere?

2. Should I draw the entire table as a figure, or should I make a table
in Word (or similar) and manually insert the graphs in their cells?

3. Are there R packages that can draw tables?

4. And one for you editors out there: Would such a table count as one
figure, several figures, or a table?!

 

Forgive me for being somewhat off-topic. I hope for your help anyway.

 

Best regards,

Peter.


[[alternative HTML version deleted]]

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


Re: [R] R GUI

2010-04-12 Thread Khanh Nguyen
I have toyed with 'traitr' recently... It is not fancy, but relatively
easy to figure out.

-k

On Mon, Apr 12, 2010 at 4:00 PM, Amitoj S. Chopra amit...@gmail.com wrote:

 I am really new with R Graphical user interfacefunctions. I am developing a
 software package to calculate pKa (biochemistry) but I want to make it look
 aesthetically pleasing and make it user friendly. I have heard that R has
 some GUI (Graphical user interface) and you can do some really cool stuff
 out there. What are the limitations and what are some resources for help. I
 have found a couple of sources but I was wondering someone with more
 experience in the subject can guide me. Thanks!
 --
 View this message in context: 
 http://n4.nabble.com/R-GUI-tp1837662p1837662.html
 Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] R GUI

2010-04-12 Thread Vojtěch Zeisek
Dne Po 12. dubna 2010 22:00:21 Amitoj S. Chopra napsal(a):
 I am really new with R Graphical user interfacefunctions. I am developing a
 software package to calculate pKa (biochemistry) but I want to make it look
 aesthetically pleasing and make it user friendly. I have heard that R has
 some GUI (Graphical user interface) and you can do some really cool stuff
 out there. What are the limitations and what are some resources for help. I
 have found a couple of sources but I was wondering someone with more
 experience in the subject can guide me. Thanks!

Hello,
especially if You are Linux / Unix user, You can use Rkward GUI 
(http://rkward.sourceforge.net/). It is written using KDE libraries 
(http://www.kde.org/) using Nokia Qt (http://qt.nokia.com/) - it is powerful 
multiplatform developer tool. Tons of programs are written in it. Although I'm 
not developer, I'd recommend it. Another way is to write it in Java (I do not 
like the language), which is very popular and nice looking language :-) or in 
scripting languages lake Python (excellent tool) or Perl, which are usable on 
all platforms and have a lot of supporting libraries and functions.
I hope it helps little bit. :-)
Best regards,
Vojtěch Zeisek

-- 
Vojtěch Zeisek

Komunita openSUSE GNU/Linuxu /
Community of the openSUSE GNU/Linux

http://www.opensuse.org/
http://web.natur.cuni.cz/~zeisek/


signature.asc
Description: This is a digitally signed message part.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Figures within tables [slightly off-topic]

2010-04-12 Thread Erik Iverson

Hello,


I am writing a manuscript for a scientific journal in clinical medicine.
I have three groups of patients, and I present a 10*3 table of their
characteristics in Table 1. Some of their characteristics, e.g. their
age, are on a continuous scale, others are dichotomous. I am thinking of
presenting the age distribution in each group as miniature graphs, each
of which must fit in one table cell. I am hoping that someone can answer
these questions:

 


1. Has anybody ever seen something like this published anywhere?

2. Should I draw the entire table as a figure, or should I make a table
in Word (or similar) and manually insert the graphs in their cells?



Depending on your needs, there's another solution. You could output 
LaTeX, and compile that to a PDF.  The first thing I thought of when I 
read your topic was the describe function in Hmisc.  The help file for 
?describe references


 http://biostat.mc.vanderbilt.edu/twiki/pub/Main/Hmisc/counties.pdf

Probably not exactly what you're looking for, but it might be start. See 
also:


http://texblog.wordpress.com/2008/02/04/placing-graphicsimages-inside-a-table/

I would probably go this route, generating code to produce a LaTeX table 
and the associated image files.  I've also used low-level grid graphics 
function calls (e.g., grid.text ) to produce 'tables' with hazard ratio 
type graphics included as a column. (a 'forest plot').


Hope that helps,
Erik

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


Re: [R] R GUI

2010-04-12 Thread Tengfei Yin
Hi

I like gWidgets, you can choose different api, like rgtk2,
tcltkeasy to use in R, looks pretty(at least for me), try the
examples in the website first, the link below is the answers with
tutorial links, you can also check gWidgets vignette.

https://stat.ethz.ch/pipermail/r-sig-gui/2008-August/000831.html

Regards

Tengfei


On Mon, Apr 12, 2010 at 3:00 PM, Amitoj S. Chopra amit...@gmail.com wrote:


 I am really new with R Graphical user interfacefunctions. I am developing a
 software package to calculate pKa (biochemistry) but I want to make it look
 aesthetically pleasing and make it user friendly. I have heard that R has
 some GUI (Graphical user interface) and you can do some really cool stuff
 out there. What are the limitations and what are some resources for help. I
 have found a couple of sources but I was wondering someone with more
 experience in the subject can guide me. Thanks!
 --
 View this message in context:
 http://n4.nabble.com/R-GUI-tp1837662p1837662.html
 Sent from the R help mailing list archive at Nabble.com.

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




-- 
Tengfei Yin
MCDB PhD student
1620 Howe Hall, 2274,
Iowa State University
Ames, IA,50011-2274
Homepage: www.tengfei.name
English Blog: www.tengfei.name/en
Chinese Blog: www.tengfei.name/ch

[[alternative HTML version deleted]]

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


[R] Tck/tk help

2010-04-12 Thread Rick M

I am trying to create a simple window that displays a dataframe.  I was able
to put together a function from a couple of examples on the web.  For the
most part my function works.  The only problem is with resizing the window. 
I found a post where someone suggested using
with(env,tkpack(configure,etc.  ) but using tkpack messes around with the
layout obtained from tkgrid().  Any tips would be appreciated.

toTclArray-function(dsn,dig=2) {

# Converts Data Frame/Matrix to a Tcl Array for Use in Displaying Tables
# dsn is the data set name
# dig is the number of digits to round to

require(tcltk)
tclarray1-tclArray()

for (i in 0:(dim(dsn)[1])) {
for (j in 0:(dim(dsn)[2]-1)) {
# First Row is Set to Column Names to be Used as Labels
if (i==0) {
tclarray1[[i,j]]-colnames(dsn)[j+1] 
} else {
tem-dsn[i,j+1]
tclarray1[[i,j]]-ifelse(is.na(tem),.,

ifelse(is.numeric(tem),round(tem,digits=dig),
as.character(tem)))
}
}
}
return (tclarray1)
}



displayInTable-function(dsn,title=,height=-1,width=-1,dig=2,colwd=14)
{
tclarray-toTclArray(dsn,dig=dig)
require(tcltk)
tt-tktoplevel()
tclRequire(Tktable)
tkwm.title(tt,title)
table1-tkwidget(tt,table,rows=(dim(dsn)[1]+1),cols=dim(dsn)[2],
titlerows=1,titlecols=0,colwidth=colwd,
height=height+1,width=width+1,
xscrollcommand=function(...) tkset(xscr,...),
yscrollcommand=function(...) tkset(yscr,...) )

xscr-tkscrollbar(tt,orient=horizontal,command=function(...)
tkxview(table1,...) )
yscr-tkscrollbar(tt,command=function(...) tkxview(table1,...) )

tkgrid(table1,yscr)
tkgrid.configure(yscr,sticky=nsw)
tkgrid(xscr,sticky=new)
tkconfigure(table1,variable=tclarray,background=white,
selectmode=extended,state=disabled)
with(tt,{tkpack(configure,table1,expand=TRUE,fill=both)
tkpack(configure,yscr,expand=TRUE,fill=y)
tkpack(configure,xscr,expand=TRUE,fill=x)
})
return(table1)
}

# Example
try-data.frame(matrix(1:100,5,20,byrow=TRUE))
colnames(try)-1:20
displayInTable(try,title=1 to 100)
-- 
View this message in context: 
http://n4.nabble.com/Tck-tk-help-tp1837711p1837711.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Excel date to R format

2010-04-12 Thread Gabor Grothendieck
See the relevant article in R News 4/1.

On Mon, Apr 12, 2010 at 10:36 AM, ManInMoon xmoon2...@googlemail.com wrote:

 I have searched and tried to read before posting but can find nothing to
 accomplish change Excel dates in double format to R

 Can someone please help

 I have a vector of double like this from Excel.

 39965.0004549653

 and I want to put them in R such that I can display them in any Date and
 Time format.

 as.Date does it ALMOST but chops off the fractional seconds. POSIXct doesn't
 appear to do what I need.
 --
 View this message in context: 
 http://n4.nabble.com/Excel-date-to-R-format-tp1837208p1837208.html
 Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] Figures within tables [slightly off-topic]

2010-04-12 Thread baptiste auguie
Hi,

On 12 April 2010 22:07, Peter Jepsen p...@dce.au.dk wrote:

 3. Are there R packages that can draw tables?

the gplots package has a textplot() function, and the gridExtra
package a tableGrob(),

http://rwiki.sciviews.org/doku.php?id=tips:graphics-grid:table

In theory it should be possible to adapt the latter to allow the
placement of a (preferably lattice / ggplot2 / Grid) graphic in the
desired cells.

HTH,

baptiste

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


Re: [R] Excel date to R format

2010-04-12 Thread Ben Bolker
Gabor Grothendieck ggrothendieck at gmail.com writes:

 
 See the relevant article in R News 4/1.
 
 On Mon, Apr 12, 2010 at 10:36 AM, ManInMoon wrote:
 
  I have a vector of double like this from Excel.
 
  39965.0004549653
 
  and I want to put them in R such that I can display them in any Date and
  Time format.
 

  Emphasis:

  as.Date does it ALMOST but chops off the fractional seconds.
   POSIXct doesn't
  appear to do what I need.

  (ManInMoon: why not?  A reproducible example would help.)


  Gabor, 

  I looked at that R News article but can't figure out whether *any*
of these classes preserve sub-second resolution (which seems crazy to me;
I guess in the case of POSIXt there may be an ANSI standard that specifies
that 'seconds' are stored as integers, but otherwise this seems like
a needless restriction).  Am I missing something?

  Ben

 as.numeric(as.POSIXct(39965.004,origin=as.Date(1970-1-1)))
[1] 39965.00

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


Re: [R] Excel date to R format

2010-04-12 Thread Gabor Grothendieck
Try this:

 sprintf(%.3f, as.numeric(as.POSIXct(39965.004,origin=as.Date(1970-1-1
[1] 39965.004

 getOption(digits.secs)
NULL
 as.POSIXct(39965.004,origin=as.Date(1970-1-1))
[1] 1970-01-01 06:06:05 EST
 sprintf(%.3f, as.numeric(as.POSIXct(39965.004,origin=as.Date(1970-1-1
[1] 39965.004
 format(as.POSIXct(39965.004,origin=as.Date(1970-1-1)), %Y-%m-%d %H:%M:%S 
 %OS3)
[1] 1970-01-01 06:06:05 05.004


 options(digits.secs = 3)
 as.POSIXct(39965.004,origin=as.Date(1970-1-1))
[1] 1970-01-01 06:06:05.004 EST


On Mon, Apr 12, 2010 at 7:52 PM, Ben Bolker bol...@ufl.edu wrote:
 Gabor Grothendieck ggrothendieck at gmail.com writes:


 See the relevant article in R News 4/1.

 On Mon, Apr 12, 2010 at 10:36 AM, ManInMoon wrote:
 
  I have a vector of double like this from Excel.
 
  39965.0004549653
 
  and I want to put them in R such that I can display them in any Date and
  Time format.
 

  Emphasis:

  as.Date does it ALMOST but chops off the fractional seconds.
   POSIXct doesn't
  appear to do what I need.

  (ManInMoon: why not?  A reproducible example would help.)


  Gabor,

  I looked at that R News article but can't figure out whether *any*
 of these classes preserve sub-second resolution (which seems crazy to me;
 I guess in the case of POSIXt there may be an ANSI standard that specifies
 that 'seconds' are stored as integers, but otherwise this seems like
 a needless restriction).  Am I missing something?

  Ben

 as.numeric(as.POSIXct(39965.004,origin=as.Date(1970-1-1)))
 [1] 39965.00

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


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


[R] R Internal Web Server Loopback Interface Limit

2010-04-12 Thread D. Dashcle

Is there a setting or easy way I can remove the code that makes R only listen 
for web traffic on 127.0.0.1? I've noticed it seems to reject traffic to both 
the regular help files (i.e. what starts up when I do ?function), as well as 
if I try to connect to pages I've made for the R.rsp package. We could live 
without the help files, but it would be neat to allow others to access the 
small web-based R scripts for R.rsp since it already has a web-server built-in. 

I setup a reverse proxy on the same box that shuffles inbound traffic to 
127.0.0.1:port number, but this is an extremely hokey solution :)

-D
  
_
The New Busy think 9 to 5 is a cute idea. Combine multiple calendars with 
Hotmail. 

PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_5
[[alternative HTML version deleted]]

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


[R] efficiently picking one row from a data frame per unique key

2010-04-12 Thread James Kebinger
Hello all, I'm trying to transform data frames by grouping the rows by the
values in a particular column, ordered by another column, then picking the
first row in each group.

I'd like to convert a data frame like this:

x  y  z
1 10 20
1 11 19
2 12 18
4 13 17

into one with three rows, like this, where i've discarded one row:

 x  y  z
1 1 11 19
2 2 12 18
4 4 13 17

I've got a solution using aggregate, but it gets very slow with any volume
of data - the performance seems mostly IO bound and never finishes with  a
data set ~6MB

Here's how I'm currently trying to do this

 d = data.frame(x=c(1,1,2,4),y=c(10,11,12,13),z=c(20,19,18,17))
d.ordered = d[order(-d$y),]
aggregate(d.ordered,by=list(key=d.ordered$x),FUN=function(x){x[1]})

I've tried to use split and unsplit, but unsplit complained about duplicate
row names when reassembling the sub frames.

thanks for your suggestions

-james

[[alternative HTML version deleted]]

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


Re: [R] SSH Through R Script

2010-04-12 Thread Sharpie


afoo wrote:
 
 Hi,
 
 I am trying to SSH to a remote server through R script. In other words, I
 would like to know how I can get a SSH connection to the remote server and
 then execute commands on that server with the R script.
 
 So in bash, I would normally type ssh -lusername remoteserver.com; press
 enter and then wait for the password prompt to key in my password.
 
 I have tried system(ssh remoteserver.com) but that doesn't work because,
 from what I know, SSH requires user interactivity - I am required to key
 in my password.
 
 I tried looking up about putting password as a command line parameter, but
 SSH doesn't allow that, my only option then is to set up a private/public
 key pair. But the admin of the remoteserver doesn't allow me to do that.
 
 Is there a way in which I can SSH in? Or is there a command in R that
 allows me to interact with the command prompts interactively?
 
 thanks,
 afoo
 

You can secure your public/private keys with a password if there is a
concern about security.  You can still use these keys to allow programs
automatic access by using ssh-agent to hold the identities.  For example,  I
could create a new key for my web server like so:

  ssh-keygen
  Enter file in which to save the key (/Users/Sharpie/.ssh/id_rsa): 
/Users/Sharpie/.ssh/webKey
  Enter passphrase (empty for no passphrase): superSecretPassword
  Enter same passphrase again: superSecretPassword

The next step is to copy the public key, ~/.ssh/webKey.pub, to the remote
server and add it to the authorized keys file.

  scp ~/.ssh/webKey.pub u...@webserver.com:~/.ssh
  ssh u...@webserver.com -e cd ~/.ssh;cat webKey.pub  authorized_keys

You could now sign in using the key:

  ssh -i ~/.ssh/webKey u...@webserver.com

But you still have to provide a password since the key is protected.  To
ease this restriction, start ssh-agent.  ssh-agent provides some environment
variables that must be set, so it has to be run using eval ` `, like so:

  eval `ssh-agent`

You can then add your key to the agent:

  ssh-add ~/.ssh/webKey

You still have to enter your password, but from now on all processes spawned
from this shell can use that key without requiring the password to be
re-entered.  Now you can start R and access ssh key free.

The best way I can think of to run ssh from within R is to start the process
on a pipe and have it write the output to a fifo.  You can then use
writeLines to send commands to the pipe and readLines to get the output from
the fifo.  First, make the fifo

  system('mkfifo sshOut')

Then, connect to the pipe and the fifo from within R:

  # The  redirects both stdout and stderr to the fifo
  sshIn - pipe( 'ssh -i ~/.ssh/webKey u...@server.com  sshOut', open =
'w'
  sshOut - fifo( 'sshOut', 'r' )

Now you can queue commands to be executed with writeLines(), send them with
flush() and get the results using readLines():

  writeLines( 'ls', sshIn )
  flush( sshIn )

  readLines( sshOut )

 [1] Pseudo-terminal will not be allocated because stdin is not a
terminal.
 [2] backup
 [3] bin   
 [4] cache 
 [5] Cellar
 [6] code  
 [7] dat   
 [8] doc   
 [9] gems  
[10] gitrepos  
[11] include   
[12] lib   
[13] libexec   
[14] logs  
[15] man   
[16] opt   
[17] share 
[18] source
[19] specifications
[20] stash 
[21] webapps 

Remember to run close() on sshIn when you want to sever the connection.

Hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://n4.nabble.com/SSH-Through-R-Script-tp1809635p1837919.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the 

Re: [R] SSH Through R Script

2010-04-12 Thread Sharpie

Sorry about the double post, but this line:


Sharpie wrote:
 
   ssh u...@webserver.com -e cd ~/.ssh;cat webKey.pub  authorized_keys
 

Should be:

  ssh u...@webserver.com cd ~/.ssh;cat webKey.pub  authorized_keys

I.e., omit the -e flag.

Apologies,

-Charlie

-
Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://n4.nabble.com/SSH-Through-R-Script-tp1809635p1837920.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] efficiently picking one row from a data frame per unique key

2010-04-12 Thread Phil Spector

James -
If I understand you correctly:

getone = function(df)df[order(df$x,df$y),][1,]

describes what you want from each data frame corresponding
to a unique value of x.   Then, supposing that your data frame
is called df:

sdf = split(df,df$x)

will create a list of data frames for the unique values
of x, and

do.call(rbind,lapply(sdf,getone))

will return a data frame with one row for each unique value
of x.

- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu


On Mon, 12 Apr 2010, James Kebinger wrote:


Hello all, I'm trying to transform data frames by grouping the rows by the
values in a particular column, ordered by another column, then picking the
first row in each group.

I'd like to convert a data frame like this:

x  y  z
1 10 20
1 11 19
2 12 18
4 13 17

into one with three rows, like this, where i've discarded one row:

x  y  z
1 1 11 19
2 2 12 18
4 4 13 17

I've got a solution using aggregate, but it gets very slow with any volume
of data - the performance seems mostly IO bound and never finishes with  a
data set ~6MB

Here's how I'm currently trying to do this

d = data.frame(x=c(1,1,2,4),y=c(10,11,12,13),z=c(20,19,18,17))
d.ordered = d[order(-d$y),]
aggregate(d.ordered,by=list(key=d.ordered$x),FUN=function(x){x[1]})

I've tried to use split and unsplit, but unsplit complained about duplicate
row names when reassembling the sub frames.

thanks for your suggestions

-james

[[alternative HTML version deleted]]

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



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


Re: [R] efficiently picking one row from a data frame per unique key

2010-04-12 Thread Peter Alspach
Tena koe James

You might try duplicated(), or more to the point !duplicated()

orderedData[!duplicated(orderedData$x),]

HTH 

Peter Alspach

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of James Kebinger
 Sent: Tuesday, 13 April 2010 1:34 p.m.
 To: r-help@r-project.org
 Subject: [R] efficiently picking one row from a data frame per unique
 key
 
 Hello all, I'm trying to transform data frames by grouping the rows by
 the
 values in a particular column, ordered by another column, then picking
 the
 first row in each group.
 
 I'd like to convert a data frame like this:
 
 x  y  z
 1 10 20
 1 11 19
 2 12 18
 4 13 17
 
 into one with three rows, like this, where i've discarded one row:
 
  x  y  z
 1 1 11 19
 2 2 12 18
 4 4 13 17
 
 I've got a solution using aggregate, but it gets very slow with any
 volume
 of data - the performance seems mostly IO bound and never finishes
with
 a
 data set ~6MB
 
 Here's how I'm currently trying to do this
 
  d = data.frame(x=c(1,1,2,4),y=c(10,11,12,13),z=c(20,19,18,17))
 d.ordered = d[order(-d$y),]
 aggregate(d.ordered,by=list(key=d.ordered$x),FUN=function(x){x[1]})
 
 I've tried to use split and unsplit, but unsplit complained about
 duplicate
 row names when reassembling the sub frames.
 
 thanks for your suggestions
 
 -james
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


[R] Binning Question

2010-04-12 Thread Noah Silverman
Hi,

I'm trying to setup some complicated binning with statistics and could
use a little help.

I've found the bin2 function from the ash package, but it doesn't do
everything I need.  My intention is to copy some of their code and then
modify as needed.

I have a vector of two columns:

head(data)
  r1  r2
[1,]  0.03516559  0.03102128
[2,]  0.02162539  0.14847034
[3,]  0.02210339  0.06539623
[4,] -0.07547792 -0.08859678
[5,]  0.03655620  0.05412436
[6,]  0.06513828  0.06053050


I'd like to create a 2 dimension list of bins with the frequency counts
for each bin.  The bin2 function does this.  Then it gets interesting.

I'd like to add a column to my vector that has the bin label for the
bin that row would belong to.  (I can see how to do this with lots of
nasty loops and greater-than, less-than calculations, but that gets
messy.)  There must be an easier way.

So, If I made 10 bins for each column (r1,r2), I'd have 100 bins. 
(bin1, bin2, bin3, etc.)  I want to label each ROW in my data set with
the bin it would belong to.  (I intend to do more work with them after
this, but this starts.  Each row gets transformed depending on the bin
it belongs to, etc..)

Thanks,

-N

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