[R] different results of fisher.test function in R2.8.1 and R2.6.0

2009-03-26 Thread 马传香
Hi;
I use the function fisher.test to compute in R2.8.1 and R2.6.0,and the
results are not identical.the last number is different.  why?
thank you !


Merry

[[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] Combining multiple dataframes in a list

2009-03-26 Thread Daren Tan
I have a list containing multiple dataframes. Depending on whether the
dataframes have 1 column or more than 1 columns, the column names are
named differently. How can I force single column dataframes to have
prefixed column names ?

> m<- list(fc=data.frame(A=1:3))
> do.call(cbind, m)
  A
1 1
2 2
3 3

> m<- list(fc=data.frame(A=1:3, B=2:4))
> do.call(cbind, m)
  fc.A fc.B
112
223
334

__
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] Physical or Statistical Explanation for the "Funnel" Plot?

2009-03-26 Thread Mike Miller

On Thu, 26 Mar 2009, Jason Rupert wrote:

The R code below produces (after running for a few minutes on a decent 
computer) the plot shown at the following location:


http://n2.nabble.com/Is-there-a-physical-and-quantitative-explanation-for-this-plot--td2542321.html

I'm just taking the mean of a given set of random variables, where the 
set size is increased.  There appears to be a quick convergence and then 
a pretty steady variance out to a set size of 10,.



I don't have time to study your code, but it sounds like you are taking 
random normal variables with mean 0 and variance 1, but then taking the 
mean for sets of those.  We know exactly the distribution for the mean of 
the "set" (a.k.a., "sample").  The mean has a normal distribution with 
mean 0 and variance 1/N where N is the size of the sample.  When you allow 
N to vary, you produce a mixture of random normal variables all having 
mean 0 but with different variances.  The plot you show looks correct -- 
the distributions in the mixture that have small variance pile up in the 
middle, while those with greater variance form the long tails.  You could 
get a lot of different shapes depending ont he distribution of N.  But 
save yourself some time.  Instead of making N normal variables and taking 
the mean, just make one and divide it by sqrt(N) -- that will give you 
*exactly* the same result.


Your graph looks a little weird - first, why turn it sideways?  We 
normally plot density on the ordinate, not on the abscissa.  Second, there 
is a thick black bar on the left, but that seems to be an artifact because 
at least half of it is below zero -- how can that happen?


Mike

__
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] Installing Rmpi on Centos 5.2

2009-03-26 Thread Rick Bilonick
I am trying to install the R package "Rmpi" which needs libmpi. I've
installed openmpi and lam in Centos 5.2:

[r...@rab45-1 /]# rpm -qv openmpi
openmpi-1.2.5-5.el5
openmpi-1.2.5-5.el5
[r...@rab45-1 /]# rpm -qv lam
lam-7.1.2-14.el5
lam-7.1.2-14.el5

I'm using this to install Rmpi:

R CMD INSTALL /home/rick/Rmpi_0.5-7.tar.gz
--with-mpi=/usr/lib64/lam/include

But I get the following error message:

/usr/bin/ld: skipping incompatible /usr/lib/lam/lib/libmpi.so when
searching for -lmpi

I'm not sure what else to install/uninstall to fix this.

Rick B.

__
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] Need some help at interfacing R with Fortran-90

2009-03-26 Thread mauede
I browsed through ch.5 of R manual "Writing R extensions".
It seems to be written for experienced programmers rathern than for people who 
occasionally face this problem.
A table summarising the main ley points for each supported platform would be 
very useful.
Something like:
Supported languages: C, Fortran-77, ..

Windows guidelines:  
1. compie Fotran code with (commands) from (terminal / command line ... ?)
2. load compiled code with (commands) from ()
3. call Fortran subroutine from R passing arguments 

Linux guidelines:
1.
2.
3.

Unix guidelines:
1.
2.
3.

Coming to my problem. I have 4 Fortran-90 subroutines. There is a "main" 
routine calling the other three ones.
Therefore I only need to call, and exchange data, between R and the "main" 
Fortran subroutine.

Question-1:
 can Fotran-90 be interfaced to R ?  The manual mentions Fortran-77. I found no 
mention of Fortran-90 (which supports 
 dynamic memory allocation, and whose set of commands is bigger then Fortran-77)

Question-2:
Shall I generate executable code (compile the Fortran subroutines) through a 
Fortran compiler (which one ?) 
outside R environment ?

Question-3:
Shall I create a library ("so") object for each one of the 4 Fortran routiines 
or just the for the "main" one ?

Question-4:
What is the whole interfacing  procedure on a Windows/XP system  (steps 
sequence) ?

Question-5:
What is the whole interfacing  procedure on a Mac/OS system  (steps sequence) ?

Thank you in advance for clarifying my confusion.
Maura



tutti i telefonini TIM!




tutti i telefonini TIM!





tutti i telefonini TIM!


[[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] how to quit mailing list

2009-03-26 Thread Jorge Ivan Velez
Dear Jiang,
Go to https://stat.ethz.ch/mailman/listinfo/r-help and follow the
instructions at the end.

HTH,

Jorge


On Thu, Mar 26, 2009 at 11:27 PM, Jiang Peng  wrote:

>  Dear list,
>   I will not use this account later, so i have to quit this list.
>
>
>I don't know how to quit this list,  I search the official website
> and find no answer.
>
> thanks very much !!
>[[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.
>

[[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] how to quit mailing list

2009-03-26 Thread Rolf Turner


On 27/03/2009, at 4:27 PM, Jiang Peng wrote:


  Dear list,
   I will not use this account later, so i have to quit this list.


I don't know how to quit this list,  I search the official website
and find no answer.


Well you didn't search very hard.  Go to

Mailing Lists ---> R.help web interface ---> Unsubscribe or edit options

Doesn't seem too difficult to me.

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{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] Bug? FORTTRAN help

2009-03-26 Thread Berwin A Turlach
G'day Kevin,

On Thu, 26 Mar 2009 13:42:20 -0700
 wrote:

> I was feeling masochistic the other day [...]

Welcome to the club. :)

> and we have been having some wierd memory problems so I started
> digging into the source for L-BFGS-B. In the lbgfsb.c file I see the
> following code:
> 
> /* Cholesky factorization of (2,2) block of wn. */
> F77_CALL(dpofa)(&wn[*col + 1 + (*col + 1) * wn_dim1], &m2, col,
> info); if (*info != 0) {
>   *info = -2;
>   return;
> }
> 
> If I am not mistaken this says that there is a m2 * col matrix that
> starts at 'col + 1 + (col + 1) * wn_dm1. Where wn_dm1 is 2 * m.

I think your interpretation is not quite correct.  Note that it makes
only a sense to calculate a Cholesky factorization of a square matrix.
The interface of dpofa (in the linpack library) is available at:
 http://www.netlib.org/linpack/dpofa.f

Thus, the call above says, calculate the Cholesky factorization of a
col * col matrix whose (1,1) element is stored at &wn[*col+1+(*col+1)]
and that matrix is stored within a matrix which was allocated such that
it has m2 rows.

Or, in other words, calculate the Cholesky factorization of a col * col
matrix whose (1,1) element is stored at &wn[*col+1+(*col+1)] and to
move from the (1,1) element to the (1,2) element you have to move to
the memory location m2*sizeof(double) ahead/behind of (1,1).

Fortran uses a column major form to store arrays, i.e. element (1,1) is
followed by element (2,1), (3,1) and so forth.  To know where to find
element (1,2) of the matrix, you have to tell Fortran with how many
rows the "big matrix" that holds "your matrix" was allocated.

> I am worried that the optimizer will silently write info memory that
> it shouldn't [...]

If you are worried about such issues, you should read chapter 4 of
"Writing R extensions", in particular Section 4.3 on gctorture and
valgrind.  Then run R on a platform that supports valgrind.  It is very
useful to catch problems such as accessing or writing into memory that
you should not access or write to.

HTH.

Cheers,

Berwin

=== Full address =
Berwin A TurlachTel.: +65 6516 4416 (secr)
Dept of Statistics and Applied Probability+65 6516 6650 (self)
Faculty of Science  FAX : +65 6872 3919   
National University of Singapore 
6 Science Drive 2, Blk S16, Level 7  e-mail: sta...@nus.edu.sg
Singapore 117546http://www.stat.nus.edu.sg/~statba

__
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 quit mailing list

2009-03-26 Thread Jiang Peng
  Dear list,
   I will not use this account later, so i have to quit this list.


I don't know how to quit this list,  I search the official website  
and find no answer.

thanks very much !!
[[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] Conerned about Interfacing R with Fortran

2009-03-26 Thread Berwin A Turlach
G'day Maura,

On Thu, 26 Mar 2009 18:21:01 +0100
 wrote:

> I am reading the manual sections illustrating how to call a Fortran
> subroutine from R. I feel uneasy at the explicit statement about
> ".Fortran" interface working with Fortran 77. I would like to call a
> Fortran-90 subroutine from my R script. Is that supported at all ?

Read the completely manual. :)  It is pretty easy to use
acroread, or other PDF readers, to search for "Fortran" in the PDF
file; the HTML version should also be searchable from your browser.

In chapter 1 (page 7 of the PDF 2.8.1 version) of the Writing R
Extensions manual, you will find:

  [...] providing support for C, C++, FORTRAN 77, Fortran
  9...@footnote{note that Ratfor is not supported. If you have Ratfor
  source code, you need to convert it to FORTRAN.  Only FORTRAN-77
  (which we write in upper case) is supported on all platforms, but most
  also support Fortran-95 (for which we use title case).  If you want to
  ship Ratfor source files, please do so in a subdirectory of @file{src}
  and not in the main subdirectory.}, Objective C [...]

and later in chapter 1, there is a complete section (namely 1.2.3) on
F95 code:

  @subsection Using F95 code

  @R{} currently does not distinguish between FORTRAN 77 and Fortran
  90/95 code, and assumes all FORTRAN comes in source files with
  extension @file{.f}.  Commercial Unix systems typically use a F95
  compiler, but only since the release of @code{gcc 4.0.0} in April 2005
  have Linux and other non-commercial OSes had much support for F95.
  Only wih @R{} 2.6.0 did the Windows port adopt a Fortran 90 compiler.

  This means that portable packages need to be written in correct
  FORTRAN 77, which will also be valid Fortran 95.  See
  @uref{http://developer.r-project.org/Portability.html} for reference
  resources.  In particular, @emph{free source form} F95 code is not
  portable.

  On some systems an alternative F95 compiler is available: from the
  @code{gcc} family this might be @command{gfortran} or @command{g95}.
  Configuring @R{} will try to find a compiler which (from its name)
  appears to be a Fortran 90/95 compiler, and set it in macro @samp{FC}.
  Note that it does not check that such a compiler is fully (or even
  partially) compliant with Fortran 90/95.  Packages making use of
  Fortran 90/95 features should use file extension @file{.f90} or
  @file{.f95} for the source files: the variable @code{PKG_FCFLAGS}
  specifies any special flags to be used.  There is no guarantee that
  compiled Fortran 90/95 code can be mixed with any other type of code,
  nor that a build of @R{} will have support for such packages.

Section 5.5 (Creating shared objects) also mentions Fortran 9x:

  Shared objects for loading into @R{} can be created using @command{R
  CMD SHLIB}.  This accepts as arguments a list of files which must be
  object files (with extension @file{.o}) or sources for C, C++, FORTRAN
  77, Fortran 9x, Objective C or Objective C++ (with extensions
  @file{.c}, @file{.cc} or @file{.cpp} or @file{.C}, @file{.f},
  @file{.f90} or @file{.f95}, @file{.m}, and @file{.mm} or @file{.M},
  respectively), or commands to be passed to the linker.  See @kbd{R CMD
  SHLIB --help} (or the @R{} help for @code{SHLIB}) for usage
  information.

Thus, it seems that calling Fortran 90 code from R is possible on
some platforms and, presumably, on those where it is possible this is
done via the .Fortran interface; although the Writing R Extensions
manual does not seem to say so explicitly.

OTOH, the help file for .Fortran states:

 Use '.Fortran' with care for compiled Fortran 9x code: it may not
 work if the Fortran 9x compiler used differs from the Fortran
 compiler used when configuring R, especially if the subroutine
 name is not lower-case or includes an underscore.

HTH.

Cheers,

Berwin

=== Full address =
Berwin A TurlachTel.: +65 6516 4416 (secr)
Dept of Statistics and Applied Probability+65 6516 6650 (self)
Faculty of Science  FAX : +65 6872 3919   
National University of Singapore 
6 Science Drive 2, Blk S16, Level 7  e-mail: sta...@nus.edu.sg
Singapore 117546http://www.stat.nus.edu.sg/~statba

__
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] Some install package fixes for Ubuntu Hardy

2009-03-26 Thread Dirk Eddelbuettel

On 26 March 2009 at 09:45, John C Nash wrote:
| I encountered some failures in using install.packages() to install rgl 
| and rJava in some of my (multiple) Ubuntu Hardy systems. A quick search 
| of the 'Net did not show any debian packages for these. The 
| install.packages messages said header or other files were missing, 
| suggesting path and related woes. Email with Duncan Murdoch (thanks!) 
| pointed the way with rgl and led to a fix for rJava in similar fashion. 
| It may save others some frustration to know my resolution. See below.
| 
| However, I do have a question which a brief rummage of r-project did not 
| answer. Where should information like this be put? My opinion is that it 

Maybe on the r-sig-debian list that is dedicated to Debian / Ubuntu and R?

| should go on the wiki, but possibly there is a better solution if we can 
| get the right messages into the package installers, though I recognize 
| the load that puts on maintainers.
| 
| Cheers, JN
| 
| Ubuntu Hardy rgl install fix:
| 
| The headers gl.h and glu.h are installed with the "dev" packages 
| libgl1-mesa-dev and libglu1-mesa-dev. So the fix is to run (in at 
| terminal as root)
| 
| apt-get install libgl1-mesa-dev
| apt-get install libglu1-mesa-dev

Yes, which is why the r-cran-rgl package (available in Debian for over five
years now, and hence in Ubuntu for probably 4 1/2) has the following
Build-Depends (with my manual indentation here):

  Build-Depends: debhelper (>= 5.0.0), r-base-dev (>= 2.8.1), cdbs, \
  libgl1-mesa-dev | libgl-dev, libglu1-mesa-dev | libglu-dev, \
  libpng12-dev, libx11-dev, libxt-dev, x11proto-core-dev 
 
| then
| R
| .
| install.packages("rgl")
| 
| etc.

Let's not forget the 'sudo apt-get install r-cran-rgl' alternative.
 
| Ubuntu Hardy rJava install fix:
| 
| Needed to get Sun JDK (not JRE)
| 
| Then add new
| ln -s /usr/java/jdkx/bin/java java
| and
| ln -s /usr/java/jdkx/bin/javac javac
| 
| where xx is the version information on the jdk directory name -- in 
| my case 1.6.0_13 (see below)
| 
| Then
| 
| R CMD javareconf
| 
| still fails to find the java compiler.
| 
| Seems $JAVA_HOME may not be defined.
| 
| Try
| export JAVA_HOME="/usr/java/jdk1.6.0_13/"
| 
| Then (as root)
| 
| R CMD javareconf
| 
| seems to work.
| Then rJava installed OK. I was then able to install RWeka (my original 
| objective) and it seems to run OK.

Likewise, the r-cran-rjava package has 

   Build-Depends: debhelper (>= 7.0.0), r-base-dev (>= 2.8.1), cdbs, \
  openjdk-6-jdk, automake

and R is now configured for this Java version at the built.


Again, questions on the r-sig-debian list may have been of help.

Hope this helps,  Dirk

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

__
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] Physical or Statistical Explanation for the "Funnel" Plot?

2009-03-26 Thread Jason Rupert

The R code below produces (after running for a few minutes on a decent 
computer) the plot shown at the following location:

http://n2.nabble.com/Is-there-a-physical-and-quantitative-explanation-for-this-plot--td2542321.html

I'm just taking the mean of a given set of random variables, where the set size 
is increased.  There appears to be a quick convergence and then a pretty steady 
variance out to a set size of 10,.  

I'm just wondering if there is a statistical explanation out there for this 
convergence and it has been explored further.  Thanks again. 

# First case
N<-10
X<-rnorm(N)
step_size<-1


# Groups
g<-rep(1:(N/step_size),each=step_size)

# The result
tmp_output<-tapply(X[1:length(g)],g,mean)

length_tmp_output<-length(tmp_output)
tmp_x_vals<-rep(step_size,length_tmp_output)
plot(tmp_x_vals, tmp_output, xlim=c(0,1))
#points(tmp_x_vals, tmp_output)

for(ii in 1:1)
{   
step_size<-ii

# Groups
g<-rep(1:(N/step_size),each=step_size)

# The result
#tmp_output<-tapply(X,g,mean)
tmp_output<-tapply(X[1:length(g)],g,mean)

length_tmp_output<-length(tmp_output)
tmp_x_vals<-rep(step_size,length_tmp_output)
points(tmp_x_vals, tmp_output)
}

__
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] Overlying a map on top of an image [SEC=UNCLASSIFIED]

2009-03-26 Thread Augusto.Sanabria
Good day everyone,

I have a *.jpeg map and I want to display it
on top of an existing image (created using 'image'),
Is there an easy way to do it?
"map" does the job but only with pre-existing maps
(from its database) not with my map.

I would greatly appreciate any help in this matter.

Thanks,


Augusto



Augusto Sanabria. MSc, PhD.
Mathematical Modeller
Risk & Impact Analysis Group
Geospatial & Earth Monitoring Division
Geoscience Australia (www.ga.gov.au)
Cnr. Jerrabomberra Av. & Hindmarsh Dr.
Symonston ACT 2601
Ph. (02) 6249-9155

__
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] use of "@" character in variable name

2009-03-26 Thread Rolf Turner


On 27/03/2009, at 2:52 PM, Marc Schwartz wrote:



On Mar 26, 2009, at 8:40 PM, Rolf Turner wrote:



On 27/03/2009, at 2:04 PM, Mike Miller wrote:


Importing data with a header row using read.delim, one variable
should be
named @5HTT but it is automatically renamed to X.5HTT, presumably
because
the "@" is either unacceptable or misunderstood.  I've tried to
find out
what the rules are on variable names but have been unsuccessful.
I'll bet
someone here can tell me where to look.  Maybe it's hidden away in
here
somewhere:

http://cran.r-project.org/doc/manuals/R-data.pdf


