Re: [R] Response to R across the university

2008-04-13 Thread Tom Backer Johnsen
Antony Unwin wrote:

.


 The course itself went very well.  We encouraged people to bring their  
 laptops and work in groups.  Using JGR as the interface to R helped a  
 lot, as it was easier for people to load their own data and use the  
 help.  Of course, JGR is compulsory in Augsburg.  Giving everyone a  
 Butterbreze (a local delicacy) halfway through may have contributed to  
 the good humour of the course as well!

I apologize for my ignorance, but what is JGR?

Tom

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

2008-04-13 Thread ronggui
JGR (speak 'Jaguar') is a universal and unified Graphical User
Interface for R (it actually abbreviates Java Gui for R).

see http://stats.math.uni-augsburg.de/JGR/

On Sun, Apr 13, 2008 at 2:51 PM, Tom Backer Johnsen [EMAIL PROTECTED] wrote:
 Antony Unwin wrote:

  .



   The course itself went very well.  We encouraged people to bring their
   laptops and work in groups.  Using JGR as the interface to R helped a
   lot, as it was easier for people to load their own data and use the
   help.  Of course, JGR is compulsory in Augsburg.  Giving everyone a
   Butterbreze (a local delicacy) halfway through may have contributed to
   the good humour of the course as well!

  I apologize for my ignorance, but what is JGR?

  Tom



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




-- 
HUANG Ronggui, Wincent

Bachelor of Social Work, Fudan University, China

Master of sociology, Fudan University, China

Ph.D. Candidate, CityU of HK,
http://www.cityu.edu.hk/sa/psa_web2006/students/rdegree/huangronggui.html

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Extracting a data.frame from HTML code

