Re: [R] help for code in jump diffusion

2008-11-22 Thread cruz
i tried to run your code, this is how/why you got NaN:

 mu-0.2
 sig-0.2
 S0-100
 j-0.2
 dt-1/252
 int-0.1
 i-0
  is.nan
function (x)  .Primitive(is.nan)
  k-rnorm(1,0,1)
  k
[1] 0.3214954
  theta-ifelse((k(int*dt)),1,0)
  theta
[1] 0
  m-rnorm(1)
  m
[1] -0.4525731
  gam-qnorm(m,0,1)
Warning message:
In qnorm(p, mean, sd, lower.tail, log.p) : NaNs produced
  gam
[1] NaN
  S0-abs(S0*((1+mu*dt+sig*sqrt(dt)+ gam)- j*theta))
  S0
[1] NaN
  if(!is.nan (S0 = 0))
+ warning(S0 must be positive)
Warning message:
S0 must be positive
 cat(NaN,\n)
NaN
  cat(S0,\n)
NaN




On Sat, Nov 22, 2008 at 2:37 PM, subbudas [EMAIL PROTECTED] wrote:

 hello everyone ,
 i have written some code in R for jump diffusion model.
 the code generates answer as
  NaN
 There were 50 or more warnings (use warnings() to see the first 50)
 my code is

 mu-0.2
 sig-0.2
 S0-100
 j-0.2
 dt-1/252
 int-0.1
 i-0
 while(i=1)
 {
  is.nan
  k-rnorm(1,0,1)
  theta-ifelse((k(int*dt)),1,0)
  m-rnorm(1)
  gam-qnorm(m,0,1)
  S0-abs(S0*((1+mu*dt+sig*sqrt(dt)+ gam)- j*theta))
  if(!is.nan (S0 = 0))
 warning(S0 must be positive)
 cat(NaN,\n)
  cat(S0,\n)
  i-i+(1/252)
 }

 the problem i am facing is i am not able to find out the reason for this NaN
 output.
 please help

 thanks in advance.




__
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] help for code in jump diffusion

2008-11-22 Thread Bernardo Rangel Tura
On Fri, 2008-11-21 at 22:37 -0800, subbudas wrote:
 hello everyone ,
 i have written some code in R for jump diffusion model.
 the code generates answer as 
  NaN 
 There were 50 or more warnings (use warnings() to see the first 50)
 my code is 
 
 mu-0.2
 sig-0.2
 S0-100
 j-0.2
 dt-1/252
 int-0.1
 i-0
 while(i=1)
 {
   is.nan
   k-rnorm(1,0,1)
   theta-ifelse((k(int*dt)),1,0)
   m-rnorm(1)
   gam-qnorm(m,0,1)
   S0-abs(S0*((1+mu*dt+sig*sqrt(dt)+ gam)- j*theta))
   if(!is.nan (S0 = 0))
  warning(S0 must be positive)
  cat(NaN,\n)
   cat(S0,\n)
   i-i+(1/252)
 }
 
 the problem i am facing is i am not able to find out the reason for this NaN
 output.
 please help 
 
 thanks in advance.


Hi 

I see two problems in your script:

1- m-rnorm(1) will produce a random number with distribution normal
mean =0 and sd=1 so m can 1 or 0
In this cases gam-qnorm(m,0,1) is NAN because m is not a probability

2- I think  if(!is.nan (S0 = 0)) ...  is wrong 


Try this script :


mu-0.2
sig-0.2
S0-100
j-0.2
dt-1/252
int-0.1
i-0
while(i=1){
k-rnorm(1,0,1)
theta-ifelse((k(int*dt)),1,0)
#   m-rnorm(1)
m-runif(1,0,1)
gam-qnorm(m,0,1)
S0-abs(S0*((1+mu*dt+sig*sqrt(dt)+ gam)- j*theta))
if(!is.nan(S0)(S0 = 0)){
warning(S0 must be positive)
cat(NaN,\n)
}
cat(S0,\n)
i-i+(1/252)
}

-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil

__
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] CRAN mirror for Taipeh vs Taipei

2008-11-22 Thread cruz
Hi,

I am residing in Taipei, Taiwan. My windows has English R (2.7.2)
installed. I noticed that the CRAN mirror for Taipei is Taiwan
(Taipeh), Is Taipeh a Deutsch or English name?

Thanks,
cruz

__
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] summary statistics into table/data base, many factors to analyse

2008-11-22 Thread Gabor Grothendieck
On Fri, Nov 21, 2008 at 5:50 AM, Gerit Offermann [EMAIL PROTECTED] wrote:
 Dear list,

 thanks to your help I managed to find means of analysing my data.

 However, the whole data set contains 264 variables. Of which some are
 factors, others are not. The factors tend to be grouped, e.g.
 data$f1304 to data$f1484 and data$f3204 to data$5408.

 But there are other types of variables in the data set as well,
 e.g. data$f1504.

 Not every spot is taken, i.e data$f1345 to data$1399 might not exist
 in the data set.

We can compute on the names like this (using the builtin anscombe
data set to get just columns y1, x1, x2, x3, x4).  Try this:

# display anscombe data set
anscombe

# names.x are names that start with x
names.x - grep(^x, names(anscombe), value = TRUE)
anscombe[, c(y1, names.x)]


 The solution summaryBy works for cross analysis, of which there is
 a handful. So I am not worried here.

 The solution from Jorge is fine.
 However, I am trying to get my head around how to efficiently
 reduce my data set to the dependet variable and the factors such that
 the solution is applicable.

 Having to type each variable into
 my.reduced.data - cbind(my.data$f1001, my.data$1002, my.data$1003...
 is an obvious option, but does not seem to be the most efficient one.

 Are there better ways to go about?

 Thanks,
 Gerit
 --
 Sensationsangebot nur bis 30.11: GMX FreeDSL - Telefonanschluss + DSL
 für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a

 __
 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] Error with lapply [addirional clarification needed]

2008-11-22 Thread megh

I need one more clarification here :

Here I did :

fn - function(i) return(list(i, i^2))
ss = sapply(1:4, fn)

Here the object ss should be a matrix object :
is.matrix(ss)

However I feel it lacks some the matrix object properties. For example the
syntax min(ss[1,]) generates an error :
Error in min(ss[1, ]) : invalid 'type' (list) of argument.

What should be the way out? Am I missing something ?

Regards,


baptiste auguie-2 wrote:
 
 Hi,
 
 you are feeding lapply i as an optional argument, which is passed to  
 fn() and causes an error. Just use lapply(1:4, fn), or better yet,  
 sapply,
 
   fn - function(i) return(i^2)
   sapply(1:4, fn)
 [1]  1  4  9 16
 
 Hope this helps,
 
 baptiste
 
 
 On 20 Nov 2008, at 16:31, megh wrote:
 

 I have written following codes, with intention to get a list with  
 values
 1,2,9,16 :

 fn - function(i) return(i^2)
 lapply(1:4, fn, i)

 However I got following error :
 Error in FUN(1:4[[1L]], ...) : unused argument(s) (1)

 Can anyone please tell me what will be the correct code here?

 Regards,


 --
 View this message in context:
 http://www.nabble.com/Error-with-lapply-tp20605066p20605066.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.
 
 _
 
 Baptiste Auguié
 
 School of Physics
 University of Exeter
 Stocker Road,
 Exeter, Devon,
 EX4 4QL, UK
 
 Phone: +44 1392 264187
 
 http://newton.ex.ac.uk/research/emag
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 

-- 
View this message in context: 
http://www.nabble.com/Error-with-lapply-tp20605066p20634821.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] Error with lapply [addirional clarification needed]

2008-11-22 Thread Peter Dalgaard

megh wrote:

I need one more clarification here :

Here I did :

fn - function(i) return(list(i, i^2))
ss = sapply(1:4, fn)

Here the object ss should be a matrix object :
is.matrix(ss)

However I feel it lacks some the matrix object properties. For example the
syntax min(ss[1,]) generates an error :
Error in min(ss[1, ]) : invalid 'type' (list) of argument.

What should be the way out? Am I missing something ?


ss is a dim'ed list object, because fn returns a list. This appears to 
be a feature, although rarely used. One point is that you can do


 fn - function(i) return(list(as.character(i), i^2))
 ss - sapply(1:4, fn)
 ss
 [,1] [,2] [,3] [,4]
[1,] 1  2  3  4
[2,] 14916
 ss[,1]