I don't know if there is a comprehensive list of the rules governing
variable names but the ``@'' sign is used to access ``slots'' under
S4 classes and methods.  See ?"@".  So it is (like?) an operation/
operator
and hence is ruled out just like ``+5HTT'' would be.  Reserved words
like
``break'' and ``while'' are also excluded.  See fortune(18).

Another rule is that a variable name can't begin with a digit.

And it can't have white space in it.

There are probably other rules, but essentially anything *sensible*
as a variable name can be used as a variable name.



See ?make.names for more information, which is noted in the
description of the 'check.names' argument in the read.table() family
of functions.


It might also be useful to note that a list of reserved words can be  
found via


?Reserved

(as I found out from ??"reserved words").

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{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] use of "@" character in variable name

2009-03-26 Thread John Fox
Dear Mike,

As a slight simplification, a legal R name can start with a period (.),
upper- or lower-case letter (A-Z, a-z), and can contain periods, underscores
(_), letters, and numerals; depending upon the locale, some other characters
may also be allowed. This information *is* in the R manuals, though it might
not be that easy to locate: See section 10.3.2 of the R Language Definition
manual or 1.8 of the Introduction to R manual.

@ is used to access slots in an S4 object.

I hope this helps,
 John


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On
> Behalf Of Mike Miller
> Sent: March-26-09 9:04 PM
> To: R-Help List
> Subject: [R] use of "@" character in variable name
> 
> Importing data with a header row using read.delim, one variable should be
> named @5HTT but it is automatically renamed to X.5HTT, presumably because
> the "@" is either unacceptable or misunderstood.  I've tried to find out
> what the rules are on variable names but have been unsuccessful.  I'll bet
> someone here can tell me where to look.  Maybe it's hidden away in here
> somewhere:
> 
> http://cran.r-project.org/doc/manuals/R-data.pdf
> 
> Thanks in advance.
> 
> Mike
> 
> __
> 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] use of "@" character in variable name

2009-03-26 Thread Marc Schwartz


On Mar 26, 2009, at 8:40 PM, Rolf Turner wrote:



On 27/03/2009, at 2:04 PM, Mike Miller wrote:

Importing data with a header row using read.delim, one variable  
should be
named @5HTT but it is automatically renamed to X.5HTT, presumably  
because
the "@" is either unacceptable or misunderstood.  I've tried to  
find out
what the rules are on variable names but have been unsuccessful.   
I'll bet
someone here can tell me where to look.  Maybe it's hidden away in  
here

somewhere:

http://cran.r-project.org/doc/manuals/R-data.pdf


I don't know if there is a comprehensive list of the rules governing
variable names but the ``@'' sign is used to access ``slots'' under
S4 classes and methods.  See ?"@".  So it is (like?) an operation/ 
operator
and hence is ruled out just like ``+5HTT'' would be.  Reserved words  
like

``break'' and ``while'' are also excluded.  See fortune(18).

Another rule is that a variable name can't begin with a digit.

And it can't have white space in it.

There are probably other rules, but essentially anything *sensible*
as a variable name can be used as a variable name.



See ?make.names for more information, which is noted in the  
description of the 'check.names' argument in the read.table() family  
of functions.


HTH,

Marc Schwartz

__
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] pgmm (blundell-bond) help needed

2009-03-26 Thread ivo welch
I have been playing with more examples, and I now know that with
larger NF's my example code actually produces a result, instead of a
singular matrix error.  interestingly, stata's xtabond2 command seems
ok with these sorts of data sets.  either R has more stringent
requirements, or stata is too casual.  in any case, I find it strange
that Blundell-Bond would not work on data sets in which N=20 and T=10,
and there is only one parameter to estimate.  there should be more
than enough degrees of freedom.

I will experiment more with it.

regards,

/iaw

__
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] use of "@" character in variable name

2009-03-26 Thread Rolf Turner


On 27/03/2009, at 2:04 PM, Mike Miller wrote:

Importing data with a header row using read.delim, one variable  
should be
named @5HTT but it is automatically renamed to X.5HTT, presumably  
because
the "@" is either unacceptable or misunderstood.  I've tried to  
find out
what the rules are on variable names but have been unsuccessful.   
I'll bet
someone here can tell me where to look.  Maybe it's hidden away in  
here

somewhere:

http://cran.r-project.org/doc/manuals/R-data.pdf


I don't know if there is a comprehensive list of the rules governing
variable names but the ``@'' sign is used to access ``slots'' under
S4 classes and methods.  See ?"@".  So it is (like?) an operation/ 
operator
and hence is ruled out just like ``+5HTT'' would be.  Reserved words  
like

``break'' and ``while'' are also excluded.  See fortune(18).

Another rule is that a variable name can't begin with a digit.

And it can't have white space in it.

There are probably other rules, but essentially anything *sensible*
as a variable name can be used as a variable name.

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{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.


[R] ROCR package finding maximum accuracy and optimal cutoff point

2009-03-26 Thread Saeed Abu Nimeh
If we use the ROCR package to find the accuracy of a classifier
pred <- prediction(svm.pred, testset[,2])
perf.acc <- performance(pred,"acc")

Do we find the maximum accuracy as follows (is there a simplier way?):
> max(perf@x.values[[1]])

Then to find the cutoff point that maximizes the accuracy do we do the
following (is there a simpler way):
> cutoff.list <- unlist(perf@x.values[[1]])
> cutoff.list[which.max(perf@y.values[[1]])]

If the above is correct how is it possible to find the average false
positive and negative rates  from the following
perf.fpr <- performance(pred, "fpr")
perf.fnr <- performance(pred, "fnr")

The dataset that consists of two columns; score and a binary response,
similar to this:
2.5, 0
-1, 0
2, 1
6.3, 1
4.1, 0
3.3, 1


Thanks,
Saeed
 ---
R 2.8.1 Win XP Pro SP2
ROCR package v1.0-2
e1071 v1.5-19

__
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] use of "@" character in variable name

2009-03-26 Thread Krzysztof Sakrejda-Leavitt
The '@' character is an operator used for accessing slots in S4 classes. 
 Similarly the '$' character is the operator for accessing elements of 
lists, etc...


Although R allows periods, SQL databases will choke on them.  LaTeX will 
(sometimes?) choke on underscores, and of course any native R operator 
will cause problems.  My take is that camelBackCapitalization is the 
best practice in naming columns, list elements, variables, and functions 
for R.


Best,

Krzysztof.

Mike Miller wrote:
Importing data with a header row using read.delim, one variable should 
be named @5HTT but it is automatically renamed to X.5HTT, presumably 
because the "@" is either unacceptable or misunderstood.  I've tried to 
find out what the rules are on variable names but have been 
unsuccessful.  I'll bet someone here can tell me where to look.  Maybe 
it's hidden away in here somewhere:


http://cran.r-project.org/doc/manuals/R-data.pdf

Thanks in advance.

Mike

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



--

---
Krzysztof Sakrejda-Leavitt

Organismic and Evolutionary Biology
University of Massachusetts, Amherst
319 Morrill Science Center South
611 N. Pleasant Street
Amherst, MA 01003

work #: 413-325-6555
email: sakre...@nsm.umass.edu

__
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] use of "@" character in variable name

2009-03-26 Thread Mike Miller
Importing data with a header row using read.delim, one variable should be 
named @5HTT but it is automatically renamed to X.5HTT, presumably because 
the "@" is either unacceptable or misunderstood.  I've tried to find out 
what the rules are on variable names but have been unsuccessful.  I'll bet 
someone here can tell me where to look.  Maybe it's hidden away in here 
somewhere:


http://cran.r-project.org/doc/manuals/R-data.pdf

Thanks in advance.

Mike

__
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] Trellis barchart help

2009-03-26 Thread jimdare

Hi,

I apologise if this sounds like a really simple problem.  I have a
time-series data set with two columns of data: Catch and TACC.  I want Catch
plotted as a barchart and TACC plotted on the same graph as a series of
points with an overlaying a line.  I have created the code for a barchart
using the Catch data but I can't seem to figure out how to add the TACC data
as a line.  Can someone please enlighten me?

Regards,
James

Barchart code:

Schart<-barchart(Catch~Year,data=SNA,
scales=list(col = "black", tck = c(1, 0),x=list(rot=45)),
par.settings = list(axis.line = list(col = "transparent")),
  axis = function(side, ...) { 
if (side == "left") 
 grid.lines(x = c(0, 0), y = c(0, 1), 
default.units = "npc") 
else if (side == "bottom") 
 grid.lines(x = c(0, 1), y = c(0, 0), 
default.units = "npc")

axis.default(side = side, ...) 
}
)
-- 
View this message in context: 
http://www.nabble.com/Trellis-barchart-help-tp22733771p22733771.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] Snow Parallel R: makeCluster with more nodes than available

2009-03-26 Thread Ubuntu Diego
Hi all,
I would like to know what would happen if using snow I create a cluster
of size 50, for example using makeCluster(50,type='SOCK') on a machine
with 2 Cores and run a function. Does snow run 25 and 25 functions on
each of my 2 "real" processors or it just run 50 functions in one
processor ?
Thanks.

__
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 CRAN Package: WriteXLS

2009-03-26 Thread Marc Schwartz
A new package called WriteXLS (Version 1.5.0), containing a single  
function of the same name, is now available via CRAN. The package is  
made available under the GPL, version >=2.


The function is based upon a Perl script that I have previously posted  
on r-help, now wrapped in R for convenience. It provides a cross- 
platform function to create Excel 2003 (XLS) files from one or more  
data frames. Each data frame will be written to a separate named  
worksheet in the Excel spreadsheet. The worksheet name will be the  
name of the data frame it contains.


The package requires that Perl and several specific Perl modules are  
installed in order to function. These modules, which may already be  
installed on systems with Perl installed, include:


  OLE::Storage_Lite
  Parse::RecDescent
  Getopt::Long
  File::Basename
  Spreadsheet::WriteExcel
  Encode
  File::Glob
  Text::CSV_XS


With the exception of the last three modules listed, for convenience  
all are included in the CRAN package and will be made available by  
adding the installed package path for these modules to the Perl @INC  
array.


The last three modules (Encode, File::Glob and Text::CSV_XS) are 'XS'  
based Perl modules, meaning that they call external C routines. Thus,  
they are not included as they require local compilation using the  
particular version of Perl installed on the user's system.


As a result, only source versions of the WriteXLS package will be made  
available. This is because the examples on the function help page will  
not run without Perl and all of these modules being available on the  
user's system. Hence the package will presently fail 'R CMD check' on  
CRAN.


For more information on installing source packages from CRAN, please  
see:


  http://cran.r-project.org/doc/manuals/R-admin.html#Installing- 
packages


WriteXLS is being maintained using R-Forge at:

  http://r-forge.r-project.org/projects/writexls

Please feel free to contact me directly with questions and comments.

Many thanks to Prof. Brian Ripley for his assistance with the testing  
of this package prior to release.


Thanks,

Marc Schwartz

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


[R] R 2.8.1 and 2.9 alpha crash when running survest of Design package

2009-03-26 Thread Nguyen Dinh Nguyen
Dear Prof Harrell and everyone,

 

My PC: Window XP service pack 3 and service pack 2

R version 2.8.1 and 2.9 alpha

 

For the last 3 days, after updating R, my two computers have been facing
problems when running existing and runable R commands that involves with
Design package

 

I attempt to use 'survest', but I failed all the times with R (both 2.8.1
and 2.9 alpha) being shut down immediately with following error report
messages.

AppName: rgui.exe AppVer: 2.90.48212.0   ModName: survival.dll

ModVer: 0.0.0.0   Offset: 7749

 

However, if I run these commands on other computers which have not been
updated for 2 week, they run OK

 

Could you please consider the matter and give me advice

 

I am looking forward to hearing from you soon

 

Regards

Nguyen D Nguyen
Garvan Institute of Medical Research

Sydney, Australia


[[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] ApEn (Approximate Entropy), Total Corr, Information Interaction

2009-03-26 Thread Stephan Kolassa

Hi Vishal,

re 1]: Ben Bolker very kindly shared an R reimplementation of Kaplan's 
Matlab code a little while ago:

http://www.nabble.com/Approximate-Entropy--to21144062.html#a21149402

Best wishes
Stephan


Vishal Belsare schrieb:

Is there any existing implementation in R/S of :

1] Pincus & Kalman's approximate entropy (ApEn) measure
2] Total Correlation / Multiinformation
3] Information Interaction

A search doesn't quite reveal anything, but I'd be keen to not
reinvent in case someone has worked on it. Many thanks in
anticipation.


Best,

Vishal Belsare

__
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] for Interaction of continous var and categorical var, any way approach the categorical var to continous ?

2009-03-26 Thread Yong Wang
Dear list,

This is NOT a techical question ragrding use of R.

I have a linear model where the response variable is neigborhood
safety . It is projected poverty deteriorate safety and number of
officers per thousand residents improve safety. The focal hypothesis
is poverty poses less safety threat when officers number is high.

To check the focal hypothesis, the continuous variable "officers" is
recoded as catogorical with two levels (high and low). the results is
below and support the hyothesis

#=
model <- lm(neigborhood safety ~ poverty * officers)
The coefficients (all significant):
poverty-0.05
officers 0.058
poverty : officers0.014
#==

My question is how to check the weakened "poverty" effect with a
minuscle increase of "officers". the coeeficient for the interaction
term of continous "poverty" and "officers" is hard to interpret and is
not suitable to check the focal hypothesis since, say, (povety=3 &
officers=8) will be the same as (poverty=8 & officer=3).

Thanks a lot in advance for any suggestions!

Sincerely,

Will

__
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] Column name assignment problem

2009-03-26 Thread Tal Galili
Way are you taking the forth argument of the paste
?paste("arunoff_",table_year,
sep="")[4]

Either way, way not use something like:
colnames(x)[column to change] <- "text, or pasted text"

Cheers,
Tal




On Thu, Mar 26, 2009 at 2:33 PM, Steve Murray wrote:

>
> Dear all,
>
> I'm trying to assign a name to the fourth column whilst using 'assign', but
> keep encountering errors. What have I done wrong?!
>
> > assign(colnames(c(paste("arunoff_",table_year, sep="")[4]), "COUNT"))
>
> Error in if (do.NULL) NULL else if (nc> 0) paste(prefix, seq_len(nc),  :
>  argument is not interpretable as logical
>
>
> Hope someone is able to help.
>
> Thanks for any pointers,
>
> Steve
>
>
> _
> [[elided Hotmail spam]]
>
> __
> 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.
>



-- 
--


My contact information:
Tal Galili
Phone number: 972-50-3373767
FaceBook: Tal Galili
My Blogs:
http://www.r-statistics.com/
http://www.talgalili.com
http://www.biostatistics.co.il

[[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] pgmm (Blundell-Bond) sample needed

2009-03-26 Thread ivowel
Dear R Experts---

Sorry for all the questions yesterday and today. I am trying to use Yves  
Croissant's pgmm function in the plm package with Blundell-Bond moments. I  
have read the Blundell-Bond paper, and want to run the simplest model  
first, d[i,t] = a*d[i,t-1] + fixed[i] + u[i,t] . no third conditioning  
variables yet. the full set of moment conditions recommended for  
system-GMM, which is (T-1)*(T-2)/2+(T-3), in which the u's interact with  
all possible lagged y's and delta y's.

I believe that pgmm operates by demanding that "firm" (i) and "year" (t) be  
the first two columns in the data set.

library(plm)
NF=20; NT=10
d= data.frame( firm= rep(1:NF, each=NT), year= rep( 1:NT, NF),  
x=rnorm(NF*NT) );

# the following fails, because dynformula magic is required; learned this  
the hard way
# v=pgmm( x ~ lag(x), data=d, gmm.inst=~x, lag.gmm=c(2,99),  
transformation="ld" )

formula= dynformula( x ~ 1, list(1)); # this creates x ~ lag(x)
v=pgmm( formula, data=d, gmm.inst=~x, lag.gmm=c(2,99), transformation="ld" )

Error in solve.default(suml(Vi)) :
system is computationally singular: reciprocal condition number =  
8.20734e-20

obviously, I am confused. when I execute the same command on the included  
UKEmpl data set, it works. however, my inputs would seem perfectly  
reasonable. I would hope that the procedure could produce a lag(x)  
coefficient estimate of around 0, and then call it a day.

could someone please tell me how to instruct pgmm to just estimate this  
simplest of all BB models?


[My ultimate goal is to replicate what another author has run via "xtabond2  
d ld, gmm(L.(d), lag(1 3)) robust" in Stata; if you know the magic of  
moving this statement into pgmm syntax, I would be even more grateful.  
Right now, I am so stuck on square 1 that I do not know how to move towards  
figuring out where I ultimately need to go.]

regards,

/iaw

[[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] ApEn (Approximate Entropy), Total Corr, Information Interaction

2009-03-26 Thread Vishal Belsare
Is there any existing implementation in R/S of :

1] Pincus & Kalman's approximate entropy (ApEn) measure
2] Total Correlation / Multiinformation
3] Information Interaction

A search doesn't quite reveal anything, but I'd be keen to not
reinvent in case someone has worked on it. Many thanks in
anticipation.


Best,

Vishal Belsare

__
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] VGAM and cnstraints

2009-03-26 Thread Raffaello Vardavas

Dear R-Users,

I am learning how to use the package VGAM to do multinomial regressions.

I have worked through the example provided by UCLA stats group:

http://www.ats.ucla.edu/stat/r/dae/mlogit.htm

However - what I would like to learn is how to use the constraint option.

So in the example given in the link i would like to introduce a constraint that 
does not allow individuals of age less than say 25 to buy brand 1 (for whatever 
reason)

how do I enter this constraint?

Thanks.

Raff.  

_


