Re: [R] Multiple left hand side variables in a formula

2013-03-02 Thread Achim Zeileis

On Fri, 1 Mar 2013, Frank Harrell wrote:


Thank you Bill.  A temporary re-arrangement of the formula will allow me to
do the usual subset= na.action= processing afterwards.  Nice idea.  I don't
need the dot notation very often for this application.


That's what the Formula package provides. It allows for multiple parts 
and multiple responses on both side of the ~. Internally, the formula is 
decomposed and separate terms are produced. And using an auxiliary formula 
it is assured that a single model frame (with unified NA processing). And 
all of this is hidden from the user by providing methods that are as 
standard as possible, see:


vignette(Formula, package = Formula)

hth,
Z


Frank

William Dunlap wrote

I don't know how much of the information that model.frame supplies you
need,
but you could make a data.frame containing all the variables on both sides
of them
formula by changing lhs~rhs into ~lhs+rsh before calling model.frame.
E.g.,

f - function (formula)  {
if (length(formula) == 3) { # has left hand side
envir - environment(formula)
formula - formula(call(~, call(+, formula[[2]],
formula[[3]])))
environment(formula) - envir
}
formula
}

This doesn't quite take care of the wild-card dot in the formula: straight
variables are omitted from dot's expansion but functions of variables are
not:

colnames(model.frame(f(log(mpg)+hp ~ .), data=mtcars))

 [1] log(mpg) hp   mpg  cyl
 [5] disp drat wt   qsec
 [9] vs   am   gear carb

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com



-Original Message-
From:



r-help-bounces@



 [mailto:



r-help-bounces@



] On Behalf

Of Frank Harrell
Sent: Friday, March 01, 2013 4:17 PM
To:



r-help@



Subject: [R] Multiple left hand side variables in a formula

The lattice package uses special logic to allow for multiple
left-hand-side
variables in a formula, e.g. y1 + y2 ~ x.  Is there an elegant way to do
this outside of lattice?  I'm trying to implement a data summarization
function that logically takes multiple dependent variables.  The usual
invocation of model.frame( ) causes R to try to do arithmetic addition to
create a single dependent variable.

Thanks
Frank



-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context:
http://r.789695.n4.nabble.com/Multiple-left-hand-side-
variables-in-a-formula-tp4660060.html
Sent from the R help mailing list archive at Nabble.com.

__




R-help@



 mailing list

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


__



R-help@



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






-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/Multiple-left-hand-side-variables-in-a-formula-tp4660060p4660065.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] replace zeros for NA in a column based on values of another column

2013-03-02 Thread Camilo Mora

Hi everyone,

Imagine that I have a data frame with four columns:
data-
a   b   c   d
0   1   1   0
1   1   1   1
1   0   0   1

I want to replace the zeros in columns a:b for NA only for the rows in  
which column d are zero. So


a   b   c   d
NA  1   1   0
1   1   1   1
1   0   0   1

I am trying this:
data[,1:3][data[4] == 0] - NA
But get this error:

Error in `[-.data.frame`(`*tmp*`, Data[4] == 0, value = NA) :
  only logical matrix subscripts are allowed in replacement

Does anyone knows the reason of this error or is there an alternative  
to replace the values in one column based on the values of another?


Thanks,

Camilo

Camilo Mora, Ph.D.
Department of Geography, University of Hawaii
http://www.soc.hawaii.edu/mora/

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


Re: [R] using reserved words in R, and reuse variable names in different functions

2013-03-02 Thread Duncan Murdoch

On 13-03-01 8:35 PM, C W wrote:

Thanks, everyone, I will definitely avoid it.  Is there any tips on naming
variables?  I've seen the Google R style guider and Hadley R style guide.


Name them in ways that are meaningful to you.  R standard function names 
are famous for not following any naming pattern consistently.  Avoid 
using dots in the name unless you are defining methods (e.g. print.lm is 
the print method for lm objects).




For example, I want to use pie_t, to denote stationary distribution pie at
time t.  Both pi and pie are function names themselves.


Actually pi is not a function, but it is a variable.  If you write a 
package that exports a function or variable named pi, it would mask the 
standard one, and that could cause big problems for users.  If you use 
it internally, it will only mask the standard one in your code, and that 
may not matter to you.


pie is a function, but all it does is draw pie charts, so who cares if 
you mask it? :-).


Duncan Murdoch


Mike

On Fri, Mar 1, 2013 at 8:12 PM, William Dunlap wdun...@tibco.com wrote:


See fortune(dog).

To wit:
   Firstly, don't call your matrix 'matrix'. Would you call your dog
'dog'? Anyway, it might clash with the function 'matrix'

I once had a cat named kitty and she never had a problem with it.

Clashes between non-functions and functions that cause problems are not
that common.  With 4000 packages, each with a number of functions, it is
hard to avoid using a name that someone has used for a function.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com



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

On Behalf

Of Rolf Turner
Sent: Saturday, March 02, 2013 5:01 AM
To: Sarah Goslee
Cc: r-help
Subject: Re: [R] using reserved words in R, and reuse variable names in

different

functions

On 03/02/2013 01:12 PM, Sarah Goslee wrote:

On Fri, Mar 1, 2013 at 7:06 PM, C W tmrs...@gmail.com wrote:

Thanks, that was just an example I came up with.  I was just curious

if

using same variable names in different functions would cause problems.

No. The environment of a function is independent of other functions.


   Especially with reserved words.

Yes. Using reserved words can cause all kinds of subtle problems.

Avoid it.




Very sound advice.  But it should be noted that t, c, and matrix
to which
the OP referred are *not* technically reserved words.  Nonetheless their

use

as names of user-defined objects should be eschewed.  See fortune(dog).

You *can't* actually assign values to reserved words.  E.g.

  TRUE - 42

throws an error.  (Whereas matrix - 42, bad form though it may be,
does not throw an error.)

  cheers,

  Rolf Turner

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

http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


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



[[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] replace zeros for NA in a column based on values of another column

2013-03-02 Thread Anthony Damico
you want to replace all rows where the 4th column is zero..  (data[ , 4 ]
== 0)
and you want to perform that replacement in the first column..

so try

data[ data[ , 4 ] == 0 , 1 ] - NA



On Sat, Mar 2, 2013 at 5:26 AM, Camilo Mora cm...@dal.ca wrote:

 Hi everyone,

 Imagine that I have a data frame with four columns:
 data-
 a   b   c   d
 0   1   1   0
 1   1   1   1
 1   0   0   1

 I want to replace the zeros in columns a:b for NA only for the rows in
 which column d are zero. So

 a   b   c   d
 NA  1   1   0
 1   1   1   1
 1   0   0   1

 I am trying this:
 data[,1:3][data[4] == 0] - NA
 But get this error:

 Error in `[-.data.frame`(`*tmp*`, Data[4] == 0, value = NA) :
   only logical matrix subscripts are allowed in replacement

 Does anyone knows the reason of this error or is there an alternative to
 replace the values in one column based on the values of another?

 Thanks,

 Camilo

 Camilo Mora, Ph.D.
 Department of Geography, University of Hawaii
 http://www.soc.hawaii.edu/**mora/ http://www.soc.hawaii.edu/mora/

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html 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] replace zeros for NA in a column based on values of another column

2013-03-02 Thread Rui Barradas

Hello,

Try

# for columns a.b it's 1:2, not 1:3
data[data[,4] == 0, 1:3] - NA  # columns a, b and c


Hope this helps,

Rui Barradas

Em 02-03-2013 10:26, Camilo Mora escreveu:

Hi everyone,

Imagine that I have a data frame with four columns:
data-
a   b   c   d
0   1   1   0
1   1   1   1
1   0   0   1

I want to replace the zeros in columns a:b for NA only for the rows in
which column d are zero. So

a   b   c   d
NA  1   1   0
1   1   1   1
1   0   0   1

I am trying this:
data[,1:3][data[4] == 0] - NA
But get this error:

Error in `[-.data.frame`(`*tmp*`, Data[4] == 0, value = NA) :
   only logical matrix subscripts are allowed in replacement

Does anyone knows the reason of this error or is there an alternative to
replace the values in one column based on the values of another?

Thanks,

Camilo

Camilo Mora, Ph.D.
Department of Geography, University of Hawaii
http://www.soc.hawaii.edu/mora/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Multiple left hand side variables in a formula

2013-03-02 Thread Frank Harrell
Achim this is perfect.  I had not seen Formula before.  Thanks for writing
it!
Frank

