[R] closed testing procedure

2011-09-11 Thread array chip
Hi, are the methods for multiple testing p value adjustment (Shaffer, Westfall, 
free) implemented in the function adjusted() in multcomp package so called 
closed testing procedure? what about those methods (holm, hochberg, hommel, BH, 
BY) implemented in the p.adjust() in the stats package?
 
Thanks
 
John

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

2011-09-11 Thread zeec
Hi,

I have a question regarding the modeling methodology of the following problem:

* I have two data sets {X_i,y_i} {X_i,z_i}, i=1..N,
  where y_i = f(X_i) + i.i.d. Gaussian noise 
  and   z_i = g(X_i) + i.i.d. Gaussian noise
* I apply bayesian linear regression to each of them and obtain
  p(y|X) and p(z|X)
  
I would like to improve the prediction of the two models using the knowledge 
that
f and g are related (for example f(X_i) = g(X_i) - 1). I can obtain a model 
p(y,z).

I know that there are methods for multi-output regression, but I hope both can 
be modeled independently and then combined. 

Thank you for your help!
Steffan
--

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


Re: [R] Multi-output regression

2011-09-11 Thread Daniel Malter
I am not a Bayesian. In the non-Bayesian case you would use SUR to model both
equations simultaneously. If both use the exact same matrix of data, X
(i.e., the value are numerically absolutely identical), then SUR will
collapse to OLS. In that sense you get a combined estimate using SUR that
respects the correlation of the error terms between equations. However, it
will be efficient to estimate each equation individually if the Xs are
exactly the same.

Daniel


zeec wrote:
 
 Hi,
 
 I have a question regarding the modeling methodology of the following
 problem:
 
 * I have two data sets {X_i,y_i} {X_i,z_i}, i=1..N,
   where y_i = f(X_i) + i.i.d. Gaussian noise 
   and   z_i = g(X_i) + i.i.d. Gaussian noise
 * I apply bayesian linear regression to each of them and obtain
   p(y|X) and p(z|X)
   
 I would like to improve the prediction of the two models using the
 knowledge that
 f and g are related (for example f(X_i) = g(X_i) - 1). I can obtain a
 model p(y,z).
 
 I know that there are methods for multi-output regression, but I hope both
 can be modeled independently and then combined. 
 
 Thank you for your help!
 Steffan
 --
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

--
View this message in context: 
http://r.789695.n4.nabble.com/Multi-output-regression-tp3804766p3804855.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] how to remove NA/NaN/Inf in a matrix??

2011-09-11 Thread anand m t
Hi all..
I'm very new R, and i'm analyzing microarray data using Bioconductor..
Recently i was given microarray data to analyze. The problem is whenever i
run MAS5 presence calls algorithm,
it throws an error saying NA/NaN/Inf in foreign function. How do i remove
such  NA/NaN/Inf's ??
I tried na.omit(dataframe)  but stil problem exists.

dimension of matrix (data) is 35556 7.

 data.mas5calls=mas5calls(data)
Getting probe level data...
Computing p-values
Error in FUN(1:6[[1L]], ...) :
  NA/NaN/Inf in foreign function call (arg 2)

Thank you.

-- 
**
Anand M.T
School of Biotechnology (Bio-Informatics),
International Instituteof Information Technology (I2IT),
P-14, Rajiv Gandhi Infotech park,
Hinjewadi,
Pune-411 057.
INDIA.

The secret of success comprised in three words.. Work, Finish  Publish -
Michael Faraday