[[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] Bug? FORTTRAN help

2009-03-26 Thread rkevinburton
I was feeling masochistic the other day and we have been having some wierd 
memory problems so I started digging into the source for L-BFGS-B. In the 
lbgfsb.c file I see the following code:

/* Cholesky factorization of (2,2) block of wn. */
F77_CALL(dpofa)(&wn[*col + 1 + (*col + 1) * wn_dim1], &m2, col, info);
if (*info != 0) {
*info = -2;
return;
}

If I am not mistaken this says that there is a m2 * col matrix that starts at 
'col + 1 + (col + 1) * wn_dm1. Where wn_dm1 is 2 * m. My first question is to 
verify that statement. 
Say I am trying to optimize the "banana function" as given in the 
documentation. In that case n = 2 and the default m = 5. So m2 is 10 and 
wn_dim1 is 20 and the dimension of wn is 100 (this is all by deduction. So if 
col is 5 then the offset into the array is 55 and there is not room in the 
vector for a 10 x 5 array. I am worried that the optimizer will silently write 
info memory that it shouldn't but more than likely it is something that I don't 
understand. So please vefify my first statement.

Thank you.

Kevin

__
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] ICC question: Interrater and intrarater variability (intraclass correlation coefficients)

2009-03-26 Thread Tal Galili
Hello dear R help group.

I encountered this old thread (http://tinyurl.com/dklgsk) containing the a
similar question to the one I have, but left without an answer.
I am and hoping one of you might help.


A simplified situation: I have a factorial design (with 2^3 experiment
combinations), for 167 subjects, each one has answered the same question
twice (out of a bunch of "types" of questions).
Each answer could get an integer number between 0 to 3.

I wish to combine the two answers, but first to be sure I could, I would
have liked to run an ICC (Intraclass correlation) check on the two answers.
Naturally, I would use the irr, condord, or psy packages (as John Fox
suggested back then), but I can't because of the repetitions of different
design question for each patient.
Since the mentioned packages (irr, condord, and psy) Can take only a n*m
matrix for subjects and raters. But no place is given for the repetitions as
data and therefore it will be impossible to get results
for the INTRArater reliability.


Thanks,

Tal









-- 
--


My contact information:
Tal Galili
Phone number: 972-50-3373767
FaceBook: Tal Galili
My Blogs:
http://www.r-statistics.com/
http://www.talgalili.com
http://www.biostatistics.co.il

[[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] Hazard rate estimation by smoothing baseline cumulative hazard from Cox model - Was: RE: Competing risks Kalbfleisch & Prentice method

2009-03-26 Thread Ravi Varadhan
Hi Eleni,

I will take a look at this.  I have some preliminary comments.

You estimate the hazard function from the Cox model baseline cumulative
hazard by differencing successive jumps.  It seems that a better approach
might be to estimate this using kernel smoothing, i.e. as the derivative of
kernel-smoothed cumulative hazard function.  This method is available in the
"muhaz" package.  However, the muhaz() function does not work with the Cox
model baseline cumulative hazard.  It requires you to input the original
data on times and censoring indicators.  It would be nice if this were
possible.  I am wondering why Terry Therneau's "survival" package doesn't
have this option.  

Best,
Ravi.



---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html

 





-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Eleni Rapsomaniki
Sent: Thursday, March 26, 2009 1:17 PM
To: Ravi Varadhan; Heinz Tuechler
Cc: r-help@r-project.org
Subject: Re: [R] Competing risks Kalbfleisch & Prentice method

Ravi,

I agree with you, that the Fine & Gray method does much more than
calculating the cumulative incidence. The Kalbfleisch & Prentice formula
relies on the strong assumption that the coefficients for the cause specific
hazard models are valid in the presence of competing risks. You will find my
code below, but it may be wrong (I'm not really a statistician!). And no, it
doesn't even calculate confidence intervals...

Thank you for pointing out these papers. 
Please let me know (nicely) if you find bugs!!!

#
#Method to calculate Cumulative Incidence adjusting for competing risks,
based on the Kalbfleisch & Prentice formula, 1980, p.169 #create data  ftime
<- rexp(200, 0.3)  fstatus <- sample(0:2,200,replace=TRUE)  cov <-
matrix(runif(600),nrow=200)  dimnames(cov)[[2]] <- c('x1','x2','x3')
dat=data.frame(ftime, fstatus, cov)


diffrHaz=function(x){
hazard=x$hazard
time=x$time

hz.v=NULL

for(e in 1:(length(hazard)-1)){
hz=hazard[e+1]-hazard[e]
hz.v=c(hz.v,hz)
}
dhz=data.frame(hazard=hz.v, time=x$time[-length(x$time)])
return(dhz)
}


#build cause specific cox models
library(Design)
 a.f=cph(Surv(ftime, fstatus==1) ~ x1+x2+x3, data=dat, surv=T, x=T, y=T)
b.f=cph(Surv(ftime, fstatus==2) ~ x1+x2+x3, data=dat, surv=T, x=T, y=T)
 
#get unique event times - up till the time of interest, eg. time=10
uts=unique(dat$ftime[dat$fstatus>0] ) uts=uts[uts<=10]  # the times up till
10 years uts=uts[order(uts)]  #order them

#get baseline hazard rate (cumulative)
a.bz=basehaz(a.f)
b.bz=basehaz(b.f)

#get instanteneous baseline hazard rate, apply above function
a.dhz1=diffrHaz(a.bz)
b.dhz1=diffrHaz(b.bz)

P.t=NULL #intitialize where to store all results for(i in 1:nrow(dat)){  # i
is the individual, iterate through the number of rows in dat
P.i.t=NULL
all.lambda.i.t=NULL

for(u.i in 1:length(uts)){
 u=uts[u.i]
#get the instanteneous baseline hazard from each model corresponding
to this timepoint (if there is no event at that time return 0)
a.dhz.u=ifelse((u %in%
a.dhz1$time)==F,0,a.dhz1$hazard[a.dhz1$time==u])
b.dhz.u=ifelse((u %in%
b.dhz1$time)==F,0,b.dhz1$hazard[b.dhz1$time==u])

#multiply by the linear predictors to get the actual hazard at that
point
a.lambda.i.u=a.dhz.u*exp(a.f$linear.predictors[i])
b.lambda.i.u=b.dhz.u*exp(b.f$linear.predictors[i])
all.lambda.i.u=a.lambda.i.u+b.lambda.i.u
#store in a vector
all.lambda.i.t=c(all.lambda.i.t, all.lambda.i.u) #build a vector
with all previous all.lambda.i.u's
S.i.u=exp(-sum(all.lambda.i.t)) #this is the probability of
surviving till time u

p.i.u=S.i.u*a.lambda.i.u

P.i.t=c(P.i.t, p.i.u)

}
P.t[i]=sum(P.i.t)
}

# to compare with unadjusted:
a.risk   = 1-survest(a.f, linear.predictors=a.f$linear.predictors,
times=10)$surv
plot(a.risk ~ P.t) #P.t is the CR adjusted, should always be lower
mean(a.risk)
mean(P.t)

Eleni Rapsomaniki
 
Research Associate
Tel: +44 (0) 1223 740273
Strangeways Research Laboratory
Department of Public Health and Primary Care University of Cambridge
 

-Original Message-
From: Ravi Varadhan [mailto:rvarad...@jhmi.edu]
Sent: 26 March 2009 14:36
To: Eleni Rapsomaniki; 'Arthur Allignol'
Cc: r-help@r-project.org
Subject: RE: [R] Competing risks Kalbfleisch & Prentice method

Hi Eleni,

I would like to take a look at your R function for obtaining the cumulative
incidence function (CIF) from individual Cox mod

Re: [R] Analogy for %in% for the whole columns (rather than individual values)

2009-03-26 Thread Dimitri Liakhovitski
Thank you very much! I tried %in% and it did not work. However == works!
Thank you!

On Thu, Mar 26, 2009 at 3:05 PM, Fredrik Karlsson  wrote:
> Hi Dimitri,
>
> What about this:
>
>
>> with(a, x == y) -> a$equal
>> a
>  x    y equal
> 1 john mary FALSE
> 2 mary mary  TRUE
> 3 mary john FALSE
> 4 john john  TRUE
>
> /Fredrik
>
> On Thu, Mar 26, 2009 at 7:48 PM, Dimitri Liakhovitski 
> wrote:
>>
>> Hello!
>>
>> I have a matrix a with 2 variables (see below) that contain character
>> strings.
>> I need to create a 3rd variable that contains True if the value in
>> column x is equal to the value in column y. The code below does it.
>>
>> a<-data.frame(x=c("john", "mary", "mary",
>> "john"),y=c("mary","mary","john","john"))
>> a$x<-as.character(a$x)
>> a$y<-as.character(a$y)
>> a$equal<-NA
>> for(i in 1:nrow(a)) {a[i,3]<-a[i,1] %in% a[i,2]}
>>
>> I was wondering if one can do it faster, without doing it row-by-row
>> as I did it. Maybe there is a faster way to compare 2 columns?
>>
>> Thank you very much!
>>
>> --
>> Dimitri Liakhovitski
>> MarketTools, Inc.
>> dimitri.liakhovit...@markettools.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.
>
>
>
> --
> "Life is like a trumpet - if you don't put anything into it, you don't get
> anything out of it."
>



-- 
Dimitri Liakhovitski
MarketTools, Inc.
dimitri.liakhovit...@markettools.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] Reading in files with variable parts to names

2009-03-26 Thread Jorge Ivan Velez
Dear Steve,

Another option would be using list() to storage your files into R:

# Year/Month
year <- 1986:1995
month <- sprintf("%02d", 1:12)

# Names
Files <- paste(year,month,'.asc',sep="")

# Data
ListFiles <- sapply(Files, read.table, header=TRUE,sep="")

# To access the fist file
ListFiles[[1]]  #for the first

HTH,

Jorge


On Thu, Mar 26, 2009 at 2:40 PM, Steve Murray wrote:

>
> Dear all,
>
> I'm trying to read in a whole directory of files which have two variable
> parts to the file name: year and month. E.g. comp198604.asc represents April
> of 1986 - 'comp' is fixed in each case. Years range between 1986 to 1995 and
> months are between 1 and 12.
>
> Just to be clear, there are 12 files associated with each year: e.g.
> comp198601, comp198602, ... comp198612  through to comp199501, comp199502
> ... comp199512.
>
> I am trying to automate the reading in of these files, but am struggling to
> find an adequate way of achieving this. The closest I've got is by doing:
>
>
>
> year <- 1986:1995
> month <- sprintf("%02d", 1:12)  # formats numbers to 2 digits (for
> maintaining leading zeros in file names)
>
> filelist <- paste("C:\\Documents and
> Settings\\Data\\comp",year,month,".asc", sep="")
>
> filelist
>
>  [1] "C:\\Documents and Settings\\Data\\comp198601.asc"
>  [2] "C:\\Documents and Settings\\Data\\comp198702.asc"
>  [3] "C:\\Documents and Settings\\Data\\comp198803.asc"
>  [4] "C:\\Documents and Settings\\Data\\comp198904.asc"
>  [5] "C:\\Documents and Settings\\Data\\comp199005.asc"
>  [6] "C:\\Documents and Settings\\Data\\comp199106.asc"
>  [7] "C:\\Documents and Settings\\Data\\comp199207.asc"
>  [8] "C:\\Documents and Settings\\Data\\comp199308.asc"
>  [9] "C:\\Documents and Settings\\Data\\comp199409.asc"
> [10] "C:\\Documents and Settings\\Data\\comp199510.asc"
> [11] "C:\\Documents and Settings\\Data\\comp198611.asc"
> [12] "C:\\Documents and Settings\\Data\\comp198712.asc"
>
>
> I need 1986 to remain fixed whilst it cycles through 01 to 12, before it
> moves onto 1987 and cycles again. There should be 120 outputs in total (10
> years each with 12 months), but at present it's only reaching 12 outputs.
>
> I'd be grateful to learn what I'm doing wrong here so that I can solve
> this.
>
> Many thanks as ever,
>
> Steve
>
>
> _
>  25GB of FREE Online Storage – Find out more
>
> __
> 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.


Re: [R] Reading in files with variable parts to names

2009-03-26 Thread Dieter Menne
Steve Murray  hotmail.com> writes:

> I'm trying to read in a whole directory of files which have two variable 
> parts to the file name: year and  month. E.g. comp198604.asc represents 
< April of 1986 - 'comp' is fixed in each case. Years range between
> 1986 to 1995 and months are between 1 and 12.
> 
> Just to be clear, there are 12 files associated with each year: e.g.
comp198601, comp198602, ...
> comp198612  through to comp199501, comp199502 ... comp199512.
 


gr = expand.grid(as.character(1986:1995),sprintf("%02d", 1:12) ,
  stringsAsFactors =FALSE)
filelist = paste(a[,1],a[2,],".asc",sep="")

__
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] Analogy for %in% for the whole columns (rather than individual values)

2009-03-26 Thread Fredrik Karlsson
Hi Dimitri,

What about this:


> with(a, x == y) -> a$equal
> a
 xy equal
1 john mary FALSE
2 mary mary  TRUE
3 mary john FALSE
4 john john  TRUE

/Fredrik

On Thu, Mar 26, 2009 at 7:48 PM, Dimitri Liakhovitski wrote:

> Hello!
>
> I have a matrix a with 2 variables (see below) that contain character
> strings.
> I need to create a 3rd variable that contains True if the value in
> column x is equal to the value in column y. The code below does it.
>
> a<-data.frame(x=c("john", "mary", "mary",
> "john"),y=c("mary","mary","john","john"))
> a$x<-as.character(a$x)
> a$y<-as.character(a$y)
> a$equal<-NA
> for(i in 1:nrow(a)) {a[i,3]<-a[i,1] %in% a[i,2]}
>
> I was wondering if one can do it faster, without doing it row-by-row
> as I did it. Maybe there is a faster way to compare 2 columns?
>
> Thank you very much!
>
> --
> Dimitri Liakhovitski
> MarketTools, Inc.
> dimitri.liakhovit...@markettools.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.
>



-- 
"Life is like a trumpet - if you don't put anything into it, you don't get
anything out of it."

[[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] Reading in files with variable parts to names

2009-03-26 Thread Rowe, Brian Lee Yung (Portfolio Analytics)
Try this to generate your year/month combinations:

> expand.grid(year=1986:1995, month=1:12)

Obviously you'll have to format the months.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Steve Murray
Sent: Thursday, March 26, 2009 2:40 PM
To: r-help@r-project.org
Subject: [R] Reading in files with variable parts to names



Dear all,

I'm trying to read in a whole directory of files which have two variable
parts to the file name: year and month. E.g. comp198604.asc represents
April of 1986 - 'comp' is fixed in each case. Years range between 1986
to 1995 and months are between 1 and 12.

Just to be clear, there are 12 files associated with each year: e.g.
comp198601, comp198602, ... comp198612  through to comp199501,
comp199502 ... comp199512.

I am trying to automate the reading in of these files, but am struggling
to find an adequate way of achieving this. The closest I've got is by
doing:



year <- 1986:1995
month <- sprintf("%02d", 1:12)  # formats numbers to 2 digits (for
maintaining leading zeros in file names)

filelist <- paste("C:\\Documents and
Settings\\Data\\comp",year,month,".asc", sep="")

filelist

 [1] "C:\\Documents and Settings\\Data\\comp198601.asc"
 [2] "C:\\Documents and Settings\\Data\\comp198702.asc"
 [3] "C:\\Documents and Settings\\Data\\comp198803.asc"
 [4] "C:\\Documents and Settings\\Data\\comp198904.asc"
 [5] "C:\\Documents and Settings\\Data\\comp199005.asc"
 [6] "C:\\Documents and Settings\\Data\\comp199106.asc"
 [7] "C:\\Documents and Settings\\Data\\comp199207.asc"
 [8] "C:\\Documents and Settings\\Data\\comp199308.asc"
 [9] "C:\\Documents and Settings\\Data\\comp199409.asc"
[10] "C:\\Documents and Settings\\Data\\comp199510.asc"
[11] "C:\\Documents and Settings\\Data\\comp198611.asc"
[12] "C:\\Documents and Settings\\Data\\comp198712.asc"


I need 1986 to remain fixed whilst it cycles through 01 to 12, before it
moves onto 1987 and cycles again. There should be 120 outputs in total
(10 years each with 12 months), but at present it's only reaching 12
outputs.

I'd be grateful to learn what I'm doing wrong here so that I can solve
this.

Many thanks as ever,

Steve


_
 25GB of FREE Online Storage - Find out more

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

--
This message w/attachments (message) may be privileged, confidential or 
proprietary, and if you are not an intended recipient, please notify the 
sender, do not use or share it and delete it. Unless specifically indicated, 
this message is not an offer to sell or a solicitation of any investment 
products or other financial product or service, an official confirmation of any 
transaction, or an official statement of Merrill Lynch. Subject to applicable 
law, Merrill Lynch may monitor, review and retain e-communications (EC) 
traveling through its networks/systems. The laws of the country of each 
sender/recipient may impact the handling of EC, and EC may be archived, 
supervised and produced in countries other than the country in which you are 
located. This message cannot be guaranteed to be secure or error-free. 
References to "Merrill Lynch" are references to any company in the Merrill 
Lynch & Co., Inc. group of companies, which are wholly-owned by Bank of America 
Corporation. Secu!
 rities and Insurance Products: * Are Not FDIC Insured * Are Not Bank 
Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a Condition to 
Any Banking Service or Activity * Are Not Insured by Any Federal Government 
Agency. Attachments that are part of this E-communication may have additional 
important disclosures and disclaimers, which you should read. This message is 
subject to terms available at the following link: 
http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you 
consent to the foregoing.
--

__
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] Reading in files with variable parts to names

2009-03-26 Thread baptiste auguie

Hi,

If your directory contains only files you want to load anyway, then  
list.files() is your friend,



list.files(pattern = "comp") # or pattern =".asc" for example



If you do need to create the names manually, then you could create the  
combinations with expand.grid, as in,


do.call(paste, as.list(expand.grid(x = seq(1950,1960), y = 1:10))) #  
you'll want to tweak paste to suit your needs



HTH,

baptiste

On 26 Mar 2009, at 18:40, Steve Murray wrote:



Dear all,

I'm trying to read in a whole directory of files which have two  
variable parts to the file name: year and month. E.g. comp198604.asc  
represents April of 1986 - 'comp' is fixed in each case. Years range  
between 1986 to 1995 and months are between 1 and 12.


Just to be clear, there are 12 files associated with each year: e.g.  
comp198601, comp198602, ... comp198612  through to comp199501,  
comp199502 ... comp199512.


I am trying to automate the reading in of these files, but am  
struggling to find an adequate way of achieving this. The closest  
I've got is by doing:




year <- 1986:1995
month <- sprintf("%02d", 1:12)  # formats numbers to 2 digits (for  
maintaining leading zeros in file names)