[[1]]
[1] 1

[[2]]
[1] 1

I.e., the rows can be of different mode.

The easiest way out is just not to do that, i.e. return a vectore c(i, 
i^2) instead.



--
   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] Error with lapply [addirional clarification needed]

2008-11-22 Thread Gabor Grothendieck
Try str(ss) to see what it really looks like.  You probably want:

fn - function(i) c(i, i^2)


On Sat, Nov 22, 2008 at 4:54 AM, megh [EMAIL PROTECTED] wrote:

 I need one more clarification here :

 Here I did :

 fn - function(i) return(list(i, i^2))
 ss = sapply(1:4, fn)

 Here the object ss should be a matrix object :
 is.matrix(ss)

 However I feel it lacks some the matrix object properties. For example the
 syntax min(ss[1,]) generates an error :
 Error in min(ss[1, ]) : invalid 'type' (list) of argument.

 What should be the way out? Am I missing something ?

 Regards,


 baptiste auguie-2 wrote:

 Hi,

 you are feeding lapply i as an optional argument, which is passed to
 fn() and causes an error. Just use lapply(1:4, fn), or better yet,
 sapply,

   fn - function(i) return(i^2)
   sapply(1:4, fn)
 [1]  1  4  9 16

 Hope this helps,

 baptiste


 On 20 Nov 2008, at 16:31, megh wrote:


 I have written following codes, with intention to get a list with
 values
 1,2,9,16 :

 fn - function(i) return(i^2)
 lapply(1:4, fn, i)

 However I got following error :
 Error in FUN(1:4[[1L]], ...) : unused argument(s) (1)

 Can anyone please tell me what will be the correct code here?

 Regards,


 --
 View this message in context:
 http://www.nabble.com/Error-with-lapply-tp20605066p20605066.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.

 _

 Baptiste Auguié

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

 Phone: +44 1392 264187

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

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



 --
 View this message in context: 
 http://www.nabble.com/Error-with-lapply-tp20605066p20634821.html
 Sent from the R help mailing list archive at Nabble.com.

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


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


[R] How to draw following plot in R?

2008-11-22 Thread RON70

I want to draw following plot, given here
http://www.2shared.com/file/4327128/830b82c4/pic.html
for the following data :

dat - cbind(rnorm(100), sample(c(1:4), 1000, T))
colnames(dat) - c(data,level)

Here x-axis should be on data and y-axis is for level and z-axis should
be to display the frequency of data for a particular level

Is there any R code(s) to doing that?

-- 
View this message in context: 
http://www.nabble.com/How-to-draw-following-plot-in-R--tp20635099p20635099.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] Brightness readings for part of an image

2008-11-22 Thread S. Messing

Hi R users,

I am doing some image analysis and I'd like to know if anyone knows of:

1. a way to specify a rectangle (using xy coordinates) within an image to
have R evaluate using xy pixel coordinates and

2.  a way to get brightness readings for that part of the image.

If there's some way to crop the image using 2x2 xy coordinates, for instance
in the EBImage package, that would work as well. 

Thanks!
-- 
View this message in context: 
http://www.nabble.com/Brightness-readings-for-part-of-an-image-tp20633094p20633094.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] How to add the value on the barchart

2008-11-22 Thread Piya Kittipadakul
I have question: how can I put the value on the bar chart.
This my code:
barchart(Tuberize~Family|factor(Year)*factor(Hr),data=tuber)

This's my data:
   Year Hr Family Tuberize
1  2007 20  A 0.26
2  2007 20  B 6.08
3  2007 20  C 0.00
4  2007 20  D 0.27
5  2008 20  A 1.18
6  2008 20  B 9.17
7  2008 20  C 0.00
8  2008 20  D 2.13
9  2007 14  A    35.83
10 2007 14  B    38.98
11 2007 14  C 7.90
12 2007 14  D    18.75
13 2008 14  A    43.70
14 2008 14  B    51.84
15 2008 14  C    27.11
16 2008 14  D    24.11
17 2008 11  A    85.67
18 2008 11  B    93.73
19 2008 11  C    81.45
20 2008 11  D    90.25
21 2007  8  A    63.04
22 2007  8  B    66.29
23 2007  8  C    70.85
24 2007  8  D    83.48
25 2008  8  A    83.33
26 2008  8  B    92.31
27 2008  8  C    82.21
28 2008  8  D    94.03

