[R] Need help in doing EMA(Exponential Mean Average).

2012-05-21 Thread Prakash Thomas
Can  somebody help me in finding  package/Example in R which could do
EMA(Exponential Mean Average).
I installed TTR package but the 'EMA function which I was trying to use
is giving the following error.
Error: Could not find function EMA

Thanks  Regards,
Thomas

[[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] system() under windows [x] but not with Mac

2012-05-21 Thread barb
Hey Guys,

i am kind of confused. Under windows the system() function works great, but
not with my mac.
  I have two questions:

1) What do i have to change. Using packages which require system or
eval(parse() everything is fine, but
when i try it myself sh: cmd: command not found
Under windows i use e.g system('cmd /c copy bild.jpg',intern=FALSE )

2) I really love the Hmisc/latex function and want to be able to do it
myself. 
How could i save a text in my notepad as name.txt

Thank you!!

   

--
View this message in context: 
http://r.789695.n4.nabble.com/system-under-windows-x-but-not-with-Mac-tp4630688.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] dot - comma problem, addendum

2012-05-21 Thread may . ka38
I forgot to mention that even after updating all packages on the 64 bit 
opensuse machine running R 2.15, the problem did not vanish.

Thanks so far

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


Re: [R] Stepwise with AICc

2012-05-21 Thread ejulia17
Dear Brian,

I found this in the archives and was going to follow your advice, but can't
get the source code of the function extractAIC you suggest modifying. 
Getting the full source code of stepAIC straight from the R session (by
typing
the function name) was immediate.  Do I need to go down another route to get
to the source of extractAIC?

With thanks for any help you may offer,
Julia

--
View this message in context: 
http://r.789695.n4.nabble.com/Stepwise-with-AICc-tp794758p4630692.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] dot - comma problem

2012-05-21 Thread may . ka38
Thanks for the replies and sorry for the missing information.

@@
System information:

R version 2.15.0 (2012-03-30)
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-suse-linux-gnu (64-bit)


@@
Package informations

ODB

packageDescription(ODB)
Package: ODB
Type: Package
Title: Open Document Databases (.odb) management
Version: 1.0.0
Date: 2011-06-15
Author: Sylvain Mareschal
Maintainer: Sylvain Mareschal mares...@gmail.com
URL: http://www.ovsa.fr/R
Description: This package provides functions to create, connect, update
and query HSQL databases embedded in Open Document Databases
(.odb) files, as OpenOffice and LibreOffice do.
License: GPL (= 3)
LazyLoad: yes
Depends: methods, DBI, RJDBC, XML
SystemRequirements: zip
Packaged: 2011-06-15 19:12:53 UTC; Sylvain
Repository: CRAN
Date/Publication: 2011-06-17 06:44:34
Built: R 2.15.0; ; 2012-04-14 01:59:04 UTC; unix

DBI

 packageDescription(DBI)
Package: DBI
Version: 0.2-5
Title: R Database Interface
Author: R Special Interest Group on Databases (R-SIG-DB)
Maintainer: David A. James daj...@gmail.com
Depends: R (= 2.3.0), methods
Imports: methods
Description: A database interface (DBI) definition for communication
between R and relational database management systems.  All
classes in this package are virtual and need to be extended by
the various R/DBMS implementations.
LazyLoad: yes
License: LGPL (= 2)
Collate: DBI.R Util.R zzz.R
Packaged: 2009-12-21 19:58:17 UTC; sfalcon
Repository: CRAN
Date/Publication: 2009-12-22 07:54:43
Built: R 2.15.0; ; 2012-04-14 01:02:50 UTC; unix


RJDBC

 packageDescription(RJDBC)
Package: RJDBC
Version: 0.2-0
Title: Provides access to databases through the JDBC interface
Author: Simon Urbanek simon.urba...@r-project.org
Maintainer: Simon Urbanek simon.urba...@r-project.org
Depends: methods, DBI, rJava (= 0.4-15), R (= 2.4.0)
Description: RJDBC is an implementation of R's DBI interface using JDBC
as a back-end. This allows R to connect to any DBMS that has a
JDBC driver.
License: GPL-2
URL: http://www.rforge.net/RJDBC/
Repository: CRAN
Date/Publication: 2011-05-17 04:39:36
Built: R 2.15.0; ; 2012-05-20 22:48:53 UTC; unix


XML

 packageDescription(XML)
Package: XML
Version: 3.8-0
Date: 2012/01/12
Author: Duncan Temple Lang (dun...@wald.ucdavis.edu)
Maintainer: Duncan Temple Lang dun...@wald.ucdavis.edu
Title: Tools for parsing and generating XML within R and S-Plus.
Depends: R (= 1.2.0), methods, utils
Imports: methods
Suggests: bitops
SystemRequirements: libxml2 (= 2.6.3)
LazyLoad: yes
Description: This package provides many approaches for both reading and
creating XML (and HTML) documents (including DTDs), both local
and accessible via HTTP or FTP.  It also offers access to an
XPath interpreter.
Note: The versions numbers 1.0 and 2.0 do not have any special
significance, but are merely the result of incrementing the
minor count by 1 for each release. Specifically, there is no
change in the interface.
URL: http://www.omegahat.org/RSXML
License: BSD
Collate: AAA.R DTD.R DTDClasses.R DTDRef.R SAXMethods.S XMLClasses.R
applyDOM.R assignChild.R catalog.R createNode.R dynSupports.R
error.R flatTree.R htmlParse.R nodeAccessors.R parseDTD.R
schema.S summary.R tangle.R toString.S tree.R version.R
xmlErrorEnums.R xmlEventHandler.R xmlEventParse.R xmlHandler.R
xmlInternalSource.R xmlOutputDOM.R xmlNodes.R xmlOutputBuffer.R
xmlTree.R xmlTreeParse.R hashTree.R zzz.R supports.R parser.R
libxmlFeatures.R xmlString.R saveXML.R namespaces.R
readHTMLTable.R reflection.R xmlToDataFrame.R bitList.R
compare.R encoding.R fixNS.R xmlRoot.R serialize.R
xmlMemoryMgmt.R keyValueDB.R solrDocs.R
Repository: CRAN
Date/Publication: 2012-01-14 09:36:02
Built: R 2.14.1; x86_64-suse-linux-gnu; 2012-01-18 02:23:50 UTC; unix

rJava

 packageDescription(rJava)
Package: rJava
Version: 0.9-3
Title: Low-level R to Java interface
Author: Simon Urbanek simon.urba...@r-project.org
Maintainer: Simon Urbanek simon.urba...@r-project.org
Depends: R (= 2.5.0), methods
Description: Low-level interface to Java VM very much like .C/.Call and
friends. Allows creation of objects, calling methods and
accessing fields.
License: GPL-2
URL: http://www.rforge.net/rJava/
SystemRequirements: java
Repository: CRAN
Date/Publication: 2011-12-11 10:41:33
Built: R 2.15.0; x86_64-suse-linux-gnu; 2012-04-14 01:58:28 UTC; unix




hints Brain Ripley: ?Sys.setlocale will explain how to undo the damage.

I checked the content of Sys.getlocale() during various stages. Here is the 
result:

1. Stage: Starting R

R version 2.15.0 (2012-03-30)
Copyright (C) 2012 The R Foundation for Statistical Computing

Re: [R] Names of Greek letters stored as character strings; plotmath.

2012-05-21 Thread peter dalgaard

On May 21, 2012, at 05:25 , Duncan Murdoch wrote:

 On 12-05-20 10:28 PM, Bert Gunter wrote:
 Well, that's not very comforting, Duncan. It's like saying that you
 have to read the engineering specs to drive the car successfully.
 
 I think Robert's message that I responded to was asking for a deeper 
 understanding than simply driving the car.  He appeared to want to know why 
 the car worked the way it did, and describing that entirely in terms of 
 things you can see without opening the hood is hard.

There are levels, though. For basic car driving, it might be sufficient to know 
that turning the steering wheel left makes the car change direction towards 
left. Rather soon, you will realize that it is imortant that it does so by 
turning the front wheels; this explains why you need to reverse into a 
parallel-parking space. At some point, it may become useful to know that the 
wheels are tangential to the curve that the car follows and that it therefore 
turns around a point on the line trough the rear wheels (not that that ever 
helped me to parallel park...).

In R, it is important to have some reasonably accurate mental image of its 
internal structures. For quote() and friends, the thing that you really need is 
the notion of a _parse tree_, i.e. the fact that expressions are not evaluated 
as-is, but first converted (parsed) to an internal structure that is equivalent 
to a list of lists:

 e - quote(2/(3+a))
 e[[1]]
`/`
 e[[2]]
[1] 2
 e[[3]]
(3 + a)
 e[[3]][[1]]
`(`
 e[[3]][[2]]
3 + a
 e[[3]][[2]][[1]]
`+`
 e[[3]][[2]][[2]]
[1] 3
 e[[3]][[2]][[3]]
a

or, graphically (mailer permitting)

`/` +--2
|
+--`(`--`+` +-- 3
|
+-- a

Once you have this concept in mind, it should become fairly clear that the 
string constant a is fundamentally different from the variable name a.

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


[R] for loop, error in model frame.default ... variable lengths differ

2012-05-21 Thread Peter Keller
I'm failing to get a for loop working.  I'm sure it's something simple, and I
have found some posts relating to it, but I'm just not understanding why
this isn't working. 

I have a data frame and would like to loop through specific column names,
using aggregate() within a for loop.  There are NA's scattered throughout
the data frame and I'm thinking it has something to do with that, but I
haven't been able to fix it.

vars - colnames(df)[c(10,12,16,18,20,21,24:29,45)]
 for(i in 1:length(vars)) {
aggregate(colnames(df)[i] ~ x1 + x2 + x3, df, mean,
na.action=na.exclude)
}