filelist <- paste("C:\\Documents and Settings\\Data\ 
\comp",year,month,".asc", sep="")


filelist

[1] "C:\\Documents and Settings\\Data\\comp198601.asc"
[2] "C:\\Documents and Settings\\Data\\comp198702.asc"
[3] "C:\\Documents and Settings\\Data\\comp198803.asc"
[4] "C:\\Documents and Settings\\Data\\comp198904.asc"
[5] "C:\\Documents and Settings\\Data\\comp199005.asc"
[6] "C:\\Documents and Settings\\Data\\comp199106.asc"
[7] "C:\\Documents and Settings\\Data\\comp199207.asc"
[8] "C:\\Documents and Settings\\Data\\comp199308.asc"
[9] "C:\\Documents and Settings\\Data\\comp199409.asc"
[10] "C:\\Documents and Settings\\Data\\comp199510.asc"
[11] "C:\\Documents and Settings\\Data\\comp198611.asc"
[12] "C:\\Documents and Settings\\Data\\comp198712.asc"


I need 1986 to remain fixed whilst it cycles through 01 to 12,  
before it moves onto 1987 and cycles again. There should be 120  
outputs in total (10 years each with 12 months), but at present it's  
only reaching 12 outputs.


I'd be grateful to learn what I'm doing wrong here so that I can  
solve this.


Many thanks as ever,

Steve


_
25GB of FREE Online Storage – Find out more

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


_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

__
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] Analogy for %in% for the whole columns (rather than individual values)

2009-03-26 Thread Jorge Ivan Velez
Dear Dimitri:
Try this:

a<-data.frame(x=c("john", "mary",
"mary","john"),y=c("mary","mary","john","john"))
a$x<-as.character(a$x)
a$y<-as.character(a$y)

a$TEST<-apply(a,1,function(x) x[1]==x[2])
a

See ?apply for more details.

HTH,

Jorge


On Thu, Mar 26, 2009 at 2:48 PM, Dimitri Liakhovitski wrote:

> Hello!
>
> I have a matrix a with 2 variables (see below) that contain character
> strings.
> I need to create a 3rd variable that contains True if the value in
> column x is equal to the value in column y. The code below does it.
>
> a<-data.frame(x=c("john", "mary", "mary",
> "john"),y=c("mary","mary","john","john"))
> a$x<-as.character(a$x)
> a$y<-as.character(a$y)
> a$equal<-NA
> for(i in 1:nrow(a)) {a[i,3]<-a[i,1] %in% a[i,2]}
>
> I was wondering if one can do it faster, without doing it row-by-row
> as I did it. Maybe there is a faster way to compare 2 columns?
>
> Thank you very much!
>
> --
> Dimitri Liakhovitski
> MarketTools, Inc.
> dimitri.liakhovit...@markettools.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.
>

[[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] Analogy for %in% for the whole columns (rather than individual values)

2009-03-26 Thread Dimitri Liakhovitski
Hello!

I have a matrix a with 2 variables (see below) that contain character strings.
I need to create a 3rd variable that contains True if the value in
column x is equal to the value in column y. The code below does it.

a<-data.frame(x=c("john", "mary", "mary",
"john"),y=c("mary","mary","john","john"))
a$x<-as.character(a$x)
a$y<-as.character(a$y)
a$equal<-NA
for(i in 1:nrow(a)) {a[i,3]<-a[i,1] %in% a[i,2]}

I was wondering if one can do it faster, without doing it row-by-row
as I did it. Maybe there is a faster way to compare 2 columns?

Thank you very much!

-- 
Dimitri Liakhovitski
MarketTools, Inc.
dimitri.liakhovit...@markettools.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] Reading in files with variable parts to names

2009-03-26 Thread Steve Murray

Dear all,

I'm trying to read in a whole directory of files which have two variable parts 
to the file name: year and month. E.g. comp198604.asc represents April of 1986 
- 'comp' is fixed in each case. Years range between 1986 to 1995 and months are 
between 1 and 12.

Just to be clear, there are 12 files associated with each year: e.g. 
comp198601, comp198602, ... comp198612  through to comp199501, comp199502 ... 
comp199512.

I am trying to automate the reading in of these files, but am struggling to 
find an adequate way of achieving this. The closest I've got is by doing:



year <- 1986:1995
month <- sprintf("%02d", 1:12)  # formats numbers to 2 digits (for maintaining 
leading zeros in file names)

filelist <- paste("C:\\Documents and Settings\\Data\\comp",year,month,".asc", 
sep="")

filelist

 [1] "C:\\Documents and Settings\\Data\\comp198601.asc"
 [2] "C:\\Documents and Settings\\Data\\comp198702.asc"
 [3] "C:\\Documents and Settings\\Data\\comp198803.asc"
 [4] "C:\\Documents and Settings\\Data\\comp198904.asc"
 [5] "C:\\Documents and Settings\\Data\\comp199005.asc"
 [6] "C:\\Documents and Settings\\Data\\comp199106.asc"
 [7] "C:\\Documents and Settings\\Data\\comp199207.asc"
 [8] "C:\\Documents and Settings\\Data\\comp199308.asc"
 [9] "C:\\Documents and Settings\\Data\\comp199409.asc"
[10] "C:\\Documents and Settings\\Data\\comp199510.asc"
[11] "C:\\Documents and Settings\\Data\\comp198611.asc"
[12] "C:\\Documents and Settings\\Data\\comp198712.asc"


I need 1986 to remain fixed whilst it cycles through 01 to 12, before it moves 
onto 1987 and cycles again. There should be 120 outputs in total (10 years each 
with 12 months), but at present it's only reaching 12 outputs.

I'd be grateful to learn what I'm doing wrong here so that I can solve this.

Many thanks as ever,

Steve


_
 25GB of FREE Online Storage – Find out more

__
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] boxplot in subgroups

2009-03-26 Thread Pooja Jain

Thank you very much Annette,

With your help I can do exactly what I wanted to.

Best wishes,
-Pooja
On 26 Mar 2009, at 06:59, Annette Heisswolf wrote:


Hei,

the error message below just tells you that you have specified nine  
places along the axis where you want to have labels (i.e. at=1:9)  
but obviously you have only specified three labels (i.e. labels =  
c("C","M","S")). Thus, R is complaining that there are not enough  
labels for all positions. However, I guess from your description  
that you want to have only three labels below your plot, one for  
each group of three boxes that share the same ASA1 value. Thus, you  
could for example do like this:


axis(side=1,at=c(2,5,8),labels=c("C","S","M"))

Then you would get the label always below the middle one of the  
three boxes of each group.


Now the boxes are, however, still distributed evenly across the  
plot, but in case you want to have those that belong to the same  
subgroup a bit closer together, you can specify their position via  
the "at" option on the boxplot function (see ?boxplot).


An example with random data might look like this:

ASA1=factor(rep(c("C","S","M"),each=100))
ASA2=factor(rep(c("C","S","M"),100))
C1_C2=runif(300)
boxplot(C1_C2~ASA2*ASA1,xlim=c(0,12),at=c(1:3,5:7,9:11),xaxt="n")
axis(side=1,at=c(2,6,10),labels=c("C","S","M"))

See ?axis for further options, e.g. tcl=0 in case you don't want to  
have a tick at the axis at the position of the label.


Hope that helps,

Annette

Pooja Jain schrieb:

Hi,
I have data that looks like this:
ASA1ASA2C1_C2
C   M   9.0225
S   S   2.4315
M   C   3.4894
M   S   4.5282
C   M   1.3183
C   S   1.3735
S   C   1.0488
S   M   7.948
M   C   4.5827
I need to plot Boxplots for a given ASA1 (either C,S, or M) with  
respect to C1_C2. However, instead of one boxplot I want to plot  
three boxplots for a given ASA1 value such that each sub-boxplot  
represent the distribution for C1-C2 for each of the three possible  
values of ASA2 (C,S or M). I want to show this subgroup with a  
single xtics (either C, S or M) corresponding to the ASA1 value  
selected.
I tried to do it, but ending with the following error. I am not  
sure how exactly I should build the object to plot as subgroup.

Error in axis(side = 1, at = 1:9, labels = c("C", "M", "S" :
 'at' and 'labels' lengths differ, 9 != 3
In addition: Warning message:
In bxp(list(stats = c(1e-04, 2.82745, 6.0193, 10.5957, 22.2476,  :
 some notches went outside hinges ('box'): maybe set notch=FALSE
I would greatly appreciate any help in this matter.
Thank you.
-Kanu


--
Annette Heisswolf
Section of Ecology
Department of Biology
University of Turku
20014 Turku, Finland

phone   + 358 2 333 6006
fax + 358 2 333 6550
mailannette.heissw...@utu.fi


__
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] Conerned about Interfacing R with Fortran

2009-03-26 Thread mauede
I am reading the manual sections illustrating how to call a Fortran subroutine 
from R.
I feel uneasy at the explicit statement about ".Fortran" interface working with 
Fortran 77.
I would like to call a Fortran-90 subroutine from my R script. Is that 
supported at all ?
Thank you,
Maura


tutti i telefonini TIM!


[[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] problem with "choose.files" command & interactive functions

2009-03-26 Thread O'Farrell, Shay
Perfect.  That's fixed the problem.  Thanks very much for the advice.  

Shay



If you don't specify where to open the dialog, it will open in the last
location where it was opened.  This saves time if you are running it
more than once, because often you will open files from the same
directory.   If you don't want that, you can specify which directory to
open, and get it to always open in the current directory using
choose.files("./*").

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.


Re: [R] Competing risks Kalbfleisch & Prentice method

2009-03-26 Thread Eleni Rapsomaniki
Ravi,

I agree with you, that the Fine & Gray method does much more than
calculating the cumulative incidence. The Kalbfleisch & Prentice formula
relies on the strong assumption that the coefficients for the cause
specific hazard models are valid in the presence of competing risks. You
will find my code below, but it may be wrong (I'm not really a
statistician!). And no, it doesn't even calculate confidence
intervals...

Thank you for pointing out these papers. 
Please let me know (nicely) if you find bugs!!!

#
#Method to calculate Cumulative Incidence adjusting for competing risks,
based on the Kalbfleisch & Prentice formula, 1980, p.169
#create data
 ftime <- rexp(200, 0.3)
 fstatus <- sample(0:2,200,replace=TRUE)
 cov <- matrix(runif(600),nrow=200)
 dimnames(cov)[[2]] <- c('x1','x2','x3')
 dat=data.frame(ftime, fstatus, cov)


diffrHaz=function(x){
hazard=x$hazard
time=x$time

hz.v=NULL

for(e in 1:(length(hazard)-1)){
hz=hazard[e+1]-hazard[e]
hz.v=c(hz.v,hz)
}
dhz=data.frame(hazard=hz.v, time=x$time[-length(x$time)])
return(dhz)
}


#build cause specific cox models
library(Design)
 a.f=cph(Surv(ftime, fstatus==1) ~ x1+x2+x3, data=dat, surv=T, x=T, y=T)
 b.f=cph(Surv(ftime, fstatus==2) ~ x1+x2+x3, data=dat, surv=T, x=T, y=T)
 
#get unique event times - up till the time of interest, eg. time=10
uts=unique(dat$ftime[dat$fstatus>0] )
uts=uts[uts<=10]  # the times up till 10 years
uts=uts[order(uts)]  #order them

#get baseline hazard rate (cumulative)
a.bz=basehaz(a.f)
b.bz=basehaz(b.f)

#get instanteneous baseline hazard rate, apply above function
a.dhz1=diffrHaz(a.bz)
b.dhz1=diffrHaz(b.bz)

P.t=NULL #intitialize where to store all results
for(i in 1:nrow(dat)){  # i is the individual, iterate through the
number of rows in dat
P.i.t=NULL
all.lambda.i.t=NULL

for(u.i in 1:length(uts)){
 u=uts[u.i]
#get the instanteneous baseline hazard from each model
corresponding to this timepoint (if there is no event at that time
return 0)
a.dhz.u=ifelse((u %in%
a.dhz1$time)==F,0,a.dhz1$hazard[a.dhz1$time==u])
b.dhz.u=ifelse((u %in%
b.dhz1$time)==F,0,b.dhz1$hazard[b.dhz1$time==u])

#multiply by the linear predictors to get the actual hazard at
that point
a.lambda.i.u=a.dhz.u*exp(a.f$linear.predictors[i])
b.lambda.i.u=b.dhz.u*exp(b.f$linear.predictors[i])
all.lambda.i.u=a.lambda.i.u+b.lambda.i.u
#store in a vector
all.lambda.i.t=c(all.lambda.i.t, all.lambda.i.u) #build a vector
with all previous all.lambda.i.u's
S.i.u=exp(-sum(all.lambda.i.t)) #this is the probability of
surviving till time u

p.i.u=S.i.u*a.lambda.i.u

P.i.t=c(P.i.t, p.i.u)

}
P.t[i]=sum(P.i.t)
}

# to compare with unadjusted:
a.risk   = 1-survest(a.f, linear.predictors=a.f$linear.predictors,
times=10)$surv
plot(a.risk ~ P.t) #P.t is the CR adjusted, should always be lower
mean(a.risk)
mean(P.t)

Eleni Rapsomaniki
 
Research Associate
Tel: +44 (0) 1223 740273
Strangeways Research Laboratory
Department of Public Health and Primary Care
University of Cambridge
 

-Original Message-
From: Ravi Varadhan [mailto:rvarad...@jhmi.edu] 
Sent: 26 March 2009 14:36
To: Eleni Rapsomaniki; 'Arthur Allignol'
Cc: r-help@r-project.org
Subject: RE: [R] Competing risks Kalbfleisch & Prentice method

Hi Eleni,

I would like to take a look at your R function for obtaining the
cumulative
incidence function (CIF) from individual Cox models for cause-specific
hazards (CSH).  Does your code predict the CIF (with pointwise
confidence
intervals and global confidence bands) for different sub-groups?  Have
you
seen the paper by Cheng, Fine, and Wei (Biometrics 1998) that does this?


A major advantage of the F&G model is that you can get a direct,
numerical
measure of the effect of a covariate on the CIF.  This cannot be
obtained by
modeling all the CSHs and then combining them.  The idiosyncratic
assumption
concerning risk set in F&G model is made mainly for mathematical
purposes so
that a proportional hazards form may be obtained for the CIF.  You can
test
this assumption by plotting schonefeld-type residuals (this is available
in
cmprsk).  Fine (Biostatistics 2006) provides a different approach that
relaxes this assumption (it also uses a different estimation approach),
but
I don't know if there is an R implementation for that.

Thanks,
Ravi.
 


---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html








-Original Message-
From: r-help-boun...@r-project.org [mailt

Re: [R] Density estimation: scale back for calendar time

2009-03-26 Thread David Winsemius
Pradeep Raje  gmail.com> writes:

> 
> Thanks David for your response.I had done that. 

But not shared it.

> Problem is not with the
> computations, but in the interpretation.
> Assume that x ordinates are 'time' [1:3472], and y are associated parameter
> values.
> Now density gives me 512/1024/2048 x-ordinates, of which some (7 to be
> precise) are negative. What do I make of the non-zero probability at
> **negative** times?

Obviously you are having problems with interpretation which is why I suggested 
that you provide a worked example. Since you appear to be resisting that 
suggestion, let's talk about hypotheticals. Two results of a density 
estimation will be density(dat)$x and density(dat)$y. The first of these is not 
a probability and could be negative in any instances where negative numbers 
were in the domain of the dat object. And it might be negative in situations 
with postive values where an estimation extended slightly beyond the original 
dataset. It is the y values that are necessarily positive. 

The idea that dates associated with a numerical object could be used to label a 
density plot seems strange. The process of density estimation would scrample 
the order of the original data so that the densities could be calculated. In a 
sense the y-axis of the original object will become the new x-axis of the 
density object. There would be no way to restore that "date" order. It had been 
my hope that a request for an example would make that more clear. Back to you.

-- 
David Winsemius
>

__
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] programming creating different functions in a loop

2009-03-26 Thread Bert Gunter
 Good point, Greg. So to handle i as a vector, you'd probably want something
like

f <- function(x,i)outer(x,i,"+")

-- Bert

Bert Gunter
Genentech Nonclinical Biostatistics
650-467-7374

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Greg Snow
Sent: Thursday, March 26, 2009 9:54 AM
To: Bert Gunter; 'Florin Maican'; r-help@r-project.org
Subject: Re: [R] programming creating different functions in a loop

But wrong questions requiring complicated answers are sometimes more fun
:-).

One difference though is in my last example, your function will give a
different answer for f(1:3, 1:10), but for the simpler cases, yours is
probably the better.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: Bert Gunter [mailto:gunter.ber...@gene.com]
> Sent: Thursday, March 26, 2009 10:33 AM
> To: Greg Snow; 'Florin Maican'; r-help@r-project.org
> Subject: RE: [R] programming creating different functions in a loop
> 
> ... but perhaps even more straightforward is:
> 
> f <- function(i,x)x+i
> 
> Of course, we don't know exactly what the poster is after with his
> rather
> arcane construction, so this may not suit. But you know the rule: if
> the
> question requires a complex, tricky answer, it's probably the wrong
> question.
> 
> Cheers,
> Bert
> 
> Bert Gunter
> Genentech Nonclinical Biostatistics
> 
> 
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On
> Behalf Of Greg Snow
> Sent: Thursday, March 26, 2009 9:25 AM
> To: Florin Maican; r-help@r-project.org
> Subject: Re: [R] programming creating different functions in a loop
> 
> Anytime that you are tempted to use assign and a loop, you should
> consider
> using lapply (or sapply) and a list instead.
> 
> Consider this alternative:
> 
> > f <- lapply( 1:3, function(i){ force(i); function(x) x+i} )
> >
> > f[[1]](3)
> [1] 4
> > f[[2]](10)
> [1] 12
> > f[[3]](0)
> [1] 3
> >
> > sapply( f, function(f) f(1:10) )
>   [,1] [,2] [,3]
>  [1,]234
>  [2,]345
>  [3,]456
>  [4,]567
>  [5,]678
>  [6,]789
>  [7,]89   10
>  [8,]9   10   11
>  [9,]   10   11   12
> [10,]   11   12   13
> 
> Hope this helps,
> 
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.s...@imail.org
> 801.408.8111
> 
> 
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> > project.org] On Behalf Of Florin Maican
> > Sent: Thursday, March 26, 2009 9:18 AM
> > To: r-help@r-project.org
> > Subject: [R] programming creating different functions in a loop
> >
> > Hi
> >
> > I want to create the  following functions in a loop
> >
> > f1<-function(x){x+1}
> > f2<-function(x){x+2}
> > f3<-function(x){x+3}
> >
> > Output   f1(2)=3
> >  f2(2)=4
> >  f3(2)=5
> >
> >
> > I tried to create the in a loop as bellow but I get wrong on answers
> > because the value of i change
> >
> > for(i  in 1:3){
> > assign(paste("f",i,sep="")
> > ,function(x)
> >  x+i
> > )
> > } # end for
> >
> > Output   f1(2)=5
> >  f2(2)=5
> >  f3(2)=5
> > But it is not what I want. The question is how I can
> > fix in R the value of "i" in my functions?  I tried to use assign()
> and
> > get(),but I did not manage.
> >
> > Thanks in advance,
> > Florin
> >
> > --
> >  Florin  Maican
> > ==
> >
> > Department of Economics,
> > School of Business, Economics and Law,
> > Gothenburg University, Sweden
> > ---
> > P.O. Box 640 SE-405 30,
> > Gothenburg, Sweden
> >
> >  Mobil:  +46 76 235 3039
> >  Phone:  +46 31 786 4866
> >  Fax:+46 31 786 4154
> >  Home Page: http://maicanfg.googlepages.com/index.html
> >  E-mail: florin.mai...@handels.gu.se
> > 
> >  "Not everything that counts can be
> >  counted, and not everything that can be
> >  counted counts."
> >  --- Einstein ---
> >
> > __
> > 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@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

Re: [R] programming creating different functions in a loop

2009-03-26 Thread Greg Snow
But wrong questions requiring complicated answers are sometimes more fun :-).

One difference though is in my last example, your function will give a 
different answer for f(1:3, 1:10), but for the simpler cases, yours is probably 
the better.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: Bert Gunter [mailto:gunter.ber...@gene.com]
> Sent: Thursday, March 26, 2009 10:33 AM
> To: Greg Snow; 'Florin Maican'; r-help@r-project.org
> Subject: RE: [R] programming creating different functions in a loop
> 
> ... but perhaps even more straightforward is:
> 
> f <- function(i,x)x+i
> 
> Of course, we don't know exactly what the poster is after with his
> rather
> arcane construction, so this may not suit. But you know the rule: if
> the
> question requires a complex, tricky answer, it's probably the wrong
> question.
> 
> Cheers,
> Bert
> 
> Bert Gunter
> Genentech Nonclinical Biostatistics
> 
> 
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On
> Behalf Of Greg Snow
> Sent: Thursday, March 26, 2009 9:25 AM
> To: Florin Maican; r-help@r-project.org
> Subject: Re: [R] programming creating different functions in a loop
> 
> Anytime that you are tempted to use assign and a loop, you should
> consider
> using lapply (or sapply) and a list instead.
> 
> Consider this alternative:
> 
> > f <- lapply( 1:3, function(i){ force(i); function(x) x+i} )
> >
> > f[[1]](3)
> [1] 4
> > f[[2]](10)
> [1] 12
> > f[[3]](0)
> [1] 3
> >
> > sapply( f, function(f) f(1:10) )
>   [,1] [,2] [,3]
>  [1,]234
>  [2,]345
>  [3,]456
>  [4,]567
>  [5,]678
>  [6,]789
>  [7,]89   10
>  [8,]9   10   11
>  [9,]   10   11   12
> [10,]   11   12   13
> 
> Hope this helps,
> 
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.s...@imail.org
> 801.408.8111
> 
> 
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> > project.org] On Behalf Of Florin Maican
> > Sent: Thursday, March 26, 2009 9:18 AM
> > To: r-help@r-project.org
> > Subject: [R] programming creating different functions in a loop
> >
> > Hi
> >
> > I want to create the  following functions in a loop
> >
> > f1<-function(x){x+1}
> > f2<-function(x){x+2}
> > f3<-function(x){x+3}
> >
> > Output   f1(2)=3
> >  f2(2)=4
> >  f3(2)=5
> >
> >
> > I tried to create the in a loop as bellow but I get wrong on answers
> > because the value of i change
> >
> > for(i  in 1:3){
> > assign(paste("f",i,sep="")
> > ,function(x)
> >  x+i
> > )
> > } # end for
> >
> > Output   f1(2)=5
> >  f2(2)=5
> >  f3(2)=5
> > But it is not what I want. The question is how I can
> > fix in R the value of "i" in my functions?  I tried to use assign()
> and
> > get(),but I did not manage.
> >
> > Thanks in advance,
> > Florin
> >
> > --
> >  Florin  Maican
> > ==
> >
> > Department of Economics,
> > School of Business, Economics and Law,
> > Gothenburg University, Sweden
> > ---
> > P.O. Box 640 SE-405 30,
> > Gothenburg, Sweden
> >
> >  Mobil:  +46 76 235 3039
> >  Phone:  +46 31 786 4866
> >  Fax:+46 31 786 4154
> >  Home Page: http://maicanfg.googlepages.com/index.html
> >  E-mail: florin.mai...@handels.gu.se
> > 
> >  "Not everything that counts can be
> >  counted, and not everything that can be
> >  counted counts."
> >  --- Einstein ---
> >
> > __
> > 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@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] Locale problem between WinXP and Ubuntu