[[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] function censReg in panel data setting

2011-09-11 Thread Arne Henningsen
Dear Igors

On 9 September 2011 22:00, Igors igors.lahanc...@gmail.com wrote:
 Thank you for your answer. However it doesn't solve my problem fully.

 The problem is that I have much bigger data set than I sent to you (it was
 only a small part : 874 obs.). My full data set is 546718 obs.

 If I try to use censReg on full data set, then it still gives me the same
 already mentioned error about Na's in the initial gradient.


 I have sent you an e-mail with full dataset and the code.

Thanks!

 I would really
 appreciate if you could check how it works and suggest me how to solve this
 problem.

Now, I get the same error message. The problem is that the
log-likelihood function becomes minus infinity. I guess that this
problem occurs, because a likelihood contribution of (at least) one
individual observation is so small that it is rounded zero and hence,
its logarithm is minus infinity. However, I have to take a deeper look
into this issue before I can give a definite answer and hopefully find
a solution.

 I have noticed that you use iterlim argumet to specify maximum number of
 iterations.  How this argument could affect possibility of obtaining
 estimates?

Using your small data set, the maximization of the (log) likelihood
function in censReg() did not converge within 100 iterations.
Therefore, I increased the maximum number of iterations from 100 to
200 -- and then the maximization converged :-(

/Arne

-- 
Arne Henningsen
http://www.arne-henningsen.name

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 remove NA/NaN/Inf in a matrix??

2011-09-11 Thread David Winsemius


On Sep 11, 2011, at 5:38 AM, anand m t wrote:


Hi all..
I'm very new R, and i'm analyzing microarray data using Bioconductor..
Recently i was given microarray data to analyze. The problem is  
whenever i

run MAS5 presence calls algorithm,
it throws an error saying NA/NaN/Inf in foreign function. How do i  
remove

such  NA/NaN/Inf's ??
I tried na.omit(dataframe)  but stil problem exists.

dimension of matrix (data) is 35556 7.


data.mas5calls=mas5calls(data)

Getting probe level data...
Computing p-values
Error in FUN(1:6[[1L]], ...) :
 NA/NaN/Inf in foreign function call (arg 2)


Besides the possibility that your data has NAs there is the possibilty  
that the authors of whatever package has that function did not  
anticipate some negative values or some other condition that your data  
led to. Maybe the foreign function, i.e. not 'mas5calls'  tried to  
take the log of 0 or some such.


It's not possible to saymuch more given the vagueness of your  
question. This is also not the Bioconductor mailing list.


--
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] On-line machine learning packages?

2011-09-11 Thread Jay
What R packages are available for performing classification tasks?
That is, when the predictor has done its job on the dataset (based on
the training set and a range of variables), feedback about the true
label will be available and this information should be integrated for
the next classification round.

//Jay

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

2011-09-11 Thread Yumin
Hello all:

As everyone knows the stock quotes in Yahoo can be downloaded directly 
on EXCEL spreadsheet. 

we can also use the simple sentence of package tseries of R to download
Yahoo quote:
   
  x - get.hist.quote(instrument = ibm, start = 2010-01-01,
quote = close)  
  x
  
The result will display on the R console. BUT how can we also download
them onto 
spreadsheet? 

Thank!

--
View this message in context: 
http://r.789695.n4.nabble.com/How-download-to-spreadsheet-tp3805182p3805182.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] On-line machine learning packages?

2011-09-11 Thread David Winsemius


On Sep 11, 2011, at 11:42 AM, Jay wrote:


What R packages are available for performing classification tasks?
That is, when the predictor has done its job on the dataset (based on
the training set and a range of variables), feedback about the true
label will be available and this information should be integrated for
the next classification round.


You should look at CRAN Task Views. Extremely easy to find from the  
main R-project page.


--
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] How download to spreadsheet?

2011-09-11 Thread Hasan Diwan
require(quantmod)
getSymbols('IBM', from='2010-01-01')
write.csv(Cl(IBM), file='ibm-2010-present.csv')

I can open the resulting file in Excel without problems. Depending on
your preference, you may want to use write.csv2 instead.

On 11 September 2011 06:59, Yumin zpx...@gmail.com wrote:
    The result will display on the R console. BUT how can we also download
 them onto
 spreadsheet?
-- 
Sent from my mobile device
Envoyait de mon telephone mobil

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


Re: [R] On-line machine learning packages?

2011-09-11 Thread Jay
Hi,

I used the rseek search engine to look for suitable solutions, however
as I was unable to find anything useful, I'm asking for help.
Anybody have experience with these kinds of problems? I looked into
dynaTree, but as information is a bit scares and as I understand it,
it might not be what I'm looking for..(?)


BR,
Jay


On Sep 11, 7:15 pm, David Winsemius dwinsem...@comcast.net wrote:
 On Sep 11, 2011, at 11:42 AM, Jay wrote:

  What R packages are available for performing classification tasks?
  That is, when the predictor has done its job on the dataset (based on
  the training set and a range of variables), feedback about the true
  label will be available and this information should be integrated for
  the next classification round.

 You should look at CRAN Task Views. Extremely easy to find from the  
 main R-project page.

 --
 David Winsemius, MD
 West Hartford, CT

 __
 r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guidehttp://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] On-line machine learning packages?