I get this error: 
Error in model.frame.default(formula = colnames(df)[i] ~ x1 + x2 +   : 
  variable lengths differ (found for 'x1')

There are probably much better ways to do this, and I would be happy to get
suggestions, but mostly I would like to know why the code isn't working.

Thanks-
Peter

--
View this message in context: 
http://r.789695.n4.nabble.com/for-loop-error-in-model-frame-default-variable-lengths-differ-tp4630698.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] for loop, error in model frame.default ... variable lengths differ

2012-05-21 Thread Jeff Newmiller
No data, not reproducible.

I think you should be using na.omit, though.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Peter Keller keller...@gmail.com wrote:

I'm failing to get a for loop working.  I'm sure it's something simple,
and I
have found some posts relating to it, but I'm just not understanding
why
this isn't working. 

I have a data frame and would like to loop through specific column
names,
using aggregate() within a for loop.  There are NA's scattered
throughout
the data frame and I'm thinking it has something to do with that, but I
haven't been able to fix it.

vars - colnames(df)[c(10,12,16,18,20,21,24:29,45)]
 for(i in 1:length(vars)) {
aggregate(colnames(df)[i] ~ x1 + x2 + x3, df, mean,
na.action=na.exclude)
}

I get this error: 
Error in model.frame.default(formula = colnames(df)[i] ~ x1 + x2 +   : 
  variable lengths differ (found for 'x1')

There are probably much better ways to do this, and I would be happy to
get
suggestions, but mostly I would like to know why the code isn't
working.

Thanks-
Peter

--
View this message in context:
http://r.789695.n4.nabble.com/for-loop-error-in-model-frame-default-variable-lengths-differ-tp4630698.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] Prevent calculation when only NA

2012-05-21 Thread jeff6868
Hi everybody,

I have a small question about R.
I'm doing some correlation matrices between my files. These files contains
each 4 columns of data.
These data files contains missing data too. It could happen sometimes that
in one file, one of the 4 columns contains only missing data NA. As I'm
doing correlations between the same columns of each files, I get a
correlation matrix with a column containing only NAs such like this:

  file1 file 2 file 3
file11   NA0.8
file2NA 1 NA   
file3   0.8 NA 1

For file2, I have no correlation coefficient. 
My function is looking for the highest correlation coefficient for each
file. But I have an error message due to this.
My question is: how can I say to the function: don't do any calculation if
you see only NAs for the file you're working on? The aim of this function is
to automatize this calculation for 300 files.
I tried by adding: na.rm=TRUE, but it stills wants to do the calculation for
the file containing only NAs (error: 0 (non-NA) cases).
Could you tell me what I should add in my function? Thanks a lot!

get.max.cor - function(station, mat){
mat[row(mat) == col(mat)] - -Inf
which( mat[station, ] == max(mat[station, ], na.rm=TRUE) )
 }





--
View this message in context: 
http://r.789695.n4.nabble.com/Prevent-calculation-when-only-NA-tp4630716.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] Bracket matching (was Re: New Eyes Needed to See Syntax Error)

2012-05-21 Thread Patrick Connolly
On Thu, 17-May-2012 at 05:00PM -0700, Rich Shepard wrote:

| On Thu, 17 May 2012, Mercier Eloi wrote:
| 
| Missing a closing parenthesis after log10.
| 
| Eloi,
| 
|   A-ha! I knew new eyes would see what I kept missing.

That example shows the benefit of using a text editor that is designed
for writing code.  Or at least how much time you can spend when you
don't have the bracket matching capability.

As many have mentioned over the years, using ESS with Emacs does that
in additiona to having many other useful extra capabilities, not many
will be imagined until they're seen.  Many people use Tinn-R which has
some of the same capability.




| 
| Many thanks!
| 
| Rich
| 
| -- 
| Richard B. Shepard, Ph.D.  |   Integrity - Credibility - Innovation
| Applied Ecosystem Services, Inc.   |Helping Ensure Our Clients' Futures
| http://www.appl-ecosys.com Voice: 503-667-4517  Fax: 503-667-8863
| 
| __
| R-help@r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-help
| PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
| and provide commented, minimal, self-contained, reproducible code.

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

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


Re: [R] Prevent calculation when only NA

2012-05-21 Thread Jim Lemon

On 05/21/2012 05:59 PM, jeff6868 wrote:

Hi everybody,

I have a small question about R.
I'm doing some correlation matrices between my files. These files contains
each 4 columns of data.
These data files contains missing data too. It could happen sometimes that
in one file, one of the 4 columns contains only missing data NA. As I'm
doing correlations between the same columns of each files, I get a
correlation matrix with a column containing only NAs such like this:

   file1 file 2 file 3
file11   NA0.8
file2NA 1 NA
file3   0.8 NA 1

For file2, I have no correlation coefficient.
My function is looking for the highest correlation coefficient for each
file. But I have an error message due to this.
My question is: how can I say to the function: don't do any calculation if
you see only NAs for the file you're working on? The aim of this function is
to automatize this calculation for 300 files.
I tried by adding: na.rm=TRUE, but it stills wants to do the calculation for
the file containing only NAs (error: 0 (non-NA) cases).
Could you tell me what I should add in my function? Thanks a lot!

get.max.cor- function(station, mat){
 mat[row(mat) == col(mat)]- -Inf
 which( mat[station, ] == max(mat[station, ], na.rm=TRUE) )
  }



Hi Jeff,
Can you use:

if(any(!is.na(mat))) {
...
}

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] plz help. how to filter/group/sort data on mass data

2012-05-21 Thread bestbird
hi, nice people
  I needs to compute the product whose annual sales values are all
among the top 100 using R ( version 2.15.0)
  data is stored in the MSSQL database.
  data structure( sales table's fields): productID, time, value
 I have found the SQL solution below:
SQL solution is as below:
--
WITH sales1 AS (
 SELECT productID, YEAR(time) AS year, SUM(value) AS value1
 FROM sales
 GROUP BY productID, YEAR(time)
)

SELECT productID
FROM (
 SELECT productID
 FROM (
 SELECT productID,RANK() OVER(PARTITION BY year ORDER BY value1 DESC)
rankorder 
FROM sales1 ) T1
 WHERE rankorder=100) T2
GROUP BY productID
HAVING COUNT(*)=(SELECT COUNT(DISTINCT year ) FROM sales1)
--
now, I must solve it using R ( I need stepwise analysis capability in
further ).
I have retrive data from database as below:

 library(RODBC)
 odbcDataSources()
 conn=odbcConnect(sqlsvr)
 result=sqlQuery(conn,'select * from sales')
 odbcClose(conn)
 result
--
But I dont' know how to process next step, such as filter,sort,group
please give me some help.


--
View this message in context: 
http://r.789695.n4.nabble.com/plz-help-how-to-filter-group-sort-data-on-mass-data-tp4630714.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] for loop, error in model frame.default ... variable lengths differ

2012-05-21 Thread Petr PIKAL
Hi

You did not provide data but I can see some problems in your code. See 
inline.
 
 I'm failing to get a for loop working.  I'm sure it's something simple, 
and I
 have found some posts relating to it, but I'm just not understanding why
 this isn't working. 
 
 I have a data frame and would like to loop through specific column 
names,
 using aggregate() within a for loop.  There are NA's scattered 
throughout
 the data frame and I'm thinking it has something to do with that, but I
 haven't been able to fix it.
 
 vars - colnames(df)[c(10,12,16,18,20,21,24:29,45)]
  for(i in 1:length(vars)) {

So i is actually values from 1 to length of vars variable.

 aggregate(colnames(df)[i] ~ x1 + x2 + x3, df, mean,

and you select variables from df[,1] to df[, length(vars)], which is 
probably not what you want.
What is x1-x3? are they variables in df?

 na.action=na.exclude)

for mean the correct statement is na.rm=TRUE

 }
 
 I get this error: 
 Error in model.frame.default(formula = colnames(df)[i] ~ x1 + x2 +   : 
   variable lengths differ (found for 'x1')

Maybe x1 has different length as df. What length(x1) and dim(df) tells 
you?

Regards
Petr

 
 There are probably much better ways to do this, and I would be happy to 
get
 suggestions, but mostly I would like to know why the code isn't working.
 
 Thanks-
 Peter
 
 --
 View this message in context: http://r.789695.n4.nabble.com/for-loop-
 error-in-model-frame-default-variable-lengths-differ-tp4630698.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] Prevent calculation when only NA

2012-05-21 Thread jeff6868
Hi Jim,

Thanks for your answer.
I tried your proposition. The idea seems to be good but I still have my
error.
Actually, the error is in the next function, which uses the function
get.max.cor I told you before.
I also tried these 2 functions with data containing no missing data, and it
works well.
But I think that the next function is doing the calculation by column (it
seems to read each column). 
Do you think it's possible to introduce in the function get.max.cor
something which stops the calculation for a file if there're only NAs in the
correlation matrix for this file, instead of removing the NAs?
For example: if there're only NAs in file2, don't try to do any calculation
with file2 and go to file3 (and so one)?
I think that this is the problem, because even if I remove NAs, it stills
wants to do a calculation. But as there're no numeric values, it gives an
error.


--
View this message in context: 
http://r.789695.n4.nabble.com/Prevent-calculation-when-only-NA-tp4630716p4630722.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] Re : Need help in doing EMA(Exponential Mean Average).

2012-05-21 Thread Pascal Oettli
Hello,

Didi you run
 
library(TTR)

?

Regards



- Mail original -
De : Prakash Thomas pthomas2...@gmail.com
À : r-help@r-project.org
Cc : 
Envoyé le : Lundi 21 mai 2012 15h02
Objet : [R]  Need help in doing EMA(Exponential Mean Average).

Can  somebody help me in finding  package/Example in R which could do
EMA(Exponential Mean Average).
I installed TTR package but the 'EMA function which I was trying to use
is giving the following error.
Error: Could not find function EMA

Thanks  Regards,
Thomas

    [[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] anovas ss typeI vs typeIII

2012-05-21 Thread Helios de Rosario
Hi, you should give more details of your problem (at least some output,
as Peter Daalgard says). But you are probably asking for something like
this:
http://www.r-bloggers.com/anova-%E2%80%93-type-ii-ss-explained/
or many other webpages that you may find if you Google or R-seek with
keywords like anova type i, type iii, etc.

If you have within-subjects factors, the same commands will not give
you a sensible result. If you want to use Anova() for that, you should
use the arguments idata, idesign, etc., as explained in the help
page of that function, or in the web appendix to the CAR book:
http://socserv.mcmaster.ca/jfox/Books/Companion/appendix/Appendix-Multivariate-Linear-Models.pdf

Helios De Rosario



-- 
Helios de Rosario Martínez
 
 Researcher


 El día 20/05/2012 a las 0:58, jacaranda tree
myjacara...@yahoo.com escribió:
 Hi all,
 I have been struggling with ANOVAs on R. I am new to R, so I created
a 
 simple data frame, and I do some analyses on R just to learn R and
then check 
 them on SPSS to make sure that I am doing fine. Here is the problem
that I've 
 run into:
 
 when we use the aov function, it uses SS Type I as default (on SPSS
it is 
 Type III). Then I used the Anova function under cars package using
the 
 command:
 
 mod - lm(DV
 ~ IV1*IV2, data = mydata,
 contrasts=list(IV1=contr.sum,
 IV2=contr.sum))
 Anova(mod, type=”3”)
 
 Above, both of my IVs are between-SS variables. But still, results
from this 
 model do not match the results from SPSS (I have to say they are not
too 
 different either). But I was wondering if I am doing something wrong.
If what 
 I am doing is okay, then my next question is can I use the same set
of 
 commands (for Anova function) if one of my IVs was within-SS and the
other IV 
 was between-SS? 
 
 
 Thank you very much!


INSTITUTO DE BIOMECÁNICA DE VALENCIA
Universidad Politécnica de Valencia • Edificio 9C
Camino de Vera s/n • 46022 VALENCIA (ESPAÑA)
Tel. +34 96 387 91 60 • Fax +34 96 387 91 69
www.ibv.org

  Antes de imprimir este e-mail piense bien si es necesario hacerlo.
En cumplimiento de la Ley Orgánica 15/1999 reguladora de la Protección
de Datos de Carácter Personal, le informamos de que el presente mensaje
contiene información confidencial, siendo para uso exclusivo del
destinatario arriba indicado. En caso de no ser usted el destinatario
del mismo le informamos que su recepción no le autoriza a su divulgación
o reproducción por cualquier medio, debiendo destruirlo de inmediato,
rogándole lo notifique al remitente.

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


Re: [R] for loop, error in model frame.default ... variable lengths differ

2012-05-21 Thread peter dalgaard

On May 21, 2012, at 10:25 , Petr PIKAL wrote:

 Hi
 
 You did not provide data but I can see some problems in your code. See 
 inline.
 
 I'm failing to get a for loop working.  I'm sure it's something simple, 
 and I
 have found some posts relating to it, but I'm just not understanding why
 this isn't working. 
 
 I have a data frame and would like to loop through specific column 
 names,
 using aggregate() within a for loop.  There are NA's scattered 
 throughout
 the data frame and I'm thinking it has something to do with that, but I
 haven't been able to fix it.
 
 vars - colnames(df)[c(10,12,16,18,20,21,24:29,45)]
 for(i in 1:length(vars)) {
 
 So i is actually values from 1 to length of vars variable.
 
aggregate(colnames(df)[i] ~ x1 + x2 + x3, df, mean,
 
 and you select variables from df[,1] to df[, length(vars)], which is 
 probably not what you want.
 What is x1-x3? are they variables in df?
 
 na.action=na.exclude)
 
 for mean the correct statement is na.rm=TRUE
 
}
 
 I get this error: 
 Error in model.frame.default(formula = colnames(df)[i] ~ x1 + x2 +   : 
  variable lengths differ (found for 'x1')
 
 Maybe x1 has different length as df. What length(x1) and dim(df) tells 
 you?
 

colnames(df)[i] is a character vector of length 1. This doesn't work any better 
than

 aggregate(colnames(airquality)[1] ~ Month, airquality, mean, na.rm=T)
Error in model.frame.default(formula = colnames(airquality[1]) ~ Month,  : 
  variable lengths differ (found for 'Month')

What the poster probably wanted was something in the vein of

 nm - colnames(airquality)[1]
 ff - formula(bquote(.(as.name(nm))~Month))
 aggregate(ff, airquality, mean, na.rm=T)
  MonthOzone
1 5 23.61538
2 6 29.4
3 7 59.11538
4 8 59.96154
5 9 31.44828




 Regards
 Petr
 
 
 There are probably much better ways to do this, and I would be happy to 
 get
 suggestions, but mostly I would like to know why the code isn't working.
 
 Thanks-
 Peter
 
 --
 View this message in context: http://r.789695.n4.nabble.com/for-loop-
 error-in-model-frame-default-variable-lengths-differ-tp4630698.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.

-- 
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] for loop, error in model frame.default ... variable lengths differ

2012-05-21 Thread Joshua Wiley
On Mon, May 21, 2012 at 2:00 AM, peter dalgaard pda...@gmail.com wrote:
[snip]
 What the poster probably wanted was something in the vein of

 nm - colnames(airquality)[1]
 ff - formula(bquote(.(as.name(nm))~Month))
 aggregate(ff, airquality, mean, na.rm=T)
  Month    Ozone
 1     5 23.61538
 2     6 29.4
 3     7 59.11538
 4     8 59.96154
 5     9 31.44828

or perhaps to use an implicit loop (since looping seemed to be part of it all):

results - lapply(c(Ozone, Solar.R), function(n) {
  aggregate(. ~ Month, airquality[, c(n, Month)], mean, na.rm = TRUE)
  })

## print results
results


## untested code based on OPs original example
vars - colnames(df)[c(10,12,16,18,20,21,24:29,45)]
results - lapply(vars, function(n) {
  aggregate(. ~ x1 + x2 + x3, df[, c(n, x1, x2, x3)], mean, na.rm = TRUE)
  })

## print results
results

Cheers,

Josh

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

-- 
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] Path to nodes in ctree package party

2012-05-21 Thread tudor
Hi Sven:

Could you find an answer to your post above? I too need to extract the path
to the terminal nodes in a ctree object and could not find a way to do it.

Thanks.

Tudor

--
View this message in context: 
http://r.789695.n4.nabble.com/Path-to-nodes-in-ctree-package-party-tp3042819p4630720.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] Job posting - Statistical Consultant ...

2012-05-21 Thread Martin Maechler
 MMJ == Mahometa, Michael J michael.mahom...@ssc.utexas.edu
 on Wed, 16 May 2012 17:09:31 + writes:

MMJ All, Just to get the word out: We are looking for a new
MMJ Statistical Consultant at .
MM...

MMJ Thanks, Michael

Sorry, but that's ABSOLUTELY  *not* appropriate!

{for one: R-help is international, so many job offers do not
 make sense anyway}.

We have an  R-SIG-jobs  (slight misnomer, yes)  mailing list
   -- http://stat.ethz.ch/mailman/listinfo/r-sig-jobs
for job postings, if you really must use an R mailing list.

Martin Maechler,
site-maintainer of the R-*@r-project.org  mailing lists,
ETH Zurich

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


Re: [R] fitting t copula with fixed dof

2012-05-21 Thread Martin Maechler
   er...@rice.edu
 on Wed, 16 May 2012 12:39:44 -0500 writes:

 I need to fit a t copula with fixed degree of freedom
 let's say 4. I do not want to estimate the dof together
 with correlation matrix optimally. Instead fix the dof to
 4 and only estimate the correlation matrix in the
 optimization routine. Is anyone aware of such estimation
 method in R.

 The packages and functions that I know of can't do this
 estimation. I searched online but couldn't find
 anything. I will appreciate any help/comments.

I searched wrongly.
The copula package has been able to do that for a very long
time. -- fitCopula()

Martin Maechler,
ETH Zurich

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


Re: [R] Prevent calculation when only NA

2012-05-21 Thread jeff6868
Hello Rui,

Thanks for your answer too.
I tried your proposition too, but by giving the value 0 for this file, it
still wants to make a calculation with it. As it is looking for the best
correlation, and then the 2nd best correlation, giving only 0 seems to be a
problem for the 2nd best correlation at least.
Maybe the best way to solve the problem would be to introduce in the
function get.max.cor a line which would delete all the colums containing
only NAs in my correlation matrix? 
For example if my calculated correlation matrix is (imagine that the numeric
values are correlation coefficients for the example):

x - data.frame(a = 1:10, b = c(1:5,NA,7:9, NA), c = 21:30, d = NA)

Maybe is it possible in my function to delete only columns containing 100%
of NA, in order to have a matrix like this:

 x - data.frame(a = 1:10, b = c(1:5,NA,7:9, NA), c = 21:30)

and to keep other columns even if there're some NAs (the calculation is
still possible as they're numeric coefficients in the column).
Actually, it cannot look for the best or the second best correlation
coefficient in a column if it contains only NA.
I think that a correlation matrix like this would allow the calculation for
the next function and the rest of my script.

--
View this message in context: 
http://r.789695.n4.nabble.com/Prevent-calculation-when-only-NA-tp4630716p4630731.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] Rprofile.site under Windows 7?

2012-05-21 Thread Gabor Grothendieck
On Sat, May 5, 2012 at 1:18 AM, Spencer Graves
spencer.gra...@structuremonitoring.com wrote:
 On 5/4/2012 9:27 PM, Duncan Murdoch wrote:

 On 12-05-04 10:33 PM, Joshua Wiley wrote:

 On Fri, May 4, 2012 at 7:17 PM, Duncan Murdochmurdoch.dun...@gmail.com
  wrote:

 On 12-05-04 7:40 PM, Spencer Graves wrote:

 [snip]

        This is almost enough to drive a person to join the I hate
 MicroSoft fan club.


 I think that would just confirm my membership in the I hate Emacs
 club.


 I don't see how this is Emacs fault...


 It claimed to save a file somewhere, but didn't.



      The file was saved, because when I reopened it in Emacs, the changes
 were there.  Windows 7 created a phantom copy, which it delivered to Emacs
 when I clicked and dragged it to the Emacs icon on the task bar.  To fix the
 problem, I copied the file to a non-protected place, opened it and the other
 copy in Emacs, copied the changes from the phantom copy into the
 non-protected copy, then copied the non-protected, edited version into the
 protected, default R installation directory.  I had not encountered this
 problem earlier, because I usually install R in an unprotected location.  I
 got sloppy with R 1.15.0 and accepted the default installation directory.


Do you actually have multiple users on your PC accessing R?  If not,
you could avoid using the Rprofile.site file entirely and just put a
.Rprofile file having the same contents using the %userprofile% folder
for the user who uses R.  That would avoid the problem of writing into
system space.  Alternately save Rprofile.site as Adminstrator.

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


[R] variate generation

2012-05-21 Thread Mohan Radhakrishnan
Hi,

   I plot no: of bytes against time and find the distribution
curve using R. These bytes are sent from the client to the server. 

Is there a way to generate bytes randomly using R according to a
distribution ? I would like to send these bytes to the server. Hope I am
not misguided here. My goal is to simulate a certain distribution of
bytes.

 

Thanks,

Mohan



DISCLAIMER:\ ===...{{dropped:31}}

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


Re: [R] Stepwise with AICc

2012-05-21 Thread Peter Ehlers

On 2012-05-20 16:22, ejulia17 wrote:

Dear Brian,

I found this in the archives and was going to follow your advice, but can't
get the source code of the function extractAIC you suggest modifying.
Getting the full source code of stepAIC straight from the R session (by
typing
the function name) was immediate.  Do I need to go down another route to get
to the source of extractAIC?

With thanks for any help you may offer,
Julia



You probably want extractAIC.lm (see what methods are available
with methods(extractAIC)). Get the code with

 stats:::extractAIC.lm

Peter Ehlers

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


Re: [R] Replace a variable by its value

2012-05-21 Thread anindya55
Thanks Rui...I need chisqtest inside loop , I've given only example code
here.

--
View this message in context: 
http://r.789695.n4.nabble.com/Replace-a-variable-by-its-value-tp4630734p4630737.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] Replace a variable by its value

2012-05-21 Thread anindya55
I have a dataset called raw-data . I am trying to use the following code -


col_name-names(raw_data)
for (i in 1:(length(names(raw_data))-2))
{
  tbl=table(raw_data$Pay.Late.Dummy, raw_data$col_name[i])
  
  chisqtest-chisq.test(tbl)
}


Say the 1st column of my raw_data is Column1. The idea is when i=1 then
raw_data$col_name[i] will automatically become raw_data$Column1 , which is
not happening. Kindly help?

--
View this message in context: 
http://r.789695.n4.nabble.com/Replace-a-variable-by-its-value-tp4630734.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] Prevent calculation when only NA

2012-05-21 Thread Rui Barradas
Hello,

Maybe the function could return a special value, such as zero.
Since a column with that number doesn't exist, the code executed afterward
would simply move on to the second greatest correlation.
The function would then become

get.max.cor - function(station, mat){
  mat[row(mat) == col(mat)] - -Inf
if(sum(is.na(mat[station, ])) == ncol(mat) - 1)
0
else
which( mat[station, ] == max(mat[station, ], na.rm=TRUE) )
}

df1 - read.table(text=
  file1 file2 file3
file11   NA0.8
file2NA 1 NA  
file3   0.8 NA 1
, header=TRUE)

get.max.cor(file2, df1)


Hope this helps,

Rui Barradas

jeff6868 wrote
 
 Hi everybody,
 
 I have a small question about R.
 I'm doing some correlation matrices between my files. These files contains
 each 4 columns of data.
 These data files contains missing data too. It could happen sometimes that
 in one file, one of the 4 columns contains only missing data NA. As I'm
 doing correlations between the same columns of each files, I get a
 correlation matrix with a column containing only NAs such like this:
 
   file1 file 2 file 3
 file11   NA0.8
 file2NA 1 NA   
 file3   0.8 NA 1
 
 For file2, I have no correlation coefficient. 
 My function is looking for the highest correlation coefficient for each
 file. But I have an error message due to this.
 My question is: how can I say to the function: don't do any calculation if
 you see only NAs for the file you're working on? The aim of this function
 is to automatize this calculation for 300 files.
 I tried by adding: na.rm=TRUE, but it stills wants to do the calculation
 for the file containing only NAs (error: 0 (non-NA) cases).
 Could you tell me what I should add in my function? Thanks a lot!
 
 get.max.cor - function(station, mat){
 mat[row(mat) == col(mat)] - -Inf
 which( mat[station, ] == max(mat[station, ], na.rm=TRUE) )
  }
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Prevent-calculation-when-only-NA-tp4630716p4630728.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] removing only rows/columns with na value from square ( symmetrical ) matrix.

2012-05-21 Thread Nevil Amos
Yes  the matrix is symmetric 
Gabor provided a partial solution:
Try this:

ix - na.action(na.omit(replace(M, upper.tri(M), 0)))
M[-ix, -ix]

However this removes all rows containing an NA in the lower half of the matrix 
- even if the corresponding column has also been removed

I I have revised the example to show this.

thanks all for you help

in the below case I would like to retain row and column 
[c(1:5,7,8,10:12),c(1:5,7,8,10:12)]
M-matrix(sample(144),12,12)
M[10,9]-NA
M-as.matrix(as.dist(M))
N=M
#the above rows are to create the symmetric matrix M and a copy N
M[6,]-NA
M[,6]-NA
#above two rows - make corresponding row and column NA
print (M)
ix - na.action(na.omit(replace(M, upper.tri(M), 0)))
M-M[-ix, -ix]
print (M)

print (however what I would like to retain is the maximum amout of data while 
removing rows or columns containing NA  ie:)
print(N [c(1:5,7,8,10:12),c(1:5,7,8,10:12)])

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

thanks to all
On 21/05/2012, at 1:10 AM, peter dalgaard wrote:

 
 On May 20, 2012, at 16:37 , Bert Gunter wrote:
 
 Your problem is not well-defined. In your example below, why not
 remove rows 1,2,6, and 10, all of which contain NA's? Is the matrix
 supposed to be symmetric?
YES

 Do NA's always occur symmetrically?
YES
 
 ...and even if they do, how do you decide whether to remove row/col 9 or 
 row/col 10 in the example? (Or, for that matter, between (1 and 2) and 6. In 
 that case you might chose to remove the smallest no. of row/cols but in 9 
 vs. 10, the situation is completely symmetric.) 
 
 
 You either need to rethink what you want to do or clarify your statement of 
 it.
 
 -- Bert
 
 On Sun, May 20, 2012 at 7:17 AM, Nevil Amos nevil.a...@monash.edu wrote:
 I have some square matrices with na values in corresponding rows and
 columns.
 
 M-matrix(1:2,10,10)
 M[6,1:2]-NA
 M[10,9]-NA
 M-as.matrix(as.dist(M))
 print (M)
 
   1 2 3 4 5 6 7 8 9 10
 1   0  2 1 2 1 NA 1 2  1  2
 2   2  0 1 2 1 NA 1 2  1  2
 3   1  1 0 2 1  2 1 2  1  2
 4   2  2 2 0 1  2 1 2  1  2
 5   1  1 1 1 0  2 1 2  1  2
 6  NA NA 2 2 2  0 1 2  1  2
 7   1  1 1 1 1  1 0 2  1  2
 8   2  2 2 2 2  2 2 0  1  2
 9   1  1 1 1 1  1 1 1  0 NA
 10  2  2 2 2 2  2 2 2 NA  0
 
 
 How do I remove just the row/column pair( in this trivial example row 6 and
 10 and column 6 and 10) containing the NA values?
 
 so that I end up with all rows/ columns that are not NA - e.g.
 
 1 2 3 4 5 7 8 9
 1 0 2 1 2 1 1 2 1
 2 2 0 1 2 1 1 2 1
 3 1 1 0 2 1 1 2 1
 4 2 2 2 0 1 1 2 1
 5 1 1 1 1 0 1 2 1
 7 1 1 1 1 1 0 2 1
 8 2 2 2 2 2 2 0 1
 9 1 1 1 1 1 1 1 0
 
 
 if i use na omit I lose rows 1,2,6, and 9
 which is not what I want.
 
 thanks
 --
 Nevil Amos
 Molecular Ecology Research Group
 Australian Centre for Biodiversity
 Monash University
 CLAYTON VIC 3800
 Australia
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 
 -- 
 
 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.
 
 -- 
 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
 
 
 
 
 
 
 
 


[[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] Prevent calculation when only NA

2012-05-21 Thread Rui Barradas
Try this.

check.na - function(mat){
nas - NULL
for(st in seq.int(ncol(mat)))
if(sum(is.na(mat[, st])) == nrow(mat) - 1) nas - c(nas, st)
if(length(nas)){
mat - mat[, -nas]
mat - mat[-nas, ]
}
mat
}

check.na(df1)
  file1 file3
file1   1.0   0.8
file3   0.8   1.0

Note that you must remove both the columns and the rows, it's a correlation
matrix.
And that's also why the 'ncol(mat) minus 1', the diagonal value need not be
NA.

Rui Barradas

jeff6868 wrote
 
 Hello Rui,
 
 Thanks for your answer too.
 I tried your proposition too, but by giving the value 0 for this file, it
 still wants to make a calculation with it. As it is looking for the best
 correlation, and then the 2nd best correlation, giving only 0 seems to be
 a problem for the 2nd best correlation at least.
 Maybe the best way to solve the problem would be to introduce in the
 function get.max.cor a line which would delete all the colums containing
 only NAs in my correlation matrix? 
 For example if my calculated correlation matrix is (imagine that the
 numeric values are correlation coefficients for the example):
 
 x - data.frame(a = 1:10, b = c(1:5,NA,7:9, NA), c = 21:30, d = NA)
 
 Maybe is it possible in my function to delete only columns containing 100%
 of NA, in order to have a matrix like this:
 
  x - data.frame(a = 1:10, b = c(1:5,NA,7:9, NA), c = 21:30)
 
 and to keep other columns even if there're some NAs (the calculation is
 still possible as they're numeric coefficients in the column).
 Actually, it cannot look for the best or the second best correlation
 coefficient in a column if it contains only NA.
 I think that a correlation matrix like this would allow the calculation
 for the next function and the rest of my script.
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Prevent-calculation-when-only-NA-tp4630716p4630732.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 extrapolation using data from imported text file

2012-05-21 Thread Andras Farkas
Dear R experts,
 
I am trying to do linear extrapolation on a dataset like the attached document. 
I looked at the approx and approxfun function that seem to do this function, 
but not fully understand them. I was wondering if someone could help with 
writing commands to do the following based on the attached file's example:
 
ID#1 and ID #2 both have response parameters (MEASUREMENT in the Book1.txt 
file) for a given time point (TIME (hours) in the Book1.txt file). Using 
linear extrapolation I would like to be able to compute the percent time spent 
in the MEASUREMENT range of 9 to 10, for ID#1 and ID#2, together 
and individually.  
 
in the attached simple example, if I did the calculation then the results 
would be:
 
1;  66% for ID #1 and 100% for ID#2, individually. This is the 1st value I 
would like to compute
 
2; Combined together the results would be the average of 66% and 100%, which 
equals to  83%, This is the 2nd value I would like to compute
 
all of your help is apreciated,
 
thanks,
 
AndrasID# TIME (hours)MEASUREMENT
1   0   8
1   24  9
1   48  10
1   72  9
2   0   9
2   24  10
2   48  10
2   72  10
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Replace a variable by its value

2012-05-21 Thread Rui Barradas
Hello,

Your doubt is a frequent one. 'col_name' is a character vector, it's
elements are character strings, not symbols.
These are all equivalent, and are what you want.

raw_data[[ col_name[i] ]]  # using a list-like syntax (data.frame subclasses
list)
raw_data[ , col_name[i] ]  # seems more like a rowscolumns data structure
raw_data[ , i ]  # using the column number

Two notes.
One, it's better to use seq.int than to use 1:length(...) because if the
length is zero, the second form will become the vector 1:0 == c(1, 0) and
your loop will execute with wrong results. See the help page for seq.int

?seq.int
seq.int(length(col_name) - 2)


The other, you're rewriting the value of 'chisqtest' every time through the
loop. If you only want the test results inside it, that's ok, if not, maybe
you could keep the results in a list, using something like


chisqtest - vector(list, length(col_name) - 2)  # create the list before
the loop
for (i in seq.int(length(col_name) - 2))
{ 
  [... loop code ...]

  chisqtest[[ i ]] - chisq.test(tbl) 
}


Hope this helps,

Rui Barradas

anindya55 wrote
 
 I have a dataset called raw-data . I am trying to use the following code
 -
 
 
 col_name-names(raw_data)
 for (i in 1:(length(names(raw_data))-2))
 {
   tbl=table(raw_data$Pay.Late.Dummy, raw_data$col_name[i])
   
   chisqtest-chisq.test(tbl)
 }
 
 
 Say the 1st column of my raw_data is Column1. The idea is when i=1 then
 raw_data$col_name[i] will automatically become raw_data$Column1 , which is
 not happening. Kindly help?
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Replace-a-variable-by-its-value-tp4630734p4630736.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] Replace a variable by its value