2009-03-26 Thread Harsh
Hi R list,
I have a peculiar problem in trying to Sweave a document in Ubuntu.

The error message I get is the following:

Error in gsub("\\n", "_", dd_name_level_nominal[k, 1], perl = TRUE) :
  input string 1 is invalid in this locale

dd_name_level_nominal[k, 1] is a character object.
I initially read these characters from a csv file which I create in Excel
2007.

I have created the tex documents on my local WinXP machine but when I try to
create it on my
Ubuntu server, it does'nt seem to work(and throws the above error). I need
to create on the Ubuntu server, since I am using
Rserv and using R as a service.
I wish I could do everything on one platform (WinXP preferably) but there
isnt an R server for Windows which is as good or better than Rserv for
Linux.

This may be a very trivial problem, but I have tried to change the locale on
R Ubuntu to en_us.utf8.
On the windoes machine the locale is
"LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252"

and
 > l10n_info()
$MBCS
[1] FALSE

$`UTF-8`
[1] FALSE

$`Latin-1`
[1] TRUE

$codepage
[1] 1252

The locales i test in R ubuntu do not provide the Latin-1.

Is there a way to circumvent this problem? I have tried to clean my input
csv file by removing spaces and other special characters. I only have
alphabets and '_'  only. There could be a new line character in there, but I
am not able to remove it in a csv reader such as EXCEL.

Thanks for your help.

Harsh Singhal
Decision Systems,
Mu Sigma Inc.

[[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] programming creating different functions in a loop

2009-03-26 Thread Bert Gunter
... but perhaps even more straightforward is:

f <- function(i,x)x+i 

Of course, we don't know exactly what the poster is after with his rather
arcane construction, so this may not suit. But you know the rule: if the
question requires a complex, tricky answer, it's probably the wrong
question. 

Cheers,
Bert

Bert Gunter
Genentech Nonclinical Biostatistics


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Greg Snow
Sent: Thursday, March 26, 2009 9:25 AM
To: Florin Maican; r-help@r-project.org
Subject: Re: [R] programming creating different functions in a loop

Anytime that you are tempted to use assign and a loop, you should consider
using lapply (or sapply) and a list instead.

Consider this alternative:

> f <- lapply( 1:3, function(i){ force(i); function(x) x+i} )
> 
> f[[1]](3)
[1] 4
> f[[2]](10)
[1] 12
> f[[3]](0)
[1] 3
> 
> sapply( f, function(f) f(1:10) )
  [,1] [,2] [,3]
 [1,]234
 [2,]345
 [3,]456
 [4,]567
 [5,]678
 [6,]789
 [7,]89   10
 [8,]9   10   11
 [9,]   10   11   12
[10,]   11   12   13

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Florin Maican
> Sent: Thursday, March 26, 2009 9:18 AM
> To: r-help@r-project.org
> Subject: [R] programming creating different functions in a loop
> 
> Hi
> 
> I want to create the  following functions in a loop
> 
> f1<-function(x){x+1}
> f2<-function(x){x+2}
> f3<-function(x){x+3}
> 
> Output   f1(2)=3
>  f2(2)=4
>  f3(2)=5
> 
> 
> I tried to create the in a loop as bellow but I get wrong on answers
> because the value of i change
> 
> for(i  in 1:3){
> assign(paste("f",i,sep="")
> ,function(x)
>  x+i
> )
> } # end for
> 
> Output   f1(2)=5
>  f2(2)=5
>  f3(2)=5
> But it is not what I want. The question is how I can
> fix in R the value of "i" in my functions?  I tried to use assign() and
> get(),but I did not manage.
> 
> Thanks in advance,
> Florin
> 
> --
>  Florin  Maican
> ==
> 
> Department of Economics,
> School of Business, Economics and Law,
> Gothenburg University, Sweden
> ---
> P.O. Box 640 SE-405 30,
> Gothenburg, Sweden
> 
>  Mobil:  +46 76 235 3039
>  Phone:  +46 31 786 4866
>  Fax:+46 31 786 4154
>  Home Page: http://maicanfg.googlepages.com/index.html
>  E-mail: florin.mai...@handels.gu.se
> 
>  "Not everything that counts can be
>  counted, and not everything that can be
>  counted counts."
>  --- Einstein ---
> 
> __
> 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@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] Way to rotate a histogram?

2009-03-26 Thread Mike Lawrence
In case anyone is still interested, a slight improvement is to plot
both density and normal distributions on top of the empirical
histogram (previous version plotted only density):

library(ggplot2)
test_data<-rnorm(100,mean=10,sd=4)
a = data.frame(obs = test_data,condition = 'None')
p1 = ggplot(
data = a
,aes(
x = obs
)
)+geom_histogram(
aes(
y = ..density..
)
)+stat_density(
mapping=aes(ymax=max(..density..))
,geom='path'
,colour='red'
)+stat_function(
fun = dnorm
,args = list(
m=mean(a$obs)
,sd=sd(a$obs)
)
,colour = 'green'
)+scale_x_continuous(
limits = range(a$obs)
)+opts(
panel.grid.minor = theme_blank()
,panel.grid.major = theme_blank()
,panel.background = theme_rect()
)+coord_flip(
)
p2 = ggplot(
data = a
,aes(
x = condition
,y = obs
)
)+geom_boxplot(
)+scale_y_continuous(
limits = range(a$obs)
)+scale_x_discrete(
name = ''
,labels = ''
)+opts(
panel.grid.minor = theme_blank()
,panel.grid.major = theme_blank()
,panel.background = theme_rect()
,axis.ticks = theme_blank()
,axis.text.y = theme_blank()
,axis.title.y = theme_blank()
)
p3 = ggplot(
data = a
,aes(
sample = (obs-mean(obs))/sd(obs)
)
)+stat_qq(
distribution=qnorm
)+geom_abline(
intercept=0
,slope=1
)+opts(
panel.grid.minor = theme_blank()
,panel.grid.major = theme_blank()
,panel.background = theme_rect()
,axis.ticks = theme_blank()
,axis.text.y = theme_blank()
,axis.title.y = theme_blank()
)


print(p1,vp = viewport(width = 1/3,height = 1,x = 1/3*.5,y = .5))
print(p2,vp = viewport(width = 1/3,height = 1,x = 1/3+1/3*.5,y = .5))
print(p3,vp = viewport(width = 1/3,height = 1,x = 2/3+1/3*.5,y = .5))


-- 
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University

Looking to arrange a meeting? Check my public calendar:
http://tinyurl.com/mikes-public-calendar

~ Certainty is folly... I think. ~

__
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 rotate axis labels? 2009

2009-03-26 Thread Ben Bolker
Usuario R  gmail.com> writes:

> 
> Hi,
> 
> What you want is done with argument srt of par function. See ?par and then
> look for srt argument.
> 
> Regards
> 

  To clarify: if you just want labels rotated parallel/perpendicular
to axes, then par("las") will do everything you need.  If you need
arbitrary rotation (e.g. 45 degrees), then as far as I know the
hack in the FAQ is still the appropriate solution.   

  Ben Bolker

__
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] programming creating different functions in a loop

2009-03-26 Thread Greg Snow
Anytime that you are tempted to use assign and a loop, you should consider 
using lapply (or sapply) and a list instead.

Consider this alternative:

> f <- lapply( 1:3, function(i){ force(i); function(x) x+i} )
> 
> f[[1]](3)
[1] 4
> f[[2]](10)
[1] 12
> f[[3]](0)
[1] 3
> 
> sapply( f, function(f) f(1:10) )
  [,1] [,2] [,3]
 [1,]234
 [2,]345
 [3,]456
 [4,]567
 [5,]678
 [6,]789
 [7,]89   10
 [8,]9   10   11
 [9,]   10   11   12
[10,]   11   12   13

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Florin Maican
> Sent: Thursday, March 26, 2009 9:18 AM
> To: r-help@r-project.org
> Subject: [R] programming creating different functions in a loop
> 
> Hi
> 
> I want to create the  following functions in a loop
> 
> f1<-function(x){x+1}
> f2<-function(x){x+2}
> f3<-function(x){x+3}
> 
> Output   f1(2)=3
>  f2(2)=4
>  f3(2)=5
> 
> 
> I tried to create the in a loop as bellow but I get wrong on answers
> because the value of i change
> 
> for(i  in 1:3){
> assign(paste("f",i,sep="")
> ,function(x)
>  x+i
> )
> } # end for
> 
> Output   f1(2)=5
>  f2(2)=5
>  f3(2)=5
> But it is not what I want. The question is how I can
> fix in R the value of "i" in my functions?  I tried to use assign() and
> get(),but I did not manage.
> 
> Thanks in advance,
> Florin
> 
> --
>  Florin  Maican
> ==
> 
> Department of Economics,
> School of Business, Economics and Law,
> Gothenburg University, Sweden
> ---
> P.O. Box 640 SE-405 30,
> Gothenburg, Sweden
> 
>  Mobil:  +46 76 235 3039
>  Phone:  +46 31 786 4866
>  Fax:+46 31 786 4154
>  Home Page: http://maicanfg.googlepages.com/index.html
>  E-mail: florin.mai...@handels.gu.se
> 
>  "Not everything that counts can be
>  counted, and not everything that can be
>  counted counts."
>  --- Einstein ---
> 
> __
> 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] installing contributed programs

2009-03-26 Thread Duncan Murdoch

On 3/26/2009 10:11 AM, David Covell wrote:

Dear R-help,

I'm sure this is contained within the documentation, but I have not yet located
it (with good effort nonetheless). I am attempting to install the binary for
randomForests. After unpacking the zip, I extracted the contents to
my R-2.8.1 folder. However, when I try to execute the command
library(randomForest) I get an unable to locate error. Is there another
library request that needs to be made? I see that the zip extraction created
the RandomForest folder under the R-2.8.1 folder. Is there a way to
specify this location within the library command?


You should let R do the installation.  The easiest way on Windows (which 
is implied by the .zip extension on your binary, but you should have 
said...) is within the Rgui:  menu item "Packages|Install package(s) 
from local zip files" (or even better, install from CRAN).


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.


Re: [R] programming creating different functions in a loop

2009-03-26 Thread Florin Maican
Thanks Luke!

It works!  My mistake was that I used "local binding" only for "i" and
not for the whole function.

Best regards,
Florin


On Thu, 26 Mar 2009 10:57:21 -0500 (CDT)
l...@stat.uiowa.edu wrote:

> for() does not creae separete bindings for the index each iteration,
> so the function bodies see the global binding of i, which in this case
> will be the final value.  One possible solution is to use local(),
> e.g.
> 
> for(i  in 1:3){
>  assign(paste("f",i,sep=""),
> local({
> k <- i  # create local binding with current loop
> index value function(x) x + k
>  }))
> }
> 
> 
> luke
> 
> 
> On Thu, 26 Mar 2009, Florin Maican wrote:
> 
> > Hi
> >
> > I want to create the  following functions in a loop
> >
> > f1<-function(x){x+1}
> > f2<-function(x){x+2}
> > f3<-function(x){x+3}
> >
> > Output   f1(2)=3
> > f2(2)=4
> > f3(2)=5
> >
> >
> > I tried to create the in a loop as bellow but I get wrong on answers
> > because the value of i change
> >
> > for(i  in 1:3){
> >assign(paste("f",i,sep="")
> >,function(x)
> > x+i
> >)
> > } # end for
> >
> > Output   f1(2)=5
> > f2(2)=5
> > f3(2)=5
> > But it is not what I want. The question is how I can
> > fix in R the value of "i" in my functions?  I tried to use assign()
> > and get(),but I did not manage.
> >
> > Thanks in advance,
> > Florin
> >
> >
> 


-- 
 Florin G. Maican
==

Ph.D. candidate,
Department of Economics,
School of Business, Economics and Law, 
Gothenburg University, Sweden   
---
P.O. Box 640 SE-405 30, 
Gothenburg, Sweden  

 Mobil:  +46 76 235 3039 
 Phone:  +46 31 786 4866 
 Fax:+46 31 786 4154  
 Home Page: http://maicanfg.googlepages.com/index.html
 E-mail: florin.mai...@handels.gu.se 

 "Not everything that counts can be 
 counted, and not everything that can be 
 counted counts."
 --- Einstein ---

__
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 rotate axis labels? 2009

2009-03-26 Thread Usuario R
Hi,

What you want is done with argument srt of par function. See ?par and then
look for srt argument.

Regards


2009/3/26 Jonas Stein 

> Hi,
>
> while searching for a solution i found many solutions in the internet.
> But the postings seemed to be many years old and the workaround was a
> dirty hack like this:
>
>
> http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f
>
> Now its the year 2009 and there might have been some improvement...
> Does anyone know a nice and easy way to turn labels on the y axis in the
> same direction as the x labels?
>
> Thank you very much for reading and hints,
>
> --
> Jonas Stein 
>
> __
> 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.


Re: [R] standard plot font

2009-03-26 Thread Uwe Ligges



Martin Batholdy wrote:

hi,

I was wondering what font-type R uses in plots (title etc.).

Is that depending on the system you are working on?
(working with mac OS)


In fact, it is dependent on the *Device* you are plotting to.
See ?Devices and the help page for the device you are going to plot to.

Uwe Ligges








thanks for help!

__
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 rotate axis labels? 2009

2009-03-26 Thread Uwe Ligges



Jonas Stein wrote:

Hi,

while searching for a solution i found many solutions in the internet.
But the postings seemed to be many years old and the workaround was a
dirty hack like this:

http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f

Now its the year 2009 and there might have been some improvement...
Does anyone know a nice and easy way to turn labels on the y axis in the
same direction as the x labels?