Thank you
Piya


  
[[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] declaring constants in an Sweave / LaTeX document

2008-11-22 Thread Kyle Matoba
List,

I would like to set a variable to hold, say, the size of my plots in a
Sweave document.  i.e. something like the following in my '.Rnw' file:

==
smallPlotSize = 4

fig1, echo=false, results=hide, height=smallPlotSize, width=smallPlotSize,
fig=true=
dat - read.table(
http://www.stanford.edu/~xing/statfinbook/_BookData/Chap05/q_us_gdp.txt;,
skip=2, header=T)

GDP - ts(data=dat$VALUE, start=c(1947,1), frequency=4)

acf(GDP, type=correlation, main= ACF of US GDP)
@
==

This way I can tweak things if I have to include a bunch of graphics of the
same size in a file.  I am not great with LaTeX and still very new to using
Sweave, so I was wondering what the preferred method of doing something like
this is between LaTeX and Sweave.  I have seen some people doing some tricky
stuff from within R such that when their code is preprocessed it is compiled
as LaTeX source, but this seems like an ugly hack for something so simple.

Please forgive me if this has been addressed elsewhere; I have found
documentation on Sweave to be rather sparse.

Best,

Kyle

[[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] Need some help in R programming code

2008-11-22 Thread saikat sarkar

Dear R guru,

I am Saikat Sarkar working as a researcher of Economics in Tampere
University, Finland. I am trying to estimate some Garch related tests with
Bayesian analysis by R programme.

I am not good in R but trying to survive.

Anyway I have the coding but not working properly. I have tried to find the
problem but failed. I am writing to all R gurus to help me out.

Could you please look at the problem and help me if you can.

Thanking you
saikat

Could you please look at the problem below:

R message is like below:
---
Error in garch.gjr.d0(param, y, X, Z, iterate = FALSE)$res :
  $ operator is invalid for atomic vectors
plot(Ch.mic,Ch.mic.rep,xlim=c(0,6),ylim=c(0,6))
---
Coding


res-garch.gjr.d0(a$estimate,y,X,X,iterate=FALSE)$res
sig2-garch.gjr.d0(a$estimate,y,X,X,iterate=FALSE)$sig2


test.mic - function(param,y,X,Z)

{
   n - length(y)

   res - garch.gjr.d0(param,y,X,Z,iterate=FALSE)$res

   s2 - garch.gjr.d0(param,y,X,Z,iterate=FALSE)$sig2

   s-sqrt(s2)

   r - res

   u - r[-1]

   r2- (r[-n]^2*s2[-n])/s[-1]

   r3- (r[-n]^3*s2[-n]*s[-n])/s[-1]

   U - cbind(r[-n],r2,r3)

   U - cbind(1,U)

   U - U/matrix(s[-1],nr=nrow(U),nc=ncol(U))

   Fstat-summary(lm(u~U-1))$fstatistic[1]

   Fstat

}


sim.gjr - function(par,y,X=0,Z=0)
{

   n - length(y)

   e-numeric(n)

   yrep-numeric(n)

   yrep[1] - y[1]

   n.dummies.mean - dim(X)[2]

   if(is.matrix(X)) e[1] - e[1]-sum(X[1,]*par[9:(8+n.dummies.mean)])

   delta - par[-(1:(8+n.dummies.mean))]

   s2 - var(y)

   for(i in 2:n){

 s2 -
par[5]+par[6]*e[i-1]^2+par[7]*ifelse(e[i-1]0,1,0)*e[i-1]^2+par[8]*s2+sum(X[i,]*delta)

 e[i] - rnorm(1,0,sqrt(s2))

 yrep[i]-par[1]+par[2]*yrep[i-1]+par[3]*s2+par[4]*yrep[i-1]*s2+e[i]

   }


   if(is.matrix(X)) yrep - yrep + X%*%par[9:(8+n.dummies.mean)]

   yrep
}

yrep - sim.gjr(a$estimate,y,X,Z)


n.test - 500

Ch.mic - Ch.mic.rep - numeric(n.test)

for(i in 1:n.test){

   simulation - sample(1:1,1)

   par - sims.matrix[simulation,]

   Ch.mic[i] - test.mic(par,y,X,X)

   yrep - sim.gjr(par,y,X,X)

   Ch.mic.rep[i] - test.mic(par,yrep,X,X)
}

 plot(Ch.mic,Ch.mic.rep,xlim=c(0,6),ylim=c(0,6))

 lines(c(0,6),c(0,6)) 
-- 
View this message in context: 
http://www.nabble.com/Need-some-help-in-R-programming-code-tp20634187p20634187.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] lsoda warning too much accuracy requested

2008-11-22 Thread Thomas Petzoldt

A short addendum, resulting from an off-list discussion:

The reason why Colleen's code failed was raising a negative base to a 
fractional exponent in the third state equation for certain sets of 
parameters, esp. fractional values of beta.


Old versions of odesolve broke down, and recent versions of deSolve (or 
the deprecated odesolve) simply returned NaN for the third state. In 
order to track such problems down, it is helpful to call the system 
separately, e.g.:


 model(0, start, parms)
[[1]]
HBA N
0.3702103 1.2229436   NaN

and then isolate the problem in the respective state equation.

Thomas P.



Thomas Petzoldt wrote:

Hi Colleen,

this error was not uncommon and is usually a sign of a numerically 
problematic or wrongly implemented model. Please use package deSolve, 
the successor of odesolve, that is more robust and has also a bunch 
alternative solvers for difficult cases.


I tested your code with deSolve (on R 2.8.0, Windows) and it runs 
without problems.


Thomas Petzoldt


BTW: your system worked also with odesolve, so my question: which 
versions (R, odesolve) and operating system are you using?


Colleen Carlson wrote:

Dear list -

 

Does anyone have any ideas / comments about why I am receiving the 
following

warning when I run lsoda:

 

1:  lsoda--  at t (=r1), too much accuracy requested in: lsoda(start, 
times,

model, parms)
2:   for precision of machine..  see tolsf (=r2) in: lsoda(start, 
times,

model, parms)

 


I have tried changing both rtol and atol but without success.  I saw the
thread in the R-archive of 11 June 2004 but this has not helped me.

 


I have built the model in stages and the problem only occurs when the
exponent beta in the third DE is anything other than 0 or 1.  If beta 
= 0 or

1 then the solver gives me perfectly justifiable results.  Just changing
beta to 0.9 or similar causes the problem.

 


I am still new to R so I am unsure if it is my programming or my
understanding of the way lsoda works.

 


Any comments or input would be welcome.

Many thanks

Colleen

___

 


My code is:

 


library(odesolve)

SI - 80

model - function(t, x, parms) {

H  - x[1]

BA - x[2]

N  - x[3]

with(as.list(parms), {

dHdt - (b/c)*(((a**c)*((H)**(1-c))-H))

dBAdt - -(BA*b)*(c0+(c1*SI)-log(BA))/(log(1-((H/a)**c)))

dNdt -  N*alpha*(((log(1-((H/a)**c)))/b)**beta) - (gamma*BA)

list(c(dHdt, dBAdt, dNdt))

})

}

times - seq(0, 40, 1)

 


parms - c(a=(SI*1.258621)-1.32759, b=0.1, c=0.4, c0=4.6012, c1=0.013597,
alpha=0.0005, beta=0.5,  gamma=0.01)

start - c(H=0.1, BA=0.1, N=600)

 


out - as.data.frame(lsoda(start, times, model, parms))


[[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] [Rd] Re Bessel functions of complex argument

2008-11-22 Thread baptiste auguie
I thought I'd share a few workaround routes I've considered (my  
attempt at using Amos' Fortran routines failed miserably -- if anyone  
is interested i can explain what I tried),


- Ryacas seems to provide a very simple way to evaluate bessel  
functions with complex argument,




yacas(N(BesselJ(2, 1+I)))
Complex(0.415798869439e-1,0.247397641513);


Not sure yet how fast this is, and how to get data in/out in R format  
but it looks promising.


- Similarly, I get the idea that Sage could provide an interface to  
Maxima or Pari and return the desired value. There doesn't seem to be  
much of a documentation centred on the use of Sage with R, though.


- Octave has implemented the Amos code (so has Matlab). This should  
make it possible to call Octave and get the result back in R (Roctave  
package I believe), or better yet, get inspiration to properly use the  
underlying Fortran code.



Baptiste




On 9 Nov 2008, at 12:22, baptiste auguie wrote:


Dear all,

I'm writing a code that requires Bessel functions with complex  
argument.
Searching the list, I found the continuation of a thread I initiated  
a few

months ago:

http://tolstoy.newcastle.edu.au/R/e4/devel/08/03/0746.html

As I understand, the most promising option would be to use the  
fortran or C

implementation of Amos,

http://portal.acm.org/citation.cfm?id=214331dl=GUIDEcoll=GUIDECFID=9717168CFTOKEN=75957024


Sadly, my limited programming skills don't include any knowledge of  
fortran,
and I have never managed to link external code to R functions (i'm  
missing a

simple example based tutorial, R-ext overwhelms me with information).

A few questions for anyone interested:

- Does the aforementioned fortran code lends itself to an easy  
interfacing

with R? (in other words, do I stand a chance in less than 10 years?)

- Is anyone willing to help me with this? The package is hosted on R- 
forge

and i could take care of the documentation, etc.

- Is there a package I've missed that already implements this? (one  
can

dream)


Many thanks,


baptiste

_

Baptiste Auguié

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

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag
__

   [[alternative HTML version deleted]]

ATT1.txt


_

Baptiste Auguié

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

Phone: +44 1392 264187

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

__
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 draw following plot in R?

2008-11-22 Thread Barry Rowlingson
2008/11/22 RON70 [EMAIL PROTECTED]:

 I want to draw following plot, given here
 http://www.2shared.com/file/4327128/830b82c4/pic.html
 for the following data :

 dat - cbind(rnorm(100), sample(c(1:4), 1000, T))
 colnames(dat) - c(data,level)

 Here x-axis should be on data and y-axis is for level and z-axis should
 be to display the frequency of data for a particular level

 Is there any R code(s) to doing that?

 I'm pretty sure there's no code for doing it in character graphics
like in your image link!

 Something similar can be found in the R graph gallery:

  http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=116

 Or if you want an interactive spinny 3d-histogram, get the rgl
package and look at demo(hist3d). See:

 http://rgl.neoscientists.org/gallery.shtml

 Those links should get you started. If you really do want ascii
character graphics...well, I think you're on your own

Barry

__
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] Bug in Kendall for n4?

2008-11-22 Thread Martin Maechler
 SM == Stavros Macrakis [EMAIL PROTECTED]
 on Fri, 21 Nov 2008 14:44:37 -0500 writes:

 library(Kendall) Kendall(1:3,1:3)
SM WARNING: Error exit, tauk2. IFAULT = 12  tau = 1,
SM 2-sided pvalue =1

SM I believe Kendall tau is well-defined for this case and
SM the reported value is correct; isn't it a bug to give a
SM warning?  (And if, e.g., the pvalue is not well-defined
SM in this case, wouldn't it be better to return NA or NaN
SM or something?) Also, shouldn't the error code be given
SM in plain English -- or at least the meaning of IFAULT =
SM 12 documented on the help page?

The real question is  *WHY* there needs to be a separate package
'Kendall'  when R itself does everything you want and does not
show any problems ?

 cor()
 cov()
 cor.test()

all have a method = kendall  and seem to work alright,
even for  n=2

   cor(1:3, c(3,1,2), method=kendall)
  [1] -0.333
   cov(1:3, c(3,1,2), method=kendall)
  [1] -2
   cor(1:3, 1:3, method=kendall)
  [1] 1
   cor.test(1:3, 1:3, method=kendall)

  Kendall's rank correlation tau

  data:  1:3 and 1:3 
  T = 3, p-value = 0.
  alternative hypothesis: true tau is not equal to 0 
  sample estimates:
  tau 
1 


Questions about the 'Kendall' package should typically first go
to its author ...
But those on  cor(), cor.test() etc do belong here.

Best regards,
Martin Maechler, ETH Zurich


SM A somewhat less clear case is Kendall(1:2,1:2), which
SM gives the same error.  Though the usual formula for
SM Kendall tau has a zero in the denominator in this case,
SM I'd think the correct generalization is 1 if the two
SM elements are in the same order, and -1 if they are not
SM (the only possibilities). But perhaps I don't fully
SM understand the interpretation of this statistic.

SM   -s

SM __
SM R-help@r-project.org mailing list
SM https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
SM read the posting guide
SM http://www.R-project.org/posting-guide.html and provide
SM 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] Need some help in R programming code

