[R] Incompleteness (or bug ?) in mAr.est for VAR estimation

2008-03-24 Thread Megh Dal
Hi all,
   
  I feel there is a incompleteness in mAr.est function in mAr package for VAR 
estimation. I does not cheak whether there is multicolinearity in data set. 
Here I used mAr.est function for following dataset :
   
   head(log(data1)
+ )
V1   V2   V3   V4   V5   V6
1 2.859340 3.909620 3.913622 3.913622 3.954699 3.699572
2 2.865624 3.910021 3.901569 3.901569 3.931433 3.708437
3 2.876949 3.912023 3.908617 3.908617 3.943134 3.708437
4 2.873000 3.909620 3.897518 3.897518 3.921973 3.716981
5 2.856470 3.912623 3.875981 3.875981 3.901569 3.716981
6 2.857619 3.915617 3.856087 3.856087 3.884241 3.716981

  clearly V3 and V4 are same. However it gives VAR estimate without any problem 
whereas EViews notified about this problem. 

   
-

[[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] Inverse t-distribution(TINV function in Excel)

2008-03-24 Thread Berend Hasselman


Felipe Carrillo wrote:
 
 
 I can't actually tell which function in R is the
 equivalent to TINV function in Excel.
 Anyone familiar with that function? Thanks
 
 

help.search(t distribution)

I think the quantile function is what you are looking for:  qt
Try

qt(pt(5,10),10)

Berend
-- 
View this message in context: 
http://www.nabble.com/Inverse-t-distribution-tp16243933p16246200.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] What is the correct model formula for the results of piecewise linear function?

2008-03-24 Thread zhijie zhang
Dear friends,
  I used the B-spline (degree=1) method to fit the piecewise linear function
and the results are listed below.

m.glm-glm(mark~x+poly(elevation,2)+bs(distance,degree=1,knots=c(16.13,24))
+bs(y,degree=1,knots=c(-0.4357,-0.3202
)),family=binomial(logit),data=point)
summary(m.glm)

Coefficients:
  Estimate Std. Error z
value Pr(|z|)
(Intercept) 12.104  3.138
3.857 0.000115 ***
x   5.815  1.987
2.926 0.003433 **
poly(elevation, 2)1 6.654  4.457
1.493 0.135444
poly(elevation, 2)2 -6.755  3.441  -
1.963 0.049645 *
bs(distance, degree = 1, knots = c(16.13, 24))1 -1.291  1.139  -
1.133 0.257220
bs(distance, degree = 1, knots = c(16.13, 24))2 -10.348  2.025
-5.110 3.22e-07 ***
bs(distance, degree = 1, knots = c(16.13, 24))3 -3.530  3.752  -
0.941 0.346850
bs(y, degree = 1, knots = c(-0.4357, -0.3202))1 -6.828  1.836  -
3.719 0.000200 ***
bs(y, degree = 1, knots = c(-0.4357, -0.3202))2 -4.426  1.614  -
2.742 0.006105 **
bs(y, degree = 1, knots = c(-0.4357, -0.3202))3-11.216  2.861  -
3.920 8.86e-05 ***
 I think bs(degree=1) has fitted the piecewise linear functions. Now i hope
to write the model formua for the above results, but not very sure about how
to write the correct results for *distance* and *y,* because they have three
parts .
 Logitp=12.104 + 5.815*x + 6.654*elevation - 6.755*elevation^2
   -1.291*distance1 - 10.348*distance2 - 3.53*distance3
  -6.828*y1 - 4.426*y2 - 11.216*y3
 In the above formula, distance1-3 denotes the three linear functions
for*distance
*, my problem is how to replace distace1-3 using original variable *distance
*? The same question is for *y*.
  Could anybody please show me the correct model formula according to the
above result?
 Thanks a lot.


-- 
With Kind Regards,
Zhi Jie

[[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] Question about as.numeric with tclvalue

2008-03-24 Thread Prof Brian Ripley
It's not clear what is going on here, but one possibility is

 as.numeric(pi)
[1] NA
Warning message:
NAs introduced by coercion

OTOH, Inf works for me.

The difference is that 'Inf' is a standard C99 value (like 1.23), whereas 
'pi' is a variable in R.  So if you want to allow expressions you need to 
parse and eval them, something like

inp - pi
assign(a, eval(parse(text=inp)), .GlobalEnv)

As ever, please see the message footer and remember to supply a 
reproducible example.


On Sun, 23 Mar 2008, Erin Hodgess wrote:

 Dear R People:

 I have an interactive menu via an Rcmdr extension package which asks
 for lower and upper limit to evaluate.

 Typically, I use:

 assign(a,as.numeric(tclvalue(lowlim)),envir=.GlobalEnv)

 and that's fine.

 However, if I try to use pi or Inf or -Inf, I get either coerced NAs or NaN.

 Does anyone have any suggestions, please?

 Thanks,
 Erin
 PS Happy Easter if you celebrate Easter.


 --
 Erin Hodgess
 Associate Professor
 Department of Computer and Mathematical Sciences
 University of Houston - Downtown
 mailto: [EMAIL PROTECTED]

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

2008-03-24 Thread Thomas Steiner
Hi,
on 
http://cran.at.r-project.org/bin/windows/base/rw-FAQ.html#Where-can-I-find-the-latest-version_003f
it says:
... The current release is distributed as an installer
`R-2.6.1-win32.exe' of about 30Mb. ...
however I find this file as well:
http://cran.at.r-project.org/bin/windows/base/R-2.6.2-win32.exe
I guess that in the FAQ it should read as 2.6.2
Have a nice holiday,
Thomas

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

2008-03-24 Thread Thomas Steiner
Dear all,

thank you very much for continuing to look into this issue!
I checked the versions and in Gabor's code the spaces and tabs, but
still the problem remains (see code and error below).

To install quantmod, I used this time Rforge and it did not work. I
had to install the Defaults package from cran first by hand (ie not
like zoo and xts where it recognizes the dependence). And to get the
most recent version of the package I had to upgrade R as well (my
mistake of course). The link mentioned by Jeff points to 0.3.4, but I
got by the command
install.packages(quantmod,repos=http://R-Forge.R-project.org;) the
version 0.3.3 as you see below.

 Lines - '17-03-2008 00:00:001,57641,57661,57471,5750
+ 17-03-2008 00:05:001,57491,57501,57411,5744
+ 17-03-2008 00:10:001,57451,57621,57411,5749'
 DF - read.delim2(textConnection(Lines))
 library(quantmod)
Lade nötiges Paket: Defaults
quantmod: Quantitative Financial Modelling Framework

Version 0.3-3
http://www.quantmod.com

Warning message:
ungenutzte Verbindung 3 (Lines) geschlossen
 z - read.zoo(textConnection(Lines), # replace with myfile.dat
+header = F, sep = \t, dec = ,,
+format = %d-%m-%Y %H:%M:%S, tz = )
Fehler in read.zoo(textConnection(Lines), header = F, sep = \t, dec = ,,  :
  index contains NAs
 q - as.quantmod.OHLC(z, col.names = c(Open, High, Low, Close))
Fehler in ncol(x) : objekt z nicht gefunden
 chartSeries(q)
Fehler in UseMethod(as.xts) : keine anwendbare Methode für as.xts

 sessionInfo()
R version 2.6.2 (2008-02-08)
i386-pc-mingw32

locale:
LC_COLLATE=German_Austria.1252;LC_CTYPE=German_Austria.1252;LC_MONETARY=German_Austria.1252;LC_NUMERIC=C;LC_TIME=German_Austria.1252

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

other attached packages:
[1] quantmod_0.3-3 Defaults_1.1-1 xts_0.0-11 zoo_1.4-2

loaded via a namespace (and not attached):
[1] grid_2.6.2 lattice_0.17-4 tools_2.6.2



Anyway, after the upgarde and Jeff's hint to use the chartSeries
function it works. Now I still have to play around to make the labels
look nice...

Thanks a lot for all your help,
Thomas

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

2008-03-24 Thread Tribo Laboy
Hi,

I am moving from MATLAB, where one can easily assign a number of
output values from a function like this:

[x,y] = myfun(a,b)

Then variables x and y can be directly used in the caller workspace.

I understand that R functions return a single argument, which could be
a list. This in a way makes it possible to return multiple values with
a single function call, but accessing the list variables is a little
bit awkward.

mylist -myfun(a,b) {
  return(list(x = a, y = b))
 }

x = mylist$x; y = mylist$y

I found some discussion going back to 2004. Is there anything new to
add to what was said at the time?

http://thread.gmane.org/gmane.comp.lang.r.general/21223/focus=21226
http://thread.gmane.org/gmane.comp.lang.r.general/42875/focus=42876

While at it, somewhere in the Introduction to R, I think, I read
that use of return is considered a bad practice. Why is that? I
thought making clear what is returned by the function is a positive
thing...

Regards,

TL

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

2008-03-24 Thread cgenolin
Hi Martin

I am re reading all the mail we exchange with new eyes because of all 
the thing I learn in the past few weeks. That very interesting and some 
new question occurs...

***
Once, you speak about callGeneric :

setClass(A, representation(x=numeric))
setClass(C, contains=c(A))

setMethod(show, A, function(object) cat(A\n))
setMethod(show, C, function(object) {
   callGeneric(as(object, A))
   cat(C\n)
})

new(C)

Considere the following definition (that you more or less teach me with 
your yesterday remarques...) :

setMethod(show, C, function(object) {
   callNextMethod()
   cat(C\n)
})

In this case, is there any difference between the former and the latter ?
Which one would you use ?

(I get that in more complicate case, for example if
setClass(C, contains=c(A,B)), it might be more complicate to use 
the latter, right ?)




*
This works :

setMethod(initialize,B,
  function(.Object,..., yValue){
  callNextMethod(.Object, ..., y=yValue)
  return(.Object)
  })
new(B,yValue=3)

but this does not :

setMethod(initialize,B,
  function(.Object, yValue){
  callNextMethod(.Object, y=yValue)
  return(.Object)
  })
new(B,yValue=3)

Why ?
Is there any help page about ... ?


**
showMethods gives the list of all the method. Is there a way to see all 
the method for a specific signature IN THE ORDER they will be call by 
callNextMethod ?
If ANY - D - E, a method that will gives :

Function initialize:
.Object = E
.Object = D
.Object = ANY

Thanks for your help
And happy easter eggs !

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] update win FAQ q1?

2008-03-24 Thread Prof Brian Ripley
On Mon, 24 Mar 2008, Thomas Steiner wrote:

 Hi,
 on 
 http://cran.at.r-project.org/bin/windows/base/rw-FAQ.html#Where-can-I-find-the-latest-version_003f
 it says:
 ... The current release is distributed as an installer
 `R-2.6.1-win32.exe' of about 30Mb. ...
 however I find this file as well:
 http://cran.at.r-project.org/bin/windows/base/R-2.6.2-win32.exe
 I guess that in the FAQ it should read as 2.6.2

It does in the copy which comes with R 2.6.2!  That page says, right at 
the top

R for Windows FAQ
Version for R-2.6.1

However, http://cran.at.r-project.org/bin/windows/ told you where to 
report this (it was not R-help, and never is for the content of CRAN).

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


Re: [R] Great difference for piecewise linear function between R and SAS

2008-03-24 Thread Duncan Murdoch
On 24/03/2008 5:23 AM, zhijie zhang wrote:
 Dear Rusers,
   I am now using  R and SAS to fit the piecewise linear functions, and what
 surprised me is that they have a great differrent result. See below.

You're using different bases.  Compare the predictions, not the 
coefficients.

To see the bases that R uses, do this:

matplot(distance, bs(distance,degree=1,knots=c(16.13,24)))
matplot(y, bs(y,degree=1,knots=c(-0.4357,-0.3202)))

Duncan Murdoch

 #R code--Knots for distance are 16.13 and 24, respectively, and Knots for y
 are -0.4357 and -0.3202
 m.glm-glm(mark~x+poly(elevation,2)+bs(distance,degree=1,knots=c(16.13,24))
 +bs(y,degree=1,knots=c(-0.4357,-0.3202
 )),family=binomial(logit),data=point)
 summary(m.glm)
 
 Coefficients:
   Estimate Std. Error z
 value Pr(|z|)
 (Intercept) 12.104  3.138
 3.857 0.000115 ***
 x   5.815  1.987
 2.926 0.003433 **
 poly(elevation, 2)1 6.654  4.457
 1.493 0.135444
 poly(elevation, 2)2 -6.755  3.441  -
 1.963 0.049645 *
 bs(distance, degree = 1, knots = c(16.13, 24))1 -1.291  1.139  -
 1.133 0.257220
 bs(distance, degree = 1, knots = c(16.13, 24))2-10.348  2.025  -
 5.110 3.22e-07 ***
 bs(distance, degree = 1, knots = c(16.13, 24))3-3.530  3.752  -
 0.941 0.346850
 bs(y, degree = 1, knots = c(-0.4357, -0.3202))1-6.828  1.836  -
 3.719 0.000200 ***
 bs(y, degree = 1, knots = c(-0.4357, -0.3202))2-4.426  1.614  -
 2.742 0.006105 **
 bs(y, degree = 1, knots = c(-0.4357, -0.3202))3-11.216  2.861  -
 3.920 8.86e-05 ***
 
 #SAS codes
 data b;
  set a;
  if distance  16.13 then d1=1; else d1=0;
  distance2=d1*(distance - 16.13);
  if distance  24 then d2=1; else d2=0;
  distance3=d2*(distance - 24);
  if y-0.4357 then dd1=1; else dd1=0;
  y2=dd1*(y+0.4357);
  if y-0.3202 then dd2=1; else dd2=0;
  y3=dd2*(y+0.3202);
 run;
 
 proc logistic descending data=b;
  model mark =x elevation elevation*elevation distance distance2 distance3 y
 y2 y3;
 run;
 
 
   The LOGISTIC Procedure  Analysis of Maximum Likelihood
 Estimates
 
  Standard  Wald
Parameter   DFEstimate   Error
 Chi-SquarePr  ChiSq
 
Intercept1 -2.6148  2.1445
 1.4867
 0.2227
x1  5.8146  1.9872
 8.5615
 0.0034
elevation1  0.4457  0.1506
 8.7545
 0.0031
elevation*elevation  1 -0.0279  0.0142
 3.8533
 0.0496
distance 1 -0.1091  0.0963
 1.2836
 0.2572
distance21 -1.0418  0.2668
 15.2424
 .0001
distance31  2.8633  0.7555
 14.3625
 0.0002
y1-16.2032  4.3568
 13.8314
 0.0002
y2   1 36.9974 10.3219
 12.8476
 0.0003
y3   1-58.4938 14.0279
 17.3875
 .0001
 Q: What is the problem? which one is correct for the piecewise linear
 function?
   Thanks very much.
 


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

2008-03-24 Thread Duncan Murdoch
On 24/03/2008 5:09 AM, Tribo Laboy wrote:
 Hi,
 
 I am moving from MATLAB, where one can easily assign a number of
 output values from a function like this:
 
 [x,y] = myfun(a,b)
 
 Then variables x and y can be directly used in the caller workspace.
 
 I understand that R functions return a single argument, which could be
 a list. This in a way makes it possible to return multiple values with
 a single function call, but accessing the list variables is a little
 bit awkward.
 
 mylist -myfun(a,b) {
   return(list(x = a, y = b))
  }
 
 x = mylist$x; y = mylist$y
 
 I found some discussion going back to 2004. Is there anything new to
 add to what was said at the time?
 
 http://thread.gmane.org/gmane.comp.lang.r.general/21223/focus=21226
 http://thread.gmane.org/gmane.comp.lang.r.general/42875/focus=42876

I don't think so.

 While at it, somewhere in the Introduction to R, I think, I read
 that use of return is considered a bad practice. Why is that? I
 thought making clear what is returned by the function is a positive
 thing...

Where did you see that? It would be good advice if it said not to hide 
many calls to return() deep within a long function.  I'd be neutral 
about it if it said not to bother with return() in a very short 
function.  In intermediate cases, I think using return() is good practice.

Duncan Murdoch

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


Re: [R] (no subject)

2008-03-24 Thread Jim Lemon
Donna Tucker wrote:
 Is there any way to use more than one color or shape in the same plot.  I 
 would like to make the points different colors for various levels of a 
 variable.  I have tried a simple 'if' statement in the plot command, but I 
 get an error message.  Here is what I have tried and the error message I get: 
  plot(test, if(test[,1]8) col=steelblue2 else col=wheat2)Error in 
 xy.coords(x, y, xlabel, ylabel, log) :   'x' and 'y' lengths differIn 
 addition: Warning message:In if (test[, 1]  8) col = steelblue2 else col = 
 wheat2 :  the condition has length  1 and only the first element will be 
 usedI know 'x' and 'y' lenghths do NOT differ.  If I just do plot(test), it 
 works perfectly.  Is there any way to this?Thanks,Donna

Hi Donna,
What is happening is that you have passed two arguments to plot 
without naming them. The first one (test) is interpreted as the x 
coordinates, and the second one:

if(test[,1]8) col=steelblue2 else col=wheat2

finishes up as steelblue2 if test[1,1] is less than 8 or wheat2 if 
not. This is interpreted as the y coordinates. Unless you have only 
one element in test (and of course we can infer that you have more), 
those lengths will differ. What you can do is to specify that your 
second argument is meant to be a color vector like this:

plot(test,col=ifelse(test[,1]8,steelblue,wheat2))

Now of course I am assuming that test is a matrix or data frame with 
at least two columns. If it isn't, the above example will fall over and 
whinge.

  How well do you know your celebrity gossip?

I'm sorry, but I can't help you at all with that.

Jim

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


Re: [R] little subplot in corner

2008-03-24 Thread Thomas Steiner
Henrique,

Although your solution is perfect, I had later a problem with setting
the background. Perhaps you know how to get this as well:

set.seed(24032008)
plot(rnorm(10),type=l,col=red)
grid()
front=c(0.5, .97, 0.5, .97)
par(fig=front, new=T)#, bg=skyblue does not work
rec=c(par(usr)[1]+(par(usr)[2]-par(usr)[1])*front[1],
par(usr)[3]+(par(usr)[4]-par(usr)[3])*front[3],
par(usr)[1]+(par(usr)[2]-par(usr)[1])*front[3],
par(usr)[1]+(par(usr)[2]-par(usr)[1])*front[4])
#rect(rec[1],rec[2],rec[3],rec[4],col=yellow)
plot(rnorm(4),type=l,col=blue,xlab=,ylab=)

as you can see it would be good to be able to set the background of
the subfigure. as the par(bg=) does not work, I tried to plot a
rectangle. Just uncomment the send-last line and you will see that the
original plot disappears after some strange rectangle is drawn.

If you have any idea again, it would be evry much appreaciated to let me know.
Thomas

PS: to see my first attempts, look at
http://commons.wikimedia.org/wiki/Image:Eurusd-id.png

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Great difference for piecewise linear function between R and SAS

2008-03-24 Thread zhijie zhang
Dear Murdoch,
   Compare the predictions, not the coefficients., this is the key point.
   I have checked their predicted probability and their results are the
same.
  What do you mean by  You're using different bases? Could you please give
me a little more info on it, so that i can go to find some materials?
  Thanks a lot.


On 3/24/08, Duncan Murdoch [EMAIL PROTECTED] wrote:

 On 24/03/2008 5:23 AM, zhijie zhang wrote:
  Dear Rusers,
I am now using  R and SAS to fit the piecewise linear functions, and
 what
  surprised me is that they have a great differrent result. See below.

 You're using different bases.  Compare the predictions, not the
 coefficients.

 To see the bases that R uses, do this:

 matplot(distance, bs(distance,degree=1,knots=c(16.13,24)))
 matplot(y, bs(y,degree=1,knots=c(-0.4357,-0.3202)))

 Duncan Murdoch

  #R code--Knots for distance are 16.13 and 24, respectively, and Knots
 for y
  are -0.4357 and -0.3202
  m.glm-glm(mark~x+poly(elevation,2)+bs(distance,degree=1,knots=c(16.13
 ,24))
  +bs(y,degree=1,knots=c(-0.4357,-0.3202
  )),family=binomial(logit),data=point)
  summary(m.glm)
 
  Coefficients:
Estimate Std.
 Error z
  value Pr(|z|)
  (Intercept) 12.104
 3.138
  3.857 0.000115 ***
  x   5.815  1.987
  2.926 0.003433 **
  poly(elevation, 2)1 6.654  4.457
  1.493 0.135444
  poly(elevation, 2)2 -6.755
 3.441  -
  1.963 0.049645 *
  bs(distance, degree = 1, knots = c(16.13, 24))1 -1.291
 1.139  -
  1.133 0.257220
  bs(distance, degree = 1, knots = c(16.13, 24))2-10.348
 2.025  -
  5.110 3.22e-07 ***
  bs(distance, degree = 1, knots = c(16.13, 24))3-3.530  3.752
   -
  0.941 0.346850
  bs(y, degree = 1, knots = c(-0.4357, -0.3202))1-6.828  1.836
   -
  3.719 0.000200 ***
  bs(y, degree = 1, knots = c(-0.4357, -0.3202))2-4.426  1.614
   -
  2.742 0.006105 **
  bs(y, degree = 1, knots = c(-0.4357, -0.3202))3-11.216
 2.861  -
  3.920 8.86e-05 ***
 
  #SAS codes
  data b;
   set a;
   if distance  16.13 then d1=1; else d1=0;
   distance2=d1*(distance - 16.13);
   if distance  24 then d2=1; else d2=0;
   distance3=d2*(distance - 24);
   if y-0.4357 then dd1=1; else dd1=0;
   y2=dd1*(y+0.4357);
   if y-0.3202 then dd2=1; else dd2=0;
   y3=dd2*(y+0.3202);
  run;
 
  proc logistic descending data=b;
   model mark =x elevation elevation*elevation distance distance2
 distance3 y
  y2 y3;
  run;
 
 
The LOGISTIC Procedure  Analysis of Maximum Likelihood
  Estimates
 

   Standard  Wald
 Parameter   DFEstimate   Error
  Chi-SquarePr  ChiSq
 
 Intercept1 -2.6148  2.1445
  1.4867
  0.2227
 x1  5.8146  1.9872
  8.5615
  0.0034
 elevation1  0.4457  0.1506
  8.7545
  0.0031
 elevation*elevation  1 -0.0279  0.0142
  3.8533
  0.0496
 distance 1 -0.1091  0.0963
  1.2836
  0.2572
 distance21 -1.0418  0.2668
  15.2424
  .0001
 distance31  2.8633  0.7555
  14.3625
  0.0002
 y1-16.2032  4.3568
  13.8314
  0.0002
 y2   1 36.9974 10.3219
  12.8476
  0.0003
 y3   1-58.4938 14.0279
  17.3875
  .0001
  Q: What is the problem? which one is correct for the piecewise linear
  function?
Thanks very much.
 
 




-- 
With Kind Regards,

oooO:
(..):
:\.(:::Oooo::
::\_)::(..)::
:::)./:::
::(_/
:
[***]
Zhi Jie,Zhang ,PHD
Tel:+86-21-54237149
Dept. of Epidemiology,School of Public Health,Fudan University
Address:No. 138 Yi Xue Yuan Road,Shanghai,China
Postcode:200032
Email:[EMAIL PROTECTED]
Website: www.statABC.com
[***]
oooO:
(..):
:\.(:::Oooo::
::\_)::(..)::
:::)./:::
::(_/
:

[[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] Inverse t-distribution

2008-03-24 Thread Alberto Monteiro

Bert Gunter wrote:

 Yes. And, amazingly, one can find out about it by typing
 
 help.search(t distribution) .
 
 Why don't you try it for yourself?
 
Maybe because the obvious search is

help.search(t)

:-)

Alberto Monteiro

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

2008-03-24 Thread Gabor Grothendieck
You need zoo 1.5-0 and you are using 1.4-2.  Also note that
the DF - line is not needed (though it doesn't hurt either)
and was just there to check your similar statement.

On Mon, Mar 24, 2008 at 4:48 AM, Thomas Steiner [EMAIL PROTECTED] wrote:
 Dear all,

 thank you very much for continuing to look into this issue!
 I checked the versions and in Gabor's code the spaces and tabs, but
 still the problem remains (see code and error below).

 To install quantmod, I used this time Rforge and it did not work. I
 had to install the Defaults package from cran first by hand (ie not
 like zoo and xts where it recognizes the dependence). And to get the
 most recent version of the package I had to upgrade R as well (my
 mistake of course). The link mentioned by Jeff points to 0.3.4, but I
 got by the command
 install.packages(quantmod,repos=http://R-Forge.R-project.org;) the
 version 0.3.3 as you see below.

  Lines - '17-03-2008 00:00:001,57641,57661,57471,5750
 + 17-03-2008 00:05:001,57491,57501,57411,5744
 + 17-03-2008 00:10:001,57451,57621,57411,5749'
  DF - read.delim2(textConnection(Lines))
  library(quantmod)
 Lade nötiges Paket: Defaults
 quantmod: Quantitative Financial Modelling Framework

 Version 0.3-3
 http://www.quantmod.com

 Warning message:
 ungenutzte Verbindung 3 (Lines) geschlossen
  z - read.zoo(textConnection(Lines), # replace with myfile.dat
 +header = F, sep = \t, dec = ,,
 +format = %d-%m-%Y %H:%M:%S, tz = )
 Fehler in read.zoo(textConnection(Lines), header = F, sep = \t, dec = ,,  
 :
  index contains NAs
  q - as.quantmod.OHLC(z, col.names = c(Open, High, Low, Close))
 Fehler in ncol(x) : objekt z nicht gefunden
  chartSeries(q)
 Fehler in UseMethod(as.xts) : keine anwendbare Methode für as.xts
 
  sessionInfo()
 R version 2.6.2 (2008-02-08)
 i386-pc-mingw32

 locale:
 LC_COLLATE=German_Austria.1252;LC_CTYPE=German_Austria.1252;LC_MONETARY=German_Austria.1252;LC_NUMERIC=C;LC_TIME=German_Austria.1252

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

 other attached packages:
 [1] quantmod_0.3-3 Defaults_1.1-1 xts_0.0-11 zoo_1.4-2

 loaded via a namespace (and not attached):
 [1] grid_2.6.2 lattice_0.17-4 tools_2.6.2
 


 Anyway, after the upgarde and Jeff's hint to use the chartSeries
 function it works. Now I still have to play around to make the labels
 look nice...

 Thanks a lot for all your help,
 Thomas


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Great difference for piecewise linear function between R and SAS

2008-03-24 Thread Duncan Murdoch
On 24/03/2008 7:06 AM, zhijie zhang wrote:
 Dear Murdoch,
Compare the predictions, not the coefficients., this is the key point.
I have checked their predicted probability and their results are the
 same.
   What do you mean by  You're using different bases? Could you please give
 me a little more info on it, so that i can go to find some materials?

There are many ways to represent a piecewise linear function.  R and 
your SAS code have both chosen linear combinations of basis functions, 
but you have used different basis functions.  R uses the B-spline basis. 
You have what is sometimes called the truncated power basis, but maybe 
not commonly in the linear context.  I don't know if it has a name here.

Duncan Murdoch

   Thanks a lot.
 
 
 On 3/24/08, Duncan Murdoch [EMAIL PROTECTED] wrote:
 On 24/03/2008 5:23 AM, zhijie zhang wrote:
 Dear Rusers,
   I am now using  R and SAS to fit the piecewise linear functions, and
 what
 surprised me is that they have a great differrent result. See below.
 You're using different bases.  Compare the predictions, not the
 coefficients.

 To see the bases that R uses, do this:

 matplot(distance, bs(distance,degree=1,knots=c(16.13,24)))
 matplot(y, bs(y,degree=1,knots=c(-0.4357,-0.3202)))

 Duncan Murdoch

 #R code--Knots for distance are 16.13 and 24, respectively, and Knots
 for y
 are -0.4357 and -0.3202
 m.glm-glm(mark~x+poly(elevation,2)+bs(distance,degree=1,knots=c(16.13
 ,24))
 +bs(y,degree=1,knots=c(-0.4357,-0.3202
 )),family=binomial(logit),data=point)
 summary(m.glm)

 Coefficients:
   Estimate Std.
 Error z
 value Pr(|z|)
 (Intercept) 12.104
 3.138
 3.857 0.000115 ***
 x   5.815  1.987
 2.926 0.003433 **
 poly(elevation, 2)1 6.654  4.457
 1.493 0.135444
 poly(elevation, 2)2 -6.755
 3.441  -
 1.963 0.049645 *
 bs(distance, degree = 1, knots = c(16.13, 24))1 -1.291
 1.139  -
 1.133 0.257220
 bs(distance, degree = 1, knots = c(16.13, 24))2-10.348
 2.025  -
 5.110 3.22e-07 ***
 bs(distance, degree = 1, knots = c(16.13, 24))3-3.530  3.752
   -
 0.941 0.346850
 bs(y, degree = 1, knots = c(-0.4357, -0.3202))1-6.828  1.836
   -
 3.719 0.000200 ***
 bs(y, degree = 1, knots = c(-0.4357, -0.3202))2-4.426  1.614
   -
 2.742 0.006105 **
 bs(y, degree = 1, knots = c(-0.4357, -0.3202))3-11.216
 2.861  -
 3.920 8.86e-05 ***

 #SAS codes
 data b;
  set a;
  if distance  16.13 then d1=1; else d1=0;
  distance2=d1*(distance - 16.13);
  if distance  24 then d2=1; else d2=0;
  distance3=d2*(distance - 24);
  if y-0.4357 then dd1=1; else dd1=0;
  y2=dd1*(y+0.4357);
  if y-0.3202 then dd2=1; else dd2=0;
  y3=dd2*(y+0.3202);
 run;

 proc logistic descending data=b;
  model mark =x elevation elevation*elevation distance distance2
 distance3 y
 y2 y3;
 run;


   The LOGISTIC Procedure  Analysis of Maximum Likelihood
 Estimates

  Standard  Wald
Parameter   DFEstimate   Error
 Chi-SquarePr  ChiSq

Intercept1 -2.6148  2.1445
 1.4867
 0.2227
x1  5.8146  1.9872
 8.5615
 0.0034
elevation1  0.4457  0.1506
 8.7545
 0.0031
elevation*elevation  1 -0.0279  0.0142
 3.8533
 0.0496
distance 1 -0.1091  0.0963
 1.2836
 0.2572
distance21 -1.0418  0.2668
 15.2424
 .0001
distance31  2.8633  0.7555
 14.3625
 0.0002
y1-16.2032  4.3568
 13.8314
 0.0002
y2   1 36.9974 10.3219
 12.8476
 0.0003
y3   1-58.4938 14.0279
 17.3875
 .0001
 Q: What is the problem? which one is correct for the piecewise linear
 function?
   Thanks very much.



 


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Great difference for piecewise linear function between R and SAS

2008-03-24 Thread Duncan Murdoch
On 3/24/2008 9:03 AM, zhijie zhang wrote:
 Dear  Murdoch,
   Thanks very much for your rapid response. It helps me greatly.
   If i want to write the model formula according to the estimets from 
 R,  Is it correct for the below formula? I'm not very sure about it, and 
 i also hope that you can recommend a good book on this area. I want to 
 learn it systematically. Thanks a million.
 Logit/p/=12.10+5.815*x+6.654*elevation-6.755*elevation^2
   -1.291*distance_1 -10.348*distance2-3.53*distance3
   _ -6.828*_y1 _ -4.426*_y2 _ -11.216*_y3 _

I would use predict() instead.  What you have there doesn't look as
though it uses the B-spline basis.

The reference given in the ?bs help page is a reasonable starting point,
but just about any book that covers splines should handle the B-spline
basis and the linear case.

Duncan Murdoch

  #R code and the estimate results--Knots for distance are 16.13 and 24, 
 respectively, and Knots for y are -0.4357 and -0.3202
 m.glm-glm(mark~x+poly(elevation,2)+bs(distance,degree=1,knots=c(16.13,24))
 
 +bs(y,degree=1,knots=c(-0.4357,-0.3202)),family=binomial(logit),data=point)
 summary(m.glm)
 
   Estimate Std. 
 Error z value Pr(|z|)
 (Intercept) 12.104  
 3.138   3.857 0.000115 ***
 x   5.815  
 1.987   2.926 0.003433 **
 poly(elevation, 2)1 6.654  
 4.457   1.493 0.135444
 poly(elevation, 2)2 -6.755  
 3.441  -1.963 0.049645 *
 bs(distance, degree = 1, knots = c(16.13, 24))1 -1.291  
 1.139  -1.133 0.257220
 bs(distance, degree = 1, knots = c(16.13, 24))2-10.348  
 2.025  -5.110 3.22e-07 ***
 bs(distance, degree = 1, knots = c(16.13, 24))3-3.530  
 3.752  -0.941 0.346850
 bs(y, degree = 1, knots = c(-0.4357, -0.3202))1-6.828  
 1.836  -3.719 0.000200 ***
 bs(y, degree = 1, knots = c(-0.4357, -0.3202))2-4.426  
 1.614  -2.742 0.006105 **
 bs(y, degree = 1, knots = c(-0.4357, -0.3202))3-11.216  
 2.861  -3.920 8.86e-05 ***
 
   Thanks again.
 
 
 
 On Mon, Mar 24, 2008 at 8:08 PM, Duncan Murdoch [EMAIL PROTECTED] 
 mailto:[EMAIL PROTECTED] wrote:
 
 On 24/03/2008 7:06 AM, zhijie zhang wrote:
   Dear Murdoch,
  Compare the predictions, not the coefficients., this is the
 key point.
  I have checked their predicted probability and their results
 are the
   same.
 What do you mean by  You're using different bases? Could you
 please give
   me a little more info on it, so that i can go to find some materials?
 
 There are many ways to represent a piecewise linear function.  R and
 your SAS code have both chosen linear combinations of basis functions,
 but you have used different basis functions.  R uses the B-spline basis.
 You have what is sometimes called the truncated power basis, but maybe
 not commonly in the linear context.  I don't know if it has a name here.
 
 Duncan Murdoch
 
 Thanks a lot.
  
  
   On 3/24/08, Duncan Murdoch [EMAIL PROTECTED]
 mailto:[EMAIL PROTECTED] wrote:
   On 24/03/2008 5:23 AM, zhijie zhang wrote:
   Dear Rusers,
 I am now using  R and SAS to fit the piecewise linear
 functions, and
   what
   surprised me is that they have a great differrent result. See
 below.
   You're using different bases.  Compare the predictions, not the
   coefficients.
  
   To see the bases that R uses, do this:
  
   matplot(distance, bs(distance,degree=1,knots=c(16.13,24)))
   matplot(y, bs(y,degree=1,knots=c(-0.4357,-0.3202)))
  
   Duncan Murdoch
  
   #R code--Knots for distance are 16.13 and 24, respectively, and
 Knots
   for y
   are -0.4357 and -0.3202
  
 m.glm-glm(mark~x+poly(elevation,2)+bs(distance,degree=1,knots=c(16.13
   ,24))
   +bs(y,degree=1,knots=c(-0.4357,-0.3202
   )),family=binomial(logit),data=point)
   summary(m.glm)
  
   Coefficients:
 Estimate Std.
   Error z
   value Pr(|z|)
   (Intercept) 12.104
   3.138
   3.857 0.000115 ***
   x   5.815  
1.987
   2.926 0.003433 **
   poly(elevation, 2)1 6.654  
4.457
   1.493 0.135444
   poly(elevation, 2)2 -6.755
   3.441  -
   1.963 0.049645 *
   bs(distance, degree = 1, knots = c(16.13, 24))1 -1.291
   1.139  -
   1.133 0.257220
   bs(distance, degree = 1, knots = c(16.13, 24))2-10.348
   2.025  -
   

[R] ARCH(1,0) with t-residuals

2008-03-24 Thread Elena M.
Dear R users,

I need to estimate an ARCH(1,0) model with t-residuals. To do this I use 
garchFit 
function from fGarch library. However, I get the following error message:
Error in.garchInitParameters (formula.mean = formula.mean, formula.var = 
formula.var, ): object alpha not found
I tried to estimate this model with different series, but I always get this 
error message.
For example,

data(EuStockMarkets)  
dax - diff(log(EuStockMarkets))[,DAX]
g=garchFit(formula=~garch(0,1),data=dax,cond.dist=dstd,include.mean=FALSE)

Series Initialization:
 ARMA model:arma
 Formula mean:  ~ arma(0, 0)
 GARCH model:   garch
 Formula var:   ~ garch(0, 1)
 ARMA Order:0 0
 Max ARMA Order:0
 GARCH Order:   0 1
 Max GARCH Order:   1
 Maximum Order: 1
 h.start:   2
 llh.start: 1
 Length of Series:  1859
 Recursion Init:mci
 Series Scale:  0.01030084

Error in .garchInitParameters(formula.mean = formula.mean, formula.var = 
formula.var,  : 
  object alpha not found

If I use GARCH(0,1) model I get the following error message:

g=garchFit(formula=~garch(0,1),data=dax,cond.dist=dstd,include.mean=FALSE)
Series Initialization:
 ARMA model:arma
 Formula mean:  ~ arma(0, 0)
 GARCH model:   garch
 Formula var:   ~ garch(1, 0)
 ARMA Order:0 0
 Max ARMA Order:0
 GARCH Order:   1 0
 Max GARCH Order:   1
 Maximum Order: 1
 h.start:   2
 llh.start: 1
 Length of Series:  1859
 Recursion Init:mci
 Series Scale:  0.01030084

Error in sum(beta) : invalid 'type' (closure) of argument

Do fGarch function allow to estimate GARCH(p,q) with p and q 0 only? Are there 
any other functions in order to estimate ARCH(1,0) with
t-residuals?
Thank you.

Regards,
Elena

Advertisement:

Lietuviams reikia saugios pasto dezutes.
Dideles ir saugios.
INBOX.LT - 10 GB nemokamas pastas!

[[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] vlookup in R

2008-03-24 Thread Sachin J
Hi,

Is there are function similar to excel vlookup in R. Please let me know.

Thanks,
Sachin


  



[[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] vlookup in R

2008-03-24 Thread Henrique Dallazuanna
I think that merge is what you want:

set.seed(24032008)
x - data.frame(ID=sample(10), Value=rnorm(10))
idx - sample(5)
merge(idx, x, by.x=1, by.y=1)

On 24/03/2008, Sachin J [EMAIL PROTECTED] wrote:
 Hi,

  Is there are function similar to excel vlookup in R. Please let me know.

  Thanks,
  Sachin


   
 


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



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

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

2008-03-24 Thread jim holtman
?findInterval

On 3/24/08, Sachin J [EMAIL PROTECTED] wrote:
 Hi,

 Is there are function similar to excel vlookup in R. Please let me know.

 Thanks,
 Sachin


  
 


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



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem 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.


Re: [R] [PS] vlookup in R

2008-03-24 Thread Ben Fairbank
Another way:

If x is a two column matrix, as suggested by Henrique D., 

   IDValue
1   7  0.000656733
2   6  0.201764789
3   1  0.671113391
4  10 -0.739727826
5   9 -1.111310154
6   5 -0.859455833
7   2 -1.408229877
8   8  0.993126295
9   3 -0.171906808
10  4 -0.140107677

And you are looking up the value corresponding to ID

 ID - 4

x[(1:dim(x)[1])[x[,1]==ID],2]

will also do it, and you can vary the value of the 2 in order to query
the column of interest, much as you can do with vlookup in the E
program.

Ben 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Sachin J
Sent: Monday, March 24, 2008 9:25 AM
To: r-help@r-project.org
Subject: [PS] [R] vlookup in R

Hi,

Is there are function similar to excel vlookup in R. Please let me know.

Thanks,
Sachin

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

2008-03-24 Thread David Winsemius
Sachin J [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 Is there are function similar to excel vlookup in R. Please let me
 know. 
 
Caveat: definition of VLOOKUP done from memory and by checking OO.o 
Calc function of same name. (Don't have Excel on this machine.)

VLOOKUP looks up a single value in the first column of an Excel range 
and returns a column value (offset by a given integer) from the first 
matching row in that range. The indexing functions (extract or 
[ ) can be used:

 df4
 V1 V2  V3
1  4.56  1 0.1
2  8.42  1 0.2
3  0.79  3 0.3
4  5.39  3 0.4
5  0.95  4 0.5
6  7.73  5 0.6
7  7.17  6 0.7
8  3.89  7 0.8
9  0.54 10 1.0
10 9.53  9 0.9

 df4[df4$V1==0.79,2]
[1] 3

vlookup - function(val, df, row){
   df[df[1] == val, row][1] }

 vlookup(0.79, df4, 2)
[1] 3

I thought there was an optional 4th argument to VLOOKUP that specifies 
the action to be taken if there is no exact match. You may need to 
change the equality in that function to an inequality and identify the 
first column value that is less than or equal to val. If I remember 
correctly, Excel assumes that the first column is ordered ascending.

-- 
David Winsemius

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

2008-03-24 Thread Ben Fairbank
Quite right, there is an optional 4th argument, and the table must be
sorted ascending on the first column in Excel.  Thus these functions
only approximately duplicate the Excel functions (improve on them IMHO).

BTW, I pasted the wrong formula in my reply; though it works, simpler is

ID - 4  #for example, find value corresponding to 4

x[x[,1]==ID,2]

Ben 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of David Winsemius
Sent: Monday, March 24, 2008 10:20 AM
To: [EMAIL PROTECTED]
Subject: [PS] Re: [R] vlookup in R

Sachin J [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 Is there are function similar to excel vlookup in R. Please let me
 know. 
 
Caveat: definition of VLOOKUP done from memory and by checking OO.o 
Calc function of same name. (Don't have Excel on this machine.)

VLOOKUP looks up a single value in the first column of an Excel range 
and returns a column value (offset by a given integer) from the first 
matching row in that range. The indexing functions (extract or 
[ ) can be used:

 df4
 V1 V2  V3
1  4.56  1 0.1
2  8.42  1 0.2
3  0.79  3 0.3
4  5.39  3 0.4
5  0.95  4 0.5
6  7.73  5 0.6
7  7.17  6 0.7
8  3.89  7 0.8
9  0.54 10 1.0
10 9.53  9 0.9

 df4[df4$V1==0.79,2]
[1] 3

vlookup - function(val, df, row){
   df[df[1] == val, row][1] }

 vlookup(0.79, df4, 2)
[1] 3

I thought there was an optional 4th argument to VLOOKUP that specifies 
the action to be taken if there is no exact match. You may need to 
change the equality in that function to an inequality and identify the 
first column value that is less than or equal to val. If I remember 
correctly, Excel assumes that the first column is ordered ascending.

-- 
David Winsemius

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

2008-03-24 Thread Martin Morgan
[EMAIL PROTECTED] wrote:
 Hi Martin
 
 I am re reading all the mail we exchange with new eyes because of all 
 the thing I learn in the past few weeks. That very interesting and some 
 new question occurs...
 
 ***
 Once, you speak about callGeneric :
 
 setClass(A, representation(x=numeric))
 setClass(C, contains=c(A))
 
 setMethod(show, A, function(object) cat(A\n))
 setMethod(show, C, function(object) {
   callGeneric(as(object, A))
   cat(C\n)
 })
 
 new(C)
 
 Considere the following definition (that you more or less teach me with 
 your yesterday remarques...) :
 
 setMethod(show, C, function(object) {
   callNextMethod()
   cat(C\n)
 })
 
 In this case, is there any difference between the former and the latter ?
 Which one would you use ?

callNextMethod is the right thing to do for this case. callGeneric is 
useful in a very specific case -- when dispatching from within a 
so-called 'group generic' function. But this is an advanced topic.

 (I get that in more complicate case, for example if
 setClass(C, contains=c(A,B)), it might be more complicate to use 
 the latter, right ?)

The right thing to do in this case is to sit down with the rules of 
method dispatch, and figure out what the 'next' method will be. A common 
alternative paradigm is to have a plain function (not visible to the 
user, e.g., not exported in a package name space) that several different 
methods all invoke, after mapping their arguments appropriately. The 
methods provide a kind of structured interface to the function, making 
sure arguments are of the appropriate type, etc. The function does the 
work, confident that the arguments are appropriate.


 *
 This works :
 
 setMethod(initialize,B,
  function(.Object,..., yValue){
  callNextMethod(.Object, ..., y=yValue)
  return(.Object)
  })
 new(B,yValue=3)
 
 but this does not :
 
 setMethod(initialize,B,
  function(.Object, yValue){
  callNextMethod(.Object, y=yValue)
  return(.Object)
  })
 new(B,yValue=3)
 
 Why ?
 Is there any help page about ... ?

Both 'work' in the sense that an object is returned (by the way, no need 
to use 'return' explicitly). And actually the examples on some of the 
man pages do not include '...', so this is really my opinion rather than 
the 'right' way to do things.

In an object-oriented sense, initialize,B-method should really just deal 
with it's own slots; it shouldn't have to 'know' about either classes 
that it extends (A) or classes that extend it. And it shouldn't do work 
that inherited methods (i.e., initialize,ANY-method) do. In the second 
form above, without the ..., there is no way for the initialize,A-method 
to see arguments that might be relevant to it (e.g., values to be used 
to initialize its slots). So initialize,B-method would have to do all 
the work of initializing A. This is not good design.


 **
 showMethods gives the list of all the method. Is there a way to see all 
 the method for a specific signature IN THE ORDER they will be call by 
 callNextMethod ?
 If ANY - D - E, a method that will gives :
 
 Function initialize:
 .Object = E
 .Object = D
 .Object = ANY

There is, but I have never been able to figure it out in detail or to 
feel confident that I was using functions that were meant to be used for 
this purpose by the user (as opposed to by the methods package).

John Chambers posted recently to the R-devel mailing list about changes 
to the internal representation of methods and classes.

https://stat.ethz.ch/pipermail/r-devel/2008-March/048729.html

I have not explored the new functions Dr. Chambers mentions; to use them 
requires the 'devel' version of R, not 2.6.2. Any questions they 
generate should definitely be addressed to the R-devel mailing list.

Best,

Martin

 Thanks for your help
 And happy easter eggs !
 
 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] vlookup in R

2008-03-24 Thread Sachin J
Hi Henrique,

This is what I am trying to accomplish:
I want to read values in V1 and V2 and populate the column V4 with R or B based 
on the
values in V3 i.e. if its A,B,C then its R else if D,F then B. You can assume 
V1, V2 are dataframe1
and V3, V4 are in dataframe2 (note V4 is empty initially i.e. its a new column).

 df1
V1V2
A R
BR
CR
DB
FB

 df2

V3V4
AR
CR
DB
FB
AR
CR
BR
BR
BR
BR
AR
DB



Thanks in advance for your help.



- Original Message 
From: Henrique Dallazuanna [EMAIL PROTECTED]
To: Sachin J [EMAIL PROTECTED]
Cc: r-help@r-project.org
Sent: Monday, March 24, 2008 10:41:52 AM
Subject: Re: [R] vlookup in R

I think that merge is what you want:

set.seed(24032008)
x - data.frame(ID=sample(10), Value=rnorm(10))
idx - sample(5)
merge(idx, x, by.x=1, by.y=1)

On 24/03/2008, Sachin J [EMAIL PROTECTED] wrote:
 Hi,

  Is there are function similar to excel vlookup in R. Please let me know.

  Thanks,
  Sachin


  
 


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



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


  



[[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 for the average or expected range?; CORECTION

2008-03-24 Thread Greg Snow
Well it looks like you found your answer.  Further the fact that my
suggestions of possibilities did not help and the fact that noone else
has chimed in would suggest that there is not any easier way to get your
answer.

 I was thinking that taking into account the correlation between the min
and the max may give different answers than your formula, but so far my
tests have not shown enough of a difference to matter.  If you use this
with a distribution rather than the normal, you may want to do a couple
of simulations just to check, but otherwise your formula seems to be
working fine.

Hope this helped,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

 -Original Message-
 From: Spencer Graves [mailto:[EMAIL PROTECTED] 
 Sent: Saturday, March 22, 2008 9:40 AM
 To: Greg Snow
 Cc: r-help@r-project.org
 Subject: Re: [R] function for the average or expected range?; 
 CORECTION
 
 Hi, Greg: 
 
   1.  I did the integration in Excel for four reasons:  
 First, it's easier (even for me) to see what's happening and 
 debug for something that simple.  Second, my audience were 
 people who were probably not R literate, and they could 
 likely understand and use the Excel file easier than than an 
 R script.  Third, my experience with the R 'integrate' has 
 been less than satisfactory, especially when integrating from 
 (-Inf) to Inf.  Finally, to check my work, I often program 
 things like that first in Excel then in R.  If I get the same 
 answer in both, I feel more confident in my R results.  I 
 haven't programmed this result in R yet, but if I do, the 
 fact that I already did it in Excel will make it easier for 
 me to be confident of the answers.  The function 
 getParamerFun{qAnalyst} gets the correct answer from n = 
 2:25 but returns wrong answers outside that range. 
 
 
   2.  I think the CORRECTION TO CORRECTION included a correct
 formula: 
 
E(R) = n*integral{-Inf to Inf of x*[(F(x))**(n-1) 
 - (1-F(x))**(n-1)]*dF(x).
 
   The CORRECTION omitted the x*.  The first version 
 had many more problems. 
 
   Am I communicating?  
   Best Wishes,
   Spencer
 
 Greg Snow wrote:
  Why do the integration in Excel instead of using the integrate 
  function in R?  The R function will allow integration from 
 -Inf to Inf.
   
  What was the correction to the formula?  The last one you showed 
  looked like the difference between the average min and average max, 
  but did not take into account the correlation between the 
 max and min 
  (going from memory, don't have my theory books handy). For 
 large n the 
  correlation is probably small enough that it makes a good 
 approximation.
 
  
 --
  --
  *From:* Spencer Graves [mailto:[EMAIL PROTECTED]
  *Sent:* Fri 3/21/2008 3:39 PM
  *To:* Greg Snow
  *Cc:* r-help@r-project.org
  *Subject:* Re: [R] function for the average or expected range?; 
  CORECTION
 
  Hi, Greg:
 
Thanks very much for the reply.
 
1.  The 'ptukey' and 'qtukey' function are the 
 distribution of 
  the studentized range, not the range.  I tried sum(ptukey(x, 2, 
  df=Inf, lower=FALSE))*.1 and got 1.179 vs. 1.128 in the standard 
  table of d2 for n = 2 observations per subgroup.
 
2.  I tried simulation and found that I needed 1e7 or 
 1e8 random 
  normal deviates to get the accuracy of the published table.
 
3.  Then I programmed in Excel the integral over 
 seq(-5, 5, .1) 
  using a correction to the formula I got from Kendall and Stuart and 
  got the exact numbers in the published table except in one 
 case where 
  it was off by 1 in the last significant digit.
 
Thanks again,
Spencer
 
  Greg Snow wrote:
   The ptukey and qtukey functions may be what you want (or at 
   least in the right direction).
  
   You could also easily estimate this by simulation.
  
   Hope this helps,
  

 
 

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

2008-03-24 Thread Henrik Bengtsson
# Setup the translation map
transMap - c(A=R, B=R, C=R, D=B, F=B);

# The input data
v3 - c(A, C, D, F, A, C, B, B, B, B, A, D);

# The translated data
v4 - transMap[v3];

df2 - data.frame(V3=v3, V4=v4);

I recommend you to read 'An Introduction to R' that comes with any R
installation.  There is a lot of useful stuff in there; it takes many
reads to grasp parts of it but it is worth it if you're going to use R
for more than, say, two weeks. You can find it via help.start().

/Henrik

On Mon, Mar 24, 2008 at 8:25 AM, Sachin J [EMAIL PROTECTED] wrote:
 Hi Henrique,

  This is what I am trying to accomplish:
  I want to read values in V1 and V2 and populate the column V4 with R or B 
 based on the
  values in V3 i.e. if its A,B,C then its R else if D,F then B. You can assume 
 V1, V2 are dataframe1
  and V3, V4 are in dataframe2 (note V4 is empty initially i.e. its a new 
 column).

   df1
  V1V2
  A R
  BR
  CR
  DB
  FB

   df2

  V3V4
  AR
  CR
  DB
  FB
  AR
  CR
  BR
  BR
  BR
  BR
  AR
  DB



  Thanks in advance for your help.




  - Original Message 
  From: Henrique Dallazuanna [EMAIL PROTECTED]
  To: Sachin J [EMAIL PROTECTED]
  Cc: r-help@r-project.org
  Sent: Monday, March 24, 2008 10:41:52 AM
  Subject: Re: [R] vlookup in R

  I think that merge is what you want:

  set.seed(24032008)
  x - data.frame(ID=sample(10), Value=rnorm(10))
  idx - sample(5)
  merge(idx, x, by.x=1, by.y=1)

  On 24/03/2008, Sachin J [EMAIL PROTECTED] wrote:
   Hi,

 
Is there are function similar to excel vlookup in R. Please let me know.
  

   Thanks,
Sachin
  
  

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



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


   
 


 [[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] vlookup in R

2008-03-24 Thread jim holtman
Is this what you want?

 control - data.frame(V1=c(A,B,C,D,F), V2=c(R,R,R,B,B))
 test - data.frame(V3=sample(c(A,B,C,D,F), 10, TRUE), v4='')
 test
   V3 v4
1   A
2   F
3   B
4   F
5   B
6   B
7   C
8   F
9   F
10  B
 test$V4 - control$V2[match(test$V3, control$V1)]
 test
   V3 v4 V4
1   A R
2   F B
3   B R
4   F B
5   B R
6   B R
7   C R
8   F B
9   F B
10  B R


On 3/24/08, Sachin J [EMAIL PROTECTED] wrote:
 Hi Henrique,

 This is what I am trying to accomplish:
 I want to read values in V1 and V2 and populate the column V4 with R or B 
 based on the
 values in V3 i.e. if its A,B,C then its R else if D,F then B. You can assume 
 V1, V2 are dataframe1
 and V3, V4 are in dataframe2 (note V4 is empty initially i.e. its a new 
 column).

  df1
 V1V2
 A R
 BR
 CR
 DB
 FB

  df2

 V3V4
 AR
 CR
 DB
 FB
 AR
 CR
 BR
 BR
 BR
 BR
 AR
 DB



 Thanks in advance for your help.



 - Original Message 
 From: Henrique Dallazuanna [EMAIL PROTECTED]
 To: Sachin J [EMAIL PROTECTED]
 Cc: r-help@r-project.org
 Sent: Monday, March 24, 2008 10:41:52 AM
 Subject: Re: [R] vlookup in R

 I think that merge is what you want:

 set.seed(24032008)
 x - data.frame(ID=sample(10), Value=rnorm(10))
 idx - sample(5)
 merge(idx, x, by.x=1, by.y=1)

 On 24/03/2008, Sachin J [EMAIL PROTECTED] wrote:
  Hi,
 
   Is there are function similar to excel vlookup in R. Please let me know.
 
   Thanks,
   Sachin
 
 
   
  
 
 
 [[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.
 


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


  
 


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




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem 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.


Re: [R] spreading out a numeric vector

2008-03-24 Thread Greg Snow
Levi,

Here is one possible function:

spread - function(x, mindiff) {
  df - x[-1] - x[-length(x)]
  i - 1
  while (any(df  mindiff)) {
x[c(df  mindiff, FALSE)] - x[c(df  mindiff, FALSE)] - mindiff/10
x[c(FALSE, df  mindiff)] - x[c(FALSE, df  mindiff)] + mindiff/10
df - x[-1] - x[-length(x)]
i - i + 1
if (i  100) {
   break
}
  }
  x
}

I have tried experimenting with using optim to minimize a function of
the distances between new points and old points penealized for being to
close, but it sometimes gave me some weird results, the above has worked
fairly well for me (the above is based on some of the code inside the
triplot function in the TeachingDemos package).

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Levi Waldron
 Sent: Saturday, March 22, 2008 7:03 PM
 To: R-help mailing list
 Subject: [R] spreading out a numeric vector
 
 I am creating a timeline plot, but running into a problem in 
 positions where the values to plot are too close together to 
 print the text without overlap.  The simplest way I can think 
 of to solve this (although there may be other ways?) is to 
 create a new numeric vector whose values are as close as 
 possible to the original vector, but spread out to a given 
 minimum difference.  For example, take the following vector:
 
  x - c(1,2,seq(2.1,2.3,0.1),3,4)
  x
 [1] 1.0 2.0 2.1 2.2 2.3 3.0 4.0
 
 
 However, suppose I don't want to plot any of these points 
 with less than 0.5 between them.  The problem could be solved 
 by a function that behaved something like this:
 
  x2 - spread(x,mindiff=0.5)
  x2
 [1] 0.5 1.0 1.5 2.0 2.5 3.0 4.0
 
 Or for a minimum difference of 0.2,
  x2 - spread(x,mindiff=0.2)
  x2
 [1] 1.0 1.8 2.0 2.2 2.4 3.0 4.0
 
 Thus, if there is a cluster of close values, spreading the 
 values may require changing values which previously weren't 
 too close to their nearest neighbors.
 
 Then I could use segments() to draw lines from the timeline 
 to where the shifted text is printed, labeling tics on the 
 timeline accurately but keeping the text from overlapping.
 
 Any ideas on how to program this or how to do it using 
 built-in functions would be greatly appreciated.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] vlookup in R

2008-03-24 Thread Sachin J
Thank you all for your help. I will definately go through the suggested 
document. 
Thanks again.

Sachin



- Original Message 
From: Henrik Bengtsson [EMAIL PROTECTED]
To: Sachin J [EMAIL PROTECTED]
Cc: Henrique Dallazuanna [EMAIL PROTECTED]; r-help@r-project.org
Sent: Monday, March 24, 2008 12:43:42 PM
Subject: Re: [R] vlookup in R

# Setup the translation map
transMap - c(A=R, B=R, C=R, D=B, F=B);

# The input data
v3 - c(A, C, D, F, A, C, B, B, B, B, A, D);

# The translated data
v4 - transMap[v3];

df2 - data.frame(V3=v3, V4=v4);

I recommend you to read 'An Introduction to R' that comes with any R
installation.  There is a lot of useful stuff in there; it takes many
reads to grasp parts of it but it is worth it if you're going to use R
for more than, say, two weeks. You can find it via help.start().

/Henrik

On Mon, Mar 24, 2008 at 8:25 AM, Sachin J [EMAIL PROTECTED] wrote:
 Hi Henrique,

  This is what I am trying to accomplish:
  I want to read values in V1 and V2 and populate the column V4 with R or B 
 based on the
  values in V3 i.e. if its A,B,C then its R else if D,F then B. You can assume 
 V1, V2 are dataframe1
  and V3, V4 are in dataframe2 (note V4 is empty initially i.e. its a new 
 column).

   df1
  V1V2
  A R
  BR
  CR
  DB
  FB

   df2

  V3V4
  AR
  CR
  DB
  FB
  AR
  CR
  BR
  BR
  BR
  BR
  AR
  DB



  Thanks in advance for your help.




  - Original Message 
  From: Henrique Dallazuanna [EMAIL PROTECTED]
  To: Sachin J [EMAIL PROTECTED]
  Cc: r-help@r-project.org
  Sent: Monday, March 24, 2008 10:41:52 AM
  Subject: Re: [R] vlookup in R

  I think that merge is what you want:

  set.seed(24032008)
  x - data.frame(ID=sample(10), Value=rnorm(10))
  idx - sample(5)
  merge(idx, x, by.x=1, by.y=1)

  On 24/03/2008, Sachin J [EMAIL PROTECTED] wrote:
   Hi,

 
Is there are function similar to excel vlookup in R. Please let me know.
  

   Thanks,
Sachin
  
  

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



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


  
 


[[alternative HTML version deleted]]


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




  



[[alternative HTML version deleted]]

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


Re: [R] inheritence in S4

2008-03-24 Thread cgenolin
 callGeneric is an advanced topic.

Ok, when I will be older :-)

 *
 This works :

 setMethod(initialize,B,
  function(.Object,..., yValue){
  callNextMethod(.Object, ..., y=yValue)
  return(.Object)
  })
 new(B,yValue=3)

 but this does not :

 setMethod(initialize,B,
  function(.Object, yValue){
  callNextMethod(.Object, y=yValue)
  return(.Object)
  })
 new(B,yValue=3)

 Why ?
 Is there any help page about ... ?

 Both 'work' in the sense that an object is returned

Well yes, but the second one does return an object without assigning 
the value 3, that is not realy working...


 In an object-oriented sense, initialize,B-method should really just 
 deal with it's own slots; it shouldn't have to 'know' about either 
 classes that it extends (A) or classes that extend it. And it 
 shouldn't do work that inherited methods (i.e., 
 initialize,ANY-method) do.

I get your point and I agree : I am developing B, you are developing A, 
I do not want to know what is in A so B should not initialize its 'A 
part'

On the other hand, I do not like the ... . ... can be anything, 
there is no controle at all, no type checking.
I would prefers to initialize B giving its value for its own slot AND 
an object class A. So I send you the value for A, you send me an objets 
'aaa' of class A then I initialize B with some value and aaa. This way, 
B keep its role but does not transmit anythink to A without controling 
it.

Best,

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.


[R] as.numeric with tclvalue redux

2008-03-24 Thread Erin Hodgess
Hi again R People:

This works fine:
 library(tcltk)
 a - tclVar(4.5)
 as.numeric(tclvalue(a))
[1] 4.5
 #But if you have:
 b - tclVar(pi)
 as.numeric(tclvalue(b))
[1] NA
Warning message:
NAs introduced by coercion


Is anyone aware of a way around this, please?

thanks,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: [EMAIL PROTECTED]

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

2008-03-24 Thread tomkur2006-takehome
Hi,

I am getting this error when I run 'make' under src/library/base:
../../../library/base/R/base is unchanged
../../../bin/R: bad substitution
make: *** [all] Error 1

I traced it down to the following line in src/library/base/Makefile:
   @cat $(srcdir)/makebasedb.R | \
  R_DEFAULT_PACKAGES=NULL LC_ALL=C $(R_EXE) --slave  /dev/null

I am trying to build R-2.6.2 on a Solaris 9 box.
Can anyone advise on what may go wrong?  Thank you.


[[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] inheritence in S4

2008-03-24 Thread Martin Morgan
[EMAIL PROTECTED] wrote:
 callGeneric is an advanced topic.
 
 Ok, when I will be older :-)
 
 *
 This works :

 setMethod(initialize,B,
  function(.Object,..., yValue){
  callNextMethod(.Object, ..., y=yValue)
  return(.Object)
  })
 new(B,yValue=3)

 but this does not :

 setMethod(initialize,B,
  function(.Object, yValue){
  callNextMethod(.Object, y=yValue)
  return(.Object)
  })
 new(B,yValue=3)

 Why ?
 Is there any help page about ... ?

 Both 'work' in the sense that an object is returned
 
 Well yes, but the second one does return an object without assigning the 
 value 3, that is not realy working...

I wasn't paying enough attention to your code. callNextMethod is like 
any R function -- it will not change .Object 'in place', but makes a 
copy, modifies the copy, and returns the copy. So either

setMethod(initialize,B,
  function(.Object,..., yValue){
  .Object - callNextMethod(.Object, ..., y=yValue)
  return(.Object)
  })

or more compactly

setMethod(initialize,B,
  function(.Object,..., yValue){
  callNextMethod(.Object, ..., y=yValue)
  })

The code example is incomplete, so I don't really know why one version 
assigned y=3 for you and the other did not; for me, neither version did 
the assignment.

Martin

 In an object-oriented sense, initialize,B-method should really just 
 deal with it's own slots; it shouldn't have to 'know' about either 
 classes that it extends (A) or classes that extend it. And it 
 shouldn't do work that inherited methods (i.e., initialize,ANY-method) 
 do.
 
 I get your point and I agree : I am developing B, you are developing A, 
 I do not want to know what is in A so B should not initialize its 'A part'
 
 On the other hand, I do not like the ... . ... can be anything, 
 there is no controle at all, no type checking.
 I would prefers to initialize B giving its value for its own slot AND an 
 object class A. So I send you the value for A, you send me an objets 
 'aaa' of class A then I initialize B with some value and aaa. This way, 
 B keep its role but does not transmit anythink to A without controling it.
 
 Best,
 
 Christophe
 
 
 Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre
 
 
 


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

Location: Arnold Building M2 B169
Phone: (206) 667-2793

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


Re: [R] as.numeric with tclvalue redux

2008-03-24 Thread Sundar Dorai-Raj


Erin Hodgess said the following on 3/24/2008 10:39 AM:
 Hi again R People:
 
 This works fine:
 library(tcltk)
 a - tclVar(4.5)
 as.numeric(tclvalue(a))
 [1] 4.5
 #But if you have:
 b - tclVar(pi)
 as.numeric(tclvalue(b))
 [1] NA
 Warning message:
 NAs introduced by coercion
 
 Is anyone aware of a way around this, please?
 
 thanks,
 Erin
 
 

Does this help?

eval.tclvalue - function(x, ...) {
   x - type.convert(tclvalue(x), as.is = TRUE)
   if(is.character(x)  exists(x, ...)) {
 get(x)
   } else {
 x
   }
}

a - tclVar(4.5)
b - tclVar(pi)
c - tclVar(abcd)

eval.tclvalue(a)
eval.tclvalue(b)
eval.tclvalue(c)

HTH,

--sundar

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] [Rd] resampling from string when it runs across multiple lines

2008-03-24 Thread Dimitris Rizopoulos
try this:

y - as.matrix(read.table(textConnection(
A C G T T G C A G  C
A C G F F F F F F  G
A C G S S S S S G  A
A C G T T G C A G  G
A B B B B B B A G  T
), stringsAsFactors = FALSE))

ind - sample(length(y), 20, TRUE)
y[ind]

I hope it helps.

Best,
Dimitris

ps, it would be best that you send that kind of e-mails in R-help not  
R-devel; check http://www.r-project.org/mail.html for more info  
regarding the different R-mailing-lists.


Dimitris Rizopoulos
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Suraaga Kulkarni [EMAIL PROTECTED]:

 Hi,

 I need to resample from a long string, which is written in many lines with
 carriage-return marks at the end of each line.  Perhaps because the data
 looks like a matrix, using the code: sample(data, 25, replace=T) gives me 25
 columns of characters from the data because it is resampling whole columns.
 What I would like it to do is to treat the data as a vector that has just
 been spread across many lines, and pick single characters from random
 positions in randomly chosen lines.

 I am reproducing a sample dataset, the command and the output here:

 y
  X..1. X..2. X..3. X..4. X..5. X..6. X..7. X..8. X..9. X..10.
 [1,] A C G T T G C A G  C
 [2,] A C G F F F F F  F  G
 [3,] A C GS S S S S G  A
 [4,] A C G T T G C A G  G
 [5,] A B B B B B B A G  T

 sample(y, 20, replace=T)
  X..9. X..4. X..2. X..7. X..9..1 X..3. X..3..1 X..9..2 X..9..3 X..4..1
 X..3..2 X..8. X..9..4 X..3..3 X..6. X..7..1
 [1,] G T C C   G G   G   G   G
 T   G A   G   G G   C
 [2,] F  FC FF G   G   F   F
 F   G F   F   G  F   F
 [3,] G SC S   G G   G   G   G
 S   G S   G   G S   S
 [4,] G T C C   G G   G   G   G
 T   G A   G   G G   C
 [5,] G B B B   G B   B   G   G
 B   B A   G   B B   B

  X..6..1 X..3..4 X..7..2 X..10.
 [1,]   G   G   C  C
 [2,]   F   GF  G
 [3,]   S   G   S  A
 [4,]   G   G   C  G
 [5,]   B   B   B   T

 I wanted to try the bootstrap approach (since that's what I am doing -
 resampling with replacement) but that requires a statistic and I don't
 know what sense that makes for character data.

 Any help will be greatly appreciated.

 Thanks,

 S.

   [[alternative HTML version deleted]]

 __
 [EMAIL PROTECTED] mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel





Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

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


Re: [R] as.numeric with tclvalue redux

2008-03-24 Thread Peter Dalgaard
Erin Hodgess wrote:
 Hi again R People:

 This works fine:
   
 library(tcltk)
 a - tclVar(4.5)
 as.numeric(tclvalue(a))
 
 [1] 4.5
   
 #But if you have:
 b - tclVar(pi)
 as.numeric(tclvalue(b))
 
 [1] NA
 Warning message:
 NAs introduced by coercion
   

 Is anyone aware of a way around this, please?

   
Brian already told you: Parse and eval.

  eval(parse(text=as.character(tclvalue(tclVar(pi)
[1] 3.141593

(Beware: Depending on the environment in which you eval(), strange 
things can happen if you use the name of an internal variable in your 
function)

What happened with the Inf issue? I can't reproduce that:

  as.numeric(as.tclObj(Inf))
[1] Inf

-- 
   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] as.numeric with tclvalue redux

2008-03-24 Thread Erin Hodgess
Thank you!


On 3/24/08, Peter Dalgaard [EMAIL PROTECTED] wrote:
 Erin Hodgess wrote:
  Hi again R People:
 
  This works fine:
 
  library(tcltk)
  a - tclVar(4.5)
  as.numeric(tclvalue(a))
 
  [1] 4.5
 
  #But if you have:
  b - tclVar(pi)
  as.numeric(tclvalue(b))
 
  [1] NA
  Warning message:
  NAs introduced by coercion
 
 
  Is anyone aware of a way around this, please?
 
 
 Brian already told you: Parse and eval.

   eval(parse(text=as.character(tclvalue(tclVar(pi)
 [1] 3.141593

 (Beware: Depending on the environment in which you eval(), strange
 things can happen if you use the name of an internal variable in your
 function)

 What happened with the Inf issue? I can't reproduce that:

   as.numeric(as.tclObj(Inf))
 [1] Inf

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





-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: [EMAIL PROTECTED]

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

2008-03-24 Thread Prof Brian Ripley
Since you have posted about this before with errors earlier in the build 
process and not told us those were resolved, very likely something prior 
to this is the problem.

You will find people here more responsive if you don't disregard the 
posting guide, e.g. by sending HTML mail.

On Mon, 24 Mar 2008, [EMAIL PROTECTED] wrote:

 Hi,

 I am getting this error when I run 'make' under src/library/base:
 ../../../library/base/R/base is unchanged
 ../../../bin/R: bad substitution
 make: *** [all] Error 1

 I traced it down to the following line in src/library/base/Makefile:
   @cat $(srcdir)/makebasedb.R | \
  R_DEFAULT_PACKAGES=NULL LC_ALL=C $(R_EXE) --slave  /dev/null

 I am trying to build R-2.6.2 on a Solaris 9 box.
 Can anyone advise on what may go wrong?  Thank you.

That doesn't help at all: we already know the problem is in bin/R, which 
will affect any attempt to run R. You will have to track down the 'bad 
substitution' (and no one else is going to be able to do it for you).

BTW, R 2.6.2 runs perfectly well on Solaris 8 and 10, and we know R 2.6.0 
works on Solaris 9 because sunfreeware.com distribute it.  This points 
pretty firmly to something non-standard about your system.



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


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


Re: [R] inheritence in S4

2008-03-24 Thread cgenolin
 The code example is incomplete, so I don't really know why one 
 version assigned y=3 for you and the other did not; for me, neither 
 version did the assignment.

I probably add the return in the mail without imagining il will change things.

My question was more on the use of ... versus the absence of ...
You anwer me by correcting my bug. So I can use callNextMethod with or 
without ... :

setClass(B,representation(y=numeric))
setMethod(initialize,B,
  function(.Object,..., yValue){
  return(callNextMethod(.Object, ..., y=yValue))
  })

new(B,yValue=3)   #1
try(new(B,yValueee=3))#2 try(new(B,yValue=3,yValueee=3))   #3

setMethod(initialize,B,
  function(.Object, yValue){
  return(callNextMethod(.Object, y=yValue))
  })
new(B,yValue=3)#4
try(new(B,yValueee=3)) #5
try(new(B,yValue=3,yValueee=3))#6

I undersand that 1 and 4 work. I understand that 2 and 5 do not work 
since yValue is missing
I understand that 6 does not work since yValueee is not a valid argument
But I would expect that 3 will work since it get a value for yValue and 
yValueee can be one of the ...

It does not...

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] Great difference for piecewise linear function between R and SAS

2008-03-24 Thread Andrew Robinson
On Mon, Mar 24, 2008 at 01:09:35PM -0500, Paul Johnson wrote:
 On Mon, Mar 24, 2008 at 8:11 AM, Duncan Murdoch [EMAIL PROTECTED] wrote:
  On 3/24/2008 9:03 AM, zhijie zhang wrote:
Dear  Murdoch,
 
 Thanks very
 
   I would use predict() instead.  What you have there doesn't look as
   though it uses the B-spline basis.
 
   The reference given in the ?bs help page is a reasonable starting point,
   but just about any book that covers splines should handle the B-spline
   basis and the linear case.
 
   Duncan Murdoch
 
 
 Dear Duncan and others:
 
 Can you please refer us to an understandable book that explains about
 b-splines?  I've tried a few and the math pretty quickly becomes
 unintelligible to a non-math major.

I think you should try Simon Wood's Generalized Additive Models: An
introduction in R.  2006 Chapman and Hall. 

I reviewed it recently and I think it's really very good.

Cheers

Andrew

-- 
Andrew Robinson  
Department of Mathematics and StatisticsTel: +61-3-8344-6410
University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599
http://www.ms.unimelb.edu.au/~andrewpr
http://blogs.mbs.edu/fishing-in-the-bay/

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

2008-03-24 Thread Martin Morgan
[EMAIL PROTECTED] wrote:
 The code example is incomplete, so I don't really know why one version 
 assigned y=3 for you and the other did not; for me, neither version 
 did the assignment.
 
 I probably add the return in the mail without imagining il will change 
 things.
 
 My question was more on the use of ... versus the absence of ...
 You anwer me by correcting my bug. So I can use callNextMethod with or 
 without ... :
 
 setClass(B,representation(y=numeric))
 setMethod(initialize,B,
  function(.Object,..., yValue){
  return(callNextMethod(.Object, ..., y=yValue))
  })
 
 new(B,yValue=3)   #1
 try(new(B,yValueee=3))#2 
 try(new(B,yValue=3,yValueee=3))   #3
 
 setMethod(initialize,B,
  function(.Object, yValue){
  return(callNextMethod(.Object, y=yValue))
  })
 new(B,yValue=3)#4
 try(new(B,yValueee=3)) #5
 try(new(B,yValue=3,yValueee=3))#6
 
 I undersand that 1 and 4 work. I understand that 2 and 5 do not work 
 since yValue is missing
 I understand that 6 does not work since yValueee is not a valid argument
 But I would expect that 3 will work since it get a value for yValue and 
 yValueee can be one of the ...

The first challenge is to understand how ... works (maybe from 'An 
Introduction to R', section 10.4?)

  f - function(...) names(list(...))

  f(x=1)
[1] x
  f(x=1, y=2)
[1] x y

Probably ok so far. Now

  g - function(..., x) f(..., z=x) # 'g' transmits 'x' as 'z'
  g(x=1)
[1] z
  g(y=1,x=2)
[1] y z

or

  h - function(..., x) f(...) # 'h' consumes 'x'
  h()
NULL
  h(x=1)
NULL
  h(y=1)
[1] y
  h(y=1,x=1)
[1] y

For instance, g passes an argument to f that consisting of (what g 
received as) ... and z. f is expects ..., and z ends up as part of that 
list.

What happens with initialize? The default method is described on 
?initialize, where the signature is

initialize(.Object, ...)

with

  ...: Data to include in the new object.  Named arguments
   correspond to slots in the class definition.
[snip]

in #3, your callNextMethod results in the default method seeing ... 
containing an argument yValueee=3. Since yValueee does not match a slot, 
R responds with an error

   Error in .nextMethod(.Object, ..., y = yValue) :
   invalid names for slots of class B: yValueee

With the ..., a class extending B can rely on the default method to fill 
in slots with provided arguments.

setClass(C, representation=representation(c=numeric), contains=B)
new(C, yValue=1, c=2) # works with ... in B's initialize method

Without ..., a class extending B would have to write an initialize 
method that fills in slots (and checks validity) itself, repeating the 
work already implemented in initialize,ANY-method.

 It does not...
 
 Christophe
 
 
 Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre
 
 
 


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

Location: Arnold Building M2 B169
Phone: (206) 667-2793

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


Re: [R] Simple problem in R

2008-03-24 Thread Charles C. Berry
On Mon, 24 Mar 2008, Chaser wrote:


 I found a package on www.bioconductor.com that allows me to install using
 this line:

 source(http://bioconductor.org/biocLite.R;)
 biocLite(MassSpecWavelet)

 The prompt showed me the following message:

 Running biocinstall version 2.1.10 with R version 2.6.2
 Your version of R requires version 2.1 of Bioconductor.
 trying URL
 'http://bioconductor.org/packages/2.1/bioc/bin/windows/contrib/2.6/MassSpecWavelet_1.4.0.zip'
 Content type 'application/zip' length 2129961 bytes (2.0 Mb)
 opened URL
 downloaded 2.0 Mb

 package 'MassSpecWavelet' successfully unpacked and MD5 sums checked

 The downloaded packages are in
C:\Documents and Settings\Yuan\Local
 Settings\Temp\RtmpIjgEwP\downloaded_packages
 updating HTML package descriptions

 In their help package, they have listed commands that will allow a sample
 runthrough of their algorithm using a sample dataset.

 I entered these codes in but was returned the following error messages:

 data(exampleMS)
 Warning message:
 In data(exampleMS) : data set 'exampleMS' not found
 SNR.Th - 3
 peakInfo - peakDetectionCWT(exampleMS, SNR.Th=SNR.Th)
 Error: could not find function peakDetectionCWT
 majorPeakInfo = peakInfo$majorPeakInfo
 Error: object peakInfo not found
 peakIndex - majorPeakInfo$peakIndex
 Error: object majorPeakInfo not found
 plotPeak(exampleMS, peakIndex, main=paste('Identified peaks with SNR ',
 SNR.Th))


 Did I make a mistake somewhere or is the code they wrote flawed?


Did you remember

library( MassSpecWavelet )

??

HTH,

Chuck


 -- 
 View this message in context: 
 http://www.nabble.com/Simple-problem-in-R-tp16259116p16259116.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.


Charles C. Berry(858) 534-2098
 Dept of Family/Preventive Medicine
E mailto:[EMAIL PROTECTED]  UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

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

2008-03-24 Thread Levi Waldron
*Thank you* Greg, this function works perfectly!  I had imagined that
the ideal solution would iteratively modify the vector to fix new
violations of mindiff created by each subsequent spreading of tight
clusters, but couldn't figure how to do it.  A small note, the vector
x must be sorted before using this function, which is a reasonable
requirement.

Thanks also to Jim Lemon for pointing out the very useful plotrix
package - the spread.labels function didn't work so well for this
application because the timelines looked strange with the labels
spread evenly, but I like a number of the functions provided by the
package.

-levi

On Mon, Mar 24, 2008 at 12:43 PM, Greg Snow [EMAIL PROTECTED] wrote:
 Levi,

  Here is one possible function:

  spread - function(x, mindiff) {
   df - x[-1] - x[-length(x)]
   i - 1
   while (any(df  mindiff)) {
 x[c(df  mindiff, FALSE)] - x[c(df  mindiff, FALSE)] - mindiff/10
 x[c(FALSE, df  mindiff)] - x[c(FALSE, df  mindiff)] + mindiff/10
 df - x[-1] - x[-length(x)]
 i - i + 1
 if (i  100) {
break
 }
   }
   x
  }

  I have tried experimenting with using optim to minimize a function of
  the distances between new points and old points penealized for being to
  close, but it sometimes gave me some weird results, the above has worked
  fairly well for me (the above is based on some of the code inside the
  triplot function in the TeachingDemos package).

  Hope this helps,

  --
  Gregory (Greg) L. Snow Ph.D.
  Statistical Data Center
  Intermountain Healthcare
  [EMAIL PROTECTED]
  (801) 408-8111

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


[R] Newbie help with Sweave

2008-03-24 Thread Zembower, Kevin
I think I've gotten my Emacs/Sweave/R system set up correctly, thanks to
Vincent and Jim, but I haven't been successful getting my first document
produced. I'm trying to use one of Friedrich Leisch's examples,
http://www.ci.tuwien.ac.at/~leisch/Sweave/example-1.Snw. I cut and
pasted the text into a document sweaveexample.Rnw in Emacs. It seemed to
be processed successfully with R:
 Sweave(sweaveexample.Rnw)
Writing to file sweaveexample.tex
Processing code chunks ...

You can now run LaTeX on 'sweaveexample.tex'


However, when I try to open the file sweaveexample.tex and process it
with Latex in Emacs, I get this error:
ERROR: Missing \endcsname inserted.

--- TeX said ---
to be read again 
   \protect 
l.7 \begin
  {document}
--- HELP ---
From the .log file...

The control sequence marked to be read again should
not appear between \csname and \endcsname.

I've tried a variety of examples, but the error messages are the same.

Can anyone point out my errors or mistakes? I've pasted in the full
files below. Thanks so much for your help and advice.

-Kevin

Kevin Zembower
Internet Services Group manager
Center for Communication Programs
Bloomberg School of Public Health
Johns Hopkins University
111 Market Place, Suite 310
Baltimore, Maryland  21202
410-659-6139 
==
sweaveexample.tex:
==
\documentclass[a4paper]{article}

\title{Sweave Example 1}
\author{Friedrich Leisch}

\usepackage{C:/PROGRA~1/R/R-26~1.2/share/texmf/Sweave}
\begin{document}

\maketitle

In this example we embed parts of the examples from the
\texttt{kruskal.test} help page into a \LaTeX{} document:

\begin{Schunk}
\begin{Sinput}
 data(airquality)
 library(ctest)
 kruskal.test(Ozone ~ Month, data = airquality)
\end{Sinput}
\begin{Soutput}
Kruskal-Wallis rank sum test

data:  Ozone by Month 
Kruskal-Wallis chi-squared = 29.2666, df = 4, p-value = 6.901e-06
\end{Soutput}
\end{Schunk}
which shows that the location parameter of the Ozone 
distribution varies significantly from month to month. Finally we
include a boxplot of the data:

\begin{center}
\includegraphics{sweaveexample-002}
\end{center}

\end{document}

sweaveexample.Rnw:
==
\documentclass[a4paper]{article}

\title{Sweave Example 1}
\author{Friedrich Leisch}

\begin{document}

\maketitle

In this example we embed parts of the examples from the
\texttt{kruskal.test} help page into a \LaTeX{} document:

=
data(airquality)
library(ctest)
kruskal.test(Ozone ~ Month, data = airquality)
@
which shows that the location parameter of the Ozone 
distribution varies significantly from month to month. Finally we
include a boxplot of the data:

\begin{center}
fig=TRUE,echo=FALSE=
boxplot(Ozone ~ Month, data = airquality)
@
\end{center}

\end{document}

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

2008-03-24 Thread Levi Waldron
Would this function be worth submitting to some existing cran library?
 I'd be willing to document it and add error-checking if there is
somewhere that it belongs (with credit to Greg of course, unless Greg
wants to submit it himself).

I am using it in conjunction with a function I wrote which draws tics
on the timeline and draws a line from the tic to the label when they
aren't aligned.


I have tried experimenting with using optim to minimize a function of
the distances between new points and old points penealized for being to
close, but it sometimes gave me some weird results, the above has worked
fairly well for me (the above is based on some of the code inside the
triplot function in the TeachingDemos package).
  
Hope this helps,
  
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Plotting matrix rows with lattice graphics?

2008-03-24 Thread Ron Bonner
Sorry if this is an FAQ, but I haven't found the answer (yet)...

I'm trying to plot each row of a simple numeric matrix in a separate  
panel using the layout features of lattice, but can't make it work -  
help would be appreciated!

Example:

  m - matrix(seq(1:20), nrow=4)

  m
  [,1] [,2] [,3] [,4] [,5]
[1,]159   13   17
[2,]26   10   14   18
[3,]37   11   15   19
[4,]48   12   16   20

The following will plot one row in one box:

  xyplot(m[1,] ~ seq(1:5))

but this gives all rows in the same box:

  xyplot(m ~ seq(1:5))

Since there are no factors, how can I set conditioning variable to get  
what I want, or is there a better way to do this?

Thanks in advance

Ron

Ron Bonner
[EMAIL PROTECTED]
skype: rbonners







[[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 GUI question

2008-03-24 Thread jeffreya

Thanks so much for all the input; I appreciate it.

I think I'll stick with Tcl/Tk for now primarily on the basis of
installation issues. I'm not sure that many of these users would have Java,
so the other alternatives all seemed to add another level of complexity on
to the installation task (again, this is aimed at a very non-computer savvy
audience).

Thanks again for the advice!

Jeff
-- 
View this message in context: 
http://www.nabble.com/R-GUI-question-tp16149624p16262820.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] Running rpy produces the error message undefined symbol: KillAllDevices

2008-03-24 Thread Bob and Deb
Hello All,

I've been using R for a while and decided to test R from the svn trunk.  I
know that trunk is not stable, but I wanted to see if I can install and run
the latest rpy on my Ubuntu 7.10 box.  It installed ok, but I got the
runtime error message:

$ python
Python 2.5.1 (r251:54863, Mar  7 2008, 04:10:12)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type help, copyright, credits or license for more information.
 import rpy
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib/python2.5/site-packages/rpy.py, line 134, in module
 % RVERSION)
RuntimeError: /usr/lib/python2.5/site-packages/_rpy2070.so: undefined
symbol: KillAllDevices

  RPy module can not be imported. Please check if your rpy
  installation supports R 2.7.0. If you have multiple R versions
  installed, you may need to set RHOME before importing rpy. For
  example:

   from rpy_options import set_options
   set_options(RHOME='c:/progra~1/r/rw2011/')
   from rpy import *




Btw, RHOME on my computer is located at /usr/local/lib/R and I have compiled
R shared library directory in my ld.so.conf.

Bob

[[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] Simple problem in R

2008-03-24 Thread Chaser

I never knew to enter that command in.

Thanks guys!
-- 
View this message in context: 
http://www.nabble.com/Simple-problem-in-R-tp16259116p16260713.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] derivatives in R

2008-03-24 Thread Lavan

Hi, I posted this message earlier in Rmetrics and I don't know whether I
posted in the wrong place, so I'm posting it again in Rhelp. 

I have a function in x and y and let's call it f(x,y). I need to get the
Hessian matrix. i.e I need (d^2f/dx^2), (d^2f/dxdy), (d^2f/dydx),
(d^2f/dy^2).I can get these using the D function. now I need to evaluste the
hessian matrix for -5x5 and -2y2 and I also need to print the output. 

I tried  using a for loop,but it is giving me an error. 

Thanks 

-- 
View this message in context: 
http://www.nabble.com/derivatives-in-R-tp16265419p16265419.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] derivatives in R

2008-03-24 Thread David Winsemius
Lavan [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 
 Hi, I posted this message earlier in Rmetrics and I don't know
 whether I posted in the wrong place, so I'm posting it again in
 Rhelp. 
 
 I have a function in x and y and let's call it f(x,y). I need to get
 the Hessian matrix. i.e I need (d^2f/dx^2), (d^2f/dxdy),
 (d^2f/dydx), (d^2f/dy^2).I can get these using the D function. now I
 need to evaluste the hessian matrix for -5x5 and -2y2 and I also
 need to print the output. 
 
 I tried  using a for loop,but it is giving me an error. 

I was wondering if the fact that you provide neither an example nor even 
the text of the error that could be the explanation for no response.

-- 
David Winsemius

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


[R] Passing (Optional) Arguments

2008-03-24 Thread Jason Q. McClintic
Dear List:

In short, I am writing a number of functions as building blocks for 
other functions and have some questions about scoping and passing arguments.

Suppose I have functions foo1, foo2, and foo3 such that:

foo1-function(a=1,b=TRUE,c=FALSE){#do stuff};
foo2-function(x=1,y=FALSE,z=c(1,2,3,4)){#do stuff};
foo3-function(lambda,...){lambda*foo1()*foo2()};

I want to be able to pass a,b,c,x,y,z to the functions foo1 and foo2 
though foo3 (whether I define default values or not). How do I do this?
I read a bit in the wiki about problems with partial argument matching 
and argument matching (lesson: make argument names not match truncated 
versions of other argument names in the target function).

To get a better feel for things I've been playing with examples such as:

b-c(0.25,0.25);
fun-function(a=1,...){a*b};

fun() returns 0.25 0.25 as expected.
fun(a=2) returns 0.5 0.5 as expected.
However, fun(b=1) returns 0.25 0.25 when I want to overwrite b with the 
value 1 and have it return 1.

Likewise with

fun-function(a=1,...){a*return(b)};

any argument I supply for b seems to be ignored.

I understand as b is not defined within the function when I enter

fun()

lexical scoping means R looks for b up one level and, finding b, uses it.

Thanks for any/all help.

Sincerely,

Jason Q. McClintic
--
Jason Q McClintic
UST MB 1945
2115 Summit Avenue
St. Paul, MN 55105
[EMAIL PROTECTED]
[EMAIL PROTECTED]

It is insufficient to protect ourselves with laws, we must protect 
ourselves with mathematics.--Bruce Schneier

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

2008-03-24 Thread Research Scholar
Hi all
 Is there a function that can find the start and end position of peaks in a
set of numbers.
eg.
x=c(14,15,12,11,12,13,14,15,16,15,14,13,12,11,14,12)
y=somefunction(x)

y
4 14


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


Re: [R] peak finding

2008-03-24 Thread Bill.Venables
It's hard to see how positions 4 and 14 correspond to 'peaks', they look
like troughs to me.  So perhaps this is what you mean:

 x - c(14,15,12,11,12,13,14,15,16,15,14,13,12,11,14,12)

 y - which(x == min(x))
 y
[1]  4 14 

as a function:

somefunction - function(x) which(x == min(x))


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 Research Scholar
Sent: Tuesday, 25 March 2008 12:54 PM
To: r-help@r-project.org
Subject: [R] peak finding

Hi all
 Is there a function that can find the start and end position of peaks
in a
set of numbers.
eg.
x - c(14,15,12,11,12,13,14,15,16,15,14,13,12,11,14,12)
y - somefunction(x)

y
4 14


Thanks
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 with rowsum/aggregate type functions

2008-03-24 Thread Charles Murtaugh
Hi--

  This is a question with a trivial and obvious answer, I'm sure, but I can't 
seem to find it in the help files and books that I have handy.  I have a 
dataframe consisting of two columns, Gene_Name, a list of gene symbols, and 
Number, a numeric measure of how frequently a tag representing that gene 
showed up in a SAGE library.  Several of the genes are represented by multiple 
tags, and therefore are present more than once in the list, e.g.:

1167 Zcchc8  6
1168 Zcwpw1  5
1169 Zdhhc18 6
1170 Zdhhc20 5
1171 Zdhhc3  6
1172 Zdhhc3  5
1173 Zeb29
1174 Zeb26

  What I want is to collapse the list by gene name, such that duplicates are 
summed up and appear only once in the final version:



Zcchc8  6

Zcwpw1  5

Zdhhc18 6
Zdhhc20 5

Zdhhc3 11

Zeb2   15



  The only way I can figure out to do this is via rowsum:



 rowsum (Number,Gene_Name)



gives me exactly what I want, *except* that in the end, I am left with a matrix 
containing the Number values and with the Gene_Names used as row names (the 
output therefore looks exactly as printed above) -- what I want is a dataframe 
equivalent to the starting table, with numbered rows and separate, accessible 
columns containing the Gene_Name and Number values.



  I was able to put such a dataframe together manually, by cobbling together 
the row names of the above list with the values:



 genes.unique - data.frame (rownames (rowsum(Number,Gene_Name)), 
 rowsum(Number,Gene_Name))



but then I have to manually replace the row names of the dataframe with 
numbers, to get back to what I wanted in the first place.



  I hope this makes some sort of sense.  Is there an easier way to do this?  
Thanks in advance!



  Charlie Murtaugh







=

L. Charles Murtaugh
Assistant Professor

University of Utah
Dept. of Human Genetics
15 N. 2030 E. Rm. 2100
Salt Lake City, UT 84112

tel 801-581-5958
fax 801-581-6463
email [EMAIL PROTECTED]


[[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] peak finding

2008-03-24 Thread Research Scholar
Hi
 Thanks for replying. I meant x[4] is the start of a peak shape and x[14] is
the end of that peak and x[9] is the maxima of the peak.
Thanks,
John




On Mon, Mar 24, 2008 at 11:09 PM, [EMAIL PROTECTED] wrote:

 It's hard to see how positions 4 and 14 correspond to 'peaks', they look
 like troughs to me.  So perhaps this is what you mean:

  x - c(14,15,12,11,12,13,14,15,16,15,14,13,12,11,14,12)

  y - which(x == min(x))
  y
 [1]  4 14

 as a function:

 somefunction - function(x) which(x == min(x))


 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 Research Scholar
 Sent: Tuesday, 25 March 2008 12:54 PM
 To: r-help@r-project.org
 Subject: [R] peak finding

 Hi all
  Is there a function that can find the start and end position of peaks
 in a
 set of numbers.
 eg.
 x - c(14,15,12,11,12,13,14,15,16,15,14,13,12,11,14,12)
 y - somefunction(x)

 y
 4 14


 Thanks
 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.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] peak finding

2008-03-24 Thread Bill.Venables
Then the answer is pretty simple: 'no'.

The idea probably needs a lot more refining to make it workable, too.
Why do you discard he peak at 2, with the shape starting at 1 and
finishing at 4, for example?

In thinking about this it might be useful for you to look at signs of
successive differences:

 sign(diff(c(-Inf, x)))
 [1]  1  1 -1 -1  1  1  1  1  1 -1 -1 -1 -1 -1  1 -1

That's perhaps a starting point.  You seem to want to know (roughly)
where do the runs of '1's start and the following run of '-1's end?
The function rle(), for run length encoding, might be useful in this
regard, too.

Bill Venables. 


-Original Message-
From: Research Scholar [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, 25 March 2008 1:24 PM
To: Venables, Bill (CMIS, Cleveland)
Cc: r-help@r-project.org
Subject: Re: [R] peak finding

Hi
 Thanks for replying. I meant x[4] is the start of a peak shape and
x[14] is the end of that peak and x[9] is the maxima of the peak. 
Thanks,
John
 
On Mon, Mar 24, 2008 at 11:09 PM, [EMAIL PROTECTED] wrote:


It's hard to see how positions 4 and 14 correspond to 'peaks',
they look
like troughs to me.  So perhaps this is what you mean:


 x - c(14,15,12,11,12,13,14,15,16,15,14,13,12,11,14,12)


 y - which(x == min(x))
 y
[1]  4 14

as a function:

somefunction - function(x) which(x == min(x))


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 Research Scholar
Sent: Tuesday, 25 March 2008 12:54 PM
To: r-help@r-project.org
Subject: [R] peak finding

Hi all
 Is there a function that can find the start and end position of
peaks
in a
set of numbers.
eg.
x - c(14,15,12,11,12,13,14,15,16,15,14,13,12,11,14,12)
y - somefunction(x)

y
4 14


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


Re: [R] peak finding

2008-03-24 Thread Christos Hatzis
John,

There is a peak finding algorithm attributed to Prof. Ripley in the R-help
archive.  It has a span parameter which might give you something close to
what you seem to be looking for.

http://finzi.psych.upenn.edu/R/Rhelp02a/archive/33097.html 

-Christos

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Research Scholar
 Sent: Monday, March 24, 2008 11:24 PM
 To: [EMAIL PROTECTED]
 Cc: r-help@r-project.org
 Subject: Re: [R] peak finding
 
 Hi
  Thanks for replying. I meant x[4] is the start of a peak 
 shape and x[14] is the end of that peak and x[9] is the 
 maxima of the peak.
 Thanks,
 John
 
 
 
 
 On Mon, Mar 24, 2008 at 11:09 PM, [EMAIL PROTECTED] wrote:
 
  It's hard to see how positions 4 and 14 correspond to 'peaks', they 
  look like troughs to me.  So perhaps this is what you mean:
 
   x - c(14,15,12,11,12,13,14,15,16,15,14,13,12,11,14,12)
 
   y - which(x == min(x))
   y
  [1]  4 14
 
  as a function:
 
  somefunction - function(x) which(x == min(x))
 
 
  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 Research Scholar
  Sent: Tuesday, 25 March 2008 12:54 PM
  To: r-help@r-project.org
  Subject: [R] peak finding
 
  Hi all
   Is there a function that can find the start and end 
 position of peaks 
  in a set of numbers.
  eg.
  x - c(14,15,12,11,12,13,14,15,16,15,14,13,12,11,14,12)
  y - somefunction(x)
 
  y
  4 14
 
 
  Thanks
  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.htmlhttp://www.r-project.org/p
  osting-guide.html and provide commented, minimal, self-contained, 
  reproducible code.
 
 
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


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


Re: [R] Partition data into clusters

2008-03-24 Thread Suhaila Zainudin
Hi,

Thanks for your reply. I have tried yr suggestions with success. TQVM.

I have another query, say I want to write each cluster into a csv file such
as follows:

clus1 - my.clusters[[1]]
write.csv(clus1, file = clus1.csv)

.
.
clus10 - my.clusters[[10]]
write.csv(clus10,file = clus10.csv)

I can write the functions to do that for all 10 clusters by repeatedly
calling write.csv as  above. Is there a more elegant way of doing it by
using a loop (for example).

for(i in 1:xx) {
clusn - my.clusters[[n]]
write.csv(clusn, file = clusn.csv)
}

I am trying something using list as well, as folows:

names( my.clusters ) - paste('Cluster_',1:10, sep='')

Now I can  use

my.clusters$Cluster_1

The above will return all members of Cluster_1.

I have an idea to use lapply or sapply to do write.csv on each
components(Cluster_1.Cluster_n)  from my.clusters, that will do the same
as the loop example. Maybe this is the better way..


Any comments are appreciated.

Thanks!

[[alternative HTML version deleted]]

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


[R] Output of order() incorrectly ordered?

2008-03-24 Thread Shirley Wu
Hello,

I have a data frame consisting of four columns and would like to sort  
based on the first column and then write the sorted data frame to a  
file.

  df - read.table(file.txt, sep=\t)
where file.txt is simply a tab-delimited file containing 4 columns of  
data (first 2 numeric, second 2 character). I then do,

  df_ordered - df[order(df$V1), ]

OR, I assume equivalently,

  df_ordered - df[ do.call(order, df), ]

and then,

  write.table(df_ordered, file=newfile.txt, ...)

The input data file looks like this:

0.083044375.276 680220  majority
5.50816e-09 2.48914e-05 26377   conformation
0.000169618 0.7665051546938 interaction
3.90425e-05 0.1764331655338 vitamin
0.0378182   170.9   1510941 array
3.00359e-07 0.00135732  69421   oligo(dT)-cellulose
1.01517e-13 4.58754e-10 699918  elastase
...

I'd like the output file to look the same except sorted by the first  
column. The output of the commands above give me something that is  
sorted in some places but not sorted in others:

[sorted section]
...
1.87276e-07 0.000846299 1142090 vitamin K
1.89026e-07 0.000854207 917889  leader peptide
1.90884e-07 0.000862605 31206   s
0.00536062  24.2246 1706420 prevent
5.42648e-05 0.2452231513041 measured
5.42648e-05 0.2452231513040 measured
0.01993990.1044 12578   fly
0.00135512  6.12377 61688   GPI
0.00124421  5.62257 681915  content
0.0128271   57.9655 681916  estimated
...
[sorted section]
...
[unsorted section]
...
[etc]

I'm not sure if this is a problem with the input data or with order()  
or what. I am only doing this in R because many of my numeric values  
are expressed in exponential notation and UNIX sort does not handle  
this to my knowledge, but this behavior baffles me. I am pretty new  
to R so it's possible I'm missing something.

Any insight would be greatly appreciated!

Thanks,
-Shirley
graduate student
Stanford University

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


[R] Subset of matrix

2008-03-24 Thread dinesh kumar
Dear  R users

I have a big matrix like

  6021118879029011741015199066136288
100714
602110.6580.6880.4740.2620.1630.1370.32
0.2520.206
11880.65810.9170.2450.3310.1220.1480.194
0.1680.171
7900.6880.91710.2430.310.1220.150.19
0.1710.174
2900.4740.2450.24310.390.3190.1870.4
0.3110.235
11740.2620.3310.310.3910.2950.3520.345
0.3060.308
10150.1630.1220.1220.3190.29510.4210.343
0.4420.435
19900.1370.1480.150.1870.3520.42110.313
0.380.395
66130.320.1940.190.40.3450.3430.31310.58
0.429
62880.2520.1680.1710.3110.3060.4420.380.58
10.723
1007140.2060.1710.1740.2350.3080.4350.395
0.4290.7231
59510.220.1680.1710.2670.3180.4780.4090.478
0.8440.85
59600.2320.1830.1860.2720.3240.420.3830.522
0.6860.711
2360.2590.2130.2180.2830.3570.3820.40.549
0.6550.608
649560.1990.1720.1750.250.3550.4440.4750.523
0.6330.614
2390.1880.1690.1730.2370.3620.4630.50.469
0.5960.692
330320.250.1670.1690.3080.3010.4070.3460.486
0.6550.64
62620.2540.1780.1820.3140.3290.3960.360.459
0.6790.633
59610.2620.1890.1940.3110.3420.3620.3770.468
0.6210.574
59620.2430.1770.180.2980.3240.3890.3530.453
0.6670.62
63060.2260.1680.1710.2740.3060.3890.380.514
0.6980.62
61060.2260.1680.1710.2740.3060.3890.380.514
0.6980.62
62870.2080.1750.1780.250.3280.4290.4220.529
0.7710.689
59500.1930.1750.1790.230.3440.4650.50.448
0.7330.816
8330.3120.2440.2420.4080.4440.3280.3170.526
0.5620.517
7500.1680.1550.1570.2080.3390.5140.5150.385
0.5780.722
61370.2010.1680.1710.2390.3060.3890.380.453
0.6980.62
1457420.3170.2290.2360.3490.3250.3390.305
0.5190.5810.534
58100.3640.2160.2210.4110.2940.3380.2690.603
0.6310.47
8250.3640.2160.2210.4110.2940.3380.2690.603
0.6310.47
74050.3130.2460.2440.3550.3670.290.3170.537
0.5070.484
10450.1330.1240.1350.1980.3330.4410.3440.277
0.3620.341
11230.110.1060.1040.1570.2620.4150.3680.227
0.3040.333
5880.2810.3120.340.3030.4190.2780.40.287
0.3120.316

with more than thousand number of rows and column
I want to extract or subset a child matrix from above with specific row
names or col names.
e.g.
For above matrix I need only rows which has following row names.
5951 236 6306 5950 145742 1123

I would appreciate if you can use this matrix as input.

Thanks in advance.

Dinesh




-- 
Dinesh Kumar Barupal
Research Associate
Metabolomics Fiehn Lab
UCD Genome Center
451 East Health Science Drive
GBSF Builidng
University of California
DAVIS
95616
http://fiehnlab.ucdavis.edu/staff/kumar

[[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] peak finding

2008-03-24 Thread Andrew Robinson
Another approach that involves more infrastructure is to fit a smooth
line to your points, compute the first derivative, and look for change
in sign in the first derivative.

eg

x - c(14,15,12,11,12,13,14,15,16,15,14,13,12,11,14,12)

smoothed.dx - predict(smooth.spline(x), deriv=1)$y

which(c(smoothed.dx,NA)  0  c(NA, smoothed.dx)  0)



My experience is that this approach sometimes requires some
fine-tuning, eg in fitting the smooth.

I hope that this helps

Andrew


On Mon, Mar 24, 2008 at 11:23:57PM -0400, Research Scholar wrote:
 Hi
  Thanks for replying. I meant x[4] is the start of a peak shape and x[14] is
 the end of that peak and x[9] is the maxima of the peak.
 Thanks,
 John
 
 
 
 
 On Mon, Mar 24, 2008 at 11:09 PM, [EMAIL PROTECTED] wrote:
 
  It's hard to see how positions 4 and 14 correspond to 'peaks', they look
  like troughs to me.  So perhaps this is what you mean:
 
   x - c(14,15,12,11,12,13,14,15,16,15,14,13,12,11,14,12)
 
   y - which(x == min(x))
   y
  [1]  4 14
 
  as a function:
 
  somefunction - function(x) which(x == min(x))
 
 
  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 Research Scholar
  Sent: Tuesday, 25 March 2008 12:54 PM
  To: r-help@r-project.org
  Subject: [R] peak finding
 
  Hi all
   Is there a function that can find the start and end position of peaks
  in a
  set of numbers.
  eg.
  x - c(14,15,12,11,12,13,14,15,16,15,14,13,12,11,14,12)
  y - somefunction(x)
 
  y
  4 14
 
 
  Thanks
  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.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.

-- 
Andrew Robinson  
Department of Mathematics and StatisticsTel: +61-3-8344-6410
University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599
http://www.ms.unimelb.edu.au/~andrewpr
http://blogs.mbs.edu/fishing-in-the-bay/

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

2008-03-24 Thread Lavan

hi thanks,
pls see the code below. the elements of matrix Il should be the derivatives
in matrix h (in Boldface) plus some additional terms, here I did calculate
derivatoves in the matrix, but I want R to calculate it for me. 


pid- function (tau1,tau2,sigma=10,n=100,x_bar=20) {

library(akima)
library(lattice)
library(rgl)

a1  - 1.5
a2  - 4

t1  -seq(-1,1);
t2  -seq(3,4);

l   -length(t1);
m   -length(t2);

N1  - matrix(NA,l,m);
N2  - matrix(NA,l,m);
wp  - matrix(NA,l,m);
rr  - matrix(NA,l,m);
N   - matrix(NA,l,m);
mu  - matrix(NA,l,m);
Il  - matrix(NA,l,m);
iIl - matrix(NA,l,m);

theta   -expression(x+y);
dx  -D(theta, x);
dy  -D(theta, y); 

d2x -D(dx, x);
dxy -D(dx, y); 
dyx -D(dy, x);
d2y -D(dy, y);

h   - matrix(c(d2x,dxy,dyx,d2y),nrow=2,ncol=2); 

for (i in 1:l)
{
for (j in 1:m)
{
wp[i,j]-((t1[i]-a1)/tau1)^2+((t2[j]-a2)/tau2)^2
mu[i,j] -(t1[i] + t2[j]);
Il[i,j]
-matrix(c(n/(sigma^2)+1/(tau1^2),n/(sigma^2),n/(sigma^2),n/(sigma^2)+1/
 
tau2^2)),2,2);
iIl -solve(Il);
ul[i,j] -
(c(n*(x_bar-mu[i,j])/(sigma^2)-(t1[i]-a1)/(tau1^2),n*(x_bar-mu[i,j])/   

(sigma^2)-(t2[j]-a2)/(tau2^2)));
ul -matrix(c(n*(x_bar-mu)/(sigma^2)-(theta1-a1)/(tau1^2),n*(x_bar-mu)/ 

(sigma^2)-(theta2-a2)/(tau2^2)),2,1);
ult -t(ul);
wl[i,j] -t(ul)%*%solve(Il,ul);
rr[i,j] -(wp[i,j]/wl[i,j]);
N[i,j]  -(wl[i,j]-wp[i,j])/wl[i,j]
 }
  }

   list(Test Statistics Wp= wp,Stat Ratio=rr, N=N,N1=N1,
N2=N2, mean=mu, Il=Il,
   inverse of Il=iIl)
}

-- 
View this message in context: 
http://www.nabble.com/derivatives-in-R-tp16265419p16267397.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] Partition data into clusters

2008-03-24 Thread Suhaila Zainudin
Hi,

Just to inform you that I found the solution for the write.csv  task I
mentioned earlier. Searching thru the r-help leads me to this solution..

###Your soln starts
xx  - max(cl2$cl.kmr10.cluster)
# find out how many clusters there are.
my.clusters - list(NULL)  # set up an empty list for storage

#  Loop through the dataset and subset by cluster.
for(i in 1:xx) {
 my.clusters[[i]] - subset(cl2,
cl2$cl.kmr10.cluster==i)
 }
# Eh voilà!
my.clusters


### Your solution ends

# Soln for writing the clustered results into multiple files using loop.


for(i in 1:xx) {
  write.csv(my.clusters[[i]], paste(mycluster,i,sep=.))
}



Regards

suhaila

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