This has always been documented in ?par:

plot(1:10, las=1)


Uwe Ligges






Thank you very much for reading and hints,



__
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] Odp: installing contributed programs

2009-03-26 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 26.03.2009 15:11:32:

> Dear R-help,
> 
> I'm sure this is contained within the documentation, but I have not yet 
located
> it (with good effort nonetheless). I am attempting to install the binary 
for
> randomForests. After unpacking the zip, I extracted the contents to
> my R-2.8.1 folder. However, when I try to execute the command
> library(randomForest) I get an unable to locate error. Is there another
> library request that needs to be made? I see that the zip extraction 
created
> the RandomForest folder under the R-2.8.1 folder. Is there a way to

It shall be in /library subfolder of your R -2.8.1 main directory. If it 
is not, just copy it there.

Regards
Petr



> specify this location within the library command?
> 
> Thanks for your help,
> David
> 
> __
> 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] How to rotate axis labels? 2009

2009-03-26 Thread Jonas Stein
Hi,

while searching for a solution i found many solutions in the internet.
But the postings seemed to be many years old and the workaround was a
dirty hack like this:

http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f

Now its the year 2009 and there might have been some improvement...
Does anyone know a nice and easy way to turn labels on the y axis in the
same direction as the x labels?

Thank you very much for reading and hints,

-- 
Jonas Stein 

__
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] standard plot font

2009-03-26 Thread Martin Batholdy

hi,

I was wondering what font-type R uses in plots (title etc.).

Is that depending on the system you are working on?
(working with mac OS)




thanks for help!

__
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] programming creating different functions in a loop

2009-03-26 Thread luke

for() does not creae separete bindings for the index each iteration,
so the function bodies see the global binding of i, which in this case
will be the final value.  One possible solution is to use local(), e.g.

for(i  in 1:3){
assign(paste("f",i,sep=""),
   local({
   k <- i  # create local binding with current loop index value
   function(x) x + k
}))
}


luke


On Thu, 26 Mar 2009, Florin Maican wrote:


Hi

I want to create the  following functions in a loop

f1<-function(x){x+1}
f2<-function(x){x+2}
f3<-function(x){x+3}

Output   f1(2)=3
f2(2)=4
f3(2)=5


I tried to create the in a loop as bellow but I get wrong on answers
because the value of i change

for(i  in 1:3){
   assign(paste("f",i,sep="")
   ,function(x)
x+i
   )
} # end for

Output   f1(2)=5
f2(2)=5
f3(2)=5
But it is not what I want. The question is how I can
fix in R the value of "i" in my functions?  I tried to use assign() and
get(),but I did not manage.

Thanks in advance,
Florin




--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:  l...@stat.uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
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] Odp: Tables

2009-03-26 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 26.03.2009 16:39:18:

> Hi,
> 
> I am just starting using R. Hence, sorry for asking probably rather easy 

> questions.
> 
> I used "read.table" to bring an .txt Table to R. Unfortunately the 
> columns do not have the same length. I tried "fill=TRUE", to fill the 
> blank space with "na". In a certain kind of way it worked, but befor 
> filling the spaces it moved data from later columns to the first:
> 
> 1a   b   c  1   a   b   c
> 2   a   b  c  2   a   b   c 
> 3   a   b  c   3   a   bc 
> 4  b  c 4   b   cNA
> 5c   5   c   NA NA

How do you know that c is in third column? If you can expect fixed width 
fields try

read.fwf

but if there is nothing what separates fields and they have variable 
length it would be quite difficult. Maybe to read each line and then to 
use some regexpr function no properly divide each line into appropriate 
columns.

But maybe somebody will come with better idea.

Regards
Petr




> 
> What is my mistake?
> 
> Thank you
> Sebastian
> 
> 
> -- 
> 
***
> 
> Dipl. Biol. Sebastian Krug
> PhD - student
> IFM - GEOMAR
> Leibniz Institute of Marine Sciences
> Research Division 2 - Marine Biogeochemistry
> Düsternbrooker Weg 20
> D - 24105 Kiel
> Germany
> 
> Tel.: +49 431 600-4282
> Fax.: +49 431 600-4446
> email: sk...@ifm-geomar.de
> 
> __
> 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] the by function

2009-03-26 Thread Melissa2k9

Hey,

I have a dataframe with subjects who have watched films. The variables of
interest are Pixel number and Temperature on the face. For each subject
there are 8 films, for each film for each subject I need to measure the mean
number of pixels then merge this vector with the data frame. I have 

mean.pixels<-as.data.frame(by(Final[,5],Final[,1:2],mean)[1:13,])

where column 5 is the pixels variable and 1 and 2 are subject and film
number respectively. Now I can do this, but the average value of the pixel
is usually around 7000. For some reason the machine has only  calculated a
certain second of the film as having say 500 pixels. I need to use the by
function to calculate the mean pixels but I only want it to consider those
values of the pixel variable that are above 1000.

Does anyone know how I can modify the command I already have to make sure
this happens? Sorry it's a bit confusing but I find it hard to explain.
-- 
View this message in context: 
http://www.nabble.com/the-by-function-tp22723918p22723918.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] installing contributed programs

2009-03-26 Thread David Covell

Dear R-help,

I'm sure this is contained within the documentation, but I have not yet located
it (with good effort nonetheless). I am attempting to install the binary for
randomForests. After unpacking the zip, I extracted the contents to
my R-2.8.1 folder. However, when I try to execute the command
library(randomForest) I get an unable to locate error. Is there another
library request that needs to be made? I see that the zip extraction created
the RandomForest folder under the R-2.8.1 folder. Is there a way to
specify this location within the library command?

Thanks for your help,
David

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

2009-03-26 Thread jim holtman
How are you sure it moved the data?  What is the column separator that
you have?  Is it just 'white space' as opposed to a tab or comma?  It
you have a CSV file with a separator, the system knows where the
columns are.  If it sees  'a  b  c' and then 'a c' as the next
row, 'c' will be in column 2 even though you thought 'b' was missing.

On Thu, Mar 26, 2009 at 11:39 AM, skrug  wrote:
> Hi,
>
> I am just starting using R. Hence, sorry for asking probably rather easy
> questions.
>
> I used "read.table" to bring an .txt Table to R. Unfortunately the columns
> do not have the same length. I tried "fill=TRUE", to fill the blank space
> with "na". In a certain kind of way it worked, but befor filling the spaces
> it moved data from later columns to the first:
>
> 1    a   b   c                  1   a   b   c
> 2   a   b      c                  2   a   b   c  3   a   b      c
>         3   a   b    c 4      b      c                     4   b   c    NA
> 5            c                       5   c   NA NA
>
> What is my mistake?
>
> Thank you
> Sebastian
>
>
> --
> ***
>
> Dipl. Biol. Sebastian Krug
> PhD - student
> IFM - GEOMAR
> Leibniz Institute of Marine Sciences
> Research Division 2 - Marine Biogeochemistry
> Düsternbrooker Weg 20
> D - 24105 Kiel
> Germany
>
> Tel.: +49 431 600-4282
> Fax.: +49 431 600-4446
> email: sk...@ifm-geomar.de
>
> __
> 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.
>



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

What is the problem that you are trying to solve?

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

2009-03-26 Thread skrug

Hi,

I am just starting using R. Hence, sorry for asking probably rather easy 
questions.


I used "read.table" to bring an .txt Table to R. Unfortunately the 
columns do not have the same length. I tried "fill=TRUE", to fill the 
blank space with "na". In a certain kind of way it worked, but befor 
filling the spaces it moved data from later columns to the first:


1a   b   c  1   a   b   c
2   a   b  c  2   a   b   c  
3   a   b  c   3   a   bc 
4  b  c 4   b   cNA

5c   5   c   NA NA

What is my mistake?

Thank you
Sebastian


--
***

Dipl. Biol. Sebastian Krug
PhD - student
IFM - GEOMAR
Leibniz Institute of Marine Sciences
Research Division 2 - Marine Biogeochemistry
Düsternbrooker Weg 20
D - 24105 Kiel
Germany

Tel.: +49 431 600-4282
Fax.: +49 431 600-4446
email: sk...@ifm-geomar.de

__
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] arima, xreg, and the armax model

2009-03-26 Thread Marc Vinyes
Hello all,
 
I'm having fun again with the arima function. This time I read in:
http://www.stat.pitt.edu/stoffer/tsa2/R_time_series_quick_fix.htm
 
<>
(by R.H. Shumway & D.S. Stoffer)
 
This is quite surprising... Does anybody know anything about it?
 
Marc Vinyes (AleaSoft)

[[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] package installation on OSX --- suggestion

2009-03-26 Thread ivo welch
dear R experts:

I am trying to install packages in OSX, R 2.8.1.  Since I do this
about every 2 years, I have completely forgotten it.  However, this
should not be difficult:

   
http://wiki.r-project.org/rwiki/doku.php?id=getting-started:installation:packages

nice document.  beautiful method.  so, I start with

   update.packages()

the final message tells me that it saved all the packages into
/var/folders/Ia/IaQbr8K+GQ8DqdaGMAC18yU/-Tmp-/RtmpjRkMV7/downloaded_packages/
.  not exactly user-friendly.  at this point, I don't know whether
they were also installed or just downloaded.  the same happens when I
do an install.package("plm", dependencies=T).  would it not make sense
if the package were installed in the standard R library location at
this point, and the final message to tell me that the package was
indeed installed, and not about the temporary directory?

[I suspect that it actually did the install, so this is just a "final
message" issue.]

just a suggestion...

[and thanks everybody for all the help yesterday.  now back to my moments.]

regards,

/ivo

__
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] programming creating different functions in a loop

2009-03-26 Thread Florin Maican
Hi 

I want to create the  following functions in a loop

f1<-function(x){x+1}
f2<-function(x){x+2}
f3<-function(x){x+3}

Output   f1(2)=3
 f2(2)=4
 f3(2)=5 


I tried to create the in a loop as bellow but I get wrong on answers
because the value of i change

for(i  in 1:3){
assign(paste("f",i,sep="")
,function(x)
 x+i
)
} # end for  

Output   f1(2)=5
 f2(2)=5
 f3(2)=5  
But it is not what I want. The question is how I can
fix in R the value of "i" in my functions?  I tried to use assign() and
get(),but I did not manage. 

Thanks in advance,
Florin

-- 
 Florin  Maican
==

Department of Economics,
School of Business, Economics and Law, 
Gothenburg University, Sweden   
---
P.O. Box 640 SE-405 30, 
Gothenburg, Sweden  

 Mobil:  +46 76 235 3039 
 Phone:  +46 31 786 4866 
 Fax:+46 31 786 4154  
 Home Page: http://maicanfg.googlepages.com/index.html
 E-mail: florin.mai...@handels.gu.se 

 "Not everything that counts can be 
 counted, and not everything that can be 
 counted counts."
 --- Einstein ---

__
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] Travel funding for DSC/useR 2009 for young researchers at U.S. institutions

2009-03-26 Thread luke


   *** Travel and Accommodation Support ***
 [Deadline extended to April 15, 2009]

Funds from the U.S. National Science Foundation may be available to
provide partial support for travel and accommodation for some graduate
students and junior faculty at U.S. post-secondary institutions to
attend DSC 2009 and useR 2009.  If you wish to apply for this support,
please send an application to l...@stat.uiowa.edu.  Your application
should include

a brief CV

a copy of your abstract if you have submitted a paper or a poster

a statement that demonstrates your eligibility, your need for
support, and an amount of support requested

students should include a brief letter of support from their
supervisor

faculty or post-doc applicants should include a brief statement
about other funding sources

The allocation will be based on merit and need; women and minority
candidates are encouraged to apply.

Applications must be made by April 15 (2009-04-15) and successful
applicants will be notified by email soon thereafter.

Please visit the conference web pages at
http://www.r-project.org/dsc-2009/ and
http://www.agrocampus-rennes.fr/math/useR-2009/
for conference details.


--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:  l...@stat.uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

___
r-annou...@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-announce

__
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] Competing risks Kalbfleisch & Prentice method

2009-03-26 Thread Ravi Varadhan
Hi Eleni,

I would like to take a look at your R function for obtaining the cumulative
incidence function (CIF) from individual Cox models for cause-specific
hazards (CSH).  Does your code predict the CIF (with pointwise confidence
intervals and global confidence bands) for different sub-groups?  Have you
seen the paper by Cheng, Fine, and Wei (Biometrics 1998) that does this? 

A major advantage of the F&G model is that you can get a direct, numerical
measure of the effect of a covariate on the CIF.  This cannot be obtained by
modeling all the CSHs and then combining them.  The idiosyncratic assumption
concerning risk set in F&G model is made mainly for mathematical purposes so
that a proportional hazards form may be obtained for the CIF.  You can test
this assumption by plotting schonefeld-type residuals (this is available in
cmprsk).  Fine (Biostatistics 2006) provides a different approach that
relaxes this assumption (it also uses a different estimation approach), but
I don't know if there is an R implementation for that.

Thanks,
Ravi.
 

---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html

 





-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Eleni Rapsomaniki
Sent: Thursday, March 26, 2009 10:18 AM
To: Arthur Allignol
Cc: r-help@r-project.org
Subject: Re: [R] Competing risks Kalbfleisch & Prentice method

Thank you for your reply.

It wasn't too hard to code actually, which is probably why it doesn't have a
special package dedicated to it. The results are almost identical to Fine &
Gray regression model. The problem with the latter is that my colleagues are
not convinced that the model assumptions (people who die from competing
causes remaining in the risk set) are theoretically sound. 

If anybody is interested in the Kalbfleisch & Prentice based cumulative
incidence adjusting for competing risks with covariates, I'm happy to supply
the code.

Eleni Rapsomaniki
 
Research Associate
Tel: +44 (0) 1223 740273
Strangeways Research Laboratory
Department of Public Health and Primary Care University of Cambridge
 

-Original Message-
From: Arthur Allignol [mailto:arthur.allig...@fdm.uni-freiburg.de]
Sent: 26 March 2009 10:36
To: Eleni Rapsomaniki
Cc: r-help@r-project.org
Subject: Re: [R] Competing risks Kalbfleisch & Prentice method

I don't think there is a package to do that.

But you could have a look at ?predict.crr.

Best regards,
Arthur Allignol

