Re: [R] lattice panel.lmline problem

2007-09-10 Thread Frede Aakmann Tøgersen
Why not use the more simple

xyplot(total.fat~x|variable,groups=Group,
   data=tmp1,type=c(p,r))

???

See ?panel.xyplot and especially the type argument of that panel function.




Best regards

Frede Aakmann Tøgersen
Scientist


UNIVERSITY OF AARHUS
Faculty of Agricultural Sciences
Dept. of Genetics and Biotechnology
Blichers Allé 20, P.O. BOX 50
DK-8830 Tjele

Phone:   +45 8999 1900
Direct:  +45 8999 1878

E-mail:  [EMAIL PROTECTED]
Web:   http://www.agrsci.org

This email may contain information that is confidential.
Any use or publication of this email without written permission from Faculty of 
Agricultural Sciences is not allowed.
If you are not the intended recipient, please notify Faculty of Agricultural 
Sciences immediately and delete this email.


 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af Ross Darnell
 Sendt: 10. september 2007 07:55
 Til: r-help@stat.math.ethz.ch
 Emne: [R] lattice panel.lmline problem
 
 I am wanting to generate panels showing scatterplots with the 
 linear fitted line for two groups within each panel superimposed.
 
 I have two conditioning factors, variable and Group and I 
 want separate panels for each level of variable
 
 with different symbols and lmlines for each level of 
 Group. However all observations for a group are missing for 
 some variables so I would still like the points and lmline 
 for the observed group plotted for that variable(panel).
 
  
 
 My attempt is 
 
  
 
 print(xyplot(total.fat~x|variable,data=tmp1,subscripts=TRUE,
 
  
 scales=list(x=list(relation=free)),xlab=,groups=Group,
 
  panel=function(x,y,subscripts,...){
 
panel.superpose(x,y,subscripts,...)
 
if(length(x[subscripts])!=0)
 
  
 {panel.superpose(x,y,panel.groups=panel.lmline,subscripts,...)}}))
 
  
 
 Which gives an error
 
  
 
 Error in lm.fit(x, y, offset = offset, singular.ok = 
 singular.ok, ...) :
 
 
 0 (non-NA) cases
 
  
 
  
 
 Which occurs when the first panel with all values for one 
 group are missing.
 
 The same error is returned if I replace the last line without the if
 statement which obviously means it's ignored.
 
  
 
 Of course I may be taking the wrong tack completely to get 
 the result I need. Any advice would be appreciated
 
   
 
  
 
 Ross Darnell
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] overlay lattice histograms with goodness-of-fit pdfs

2007-09-10 Thread Frede Aakmann Tøgersen

The following is one of the examples in the help page for histogram:

 histogram( ~ height | voice.part, data = singer,
   xlab = Height (inches), type = density,
   panel = function(x, ...) {
   panel.histogram(x, ...)
   panel.mathdensity(dmath = dnorm, col = black,
 args = list(mean=mean(x),sd=sd(x)))
   } )

This should give you some thing to start from.

Also using the subset argument of the lattice functions will make make your 
code more readable. Instead of your code

histogram(~ data | month * station,
data = sta.stack[sta.stack[,type]==precip  
(sta.stack[,month]==Dec | sta.stack[,month]==Jan | 
sta.stack[,month]==Feb),],
xlab = Precipitation (mm))

you can use (not tested because you didn't supply a reproducable example)

histogram(~ data | month * station, data = sta.stack
subset = type==precip  month %in% c(Dec, Jan, Feb),
xlab = Precipitation (mm))


Med venlig hilsen
Frede Aakmann Tøgersen
 

 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af Brad 
 Christoffersen
 Sendt: 10. september 2007 12:08
 Til: R-help@stat.math.ethz.ch
 Emne: [R] overlay lattice histograms with goodness-of-fit pdfs
 
 Hello,
 
 I am new to R exploratory data analysis and plotting.  Is 
 anyone aware of a way to overlay a set of conditional 
 histograms with conditional PDFs?  Below, I generate a 
 lattice plot of precipitation histograms based on different 
 months and stations, given a subset of the dataset:
 
 
 histogram(~ data | month * station,
   data = sta.stack[sta.stack[,type]==precip  
 (sta.stack[,month]==Dec | sta.stack[,month]==Jan | 
 sta.stack[,month]==Feb),],
   xlab = Precipitation (mm))
 
 
 I previously used a combination of the low-level 'lines()' 
 and 'dgamma()'
 functions to overlay a gamma PDF onto a single histogram.  
 Now what I would like to do is to do the same thing, but with 
 a function that allows me to specify a formula similar to 
 that in the histogram function above
 
 [SomeKindOfPDF] ~ [x-range] | month * station
 
 which will plot the PDF with the appropriate factors (month 
 and station).
 
 All I'm looking for is for someone to get me going in the 
 right direction with a useful package or function to use.
 
 Any help is much appreciated!
 Brad Christoffersen
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] contourplot lines, text, and mtext

2007-09-06 Thread Frede Aakmann Tøgersen
To learn more about panel functions see the help page for xyplot and especially 
the panel argument.
 
You can get what you want by 
 

contourplot(z~x*y,data=grid,region=T,
col.regions=gray(seq(1,0,len=255)),
colorkey=T,cuts=50,contour=F,
panel = function(x,y,z,...){
  panel.contourplot(x,y,z,...)
  llines(x=c(-5,5),y=c(-5,5),lwd=5,col=blue)
})

or

contourplot(z~x*y,data=grid,region=T,
col.regions=gray(seq(1,0,len=255)),
colorkey=T,cuts=50,contour=F,
panel = function(x,y,z,...){
  panel.contourplot(x,y,z,...)
  panel.abline(0,1,lwd=5,col=blue)
})

 
Med venlig hilsen / Regards

Frede Aakmann Tøgersen
Forsker / Scientist



 AARHUS UNIVERSITET / UNIVERSITY OF AARHUS  
Det Jordbrugsvidenskabelige Fakultet / Faculty of Agricultural Sciences 
Inst. for Genetik og Bioteknologi / Dept. of Genetics and Biotechnology 
Blichers Allé 20, P.O. BOX 50   
DK-8830 Tjele   

Tel: +45 8999 1900  
Direct:  +45 8999 1878  
Mobile:  +45
E-mail:  [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]   
Web: www.agrsci.dk 
https://djfpost.agrsci.dk/exchweb/bin/redir.asp?URL=http://www.agrsci.dk/ 
 


Tilmeld dig DJF's nyhedsbrev / Subscribe Faculty of Agricultural Sciences 
Newsletter 
https://djfpost.agrsci.dk/exchweb/bin/redir.asp?URL=http://www.agrsci.dk/user/register?lan=dan-DK
 . 