Achim Zeileis-4 wrote
 On Fri, 1 Mar 2013, Frank Harrell wrote:
 
 Thank you Bill.  A temporary re-arrangement of the formula will allow me
 to
 do the usual subset= na.action= processing afterwards.  Nice idea.  I
 don't
 need the dot notation very often for this application.
 
 That's what the Formula package provides. It allows for multiple parts 
 and multiple responses on both side of the ~. Internally, the formula is 
 decomposed and separate terms are produced. And using an auxiliary formula 
 it is assured that a single model frame (with unified NA processing). And 
 all of this is hidden from the user by providing methods that are as 
 standard as possible, see:
 
 vignette(Formula, package = Formula)
 
 hth,
 Z
 
 Frank

 William Dunlap wrote
 I don't know how much of the information that model.frame supplies you
 need,
 but you could make a data.frame containing all the variables on both
 sides
 of them
 formula by changing lhs~rhs into ~lhs+rsh before calling model.frame.
 E.g.,

 f - function (formula)  {
 if (length(formula) == 3) { # has left hand side
 envir - environment(formula)
 formula - formula(call(~, call(+, formula[[2]],
 formula[[3]])))
 environment(formula) - envir
 }
 formula
 }

 This doesn't quite take care of the wild-card dot in the formula:
 straight
 variables are omitted from dot's expansion but functions of variables
 are
 not:
 colnames(model.frame(f(log(mpg)+hp ~ .), data=mtcars))
  [1] log(mpg) hp   mpg  cyl
  [5] disp drat wt   qsec
  [9] vs   am   gear carb

 Bill Dunlap
 Spotfire, TIBCO Software
 wdunlap tibco.com


 -Original Message-
 From:

 r-help-bounces@

  [mailto:

 r-help-bounces@

 ] On Behalf
 Of Frank Harrell
 Sent: Friday, March 01, 2013 4:17 PM
 To:

 r-help@

 Subject: [R] Multiple left hand side variables in a formula

 The lattice package uses special logic to allow for multiple
 left-hand-side
 variables in a formula, e.g. y1 + y2 ~ x.  Is there an elegant way to
 do
 this outside of lattice?  I'm trying to implement a data summarization
 function that logically takes multiple dependent variables.  The usual
 invocation of model.frame( ) causes R to try to do arithmetic addition
 to
 create a single dependent variable.

 Thanks
 Frank



 -
 Frank Harrell
 Department of Biostatistics, Vanderbilt University
 --
 View this message in context:
 http://r.789695.n4.nabble.com/Multiple-left-hand-side-
 variables-in-a-formula-tp4660060.html
 Sent from the R help mailing list archive at Nabble.com.

 __


 R-help@

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

 __

 R-help@

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





 -
 Frank Harrell
 Department of Biostatistics, Vanderbilt University
 --
 View this message in context:
 http://r.789695.n4.nabble.com/Multiple-left-hand-side-variables-in-a-formula-tp4660060p4660065.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 

 R-help@

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

 
 __

 R-help@

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





-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/Multiple-left-hand-side-variables-in-a-formula-tp4660060p4660080.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] Multiple left hand side variables in a formula

2013-03-02 Thread Frank Harrell
Hi Gabor,

This is not for a regression function but for a major update I'm working on
for the summary.formula function in the Hmisc package.  So I need to handle
several data types in the formula.

Thanks
Frank

Gabor Grothendieck wrote
 Gabor Grothendieck wrote
 On Fri, Mar 1, 2013 at 7:16 PM, Frank Harrell lt;

 f.harrell@

 gt; wrote:
 The lattice package uses special logic to allow for multiple
 left-hand-side
 variables in a formula, e.g. y1 + y2 ~ x.  Is there an elegant way to
 do
 this outside of lattice?  I'm trying to implement a data summarization
 function that logically takes multiple dependent variables.  The usual
 invocation of model.frame( ) causes R to try to do arithmetic addition
 to
 create a single dependent variable.


 Try:

 lm( cbind(Sepal.Length, Sepal.Width) ~., iris)

 
 On Fri, Mar 1, 2013 at 8:02 PM, Frank Harrell lt;

 f.harrell@

 gt; wrote:
 Thanks for your reply Gabor.  That doesn't handle a mixture of factor and
 numeric variables on the left hand side.
 Frank

 
 It can handle 2 level factors
 
lm(cbind(Sepal.Length, setosa = Species == setosa) ~ ., iris)
 
 and more with some manual effort:
 
lm(cbind(virginica = Species == virginica, setosa = Species ==
 setosa) ~ ., iris)
 
 Typically you don't see more than that as a dependent variable.  Do
 you actually need more?
 
 --
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at gmail.com
 
 __

 R-help@

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





-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/Multiple-left-hand-side-variables-in-a-formula-tp4660060p4660081.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] Dealing with parentheses within variable names

2013-03-02 Thread Duncan Murdoch

On 13-03-01 12:57 PM, Duncan Murdoch wrote:

On 01/03/2013 11:20 AM, William Dunlap wrote:



A core R function that fails with odd names is reformulate():
  reformulate(c(P/E, % Growth), response=+-)
 Error in parse(text = termtext) : text:1:16: unexpected input
 1: response ~ P/E+% Growth
  ^


Thanks.  That one looks relatively easy to fix.


After taking a closer look, I realized that it is actually behaving as 
designed.  The first input to reformulate is supposed to be a character 
vector, not bits of R language.  For example, we want


reformulate(x*w)

to return

~ x*w

not

~ `x*w`

So you might think your example should have been entered as

reformulate(c(`P/E`, `% Growth`), response=`+-`)

However, this doesn't quite work:  it ends up with response having 
double backticks.  The way to get what you want is to use


reformulate(c(`P/E`, `% Growth`), response=as.name(+-))

Definitely not my favourite design for a function, but I think it's not 
a code issue.  Maybe something should be added to the help page, but 
this is such an obscure issue that I'm not sure I could make things clearer.


Duncan Murdoch

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


[R] How to start console output with a comment sign (as in knitr)

2013-03-02 Thread Marcus Kriele
Dear all,
knitr writes a comment sign in front of each line of console output.  This 
extremely useful, especially for beginners who are starting to write scripts.  
One could just compose their script in the console (getting immediate output) 
and then copy the whole chunk into their .r-file. 
I have been able to configure the options such that the prompt and the 
continuing line labels are replaced by blanks.  However, I do not know how to 
automatically comment out each line of output.  Ideally, my console would 
behave exactly like knitr.

At my work place I only have access to the R console that is included the 
standard download for windows.  I cannot replace it by an editor that may have 
additional features.

Would there be a way to achieve the knitr-look in the standard console?

Many thanks,  Marcus
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 zeros for NA in a column based on values of another column

2013-03-02 Thread arun
HI,

Not sure I understand it correctly,

data1-read.table(text=
 a  b  c  d
 0  1  1  0
 1  1  1  1
 1  0  0  1
,sep=,header=TRUE)
data2- data1
data3- data1
If i follow this logic for the 1st and 2nd columns,
 data1[ data1[ , 4 ] == 0 , 1 ] - NA
 data1[ data1[ , 4 ] == 0 , 2 ] - NA
 data1
#   a  b c d
#1 NA NA 1 0
#2  1  1 1 1
#3  1  0 0 1

Still, the column 'b' with 0 element is left as such while and `1` in b is 
replaced with NA

  data2[,1][data2[,4]==0  data2[,1]==0]- NA
 data2[,2][data2[,4]==0  data2[,2]==0]- NA
 data2
#   a b c d
#1 NA 1 1 0
#2  1 1 1 1
#3  1 0 0 1

#or you can try
data3[,1:2]- lapply(letters[1:2],function(x) 
{x1-cbind(data3[,x],data3[,4]);colnames(x1)- c(x,d);x1; 
x1[rowSums(x1)==0,1]-NA;x1[,1]})
 data3
#   a b c d
#1 NA 1 1 0
#2  1 1 1 1
#3  1 0 0 1

A.K.




- Original Message -
From: Anthony Damico ajdam...@gmail.com
To: Camilo Mora cm...@dal.ca
Cc: R help r-help@r-project.org
Sent: Saturday, March 2, 2013 6:10 AM
Subject: Re: [R] replace zeros for NA in a column based on values of another 
column

you want to replace all rows where the 4th column is zero..  (data[ , 4 ]
== 0)
and you want to perform that replacement in the first column..

so try

data[ data[ , 4 ] == 0 , 1 ] - NA