Eleni Rapsomaniki wrote:
>  
> 
> Dear R users
> 
>  
> 
> I would like to calculate the Cumulative incidence for an event 
> adjusting for competing risks and adjusting for covariates. One way to 
> do this in R is to use the cmprsk package, function crr. This uses the 
> Fine & Gray regression model. However, a simpler and more classical 
> approach would be to implement the Kalbfleisch & Prentice method
(1980,
> p 169), where one fits cause specific cox models for the event of 
> interest and each type of competing risk, and then calculates
incidence
> based on the overall survival.  I believe that this is what the cuminc 
> function in the aforementioned package does, but it does not allow to 
> adjust for a vector of covariates.
> 
>  
> 
> My question is, is there an R package that implements the Kalbfleisch
&
> Prentice method for competing risks with covariates?
> 
>  
> 
> for example, if k1 is the cause of interest among k competing causes:
> 
> P_k1(t; x)=P(T<=t, cause=k1|x)=Sum(u=0, ..., u=t)
{hazard_k(u;x)*S(u;x)}
> 
> where S(u;x) = exp{-sum_of_k(sum(hazard_k(u))}
> 
>  
> 
> I have searched extensively for an implementation of this in many 
> packages, but it appears that more complex approaches are more
commonly
> implemented, such as timereg package. 
> 
>  
> 
> Eleni Rapsomaniki
> 
>  
> 
> Research Associate
> 
> Strangeways Research Laboratory
> 
> Department of Public Health and Primary Care
> 
>  
> 
> University of Cambridge
> 
>  
> 
>  
> 
> 
>   [[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] Competing risks Kalbfleisch & Prentice method

2009-03-26 Thread Eleni Rapsomaniki
Thank you for your reply.

It wasn't too hard to code actually, which is probably why it doesn't
have a special package dedicated to it. The results are almost identical
to Fine & Gray regression model. The problem with the latter is that my
colleagues are not convinced that the model assumptions (people who die
from competing causes remaining in the risk set) are theoretically
sound. 

If anybody is interested in the Kalbfleisch & Prentice based cumulative
incidence adjusting for competing risks with covariates, I'm happy to
supply the code.

Eleni Rapsomaniki
 
Research Associate
Tel: +44 (0) 1223 740273
Strangeways Research Laboratory
Department of Public Health and Primary Care
University of Cambridge
 

-Original Message-
From: Arthur Allignol [mailto:arthur.allig...@fdm.uni-freiburg.de] 
Sent: 26 March 2009 10:36
To: Eleni Rapsomaniki
Cc: r-help@r-project.org
Subject: Re: [R] Competing risks Kalbfleisch & Prentice method

I don't think there is a package to do that.

But you could have a look at ?predict.crr.

Best regards,
Arthur Allignol

Eleni Rapsomaniki wrote:
>  
> 
> Dear R users
> 
>  
> 
> I would like to calculate the Cumulative incidence for an event
> adjusting for competing risks and adjusting for covariates. One way to
> do this in R is to use the cmprsk package, function crr. This uses the
> Fine & Gray regression model. However, a simpler and more classical
> approach would be to implement the Kalbfleisch & Prentice method
(1980,
> p 169), where one fits cause specific cox models for the event of
> interest and each type of competing risk, and then calculates
incidence
> based on the overall survival.  I believe that this is what the cuminc
> function in the aforementioned package does, but it does not allow to
> adjust for a vector of covariates.
> 
>  
> 
> My question is, is there an R package that implements the Kalbfleisch
&
> Prentice method for competing risks with covariates?
> 
>  
> 
> for example, if k1 is the cause of interest among k competing causes:
> 
> P_k1(t; x)=P(T<=t, cause=k1|x)=Sum(u=0, ..., u=t)
{hazard_k(u;x)*S(u;x)}
> 
> where S(u;x) = exp{-sum_of_k(sum(hazard_k(u))}
> 
>  
> 
> I have searched extensively for an implementation of this in many
> packages, but it appears that more complex approaches are more
commonly
> implemented, such as timereg package. 
> 
>  
> 
> Eleni Rapsomaniki
> 
>  
> 
> Research Associate
> 
> Strangeways Research Laboratory
> 
> Department of Public Health and Primary Care
> 
>  
> 
> University of Cambridge
> 
>  
> 
>  
> 
> 
>   [[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] Some install package fixes for Ubuntu Hardy

2009-03-26 Thread John C Nash
I encountered some failures in using install.packages() to install rgl 
and rJava in some of my (multiple) Ubuntu Hardy systems. A quick search 
of the 'Net did not show any debian packages for these. The 
install.packages messages said header or other files were missing, 
suggesting path and related woes. Email with Duncan Murdoch (thanks!) 
pointed the way with rgl and led to a fix for rJava in similar fashion. 
It may save others some frustration to know my resolution. See below.


However, I do have a question which a brief rummage of r-project did not 
answer. Where should information like this be put? My opinion is that it 
should go on the wiki, but possibly there is a better solution if we can 
get the right messages into the package installers, though I recognize 
the load that puts on maintainers.


Cheers, JN

Ubuntu Hardy rgl install fix:

The headers gl.h and glu.h are installed with the "dev" packages 
libgl1-mesa-dev and libglu1-mesa-dev. So the fix is to run (in at 
terminal as root)


apt-get install libgl1-mesa-dev
apt-get install libglu1-mesa-dev

then
R
.
install.packages("rgl")

etc.



Ubuntu Hardy rJava install fix:

Needed to get Sun JDK (not JRE)

Then add new
ln -s /usr/java/jdkx/bin/java java
and
ln -s /usr/java/jdkx/bin/javac javac

where xx is the version information on the jdk directory name -- in 
my case 1.6.0_13 (see below)


Then

R CMD javareconf

still fails to find the java compiler.

Seems $JAVA_HOME may not be defined.

Try
export JAVA_HOME="/usr/java/jdk1.6.0_13/"

Then (as root)

R CMD javareconf

seems to work.
Then rJava installed OK. I was then able to install RWeka (my original 
objective) and it seems to run OK.


__
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] Minimal R-installation (and it's size)

2009-03-26 Thread Oliver Bandel

Hello,

for very small systems (embedded devices) I think about
a minimalistic R-installation.

When I look at the R-binary, it has just 5472 Bytes of size.
I think this will only be a small initial program,
that afterwards starts other executables and
also will load standard/base package(s).

Can you give me a hint, on how to maintain a minimalistic
R-installation and how much (how less) memory/disk usage
it presumably will need?

Or asked the other way around: how much space (memory/disk)
does R need when it is used only with the packages that are initially
loaded, when I start it up in a distribution like Debian for example)?


Ciao,
   Oliver

__
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] Plot the highest point in a contour plot

2009-03-26 Thread Thomas Levine
I'm plotting contour plots with contourplot.

which.max gives me the index of the highest point of a matrix. I can find
the point in the matrix from here, convert it to a point on a graph and add
it with points, but you'd think someone's already written this.

How do I plot the highest point in a contourplot automatically?

Tom

[[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] problem with "choose.files" command & interactive functions

2009-03-26 Thread Duncan Murdoch

On 3/26/2009 9:09 AM, Shay O'Farrell wrote:

Hi all,

I’m new to R, and I’m having a small but annoying problem with the 
choose.files command, using version 2.8.1 in Windows XP. I am holding my 
data text files in C:\\Data\\, and I’m writing a short script that first 
resets the default directory to this directory, then allows me to 
interactively select which text file to import and attach, using the 
Windows widget. Here is my script:


setwd("C:\\Data\\")
data<-read.table(choose.files(),header=T,as.is=T)
attach(data)

If I copy and paste the script into R Editor (or directly into RGui) and 
run it, it works perfectly. However, if have imported the script using 
the Open Script button in RGui, then I have a glitch... when I run the 
script, the widget looks in the last folder that I opened interactively 
(i.e., the folder from which I imported my script file) instead of 
looking in the new working directory. BUT... if I run line 3 again 
straight after, it works perfectly the second time. What am I doing 
wrong? Any help would be appreciated.


If you don't specify where to open the dialog, it will open in the last 
location where it was opened.  This saves time if you are running it 
more than once, because often you will open files from the same 
directory.   If you don't want that, you can specify which directory to 
open, and get it to always open in the current directory using 
choose.files("./*").


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] problem with "choose.files" command & interactive functions

2009-03-26 Thread Shay O'Farrell

Hi all,

I’m new to R, and I’m having a small but annoying problem with the 
choose.files command, using version 2.8.1 in Windows XP. I am holding my 
data text files in C:\\Data\\, and I’m writing a short script that first 
resets the default directory to this directory, then allows me to 
interactively select which text file to import and attach, using the 
Windows widget. Here is my script:


setwd("C:\\Data\\")
data<-read.table(choose.files(),header=T,as.is=T)
attach(data)

If I copy and paste the script into R Editor (or directly into RGui) and 
run it, it works perfectly. However, if have imported the script using 
the Open Script button in RGui, then I have a glitch... when I run the 
script, the widget looks in the last folder that I opened interactively 
(i.e., the folder from which I imported my script file) instead of 
looking in the new working directory. BUT... if I run line 3 again 
straight after, it works perfectly the second time. What am I doing 
wrong? Any help would be appreciated.


Thanks

Shay

__
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] same value in column-->delete

2009-03-26 Thread Uwe Ligges



Patrizio Frederic wrote:

this works

which.is.not.unique <- apply(x,2,function(x)ifelse(length(unique(x))==1,F,T))
x[,which.is.not.unique]




or you simplify that idea and say

x[, apply(x, 2, function(x) length(unique(x)) > 1)]

Uwe Ligges




patrizio

2009/3/26 Duijvesteijn, Naomi :

  Hi Readers,


  I have a question.


  I have a large dataset and want to throw away columns that have the same
  value in the column itself and I want to know which column this was.


  For example

  > x<-data.frame(id=c(1,2,3), snp1=c("A","G",
  "G"),snp2=c("G","G","G"),snp3=c("G","G","A"))

  > x

id snp1 snp2 snp3

  1  1AGG

  2  2GGG

  3  3GGA


  Now I want to know that snp2 in monomorphic (the same value for the column)
  and after I know which column it is I want to take these columns out.


  Thanks,

  Naomi





  Disclaimer:  De  informatie opgenomen in dit bericht (en bijlagen) kan
  vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde(n).
  Indien u dit bericht ten onrechte ontvangt, wordt u geacht de inhoud niet te
  gebruiken, de afzender direct te informeren en het bericht te vernietigen.
  Aan dit bericht kunnen geen rechten of plichten worden ontleend.

  
  

  Disclaimer: The information contained in this message may be confidential
  and is intended to be exclusively for the addressee. Should you receive this
  message unintentionally, you are expected not to use the contents herein, to
  notify the sender immediately and to destroy the message. No rights can be
  derived from this message.

__
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@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] Column name assignment problem

2009-03-26 Thread Steve Murray

Dear all,

I'm trying to assign a name to the fourth column whilst using 'assign', but 
keep encountering errors. What have I done wrong?!

> assign(colnames(c(paste("arunoff_",table_year, sep="")[4]), "COUNT"))

Error in if (do.NULL) NULL else if (nc> 0) paste(prefix, seq_len(nc),  : 
  argument is not interpretable as logical


Hope someone is able to help.

Thanks for any pointers,

Steve


_
[[elided Hotmail spam]]

__
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: Fortran-90 and R

2009-03-26 Thread jgarcia
Perhaps you should consider also the possibility  of simply export the
data from the R workspace to the system and make your fortran code to read
these system files.

> On Thu, 2009-03-26 at 11:01 +0100, mau...@alice.it wrote:
>> I do hope the chapte about "Interfacing R and Fortran" is sufficient.
>> I have a heavy load of work from two projects and no previous experience
>> in either cases (analysis packages,
>> algorithms, and so on ...). I am a postdoc.
>
> Ranjan Maitra
>
> Posted this link
>
> http://www.stat.umn.edu/~charlie/rc/
>
> last week. I found this quite simple to follow, so it might be a useful
> companion to the Writing R Extensions manual already suggested. The link
> above doesn't specifically address fortran 90, but if special handling
> of f90 code is required, the Writing R Extensions manual will tell you
> what needs to be done differently.
>
> HTH
>
> G
>
>> Thank you.
>> Maura
>>
>> -Messaggio originale-
>> Da: Peter Dalgaard [mailto:p.dalga...@biostat.ku.dk]
>> Inviato: gio 26/03/2009 8.57
>> A: mau...@alice.it
>> Cc: r-help@r-project.org
>> Oggetto: Re: [R] Fortran-90 and R
>>
>> mau...@alice.it wrote:
>> > I have some code in Fortran-90 that outperforms my R implementation of
>> the same algorithm (in terms of speed).
>> > I wonder whether it is possible to interface R with Fortran-90. that
>> is would like to call a Fortran routine from my R
>> > script, passing to the Fortran routine some real numbers array, some
>> scalar real numbers, and an integer number .
>> > I have no idea how to do that because Fortran is a compiled language
>> whereas R s an interpreted language ..
>> > therefore I do not know whetehr it makes any sense to build a make
>> file for the linker ... Is the linker necessary ?
>> >
>> > Thank you very much.
>> > Maura
>>
>> You need to read this:
>>
>> http://cran.r-project.org/doc/manuals/R-exts.pdf
>>
>>  -p
>>
>>
>> __
>> 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.
> --
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>  Dr. Gavin Simpson [t] +44 (0)20 7679 0522
>  ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
>  Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
>  Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
>  UK. WC1E 6BT. [w] http://www.freshwaters.org.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-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] same value in column-->delete

2009-03-26 Thread Patrizio Frederic
this works

which.is.not.unique <- apply(x,2,function(x)ifelse(length(unique(x))==1,F,T))
x[,which.is.not.unique]

patrizio

2009/3/26 Duijvesteijn, Naomi :
>
>   Hi Readers,
>
>
>   I have a question.
>
>
>   I have a large dataset and want to throw away columns that have the same
>   value in the column itself and I want to know which column this was.
>
>
>   For example
>
>   > x<-data.frame(id=c(1,2,3), snp1=c("A","G",
>   "G"),snp2=c("G","G","G"),snp3=c("G","G","A"))
>
>   > x
>
>     id snp1 snp2 snp3
>
>   1  1    A    G    G
>
>   2  2    G    G    G
>
>   3  3    G    G    A
>
>
>   Now I want to know that snp2 in monomorphic (the same value for the column)
>   and after I know which column it is I want to take these columns out.
>
>
>   Thanks,
>
>   Naomi
>
>
>
>
>
>   Disclaimer:  De  informatie opgenomen in dit bericht (en bijlagen) kan
>   vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde(n).
>   Indien u dit bericht ten onrechte ontvangt, wordt u geacht de inhoud niet te
>   gebruiken, de afzender direct te informeren en het bericht te vernietigen.
>   Aan dit bericht kunnen geen rechten of plichten worden ontleend.
>
>   
>   
>
>   Disclaimer: The information contained in this message may be confidential
>   and is intended to be exclusively for the addressee. Should you receive this
>   message unintentionally, you are expected not to use the contents herein, to
>   notify the sender immediately and to destroy the message. No rights can be
>   derived from this message.
>
> __
> 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] Centring variables in Cox Proportional Hazards Model

2009-03-26 Thread Frank E Harrell Jr

Laura Bonnett wrote:

Dear All,

I am contemplating centering the covariates in my Cox model to reduce
multicollinearity between the predictors and the interaction term and
to render a more meaningful interpretation of the regression
coefficient.  Suppose I have two indicator variables, x1 and x2 which
represent age categories (x1 is patients less than 16 while x2 is for
patients older than 65).  If I use the following Cox model, is there
anyway I can centre the variables?  Do I have to do it before I fit
them into the model and if so, how?

fit2=coxph(Surv(rem.Remtime,rem.Rcens)~x1(partial)+x2(partial),data=partial,method="breslow")

Thank you,

Laura



There is no need to center the variables.   Also, you are going to find 
a huge lack of fit for the shape of the age effect you are using, as 
opposed to using a smooth function in continuous age.


Your notation is treating x1 and x2 as functions of data frame which is 
strange.  With data=partial you would ordinarily just have something 
like x1+x2 in the model.


Frank

--
Frank E Harrell Jr   Professor and Chair   School of Medicine
 Department of Biostatistics   Vanderbilt University

__
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] same value in column-->delete

2009-03-26 Thread Gustaf Rydevik
On Thu, Mar 26, 2009 at 12:15 PM, Duijvesteijn, Naomi
 wrote:
>
>   Hi Readers,
>
>
>   I have a question.
>
>
>   I have a large dataset and want to throw away columns that have the same
>   value in the column itself and I want to know which column this was.
>
>
>   For example
>
>   > x<-data.frame(id=c(1,2,3), snp1=c("A","G",
>   "G"),snp2=c("G","G","G"),snp3=c("G","G","A"))
>
>   > x
>
>     id snp1 snp2 snp3
>
>   1  1    A    G    G
>
>   2  2    G    G    G
>
>   3  3    G    G    A
>
>
>   Now I want to know that snp2 in monomorphic (the same value for the column)
>   and after I know which column it is I want to take these columns out.
>
>
>   Thanks,
>
>   Naomi
>


Another, perhaps slightly more intuitive solution than Jim's would be
the following:

 x<-data.frame(id=c(1,2,3), snp1=c("A","G",
"G"),snp2=c("G","G","G"),snp3=c("G","G","A"))
is.monovalued<-function(df){
  sapply(df,function(x){
length(unique(x))==1
  })
}

monovaluedCols<-is.monovalued(x)
which(monovaluedCols)
x[!monovaluedCols]

/Gustaf
-- 
Gustaf Rydevik, M.Sci.
tel: +46(0)703 051 451
address:Essingetorget 40,112 66 Stockholm, SE
skype:gustaf_rydevik

__
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] Getting started,

2009-03-26 Thread Gabor Grothendieck
Try this:

library(zoo)
library(chron)

my.url <- 
"http://www.federalreserve.gov/releases/h15/data/Business_day/H15_ED_M1.txt";
z <- read.zoo(my.url, skip = 8, header = TRUE, sep = ",", na.strings = "ND",
strip.white = TRUE, FUN = as.chron)
plot(z[1:50,])

# or to plot with NAs interpolated
plot(na.approx(z[1:50,]))

See the three zoo vignettes:
vignette(package = "zoo")
vignette("zoo")
# etc.

and for more on dates see R News 4/1.


On Thu, Mar 26, 2009 at 6:58 AM, gug  wrote:
>
> Hello,
>
> First of all, I'm new to R and I don't have anyone who already knows the
> language to ask for tips, so please excuse my ignorance.
>
> I'm trying to download data direct from the Federal Reserve statistics
> website and graph it, using the following:
>
>        #This downloads the data from the Fed website
> download.file("http://www.federalreserve.gov/releases/h15/data/Business_day/H15_ED_M1.txt","Eurodollar_deposits1M.dat";)
>
>        #This reads that data into a table
> data_download=read.table("Eurodollar_deposits1M.dat",skip=8,sep=",",head=T)
>
>        #This is attempting to get R to read the date column, which is in
> "mm/dd/" format
>        #I have restricted it to the first 50 data points (to keep it simple)
> date_vec = as.Date(data_download[1:50,1],"%m/%d/%y")
>
>        #This reads the values again for just the first 50 data points
> eurodollar_vec = data_download[1:50,2]
>
>        #This plots the date and data values.
> plot(date_vec,eurodollar_vec)
>
>
> A few issues with the output from this:
>
> 1) The date_vec data ends up looking like this "2019-01-04" - for some
> reason all year 2019, irrespective of the actual year (e.g. 1971, 1972).
> Any suggestions as to where I am going wrong?
>
> 2) The chart ends up as a scatter diagram, not surprisingly.  I initially
> tried to use the ts.plot() function but when I did, I found that it doesn't
> use the date column in the data as the x axis.  Is there a way of creating a
> time series that uses the date column, or alternatively, how would I turn
> these two columns (date & value) into a line graph?
>
> 3) The y-axis output should be from about 4.5 to about 8.5, but the y-axis
> shows as being about 430-670.  There also seems to be a line of points
> across the top which are all of the same value - as though anything above
> about 670 gets charted as 670.
>
>
> I'm sorry for this being a "what am I doing wrong" post, but I have looked
> through the manuals without success, and I am new enough to R that I don't
> have a feel for ways round these sorts of problems.  Any suggestions would
> be greatly appreciated.  Thanks.
> --
> View this message in context: 
> http://www.nabble.com/Getting-started%2C-tp22719735p22719735.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] same value in column-->delete

2009-03-26 Thread jim holtman
Try this:

> x
  id snp1 snp2 snp3
1  1AGG
2  2GGG
3  3GGA
> str(x)
'data.frame':   3 obs. of  4 variables:
 $ id  : num  1 2 3
 $ snp1: Factor w/ 2 levels "A","G": 1 2 2
 $ snp2: Factor w/ 1 level "G": 1 1 1
 $ snp3: Factor w/ 2 levels "A","G": 2 2 1
> # test for which columns are the same
> apply(x, 2, function(.col) all(head(.col, -1) == tail(.col, -1)))
   id  snp1  snp2  snp3
FALSE FALSE  TRUE FALSE
>


On Thu, Mar 26, 2009 at 7:15 AM, Duijvesteijn, Naomi
 wrote:
>
>   Hi Readers,
>
>
>   I have a question.
>
>
>   I have a large dataset and want to throw away columns that have the same
>   value in the column itself and I want to know which column this was.
>
>
>   For example
>
>   > x<-data.frame(id=c(1,2,3), snp1=c("A","G",
>   "G"),snp2=c("G","G","G"),snp3=c("G","G","A"))
>
>   > x
>
>     id snp1 snp2 snp3
>
>   1  1    A    G    G
>
>   2  2    G    G    G
>
>   3  3    G    G    A
>
>
>   Now I want to know that snp2 in monomorphic (the same value for the column)
>   and after I know which column it is I want to take these columns out.
>
>
>   Thanks,
>
>   Naomi
>
>
>
>
>
>   Disclaimer:  De  informatie opgenomen in dit bericht (en bijlagen) kan
>   vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde(n).
>   Indien u dit bericht ten onrechte ontvangt, wordt u geacht de inhoud niet te
>   gebruiken, de afzender direct te informeren en het bericht te vernietigen.
>   Aan dit bericht kunnen geen rechten of plichten worden ontleend.
>
>   
>   
>
>   Disclaimer: The information contained in this message may be confidential
>   and is intended to be exclusively for the addressee. Should you receive this
>   message unintentionally, you are expected not to use the contents herein, to
>   notify the sender immediately and to destroy the message. No rights can be
>   derived from this message.
>
> __
> 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.
>
>



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