2012-05-21 Thread Petr PIKAL
Hi

 
 I have a dataset called raw-data . I am trying to use the following 
code -
 
 
 col_name-names(raw_data)
 for (i in 1:(length(names(raw_data))-2))
 {
   tbl=table(raw_data$Pay.Late.Dummy, raw_data$col_name[i])
 
   chisqtest-chisq.test(tbl)
 }
 
 
 Say the 1st column of my raw_data is Column1. The idea is when i=1 then
 raw_data$col_name[i] will automatically become raw_data$Column1 , which 
is

Why do you think so? raw_data$col_name[i] is most probably one value.

Maybe you want

tbl=table(raw_data$Pay.Late.Dummy, raw_data[,i])

Regards
Petr


 not happening. Kindly help?
 
 --
 View this message in context: http://r.789695.n4.nabble.com/Replace-a-
 variable-by-its-value-tp4630734.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] Need Help in K-fold validation in Decision tree

2012-05-21 Thread santoshdvn
Hi ,

I have built decision tree using  rpart . I want to do k Fold validation on
the decision tree .

Could you help how can i do that .. please tell the package which required
for K fold validation.

Regards,
Santosh 

--
View this message in context: 
http://r.789695.n4.nabble.com/Need-Help-in-K-fold-validation-in-Decision-tree-tp4630730.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] htmlParse Error

2012-05-21 Thread vioravis
I am trying to parse a webpage using the htmlParse command in XML package as
follows:

library(XML)
u = http://en.wikipedia.org/wiki/World_population;
doc = htmlParse(u)

I get the following error:

Error in htmlParse(u) : 
  error in creating parser for http://en.wikipedia.org/wiki/World_population

I am using a R 2.13.1 (32 bit version) on a 64 bit Windows. (I tried
installing it in 64 bit version of R but getting an error that the previous
version cannot be removed)

Can someone please help with how to resolve this issue? 

Thank you.

Ravi


--
View this message in context: 
http://r.789695.n4.nabble.com/htmlParse-Error-tp4630738.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] removeing only rows/columns with na value from square ( symmetrical ) matrix.

2012-05-21 Thread Gabor Grothendieck
On Sun, May 20, 2012 at 10:54 AM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 On Sun, May 20, 2012 at 10:52 AM, Gabor Grothendieck
 ggrothendi...@gmail.com wrote:
 On Sun, May 20, 2012 at 10:17 AM, Nevil Amos nevil.a...@monash.edu wrote:
 I have some square matrices with na values in corresponding rows and
 columns.

 M-matrix(1:2,10,10)
 M[6,1:2]-NA
 M[10,9]-NA
 M-as.matrix(as.dist(M))
 print (M)

    1 2 3 4 5 6 7 8 9 10
 1   0  2 1 2 1 NA 1 2  1  2
 2   2  0 1 2 1 NA 1 2  1  2
 3   1  1 0 2 1  2 1 2  1  2
 4   2  2 2 0 1  2 1 2  1  2
 5   1  1 1 1 0  2 1 2  1  2
 6  NA NA 2 2 2  0 1 2  1  2
 7   1  1 1 1 1  1 0 2  1  2
 8   2  2 2 2 2  2 2 0  1  2
 9   1  1 1 1 1  1 1 1  0 NA
 10  2  2 2 2 2  2 2 2 NA  0


 How do I remove just the row/column pair( in this trivial example row 6 and
 10 and column 6 and 10) containing the NA values?

 so that I end up with all rows/ columns that are not NA - e.g.

  1 2 3 4 5 7 8 9
 1 0 2 1 2 1 1 2 1
 2 2 0 1 2 1 1 2 1
 3 1 1 0 2 1 1 2 1
 4 2 2 2 0 1 1 2 1
 5 1 1 1 1 0 1 2 1
 7 1 1 1 1 1 0 2 1
 8 2 2 2 2 2 2 0 1
 9 1 1 1 1 1 1 1 0


 Try this:

 ix - na.action(na.omit(replace(M, upper.tri(M), 0)))
 M[-ix, -ix]

 and here is a minor variation which is slightly shorter:

 ix - complete.cases(replace(M, upper.tri(M), 0))
 M[ix, ix]


Please keep all follow ups on the original thread.

Here is a greedy algorithm to iteratively drop the column and row with
the most NAs.

dropNA - function(M) {
   while(any(is.na(M))) {
  ix - which.max(colSums(is.na(M)))
  M - M[-ix, -ix]
   }
   M
}

dropNA(M)

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at 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] removing only rows/columns with na value from square ( symmetrical ) matrix.

2012-05-21 Thread Petr PIKAL
Hi

You can do it by hand and remove row/col with max number of NA values.

rem-which.max(colSums(is.na(M)))
M1-M[-rem, -rem]
rem-which.max(colSums(is.na(M1)))
M2-M1[-rem, -rem]
M2
 1   2  3   4  5   7   8  10  11  12
10 143 92 134 42 123  40 107  49  93
2  143   0 77   6 99  46  47 114 138  82
3   92  77  0   2 89  24  62  59  97  52
4  134   6  2   0 71  23  43  80  35  86
5   42  99 89  71  0  68  95  27  55  14
7  123  46 24  23 68   0 124  18  53 101
8   40  47 62  43 95 124   0 126  11 129
10 107 114 59  80 27  18 126   0  31  13
11  49 138 97  35 55  53  11  31   0  75
12  93  82 52  86 14 101 129  13  75   0

I believe this can be transformed to cycle in which you need to test 
whether there is any NA for ending a cycle or not starting it if there is 
no NA values.

Regards
Petr

 Yes  the matrix is symmetric 
 Gabor provided a partial solution:
 Try this:
 
 ix - na.action(na.omit(replace(M, upper.tri(M), 0)))
 M[-ix, -ix]
 
 However this removes all rows containing an NA in the lower half of the 
 matrix - even if the corresponding column has also been removed
 
 I I have revised the example to show this.
 
 thanks all for you help
 
 in the below case I would like to retain row and column [c(1:5,7,8,10:
 12),c(1:5,7,8,10:12)]
 M-matrix(sample(144),12,12)
 M[10,9]-NA
 M-as.matrix(as.dist(M))
 N=M
 #the above rows are to create the symmetric matrix M and a copy N
 M[6,]-NA
 M[,6]-NA
 #above two rows - make corresponding row and column NA
 print (M)
 ix - na.action(na.omit(replace(M, upper.tri(M), 0)))
 M-M[-ix, -ix]
 print (M)
 
 print (however what I would like to retain is the maximum amout of data 

 while removing rows or columns containing NA  ie:)
 print(N [c(1:5,7,8,10:12),c(1:5,7,8,10:12)])
 
 -- 
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at gmail.com
 
 thanks to all
 On 21/05/2012, at 1:10 AM, peter dalgaard wrote:
 
  
  On May 20, 2012, at 16:37 , Bert Gunter wrote:
  
  Your problem is not well-defined. In your example below, why not
  remove rows 1,2,6, and 10, all of which contain NA's? Is the matrix
  supposed to be symmetric?
 YES
 
  Do NA's always occur symmetrically?
 YES
  
  ...and even if they do, how do you decide whether to remove row/col 9 
or
 row/col 10 in the example? (Or, for that matter, between (1 and 2) and 
6. 
 In that case you might chose to remove the smallest no. of row/cols but 
in
 9 vs. 10, the situation is completely symmetric.) 
  
  
  You either need to rethink what you want to do or clarify your 
statement of it.
  
  -- Bert
  
  On Sun, May 20, 2012 at 7:17 AM, Nevil Amos nevil.a...@monash.edu 
wrote:
  I have some square matrices with na values in corresponding rows and
  columns.
  
  M-matrix(1:2,10,10)
  M[6,1:2]-NA
  M[10,9]-NA
  M-as.matrix(as.dist(M))
  print (M)
  
1 2 3 4 5 6 7 8 9 10
  1   0  2 1 2 1 NA 1 2  1  2
  2   2  0 1 2 1 NA 1 2  1  2
  3   1  1 0 2 1  2 1 2  1  2
  4   2  2 2 0 1  2 1 2  1  2
  5   1  1 1 1 0  2 1 2  1  2
  6  NA NA 2 2 2  0 1 2  1  2
  7   1  1 1 1 1  1 0 2  1  2
  8   2  2 2 2 2  2 2 0  1  2
  9   1  1 1 1 1  1 1 1  0 NA
  10  2  2 2 2 2  2 2 2 NA  0
  
  
  How do I remove just the row/column pair( in this trivial example 
row 6 and
  10 and column 6 and 10) containing the NA values?
  
  so that I end up with all rows/ columns that are not NA - e.g.
  
  1 2 3 4 5 7 8 9
  1 0 2 1 2 1 1 2 1
  2 2 0 1 2 1 1 2 1
  3 1 1 0 2 1 1 2 1
  4 2 2 2 0 1 1 2 1
  5 1 1 1 1 0 1 2 1
  7 1 1 1 1 1 0 2 1
  8 2 2 2 2 2 2 0 1
  9 1 1 1 1 1 1 1 0
  
  
  if i use na omit I lose rows 1,2,6, and 9
  which is not what I want.
  
  thanks
  --
  Nevil Amos
  Molecular Ecology Research Group
  Australian Centre for Biodiversity
  Monash University
  CLAYTON VIC 3800
  Australia
  
[[alternative HTML version deleted]]
  
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
  
  
  
  -- 
  
  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.
  
  -- 
  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
  
  
  
  
  
  
  
  
 
 
[[alternative HTML version deleted]]
 
 __
 R-help@r-project.org 

[R] all occurences of an element in a vector

2012-05-21 Thread carol white
Hi,
How do you identify all occurences of an element or a sub-vector in a vector as 
opposed to match, %in%, and intersect which find the first occurrence of an 
element?

Cheers,

Carol

[[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] system() under windows [x] but not with Mac

2012-05-21 Thread David Winsemius


On May 20, 2012, at 6:49 PM, barb wrote:


Hey Guys,

i am kind of confused. Under windows the system() function works  
great, but

not with my mac.
 I have two questions:

1) What do i have to change. Using packages which require system or
eval(parse() everything is fine, but
when i try it myself sh: cmd: command not found
Under windows i use e.g system('cmd /c copy bild.jpg',intern=FALSE )


There is no 'cmd' system function in MacOSX.

system(cp q.csv q2.csv)  # succeeds in making a copy of an existing  
file in the working directory




2) I really love the Hmisc/latex function and want to be able to do it
myself.
   How could i save a text in my notepad as name.txt


I do not understand what the problem is. What is meant by do it?  
What is the notepad?





--

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] Prevent calculation when only NA

2012-05-21 Thread jeff6868
I tried your function. It works great thanks. I used then diag() in order to
have the value 1 for the whole diagonal of my matrix. But it still doesn't
work it's crazy.
By deleting colums and rows (and so some files) containing only NAs in the
correlation matrix, it doesn't work when I apply the function, because I'm
working on a list of files.
By deleting the files in the correlation matrix, it cannot apply the
function on the list.files (dimensions are different if I delete some files
in the correlation). And as I don't know before the calculation which files
are going to contain these NA columns and rows, I have to do it on another
way. 
I think I should first select the files for my list (and for the
correlation) which contains at least for example 1000 numeric values in a
certain array in order to calculate my correlations. But i'll post it in
another topic.


--
View this message in context: 
http://r.789695.n4.nabble.com/Prevent-calculation-when-only-NA-tp4630716p4630752.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] merging unbalanced rows

2012-05-21 Thread Belay Gebregiorgis
Hi Everyone,

I am merging two data frames that have different number of rows. But I end
up having rows a lot more than  both rows combined. I tried the following
but the duplicate bit does not change anything. Can anyone suggest to me
how I can handle this?

Regards,
Belay


x -c(1, 2, 3, 4,5, NA, NA,NA,NA,10)
y -c( NA, 4,NA,5,2, 10, 7, 1, 8, 9)
d-1:10  this one belongs to the data frame a
d-1:5  this one belongs to the data frame b
s1-1:5
s2-6:10

a-data.frame(x,y,d)
b- data.frame(s1,s2,d)

c-merge(a, b, by=c(d))

c[!duplicated(c[,c(x,y)]),]