Denne email kan indeholde fortrolig information. Enhver brug eller 
offentliggørelse af denne email uden skriftlig tilladelse fra DJF er ikke 
tilladt. Hvis De ikke er den tiltænkte adressat, bedes De venligst straks 
underrette DJF samt slette emailen.

This email may contain information that is confidential. Any use or publication 
of this email without written permission from Faculty of Agricultural Sciences 
is not allowed. If you are not the intended recipient, please notify Faculty of 
Agricultural Sciences immediately and delete this email.

 



Fra: [EMAIL PROTECTED] på vegne af Richard D. Morey
Sendt: fr 07-09-2007 03:28
Til: r-help@stat.math.ethz.ch
Emne: [R] contourplot lines, text, and mtext



If I have a contourplot (in the lattice package) and I want to add
straight lines to it, how do I do this?

I see that there are llines() and lsegement() functions for lattice
plots, but they don't seem to do anything in this case:

library(lattice)
library(KernSmooth)
x=rnorm(1)
y=x+rnorm(x,0,.5)
a=bkde2D(cbind(x,y),.7)
z=as.vector(a$fhat)
grid=expand.grid(x=a$x1,y=a$x2)
grid$z=z
contourplot(z~x*y,data=grid,region=T,col.regions=gray(seq(1,0,len=255)),colorkey=T,cuts=50,contour=F)
llines(x=c(-5,5),y=c(-5,5))
  NULL
lsegments(x0=-5,y0=-5,x1=5,y1=5)

I'm just trying to do the equivalent of abline(0,1) on the plot.

ltext(), on the other hand, seems to like to place text in the upper
left corner of the plot. I suspect that I misunderstand the coordinate
system that lattice uses for contour plots. Can anyone enlighten me?

Richard


--
Richard D. Morey, M.A.
Research Assistant, Perception and Cognition Lab
University of M
issouri-Columbia

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] [Lattice] Incrase the height of strips in Trellis plots

2007-09-05 Thread Frede Aakmann Tøgersen
This should give you something close to what you want:


xyplot(Petal.Length ~ Petal.Width | Species, iris,
   strip = strip.custom(par.strip.text = list(cex = 2)),
   par.settings = list(layout.heights=list(strip=1.45)))

The par.settings argument alters locally the default par settings of lattice 
plots, see e.g. ?trellis.par.get and the ?xyplot about the par.settings 
argument.

A closer inspection (try using strip = 2 or numbers less than 1.45 in stead of 
strip = 1.45) of the figure reveals that there are some problems with vertical 
alignment of the strip text, i.e. not centered. 

To remedy this I think that you have to use you own strip function. You may be 
able to build you own function by altering the default strip function, see 
?lattice.options and try lattice.options() at the command prompt. However this 
may be more difficult than it seems at first. Perhaps some one more familiar 
with the lattice package can solve this.
 

Best regards

Frede Aakmann Tøgersen
Scientist


UNIVERSITY OF AARHUS
Faculty of Agricultural Sciences
Dept. of Genetics and Biotechnology
Blichers Allé 20, P.O. BOX 50
DK-8830 Tjele

Phone:   +45 8999 1900
Direct:  +45 8999 1878

E-mail:  [EMAIL PROTECTED]
Web:   http://www.agrsci.org

This email may contain information that is confidential.
Any use or publication of this email without written permission from Faculty of 
Agricultural Sciences is not allowed.
If you are not the intended recipient, please notify Faculty of Agricultural 
Sciences immediately and delete this email.


 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af Bernd Weiss
 Sendt: 5. september 2007 06:48
 Til: r-help@stat.math.ethz.ch
 Emne: [R] [Lattice] Incrase the height of strips in Trellis plots
 
 Dear all,
 
 I wonder how to increase the height of strips via 
 strip.default or strip.custom. The following example 
 hopefully illustrates the difficulty I am facing:
 
 library(lattice)
 xyplot(Petal.Length ~ Petal.Width | Species, iris,
 strip = strip.custom(par.strip.text = list(cex = 2)))
 
 Thanks for any advice,
 
 Bernd
 
 
  version
_
 platform   i386-pc-mingw32
 arch   i386
 os mingw32
 system i386, mingw32
 status
 major  2
 minor  5.1
 year   2007
 month  06
 day27
 svn rev42083
 language   R
 version.string R version 2.5.1 (2007-06-27)
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] nls() and numerical integration (e.g. integrate()) workingtogether?

2007-08-23 Thread Frede Aakmann Tøgersen
Michael, it should be possible to get nls and integrate to work together. 
Bt, there are several problems you need to consider first. The most 
important is the definition of e.g. your f-function and how integrate() work. 
The easiest way to show you the problem is like in the following.

The integrate() has an ... argument through which you can pass additional 
arguments to your integrand. Let's define

f - function(z,x1,b1) {z + b1*x1}

where z is the variable of integration and x1 and b1 is thought of as 
parameters. We pass the parameters x1 and b1 to f through the ... argument of 
integrate() later on (see ?integrate).

Now since integrate() is an adaptive integration rutine you'll find, that 
integrate() based on some rule decides to partition the interval of integration 
(here (0,1)) into a number of subintervals. integrate() then evaluates f() in 
the points defining the partition and uses some quadrature rule to estimate the 
integral and its associated error. If the error is above the tolerance then 
integrate() makes further subdivision. The most important consequence of this 
is that you do not know the length of the vector z that is passed to f() by 
integrate(). Most likely this length is different from the length of x1. You 
can see this by trying out the following code:

f - function(z,x1,b1) {
  print(z)
  print(b1)
  print(x1)
  z + b1*x1
}

# f is a vectorized funtion: try f(c(2,3),x1,b1=.5), so why use Vectorize()?

Now integrate f from 0 to 1.

integrate(f,0,1,x1=x1,b1=.5)

Note that we have the parameters x1 and b1 to f through the ... argument. 

You'll see some error message relating to the problem with different lengths of 
vectors.

You need to resolve this problem before continuing.


Med venlig hilsen / Regards

Frede Aakmann Tøgersen
Forsker / Scientist

  
   AARHUS UNIVERSITET / UNIVERSITY OF AARHUS 
Det Jordbrugsvidenskabelige Fakultet / Faculty of Agricultural Sciences 
Inst. for Genetik og Bioteknologi / Dept. of Genetics and Biotechnology 
Blichers Allé 20, P.O. BOX 50 
DK-8830 Tjele 
  
Tel: +45 8999 1900 
Direct: +45 8999 1878 
Mobile: +45  
E-mail: [EMAIL PROTECTED] 
Web: www.agrsci.dk 
 


