[R] R 2.14.0 Design library

2012-01-04 Thread Bonnett, Laura
Dear all,

I have recently upgraded to R 2.14.0 with Windows 7.  I wish to use the command 
'cph' but the Design library is no longer on the list of installable packages.  
How can I install Design so that I may use the 'cph' function?

Many thanks,
Laura


[[alternative HTML version deleted]]

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


Re: [R] R 2.14.0 Design library

2012-01-04 Thread Milan Bouchet-Valat
Le mercredi 04 janvier 2012 à 09:04 +, Bonnett, Laura a écrit :
 Dear all,
 
 I have recently upgraded to R 2.14.0 with Windows 7.  I wish to use
 the command 'cph' but the Design library is no longer on the list of
 installable packages.  How can I install Design so that I may use the
 'cph' function?
Design has been replaced with rms for some time, with (AFAIK) the
same functions.

http://cran.r-project.org/web/packages/rms/index.html


Cheers

__
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 2.14.0 Design library

2012-01-04 Thread Bonnett, Laura
Thank you!

-Original Message-
From: Milan Bouchet-Valat [mailto:nalimi...@club.fr] 
Sent: 04 January 2012 09:23
To: Bonnett, Laura
Cc: 'r-help@r-project.org'
Subject: Re: [R] R 2.14.0 Design library

Le mercredi 04 janvier 2012 à 09:04 +, Bonnett, Laura a écrit :
 Dear all,
 
 I have recently upgraded to R 2.14.0 with Windows 7.  I wish to use
 the command 'cph' but the Design library is no longer on the list of
 installable packages.  How can I install Design so that I may use the
 'cph' function?
Design has been replaced with rms for some time, with (AFAIK) the
same functions.

http://cran.r-project.org/web/packages/rms/index.html


Cheers
__
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] Extract concordance from coxph.object

2012-01-04 Thread Bonnett, Laura
Dear all,

As I said in my previous email I have just upgraded to R 2.14.0 on Windows 7.  
I have just run the 'coxph' function and notice that a Concordance statistic is 
produced.  Is there any way to extract this information from the output?

E.g. can I call the concordance value independently of calling the output?

Many thanks,
Laura

[[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] About source()

2012-01-04 Thread Uwe Ligges



On 03.01.2012 21:22, Li SUN wrote:

Thanks, Rolf, Justin and Uwe!

Actually I wanted to run .R file as a script, just like what people do
for bash scripts or python scripts. It seems to me that adding
#!/usr/bin/R -f at the first line is what I need. Is this true?



Perhaps even Rscript rather than R.

Uwe Ligges


Li Sun


2012/1/2 Rolf Turnerrolf.tur...@xtra.co.nz:

On 03/01/12 17:02, Li SUN wrote:


Hello,

I am a beginner to the R language and find it fantastic and
well-designed, quite different from other programming languages.


What a refreshingly sensible attitude!!! :-)


This is the first time I post on the r-help mailing list.

In invoking the function source(filename), it seems that the filename
has to exist in the current working directory, otherwise it has to be
specified in full path. So is there any mechanism(such as environment
variable) to specify an additional directory of .R files that source()
could search in?



I'm no expert on this, and others may correct me, but

(1) I don't believe any such mechanism exists.

(2) It's probably not a good idea, even if such a mechanism
were to exist.  Directories have a tree structure, rather than
being linearly ordered in the way that data bases on your
R search path are ordered.

I believe you would run all sorts of risks of confusion and
of getting the wrong file were you to invoke such a mechanism.

It is ``good practice'' to have separate directories associated
with different projects and to situate all files, that you might wish
to source in respect of a given project, in the directory associated
with that project.

I know that this is an irritating sort of response --- ``No, you can't
do that, and you shouldn't do it anyway!'' --- but I sincerely believe
this to be true.

That being said, I also believe that you could program up such a mechanism
yourself. I.e. build a function source2() which would have a hard coded
list
of directories to search, and would make use of the try() function.

Might be a good exercise for you, given that you are starting out in R
and looking to upgrade your skills! :-)

cheers,

Rolf Turner




__
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] tcltk on linux/rhel6

2012-01-04 Thread Prof Brian Ripley

On 04/01/2012 01:52, Peter Langfelder wrote:

On Tue, Jan 3, 2012 at 4:03 PM, Carl Baribaultcrlbr...@gmail.com  wrote:

Dear All,

I've seen posts to the effect that..
1) choose.dir is only available for windows, and
2) tk_choose.dir would be the linux equivalent.

I'm still having trouble with the subject package on linux/rhel6.

I've specified --with-tcltk during ./configure, and I still get the response...


install.packages(tcltk)


My understanding is that tcltk is included in the base installation
now. You should be able to load it using library(tcltk) without
explicitly installing it. You can install tcltk2 as an add-on package.


Yes, but you need OS support (for both).

Whoever installed this R needs to read the R-admin manual and note the 
need for -devel RPMs for Tcl and Tk.  Then study the configure messages 
which tell you if tcltk was built.


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@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] About source()

2012-01-04 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 04/01/12 10:39, Uwe Ligges wrote:
 
 
 On 03.01.2012 21:22, Li SUN wrote:
 Thanks, Rolf, Justin and Uwe!
 
 Actually I wanted to run .R file as a script, just like what
 people do for bash scripts or python scripts. It seems to me that
 adding #!/usr/bin/R -f at the first line is what I need. Is
 this true?
 
 
 Perhaps even Rscript rather than R.

And there is also littler from Dirk Eddelbüttel:

http://dirk.eddelbuettel.com/code/littler.html

- From the description: littler provides hash-bang (i.e. script
starting with #!/some/path) capability for GNU R, as well as simple
command-line and piping use.

Similar to Rscript, but with some differences.

I used both, and in most cases they are equivalent.


Rainer


 
 Uwe Ligges
 
 Li Sun
 
 
 2012/1/2 Rolf Turnerrolf.tur...@xtra.co.nz:
 On 03/01/12 17:02, Li SUN wrote:
 
 Hello,
 
 I am a beginner to the R language and find it fantastic and 
 well-designed, quite different from other programming
 languages.
 
 What a refreshingly sensible attitude!!! :-)
 
 This is the first time I post on the r-help mailing list.
 
 In invoking the function source(filename), it seems that the
 filename has to exist in the current working directory,
 otherwise it has to be specified in full path. So is there
 any mechanism(such as environment variable) to specify an
 additional directory of .R files that source() could search
 in?
 
 
 I'm no expert on this, and others may correct me, but
 
 (1) I don't believe any such mechanism exists.
 
 (2) It's probably not a good idea, even if such a mechanism 
 were to exist.  Directories have a tree structure, rather than 
 being linearly ordered in the way that data bases on your R
 search path are ordered.
 
 I believe you would run all sorts of risks of confusion and of
 getting the wrong file were you to invoke such a mechanism.
 
 It is ``good practice'' to have separate directories
 associated with different projects and to situate all files,
 that you might wish to source in respect of a given project, in
 the directory associated with that project.
 
 I know that this is an irritating sort of response --- ``No,
 you can't do that, and you shouldn't do it anyway!'' --- but I
 sincerely believe this to be true.
 
 That being said, I also believe that you could program up such
 a mechanism yourself. I.e. build a function source2() which
 would have a hard coded list of directories to search, and
 would make use of the try() function.
 
 Might be a good exercise for you, given that you are starting
 out in R and looking to upgrade your skills! :-)
 
 cheers,
 
 Rolf Turner
 
 
 
 __ 
 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.


- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :   +33 - (0)9 53 10 27 44
Cell:   +33 - (0)6 85 62 59 98
Fax :   +33 - (0)9 58 10 27 44

Fax (D):+49 - (0)3 21 21 25 22 44

email:  rai...@krugs.de

Skype:  RMkrug
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk8EIs4ACgkQoYgNqgF2egpF+QCeObN8q+U6HHlM/Tsls/wF+VoH
/twAn2zaTzVrCdTxvENSK2buPlFsjlnC
=tEkV
-END PGP SIGNATURE-

__
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] Extract concordance from coxph.object

2012-01-04 Thread Milan Bouchet-Valat
Le mercredi 04 janvier 2012 à 09:27 +, Bonnett, Laura a écrit :
 Dear all,
 
 As I said in my previous email I have just upgraded to R 2.14.0 on Windows 7. 
  I have just run the 'coxph' function and notice that a Concordance statistic 
 is produced.  Is there any way to extract this information from the output?
 
 E.g. can I call the concordance value independently of calling the output?
If you have a look at
str(coxmodel)
(assuming coxmodel holds the object)

then you'll see that there's a concordance member.

You can use
coxmodel$concordance
to get it.


Cheers

__
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] KS and AD test for Generalized PAreto and Generalized Extreme value

2012-01-04 Thread Vincy Pyne
Dear R helpers,

I need to use KS and AD test for Generalized Pareto and Generalized extreme 
value.

E.g. if I need to use KS for Weibull, I have teh syntax

ks.test(x.wei,pweibull, shape=2,scale=1)

Similarly, for AD I use

ad.test(x, distr.fun, ...)

My problem is fir given data, I have estimated the parameters of GPD and GEV 
using lmom. But I am not able to find out the distribution name I should be use 
for these distributions if I wish to use these tests. 

E.g, for gamma, I can use pgamma etc. What distribution name I should use for 
GPD and GEV and for that matter where can I find the distribution names I can 
use for KS and AD test.

Thanks in advance

Regards

Vincy

[[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] An R interface to Model Building

2012-01-04 Thread Yvonnick Noel

Brett, Spencer,

I replied to Brett on the R-SIG-GUI mailing list, suggesting to use the 
proto package. I found it most useful to structure the code when 
developing my R2STATS interface.



2.  Have you reviewed the other R projects with a graphical user
interface for R?  Several are listed at http://sciviews.org/_rgui
http://sciviews.org/_rgui/.



Is this page still maintained? I wrote to Philippe Grosjean months ago 
but received no reply.

3.  If you would like to collaborate on a project with others,
r-forge.r-project.org is a standard place for hosting collaborative
projects relating to R.  I looked for a few of the projects listed at
http://sciviews.org/_rgui  http://sciviews.org/_rgui/ and couldn't
find any on R-Forge.


The R2STATS and the AtelieR packages are on R-Forge and provide GUIs for 
fitting and comparing various models (GLM and GLMM), both in a 
frequentist and a Bayesian approach.


Best,

Yvonnick Noel
University of Brittany at Rennes
Department of Psychology
France

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


[R] A problem of meta analysis based on metafor package

2012-01-04 Thread XUT
I would like to make a meta analysis based on metafor package. If I only have
the data of RR, 95%CI of every study, could I finish the meta analysis? If
possible, how to do it?  Millions of thanks!

--
View this message in context: 
http://r.789695.n4.nabble.com/A-problem-of-meta-analysis-based-on-metafor-package-tp4260896p4260896.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] Linear regression using matrices

2012-01-04 Thread Mark Sanderson
I'm new to R and I'm not a Statistician I'm an Accountant, but I'm finding it
an excellent tool for the business analysis work I do.

I need to run LM() where both response and predictor are held in matrices.
The model follows the form:-
regression1 = matrix1.col1 - matrix2.col1
regression2 = matrix1.col2-matrix2.col2
and so on..

I have no problem with the multivariate response but I can't get the
function to recognise a tabular predictor.

Is this possible without using a loop ?

--
View this message in context: 
http://r.789695.n4.nabble.com/Linear-regression-using-matrices-tp4260945p4260945.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] problem in R

2012-01-04 Thread iliketurtles
data-matrix(rnorm(10))
data[c(1,4,6)]-NA
print(data)
data-matrix(data[!is.na(data)])
print(data)

-


Isaac
Research Assistant
Quantitative Finance Faculty, UTS
--
View this message in context: 
http://r.789695.n4.nabble.com/problem-in-R-tp4260254p4260976.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] Error formal argument softmax matched by multiple actual arguments

2012-01-04 Thread Yashwanth M.R
I am running the nnet package as 



 neural.soft-nnet(custcat~region+ed+marital+tenure+age+address+income,size=3,softmax=TRUE)
  


This returns the error message : formal argument softmax matched by
multiple actual arguments 


Here the dependent variable custcat is a factor with 4-levels. This error
does not crop up for any other arguments of nnet(), including entropy=TRUE,
linout=TRUE and censored=TRUE 


This post : 
http://userprimary.net/posts/2010/03/16/reentrant-bugs-without-concurrency/
http://userprimary.net/posts/2010/03/16/reentrant-bugs-without-concurrency/  


identifies the error message formal argument   matched by multiple
actual arguments as a bug arising out of the R-internals function matchArgs 

Is there a work-around to this problem? I am using R version 2.12.2
(2011-02-25) 


Regards, Yashwanth

--
View this message in context: 
http://r.789695.n4.nabble.com/Error-formal-argument-softmax-matched-by-multiple-actual-arguments-tp4260949p4260949.html
Sent from the R help mailing list archive at Nabble.com.
[[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] Linear regression using matrices

2012-01-04 Thread iliketurtles
I've done a lot of research on this very topic and found a few solutions. But
all the ways I've discovered involve loops.

Applying it to what you want, the best way I've found is to do (stolen from
an experienced R user, of course):

y-array(rnorm(100),dim=c(10,10))
x-array(rnorm(100),dim=c(10,10))

regg-list()
for(i in 1:ncol(y))
 {
 regg[[i]]-lm(y[,i]~x[,i])
 }

Now the reason I've stuck onto the list() method is because the output is
still in lm() format. So you can write neat functions to extract every
statistic you want off summary(regg[[N]]). 

-


Isaac
Research Assistant
Quantitative Finance Faculty, UTS
--
View this message in context: 
http://r.789695.n4.nabble.com/Linear-regression-using-matrices-tp4260945p4260988.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] RODBC installation: error message

2012-01-04 Thread Duncan Murdoch

On 12-01-03 2:39 PM, gregory benison wrote:

If one attempts to install RODBC (via install.packages('RODBC'))
without having an ODBC driver installed, this error message results:

checking sqlext.h presence... no
checking for sqlext.h... no
configure: error: ODBC headers sql.h and sqlext.h not found
ERROR: configuration failed for package 'RODBC'
* removing '/usr/lib/R/library/RODBC'

Yes, the RODBC README describes the needed prerequisites, but for
someone who just wants to use RODBC and tries to install it in the
most natural way, i.e. from R Installation and Administration:


For most users it suffices to call ‘install.packages(pkgname)’


the result is the above error message, which could be more informative.


RODBC is not my package, but I can say from experience that it's hard to 
put together error messages that satisfy everyone.  Here, the problem is 
that configuration couldn't find the files sql.h and sqlext.h, and 
that's what the error says.  Not installing ODBC is one reason that 
might happen; another is installing it improperly, and there are 
probably others, too.  I think it's best if the error messages describe 
the problems; trying to diagnose the solution is something that needs 
human intervention.


One thing R could do better is to provide a standard way to view README 
and similar files before installing a package.  That might have helped here.


Duncan Murdoch



Greg Benison

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


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


Re: [R] R 2.14.0 Design library

2012-01-04 Thread Frank Harrell
See http://biostat.mc.vanderbilt.edu/Rrms for a list of changes that the user
needs to deal with, especially with respect to plotting predicted values.

Frank


Bonnett, Laura wrote
 
 Thank you!
 
 -Original Message-
 From: Milan Bouchet-Valat [mailto:nalimilan@] 
 Sent: 04 January 2012 09:23
 To: Bonnett, Laura
 Cc: 'r-help@'
 Subject: Re: [R] R 2.14.0 Design library
 
 Le mercredi 04 janvier 2012 à 09:04 +, Bonnett, Laura a écrit :
 Dear all,
 
 I have recently upgraded to R 2.14.0 with Windows 7.  I wish to use
 the command 'cph' but the Design library is no longer on the list of
 installable packages.  How can I install Design so that I may use the
 'cph' function?
 Design has been replaced with rms for some time, with (AFAIK) the
 same functions.
 
 http://cran.r-project.org/web/packages/rms/index.html
 
 
 Cheers
 __
 R-help@ mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/R-2-14-0-Design-library-tp4260537p4261125.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] Using a mathematical expression in sapply() XXXX