On Sat, Mar 2, 2013 at 5:26 AM, Camilo Mora cm...@dal.ca wrote:

 Hi everyone,

 Imagine that I have a data frame with four columns:
 data-
 a       b       c       d
 0       1       1       0
 1       1       1       1
 1       0       0       1

 I want to replace the zeros in columns a:b for NA only for the rows in
 which column d are zero. So

 a       b       c       d
 NA      1       1       0
 1       1       1       1
 1       0       0       1

 I am trying this:
 data[,1:3][data[4] == 0] - NA
 But get this error:

 Error in `[-.data.frame`(`*tmp*`, Data[4] == 0, value = NA) :
   only logical matrix subscripts are allowed in replacement

 Does anyone knows the reason of this error or is there an alternative to
 replace the values in one column based on the values of another?

 Thanks,

 Camilo

 Camilo Mora, Ph.D.
 Department of Geography, University of Hawaii
 http://www.soc.hawaii.edu/**mora/ http://www.soc.hawaii.edu/mora/

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


    [[alternative HTML version deleted]]

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


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

2013-03-02 Thread Frank Harrell
I would like to have a lattice conditioning ( | var ) variable have
expression() as values because I want panel labels to be able to use
plotmath notation for subscripts, etc.   lattice barks at this.  Does anyone
know of a trick workaround?  An attempted example program is below.  Thanks
-Frank

require(lattice)
set.seed(1)
var - c(rep('A', 100), rep('B', 100))
trt - sample(c('T1','T2'), 200, TRUE)
x - c(runif(100), 10*runif(100))
y - x + c(runif(100)/10, runif(100))
N - tapply(x, llist(var, trt), function(x) sum(!is.na(x)))
print(N)

vn - vector('expression', length(var))
for(v in unique(var)) {
  i - var == v
  n - tapply(!is.na(x[i]), trt[i], sum)
  nam - names(n)
  w - sprintf('paste(%s, (, n[%s]==%g,~~n[%s]==%g,))',
   v, nam[1], n[1], nam[2], n[2])
  cat(w, '\n')
  vn[var == v] - parse(text=w)
  n - sprintf('%s  (n%s=%g, n%s=%g)', v, nam[1],n[1], nam[2],n[2])
  vn[var == v] - n
}
trt - factor(trt)