Tilmeld dig DJF's nyhedsbrev / Subscribe Faculty of Agricultural Sciences 
Newsletter. 

Denne email kan indeholde fortrolig information. Enhver brug eller 
offentliggørelse af denne email uden skriftlig tilladelse fra DJF er ikke 
tilladt. Hvis De ikke er den tiltænkte adressat, bedes De venligst straks 
underrette DJF samt slette emailen.

This email may contain information that is confidential. Any use or publication 
of this email without written permission from Faculty of Agricultural Sciences 
is not allowed. If you are not the intended recipient, please notify Faculty of 
Agricultural Sciences immediately and delete this email.

 

 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af Michael Lindner
 Sendt: 23. august 2007 08:07
 Til: r-help@stat.math.ethz.ch
 Emne: [R] nls() and numerical integration (e.g. integrate()) 
 workingtogether?
 
 Dear List-Members,
 
 since 3 weeks I have been heavily working on reproducing the 
 results of an economic paper. The method there uses the 
 numerical solution of an integral within nonlinear least 
 squares. Within the integrand there is also some parameter to 
 estimate. Is that in the end possible to implement in R 
 [Originally it was done in GAUSS]? I'm nearly into giving up.
 
 I constucted an example to showing the problems I face.
 
 I have three questions - related to three errors shown below: 
 1) How to make clear that in the integrand z is the 
 integration variable and
 b1 is a parameter while x1 is a data variable
 2) and 3) How to set up a correct estimation of the integral?
 
 library(stats)
 y - c(2,15,24,21,5,6,)
 x1 - c(2.21,5,3,5,2,1)
 x2 - c(4.51,6,2,11,0.4,3)
 f - function(z) {z + b1*x1}
 vf - Vectorize(f)
 g - function(z) {z + x1}
 vg - Vectorize(f)
 
 Error 1: 
  nls(y ~ integrate(vf,0,1)+b2*x2,start=list(b1=0.5,b2=2))
 Error in function (z)  : object b1 not found
 
 Error 2:
  nls(y ~ integrate(vg,0,1)+b2*x2,start=list(b1=0.5,b2=2))
 Error in integrate(vg, 0, 1) : REAL() can only be applied to 
 a 'numeric', not a 'list'
 
 Error 3:
  nls(y ~ integrate(g,0,1)+b2*x2,start=list(b1=0.5,b2=2))
 Error in integrate(g, 0, 1) + b2 * x2 : non-numeric argument 
 to binary operator In addition: Warning messages:
 1: longer object length
 is not a multiple of shorter object length in: z + x1
 
 With a lot of thanks in advance,
 
 Michael
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/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

Re: [R] R and excell differences in calculation F distributionfunction

2007-08-07 Thread Frede Aakmann Tøgersen
I think you'll have to compare FDIST to pf() and not df()



Best regards

Frede Aakmann Tøgersen
Scientist


UNIVERSITY OF AARHUS
Faculty of Agricultural Sciences
Dept. of Genetics and Biotechnology
Blichers Allé 20, P.O. BOX 50
DK-8830 Tjele

Phone:   +45 8999 1900
Direct:  +45 8999 1878

E-mail:  [EMAIL PROTECTED]
Web:   http://www.agrsci.org

This email may contain information that is confidential.
Any use or publication of this email without written permission from Faculty of 
Agricultural Sciences is not allowed.
If you are not the intended recipient, please notify Faculty of Agricultural 
Sciences immediately and delete this email.


 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af Luis Ridao Cruz
 Sendt: 7. august 2007 12:27
 Til: r-help@stat.math.ethz.ch
 Emne: [R] R and excell differences in calculation F 
 distributionfunction
 
 R-help,
 
 I'm trying to work out the density function by doing:
 
  df(5.22245, 3, 22)
 [1] 0.005896862
 
  df(15.20675, 6, 4)
 [1] 0.001223825
 
 
 In excell the result is :
 
 0.0071060464 *   FDIST(5.22245,3,22) 
 
 0.011406 --   FDIST(15.20675,6,4)
 
 
 From my point of view the differences in the second case
 are substantial.
 
 Can anyone give me a hint on this?
 
 Thanks in advance
  
 
 
 
 
 
 
 
 Luis Ridao Cruz
 Faroese Fisheries Laboratory
 Nóatún 1, P.O. Box 3051
 FR-110 Tórshavn
 Faroe Islands
 Tel : (+298) 353900, Tel (direct) : (+298) 353912
 Mob.:(+298) 580800, Fax: : (+298) 353901
 E-mail: [EMAIL PROTECTED]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Problems using lm in combination with predict

2007-08-06 Thread Frede Aakmann Tøgersen
 
 My modelmatrix is of dimension  28x4
 
 Then I want to make use of the function predict because there 
 confidence.intervals are include.
 
 My idea was:
 
 mod - lm(y~Worktime+Vacation+Illnes+Bankholidays)
 
 newdate=data.frame(x=c(324,123,0.9,0.1))


Perhaps you want to specify newdate like this

newdate=data.frame(Worktime = 324, Vacation = 123, Illness = 0.9, Bankholidays 
= 0.1))?



Best regards

Frede Aakmann Tøgersen
Scientist


UNIVERSITY OF AARHUS
Faculty of Agricultural Sciences
Dept. of Genetics and Biotechnology
Blichers Allé 20, P.O. BOX 50
DK-8830 Tjele

Phone:   +45 8999 1900
Direct:  +45 8999 1878

E-mail:  [EMAIL PROTECTED]
Web:   http://www.agrsci.org

This email may contain information that is confidential.
Any use or publication of this email without written permission from Faculty of 
Agricultural Sciences is not allowed.
If you are not the intended recipient, please notify Faculty of Agricultural 
Sciences immediately and delete this email.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] getting values from arrays using which()

2007-07-05 Thread Frede Aakmann Tøgersen

ndx - which(myArray=99 , ind.arr=T)

cbind(ndx, myArray[ndx])



Best regards

Frede Aakmann Tøgersen
Scientist


UNIVERSITY OF AARHUS
Faculty of Agricultural Sciences
Dept. of Genetics and Biotechnology
Blichers Allé 20, P.O. BOX 50
DK-8830 Tjele

Phone:   +45 8999 1900
Direct:  +45 8999 1878

E-mail:  [EMAIL PROTECTED]
Web:   http://www.agrsci.org

This email may contain information that is confidential.
Any use or publication of this email without written permission from Faculty of 
Agricultural Sciences is not allowed.
If you are not the intended recipient, please notify Faculty of Agricultural 
Sciences immediately and delete this email.