What is the problem that you are trying to solve?

__
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] Getting started,

2009-03-26 Thread jim holtman
In answer to your first question, your statement should be:

date_vec = as.Date(data_download[1:50,1],"%m/%d/%Y")

Notice the capital "Y"; lower case says the year is only 2 digits, so
you were pickup up the '19' from the date.

Use 'plot(..., type='l')' for a line plot.

Your data is being read in as factors:

> str(data_download)
'data.frame':   9972 obs. of  2 variables:
 $ DATE: Factor w/ 9972 levels "01/01/1973","01/01/1974",..: 84 112
140 167 195 279 307 335 362 390 ...
 $ EDM1: Factor w/ 673 levels " 0.70"," 0.75",..: 599 597 593 594 591
586 583 571 574 586 ...

You need to convert EDM1 to numeric

data_download$EDM1 <- as.numeric(as.character(data_download$EDM1))

and then your data will plot as you like.

On Thu, Mar 26, 2009 at 6:58 AM, gug  wrote:
>
> Hello,
>
> First of all, I'm new to R and I don't have anyone who already knows the
> language to ask for tips, so please excuse my ignorance.
>
> I'm trying to download data direct from the Federal Reserve statistics
> website and graph it, using the following:
>
>        #This downloads the data from the Fed website
> download.file("http://www.federalreserve.gov/releases/h15/data/Business_day/H15_ED_M1.txt","Eurodollar_deposits1M.dat";)
>
>        #This reads that data into a table
> data_download=read.table("Eurodollar_deposits1M.dat",skip=8,sep=",",head=T)
>
>        #This is attempting to get R to read the date column, which is in
> "mm/dd/" format
>        #I have restricted it to the first 50 data points (to keep it simple)
> date_vec = as.Date(data_download[1:50,1],"%m/%d/%y")
>
>        #This reads the values again for just the first 50 data points
> eurodollar_vec = data_download[1:50,2]
>
>        #This plots the date and data values.
> plot(date_vec,eurodollar_vec)
>
>
> A few issues with the output from this:
>
> 1) The date_vec data ends up looking like this "2019-01-04" - for some
> reason all year 2019, irrespective of the actual year (e.g. 1971, 1972).
> Any suggestions as to where I am going wrong?
>
> 2) The chart ends up as a scatter diagram, not surprisingly.  I initially
> tried to use the ts.plot() function but when I did, I found that it doesn't
> use the date column in the data as the x axis.  Is there a way of creating a
> time series that uses the date column, or alternatively, how would I turn
> these two columns (date & value) into a line graph?
>
> 3) The y-axis output should be from about 4.5 to about 8.5, but the y-axis
> shows as being about 430-670.  There also seems to be a line of points
> across the top which are all of the same value - as though anything above
> about 670 gets charted as 670.
>
>
> I'm sorry for this being a "what am I doing wrong" post, but I have looked
> through the manuals without success, and I am new enough to R that I don't
> have a feel for ways round these sorts of problems.  Any suggestions would
> be greatly appreciated.  Thanks.
> --
> View this message in context: 
> http://www.nabble.com/Getting-started%2C-tp22719735p22719735.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.
>



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

What is the problem that you are trying to solve?

__
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] Centring variables in Cox Proportional Hazards Model

2009-03-26 Thread Laura Bonnett
Dear All,

I am contemplating centering the covariates in my Cox model to reduce
multicollinearity between the predictors and the interaction term and
to render a more meaningful interpretation of the regression
coefficient.  Suppose I have two indicator variables, x1 and x2 which
represent age categories (x1 is patients less than 16 while x2 is for
patients older than 65).  If I use the following Cox model, is there
anyway I can centre the variables?  Do I have to do it before I fit
them into the model and if so, how?

fit2=coxph(Surv(rem.Remtime,rem.Rcens)~x1(partial)+x2(partial),data=partial,method="breslow")

Thank you,

Laura

__
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] Using JRclient in java application

2009-03-26 Thread Tomasz Spulak
Hi,

I'm wondering if anyone can help me. I'm writing java application that using
JRclient and Rserve to communicate with R. I want to get response from R for
command:

x <- rbind(matrix(rnorm(100, sd = 0.3), ncol = 2),matrix(rnorm(100, mean =
1, sd = 0.3), ncol = 2))
kmeans(x, 2, 22, algorithm = "Hartigan-Wong")

and put result of kmeans() function in my TextArea.I've tried something like
that:

zz <- file("ex.txt", "w")
capture.output(kmeans(x, 2, 22, algorithm = "Hartigan-Wong"), file = zz,
append = TRUE)

and then get "ex.txt" file from R and rewrite it to my local file using java
method:

public void saveFileFromServer(Rconnection rConnection, String fileName,
String pathToSave) throws Exception {

RFileInputStream ris = rConnection.openFile(fileName);

FileOutputStream outs = new FileOutputStream(pathToSave + "/"
+ new File(fileName).getName());

byte[] buf = new byte[1024];
int n = 0;
while ((n = ris.read(buf)) != -1) {

outs.write(buf, 0, n);
}

outs.flush();
ris.close();
outs.close();
}

It works fine (i have file "ex.txt" with results) when i run my application
from Eclipse.
Problems starts when i put application in jar. In that case my "ex.txt" file
is empty.

Can anyone tell what i'm doing wrong?

Thanks in advance

Tomek Spulak

[[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] same value in column-->delete

2009-03-26 Thread Duijvesteijn, Naomi

   Hi Readers,


   I have a question.


   I have a large dataset and want to throw away columns that have the same
   value in the column itself and I want to know which column this was.


   For example

   > x<-data.frame(id=c(1,2,3), snp1=c("A","G",
   "G"),snp2=c("G","G","G"),snp3=c("G","G","A"))

   > x

 id snp1 snp2 snp3

   1  1AGG

   2  2GGG

   3  3GGA


   Now I want to know that snp2 in monomorphic (the same value for the column)
   and after I know which column it is I want to take these columns out.


   Thanks,

   Naomi


   
   
   
   Disclaimer:  De  informatie opgenomen in dit bericht (en bijlagen) kan
   vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde(n).
   Indien u dit bericht ten onrechte ontvangt, wordt u geacht de inhoud niet te
   gebruiken, de afzender direct te informeren en het bericht te vernietigen.
   Aan dit bericht kunnen geen rechten of plichten worden ontleend.

   
   

   Disclaimer: The information contained in this message may be confidential
   and is intended to be exclusively for the addressee. Should you receive this
   message unintentionally, you are expected not to use the contents herein, to
   notify the sender immediately and to destroy the message. No rights can be
   derived from this message.
__
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] Manual sort in a for loop

2009-03-26 Thread Steve Murray

Thanks all - I'm fairly new to R, so I was oblivious to the pros and cons of 
using a data frame as opposed to a list! The 'get' command also seemed to work 
successfully.

Thanks again,

Steve


_
 25GB of FREE Online Storage – Find out more

__
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] Warning messages from quantreg

2009-03-26 Thread Daren Tan
Hi, I keep getting warning messages from quantreg about "tiny
diagonals replaced with Inf when calling blkfct". Is there any cause
for concern like improper codes, NAs in datasets or missing values ?

Thanks
Stanley

__
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: Fortran-90 and R

2009-03-26 Thread Gavin Simpson
On Thu, 2009-03-26 at 11:01 +0100, mau...@alice.it wrote:
> I do hope the chapte about "Interfacing R and Fortran" is sufficient. 
> I have a heavy load of work from two projects and no previous experience in 
> either cases (analysis packages,
> algorithms, and so on ...). I am a postdoc.

Ranjan Maitra

Posted this link

http://www.stat.umn.edu/~charlie/rc/

last week. I found this quite simple to follow, so it might be a useful
companion to the Writing R Extensions manual already suggested. The link
above doesn't specifically address fortran 90, but if special handling
of f90 code is required, the Writing R Extensions manual will tell you
what needs to be done differently.

HTH

G

> Thank you.
> Maura 
> 
> -Messaggio originale-
> Da: Peter Dalgaard [mailto:p.dalga...@biostat.ku.dk]
> Inviato: gio 26/03/2009 8.57
> A: mau...@alice.it
> Cc: r-help@r-project.org
> Oggetto: Re: [R] Fortran-90 and R
>  
> mau...@alice.it wrote:
> > I have some code in Fortran-90 that outperforms my R implementation of the 
> > same algorithm (in terms of speed).
> > I wonder whether it is possible to interface R with Fortran-90. that is 
> > would like to call a Fortran routine from my R 
> > script, passing to the Fortran routine some real numbers array, some scalar 
> > real numbers, and an integer number . 
> > I have no idea how to do that because Fortran is a compiled language 
> > whereas R s an interpreted language ..
> > therefore I do not know whetehr it makes any sense to build a make file for 
> > the linker ... Is the linker necessary ?
> > 
> > Thank you very much.
> > Maura
> 
> You need to read this:
> 
> http://cran.r-project.org/doc/manuals/R-exts.pdf
> 
>   -p
> 
> 
> __
> 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.
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.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] Getting started,

2009-03-26 Thread gug

Hello,

First of all, I'm new to R and I don't have anyone who already knows the
language to ask for tips, so please excuse my ignorance.

I'm trying to download data direct from the Federal Reserve statistics
website and graph it, using the following:

#This downloads the data from the Fed website
download.file("http://www.federalreserve.gov/releases/h15/data/Business_day/H15_ED_M1.txt","Eurodollar_deposits1M.dat";)

#This reads that data into a table
data_download=read.table("Eurodollar_deposits1M.dat",skip=8,sep=",",head=T)

#This is attempting to get R to read the date column, which is in
"mm/dd/" format
#I have restricted it to the first 50 data points (to keep it simple)
date_vec = as.Date(data_download[1:50,1],"%m/%d/%y")

#This reads the values again for just the first 50 data points
eurodollar_vec = data_download[1:50,2]

#This plots the date and data values.
plot(date_vec,eurodollar_vec)


A few issues with the output from this:

1) The date_vec data ends up looking like this "2019-01-04" - for some
reason all year 2019, irrespective of the actual year (e.g. 1971, 1972). 
Any suggestions as to where I am going wrong?

2) The chart ends up as a scatter diagram, not surprisingly.  I initially
tried to use the ts.plot() function but when I did, I found that it doesn't
use the date column in the data as the x axis.  Is there a way of creating a
time series that uses the date column, or alternatively, how would I turn
these two columns (date & value) into a line graph?

3) The y-axis output should be from about 4.5 to about 8.5, but the y-axis
shows as being about 430-670.  There also seems to be a line of points
across the top which are all of the same value - as though anything above
about 670 gets charted as 670.


I'm sorry for this being a "what am I doing wrong" post, but I have looked
through the manuals without success, and I am new enough to R that I don't
have a feel for ways round these sorts of problems.  Any suggestions would
be greatly appreciated.  Thanks.
-- 
View this message in context: 
http://www.nabble.com/Getting-started%2C-tp22719735p22719735.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] Density estimation: scale back for calendar time

2009-03-26 Thread Pradeep Raje
Thanks David for your response.I had done that. Problem is not with the
computations, but in the interpretation.
Assume that x ordinates are 'time' [1:3472], and y are associated parameter
values.
Now density gives me 512/1024/2048 x-ordinates, of which some (7 to be
precise) are negative. What do I make of the non-zero probability at
**negative** times?

If you see your rnorm case, you get the first few items negative. If the x
items are bounded non-negative, what would density estimates at negative
x-points mean?

I can't do a linear scaling because that will disturb the density estimates
on different days.
Regards,
pradeep

On Wed, Mar 25, 2009 at 11:39 PM, David Winsemius wrote:

> I am afraid your notion of a "concrete idea" is less concrete than what I
> would need to understand what you are requesting. Your first lines of
> example code should be:
>
> library()
>   
> density(x, )
>
> ... since  stats::density() by default would return 512 y estimates, even
> if the length of x were longer.
>
> > x <- rnorm(3471)
> > plot(density(x))
> > str(density(x))
> List of 7
>  $ x: num [1:512] -3.98 -3.96 -3.94 -3.93 -3.91 ...
>  $ y: num [1:512] 7.98e-06
>
> --
> David Winsemius
>
>
> On Mar 25, 2009, at 9:30 AM, Pradeep Raje wrote:
>
>  Dear all:Request your indulgence. The econophysics gurus do this stuff all
>> the time: all their PDFs are smooth, with neat log x axis.
>> 1. The kernel density estimate (KDE) function returns the empirical
>> probability density at 2^n points (min: 512). The big question is how do I
>> scale back the x-values (say, density$x) to x-values in terms of the
>> original dataset?
>> 2. To give you a concrete idea, i have a dataset of 3471 obs (x=date
>> index,
>> y=parameter values). Now the density estimate d<-density(x) gives be 2048
>> x-values. When I plot the PDF, the x axis is obviously d$x, length=2048.
>> 3. How can I scale back these 2048 values to get a sense of calendar time
>> (original date index)?
>> 4. Subsidiary question is: how do i bring in the remaining values
>> (3471-2048)?
>>
>
> You seem to have the idea that the original data is "lined up" with the
> density estimates. That is not so.
>
>
>> Thanks very much in advance.
>> pradeep
>>
>>[[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.
>>
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>

[[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] Sort by timestamp

2009-03-26 Thread j.k

#Good morning alltogheter. I'm using R for a short time to analyse TimeSeries
and I have the following Problem:
#I have a bunch of Time Series:
#First of all I import them from a txt File

data.input01 <-read.csv("./LD/20081030.txt", header = TRUE, sep = ";",
quote="\"", dec=",", fill = TRUE, comment.char="")
data.input02 <-read.csv("./LD/20090305.txt", header = TRUE, sep = ";",
quote="\"", dec=",", fill = TRUE, comment.char="")
data.input03 <-read.csv("./LD/20081114.txt", header = TRUE, sep = ";",
quote="\"", dec=",", fill = TRUE, comment.char="")
data.input04 <-read.csv("./LD/20081201.txt", header = TRUE, sep = ";",
quote="\"", dec=",", fill = TRUE, comment.char="")
data.input05 <-read.csv("./LD/20081219.txt", header = TRUE, sep = ";",
quote="\"", dec=",", fill = TRUE, comment.char="")
data.input06 <-read.csv("./LD/20090107.txt", header = TRUE, sep = ";",
quote="\"", dec=",", fill = TRUE, comment.char="")

#After the import they look like that:

  V1   V2
1  2008-10-14 08:45:00 92130.68
2  2008-10-14 08:50:00 94051.70
3  2008-10-14 08:55:00 97050.85
4  2008-10-14 09:00:00 81133.81
5  2008-10-14 09:05:00 70705.40
6  2008-10-14 09:10:00 75213.92
7  2008-10-14 09:15:00 90876.14
8  2008-10-14 09:20:00 85995.17

#Next steps are to combine them with rbind and sort duplicates out

data.troughput01 <-
rbind(data.input03,data.input01,data.input04,data.input02,data.input05,data.input06)
data.troughput02 <- unique(data.troughput01)

#The Problem is that the dates are mixed and I want to sort/order them by
the date and time.
#The class of the Date/time is as followed:
class(data.input01$V1)
[1] "factor"

# I've already tried sort and order but it didn't work
#Are there any suggestions, how I can solve this issue??

Thanks in advance
Johannes

-- 
View this message in context: 
http://www.nabble.com/Sort-by-timestamp-tp22717322p22717322.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] loop problem

2009-03-26 Thread Jim Lemon

Muhammad Azam wrote:

Dear R members
I have a problem regarding storing the lists.
Let 
L=number of distinct values of any predictor (say L=5)

P=number of predictors (say P=20)

g1 <- c()
for(i in 1:P){
if(L > 1){
  for(j in 1:(L-1)){
g <- 
g1[j] <- g
   }
}
g2[]=sort.list(g1)
}

Now the question is: What should we use inside brackets of g2[], whether "i" or some thing else? If L is not greater than 1 then there will be a "NULL" for g2. We don't want to store it in g2, so how can we handle this problem. Looking forward for some help. Thanks and 
  

Hi Muhammad,
The first thing I would ask is "Why not store NULL in g2[[i]] if that 
element is NULL?". If you do this:


for(i in 1:P) {
if(L > 1) {
 g1<-rep(NA,L)
 for(j in 1:(L-1)) g1[j]<-...
 g2[[i]]<-sort.list(g1)
}
}

you will have fewer elements in g2 than you have sets of predictors and 
will then have to match up the sets of predictors with the elements in 
g2. I think you could just test for NULL


is.null(g2[[i]])

later on if you don't want to process these in a subsequent step.

Jim

__
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] Manual sort in a for loop

2009-03-26 Thread Simon Pickett
I would suggest avoiding the function ?assign inside a loop. I used top use 
this until someone here kindly pointed out that it was much easier to catch 
the data of interest in a list...


eg.

df.list <- vector("list", length(10))
for (i in 1:10)}
df.list[[i]]<-data.frame(arunoff_,table_year,_temp)[c(10,7,9,5,4,12,1,3,2,8,11,6),]
}

HTH

Simon.




- Original Message - 
From: "Steve Murray" 

To: 
Sent: Wednesday, March 25, 2009 5:58 PM
Subject: [R] Manual sort in a for loop




Dear all,

I am trying to manually re-sort rows in a number of tables. The rows 
aren't sorted on any particular values but are simply ordered by user 
choice (as shown by the row numbers in the code). I have been able to 
carry out each re-arrangement without the use of the 'for' loop, but 
cannot seem to successfully execute the statements when incorporated into 
the loop. The code I have is as follows:


table_year=1951
for (i in (paste("arunoff_",year,"_temp",sep=""))) {
 assign(paste("arunoff_",table_year, 
sep=""),paste("arunoff_",table_year,"_temp")[c(10,7,9,5,4,12,1,3,2,8,11,6),])

 table_year = table_year+1
 }


The error I get is:

Error in paste("arunoff_", table_year, "_temp")[c(10, 7, 9, 5, 4, 12,  :
 incorrect number of dimensions

...depsite this not occurring when I do each table individually (so it 
can't be a case of there not being enough rows, as> dim(arunoff_1951_temp) 
gives [1] 12 11


I have a feeling that it may be a syntax error, possibly between 'temp' 
and the square bracket, but I can't be sure of this.



Any solutions or advice offered would be gratefully received.

Many thanks,

Steve

_
[[elided Hotmail spam]]

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


  1   2   >