[[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] removeing only rows/columns with na value from square ( symmetrical ) matrix.

2012-05-21 Thread Rui Barradas

Hello,

Try

while(TRUE){
ix - apply(M, 2, function(x) sum(is.na(x)))
if(all(ix == 0)) break
ix - max(which(ix == max(ix)))
M - M[-ix , -ix]
}
M

Note that in the original there's really no difference between columns 9 
and 10.
If in the above code you use 'min', column 9 is removed and it's still a 
minimum of removals.

(Like in any case of a tie.)

Hope this helps,

Rui Barradas

Em 21-05-2012 11:00, Nevil Amos nevil.a...@monash.edu escreveu:

Date: Mon, 21 May 2012 00:17:10 +1000
From: Nevil Amosnevil.a...@monash.edu
To:r-help@r-project.org
Subject: [R] removeing only rows/columns with na value from square (
symmetrical ) matrix.
Message-ID:
CAGUDtZJOW7x3sjZsnqf7uAQN6gKFg+EMqq=-hbqkgcwggaj...@mail.gmail.com
Content-Type: text/plain

I have some square matrices with na values in corresponding rows and
columns.

M-matrix(1:2,10,10)
M[6,1:2]-NA
M[10,9]-NA
M-as.matrix(as.dist(M))
print (M)

 1  2 3 4 5  6 7 8  9 10
1   0  2 1 2 1 NA 1 2  1  2
2   2  0 1 2 1 NA 1 2  1  2
3   1  1 0 2 1  2 1 2  1  2
4   2  2 2 0 1  2 1 2  1  2
5   1  1 1 1 0  2 1 2  1  2
6  NA NA 2 2 2  0 1 2  1  2
7   1  1 1 1 1  1 0 2  1  2
8   2  2 2 2 2  2 2 0  1  2
9   1  1 1 1 1  1 1 1  0 NA
10  2  2 2 2 2  2 2 2 NA  0


How do I remove just the row/column pair( in this trivial example row 6 and
10 and column 6 and 10) containing the NA values?

so that I end up with all rows/ columns that are not NA - e.g.

   1 2 3 4 5 7 8 9
1 0 2 1 2 1 1 2 1
2 2 0 1 2 1 1 2 1
3 1 1 0 2 1 1 2 1
4 2 2 2 0 1 1 2 1
5 1 1 1 1 0 1 2 1
7 1 1 1 1 1 0 2 1
8 2 2 2 2 2 2 0 1
9 1 1 1 1 1 1 1 0


if i use na omit I lose rows 1,2,6, and 9
which is not what I want.

thanks
-- Nevil Amos Molecular Ecology Research Group Australian Centre for 
Biodiversity Monash University CLAYTON VIC 3800 Australia 
[[alternative HTML version deleted]]


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


Re: [R] all occurences of an element in a vector

2012-05-21 Thread Ista Zahn
Hi Carol,

I'm not sure what a sub-vector in a vector is, but I think you might
be looking for ?grep

Best,
Ista

On Mon, May 21, 2012 at 9:20 AM, carol white wht_...@yahoo.com wrote:
 Hi,
 How do you identify all occurences of an element or a sub-vector in a vector 
 as opposed to match, %in%, and intersect which find the first occurrence of 
 an element?

 Cheers,

 Carol

        [[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] Need Help in K-fold validation in Decision tree

2012-05-21 Thread Steve Lianoglou
Hi,

On Mon, May 21, 2012 at 6:01 AM, santoshdvn santosh...@gmail.com wrote:
 Hi ,

 I have built decision tree using  rpart . I want to do k Fold validation on
 the decision tree .

 Could you help how can i do that .. please tell the package which required
 for K fold validation.

I think you'll find the caret package, along with its vignettes, very helpful:

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

If you google for caret machine learning you'll find many useful
links. For instance:

* The JSS Publication:
http://www.jstatsoft.org/v28/i05/paper

* Slides from a presentation of caret:
http://files.meetup.com/1542972/Max_caret_NYCPA.pdf


HTH,
-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Syntax for lme function to model random factors and interactions

2012-05-21 Thread i_like_macs
Hello,

I have a question regarding the syntax of the lme function in the nlme
package. What I'm trying to do is to calculate an estimate of R^2 based on
the likelihood ratio test. For this calculation, I need to determine the
maximum log-likelihood of the intercept-only model and the model of interest
(with the desired factors and interactions).

My model has four independent factors (i.e. A, B, C and D). A and B are
fixed factors, whilst C and D are random factors. 

Presently, I'm trying to code the lme function for the full ANOVA model, but
am unsure how to code both random factors. Additionally, I'm unsure whether
I coded the interactions correctly (i.e. I'm unsure whether the interactions
which contain random factors also need to be specified in the random
argument). I've skimmed through the Pinheiro and Bates book, Mixed-Effects
Models in S and S-PLUS, but could not find an answer.

My R code for the lme function which includes all the main factors and
interactions (2- and 3-way) so far is:

lme(Y ~ A +
B + 
C + 
D + 
A * B + 
A * C + 
A * D + 
B * C + 
B * D + 
C * D + 
A * B * C + 
A * B * D + 
A * C * D + 
B * C * D,
data = myData,
random = ~ 1|C,
method = ML)

Can someone help me with how to code the random factors and interactions
which contain these random factors please? I apologise in advance, that I am
self-taught in statistics, and just started using R. Hence I hope my
question made sense. Thank you very much.

Daisuke Koya
Confused PhD student

--
View this message in context: 
http://r.789695.n4.nabble.com/Syntax-for-lme-function-to-model-random-factors-and-interactions-tp4630744.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] Replace a variable by its value

2012-05-21 Thread anindya55
Sorry, wasn't clear .. .Rui's code as worked

--
View this message in context: 
http://r.789695.n4.nabble.com/Replace-a-variable-by-its-value-tp4630734p4630748.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] Changing selected elements of an array

2012-05-21 Thread Øystein Godøy
Hi!

I have a matrix defined on geographical positions (through) row and column 
names. I need to change a number of elements in this matrix using the 
information of a data.frame containing geographical positions and a number of 
variables.

Changing the value of one specific element is easy, but changing on a number 
of selected positions seems more difficult. When I use the geographical 
positions of the data.frame as index, blobs are changed and not individual 
elements.

How can I circumvent this feature of R?

E.g: in this situation I would like the downward diagonal to be changed, not 
the square box...

 tmpmat - 
matrix(NA,nrow=9,ncol=10,dimnames=list(formatC(tmplat,format=f,digits=2),formatC(tmplon,format=f,digits=2)))
 tmpmat
  8.00 9.50 9.75 14.25 15.00 15.75 18.00 20.50 21.75 25.25
55.25   NA   NA   NANANANANANANANA
56.75   NA   NA   NANANANANANANANA
57.75   NA   NA   NANANANANANANANA
58.00   NA   NA   NANANANANANANANA
59.50   NA   NA   NANANANANANANANA
62.75   NA   NA   NANANANANANANANA
64.50   NA   NA   NANANANANANANANA
66.25   NA   NA   NANANANANANANANA
67.25   NA   NA   NANANANANANANANA
 tmpmat[c(58.00,59.50,62.75),c(15.00,15.75,18.00)] - 300
 tmpmat
  8.00 9.50 9.75 14.25 15.00 15.75 18.00 20.50 21.75 25.25
55.25   NA   NA   NANANANANANANANA
56.75   NA   NA   NANANANANANANANA
57.75   NA   NA   NANANANANANANANA
58.00   NA   NA   NANA   300   300   300NANANA
59.50   NA   NA   NANA   300   300   300NANANA
62.75   NA   NA   NANA   300   300   300NANANA
64.50   NA   NA   NANANANANANANANA
66.25   NA   NA   NANANANANANANANA
67.25   NA   NA   NANANANANANANANA

While I wanted:
 tmpmat
  8.00 9.50 9.75 14.25 15.00 15.75 18.00 20.50 21.75 25.25
55.25   NA   NA   NANANANANANANANA
56.75   NA   NA   NANANANANANANANA
57.75   NA   NA   NANANANANANANANA
58.00   NA   NA   NANA   300NA   NANANANA
59.50   NA   NA   NANANA   300   NANANANA
62.75   NA   NA   NANANANA   300NANANA
64.50   NA   NA   NANANANANANANANA
66.25   NA   NA   NANANANANANANANA
67.25   NA   NA   NANANANANANANANA

All the best
Øystein
-- 
Dr. Oystein Godoy
Norwegian Meteorological Institute 
P.O.BOX 43, Blindern, N-0313 OSLO, Norway
Ph: (+47) 2296 3000 (switchb) 2296 3334 (direct line)
Fax:(+47) 2296 3050 Institute home page: http://met.no/

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


Re: [R] Implementing a Kalman filter in R

2012-05-21 Thread Giovanni Petris

In addition to the papers suggested by Roy, if you are interested in a
book-length treatment of state space models and Kalman filter in R, I
would look at

 http://www.springer.com/978-0-387-77237-0

And I would carry out the implementation in R using package dlm

Just my (biased) 2 cents

Best,
Giovanni

On Sat, 2012-05-19 at 08:49 -0700, Roy Mendelssohn wrote:
 Hi Teo:
 
 On May 19, 2012, at 6:57 AM, mala10af wrote:
 
  Hi all,
  
  I am a student and I ma writing my master thesis about oil and gasoline
  options. In my master thesis I would like to estimate some parameter of the
  oil market. I base my pricing models according to Schwartz (1997). In order
  to get those data a I need to run a Kalman filter algorith with mximisation
  of the likelihodd. I am not that familiar with R. Can any of you suggestment
  a basic code to run the kalman filter´, so I can use it as a starting point
  to build up more complex one? Does any of you can suggest me a good book
  about R?
  
  Thank you for your help.
  
  Teo
 
 See:
 
 http://www.jstatsoft.org/v41/i04
 
 and
 
 http://www.jstatsoft.org/v39/i02
 
 -Roy
 
 
 \**
 The contents of this message do not reflect any position of the U.S. 
 Government or NOAA.
 **
 Roy Mendelssohn
 Supervisory Operations Research Analyst
 NOAA/NMFS
 Environmental Research Division
 Southwest Fisheries Science Center
 1352 Lighthouse Avenue
 Pacific Grove, CA 93950-2097
 
 e-mail: roy.mendelss...@noaa.gov (Note new e-mail address)
 voice: (831)-648-9029
 fax: (831)-648-8440
 www: http://www.pfeg.noaa.gov/
 
 Old age and treachery will overcome youth and skill.
 From those who have been given much, much will be expected 
 the arc of the moral universe is long, but it bends toward justice -MLK Jr.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] all occurences of an element in a vector

2012-05-21 Thread carol white
like searching m or [m,n] in [1,n,m,e,m,n,n,u].

I want the exact match of all occurrences of m and n in the last vector. 
Therefore, grep is not helpful as it will extract if there are also mm and mmm.

Cheers,

Carol



 From: Ista Zahn istaz...@gmail.com

Cc: r-h...@stat.math.ethz.ch r-h...@stat.math.ethz.ch 
Sent: Monday, May 21, 2012 3:38 PM
Subject: Re: [R] all occurences of an element in a vector

Hi Carol,

I'm not sure what a sub-vector in a vector is, but I think you might
be looking for ?grep

Best,
Ista


 Hi,
 How do you identify all occurences of an element or a sub-vector in a vector 
 as opposed to match, %in%, and intersect which find the first occurrence of 
 an element?

 Cheers,

 Carol

        [[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] Syntax for lme function to model random factors and interactions

2012-05-21 Thread Joshua Wiley
Hi,

See inline below

On Mon, May 21, 2012 at 6:03 AM, i_like_macs dk...@mac.com wrote:
 Hello,

 I have a question regarding the syntax of the lme function in the nlme
 package. What I'm trying to do is to calculate an estimate of R^2 based on
 the likelihood ratio test. For this calculation, I need to determine the
 maximum log-likelihood of the intercept-only model and the model of interest
 (with the desired factors and interactions).

 My model has four independent factors (i.e. A, B, C and D). A and B are
 fixed factors, whilst C and D are random factors.

 Presently, I'm trying to code the lme function for the full ANOVA model, but
 am unsure how to code both random factors. Additionally, I'm unsure whether
 I coded the interactions correctly (i.e. I'm unsure whether the interactions
 which contain random factors also need to be specified in the random
 argument). I've skimmed through the Pinheiro and Bates book, Mixed-Effects
 Models in S and S-PLUS, but could not find an answer.

Do they need to be specified for the model to run?  No.  Do they need
to be specified for the model to make sense?  That depends on your
data, theory, and what question you are trying to answer.  I think you
would be better off posting this sort of question to
R-sig-mixedeffects list.  That said, it sounds to me like maybe it
would be easiest to spend some more time learning about mixed effects
models (I know they can be tricky) and then come back to trying to
specify the model in R.  We can help with the code aspect, but do not
typically provide statistical advice on what is or is not an
appropriate model.


 My R code for the lme function which includes all the main factors and
 interactions (2- and 3-way) so far is:

 lme(Y ~ A +
                B +
                C +
                D +
                A * B +
                A * C +
                A * D +
                B * C +
                B * D +
                C * D +
                A * B * C +
                A * B * D +
                A * C * D +
                B * C * D,
                data = myData,
                random = ~ 1|C,
                method = ML)

note that this can be written much more succinctly as:

lme(Y ~ (A + B + C + D)^3, data = myData, random = ~ 1 | C, method = ML)

which will expand to all three-way interactions and lower terms.  Have
you tried running this model?

Cheers,

Josh


 Can someone help me with how to code the random factors and interactions
 which contain these random factors please? I apologise in advance, that I am
 self-taught in statistics, and just started using R. Hence I hope my
 question made sense. Thank you very much.

 Daisuke Koya
 Confused PhD student

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Syntax-for-lme-function-to-model-random-factors-and-interactions-tp4630744.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] all occurences of an element in a vector

2012-05-21 Thread Joshua Wiley
On Mon, May 21, 2012 at 7:33 AM, carol white wht_...@yahoo.com wrote:
 like searching m or [m,n] in [1,n,m,e,m,n,n,u].

 I want the exact match of all occurrences of m and n in the last vector. 
 Therefore, grep is not helpful as it will extract if there are also mm and 
 mmm.

I am pretty sure grep() is helpful if you are using the appropriate
regular expression to search for.  Like Ista, I am not sure exactly
what your search criteria are.  The easiest I think would be to give
us some examples.  Say give three vectors and what the desired output
from your search is.

Josh


 Cheers,

 Carol


 
  From: Ista Zahn istaz...@gmail.com

 Cc: r-h...@stat.math.ethz.ch r-h...@stat.math.ethz.ch
 Sent: Monday, May 21, 2012 3:38 PM
 Subject: Re: [R] all occurences of an element in a vector

 Hi Carol,

 I'm not sure what a sub-vector in a vector is, but I think you might
 be looking for ?grep

 Best,
 Ista


 Hi,
 How do you identify all occurences of an element or a sub-vector in a vector 
 as opposed to match, %in%, and intersect which find the first occurrence of 
 an element?

 Cheers,

 Carol

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




-- 
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] Names of Greek letters stored as character strings; plotmath.

2012-05-21 Thread William Dunlap
 I think though that the concepts involved are really truly subtle

I don't think the concepts are truly subtle; it is essentially the
difference between things and names of things (and names are
also things).   However, we have muddied the waters by providing
convenience functions like library() and help() and some plotmath
constructs that try to cover up the difference between a thing and
its name. 

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: Rolf Turner [mailto:rolf.tur...@xtra.co.nz]
 Sent: Sunday, May 20, 2012 4:40 PM
 To: Robert Baer
 Cc: William Dunlap; r-help
 Subject: Re: [R] Names of Greek letters stored as character strings;plotmath.
 
 On 21/05/12 10:53, Robert Baer wrote:
 
 SNIP
 
 
 
  This discussion has been exceedingly helpful, sort of.
 
  Every time I try to do a task involving this I read the documentation
  for bquote(), expression(), plotmath(), etc.,  over and over, and I
  still fail to get the big picture of how R parses things under the
  hood.  Typically, I only succeed each time by frustrating trial and
  error.   Can I ask how you guys got a handle on the bigger (besides
  your usual brilliance G)?
 
  Is there more comprehensive documentation in the developer literature
  or is there a user wiki that you would recommend for those who never
  quite get the big picture?  If not, this would be a worthy topic for
  an R Journal article if someone has knowledge and the time to do it.
  Wish I were knowledgeable enough to do it myself.
 
 Amen.  My experience/reaction exactly.
 
 I think though that the concepts involved are really truly subtle and it may
 be difficult for the brilliant guys to explain them in such a way that
 those of
 us who are less brilliant can understand them.
 
  cheers,
 
  Rolf

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


Re: [R] variate generation

2012-05-21 Thread R. Michael Weylandt
And what distribution would that be 

R provides many built in distributions, but if those aren't enough for
you, you can check:
http://cran.r-project.org/web/views/Distributions.html

Best,
Michael

On Mon, May 21, 2012 at 7:26 AM, Mohan Radhakrishnan moh...@fss.co.in wrote:
 Hi,

           I plot no: of bytes against time and find the distribution
 curve using R. These bytes are sent from the client to the server.

 Is there a way to generate bytes randomly using R according to a
 distribution ? I would like to send these bytes to the server. Hope I am
 not misguided here. My goal is to simulate a certain distribution of
 bytes.



 Thanks,

 Mohan



 DISCLAIMER:\ ===...{{dropped:31}}

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 unbalanced rows

2012-05-21 Thread R. Michael Weylandt
I think you want this:

merge(a,b, by = d, all = FALSE)

Type ?merge to see all the options to merge available to you,

Best,
Michael

On Mon, May 21, 2012 at 9:31 AM, Belay Gebregiorgis belay...@gmail.com wrote:
 Hi Everyone,

 I am merging two data frames that have different number of rows. But I end
 up having rows a lot more than  both rows combined. I tried the following
 but the duplicate bit does not change anything. Can anyone suggest to me
 how I can handle this?

 Regards,
 Belay


 x -c(1, 2, 3, 4,5, NA, NA,NA,NA,10)
 y -c( NA, 4,NA,5,2, 10, 7, 1, 8, 9)
 d-1:10  this one belongs to the data frame a
 d-1:5  this one belongs to the data frame b
 s1-1:5
 s2-6:10

 a-data.frame(x,y,d)
 b- data.frame(s1,s2,d)

 c-merge(a, b, by=c(d))

 c[!duplicated(c[,c(x,y)]),]

        [[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] system() under windows [x] but not with Mac

2012-05-21 Thread Joshua Wiley
On Mon, May 21, 2012 at 6:25 AM, David Winsemius dwinsem...@comcast.net wrote:

 On May 20, 2012, at 6:49 PM, barb wrote:

 Hey Guys,

 i am kind of confused. Under windows the system() function works great,
 but
 not with my mac.
  I have two questions:

 1) What do i have to change. Using packages which require system or
 eval(parse() everything is fine, but
 when i try it myself sh: cmd: command not found
 Under windows i use e.g system('cmd /c copy bild.jpg',intern=FALSE )


 There is no 'cmd' system function in MacOSX.

 system(cp q.csv q2.csv)  # succeeds in making a copy of an existing file
 in the working directory



 2) I really love the Hmisc/latex function and want to be able to do it
 myself.
   How could i save a text in my notepad as name.txt


 I do not understand what the problem is. What is meant by do it? What is
 the notepad?

Geez, David, clearly the OP wants R to call the webcam to grab images
of a notepad, perform text recognition on those images, and store the
text in name.txt

...what do you mean when you say save the text in your notepad?


 --

 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.



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


[R] Complex text parsing task

2012-05-21 Thread Paul Miller
Hello Everyone,

I have what I think is a complex text parsing task. I've provided some sample 
data below. There's a relatively simple version of the coding that needs to be 
done and a more complex version. If someone could help me out with either 
version, I'd greatly appreciate it.

Here are my sample data.

haveData - 
structure(list(profile_key = structure(c(1L, 1L, 2L, 2L, 2L, 
3L, 3L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 7L, 7L), .Label = c(001-001 , 
001-002 , 001-003 , 001-004 , 001-005 , 001-006 , 001-007 
), class = factor), encounter_date = structure(c(9L, 10L, 11L, 
12L, 13L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 4L, 7L, 7L), .Label = c( 2009-03-01 
, 
 2009-03-22 ,  2009-04-01 ,  2010-03-01 ,  2010-10-15 , 
 2010-11-15 ,  2011-03-01 ,  2011-03-14 ,  2011-10-10 , 
 2011-10-24 ,  2012-09-15 ,  2012-10-05 ,  2012-10-17 
), class = factor), raw = structure(c(9L, 12L, 16L, 13L, 10L, 
7L, 6L, 3L, 2L, 4L, 14L, 15L, 1L, 5L, 8L, 11L), .Label = c( ... If patient 
KRAS result is wild type, they will start Erbitux. ... (Several lines of 
material) ... Ordered KRAS mutation test 11/11/2011. Results are still not 
available. ... , 
 ... KRAS (mutated). Therefore did not prescribe Erbitux. ... , 
 ... KRAS (mutated). Will not prescribe Erbitux due to mutation. ... , 
 ... KRAS (Wild). ...,  ... KRAS results are in. Patient has the mutation. 
... , 
 ... KRAS results still pending. Note that patient was negative for Lynch 
mutation. ..., 
 ... KRAS test results pending. Note that patient was negative for Lynch 
mutation. ..., 
 ... Ordered KRAS mutation testing on 02/15/2011. Results came back negative. 
... (Several lines of material) ... Patient KRAS mutation test is negative. 
Will start Erbitux. ..., 
 ... Ordered KRAS testing on 10/10/2010. Results not yet available. If patient 
has a mutaton, will start Erbitux. ..., 
 ... Ordered KRAS testing. Waiting for results. ...,  ... Patient is KRAS 
negative. Started Erbitux on 03/01/2011. ..., 
 ... Received KRAS results on 10/20/2010. Test results indicate tumor is wild 
type. Ua Protein positve. ER/PR positive. HER2/neu positve. ..., 
 ... Still need to order KRAS mutation testing. ... ,  ... Tumor is negative 
for KRAS mutation. ..., 
 ... Tumor is wild type. Patient is eligible to receive Eribtux. ..., 
 ... Will conduct KRAS mutation testing prior to initiation of therapy with 
Erbitux. ...
), class = factor)), .Names = c(profile_key, encounter_date, 
raw), row.names = c(NA, -16L), class = data.frame)

The following code displays the results of so-called simple coding.

 Simple coding 

KRASpatient - c(001-001, 001-002, 001-003, 001-004, 001-005, 
001-006,  001-007)
KRAStested - c(2,3,2,2,2,3,3)
KRASwild - c(1,0,2,0,3,1,3)
KRASmutant - c(4,2,2,3,1,2,2)
simpleData - data.frame(KRASpatient, KRAStested, KRASwild, KRASmutant) 
simpleData

Here, KRAStested is calculated by summing all references to KRAS for each 
patient. Wild is calculated by summing all references to wild type, wild, 
and negative that come within 20 words of the closest reference to KRAS. 
Mutant is calculated by summing all references to mutant, mutated, and 
positive that occur within 20 words of the closest reference to KRAS.   

The second kind of coding is what I'm referring to as complex coding.  The 
following code displays the results of this type of coding.

 Complex coding 

KRAStested - c(2,1,0,2,2,2,3)
KRASwild - c(1,0,0,0,3,0,3)
KRASmutant - c(0,0,0,3,0,1,0)
complexData - data.frame(KRASpatient, KRAStested, KRASwild, KRASmutant) 
complexData

The results of complex coding differ substantially from those obtained under 
simple coding and I think illustrate the potential problems with that 
approach. With complex coding, the goal would be to identify and sum only 
true references to KRAS testing and true references to the result of that 
testing (either wild type/negative or mutant/positive).

True references to KRAS testing would be identified using a set of qualifiers 
that eliminate the false references. So, for example, one of the patients in my 
(made up) sample data has the phrase Will conduct KRAS mutation testing prior 
to initiation of therapy with Erbitux in their medical record. In this case, 
Will is a qualifier that indicates this is not a true reference to KRAS 
testing. For this exercise, other qualifiers related to KRAS testing would 
include need, order (but not the past tense ordered), wait, waiting, 
await, and awaiting.
To be a qualifier, these terms would need to occur within 12 words of the 
closest true reference to KRAS.

True references to the results of testing would also be identified using a set 
of qualifiers that eliminate false references. Here the list of qualifiers 
would include if, lynch, kras mutation test, kras mutation testing and 
for kras mutation. Qualifiers would need to come within 12 words of a true 
reference to KRAS testing.

There's an additional wrinkle for identifying true references to the results of 
testing. One also needs 

[R] select part of files from a list.files

2012-05-21 Thread jeff6868
Hi everyone.

I'm working on a list of files (about 50 files). I've listed them thanks to
the function: list.files.
Each of my files contains 35000 lines of data. These files may also contain
some missing values NA (sometimes till 10 000 NAs following each other).
The aim is to do some correlation matrices between these files (I already
have the script). But as I have often missing values, the script doesn't
work yet for all my files.

In this topic, I would like to select a part of the data of these files
before the correlation.
In the files list I've created, I would like to select only the 9000 first
lines of each of my files: myfiles[1:9000,1], and then, in these 9000 lines,
I would like to keep only in my list the files which contains at least 1000
non-NA lines (so numeric data) on my 9000 lines.

I would like then to apply my script on this list of files which contains at
least 1000 numeric data on the first 9000 lines of my whole data.

I've created easy data.frames for the example, if someone could explain me
how I can do this easily (at least 2 non NA values for the 5 first lines for
example for these fake data.frames just here).
Thank you very much!

ST1 - data.frame(a=1:10)
ST2 - data.frame(b=c(NA,NA,NA,NA,NA,6:10))
ST3 - data.frame(c=c(1,NA,NA,4:10))
ST4 - data.frame(d=c(NA,NA,NA,NA,NA,NA,NA,NA,NA,NA))
ST5 - data.frame(e=c(1,2,3,4,NA,NA,7:9,NA))

( in this example, the aim is to keep only in the list.files: ST1, ST3 and
ST5 because they all contains at least 2 non-NA values in the 5 first lines,
and so to remove from the list.files ST2 and ST4 because they contain both
too much NAs in the first 5 lines). Hope you've understood! Thanks again!




--
View this message in context: 
http://r.789695.n4.nabble.com/select-part-of-files-from-a-list-files-tp4630769.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] select part of files from a list.files

2012-05-21 Thread Joshua Wiley
Hi Jeff,

Does this work okay for you?

ST - list(data.frame(a=1:10),
  data.frame(b=c(NA,NA,NA,NA,NA,6:10)),
  data.frame(c=c(1,NA,NA,4:10)),
  data.frame(d=c(NA,NA,NA,NA,NA,NA,NA,NA,NA,NA)),
  data.frame(e=c(1,2,3,4,NA,NA,7:9,NA)))