Med venlig hilsen
Frede Aakmann Tøgersen
 

 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af Jabez Wilson
 Sendt: 5. juli 2007 12:21
 Til: R-Help
 Emne: [R] getting values from arrays using which()
 
 Dear R-Help,
 
 I have an array 1260x1260, upper triangle consisting of 
 numbers between 0 and 100, and lower triangle all NA. I can 
 extract the index of those values say above 99 using the 
 following code:
 which(myArray=99 , ind.arr=T)
 
 which returns:
row  col
 5475   252  253
 45423  764  765
 46902  777  778
 34146  611  962
 50681 1220 1221
 
 Now I would like to if poss print the actual value contained 
 in the index as well so it would look like:
 
row  col
 5475   252  25399  
 45423  764  76596.5
 46902  777  77899
 34146  611  962100
 50681 1220 1221100
 
 Can this be done?
 
 
   ___ 
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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 difftime function: How can we fix the difftime unit?

2007-03-21 Thread Frede Aakmann Tøgersen
That's easy:
 
difftime(x, y, units = min)
 
Best regards
 
Frede



Fra: [EMAIL PROTECTED] på vegne af d. sarthi maheshwari
Sendt: to 22-03-2007 07:03
Til: r-help@stat.math.ethz.ch
Emne: [R] R difftime function: How can we fix the difftime unit?



Hi,

I am trying to take difference of two time objects. I want to fix the
result's unit to minutes. How can I do that?

Here is an example:

 difftime(x, y)
Time difference of 2.030720 hours
 difftime(x, z)
Time difference of 30.34672 mins

where x = '2007-03-05 08:32:58'
  y = '2007-03-05 06:31:07'
andz = '2007-03-05 08:02:37'

How can I get answer something like

for (x-y)
Time difference of 121.8432 mins

and for (x-z)
Time difference of 30.34672 mins

Kindly help.

--
Thanks  Regards
Sarthi M.

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] CPU usage on Windows

2007-03-19 Thread Frede Aakmann Tøgersen
(cc'ing ESS mailing list to which this belongs) 
 
I have been using Emacs, ESS, and R on Windows for several years now. It works 
all together to allmost full satisfaction. Thanks to all people providing these 
tools.
 
I haven't noticed this specific problem, but I guess it is related to what I 
see from time to time when using R, Emacs and ESS to do graphics. I am not 
really into all the details to how Emacs and R communicates through ESS (using 
ddeclinet) but here is something that perhaps can provide useful information to 
more skilled persons.
 
I think it has to do with the way that R og Emacs communicates through 
ddeclient. Normally Emacs waits for R to finish by looking for the next command 
prompt from R indicating that R is finished with the commands submitted to R by 
Emacs/ESS. This means that Emacs can be busy waiting for R to finish which is 
most noticeable when submitting chunks of commands using e.g. C-c C-r (submit a 
region). Emacs/ESS then waits for R to finish each command in the region 
waiting for a signal on a clear command prompt before submitting the next 
command. This can be overriden by using C-c A-r (A = meta (unix) or Alt 
(windows)).
 
What I have noticed is that when I have made a plot and R creates the graphics 
windows. Then R og and the graphics windows from time to time hang (not being 
updated) when I want to focus on the graphics window (to put in front) 
subsequently. In this situation it helps to go to the buffer with the inferior 
ESS process and do a carriage return, which immediately frees the graphics 
windows and now it is getting updated when put in front.
 
This behaviour which I believe is due to the way that Emacs and R communicates 
over ddeclient is not persistent and until now I have hesitated to report it 
because I couldn't provide a small reproducable example. I have noticed this 
over several versions of Emacs (21.2 - 22.1), ESS ( 5 - 5.4) and Windows 
98/NT/XP. 
 
 
Frede Aakmann Tøgersen
Forsker / Scientist



 AARHUS UNIVERSITET / UNIVERSITY OF AARHUS  
Det Jordbrugsvidenskabelige Fakultet / Faculty of Agricultural Sciences 
Forskningscenter Foulum / Research Centre Foulum
Genetik og Bioteknologi / Dept. of Genetics and Biotechnology   
Blichers Allé 20, P.O. BOX 50   
DK-8830 Tjele   

Tel: +45 8999 1900  
Direct:  +45 8999 1878  
Mobile:  +45
E-mail:  [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]   
Web: www.agrsci.dk 
https://djfpost.agrsci.dk/exchweb/bin/redir.asp?URL=http://www.agrsci.dk/ 
 



Fra: [EMAIL PROTECTED] på vegne af Duncan Murdoch
Sendt: lø 17-03-2007 00:37
Til: Jonathan Wang
Cc: r-help@stat.math.ethz.ch
Emne: Re: [R] CPU usage on Windows



On 3/16/2007 6:56 PM, Jonathan Wang wrote:
 I'm using R with emacs  ESS on Windows. When I create a plot, sometimes R
 will seem to get stuck in a busy loop, i.e. it will use 100% of my CPU.
 However the system is still somewhat responsive, and the problem usually
 goes away if I create a new device with windows(). If I then close this
 device, making the first device active again, sometimes R will get stuck in
 the busy loop again.

 Has anybody heard of this behavior, or, better yet, have a solution?

I've heard of a number of problems with Emacs on Windows.  I wouldn't
recommend using it.  As far as I can see, it makes a number of
assumptions about the OS that just aren't true about Windows.

If you can reproduce the behaviour outside of Emacs, I'll investigate.

Duncan Murdoch

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


Re: [R] Extracting a subset from a dataframe

2007-02-22 Thread Frede Aakmann Tøgersen
Augusto

cnd - D1$dates %in% D2$dates
D1[!cnd,]

should do it.
 
Med venlig hilsen / Regards

Frede Aakmann Tøgersen
Forsker / Scientist



 AARHUS UNIVERSITET / UNIVERSITY OF AARHUS  
Det Jordbrugsvidenskabelige Fakultet / Faculty of Agricultural Sciences 
Forskningscenter Foulum / Research Centre Foulum
Genetik og Bioteknologi / Dept. of Genetics and Biotechnology   
Blichers Allé 20, P.O. BOX 50   
DK-8830 Tjele   

Tel: +45 8999 1900  
Direct:  +45 8999 1878  
Mobile:  +45
E-mail:  [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]   
Web: www.agrsci.dk 
https://djfpost.agrsci.dk/exchweb/bin/redir.asp?URL=http://www.agrsci.dk/ 
 


Tilmeld dig DJF's nyhedsbrev / Subscribe Faculty of Agricultural Sciences 
Newsletter 
https://djfpost.agrsci.dk/exchweb/bin/redir.asp?URL=http://www.agrsci.dk/user/register?lan=dan-DK
 . 

Denne email kan indeholde fortrolig information. Enhver brug eller 
offentliggørelse af denne email uden skriftlig tilladelse fra DJF er ikke 
tilladt. Hvis De ikke er den tiltænkte adressat, bedes De venligst straks 
underrette DJF samt slette emailen.

This email may contain information that is confidential. Any use or publication 
of this email without written permission from Faculty of Agricultural Sciences 
is not allowed. If you are not the intended recipient, please notify Faculty of 
Agricultural Sciences immediately and delete this email.

 



Fra: [EMAIL PROTECTED] på vegne af [EMAIL PROTECTED]
Sendt: fr 23-02-2007 07:26
Til: R-help@stat.math.ethz.ch
Emne: [R] Extracting a subset from a dataframe



Good day everyone,

Can anyone suggest an effective method to solve
the following problem:

I have 2 dataframes D1 and D2 as follows:

D1:
dates   ws   wc pwc
 2005-10-19:12:00  10.8  80  81
 2005-10-20:12:00  12.3   5  15
 2005-10-21:15:00  12.3   3  15
 2005-10-22:15:00  11.3  13  95
 2005-10-23:12:00  12.3  13   2
 2005-10-24:15:00  10.3   2  95
 2005-10-25:15:00  10.3   2   2

D2:
dates   ws   wc  pwc
 2005-02-02:15:00  17.5   5  96
 2005-02-19:15:00  20.1  15  97
 2005-02-20:18:00  16.5  95  95
 2005-03-03:18:00  10.3  95  95
 2005-03-04:00:00  13.4  13  95
 2005-10-22:15:00  11.3  13  95
 2005-10-25:15:00  10.3   2   2

I want to create another dataframe made up
of the values of dataframe1 which are not common
with dataframe2, ie. newD = D1 - (D1 intersection D2)

that is,
newD:
   datesws   wc  pwc
 2005-10-19:12:00  10.8  80  81
 2005-10-20:12:00  12.3   5  15
 2005-10-21:15:00  12.3   3  15
 2005-10-23:12:00  12.3  13   2
 2005-10-24:15:00  10.3   2  95

Thanks for any help you can provide,

Augusto


Augusto Sanabria. MSc, PhD.
Mathematical Modeller
Risk Research Group
Geospatial  Earth Monitoring Division
Geoscience Australia (www.ga.gov.au)
Cnr. Jerrabomberra Av.  Hindmarsh Dr.
Symonston ACT 2601
Ph. (02) 6249-9155

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] importing timestamp data into R