2011-09-11 Thread Jason Edgecombe

Try this:

http://cran.r-project.org/web/views/MachineLearning.html

On 09/11/2011 12:43 PM, Jay wrote:

Hi,

I used the rseek search engine to look for suitable solutions, however
as I was unable to find anything useful, I'm asking for help.
Anybody have experience with these kinds of problems? I looked into
dynaTree, but as information is a bit scares and as I understand it,
it might not be what I'm looking for..(?)


BR,
Jay


On Sep 11, 7:15 pm, David Winsemiusdwinsem...@comcast.net  wrote:

On Sep 11, 2011, at 11:42 AM, Jay wrote:


What R packages are available for performing classification tasks?
That is, when the predictor has done its job on the dataset (based on
the training set and a range of variables), feedback about the true
label will be available and this information should be integrated for
the next classification round.
You should look at CRAN Task Views. Extremely easy to find from the  
main R-project page.


--
David Winsemius, MD
West Hartford, CT

__
r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guidehttp://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 remove NA/NaN/Inf in a matrix??

2011-09-11 Thread Ken
Try:
library(Hmisc)
?na.delete
  Ken Hutchison 

On Sep 11, 2554 BE, at 5:38 AM, anand m t anandro...@gmail.com wrote:

 Hi all..
 I'm very new R, and i'm analyzing microarray data using Bioconductor..
 Recently i was given microarray data to analyze. The problem is whenever i
 run MAS5 presence calls algorithm,
 it throws an error saying NA/NaN/Inf in foreign function. How do i remove
 such  NA/NaN/Inf's ??
 I tried na.omit(dataframe)  but stil problem exists.
 
 dimension of matrix (data) is 35556 7.
 
 data.mas5calls=mas5calls(data)
 Getting probe level data...
 Computing p-values
 Error in FUN(1:6[[1L]], ...) :
  NA/NaN/Inf in foreign function call (arg 2)
 
 Thank you.
 
 -- 
 **
 Anand M.T
 School of Biotechnology (Bio-Informatics),
 International Instituteof Information Technology (I2IT),
 P-14, Rajiv Gandhi Infotech park,
 Hinjewadi,
 Pune-411 057.
 INDIA.
 
 The secret of success comprised in three words.. Work, Finish  Publish -
 Michael Faraday
 