xyplot(as.integer(trt) ~ x | vn, panel=panel.bpplot, ylim=c(0,3),
   scale=list(y=list(at=1:2, labels=levels(trt)),
 x=list(relation='free', limits=list(c(0,1),c(0,13,
   ylab='Treatment', layout=c(1,2))

Error in unique.default(x) : 
  unimplemented type 'expression' in 'HashTableSetup'




-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/Expressions-in-lattice-conditional-variables-tp4660089.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] Expressions in lattice conditional variables

2013-03-02 Thread Frank Harrell
Whoops - these 2 lines should have been omitted from the program:

n - sprintf('%s  (n%s=%g, n%s=%g)', v, nam[1],n[1], nam[2],n[2]) 
 vn[var == v] - n 


Frank Harrell wrote
 I would like to have a lattice conditioning ( | var ) variable have
 expression() as values because I want panel labels to be able to use
 plotmath notation for subscripts, etc.   lattice barks at this.  Does
 anyone know of a trick workaround?  An attempted example program is below. 
 Thanks -Frank
 
 require(lattice)
 set.seed(1)
 var - c(rep('A', 100), rep('B', 100))
 trt - sample(c('T1','T2'), 200, TRUE)
 x - c(runif(100), 10*runif(100))
 y - x + c(runif(100)/10, runif(100))
 N - tapply(x, llist(var, trt), function(x) sum(!is.na(x)))
 print(N)
 
 vn - vector('expression', length(var))
 for(v in unique(var)) {
   i - var == v
   n - tapply(!is.na(x[i]), trt[i], sum)
   nam - names(n)
   w - sprintf('paste(%s, (, n[%s]==%g,~~n[%s]==%g,))',
v, nam[1], n[1], nam[2], n[2])
   cat(w, '\n')
   vn[var == v] - parse(text=w)
   n - sprintf('%s  (n%s=%g, n%s=%g)', v, nam[1],n[1], nam[2],n[2])
   vn[var == v] - n
 }
 trt - factor(trt)
 
 xyplot(as.integer(trt) ~ x | vn, panel=panel.bpplot, ylim=c(0,3),
scale=list(y=list(at=1:2, labels=levels(trt)),
  x=list(relation='free', limits=list(c(0,1),c(0,13,
ylab='Treatment', layout=c(1,2))
 
 Error in unique.default(x) : 
   unimplemented type 'expression' in 'HashTableSetup'





-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/Expressions-in-lattice-conditional-variables-tp4660089p4660090.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 zeros for NA in a column based on values of another column

2013-03-02 Thread Rui Barradas

Hello,

Arun has a point, I forgot to check the element to be replaced for a 
zero. The following code will do that.


dat - read.table(text = 
a   b   c   d
0   1   1   0
1   1   1   1
1   0   0   1
, header = TRUE)
dat - data.matrix(dat)
str(dat)

dat[, 1:2] - sapply(1:2, function(i) ifelse(dat[, i] == 0  dat[, 4] == 
0, NA, dat[, i]))



Hope this helps,

Rui Barradas

Em 02-03-2013 16:11, arun escreveu:

HI,

Not sure I understand it correctly,

data1-read.table(text=
  a  b  c  d
  0  1  1  0
  1  1  1  1
  1  0  0  1
,sep=,header=TRUE)
data2- data1
data3- data1
If i follow this logic for the 1st and 2nd columns,
  data1[ data1[ , 4 ] == 0 , 1 ] - NA
  data1[ data1[ , 4 ] == 0 , 2 ] - NA
  data1
#   a  b c d
#1 NA NA 1 0
#2  1  1 1 1
#3  1  0 0 1

Still, the column 'b' with 0 element is left as such while and `1` in b is 
replaced with NA

   data2[,1][data2[,4]==0  data2[,1]==0]- NA
  data2[,2][data2[,4]==0  data2[,2]==0]- NA
  data2
#   a b c d
#1 NA 1 1 0
#2  1 1 1 1
#3  1 0 0 1

#or you can try
data3[,1:2]- lapply(letters[1:2],function(x) {x1-cbind(data3[,x],data3[,4]);colnames(x1)- 
c(x,d);x1; x1[rowSums(x1)==0,1]-NA;x1[,1]})
  data3
#   a b c d
#1 NA 1 1 0
#2  1 1 1 1
#3  1 0 0 1

A.K.




- Original Message -
From: Anthony Damico ajdam...@gmail.com
To: Camilo Mora cm...@dal.ca
Cc: R help r-help@r-project.org
Sent: Saturday, March 2, 2013 6:10 AM
Subject: Re: [R] replace zeros for NA in a column based on values of another 
column

you want to replace all rows where the 4th column is zero..  (data[ , 4 ]
== 0)
and you want to perform that replacement in the first column..

so try

data[ data[ , 4 ] == 0 , 1 ] - NA



On Sat, Mar 2, 2013 at 5:26 AM, Camilo Mora cm...@dal.ca wrote:


Hi everyone,

Imagine that I have a data frame with four columns:
data-
a   b   c   d
0   1   1   0
1   1   1   1
1   0   0   1

I want to replace the zeros in columns a:b for NA only for the rows in
which column d are zero. So

a   b   c   d
NA  1   1   0
1   1   1   1
1   0   0   1

I am trying this:
data[,1:3][data[4] == 0] - NA
But get this error:

Error in `[-.data.frame`(`*tmp*`, Data[4] == 0, value = NA) :
only logical matrix subscripts are allowed in replacement

Does anyone knows the reason of this error or is there an alternative to
replace the values in one column based on the values of another?

Thanks,

Camilo

Camilo Mora, Ph.D.
Department of Geography, University of Hawaii
http://www.soc.hawaii.edu/**mora/ http://www.soc.hawaii.edu/mora/

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



 [[alternative HTML version deleted]]

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


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



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


Re: [R] How to start console output with a comment sign (as in knitr)

2013-03-02 Thread Bert Gunter
?options

Change the prompt option:
options(prompt = # )   ## is I think what you want.

-- Bert

On Sat, Mar 2, 2013 at 5:35 AM, Marcus Kriele mkri...@me.com wrote:
 Dear all,
 knitr writes a comment sign in front of each line of console output.  This 
 extremely useful, especially for beginners who are starting to write scripts. 
  One could just compose their script in the console (getting immediate 
 output) and then copy the whole chunk into their .r-file.
 I have been able to configure the options such that the prompt and the 
 continuing line labels are replaced by blanks.  However, I do not know how to 
 automatically comment out each line of output.  Ideally, my console would 
 behave exactly like knitr.

 At my work place I only have access to the R console that is included the 
 standard download for windows.  I cannot replace it by an editor that may 
 have additional features.

 Would there be a way to achieve the knitr-look in the standard console?

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


[R] print method like print.anova()

2013-03-02 Thread Michael Friendly
I have a print method for a set of statistical tests, vcdExtra::CMHtest, 
for which I'd like to
have more sensible printing of pvalues, as in print.anova().
[Testing this requires the latest version of vcdExtra, from R-Forge
**|install.packages(vcdExtra, repos=http://R-Forge.R-project.org;)|**
]

With my current print method, I get results like this, but all Prob 
values should better
be reported as something like '0.0001' .

  CMHtest(MSPatients[,,1])
Cochran-Mantel-Haenszel Statistics for New Orleans Neurologist by 
Winnipeg Neurologist

  AltHypothesis  Chisq Df   Prob
corNonzero correlation 51.424  1 7.4426e-13
cmeans  Col mean scores differ 55.393  3 5.6601e-12
rmeans  Row mean scores differ 53.631  3 1.3450e-11
generalGeneral association 64.318  9 1.9580e-10

In the print.CMHtest() function below the lines before # # TODO give the 
output shown above.
The lines below try to use print.anova(), but this gives something even 
worse:

Cochran-Mantel-Haenszel Statistics for New Orleans Neurologist by 
Winnipeg Neurologist

 AltHypothesis  Chisq Df  Prob
cor 3 51.424  1 7.440e-13
cmeans  1 55.393  3 5.660e-12
rmeans  4 53.631  3 1.345e-11
general 2 64.318  9 1.958e-10

Here is the print method, showing the attempt to use print.anova() as well:

print.CMHtest - function(x, digits = max(getOption(digits) - 2, 3), 
...) {
 heading - Cochran-Mantel-Haenszel Statistics
 if (!is.null(x$names)) heading - paste(heading, for, 
paste(x$names, collapse= by ))
 # TODO: determine score types (integer, midrank) for heading

 df - x$table
 types - rownames(df)
 labels - list(cor=Nonzero correlation, rmeans=Row mean scores 
differ,
 cmeans=Col mean scores differ, general=General association)
 df - 
data.frame(AltHypothesis=as.character(unlist(labels[types])), df)
 cat(heading,\n\n)
 print(df, digits=digits, ...)
 cat(\n)

## TODO: use print.anova() method, but this screws up the AltHyp
 attr(df, heading) - paste(heading,\n)
 class(df) - c(anova, data.frame)
 print(df)
 invisible(x)
}




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


[[alternative HTML version deleted]]

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


Re: [R] How to start console output with a comment sign (as in knitr)

2013-03-02 Thread Greg Snow
Try the following to see if it does what you want:

## init
con - textConnection(output, w)
options(echo=FALSE)
sink(con)

addTaskCallback( function(expr, out, err, vis) {
sink()
close(con)
if(vis) {
cat(paste(#, output, collapse=\n), \n)
}
con - textConnection(output, w)
sink(con)
TRUE
})

3+4
5*6
tmp - 7-8
ls()


### clean up when finished
removeTaskCallback(1)
sink()
options(echo=TRUE)


This misses errors and warnings, but should do what you want for everything
else.


On Sat, Mar 2, 2013 at 6:35 AM, Marcus Kriele mkri...@me.com wrote:

 Dear all,
 knitr writes a comment sign in front of each line of console output.  This
 extremely useful, especially for beginners who are starting to write
 scripts.  One could just compose their script in the console (getting
 immediate output) and then copy the whole chunk into their .r-file.
 I have been able to configure the options such that the prompt and the
 continuing line labels are replaced by blanks.  However, I do not know how
 to automatically comment out each line of output.  Ideally, my console
 would behave exactly like knitr.

 At my work place I only have access to the R console that is included the
 standard download for windows.  I cannot replace it by an editor that may
 have additional features.

 Would there be a way to achieve the knitr-look in the standard console?

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




-- 
Gregory (Greg) L. Snow Ph.D.
538...@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] print method like print.anova()

2013-03-02 Thread Milan Bouchet-Valat
Le samedi 02 mars 2013 à 12:37 -0500, Michael Friendly a écrit :
 I have a print method for a set of statistical tests, vcdExtra::CMHtest, 
 for which I'd like to
 have more sensible printing of pvalues, as in print.anova().
 [Testing this requires the latest version of vcdExtra, from R-Forge
 **|install.packages(vcdExtra, repos=http://R-Forge.R-project.org;)|**
 ]
 
 With my current print method, I get results like this, but all Prob 
 values should better
 be reported as something like '0.0001' .
I think you want to use format.pval(), which is intended exactly for
this use case:
format.pval(c(7.4426e-13, 5.6601e-12, 1.3450e-11, 1.9580e-10), eps=1e-3)
# [1]  0.001  0.001  0.001  0.001


My two cents

   CMHtest(MSPatients[,,1])
 Cochran-Mantel-Haenszel Statistics for New Orleans Neurologist by 
 Winnipeg Neurologist
 
   AltHypothesis  Chisq Df   Prob
 corNonzero correlation 51.424  1 7.4426e-13
 cmeans  Col mean scores differ 55.393  3 5.6601e-12
 rmeans  Row mean scores differ 53.631  3 1.3450e-11
 generalGeneral association 64.318  9 1.9580e-10
 
 In the print.CMHtest() function below the lines before # # TODO give the 
 output shown above.
 The lines below try to use print.anova(), but this gives something even 
 worse:
 
 Cochran-Mantel-Haenszel Statistics for New Orleans Neurologist by 
 Winnipeg Neurologist
 
  AltHypothesis  Chisq Df  Prob
 cor 3 51.424  1 7.440e-13
 cmeans  1 55.393  3 5.660e-12
 rmeans  4 53.631  3 1.345e-11
 general 2 64.318  9 1.958e-10
 
 Here is the print method, showing the attempt to use print.anova() as well:
 
 print.CMHtest - function(x, digits = max(getOption(digits) - 2, 3), 
 ...) {
  heading - Cochran-Mantel-Haenszel Statistics
  if (!is.null(x$names)) heading - paste(heading, for, 
 paste(x$names, collapse= by ))
  # TODO: determine score types (integer, midrank) for heading
 
  df - x$table
  types - rownames(df)
  labels - list(cor=Nonzero correlation, rmeans=Row mean scores 
 differ,
  cmeans=Col mean scores differ, general=General association)
  df - 
 data.frame(AltHypothesis=as.character(unlist(labels[types])), df)
  cat(heading,\n\n)
  print(df, digits=digits, ...)
  cat(\n)
 
 ## TODO: use print.anova() method, but this screws up the AltHyp
  attr(df, heading) - paste(heading,\n)
  class(df) - c(anova, data.frame)
  print(df)
  invisible(x)
 }
 
 
 


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


Re: [R] print method like print.anova()

2013-03-02 Thread John Fox
Hi Michael,

Take a look at ?printCoefmat.

I hope this helps,
 John

On Sat, 02 Mar 2013 12:37:36 -0500
 Michael Friendly frien...@yorku.ca wrote:
 I have a print method for a set of statistical tests, vcdExtra::CMHtest, 
 for which I'd like to
 have more sensible printing of pvalues, as in print.anova().
 [Testing this requires the latest version of vcdExtra, from R-Forge
 **|install.packages(vcdExtra, repos=http://R-Forge.R-project.org;)|**
 ]
 
 With my current print method, I get results like this, but all Prob 
 values should better
 be reported as something like '0.0001' .
 
   CMHtest(MSPatients[,,1])
 Cochran-Mantel-Haenszel Statistics for New Orleans Neurologist by 
 Winnipeg Neurologist
 
   AltHypothesis  Chisq Df   Prob
 corNonzero correlation 51.424  1 7.4426e-13
 cmeans  Col mean scores differ 55.393  3 5.6601e-12
 rmeans  Row mean scores differ 53.631  3 1.3450e-11
 generalGeneral association 64.318  9 1.9580e-10
 
 In the print.CMHtest() function below the lines before # # TODO give the 
 output shown above.
 The lines below try to use print.anova(), but this gives something even 
 worse:
 
 Cochran-Mantel-Haenszel Statistics for New Orleans Neurologist by 
 Winnipeg Neurologist
 
  AltHypothesis  Chisq Df  Prob
 cor 3 51.424  1 7.440e-13
 cmeans  1 55.393  3 5.660e-12
 rmeans  4 53.631  3 1.345e-11
 general 2 64.318  9 1.958e-10
 
 Here is the print method, showing the attempt to use print.anova() as well:
 
 print.CMHtest - function(x, digits = max(getOption(digits) - 2, 3), 
 ...) {
  heading - Cochran-Mantel-Haenszel Statistics
  if (!is.null(x$names)) heading - paste(heading, for, 
 paste(x$names, collapse= by ))
  # TODO: determine score types (integer, midrank) for heading
 
  df - x$table
  types - rownames(df)
  labels - list(cor=Nonzero correlation, rmeans=Row mean scores 
 differ,
  cmeans=Col mean scores differ, general=General association)
  df - 
 data.frame(AltHypothesis=as.character(unlist(labels[types])), df)
  cat(heading,\n\n)
  print(df, digits=digits, ...)
  cat(\n)
 
 ## TODO: use print.anova() method, but this screws up the AltHyp
  attr(df, heading) - paste(heading,\n)
  class(df) - c(anova, data.frame)
  print(df)
  invisible(x)
 }
 
 
 
 
 -- 
 Michael Friendly Email: friendly AT yorku DOT ca
 Professor, Psychology Dept.  Chair, Quantitative Methods
 York University  Voice: 416 736-2100 x66249 Fax: 416 736-5814
 4700 Keele StreetWeb:   http://www.datavis.ca
 Toronto, ONT  M3J 1P3 CANADA
 
 
   [[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] Errors-In-Variables in R

2013-03-02 Thread Cedric Sodhi
In reference to [1], how would you solve the following regression
problem:

Given observations (X_i,Y_i) with known respective error distributions
(e_X_i,e_Y_i) (say, 0-mean Gaussian with known STD), find the parameters
a and b which maximize the Likelihood of

Y = a*X + b

Taking the example further, how many of the very simplified assumptions
from the above example can be lifted or eased and R still has a method
for finding an errors-in-variables fit?

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


[R] how to log out from the conference

2013-03-02 Thread Quetzalcoatlus
Hello,

please log me out from the conference. I tried to contact the webmaster but 
the only e-mail I reached was this one. Probably fault on my side in the 
registration.

Thanks,

Petr Suvorov
[[alternative HTML version deleted]]

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


Re: [R] How to start console output with a comment sign (as in knitr)

2013-03-02 Thread Marcus Kriele
Thanks Greg, this is great!  Regards, Marcus
On 2013-03-02, at 19:06 , Greg Snow wrote:

 Try the following to see if it does what you want:
 
 ## init
 con - textConnection(output, w)
 options(echo=FALSE)
 sink(con)
 
 addTaskCallback( function(expr, out, err, vis) {
   sink()
   close(con)
   if(vis) {
   cat(paste(#, output, collapse=\n), \n)
   }
   con - textConnection(output, w)
   sink(con)
   TRUE
 })
 
 3+4
 5*6
 tmp - 7-8
 ls()
 
 
 ### clean up when finished
 removeTaskCallback(1)
 sink()
 options(echo=TRUE)
 
 
 This misses errors and warnings, but should do what you want for everything 
 else.
 
 
 On Sat, Mar 2, 2013 at 6:35 AM, Marcus Kriele mkri...@me.com wrote:
 


[[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] easy way to install new R version??

2013-03-02 Thread capricy gao
Some packages have to be installed on new R version, 2.15.3

but I have 2.15.2

If I don't want to go through all download, and uninstall and install 
procedures, is there any simple R command that could handle this? Thanks.
[[alternative HTML version deleted]]

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


Re: [R] explanation of the problem..

2013-03-02 Thread arun
HI Utpal,

Alight, I will look into it.  I was under the impression that this is what you 
wanted:

dat1- structure(list(V1 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L), V2 = c(1L,
1L, 1L, 1L, 1L, 1L, 0L), V3 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L),
    V4 = c(1L, 1L, 0L, 1L, 1L, 1L, 1L), V5 = c(1L, 1L, 1L, 1L,
    1L, 0L, 1L), V6 = c(1L, 1L, 1L, 0L, 1L, 1L, 1L), V7 = c(1L,
    1L, 1L, 1L, 1L, 1L, 1L), V8 = c(1L, 1L, 1L, 0L, 1L, 0L, 1L
    ), V9 = c(1L, 0L, 1L, 1L, 1L, 1L, 1L), V10 = c(1L, 1L, 1L,
    1L, 1L, 1L, 1L), V11 = c(0L, 1L, 1L, 1L, 1L, 1L, 1L), V12 = c(1L,
    1L, 1L, 1L, 1L, 1L, 1L), V13 = c(1L, 1L, 1L, 1L, 1L, 1L,
    1L)), .Names = c(V1, V2, V3, V4, V5, V6, V7,
V8, V9, V10, V11, V12, V13), class = data.frame, row.names = c(NA,
-7L))
dat2- dat1[,1:4]
 dat2[4,]- c(3,2,3,1)
 dat2[6,]- c(3,3,3,3)


 dat2
#  V1 V2 V3 V4
#1  1  1  1  1
#2  1  1  1  1
#3  1  1  1  0
#4  3  2  3  1
#5  1  1  1  1
#6  3  3  3  3
#7  1  0  1  1

res-
 lapply(2:ncol(dat2),function(i) {x1- 
combn(names(dat2),i);unlist(lapply(1:ncol(x1), function(i) {x2- 
dat2[,x1[,i]];dim(x2[!as.logical(rowSums(x2==0)),])[1]}))})
res
#[[1]]
#[1] 6 7 6 6 5 6

#[[2]]
#[1] 6 5 6 5
#
#[[3]]
#[1] 5


A.K.





From: Utpal Bakshi utpalm...@gmail.com
To: arun smartpink...@yahoo.com 
Sent: Saturday, March 2, 2013 2:14 PM
Subject: Re: explanation of the problem..


may be you could use the specaccum function of vegan package for permutations.. 
the function is shown in pan genome script file..




On Sun, Mar 3, 2013 at 12:39 AM, arun smartpink...@yahoo.com wrote:

Another problem, is that with this combinations of many columns will be 
computationally intensive. 







 From: Utpal Bakshi utpalm...@gmail.com
To: arun smartpink...@yahoo.com 
Sent: Saturday, March 2, 2013 1:54 PM

Subject: Re: explanation of the problem..
 


Hi Arun.. yes... even if the number is greater than 1 (what ever it may be), 
it will still count as 1.. 


for example 




dat1
#  V1 V2 V3 
#1  3  1  2  
#2  1  16  0  #3  1  0  1  


will considered as same as


dat1
#  V1 V2 V3 
#1  1  1  1  
#2  1  1  0  #3  1  0  1 



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


Re: [R] easy way to install new R version??

2013-03-02 Thread Gabor Grothendieck
On Sat, Mar 2, 2013 at 1:49 PM, capricy gao capri...@yahoo.com wrote:
 Some packages have to be installed on new R version, 2.15.3

 but I have 2.15.2

 If I don't want to go through all download, and uninstall and install 
 procedures, is there any simple R command that could handle this? Thanks.

After installing 2.15.3 from within R do this:

update.packages()

-- 
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] xYplot help

2013-03-02 Thread Frank Harrell
xYplot has many options that are passed to panel.xYplot.  Did you read the
documentation?  You can suppress labels, use an automatically generated
Key() function to control where you want keys, and use several other
options.  Start with label.curve=FALSE and go from there.
Frank

bwr87 wrote
 I'm trying to work the lattice xYplot function to plot confidence
 intervals
 for two groups on the same plot.  The problem is that it automatically
 labels the groups (1 and 2) on the plot itself, and the labels get
 obscured
 by the CI lines and make it look bad.
 
 This is my code:
 
 xYplot(Cbind(Mean,L95,U95) ~ jitter(Time), type='b', data=A,main=Bouts
 Vs.
 Time,col=c('black', 'gray'), groups=Group,title=Bouts,xlab=Time,
 ylab=Bouts, method=bars, lwd=3, ylim=c(0,30))
 
 
 A is the data, with columns Time, Group, Mean, L95, U95.  L95 and U95 are
 the lower and upper confidence interval estimates. Group is either 1 or 2,
 each measured at the same number of time points.
 
 The goal is simply to take the labels off of the plot itself.  Then I can
 use an auto.key to put the labels on the side.
 
 Please help!
 
 -Ben
 
   [[alternative HTML version deleted]]
 
 __

 R-help@

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





-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/xYplot-help-tp4660102p4660108.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] Expressions in lattice conditional variables

2013-03-02 Thread Peter Ehlers

Frank,

As you probably realize, the problem is not with lattice but with
unique (actually: .Internal(unique, ...)):

  unique(expression('a','b','b'))

generates your error.

Lattice needs a factor variable for the panels, and it tries to
use unique() on your 'vn' to do that.

For example, if you replace '|vn' with '|as.character(vn)', you'll
get the plot, but of course the strip labels are a mess.

I'm not sure that I understand your need correctly, but if it's
a matter of creating the strip labels, then I would explore using
the factor.levels argument to strip.default().

I hope that this isn't totally out to lunch.

Peter Ehlers

On 2013-03-02 09:20, Frank Harrell wrote:

Whoops - these 2 lines should have been omitted from the program:

n - sprintf('%s  (n%s=%g, n%s=%g)', v, nam[1],n[1], nam[2],n[2])
  vn[var == v] - n


Frank Harrell wrote

I would like to have a lattice conditioning ( | var ) variable have
expression() as values because I want panel labels to be able to use
plotmath notation for subscripts, etc.   lattice barks at this.  Does
anyone know of a trick workaround?  An attempted example program is below.
Thanks -Frank

require(lattice)
set.seed(1)
var - c(rep('A', 100), rep('B', 100))
trt - sample(c('T1','T2'), 200, TRUE)
x - c(runif(100), 10*runif(100))
y - x + c(runif(100)/10, runif(100))
N - tapply(x, llist(var, trt), function(x) sum(!is.na(x)))
print(N)

vn - vector('expression', length(var))
for(v in unique(var)) {
   i - var == v
   n - tapply(!is.na(x[i]), trt[i], sum)
   nam - names(n)
   w - sprintf('paste(%s, (, n[%s]==%g,~~n[%s]==%g,))',
v, nam[1], n[1], nam[2], n[2])
   cat(w, '\n')
   vn[var == v] - parse(text=w)
   n - sprintf('%s  (n%s=%g, n%s=%g)', v, nam[1],n[1], nam[2],n[2])
   vn[var == v] - n
}
trt - factor(trt)

xyplot(as.integer(trt) ~ x | vn, panel=panel.bpplot, ylim=c(0,3),
scale=list(y=list(at=1:2, labels=levels(trt)),
  x=list(relation='free', limits=list(c(0,1),c(0,13,
ylab='Treatment', layout=c(1,2))

Error in unique.default(x) :
   unimplemented type 'expression' in 'HashTableSetup'






-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/Expressions-in-lattice-conditional-variables-tp4660089p4660090.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] using reserved words in R, and reuse variable names in different functions

2013-03-02 Thread Peter Ehlers

Duncan's comment may not qualify as a fortune, but it did make
me chuckle.

Peter Ehlers

On 2013-03-02 03:01, Duncan Murdoch wrote:

On 13-03-01 8:35 PM, C W wrote:


[...snip...]


pie is a function, but all it does is draw pie charts, so who cares if
you mask it? :-).

Duncan Murdoch

[...snip...]

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


Re: [R] Errors-In-Variables in R

2013-03-02 Thread Rui Barradas

There's a no homework policy in R-help.

Rui Barradas

Em 02-03-2013 18:28, Cedric Sodhi escreveu:

In reference to [1], how would you solve the following regression
problem:

Given observations (X_i,Y_i) with known respective error distributions
(e_X_i,e_Y_i) (say, 0-mean Gaussian with known STD), find the parameters
a and b which maximize the Likelihood of

Y = a*X + b

Taking the example further, how many of the very simplified assumptions
from the above example can be lifted or eased and R still has a method
for finding an errors-in-variables fit?

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

2013-03-02 Thread Charles Determan Jr
Greetings,

I have been exploring the use of the caret package to conduct some plsda
modeling.  Previously, I have come across methods that result in a R2 and
Q2 for the model.  Using the 'iris' data set, I wanted to see if I could
accomplish this with the caret package.  I use the following code:

library(caret)
data(iris)

#needed to convert to numeric in order to do regression
#I don't fully understand this but if I left as a factor I would get an
error following the summary function
iris$Species=as.numeric(iris$Species)
inTrain1=createDataPartition(y=iris$Species,
p=.75,
list=FALSE)

training1=iris[inTrain1,]
testing1=iris[-inTrain1,]

ctrl1=trainControl(method=cv,
number=10)

plsFit2=train(Species~.,
data=training1,
method=pls,
trControl=ctrl1,
metric=Rsquared,
preProc=c(scale))

data(iris)
training1=iris[inTrain1,]
datvars=training1[,1:4]
dat.sc=scale(datvars)

n=nrow(dat.sc)
dat.indices=seq(1,n)

timematrix=with(training1,
classvec2classmat(Species[dat.indices]))

pls.dat=plsr(timematrix ~ dat.sc,
ncomp=3, method=oscorespls, data=training1)

x=crossval(pls.dat, segments=10)

summary(x)
summary(plsFit2)

I see two different R2 values and I cannot figure out how to get the Q2
value.  Any insight as to what my errors may be would be appreciated.

Regards,

-- 
Charles

[[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] Errors-In-Variables in R

2013-03-02 Thread Cedric Sodhi
Perhaps it would have been clearer that this is no homework if I
hadn't forgotten to say what [1] is. Sorry for that.

[1] https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=15225

(This is no homework but genuinely adresses the problem that R to my
knowledge does not have models for error in variables)


On Sat, Mar 02, 2013 at 09:34:21PM +, Rui Barradas wrote:
 There's a no homework policy in R-help.
 
 Rui Barradas
 
 Em 02-03-2013 18:28, Cedric Sodhi escreveu:
  In reference to [1], how would you solve the following regression
  problem:
 
  Given observations (X_i,Y_i) with known respective error distributions
  (e_X_i,e_Y_i) (say, 0-mean Gaussian with known STD), find the parameters
  a and b which maximize the Likelihood of
 
  Y = a*X + b
 
  Taking the example further, how many of the very simplified assumptions
  from the above example can be lifted or eased and R still has a method
  for finding an errors-in-variables fit?
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/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] Raster images and saving with original pixel dimensions in tiff, jpeg, or png perferablly.

2013-03-02 Thread Hans Thompson
Hello R-Help,

I want to be able to read in a raster image, plot it with grid.raster
or rasterImage and save the image with one pixel per a pixel element
from my array. Saved preferably in a common image format.

The real goal of my question is to eventually read in images with text
on them, manipulate them with my controlled functions, save them
without changing the image dimensions, and perform OCR outside R.

I have read The R Journal article on raster images
(http://journal.r-project.org/archive/2011-1/RJournal_2011-1_Murrell.pdf)
and have experimented with some of the par() variables with no
success.  There are some arguments in gird.raster that elude me
currently on how to use them.  These include, vjust, hjust,
default.units, gp and vp.  Perhaps these are what I need to use but I
am getting nowhere without more documentation.

Here is the basic code I've used to experiment with making this work.
The end result I'm hoping for would be an image exactly like the one
I've read in (Rlogo.jpg for this small example).  I turned off
dev.copy lines because I'm not sure on the guidelines for file writing
functions.

Thanks,
Hans Thompson

Forgive me If I made any mistakes following posting guidelines.

START#
library(jpeg)
library(grid)

img - readJPEG(system.file(img, Rlogo.jpg, package=jpeg))
grid.raster(img, interpolate =F)
#turnon next line for output. Don't want to accidentally write any
unwanted files.
#dev.copy(tiff, outputimage.tiff)
dev.off()

#or using package = graphics but not perfered.

library(graphics)

plot( c(0, dim(img)[2]), c(0, dim(img)[1]), type = n, xlab = , ylab = )
rasterImage(img, 0, 0, dim(img)[2], dim(img)[1])
#dev.copy(tiff, outputfile2.tiff)
dev.off()

##STOP##

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


Re: [R] caret pls model statistics

2013-03-02 Thread Charles Determan Jr
I have discovered on of my errors.  The timematrix was unnecessary and an
unfortunate habit I brought from another package.  The following provides
the same R2 values as it should, however, I still don't know how to
retrieve Q2 values.  Any insight would again be appreciated:

library(caret)
library(pls)

data(iris)

#needed to convert to numeric in order to do regression
#I don't fully understand this but if I left as a factor I would get an
error following the summary function
iris$Species=as.numeric(iris$Species)
inTrain1=createDataPartition(y=iris$Species,
p=.75,
list=FALSE)

training1=iris[inTrain1,]
testing1=iris[-inTrain1,]

ctrl1=trainControl(method=cv,
number=10)

plsFit2=train(Species~.,
data=training1,
method=pls,
trControl=ctrl1,
metric=Rsquared,
preProc=c(scale))

data(iris)
training1=iris[inTrain1,]
datvars=training1[,1:4]
dat.sc=scale(datvars)

pls.dat=plsr(as.numeric(training1$Species)~dat.sc,
ncomp=3, method=oscorespls, data=training1)

x=crossval(pls.dat, segments=10)

summary(x)
summary(plsFit2)

Regards,
Charles

On Sat, Mar 2, 2013 at 3:55 PM, Charles Determan Jr deter...@umn.eduwrote:

 Greetings,

 I have been exploring the use of the caret package to conduct some plsda
 modeling.  Previously, I have come across methods that result in a R2 and
 Q2 for the model.  Using the 'iris' data set, I wanted to see if I could
 accomplish this with the caret package.  I use the following code:

 library(caret)
 data(iris)

 #needed to convert to numeric in order to do regression
 #I don't fully understand this but if I left as a factor I would get an
 error following the summary function
 iris$Species=as.numeric(iris$Species)
 inTrain1=createDataPartition(y=iris$Species,
 p=.75,
 list=FALSE)

 training1=iris[inTrain1,]
 testing1=iris[-inTrain1,]

 ctrl1=trainControl(method=cv,
 number=10)

 plsFit2=train(Species~.,
 data=training1,
 method=pls,
 trControl=ctrl1,
 metric=Rsquared,
 preProc=c(scale))

 data(iris)
 training1=iris[inTrain1,]
 datvars=training1[,1:4]
 dat.sc=scale(datvars)

 n=nrow(dat.sc)
 dat.indices=seq(1,n)

 timematrix=with(training1,
 classvec2classmat(Species[dat.indices]))

 pls.dat=plsr(timematrix ~ dat.sc,
 ncomp=3, method=oscorespls, data=training1)

 x=crossval(pls.dat, segments=10)

 summary(x)
 summary(plsFit2)

 I see two different R2 values and I cannot figure out how to get the Q2
 value.  Any insight as to what my errors may be would be appreciated.

 Regards,

 --
 Charles




-- 
Charles Determan
Integrated Biosciences PhD Student
University of Minnesota

[[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] Errors-In-Variables in R

2013-03-02 Thread R. Michael Weylandt
Based on your comments in the (not-a-)bug report, I *think* this might help:

quanttrader.info/public/betterHedgeRatios.pdf

or more generally, the idea of total least squares regression.

Cheers,
MW

On Sat, Mar 2, 2013 at 9:55 PM, Cedric Sodhi man...@gmx.net wrote:
 Perhaps it would have been clearer that this is no homework if I
 hadn't forgotten to say what [1] is. Sorry for that.

 [1] https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=15225

 (This is no homework but genuinely adresses the problem that R to my
 knowledge does not have models for error in variables)


 On Sat, Mar 02, 2013 at 09:34:21PM +, Rui Barradas wrote:
 There's a no homework policy in R-help.

 Rui Barradas

 Em 02-03-2013 18:28, Cedric Sodhi escreveu:
  In reference to [1], how would you solve the following regression
  problem:
 
  Given observations (X_i,Y_i) with known respective error distributions
  (e_X_i,e_Y_i) (say, 0-mean Gaussian with known STD), find the parameters
  a and b which maximize the Likelihood of
 
  Y = a*X + b
 
  Taking the example further, how many of the very simplified assumptions
  from the above example can be lifted or eased and R still has a method
  for finding an errors-in-variables fit?
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide 
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 

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

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


[R] Metafor SMCR Pre-Post Effect sizes

2013-03-02 Thread Markus Kösters
Dear all,

I am very grateful that Wolfgang Viechtbauer implemented the standardised mean 
change for dependent
groups. I was playing around a bit today, and I am not sure if I understand the 
SMCR procedure correctly. The documentation states that sd1i and sd2i are 
needed, but it seems to me that SMCR is ignoring sd2i (so Variances are not 
pooled). Instead, it uses sd1i (pre-test sd), as suggested by Becker 1988. Is 
that correct?

Thank you all very much for your time and help,

Markus



[[alternative HTML version deleted]]

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


Re: [R] using reserved words in R, and reuse variable names in different functions

2013-03-02 Thread Rolf Turner


Well *I* think it should be a fortune!

cheers,

Rolf

On 03/03/2013 10:30 AM, Peter Ehlers wrote:

Duncan's comment may not qualify as a fortune, but it did make
me chuckle.

Peter Ehlers

On 2013-03-02 03:01, Duncan Murdoch wrote:

On 13-03-01 8:35 PM, C W wrote:


[...snip...]


pie is a function, but all it does is draw pie charts, so who cares if
you mask it? :-).

Duncan Murdoch

[...snip...]


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


Re: [R] Errors-In-Variables in R

2013-03-02 Thread Rui Barradas

Hello,

Like you say, apparently R doesn't have models for error in variables.
But R packages might have.

library(sos)
findFn('errors-in-variables')

Some look promising. Hope you find something.

Rui Barradas

Em 02-03-2013 21:55, Cedric Sodhi escreveu:

Perhaps it would have been clearer that this is no homework if I
hadn't forgotten to say what [1] is. Sorry for that.

[1] https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=15225

(This is no homework but genuinely adresses the problem that R to my
knowledge does not have models for error in variables)


On Sat, Mar 02, 2013 at 09:34:21PM +, Rui Barradas wrote:

There's a no homework policy in R-help.

Rui Barradas

Em 02-03-2013 18:28, Cedric Sodhi escreveu:

In reference to [1], how would you solve the following regression
problem:

Given observations (X_i,Y_i) with known respective error distributions
(e_X_i,e_Y_i) (say, 0-mean Gaussian with known STD), find the parameters
a and b which maximize the Likelihood of

Y = a*X + b

Taking the example further, how many of the very simplified assumptions
from the above example can be lifted or eased and R still has a method
for finding an errors-in-variables fit?

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

2013-03-02 Thread David Winsemius

On Mar 2, 2013, at 1:55 PM, Cedric Sodhi wrote:

 Perhaps it would have been clearer that this is no homework if I
 hadn't forgotten to say what [1] is. Sorry for that.
 
 [1] https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=15225
 
 (This is no homework but genuinely adresses the problem that R to my
 knowledge does not have models for error in variables)
 

In addition to searching for errors in variables you should also be searching 
for deming regression, 'orthogonal regression, total least squares 
regression, and measurement error models

Here are a few links to get you started:


http://markmail.org/message/4mo62jqfyudrchzi?q=list:org%2Er-project%2Er-help+deming+orthogonal
http://markmail.org/message/htlptlcccunsd5mm?q=list:org%2Er-project%2Er-help+deming+orthogonal
http://markmail.org/message/zhogz6337m3ofl7d?q=list:org%2Er-project%2Er-help+deming+orthogonal

-- 
David.

 
 On Sat, Mar 02, 2013 at 09:34:21PM +, Rui Barradas wrote:
 There's a no homework policy in R-help.
 
 Rui Barradas
 
 Em 02-03-2013 18:28, Cedric Sodhi escreveu:
 In reference to [1], how would you solve the following regression
 problem:
 
 Given observations (X_i,Y_i) with known respective error distributions
 (e_X_i,e_Y_i) (say, 0-mean Gaussian with known STD), find the parameters
 a and b which maximize the Likelihood of
 
 Y = a*X + b
 
 Taking the example further, how many of the very simplified assumptions
 from the above example can be lifted or eased and R still has a method
 for finding an errors-in-variables fit?
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] if value is in vector, perform this function

2013-03-02 Thread Louise Stevenson
Hi,

I'm trying to set up R to run a simulation of two populations in which every 
3.5 days, the initial value of one of the populations is reset to 1.5. I'm 
simulation an experiment we did in which we fed Daphnia populations twice a 
week with algae, so I want the initial value of the algal population to reset 
to 1.5 twice a week to simulate that feeding. I've use for loops and if/else 
loops before but I can't figure out how to syntax if t is in this vector of 
possible t values, do this command, else, do this command if that makes sense. 
Here's what I have (and it doesn't work):

params = c(1, 0.15, 0.164, 1)
init = c(1.5, 0.05)
t=seq(1,60, by=0.5) #all time values, experiment ran for 60 days

#feeding sequence - every 3.5 days
feed_days = seq(1,60,by=3.5)

Daphnia - function(t,x,params){
C_D = x[2];
C_A = 0;
for(t %in% feed_days){
if t == TRUE {
C_A = 1.5
}
else{
C_A = 0
 }}
gamma = params[1]; m_D = params[2]; K_q = params[3]; q_max = params[4];
M_D = m_D * C_D
I_A = (C_D * q_max * C_A) / (K_q + C_A)
r_D = gamma * I_A
return(
list(c(
 - I_A,
r_D - M_D
)))
}

library(deSolve)
results - ode(init, t, Daphnia, params, method = lsoda)


Let me know if there's any other info that would be helpful and thanks very 
much for your help!


[[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] Empirical Bayes Estimator for Poisson-Gamma Parameters

2013-03-02 Thread Nicole Ford
just seeing this.

when you say y1 and y2, are you asking about 2 differnt models in an effort to 
model select?  i need more info, i might be able to help.  please supply a bit 
more info. 

~n
On Feb 25, 2013, at 4:39 AM, Ali A. Bromideh wrote:

 Dear Sir/Madam,
 
 
 
 I apologize for any cross-posting. I got a simple question, which I thought
 the R list may help me to find an answer. Suppose we have Y_1, Y_2, ., Y_n ~
 Poisson (Lambda_i) and Lambda_i ~Gamma(alpha_i, beta_i).  Empirical Bayes
 Estimator for hyper-parameters of the gamma distr, i.e. (alpha_t, beta_t)
 are needed. 
 
 
 
 y=c(12,5,17,14)
 
 n=4
 
 
 
 What about a Hierarchal B ayes estimators?
 
 
 
 
 
 Any relevant work and codes in R (or S+) is highly appreciated. 
 
 
 
 Kind regards,
 
 Ali
 
 
 
 
   [[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] Empirical Bayes Estimator for Poisson-Gamma Parameters

2013-03-02 Thread Nicole Ford
also, kruschke at indiana has some info on this, both online and youtube.  (if 
homework.)  if not, more infor will be helpful.

~n


On Feb 25, 2013, at 9:41 AM, Bert Gunter wrote:

 Homework? We don't do homework here.
 
 If not, search (e.g. via google -- R hierarchical Bayes -- or some such).
 
 -- Bert
 
 On Mon, Feb 25, 2013 at 1:39 AM, Ali A. Bromideh a.bromi...@ikco.com wrote:
 Dear Sir/Madam,
 
 
 
 I apologize for any cross-posting. I got a simple question, which I thought
 the R list may help me to find an answer. Suppose we have Y_1, Y_2, ., Y_n ~
 Poisson (Lambda_i) and Lambda_i ~Gamma(alpha_i, beta_i).  Empirical Bayes
 Estimator for hyper-parameters of the gamma distr, i.e. (alpha_t, beta_t)
 are needed.
 
 
 
 y=c(12,5,17,14)
 
 n=4
 
 
 
 What about a Hierarchal B ayes estimators?
 
 
 
 
 
 Any relevant work and codes in R (or S+) is highly appreciated.
 
 
 
 Kind regards,
 
 Ali
 
 
 
 
[[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.

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


Re: [R] Ordering Table Columns

2013-03-02 Thread Pete Brecknock
cdouglass wrote
 Hello all,
 
 Totally new to this and I'm just doing a frequency distribution analysis
 on T-shirt sales by size.  I have a .csv with 60 orders.  I read in the
 data using read.csv.  If I look at the summary() or table() of the data it
 looks fine, except that the shirt sizes are alphabetical rather than from
 S-XXL--so the bar graph loses the shape of the data based on size.
 
 All I want to do is get the table to arrange the data:
 S M L XL XXL
 
 Here's the code that I've run that got me closer to what I want.  It seems
 like it should be simple, but going through the R in a Nutshell and
 asking Google as many different ways as I can think to phrase it are
 turning up nothing.
 
 shirt - read.csv(http://localhost/examples/tshirt_purchases.csv;,
 header=TRUE, sep = ,, nrows=60)
 shirt.table-summary(shirt)
 shirt.table
  Shirt.Size
  L  :20
  M  :20
  S  :11
  XL : 7
  XXL: 2  
 
 What I want is:
 
 Shirt.Size
 S  :11   
 M  :20 
 L  :20  
  XL : 7
  XXL: 2  
 
 Does anyone know how to do this, or am I coming at it from the wrong
 direction?
 If this has been answered previously and I've just failed to find it in my
 searches, please accept my apologies.  
 
 Many Thanks,
 Chris

Think you want to have a look at factors 

Typing ?factor will throw up the relevant help pages  

# Your Data
tbl - read.table(header = TRUE, text = 
 ShirtSize Number 
 L 20 
 M 20 
 S 11 
 XL 7 
 XXL 2   
)

# ShirtSize Alphabetical
tbl[tbl$ShirtSize,]

# Reorder Factor
tbl$ShirtSize = factor(tbl$ShirtSize, levels=c(S,M,L,XL,XXL))

# ShirtSize Order by Size
tbl[tbl$ShirtSize,]


Pete



--
View this message in context: 
http://r.789695.n4.nabble.com/Ordering-Table-Columns-tp4660110p4660129.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] caret pls model statistics

2013-03-02 Thread Max Kuhn
Charles,

You should not be treating the classes as numeric (is virginica really
three times setosa?). Q^2 and/or R^2 are not appropriate for classification.

Max


On Sat, Mar 2, 2013 at 5:21 PM, Charles Determan Jr deter...@umn.eduwrote:

 I have discovered on of my errors.  The timematrix was unnecessary and an
 unfortunate habit I brought from another package.  The following provides
 the same R2 values as it should, however, I still don't know how to
 retrieve Q2 values.  Any insight would again be appreciated:

 library(caret)
 library(pls)

 data(iris)

 #needed to convert to numeric in order to do regression
 #I don't fully understand this but if I left as a factor I would get an
 error following the summary function
 iris$Species=as.numeric(iris$Species)
 inTrain1=createDataPartition(y=iris$Species,
 p=.75,
 list=FALSE)

 training1=iris[inTrain1,]
 testing1=iris[-inTrain1,]

 ctrl1=trainControl(method=cv,
 number=10)

 plsFit2=train(Species~.,
 data=training1,
 method=pls,
 trControl=ctrl1,
 metric=Rsquared,
 preProc=c(scale))

 data(iris)
 training1=iris[inTrain1,]
 datvars=training1[,1:4]
 dat.sc=scale(datvars)

 pls.dat=plsr(as.numeric(training1$Species)~dat.sc,
 ncomp=3, method=oscorespls, data=training1)

 x=crossval(pls.dat, segments=10)

 summary(x)
 summary(plsFit2)

 Regards,
 Charles

 On Sat, Mar 2, 2013 at 3:55 PM, Charles Determan Jr deter...@umn.edu
 wrote:

  Greetings,
 
  I have been exploring the use of the caret package to conduct some plsda
  modeling.  Previously, I have come across methods that result in a R2 and
  Q2 for the model.  Using the 'iris' data set, I wanted to see if I could
  accomplish this with the caret package.  I use the following code:
 
  library(caret)
  data(iris)
 
  #needed to convert to numeric in order to do regression
  #I don't fully understand this but if I left as a factor I would get an
  error following the summary function
  iris$Species=as.numeric(iris$Species)
  inTrain1=createDataPartition(y=iris$Species,
  p=.75,
  list=FALSE)
 
  training1=iris[inTrain1,]
  testing1=iris[-inTrain1,]
 
  ctrl1=trainControl(method=cv,
  number=10)
 
  plsFit2=train(Species~.,
  data=training1,
  method=pls,
  trControl=ctrl1,
  metric=Rsquared,
  preProc=c(scale))
 
  data(iris)
  training1=iris[inTrain1,]
  datvars=training1[,1:4]
  dat.sc=scale(datvars)
 
  n=nrow(dat.sc)
  dat.indices=seq(1,n)
 
  timematrix=with(training1,
  classvec2classmat(Species[dat.indices]))
 
  pls.dat=plsr(timematrix ~ dat.sc,
  ncomp=3, method=oscorespls, data=training1)
 
  x=crossval(pls.dat, segments=10)
 
  summary(x)
  summary(plsFit2)
 
  I see two different R2 values and I cannot figure out how to get the Q2
  value.  Any insight as to what my errors may be would be appreciated.
 
  Regards,
 
  --
  Charles
 



 --
 Charles Determan
 Integrated Biosciences PhD Student
 University of Minnesota

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




-- 

Max

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