2007-01-04 Thread Frede Aakmann Tøgersen
Suppose that you have the timestamps in a comma seperated text file, 
times.dat then do

tid - read.csv(times.dat, header = TRUE, colClasses = character)

# Note the colClasses argument! If not used the columns of tid are factors by 
default.

time.conv - function(x) as.POSIXct(strptime(x, format = [%Y/%m/%d %H:%M:%S 
]))

# The value of strptime has class POSIXlt and needs to be converted to 
POSIXct

tid2 - tid
for (i in 1:2) tid2[,i] - time.conv(tid2[,i])

print(tid2)
str(tid2)
class(tid2[,1])

Med venlig hilsen
Frede Aakmann Tøgersen
 

 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af sj
 Sendt: 4. januar 2007 22:39
 Til: r-help@stat.math.ethz.ch
 Emne: [R] importing timestamp data into R
 
 I have a set of timestamp data that I have in a text file 
 that I would like to import into R for analysis.
 The timestamps are formated as follows:
 
 DT_1,DT_2
 [2006/08/10 21:12:14 ],[2006/08/10 21:54:00 ] [2006/08/10 
 20:42:00 ],[2006/08/10 22:48:00 ] [2006/08/10 20:58:00 
 ],[2006/08/10 21:39:00 ]
 [2006/08/04 12:15:24 ],[2006/08/04 12:20:00 ]
 [2006/08/04 12:02:00 ],[2006/08/04 14:20:00 ]
 
 I can get them into R but I cannot figure out how to convert 
 them into something R will recognize as a date/time. I have 
 tried using as.Date, strptime, and chron. Any help would be 
 appreciated?
 
 best,
 
 Spencer
 
 
 
 On 1/4/07, Darin A. England [EMAIL PROTECTED] wrote:
 
 
  Does anyone know a reason why, in principle, a call to randomForest 
  cannot accept a data frame with missing predictor values? If each 
  individual tree is built using CART, then it seems like 
 this should be 
  possible. (I understand that one may impute missing values using 
  rfImpute or some other method, but I would like to avoid doing
  that.)
 
  If this functionality were available, then when the trees are being 
  constructed and when subsequent data are put through the 
 forest, one 
  would also specify an argument for the use of surrogate rules, just 
  like in rpart.
 
  I realize this question is very specific to randomForest, 
 as opposed 
  to R in general, but any comments are appreciated. I suppose I am 
  looking for someone to say It's not appropriate, and 
 here's why ... 
  or Good idea. Please implement and post your code.
 
  Thanks,
 
  Darin England, Senior Scientist
  Ingenix
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] About compositional data analysis

2006-10-17 Thread Frede Aakmann Tøgersen
Well, one place to start is to read the following vignette

http://finzi.psych.upenn.edu/R/library/compositions/doc/UsingCompositions.pdf

This was found using the search function

RSiteSearch(compositional data)

in R.

You may also want to study

@Article{aitchison82, 
author = J. Aitchison, 
title = The statistical analysis of compositional data, 
journal = jrssb, 
year = 1982, 
volume = 44, 
number = 2, 
pages = 139-177, 
annote = With discussion. }

@Book{aitchison86, author = J. Aitchison, 
title = The Statistical Annalysis of Compositional Data, 
publisher = Chapman and Hall, 
year = 1986, 
series = Monographs on Statistics and Applied Probability, 
address = London, 
annote = A greatly expanded version of the original 1982 paper, with lots of 
examples of hypothesis testing }


Med venlig hilsen
Frede Aakmann Tøgersen
 

 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af S.Q. WEN
 Sendt: 17. oktober 2006 06:50
 Til: R-help@stat.math.ethz.ch
 Emne: [R] About compositional data analysis
 
 The compositional data xi=(x_i1,x_i2,...,x_in),  for each 
 fixed i  ,  xij0,
 and   sum(xij)=1;
 
 
 I want to compare the mean( u_i) of several groups i.e.
 H0: u_1=u_2=...=u_N
 or
 H0: u_11=u_21=...=u_N1
 
 Are there any ANOVA tpye tools  to do this work in R?
 
 Thanks,
 WEN S Q
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Different result from nls in R-2.2.1 and R-2.3.1