2012-01-04 Thread Dan Abner
Hello everyone,

I have the following call to sapply() and error message. Is the most
efficient way to deal with this to make sum(!is.na(x)) a function in a
separate line prior to this call? If not, please advise.

N.Valid=sapply(x,sum(!is.na(x)))
Error in match.fun(FUN) :
  'sum(!is.na(x))' is not a function, character or symbol


Thanks!

Dan

[[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] Using a mathematical expression in sapply() XXXX

2012-01-04 Thread Milan Bouchet-Valat
Le mercredi 04 janvier 2012 à 08:41 -0500, Dan Abner a écrit :
 Hello everyone,
 
 I have the following call to sapply() and error message. Is the most
 efficient way to deal with this to make sum(!is.na(x)) a function in a
 separate line prior to this call? If not, please advise.
 
 N.Valid=sapply(x,sum(!is.na(x)))
 Error in match.fun(FUN) :
   'sum(!is.na(x))' is not a function, character or symbol
You can use this:
sapply(x, function(x) sum(!is.na(x)))

But, if you can convert x to a matrix, it would be faster and shorter to
check for NAs beforehand, and use apply():
x - matrix(c(1, 2, NA, 3, NA, 4), 2)
apply(!is.na(x), 2, sum)


Regards

__
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] simulating stable VAR process

2012-01-04 Thread statquant2
Hello all,
I looking at package dse or vars or mAr
I know how to simulate a VAR(p) process, my problem is that most of those
processes are unstable (not weakly stationary).
Do anybody know how to generate a random VAR (or VARMA even better) process
that is weakly stationary?

Thanks

--
View this message in context: 
http://r.789695.n4.nabble.com/simulating-stable-VAR-process-tp4261177p4261177.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] simulating stable VAR process

2012-01-04 Thread statquant2
More specifically.
I know that a condition for a VAR(p) process to be stable (weakly
stationary)  is that the companion form of the equation (see AWESOME Pfaff
book analysis of integrated and cointegrated time series in R) as
eigenvalues of modulus 1.

My problem is that I want to generate such processes...

When I try to generate random VAR(p) processes they seems to explode
(clearly they are not weakly stationary...)
Is there a way somebody know?

--
View this message in context: 
http://r.789695.n4.nabble.com/simulating-stable-VAR-process-tp4261177p4261210.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] Using a mathematical expression in sapply() XXXX

2012-01-04 Thread R. Michael Weylandt michael.weyla...@gmail.com


On Jan 4, 2012, at 7:41 AM, Dan Abner dan.abne...@gmail.com wrote:

 Hello everyone,
 
 I have the following call to sapply() and error message. Is the most
 efficient way to deal with this to make sum(!is.na(x)) a function in a
 separate line prior to this call?

Yes or inline using an anonymous/lambda function:

sapply(XX, function(x) sum(!is.na(x)))

 If not, please advise.
 
 N.Valid=sapply(x,sum(!is.na(x)))
 Error in match.fun(FUN) :
  'sum(!is.na(x))' is not a function, character or symbol
 
 
 Thanks!
 
 Dan
 
[[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] RODBC installation: error message

2012-01-04 Thread Milan Bouchet-Valat
Le mardi 03 janvier 2012 à 11:39 -0800, gregory benison a écrit :
 If one attempts to install RODBC (via install.packages('RODBC'))
 without having an ODBC driver installed, this error message results:
 
 checking sqlext.h presence... no
 checking for sqlext.h... no
 configure: error: ODBC headers sql.h and sqlext.h not found
 ERROR: configuration failed for package 'RODBC'
 * removing '/usr/lib/R/library/RODBC'
 
 Yes, the RODBC README describes the needed prerequisites, but for
 someone who just wants to use RODBC and tries to install it in the
 most natural way, i.e. from R Installation and Administration:
 
  For most users it suffices to call ‘install.packages(pkgname)’
I guess this applies only to users installing binary packages. If you
build packages from source, the build system runs ./configure, which
returns this automated message.

Ideally, you shouldn't need to build packages from source when all you
want is use them... (Distributions could ship binary packages that R
would detect and install automatically?)


Cheers

__
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] Update method on existing reference class object

2012-01-04 Thread Peder Bacher
Hi

Being able to do object oriented programming in R is really good. I now
started using the Reference Classes and really like it.

Though, I have one problem: I cannot find a way to update a method on an
existing object.

The flexibility that scripting gives (really needed for interactive data
analysis) is lost if everything have to be recalculated all the time.

For example:
cl1 - setRefClass(cl1,
  fields=list(x=data.frame),
  methods=list(
init=function(){Read and process data},
fitModel=function(){Fit different kind of models and keep the results
in x and other fields}

)
)

tmp - cl1$new()
tmp$x - 5
tmp$fun()