doit - function(data, rows, minpresent) {
  if (sum(!is.na(data[rows, ])) = minpresent) {
data
  } else {NULL}
}

results - lapply(ST, doit, rows = 1:5, minpresent = 2)
## print results
results

in your actual case, you would change to rows = 1:9000 and minpresent
= 1000.  You will have a list where each element is a dataset, and if
the dataset does not meet requirements, the element is NULL.

Hope this helps,

Josh

On Mon, May 21, 2012 at 8:32 AM, jeff6868
geoffrey_kl...@etu.u-bourgogne.fr wrote:
 Hi everyone.

 I'm working on a list of files (about 50 files). I've listed them thanks to
 the function: list.files.
 Each of my files contains 35000 lines of data. These files may also contain
 some missing values NA (sometimes till 10 000 NAs following each other).
 The aim is to do some correlation matrices between these files (I already
 have the script). But as I have often missing values, the script doesn't
 work yet for all my files.

 In this topic, I would like to select a part of the data of these files
 before the correlation.
 In the files list I've created, I would like to select only the 9000 first
 lines of each of my files: myfiles[1:9000,1], and then, in these 9000 lines,
 I would like to keep only in my list the files which contains at least 1000
 non-NA lines (so numeric data) on my 9000 lines.

 I would like then to apply my script on this list of files which contains at
 least 1000 numeric data on the first 9000 lines of my whole data.

 I've created easy data.frames for the example, if someone could explain me
 how I can do this easily (at least 2 non NA values for the 5 first lines for
 example for these fake data.frames just here).
 Thank you very much!

 ST1 - data.frame(a=1:10)
 ST2 - data.frame(b=c(NA,NA,NA,NA,NA,6:10))
 ST3 - data.frame(c=c(1,NA,NA,4:10))
 ST4 - data.frame(d=c(NA,NA,NA,NA,NA,NA,NA,NA,NA,NA))
 ST5 - data.frame(e=c(1,2,3,4,NA,NA,7:9,NA))

 ( in this example, the aim is to keep only in the list.files: ST1, ST3 and
 ST5 because they all contains at least 2 non-NA values in the 5 first lines,
 and so to remove from the list.files ST2 and ST4 because they contain both
 too much NAs in the first 5 lines). Hope you've understood! Thanks again!




 --
 View this message in context: 
 http://r.789695.n4.nabble.com/select-part-of-files-from-a-list-files-tp4630769.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] Complex text parsing task

2012-05-21 Thread Paul Miller
Hi Nick,

Can you elaborate (hopefully in a constructive way) on what it is that you find 
objectionable about my post?

Thanks,

Paul

--- On Mon, 5/21/12, Nick Gayeski n...@wildfishconservancy.org wrote:

 From: Nick Gayeski n...@wildfishconservancy.org
 Subject: RE: [R] Complex text parsing task
 To: 'Paul Miller' pjmiller...@yahoo.com, r-help@r-project.org
 Received: Monday, May 21, 2012, 10:36 AM
 Please stop sending these emails!
 
 
 -Original Message-
 From: r-help-boun...@r-project.org
 [mailto:r-help-boun...@r-project.org]
 On
 Behalf Of Paul Miller
 Sent: Monday, May 21, 2012 8:32 AM
 To: r-help@r-project.org
 Subject: [R] Complex text parsing task
 
 Hello Everyone,
 
 I have what I think is a complex text parsing task. I've
 provided some
 sample data below. There's a relatively simple version of
 the coding that
 needs to be done and a more complex version. If someone
 could help me out
 with either version, I'd greatly appreciate it.
 
 Here are my sample data.
 
 haveData -
 structure(list(profile_key = structure(c(1L, 1L, 2L, 2L, 2L,
 3L, 3L, 4L, 4L,
 5L, 5L, 5L, 6L, 6L, 7L, 7L), .Label = c(001-001 ,
 001-002 , 001-003 , 001-004 , 001-005 , 001-006 ,
 001-007 
 ), class = factor), encounter_date = structure(c(9L, 10L,
 11L, 12L, 13L,
 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 4L, 7L, 7L), .Label = c(
 2009-03-01 , 
 2009-03-22 ,  2009-04-01 ,  2010-03-01 ,  2010-10-15
 ,  2010-11-15
 ,  2011-03-01 ,  2011-03-14 ,  2011-10-10 , 
 2011-10-24 , 
 2012-09-15 ,  2012-10-05 ,  2012-10-17 
 ), class = factor), raw = structure(c(9L, 12L, 16L, 13L,
 10L, 7L, 6L, 3L,
 2L, 4L, 14L, 15L, 1L, 5L, 8L, 11L), .Label = c( ... If
 patient KRAS result
 is wild type, they will start Erbitux. ... (Several lines of
 material) ...
 Ordered KRAS mutation test 11/11/2011. Results are still not
 available. ...
 ,  ... KRAS (mutated). Therefore did not prescribe
 Erbitux. ... ,  ...
 KRAS (mutated). Will not prescribe Erbitux due to mutation.
 ... ,  ...
 KRAS (Wild). ...,  ... KRAS results are in. Patient has
 the mutation. ...
 ,  ... KRAS results still pending. Note that patient was
 negative for
 Lynch mutation. ...,  ... KRAS test results pending. Note
 that patient was
 negative for Lynch mutation. ...,  ... Ordered KRAS
 mutation testing on
 02/15/2011. Results came back negative. ... (Several lines
 of material) ...
 Patient KRAS mutation test is negative. Will start Erbitux.
 ...,  ...
 Ordered KRAS testing on 10/10/2010. Results not yet
 available. If patient
 has a mutaton, will start Erbitux. ...,  ... Ordered KRAS
 testing. Waiting
 for results. ...,  ... Patient is KRAS negative. Started
 Erbitux on
 03/01/2011. ...,  ... Received KRAS results on 10/20/2010.
 Test results
 indicate tumor is wild type. Ua Protein positve. ER/PR
 positive. HER2/neu
 positve. ...,  ... Still need to order KRAS mutation
 testing. ... ,  ...
 Tumor is negative for KRAS mutation. ...,  ... Tumor is
 wild type. Patient
 is eligible to receive Eribtux. ...,  ... Will conduct
 KRAS mutation
 testing prior to initiation of therapy with Erbitux. ...
 ), class = factor)), .Names = c(profile_key,
 encounter_date, raw),
 row.names = c(NA, -16L), class = data.frame)
 
 The following code displays the results of so-called
 simple coding.
 
  Simple coding 
 
 KRASpatient - c(001-001, 001-002, 001-003,
 001-004, 001-005,
 001-006,  001-007) KRAStested -
 c(2,3,2,2,2,3,3) KRASwild -
 c(1,0,2,0,3,1,3) KRASmutant - c(4,2,2,3,1,2,2)
 simpleData -
 data.frame(KRASpatient, KRAStested, KRASwild, KRASmutant)
 simpleData
 
 Here, KRAStested is calculated by summing all references to
 KRAS for each
 patient. Wild is calculated by summing all references to
 wild type,
 wild, and negative that come within 20 words of the
 closest reference to
 KRAS. Mutant is calculated by summing all references to
 mutant, mutated,
 and positive that occur within 20 words of the closest
 reference to KRAS.
 
 
 The second kind of coding is what I'm referring to as
 complex coding.  The
 following code displays the results of this type of coding.
 
  Complex coding 
 
 KRAStested - c(2,1,0,2,2,2,3)
 KRASwild - c(1,0,0,0,3,0,3)
 KRASmutant - c(0,0,0,3,0,1,0)
 complexData - data.frame(KRASpatient, KRAStested,
 KRASwild, KRASmutant)
 complexData
 
 The results of complex coding differ substantially from
 those obtained
 under simple coding and I think illustrate the potential
 problems with
 that approach. With complex coding, the goal would be to
 identify and sum
 only true references to KRAS testing and true references to
 the result of
 that testing (either wild type/negative or
 mutant/positive).
 
 True references to KRAS testing would be identified using a
 set of
 qualifiers that eliminate the false references. So, for
 example, one of the
 patients in my (made up) sample data has the phrase Will
 conduct KRAS
 mutation testing prior to initiation of therapy with
 Erbitux in their
 medical record. In this case, Will is a qualifier that
 

Re: [R] Changing selected elements of an array

2012-05-21 Thread Joshua Wiley
Hi Øystein,

You can do it by passing a matrix for indexing instead of two vectors.
 Here's an example:


tmpmat - matrix(NA, nrow = 10, ncol = 10,
  dimnames = list(letters[1:10], LETTERS[1:10]))

tmpmat[cbind(c(d, e, f), c(D, E, F))] - 100
tmpmat

The matrix is created using cbind() to columnwise bind the two vectors
together.  Then it does what you want I think.

Hope this helps,

Josh

On Mon, May 21, 2012 at 7:15 AM, Øystein Godøy o.go...@met.no wrote:
 Hi!

 I have a matrix defined on geographical positions (through) row and column
 names. I need to change a number of elements in this matrix using the
 information of a data.frame containing geographical positions and a number of
 variables.

 Changing the value of one specific element is easy, but changing on a number
 of selected positions seems more difficult. When I use the geographical
 positions of the data.frame as index, blobs are changed and not individual
 elements.

 How can I circumvent this feature of R?

 E.g: in this situation I would like the downward diagonal to be changed, not
 the square box...

 tmpmat -
 matrix(NA,nrow=9,ncol=10,dimnames=list(formatC(tmplat,format=f,digits=2),formatC(tmplon,format=f,digits=2)))
 tmpmat
      8.00 9.50 9.75 14.25 15.00 15.75 18.00 20.50 21.75 25.25
 55.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 56.75   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 57.75   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 58.00   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 59.50   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 62.75   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 64.50   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 66.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 67.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 tmpmat[c(58.00,59.50,62.75),c(15.00,15.75,18.00)] - 300
 tmpmat
      8.00 9.50 9.75 14.25 15.00 15.75 18.00 20.50 21.75 25.25
 55.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 56.75   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 57.75   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 58.00   NA   NA   NA    NA   300   300   300    NA    NA    NA
 59.50   NA   NA   NA    NA   300   300   300    NA    NA    NA
 62.75   NA   NA   NA    NA   300   300   300    NA    NA    NA
 64.50   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 66.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 67.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA

 While I wanted:
 tmpmat
      8.00 9.50 9.75 14.25 15.00 15.75 18.00 20.50 21.75 25.25
 55.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 56.75   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 57.75   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 58.00   NA   NA   NA    NA   300    NA   NA    NA    NA    NA
 59.50   NA   NA   NA    NA    NA   300   NA    NA    NA    NA
 62.75   NA   NA   NA    NA    NA    NA   300    NA    NA    NA
 64.50   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 66.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
 67.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA

 All the best
 Øystein
 --
 Dr. Oystein Godoy
 Norwegian Meteorological Institute
 P.O.BOX 43, Blindern, N-0313 OSLO, Norway
 Ph: (+47) 2296 3000 (switchb) 2296 3334 (direct line)
 Fax:(+47) 2296 3050 Institute home page: http://met.no/

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Complex text parsing task

2012-05-21 Thread Joshua Wiley
Hi Paul,

I do not think that Nick's comment was really meant to be directed at
you.  He is probably just tired of getting so many emails from R-help.

Nick, to stop getting emails if you no longer want them, try following
the link at the bottom of every single email you have received from
R-help...you can unsubscribe yourself from there if you want.  If you
like R-help but just do not like the quantity of emails, you could
consider switching your subscription to a daily digest so you just get
one email.  Alternately, you could create a special folder in your
email for R-help messages, and create a filter that automatically
sends all message from R-help to that special folder so you still have
them all but they do not clutter up your inbox.

Cheers,

Josh

On Mon, May 21, 2012 at 8:53 AM, Paul Miller pjmiller...@yahoo.com wrote:
 Hi Nick,

 Can you elaborate (hopefully in a constructive way) on what it is that you 
 find objectionable about my post?

 Thanks,

 Paul

 --- On Mon, 5/21/12, Nick Gayeski n...@wildfishconservancy.org wrote:

 From: Nick Gayeski n...@wildfishconservancy.org
 Subject: RE: [R] Complex text parsing task
 To: 'Paul Miller' pjmiller...@yahoo.com, r-help@r-project.org
 Received: Monday, May 21, 2012, 10:36 AM
 Please stop sending these emails!


 -Original Message-
 From: r-help-boun...@r-project.org
 [mailto:r-help-boun...@r-project.org]
 On
 Behalf Of Paul Miller
 Sent: Monday, May 21, 2012 8:32 AM
 To: r-help@r-project.org
 Subject: [R] Complex text parsing task

 Hello Everyone,

 I have what I think is a complex text parsing task. I've
 provided some
 sample data below. There's a relatively simple version of
 the coding that
 needs to be done and a more complex version. If someone
 could help me out
 with either version, I'd greatly appreciate it.

 Here are my sample data.

 haveData -
 structure(list(profile_key = structure(c(1L, 1L, 2L, 2L, 2L,
 3L, 3L, 4L, 4L,
 5L, 5L, 5L, 6L, 6L, 7L, 7L), .Label = c(001-001 ,
 001-002 , 001-003 , 001-004 , 001-005 , 001-006 ,
 001-007 
 ), class = factor), encounter_date = structure(c(9L, 10L,
 11L, 12L, 13L,
 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 4L, 7L, 7L), .Label = c(
 2009-03-01 , 
 2009-03-22 ,  2009-04-01 ,  2010-03-01 ,  2010-10-15
 ,  2010-11-15
 ,  2011-03-01 ,  2011-03-14 ,  2011-10-10 , 
 2011-10-24 , 
 2012-09-15 ,  2012-10-05 ,  2012-10-17 
 ), class = factor), raw = structure(c(9L, 12L, 16L, 13L,
 10L, 7L, 6L, 3L,
 2L, 4L, 14L, 15L, 1L, 5L, 8L, 11L), .Label = c( ... If
 patient KRAS result
 is wild type, they will start Erbitux. ... (Several lines of
 material) ...
 Ordered KRAS mutation test 11/11/2011. Results are still not
 available. ...
 ,  ... KRAS (mutated). Therefore did not prescribe
 Erbitux. ... ,  ...
 KRAS (mutated). Will not prescribe Erbitux due to mutation.
 ... ,  ...
 KRAS (Wild). ...,  ... KRAS results are in. Patient has
 the mutation. ...
 ,  ... KRAS results still pending. Note that patient was
 negative for
 Lynch mutation. ...,  ... KRAS test results pending. Note
 that patient was
 negative for Lynch mutation. ...,  ... Ordered KRAS
 mutation testing on
 02/15/2011. Results came back negative. ... (Several lines
 of material) ...
 Patient KRAS mutation test is negative. Will start Erbitux.
 ...,  ...
 Ordered KRAS testing on 10/10/2010. Results not yet
 available. If patient
 has a mutaton, will start Erbitux. ...,  ... Ordered KRAS
 testing. Waiting
 for results. ...,  ... Patient is KRAS negative. Started
 Erbitux on
 03/01/2011. ...,  ... Received KRAS results on 10/20/2010.
 Test results
 indicate tumor is wild type. Ua Protein positve. ER/PR
 positive. HER2/neu
 positve. ...,  ... Still need to order KRAS mutation
 testing. ... ,  ...
 Tumor is negative for KRAS mutation. ...,  ... Tumor is
 wild type. Patient
 is eligible to receive Eribtux. ...,  ... Will conduct
 KRAS mutation
 testing prior to initiation of therapy with Erbitux. ...
 ), class = factor)), .Names = c(profile_key,
 encounter_date, raw),
 row.names = c(NA, -16L), class = data.frame)

 The following code displays the results of so-called
 simple coding.

  Simple coding 

 KRASpatient - c(001-001, 001-002, 001-003,
 001-004, 001-005,
 001-006,  001-007) KRAStested -
 c(2,3,2,2,2,3,3) KRASwild -
 c(1,0,2,0,3,1,3) KRASmutant - c(4,2,2,3,1,2,2)
 simpleData -
 data.frame(KRASpatient, KRAStested, KRASwild, KRASmutant)
 simpleData

 Here, KRAStested is calculated by summing all references to
 KRAS for each
 patient. Wild is calculated by summing all references to
 wild type,
 wild, and negative that come within 20 words of the
 closest reference to
 KRAS. Mutant is calculated by summing all references to
 mutant, mutated,
 and positive that occur within 20 words of the closest
 reference to KRAS.


 The second kind of coding is what I'm referring to as
 complex coding.  The
 following code displays the results of this type of coding.

  Complex coding 

 KRAStested - c(2,1,0,2,2,2,3)
 KRASwild - c(1,0,0,0,3,0,3)
 

Re: [R] Complex text parsing task

2012-05-21 Thread Paul Miller
Hi Josh,

Thanks for pointing this out. It hadn't occurred to me that someone might post 
something like this to indicate they would like to receive fewer or no 
messages. 

Paul 

--- On Mon, 5/21/12, Joshua Wiley jwiley.ps...@gmail.com wrote:

 From: Joshua Wiley jwiley.ps...@gmail.com
 Subject: Re: [R] Complex text parsing task
 To: Paul Miller pjmiller...@yahoo.com
 Cc: Nick Gayeski n...@wildfishconservancy.org, r-help@r-project.org
 Received: Monday, May 21, 2012, 11:01 AM
 Hi Paul,
 
 I do not think that Nick's comment was really meant to be
 directed at
 you.  He is probably just tired of getting so many
 emails from R-help.
 
 Nick, to stop getting emails if you no longer want them, try
 following
 the link at the bottom of every single email you have
 received from
 R-help...you can unsubscribe yourself from there if you
 want.  If you
 like R-help but just do not like the quantity of emails, you
 could
 consider switching your subscription to a daily digest so
 you just get
 one email.  Alternately, you could create a special
 folder in your
 email for R-help messages, and create a filter that
 automatically
 sends all message from R-help to that special folder so you
 still have
 them all but they do not clutter up your inbox.
 
 Cheers,
 
 Josh
 
 On Mon, May 21, 2012 at 8:53 AM, Paul Miller pjmiller...@yahoo.com
 wrote:
  Hi Nick,
 
  Can you elaborate (hopefully in a constructive way) on
 what it is that you find objectionable about my post?
 
  Thanks,
 
  Paul
 
  --- On Mon, 5/21/12, Nick Gayeski n...@wildfishconservancy.org
 wrote:
 
  From: Nick Gayeski n...@wildfishconservancy.org
  Subject: RE: [R] Complex text parsing task
  To: 'Paul Miller' pjmiller...@yahoo.com,
 r-help@r-project.org
  Received: Monday, May 21, 2012, 10:36 AM
  Please stop sending these emails!
 
 
  -Original Message-
  From: r-help-boun...@r-project.org
  [mailto:r-help-boun...@r-project.org]
  On
  Behalf Of Paul Miller
  Sent: Monday, May 21, 2012 8:32 AM
  To: r-help@r-project.org
  Subject: [R] Complex text parsing task
 
  Hello Everyone,
 
  I have what I think is a complex text parsing task.
 I've
  provided some
  sample data below. There's a relatively simple
 version of
  the coding that
  needs to be done and a more complex version. If
 someone
  could help me out
  with either version, I'd greatly appreciate it.
 
  Here are my sample data.
 
  haveData -
  structure(list(profile_key = structure(c(1L, 1L,
 2L, 2L, 2L,
  3L, 3L, 4L, 4L,
  5L, 5L, 5L, 6L, 6L, 7L, 7L), .Label = c(001-001
 ,
  001-002 , 001-003 , 001-004 , 001-005 ,
 001-006 ,
  001-007 
  ), class = factor), encounter_date =
 structure(c(9L, 10L,
  11L, 12L, 13L,
  5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 4L, 7L, 7L), .Label
 = c(
  2009-03-01 , 
  2009-03-22 ,  2009-04-01 ,  2010-03-01 , 
 2010-10-15
  ,  2010-11-15
  ,  2011-03-01 ,  2011-03-14 ,  2011-10-10 ,
 
  2011-10-24 , 
  2012-09-15 ,  2012-10-05 ,  2012-10-17 
  ), class = factor), raw = structure(c(9L, 12L,
 16L, 13L,
  10L, 7L, 6L, 3L,
  2L, 4L, 14L, 15L, 1L, 5L, 8L, 11L), .Label = c(
 ... If
  patient KRAS result
  is wild type, they will start Erbitux. ... (Several
 lines of
  material) ...
  Ordered KRAS mutation test 11/11/2011. Results are
 still not
  available. ...
  ,  ... KRAS (mutated). Therefore did not
 prescribe
  Erbitux. ... ,  ...
  KRAS (mutated). Will not prescribe Erbitux due to
 mutation.
  ... ,  ...
  KRAS (Wild). ...,  ... KRAS results are in.
 Patient has
  the mutation. ...
  ,  ... KRAS results still pending. Note that
 patient was
  negative for
  Lynch mutation. ...,  ... KRAS test results
 pending. Note
  that patient was
  negative for Lynch mutation. ...,  ... Ordered
 KRAS
  mutation testing on
  02/15/2011. Results came back negative. ...
 (Several lines
  of material) ...
  Patient KRAS mutation test is negative. Will start
 Erbitux.
  ...,  ...
  Ordered KRAS testing on 10/10/2010. Results not
 yet
  available. If patient
  has a mutaton, will start Erbitux. ...,  ...
 Ordered KRAS
  testing. Waiting
  for results. ...,  ... Patient is KRAS negative.
 Started
  Erbitux on
  03/01/2011. ...,  ... Received KRAS results on
 10/20/2010.
  Test results
  indicate tumor is wild type. Ua Protein positve.
 ER/PR
  positive. HER2/neu
  positve. ...,  ... Still need to order KRAS
 mutation
  testing. ... ,  ...
  Tumor is negative for KRAS mutation. ...,  ...
 Tumor is
  wild type. Patient
  is eligible to receive Eribtux. ...,  ... Will
 conduct
  KRAS mutation
  testing prior to initiation of therapy with
 Erbitux. ...
  ), class = factor)), .Names = c(profile_key,
  encounter_date, raw),
  row.names = c(NA, -16L), class = data.frame)
 
  The following code displays the results of
 so-called
  simple coding.
 
   Simple coding 
 
  KRASpatient - c(001-001, 001-002,
 001-003,
  001-004, 001-005,
  001-006,  001-007) KRAStested -
  c(2,3,2,2,2,3,3) KRASwild -
  c(1,0,2,0,3,1,3) KRASmutant - c(4,2,2,3,1,2,2)
  simpleData -
  