2006-09-21 Thread Frede Aakmann Tøgersen


Short story: January 2006 I did some analysis in R-2.2.1 using nls. Repeating 
the exercise in R-2.3.1 yesterday produced somewhat different results. 

After some debugging I found that either nls is the problem or that mine 
understanding of environments or scoping rules is lacking something.

This is a short reproducing example.



x - seq(0,5,len=20)

n - 1
y - 2*x^2 + n + rnorm(x)

xy - data.frame(x=x,y=y)

myf - function(x,a,b,n){
  res - a*x^b + n
  ## a print for debugging purpose
  print(n)
  res
}

## This works as I expect it to do in R-2.2.1 but doesn't work in R-2.3.1. 
## n is somehow sat to nrow(xy) inside nls()
## Note that x and y is defined in the dataframe xy, whereas n is found in the 
global environment.
fit - nls(y ~ myf(x,a,b,n), data=xy, start=c(a=1,b=1), trace=TRUE)

## this works in both versions
## x,y,n found in the .GlobalEnv
fit - nls(y ~ myf(x,a,b,n), start=c(a=1,b=1), trace=TRUE)

## this works in both versions.
## x, y, n found in dataframe xyn
xyn - data.frame(xy,n=n)
fit - nls(y ~ myf(x,a,b,n), data=xyn, start=c(a=1,b=1), trace=TRUE)

## this works in both versions
## Now using the variable .n instead of n
## .n is found in .GlobaEnv
.n - 1
fit - nls(y ~ myf(x,a,b,.n), data=xy, start=c(a=1,b=1), trace=TRUE)


In my real case and the example above, I do have three or more parameters of 
which fitting is done only on few of theme. Is this a problem? Or should I ask, 
why is this a problem in R-2.3.1 but not in R-2.2.1?

Is my problem related to this difference between lines of code from nls:

R-2.2.1: mf - as.list(eval(mf, parent.frame()))

R-2.3.1: mf - eval.parent(mf)
 n - nrow(mf)
 mf - as.list(mf)

where n is being defined in the scope of nls in the latest version?

Best regards

Frede Aakmann Tøgersen



Danish Institute of Agricultural Sciences
Research Centre Foulum
Dept. of Genetics and Biotechnology
Blichers Allé 20, P.O. BOX 50
DK-8830 Tjele

Phone:   +45 8999 1900
Direct:  +45 8999 1878

E-mail:  [EMAIL PROTECTED]
Web:   http://www.agrsci.org

This email may contain information that is confidential.
Any use or publication of this email without written permission from DIAS is 
not allowed.
If you are not the intended recipient, please notify DIAS immediately and 
delete this email.

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


Re: [R] problem with integrate() - correction

2006-06-22 Thread Frede Aakmann Tøgersen
Well why not do it symbolically, e.g.

int(a*x^b,x) = \frac{a}{b+1}x^{b+1}

and integrating this again gives

\frac{a}{(b+1)(b+2)}x^{b+2},

of course for resonable values of a and b such that things are well defined.

But if you follow the link

https://stat.ethz.ch/pipermail/r-help/2005-January/064026.html

you may come to this solution:


ip - function(x) 1240 * x^(-0.88)

iip - function(x){
  res - rep(NA,length(x))
  for (i in seq(along=x))
res[i] - integrate(ip, x[i] - 0.045, x[i] + 0.045)$value
  return(res)
}

f - integrate(iip, 10, 100)

which may not be an effective way to do it.


Med venlig hilsen
Frede Aakmann Tøgersen
 

 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af Rainer M Krug
 Sendt: 22. juni 2006 14:03
 Til: [EMAIL PROTECTED]
 Cc: R help list
 Emne: [R] problem with integrate() - correction
 
 Sorry
 
 should read:
 
 ip - function(x) 1240 * x^(-0.88)
 
 
 Rainer M Krug wrote:
  Hi
  
  System:
  Linux, SuSE 10
  R 2.3.0
  
  I try to do the following
  
  ip - function(x) 1240*dip(x, 0.88)
  iip - function(x) integrate(ip, x - 0.045, x + 0.045)$value f - 
  integrate(iip, 10, 100)
  Error in integrate(iip, 10, 100) : evaluation of function gave a 
  result of wrong length
  
  How can I solve this?
  
  Thanks
  
  Rainer
  
  
  
 
 
 --
 Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT)
 
 Department of Conservation Ecology and Entomology University 
 of Stellenbosch Matieland 7602 South Africa
 
 Tel:  +27 - (0)72 808 2975 (w)
 Fax:  +27 - (0)21 808 3304
 Cell: +27 - (0)83 9479 042
 
 email:[EMAIL PROTECTED]
   [EMAIL PROTECTED]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html


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


Re: [R] A question about stepwise procedures: step function

2006-06-16 Thread Frede Aakmann Tøgersen
Well Jia, you use 'all' as a name for your dataframe, but this is also a 
function, see ?all. If I try it with

mydata - data.frame(z1,z2,z3) 

all goes well.