2008-04-13 Thread Paul Smith
On Sun, Apr 13, 2008 at 12:37 AM, Martin Morgan [EMAIL PROTECTED] wrote:
 Hi Ethan --

  Use the XML library

   library(XML)
   url - 
 'http://www.nascar.com/races/cup/2007/1/data/standings_official.html'
   xml - htmlTreeParse(url, useInternal=TRUE)

  The previous line retrieves the html and stores it in an internal
  represnetation. There are warnings, but I think these are about
  ill-formed HTML at nascar.com

  A little looking suggests that the data you're after are table data
  (element 'td') inside table rows ('tr') inside a 'tbody' element. A
  little bit more looking shows that there's a blank line in the table,
  at unlucky row 13, I guess.

  So what we'd like to do is to extract all 'td' elements from all the
  rows but unlucky 13. We do this with an 'xpath' query, which specifies
  the path, from the root of the document through the relevant nodes, to
  the data that we want. Here's the query and data extraction

   q - //tbody/tr[position()!=13]/td
   dat - unlist(xpathApply(xml, q, xmlValue))

  The '//tbody' says 'find any tbody node somewhere below the current
  (i.e., root, at this point in the query) node', '/' says 'immediately
  below the current', we have some access to basic logic testing to
  subset the nodes we're after. xmlValue extracts the 'value' (text
  content, roughly) of the nodes that we've described the path to. This
  is a nice weekend hack, relying on the overall structure of the table
  and assuming, for instance, that there is only one tbody on the
  page. We'd have to work harder during the week.

  And then some R to make it into a data frame

   df - as.data.frame(t(matrix(dat, 11)))

  (11 because we've counted how many columns there are in the table; we
  could have discovered this from the document, e.g.,
  count(//tbody/tr[1]/td) as the xpath). The columns are all
  character, whereas you'd like some to be numeric.

  The page at http://www.w3.org/TR/xpath is very helpful for xpath,
  especially section 2.5.

  Hope that helps,

  Martin



  Ethan Pew [EMAIL PROTECTED] writes:

   Dear all,
  
   I'd like to use R to read in data from the web. I need some help finding an
   efficient way to strip the HTML tags and reformat the data as a data.frame
   to analyze in R.
  
   I'm currently using readLines() to read in the HTML code and then grep() to
   isolate the block of HTML code I want from each page, but this may not be
   the best approach.
  
   A short example:
   x1 - readLines(
   http://www.nascar.com/races/cup/2007/1/data/standings_official.html,n=-1)
  
   grep1 - grep(table,x1,value=FALSE)
   grep2 - grep(/table,x1,value=FALSE)
  
   block1 - x1[grep1:grep2]
  
  
   It seems like there should be a straightforward solution to extract a
   data.frame from the HTML code (especially since the data is already
   formatted as a table) but I haven't had any luck in my searches so far.
   Ultimately I'd like to compile several datasets from multiple webpages and
   websites, and I'm optimistic that I can use R to automate the process.  If
   someone could point me in the right direction, that would be fantastic.

Perhaps, the best way would be to copy the table to a spreadsheet and
then save it as a text file. Afterwards, to insert the data in R, use
read.table.

Paul

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

2008-04-13 Thread Louisa Hay

Hi, I' am doing a stats project using R to work out the size of a t-test and 
wilcoxon test depending on the distribution and sample size. I just can't get 
it to work - I want to put my results from the function size() into an array.At 
the moment I keep getting the error message:Error in res[distribution, test, 
samplesize] - results : subscript out of boundsCan anyone tell me where I'm 
going wrong, 
please?!size.power.test-function(){k-1000distributions-c(Normal,Uniform)tests-c(t,Wilcoxon)samplesizes-c(10,30,40)res-array(0,c(length(distributions),length(tests),length(samplesizes)))dimnames(res)-list(distributions,tests,samplesizes)for(distribution
 in distributions){for(test in tests){for(samplesize in samplesizes){for(i in 
1:k){results-size()res[distribution,test,samplesize]-results}output-size.power.testreturn(output)size-function(k=1000,H0=0,mu.true=0,sigma.true=1,alpha=0.05,x1=-sqrt(3),y1=sqrt(3)){distributions-c(Normal,Uniform)tests-c(t,Wil!
 coxon)samplesizes-c(10,30,40)reject1-numeric(k)for(distribution in 
distributions){for(test in tests){for(samplesize in samplesizes){for(i in 
1:k){if(distribution==Normal){#randomly generate data from normal 
distribution with true 
meandat-rnorm(n=samplesize,mean=mu.true,sd=sigma.true)}else{#randomly generate 
data from a uniform 
distributiondat-runif(samplesize,min=x1,max=y1)}if(test==t){#perform a 
t-test on sampleres-t.test(dat,alternative=two.sided,mu=H0)#record if 
p-value is less than alphareject1[i]-(res$p.value=alpha)}else{#perform a 
wilcoxon-test on 
sampleres-wilcox.test(dat,alternative=two.sided,mu=H0)#record if p-value is 
less than 
alphareject1[i]-(res$p.value=alpha)}}output-list(sum(reject1)/k)return(output)

A prize an hour, 24 hours a day. Try Big Snap now! 
_
[[elided Hotmail spam]]

[[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] Skipping specified rows in scan or read.table

2008-04-13 Thread Paul Smith
On Wed, Apr 9, 2008 at 7:37 PM, Ravi Varadhan [EMAIL PROTECTED] wrote:
  I have a data file, certain lines of which are character fields.  I would
  like to skip these rows, and read the data file as a numeric data frame.  I
  know that I can skip lines at the beginning with read.table and scan, but is
  there a way to skip a specified sequence of lines (e.g., 1, 2, 10, 11, 19,
  20, 28, 29, etc.) ?

  If I read the entire data file, and then delete the character fields, the
  values are still kept as factors, with each value denoted by its level.
  Since, I have continuous variables, there are as many levels as there are
  values.  I am unable to coerce this to numeric mode.  Is there a way to do
  this so that I can then manipulate the numeric data frame?

Read the entire data file to the data frame mydata, and then delete
the character fields. Afterwards,

mydata - edit(mydata)

and, inside edit, coerce the columns that you want to numeric.

Paul

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

2008-04-13 Thread Louisa Hay

Hi, I' am doing a stats project using R to work out the size of a t-test and 
wilcoxon test depending on the distribution and sample size. I just can't get 
it to work - I want to put my results from the function size() into an array.At 
the moment I keep getting the error message:Error in res[distribution, test, 
samplesize] - results : subscript out of boundsCan anyone tell me where I'm 
going wrong, 
please?!size.power.test-function(){k-1000distributions-c(Normal,Uniform)tests-c(t,Wilcoxon)samplesizes-c(10,30,40)res-array(0,c(length(distributions),length(tests),length(samplesizes)))dimnames(res)-list(distributions,tests,samplesizes)for(distribution
 in distributions){for(test in tests){for(samplesize in samplesizes){for(i in 
1:k){results-size()res[distribution,test,samplesize]-results}output-size.power.testreturn(output)size-function(k=1000,H0=0,mu.true=0,sigma.true=1,alpha=0.05,x1=-sqrt(3),y1=sqrt(3)){distributions-c(Normal,Uniform)tests-c(t,Wil!
 coxon)samplesizes-c(10,30,40)reject1-numeric(k)for(distribution in 
distributions){for(test in tests){for(samplesize in samplesizes){for(i in 
1:k){if(distribution==Normal){#randomly generate data from normal 
distribution with true 
meandat-rnorm(n=samplesize,mean=mu.true,sd=sigma.true)}else{#randomly generate 
data from a uniform 
distributiondat-runif(samplesize,min=x1,max=y1)}if(test==t){#perform a 
t-test on sampleres-t.test(dat,alternative=two.sided,mu=H0)#record if 
p-value is less than alphareject1[i]-(res$p.value=alpha)}else{#perform a 
wilcoxon-test on 
sampleres-wilcox.test(dat,alternative=two.sided,mu=H0)#record if p-value is 
less than 
alphareject1[i]-(res$p.value=alpha)}}output-list(sum(reject1)/k)return(output)
_
Welcome to the next generation of Windows Live

[[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] Arrays and functions

2008-04-13 Thread Ted Harding
On 13-Apr-08 08:43:33, Louisa Hay wrote:
 Hi,
 I' am doing a stats project using R to work out the size
 of a t-test and wilcoxon test depending on the distribution
 and sample size.
 
 I just can't get it to work - I want to put my results from
 the function size() into an array.
 
 At the moment I keep getting the error message:
   Error in res[distribution, test, samplesize] - results :
   subscript out of bounds
 
 Can anyone tell me where I'm going wrong,please?!

You have created a 3-dimensional array 'res' with
dimensions 2x2x3.

Apart from anything else, when you make the assignment

  res[distribution,test,samplesize]-results

the first value of 'samplesize' you use will be 10.
There is no array element with 3rd index equal to 10
(the maximum possible is 3). Hence (I suspect) your
error message.

I would recommend re-writing your code so that you use
the numbers of elements in each of your vectors
'distributions', 'tests' and 'samplesizes' to set the
ranges in your 'for' loops.

For example:

  Ndist-length(distributions)
  Ntest-length(tests)
  Nsamp-length(samplesizes)

and then you can do, for instance,

  for(idist in (1:Ndist)){
   for(itest in (1:Ntest)){
for(isamp in (1:Nsamp)){
 for(i in (1:k)){
  results-size()
  res[idist,itest,isamp]-results
 }
}
   }
  }

I also suspect that there are a lot of other things in
your code which could do with looking at too, but at
least the above approach should get you past the subscript
out of bounds problem!

Best wishes,
Ted.

 size.power.test-function(){
  k-1000
  distributions-c(Normal,Uniform)
  tests-c(t,Wilcoxon)
  samplesizes-c(10,30,40)
  res-array(0,c(length(distributions),
 length(tests),
 length(samplesizes))
)
  dimnames(res)-list(distributions,tests,samplesizes)
  for(distribution in distributions){
   for(test in tests){
for(samplesize in samplesizes){
 for(i in 1:k){
  results-size()
  res[distribution,test,samplesize]-results
 }
output-size.power.test
return(output)
   }
  }
 }
 }
 
 size-function(k=1000,H0=0,mu.true=0,
sigma.true=1,alpha=0.05,
x1=-sqrt(3),y1=sqrt(3)){
  distributions-c(Normal,Uniform)
  tests-c(t,Wilcoxon)
  samplesizes-c(10,30,40)
  reject1-numeric(k)
  for(distribution in distributions){
   for(test in tests){
for(samplesize in samplesizes){
 for(i in 1:k){
  if(distribution==Normal){
   #randomly generate data from normal distribution
   #with true mean
   dat-rnorm(n=samplesize,mean=mu.true,sd=sigma.true)
  }else{
  #randomly generate data from a uniform distribution
  dat-runif(samplesize,min=x1,max=y1)
 }
 if(test==t){
  #perform a t-test on sample
  res-t.test(dat,alternative=two.sided,mu=H0)
  #record if p-value is less than alpha
  reject1[i]-(res$p.value=alpha)
 }else{
  #perform a wilcoxon-test on sample
  res-wilcox.test(dat,alternative=two.sided,mu=H0)
  #record if p-value is less than alpha
 
  reject1[i]-(res$p.value=alpha)
  }
 }
 output-list(sum(reject1)/k)
 return(output)
}
   }
  }
 }
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 094 0861
Date: 13-Apr-08   Time: 10:23:11
-- XFMail --

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


[R] R help for PMML models

2008-04-13 Thread ajay ohri
Hi List,

What would be the syntax for outputting a linear  regression model and /or a
logistic regression model to PMML .

Regards,

Ajay

www.decisionstats.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] R help for PMML models

2008-04-13 Thread Tobias Verbeke
What would be the syntax for outputting a linear  regression model and /or a
logistic regression model to PMML .

There is a pmml.lm method in the pmml package (on CRAN).
I have improved code for that (and a pmml.glm) based on 
a student (Ashraf Fouadi) traineeship I supervised. 

It is planned to contribute this to the pmml package,
but if this is urgent I can send it in a private message.

Kind regards,
Tobias

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



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] lm() of one matrix against another

2008-04-13 Thread baptiste Auguié
Thanks for both replies, here is the cleaner version,


 n-5
 N-10

 data.x-matrix(1:(n*N),ncol=n)
 data.y-matrix(1:(n*N) + rnorm(n*N,sd=1),ncol=n)

 matplot(data.x,data.y,t=p,pch=1:n,bty=n)

 mapply(function(x,y){res - lm(y~x) ; lines(x,predict(res)) ; res} ,
   as.data.frame(data.x),as.data.frame(data.y),SIMPLIFY=F)



Out of curiosity, I'm not sure if one could get the lines colored  
corresponding to their index within mapply (or any function of the  
apply family for that matter). Is there a special trick to refer to  
the index under evaluation?

Thanks again,

baptiste



On 12 Apr 2008, at 20:08, Henrique Dallazuanna wrote:
 Try
 mapply(function(x,y)lm(y~x),as.data
 .frame(data.x),as.data.frame(data.y),SIMPLIFY=F)

 2008/4/12, baptiste Auguié [EMAIL PROTECTED]:
 Hello R list,


 I have two matrices of identical dimensions, and I want to fit a
 straight line for each pair of columns and plot the resulting lines.
 I got it to work with a for loop, but there must be a better way,


 n-5
 N-10

 data.x-matrix(1:(n*N),ncol=n)
 data.y-matrix(1:(n*N) + rnorm(n*N,sd=1),ncol=n)

 matplot(data.x,data.y,t=p,pch=1:n,bty=n)

 for (ii in 1:n)
 {
 test - lm(y~x,data=list(x=data.x[,ii],y=data.y[,ii]) )
 lines(data.x[,ii],test$coefficients[1] + test$coefficients[2] *
 data.x[,ii],lty=2,col=ii)
 }



 Thanks,

 baptiste


 _

 Baptiste Auguié

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

 Phone: +44 1392 264187

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

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



 -- 
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O

_

Baptiste Auguié

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

Phone: +44 1392 264187

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

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

2008-04-13 Thread cgenolin
Hi the list,

I need to use getGraphicsEvent to plot two graph. On the following toy 
example:
- the function b is ploting two graph depending on a parameter
- the function a is calling b according to some user answers. It is 
suppose to call b until the user press Return, but it does not.


b - function(x){
dev.off(2);dev.off(3)
windows();windows(3,3,xpos=0)
dev.set(2);plot(1:x)
dev.set(3);plot(1:x^2)
return(NULL)
}
b(2)

a - function(y){
b(y)
getGraphicsEvent(Arrow Up or Return,
onKeybd=function(key){
if(key!=ctrl-J){
if(key==Up){y - y+1}else{}
b(y)
cat(\n*** This function a never gets here... ***\n)
return(NULL)
}else{
return(TRUE)
}
}
)
}

a(3)

Is there something wrong in my code, or something I did not understand 
in getGraphicsEvent ?
I try on R 2.2.1, then on R 2.7

Thanks for your help.

Christophe


Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Computing time when calling C functions - why does an extra function call induce such an overhead?

2008-04-13 Thread Prof Brian Ripley

I've not seen any reposnse to this, probably because

-- this is not the list for C programming questions  (use R-devel)
-- there is no example provided for the times quoted.
-- the code is not compilable.

But I got a compiler warning on

  int *ipiv  = (int *) R_alloc((int) nrA, sizeof(int));

foo.c:8: warning: cast from pointer to integer of different size

(it should be *nrA) and that's most likely your error.  (BTW, using 
liberal casts like this is just stopping your tools helping you!)


The overhead of C function call is measured in nanosecs on modern systems, 
especially to functions in the same compilation unit.


On Thu, 10 Apr 2008, Søren Højsgaard wrote:


Dear list,

I am a little puzzled by computing time in connection with calling C 
functions. With the function mysolve1 given below I solve Ax=B, where 
the actual matrix operation takes place in mysolve2. Doing this 5000 
times takes 3.51 secs. However, if I move the actual matrix inversion 
part into mysolve1 (by uncommenting the two commented lines and skip the 
call to mysolve2) then the computations take only 0.03 secs. Can anyone 
tell me why there is such a time-overhead in introducing the extra 
function call to mysolve2?


I am on windows XP using R 2.6.1

Best regards
Søren


SEXP mysolve1(SEXP Ain, SEXP Bin, SEXP tolin)
{
 int *Adims, *Bdims;
 double tol = asReal(tolin);
 SEXP A, B;
 PROTECT(A = duplicate(Ain));
 PROTECT(B = duplicate(Bin));
 Adims = INTEGER(coerceVector(getAttrib(A, R_DimSymbol), INTSXP));
 Bdims = INTEGER(coerceVector(getAttrib(B, R_DimSymbol), INTSXP));
 int nrA, ncB;
 double *Ap, *Bp;
 nrA = Adims[0];
 ncB = Bdims[1];
 Ap  = REAL(A);
 Bp  = REAL(B);
/*   int info, *ipiv  = (int *) R_alloc(nrA, sizeof(int)); */
/*   F77_CALL(dgesv)(nrA, ncB, Ap, nrA, ipiv, Bp, nrA, info); */
 mysolve2(Ap, nrA, Bp, ncB, tol);
 UNPROTECT(2);
 return B;
}

void mysolve2(double *A, int *nrA, double *B, int *ncB, double *tolin)
{
 int info;
 int *ipiv  = (int *) R_alloc((int) nrA, sizeof(int));
 F77_CALL(dgesv)(nrA, ncB, A, nrA, ipiv, B, nrA, info);
}

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



--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] .Rprofile, date tagging history, loading packages

2008-04-13 Thread Muenchen, Robert A (Bob)
Dear R-Helpers,

I'm fiddling with my .Rprofile in Windows XP  R 2.7.0 Beta. I prefer to
manually save my workspace but automatically save my command history via
the .Rprofile. That is working fine once I found that utils:: was
required before the loadhistory  savehistory functions. What I would
like to do is add a separator line with a date between the histories of
each session. Something like,

=History for Sun Apr 13 09:43:50 2008

Is this possible? I have it print the date at startup, but that doesn't
appear as part of the history.

Also, I'm loading two packages at startup, which is working fine with
this code:

local({
   myOriginal - getOption(defaultPackages)
   myAutoLoads - c(Hmisc,ggplot2)
   myBoth - c(myOriginal,myAutoLoads)
   options(defaultPackages = myBoth)
 })

But when reading AITR, I noticed it has a .Rprofile example that looks
much simpler. It just loads the one additional package without checking
the defaultPackages. Is this just as good? Does it even need to be in
the .First function definition, or could it simply be a command by
itself in .Rprofile?

.First - function() {
options(prompt=$ , continue=+\t) # $ is the prompt
options(digits=5, length=999) # custom numbers and printout
x11() # for graphics
par(pch = +) # plotting character
source(file.path(Sys.getenv(HOME), R, mystuff.R))
# my personal functions
library(MASS) # attach a package
}

Thanks,
Bob

My whole .Rprofile:

# Startup Settings

# Place any R commands below.

options(width=64, digits=5, show.signif.stars=TRUE)
set.seed(1234)
setwd(/myRfolder)
myPackages - c(car,foreign,hexbin,
  ggplot2,gmodels,gplots, Hmisc,
  lattice, reshape,ggplot2,Rcmdr)
utils::loadhistory(file = myCumulative.Rhistory)


# Load packages automatically below.

 local({
   myOriginal - getOption(defaultPackages)

   # Edit next line to include your favorites.
   myAutoLoads - c(Hmisc,ggplot2)
   myBoth - c(myOriginal,myAutoLoads)
   options(defaultPackages = myBoth)
 })

# Things put here are done first.
.First - function() 
  {
cat(\n   Welcome to R!)
cat(\n   , paste(date()), \n\n )
  }


# Things put here are done last.
.Last - function() 
  {
graphics.off()
cat(\n\n  myCumulative.Rhistory has been saved on  ,paste(date())
) 
cat(\n\n  Goodbye!\n\n) 
utils::savehistory(file=myCumulative.Rhistory)
  }

=
Bob Muenchen (pronounced Min'-chen), Manager 
Statistical Consulting Center
U of TN Office of Information Technology
200 Stokely Management Center, Knoxville, TN 37996-0520
Voice: (865) 974-5230 
FAX: (865) 974-4810
Email: [EMAIL PROTECTED]
Web: http://oit.utk.edu/scc, 
News: http://listserv.utk.edu/archives/statnews.html
=

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


Re: [R] .Rprofile, date tagging history, loading packages

2008-04-13 Thread Duncan Murdoch
Muenchen, Robert A (Bob) wrote:
 Dear R-Helpers,

 I'm fiddling with my .Rprofile in Windows XP  R 2.7.0 Beta. I prefer to
 manually save my workspace but automatically save my command history via
 the .Rprofile. That is working fine once I found that utils:: was
 required before the loadhistory  savehistory functions. What I would
 like to do is add a separator line with a date between the histories of
 each session. Something like,

 =History for Sun Apr 13 09:43:50 2008

 Is this possible? I have it print the date at startup, but that doesn't
 appear as part of the history.
   

See ?timestamp.  I think it does what you want.

I don't know the relative merits of the two methods below; I suspect 
they're all pretty much equivalent (but watch out for things like search 
order, and which functions are available at which time.)

Duncan Murdoch
 Also, I'm loading two packages at startup, which is working fine with
 this code:

 local({
myOriginal - getOption(defaultPackages)
myAutoLoads - c(Hmisc,ggplot2)
myBoth - c(myOriginal,myAutoLoads)
options(defaultPackages = myBoth)
  })

 But when reading AITR, I noticed it has a .Rprofile example that looks
 much simpler. It just loads the one additional package without checking
 the defaultPackages. Is this just as good? Does it even need to be in
 the .First function definition, or could it simply be a command by
 itself in .Rprofile?

 .First - function() {
 options(prompt=$ , continue=+\t) # $ is the prompt
 options(digits=5, length=999) # custom numbers and printout
 x11() # for graphics
 par(pch = +) # plotting character
 source(file.path(Sys.getenv(HOME), R, mystuff.R))
 # my personal functions
 library(MASS) # attach a package
 }

 Thanks,
 Bob

 My whole .Rprofile:

 # Startup Settings

 # Place any R commands below.

 options(width=64, digits=5, show.signif.stars=TRUE)
 set.seed(1234)
 setwd(/myRfolder)
 myPackages - c(car,foreign,hexbin,
   ggplot2,gmodels,gplots, Hmisc,
   lattice, reshape,ggplot2,Rcmdr)
 utils::loadhistory(file = myCumulative.Rhistory)


 # Load packages automatically below.

  local({
myOriginal - getOption(defaultPackages)

# Edit next line to include your favorites.
myAutoLoads - c(Hmisc,ggplot2)
myBoth - c(myOriginal,myAutoLoads)
options(defaultPackages = myBoth)
  })

 # Things put here are done first.
 .First - function() 
   {
 cat(\n   Welcome to R!)
 cat(\n   , paste(date()), \n\n )
   }


 # Things put here are done last.
 .Last - function() 
   {
 graphics.off()
 cat(\n\n  myCumulative.Rhistory has been saved on  ,paste(date())
 ) 
 cat(\n\n  Goodbye!\n\n) 
 utils::savehistory(file=myCumulative.Rhistory)
   }

 =
 Bob Muenchen (pronounced Min'-chen), Manager 
 Statistical Consulting Center
 U of TN Office of Information Technology
 200 Stokely Management Center, Knoxville, TN 37996-0520
 Voice: (865) 974-5230 
 FAX: (865) 974-4810
 Email: [EMAIL PROTECTED]
 Web: http://oit.utk.edu/scc, 
 News: http://listserv.utk.edu/archives/statnews.html
 =

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

2008-04-13 Thread John Kane
http://stats.math.uni-augsburg.de/JGR/

Obviously a shameless product plug :)
--- Tom Backer Johnsen [EMAIL PROTECTED] wrote:

 Antony Unwin wrote:
 
 .
 
 
  The course itself went very well.  We encouraged
 people to bring their  
  laptops and work in groups.  Using JGR as the
 interface to R helped a  
  lot, as it was easier for people to load their own
 data and use the  
  help.  Of course, JGR is compulsory in Augsburg. 
 Giving everyone a  
  Butterbreze (a local delicacy) halfway through may
 have contributed to  
  the good humour of the course as well!
 
 I apologize for my ignorance, but what is JGR?
 
 Tom
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] R project

2008-04-13 Thread Nicola Smith

Hi,I am currently doing a project in which we are to investigate the size and 
power of three different one sample tests over three different distributions 
using a number of different sample sizes and values for mu1. I have written a 
function and was trying to get my answer for each test into the right position 
in an array so the output is the power of each combination of test, 
distribution, sample size and mu1, however my code is not working and i keep 
getting an error message returned. My code is: 
proj1.sim-function(){
  tests-c(t,Wilcoxon,bootstrap)
  distns-c(Normal,Uniform,Beta)
  sample.sizes-c(5,10,25,50,100)
  mu1s-c(0,0.5,1,1.5,2)
  
res-array(0,c(length(tests),length(distns),length(sample.sizes),length(mu1s)))
  dimnames(res)-list(tests,distns,sample.sizes,mu1s)
  for(test in tests){
for(distn in distns){
  for(sample.size in sample.sizes){
for(mu1 in mu1s){
  result-hypoth.test(sample.size,distn,test,mu1)
  res[test,distn,sample.size,mu1]-result
  
 output(res)
}
 
hypoth.test-function(sample.size,distn,test,mu1){
#Purpose:
#Samples n values from the chosen distribution
#Inputs:
#n - sample size of data to generate
#distn - the distribution to generate data from
#test - which test to use
#H0 - the null hypothesis
#mu.true - the true value of the mean under the chosen distribution
#sigma.true - the true value of the variance under the chosen distribution
#alpha - trimming level
#K - number of simulations to perform
#Outputs:
#reject.null - the number of times we reject the null hypothesis
 
  H0-0
  alpha-0.05
  K-1100
  sigma-1
  #create vectors for the results
  reject-numeric(K)
  mu1-numeric(5)
  sample.size-numeric(5)
  #loop through the observations the required number of K simulations
  for(i in 1:K){
#determine whether the data comes from a Normal or Uniform distribution
if(distn==Normal){
  #Normal distribution
  dat-rnorm(n=sample.size,mean=mu1,sd=sigma)
} else if(distn==Uniform){
  dat-runif(n=sample.size,min=-sqrt(3)+mu1, max=sqrt(3)+mu1)
} else {
  z-rbeta(n=sample.size,shape1=0.8,shape2=7.2)
  dat-((z-0.1)*(sigma/0.1))+H0
}
#determine which test is required to sample the observations
if(test==t){
  #t-test
  res-t.test(dat,alternative=two.sided,mu=H0)
} else if(test==Wilcoxon){
  res-wilcox.test(dat,alternative=two.sided,mu=H0)
} else {
  nboot-(K-1)
  n-length(dat)
  bootmean-NULL
  for(i in 1:nboot){
rdata-sample(dat,n,replace=T)
bootmean[i]-mean(rdata)
  }
  nlo-round((nboot+1)*(alpha/2))
  nhi-round((nboot+1)*((1-alpha)/2))
  bootmean-sort(bootmean)
  low-bootmean[nlo]
  high-bootmean[nhi]
  res-c(low,high)
}
#record whether we reject the null or not i.e. whether the p-value is less
#than or equal to the given alpha level(reject), or not (do not reject)
if(test==bootstrap){
  reject[i]-(H0low|H0high)
} else {
  reject[i]-(res$p.value=alpha)
}
#sum together the total number of null hypothesis rejected
reject.null-sum(reject)
  }
  power-(reject.null)/K
  return(power)
} Would you be able to tell me where I am going wrong? Thanks,Nicola Smith 
_
[[elided Hotmail spam]]

[[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] Matched pairs with two data frames

2008-04-13 Thread Udo
Hi,
I have a frame treat and want to find matched pairs in the data frame
control. In the matched (combined) data frame there should be two
variables (0/1),indicating the source of the data (treat or control),
so that it is possibe to set a filter (extraxt/select data).

#Here are the dataframes (my real data frames have many variables)
treat - data.frame(age=c(1,1,2,2,2,4),
school=c(10,10,20,20,20,11),
out1=c(9.5,2.3,3.3,4.1,5.9,4.6))
control - data.frame(age=c(1,1,1,1,3,2),
  school=c(10,10,10,10,33,20),
  out2=c(1.1,2,3.5,4.9,5.2,6.5))
print(treat)
print(control)

matched.data.frame - ?? #Match treat control by age school


#My SPSS syntax would be similar to this:
MATCH FILES FILE=treat /IN=fromtreat
  /FILE=control /IN=fromcontrol
  /BY age school.
SELECT IF fromdad AND fromfam. #select data, set filter

The /IN= option creates a 0/1 variable that indicates the
source of the data

The resultand matched data frame should have
the following structure:
age   schoolout1out2  fromtreat fromcontrol
1   10  9.5 1.1 1   1
1   10  2.3 2.0 1   1

4   11  4.6 NA  1   0
3   33  NA  5.2 0   1


I tried which and match, but I failed and was unlucky looking
at the help/archive. Merge doesn´t do the job, because it makes
all possible matches.


Thank´s for any help!
Udo



Udo KN G
  Ö I

Clinic for Child an Adolescent Psychiatry
Philipps University of Marburg / Germany

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] plotting muliple CI ellipses for EB estimates

2008-04-13 Thread John Fox
Dear Samuel,

The radius reflect the desired coverage of the ellipse. You should be able
to use  radius - sqrt(qchisq(.95, 2)), I think.

I hope this helps,
 John


John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 project.org] On Behalf Of Sam Field
 Sent: April-13-08 11:47 AM
 To: r-help@r-project.org
 Subject: [R] plotting muliple CI ellipses for EB estimates
 
 I have empirical Bayes estimates for slopes and intercepts for a number
 of
 subjects and I would like to plot the slopes and intercepts with
 confidence
 ellipses. These ellipses would be based on the confidence intervals for
 the
 slope and intercepts (forming the major and minor axis of each
 ellipse), and
 the correlation in the slope and intercepts.
 
 
 The ellipse function in the car library looks like the way to go, the
 add=
 argument would allow me to over-plot.  There are three arguments that
 generate
 the ellipse.
 
 center
 shape
 radius
 
 Center would be the posterior means for the intercept and slopes.
 shape would be the posterior covariance matrices (I think)
 
 I don't know what I would use for the radius argument however. My guess
 would
 be the upper bound of a confidence interval for either the slope or the
 intercept, but this does not return sensible results. I guess I need to
 know
 more about the geometry of ellipse, but if anybody can provide any
 assistance,
 I would really appreciate it.
 
 
 thanks!
 
 
 
 --
 Note the new contact information***
 
 Samuel H. Field, Ph.D.
 Senior Research Investigator
 CHERP/Division of Internal Medicine - University of Pennsylvania
 Philadelphia VA Medical Center
 3900 Woodland Ave (9 East)
 Philadelphia, PA 19104
 (215) 823-5800 EXT. 6155 (Office)
 (215) 823-6330 (Fax)
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] question about nlminb

2008-04-13 Thread John Pitchard
Hi Spencer,

Thanks for your email.

Do you have a reference for generating the variance-covariance matrix
from the restricted variance-covariance? Is this a well known
technique?

Regards,
John

On 10/04/2008, Spencer Graves [EMAIL PROTECTED] wrote:
 Hi, John:
  I just got the following error right after the attempt to use
 'rmvnorm'.
  Error: could not find function rmvnorm

  I tried 'library(mvtnorm)', but the 'rmvnorm' in that package gave me
 the following:
  Error in rmvnorm(1, mean = c(3, -20, -10, 3, 2), sd = c(0.1, 15, 4,  :
   unused argument(s) (sd = c(0.1, 15, 4, 0.15, 0.8), cov = c(1, 0.5, 0.5,
 0.5, 0.5, 0.5, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 1,
 0.5, 0.5, 0.5, 0.5, 0.5, 1))

  Then I got 87 hits to RSiteSearch(rmvnorm, 'fun').
  Regarding, How would I go about getting the entire variance-covariance
 matrix?, this is really easy:  Just define a 5 x 4 matrix A so the
 5-dimensional 'opt' you want is a constant plus A times the 4-dimensional
 restricted 'opt'.  [Please don't use the same name for two different things
 like 'opt' in your function below.  Half a century ago, when Fortran was
 young, that was very smart programming.  Today, it's primary effect it to
 make it difficult for mere mortals to understand your code.  Use something
 like 'opt5' for one and 'opt4' for the other.]
  Then

  Sig5 = A %*% vcov.nlminb(opt) %*% t(A).
  I believe the A matrix you want is as follows:
  A = matrix(NA, dim=c(5, 4))
  A[1:4, 1:4] - diag(4)
  A[5, ] - (-1)

  However, since your example was not self contained, I have not tested
 this.   Hope this helps. Spencer


  John Pitchard wrote:

  Hi Spencer,
 
  Sorry for not producing code as a worked example.
 
 
  Here's an example:
  ==
  # setting the seed number
  set.seed(0)
  # creating a correlation matrix
  corr - diag(5)
  corr[lower.tri(corr)] - 0.5
  corr[upper.tri(corr)] - 0.5
 
  # Data for the minimisation
  mat - rmvnorm(1, mean=c(3, -20, -10, 3, 2), sd=c(0.1, 15, 4,
  0.15, 0.8), cov=corr)
 
  obj.fun - function(opt, mat) {
opt - c(opt, 1-sum(opt))
LinearComb - mat%*%opt
obj - -min(LinearComb)
obj
  }
 
  opt - nlminb(rep(0,4), lower=rep(-3, 4), upper=rep(3, 4), obj.fun,
 mat=mat)
  opt.x - opt$parameters
  opt.x - c(opt.x, 1-sum(opt.x))
 
  # using vcov.nlminb from the MASS library to obtain the covariance matrix
  vcov.nlminb(opt)
  
 
 
  I have a variance-covariance matrix for 4 of the elements in the
  vector but not the last component. How would I go about getting the
  entire variance-covariance matrix?
 
  Thanks in advance for any help.
 
  Regards,
  John
 
 
 
 
  On 09/04/2008, Spencer Graves [EMAIL PROTECTED] wrote:
 
 
  Have you considered optimizing over x1 = x[1:(length(x)-1]?   You
 could feed a wrapper function 'f2(x1, ...)' that computes xFull = c(x1,
 1-sum(x1)) and feeds that to your 'fn'.
  If this makes sense, great.  Else, if my answer is not useful, be so
 kind as to PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html and provide
 commented, minimal, self-contained, reproducible code.
  Spencer
  
   John Pitchard wrote:
  
  
  
 Dear All,
   
I wanted to post some more details about the query I sent to s-news
 last
week.
   
I have a vector with a constraint. The constraint is that the sum of
 the
vector must add up to 1 - but not necessarily positive, i.e.
   
x[n] - 1 -(x[1] + ...+x[n-1])
   
I perform the optimisation on the vector x such that
   
x - c(x, 1-sum(x))
   
In other words,
   
fn - function(x){
 x - c(x, 1 - sum(x))
 # other calculations here
}
   
then feed this into nlminb()
   
out - nlminb(x, fn)
out.x - out$parameters
out.x - c(out.x, 1 - sum(out.x))
out.x
   
I would like to calculate standard errors for each of the components
 of x.
Is this possible by outputing the Hessian matrix? Furthermore, how
 would I
calculate this for the last component (if this is indeed possible)
 which has
the restriction (i.e. 1-sum(out.x))?
   
Any help would be much appreciated.
   
Regards,
John
   
  [[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 

Re: [R] Matched pairs with two data frames

2008-04-13 Thread Peter Alspach
Udo

Seems you might want merge()

HTH ...

Peter Alspach
 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Udo
 Sent: Monday, 14 April 2008 6:41 a.m.
 To: r-help@r-project.org
 Subject: [R] Matched pairs with two data frames
 
 Hi,
 I have a frame treat and want to find matched pairs in the 
 data frame control. In the matched (combined) data frame 
 there should be two variables (0/1),indicating the source 
 of the data (treat or control), so that it is possibe to set 
 a filter (extraxt/select data).
 
 #Here are the dataframes (my real data frames have many 
 variables) treat - data.frame(age=c(1,1,2,2,2,4),
 school=c(10,10,20,20,20,11),
 out1=c(9.5,2.3,3.3,4.1,5.9,4.6)) control 
 - data.frame(age=c(1,1,1,1,3,2),
   school=c(10,10,10,10,33,20),
   out2=c(1.1,2,3.5,4.9,5.2,6.5))
 print(treat)
 print(control)
 
 matched.data.frame - ?? #Match treat control by age school
 
 
 #My SPSS syntax would be similar to this:
 MATCH FILES FILE=treat /IN=fromtreat
   /FILE=control /IN=fromcontrol
   /BY age school.
 SELECT IF fromdad AND fromfam. #select data, set filter
 
 The /IN= option creates a 0/1 variable that indicates the 
 source of the data
 
 The resultand matched data frame should have the following structure:
 age   schoolout1out2  fromtreat fromcontrol
 1 10  9.5 1.1 1   1
 1 10  2.3 2.0 1   1
 
 4 11  4.6 NA  1   0
 3 33  NA  5.2 0   1
 
 
 I tried which and match, but I failed and was unlucky 
 looking at the help/archive. Merge doesn´t do the job, 
 because it makes all possible matches.
 
 
 Thank´s for any help!
 Udo
 
 
 
 Udo KN G
   Ö I
 
 Clinic for Child an Adolescent Psychiatry Philipps University 
 of Marburg / Germany
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

The contents of this e-mail are privileged and/or confidential to the named
 recipient and are not to be used by any other person and/or organisation.
 If you have received this e-mail in error, please notify the sender and delete
 all material pertaining to this e-mail.

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

2008-04-13 Thread Spencer Graves
  It's very well known that if a random vector X has a finite mean 
mu and covariance Sig, and Y = A X, then

(1) EY = A %*% mu

and

(2) cov(Y) = A %*% Sig %*% t(X) 
   = tcrossprod(A %*% Sig, A)

  Expression (1) says that mathematical expectation is a linear 
operator.  Expression (2) follows by application of (1).  See any good 
reference that discusses expected values.  I didn't find a web site with 
a 2 minute search, but I would expect to find it in C. R. Rao (1973) 
Linear Statistical Inference and Its Application, 2nd ed. (Wiley) and in 
many other places. 

  Best Wishes,
  Spencer 

John Pitchard wrote:
 Hi Spencer,

 Thanks for your email.

 Do you have a reference for generating the variance-covariance matrix
 from the restricted variance-covariance? Is this a well known
 technique?

 Regards,
 John

 On 10/04/2008, Spencer Graves [EMAIL PROTECTED] wrote:
   
 Hi, John:
  I just got the following error right after the attempt to use
 'rmvnorm'.
  Error: could not find function rmvnorm

  I tried 'library(mvtnorm)', but the 'rmvnorm' in that package gave me
 the following:
  Error in rmvnorm(1, mean = c(3, -20, -10, 3, 2), sd = c(0.1, 15, 4,  :
   unused argument(s) (sd = c(0.1, 15, 4, 0.15, 0.8), cov = c(1, 0.5, 0.5,
 0.5, 0.5, 0.5, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 1,
 0.5, 0.5, 0.5, 0.5, 0.5, 1))

  Then I got 87 hits to RSiteSearch(rmvnorm, 'fun').
  Regarding, How would I go about getting the entire variance-covariance
 matrix?, this is really easy:  Just define a 5 x 4 matrix A so the
 5-dimensional 'opt' you want is a constant plus A times the 4-dimensional
 restricted 'opt'.  [Please don't use the same name for two different things
 like 'opt' in your function below.  Half a century ago, when Fortran was
 young, that was very smart programming.  Today, it's primary effect it to
 make it difficult for mere mortals to understand your code.  Use something
 like 'opt5' for one and 'opt4' for the other.]
  Then

  Sig5 = A %*% vcov.nlminb(opt) %*% t(A).
  I believe the A matrix you want is as follows:
  A = matrix(NA, dim=c(5, 4))
  A[1:4, 1:4] - diag(4)
  A[5, ] - (-1)

  However, since your example was not self contained, I have not tested
 this.   Hope this helps. Spencer


  John Pitchard wrote:

 
 Hi Spencer,

 Sorry for not producing code as a worked example.


 Here's an example:
 ==
 # setting the seed number
 set.seed(0)
 # creating a correlation matrix
 corr - diag(5)
 corr[lower.tri(corr)] - 0.5
 corr[upper.tri(corr)] - 0.5

 # Data for the minimisation
 mat - rmvnorm(1, mean=c(3, -20, -10, 3, 2), sd=c(0.1, 15, 4,
 0.15, 0.8), cov=corr)

 obj.fun - function(opt, mat) {
   opt - c(opt, 1-sum(opt))
   LinearComb - mat%*%opt
   obj - -min(LinearComb)
   obj
 }

 opt - nlminb(rep(0,4), lower=rep(-3, 4), upper=rep(3, 4), obj.fun,
   
 mat=mat)
 
 opt.x - opt$parameters
 opt.x - c(opt.x, 1-sum(opt.x))

 # using vcov.nlminb from the MASS library to obtain the covariance matrix
 vcov.nlminb(opt)
 


 I have a variance-covariance matrix for 4 of the elements in the
 vector but not the last component. How would I go about getting the
 entire variance-covariance matrix?

 Thanks in advance for any help.

 Regards,
 John




 On 09/04/2008, Spencer Graves [EMAIL PROTECTED] wrote:


   
Have you considered optimizing over x1 = x[1:(length(x)-1]?   You
 
 could feed a wrapper function 'f2(x1, ...)' that computes xFull = c(x1,
 1-sum(x1)) and feeds that to your 'fn'.
 
If this makes sense, great.  Else, if my answer is not useful, be so
 
 kind as to PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html and provide
 commented, minimal, self-contained, reproducible code.
 
Spencer

 John Pitchard wrote:



 
  Dear All,

 I wanted to post some more details about the query I sent to s-news
   
 last
 
 week.

 I have a vector with a constraint. The constraint is that the sum of
   
 the
 
 vector must add up to 1 - but not necessarily positive, i.e.

 x[n] - 1 -(x[1] + ...+x[n-1])

 I perform the optimisation on the vector x such that

 x - c(x, 1-sum(x))

 In other words,

 fn - function(x){
  x - c(x, 1 - sum(x))
  # other calculations here
 }

 then feed this into nlminb()

 out - nlminb(x, fn)
 out.x - out$parameters
 out.x - c(out.x, 1 - sum(out.x))
 out.x

 I would like to calculate standard errors for each of the components
   
 of x.
 
 Is this possible by outputing the Hessian matrix? Furthermore, how
   
 would I
 
 calculate this for the last component (if this is indeed possible)
   
 which has
 
 the restriction (i.e. 1-sum(out.x))?

 Any help would be much appreciated.

 Regards,
 John

   [[alternative HTML version deleted]]

 

Re: [R] nonlinear curve fitting on a torus

2008-04-13 Thread Spencer Graves
  Having seen no reply to this, I will offer a couple of comments 
that may or may not be useful.  Googling for geodesic equation on a 
torus produced interesting hits, but RSiteSearch(geodesic equation on 
a torus) found nothing.  RSiteSearch(torus) returned 33 hits, some of 
which referred to a package geozoo. 

  If you want a solution of a differential equation, you might 
consider lsoda {odesolve}.  The 'fda' package may also be useful. 

  To say more, I'd prefer to hear more specifics from you.  PLEASE 
do read the posting guide http://www.R-project.org/posting-guide.html; 
and provide commented, minimal, self-contained, reproducible code.  
Doing so can make it much easier for people to understand what you 
want.  If you provide code that doesn't quite work, someone who is 
interested can copy it from your email into R and try things, possibly 
generating a solution to your problem.  Without a self-contained 
example, you restrict the pool of possible respondents to people who 
have actually worked with a geodesic equation on a torus -- or to 
fools like me who are willing to expose their ignorance commenting on 
something we know essentially nothing about. 

  Hope this helps. 
  Spencer Graves

Sungsu wrote:
   Dear R users.

   I have data observed on the surface of a torus, and
   am trying to fit the nonlinear regression using

   the geodesic equation on a torus. Could anyone give
   me a helpful advise on this problem? I would
   definitely appreicate your reply.

 Sincerely,
  
  SUNGSU KIM

   [[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] Assigning to multiple variables

2008-04-13 Thread Scott Romans
If we have a function that returns 2 or more values (such as dim as  
applied to a matrix), can we assign these 2 or more values to an equal  
number of differently named variables in one line? For example, is  
there any way to do something like this:

[NumberRows NumberColumns] - dim(MatrixA)

Thanks in advance!

Scott

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


[R] R equivalent of erfcinv in matlab

2008-04-13 Thread sun
I am converting some matlab code into R that use inverse of the 
complementary error function, erfcinv and did not find an equivalent in 
R, is there such a function in some contributed modules?

Thanks.

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


Re: [R] Assigning to multiple variables

2008-04-13 Thread Gabor Grothendieck
Normally in R one returns a list and assigns that to a single
variable but if you really want to do it here is how:

http://tolstoy.newcastle.edu.au/R/help/04/06/1430.html

On Sun, Apr 13, 2008 at 4:56 PM, Scott Romans [EMAIL PROTECTED] wrote:
 If we have a function that returns 2 or more values (such as dim as
 applied to a matrix), can we assign these 2 or more values to an equal
 number of differently named variables in one line? For example, is
 there any way to do something like this:

 [NumberRows NumberColumns] - dim(MatrixA)

 Thanks in advance!

 Scott

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] [Fwd: Re: Assigning to multiple variables]

2008-04-13 Thread Tom Backer Johnsen
Scott Romans wrote:
 If we have a function that returns 2 or more values (such as dim as  
 applied to a matrix), can we assign these 2 or more values to an equal  
 number of differently named variables in one line? For example, is  
 there any way to do something like this:
 
 [NumberRows NumberColumns] - dim(MatrixA)

In that case R returns an object (a vector) with two values where the
first is the number of rows and the second is the number of columns.
Almost everything in R are objects.

So:

 d - dim(attitude)
 rows - d[1]
 rows
[1] 30


Tom

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] [Fwd: Re: Response to R across the university]

2008-04-13 Thread Tom Backer Johnsen
Well, I downloaded the install JGR package for Windows and that seemed
to work fine, after the installation I ended up with a modified R window
which looked nice and uncluttered.  Which I like.  Very much.

On the other hand, I cannot see how to launch the thing again once I
have closed that window.  There is supposed to be a launcher somewhere
(JGR.exe?), but I have not been able to find it.  It does not seem to be
part of the installation, nor have I been able to locate it at the JGR site.

However, there might be a possible problem on my side, at the moment I
am working with a setup for Windows from the local IT department here in
Bergen which behaves very strangely (I am going to pull the plug on on
that one very soon), but there might possibly be a problem elsewhere.
Would it be possible for someone to check?

Tom

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


Re: [R] R equivalent of erfcinv in matlab

2008-04-13 Thread Peter Dalgaard
sun wrote:
 I am converting some matlab code into R that use inverse of the 
 complementary error function, erfcinv and did not find an equivalent in 
 R, is there such a function in some contributed modules?

   
Basically, it is qnorm() with suitable scaling. The help page for Normal 
has the construction for erfc() from pnorm()  so just solve erfc(x) = y 
for x.

-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

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

2008-04-13 Thread Jorge Ivan Velez
Hi Udo,

Perhaps

 merge(treat,control)

does what you need.

I hope this helps,

Jorge


On Sun, Apr 13, 2008 at 2:41 PM, Udo [EMAIL PROTECTED] wrote:

 Hi,
 I have a frame treat and want to find matched pairs in the data frame
 control. In the matched (combined) data frame there should be two
 variables (0/1),indicating the source of the data (treat or control),
 so that it is possibe to set a filter (extraxt/select data).

 #Here are the dataframes (my real data frames have many variables)
 treat - data.frame(age=c(1,1,2,2,2,4),
school=c(10,10,20,20,20,11),
out1=c(9.5,2.3,3.3,4.1,5.9,4.6))
 control - data.frame(age=c(1,1,1,1,3,2),
  school=c(10,10,10,10,33,20),
  out2=c(1.1,2,3.5,4.9,5.2,6.5))
 print(treat)
 print(control)

 matched.data.frame - ?? #Match treat control by age school


 #My SPSS syntax would be similar to this:
 MATCH FILES FILE=treat /IN=fromtreat
  /FILE=control /IN=fromcontrol
  /BY age school.
 SELECT IF fromdad AND fromfam. #select data, set filter

 The /IN= option creates a 0/1 variable that indicates the
 source of the data

 The resultand matched data frame should have
 the following structure:
 age   schoolout1out2  fromtreat fromcontrol
 1   10  9.5 1.1 1   1
 1   10  2.3 2.0 1   1
 
 4   11  4.6 NA  1   0
 3   33  NA  5.2 0   1
 

 I tried which and match, but I failed and was unlucky looking
 at the help/archive. Merge doesn´t do the job, because it makes
 all possible matches.


 Thank´s for any help!
 Udo


 
 Udo KN G
  Ö I

 Clinic for Child an Adolescent Psychiatry
 Philipps University of Marburg / Germany

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Calinsky and Harabasz Index for Cluster Determination with Diana in R

2008-04-13 Thread ozgun.harmanci
Hello all,
I have a set of data points, which I have pair distances for. I
managed to create dendrogram for this data set using diana() in R,
however this only gives me the tree and not the clusters themselves. I
am trying to determine clusters using Calinsky and Harabasz Index (CH
Index). I, however, cannot find how to accomplish this using R. Is
there anyone who could help me with this? I searched R documentation
for implementation of CH index and found some things but not the
clustering. Thanks a bunch.

Sincerely,
Arif.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Mapping file-Legend- from 2 Files/Tables

2008-04-13 Thread Edwin Sendjaja
Hello,


Because no one has answered this. I presume that no one knows the soluition.




Fortunately, I found the solution:

Keyword: merge()
--
table1-read.table(Salesman.data)
table2-read.table(Employee.data)

data-merge(table1, table2, by.x=User_ID, by.y=User_ID)  


result-data$Name (for example)

Thank you.



Kind Regards,


Edwin Sendjaja 

Am Samstag, 12. April 2008 19:40:03 schrieb Edwin Sendjaja:
 Does anyone know how to solve this. I am so desperate.

 I'd be terribly grateful for any help.

 Am Samstag, 12. April 2008 05:19:16 schrieb Edwin Sendjaja:
  Hello,
 
  I have got 2  Tables from different files:
 
  Table 1 (lets say file: Salesman.data)
  
 
| ID  | User_ID
 
  ---
  1| 1   |   4
  2| 2   |   6
  3| 3   |   7
  4| 4   |   2
  5| 5   |   3
 
 
  
  Table2 (file: Employee.data)
  --
 
| User_ID  | Name
 
  --
  1|   1  |   Donna
  2|   2  |   John
  3|   3  |   Michael
  4|   4  |   Wolf
  5|   5  |   Tim
  6|   6  |   Edward
  7|   7  |   Shaun
 
 
 
  What i want do is:
 
 
  I want to map the table 2 into table 1.
  instead of User_ID I want to use the name of the person which is related
  to the User_ID.
 
 
 
  The legend should look like this
 
   _
 
   |LEGEND   |
   |-|
   |   -2- John   |
   |   -3- Michael  |
   |   -4- Wolf   |
   |   -6-Edward|
   |   -7-   Shaun  |
 
--
 
 
  Does anyone know how I can create such a mapping legend?
  Is there any good command to do this?
 
  I've tried using replace but this is not a good solution. because it
  replaces only 1 values.
 
 
  Kind Regards,
 
  Edwin Sendjaja
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/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] R equivalent of erfcinv in matlab

2008-04-13 Thread sun
Peter Dalgaard wrote:
 sun wrote:
 I am converting some matlab code into R that use inverse of the 
 complementary error function, erfcinv and did not find an equivalent in 
 R, is there such a function in some contributed modules?

   
 Basically, it is qnorm() with suitable scaling. The help page for Normal 
 has the construction for erfc() from pnorm()  so just solve erfc(x) = y 
 for x.
 
Thanks for your quick answer and useful information!
But please forgive my ignorance, I do not really know how to solve this 
inverse function actually.
for example,

 erfc - function(x) 2 * pnorm(x * sqrt(2), lower = FALSE)
  erfc(0.3)
[1] 0.6713732

How do I find 0.3  given 0.6713732?

Thanks!

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


Re: [R] R equivalent of erfcinv in matlab

2008-04-13 Thread Bill.Venables
At a guess ...

 erfc - function(x) 2 * pnorm(x * sqrt(2), lower = FALSE)
 erfcinv - function(x) qnorm(x/2, lower = FALSE)/sqrt(2)
 erfc(0.3)
[1] 0.6713732
 erfcinv(erfc(0.3))
[1] 0.3
 

It may not hurt to include these wrappers in R for matlab refugees.
They seem to be coming thick and fast these days.


Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary):  +61 7 3826 7304
Mobile: +61 4 8819 4402
Home Phone: +61 7 3286 7700
mailto:[EMAIL PROTECTED]
http://www.cmis.csiro.au/bill.venables/ 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of sun
Sent: Monday, 14 April 2008 8:50 AM
To: [EMAIL PROTECTED]
Subject: Re: [R] R equivalent of erfcinv in matlab

Peter Dalgaard wrote:
 sun wrote:
 I am converting some matlab code into R that use inverse of the 
 complementary error function, erfcinv and did not find an equivalent
in 
 R, is there such a function in some contributed modules?

   
 Basically, it is qnorm() with suitable scaling. The help page for
Normal 
 has the construction for erfc() from pnorm()  so just solve erfc(x) =
y 
 for x.
 
Thanks for your quick answer and useful information!
But please forgive my ignorance, I do not really know how to solve this 
inverse function actually.
for example,

 erfc - function(x) 2 * pnorm(x * sqrt(2), lower = FALSE)
  erfc(0.3)
[1] 0.6713732

How do I find 0.3  given 0.6713732?

Thanks!

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] [Fwd: Re: Response to R across the university]

2008-04-13 Thread Liviu Andronic
On Sun, Apr 13, 2008 at 11:36 PM, Tom Backer Johnsen
[EMAIL PROTECTED] wrote:
  On the other hand, I cannot see how to launch the thing again once I
  have closed that window.  There is supposed to be a launcher somewhere
  (JGR.exe?), but I have not been able to find it.  It does not seem to be
  part of the installation, nor have I been able to locate it at the JGR site.

To the best of my knowledge, there is no JGR.exe.
JGR needs loaded like any R library, via library(). You can set R to
automatically load JGR at the beginning of a new session. Simply add
library(JGR)
JGR()

to the Rprofile.site. If missing, create the file within your
installation ./etc directory.

Regards,
Liviu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] [Fwd: Re: Response to R across the university]

2008-04-13 Thread Jim Porzak
Tom,

Yes, just re-execute JGR-15.exe (I assume your are on windows  downloaded
the latest version). Window's explorer search should find it.

For convenience, I make a shortcut on my desktop pointing to JGR-xxx.exe.

BTW, I do most of my development work in JGR. Thanks to all the Augsburg JGR
team!!!

On Sun, Apr 13, 2008 at 2:36 PM, Tom Backer Johnsen [EMAIL PROTECTED]
wrote:

 Well, I downloaded the install JGR package for Windows and that seemed
 to work fine, after the installation I ended up with a modified R window
 which looked nice and uncluttered.  Which I like.  Very much.

 On the other hand, I cannot see how to launch the thing again once I
 have closed that window.  There is supposed to be a launcher somewhere
 (JGR.exe?), but I have not been able to find it.  It does not seem to be
 part of the installation, nor have I been able to locate it at the JGR
 site.

 However, there might be a possible problem on my side, at the moment I
 am working with a setup for Windows from the local IT department here in
 Bergen which behaves very strangely (I am going to pull the plug on on
 that one very soon), but there might possibly be a problem elsewhere.
 Would it be possible for someone to check?

 Tom

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




-- 
HTH,
Jim Porzak
Responsys, Inc.
San Francisco, CA
http://www.linkedin.com/in/jimporzak

[[alternative HTML version deleted]]

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


Re: [R] R equivalent of erfcinv in matlab

2008-04-13 Thread sun
[EMAIL PROTECTED] wrote:
 At a guess ...
 
 erfc - function(x) 2 * pnorm(x * sqrt(2), lower = FALSE)
 erfcinv - function(x) qnorm(x/2, lower = FALSE)/sqrt(2)
 erfc(0.3)
 [1] 0.6713732
 erfcinv(erfc(0.3))
 [1] 0.3
 
 It may not hurt to include these wrappers in R for matlab refugees.
 They seem to be coming thick and fast these days.
 
 
 Bill Venables
 CSIRO Laboratories
 PO Box 120, Cleveland, 4163
 AUSTRALIA
 Office Phone (email preferred): +61 7 3826 7251
 Fax (if absolutely necessary):  +61 7 3826 7304
 Mobile: +61 4 8819 4402
 Home Phone: +61 7 3286 7700
 mailto:[EMAIL PROTECTED]
 http://www.cmis.csiro.au/bill.venables/ 

Thanks very much indeed. This solved my problem.  I think it will be 
very helpful to have these wrapper functions at least in some extra 
packages for the ease of people migrating.

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


Re: [R] R equivalent of erfcinv in matlab

2008-04-13 Thread Ben Bolker
 Bill.Venables at csiro.au writes:

 
 At a guess ...
 
  erfc - function(x) 2 * pnorm(x * sqrt(2), lower = FALSE)
  erfcinv - function(x) qnorm(x/2, lower = FALSE)/sqrt(2)
  erfc(0.3)
 [1] 0.6713732
  erfcinv(erfc(0.3))
 [1] 0.3
  
 
 It may not hurt to include these wrappers in R for matlab refugees.
 They seem to be coming thick and fast these days.
 

  There's a page on the wiki about matlab to R (actually
I think it's titled Octave to R -- this could go on
there whether or not it gets into base R.
I would put it on myself, right now, but the wiki
appears to be down?

 ping wiki.r-project.org
PING econum.umh.ac.be (193.190.194.5) 56(84) bytes of data.

  Ben Bolker

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


Re: [R] SQL INSERT using RMySQL

2008-04-13 Thread Gregory Warnes

Hi All,

I figured out my problem.  There was a combination of lack of  
understanding on my part, and a bit of missing functionality.  I made  
a small patch to the rmysqlWriteTable() function passes the field  
names to MySQL corresponding to the data columns passed in:

diff -ru RMySQL.orig/R/MySQLSupport.R RMySQL/R/MySQLSupport.R
--- RMySQL.orig/R/MySQLSupport.R2007-05-31 22:36:02.0 -0400
+++ RMySQL/R/MySQLSupport.R 2008-04-11 17:50:29.0 -0400
@@ -616,7 +616,9 @@
 on.exit(unlink(fn), add = TRUE)
 sql4 - paste(LOAD DATA LOCAL INFILE ', fn, ',
 INTO TABLE , name,
-   LINES TERMINATED BY '\n' , sep=)
+   LINES TERMINATED BY '\n' ,
+   ( , paste(names(field.types), collapse=, ),  
);,
+ sep=)
 rs - try(dbSendQuery(new.con, sql4))
 if(inherits(rs, ErrorClass)){
warning(could not load data into table)

I also defined a useful function for describing the structure of an  
existing table:


setGeneric(
dbDescribeTable,
function(conn, name, ...)
  standardGeneric(dbDescribeTable),
valueClass = character
)


setMethod(
   dbDescribeTable,
   signature(conn=MySQLConnection, name=character),
   def = function(conn, name, ...){
 rs - dbGetQuery(conn, paste(describe, name))
 fields - rs$Type
 names(fields) - rs$Field
 if(length(fields)==0)
   fields - character()
 fields
   },
   valueClass = character
   )

And I now have working code:

  ## Columns in the table
  dbDescribeTable(con, past_purchases)
 idcustomer_id   item_upc
int(10) unsigned  int(11)   bigint(12)
  suggested   quantity  total
   tinyint(1)  int(11)  int(11)
on_sale   actual_price   featured
   tinyint(1)   double   tinyint(1)
   date
 date
 
  ## columns in my data (note the absence of the primary key 'id')
  head(fulldata)
   customer_iditem_upc suggested quantity total on_sale
1   3 632 FALSE1 1   FALSE
2   3 733 FALSE1 1   FALSE
3   3 1116095 FALSE1 1   FALSE
4   3 1117164 FALSE1 1   FALSE
5   3 1117210 FALSE1 1   FALSE
6   3 1119092 FALSE1 1   FALSE
   actual_price featured   date
110.49FALSE 2008-03-22
2 4.99FALSE 2008-03-22
3 5.49FALSE 2008-03-22
4 9.99FALSE 2008-03-22
5 4.19FALSE 2008-03-22
6 3.99FALSE 2008-03-22
 
  dim(fulldata)
[1] 75  9
 
 
  ## Size of the table before adding my data
  dbGetQuery(con, SELECT COUNT(ID) FROM past_purchases)[1,1]
[1] 675
 
  ## Insert the data
  dbWriteTable(
+  con,
+  past_purchases,
+  value=fulldata,
+  overwrite=FALSE,
+  append=TRUE,
+  row.names=FALSE #,
+  #field.types=field.types
+  )
[1] TRUE
 
  ## Size of the table after adding my data
  dbGetQuery(con, SELECT COUNT(ID) FROM past_purchases)[1,1]
[1] 750

-Greg



On Apr 11, 2008, at 10:57PM , Chris Stubben wrote:

 Greg,

 If you have a MySQL table with an auto_increment field, you could just
 insert a NULL value into that column and the database will  
 increment the key
 (it may not work in SQL STRICT mode, I'm not sure).  I don't think  
 there's
 any way to specify which columns you want to load data into using
 dbWriteTable yet, but that would be a nice feature since LOAD data now
 allows that (and SET syntax and other options).

 Try this code below - I used cbind(NA, x) to insert a null into the  
 first
 column.

 Chris

 dbSendQuery(con, create table tmp (id int not null auto_increment  
 primary
 key, a char(1), b char(1)))
 MySQLResult:(369,1,67)
 x-data.frame( a=letters[1:3], b=letters[4:6])
 x
   a b
 1 a d
 2 b e
 3 c f
 dbWriteTable(con, tmp, cbind(NA, x), row.name=FALSE, append=TRUE)
 [1] TRUE
 dbWriteTable(con, tmp, cbind(NA, x), row.name=FALSE, append=TRUE)
 [1] TRUE
 dbReadTable(con, tmp)
   id a b
 1  1 a d
 2  2 b e
 3  3 c f
 4  4 a d
 5  5 b e
 6  6 c f





 Gregory. R. Warnes wrote:

 Hi All,

 I've finally gotten around to database access using R.  I'm happily
 extracting rows from a MySQL database using RMySQL, but am having
 problems appending rows to an existing table.

 What I *want* to do is to append rows to the table, allowing the
 database to automatically generate primary key values.  I've only
 managed to add rows by using

  dbWriteTable( con, past_purchases, newRecords, overwrite=FALSE,
 append=TRUE, ...)

 And this only appears to properly append rows (as opposed to
 overwriting them) IFF
 

Re: [R] prediction intervals from a mixed-effects models?

2008-04-13 Thread Gregory Warnes

On Apr 13, 2008, at 1:41PM , Dieter Menne wrote:
 Spencer Graves spencer.graves at pdf.com writes:


   How can I get prediction intervals from a mixed-effects model?
 Consider the following example:

 library(nlme)
 fm3 - lme(distance ~ age*Sex, data = Orthodont, random = ~ 1)
 df3.1 - with(Orthodont, data.frame(age=seq(5, 20, 5),
 Subject=rep(Subject[1], 4),
 Sex=rep(Sex[1], 4)))
 predict(fm3, df3.1, interval='prediction')
 #  M01  M01  M01  M01
 # 22.69012 26.61199 30.53387 34.45574

 # NOTE:  The 'interval' argument to the 'predict' function was  
 ignored.
 # It works works for an 'lm' object, but not an 'lme' object.


 In theory, ci from gmodels should work

 library(gmodels)
 ci(df3.1)


 However, I get an error message. I will forward this to Greg to let  
 him check if
 I did something stupid.

gmodels::ci() will give confidence intervals for the fixed effects via

ci(fm3)

ci() won't generate prediction intervals for individual parameters,  
and according to

?predict.lme

it won't either.

-Greg




 Dieter

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

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


Re: [R] R equivalent of erfcinv in matlab

2008-04-13 Thread Bill.Venables
That's not a bad idea.  If the wiki comes up again, please do it.

They are so short I wonder that they just can't go in to base R though.
It's not particularly matlab terminology, it's engineering and physics
terminology pretty widely.  See, e.g. Abramowitz and Stegun.

For specifcity, here are the four I would suggest.

erf - function (x) 2 * pnorm(x * sqrt(2)) - 1
erfc - function (x) 2 * pnorm(x * sqrt(2), lower = FALSE)
erfinv - function (x) qnorm((1 + x)/2)/sqrt(2)
erfcinv - function (x) qnorm(x/2, lower = FALSE)/sqrt(2) 

But I don't feel strongly enough about it to push it on R-devel myself
right now.  
I always forget the connexion and it seems to come up when you least
expect it.  I've just added them to my little horde of useful stuff, so
I'm OK now!

Bill.


Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary):  +61 7 3826 7304
Mobile: +61 4 8819 4402
Home Phone: +61 7 3286 7700
mailto:[EMAIL PROTECTED]
http://www.cmis.csiro.au/bill.venables/ 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Ben Bolker
Sent: Monday, 14 April 2008 11:00 AM
To: [EMAIL PROTECTED]
Subject: Re: [R] R equivalent of erfcinv in matlab

 Bill.Venables at csiro.au writes:

 
 At a guess ...
 
  erfc - function(x) 2 * pnorm(x * sqrt(2), lower = FALSE)
  erfcinv - function(x) qnorm(x/2, lower = FALSE)/sqrt(2)
  erfc(0.3)
 [1] 0.6713732
  erfcinv(erfc(0.3))
 [1] 0.3
  
 
 It may not hurt to include these wrappers in R for matlab refugees.
 They seem to be coming thick and fast these days.
 

  There's a page on the wiki about matlab to R (actually
I think it's titled Octave to R -- this could go on
there whether or not it gets into base R.
I would put it on myself, right now, but the wiki
appears to be down?

 ping wiki.r-project.org
PING econum.umh.ac.be (193.190.194.5) 56(84) bytes of data.

  Ben Bolker

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Equivalent to a BY command in SAS

2008-04-13 Thread zerfetzen

Hi,
I'm very new to R and absolutely love it.  Does anyone know how to use
something in R that functions like a BY command in SAS?

For example, let's say you have a variable x, and you want to see the mean. 
Easy...

 mean(x)

But what if you want to see the mean of x conditional on another discrete
variable?  My best attempts so far are something like...

 mean(x, y_cat=1)

...which of course doesn't work.  I have downloaded plenty of R user guides
that are very informative, but am not seeing much on detailed descriptives
or data manipulation (for my life, I can't figure out how to sort an
attached data frame, but that's another issue).  Thanks.
-- 
View this message in context: 
http://www.nabble.com/Equivalent-to-a-BY-command-in-SAS-tp16670452p16670452.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] Equivalent to a BY command in SAS

2008-04-13 Thread Dylan Beaudette
On Sun, Apr 13, 2008 at 7:36 PM, zerfetzen [EMAIL PROTECTED] wrote:

  Hi,
  I'm very new to R and absolutely love it.  Does anyone know how to use
  something in R that functions like a BY command in SAS?

  For example, let's say you have a variable x, and you want to see the mean.
  Easy...

   mean(x)

  But what if you want to see the mean of x conditional on another discrete
  variable?  My best attempts so far are something like...

Using the built-in dataset 'CO2' :

# compute the mean 'conc' for every level of 'Plant'
tapply(CO2$conc, CO2$Plant, FUN=mean)

Qn1 Qn2 Qn3 Qc1 Qc3 Qc2 Mn3 Mn2 Mn1 Mc2 Mc3 Mc1
435 435 435 435 435 435 435 435 435 435 435 435

?tapply for details
?by for more details


Dylan


   mean(x, y_cat=1)

  ...which of course doesn't work.  I have downloaded plenty of R user guides
  that are very informative, but am not seeing much on detailed descriptives
  or data manipulation (for my life, I can't figure out how to sort an
  attached data frame, but that's another issue).  Thanks.
  --
  View this message in context: 
 http://www.nabble.com/Equivalent-to-a-BY-command-in-SAS-tp16670452p16670452.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] Equivalent to a BY command in SAS

2008-04-13 Thread Vincent Goulet
Le dim. 13 avr. à 22:36, zerfetzen a écrit :

 Hi,
 I'm very new to R and absolutely love it.  Does anyone know how to use
 something in R that functions like a BY command in SAS?

 For example, let's say you have a variable x, and you want to see  
 the mean.
 Easy...

 mean(x)

 But what if you want to see the mean of x conditional on another  
 discrete
 variable?  My best attempts so far are something like...

 mean(x, y_cat=1)

 ...which of course doesn't work.  I have downloaded plenty of R user  
 guides
 that are very informative, but am not seeing much on detailed  
 descriptives
 or data manipulation (for my life, I can't figure out how to sort an
 attached data frame, but that's another issue).  Thanks.

You didn't give much detail about what exactly you want to do (have a  
look at the Posting Guide), but... perhaps by() will do what you what.  
See ?by .

Bye!

---
   Vincent Goulet, Associate Professor
   École d'actuariat
   Université Laval, Québec
   [EMAIL PROTECTED]   http://vgoulet.act.ulaval.ca

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

2008-04-13 Thread Roslina Zakaria
Hi R-users,

I would like to do looping for this process below to estimate alpha beta from 
gamma distribution:
Here are my data:
day_data1 - 
123456 789   10   11   12   13   14  15 
  16   17   18   19   20   21   22   23
1943 48.3 18.5  0.0  0.0 18.3  0.0   0.0  0.0  0.0  0.0  0.0  0.0  2.0  0.0 0.0 
 0.0  0.0  0.0  0.0  0.0  0.0  0.8  2.8
1944  0.0  0.0  0.0  0.0  0.0  0.0   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0 0.0 
 0.0  6.6  0.0  0.0  0.0  0.0  0.0  0.0
1945  5.3  0.0  0.0  0.0  0.0  2.5   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0 0.0 
 0.0  5.3  0.0  0.0  0.0  0.0  0.0  0.0
1946  0.0  0.0  0.0  0.0  0.0  2.3   0.0  0.0  0.0  0.0  4.8  0.3  1.5  0.0 0.8 
 0.0  0.0  5.8 70.6 12.4  0.5 23.6  0.0
1947  0.0  0.0  0.0  0.0  0.0  0.0   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0 0.0 
 2.0  0.0  0.0  0.0  2.8  0.0  0.0  0.0
1948  0.3 20.1  0.0  0.0  0.0  0.0   0.0  0.0  0.0  0.0  1.5  0.5  0.0  0.0 0.0 
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0

## To extract all the positive values
x1 - day_data1[,1]  
x2 - day_data1[,2]
x3 - day_data1[,3]
x4 - day_data1[,4]
x5 - day_data1[,5]
tol - 1E-6  
a1 - x1[x1tol]
a2 - x2[x2tol]
a3 - x3[x3tol]
a4 - x4[x4tol]
a5 - x5[x5tol]

library(MASS)
## Example January Charleville 1943-2007
fitdistr(a1,dgamma, list(shape = 1, rate = 0.1), lower = 0.01)
fitdistr(a2,dgamma, list(shape = 1, rate = 0.1), lower = 0.01)
fitdistr(a3,dgamma, list(shape = 1, rate = 0.1), lower = 0.01)
fitdistr(a4,dgamma, list(shape = 1, rate = 0.1), lower = 0.01)
fitdistr(a5,dgamma, list(shape = 1, rate = 0.1), lower = 0.01)

Here is my code: 

alpha.beta - function(data,n)
{  tol - 1E-6
  { for (i in 1:n)
xi - data[,i]
ai - xi [xi  tol]
fit - fitdistr(ai,dgamma, list(shape = 1, rate = 0.1), lower = 0.01)
  }
  fit
}

I’m not sure what went wrong since it gives only one output by right 31 outputs.
Thank you for your attention. 

__
t spam protection around 
http://mail.yahoo.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] Equivalent to a BY command in SAS

2008-04-13 Thread Rolf Turner

On 14/04/2008, at 2:36 PM, zerfetzen wrote:


 Hi,
 I'm very new to R and absolutely love it.  Does anyone know how to use
 something in R that functions like a BY command in SAS?

 For example, let's say you have a variable x, and you want to see  
 the mean.
 Easy...

 mean(x)

 But what if you want to see the mean of x conditional on another  
 discrete
 variable?  My best attempts so far are something like...

 mean(x, y_cat=1)

 ...which of course doesn't work.  I have downloaded plenty of R  
 user guides
 that are very informative, but am not seeing much on detailed  
 descriptives
 or data manipulation (for my life, I can't figure out how to sort an
 attached data frame, but that's another issue).  Thanks.

  set.seed(42)
  x - rnorm(100)
  y - sample(letters[1:3],100,TRUE)
  by(x,y,mean)
INDICES: a
[1] 0.1089523

INDICES: b
[1] -0.2253035

INDICES: c
[1] 0.2997985

Or:

   tapply(x,y,mean)
  a  b  c
  0.1089523 -0.2253035  0.2997985

cheers,

Rolf Turner


##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

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