Re: [R] Changing selected elements of an array

2012-05-21 Thread Øystein Godøy
Hi Joshua,

Many thanks for your quick reply. 

 You can do it by passing a matrix for indexing instead of two vectors.
  Here's an example:
 
 tmpmat - matrix(NA, nrow = 10, ncol = 10,
   dimnames = list(letters[1:10], LETTERS[1:10]))
 
 tmpmat[cbind(c(d, e, f), c(D, E, F))] - 100
 tmpmat
 
 The matrix is created using cbind() to columnwise bind the two vectors
 together.  Then it does what you want I think.
 
 Hope this helps,

This looks interesting and is what I want, but I am not fully understanding 
the output I receive. The input array has 100 elements while the resulting 
vector after replacement is 106 elements long. I have tried to understand the 
manual on this, but it is yet not obvious for me how I am supposed to handle 
this output.

All the best
Øystein
-- 
Dr. Oystein Godoy
Norwegian Meteorological Institute 
P.O.BOX 43, Blindern, N-0313 OSLO, Norway
Ph: (+47) 2296 3000 (switchb) 2296 3334 (direct line)
Fax:(+47) 2296 3050 Institute home page: http://met.no/

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


Re: [R] select part of files from a list.files

2012-05-21 Thread jeff6868
Hi Joshua,

Thanks you for your answer. I have to leave my work now but I'll try your
proposition tomorrow and I'll tell you if it works for me.
Good evening

--
View this message in context: 
http://r.789695.n4.nabble.com/select-part-of-files-from-a-list-files-tp4630769p4630777.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] Changing selected elements of an array

2012-05-21 Thread Joshua Wiley
On Mon, May 21, 2012 at 9:27 AM, Øystein Godøy o.go...@met.no wrote:
 Hi Joshua,

 Many thanks for your quick reply.

 You can do it by passing a matrix for indexing instead of two vectors.
  Here's an example:

 tmpmat - matrix(NA, nrow = 10, ncol = 10,
   dimnames = list(letters[1:10], LETTERS[1:10]))

 tmpmat[cbind(c(d, e, f), c(D, E, F))] - 100
 tmpmat

 The matrix is created using cbind() to columnwise bind the two vectors
 together.  Then it does what you want I think.

 Hope this helps,

 This looks interesting and is what I want, but I am not fully understanding
 the output I receive. The input array has 100 elements while the resulting
 vector after replacement is 106 elements long. I have tried to understand the
 manual on this, but it is yet not obvious for me how I am supposed to handle
 this output.

I cannot reproduce this behavior.  On my system, the output has 100 elements.


 All the best
 Øystein
 --
 Dr. Oystein Godoy
 Norwegian Meteorological Institute
 P.O.BOX 43, Blindern, N-0313 OSLO, Norway
 Ph: (+47) 2296 3000 (switchb) 2296 3334 (direct line)
 Fax:(+47) 2296 3050 Institute home page: http://met.no/



-- 
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] Changing selected elements of an array

2012-05-21 Thread Øystein Godøy
Joshua Wiley wrote on 2012-05-21
...
  This looks interesting and is what I want, but I am not fully
  understanding the output I receive. The input array has 100 elements
  while the resulting vector after replacement is 106 elements long. I
  have tried to understand the manual on this, but it is yet not obvious
  for me how I am supposed to handle this output.
 
 I cannot reproduce this behavior.  On my system, the output has 100
 elements.
...
That is valuable information for me as your result is inline with what I 
understand from the manual. I am using R version 2.10.1 (2009-12-14) through 
the system implementation following Ubuntu Lucid. I have to look further into 
the cause for this. I just doublechecked your sample code on another system 
and got the same result there.

Thanks for your effort.

All the best
Øystein
-- 
Dr. Oystein Godoy
Norwegian Meteorological Institute 
P.O.BOX 43, Blindern, N-0313 OSLO, Norway
Ph: (+47) 2296 3000 (switchb) 2296 3334 (direct line)
Fax:(+47) 2296 3050 Institute home page: http://met.no/

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


Re: [R] Loop Help

2012-05-21 Thread David L Carlson
Here is a slightly different approach that takes advantage of recycling:

# Make 7 data frames
for (i in 1:7) {
  assign(paste(TOWER, i, sep=), data.frame(A=letters[1:4],
X=rnorm(4)))
}
# Add Tower column taking advantage of recyling
tnames - paste(TOWER, 1:7, sep=)
for (i in 1:7) {
  assign(tnames[i], cbind(eval(as.name(tnames[i])), Tower=i))
}
# Combine them into a single data frame
TOWER - do.call(rbind, lapply(tnames, as.name))


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Rui Barradas
 Sent: Saturday, May 19, 2012 9:04 AM
 To: bdossman
 Cc: r-help@r-project.org
 Subject: Re: [R] Loop Help
 
 Hello,
 
 The error is that you are trying to use the number of rows of a
 character string.
 TOWERS[1], TOWERS[2], etc, are not data frames. Use a print statement
 before the line that throws the error to check it.
 
 Your problem can be solved along the lines of what follows.
 Note that I've put all data frames in a list, it's better to have them
 kept like that, it makes everything else simpler.
 
 
 # Create a list with some made up data.frames
 towers - list(TOWER1=data.frame(A=letters[1:4], X=rnorm(4)),
  TOWER2=data.frame(A=LETTERS[1:6], X=runif(6)))
 towers
 
 # In your case this is  from TOWER1 to TOWER7
 TOWERS - names(towers)
 
 towers.with.id - lapply(TOWERS, function(i){
  towers[[ i ]]$Tower - factor(i)
  towers[[ i ]]})
 
 
 (Use something other than 'towers.with.id', this is just an example.)
 
 
 #names(towers.with.id) - TOWERS  # (*) See below
 towers.with.id
 do.call(rbind, towers.with.id)
 
 
 (*) Try to run these last three instructions with the marked line
 commented/uncommented.
 It's better to uncomment, maybe after rbind.
 You'll later be able to access the list elements with a syntax like
 
 
 towers.with.id[[ TOWER2 ]]# full data.frame 2
 towers.with.id[[ TOWERS[2] ]]$A# just that column
 towers.with.id[[ TOWER2 ]]$A[3]# third element of that column
 
 
 If you do.call/rbind before, to solve the rbind-ed data.frame's row
 names use
 
 rownames(result) - seq.int(nrow(result))
 
 where 'result' is the result of do.call.
 
 Hope this helps,
 
 Rui Barradas
 
 Em 19-05-2012 11:00, r-help-requ...@r-project.org escreveu:
  Date: Fri, 18 May 2012 16:14:08 -0700 (PDT)
  From: bdossmanbdoss...@gmail.com
  To:r-help@r-project.org
  Subject: [R] Loop Help
  Message-ID:1337382848213-4630555.p...@n4.nabble.com
  Content-Type: text/plain; charset=us-ascii
 
  Hi all,
 
  I am a beginner R user and need some help with a simple loop
 function.
 
  Currently, I have seven datasets (TOWER1,TOWER2...TOWER7) that are
 all in
  the same format (same # of col and headers). I am trying to add a new
 column
  (factor) to each dataset that simply identifies the dataset.
 Ultimately, I
  would like to merge all 7 datasets and need that column to identify
 what
  rows came from what dataset.
 
  Using the code below, I get the error message Error in rep(i,
  nrow(TOWER.i)) : invalid 'times' argument but it doesn't make sense
 to me
  since nrow should give an integer value. Any help will be really
  appreciated.
 
  TOWERS-
 c(TOWER1,TOWER2,TOWER3,TOWER4,TOWER5,TOWER6,TOWER7)
 
  for(i in 1:7){
  TOWER.i-TOWERS[i]
  TOWER-rep(i,nrow(TOWER.i))
  TOWER.i-cbind(TOWER.i[1:2],TOWER, TOWER.i[2:length(TOWER.i)])
  }
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] system() under windows [x] but not with Mac

2012-05-21 Thread MacQueen, Don
The Mac does not have an application called notepad, so you can't save a
text in [your] notepad. However, the Mac has TextEdit, and if you save
any file with the .txt suffix it will open in TextEdit when you
double-click on it in a Finder window (outside R, that is).

You could even, from inside R, type
  system('open name.txt')
and it will open the file in TextEdit, provided that the file is in what R
considers to be your working directory.

To save a file from within R, start by viewing the help pages for
  write.table
  sink
  cat
depending on what you want to save and how you want it structured in the
file.

-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 5/20/12 3:49 PM, barb mainze...@hotmail.com wrote:

Hey Guys,

i am kind of confused. Under windows the system() function works great,
but
not with my mac.
  I have two questions:

1) What do i have to change. Using packages which require system or
eval(parse() everything is fine, but
when i try it myself sh: cmd: command not found
Under windows i use e.g system('cmd /c copy bild.jpg',intern=FALSE )

2) I really love the Hmisc/latex function and want to be able to do it
myself. 
How could i save a text in my notepad as name.txt

Thank you!!

   

--
View this message in context:
http://r.789695.n4.nabble.com/system-under-windows-x-but-not-with-Mac-tp46
30688.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] Loop Help

2012-05-21 Thread David L Carlson
I should have added

TOWER$Tower - factor(TOWER$Tower)

To the end to convert Tower from an integer to a factor.

--
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-bounces@r-
 project.org] On Behalf Of David L Carlson
 Sent: Monday, May 21, 2012 12:30 PM
 To: 'Rui Barradas'; 'bdossman'
 Cc: r-help@r-project.org
 Subject: Re: [R] Loop Help
 
 Here is a slightly different approach that takes advantage of
 recycling:
 
 # Make 7 data frames
 for (i in 1:7) {
   assign(paste(TOWER, i, sep=), data.frame(A=letters[1:4],
 X=rnorm(4)))
 }
 # Add Tower column taking advantage of recyling
 tnames - paste(TOWER, 1:7, sep=)
 for (i in 1:7) {
   assign(tnames[i], cbind(eval(as.name(tnames[i])), Tower=i))
 }
 # Combine them into a single data frame
 TOWER - do.call(rbind, lapply(tnames, as.name))
 
 
  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
  project.org] On Behalf Of Rui Barradas
  Sent: Saturday, May 19, 2012 9:04 AM
  To: bdossman
  Cc: r-help@r-project.org
  Subject: Re: [R] Loop Help
 
  Hello,
 
  The error is that you are trying to use the number of rows of a
  character string.
  TOWERS[1], TOWERS[2], etc, are not data frames. Use a print statement
  before the line that throws the error to check it.
 
  Your problem can be solved along the lines of what follows.
  Note that I've put all data frames in a list, it's better to have
 them
  kept like that, it makes everything else simpler.
 
 
  # Create a list with some made up data.frames
  towers - list(TOWER1=data.frame(A=letters[1:4], X=rnorm(4)),
   TOWER2=data.frame(A=LETTERS[1:6], X=runif(6)))
  towers
 
  # In your case this is  from TOWER1 to TOWER7
  TOWERS - names(towers)
 
  towers.with.id - lapply(TOWERS, function(i){
   towers[[ i ]]$Tower - factor(i)
   towers[[ i ]]})
 
 
  (Use something other than 'towers.with.id', this is just an example.)
 
 
  #names(towers.with.id) - TOWERS  # (*) See below
  towers.with.id
  do.call(rbind, towers.with.id)
 
 
  (*) Try to run these last three instructions with the marked line
  commented/uncommented.
  It's better to uncomment, maybe after rbind.
  You'll later be able to access the list elements with a syntax like
 
 
  towers.with.id[[ TOWER2 ]]# full data.frame 2
  towers.with.id[[ TOWERS[2] ]]$A# just that column
  towers.with.id[[ TOWER2 ]]$A[3]# third element of that column
 
 
  If you do.call/rbind before, to solve the rbind-ed data.frame's row
  names use
 
  rownames(result) - seq.int(nrow(result))
 
  where 'result' is the result of do.call.
 
  Hope this helps,
 
  Rui Barradas
 
  Em 19-05-2012 11:00, r-help-requ...@r-project.org escreveu:
   Date: Fri, 18 May 2012 16:14:08 -0700 (PDT)
   From: bdossmanbdoss...@gmail.com
   To:r-help@r-project.org
   Subject: [R] Loop Help
   Message-ID:1337382848213-4630555.p...@n4.nabble.com
   Content-Type: text/plain; charset=us-ascii
  
   Hi all,
  
   I am a beginner R user and need some help with a simple loop
  function.
  
   Currently, I have seven datasets (TOWER1,TOWER2...TOWER7) that are
  all in
   the same format (same # of col and headers). I am trying to add a
 new
  column
   (factor) to each dataset that simply identifies the dataset.
  Ultimately, I
   would like to merge all 7 datasets and need that column to identify
  what
   rows came from what dataset.
  
   Using the code below, I get the error message Error in rep(i,
   nrow(TOWER.i)) : invalid 'times' argument but it doesn't make
 sense
  to me
   since nrow should give an integer value. Any help will be really
   appreciated.
  
   TOWERS-
  c(TOWER1,TOWER2,TOWER3,TOWER4,TOWER5,TOWER6,TOWER7)
  
   for(i in 1:7){
 TOWER.i-TOWERS[i]
 TOWER-rep(i,nrow(TOWER.i))
 TOWER.i-cbind(TOWER.i[1:2],TOWER, TOWER.i[2:length(TOWER.i)])
   }
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/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] Names of Greek letters stored as character strings; plotmath.

2012-05-21 Thread Bert Gunter
Yet again:Thank you Peter and Duncan. I appreciate your comments and insights.

I agree wholeheartedly with Peter's comments below about understanding
what a parsed expression is in R. In R -- and in functional
programming in general, I believe -- computing on the language is
extremely handy, even for relatively basic programming.  I found VR's
discussion in S Programming on Computing on the Language very
helpful in this regard, especially their table 3.2,  which dissects
the different but cognate situation of formulas,  functions, and
function calls. Perhaps something similar could be done for
expression(), parse(), and quote(). I think there are subtleties here
that deserve explicit mention and elaboration.

As a feeble attempt in this direction, which I hope illuminates more
than it obfuscates -- and I would greatly appreciate prompt
corrections of any errors -- perhaps the following might be useful:

a - 3
x - quote(a+2)
y - parse(text = a+2)
z - expression(a+2)
##
eval(x) ## 5
eval(y) ## the same
eval(z) ## the same
##
## Now note:
as.list(x) ## quote(a+2) the parse tree for the expression a+2
##
as.list(y) ## looks like a list whose component is the parse tree for
the expression
## as demonstrated by:
##
identical(x,y[[1]]) ##TRUE
##
as.list(z) ## appears to be the same as z. And, indeed,
##
identical(y[[1]],z[[1]])  ##TRUE. The parse tree for the expression again.
##
### However
##
identical(y,z) ## FALSE !!
## To see what's going on, use str()
str(x) ## language a + 2
str(y[[1]]) ## the same
str(z[[1]]) ## the same
##
## But
str(y) ## complex structure with attributes
str(z) ## simple expression
##

To me, this reinforces Bill Dunlap's and Thomas Lumley's counsels:
avoid explicit parsing and evaluation via eval(parse(...)) in favor of
working with the parsed expression via substitute() and bquote().

HTH,

Bert


On Mon, May 21, 2012 at 12:20 AM, peter dalgaard pda...@gmail.com wrote:

 On May 21, 2012, at 05:25 , Duncan Murdoch wrote:

 On 12-05-20 10:28 PM, Bert Gunter wrote:
 Well, that's not very comforting, Duncan. It's like saying that you
 have to read the engineering specs to drive the car successfully.

 I think Robert's message that I responded to was asking for a deeper 
 understanding than simply driving the car.  He appeared to want to know why 
 the car worked the way it did, and describing that entirely in terms of 
 things you can see without opening the hood is hard.

 There are levels, though. For basic car driving, it might be sufficient to 
 know that turning the steering wheel left makes the car change direction 
 towards left. Rather soon, you will realize that it is imortant that it does 
 so by turning the front wheels; this explains why you need to reverse into a 
 parallel-parking space. At some point, it may become useful to know that the 
 wheels are tangential to the curve that the car follows and that it therefore 
 turns around a point on the line trough the rear wheels (not that that ever 
 helped me to parallel park...).

 In R, it is important to have some reasonably accurate mental image of its 
 internal structures. For quote() and friends, the thing that you really need 
 is the notion of a _parse tree_, i.e. the fact that expressions are not 
 evaluated as-is, but first converted (parsed) to an internal structure that 
 is equivalent to a list of lists:

 e - quote(2/(3+a))
 e[[1]]
 `/`
 e[[2]]
 [1] 2
 e[[3]]
 (3 + a)
 e[[3]][[1]]
 `(`
 e[[3]][[2]]
 3 + a
 e[[3]][[2]][[1]]
 `+`
 e[[3]][[2]][[2]]
 [1] 3
 e[[3]][[2]][[3]]
 a

 or, graphically (mailer permitting)

 `/` +--2
    |
    +--`(`--`+` +-- 3
                |
                +-- a

 Once you have this concept in mind, it should become fairly clear that the 
 string constant a is fundamentally different from the variable name a.

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











-- 

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.


[R] R development master class: NYC June 21-22, Bay Area June 28-29

2012-05-21 Thread Hadley Wickham
Hi all,

I'm going to be teaching an R development master classes in NYC June
21-12 and in the Bay Area June 28-29. The basic idea of the class is
to help you write better code, focused on the mantra of do not repeat
yourself. In day one you will learn powerful new tools of
abstraction, allowing you to solve a wider range of problems with
fewer lines of code. Day two will teach you how to make packages, the
fundamental unit of code distribution in R, allowing others to save
time by allowing them to use your code.

To get the most out of this course, you should have some experience
programming in R already: you should be familiar with writing
functions, and the basic data structures of R: vectors, matrices,
arrays, lists and data frames. You will find the course particularly
useful if you're an experienced R user looking to take the next step,
or if you're moving to R from other programming languages and you want
to quickly get up to speed with R's unique features. You can see the
material we covered last time at http://bit.ly/odi3ai.

Both days will incorporate a mix of lectures and hands-on learning.
Expect to learn about a topic and then immediately put it into
practice with a small example. Plenty of help will be available if you
get stuck. You'll receive a printed copy of all slides, as well as
electronic access to the slides, code and data. The material covered
in the course is currently being turned into a book: you can access
the current draft at http://bit.ly/dDv5rt.