2008-11-22 Thread jim holtman
You need to also provide the data that your code is using since the
error message indicates that the problem is probably in the way that
the object 'a' is defined and there is no indication of what it looks
like.  You should either provide the output of str(a), or the output
of 'dput(a)' so we have an idea of what it is.  The error message
seems to indicate the the $ is not legal for 'a' as it is currently
defined.

On Sat, Nov 22, 2008 at 4:55 AM, saikat sarkar [EMAIL PROTECTED] wrote:

 Dear R guru,

 I am Saikat Sarkar working as a researcher of Economics in Tampere
 University, Finland. I am trying to estimate some Garch related tests with
 Bayesian analysis by R programme.

 I am not good in R but trying to survive.

 Anyway I have the coding but not working properly. I have tried to find the
 problem but failed. I am writing to all R gurus to help me out.

 Could you please look at the problem and help me if you can.

 Thanking you
 saikat

 Could you please look at the problem below:

 R message is like below:
 ---
 Error in garch.gjr.d0(param, y, X, Z, iterate = FALSE)$res :
  $ operator is invalid for atomic vectors
 plot(Ch.mic,Ch.mic.rep,xlim=c(0,6),ylim=c(0,6))
 ---
 Coding
 

 res-garch.gjr.d0(a$estimate,y,X,X,iterate=FALSE)$res
 sig2-garch.gjr.d0(a$estimate,y,X,X,iterate=FALSE)$sig2


 test.mic - function(param,y,X,Z)

 {
   n - length(y)

   res - garch.gjr.d0(param,y,X,Z,iterate=FALSE)$res

   s2 - garch.gjr.d0(param,y,X,Z,iterate=FALSE)$sig2

   s-sqrt(s2)

   r - res

   u - r[-1]

   r2- (r[-n]^2*s2[-n])/s[-1]

   r3- (r[-n]^3*s2[-n]*s[-n])/s[-1]

   U - cbind(r[-n],r2,r3)

   U - cbind(1,U)

   U - U/matrix(s[-1],nr=nrow(U),nc=ncol(U))

   Fstat-summary(lm(u~U-1))$fstatistic[1]

   Fstat

 }


 sim.gjr - function(par,y,X=0,Z=0)
 {

   n - length(y)

   e-numeric(n)

   yrep-numeric(n)

   yrep[1] - y[1]

   n.dummies.mean - dim(X)[2]

   if(is.matrix(X)) e[1] - e[1]-sum(X[1,]*par[9:(8+n.dummies.mean)])

   delta - par[-(1:(8+n.dummies.mean))]

   s2 - var(y)

   for(i in 2:n){

 s2 -
 par[5]+par[6]*e[i-1]^2+par[7]*ifelse(e[i-1]0,1,0)*e[i-1]^2+par[8]*s2+sum(X[i,]*delta)

 e[i] - rnorm(1,0,sqrt(s2))

 yrep[i]-par[1]+par[2]*yrep[i-1]+par[3]*s2+par[4]*yrep[i-1]*s2+e[i]

   }


   if(is.matrix(X)) yrep - yrep + X%*%par[9:(8+n.dummies.mean)]

   yrep
 }

 yrep - sim.gjr(a$estimate,y,X,Z)


 n.test - 500

 Ch.mic - Ch.mic.rep - numeric(n.test)

 for(i in 1:n.test){

   simulation - sample(1:1,1)

   par - sims.matrix[simulation,]

   Ch.mic[i] - test.mic(par,y,X,X)

   yrep - sim.gjr(par,y,X,X)

   Ch.mic.rep[i] - test.mic(par,yrep,X,X)
 }

  plot(Ch.mic,Ch.mic.rep,xlim=c(0,6),ylim=c(0,6))

  lines(c(0,6),c(0,6))
 --
 View this message in context: 
 http://www.nabble.com/Need-some-help-in-R-programming-code-tp20634187p20634187.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.




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

What is the problem that you are trying to solve?

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


[R] Nested Clade Analysis

2008-11-22 Thread knussear

Hi

Wondering if anyone knows of a package that does Nested Clade Analysis?

Thanks
-- 
View this message in context: 
http://www.nabble.com/Nested-Clade-Analysis-tp20637180p20637180.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] Basic question on concatenating factors

2008-11-22 Thread jim holtman
Here is a function I have used.  I got it from the list, and
unfortunately don't remember who to credit:

 c.Factor -
function (x, y)
{
newlevels = union(levels(x), levels(y))
m = match(levels(y), newlevels)
ans = c(unclass(x), m[unclass(y)])
levels(ans) = newlevels
class(ans) = factor
ans
}


On Fri, Nov 21, 2008 at 12:29 PM, Alain Guillet
[EMAIL PROTECTED] wrote:
 Hi,

 I have a solution to concatenate two factors in one but I don't believe
 it is the best one: factor(c(as.character(f1),as.character(f2)))
 [1] a a b b b a
 Levels: a b


 You can always add a level by assigning a new vector at the level vector:
 levels(f1) - c(a,b,c)
 f1
 [1] a a b
 Levels: a b c



 udi cohen wrote:
 Hi all,

 I hope it's not too trivial for the list - I'm trying to concatenate
 two factor arrays, and obtain the following:


 f1-factor(c(a,a,b))
 f1

 [1] a a b
 Levels: a b

 f2-factor(c(b,b,a))
 f2

 [1] b b a
 Levels: a b

 c(f1,f2)

 [1] 1 1 2 2 2 1

 Instead of getting:

 [1] a a b b b a
 Levels: a b

 a related question is: how do I add a level which does not exists yet
 in a factored vector, so I'll be able to add later these values,
 without getting:

 In `[-.factor`(`*tmp*`, 2, value = c) :
   invalid factor level, NAs generated

 Thanks,

 EC

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



 --
 Alain Guillet
 Statistician and Computer Scientist

 SMCS - Institut de statistique - Université catholique de Louvain
 Bureau d.126
 Voie du Roman Pays, 20
 B-1348 Louvain-la-Neuve
 Belgium

 tel: +32 10 47 30 50


[[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 that you are trying to solve?

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


Re: [R] rgl lighting question

2008-11-22 Thread Duncan Murdoch

On 21/11/2008 2:30 PM, Rajarshi Guha wrote:
Hi, I'm using rgl to generate a 3D surface plot and I'm struggling to  
get the lighting correct. Currently the surface gets plotted, but is  
very 'shiny'. On rotating the view, I get to see parts of the surface  
- but overall I don't see much detail because of the spotlight like  
lighting.


I've played around with the specular, ambient and diffuse but I can't  
bring out the details of the surface. Could anybody point me to some  
examples of how to make a plain matte surface, which isn't obscured  
by specular reflections?


This gives the regular shiny surface:

library(rgl)
example(surface3d)

This gives one with no specular reflections, because the material 
doesn't do that:


open3d()
surface3d(x, y, z, color=col, back=lines, specular=black)

And here's another way to get no specular reflections.  This time 
there's no light to reflect that way:


open3d()
rgl.pop(lights)
light3d(specular=black)
surface3d(x, y, z, color=col, back=lines)

I suspect you missed the rgl.pop() call.  If you just call light3d or 
rgl.light() you'll add an additional light, you don't change the 
existing one.


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] different .Rprofile files for different projects

2008-11-22 Thread Gavin Simpson
On Thu, 2008-11-20 at 19:43 -0800, Andrew J. Rominger wrote:
 Dear list,
 
 First off, let me offer my apologies, I know this is a very basic
 question.  After amassing a large number of objects (from multiple
 projects) in one working directory, I'd like to be able to start using
 different directories, just for the sake of organization alone.  But I
 have no idea how to do this.  I am using a mac, running R 2.5.

I'm not very familiar with the MacOS X version of R, but students of
mine were using it recently and under the Misc menu there is an entry to
change the working directory, which provides a standard Mac directory
selection dialogue box IIRC.

Alternatively, start R as per usual and then change into the correct
directory using the setwd() function.

You should probably update your R - 2.5.0 is 18 months old now, 2.8.0 is
current.

G

 
 Searching the FAQ online I find:
 
 12.1 How can I have a per session .Rprofile?
 You can by writing a .Rprofile file in your favorite session
 directory...
 
 So I think my specific question is how do I write a .Rprofile?  I know
 it should be obvious, but is there a command to be called in the R
 console during a given session, or do I write a stub file outside of R
 (in a session directory?), open this using Preferences and then modify
 it in an R session?  If the latter, how do I go about writing a stub
 and making R recognize it as a working directory, and what is a
 session directory/how can I find where the default session directory
 is located?
 
 Again, my apologies for being naive, and thanks very much for any
 help--
 Andy Rominger
 
 __
 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.
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
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] Basic question on concatenating factors