[[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] Using a mathematical expression in sapply() XXXX

2012-01-04 Thread Meyners, Michael
Dan,

It depends on what you want to achieve. I suspect you just want to remove 
missing values before summing; if so, consider

sapply(x, sum, na.rm=TRUE)

instead. To make your code running, try

sapply(x, function(x) sum(!is.na(x)))

However, this would just count the number of non-missing values per subgroup, 
not the sum of the values. 

Similarly, 

sapply(x, function(x) sum(x, na.rm=TRUE))

would follow the same rationale but give the sums (with missing values 
removed), i.e. the same results as the first line of code. I'd rather choose 
the first option than this one, though.

Of course, you could also define a new function 

sum1 - function(x) sum(!is.na(x)) # or probably rather sum(x, na.rm=TRUE), 
depending on your needs

and then use 

sapply(x, sum1)

but that seems a bit overkill, I'd say...

HTH, Michael


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Dan Abner
 Sent: Wednesday, January 04, 2012 14:41
 To: r-help@r-project.org
 Subject: [R] Using a mathematical expression in sapply() 
 
 Hello everyone,
 
 I have the following call to sapply() and error message. Is the most
 efficient way to deal with this to make sum(!is.na(x)) a function in a
 separate line prior to this call? If not, please advise.
 
 N.Valid=sapply(x,sum(!is.na(x)))
 Error in match.fun(FUN) :
   'sum(!is.na(x))' is not a function, character or symbol
 
 
 Thanks!
 
 Dan
 
   [[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] Linear regression using matrices

2012-01-04 Thread Mark Sanderson
OK thanks.

In my case I think it might be possible to work around this by reshaping my
data and then using lmlist() to run separate regressions for each data
group. lmlist() is new to me but it looks like it will do the job.


--
View this message in context: 
http://r.789695.n4.nabble.com/Linear-regression-using-matrices-tp4260945p4261368.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] Getting Sphericity Tests for Within Subject Repeated Measure Anova (using car package)

2012-01-04 Thread Michael Friendly

On 1/3/2012 9:36 PM, maximilian.mueller wrote:


Here is the syntax:


options(contrasts=c(contr.sum, contr.poly))
read.csv2(test21.csv) - dat3
mod3 - lm(cbind(umsatz_t1, umsatz_t2, umsatz_t3, umsatz_t4) +
cbind(ebitda_t1, ebitda_t2, ebitda_t3, ebitda_t4)

+   ~ 1, data=dat3)

idata3 - data.frame(Umsatz=factor(1:4), EBITDA=factor(1:4))
aov3 - Anova(mod3, idata=idata3, idesign= ~Umsatz+EBITDA, type=III)

Fehler in check.imatrix(X.design) :
  Terms in the intra-subject model matrix are not orthogonal.

summary(aov3, multivariate=F)


That's because you've defined two identical factor variables.

idata3- data.frame(Umsatz=factor(1:4), EBITDA=factor(1:4))


 idata3 - data.frame(Umsatz=factor(1:4), EBITDA=factor(1:4))
 idata3
  Umsatz EBITDA
1  1  1
2  2  2
3  3  3
4  4  4


If your data is a doubly-multivariate design with two repeated variables
Umsatz and EBIDTA crossed with 4 time points each, you might want to look
at the vignette HE Plots for Repeated Measures Designs in the heplots 
package for theory and examples


vignette(repeated, package=heplots)

--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University  Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele StreetWeb:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

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


Re: [R] Using a mathematical expression in sapply() XXXX

2012-01-04 Thread peter dalgaard

On Jan 4, 2012, at 14:57 , Milan Bouchet-Valat wrote:

 Le mercredi 04 janvier 2012 à 08:41 -0500, Dan Abner a écrit :
 Hello everyone,
 
 I have the following call to sapply() and error message. Is the most
 efficient way to deal with this to make sum(!is.na(x)) a function in a
 separate line prior to this call? If not, please advise.
 
 N.Valid=sapply(x,sum(!is.na(x)))
 Error in match.fun(FUN) :
  'sum(!is.na(x))' is not a function, character or symbol
 You can use this:
 sapply(x, function(x) sum(!is.na(x)))
 
 But, if you can convert x to a matrix, it would be faster and shorter to
 check for NAs beforehand, and use apply():
 x - matrix(c(1, 2, NA, 3, NA, 4), 2)
 apply(!is.na(x), 2, sum)

Just for completeness: You might also do

sapply(lapply(x, is.na), sum)

I suspect that the anonymous function approach is more efficient, though (if 
you really need those extra milliseconds of your life).

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

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [R] KS and AD test for Generalized PAreto and Generalized Extreme value

2012-01-04 Thread David Winsemius


On Jan 4, 2012, at 5:49 AM, Vincy Pyne wrote:


Dear R helpers,

I need to use KS and AD test for Generalized Pareto and Generalized  
extreme value.


When I searched on these names Generalized Pareto  and Generalized  
extreme value I got plenty of hits (over 90 in one case and over 100  
in another)


You should learn to search with either sos::findFn or with RSiteSearch,

--
David.


E.g. if I need to use KS for Weibull, I have teh syntax

ks.test(x.wei,pweibull, shape=2,scale=1)

Similarly, for AD I use

ad.test(x, distr.fun, ...)

My problem is fir given data, I have estimated the parameters of GPD  
and GEV using lmom. But I am not able to find out the distribution  
name I should be use for these distributions if I wish to use these  
tests.


E.g, for gamma, I can use pgamma etc. What distribution name I  
should use for GPD and GEV and for that matter where can I find the  
distribution names I can use for KS and AD test.


Thanks in advance

Regards

Vincy

[[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
West Hartford, CT

__
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] RODBC installation: error message

2012-01-04 Thread Marc Schwartz
On Jan 4, 2012, at 8:02 AM, Milan Bouchet-Valat wrote:

 Le mardi 03 janvier 2012 à 11:39 -0800, gregory benison a écrit :
 If one attempts to install RODBC (via install.packages('RODBC'))
 without having an ODBC driver installed, this error message results:
 
 checking sqlext.h presence... no
 checking for sqlext.h... no
 configure: error: ODBC headers sql.h and sqlext.h not found
 ERROR: configuration failed for package 'RODBC'
 * removing '/usr/lib/R/library/RODBC'
 
 Yes, the RODBC README describes the needed prerequisites, but for
 someone who just wants to use RODBC and tries to install it in the
 most natural way, i.e. from R Installation and Administration:
 
 For most users it suffices to call ‘install.packages(pkgname)’
 I guess this applies only to users installing binary packages. If you
 build packages from source, the build system runs ./configure, which
 returns this automated message.
 
 Ideally, you shouldn't need to build packages from source when all you
 want is use them... (Distributions could ship binary packages that R
 would detect and install automatically?)

That is up to the resources available for each Linux distribution. Debian based 
distributions have done a better job of this for R than most, largely due to 
Dirk et al making the commitment and taking the time over the years to support 
a large number of CRAN packages via apt. 

However, there is not the same level of commitment for others (eg. Fedora, 
RHEL/CentOS, etc.), leaving most others to install from source, thus requiring 
users to manually satisfy pre-requisites for installation. R itself is 
available for installation via binary, but the selection of CRAN packages is 
much more limited.

As Duncan noted, the message is pretty clear in that the ODBC header files are 
missing, which are required to compile RODBC from source. On RH based Linuxen, 
this requires the installation of the unixODBC-devel RPM, much as one would 
need to have other *-devel RPMs (eg. readline-devel) installed for compiling 
many applications from source. 

In years past, the *-devel RPMs were frequently installed by default, but as 
the Linux community has evolved, current defaults tend to not install 
'development' related packages, which include compilers and related tools. This 
allows for smaller footprints for the installed OS for non-technical end users.

If you are going to use R on Linux, you need to be prepared to get your hands 
dirty under the hood at a lower level than if you are using Windows or OSX. 

In this particular case, Prof. Ripley has taken great pains to provide 
documents to guide the user on the installation of not only RODBC itself, but 
other components of the ODBC ecosystem to get things working.

Regards,

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.


[R] Warning message about closing a connection XXXX

2012-01-04 Thread Dan Abner
Hello everyone,

After running the following code, I obtain this error message.


 mydata - read.table(textConnection(mystring),
+header=TRUE, sep=,,
+row.names=id, na.strings= )
 mydata
Warning message:
closing unused connection 3 (mystring)

=

However, when I attempt to run read.table() again and immediately submit
the close() function (below), I obtain this message:

 close(mystring)
Error in UseMethod(close) :
  no applicable method for 'close' applied to an object of class character
 =

How can I avoid the warning message altogether?

Thank you,

Dan

[[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] Warning message about closing a connection XXXX

2012-01-04 Thread David Winsemius


On Jan 4, 2012, at 9:53 AM, Dan Abner wrote:


Hello everyone,

After running the following code, I obtain this error message.



mydata - read.table(textConnection(mystring),

+header=TRUE, sep=,,
+row.names=id, na.strings= )

mydata

Warning message:
closing unused connection 3 (mystring)

=

However, when I attempt to run read.table() again and immediately  
submit

the close() function (below), I obtain this message:


close(mystring)

Error in UseMethod(close) :
 no applicable method for 'close' applied to an object of class  
character

=

How can I avoid the warning message altogether?


?closeAllConnections

The error message occurs because mystring was never the connection  
name.


--

David Winsemius, MD
West Hartford, CT

__
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 Sphericity Tests for Within Subject Repeated Measure Anova (using car package)

2012-01-04 Thread John Fox
Dear Max,

I'm having a little trouble following what you did and am also confused by the 
subject of your posting. Is this a response to another message? Is it really 
about getting sphericity tests?

In addition:

(1) Why are you adding together the response matrices cbind(umsatz_t1, 
umsatz_t2, umsatz_t3, umsatz_t4) and cbind(ebitda_t1, ebitda_t2, ebitda_t3, 
ebitda_t4)?

(2) From the names of the responses, I imagine that you have two, crossed, 
repeated-measures factors: umsatz vs. ebita, and times 1 through 4. If that's 
correct, then the intra-subject data should look like

  idata3 - data.frame(
condition=rep(c(umsatz, ebita), each=5), 
time=ordered(rep(1:5, 2)))

and the intra-subject design should be ~condition*time.

Best,
 John


John Fox
Senator William McMaster
  Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox




 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of maximilian.mueller
 Sent: January-03-12 9:36 PM
 To: r-help@r-project.org
 Subject: Re: [R] Getting Sphericity Tests for Within Subject Repeated
 Measure Anova (using car package)
 
 Hello everyone,
 
 I am also trying to do within subjects repeated measures anova
 followed by the test of sphericity (see sample dataset attached below)
 and I am facing some problems.
 
 I tried to assign the example to my research question, but could not
 really solve it.
 
 Here is the syntax:
 
  options(contrasts=c(contr.sum, contr.poly))
  read.csv2(test21.csv) - dat3
  mod3 - lm(cbind(umsatz_t1, umsatz_t2, umsatz_t3, umsatz_t4) +
  cbind(ebitda_t1, ebitda_t2, ebitda_t3, ebitda_t4)
 + ~ 1, data=dat3)
  idata3 - data.frame(Umsatz=factor(1:4), EBITDA=factor(1:4))
  aov3 - Anova(mod3, idata=idata3, idesign= ~Umsatz+EBITDA,
 type=III)
 Fehler in check.imatrix(X.design) :
   Terms in the intra-subject model matrix are not orthogonal.
  summary(aov3, multivariate=F)
 
 with the data set  dat3
 
  dat3
 umsatz_t1  umsatz_t2  umsatz_t3  umsatz_t4  ebitda_t1  ebitda_t2
 ebitda_t3
 1  0.10239021 0.18241379 0.28875806 0.28875806 0.07622154 0.05543311
 0.06776469
 2  0.10239021 1.21769038 0.05840222 0.05840222 0.04794192 0.04642960
 0.03727069
 3  0.05124775 0.65373713 0.25976771 0.25976771 0.04794192 0.04435191
 0.03167950
 4  0.10239021 0.18241379 0.28875806 0.28875806 0.07622154 0.05543311
 0.06776469
 5  0.10239021 1.21769038 0.05840222 1.21769038 0.04794192 0.04642960
 0.03727069
 6  0.06776469 0.28875806 0.06776469 0.65373713 0.07622154 0.18241379
 0.10239021
 7  0.03727069 0.05840222 0.03727069 0.18241379 0.04794192 0.25976771
 0.04794192
 8  0.03727069 0.25976771 0.06776469 1.21769038 0.04557920 0.65373713
 0.07622154
 9  0.06776469 0.28875806 0.06776469 0.28875806 0.07622154 0.18241379
 0.04794192
 10 0.03727069 0.05840222 0.03727069 0.05840222 0.04794192 0.04642960
 0.04557920
 11 0.25976771 0.05543311 0.03727069 0.05543311 0.07622154 0.06776469
 0.03167950
 12 0.28875806 0.04642960 0.07622154 0.04642960 0.04794192 0.03727069
 0.06776469
 13 0.05840222 0.18241379 0.04794192 0.25976771 0.07622154 0.03167950
 0.03727069
 14 0.06776469 1.21769038 0.07622154 0.28875806 0.04794192 0.06776469
 0.04642960
 15 0.03727069 0.28875806 0.03727069 0.03727069 0.06776469 0.03727069
 0.04435191
 16 0.04794192 0.04642960 0.04557920 0.04557920 0.06776469 0.28875806
 0.06776469
 17 0.07622154 0.06776469 0.03167950 0.07622154 0.03727069 0.05840222
 0.03727069
 18 0.04794192 0.04642960 0.03727069 0.04435191 0.07622154 0.03167950
 0.03727069
 19 0.04794192 0.04435191 0.03167950 0.05543311 0.04794192 0.06776469
 0.04642960
 ebitda_t4
 1  0.04642960
 2  0.04435191
 3  0.05543311
 4  0.04642960
 5  0.18241379
 6  0.25976771
 7  0.04794192
 8  0.07622154
 9  0.04794192
 10 0.04557920
 11 0.07622154
 12 0.04794192
 13 0.04557920
 14 0.03167950
 15 0.03167950
 16 0.65373713
 17 0.18241379
 18 0.04557920
 19 0.03167950
 
 
 Thanks four your help...
 
 Sincerely,
 Max
 
 
 
 -
 M a x i m i l i a n  M ue l l e r
 
 PhD-Student
 Department of Business Studies
 Leuphana Universität Lüneburg
 
 --
 View this message in context: http://r.789695.n4.nabble.com/Getting-
 Sphericity-Tests-for-Within-Subject-Repeated-Measure-Anova-using-car-
 package-tp841030p4259642.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


[R] Is there a way to update a method on an existing Reference Class object?

2012-01-04 Thread Peder Bacher
Hi

Being able to do object oriented programming in R is really good. I
now started using the Reference Classes and really like it.

Though, I have one problem: I cannot find a way to update a method on
an existing object.

The flexibility that scripting gives (really needed for interactive
data analysis) is lost if everything have to be recalculated all the
time.

For example I would normally work something like this:

cl1 - setRefClass(cl1,
  fields=list(x=data.frame),
  methods=list(
    init=function(){Read and process data},
    fitModel=function(){Fit different kind of models and keep the
results in x and other fields},
    plotFit1=function(){Plot the fit one way},
    plotFit2=function(){Plot the fit in another way way})
)

I would then initialize it and run the functions on it:
cl1Object - cl1$new()
...

The problem then comes if I need to change something in one of the
methods, because I then have to run all the initialization and fitting
again, since the change is done to cl1 and not cl1Object, of
course.

The reference class documentation states that it is not possible since
this would give problems with inheritance etc. Is there a workaround
to this?

The very best
Peder

__
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] [Matlab] Need help on ARIMA and Matlab

2012-01-04 Thread Antonio Tirri
Hi, I have to forecast some value of a time series using an ARIMA(5,1,3)
model.

I saw in Matlab there isn't a function for ARIMA models because ARIMA
models are a type of Box-Jenkins models. But how to set parameters?

In the Box-Jenkins models

 m = bj(data,[nb nc nd nf nk])

How to set nb, nc, nd, nf and nk in order to have an ARIMA(p,d,q) model?

Thanks

[[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] subscript with comma

2012-01-04 Thread suse
Hi,

I want to write a word with subscript in a graph. Unfortunately, the
subscript contains a comma, so all my trials didn't work and I didn't find
how to do it.
I want to write sm as normal text and w,grass in the subscript. Can
anybody help me?

And a more general question: I read the help to plotmath, but I still
didn't understand, how it works. Is there a good documentation, book,...
which explains all this stuff?

Thanks in advance!


--
View this message in context: 
http://r.789695.n4.nabble.com/subscript-with-comma-tp4261579p4261579.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] Adding a vertical line to plot with two overlapping density plots

2012-01-04 Thread josh rosen
Hi,
A simple question I hope. I wish to add a single vertical line to a plot
with several density plots.
Here is a simplified example.


thedata - data.frame(x1=rnorm(100,1,1),x2=rnorm(100,3,1)) #create data
thedata.m-melt(thedata)
densityplot(~value, thedata.m, groups=variable,auto.key=list(columns=2))
#this gives the two density plots
#

what I wish now is to add a vertical line, for example v=2.

Many thanks,
Josh.

[[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] [Matlab] Need help on ARIMA and Matlab

2012-01-04 Thread R. Michael Weylandt
Perhaps you are confusedthis is R-help

that said, it's very easy with

forecast:::forecast.Arima

in R

Michael

On Wed, Jan 4, 2012 at 8:38 AM, Antonio Tirri antonio.ti...@gmail.com wrote:
 Hi, I have to forecast some value of a time series using an ARIMA(5,1,3)
 model.

 I saw in Matlab there isn't a function for ARIMA models because ARIMA
 models are a type of Box-Jenkins models. But how to set parameters?

 In the Box-Jenkins models

  m = bj(data,[nb nc nd nf nk])

 How to set nb, nc, nd, nf and nk in order to have an ARIMA(p,d,q) model?

 Thanks

        [[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] Using a mathematical expression in sapply() XXXX

2012-01-04 Thread David Winsemius


On Jan 4, 2012, at 9:17 AM, peter dalgaard wrote:



On Jan 4, 2012, at 14:57 , Milan Bouchet-Valat wrote:


Le mercredi 04 janvier 2012 à 08:41 -0500, Dan Abner a écrit :

Hello everyone,

I have the following call to sapply() and error message. Is the most
efficient way to deal with this to make sum(!is.na(x)) a function  
in a

separate line prior to this call? If not, please advise.

N.Valid=sapply(x,sum(!is.na(x)))
Error in match.fun(FUN) :
'sum(!is.na(x))' is not a function, character or symbol

You can use this:
sapply(x, function(x) sum(!is.na(x)))

But, if you can convert x to a matrix, it would be faster and  
shorter to

check for NAs beforehand, and use apply():
x - matrix(c(1, 2, NA, 3, NA, 4), 2)
apply(!is.na(x), 2, sum)


Just for completeness: You might also do

sapply(lapply(x, is.na), sum)


I thought from context that the sum of negation of is.na was what was  
desired, since the negation operator was used and the name of the  
results was N.Valid. So consider substituting the existing function,  
complete.cases in place of is.na:


sapply(lapply(x, complete.cases), sum)

Or use the existing function na.omit with length:

sapply(lapply(x, na.omit), length)



I suspect that the anonymous function approach is more efficient,  
though (if you really need those extra milliseconds of your life).





--

David Winsemius, MD
West Hartford, CT

__
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] quadratic programming-maximization instead of

2012-01-04 Thread Ravi Varadhan
Maximizing f(x) = x'Ax  makes sense only when A is negative-definite.  
Therefore, this is the same as minimizing x'Bx, where B = -A, and B is 
positive-definite.

In other words, you should be able to simply flip the sign of the original 
matrix .  This should yield a positive-definite matrix since the original 
matrix ought to be negative-definite.

Ravi

---
Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins 
University

Ph. (410) 502-2619
email: rvarad...@jhmi.edumailto:rvarad...@jhmi.edu


[[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] subscript with comma

2012-01-04 Thread Uwe Ligges



On 04.01.2012 16:12, suse wrote:

Hi,

I want to write a word with subscript in a graph. Unfortunately, the
subscript contains a comma, so all my trials didn't work and I didn't find
how to do it.
I want to write sm as normal text and w,grass in the subscript. Can
anybody help me?

And a more general question: I read the help to plotmath, but I still
didn't understand, how it works. Is there a good documentation, book,...
which explains all this stuff?


?plotmath suggests to use a comma separated list as in:

plot(1, main=expression(sm[list(w,grass)]))

Uwe Ligges






Thanks in advance!


--
View this message in context: 
http://r.789695.n4.nabble.com/subscript-with-comma-tp4261579p4261579.html
Sent from the R help mailing list archive at Nabble.com.

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


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


[R] Merging and subsetting with row names XXXX

2012-01-04 Thread Dan Abner
Hello everyone,

I have two questions:

1)

I want to create a subset of a data frame column-wise and simultaneously
extract the row names into a proper variable. I tried this, but received
an error:

 myleft-mydata[c(id=row.names(mydata),workshop,gender,q1,q2)]
Error in `[.data.frame`(mydata, c(id = row.names(mydata), workshop,  :
  undefined columns selected
Is the following the best way to go about this:


myleft-data.frame(id=row.names(mydata),mydata)[c(id,workshop,gender,q1,q2)]
 myleft

2)

Is it possible to merge data using merge() with a by variable that is the
row names? I tried this:

 both-merge(myleft,myright,by=row.names(myleft))
Error in fix.by(by.x, x) : 'by' must specify valid column(s)
 both
Suggestions?


Thanks!

Dan

[[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] Adding a vertical line to plot with two overlapping density plots

2012-01-04 Thread Petr PIKAL
Hi

 
 Hi,
 A simple question I hope. I wish to add a single vertical line to a plot
 with several density plots.
 Here is a simplified example.
 
 
 thedata - data.frame(x1=rnorm(100,1,1),x2=rnorm(100,3,1)) #create data
 thedata.m-melt(thedata)
 densityplot(~value, thedata.m, groups=variable,auto.key=list(columns=2))
 #this gives the two density plots
 #
 
 what I wish now is to add a vertical line, for example v=2.

If you mean densityplot from lattice here is a function (addapted from 
Gabor Grothendieck's code] which adds arbitrary line(s) into panels. Is 
options are similar to abline and once=TRUE means you want different lines 
to different panels.

 addLine
function (a = NULL, b = NULL, v = NULL, h = NULL, ..., once = FALSE) 
{
tcL - trellis.currentLayout()
k - 0
for (i in 1:nrow(tcL)) for (j in 1:ncol(tcL)) if (tcL[i, 
j]  0) {
k - k + 1
trellis.focus(panel, j, i, highlight = FALSE)
if (once) 
panel.abline(a = a[k], b = b[k], v = v[k], h = h[k], 
...)
else panel.abline(a = a, b = b, v = v, h = h, ...)
trellis.unfocus()
}
}

Regards
Petr



 
 Many thanks,
 Josh.
 
[[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] Merging and subsetting with row names XXXX

2012-01-04 Thread Petr PIKAL
Hi

As you did not provide any data you probably can not get canned solution

 Hello everyone,
 
 I have two questions:
 
 1)
 
 I want to create a subset of a data frame column-wise and simultaneously
 extract the row names into a proper variable. I tried this, but 
received
 an error:
 
  myleft-mydata[c(id=row.names(mydata),workshop,gender,q1,q2)]
 Error in `[.data.frame`(mydata, c(id = row.names(mydata), workshop,  :
   undefined columns selected
 Is the following the best way to go about this:
 
 
 myleft-data.frame(id=row.names(mydata),mydata)[c
 (id,workshop,gender,q1,q2)]
  myleft

If I understand correctly you want only some columns, all rows and make 
also new column identical with row names.

either
cbind(id=row.names(mydata),mydata[, c(2,4,5,6)])

or
data.frame(id=row.names(mydata),mydata[, c(2,4,5,6)])
 
can do it.

 
 2)
 
 Is it possible to merge data using merge() with a by variable that is 
the

AFAI no.

 row names? I tried this:
 
  both-merge(myleft,myright,by=row.names(myleft))
 Error in fix.by(by.x, x) : 'by' must specify valid column(s)
  both
 Suggestions?

Regards
Petr


 
 
 Thanks!
 
 Dan
 
[[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] function in R for my exercise

2012-01-04 Thread Thomthom
Hi R helpers!

I have a question. I'm trying to create a function for an exercise. Here are
the arguments I should include:

x and y are numeric
z is a name (plus,minus,multiply,divide)
and swap is logical.

Here is what the function should do:

When z=plus, then x+y is performed and so on for the other z names. It
should give a NA when the z argument doesn't correspond to something mention
before.
When swap =TRUE, then y must be on the left side of the equation (y/x
instead of x/y).

So far, I managed to get something worked for the first part of the body
function (typing plus performes indeed an addition...) but I couldn't get
how to make the second part working. Any suggestion?

Here is the code I have so far:

myFunc- function(x,y,z,swap)
{ res= NULL
  if(z ==plus) res=x+y
   else if(z==minus) res=x-y
   else if(z== multiply) res=x*y
   else if(z==divide) res=x/y
   else res-NA
  
  return(res)}

Then, I tried to include some lines to take this swap function into
account by splitting somehow my function in 2:

myFunc- function(x,y,z,swap)
{ res1= NULL
  res2=NULL

  if(z ==plus) res1=x+y
   else if(z==minus) res1=x-y
   else if(z== multiply) res1=x*y
   else if(z==divide) res1=x/y
   else res1-NA

  if(z ==plus) res2=y+x
   else if(z==minus) res2=y-x
   else if(z== multiply) res2=y*x
   else if(z==divide) res2=y/x
   else res2-NA

  if (swap-T) return(res2)
  else return(res1)
   }
Any suggestions would be more than appreciated! I already thank you!

And happy new year! (that may be redundant to most of you I know ^^)

Thomas

--
View this message in context: 
http://r.789695.n4.nabble.com/function-in-R-for-my-exercise-tp4261710p4261710.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] Adding a vertical line to plot with two overlapping density plots

2012-01-04 Thread josh rosen
thank you very much Petr. Yes, I meant densityplot form lattice.

The code I gave plots the densities of both x1 and x2 in one panel.
Could you show me how to integrate the function addline into the code so
that a vertical line v=0 is added?



On 4 January 2012 15:55, Petr PIKAL petr.pi...@precheza.cz wrote:

 Hi

 
  Hi,
  A simple question I hope. I wish to add a single vertical line to a plot
  with several density plots.
  Here is a simplified example.
 
  
  thedata - data.frame(x1=rnorm(100,1,1),x2=rnorm(100,3,1)) #create data
  thedata.m-melt(thedata)
  densityplot(~value, thedata.m, groups=variable,auto.key=list(columns=2))
  #this gives the two density plots
  #
 
  what I wish now is to add a vertical line, for example v=2.

 If you mean densityplot from lattice here is a function (addapted from
 Gabor Grothendieck's code] which adds arbitrary line(s) into panels. Is
 options are similar to abline and once=TRUE means you want different lines
 to different panels.

  addLine
 function (a = NULL, b = NULL, v = NULL, h = NULL, ..., once = FALSE)
 {
tcL - trellis.currentLayout()
k - 0
for (i in 1:nrow(tcL)) for (j in 1:ncol(tcL)) if (tcL[i,
j]  0) {
k - k + 1
trellis.focus(panel, j, i, highlight = FALSE)
if (once)
panel.abline(a = a[k], b = b[k], v = v[k], h = h[k],
...)
else panel.abline(a = a, b = b, v = v, h = h, ...)
trellis.unfocus()
}
 }

 Regards
 Petr



 
  Many thanks,
  Josh.
 
 [[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] problem in R

2012-01-04 Thread R. Michael Weylandt
I'm not a huge fan of this sort of solution because it doesn't make
sense for non-vector-shaped (i.e., matrix or data.frame) data. It only
works here because the matrix produced is a special 1xN case.

E.g.,

# Set up some data (and yes, I realize I'm using the trick I'm
speaking out against, but c'est la vie)
testData - matrix(rnorm(20), 5)
testData[c(3,6,7)] - NA

testData[!is.na(testData)] # No longer a matrix so any information
stored in the shape is lost

# I'd prefer something like
testData[complete.cases(testData), ]

or perhaps these sorts of helper functions:

completeRows - function(x){
x[rowSums(is.na(x)) == 0L, ]
}

completeCols - function(x){
x[, colSums(is.na(x)) == 0L]
}

both of which I believe will work for matrices  data.frames. With a
little work, one could make them work for regular vectors as well to
have a general solution.

In general, however, you'll need to figure out what the correct
treatment of NA's for your problem is: some functions like lm(), sum()
etc. can deal with NAs so you don't need to pre-change your input.
(Protip: with lm(), I find people almost always prefer na.exclude to
the default na.omit)

Michael

On Wed, Jan 4, 2012 at 6:01 AM, iliketurtles isaacm...@gmail.com wrote:
 data-matrix(rnorm(10))
 data[c(1,4,6)]-NA
 print(data)
 data-matrix(data[!is.na(data)])
 print(data)

 -
 

 Isaac
 Research Assistant
 Quantitative Finance Faculty, UTS
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/problem-in-R-tp4260254p4260976.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] Adding a vertical line to plot with two overlapping density plots

2012-01-04 Thread Petr PIKAL
 
 thank you very much Petr. Yes, I meant densityplot form lattice. 
 
 The code I gave plots the densities of both x1 and x2 in one panel. 
 Could you show me how to integrate the function addline into the code so 

 that a vertical line v=0 is added? 

The function is used after you make a plot.

addLine(v=2)

shall be OK

before you of course need to define the function

addLine - function (a = NULL, b = NULL, v = NULL, h = NULL, ..., once = 
FALSE)
 {
tcL - trellis.currentLayout()
k - 0
for (i in 1:nrow(tcL)) for (j in 1:ncol(tcL)) if (tcL[i,
j]  0) {
k - k + 1
trellis.focus(panel, j, i, highlight = FALSE)
if (once)
panel.abline(a = a[k], b = b[k], v = v[k], h = h[k],
...)
else panel.abline(a = a, b = b, v = v, h = h, ...)
trellis.unfocus()
}
 }


Regards
Petr


 
  

 On 4 January 2012 15:55, Petr PIKAL petr.pi...@precheza.cz wrote:
 Hi
 
 
  Hi,
  A simple question I hope. I wish to add a single vertical line to a 
plot
  with several density plots.
  Here is a simplified example.
 
  
  thedata - data.frame(x1=rnorm(100,1,1),x2=rnorm(100,3,1)) #create 
data
  thedata.m-melt(thedata)
  densityplot(~value, thedata.m, 
groups=variable,auto.key=list(columns=2))
  #this gives the two density plots
  #
 
  what I wish now is to add a vertical line, for example v=2.

 If you mean densityplot from lattice here is a function (addapted from
 Gabor Grothendieck's code] which adds arbitrary line(s) into panels. Is
 options are similar to abline and once=TRUE means you want different 
lines
 to different panels.
 
  addLine
 function (a = NULL, b = NULL, v = NULL, h = NULL, ..., once = FALSE)
 {
tcL - trellis.currentLayout()
k - 0
for (i in 1:nrow(tcL)) for (j in 1:ncol(tcL)) if (tcL[i,
j]  0) {
k - k + 1
trellis.focus(panel, j, i, highlight = FALSE)
if (once)
panel.abline(a = a[k], b = b[k], v = v[k], h = h[k],
...)
else panel.abline(a = a, b = b, v = v, h = h, ...)
trellis.unfocus()
}
 }
 
 Regards
 Petr
 
 
 
 
  Many thanks,
  Josh.
 
 [[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] function in R for my exercise

2012-01-04 Thread R. Michael Weylandt
Unfortunately, there's a general no-homework rule because we never
know what your instructor wants you to figure out on your own (though,
a sincere thanks for admitting this was hw rather than trying to trick
us like so many). That said, I think your second function, while a
little clumsy, does work but for one little error near the end. It's
very obvious when you see it so don't overthink it, but look closely
at the lines that involve swap.

If you want to make it more elegant, I'd suggest you look at the
?switch construct: also, to make the swap bit more elegant, think
about how one exchanges variable values in a language like C and put
some construct like that within an if statement near the top. If you
want to get real elegant, note that after you figure out switch,
constructs like `+`(3, 4) are valid in R (though certainly beyond the
scope of your exercise)

Hope this helps,

Michael

On Wed, Jan 4, 2012 at 9:45 AM, Thomthom rime.tho...@gmail.com wrote:
 Hi R helpers!

 I have a question. I'm trying to create a function for an exercise. Here are
 the arguments I should include:

 x and y are numeric
 z is a name (plus,minus,multiply,divide)
 and swap is logical.

 Here is what the function should do:

 When z=plus, then x+y is performed and so on for the other z names. It
 should give a NA when the z argument doesn't correspond to something mention
 before.
 When swap =TRUE, then y must be on the left side of the equation (y/x
 instead of x/y).

 So far, I managed to get something worked for the first part of the body
 function (typing plus performes indeed an addition...) but I couldn't get
 how to make the second part working. Any suggestion?

 Here is the code I have so far:

 myFunc- function(x,y,z,swap)
                { res= NULL
                  if(z ==plus) res=x+y
                   else if(z==minus) res=x-y
                   else if(z== multiply) res=x*y
                   else if(z==divide) res=x/y
                   else res-NA

                  return(res)}

 Then, I tried to include some lines to take this swap function into
 account by splitting somehow my function in 2:

 myFunc- function(x,y,z,swap)
                { res1= NULL
                  res2=NULL

                  if(z ==plus) res1=x+y
                   else if(z==minus) res1=x-y
                   else if(z== multiply) res1=x*y
                   else if(z==divide) res1=x/y
                   else res1-NA

                  if(z ==plus) res2=y+x
                   else if(z==minus) res2=y-x
                   else if(z== multiply) res2=y*x
                   else if(z==divide) res2=y/x
                   else res2-NA

                  if (swap-T) return(res2)
                  else return(res1)
               }
 Any suggestions would be more than appreciated! I already thank you!

 And happy new year! (that may be redundant to most of you I know ^^)

 Thomas

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/function-in-R-for-my-exercise-tp4261710p4261710.html
 Sent from the R help mailing list archive at Nabble.com.

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

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


[R] putting regression output right on a plot

2012-01-04 Thread Mark Leeds
hi: does anyone know if it's possible and, if so, where there's an example,
of putting the output of summary(lm) right on the plot of the data  itself.
If the answer is to use capture.output and then text, I'll try that but I
was thinking there might be an example somewhere ? thanks.

[[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] interaction plot and x axis

2012-01-04 Thread Lathouri, Maria
Dear all



 I am trying to make an interaction plot among 6 variables; e.g. PH to be in 
the x axis and the rest 5 variables in the y axis. The code that I am using is 
the below:



The name of my file is e.g. spec so



 spec-read.csv(spec.csv)

head (spec)

str(spec)

names-names(spec)[2:6]
speclong - reshape(spec, idvar = id, varying = list(names), 
v.names=outcome,direction = long)

speclong$time2-factor(speclong$time,labels=rep(   ,5))

interaction.plot(speclong$PH,speclong$time2,speclong$outcome, xaxt=n, 
type=l, log=y, trace.label=,col=rainbow(8))



what I want is to change the labels of the x axis. If for example I don't use 
xaxt=n, by default it shows some values of PH e.g. 4.93, 5.97, 6.23, 6.47, 
6.59, 6.77, 6.89, 7.35 but it don't show the ticks in each value. However I 
would like to define the x values e.g. 5.0, 5.5, 6.0, 6.5, 7.0. I used the xlim 
but it says error as well

axis(1, at=c(5.0, 5.5, 6.0, 6.5, 7.0)) but still there is a problem.



Does anyone know how I can define that?



Thank you in advance.



Kind regards

Maria

[[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] KS and AD test for Generalized PAreto and Generalized Extreme value

2012-01-04 Thread R. Michael Weylandt
fExtremes::pgpd  pgev have always worked for me. Though, if I
remember right, the physical sciences and finance tend to use
reciprocal definitions for one of the parameters (can't remember which
-- xi in gpd perhaps?) so tread lightly.

Michael

On Wed, Jan 4, 2012 at 8:21 AM, David Winsemius dwinsem...@comcast.net wrote:

 On Jan 4, 2012, at 5:49 AM, Vincy Pyne wrote:

 Dear R helpers,

 I need to use KS and AD test for Generalized Pareto and Generalized
 extreme value.


 When I searched on these names Generalized Pareto  and Generalized
 extreme value I got plenty of hits (over 90 in one case and over 100 in
 another)

 You should learn to search with either sos::findFn or with RSiteSearch,

 --
 David.


 E.g. if I need to use KS for Weibull, I have teh syntax

 ks.test(x.wei,pweibull, shape=2,scale=1)

 Similarly, for AD I use

 ad.test(x, distr.fun, ...)

 My problem is fir given data, I have estimated the parameters of GPD and
 GEV using lmom. But I am not able to find out the distribution name I should
 be use for these distributions if I wish to use these tests.

 E.g, for gamma, I can use pgamma etc. What distribution name I should use
 for GPD and GEV and for that matter where can I find the distribution names
 I can use for KS and AD test.

 Thanks in advance

 Regards

 Vincy

        [[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
 West Hartford, CT


 __
 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] Warning message about closing a connection XXXX

2012-01-04 Thread William Dunlap
Re
   How can I avoid the warning message altogether?
  
  ?closeAllConnections

I think of calls to closeAllConnections() in the same
way that I think of calls to rm(list=objects()):
they both can remove things that are not theirs to remove.

Calling gc() will close all unused connections, so
no damage can be done.  (I thought that the warning
about closing unused text connections was dropped in
a recent release of R so neither is really needed.)

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
 
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf Of David Winsemius
 Sent: Wednesday, January 04, 2012 7:10 AM
 To: Dan Abner
 Cc: r-help@r-project.org
 Subject: Re: [R] Warning message about closing a connection 
 
 
 On Jan 4, 2012, at 9:53 AM, Dan Abner wrote:
 
  Hello everyone,
 
  After running the following code, I obtain this error message.
 
 
  mydata - read.table(textConnection(mystring),
  +header=TRUE, sep=,,
  +row.names=id, na.strings= )
  mydata
  Warning message:
  closing unused connection 3 (mystring)
 
  =
 
  However, when I attempt to run read.table() again and immediately
  submit
  the close() function (below), I obtain this message:
 
  close(mystring)
  Error in UseMethod(close) :
   no applicable method for 'close' applied to an object of class
  character
  =
 
  How can I avoid the warning message altogether?
 
 ?closeAllConnections
 
 The error message occurs because mystring was never the connection
 name.
 
 --
 
 David Winsemius, MD
 West Hartford, CT
 
 __
 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] Finding Source of Error Message of 'Non-Unique Index Entries'

2012-01-04 Thread Rich Shepard

On Tue, 3 Jan 2012, David Winsemius wrote:


burns.tds[ !duplicated(burns.tds) ,  ]


  Apparently it does not matter if the site column in the data frame is a
factor or a character, read.zoo() generates the same error. Applying the
above produces a long list starting with:

burns.tds[!duplicated(burns.tds), ]
site   sampdatequant
599 BC-3 1992-03-270.100
600 BC-3 1992-04-300.100
601 BC-3 1992-05-300.100
603 BC-3 1992-06-190.100
1214BC-3 1992-07-200.100
1215BC-3 1992-08-100.100
1216BC-3 1992-09-300.100
1217BC-3 1992-10-290.100
1218BC-3 1992-11-190.100
1929BC-3 1995-03-238.080

  I don't know how to interpret this. I don't see two rows with the same
values, but ~ 500 rows each with a different value. What is duplicated? The
entire row? The site ID?

  ?duplicated has some examples, but those do not show the output of the
function nor explain what's duplicated.

  I need to get past this blockage and appreciate your help in determining
why read.zoo() sees duplicates when the database table has none, and how to
resolve this issue.

TIA,

Rich

__
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] Warning message about closing a connection XXXX

2012-01-04 Thread Prof Brian Ripley

On 04/01/2012 17:12, William Dunlap wrote:

Re
 How can I avoid the warning message altogether?

   ?closeAllConnections

I think of calls to closeAllConnections() in the same
way that I think of calls to rm(list=objects()):
they both can remove things that are not theirs to remove.

Calling gc() will close all unused connections, so
no damage can be done.  (I thought that the warning
about closing unused text connections was dropped in
a recent release of R so neither is really needed.)


Yes, it was.  The warning is there because the user may need to do 
something about the 'other end' of the now-closed connection, which R 
manages for textConnections.


There is however one circumstance where gc() does not close all unused 
connections, and that is when gzcon() is used (because that involves two 
connections and it is not clear when the inner one is 'in use': and we 
used to guess wrong).


Rather than using a sledgehammer, use showConnections(all=TRUE) to see 
all connections, and close the ones you want to (and its help page shows 
you how).



Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of David Winsemius
Sent: Wednesday, January 04, 2012 7:10 AM
To: Dan Abner
Cc: r-help@r-project.org
Subject: Re: [R] Warning message about closing a connection 


On Jan 4, 2012, at 9:53 AM, Dan Abner wrote:


Hello everyone,

After running the following code, I obtain this error message.



mydata- read.table(textConnection(mystring),

+header=TRUE, sep=,,
+row.names=id, na.strings= )

mydata

Warning message:
closing unused connection 3 (mystring)

=

However, when I attempt to run read.table() again and immediately
submit
the close() function (below), I obtain this message:


close(mystring)

Error in UseMethod(close) :
  no applicable method for 'close' applied to an object of class
character
=

How can I avoid the warning message altogether?


?closeAllConnections

The error message occurs because mystring was never the connection
name.

--

David Winsemius, MD
West Hartford, CT

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



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@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] subscript with comma

2012-01-04 Thread David Winsemius


On Jan 4, 2012, at 10:51 AM, Uwe Ligges wrote:




On 04.01.2012 16:12, suse wrote:

Hi,

I want to write a word with subscript in a graph. Unfortunately, the
subscript contains a comma, so all my trials didn't work and I  
didn't find

how to do it.
I want to write sm as normal text and w,grass in the subscript.  
Can

anybody help me?

And a more general question: I read the help to plotmath, but I  
still
didn't understand, how it works. Is there a good documentation,  
book,...

which explains all this stuff?


I've wondered about that, too. Murrell's text, R Graphics, doesn't  
even have plotmath in its function list or Index. The insight that  
allowed me to get a significantly higher frequency of success was   
realizing that the correct separators between separate expressions  
were * and ~ rather than space or comma. Inside an expression  
a comma will signal a new expression element. A space without a  
plotmath operator intervening just throws an error


 plot(1, main=expression(sm[w grass]))
Error: unexpected symbol in plot(1, main=expression(sm[w grass

My suggestion is to search the archive for answers from Ligges,  
Dalgaard, Lumley and Grothendeick that involve expression or  
plotmath. (Apologies to any other plotmath-meisters). I still get  
surprises such as with these:


plot(1, main=expression(sm[w|grass]))

plot(1, main=expression(sm[w%|%grass]))




?plotmath suggests to use a comma separated list as in:

plot(1, main=expression(sm[list(w,grass)]))



The other approach that succeeds it just to use a quoted comma  
connected by valid separators.


plot(1, main=expression(sm[w*,~grass]))

--

David Winsemius, MD
West Hartford, CT

__
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] Finding Source of Error Message of 'Non-Unique Index Entries'

2012-01-04 Thread David Winsemius


On Jan 4, 2012, at 12:21 PM, Rich Shepard wrote:


On Tue, 3 Jan 2012, David Winsemius wrote:


burns.tds[ !duplicated(burns.tds) ,  ]


 Apparently it does not matter if the site column in the data frame  
is a
factor or a character, read.zoo() generates the same error. Applying  
the

above produces a long list starting with:

burns.tds[!duplicated(burns.tds), ]
   site   sampdatequant
599 BC-3 1992-03-270.100
600 BC-3 1992-04-300.100
601 BC-3 1992-05-300.100
603 BC-3 1992-06-190.100
1214BC-3 1992-07-200.100
1215BC-3 1992-08-100.100
1216BC-3 1992-09-300.100
1217BC-3 1992-10-290.100
1218BC-3 1992-11-190.100
1929BC-3 1995-03-238.080

 I don't know how to interpret this. I don't see two rows with the  
same
values, but ~ 500 rows each with a different value. What is  
duplicated? The

entire row? The site ID?


You didn't ask for what was duplicated, but rather what was NOT  
duplicated with that code. In the case of a dataframe it is the entire  
row that is tested.




 ?duplicated has some examples, but those do not show the output of  
the

function nor explain what's duplicated.

 I need to get past this blockage and appreciate your help in  
determining
why read.zoo() sees duplicates when the database table has none, and  
how to

resolve this issue.


I think you need to reduce this problem to a dataframe that you either  
post an access method for or use dput() to include. Then you need to  
say what you goals are and what code is not working on that example.




TIA,

Rich

__
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
West Hartford, CT

__
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] Warning message about closing a connection XXXX

2012-01-04 Thread Duncan Murdoch

On 12-01-04 12:25 PM, Prof Brian Ripley wrote:

On 04/01/2012 17:12, William Dunlap wrote:

Re
   How can I avoid the warning message altogether?

?closeAllConnections

I think of calls to closeAllConnections() in the same
way that I think of calls to rm(list=objects()):
they both can remove things that are not theirs to remove.

Calling gc() will close all unused connections, so
no damage can be done.  (I thought that the warning
about closing unused text connections was dropped in
a recent release of R so neither is really needed.)


Yes, it was.  The warning is there because the user may need to do
something about the 'other end' of the now-closed connection, which R
manages for textConnections.

There is however one circumstance where gc() does not close all unused
connections, and that is when gzcon() is used (because that involves two
connections and it is not clear when the inner one is 'in use': and we
used to guess wrong).

Rather than using a sledgehammer, use showConnections(all=TRUE) to see
all connections, and close the ones you want to (and its help page shows
you how).


In older versions that do give the warning, wouldn't it be sufficient to 
name the textConnection, and close it explicitly?  E.g.


 mydata- read.table(con - textConnection(mystring),  header=TRUE, 
sep=,,   row.names=id, na.strings= )


 close(con)

Duncan Murdoch





Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of David Winsemius
Sent: Wednesday, January 04, 2012 7:10 AM
To: Dan Abner
Cc: r-help@r-project.org
Subject: Re: [R] Warning message about closing a connection 


On Jan 4, 2012, at 9:53 AM, Dan Abner wrote:


Hello everyone,

After running the following code, I obtain this error message.



mydata- read.table(textConnection(mystring),

+header=TRUE, sep=,,
+row.names=id, na.strings= )

mydata

Warning message:
closing unused connection 3 (mystring)

=

However, when I attempt to run read.table() again and immediately
submit
the close() function (below), I obtain this message:


close(mystring)

Error in UseMethod(close) :
   no applicable method for 'close' applied to an object of class
character
=

How can I avoid the warning message altogether?


?closeAllConnections

The error message occurs because mystring was never the connection
name.

--

David Winsemius, MD
West Hartford, CT

__
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] subscript with comma

2012-01-04 Thread Nordlund, Dan (DSHS/RDA)
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of David Winsemius
 Sent: Wednesday, January 04, 2012 9:53 AM
 To: Uwe Ligges
 Cc: r-help@r-project.org; suse
 Subject: Re: [R] subscript with comma
 
 
 On Jan 4, 2012, at 10:51 AM, Uwe Ligges wrote:
 
 
 
  On 04.01.2012 16:12, suse wrote:
  Hi,
 
  I want to write a word with subscript in a graph. Unfortunately, the
  subscript contains a comma, so all my trials didn't work and I
  didn't find
  how to do it.
  I want to write sm as normal text and w,grass in the subscript.
  Can
  anybody help me?
 
  And a more general question: I read the help to plotmath, but I
  still
  didn't understand, how it works. Is there a good documentation,
  book,...
  which explains all this stuff?
 
 I've wondered about that, too. Murrell's text, R Graphics, doesn't
 even have plotmath in its function list or Index. The insight that
 allowed me to get a significantly higher frequency of success was
 realizing that the correct separators between separate expressions
 were * and ~ rather than space or comma. Inside an expression
 a comma will signal a new expression element. A space without a
 plotmath operator intervening just throws an error
 
   plot(1, main=expression(sm[w grass]))
 Error: unexpected symbol in plot(1, main=expression(sm[w grass
 
 My suggestion is to search the archive for answers from Ligges,
 Dalgaard, Lumley and Grothendeick that involve expression or
 plotmath. (Apologies to any other plotmath-meisters). I still get
 surprises such as with these:
 
 plot(1, main=expression(sm[w|grass]))
 
 plot(1, main=expression(sm[w%|%grass]))
 
 
 
  ?plotmath suggests to use a comma separated list as in:
 
  plot(1, main=expression(sm[list(w,grass)]))
 
 
 The other approach that succeeds it just to use a quoted comma
 connected by valid separators.
 
 plot(1, main=expression(sm[w*,~grass]))
 
 --
 
 David Winsemius, MD
 West Hartford, CT
 

I haven't followed this whole thread and may have missed some requirement, but 
what about just using the text string that you want in the subscript?  E.g.

plot(1, main=expression(sm['w,grass']))


Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204


__
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] Warning message about closing a connection XXXX

2012-01-04 Thread Prof Brian Ripley

On 04/01/2012 18:21, Duncan Murdoch wrote:

On 12-01-04 12:25 PM, Prof Brian Ripley wrote:

On 04/01/2012 17:12, William Dunlap wrote:

Re
 How can I avoid the warning message altogether?

?closeAllConnections

I think of calls to closeAllConnections() in the same
way that I think of calls to rm(list=objects()):
they both can remove things that are not theirs to remove.

Calling gc() will close all unused connections, so
no damage can be done. (I thought that the warning
about closing unused text connections was dropped in
a recent release of R so neither is really needed.)


Yes, it was. The warning is there because the user may need to do
something about the 'other end' of the now-closed connection, which R
manages for textConnections.

There is however one circumstance where gc() does not close all unused
connections, and that is when gzcon() is used (because that involves two
connections and it is not clear when the inner one is 'in use': and we
used to guess wrong).

Rather than using a sledgehammer, use showConnections(all=TRUE) to see
all connections, and close the ones you want to (and its help page shows
you how).


In older versions that do give the warning, wouldn't it be sufficient to
name the textConnection, and close it explicitly? E.g.

mydata- read.table(con - textConnection(mystring), header=TRUE,
sep=,, row.names=id, na.strings= )

close(con)


Yes, but you cannot do that retrospectively.  I would say this is still 
good practice.



Duncan Murdoch





Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of David Winsemius
Sent: Wednesday, January 04, 2012 7:10 AM
To: Dan Abner
Cc: r-help@r-project.org
Subject: Re: [R] Warning message about closing a connection 


On Jan 4, 2012, at 9:53 AM, Dan Abner wrote:


Hello everyone,

After running the following code, I obtain this error message.



mydata- read.table(textConnection(mystring),

+ header=TRUE, sep=,,
+ row.names=id, na.strings= )

mydata

Warning message:
closing unused connection 3 (mystring)

=

However, when I attempt to run read.table() again and immediately
submit
the close() function (below), I obtain this message:


close(mystring)

Error in UseMethod(close) :
no applicable method for 'close' applied to an object of class
character
=

How can I avoid the warning message altogether?


?closeAllConnections

The error message occurs because mystring was never the connection
name.

--

David Winsemius, MD
West Hartford, CT

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








--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@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] Is using glht with Tukey for lme post-hoc comparisons an appropriate substitute to TukeyHSD?

2012-01-04 Thread Richard M. Heiberger
Anne,

Thank you for writing back, and for including your data.

I have two things here.  First, I ran an a analysis of your data and have
my observations
on interpretation.  Second, I answer your general question about glht and
TukeyHSD when there are interactions.
I illustrate how to get the same answer from glht with an example from your
data.


## install.packages(HH)  ## if you do not already have it
library(HH)

Active - read.table(textConnection(
Treatment HabitatpActive
  1G   E 0.18541667
  1G   E 0.0250
  1G   E 0.04208333
  1G   E 0.14847222
  1G   E 0.0806
  1G   E 0.1678
  1G   S 0.0511
  1G   S 0.1908
  1G   S 0.1233
  1G   S 0.3572
  1G   S 0.4375
  1G   S 0.02638889
  1R   E 0.38736111
  1R   E 0.51180556
  1R   E 0.14916667
  1R   E 0.61041667
  1R   E 0.36013889
  1R   E 0.11347222
  1R   S 0.10805556
  1R   S 0.1872
  1R   S 0.27625000
  1R   S 0.25236111
  1R   S 0.18208333
  1R   S 0.16152778
  2G   E 0.25916667
  2G   E 0.3719
  2G   E 0.02263889
  2G   E 0.18402778
  2G   E 0.4575
  2G   E 0.0225
  2G   S 0.02958333
  2G   S 0.10069444
  2G   S 0.12875000
  2G   S 0.1136
  2G   S 0.13680556
  2G   S 0.07875000
  2R   E 0.57513889
  2R   E 0.1289
  2R   E 0.3200
  2R   E 0.55736111
  2R   E 0.7889
  2R   E 0.6506
  2R   S 0.35527778
  2R   S 0.4836
  2R   S 0.2136
  2R   S 0.3528
  2R   S 0.5261
  2R   S 0.29416667
 R+G   E 0.37027778
 R+G   E 0.20263889
 R+G   E 0.0719
 R+G   E 0.49041667
 R+G   E 0.21847222
 R+G   E 0.1356
 R+G   S 0.2086
 R+G   S 0.23986111
 R+G   S 0.02180556
 R+G   S 0.2325
 R+G   S 0.28916667
 R+G   S 0.50208333
), header=TRUE)
## close.connection()
closeAllConnections()

logitAct - logit(Active$pActive)
model3 - aov(logitAct ~ Treatment*Habitat, data=Active)
summary(model3)
summary(glht(model3, focus=Treatment, linfct=mcp(Treatment=Tukey)))
TukeyHSD(model3)
with(Active, table(Treatment, Habitat))

par(omd=c(0, .95, 0, 1))
model3.mmc - glht.mmc(model3, linfct=mcp(Treatment=Tukey))
plot(model3.mmc, ry=c(-2.75, 0.25), x.offset=.8)
plot.matchMMC(model3.mmc$mca)

## 1G  1R  2G  2R R+G
R.linear - c(-1,  0,  -1,  2,  0 )
names(R.linear) - c('1G', '1R', '2G', '2R', 'R+G')
lmat.R - orthog.complete(as.matrix(R.linear))
dimnames(lmat.R)[[2]][1] - R.linear

model3.mmc - glht.mmc(model3, linfct=mcp(Treatment=Tukey),
focus.lmat=lmat.R)
plot(model3.mmc, ry=c(-2.75, 0.25), x.offset=.8)
plot.matchMMC(model3.mmc$lmat, col.signif=blue)

Active$Treatment - factor(Active$Treatment, levels=c('1G', '2G', 'R+G',
'1R', '2R'))
contrasts(Active$Treatment) - lmat.R[c('1G', '2G', 'R+G', '1R', '2R'),]
model3g - aov(logitAct ~ Treatment*Habitat, data=Active)
summary(model3g, split=list(Treatment=list(R.linear=1, rest=2:4)),
expand.split=FALSE)

position(Active$Habitat) - c(2, 4)
interaction2wt(logitAct ~ Treatment*Habitat, data=Active)

## from the above tables and graphs, it looks like the only thing
## going on in the data you posted is the linear effect of R.


## On your questions on glht and TukeyHSD.
## Without interactions or covariates they give the same answer.
## With interactions or covariates the default for glht is to give
different answers.
## The output from glht includes a warning to that effect.
##
## From ?glht
## Warning message:
## In mcp2matrix(model, linfct = linfct) :
##   covariate interactions found -- default contrast might be inappropriate
##
## From ?glht, read about the interaction_average argument.
## With the glht argument interaction_average=TRUE, they give the same
answer
## With your example,
summary(glht(model3, linfct=mcp(Treatment=Tukey,
interaction_average=TRUE)))
TukeyHSD(model3, which=Treatment)

Rich
On Tue, Jan 3, 2012 at 7:26 PM, Anne Aubut an438...@dal.ca wrote:

 Hello Richard,
 Thank you so much for getting back to me.  In the ?glht example, the
 confidence intervals are the same and the p-values are very similar.  I ran
 a 2-way ANOVA and compared the results for the glht code with Tukey and
 TukeyHSD for Treatment, which was a significant main effect (output is
 below).  I found that the p-values for glht and TukeyHSD differed quite a
 bit.  If glht with Tukey is just another method to run Tukey HSD, I don't
 understand why the two methods yeilded different results.  If they are not
 equivalent, how is glht calculating the p-values?  I also ran my 2-way
 ANOVA without the Treatment*Habitat interaction and I found that the glht
 and TukeyHSD methods did 

Re: [R] Finding Source of Error Message of 'Non-Unique Index Entries'

2012-01-04 Thread Rich Shepard

On Wed, 4 Jan 2012, David Winsemius wrote:


You didn't ask for what was duplicated, but rather what was NOT duplicated
with that code. In the case of a dataframe it is the entire row that is
tested.


  My original question was what was duplicated, but ... I changed the
function by dropping the 'not'. There's something seriously wrong here and I
need help from R gurus to tell me why.

  Example:

burns.tds[duplicated(burns.tds), ]
  ...
25760 BC-1.5 1996-09-19  NA
25761 BC-1.5 1996-09-19   0.010
  ...

  But, when I query the database table I see this:

select * from chemistry where site = 'BC-1.5' and sampdate = '1996-09-19'
and param = 'TDS';
  site  |  sampdate  | param | quant | units | qual | easting | northing |
 stream  | basin 
++---+---+---+--+-+--+-

-+
 BC-1.5 | 1996-09-19 | TDS   |   935 | mg/L  |  | |  | 
BurnsCrk | 
(1 row)


  There is only a single row for that site, sampdate, and parameter and the
quantity is different from those in the R data frame.


I think you need to reduce this problem to a dataframe that you either
post an access method for or use dput() to include. Then you need to say
what you goals are and what code is not working on that example.


  I'll gladly do this. Which data frame should I make available: the
original chemdata or the subset burns.tds? I'll start with the latter.
Compressed dput() output attached.

  My goal is to produce time series plots of TDS, by site, on several
streams over the period for which that component was measured. Lattice lets
me superpose multiple lines on the same axis set with different color lines
and a legend.

  What's not working is something in the workflow of subsettiong chemdata to
extract all TDS data for a named stream (e.g., burns.tds and winters.tds),
then convert them to zoo objects using read.zoo(). Somewhere along this
process my data are being mangled. It's not in the source data frame,
chemdata:

chemdata[duplicated(chemdata), ]
 [1] site sampdate paramquantunitsqual easting  northing
 [9] stream   basin 
0 rows (or 0-length row.names)


  The command I used to subset burns.tds from chemdata was:

burns.tds - subset(chemdata, stream == 'BurnsCrk', select = c(site,
sampdate, param == 'TDS', quant), drop = T)

Thanks, David,

Rich

__
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] Adding a vertical line to plot with two overlapping density plots

2012-01-04 Thread David L Carlson
That works, but if all you want is one vertical line at 0, this will work

densityplot(~value, thedata.m, groups=variable,auto.key=list(columns=2),
panel = function(x, y, ...) {
panel.densityplot(x, ...)
panel.abline(v=0)
}
)

--
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77843-4352


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Petr PIKAL
Sent: Wednesday, January 04, 2012 10:27 AM
To: josh rosen
Cc: r-help@r-project.org
Subject: Re: [R] Adding a vertical line to plot with two overlapping density
plots

 
 thank you very much Petr. Yes, I meant densityplot form lattice. 
 
 The code I gave plots the densities of both x1 and x2 in one panel. 
 Could you show me how to integrate the function addline into the code so 

 that a vertical line v=0 is added? 

The function is used after you make a plot.

addLine(v=2)

shall be OK

before you of course need to define the function

addLine - function (a = NULL, b = NULL, v = NULL, h = NULL, ..., once = 
FALSE)
 {
tcL - trellis.currentLayout()
k - 0
for (i in 1:nrow(tcL)) for (j in 1:ncol(tcL)) if (tcL[i,
j]  0) {
k - k + 1
trellis.focus(panel, j, i, highlight = FALSE)
if (once)
panel.abline(a = a[k], b = b[k], v = v[k], h = h[k],
...)
else panel.abline(a = a, b = b, v = v, h = h, ...)
trellis.unfocus()
}
 }


Regards
Petr


 
  

 On 4 January 2012 15:55, Petr PIKAL petr.pi...@precheza.cz wrote:
 Hi
 
 
  Hi,
  A simple question I hope. I wish to add a single vertical line to a 
plot
  with several density plots.
  Here is a simplified example.
 
  
  thedata - data.frame(x1=rnorm(100,1,1),x2=rnorm(100,3,1)) #create 
data
  thedata.m-melt(thedata)
  densityplot(~value, thedata.m, 
groups=variable,auto.key=list(columns=2))
  #this gives the two density plots
  #
 
  what I wish now is to add a vertical line, for example v=2.

 If you mean densityplot from lattice here is a function (addapted from
 Gabor Grothendieck's code] which adds arbitrary line(s) into panels. Is
 options are similar to abline and once=TRUE means you want different 
lines
 to different panels.
 
  addLine
 function (a = NULL, b = NULL, v = NULL, h = NULL, ..., once = FALSE)
 {
tcL - trellis.currentLayout()
k - 0
for (i in 1:nrow(tcL)) for (j in 1:ncol(tcL)) if (tcL[i,
j]  0) {
k - k + 1
trellis.focus(panel, j, i, highlight = FALSE)
if (once)
panel.abline(a = a[k], b = b[k], v = v[k], h = h[k],
...)
else panel.abline(a = a, b = b, v = v, h = h, ...)
trellis.unfocus()
}
 }
 
 Regards
 Petr
 
 
 
 
  Many thanks,
  Josh.
 
 [[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-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] Warning message about closing a connection XXXX

2012-01-04 Thread peter dalgaard

On Jan 4, 2012, at 19:21 , Duncan Murdoch wrote:

 On 12-01-04 12:25 PM, Prof Brian Ripley wrote:
 
 
 Rather than using a sledgehammer, use showConnections(all=TRUE) to see
 all connections, and close the ones you want to (and its help page shows
 you how).
 
 In older versions that do give the warning, wouldn't it be sufficient to name 
 the textConnection, and close it explicitly?  E.g.
 
 mydata- read.table(con - textConnection(mystring),  header=TRUE, sep=,,   
 row.names=id, na.strings= )
 
 close(con)
 

Or, in recent versions, use the tools designed for the purpose and do

mydata - read.table(text=mystring, )


-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [R] Finding Source of Error Message of 'Non-Unique Index Entries'

2012-01-04 Thread David Winsemius
Nothing attached. I don't know what you entitled teh compressed dput  
output but it did not pass the filters of the mailserver and you did  
not copy me. If chemdata is available as a text file, hten make sure  
its extension is .txt and then attach it.


--
David.

On Jan 4, 2012, at 1:31 PM, Rich Shepard wrote:


On Wed, 4 Jan 2012, David Winsemius wrote:

You didn't ask for what was duplicated, but rather what was NOT  
duplicated
with that code. In the case of a dataframe it is the entire row  
that is

tested.


 My original question was what was duplicated, but ... I changed the
function by dropping the 'not'. There's something seriously wrong  
here and I

need help from R gurus to tell me why.

 Example:

burns.tds[duplicated(burns.tds), ]
 ...
25760 BC-1.5 1996-09-19  NA
25761 BC-1.5 1996-09-19   0.010
 ...

 But, when I query the database table I see this:

select * from chemistry where site = 'BC-1.5' and sampdate =  
'1996-09-19'

and param = 'TDS';
 site  |  sampdate  | param | quant | units | qual | easting |  
northing |
stream  | basin ++---+---+---+-- 
+-+--+-

-+
BC-1.5 | 1996-09-19 | TDS   |   935 | mg/L  |  |  
|  | BurnsCrk | (1 row)


 There is only a single row for that site, sampdate, and parameter  
and the

quantity is different from those in the R data frame.

I think you need to reduce this problem to a dataframe that you  
either
post an access method for or use dput() to include. Then you need  
to say

what you goals are and what code is not working on that example.


 I'll gladly do this. Which data frame should I make available: the
original chemdata or the subset burns.tds? I'll start with the latter.
Compressed dput() output attached.

 My goal is to produce time series plots of TDS, by site, on several
streams over the period for which that component was measured.  
Lattice lets
me superpose multiple lines on the same axis set with different  
color lines

and a legend.

 What's not working is something in the workflow of subsettiong  
chemdata to
extract all TDS data for a named stream (e.g., burns.tds and  
winters.tds),
then convert them to zoo objects using read.zoo(). Somewhere along  
this

process my data are being mangled. It's not in the source data frame,
chemdata:

chemdata[duplicated(chemdata), ]
[1] site sampdate paramquantunitsqual easting   
northing

[9] stream   basin 0 rows (or 0-length row.names)

 The command I used to subset burns.tds from chemdata was:

burns.tds - subset(chemdata, stream == 'BurnsCrk', select = c(site,
sampdate, param == 'TDS', quant), drop = T)

Thanks, David,

Rich

__
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
West Hartford, CT

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


Re: [R] Using a mathematical expression in sapply() XXXX

2012-01-04 Thread peter dalgaard

On Jan 4, 2012, at 16:32 , David Winsemius wrote:

 
 On Jan 4, 2012, at 9:17 AM, peter dalgaard wrote:
 
 
 On Jan 4, 2012, at 14:57 , Milan Bouchet-Valat wrote:
 
 Le mercredi 04 janvier 2012 à 08:41 -0500, Dan Abner a écrit :
 Hello everyone,
 
 I have the following call to sapply() and error message. Is the most
 efficient way to deal with this to make sum(!is.na(x)) a function in a
 separate line prior to this call? If not, please advise.
 
 N.Valid=sapply(x,sum(!is.na(x)))
 Error in match.fun(FUN) :
 'sum(!is.na(x))' is not a function, character or symbol
 You can use this:
 sapply(x, function(x) sum(!is.na(x)))
 
 But, if you can convert x to a matrix, it would be faster and shorter to
 check for NAs beforehand, and use apply():
 x - matrix(c(1, 2, NA, 3, NA, 4), 2)
 apply(!is.na(x), 2, sum)
 
 Just for completeness: You might also do
 
 sapply(lapply(x, is.na), sum)
 
 I thought from context that the sum of negation of is.na was what was 
 desired, since the negation operator was used and the name of the results was 
 N.Valid.

Oops. Yes.

 So consider substituting the existing function, complete.cases in place of 
 is.na:
 
 sapply(lapply(x, complete.cases), sum)

Yes. I suppose Negate(is.na) would just be being silly. Unless x is a list of 
data frames or something...



Picking up on Milan's note, notice that if x is a data frame, then conversion 
to matrix is automatic and, e.g. 

 apply(!is.na(airquality), 2, sum)
  Ozone Solar.RWindTemp   Month Day 
116 146 153 153 153 153 

works fine.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [R] Finding Source of Error Message of 'Non-Unique Index Entries' [FIXED]

2012-01-04 Thread Rich Shepard

On Wed, 4 Jan 2012, David Winsemius wrote:

Nothing attached. I don't know what you entitled teh compressed dput output 
but it did not pass the filters of the mailserver and you did not copy me.


David,

  It must have been stripped off as too large (14K).

  Regardless, I solved the problem:

  The examples in the subset help page show only a single row criterion
being used, but does not explicitly note that rows can be selected only one
criterion at a time.

  Because the issue showed up only with the subset() function to extract
rows with the parameter TDS, the problem had to be in that syntax. By
changing the data frame argument to subset() from the overall chemdata to
that of only a single stream, creation of the zoo object threw no errors and
duplicated() returned zero rows.

  Wow! And I thought I understood the subset() syntax. I now do!

Thanks to you, Gabor, and everyone else who responded to this thread,

Rich

__
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] Finding Source of Error Message of 'Non-Unique Index Entries' [FIXED]

2012-01-04 Thread David Winsemius


On Jan 4, 2012, at 3:21 PM, Rich Shepard wrote:


On Wed, 4 Jan 2012, David Winsemius wrote:

Nothing attached. I don't know what you entitled teh compressed  
dput output but it did not pass the filters of the mailserver and  
you did not copy me.


David,

 It must have been stripped off as too large (14K).

 Regardless, I solved the problem:

 The examples in the subset help page show only a single row criterion
being used, but does not explicitly note that rows can be selected  
only one

criterion at a time.


Because that is simply not true. Connect your criteria with ampersands  
and you can have as many as you want. The only requirement is that the  
logical vector that results be exactly the number of rows in the  
dataframe  as described in the help page.




 Because the issue showed up only with the subset() function to  
extract

rows with the parameter TDS, the problem had to be in that syntax. By
changing the data frame argument to subset() from the overall  
chemdata to
that of only a single stream, creation of the zoo object threw no  
errors and

duplicated() returned zero rows.

 Wow! And I thought I understood the subset() syntax. I now do!

Thanks to you, Gabor, and everyone else who responded to this thread,

Rich

__
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
West Hartford, CT

__
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] Passing multiple arguments to a function through sapply() XXXX

2012-01-04 Thread Dan Abner
Hello everyone,

How does one pass multiple arguments of a user defined function to that
function when called within sapply()?

I have the following:

 myna-function(x,miss.val) {x[x %in% miss.val]-NA;x}
 mydataNA3-sapply(mydataNA,c(x=myna,miss.val=c(9,99)))
Error in match.fun(FUN) :
  'c(x = myna, miss.val = c(9, 99))' is not a function, character or symbol
 mydataNA3


Thanks!

Dan

[[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] Passing multiple arguments to a function through sapply() XXXX

2012-01-04 Thread David Winsemius


On Jan 4, 2012, at 3:47 PM, Dan Abner wrote:


Hello everyone,

How does one pass multiple arguments of a user defined function to  
that

function when called within sapply()?

I have the following:


myna-function(x,miss.val) {x[x %in% miss.val]-NA;x}
mydataNA3-sapply(mydataNA,c(x=myna,miss.val=c(9,99)))

Error in match.fun(FUN) :
 'c(x = myna, miss.val = c(9, 99))' is not a function, character or  
symbol

mydataNA3


In the absence of test data this is a guess:

mydataNA3-sapply(mydataNA, myna, miss.val=c(9,99) )

--

David Winsemius, MD
West Hartford, CT

__
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] putting regression output right on a plot

2012-01-04 Thread David Winsemius


On Jan 4, 2012, at 11:30 AM, Mark Leeds wrote:

hi: does anyone know if it's possible and, if so, where there's an  
example,
of putting the output of summary(lm) right on the plot of the data   
itself.
If the answer is to use capture.output and then text, I'll try that  
but I

was thinking there might be an example somewhere ? thanks.



http://finzi.psych.upenn.edu/R/library/gplots/html/sinkplot.html
http://finzi.psych.upenn.edu/R/library/gtools/html/capture.html



[[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
West Hartford, CT

__
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] Warning message about closing a connection XXXX

2012-01-04 Thread Martin Morgan

On 01/04/2012 09:25 AM, Prof Brian Ripley wrote:

On 04/01/2012 17:12, William Dunlap wrote:

Re
 How can I avoid the warning message altogether?

?closeAllConnections

I think of calls to closeAllConnections() in the same
way that I think of calls to rm(list=objects()):
they both can remove things that are not theirs to remove.

Calling gc() will close all unused connections, so
no damage can be done. (I thought that the warning
about closing unused text connections was dropped in
a recent release of R so neither is really needed.)


Yes, it was. The warning is there because the user may need to do
something about the 'other end' of the now-closed connection, which R
manages for textConnections.

There is however one circumstance where gc() does not close all unused
connections, and that is when gzcon() is used (because that involves two
connections and it is not clear when the inner one is 'in use': and we
used to guess wrong).

Rather than using a sledgehammer, use showConnections(all=TRUE) to see
all connections, and close the ones you want to (and its help page shows
you how).


Since connections are using R's finalizers, and order of evaluation of 
finalizers are not reliable, it is not always possible to get in front 
of the automatic close, e.g., when a reference class relies on a 
finalize method to tidy up after itself (perhaps this was also the case 
with gzcon?).


setOldClass(c(file, connection))

setRefClass(A, fields=list(x=file),
methods=list(initialize=function(fname, ...) {
callSuper(x=file(fname, r))
}, finalize=function() {
## This sometimes provokes an error
close(.self$x)
}))

getRefClass(A)$new(/tmp)

A desirable feature would allow the message or automatic close to be 
silenced, or the potentially closed connection to be queried for its 
validity.


Martin




Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of David Winsemius
Sent: Wednesday, January 04, 2012 7:10 AM
To: Dan Abner
Cc: r-help@r-project.org
Subject: Re: [R] Warning message about closing a connection 


On Jan 4, 2012, at 9:53 AM, Dan Abner wrote:


Hello everyone,

After running the following code, I obtain this error message.



mydata- read.table(textConnection(mystring),

+ header=TRUE, sep=,,
+ row.names=id, na.strings= )

mydata

Warning message:
closing unused connection 3 (mystring)

=

However, when I attempt to run read.table() again and immediately
submit
the close() function (below), I obtain this message:


close(mystring)

Error in UseMethod(close) :
no applicable method for 'close' applied to an object of class
character
=

How can I avoid the warning message altogether?


?closeAllConnections

The error message occurs because mystring was never the connection
name.

--

David Winsemius, MD
West Hartford, CT

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






--
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109

Location: M1-B861
Telephone: 206 667-2793

__
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] [newbie] stack operations, or functions with side effects (or both)

2012-01-04 Thread Tom Roche

summary: Specifically, how does one do stack/FIFO operations in R?
Generally, how does one code functions with side effects in R?

details:

I have been a coder for years, mostly using C-like semantics (e.g.,
Java). I am now trying to become a scientist, and to use R, but I don't
yet have the sense of good R and R idiom (i.e., expressions that are
to R what (e.g.) the Schwartzian transform is to Perl).

I have a data-assimilation problem for which I see a solution that
wants a stack--or, really, just a pop(...) such that

* s - c(1:5)
* print(s)
[1] 1 2 3 4 5
* pop(s)
[1] 1
* print(s)
[1] 2 3 4 5

but in fact I get

 pop(s)
Error: could not find function pop

and Rseek'ing finds me nothing. When I try to write pop(...) I get

pop1 - function(vector_arg) {
+   length(vector_arg) - lv
+   vector_arg[1] - ret
+   vector_arg - vector_arg[2:lv]
+   ret
+ }
 
 pop1(s)
[1] 1
 print(s)
[1] 1 2 3 4 5

i.e., no side effect on the argument

pop2 - function(vector_arg) {
+   length(vector_arg) - lv
+   vector_arg[1] - ret
+   assign(vector_arg, vector_arg[2:lv])
+   return(ret)
+ }
 
 pop2(s)
[1] 1
 print(s)
[1] 1 2 3 4 5

ditto :-( What am I missing?

* Is there already a stack API for R (which I would expect)? If so, where?

* How to cause the desired side effect to the argument in the code above?

TIA, Tom Roche tom_ro...@pobox.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] [newbie] stack operations, or functions with side effects (or both)

2012-01-04 Thread Justin Haynes
do s[1] and s[-1] do what you're looking for?
those are just to display... if you want to change s, you need to reassign
it or fiddle with namespacing.  however, I'd say it is better to write R
code as though data structures are immutable until you explicitly re-assign
them rather than trying to deal with side effects and state...


 pop - function(vec){
+   print(vec[1])
+   print(vec[-1])
+   return(vec[-1])
+}
 s - 1:5
 s - pop(s)
[1] 1
[1] 2 3 4 5
 s
[1] 2 3 4 5



On Wed, Jan 4, 2012 at 1:22 PM, Tom Roche tom_ro...@pobox.com wrote:


 summary: Specifically, how does one do stack/FIFO operations in R?
 Generally, how does one code functions with side effects in R?

 details:

 I have been a coder for years, mostly using C-like semantics (e.g.,
 Java). I am now trying to become a scientist, and to use R, but I don't
 yet have the sense of good R and R idiom (i.e., expressions that are
 to R what (e.g.) the Schwartzian transform is to Perl).

 I have a data-assimilation problem for which I see a solution that
 wants a stack--or, really, just a pop(...) such that

 * s - c(1:5)
 * print(s)
 [1] 1 2 3 4 5
 * pop(s)
 [1] 1
 * print(s)
 [1] 2 3 4 5

 but in fact I get

  pop(s)
 Error: could not find function pop

 and Rseek'ing finds me nothing. When I try to write pop(...) I get

 pop1 - function(vector_arg) {
 +   length(vector_arg) - lv
 +   vector_arg[1] - ret
 +   vector_arg - vector_arg[2:lv]
 +   ret
 + }
 
  pop1(s)
 [1] 1
  print(s)
 [1] 1 2 3 4 5

 i.e., no side effect on the argument

 pop2 - function(vector_arg) {
 +   length(vector_arg) - lv
 +   vector_arg[1] - ret
 +   assign(vector_arg, vector_arg[2:lv])
 +   return(ret)
 + }
 
  pop2(s)
 [1] 1
  print(s)
 [1] 1 2 3 4 5

 ditto :-( What am I missing?

 * Is there already a stack API for R (which I would expect)? If so, where?

 * How to cause the desired side effect to the argument in the code above?

 TIA, Tom Roche tom_ro...@pobox.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.


Re: [R] tcltk on linux/rhel6

2012-01-04 Thread Carl Baribault
Brian,

FYI, I had previously installed tcl-devel but had overlooked tk-devel
on the OS.  Now that I've installed tk-devel on the OS, the following
sequence of commands has succeeded:

sudo ./configure --with-tcltk
sudo make
sudo make check
sudo make install
R
...
 library(tcltk)
Loading Tcl/Tk interface ... done


Thanks for your suggestions.

Best,
CB

On Wed, Jan 4, 2012 at 3:40 AM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote:
 On 04/01/2012 01:52, Peter Langfelder wrote:

 On Tue, Jan 3, 2012 at 4:03 PM, Carl Baribaultcrlbr...@gmail.com  wrote:

 Dear All,

 I've seen posts to the effect that..
 1) choose.dir is only available for windows, and
 2) tk_choose.dir would be the linux equivalent.

 I'm still having trouble with the subject package on linux/rhel6.

 I've specified --with-tcltk during ./configure, and I still get the
 response...

 install.packages(tcltk)


 My understanding is that tcltk is included in the base installation
 now. You should be able to load it using library(tcltk) without
 explicitly installing it. You can install tcltk2 as an add-on package.


 Yes, but you need OS support (for both).

 Whoever installed this R needs to read the R-admin manual and note the need
 for -devel RPMs for Tcl and Tk.  Then study the configure messages which
 tell you if tcltk was built.

 --
 Brian D. Ripley,                  rip...@stats.ox.ac.uk
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford,             Tel:  +44 1865 272861 (self)
 1 South Parks Road,                     +44 1865 272866 (PA)
 Oxford OX1 3TG, UK                Fax:  +44 1865 272595

__
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] calculate quantiles of a custom function

2012-01-04 Thread Gerhard
Am Dienstag, 3. Januar 2012, 19:51:36 schrieb Prof. Dr. Matthias Kohl:
 D - AbscontDistribution(d = function(x) dbeta(x, 2, 6) + dbeta(x,6,2), 
 low = 0, up = 1, withStand = TRUE)

Dear all,

thank you all again for your help. 

So, summing up, (in case this might be useful to other beginners - like me) 
this is how it can be done:


library(distr)

dcustom - function(x) {
  (dbeta(x,2,6) + dbeta(x,6,2))/2# I need to divide by 2 to get 1 as
 # result of 
integration;
}

pcustom - function(x) {
  integrate(dmyspeaker,0,x)$value 
}

D - AbscontDistribution(d = dcustom, low = 0, up = 1, withStand = TRUE)

qcustom - function(x){
  q(D)(x)
}


Best, 

Gerhard

__
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 on plotting ts data

2012-01-04 Thread lornyi
Hi, i try to plot ts data on x-y coordiante
I want my data to be points, but somehow it always comes out with lines and
# linked bwtween data,
i used  plot(lag(x,-9),y,type=p), x and y are time series data
is there anyway to remove those lines?
Thanks a lot

--
View this message in context: 
http://r.789695.n4.nabble.com/problem-on-plotting-ts-data-tp4261865p4261865.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] Combining characters

2012-01-04 Thread jeremy
Hi all,

I'm trying to combine exhaustively several character arrays in R like:
x=c(one,two,three)
y=c(yellow,blue,green)
z=c(apple,cheese)

in order to get concatenation of 

x[1] y[1] z[1]  (one yellow apple)
x[1] y[1] z[2] (one yellow cheese)
x[1] y[2] z[1](one blue apple)
...
x[length(x)] y[length(y)] z[length(z)]  (three green cheese)

Anyone has a solution ?
Thank in advance

--
View this message in context: 
http://r.789695.n4.nabble.com/Combining-characters-tp4261888p4261888.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] Symbols in graph

2012-01-04 Thread Y Nygård
Hi,

Is there an easy way to add symbols to a line in a scatter plot, so that
only a few symbols are added per line (a line drawn based on a large set of
data points) , in order to distinguish several lines in one graph (not a
symbol for each data point as is the default in plot()).

Thanks a lot!

Rgds, Yvonne

[[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] subscript with comma

2012-01-04 Thread suse
Thank you! It works now. 
But I still don't understand, how all these expressions, , paste, group,
eval... have to be used together.  (For example, I first tried
expression(sm[w,grass]) but it didn't work, and I couldn't find, why (and
when) commas are interpreted here differently). So: Is there somewhere an
introduction (rather than examples) to this? Books, documents etc.

--
View this message in context: 
http://r.789695.n4.nabble.com/subscript-with-comma-tp4261579p4261931.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] problem on plotting ts data

2012-01-04 Thread lornyi
thanks, it works!

--
View this message in context: 
http://r.789695.n4.nabble.com/problem-on-plotting-ts-data-tp4261865p4262179.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] problem on plotting ts data

2012-01-04 Thread Rui Barradas
Hello,

Try 'as.vector' or 'as.numeric'

x - as.ts(rnorm(20))
y - as.ts(rnorm(20))
plot(x)

plot(as.vector(lag(x,-9)),as.vector(y),type=p) # works
plot(as.numeric(lag(x,-9)),as.numeric(y),type=p)  # also works

Rui Barradas



--
View this message in context: 
http://r.789695.n4.nabble.com/problem-on-plotting-ts-data-tp4261865p4262106.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] function in R for my exercise

2012-01-04 Thread Thomthom
Hi Michael,

Thanks for your answer! sorry I didn't see this rule... No problem,
I'll try to figure it out by myself.

Thanks for your indication though!

Thomas

2012/1/4, Michael Weylandt [via R] ml-node+s789695n4261894...@n4.nabble.com:


 Unfortunately, there's a general no-homework rule because we never
 know what your instructor wants you to figure out on your own (though,
 a sincere thanks for admitting this was hw rather than trying to trick
 us like so many). That said, I think your second function, while a
 little clumsy, does work but for one little error near the end. It's
 very obvious when you see it so don't overthink it, but look closely
 at the lines that involve swap.

 If you want to make it more elegant, I'd suggest you look at the
 ?switch construct: also, to make the swap bit more elegant, think
 about how one exchanges variable values in a language like C and put
 some construct like that within an if statement near the top. If you
 want to get real elegant, note that after you figure out switch,
 constructs like `+`(3, 4) are valid in R (though certainly beyond the
 scope of your exercise)

 Hope this helps,

 Michael

 On Wed, Jan 4, 2012 at 9:45 AM, Thomthom rime.tho...@gmail.com wrote:
 Hi R helpers!

 I have a question. I'm trying to create a function for an exercise. Here
 are
 the arguments I should include:

 x and y are numeric
 z is a name (plus,minus,multiply,divide)
 and swap is logical.

 Here is what the function should do:

 When z=plus, then x+y is performed and so on for the other z names. It
 should give a NA when the z argument doesn't correspond to something
 mention
 before.
 When swap =TRUE, then y must be on the left side of the equation (y/x
 instead of x/y).

 So far, I managed to get something worked for the first part of the body
 function (typing plus performes indeed an addition...) but I couldn't
 get
 how to make the second part working. Any suggestion?

 Here is the code I have so far:

 myFunc- function(x,y,z,swap)
                { res= NULL
                  if(z ==plus) res=x+y
                   else if(z==minus) res=x-y
                   else if(z== multiply) res=x*y
                   else if(z==divide) res=x/y
                   else res-NA

                  return(res)}

 Then, I tried to include some lines to take this swap function into
 account by splitting somehow my function in 2:

 myFunc- function(x,y,z,swap)
                { res1= NULL
                  res2=NULL

                  if(z ==plus) res1=x+y
                   else if(z==minus) res1=x-y
                   else if(z== multiply) res1=x*y
                   else if(z==divide) res1=x/y
                   else res1-NA

                  if(z ==plus) res2=y+x
                   else if(z==minus) res2=y-x
                   else if(z== multiply) res2=y*x
                   else if(z==divide) res2=y/x
                   else res2-NA

                  if (swap-T) return(res2)
                  else return(res1)
               }
 Any suggestions would be more than appreciated! I already thank you!

 And happy new year! (that may be redundant to most of you I know ^^)

 Thomas

 --
 View this message in context:
 http://r.789695.n4.nabble.com/function-in-R-for-my-exercise-tp4261710p4261710.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.


 ___
 If you reply to this email, your message will be added to the discussion
 below:
 http://r.789695.n4.nabble.com/function-in-R-for-my-exercise-tp4261710p4261894.html

 To unsubscribe from function in R for my exercise, visit
 http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4261710code=cmltZS50aG9tYXNAZ21haWwuY29tfDQyNjE3MTB8LTg1ODkwMDI4MA==


-- 
Thomas


--
View this message in context: 
http://r.789695.n4.nabble.com/function-in-R-for-my-exercise-tp4261710p4262273.html
Sent from the R help mailing list archive at Nabble.com.
[[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, 

[R] plot rq lm

2012-01-04 Thread agent dunham
Dear Community, 

I'd like to plot an rq object the same way I do with a lm one, is it
possible? Something like this

plot(rqmodel , 1:4, id.labels=rownames(pga1)); where

rqmodel - rq(log(vd) ~ v1 + log(v2) +log(v3) + v4 + v5 ,data =dat)


Thanks in advance and apologies, I'm pretty newbie with this, u...@host.com


--
View this message in context: 
http://r.789695.n4.nabble.com/plot-rq-lm-tp4262170p4262170.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] Options for generating editable figures?

2012-01-04 Thread Allen McBride
Thank you for the advice; this is very helpful. I will see how they feel 
about installing Inkscape. I'll also work on getting R installed in a 
Windows environment so I can produce .emf and .wmf files. I found one 
old message on this list from someone who had luck doing this by running 
R with Wine. (When you say you mostly give them graphs in .wmf or .emf, 
I'm assuming you have a Windows machine? If I'm wrong and you have some 
other way of producing these files, please let me know. I almost got 
pstoedit/libemf working through MacPorts, but it messes up the line 
widths and characters pretty bad.)


Thanks,
--Allen


On 1/3/12 12:47 PM, Greg Snow wrote:

I have had clients who also wanted to make little changes to the graphs (mostly 
changing colors or line widths).  Most after doing this a couple of times have 
been happy to give be better descriptions of what they want so I can just do it 
correctly the first time.

I mostly give them the graphs in .wmf or .emf format, however I have found that 
if I create the file and send it to them, most have problems getting it into 
word or power point, instead I usually copy and paste it into a word document 
and send the word document to them, they can then copy and paste from there to 
their presentation or report.  Of course this is only an option if you have MS 
word on the same computer as you are working on.  With those files double 
clicking takes the user into a basic editor where they can change colors, line 
widths, etc.  However, sometimes opening that editor will redo all the text, so 
what started as changing one line color also requires them to re orient all the 
axis and tick labels.

Inkscape is a much more capable program for doing these kinds of edits, and for 
basic editing it is fairly straight forward, so for your description of options 
below, I would suggest that you make them learn Inkscape if they really want to 
edit the graphs themselves.  Inkscape can also import pdf files (though it is 
an import rather than a simple open and you often need to ungroup a bunch of 
objects before editing them) so that may be another option for you.



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


Re: [R] Combining characters

2012-01-04 Thread Rui Barradas
Hello,

If you want to apply the same procedure to all elements of an object, check
out the  '*apply' functions.

In this case,

x=c(one,two,three)
y=c(yellow,blue,green)
z=c(apple,cheese)

lapply(x, function(x) paste(x, y))

gives a good picture of what you want to do, just transform it into a
function and use the function:

f - function(x, y) unlist(lapply(x, function(x) paste(x,y)))

f(x, f(y, z))

With more than 3 vectors, you could try a recursive version.
I hope this helps.

Rui Barradas


--
View this message in context: 
http://r.789695.n4.nabble.com/Combining-characters-tp4261888p4262632.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] using var from bash in R script

2012-01-04 Thread dood
Dear R users,

This probably a really noob question, but I'm stuck. I'd like to pass some
variables from bash to R as strings. I can successfully pass variables using
commandArgs(), the problem is that I end up with an array. So, for example:

 Args - commandArgs(TRUE)
 Args
[1] one   two   three

Now, it just so happens that one, two, three are names of columns that
I'd like to work with. I'd like to do something like this:

 print(summary(lm(Args[1] ~ Args[2])))

But, this doesn't work. The alternative would be to let bash write a number
of R-scripts and then rm them when done, but that seems like an unnecessary
step. 

Can this be done?

Thanks



--
View this message in context: 
http://r.789695.n4.nabble.com/using-var-from-bash-in-R-script-tp4262857p4262857.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] RODBC installation: error message

2012-01-04 Thread gregory benison

 One thing R could do better is to provide a standard way to view README and
 similar files before installing a package.  That might have helped here.


Agreed... right now, the R documentation points to a straightforward,
one-line way to download and install packages from the R command line,
but not to a similarly straightforward way to view a package's README
content (as far as I can tell).

__
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] Combining characters

2012-01-04 Thread andrija djurovic
Hi. You can use expand.grid here

expand.grid(x,y,z)

Andrija

On Wed, Jan 4, 2012 at 5:32 PM, jeremy jeremynamer...@gmail.com wrote:
 Hi all,

 I'm trying to combine exhaustively several character arrays in R like:
 x=c(one,two,three)
 y=c(yellow,blue,green)
 z=c(apple,cheese)

 in order to get concatenation of

 x[1] y[1] z[1]  (one yellow apple)
 x[1] y[1] z[2] (one yellow cheese)
 x[1] y[2] z[1](one blue apple)
 ...
 x[length(x)] y[length(y)] z[length(z)]  (three green cheese)

 Anyone has a solution ?
 Thank in advance

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Combining-characters-tp4261888p4261888.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] Combining characters

2012-01-04 Thread R. Michael Weylandt
? expand.grid

Michael

On Wed, Jan 4, 2012 at 10:32 AM, jeremy jeremynamer...@gmail.com wrote:
 Hi all,

 I'm trying to combine exhaustively several character arrays in R like:
 x=c(one,two,three)
 y=c(yellow,blue,green)
 z=c(apple,cheese)

 in order to get concatenation of

 x[1] y[1] z[1]  (one yellow apple)
 x[1] y[1] z[2] (one yellow cheese)
 x[1] y[2] z[1](one blue apple)
 ...
 x[length(x)] y[length(y)] z[length(z)]  (three green cheese)

 Anyone has a solution ?
 Thank in advance

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Combining-characters-tp4261888p4261888.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] Combining characters

2012-01-04 Thread Marc Schwartz

On Jan 4, 2012, at 10:32 AM, jeremy wrote:

 Hi all,
 
 I'm trying to combine exhaustively several character arrays in R like:
 x=c(one,two,three)
 y=c(yellow,blue,green)
 z=c(apple,cheese)
 
 in order to get concatenation of 
 
 x[1] y[1] z[1]  (one yellow apple)
 x[1] y[1] z[2] (one yellow cheese)
 x[1] y[2] z[1](one blue apple)
 ...
 x[length(x)] y[length(y)] z[length(z)]  (three green cheese)
 
 Anyone has a solution ?
 Thank in advance


See ?expand.grid and ?paste

DF - expand.grid(x, y, z)

 DF
Var1   Var2   Var3
1one yellow  apple
2two yellow  apple
3  three yellow  apple
4one   blue  apple
5two   blue  apple
6  three   blue  apple
7one  green  apple
8two  green  apple
9  three  green  apple
10   one yellow cheese
11   two yellow cheese
12 three yellow cheese
13   one   blue cheese
14   two   blue cheese
15 three   blue cheese
16   one  green cheese
17   two  green cheese
18 three  green cheese


 with(DF, paste(Var1, Var2, Var3))
 [1] one yellow appletwo yellow applethree yellow apple 
 [4] one blue apple  two blue apple  three blue apple   
 [7] one green apple two green apple three green apple  
[10] one yellow cheese   two yellow cheese   three yellow cheese
[13] one blue cheese two blue cheese three blue cheese  
[16] one green cheesetwo green cheesethree green cheese 

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] Combining characters

2012-01-04 Thread Joshua Wiley
Try expand.grid() to create all the combinations.  Then just collapse
them with paste():

apply(expand.grid(x, y, z), 1, paste, collapse =  )

Cheers,

Josh

On Wed, Jan 4, 2012 at 8:32 AM, jeremy jeremynamer...@gmail.com wrote:
 Hi all,

 I'm trying to combine exhaustively several character arrays in R like:
 x=c(one,two,three)
 y=c(yellow,blue,green)
 z=c(apple,cheese)

 in order to get concatenation of

 x[1] y[1] z[1]  (one yellow apple)
 x[1] y[1] z[2] (one yellow cheese)
 x[1] y[2] z[1](one blue apple)
 ...
 x[length(x)] y[length(y)] z[length(z)]  (three green cheese)

 Anyone has a solution ?
 Thank in advance

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Combining-characters-tp4261888p4261888.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.



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.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] Combining characters

2012-01-04 Thread Justin Haynes
apply(expand.grid(x, y, z, stringsAsFactors=F), 1, paste, collapse=' ')



On Wed, Jan 4, 2012 at 8:32 AM, jeremy jeremynamer...@gmail.com wrote:

 Hi all,

 I'm trying to combine exhaustively several character arrays in R like:
 x=c(one,two,three)
 y=c(yellow,blue,green)
 z=c(apple,cheese)

 in order to get concatenation of

 x[1] y[1] z[1]  (one yellow apple)
 x[1] y[1] z[2] (one yellow cheese)
 x[1] y[2] z[1](one blue apple)
 ...
 x[length(x)] y[length(y)] z[length(z)]  (three green cheese)

 Anyone has a solution ?
 Thank in advance

 --
 View this message in context:
 http://r.789695.n4.nabble.com/Combining-characters-tp4261888p4261888.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.


[[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] using var from bash in R script

2012-01-04 Thread Marc Schwartz

On Jan 4, 2012, at 3:08 PM, dood wrote:

 Dear R users,
 
 This probably a really noob question, but I'm stuck. I'd like to pass some
 variables from bash to R as strings. I can successfully pass variables using
 commandArgs(), the problem is that I end up with an array. So, for example:
 
 Args - commandArgs(TRUE)
 Args
 [1] one   two   three
 
 Now, it just so happens that one, two, three are names of columns that
 I'd like to work with. I'd like to do something like this:
 
 print(summary(lm(Args[1] ~ Args[2])))
 
 But, this doesn't work. The alternative would be to let bash write a number
 of R-scripts and then rm them when done, but that seems like an unnecessary
 step. 
 
 Can this be done?
 
 Thanks


See ?as.formula and ?paste

Something along the lines of the following should work:

Args - c(one, two, three)

 Args
[1] one   two   three
 
 paste(Args[1], ~, Args[2])
[1] one ~ two

 as.formula(paste(Args[1], ~, Args[2]))
one ~ two

Then use:

summary(lm(as.formula(paste(Args[1], ~, Args[2]


If 'one', 'two' and 'three' are columns in a data frame (say 'DF'), you will 
want to use the data argument in the call to lm():

  summary(lm(as.formula(paste(Args[1], ~, Args[2])), data = DF))

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] Symbols in graph

2012-01-04 Thread Jim Lemon
 Hi,

 Is there an easy way to add symbols to a line in a scatter plot, so that
 only a few symbols are added per line (a line drawn based on a large set
 of
 data points) , in order to distinguish several lines in one graph (not a
 symbol for each data point as is the default in plot()).

Hi Yvonne,
You can use the points function to plot every 10th point (or other
sequence).

points(x[seq(1,length(x),by=10)],y[seq(1,length(y),by=10)],...)

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.


[R] a quick question about rbinom

2012-01-04 Thread lynn.tsai
Hello, I have the following code using rbinom, but I don't understand what
*+1* means in the code. Could someone help? Thanks so much,

 X1-c(A,B)[rbinom(n,1,0.6)+1]
 X2-c(C,D)[rbinom(n,1,0.1)+1]

--
View this message in context: 
http://r.789695.n4.nabble.com/a-quick-question-about-rbinom-tp4262977p4262977.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] a quick question about rbinom

2012-01-04 Thread Bert Gunter
Homework?

If not, context?

-- Bert

On Wed, Jan 4, 2012 at 1:38 PM, lynn.tsai vernal@gmail.com wrote:
 Hello, I have the following code using rbinom, but I don't understand what
 *+1* means in the code. Could someone help? Thanks so much,

 X1-c(A,B)[rbinom(n,1,0.6)+1]
 X2-c(C,D)[rbinom(n,1,0.1)+1]

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/a-quick-question-about-rbinom-tp4262977p4262977.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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
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] a quick question about rbinom

2012-01-04 Thread Justin Haynes
homework or not,

?rbinom

should be plenty.




On Wed, Jan 4, 2012 at 1:38 PM, lynn.tsai vernal@gmail.com wrote:

 Hello, I have the following code using rbinom, but I don't understand what
 *+1* means in the code. Could someone help? Thanks so much,

  X1-c(A,B)[rbinom(n,1,0.6)+1]
  X2-c(C,D)[rbinom(n,1,0.1)+1]

 --
 View this message in context:
 http://r.789695.n4.nabble.com/a-quick-question-about-rbinom-tp4262977p4262977.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.


[[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] subscript with comma

2012-01-04 Thread Duncan Murdoch

On 12-01-04 11:41 AM, suse wrote:

Thank you! It works now.
But I still don't understand, how all these expressions, , paste, group,
eval... have to be used together.  (For example, I first tried
expression(sm[w,grass]) but it didn't work, and I couldn't find, why (and
when) commas are interpreted here differently). So: Is there somewhere an
introduction (rather than examples) to this? Books, documents etc.


You could try the reference from the ?plotmath page, but I don't think 
it is a tutorial, which seems to be what you want.


Basically the examples are how to do it.  Learn what expressions are 
like in R, then put together the pieces from demo(plotmath) by building 
expressions containing those pieces.


I don't see anything like sm[w,grass] in the demos, so I would just try 
it to see what happens:  and as you found, it doesn't work.


But there is an example with commas (list(x,y,z)) and an example with 
subscript (x[i]), so you should be able to guess that sm[list(w,grass)] 
would work, and it does!


Duncan Murdoch



--
View this message in context: 
http://r.789695.n4.nabble.com/subscript-with-comma-tp4261579p4261931.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] About source()

2012-01-04 Thread Li SUN
Thanks, guys!

I am using Rscript at the moment and will definitely try littler.

Li Sun



2012/1/4 Rainer M Krug r.m.k...@gmail.com:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 On 04/01/12 10:39, Uwe Ligges wrote:


 On 03.01.2012 21:22, Li SUN wrote:
 Thanks, Rolf, Justin and Uwe!

 Actually I wanted to run .R file as a script, just like what
 people do for bash scripts or python scripts. It seems to me that
 adding #!/usr/bin/R -f at the first line is what I need. Is
 this true?


 Perhaps even Rscript rather than R.

 And there is also littler from Dirk Eddelbüttel:

 http://dirk.eddelbuettel.com/code/littler.html

 - From the description: littler provides hash-bang (i.e. script
 starting with #!/some/path) capability for GNU R, as well as simple
 command-line and piping use.

 Similar to Rscript, but with some differences.

 I used both, and in most cases they are equivalent.


 Rainer



 Uwe Ligges

 Li Sun


 2012/1/2 Rolf Turnerrolf.tur...@xtra.co.nz:
 On 03/01/12 17:02, Li SUN wrote:

 Hello,

 I am a beginner to the R language and find it fantastic and
 well-designed, quite different from other programming
 languages.

 What a refreshingly sensible attitude!!! :-)

 This is the first time I post on the r-help mailing list.

 In invoking the function source(filename), it seems that the
 filename has to exist in the current working directory,
 otherwise it has to be specified in full path. So is there
 any mechanism(such as environment variable) to specify an
 additional directory of .R files that source() could search
 in?


 I'm no expert on this, and others may correct me, but

 (1) I don't believe any such mechanism exists.

 (2) It's probably not a good idea, even if such a mechanism
 were to exist.  Directories have a tree structure, rather than
 being linearly ordered in the way that data bases on your R
 search path are ordered.

 I believe you would run all sorts of risks of confusion and of
 getting the wrong file were you to invoke such a mechanism.

 It is ``good practice'' to have separate directories
 associated with different projects and to situate all files,
 that you might wish to source in respect of a given project, in
 the directory associated with that project.

 I know that this is an irritating sort of response --- ``No,
 you can't do that, and you shouldn't do it anyway!'' --- but I
 sincerely believe this to be true.

 That being said, I also believe that you could program up such
 a mechanism yourself. I.e. build a function source2() which
 would have a hard coded list of directories to search, and
 would make use of the try() function.

 Might be a good exercise for you, given that you are starting
 out in R and looking to upgrade your skills! :-)

 cheers,

 Rolf Turner



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


 - --
 Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
 Biology, UCT), Dipl. Phys. (Germany)

 Centre of Excellence for Invasion Biology
 Stellenbosch University
 South Africa

 Tel :       +33 - (0)9 53 10 27 44
 Cell:       +33 - (0)6 85 62 59 98
 Fax :       +33 - (0)9 58 10 27 44

 Fax (D):    +49 - (0)3 21 21 25 22 44

 email:      rai...@krugs.de

 Skype:      RMkrug
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.4.11 (GNU/Linux)
 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

 iEYEARECAAYFAk8EIs4ACgkQoYgNqgF2egpF+QCeObN8q+U6HHlM/Tsls/wF+VoH
 /twAn2zaTzVrCdTxvENSK2buPlFsjlnC
 =tEkV
 -END PGP SIGNATURE-

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