To see prices, locations and register, please see:
http://bit.ly/lTft9e. Early bird discounts available until May 31, and
limited discounts for students (66% off) and academics (33% off) are
available - please contact me for details.

Regards,

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

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


Re: [R] Complex sort problem

2012-05-21 Thread Petr Savicky
On Fri, May 18, 2012 at 09:20:59PM -0400, Axel Urbiz wrote:
[...]
 Petr: I kind of see your line of thought, but still cannot see how it works
 on a specific example like this one.

I did not have email in the last few days.

The previous suggestion from

  https://stat.ethz.ch/pipermail/r-help/2012-May/313197.html

was meant for the situation that we want to keep the result of
sorting according to several variables, so that later, sorting
of a subset can be done only by sorting according to a single
variable. Now, i see, all sortings are already according to
a single variable, so this is not helpful.

Try the following, which uses the example from your code.
In particular, it uses a matrix (not a data frame) and
there are no duplicates in the data.

  set.seed(1)
 
  dframe - matrix(runif(250), 50, 5)
 
  ### store sort indexes
 
  sort_matrix - matrix(ncol = ncol(dframe), nrow = nrow(dframe))
 
  for (i in 1:ncol(dframe)) {
xtemp - dframe[, i]
sort_matrix[, i] - sort.list(xtemp, method = shell)
  }
 
  ### take a bootstrap sample
 
  nr_samples - nrow(dframe)
  b.ind - sample(1:nr_samples, nr_samples*0.5, replace = TRUE)
  freq - tabulate(b.ind, nbins=nr_samples)
 
  ### create bootstrap sample sorted with respect to an arbitrary variable
 
  var1 - 1
  ind - sort_matrix[, var1]
  DF1 - dframe[ind, ]# this can be computed in advance (before b.ind)
  NDF1 - DF1[rep(1:nrow(DF1), times=freq[ind]), ]
 
  ### compare with a straightforward method

  subDF - dframe[b.ind, ]
  subDF1 - subDF[order(subDF[, var1]), ]
  identical(NDF1, subDF1)

  [1] TRUE

The main step is that ind is used to transform both the data
and the frequency table. So, they remain consistent and the
reordered frequencies may be used for the reordered data.

Hope this helps.

Petr Savicky.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] M-estimation in multivariate linear regression model in R

2012-05-21 Thread Monika Steinhubelova
 Hello,

I try to find a function for M-estimation in multivariate linear regression
model (function that can estimate betas in my model: y=x * beta + e, where
y is a matrix). I´ve searched R-site for a long time, but I am hopeless.

I would like to ask, if there is any function for M-estimation in
multivariate linear regression model in R. I know I can estimate betas in
my model by rlm() function -- rewrite y-variables into one column (vec
operation) ... But ... I would like to use one function to get betas and
don´t rewrite y-variables.

Thank you for any help (claim that there is no function like I need is also
very helpfull, so I will compute my problem by rlm function).

Monika Steinhubelova

[[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] write.xls

2012-05-21 Thread Martin Studer
Hi Spencer,

it looks like you either don't have Java installed  or the architectures of
R and your JVM don't match, i.e. your running 64-bit R (as noted from your
sessionInfo() output) but are using a 32-bit JVM. In any case installing
64-bit Java should resolve your issue.

Hope that helps.

Best regards,
Martin

--
View this message in context: 
http://r.789695.n4.nabble.com/write-xls-tp4630642p4630787.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] Need help for R install

2012-05-21 Thread Cao, Renzhi (MU-Student)
Dear R committee:
   I am Renzhi, Ph.D student in computer science in the University of 
Missouri. I have one question for you. I try to install R in the linux server, 
but I don't have the root permission, is there any way to install the R locally?
Thank you very much for helping me.

Renzhi Cao
Graduate Research Assistant
Department of Computer Science
University of Missouri-Columbia
Columbia, MO 65211
Cell: 573-825-8874
Email : rc...@mail.missouri.edumailto:rc...@mail.missouri.edu
http://home.ustc.edu.cn/~ahjxcrz


[[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] Syntax for lme function to model random factors and interactions

2012-05-21 Thread i_like_macs
Hello Joshua,

Many thanks for your help, especially from a fellow Bruin (I went there as
an undergrad!). 

I understand that there is another forum for mixed models. If my problem
can't be solved within this thread, I'll have to go there. I do understand
some theory about mixed models, but obviously am far from an expert.

My question is not so much statistical advice, as it concerns the correct
syntax to include random factors and interactions (which include these
random factors) for the lme function. Maybe it's because I'm used to SPSS,
but I find R very difficult to use, even after looking up its built-in help.

I could run your neat code suggestion:

lme(Y ~ (A + B + C + D)^3, data = myData, random = ~ 1 | C, method = ML) 

but would like to know how to also include D as a random factor. My
understanding is that the random argument for the lme function is coded
as:

~ x1 + ... + xn | g1 / ... / gm

where the left side describes the model for random effects, and the right
side describes the grouping structure. Reading other posts, I learned that I
need both sides for the code to run without errors. However, it's not clear
to me what both sides represent. The left side appears to be where the
random factors are specified, perhaps like this:

random = ~ C + D

But then this results in errors. Does this mean I have to somehow join the
two following lines of code to specify both random factors?

random = ~ 1 | C
random = ~ 1 | D

It's not clear what the ~ 1 represents here, as I would have guessed that
this is where the random factors would be specified. Is this related to an
intercept-only model?

I'm sorry for sounding so lost. This is because I am. Perhaps I need to know
more theory of mixed models, but this seems to be possible only if I
understand what parts of the lme function are.

Thank you very much again,

Daisuke


--
View this message in context: 
http://r.789695.n4.nabble.com/Syntax-for-lme-function-to-model-random-factors-and-interactions-tp4630744p4630789.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] Erratic error with adaptIntegrate in cubature package

2012-05-21 Thread Helen Broome
Hi everyone,

I have been using adaptIntegrate from the cubature package for a
multidimensional integral that has infinite variance (and so not
appropriate for Monte Carlo techniques). Most of the time it works but
sometimes (though not always) when I slightly increase the accuracy I want,
or increase the bounds of integration I get the following error:

  REAL() can only be applied to a 'numeric', not a 'pairlist'

For instance if the calculation works with absError=1e-3 and takes
approximately 10 seconds then asking for absError=1e-4 I get the error
about REAL() within one second. So even though the computation should take
longer it doesn't seem to be starting. However later on when I ask for
absError=1e-4 it works.

The error is quite erratic so I don't understand what is going wrong or how
to prevent it happening.

There are three parameters that I sometimes change and each can cause this
error all of a sudden (but most of the time it doesn't so there doesn't
seem to be any consistency!)
- absError (a parameter from the adaptIntegrate function) I write this as
absError = 1e-x for some natural number x
- upperBound / lowerBound (a parameter from the adaptIntegrate function) I
write these as upperBound = c(a,b) for some real numbers a,b.
- a parameter that I pass to my function that is being integrated and is
just a real number

Once I defined a variable
A-10
and then passed A to the function and got an error but when I tried the
exact same call but wrote 10 directly instead of using A it worked fine.
However later on using A again there was no problem.

Most of the time the error occurs when I slightly increase the desired
accuracy or the domain of integration.

Is this a known bug?

Thanks for any suggestions!

[[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] help with melt/cast in reshape-package

2012-05-21 Thread Martin Schilling
I'm sorry everyone for the inconvenience of spamming the R-help...

Here's the complete post:


Hi everyone,

 Since it's quite a while that I used the reshape package, I now feel kind
 of rusty.

 I have a data.frame like this:



 id  Sample.Name   Marker   Allele.1
 Allele.2sample_idspecies
 101_primer01  Dalb01   165
  179  SH233 D. madagascariensis
 201_primer04  Dalb04221
   225  SH233 D. madagascariensis
 301_primer08  Dalb08218
   218  SH233 D. madagascariensis
 401_primer10  Dalb10134
   134  SH233 D. madagascariensis
 501_primer14  Dalb14250
   250  SH233 D. madagascariensis
 601_primer16  Dalb16232
   232  SH233 D. madagascariensis

 this was just the head(), in fact, the sample_id col has in fact different
 ids, I would like to aggregate them into one
 and I would like to get something like this:

 species   sample_id Marker1_Allele1
Marker1_Allele2  Marker2_Allele1  Marker2_Allele2
  Marker3_Allele1 Marker3_Allele2   etc. (with 35
 different markers)

 D. madagascariensis   SH233 179
   225  134
  244

 I tried to prepare the cast() but didn't quite figure out how to achieve
 this. I wanted to create a col with the MarkerX_AlleleY 's, but didn't find
 any useful solutions. The sample_id's should be aggregated so that each
 sample_id needs just one row. Should I  just merge columns Allele.1,
 Allele.2 and sample_id?


I'm kind of stuck, but would appreciate any help on the columns to be
merged.

Thanks a lot
Martin Schilling






[[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] problem with data frame to numeric transformation

2012-05-21 Thread Ivette
http://r.789695.n4.nabble.com/file/n4630788/GOF_CGIK.R GOF_CGIK.R  
http://r.789695.n4.nabble.com/file/n4630788/RESIDSNEWr.csv RESIDSNEWr.csv 

In order to save place, I attach the data and the R code, for which I have 2
questions.

1/ I cannot convert successfully the data frames with names first and
second in numeric format. They participate here: 

calibKendallsTau(cc,cor(first,second,method=kendall)) and I get an error
message.

2/ I have cut the dates from my data file RESIDSNEWr.csv, but let's suppose
I want to keep them. How shall I update the code from 1/ in order to have
also the dates?

Many thanks in advance to all, who will answer my message




--
View this message in context: 
http://r.789695.n4.nabble.com/problem-with-data-frame-to-numeric-transformation-tp4630788.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] M-estimation in multivariate linear regression model in R

2012-05-21 Thread Bert Gunter
Familiarize yourself with the CRAN task views and check out the Robust
task view.

Also ?rlm in MASS.

-- Bert

On Mon, May 21, 2012 at 11:23 AM, Monika Steinhubelova
monika.steinhubel...@gmail.com wrote:
  Hello,

 I try to find a function for M-estimation in multivariate linear regression
 model (function that can estimate betas in my model: y=x * beta + e, where
 y is a matrix). I“ve searched R-site for a long time, but I am hopeless.

 I would like to ask, if there is any function for M-estimation in
 multivariate linear regression model in R. I know I can estimate betas in
 my model by rlm() function -- rewrite y-variables into one column (vec
 operation) ... But ... I would like to use one function to get betas and
 don“t rewrite y-variables.

 Thank you for any help (claim that there is no function like I need is also
 very helpfull, so I will compute my problem by rlm function).

 Monika Steinhubelova

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




-- 

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] Need help for R install

2012-05-21 Thread Dominik Bruhn
Hy,
I don't think there is a committee here but I'll try to help you
nevertheless:

If you don't have root permissions you can still install R in several ways:
1. Build it by yourself. If you have a compiler installed, you can build
R from source. See [1] for a manual.

2. Install a virtual machine where you can install your own Linux and
have root rights. You can use Virtual Box for this.

I hope this helps!
Dominik


[1]: http://cran.r-project.org/doc/manuals/R-admin.html#Simple-compilation


On 21/05/12 19:29, Cao, Renzhi (MU-Student) wrote:
 Dear R committee:
I am Renzhi, Ph.D student in computer science in the University of 
 Missouri. I have one question for you. I try to install R in the linux 
 server, but I don't have the root permission, is there any way to install the 
 R locally?
 Thank you very much for helping me.
 
 Renzhi Cao
 Graduate Research Assistant
 Department of Computer Science
 University of Missouri-Columbia
 Columbia, MO 65211
 Cell: 573-825-8874
 Email : rc...@mail.missouri.edumailto:rc...@mail.missouri.edu
 http://home.ustc.edu.cn/~ahjxcrz
 
 
   [[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.
 


-- 
Dominik Bruhn
mailto: domi...@dbruhn.de



signature.asc
Description: OpenPGP digital 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] Need help for R install

2012-05-21 Thread R. Michael Weylandt
It should certainly be possible to install to some directory where you
have write permissions, but the exact specifics will depend on which
Linux you're using.

There are R-SIG-Debian and R-SIG-Fedora lists which can give OS
specific advice, but it might be easier just to talk to your IT folks.
I'm not familiar enough with all the Linux package managers to know
which give you the choice of where to install.

As Dominik noted, assuming you have a fortran and a c compiler
available, you should be able to build in a directory where you have
write permissions.

Best,
Michael

On Mon, May 21, 2012 at 1:29 PM, Cao, Renzhi (MU-Student)
rc...@mail.missouri.edu wrote:
 Dear R committee:
       I am Renzhi, Ph.D student in computer science in the University of 
 Missouri. I have one question for you. I try to install R in the linux 
 server, but I don't have the root permission, is there any way to install the 
 R locally?
        Thank you very much for helping me.

 Renzhi Cao
 Graduate Research Assistant
 Department of Computer Science
 University of Missouri-Columbia
 Columbia, MO 65211
 Cell: 573-825-8874
 Email : rc...@mail.missouri.edumailto:rc...@mail.missouri.edu
 http://home.ustc.edu.cn/~ahjxcrz


        [[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] sweave tables as images?

2012-05-21 Thread Alexander Shenkin
Hello folks,

I've been on a journey trying to figure out how to manage documents that
are amenable to sharing and editing, but that contain dynamic content
generated by R.  I've come to the following solution: I use Sweave to
generate labeled png  pdf figures, and I Insert  Link those figures
as Pictures in a Word 2010 doc.  Thus, when data or code changes, I
regenerate the figures with Sweave, open the Word doc and hit F9, and
all the figures are automatically updated.  I can send the file around,
folks can comment and edit, track changes, etc.

Now, however, I'm trying to do the same for tables that I did for
figures, and it seems a bit more difficult.  I can spit out tex tables
into separate files using the split=TRUE chunk option, and I can even
make those tables into html with xtable(type=html).  Word, however,
doesn't have the Insert  Link option for external text files (which
makes it such that, if the external file isn't found, Word uses a copy
stored in the doc).

So, I think it will be better if I can somehow generate the tables as
images.  Is there any way to generate tables as images in separate files
in Sweave?  Or, is there another tree up which I should be barking?

Thanks,
Allie

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


Re: [R] sweave tables as images?

2012-05-21 Thread R. Michael Weylandt
Take a look at addtable2plot in plotrix or grid.table / tableGrob in
gridExtras.

Michael

On Mon, May 21, 2012 at 4:29 PM, Alexander Shenkin ashen...@ufl.edu wrote:
 Hello folks,

 I've been on a journey trying to figure out how to manage documents that
 are amenable to sharing and editing, but that contain dynamic content
 generated by R.  I've come to the following solution: I use Sweave to
 generate labeled png  pdf figures, and I Insert  Link those figures
 as Pictures in a Word 2010 doc.  Thus, when data or code changes, I
 regenerate the figures with Sweave, open the Word doc and hit F9, and
 all the figures are automatically updated.  I can send the file around,
 folks can comment and edit, track changes, etc.

 Now, however, I'm trying to do the same for tables that I did for
 figures, and it seems a bit more difficult.  I can spit out tex tables
 into separate files using the split=TRUE chunk option, and I can even
 make those tables into html with xtable(type=html).  Word, however,
 doesn't have the Insert  Link option for external text files (which
 makes it such that, if the external file isn't found, Word uses a copy
 stored in the doc).

 So, I think it will be better if I can somehow generate the tables as
 images.  Is there any way to generate tables as images in separate files
 in Sweave?  Or, is there another tree up which I should be barking?

 Thanks,
 Allie

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] fda modeling

2012-05-21 Thread Troels Ring
Dear friends - We have 25 rats, 14 of these subjected to partial removal 
of kidney tissue, 11 to sham operation, and then followed for 6 weeks. 
So far we have data on 26 urine metabolites measured by NMR 7 times 
during the observation. I have smoothed the measurements by b.splines in 
fda including a roughness penalty, and inspecting the mean curves for 
nephrectomized and sham animals indicate differences for several of the 
metabolites. Now the real idea is to use the NMR measurements to 
understand what goes on in the kidneys since we know the partial removal 
of kidney tissue will result in progressive damage in the kidneys - the 
nature of that is what we want to understand. We have a blood sample 
from the rats just prior to sacrifice, and the creatinine concentration 
there is a good proxy for renal function. So the course of 
concentrations of the metabolites are thought to be valuable in 
understanding the physiology. Some of these are thought to be 
correlated. We have two groups where sham animals have better renal 
function than partially nephrectomized, but there is variation in both 
groups which is also interesting - some animals progress more rapidly 
after the same operation  than others - we would like to know why.
The data are available (eventually - the resulting blood tests still are 
missing) if anyone would like to have a look but the main issue is if it 
is at all feasible to make fda work on such a problem.

Best wishes
Troels Ring,
Nephrology
Aalborg,  Denmark

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


Re: [R] Need help for R install

2012-05-21 Thread Dominik Bruhn
Please do not answer directly to the people but answer to the list
instead so everybody sees your mail.

You can change the target directory using the --prefix= command line
parameter of the ./configure script.


On 21/05/12 22:37, Cao, Renzhi (MU-Student) wrote:
 Dear Dominik:
 Thank you very much for your advice. I have a C compiler, is that 
 enough? I will check the manual you mentioned. The R will be installed into a 
 root directory, and it seems I cannot change the target path of the 
 installation. 
Thank you.
 
 Renzhi Cao
 Graduate Research Assistant
 Department of Computer Science
 University of Missouri-Columbia
 Columbia, MO 65211
 Cell: 573-825-8874
 Email : rc...@mail.missouri.edu
 http://home.ustc.edu.cn/~ahjxcrz
 
 
 -Original Message-
 From: Dominik Bruhn [mailto:domi...@dbruhn.de] 
 Sent: Monday, May 21, 2012 3:23 PM
 To: Cao, Renzhi (MU-Student)
 Cc: r-help@R-project.org
 Subject: Re: [R] Need help for R install
 
 Hy,
 I don't think there is a committee here but I'll try to help you
 nevertheless:
 
 If you don't have root permissions you can still install R in several ways:
 1. Build it by yourself. If you have a compiler installed, you can build R 
 from source. See [1] for a manual.
 
 2. Install a virtual machine where you can install your own Linux and have 
 root rights. You can use Virtual Box for this.
 
 I hope this helps!
 Dominik
 
 
 [1]: http://cran.r-project.org/doc/manuals/R-admin.html#Simple-compilation
 
 
 On 21/05/12 19:29, Cao, Renzhi (MU-Student) wrote:
 Dear R committee:
I am Renzhi, Ph.D student in computer science in the University of 
 Missouri. I have one question for you. I try to install R in the linux 
 server, but I don't have the root permission, is there any way to install 
 the R locally?
 Thank you very much for helping me.

 Renzhi Cao
 Graduate Research Assistant
 Department of Computer Science
 University of Missouri-Columbia
 Columbia, MO 65211
 Cell: 573-825-8874
 Email : rc...@mail.missouri.edumailto:rc...@mail.missouri.edu
 http://home.ustc.edu.cn/~ahjxcrz


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

 
 
 --
 Dominik Bruhn
 mailto: domi...@dbruhn.de
 
 


-- 
Dominik Bruhn
mailto: domi...@dbruhn.de



signature.asc
Description: OpenPGP digital 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.


[R] simple, unidimensional heat map

2012-05-21 Thread Dimitri Liakhovitski
I was wondering if someone could point in the direction of a package
that could generate not heatmaps, but something like a unidimensional
heat map.
I might be mistaken, but it seems like image and heatmap are an
overkill for such a simple task.

For example, if I have a data frame:
x-data.frame(myname=paste(value,1:10,sep=),a=1:10,b=sample(1:10,10,replace=T))

I'd like to create a chart (it's more of a table, actually) with one
horizontal axis (myname) and 2 rows of rectangles above it - one for
a and one for b. Such that the higher the value, the more intense
the color of the rectangle (10 rectangles for 10 values).

Thanks a lot for any pointers!

-- 
Dimitri Liakhovitski
marketfusionanalytics.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] sweave tables as images?

2012-05-21 Thread Alexander Shenkin
Thanks Michael - I think grid.table does the trick.