Med venlig hilsen
Frede Aakmann Tøgersen
 

 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af Li, Jia
 Sendt: 15. juni 2006 17:45
 Til: Hong Ooi; r-help@stat.math.ethz.ch
 Emne: Re: [R] A question about stepwise procedures: step function
 
 Sorry, I still cannot find what's wrong with it. And it seems 
 that nothing is wrong with t.
  
 Jia
  
  z1-rnorm(N,0,1)
  z2-rnorm(N,3,5)
  z3-rbinom(N,1,0.6)
  
  prop.cens-0.45   
  cen-rbinom(N,1,1-prop.cens) #-- censor indicator:45% censor in
 the data.
  t- rexp(N)
 
  all-data.frame(z1,z2,z3)
  fit.model.all- coxph(Surv(t,cen) ~z1+z2+z3,data=all) fit.model.all
 Call:
 coxph(formula = Surv(t, cen) ~ z1 + z2 + z3, data = all)
  
 
 coef exp(coef) se(coef)   zp
 z1  0.057466 1.059   0.1377  0.4173 0.68
 z2  0.000907 1.001   0.0332  0.0273 0.98
 z3 -0.349273 0.705   0.2867 -1.2184 0.22
  
 Likelihood ratio test=1.81  on 3 df, p=0.613  n= 100 
  reg.model.all-step(fit.model.all)
 Start:  AIC= 376.39
  Surv(t, cen) ~ z1 + z2 + z3 
  
 Error in as.data.frame.default(data) : cannot coerce class function
 into a data.frame
 
 
   _  
 
 From: Hong Ooi [mailto:[EMAIL PROTECTED]
 Sent: Thursday, June 15, 2006 10:53 AM
 To: Li, Jia
 Subject: RE: [R] A question about stepwise procedures: step function
 
 
 
 Note: This e-mail is subject to the disclaimer contained at the bottom
 of this message.
 
   _  
 
 t is the name of a function. If you have a variable called t in your
 dataset, try renaming it.
  
 
   _  
 
 From: [EMAIL PROTECTED] on behalf of Li, Jia
 Sent: Thu 15/06/2006 11:52 PM
 To: r-help@stat.math.ethz.ch; [EMAIL PROTECTED]
 Subject: Re: [R] A question about stepwise procedures: step function
 
 
 
 Hi,
 
 Step works for a Cox model. And I got the same error massage using
 stepAIC.
 
 Jia
 
   _ 
 
 From: Ritwik Sinha [mailto:[EMAIL PROTECTED]
 Sent: Thursday, June 15, 2006 12:12 AM
 To: Li, Jia
 Subject: Re: [R] A question about stepwise procedures: step function
 
 
 Hi,
 
 The step documentation says
 
 object: an object representing a model of an appropriate class
   (mainly 'lm' and 'glm'). This is used as the initial
   model in the stepwise search.
 
 I wonder if it will work for a cox proportional hazard model. 
 You could
 try stepAIC in MASS.
 
 
 
 
 On 6/14/06, Li, Jia  [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] 
 wrote:
 
 Dear all,

 I tried to use step  function to do model 
 selection, but I got
 an error massage.  What I don't understand is that data as data.frame
 worked well for my other programs, how come I cannot make it run this
 time. Could you please tell me how I can fix it?


 **
 **
 ***

 all-data.frame(z1,z2,z3)

 fit.model.all- coxph(Surv(t,cen) ~z1+z2+z3,data=all)

  reg.model.all-step(fit.model.all)
 Start:  AIC= 689.1
 Surv(t, cen) ~ z1 + z2 + z3
 Error in as.data.frame.default(data) : cannot coerce class
 function into a data.frame

 **
 **
 ***
 Thanks a lot!

 Jia

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

 
 
 
 
 --
 Ritwik Sinha
 Graduate Student
 Epidemiology and Biostatistics
 Case Western Reserve University
 
 http://darwin.cwru.edu/~rsinha
 
 [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
 http://www.R-project.org/posting-guide.html
 
 
   _  
 
 The information transmitted in this message and its 
 attachme...{{dropped}}
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html


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


Re: [R] When calling external C-function repeatedly I get differentresults; can't figure out why..

2006-03-09 Thread Frede Aakmann Tøgersen
Not an expert in programming either, but to me it seems like you've forgotten 
to initialize the variable tr. It just picks up garbage from allocated memory 
previously initialized by other processes.


Med venlig hilsen
Frede Aakmann Tøgersen
 

 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af Søren Højsgaard
 Sendt: 9. marts 2006 02:15
 Til: r-help@stat.math.ethz.ch
 Emne: [R] When calling external C-function repeatedly I get 
 differentresults; can't figure out why..
 
 Dear all,
 I need to calculate tr(xyxy) fast for matrices x and y. 
 Inspired by the R-source code, I've created the following 
 functions (I am *new* to writing external C-functions, so 
 feel free to laugh at my code - or, perhaps, suggest changes):
  
 #include Rinternals.h
 #include R_ext/Applic.h /* for dgemm */
 
 static void matprod(double *x, int nrx, int ncx,
   double *y, int nry, int ncy, double *z) {
 char *transa = N, *transb = N;
 double one = 1.0, zero = 0.0;
 F77_CALL(dgemm)(transa, transb, nrx, ncy, ncx, one,
   x, nrx, y, nry, zero, z, nrx); }
 
 SEXP trProd2(SEXP x, SEXP y)
 {
   int nrx, ncx, nry, ncy, mode, i;
   SEXP xdims, ydims, ans, ans2, tr;
   xdims = getAttrib(x, R_DimSymbol);
   ydims = getAttrib(y, R_DimSymbol);
   mode = REALSXP;
   nrx = INTEGER(xdims)[0];
   ncx = INTEGER(xdims)[1];
   nry = INTEGER(ydims)[0];
   ncy = INTEGER(ydims)[1];
   PROTECT(ans  = allocMatrix(mode, nrx, ncy));
   PROTECT(ans2 = allocMatrix(mode, nrx, ncy));
   PROTECT(tr   = allocVector(mode, 1));
   matprod(REAL(x), nrx, ncx, REAL(y), nry, ncy, REAL(ans)); 
   
   matprod(REAL(ans), nrx, ncy, REAL(ans), nrx, ncy, REAL(ans2)); 
   
   for (i=0; i nrx; i++){
 REAL(tr)[0] = REAL(tr)[0] + REAL(ans2)[i*(nrx+1)];
   }
   UNPROTECT(3);
   return(tr);
 }
 
 In R I do:
  
 trProd2 - function(x, y) {
 .Call(trProd2, x, y)
 }
 x - y - matrix(1:4,ncol=2)
 storage.mode(x) - storage.mode(y) - double
 
 for (i in 1:10)
   print(trProd2(x, y))
 [1] 835
 [1] 833
 [1] 833
 [1] 862
 [1] 834
 [1] 835
 [1] 834
 [1] 836
 [1] 862
 [1] 833
 
 The correct answer is 833. Can anyone give me a hint to what 
 is wrong? I am on a windows xp platform.
 Thanks in advance
 Søren
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html
 


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


Re: [R] indexing within panels in xyplot

2006-02-20 Thread Frede Aakmann Tøgersen

Based on your two first sentences I think the solution is to use

xyplot(y ~ x | facA, groups = facB, data = toydf,type=c(p,r))

Try it and see if this is what you want.


Best regards

Frede Aakmann Tøgersen
Scientist


Danish Institute of Agricultural Sciences
Research Centre Foulum
Dept. of Genetics and Biotechnology
Blichers Allé 20, P.O. BOX 50
DK-8830 Tjele

Phone:   +45 8999 1900
Direct:  +45 8999 1878

E-mail:  [EMAIL PROTECTED]
Web:   http://www.agrsci.org

This email may contain information that is confidential.
Any use or publication of this email without written permission from DIAS is 
not allowed.
If you are not the intended recipient, please notify DIAS immediately and 
delete this email.



 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af Sebastian Luque
 Sendt: 21. februar 2006 08:20
 Til: r-help@stat.math.ethz.ch
 Emne: [R] indexing within panels in xyplot
 
 Dear R-helpers,
 
 I need to show a linear fit through a subset of the data 
 within each combination of levels of two factors.  So I 
 prepared an xyplot with different panels for each level of 
 one of the factors, and different symbols within each panel 
 for the levels of the second factor.  My problem is selecting 
 the subset of each combination through which the line should 
 be fit for subsequent plotting.  This hopefully shows the idea:
 
 
 --cut here---start-
 toydf - expand.grid(1:100, c(A, B),
  c(pop1, pop2, pop3, pop4, 
 pop5)) toydf - data.frame(facA = toydf[[3]], facB = toydf[[2]],
 x = toydf[[1]], y = rnorm(1000))
 
 xyplot(y ~ x | facA, groups = facB, data = toydf,
panel.groups = function(x, y, subscripts, ...) {
  panel.xyplot(x, y, ...)
  lindx - which(y[subscripts] == max(y[subscripts], 
 na.rm = TRUE))
  xleft - mean(x[lindx], na.rm = TRUE)
  fit - lm(y[x = xleft] ~ x[x = xleft])
  panel.abline(fit)
})
 --cut here---end---
 
 i.e. the left limit for fitting the line is defined by the 
 mean of x values where y is equal to the maximum y values, 
 *within* each combination of levels of both factors.  The 
 above is giving me:
 
 Error in lm.fit(x, y, offset = offset, singular.ok = 
 singular.ok, ...) : 
   0 (non-NA) cases
 In addition: Warning message:
 no finite arguments to max; returning -Inf 
 
 which shows I'm not understanding how the 'subscripts' argument works.
 I'd appreciate some pointers on what I'm doing wrong, as I 
 haven't been able to find help in the help pages and List archives.
 
 Thanks,
 
 --
 Sebastian P. Luque
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html
 


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


Re: [R] lattice: combining panel.xyplot with panel.abline - is thispossible?

2006-01-30 Thread Frede Aakmann Tøgersen

Well, one way to do it is

xyplot(y~time|id, data=dat,type='l',
   panel=function(x,y,subscripts,...){
 panel.xyplot(x,y,subscripts,...)
 panel.abline(v=dat[subscripts,cm1])
 panel.abline(v=dat[subscripts,cm2])
  }
)

Since I don't know what the dataframe 'mergeData' is I have used 'dat'.

Best regards

Frede Aakmann Tøgersen
Scientist


Danish Institute of Agricultural Sciences
Research Centre Foulum
Dept. of Genetics and Biotechnology
Blichers Allé 20, P.O. BOX 50
DK-8830 Tjele

Phone:   +45 8999 1900
Direct:  +45 8999 1878

E-mail:  [EMAIL PROTECTED]
Web:   http://www.agrsci.org

This email may contain information that is confidential.
Any use or publication of this email without written permission from DIAS is 
not allowed.
If you are not the intended recipient, please notify DIAS immediately and 
delete this email.

 

 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af Søren Højsgaard
 Sendt: 31. januar 2006 01:44
 Til: r-help@stat.math.ethz.ch
 Emne: [R] lattice: combining panel.xyplot with panel.abline - 
 is thispossible?
 
 Consider this data frame:
  
 dat-data.frame(id=gl(3,5),time=rep(1:5,3),cm1=rep(c(2,3,4),ea
 ch=5),cm2=rep(c(2.5,3.5,4.5),each=5),y=rnorm(15))
 
  dat
id time cm1 cm2  y
 1   11   2 2.5 -1.0824549
 2   12   2 2.5 -0.7784834
 3   13   2 2.5 -1.7783560
 4   14   2 2.5  0.5056637
 5   15   2 2.5 -0.1967505
 6   21   3 3.5  1.1643136
 7   22   3 3.5 -1.4323765
 8   23   3 3.5  0.6810645
 9   24   3 3.5  1.1310363
 10  25   3 3.5  1.5677158
 11  31   4 4.5  1.6394222
 12  32   4 4.5  1.2024161
 13  33   4 4.5  0.1784666
 14  34   4 4.5 -1.3260668
 15  35   4 4.5 -0.2711263
 
 
 I would like to plot y against time with a panel for each id, 
 i.e. with something like 
 
 xyplot(y~time|id, data=dat,type='l') or
 
 xyplot(currCow.mean~currCow.cm|cowid, data=mergeData, type='l',
   panel=function(x,y,...){
 panel.xyplot(x,y)
   }
 )
 
 
 Then, I would additionally like to have two vertical lines in 
 each panel, and these are defined by cm1 and cm2. My 
 understanding of xyplot is that id will give a partitioning 
 of data into subsets, so I expected to be able to get each 
 subset into the panelfunction and from there I can extract 
 cm1 and cm2 and call panel.abline(a,b)...
 
 1) Is that possible? 
 2) Are there other ways of achieving what I want?
 
 Appologies if this is trivial...
 
 Best regards
 
 Søren
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html
 


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


Re: [R] paste argument of a function as a file name

2005-11-10 Thread Frede Aakmann Tøgersen
Why not use something like


MY.function - function(x){
  filn - deparse(substitute(x))
  filename - paste(filn,xls,sep=.)
  ...
  ...
  write.table(x,file=filename)
}


Med venlig hilsen
Frede Aakmann Tøgersen
 

 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af Luis Ridao Cruz
 Sendt: 10. november 2005 14:28
 Til: r-help@stat.math.ethz.ch
 Emne: [R] paste argument of a function as a file name
 
 R-help,
 
 I have a function which is exporting the output to a file via 
 write.table(df, file =  file name.xls )
 
 What I want is to paste the file name (above) by taking the 
 argument to the function as a file name 
 
 something like this:
 
 MY.function- function(df)
 {
 ...
 ...
 write.table(df,argument.xls)
 }
 MY.function(argument)
 
 
 Thank you
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html
 


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


Re: [R] spline.des

2005-10-04 Thread Frede Aakmann Tøgersen

Hey

The function spline.des is in the splines package. You need to do 

library(splines)

before you have the full functionality of the fda package.


Best regards
Frede Aakmann Tøgersen
 

 

 -Oprindelig meddelelse-
 Fra: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] På vegne af lforzani
 Sendt: 3. oktober 2005 22:28
 Til: Douglas Bates; Horacio Montenegro
 Cc: r-help@stat.math.ethz.ch
 Emne: [R] spline.des
 
 Hello, I am using library fda and I can not run a lot of 
 functions because I receive the error:
 
 Error in bsplineS(evalarg, breaks, norder, nderiv) : 
 couldn't find function spline.des
 
 
 do you know how I can fix that? Thnaks. Liliana
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html
 


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