2008-11-22 Thread Henrique Dallazuanna
You can try this also:

unlist(list(f1, f2))

On Fri, Nov 21, 2008 at 3:15 PM, udi cohen [EMAIL PROTECTED] wrote:

 Hi all,

 I hope it's not too trivial for the list - I'm trying to concatenate
 two factor arrays, and obtain the following:

  f1-factor(c(a,a,b))
  f1
 [1] a a b
 Levels: a b
  f2-factor(c(b,b,a))
  f2
 [1] b b a
 Levels: a b
  c(f1,f2)
 [1] 1 1 2 2 2 1

 Instead of getting:

 [1] a a b b b a
 Levels: a b

 a related question is: how do I add a level which does not exists yet
 in a factored vector, so I'll be able to add later these values,
 without getting:

 In `[-.factor`(`*tmp*`, 2, value = c) :
  invalid factor level, NAs generated

 Thanks,

 EC

 __
 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] declaring constants in an Sweave / LaTeX document

2008-11-22 Thread Duncan Murdoch

On 22/11/2008 2:01 AM, Kyle Matoba wrote:

List,

I would like to set a variable to hold, say, the size of my plots in a
Sweave document.  i.e. something like the following in my '.Rnw' file:

==
smallPlotSize = 4

fig1, echo=false, results=hide, height=smallPlotSize, width=smallPlotSize,
fig=true=
dat - read.table(
http://www.stanford.edu/~xing/statfinbook/_BookData/Chap05/q_us_gdp.txt;,
skip=2, header=T)

GDP - ts(data=dat$VALUE, start=c(1947,1), frequency=4)

acf(GDP, type=correlation, main= ACF of US GDP)
@
==


I don't think that is possible, but you can do things like

\SweaveOpts{height=3.5, width=7}

anywhere in your document to set the default size for subsequent plots.

You can also set LaTeX macros to change the displayed size, e.g.

\newcommand{\Fullwidth}{\setkeys{Gin}{width=\textwidth}}
\newcommand{\Smallwidth}{\setkeys{Gin}{width=4in}}

Here you're talking to LaTeX, not to R, so those are setting options to 
the \includegraphics{} calls.  Unfortunately, you can't put \SweaveOpts 
in the macro to also set the R width and height, because Sweave handles 
all the \SweaveOpts calls before calling LaTeX.


Duncan Murdoch


This way I can tweak things if I have to include a bunch of graphics of the
same size in a file.  I am not great with LaTeX and still very new to using
Sweave, so I was wondering what the preferred method of doing something like
this is between LaTeX and Sweave.  I have seen some people doing some tricky
stuff from within R such that when their code is preprocessed it is compiled
as LaTeX source, but this seems like an ugly hack for something so simple.

Please forgive me if this has been addressed elsewhere; I have found
documentation on Sweave to be rather sparse.

Best,

Kyle

[[alternative HTML version deleted]]

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


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


Re: [R] How to add the value on the barchart

2008-11-22 Thread John Kane
Try something like the code below.  Unfortunately I cannot remember who wrote 
the code.  
===

my.values=10:15
 x - barplot(my.values, ylim=c(0,11))

 text(x, my.values, wibble, pos=3) # always does what you want
 # whereas:

 text(x, 0.6+my.values, wibble) # doesn't look very nice
 