On 5/21/2012 3:33 PM, R. Michael Weylandt wrote:
 Take a look at addtable2plot in plotrix or grid.table / tableGrob in
 gridExtras.

 Michael

 On Mon, May 21, 2012 at 4:29 PM, Alexander Shenkin ashen...@ufl.edu wrote:
 Hello folks,

 I've been on a journey trying to figure out how to manage documents that
 are amenable to sharing and editing, but that contain dynamic content
 generated by R.  I've come to the following solution: I use Sweave to
 generate labeled png  pdf figures, and I Insert  Link those figures
 as Pictures in a Word 2010 doc.  Thus, when data or code changes, I
 regenerate the figures with Sweave, open the Word doc and hit F9, and
 all the figures are automatically updated.  I can send the file around,
 folks can comment and edit, track changes, etc.

 Now, however, I'm trying to do the same for tables that I did for
 figures, and it seems a bit more difficult.  I can spit out tex tables
 into separate files using the split=TRUE chunk option, and I can even
 make those tables into html with xtable(type=html).  Word, however,
 doesn't have the Insert  Link option for external text files (which
 makes it such that, if the external file isn't found, Word uses a copy
 stored in the doc).

 So, I think it will be better if I can somehow generate the tables as
 images.  Is there any way to generate tables as images in separate files
 in Sweave?  Or, is there another tree up which I should be barking?

 Thanks,
 Allie

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Syntax for lme function to model random factors and interactions

2012-05-21 Thread Peter Ehlers

Inline:

On 2012-05-21 11:17, i_like_macs wrote:

Hello Joshua,

Many thanks for your help, especially from a fellow Bruin (I went there as
an undergrad!).

I understand that there is another forum for mixed models. If my problem
can't be solved within this thread, I'll have to go there. I do understand
some theory about mixed models, but obviously am far from an expert.

My question is not so much statistical advice, as it concerns the correct
syntax to include random factors and interactions (which include these
random factors) for the lme function. Maybe it's because I'm used to SPSS,
but I find R very difficult to use, even after looking up its built-in help.


Just a small comment, since you're interested in correct syntax:
you apparently consider A*B to represent the (A,B)
interaction term; in R, it's A:B and this *is* clearly documented
in the help pages.

Peter Ehlers



I could run your neat code suggestion:

lme(Y ~ (A + B + C + D)^3, data = myData, random = ~ 1 | C, method = ML)

but would like to know how to also include D as a random factor. My
understanding is that the random argument for the lme function is coded
as:

~ x1 + ... + xn | g1 / ... / gm

where the left side describes the model for random effects, and the right
side describes the grouping structure. Reading other posts, I learned that I
need both sides for the code to run without errors. However, it's not clear
to me what both sides represent. The left side appears to be where the
random factors are specified, perhaps like this:

random = ~ C + D

But then this results in errors. Does this mean I have to somehow join the
two following lines of code to specify both random factors?

random = ~ 1 | C
random = ~ 1 | D

It's not clear what the ~ 1 represents here, as I would have guessed that
this is where the random factors would be specified. Is this related to an
intercept-only model?

I'm sorry for sounding so lost. This is because I am. Perhaps I need to know
more theory of mixed models, but this seems to be possible only if I
understand what parts of the lme function are.

Thank you very much again,

Daisuke


--
View this message in context: 
http://r.789695.n4.nabble.com/Syntax-for-lme-function-to-model-random-factors-and-interactions-tp4630744p4630789.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] List indexing question

2012-05-21 Thread David Perlman
Consider the following:
 x-list(c(1,2,3),c(4,5,6))
 x[1]
[[1]]
[1] 1 2 3

 x[2]
[[1]]
[1] 4 5 6

So far that all seems reasonable.  But now there's a problem.  I'm used to 
python, where I would say x[2][1] and get the value 4.  But I can't figure out 
how to do that in R.

 x[2][1]
[[1]]
[1] 4 5 6

 x[2,1]
Error in x[2, 1] : incorrect number of dimensions

I have no idea why x[2][1] returns the same thing as x[2]; that makes no sense 
to me at all.

What is the proper syntax for what I'm trying to do?

Thanks!


-dave--
A neuroscientist is at the video arcade, when someone makes him a $1000 bet
on Pac-Man. He smiles, gets out his screwdriver and takes apart the Pac-Man
game. Everyone says What are you doing? The neuroscientist says Well,
since we all know that Pac-Man is based on electric signals traveling
through these circuits, obviously I can understand it better than the other
guy by going straight to the source!

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


Re: [R] List indexing question

2012-05-21 Thread R. Michael Weylandt
It's a little funny, you actually need

x[[2]][1]

What's going on is the following:

lists can contain anything else in R, including more lists so
subsetting them takes a hair more work. x[2] returns the sublist of x
containing the second list element -- this is, however, not the same
as x[[2]] which truly returns the second element of x. The single
brackets allow more complex subsetting: x[1:2] would return the
sublist of first and second elements (still in a list) while x[[1:2]]
would be an error (because that doesn't really make any sense)

The way I heard this explained best is: if x is a train, x[2] is the
second car of the train, while x[[2]] is the contents of that car.

Hope this helps,
Michael

On Mon, May 21, 2012 at 8:07 PM, David Perlman dperl...@wisc.edu wrote:
 Consider the following:
 x-list(c(1,2,3),c(4,5,6))
 x[1]
 [[1]]
 [1] 1 2 3

 x[2]
 [[1]]
 [1] 4 5 6

 So far that all seems reasonable.  But now there's a problem.  I'm used to 
 python, where I would say x[2][1] and get the value 4.  But I can't figure 
 out how to do that in R.

 x[2][1]
 [[1]]
 [1] 4 5 6

 x[2,1]
 Error in x[2, 1] : incorrect number of dimensions

 I have no idea why x[2][1] returns the same thing as x[2]; that makes no 
 sense to me at all.

 What is the proper syntax for what I'm trying to do?

 Thanks!


 -dave--
 A neuroscientist is at the video arcade, when someone makes him a $1000 bet
 on Pac-Man. He smiles, gets out his screwdriver and takes apart the Pac-Man
 game. Everyone says What are you doing? The neuroscientist says Well,
 since we all know that Pac-Man is based on electric signals traveling
 through these circuits, obviously I can understand it better than the other
 guy by going straight to the source!

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Problem with function

2012-05-21 Thread acnunn
Hi,

I'm new to R, so apologies in advance for the triviality of this question,
but I was wondering if anyone could tell me why this function doesn't return
the expected output, i.e. a matrix containing two columns from a large data
frame called 'finalTable'? Oddly, the statement between the curly brackets
works if run with 'thisCol' and 'thatCol' already defined. Any help would be
much appreciated.



Here's what 'finalTable' looks like, if it helps:-



Many thanks, Adam

--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-function-tp4630805.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] Random effect in an Incomplete block design

2012-05-21 Thread Reza Deihimfard
Dear R Users,

I am facing a problem analyzing an incomplete block design with two replicates. 
As you can see in the attached .xls file, the factor2 (6 levels) nested within 
factor1(two levels) nested within replicates all were chosen as random effects 
in the statistical model (see below). Note that the replicates are incomplete. 
The effect of year crossed with these factors as random.  To handle incomplete 
design and random effects, I used lme package instead of aov as follows:

library(nlme)
data- read.table(C:\\Users\\user\\Desktop\\sb.txt,header=T)
attach(data)
model-lme(var~1+ year+ year*replicates+ year*factor1+ year*factor2, 
random=~1|replicates/factor1/factor2)
summary(model)
 
 The above-code is runnable. However, could you please make me sure of the 
following points?

1- Have I defined the interactions correctly (particularly year by other 
factors) ?
 
2- Which one should I include into the statistical model, replicates or 
block.incomplete?
 
3- How can I compare different levels of each factor (i.e. factor1, factor2, 
year)? In other words, is there any way to use LSD or SED methods in the 
package lme?
 
Your help would be highly appreciated.
 
Best regards,
RezaPlotyearreplicates  block.incompletefactor1 factor2 var
1   19901   1   t2  G2  10
2   19901   1   t2  G3  12
3   19901   1   t2  G4  16
4   19901   1   t2  C1  12
5   19901   1   t2  C2  11
6   19901   1   t2  G1  13
7   19901   2   t1  G1  19
8   19901   2   t1  G2  29
9   19901   2   t1  G3  30
10  19901   2   t1  C1  23
11  19901   2   t1  R   32
12  19901   2   t1  C2  33
13  19902   1   t2  G4  12
14  19902   1   t2  C1  14
15  19902   1   t2  C2  18
16  19902   1   t2  G1  14
17  19902   1   t2  G2  13
18  19902   1   t2  G3  15
19  19902   2   t1  C1  21
20  19902   2   t1  R   31
21  19902   2   t1  C2  32
22  19902   2   t1  G1  25
23  19902   2   t1  G2  34
24  19902   2   t1  G3  35
1   19961   1   t2  G1  28
2   19961   1   t2  G2  30
3   19961   1   t2  G3  34
4   19961   1   t2  G4  30
5   19961   1   t2  C1  29
6   19961   1   t2  C2  31
7   19961   2   t1  C2  37
8   19961   2   t1  G1  47
9   19961   2   t1  G2  48
10  19961   2   t1  G3  41
11  19961   2   t1  C1  50
12  19961   2   t1  R   51
13  19962   1   t2  G3  30
14  19962   1   t2  G4  32
15  19962   1   t2  C1  36
16  19962   1   t2  C2  32
17  19962   1   t2  G1  31
18  19962   1   t2  G2  33
19  19962   2   t1  G3  39
20  19962   2   t1  C1  49
21  19962   2   t1  R   50
22  19962   2   t1  C2  43
23  19962   2   t1  G1  52
24  19962   2   t1  G2  53
1   20021   1   t2  C1  16
2   20021   1   t2  C2  18
3   20021   1   t2  G1  22
4   20021   1   t2  G2  18
5   20021   1   t2  G3  17
6   20021   1   t2  G4  19
7   20021   2   t1  C1  25
8   20021   2   t1  R   35
9   20021   2   t1  C2  36
10  20021   2   t1  G1  29
11  20021   2   t1  G2  38
12  20021   2   t1  G3  39
13  20022   1   t2  G1  18
14  20022   1   t2  G2  20
15  20022   1   t2  G3  24
16  20022   1   t2  G4  20
17  20022   1   t2  C1  19
18  20022   1   t2  C2  21
19  20022   2   t1  G1  27
20  20022   2   t1  G2  37
21  20022   2   t1  G3  38
22  20022   2   t1  C1  31
23  20022   2   t1  R   40
24  20022   2   t1  C2  41
__

Re: [R] problem with data frame to numeric transformation

2012-05-21 Thread Rui Barradas
Hello,

You need to tell read.table that the table has headers.


# needed 'header=TRUE'
first - read.table(RESIDSNEWr.csv, sep=;, quote=\,
header=TRUE)[c(1)]
second - read.table(RESIDSNEWr.csv, sep=;, quote=\,
header=TRUE)[c(2)]
# see what they look like
str(first)
str(second)

is.numeric(first) ## FALSE
is.numeric(second) ## FALSE

is.numeric(first$aaa) ## TRUE
is.numeric(second$bbb) ## TRUE
# general purpose
sapply(first, is.numeric)
sapply(second, is.numeric)


And the rest works at the first try.

 calibKendallsTau(cc,cor(first,second,method=kendall))
 bbb
aaa 4.420256
 
 ## goodness-of-fit tests
 gf.cc - gofCopula(cc,u,method=itau)
Progress will be displayed every 100 iterations.
Iteration 100 
[...etc...]
Iteration 1000 
 
 gf.cc$pvalue
[1] 0.0004995005


Hope this helps,

Rui Barradas

Ivette wrote
 
  http://r.789695.n4.nabble.com/file/n4630788/GOF_CGIK.R GOF_CGIK.R  
 http://r.789695.n4.nabble.com/file/n4630788/RESIDSNEWr.csv RESIDSNEWr.csv 
 
 In order to save place, I attach the data and the R code, for which I have
 2 questions.
 
 1/ I cannot convert successfully the data frames with names first and
 second in numeric format. They participate here: 
 
 calibKendallsTau(cc,cor(first,second,method=kendall)) and I get an error
 message.
 
 2/ I have cut the dates from my data file RESIDSNEWr.csv, but let's
 suppose I want to keep them. How shall I update the code from 1/ in order
 to have also the dates?
 
 Many thanks in advance to all, who will answer my message
 


--
View this message in context: 
http://r.789695.n4.nabble.com/problem-with-data-frame-to-numeric-transformation-tp4630788p4630803.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 with function

2012-05-21 Thread Rui Barradas
Hello,

There's nothing wrong with having 'thisCol' and 'thatCol' already defined or
not.
The problem is that your function does NOT return a value. Get rid of the
assignment and it will work.


CompFunct - function(thisCol, thatCol) {cbind(finalTable[, thisCol],
finalTable[, thatCol])}


I would also include a data.frame argument,

CompFunct2 - function(x, thisCol, thatCol) {cbind(x[, thisCol], x[,
thatCol])}
CompFunct2(finalTable, 2, 3)

(But the function is so simple that maybe it's purpose is to save some
keystrokes.)


Hope this helps,

Rui Barradas

acnunn wrote
 
 Hi,
 
 I'm new to R, so apologies in advance for the triviality of this question,
 but I was wondering if anyone could tell me why this function doesn't
 return the expected output, i.e. a matrix containing two columns from a
 large data frame called 'finalTable'? Oddly, the statement between the
 curly brackets works if run with 'thisCol' and 'thatCol' already defined.
 Any help would be much appreciated.
 
 
 
 Here's what 'finalTable' looks like, if it helps:-
 
 
 
 Many thanks, Adam
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-function-tp4630805p4630808.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] List indexing question

2012-05-21 Thread Michael Sumner
There is also the recursive extraction with [[:

x[[c(2, 1)]]
[1] 4

From ?Extract

 ‘[[’ can be applied recursively to lists, so that if the single
 index ‘i’ is a vector of length ‘p’, ‘alist[[i]]’ is equivalent to
 ‘alist[[i1]]...[[ip]]’ providing all but the final indexing
 results in a list. 

On Tue, May 22, 2012 at 10:14 AM, R. Michael Weylandt
michael.weyla...@gmail.com wrote:
 It's a little funny, you actually need

 x[[2]][1]

 What's going on is the following:

 lists can contain anything else in R, including more lists so
 subsetting them takes a hair more work. x[2] returns the sublist of x
 containing the second list element -- this is, however, not the same
 as x[[2]] which truly returns the second element of x. The single
 brackets allow more complex subsetting: x[1:2] would return the
 sublist of first and second elements (still in a list) while x[[1:2]]
 would be an error (because that doesn't really make any sense)

 The way I heard this explained best is: if x is a train, x[2] is the
 second car of the train, while x[[2]] is the contents of that car.

 Hope this helps,
 Michael

 On Mon, May 21, 2012 at 8:07 PM, David Perlman dperl...@wisc.edu wrote:
 Consider the following:
 x-list(c(1,2,3),c(4,5,6))
 x[1]
 [[1]]
 [1] 1 2 3

 x[2]
 [[1]]
 [1] 4 5 6

 So far that all seems reasonable.  But now there's a problem.  I'm used to 
 python, where I would say x[2][1] and get the value 4.  But I can't figure 
 out how to do that in R.

 x[2][1]
 [[1]]
 [1] 4 5 6

 x[2,1]
 Error in x[2, 1] : incorrect number of dimensions

 I have no idea why x[2][1] returns the same thing as x[2]; that makes no 
 sense to me at all.

 What is the proper syntax for what I'm trying to do?

 Thanks!


 -dave--
 A neuroscientist is at the video arcade, when someone makes him a $1000 bet
 on Pac-Man. He smiles, gets out his screwdriver and takes apart the Pac-Man
 game. Everyone says What are you doing? The neuroscientist says Well,
 since we all know that Pac-Man is based on electric signals traveling
 through these circuits, obviously I can understand it better than the other
 guy by going straight to the source!

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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.



-- 
Michael Sumner
Institute for Marine and Antarctic Studies, University of Tasmania
Hobart, Australia
e-mail: mdsum...@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] Problem with function

2012-05-21 Thread David Winsemius


On May 21, 2012, at 5:13 PM, acnunn wrote:


Hi,

I'm new to R, so apologies in advance for the triviality of this  
question,
but I was wondering if anyone could tell me why this function  
doesn't return
the expected output, i.e. a matrix containing two columns from a  
large data
frame called 'finalTable'? Oddly, the statement between the curly  
brackets
works if run with 'thisCol' and 'thatCol' already defined. Any help  
would be

much appreciated.



Nothing there.



Here's what 'finalTable' looks like, if it helps:-




Nothing to look at here, either.

You have managed to find an even more obscure method of not presenting  
information than is usual for Nabble postings.


--
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] glm(weights) and standard errors

2012-05-21 Thread Steve Taylor
Is there a way to tell glm() that rows in the data represent a certain number 
of observations other than one?  Perhaps even fractional values?

Using the weights argument has no effect on the standard errors.  Compare the 
following; is there a way to get the first and last models to produce the same 
results?

data(sleep)
coef(summary(glm(extra ~ group, data=sleep)))
coef(summary(glm(extra ~ group, data=sleep, weights=rep(10L,nrow(sleep)
sleep10 = sleep[rep(1:nrow(sleep),10),]
coef(summary(glm(extra ~ group, data=sleep10)))
coef(summary(glm(extra ~ group, data=sleep10, weights=rep(0.1,nrow(sleep10)

My reason for asking is so that I can fit a model to a stacked multiple 
imputation data set, as suggested by:

Wood, A. M., White, I. R. and Royston, P. (2008), How should variable selection 
be performed with multiply imputed data?. Statist. Med., 27: 3227-3246. doi: 
10.1002/sim.3177

Other suggestions would be most welcome.

___

Steve Taylor
Biostatistician
Pacific Islands Families Study
Faculty of Health and Environmental Sciences
AUT University

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


Re: [R] glm(weights) and standard errors

2012-05-21 Thread David Winsemius


On May 21, 2012, at 10:58 PM, Steve Taylor wrote:

Is there a way to tell glm() that rows in the data represent a  
certain number of observations other than one?  Perhaps even  
fractional values?


Using the weights argument has no effect on the standard errors.   
Compare the following; is there a way to get the first and last  
models to produce the same results?


data(sleep)
coef(summary(glm(extra ~ group, data=sleep)))
coef(summary(glm(extra ~ group, data=sleep,  
weights=rep(10L,nrow(sleep)


Here's a reasonably simple way to do it:

coef(summary(glm(extra ~ group, data=sleep[ rep(10L,nrow(sleep)), ] )))


--
David.


sleep10 = sleep[rep(1:nrow(sleep),10),]
coef(summary(glm(extra ~ group, data=sleep10)))
coef(summary(glm(extra ~ group, data=sleep10,  
weights=rep(0.1,nrow(sleep10)


My reason for asking is so that I can fit a model to a stacked  
multiple imputation data set, as suggested by:


Wood, A. M., White, I. R. and Royston, P. (2008), How should  
variable selection be performed with multiply imputed data?.  
Statist. Med., 27: 3227-3246. doi: 10.1002/sim.3177


Other suggestions would be most welcome.

___

Steve Taylor
Biostatistician
Pacific Islands Families Study
Faculty of Health and Environmental Sciences
AUT University

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


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] List indexing question

2012-05-21 Thread arun
Hi David,

Try

 x[[2]][1]
[1] 4
 


A.K.

- Original Message -
From: David Perlman dperl...@wisc.edu
To: r-help@r-project.org
Cc: 
Sent: Monday, May 21, 2012 8:07 PM
Subject: [R] List indexing question

Consider the following:
 x-list(c(1,2,3),c(4,5,6))
 x[1]
[[1]]
[1] 1 2 3

 x[2]
[[1]]
[1] 4 5 6

So far that all seems reasonable.  But now there's a problem.  I'm used to 
python, where I would say x[2][1] and get the value 4.  But I can't figure out 
how to do that in R.

 x[2][1]
[[1]]
[1] 4 5 6

 x[2,1]
Error in x[2, 1] : incorrect number of dimensions

I have no idea why x[2][1] returns the same thing as x[2]; that makes no sense 
to me at all.

What is the proper syntax for what I'm trying to do?

Thanks!


-dave--
A neuroscientist is at the video arcade, when someone makes him a $1000 bet
on Pac-Man. He smiles, gets out his screwdriver and takes apart the Pac-Man
game. Everyone says What are you doing? The neuroscientist says Well,
since we all know that Pac-Man is based on electric signals traveling
through these circuits, obviously I can understand it better than the other
guy by going straight to the source!

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


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


  1   2   >