[[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] Emacs ESS finding all versions of R

2011-09-11 Thread Alex Olssen
Dear R-help,

Apologies if this isn't exactly the right place for this question.

I am trying to run R in emacs using ESS.  I have done this
successfully many times - it works right now on my home computer in
windows 7 and in ubuntu.

The problem is that when I start emacs the regular splash screen
doesn't show.  In the mini-buffer I get the message Finding all
versions of R on your system.  And then emacs just freezes up.

I am running windows xp.

emacs is located at
C:\Program Files\emacs-23.3\bin\emacs

I have an ess-5.14 folder at
C:\Program Files\emacs-23.3\site-lisp\ess-5.14

R is located at
C:\Program Files\R\R-2.13.1\bin\R
or
C:\Program Files\R\R-2.13.1\bin\i386\Rterm
?

In my ~/.emacs file I have tried included only the following lines
(require 'ess-site)
and
(require 'ess-site)
(setq inferior-R-program-name C:\\Program Files\\R\\R-2.13\\bin\\R)
as well as many variations on the R path, including \, /, and going to
Rterm instead.

Any help would be greatly appreciated.

Thanks,
Alex Olssen

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

2011-09-11 Thread li li
Dear all,
Can anyone take a look at my program below?
There are two functions: f1 (lambda,z,p1) and f2(p1,cl, cu).
I fixed p1=0.15 for both functions. For any fixed value of lambda (between
0.01 and 0.99),
I solve f1(p1=0.15, lambda=lambda, z)=0 for the corresponding cl and cu
values.
Then I plug the calculated cl and cu back into the function f2.
Eventually, I want to find the lambda value and the corresponding cl and cu
values that would
make f2=0.1.
   The result of this program does not seem to match the answer I have. Can
some one give me
some hint? Thank you very much.
Hannah



u1 - -3

u2 - 4


f1 - function(lambda,z,p1){

lambda*(p1*exp(u1*z-u1^2/2)+(0.2-p1)*exp(u2*z-u2^2/2))-(1-lambda)*0.8}


f2 - function(p1,cl, cu){

 0.8*(pnorm(cl)+(1-pnorm(cu)))/(0.8*(pnorm(cl)+(1-pnorm(cu)))+p1*(pnorm(cl-
u1)+(1-pnorm(cu-u1)))+(0.2-p1)*(pnorm(cl-u2)+(1-pnorm(cu-u2}


p1 - 0.15


lam - seq(0.01,0.99, by=0.001)

x1 - numeric(length(lam))


for (i in 1:length(lam)){



cl - uniroot(f1, lower =-10, upper = 0,

   tol = 1e-10,p1=p1,lambda=lam[i])$root


cu - uniroot(f1, lower =0, upper = 10,

   tol = 1e-10,p1=p1,lambda=lam[i])$root



x1[i]- f2(p1=p1, cl=cl, cu=cu) }



k - 1

while(klength(lam)  x1[k]=0.1){

k=k+1

  }

  k-k-1;k



lower - uniroot(f1, lower =-10, upper = 0,

   tol = 1e-10,p1=p1,lambda=lam[k])$root


upper - uniroot(f1, lower =0, upper = 10,

   tol = 1e-10,p1=p1,lambda=lam[k])$root




res - c(lower, upper)

[[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] Emacs ESS finding all versions of R

2011-09-11 Thread Richard M. Heiberger
Alex,

This query belongs on the ESS list
ess-h...@r-project.org
Please place any followup questions there.

You seem to have accepted the default location of R, so ESS should just
work.
The only line you need in ~/.emacs
is
(require 'ess-site)
The other lines you mention cause interference and should not be there.

I assume you have 32-bit windows since you mentioned i386/ but did not
mention x64/
The i386/Rterm.exe and x64/Rterm.exe are the relevant executable files.
ESS will find them.

It is possible that you have other lines in your .emacs or in your
site-start.el files and they are causing
trouble.

Start emacs without any initialization files
   emacs -Q
And then manually load the ess-site.el file.

Please report back to the ESS mailing list

Rich


On Sun, Sep 11, 2011 at 4:23 PM, Alex Olssen alex.ols...@gmail.com wrote:

 Dear R-help,

 Apologies if this isn't exactly the right place for this question.

 I am trying to run R in emacs using ESS.  I have done this
 successfully many times - it works right now on my home computer in
 windows 7 and in ubuntu.

 The problem is that when I start emacs the regular splash screen
 doesn't show.  In the mini-buffer I get the message Finding all
 versions of R on your system.  And then emacs just freezes up.

 I am running windows xp.

 emacs is located at
 C:\Program Files\emacs-23.3\bin\emacs

 I have an ess-5.14 folder at
 C:\Program Files\emacs-23.3\site-lisp\ess-5.14

 R is located at
 C:\Program Files\R\R-2.13.1\bin\R
 or
 C:\Program Files\R\R-2.13.1\bin\i386\Rterm
 ?

 In my ~/.emacs file I have tried included only the following lines
 (require 'ess-site)
 and
 (require 'ess-site)
 (setq inferior-R-program-name C:\\Program Files\\R\\R-2.13\\bin\\R)
 as well as many variations on the R path, including \, /, and going to
 Rterm instead.

 Any help would be greatly appreciated.

 Thanks,
 Alex Olssen

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.htmlhttp://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] Variable scoping question

2011-09-11 Thread jim holtman
Bill,

Thanks for the improvment.  I had not been concerned in looking at the
type; was primarily interested in the sizes.  Will go back and update
the function.

On Thu, Sep 8, 2011 at 11:53 AM, William Dunlap wdun...@tibco.com wrote:
 In my.ls() you ought to convert the pos argument
 to an environment and consistently use that environment
 in the calls to eval, get, and ls in the function.
 E.g., with the following modification

 my.ls1 - function (pos = 1, sorted = FALSE, envir = as.environment(pos))
 {
    .result - sapply(ls(envir = envir, all.names = TRUE), function(..x) 
 object.size(eval(as.symbol(..x),
        envir = envir)))
    if (sorted) {
        .result - rev(sort(.result))
    }
    .ls - as.data.frame(rbind(as.matrix(.result), `**Total` = sum(.result)))
    names(.ls) - Size
    .ls$Size - formatC(.ls$Size, big.mark = ,, digits = 0,
        format = f)
    .ls$Mode - c(unlist(lapply(rownames(.ls)[-nrow(.ls)], function(x) 
 mode(eval(as.symbol(x),
        envir = envir, ---)
    .ls
 }

 we get:

 sorted - 10:1 # put a variable in .GlobalEnv that is also in my.ls*
 my.ls1()
          Size     Mode
 my.ls   12,576 function
 my.ls1  23,424 function
 sorted      88  numeric
 **Total 36,088  ---
 my.ls()
          Size     Mode
 my.ls   12,576 function
 my.ls1  23,424 function
 sorted      48  logical
 **Total 36,048  ---

 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 Nordlund, Dan
 (DSHS/RDA)
 Sent: Thursday, September 08, 2011 8:33 AM
 To: r-help@r-project.org
 Subject: Re: [R] Variable scoping question

  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
  project.org] On Behalf Of jim holtman
  Sent: Thursday, September 08, 2011 6:52 AM
  To: Bos, Roger
  Cc: r-help@r-project.org
  Subject: Re: [R] Variable scoping question
 
  Here is a function I use to look at the sizes of objects:
 
  my.ls -
  function (pos = 1, sorted = FALSE)
  {
      .result - sapply(ls(pos = pos, all.names = TRUE), function(..x)
  object.size(eval(as.symbol(..x
      if (sorted) {
          .result - rev(sort(.result))
      }
      .ls - as.data.frame(rbind(as.matrix(.result), `**Total` =
  sum(.result)))
      names(.ls) - Size
      .ls$Size - formatC(.ls$Size, big.mark = ,, digits = 0,
          format = f)
      .ls$Mode - c(unlist(lapply(rownames(.ls)[-nrow(.ls)], function(x)
  mode(eval(as.symbol(x),
          ---)
      .ls
  }
 

 Jim,

 I thought I would try out your function above.  I copy-and-pasted the 
 function into a newly started,
 vanilla R session, then ran the following code.

  x - 1:1000
  my.ls()
           Size      Mode
 my.ls   12,576  function
 x        4,040 character
 **Total 16,616   ---
 

 I don't understand the character mode for the vector x.  Any thoughts?  Here 
 is my sessionInfo().

  sessionInfo()
 R version 2.13.1 (2011-07-08)
 Platform: x86_64-pc-mingw32/x64 (64-bit)

 locale:
 [1] LC_COLLATE=English_United States.1252
 [2] LC_CTYPE=English_United States.1252
 [3] LC_MONETARY=English_United States.1252
 [4] LC_NUMERIC=C
 [5] LC_TIME=English_United States.1252

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

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


 Dan

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


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

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




-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

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


[R] how to quote factors in a function?

2011-09-11 Thread casperyc
### code ###
x=sample(LETTERS[1:26],100,T)
prob=function(y){
count=sum(x==y)
total=length(x)
count/total
}
### end ###

How do I quote the letters A,B,C,D ect, in order to make the prob function
return the weights of the desired Letter?

Thanks!

--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-quote-factors-in-a-function-tp3805913p3805913.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] (no subject)

2011-09-11 Thread Stephen Sefick
Please include a meaningful 'Subject' because these conversations are 
archived, and serve as a valuable help resource for the community.  I 
don't believe I understand what you want.


Stephen

On 09/11/2011 03:32 PM, li li wrote:

Dear all,
 Can anyone take a look at my program below?
There are two functions: f1 (lambda,z,p1) and f2(p1,cl, cu).
I fixed p1=0.15 for both functions. For any fixed value of lambda (between
0.01 and 0.99),
I solve f1(p1=0.15, lambda=lambda, z)=0 for the corresponding cl and cu
values.
Then I plug the calculated cl and cu back into the function f2.
Eventually, I want to find the lambda value and the corresponding cl and cu
values that would
make f2=0.1.
The result of this program does not seem to match the answer I have. Can
some one give me
some hint? Thank you very much.
 Hannah



u1- -3

u2- 4


f1- function(lambda,z,p1){

lambda*(p1*exp(u1*z-u1^2/2)+(0.2-p1)*exp(u2*z-u2^2/2))-(1-lambda)*0.8}


f2- function(p1,cl, cu){

  0.8*(pnorm(cl)+(1-pnorm(cu)))/(0.8*(pnorm(cl)+(1-pnorm(cu)))+p1*(pnorm(cl-
u1)+(1-pnorm(cu-u1)))+(0.2-p1)*(pnorm(cl-u2)+(1-pnorm(cu-u2}


p1- 0.15


lam- seq(0.01,0.99, by=0.001)

x1- numeric(length(lam))


for (i in 1:length(lam)){



cl- uniroot(f1, lower =-10, upper = 0,

tol = 1e-10,p1=p1,lambda=lam[i])$root


cu- uniroot(f1, lower =0, upper = 10,

tol = 1e-10,p1=p1,lambda=lam[i])$root



x1[i]- f2(p1=p1, cl=cl, cu=cu) }



k- 1

while(klength(lam)  x1[k]=0.1){

 k=k+1

   }

   k-k-1;k



lower- uniroot(f1, lower =-10, upper = 0,

tol = 1e-10,p1=p1,lambda=lam[k])$root


upper- uniroot(f1, lower =0, upper = 10,

tol = 1e-10,p1=p1,lambda=lam[k])$root




res- c(lower, upper)

[[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] how to quote factors in a function?

2011-09-11 Thread R. Michael Weylandt michael.weyla...@gmail.com
You quote them in quotes. A

Also: bad scoping. 

Michael Weylandt

On Sep 11, 2011, at 6:11 PM, casperyc caspe...@hotmail.co.uk wrote:

 ### code ###
x=sample(LETTERS[1:26],100,T)
prob=function(y){
count=sum(x==y)
total=length(x)
count/total
}
 ### end ###
 
 How do I quote the letters A,B,C,D ect, in order to make the prob function
 return the weights of the desired Letter?
 
 Thanks!
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/how-to-quote-factors-in-a-function-tp3805913p3805913.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] how to quote factors in a function?

2011-09-11 Thread Jorge I Velez
Hi casperyc,

Try

# option 1
x - sample(LETTERS[1:26], 100, TRUE)

prob - function(y){
   count=sum(x==y)
   total=length(x)
   count/total
 }
prob('A')
prob('B')
prob('Z')


# option 2
tx - prop.table(table(x))
tx
tx['A']

# option 2.1
foo - function(x, l = NULL){
tx - prop.table(table(x))
if(is.null(l)){
  r - tx
}
   else r - tx[l]
  r
}

foo(x)
foo(x, 'A')

HTH,
Jorge


On Sun, Sep 11, 2011 at 6:11 PM, casperyc  wrote:

 ### code ###
x=sample(LETTERS[1:26],100,T)
prob=function(y){
count=sum(x==y)
total=length(x)
count/total
}
 ### end ###

 How do I quote the letters A,B,C,D ect, in order to make the prob
 function
 return the weights of the desired Letter?

 Thanks!

 --
 View this message in context:
 http://r.789695.n4.nabble.com/how-to-quote-factors-in-a-function-tp3805913p3805913.html
 Sent from the R help mailing list archive at Nabble.com.

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


[[alternative HTML version deleted]]

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


Re: [R] (no subject)

2011-09-11 Thread Jean-Christophe BOUËTTÉ
Hello,
you would get more answers if you code had proper indentation and comments.
Also, please provide a meaningful topic. You should also explain how
this is an R question and not just a debug my code request. What are
are you trying to achieve? Which of the numerous variables you
declared should we look at? What was the result you expected and what
did you get?

JC

2011/9/11 li li hannah@gmail.com:
 Dear all,
    Can anyone take a look at my program below?
 There are two functions: f1 (lambda,z,p1) and f2(p1,cl, cu).
 I fixed p1=0.15 for both functions. For any fixed value of lambda (between
 0.01 and 0.99),
 I solve f1(p1=0.15, lambda=lambda, z)=0 for the corresponding cl and cu
 values.
 Then I plug the calculated cl and cu back into the function f2.
 Eventually, I want to find the lambda value and the corresponding cl and cu
 values that would
 make f2=0.1.
   The result of this program does not seem to match the answer I have. Can
 some one give me
 some hint? Thank you very much.
            Hannah



 u1 - -3

 u2 - 4


 f1 - function(lambda,z,p1){

 lambda*(p1*exp(u1*z-u1^2/2)+(0.2-p1)*exp(u2*z-u2^2/2))-(1-lambda)*0.8}


 f2 - function(p1,cl, cu){

  0.8*(pnorm(cl)+(1-pnorm(cu)))/(0.8*(pnorm(cl)+(1-pnorm(cu)))+p1*(pnorm(cl-
 u1)+(1-pnorm(cu-u1)))+(0.2-p1)*(pnorm(cl-u2)+(1-pnorm(cu-u2}


 p1 - 0.15


 lam - seq(0.01,0.99, by=0.001)

 x1 - numeric(length(lam))


 for (i in 1:length(lam)){



 cl - uniroot(f1, lower =-10, upper = 0,

           tol = 1e-10,p1=p1,lambda=lam[i])$root


 cu - uniroot(f1, lower =0, upper = 10,

           tol = 1e-10,p1=p1,lambda=lam[i])$root



 x1[i]- f2(p1=p1, cl=cl, cu=cu) }



 k - 1

 while(klength(lam)  x1[k]=0.1){

    k=k+1

  }

  k-k-1;k



 lower - uniroot(f1, lower =-10, upper = 0,

           tol = 1e-10,p1=p1,lambda=lam[k])$root


 upper - uniroot(f1, lower =0, upper = 10,

           tol = 1e-10,p1=p1,lambda=lam[k])$root




 res - c(lower, upper)

        [[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] coxreg vs coxph: time-dependent treatment

2011-09-11 Thread Ehsan Karim
Dear List,

After including cluster() option the coxreg (from eha package)
produces results slightly different than that of coxph (from survival)
in the following time-dependent treatment effect calculation (example
is used just to make the point). Will appreciate any explaination /
comment.

cheers,

Ehsan



require(survival)
require(eha)
data(heart)

# create weights
follow - heart$stop - heart$start
fit - glm(transplant ~ age + surgery + year + follow,
  data=heart, family = binomial)
heart$iptw - ifelse(heart$transplant == 0,
  1 - predict(fit, type = response),
  predict(fit, type = response))
summary(heart$iptw)

# no weights (basic calculation)
fit0 - coxph(Surv(start,stop,event)~transplant, data=heart)
fit0 # fit with coxph without case-weights
fit1 - coxreg(Surv(start,stop,event)~transplant, data=heart)
fit1 # fit with coxreg from eha without case-weights

# coxph
fit2 - coxph(Surv(start,stop,event)~transplant + cluster(id),
  data=heart, weights = iptw, robust = T)
fit2 # fit with coxph having robust and cluster option
fit3 - coxph(Surv(start,stop,event)~transplant + cluster(id),
  data=heart, weights = iptw)
fit3 # fit with coxph having cluster option
fit4 - coxph(Surv(start,stop,event)~transplant,
  data=heart, weights = iptw)
fit4 # fit with coxph

# coxreg
fit5 - coxreg(Surv(start,stop,event)~transplant + cluster(id),
  data=heart, weights = iptw)
fit5 # fit with coxreg from eha having cluster option
fit6 - coxreg(Surv(start,stop,event)~transplant,
  data=heart, weights = iptw)
fit6 # fit with coxreg from eha


 exp(coef(fit3))# HR from coxph having cluster option
transplant1
  0.3782417
 exp(coef(fit4))# HR from coxph
transplant1
  0.3782417
 exp(coef(fit5))[1] # HR from coxreg having cluster option
transplant1
  0.3645507
 exp(coef(fit6))[1] # HR from coxreg
transplant1
  0.3782417


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


Re: [R] coxreg vs coxph: time-dependent treatment

2011-09-11 Thread Ehsan Karim
Sorry: there was an error in the weight calculation, fixed version is
the following, but still the final estimates differ as explained in
the original email:


#

require(survival)
require(eha)

data(heart)
head(heart)

follow - heart$stop - heart$start
fit - glm(transplant ~ age + surgery + year + follow,
  data=heart, family = binomial)
heart$wt - ifelse(heart$transplant == 0,
  (1 - predict(fit, type = response)),
  (predict(fit, type = response)))
heart$iptw - unlist(tapply(1/heart$wt, heart$id, cumprod))
summary(heart$iptw)

# no weights
fit0 - coxph(Surv(start,stop,event)~transplant, data=heart)
fit0 # fit with coxph without case-weights
fit1 - coxreg(Surv(start,stop,event)~transplant, data=heart)
fit1 # fit with coxreg from eha without case-weights

# coxph
fit2 - coxph(Surv(start,stop,event)~transplant + cluster(id),
  data=heart, weights = iptw, robust = T)
fit2 # fit with coxph having robust and cluster option
fit3 - coxph(Surv(start,stop,event)~transplant + cluster(id),
  data=heart, weights = iptw)
fit3 # fit with coxph having cluster option
fit4 - coxph(Surv(start,stop,event)~transplant,
  data=heart, weights = iptw)
fit4 # fit with coxph

# coxreg
fit5 - coxreg(Surv(start,stop,event)~transplant + cluster(id),
  data=heart, weights = iptw)
fit5 # fit with coxreg from eha having cluster option
fit6 - coxreg(Surv(start,stop,event)~transplant,
  data=heart, weights = iptw)
fit6 # fit with coxreg from eha

exp(coef(fit3))# HR from coxph having cluster option
exp(coef(fit4))# HR from coxph
exp(coef(fit5))[1] # HR from coxreg having cluster option
exp(coef(fit6))[1] # HR from coxreg

#
 exp(coef(fit3))# HR from coxph having cluster option
transplant1
   17.94681
 exp(coef(fit4))# HR from coxph
transplant1
   17.94681
 exp(coef(fit5))[1] # HR from coxreg having cluster option
transplant1
   20.06519
 exp(coef(fit6))[1] # HR from coxreg
transplant1
   17.94681
#

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


Re: [R] Adding groups to regression line panel function in Lattice

2011-09-11 Thread Deepayan Sarkar
On Fri, Sep 9, 2011 at 9:38 PM, Bigelow, Seth sbige...@fs.fed.us wrote:
 I wish to display a single-panel Lattice figure with grouped data and fitted 
 regression lines. I don't seem to be able to get the
 individual regression lines to display, e.g.;

 d - data.frame(q = rep(1:6, each=10), cc = rep(seq(10,100, 10),6))           
                # create data frame with group identifier 'q', independent 
 variable cc
 d$ba = d$q*0.1*d$cc + 5*rnorm(nrow(d))                                        
                                    # create dependent variable 'ba'

 mypanel - function(...){                                                     
                                                          # panel function
                panel.lmline(d$cc, d$ba, groups = d$q)                         
                                          #
                panel.xyplot(...)
                }

But panel.lmline() does not honour a 'groups' argument, so there is no
reason for this to work.

 xyplot(ba~cc,d,
                groups=q,
                panel = panel.superpose,
                panel.groups=mypanel
                )

 Can anyone suggest how to get lines to display by group?

How about

xyplot(ba~cc,d, groups=q, type=c(p, r))

 (and how to get lmline panel to fit line without estimating an intercept?)

xyplot(ba~cc,d, groups=q, panel = panel.superpose,
   panel.groups = function(x, y, ...) {
   panel.xyplot(x, y, ...)
   panel.abline(0, coef(lm(y ~ 0 + x)), ...)
   })

-Deepayan
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Open a file to APPEND

2011-09-11 Thread Noah Silverman
Hi,

I want to store the output of my program to a file.  However, With subsequent 
runs of  my code, I'd like to append to the same log file.  

Currently, I'm using:

outfile - file(log.txt, open=w)
cat(results, file=outfile)

This works, but will overwrite the log file each time.

Is there a way to open a file and have R append to the end?

Thanks!

--
Noah Silverman
UCLA Department of Statistics
8117 Math Sciences Building #8208
Los Angeles, CA 90095


[[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] Hourly data with zoo

2011-09-11 Thread steven mosher
I have date data as a numeric and hourly data in 0 to 2300 hours in a dataframe.

d  -  rep(20110101,24)
h  -  seq(from =  0, to  =  2300, by  = 100)

df  -  data.frame(LST_DATE  =  d,  LST_TIME  =  h,  data  =  rnorm(24, 0, 1))

S  -  chron(dates. = as.character(df$LST_DATE), times. =
paste(as.character(df$LST_TIME/100), :0:0, sep  = ),
   format  = c(dates  =  Ymd,  times =  h:m:s))
X  -  zoo(df$data, order.by = S)

And I want to create a regular zoo series,  The above works but its
pretty ugly. Is there a more elegant way to do this.

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