=
--- On Fri, 11/21/08, Piya Kittipadakul [EMAIL PROTECTED] wrote:

 From: Piya Kittipadakul [EMAIL PROTECTED]
 Subject: [R] How to add the value on the barchart
 To: r-help@r-project.org
 Received: Friday, November 21, 2008, 7:14 PM
 I have question: how can I put the value on the bar chart.
 This my code:
 barchart(Tuberize~Family|factor(Year)*factor(Hr),data=tuber)
 
 This's my data:
    Year Hr Family Tuberize
 1  2007 20  A 0.26
 2  2007 20  B 6.08
 3  2007 20  C 0.00
 4  2007 20  D 0.27
 5  2008 20  A 1.18
 6  2008 20  B 9.17
 7  2008 20  C 0.00
 8  2008 20  D 2.13
 9  2007 14  A    35.83
 10 2007 14  B    38.98
 11 2007 14  C 7.90
 12 2007 14  D    18.75
 13 2008 14  A    43.70
 14 2008 14  B    51.84
 15 2008 14  C    27.11
 16 2008 14  D    24.11
 17 2008 11  A    85.67
 18 2008 11  B    93.73
 19 2008 11  C    81.45
 20 2008 11  D    90.25
 21 2007  8  A    63.04
 22 2007  8  B    66.29
 23 2007  8  C    70.85
 24 2007  8  D    83.48
 25 2008  8  A    83.33
 26 2008  8  B    92.31
 27 2008  8  C    82.21
 28 2008  8  D    94.03
 
 Thank you
 Piya
 
 
   
   [[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.


  __
Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your 
favourite sites. Download it now at
http://ca.toolbar.yahoo.com.

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


Re: [R] rgl lighting question

2008-11-22 Thread Rajarshi Guha
Thanks a lot for the pointer to rgl.pop() - that works (as does  
looking at the examples!)


On Nov 22, 2008, at 10:28 AM, Duncan Murdoch wrote:


On 21/11/2008 2:30 PM, Rajarshi Guha wrote:
Hi, I'm using rgl to generate a 3D surface plot and I'm struggling  
to  get the lighting correct. Currently the surface gets plotted,  
but is  very 'shiny'. On rotating the view, I get to see parts of  
the surface  - but overall I don't see much detail because of the  
spotlight like  lighting.
I've played around with the specular, ambient and diffuse but I  
can't  bring out the details of the surface. Could anybody point  
me to some  examples of how to make a plain matte surface, which  
isn't obscured  by specular reflections?


This gives the regular shiny surface:

library(rgl)
example(surface3d)

This gives one with no specular reflections, because the material  
doesn't do that:


open3d()
surface3d(x, y, z, color=col, back=lines, specular=black)

And here's another way to get no specular reflections.  This time  
there's no light to reflect that way:


open3d()
rgl.pop(lights)
light3d(specular=black)
surface3d(x, y, z, color=col, back=lines)

I suspect you missed the rgl.pop() call.  If you just call light3d  
or rgl.light() you'll add an additional light, you don't change the  
existing one.


Duncan Murdoch


---
Rajarshi Guha  [EMAIL PROTECTED]
GPG Fingerprint: D070 5427 CC5B 7938 929C  DD13 66A1 922C 51E7 9E84
---
Paper or plastic?
Not 'Not paper AND not plastic!!'
 -- Augustus DeMorgan in a grocery store

__
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 add the value on the barchart

2008-11-22 Thread David Winsemius

Following the example in
https://stat.ethz.ch/pipermail/r-help/2006-January/086985.html

You might want to try something like:
 barchart(Tuberize~Family|factor(Year)*factor(Hr),data=tuber,
+   panel = function(y,x,...){
+   panel.barchart(x,y,...)
+   panel.text(x,y,label = tuber$Tuberize, pos=3)
+   }
+ )

It still needs some work to increase the ylim so the values are not  
obscured at the upper ranges of the panels, but this should point you  
in the right direction.


--
David Winsemius

On Nov 21, 2008, at 7:14 PM, Piya Kittipadakul wrote:


I have question: how can I put the value on the bar chart.
This my code:
barchart(Tuberize~Family|factor(Year)*factor(Hr),data=tuber)

This's my data:
   Year Hr Family Tuberize
1  2007 20  A 0.26
2  2007 20  B 6.08
3  2007 20  C 0.00
4  2007 20  D 0.27
5  2008 20  A 1.18
6  2008 20  B 9.17
7  2008 20  C 0.00
8  2008 20  D 2.13
9  2007 14  A35.83
10 2007 14  B38.98
11 2007 14  C 7.90
12 2007 14  D18.75
13 2008 14  A43.70
14 2008 14  B51.84
15 2008 14  C27.11
16 2008 14  D24.11
17 2008 11  A85.67
18 2008 11  B93.73
19 2008 11  C81.45
20 2008 11  D90.25
21 2007  8  A63.04
22 2007  8  B66.29
23 2007  8  C70.85
24 2007  8  D83.48
25 2008  8  A83.33
26 2008  8  B92.31
27 2008  8  C82.21
28 2008  8  D94.03

Thank you
Piya



[[alternative HTML version deleted]]

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


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


Re: [R] How to add the value on the barchart

2008-11-22 Thread David Winsemius
On second look I see that although values appear in every panel, they  
are the same in every panel as well. Some sort of use of the  
subscripting facility probably needs to be employed.


--
David Winsemius
On Nov 22, 2008, at 1:05 PM, David Winsemius wrote:


Following the example in
https://stat.ethz.ch/pipermail/r-help/2006-January/086985.html

You might want to try something like:
 barchart(Tuberize~Family|factor(Year)*factor(Hr),data=tuber,
+   panel = function(y,x,...){
+   panel.barchart(x,y,...)
+   panel.text(x,y,label = tuber$Tuberize, pos=3)
+   }
+ )

It still needs some work to increase the ylim so the values are not  
obscured at the upper ranges of the panels, but this should point  
you in the right direction.


--
David Winsemius

On Nov 21, 2008, at 7:14 PM, Piya Kittipadakul wrote:


I have question: how can I put the value on the bar chart.
This my code:
barchart(Tuberize~Family|factor(Year)*factor(Hr),data=tuber)

This's my data:
  Year Hr Family Tuberize
1  2007 20  A 0.26
2  2007 20  B 6.08
3  2007 20  C 0.00
4  2007 20  D 0.27
5  2008 20  A 1.18
6  2008 20  B 9.17
7  2008 20  C 0.00
8  2008 20  D 2.13
9  2007 14  A35.83
10 2007 14  B38.98
11 2007 14  C 7.90
12 2007 14  D18.75
13 2008 14  A43.70
14 2008 14  B51.84
15 2008 14  C27.11
16 2008 14  D24.11
17 2008 11  A85.67
18 2008 11  B93.73
19 2008 11  C81.45
20 2008 11  D90.25
21 2007  8  A63.04
22 2007  8  B66.29
23 2007  8  C70.85
24 2007  8  D83.48
25 2008  8  A83.33
26 2008  8  B92.31
27 2008  8  C82.21
28 2008  8  D94.03

Thank you
Piya



[[alternative HTML version deleted]]

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


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


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


Re: [R] Fitting a sine wave using solver

2008-11-22 Thread Carl Witthoft

To follow Dieter's comment,

You can in fact fit a data to a sine in Excel using LINEST.  I've done 
it.  I don't recommend it :-) .


What I did was create columns containing sin(x) and cos(x) , roughly 
speaking, and fit using


LINEST([y=values],{sines, cosines},...)

Ya need the cosines or something similar to get rid of phase ambiguity.


But using either FFTs or glm()  should do fine.

And stay away from Excel!  :-(

Carl

__
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 add the value on the barchart

2008-11-22 Thread David Winsemius

No, it only needed closer attention to the example:

This gets you to the point where you need to fix the y scale settings  
but the values are properly cycled through.


barchart(Tuberize~Family|factor(Year)*factor(Hr),data=tuber,
panel = function(y,x,...){
panel.barchart(x,y,...)
panel.text(x,y,label = y, pos=3)
   }

)

And this fixes the lack of space problem, albeit with not a  
particularly general solution:


barchart(Tuberize~Family|factor(Year)*factor(Hr),data=tuber,
prepanel = function(x,y){ list(ylim = c(0,120) )},
panel = function(y,x,...){
panel.barchart(x,y,...)
panel.text(x,y,label = y, pos=3)
 }
)
As we say in medical circles, ... Thank you for this interesting  
consult.


--
David Winsemius, MD

On Nov 22, 2008, at 2:16 PM, David Winsemius wrote:

On second look I see that although values appear in every panel,  
they are the same in every panel as well. Some sort of use of the  
subscripting facility probably needs to be employed.


--
David Winsemius
On Nov 22, 2008, at 1:05 PM, David Winsemius wrote:


Following the example in
https://stat.ethz.ch/pipermail/r-help/2006-January/086985.html

You might want to try something like:
 barchart(Tuberize~Family|factor(Year)*factor(Hr),data=tuber,
+   panel = function(y,x,...){
+   panel.barchart(x,y,...)
+   panel.text(x,y,label = tuber$Tuberize, pos=3)
+   }
+ )

It still needs some work to increase the ylim so the values are not  
obscured at the upper ranges of the panels, but this should point  
you in the right direction.


--
David Winsemius

On Nov 21, 2008, at 7:14 PM, Piya Kittipadakul wrote:


I have question: how can I put the value on the bar chart.
This my code:
barchart(Tuberize~Family|factor(Year)*factor(Hr),data=tuber)

This's my data:
 Year Hr Family Tuberize
1  2007 20  A 0.26
2  2007 20  B 6.08
3  2007 20  C 0.00
4  2007 20  D 0.27
5  2008 20  A 1.18
6  2008 20  B 9.17
7  2008 20  C 0.00
8  2008 20  D 2.13
9  2007 14  A35.83
10 2007 14  B38.98
11 2007 14  C 7.90
12 2007 14  D18.75
13 2008 14  A43.70
14 2008 14  B51.84
15 2008 14  C27.11
16 2008 14  D24.11
17 2008 11  A85.67
18 2008 11  B93.73
19 2008 11  C81.45
20 2008 11  D90.25
21 2007  8  A63.04
22 2007  8  B66.29
23 2007  8  C70.85
24 2007  8  D83.48
25 2008  8  A83.33
26 2008  8  B92.31
27 2008  8  C82.21
28 2008  8  D94.03

Thank you
Piya



[[alternative HTML version deleted]]

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


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




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


Re: [R] Bug in Kendall for n4?

2008-11-22 Thread Stavros Macrakis
On Sat, Nov 22, 2008 at 9:04 AM, Martin Maechler
[EMAIL PROTECTED] wrote:
SM I believe Kendall tau is well-defined for this case...

 The real question is  *WHY* there needs to be a separate package 'Kendall'  
 when R itself does everything you want and does not show any problems?

Thanks for pointing me to cor(...,method=kendall), which I did not
know about; I used the Kendall CRAN package out of pure ignorance.

In my defense, I think it is excusable ignorance, as Search on the R
Project home page finds the Kendall package (which only mentions cor
as a See Also).  I only more recently discovered the advantages of
help.search.

By the way, is Kendall well-defined when the arguments are not
permutations of each other?  cor seems to return results even in this
case:

   a-factor(c(Alice,Bob,Chris))
   b-a[1:2]
   c-a[2:3]
   cor(a,b,method=kendall)
   =  1

apparently interpreting b as c(1,2) and c as c(1,2) based on
alphabetical order (even though it is an UNordered factor), which
seems to make the value depend on the subjects' names, which I'd think
was wrong for a rank-order statistic.

Thanks again,

   -s

__
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] applying an operation for several dataframes

2008-11-22 Thread Georg Ehret
Dear R community,
I am trying to apply a simple operation to several dataframes (e.g.
nrow) and cannot get the looping to work. My objective is to get an output
that indicates me the number of rows for every dataframe.

 c
  V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
1  1 11 21 31 41 51 61 71 81  91
2  2 12 22 32 42 52 62 72 82  92
3  3 13 23 33 43 53 63 73 83  93
4  4 14 24 34 44 54 64 74 84  94
5  5 15 25 35 45 55 65 75 85  95
 cc
   V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
1   1 11 21 31 41 51 61 71 81  91
2   2 12 22 32 42 52 62 72 82  92
3   3 13 23 33 43 53 63 73 83  93
4   4 14 24 34 44 54 64 74 84  94
5   5 15 25 35 45 55 65 75 85  95
6   6 16 26 36 46 56 66 76 86  96
7   7 17 27 37 47 57 67 77 87  97
8   8 18 28 38 48 58 68 78 88  98
9   9 19 29 39 49 59 69 79 89  99
10 10 20 30 40 50 60 70 80 90 100
 names-c(c,cc)
 for(i in names){nrow(i)}

Thank you!
Georg.
*
Georg Ehret
[EMAIL PROTECTED]
Geneva University Hospital
Switzerland

[[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] applying an operation for several dataframes

2008-11-22 Thread jim holtman
?get

names - c('c', 'cc')
for (i in names){
print(nrow(get(i)))
}


On Sat, Nov 22, 2008 at 4:06 PM, Georg Ehret [EMAIL PROTECTED] wrote:
 Dear R community,
I am trying to apply a simple operation to several dataframes (e.g.
 nrow) and cannot get the looping to work. My objective is to get an output
 that indicates me the number of rows for every dataframe.

 c
  V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
 1  1 11 21 31 41 51 61 71 81  91
 2  2 12 22 32 42 52 62 72 82  92
 3  3 13 23 33 43 53 63 73 83  93
 4  4 14 24 34 44 54 64 74 84  94
 5  5 15 25 35 45 55 65 75 85  95
 cc
   V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
 1   1 11 21 31 41 51 61 71 81  91
 2   2 12 22 32 42 52 62 72 82  92
 3   3 13 23 33 43 53 63 73 83  93
 4   4 14 24 34 44 54 64 74 84  94
 5   5 15 25 35 45 55 65 75 85  95
 6   6 16 26 36 46 56 66 76 86  96
 7   7 17 27 37 47 57 67 77 87  97
 8   8 18 28 38 48 58 68 78 88  98
 9   9 19 29 39 49 59 69 79 89  99
 10 10 20 30 40 50 60 70 80 90 100
 names-c(c,cc)
 for(i in names){nrow(i)}

 Thank you!
 Georg.
 *
 Georg Ehret
 [EMAIL PROTECTED]
 Geneva University Hospital
 Switzerland

[[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 that you are trying to solve?

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


Re: [R] syntax and package for generalized linear mixed models

2008-11-22 Thread David Winsemius

On Nov 21, 2008, at 11:28 AM, Douglas Bates wrote:

 As tempting as it may be to want to have several dials and knobs on
 statistical models to tune their behavior, we still need to be careful
 to specify a mathematical model that is consistent.

  -- Douglas Bates

Yet another fortune candidate.

-- 
David Winsemius



[[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] unique columns in a matrix and number of each

2008-11-22 Thread Salas, Andria Kay
I need help determining the unique columns of a matrix and the numbers of each 
unique column.  For example, let's say I have a matrix with 6 columns, 2 of 
these are filled with the value of 1 and the other 4 are filled with the value 
of 0.  I would then like to have a command that tells me what the unique 
columns are (so columns with 1s and columns with 0s) and the number of each 
type of column (so 2 columns of 1s and 4 columns of 0s) that occur in the 
matrix.  

Thank you for any help anyone can provide!!  I have been very impressed with 
the help that I have received so far!!  Thank you!  
__
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] Where is Hong Kong in maps?

2008-11-22 Thread Wind2

It seems that there is no Hong Kong in maps' world cities.

world.cities[substr(world.cities$name,1,3)==Hon,]
 namecountry.etcpop   latlong capital
14623  Honami  Japan  26040 33.61  130.68   0
14624   Honaz Turkey   8073 37.75   29.27   0
14625   Honda   Colombia  28055  5.19  -74.75   0
14626  Hondaidhoo   Maldives 83  6.77   73.08   0
14627 Hondarribia  Spain  16159 43.37   -1.80   0
14628   Hondo  Japan  40728 32.46  130.19   0
14629 Hondo Valle Dominican Republic   3695 18.72  -71.70   0
14630Honefoss Norway  13587 60.19   10.23   0
14631HongDenmark   3792 55.52   11.30   0
14632Hong GaiVietnam 149427 20.97  107.08   0
14633  Hongan  China  65273 31.28  114.61   0
14634HongchonKorea South  33721 37.69  127.89   0
14635Honggang  China 150194 46.47  124.87   0
14636  Honghu  China 178779 29.82  113.47   0
14637   Hongjiang  China  59377 27.12  109.99   0
14638HongsongKorea South  38208 36.60  126.66   0
14639 HongwonKorea North  71617 40.02  127.97   0
14640 HoniaraSolomon Islands  57410 -9.43  159.91   1
14641 Honiton UK  11516 50.81   -3.20   0
14642   Honjo  Japan  46939 39.44  140.09   0
14643   Honjo  Japan  61961 36.24  139.18   0
14644   HonkajokiFinland   1950 61.83   21.53   0
14645 Honningsvag Norway   2521 70.98   25.98   0
14646HonoluluUSA 386345 21.32 -157.80   0

The info of the maps package:
Package:   maps
Title: Draw Geographical Maps
Version:   2.0-40
Date:  2008-04-17

I wonder maybe I have made some mistakes using maps since I am a beginner in
R.


-- 
View this message in context: 
http://www.nabble.com/Where-is-Hong-Kong-in-maps%EF%BC%9F-tp20635934p20635934.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's the BEST way in R to adapt this vector?

2008-11-22 Thread zerfetzen

Goal:
Suppose you have a vector that is a discrete variable with values ranging
from 1 to 3, and length of 10.  We'll use this as the example:

y - c(1,2,3,1,2,3,1,2,3,1)

...and suppose you want your new vector (y.new) to be equal in length to the
possible discrete values (3) times the length (10), and formatted in such a
way that if y[1] == 1, then y.new[1:3] == c(1,0,0), and if y[2] == 2, then
y.new[4:6] == c(0,1,0).  For example, the final goal should be:

y.new - c(1,0,0,0,1,0,0,0,1,1,0,0,0,1,0,0,0,1,1,0,0,0,1,0,0,0,1,1,0,0)

Note: I know how to do this with loops, but that's not taking advantage of
R's capabilities with vectors and, I suspect, matrices.

So far, my best guess would be to start as follows:

y1 - ifelse(y == 1, 1, 0)
y2 - ifelse(y == 2, 1, 0)
y3 - ifelse(y == 3, 1, 0)

From here, maybe put these into a 10x3 matrix, and read them out by row into
y.new?  Is that even the most efficient way?  If it is, I'm sure I can get
them into a matrix, but how do I read them out correctly?  Thanks for any
input.
-- 
View this message in context: 
http://www.nabble.com/What%27s-the-BEST-way-in-R-to-adapt-this-vector--tp20638991p20638991.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] What's the BEST way in R to adapt this vector?

2008-11-22 Thread hadley wickham
On Sat, Nov 22, 2008 at 12:00 PM, zerfetzen [EMAIL PROTECTED] wrote:

 Goal:
 Suppose you have a vector that is a discrete variable with values ranging
 from 1 to 3, and length of 10.  We'll use this as the example:

 y - c(1,2,3,1,2,3,1,2,3,1)

 ...and suppose you want your new vector (y.new) to be equal in length to the
 possible discrete values (3) times the length (10), and formatted in such a
 way that if y[1] == 1, then y.new[1:3] == c(1,0,0), and if y[2] == 2, then
 y.new[4:6] == c(0,1,0).  For example, the final goal should be:

 y.new - c(1,0,0,0,1,0,0,0,1,1,0,0,0,1,0,0,0,1,1,0,0,0,1,0,0,0,1,1,0,0)

 Note: I know how to do this with loops, but that's not taking advantage of
 R's capabilities with vectors and, I suspect, matrices.

How about:

as.vector(diag(3)[, y])

Hadley

-- 
http://had.co.nz/

__
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] What's the BEST way in R to adapt this vector?

2008-11-22 Thread Gabor Grothendieck
Try this:

outer(y, sort(unique(y)), ==)+0


On Sat, Nov 22, 2008 at 3:37 PM, zerfetzen [EMAIL PROTECTED] wrote:

 Goal:
 Suppose you have a vector that is a discrete variable with values ranging
 from 1 to 3, and length of 10.  We'll use this as the example:

 y - c(1,2,3,1,2,3,1,2,3,1)

 ...and suppose you want your new vector (y.new) to be equal in length to the
 possible discrete values (3) times the length (10), and formatted in such a
 way that if y[1] == 1, then y.new[1:3] == c(1,0,0), and if y[2] == 2, then
 y.new[4:6] == c(0,1,0).  For example, the final goal should be:

 y.new - c(1,0,0,0,1,0,0,0,1,1,0,0,0,1,0,0,0,1,1,0,0,0,1,0,0,0,1,1,0,0)

 Note: I know how to do this with loops, but that's not taking advantage of
 R's capabilities with vectors and, I suspect, matrices.

 So far, here's my best:

 y - c(1,2,3,1,2,3,1,2,3,1)
 y.k - length(unique(y)) #Num. of Categories of y
 y.n - NROW(y)
 y.nk - y.n * y.k #Length of new vector
 y.1 - ifelse(y == 1,1,0)
 y.2 - ifelse(y == 2,1,0)
 y.3 - ifelse(y == 3,1,0)
 z - cbind(y.1, y.2, y.3)
 z.trans - t(z)
 y.new - c(1:y.nk); y.new[1:y.nk] - NA
 y.new - as.vector(z.trans)
 rm(y.k, y.n, y.nk, y.1, y.2, y.3, z, z.trans)
 y
 y.new

 Is there a better a way?  I'm still pretty new.  Thanks.
 --
 View this message in context: 
 http://www.nabble.com/What%27s-the-BEST-way-in-R-to-adapt-this-vector--tp20638991p20638991.html
 Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] What's the BEST way in R to adapt this vector?

2008-11-22 Thread Berwin A Turlach
On Sat, 22 Nov 2008 10:00:18 -0800 (PST)
zerfetzen [EMAIL PROTECTED] wrote:

 Goal:
 Suppose you have a vector that is a discrete variable with values
 ranging from 1 to 3, and length of 10.  We'll use this as the example:
 
 y - c(1,2,3,1,2,3,1,2,3,1)
 
 ...and suppose you want your new vector (y.new) to be equal in length
 to the possible discrete values (3) times the length (10), and
 formatted in such a way that if y[1] == 1, then y.new[1:3] ==
 c(1,0,0), and if y[2] == 2, then y.new[4:6] == c(0,1,0).  For
 example, the final goal should be:
 
 y.new -
 c(1,0,0,0,1,0,0,0,1,1,0,0,0,1,0,0,0,1,1,0,0,0,1,0,0,0,1,1,0,0)
 
 Note: I know how to do this with loops, but that's not taking
 advantage of R's capabilities with vectors and, I suspect, matrices.

 So far, my best guess would be to start as follows:
[]

My guess would be to use:

R y - c(1,2,3,1,2,3,1,2,3,1)
R y.new - as.numeric(as.vector(outer(sort(unique(y)), y, ==)))
R y.new
 [1] 1 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 1 1 0 0


 [...] From here, maybe put these into a 10x3 matrix, and read them out
 by row into y.new?  

Better put them into a 3x10 matrix and then turn the matrix into a
vector by as.vector().  Essentially, a matrix is a vector with an
attribute giving the dimensions of a matrix and as.vector() removes that
attribute.  Furthermore, in R (just as in Fortran), matrices are stored
in column major format; thus, as soon as the dim attribute is removed,
the values are in the correct order.

HTH.

Cheers,

Berwin

=== Full address =
Berwin A TurlachTel.: +65 6516 4416 (secr)
Dept of Statistics and Applied Probability+65 6516 6650 (self)
Faculty of Science  FAX : +65 6872 3919   
National University of Singapore 
6 Science Drive 2, Blk S16, Level 7  e-mail: [EMAIL PROTECTED]
Singapore 117546http://www.stat.nus.edu.sg/~statba

__
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] Basic question on concatenating factors

2008-11-22 Thread Stavros Macrakis
On Sat, Nov 22, 2008 at 10:20 AM, jim holtman [EMAIL PROTECTED] wrote:
  c.Factor -
 function (x, y)
 {
newlevels = union(levels(x), levels(y))
m = match(levels(y), newlevels)
ans = c(unclass(x), m[unclass(y)])
levels(ans) = newlevels
class(ans) = factor
ans
 }

This algorithm depends crucially on union preserving the order of the
elements of its arguments. As far as I can tell, the spec of union
does not require this.  If union were to (for example) sort its
arguments then merge them (generally a more efficient algorithm), this
function would no longer work.

Fortunately, the fix is simple.  Instead of union, use:

 newlevels - c(levels(x),setdiff(levels(y),levels(x))

which is guaranteed to preserve the order of levels(x).

 -s

__
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] Basic question on concatenating factors

2008-11-22 Thread jim holtman
You are right.  union used 'unique(c(x,y))' and I am not sure if
'unique' preserves the order, but the help page seems to indicate that
 an element is omitted if it is identical to any previous element ;
this might mean that the order is preserved.

On Sat, Nov 22, 2008 at 11:43 PM, Stavros Macrakis
[EMAIL PROTECTED] wrote:
 On Sat, Nov 22, 2008 at 10:20 AM, jim holtman [EMAIL PROTECTED] wrote:
  c.Factor -
 function (x, y)
 {
newlevels = union(levels(x), levels(y))
m = match(levels(y), newlevels)
ans = c(unclass(x), m[unclass(y)])
levels(ans) = newlevels
class(ans) = factor
ans
 }

 This algorithm depends crucially on union preserving the order of the
 elements of its arguments. As far as I can tell, the spec of union
 does not require this.  If union were to (for example) sort its
 arguments then merge them (generally a more efficient algorithm), this
 function would no longer work.

 Fortunately, the fix is simple.  Instead of union, use:

 newlevels - c(levels(x),setdiff(levels(y),levels(x))

 which is guaranteed to preserve the order of levels(x).

 -s




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

What is the problem that you are trying to solve?

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


Re: [R] unique columns in a matrix and number of each

2008-11-22 Thread jim holtman
One way is to 'paste' together the values in a column and then use
'table' to count them.

'duplicated' can probably do the same thing with the MARGIN option to
find the duplicated one.  You still them have to find the original
ones.

On Sat, Nov 22, 2008 at 3:42 PM, Salas, Andria Kay [EMAIL PROTECTED] wrote:
 I need help determining the unique columns of a matrix and the numbers of 
 each unique column.  For example, let's say I have a matrix with 6 columns, 2 
 of these are filled with the value of 1 and the other 4 are filled with the 
 value of 0.  I would then like to have a command that tells me what the 
 unique columns are (so columns with 1s and columns with 0s) and the number of 
 each type of column (so 2 columns of 1s and 4 columns of 0s) that occur in 
 the matrix.

 Thank you for any help anyone can provide!!  I have been very impressed with 
 the help that I have received so far!!  Thank you!
 __
 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 that you are trying to solve?

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


Re: [R] Basic question on concatenating factors

2008-11-22 Thread Prof Brian Ripley

On Sun, 23 Nov 2008, jim holtman wrote:


You are right.  union used 'unique(c(x,y))' and I am not sure if
'unique' preserves the order, but the help page seems to indicate that
an element is omitted if it is identical to any previous element ;
this might mean that the order is preserved.


It says

 'unique' returns a vector, data frame or array like 'x' but with
 duplicate elements/rows removed.

Although it is a generic function, it is hard to see how that can be 
interpreted to allow the order to be changed.


The claim that union would be more efficiently implemented via sorting is 
made with no evidence: do look up a basic computer science textbook for 
this kind of thing, as well as how R actually does it.  (Also 'efficient' 
was not defined: both speed and memory usage are potentially measures of 
efficiency.)  But for example



x - rnorm(1e7)
system.time(unique(x))

   user  system elapsed
  2.258   0.261   2.523

system.time(sort(x))

   user  system elapsed
  4.102   0.112   4.231

system.time(sort(x, method=quick))

   user  system elapsed
  1.928   0.109   2.047

will indicate that unique() is comparable in speed to sorting.




On Sat, Nov 22, 2008 at 11:43 PM, Stavros Macrakis
[EMAIL PROTECTED] wrote:

On Sat, Nov 22, 2008 at 10:20 AM, jim holtman [EMAIL PROTECTED] wrote:

 c.Factor -
function (x, y)
{
   newlevels = union(levels(x), levels(y))
   m = match(levels(y), newlevels)
   ans = c(unclass(x), m[unclass(y)])
   levels(ans) = newlevels
   class(ans) = factor
   ans
}


This algorithm depends crucially on union preserving the order of the
elements of its arguments. As far as I can tell, the spec of union
does not require this.  If union were to (for example) sort its
arguments then merge them (generally a more efficient algorithm), this
function would no longer work.

Fortunately, the fix is simple.  Instead of union, use:

newlevels - c(levels(x),setdiff(levels(y),levels(x))

which is guaranteed to preserve the order of levels(x).

-s





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

What is the problem that you are trying to solve?

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



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