Re: [R] Histogram problem

2009-08-21 Thread Petr PIKAL
Hi

R does what you said to it it shall do! 

Without  **reproducible** code and explanation what you did, what you get 
and what you **expect** to get it would be quite complicated task to 
understand what your code actually do.

e.g. this

  for (i in 1:Count){
 
  for (j in 1:Count2){
 
 
  if ((SPXdf[i,2]  Bins[j]))
  {Num[j] = Num[j] + 1}
  }
 
  }

add 1 to Num[j] each time when SPXdf[i,2]  Bins[j] but without real 
numbers and understanding why you can not use hist and are making your own 
histogram function it is hard to say what do you want. 
I am pretty sure you are inventing a wheel.

Regards
Petr

Conrad Addo conrad.a...@gmail.com napsal dne 20.08.2009 16:29:36:

 Petr
 
 Actually I wanted to find why the NUm vector was adding incrementally, 
not 
 about the CSV.
 
 Thanks

 On Thu, Aug 20, 2009 at 3:24 PM, Petr PIKAL petr.pi...@precheza.cz 
wrote:
 Hi
 
 r-help-boun...@r-project.org napsal dne 20.08.2009 15:33:38:
 
  I'm trying to create a histogram from the following code, but my data
 keeps
  adding the Num vector and plotting that.  My data in the CSV file is
 just
  one vector.  Does anyone know why?

 Well, I think that only you know why CSV file is just one vector, (which 
I
 do not believe as SPXdf[,2] does not coplain).
 
 
  Thanks
  Conrad
 
 
  SPXdf = data.frame(read.csv(file = SPX.csv, header = TRUE, sep = 
,,
 dec
  = ., fill = TRUE))
 
 
  SPXdf = data.frame(read.csv(file = SPX.csv, header = TRUE, sep = 
,,
 dec
 + = ., fill = TRUE))
 Error in file(file, r) : cannot open the connection
 In addition: Warning message:
 In file(file, r) : cannot open file 'SPX.csv': No such file or 
directory
  Max = max(SPXdf[,2])
 Error: object 'SPXdf' not found
  Min = min(SPXdf[,2])
 E
 
 I can not retrieve the data, it throws an error.
 
 
  Max = max(SPXdf[,2])
  Min = min(SPXdf[,2])
  Count = length(SPXdf[,2])
  sig = sd(SPXdf[,2])
 
  BinSize = (3.5*sig)/(Count^(1/3))
  BinNum = (Max - Min)/(BinSize)
  Bins = seq(Min,Max,by = BinSize)
  Count2 = length(Bins)
  Num = mat.or.vec(1,Count2)
 
 
  for (i in 1:Count){
 
  for (j in 1:Count2){
 
 
  if ((SPXdf[i,2]  Bins[j]))
  {Num[j] = Num[j] + 1}
  }
 
  }
 
  barplot(Num,Bins, xlab = SPXdf, ylab = Frequency)

 R does what you require. You want barplot of Num vector with width
 according to Bin vector.
 
 Just as a curiosity, does hist(SPXdf[,2]) show a histogram?
 
 Regards
 Petr
 
 
 
 [[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] Principle components analysis on a large dataset

2009-08-21 Thread Jari Oksanen
Moshe Olshansky m_olshansky at yahoo.com writes:

 
 Hi Misha,
 
 Since PCA is a linear procedure and you have only 6000 observations, you do
not need 68000 variables. Using
 any 6000 of your variables so that the resulting 6000x6000 matrix is
non-singular will do. You can choose
 these 6000 variables (columns) randomly, hoping that the resulting matrix is
non-singular (and
 checking for this). Alternatively, you can try something like choosing one
nice column, then choosing
 the second one which is the mostly orthogonal to the first one (kind of
Gram-Schmidt), then choose the
 third one which is mostly orthogonal to the first two, etc. (I am not sure how
much rounoff may be a problem-
 try doing this using higher precision if you can). Note that you do not need
to load the entire 6000x68000
 matrix into memory (you can load several thousands of columns, proc
  ess them and discard them).
 Anyway, you will end up with a 6000x6000 matrix, i.e. 36,000,000 entries,
which can fit into a memory and you
 can perform the usual PCA on this matrix.
 
 Good luck!
 
 Moshe.
 
 P.S. I am curious to see what other people think.
 
I think this will give you *a* principal component analysis, but it won't give
you *the* principal component analysis in the sense that the first principal
component would account for a certain proportion of the total variance etc. If
you try this, you see that each random sample will have different eigenvalues,
different proportions of eigenvalues and different sum of all eigenvalues like
you would expect for different data sets.

I even failed to create the raw data matrix of dimensins 68000 x 6000 (Error:
cannot allocate vector of size 3.0 Gb).

Cheers, Jari Oksanen

__
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] a --no-save option for Rprofile.site?

2009-08-21 Thread Barry Rowlingson
On Fri, Aug 21, 2009 at 4:33 AM, Scott Hydehy...@byuh.edu wrote:

 I've found that I can use --no-save after the RCMDR=TRUE above that will
 do what I want -- don't save any data after exiting.  However, this isn't
 the most secure -- a student only has to delete the option, or start R a
 different way.

 Is there a way to place an option or statement in Rprofile.site file to
 accomplish the same thing?

 Do you also want to stop the student saving things by using the
'save' or 'save.image' functions? Or any of the other file
manipulation functions (sink, cat, connection etc etc etc)?

 This sounds like something best done at the operating system level.
Set permissions and ownerships on your file systems so users can't
overwrite any data you don't want overwritten.

 I'm not sure if Windows will work on a completely read-only file
system (it probably needs the user to be able to write to C:\Temp and
so forth) so there will always be somewhere that users can squirrel
data away. If this is in the users' own profile directory then it
won't affect other users.

 However, if you are using the same username (I'm guessing maybe you
have a single user called 'test' for your test centre logins rather
than giving individual logins for each test subject, or test subjects
don't login, they just sit down at a currently running session) you'll
have to do something else to clear things out, again probably at the
OS level, like a Windows logout script that deletes anything owned by
the user, or some kind of hunter-killer function in R that traverses
the file system and deletes anything that shouldn't be there.

 Also note that R has a system() function so if you don't want users
getting to Windows you'll have to fix that as well.

 How secure do you want this???

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] definition of AIC and BIC in gls

2009-08-21 Thread Gavin Simpson
On Thu, 2009-08-20 at 09:08 -0400, Bond, Stephen wrote:
 Hello everybody,
 
 Please help with connecting the AIC and BIC numbers printed by
 summary.gls to the logLik number.
 
 
  1.  is the logLik number the true ML or density scaling constants
 have been omitted?

I'm not sure, sorry, but the best place to look would be the code or the
book that accompanies the nlme package:

Pinheiro, J.C., and Bates, D.M. (2000) Mixed-Effects Models in S
 and S-PLUS, Springer.

  2.  what is the formula for calculating the AIC and BIC from logLik
 (and how can I see it)? I tried printing summary.gls but it says
 object not found.

That code is in the nlme namespace so you need to work a little bit
harder to see it.

One way is to use the getAnywhere function.

start with

methods(summary)

after loading the nlme package and you'll see summary.gls listed but it
has an * appended to the name, indicating that it is non-visible. Now we
know that the function exists, do

getAnywhere(summary.gls)

and the function code will be displayed.

Alternatively, you could grab the package sources from CRAN and delve
into the raw source code there. If you look at the code for summary.gls
you'll see that the three things you enquire about are performed using
the logLik, AIC, and BIC generic functions.

To see what methods are available for class gls, do:

methods(class = gls)

So look inside logLik.gls, AIC.logLik and BIC.logLik using getAnywhere
and that should hopefully answer your questions.

HTH

G

 
 Thank you very much.
 Stephen
 
   [[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.
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 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] PowerCut Killed R - is my code retrievable?

2009-08-21 Thread Gavin Simpson
On Thu, 2009-08-20 at 20:46 +0100, Polwart Calum (County Durham and
snip /
 
  A half-decent text editor should be saving things to disk
  as you go. For example, in emacs, if your emacs dies while editing a
  file then when you restart it, it will notice and offer to restore it
  from its restore file.
 
 Yeh thats what I was expecting to happen.  I can't actually remember
 but I think it was gedit that I had open although sometimes I use
 kate.  Neither have autorecoverry as I now know.  Both can recover
 (possibly) files that had once been saved but it seems I never saved
 it - nit was literally just a big temporary, editable clipboard!

In gedit, Edit  Preferences, then select the Editor tab. Check the
Autosave files box and set a low-ish number to suit your needs.

By the looks of things, gedit will create backup files, but IIRC this
happens when you save, so the backup contains the version before your
most recent save. It doesn't maintain a recovery file like emacs. So the
autosave option is the best option to avoid large losses if you use
gedit.

HTH

G

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


[R] A question on List

2009-08-21 Thread RON70

Suppose I have following list :

mat - vector(list)
for (i in 1:4) mat[[i]] - matrix(rnorm(25),5)
mat

 mat
[[1]]
[,1]   [,2]   [,3]   [,4]   [,5]
[1,] -1.27171814 -0.8087277 -0.4771356  0.6001265  0.9842248
[2,] -1.37337445  1.0754536 -1.6304287 -0.6854075 -0.6029390
[3,] -0.32393457 -0.8933633 -0.9077967  0.9738039 -3.0220266
[4,] -1.22184968 -1.2571625 -0.4064736 -1.6686981 -0.4896512
[5,] -0.09333244  1.4880530  1.6410411 -0.5489993  1.0939736

[[2]]
   [,1]   [,2]   [,3]   [,4]   [,5]
[1,] -1.0139178 -0.4817983 -0.214  0.1649356  1.7750268
[2,]  1.5544890  0.6345386  1.6307417 -2.0887206  1.8299279
[3,] -0.3575260 -0.6669547  0.5960779 -1.1091696 -0.2831409
[4,]  0.7742701  0.8313172  0.4178063 -2.5993914 -0.9920140
[5,] -0.6238547  0.8777678 -1.4249051 -0.4793574  0.5290309

[[3]]
   [,1]   [,2] [,3]   [,4][,5]
[1,] -1.2833578  0.2271013 -1.605616640  0.3379672  0.86307678
[2,]  0.8928252 -0.2826024 -0.294600779  0.3659292 -0.06884467
[3,] -0.8237363  1.2258510  1.091578624  1.6907392 -0.42073560
[4,] -0.2537396  0.3662041  0.009558159  1.2127068 -1.14449393
[5,] -0.5001592  0.5390412  0.372628875 -0.9434233 -0.52022201

[[4]]
[,1] [,2][,3]   [,4]   [,5]
[1,]  0.55638191  2.000902039 -0.40155111  0.6214637  0.4044958
[2,]  0.06705861 -0.005629049  0.05144204  0.4910031 -0.2711823
[3,] -2.07173018 -0.210809259  0.22680564  0.5624870 -2.1322234
[4,]  0.04591303 -0.735466145 -0.13164334 -1.8873585 -1.2711131
[5,]  0.67454754  0.911601123  1.34304395  2.2798986 -0.5136242

Define another vector :

vect - rnorm(4)


Now I want to do following calculation

for (i in 1:4) mat[[i]] - mat[[i]] * vect[i]
mat


My question is, can I do previous calculation without having for loop?

Thanks

-- 
View this message in context: 
http://www.nabble.com/A-question-on-List-tp25075922p25075922.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] multiple linear regression

2009-08-21 Thread Inchallah Yarab
Good morning, 

I want to make a linear regression of a variable fuction of  two variables y = 
a1 x1 + a2 x2 + c 

I found the function lm (y ~ x)  but it used  for a simple linear regression, 
but for  multiple regression i do not know which function do this!!

 Can you help me please!! 

Thank you in advance


  
[[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] Video demo of using svSocket with data.table

2009-08-21 Thread Philippe Grosjean

Hello Matthew and all R-UseRs,

You video demo is very nice. This suggests various uses of svSocket that 
I had not think about! The primary goal was to make it:

- flexible (I think it is clear from the demo),
- running in the background while not blocking the CLI (Rgui, R.app, or 
the terminal, very clear from your demo too),
- stateful (yes, this is not in your demo, but a client can disconnect 
and reconnect and got the same server state it had just before 
disconnection, including possibly, partial command send to R server),


Not implemented yet, but planned for the future:
- binary transfer of R objects,
- connection to distant secured server using TSL (of course, distant 
connection requires a lot of extra precautions because R is NOT an 
Internet-secure language and environment, but that applies to all 
client/server R solutions like Rserve or Rpad),
- mirroring of the commands, results and history on the different 
clients to make a simple collaborative R session.


The primary use in SciViews is the communication engine between the 
client (a code editor, or IDE program like Komodo Edit) and server (R). 
Your demo gives an idea on the flexibility one got with it, including 
the possibility to inspect and/or change objects while R is running a 
long process. Your example of changing the plot in real-time without 
interrupting the main server's process is very illustrative. So now, 
imagine the debugging flexibility for long running tasks, and/or 
combination of svSocket with browser()... But that's another story, 
because svSocket does not work nicely with browser() for the moment.


All the best,

Philippe

..°}))
 ) ) ) ) )
( ( ( ( (Prof. Philippe Grosjean
 ) ) ) ) )
( ( ( ( (Numerical Ecology of Aquatic Systems
 ) ) ) ) )   Mons-Hainaut University, Belgium
( ( ( ( (
..

Matthew Dowle wrote:

Dear r-help,
If you haven't already seen this then :
http://www.youtube.com/watch?v=rvT8XThGA8o
The video consists of typing at the console and graphics, there is no audio
or slides. Please press the HD button and maximise.  Its about 8 mins.
Regards, Matthew

__
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] [Hmisc] latex() with ctable=T inserting unwanted empty line in .tex file when used on summary.formula(method=reverse) object

2009-08-21 Thread vincent chouraki
Vincent Chouraki wrote:
 
 
 When I'm using Hmisc's latex() function with ctable=TRUE on a
summary.formula with method=reverse object and saving in a .tex file,
 the latter contains an unwanted empty line which makes compilation fail. 
 
 
... Example removed
 

Vincent, 

I checked it and think it is a bug. I have forwarded this to the maintainer,
Thomas Dupong, with a cc to Frank Harrell.

Dieter

Thank you!

I'm using this code in the meantime

write ( readLines ( test.tex ) [ readLines ( test.tex ) !=  ] , file = 
testbis.tex , sep = \n )

 

Vincent Chouraki,
Interne de santé publique,
INSERM UMR 744,
Institut Pasteur de Lille, France,
Site web : www.santepub-lille.fr


  
[[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] multiple linear regression

2009-08-21 Thread Ronggui Huang
pls use lm(y ~ x1+x2)

2009/8/21 Inchallah Yarab inchallahya...@yahoo.fr:
 Good morning,

 I want to make a linear regression of a variable fuction of  two variables y 
 = a1 x1 + a2 x2 + c

 I found the function lm (y ~ x)  but it used  for a simple linear regression, 
 but for  multiple regression i do not know which function do this!!

  Can you help me please!!

 Thank you in advance



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





-- 
HUANG Ronggui, Wincent
PhD Candidate
Dept of Public and Social Administration
City University of Hong Kong
Home page: http://asrr.r-forge.r-project.org/rghuang.html

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


[R] Orthogonal Complement

2009-08-21 Thread Bogaso

A matrix B with dimension mx[m-n] is said to be orthogonal complement of
A with dimension mxn (mn) if A'B = 0

Is there any any inbuild function in R which calculates the orthogonal
complement of a given matrix?

Thanks
-- 
View this message in context: 
http://www.nabble.com/Orthogonal-Complement-tp25075944p25075944.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] Odp: A question on List

2009-08-21 Thread Petr PIKAL
Hi

 mapply(*, vect, mat, SIMPLIFY=F)

Regards
Petr

r-help-boun...@r-project.org napsal dne 21.08.2009 10:53:19:

 
 Suppose I have following list :
 
 mat - vector(list)
 for (i in 1:4) mat[[i]] - matrix(rnorm(25),5)
 mat
 
  mat
 [[1]]
 [,1]   [,2]   [,3]   [,4]   [,5]
 [1,] -1.27171814 -0.8087277 -0.4771356  0.6001265  0.9842248
 [2,] -1.37337445  1.0754536 -1.6304287 -0.6854075 -0.6029390
 [3,] -0.32393457 -0.8933633 -0.9077967  0.9738039 -3.0220266
 [4,] -1.22184968 -1.2571625 -0.4064736 -1.6686981 -0.4896512
 [5,] -0.09333244  1.4880530  1.6410411 -0.5489993  1.0939736
 
 [[2]]
[,1]   [,2]   [,3]   [,4]   [,5]
 [1,] -1.0139178 -0.4817983 -0.214  0.1649356  1.7750268
 [2,]  1.5544890  0.6345386  1.6307417 -2.0887206  1.8299279
 [3,] -0.3575260 -0.6669547  0.5960779 -1.1091696 -0.2831409
 [4,]  0.7742701  0.8313172  0.4178063 -2.5993914 -0.9920140
 [5,] -0.6238547  0.8777678 -1.4249051 -0.4793574  0.5290309
 
 [[3]]
[,1]   [,2] [,3]   [,4][,5]
 [1,] -1.2833578  0.2271013 -1.605616640  0.3379672  0.86307678
 [2,]  0.8928252 -0.2826024 -0.294600779  0.3659292 -0.06884467
 [3,] -0.8237363  1.2258510  1.091578624  1.6907392 -0.42073560
 [4,] -0.2537396  0.3662041  0.009558159  1.2127068 -1.14449393
 [5,] -0.5001592  0.5390412  0.372628875 -0.9434233 -0.52022201
 
 [[4]]
 [,1] [,2][,3]   [,4]   [,5]
 [1,]  0.55638191  2.000902039 -0.40155111  0.6214637  0.4044958
 [2,]  0.06705861 -0.005629049  0.05144204  0.4910031 -0.2711823
 [3,] -2.07173018 -0.210809259  0.22680564  0.5624870 -2.1322234
 [4,]  0.04591303 -0.735466145 -0.13164334 -1.8873585 -1.2711131
 [5,]  0.67454754  0.911601123  1.34304395  2.2798986 -0.5136242
 
 Define another vector :
 
 vect - rnorm(4)
 
 
 Now I want to do following calculation
 
 for (i in 1:4) mat[[i]] - mat[[i]] * vect[i]
 mat
 
 
 My question is, can I do previous calculation without having for loop?
 
 Thanks
 
 -- 
 View this message in context: http://www.nabble.com/A-question-on-List-
 tp25075922p25075922.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] how to draw pentagon?

2009-08-21 Thread Hemavathi Ramulu
hi,
Thanks alot for the idea. I managed to draw few diagrams.

On Tue, Aug 18, 2009 at 9:02 PM, Petr PIKAL petr.pi...@precheza.cz wrote:

 Hi

 r-help-boun...@r-project.org napsal dne 18.08.2009 06:13:09:

  Hi everyone,
  I want you all help me to give an idea, how to draw pentagon with
 points?
  Maybe can use function, but I'm stuck.

 Maybe. Maybe you can use a pencil, instead.

 Basically this

 plot(1:10, type=n)
 polygon(c(2,3,5,6,4), c(5,3,3,5,7))
 points(c(2,3,5,6,4), c(5,3,3,5,7))

 will draw one of infinite number of pentagons.

 If you can establish a function for drawing any pentagon in any display
 with any range it would be more complicated and you probably need to study
 ?grDevices and ?par more thoroughly

 Regards
 Petr

 
  Yhank you.
 
  --
  Hemavathi Ramulu
 
 [[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.




-- 
Hemavathi Ramulu

[[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] Video demo of using svSocket with data.table

2009-08-21 Thread Romain Francois

Hi Philippe,

When Matthew brought this up the first time on this list, there were 
several replies to warn about potential problems related to R not being 
thread safe, and that this might cause trouble.


Since you were on holidays, we did not get your viewpoint. Could you 
elaborate on how you deal with this.


browser works off the REPL, so this is unlikely that svSocket can take 
advantage of it, since the socket runs on a different loop. or maybe you 
can add something that feeds the R main loop, but I'm not sure this is 
possible unless you embed R ...


Romain

On 08/21/2009 11:04 AM, Philippe Grosjean wrote:


Hello Matthew and all R-UseRs,

You video demo is very nice. This suggests various uses of svSocket that
I had not think about! The primary goal was to make it:
- flexible (I think it is clear from the demo),
- running in the background while not blocking the CLI (Rgui, R.app, or
the terminal, very clear from your demo too),
- stateful (yes, this is not in your demo, but a client can disconnect
and reconnect and got the same server state it had just before
disconnection, including possibly, partial command send to R server),

Not implemented yet, but planned for the future:
- binary transfer of R objects,
- connection to distant secured server using TSL (of course, distant
connection requires a lot of extra precautions because R is NOT an
Internet-secure language and environment, but that applies to all
client/server R solutions like Rserve or Rpad),
- mirroring of the commands, results and history on the different
clients to make a simple collaborative R session.

The primary use in SciViews is the communication engine between the
client (a code editor, or IDE program like Komodo Edit) and server (R).
Your demo gives an idea on the flexibility one got with it, including
the possibility to inspect and/or change objects while R is running a
long process. Your example of changing the plot in real-time without
interrupting the main server's process is very illustrative. So now,
imagine the debugging flexibility for long running tasks, and/or
combination of svSocket with browser()... But that's another story,
because svSocket does not work nicely with browser() for the moment.

All the best,

Philippe

..°}))
) ) ) ) )
( ( ( ( ( Prof. Philippe Grosjean
) ) ) ) )
( ( ( ( ( Numerical Ecology of Aquatic Systems
) ) ) ) ) Mons-Hainaut University, Belgium
( ( ( ( (
..

Matthew Dowle wrote:

Dear r-help,
If you haven't already seen this then :
http://www.youtube.com/watch?v=rvT8XThGA8o
The video consists of typing at the console and graphics, there is no
audio
or slides. Please press the HD button and maximise. Its about 8 mins.
Regards, Matthew


--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/w33B : Completion for java objects
|- http://tr.im/vzip : Code Snippet : List of CRAN packages
`- http://tr.im/vsK1 : R parser package on CRAN

__
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] Function nsl() missing in package utils

2009-08-21 Thread Janko Thyson
Dear list,

today I stumbled across the function „nsl()” for the first time in order to
perform a hostname lookup. According to the R Reference Index (Version
2.9.1, page 1522), the function should be part of the utils package.
However, I cannot find it in the utils package of my installation(s). I've
tried the R-versions 2.8.1, 2.9.0 and 2.9.1. 

I'd be very thankful if someone could give me a hint on nsl or some other
function to do a hostname lookup!

Regards,
Janko Thyson


Janko Thyson
janko.thy...@kuei.de

Catholic University of Eichstätt-Ingolstadt
Ingolstadt School of Management
Statistics and Quantitative Methods
Auf der Schanz 49
D-85049 Ingolstadt

www.wfi.edu/lsqm

Fon:  +49 841 937-1923
Fax:  +49 841 937-1965

__
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] change default measurement unit to millimetre

2009-08-21 Thread e-letter
On 20/08/2009, Patrick Connolly p_conno...@slingshot.co.nz wrote:
 On Thu, 20-Aug-2009 at 10:25PM +1000, Jim Lemon wrote:

 e-letter wrote:
 Readers,

 How do I configure R so that all units of measurement are in
 millimetres? For example if I want to set the width of a graph, I want
 to write:
 width=100
 and R interprets this value as millimetres.


 Hi e-letter,
 If you just want a quick hack:

 mm2in-function(mm) return(mm/25.4)

 then

 width=mm2in(100)

 As a dedicated lazy typist, I've discovered that this is less typing:

 width=100/25.4

Thanks, but really I want to change the entire R installation to
accept millimetre as the default unit of measurement.

__
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] Orthogonal Complement

2009-08-21 Thread Bogaso

Please ignore my previous mail as it already replied at 
http://www.nabble.com/Orthogonal-Complement-td21406355.html#a21406355


Bogaso wrote:
 
 A matrix B with dimension mx[m-n] is said to be orthogonal complement of
 A with dimension mxn (mn) if A'B = 0
 
 Is there any any inbuild function in R which calculates the orthogonal
 complement of a given matrix?
 
 Thanks
 

-- 
View this message in context: 
http://www.nabble.com/Orthogonal-Complement-tp25075944p25076137.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] A question on List

2009-08-21 Thread baptiste auguie
Try this,

mat - replicate(4, matrix(rnorm(25), 5), simpl=F)
mat

vect - rnorm(4)

mapply( `*` , mat, vect, SIMPLIFY=F)

HTH,

baptiste

PS: I see someone replied already, but you might find replicate useful too

2009/8/21 RON70 ron_michae...@yahoo.com:

 Suppose I have following list :

 mat - vector(list)
 for (i in 1:4) mat[[i]] - matrix(rnorm(25),5)
 mat

 mat
 [[1]]
            [,1]       [,2]       [,3]       [,4]       [,5]
 [1,] -1.27171814 -0.8087277 -0.4771356  0.6001265  0.9842248
 [2,] -1.37337445  1.0754536 -1.6304287 -0.6854075 -0.6029390
 [3,] -0.32393457 -0.8933633 -0.9077967  0.9738039 -3.0220266
 [4,] -1.22184968 -1.2571625 -0.4064736 -1.6686981 -0.4896512
 [5,] -0.09333244  1.4880530  1.6410411 -0.5489993  1.0939736

 [[2]]
           [,1]       [,2]       [,3]       [,4]       [,5]
 [1,] -1.0139178 -0.4817983 -0.214  0.1649356  1.7750268
 [2,]  1.5544890  0.6345386  1.6307417 -2.0887206  1.8299279
 [3,] -0.3575260 -0.6669547  0.5960779 -1.1091696 -0.2831409
 [4,]  0.7742701  0.8313172  0.4178063 -2.5993914 -0.9920140
 [5,] -0.6238547  0.8777678 -1.4249051 -0.4793574  0.5290309

 [[3]]
           [,1]       [,2]         [,3]       [,4]        [,5]
 [1,] -1.2833578  0.2271013 -1.605616640  0.3379672  0.86307678
 [2,]  0.8928252 -0.2826024 -0.294600779  0.3659292 -0.06884467
 [3,] -0.8237363  1.2258510  1.091578624  1.6907392 -0.42073560
 [4,] -0.2537396  0.3662041  0.009558159  1.2127068 -1.14449393
 [5,] -0.5001592  0.5390412  0.372628875 -0.9434233 -0.52022201

 [[4]]
            [,1]         [,2]        [,3]       [,4]       [,5]
 [1,]  0.55638191  2.000902039 -0.40155111  0.6214637  0.4044958
 [2,]  0.06705861 -0.005629049  0.05144204  0.4910031 -0.2711823
 [3,] -2.07173018 -0.210809259  0.22680564  0.5624870 -2.1322234
 [4,]  0.04591303 -0.735466145 -0.13164334 -1.8873585 -1.2711131
 [5,]  0.67454754  0.911601123  1.34304395  2.2798986 -0.5136242

 Define another vector :

 vect - rnorm(4)


 Now I want to do following calculation

 for (i in 1:4) mat[[i]] - mat[[i]] * vect[i]
 mat


 My question is, can I do previous calculation without having for loop?

 Thanks

 --
 View this message in context: 
 http://www.nabble.com/A-question-on-List-tp25075922p25075922.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

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.


[R] Where to put source code?

2009-08-21 Thread Peter Meilstrup
I'm trying to move from Matlab to R, and I'm stuck even getting
started. This sounds to me like the dumbest question in the world
but... how does one put R source code in files? Over the last three
days I've gone front to back through the Introduction to R and the R
Language Definition, and while I'm excited that the language is so
Lispish, none of what I read described how to write a function, save
the source code in a file, and have it be usable other than directly
entering the function definition at the command prompt.

How do you edit your functions, where do you put the source files that
contain your functions, how do you tell R to use function definitions
from a particular file? How do you make incremental changes to your
functions while debugging?

I have not gone into the documentation about writing packages and
extensions other than to glance at them and decide that can't
POSSIBLY be the answer I'm looking for.

I'm just looking for the local equivalent of (in matlab) writing a
function, saving it as functionName.m and then being able to call
functionName(). Or in Python of writing a module.py and then typing
import module at the prompt.

Again this feels like an extraordinarily stupid question. But for some
weird reason I'm coming up with nothing in the FAQ or in Rseek.

Peter

__
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] supression of ongoing print command (outputted in chunks)

2009-08-21 Thread john.gelburg

Hi,

It looks like print command window output is suppressed sometimes and from
time to time it is outputted in chunks. Is there any way to make R enforce
some flush of its waiting output?

Thanks
-- 
View this message in context: 
http://www.nabble.com/supression-of-ongoing-print-command-%28outputted-in-chunks%29-tp25075917p25075917.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] 2d color coded line plot

2009-08-21 Thread Gonçalo Graça
Hi! I'm not experienced very experienced with R and i'm looking for a 
way doing plots like in this example 
http://www.mathworks.de/matlabcentral/fx_files/23566/2/color_line3.png, 
which basically it is a 2d plot in which the 3rd dimension (variable) is 
color coded. I have only seen elsewhere that it is possible to color 
code dots in a scatter plot and I tried it with success although I  I 
didn't find a way of including the color bar has legend to the plot.


I wonder if any one can give me some hint on this.

Thank you!

Gonçalo

__
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] eval and evironments: call local function in a global function

2009-08-21 Thread Renaud Gaujoux
Thanks Duncan, I agree that touching the environments is risky and not 
robust. I rather go for another solution.
But the function solution still require to pass an extra object to the 
user's function. I'd like the user to simply be able to call function 
setVar as if it was a standard R function (visible from any of his -- 
possibly nested -- functions), but this function would act on a variable 
local to the main call, that I can setup on runtime. This variable 
should be protected from direct access as much as possible (my idea with 
the local layer was something to implement kind of a private variable). 
Maybe it's just impossible ?

-- Sorry to insist :) --

Renaud

Duncan Murdoch wrote:

On 8/20/2009 4:27 AM, Renaud Gaujoux wrote:

Hi,

in my project I want the user to be able to write hook functions that 
are in turn called in my main code. I'd like the user's hooks to be 
able to call some function that set a variable outside their running 
environment.

The trick is that this variable is not global, but defined
on runtime before calling the hooks, and I don't want to leave any 
trace (i.e. global variables) after the main code has finished.


The best way to do this is to pass the function (setVar below) as an 
argument to the user's function.  If it's the user's function, you 
have no business messing with it by changing its environment.  How do 
you know the user didn't spend hours working out some crazy scheme of 
creating a nested function with a carefully crafted environment, and 
evaluation of his function depends on you leaving it alone?





I thought that the following would work but it doesn't. I guess I got 
too messy with environment and enclosures:


# global function defined by the user
fun.global - function(){
message('fun.global')
setVar(5) #
}


Pass setVar as an arg:

fun.global - function(setVar) {
message('fun.global')
setVar(5)
}




# my main code
main - function(){
message('main')
 
# define a function to set some local variable

setVar - local({
l.var - 0
function(value){
message('setVar')
   l.var - value
}
})
.workspace - environment(setVar)
environment(setVar) - new.env()
 
eval(fun.global(), enclos=environment(setVar))

print(get('l.var', envir=.workspace, inherits=FALSE))
}


I wouldn't bother with the extra layer of local(), just put l.var in 
main's evalution frame.  (Since you're the one writing setVar, you can 
avoid any name clashes.)  That is:


main - function() {
message('main')
l.var - 0
setVar - function(value) {
message('setVar')
l.var - value
}
fun.global(setVar)
print(l.var)
}   



Duncan Murdoch



main()

I get the following output:
  main
  fun.global
  Error in fun.global() : could not find function setVar

There is definitely a problem of lookup somewhere. I first tried 
without eval, as I thought that function setVar would then be defined 
in a parent environment of the call to fun.global, but it does not 
work either.

Can anybody tell me what's the problem and how I should do my stuff?

Thanks,
Renaud

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

2009-08-21 Thread Gabor Grothendieck
It has no effect.  Both 6 and 6. represent the number six
as a double:

 identical(6, 6.)
[1] TRUE
 typeof(6.)
[1] double

On Thu, Aug 20, 2009 at 10:34 PM, kfcnhlzhengchenj...@hotmail.com wrote:

 sigma0 - sqrt((6. * var(maxima))/pi)

 What does the '.' do here?
 --
 View this message in context: 
 http://www.nabble.com/extra-.-tp25073255p25073255.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] Where to put source code?

2009-08-21 Thread baptiste auguie
Hi,

Say you have the following data and functions that you want to reuse,

d = data.frame(1:10)

foo = function(x,y , ...){
plot(x,y, type=l, ...)
}

You may save the code in a file testing.r, noting that in general
data may find a convenient storage format using save(d, file=
mydata.rda). When opening a new R session you can load this code
with ?source,

source(/your/path/to/this/file/testing.r) # or simply
source(testing.r)  if you're in the same working directory (see
?getwd)

Similarly you can load the data,

load(mydata.rda)

The code and data are then loaded and available for you to use.

If you find after some time that you have accumulated quite a lot of
functions and data that clutter your workspace, writing a package is a
neat and easy option to organize them, see ?package.skeleton to get
you started.

HTH,


baptiste




2009/8/21 Peter Meilstrup peter.meilst...@gmail.com:
 I'm trying to move from Matlab to R, and I'm stuck even getting
 started. This sounds to me like the dumbest question in the world
 but... how does one put R source code in files? Over the last three
 days I've gone front to back through the Introduction to R and the R
 Language Definition, and while I'm excited that the language is so
 Lispish, none of what I read described how to write a function, save
 the source code in a file, and have it be usable other than directly
 entering the function definition at the command prompt.

 How do you edit your functions, where do you put the source files that
 contain your functions, how do you tell R to use function definitions
 from a particular file? How do you make incremental changes to your
 functions while debugging?

 I have not gone into the documentation about writing packages and
 extensions other than to glance at them and decide that can't
 POSSIBLY be the answer I'm looking for.

 I'm just looking for the local equivalent of (in matlab) writing a
 function, saving it as functionName.m and then being able to call
 functionName(). Or in Python of writing a module.py and then typing
 import module at the prompt.

 Again this feels like an extraordinarily stupid question. But for some
 weird reason I'm coming up with nothing in the FAQ or in Rseek.

 Peter

 __
 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

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] Where to put source code?

2009-08-21 Thread Romain Francois

Hi,

You might be interested in :
  - this (out of date) page : http://www.sciviews.org/_rgui/
  - this (not yet filled) page : 
http://wiki.r-project.org/rwiki/doku.php?id=guis:projects


for a list of potential guis/text editor you can use to write your R code.

Romain


On 08/21/2009 12:06 PM, Peter Meilstrup wrote:


I'm trying to move from Matlab to R, and I'm stuck even getting
started. This sounds to me like the dumbest question in the world
but... how does one put R source code in files? Over the last three
days I've gone front to back through the Introduction to R and the R
Language Definition, and while I'm excited that the language is so
Lispish, none of what I read described how to write a function, save
the source code in a file, and have it be usable other than directly
entering the function definition at the command prompt.

How do you edit your functions, where do you put the source files that
contain your functions, how do you tell R to use function definitions
from a particular file? How do you make incremental changes to your
functions while debugging?

I have not gone into the documentation about writing packages and
extensions other than to glance at them and decide that can't
POSSIBLY be the answer I'm looking for.

I'm just looking for the local equivalent of (in matlab) writing a
function, saving it as functionName.m and then being able to call
functionName(). Or in Python of writing a module.py and then typing
import module at the prompt.

Again this feels like an extraordinarily stupid question. But for some
weird reason I'm coming up with nothing in the FAQ or in Rseek.

Peter


--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/w33B : Completion for java objects
|- http://tr.im/vzip : Code Snippet : List of CRAN packages
`- http://tr.im/vsK1 : R parser package on CRAN

__
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] 2d color coded line plot

2009-08-21 Thread ONKELINX, Thierry
Have a look at the ggplot2 package. You will find a lot of examples at 
http://had.co.nz/ggplot2/

library(ggplot2)
dataset - data.frame(x = seq(-1, 1, length = 101))
dataset$y - dataset$x + dataset$x^2
dataset$z - 10 * dataset$x + 1

ggplot(dataset, aes(x = x, y = y, colour = z)) + geom_point()
ggplot(dataset, aes(x = x, y = y, colour = z)) + geom_line()
ggplot(dataset, aes(x = x, y = y, colour = z)) + geom_line(size = 2) + 
scale_colour_gradient2(low = blue, mid = yellow, high = red, breaks = 
seq(-9, 11, by = 1)) 

HTH,

Thierry


ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and 
Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology 
and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
thierry.onkel...@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than 
asking him to perform a post-mortem examination: he may be able to say what the 
experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure 
that a reasonable answer can be extracted from a given body of data.
~ John Tukey

-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens 
Gonçalo Graça
Verzonden: vrijdag 21 augustus 2009 11:31
Aan: r-help@r-project.org
Onderwerp: [R] 2d color coded line plot

Hi! I'm not experienced very experienced with R and i'm looking for a way doing 
plots like in this example 
http://www.mathworks.de/matlabcentral/fx_files/23566/2/color_line3.png,
which basically it is a 2d plot in which the 3rd dimension (variable) is color 
coded. I have only seen elsewhere that it is possible to color code dots in a 
scatter plot and I tried it with success although I  I didn't find a way of 
including the color bar has legend to the plot.

I wonder if any one can give me some hint on this.

Thank you!

Gonçalo

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

Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed document.

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


Re: [R] Where to put source code?

2009-08-21 Thread Barry Rowlingson
On Fri, Aug 21, 2009 at 11:06 AM, Peter
Meilstruppeter.meilst...@gmail.com wrote:

 I'm just looking for the local equivalent of (in matlab) writing a
 function, saving it as functionName.m and then being able to call
 functionName(). Or in Python of writing a module.py and then typing
 import module at the prompt.

 Again this feels like an extraordinarily stupid question. But for some
 weird reason I'm coming up with nothing in the FAQ or in Rseek.

 It's a bit of a paradigm shift from the way Matlab and Python do it,
I'm afraid...

 In Matlab and Python, the system always goes to the file
representation of the function.

 In R, it doesn't. It goes to the R object in the in-memory storage
(aka environment). You update this by running 'source(file.R)'
which executes 'foo = function(...){etc}', thus overwriting the old
function definition.

  At the end of an R session, if you save the image (in a .RData
file), then when you restart R with that saved image your function
definitions will be reloaded too - but from the .RData and not the .R
text file.

 I use Emacs with ESS, and edit my functions in .R files. I then hit
Ctrl-C Ctrl-L and they are sourced into R. I find that's the easiest
way to develop simple functions. The other R environments can do
similar things.

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] categorized barplot

2009-08-21 Thread Jim Lemon

Rafael Moral wrote:

Dear useRs,

I can't seem to find out how to categorize my histogram.

I have the following dataset:

TimeFirst.day  Second.day
08:00-10:009 8
10:00-12:00   13   15
12:00-14:009 9
14:00-16:00   109

I attached a jpeg file to this e-mail containing the sketches.
What I'd like to do is a barplot (or histogram), firstly with 2 categories - 
first and second day (figure 1)
And then with 4 categories - the times (figure 2)
Also, I'd like the graphs both with lines (as sketched) and bars.

  

Hi Rafael,
The hierobarp function in the plotrix package does something like this, 
overlaying successively finer breakdowns. I am currently writing more 
variants of this function and one that displayed a multiway array would 
be quite useful. If you think that a variant of hierobarp would suit 
your needs, let me know.


Jim

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


Re: [R] eval and evironments: call local function in a global function

2009-08-21 Thread Gabor Grothendieck
Another possibility is that you could inject setVar into
fun.global's environment.

First save any existing setVar in fun.global's environment to tmp
and then assign our own setVar there.  We then run fun.global()
and reverse the changes we made in fun.global's environment
setting everything back to what it was before.

If setVar is called from fun.global2 instead of fun.global then
its up to the user to ensure that fun.global2 can access
fun.global's environment.

fun.global - function() { message('fun.global'); fun.global2() }
fun.global2 - function() { message(fun.global2); setVar(2) }

main - function() {
  l.var - 0
  e - environment(fun.global)

  tmp - if (exists(setVar, e)) get(setVar, e) ##
  assign(setVar, function(value) { message(setVar); l.var - value }, e)
  fun.global()
  if (is.null(tmp)) rm(setVar, envir = e) else assign(setVar, tmp, e)

  print(l.var)
}
main()


Yet another possibility is to simply mandate that the user call setVar
directly from fun.global and ask them to do it like this:

fun.global - function() parent.frame()$setVar(4)
main - function() {
   l.var - 0
   setVar - function(value) { message(set Var); l.var - value }
   environment(fun.global) - environment()
   fun.global()
   print(l.var)
}
main()




On Fri, Aug 21, 2009 at 6:33 AM, Renaud
Gaujouxren...@mancala.cbio.uct.ac.za wrote:
 Thanks Duncan, I agree that touching the environments is risky and not
 robust. I rather go for another solution.
 But the function solution still require to pass an extra object to the
 user's function. I'd like the user to simply be able to call function setVar
 as if it was a standard R function (visible from any of his -- possibly
 nested -- functions), but this function would act on a variable local to the
 main call, that I can setup on runtime. This variable should be protected
 from direct access as much as possible (my idea with the local layer was
 something to implement kind of a private variable). Maybe it's just
 impossible ?
 -- Sorry to insist :) --

 Renaud

 Duncan Murdoch wrote:

 On 8/20/2009 4:27 AM, Renaud Gaujoux wrote:

 Hi,

 in my project I want the user to be able to write hook functions that are
 in turn called in my main code. I'd like the user's hooks to be able to call
 some function that set a variable outside their running environment.

 The trick is that this variable is not global, but defined

 on runtime before calling the hooks, and I don't want to leave any trace
 (i.e. global variables) after the main code has finished.

 The best way to do this is to pass the function (setVar below) as an
 argument to the user's function.  If it's the user's function, you have no
 business messing with it by changing its environment.  How do you know the
 user didn't spend hours working out some crazy scheme of creating a nested
 function with a carefully crafted environment, and evaluation of his
 function depends on you leaving it alone?



 I thought that the following would work but it doesn't. I guess I got too
 messy with environment and enclosures:

 # global function defined by the user
 fun.global - function(){
    message('fun.global')
    setVar(5) #
 }

 Pass setVar as an arg:

 fun.global - function(setVar) {
    message('fun.global')
    setVar(5)
 }



 # my main code
 main - function(){
    message('main')
      # define a function to set some local variable
    setVar - local({
    l.var - 0
    function(value){
        message('setVar')
       l.var - value
    }
    })
    .workspace - environment(setVar)
    environment(setVar) - new.env()
      eval(fun.global(), enclos=environment(setVar))
    print(get('l.var', envir=.workspace, inherits=FALSE))
 }

 I wouldn't bother with the extra layer of local(), just put l.var in
 main's evalution frame.  (Since you're the one writing setVar, you can avoid
 any name clashes.)  That is:

 main - function() {
    message('main')
    l.var - 0
    setVar - function(value) {
    message('setVar')
    l.var - value
    }
    fun.global(setVar)
    print(l.var)
 }

 Duncan Murdoch


 main()

 I get the following output:
   main
   fun.global
   Error in fun.global() : could not find function setVar

 There is definitely a problem of lookup somewhere. I first tried without
 eval, as I thought that function setVar would then be defined in a parent
 environment of the call to fun.global, but it does not work either.
 Can anybody tell me what's the problem and how I should do my stuff?

 Thanks,
 Renaud

 __
 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 

Re: [R] eval and evironments: call local function in a global function

2009-08-21 Thread Renaud Gaujoux
Ah! It looks interesting and seems more conservative than changing the 
actual environment. I could do the restore within an on.exit to deal 
with the error eventuality.
Do you think could define a dummy setVar function in my package 
namespace, and change its behaviour on runtime?


This way, as soon as he has loaded the package, the user will be able to 
call setVar anywhere in his functions. What setVar does would be set by 
my main code that runs before calling the user's function.


Gabor Grothendieck wrote:

Another possibility is that you could inject setVar into
fun.global's environment.

First save any existing setVar in fun.global's environment to tmp
and then assign our own setVar there.  We then run fun.global()
and reverse the changes we made in fun.global's environment
setting everything back to what it was before.

If setVar is called from fun.global2 instead of fun.global then
its up to the user to ensure that fun.global2 can access
fun.global's environment.

fun.global - function() { message('fun.global'); fun.global2() }
fun.global2 - function() { message(fun.global2); setVar(2) }

main - function() {
  l.var - 0
  e - environment(fun.global)

  tmp - if (exists(setVar, e)) get(setVar, e) ##
  assign(setVar, function(value) { message(setVar); l.var - value }, e)
  fun.global()
  if (is.null(tmp)) rm(setVar, envir = e) else assign(setVar, tmp, e)

  print(l.var)
}
main()


Yet another possibility is to simply mandate that the user call setVar
directly from fun.global and ask them to do it like this:

fun.global - function() parent.frame()$setVar(4)
main - function() {
   l.var - 0
   setVar - function(value) { message(set Var); l.var - value }
   environment(fun.global) - environment()
   fun.global()
   print(l.var)
}
main()




On Fri, Aug 21, 2009 at 6:33 AM, Renaud
Gaujouxren...@mancala.cbio.uct.ac.za wrote:
  

Thanks Duncan, I agree that touching the environments is risky and not
robust. I rather go for another solution.
But the function solution still require to pass an extra object to the
user's function. I'd like the user to simply be able to call function setVar
as if it was a standard R function (visible from any of his -- possibly
nested -- functions), but this function would act on a variable local to the
main call, that I can setup on runtime. This variable should be protected
from direct access as much as possible (my idea with the local layer was
something to implement kind of a private variable). Maybe it's just
impossible ?
-- Sorry to insist :) --

Renaud

Duncan Murdoch wrote:


On 8/20/2009 4:27 AM, Renaud Gaujoux wrote:
  

Hi,

in my project I want the user to be able to write hook functions that are
in turn called in my main code. I'd like the user's hooks to be able to call
some function that set a variable outside their running environment.


The trick is that this variable is not global, but defined
  

on runtime before calling the hooks, and I don't want to leave any trace
(i.e. global variables) after the main code has finished.


The best way to do this is to pass the function (setVar below) as an
argument to the user's function.  If it's the user's function, you have no
business messing with it by changing its environment.  How do you know the
user didn't spend hours working out some crazy scheme of creating a nested
function with a carefully crafted environment, and evaluation of his
function depends on you leaving it alone?


  

I thought that the following would work but it doesn't. I guess I got too
messy with environment and enclosures:

# global function defined by the user
fun.global - function(){
   message('fun.global')
   setVar(5) #
}


Pass setVar as an arg:

fun.global - function(setVar) {
   message('fun.global')
   setVar(5)
}

  

# my main code
main - function(){
   message('main')
 # define a function to set some local variable
   setVar - local({
   l.var - 0
   function(value){
   message('setVar')
  l.var - value
   }
   })
   .workspace - environment(setVar)
   environment(setVar) - new.env()
 eval(fun.global(), enclos=environment(setVar))
   print(get('l.var', envir=.workspace, inherits=FALSE))
}


I wouldn't bother with the extra layer of local(), just put l.var in
main's evalution frame.  (Since you're the one writing setVar, you can avoid
any name clashes.)  That is:

main - function() {
   message('main')
   l.var - 0
   setVar - function(value) {
   message('setVar')
   l.var - value
   }
   fun.global(setVar)
   print(l.var)
}

Duncan Murdoch

  

main()

I get the following output:
  main
  fun.global
  Error in fun.global() : could not find function setVar

There is definitely a problem of lookup somewhere. I first tried without
eval, as I thought that function setVar would then be defined in a parent
environment of the call to fun.global, but it does not work either.
Can anybody tell me what's the problem and how I should do my stuff?

Re: [R] Wind-data analysis with R?

2009-08-21 Thread Jim Lemon

Oliver Bandel wrote:

Hello,

are there people outside who use R for analysis of wind-measurement data
(meteorological or for planning of wind power stations)?

Are there already scripts/modules available for analysing and
displaying/plotting wind data in the way it is done in projection/planning
of wind power stations?

If not, would it be of interest to use R for this, and therefore
adapt data-logger output to R (by providing certain data formats)
or by providing R-modules for parsing of the data-logger files?

Or would that better be done by connection to a RDBMS?

  

Hi Oliver,
If a wind rose diagram would be any help:

plot.windrose (oce)
oz.windrose(plotrix)
windrose (circular)
rosavent (climatol)
rose (IPDmisc)

and perhaps some others as well.

Jim

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


Re: [R] eval and evironments: call local function in a global function

2009-08-21 Thread Gabor Grothendieck
Certainly its possible to dynamically write to the package's namespace.
For example, lattice does that. It stores various lattice options there.

Injecting setVar is not really more conservative though.   Consider that
when you modify the environment of a function in main:

environment(fun.global) - environment()

you are actually modifying a copy of fun.global and the original fun.global
is not changed at all so you are not disturbing any external objects whereas
injecting setVar and setting it back again actually modifies the environment
external to main.

On Fri, Aug 21, 2009 at 7:20 AM, Renaud Gaujouxren...@cbio.uct.ac.za wrote:
 Ah! It looks interesting and seems more conservative than changing the
 actual environment. I could do the restore within an on.exit to deal with
 the error eventuality.
 Do you think could define a dummy setVar function in my package namespace,
 and change its behaviour on runtime?

 This way, as soon as he has loaded the package, the user will be able to
 call setVar anywhere in his functions. What setVar does would be set by my
 main code that runs before calling the user's function.

 Gabor Grothendieck wrote:

 Another possibility is that you could inject setVar into
 fun.global's environment.

 First save any existing setVar in fun.global's environment to tmp
 and then assign our own setVar there.  We then run fun.global()
 and reverse the changes we made in fun.global's environment
 setting everything back to what it was before.

 If setVar is called from fun.global2 instead of fun.global then
 its up to the user to ensure that fun.global2 can access
 fun.global's environment.

 fun.global - function() { message('fun.global'); fun.global2() }
 fun.global2 - function() { message(fun.global2); setVar(2) }

 main - function() {
  l.var - 0
  e - environment(fun.global)

  tmp - if (exists(setVar, e)) get(setVar, e) ##
  assign(setVar, function(value) { message(setVar); l.var - value },
 e)
  fun.global()
  if (is.null(tmp)) rm(setVar, envir = e) else assign(setVar, tmp, e)

  print(l.var)
 }
 main()


 Yet another possibility is to simply mandate that the user call setVar
 directly from fun.global and ask them to do it like this:

 fun.global - function() parent.frame()$setVar(4)
 main - function() {
       l.var - 0
       setVar - function(value) { message(set Var); l.var - value }
       environment(fun.global) - environment()
       fun.global()
       print(l.var)
 }
 main()




 On Fri, Aug 21, 2009 at 6:33 AM, Renaud
 Gaujouxren...@mancala.cbio.uct.ac.za wrote:


 Thanks Duncan, I agree that touching the environments is risky and not
 robust. I rather go for another solution.
 But the function solution still require to pass an extra object to the
 user's function. I'd like the user to simply be able to call function
 setVar
 as if it was a standard R function (visible from any of his -- possibly
 nested -- functions), but this function would act on a variable local to
 the
 main call, that I can setup on runtime. This variable should be protected
 from direct access as much as possible (my idea with the local layer was
 something to implement kind of a private variable). Maybe it's just
 impossible ?
 -- Sorry to insist :) --

 Renaud

 Duncan Murdoch wrote:


 On 8/20/2009 4:27 AM, Renaud Gaujoux wrote:


 Hi,

 in my project I want the user to be able to write hook functions that
 are
 in turn called in my main code. I'd like the user's hooks to be able to
 call
 some function that set a variable outside their running environment.


 The trick is that this variable is not global, but defined


 on runtime before calling the hooks, and I don't want to leave any
 trace
 (i.e. global variables) after the main code has finished.


 The best way to do this is to pass the function (setVar below) as an
 argument to the user's function.  If it's the user's function, you have
 no
 business messing with it by changing its environment.  How do you know
 the
 user didn't spend hours working out some crazy scheme of creating a
 nested
 function with a carefully crafted environment, and evaluation of his
 function depends on you leaving it alone?




 I thought that the following would work but it doesn't. I guess I got
 too
 messy with environment and enclosures:

 # global function defined by the user
 fun.global - function(){
   message('fun.global')
   setVar(5) #
 }


 Pass setVar as an arg:

 fun.global - function(setVar) {
   message('fun.global')
   setVar(5)
 }



 # my main code
 main - function(){
   message('main')
     # define a function to set some local variable
   setVar - local({
   l.var - 0
   function(value){
       message('setVar')
      l.var - value
   }
   })
   .workspace - environment(setVar)
   environment(setVar) - new.env()
     eval(fun.global(), enclos=environment(setVar))
   print(get('l.var', envir=.workspace, inherits=FALSE))
 }


 I wouldn't bother with the extra layer of local(), just put l.var in
 main's evalution frame.  (Since you're 

Re: [R] 2d color coded line plot

2009-08-21 Thread Jim Lemon

Gonçalo Graça wrote:
Hi! I'm not experienced very experienced with R and i'm looking for a 
way doing plots like in this example 
http://www.mathworks.de/matlabcentral/fx_files/23566/2/color_line3.png, 
which basically it is a 2d plot in which the 3rd dimension (variable) 
is color coded. I have only seen elsewhere that it is possible to 
color code dots in a scatter plot and I tried it with success although 
I  I didn't find a way of including the color bar has legend to the plot.


I wonder if any one can give me some hint on this.

Hi Goncalo,
Have a look at the color.scale.line, color.scale and smoothColor 
functions in the plotrix package. See color.legend for the color bar.


Jim

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


Re: [R] eval and evironments: call local function in a global function

2009-08-21 Thread Renaud Gaujoux

And to make things a bit more difficult: I also use the multicore package.
So I guess that naively modifying setVar in my package namespace would 
not be appropriate as each process needs to define its own setVar 
function. Unless setVar is implemented so that it knows which process is 
calling it and respond accordingly.

I need to give more thinking to that than what I expected to.
Do you think I'm just bothering myself in vain (:() or that one can get 
to a sound and robust solution (except the object one)?


Gabor Grothendieck wrote:

Certainly its possible to dynamically write to the package's namespace.
For example, lattice does that. It stores various lattice options there.

Injecting setVar is not really more conservative though.   Consider that
when you modify the environment of a function in main:

environment(fun.global) - environment()

you are actually modifying a copy of fun.global and the original fun.global
is not changed at all so you are not disturbing any external objects whereas
injecting setVar and setting it back again actually modifies the environment
external to main.

On Fri, Aug 21, 2009 at 7:20 AM, Renaud Gaujouxren...@cbio.uct.ac.za wrote:
  

Ah! It looks interesting and seems more conservative than changing the
actual environment. I could do the restore within an on.exit to deal with
the error eventuality.
Do you think could define a dummy setVar function in my package namespace,
and change its behaviour on runtime?

This way, as soon as he has loaded the package, the user will be able to
call setVar anywhere in his functions. What setVar does would be set by my
main code that runs before calling the user's function.

Gabor Grothendieck wrote:


Another possibility is that you could inject setVar into
fun.global's environment.

First save any existing setVar in fun.global's environment to tmp
and then assign our own setVar there.  We then run fun.global()
and reverse the changes we made in fun.global's environment
setting everything back to what it was before.

If setVar is called from fun.global2 instead of fun.global then
its up to the user to ensure that fun.global2 can access
fun.global's environment.

fun.global - function() { message('fun.global'); fun.global2() }
fun.global2 - function() { message(fun.global2); setVar(2) }

main - function() {
 l.var - 0
 e - environment(fun.global)

 tmp - if (exists(setVar, e)) get(setVar, e) ##
 assign(setVar, function(value) { message(setVar); l.var - value },
e)
 fun.global()
 if (is.null(tmp)) rm(setVar, envir = e) else assign(setVar, tmp, e)

 print(l.var)
}
main()


Yet another possibility is to simply mandate that the user call setVar
directly from fun.global and ask them to do it like this:

fun.global - function() parent.frame()$setVar(4)
main - function() {
  l.var - 0
  setVar - function(value) { message(set Var); l.var - value }
  environment(fun.global) - environment()
  fun.global()
  print(l.var)
}
main()




On Fri, Aug 21, 2009 at 6:33 AM, Renaud
Gaujouxren...@mancala.cbio.uct.ac.za wrote:

  

Thanks Duncan, I agree that touching the environments is risky and not
robust. I rather go for another solution.
But the function solution still require to pass an extra object to the
user's function. I'd like the user to simply be able to call function
setVar
as if it was a standard R function (visible from any of his -- possibly
nested -- functions), but this function would act on a variable local to
the
main call, that I can setup on runtime. This variable should be protected
from direct access as much as possible (my idea with the local layer was
something to implement kind of a private variable). Maybe it's just
impossible ?
-- Sorry to insist :) --

Renaud

Duncan Murdoch wrote:



On 8/20/2009 4:27 AM, Renaud Gaujoux wrote:

  

Hi,

in my project I want the user to be able to write hook functions that
are
in turn called in my main code. I'd like the user's hooks to be able to
call
some function that set a variable outside their running environment.



The trick is that this variable is not global, but defined

  

on runtime before calling the hooks, and I don't want to leave any
trace
(i.e. global variables) after the main code has finished.



The best way to do this is to pass the function (setVar below) as an
argument to the user's function.  If it's the user's function, you have
no
business messing with it by changing its environment.  How do you know
the
user didn't spend hours working out some crazy scheme of creating a
nested
function with a carefully crafted environment, and evaluation of his
function depends on you leaving it alone?



  

I thought that the following would work but it doesn't. I guess I got
too
messy with environment and enclosures:

# global function defined by the user
fun.global - function(){
  message('fun.global')
  setVar(5) #
}



Pass setVar as an arg:

fun.global - function(setVar) {
  

Re: [R] Orthogonal Complement

2009-08-21 Thread Gabor Grothendieck
Check out ?Null in MASS.

On Fri, Aug 21, 2009 at 5:52 AM, Bogasobogaso.christo...@gmail.com wrote:

 Please ignore my previous mail as it already replied at
 http://www.nabble.com/Orthogonal-Complement-td21406355.html#a21406355


 Bogaso wrote:

 A matrix B with dimension mx[m-n] is said to be orthogonal complement of
 A with dimension mxn (mn) if A'B = 0

 Is there any any inbuild function in R which calculates the orthogonal
 complement of a given matrix?

 Thanks


 --
 View this message in context: 
 http://www.nabble.com/Orthogonal-Complement-tp25075944p25076137.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] supression of ongoing print command (outputted in chunks)

2009-08-21 Thread jim holtman
?flush.console

If you are using the Windows RGUI (you did not specify the system you
are on), you can set the output to non-buffered.

On Fri, Aug 21, 2009 at 4:49 AM, john.gelburgjohn.gelb...@gmail.com wrote:

 Hi,

 It looks like print command window output is suppressed sometimes and from
 time to time it is outputted in chunks. Is there any way to make R enforce
 some flush of its waiting output?

 Thanks
 --
 View this message in context: 
 http://www.nabble.com/supression-of-ongoing-print-command-%28outputted-in-chunks%29-tp25075917p25075917.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] how to plot 95% confidential interval as vertical lines to x axe in density plot

2009-08-21 Thread Mao Jianfeng
Dear R-help listers,

Under the helps from the ggplot2 list, I have set up method of drawing
a graph with multiple density plots arranged one by one in one page.

Now, I want to add 95% confidential interval as vertical lines to x
axe in density plot. I have found the library(hdrcde) can do this
work, but I do not know
how to handle functions of this library when I used ggplot2 to draw the graph.

Thank you in advance.

The data and codes followed:

# dummy data
factor-rep(c(Alice,Jone,Mike),each=100)
factor-factor(factor)
traits1-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits2-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits3-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits4-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits5-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits6-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits7-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits8-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits9-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits10-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits11-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits12-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits13-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits14-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits15-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits16-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits17-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits18-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits19-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits20-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))
traits21-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))

myda-data.frame(factor,traits1,traits2,traits3,traits4,traits5,traits6,traits7,traits8,traits9,traits10,traits11,traits12,traits13,traits14,traits15,traits16,traits17,traits18,
traits19,traits20,traits21)


library(ggplot2)
d = melt(myda, id = factor)

str(d)

pdf(test33.pdf)
p =
ggplot(data=d, mapping=aes(x=value, y=..density..)) +
facet_wrap(~variable)+
stat_density(aes(fill=factor), alpha=0.5, col=NA, position = 'identity') +
stat_density(aes(colour = factor), geom=path, position = 'identity')
print(p)
dev.off()

Mao J-F

__
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] eval and evironments: call local function in a global function

2009-08-21 Thread Gabor Grothendieck
I think you need to consider particular scenarios in which this is used
and the characteristics of the user since there are going to be tradeoffs
in the design.

It may be that by examining typical usage cases that you find that
the fun.global2 situation (i.e. fun.global calls fun.global2 calls setVar)
is unlikely, that passing an object or function to fun.global is not
that onerous for the user or that simply using parent.frame()$setVar(4)
in fun.global is not seen as a significant problem for them either.

On Fri, Aug 21, 2009 at 7:57 AM, Renaud Gaujouxren...@cbio.uct.ac.za wrote:
 And to make things a bit more difficult: I also use the multicore package.
 So I guess that naively modifying setVar in my package namespace would not
 be appropriate as each process needs to define its own setVar function.
 Unless setVar is implemented so that it knows which process is calling it
 and respond accordingly.
 I need to give more thinking to that than what I expected to.
 Do you think I'm just bothering myself in vain (:() or that one can get to a
 sound and robust solution (except the object one)?

 Gabor Grothendieck wrote:

 Certainly its possible to dynamically write to the package's namespace.
 For example, lattice does that. It stores various lattice options there.

 Injecting setVar is not really more conservative though.   Consider that
 when you modify the environment of a function in main:

 environment(fun.global) - environment()

 you are actually modifying a copy of fun.global and the original
 fun.global
 is not changed at all so you are not disturbing any external objects
 whereas
 injecting setVar and setting it back again actually modifies the
 environment
 external to main.

 On Fri, Aug 21, 2009 at 7:20 AM, Renaud Gaujouxren...@cbio.uct.ac.za
 wrote:


 Ah! It looks interesting and seems more conservative than changing the
 actual environment. I could do the restore within an on.exit to deal with
 the error eventuality.
 Do you think could define a dummy setVar function in my package
 namespace,
 and change its behaviour on runtime?

 This way, as soon as he has loaded the package, the user will be able to
 call setVar anywhere in his functions. What setVar does would be set by
 my
 main code that runs before calling the user's function.

 Gabor Grothendieck wrote:


 Another possibility is that you could inject setVar into
 fun.global's environment.

 First save any existing setVar in fun.global's environment to tmp
 and then assign our own setVar there.  We then run fun.global()
 and reverse the changes we made in fun.global's environment
 setting everything back to what it was before.

 If setVar is called from fun.global2 instead of fun.global then
 its up to the user to ensure that fun.global2 can access
 fun.global's environment.

 fun.global - function() { message('fun.global'); fun.global2() }
 fun.global2 - function() { message(fun.global2); setVar(2) }

 main - function() {
  l.var - 0
  e - environment(fun.global)

  tmp - if (exists(setVar, e)) get(setVar, e) ##
  assign(setVar, function(value) { message(setVar); l.var - value
 },
 e)
  fun.global()
  if (is.null(tmp)) rm(setVar, envir = e) else assign(setVar, tmp, e)

  print(l.var)
 }
 main()


 Yet another possibility is to simply mandate that the user call setVar
 directly from fun.global and ask them to do it like this:

 fun.global - function() parent.frame()$setVar(4)
 main - function() {
      l.var - 0
      setVar - function(value) { message(set Var); l.var - value }
      environment(fun.global) - environment()
      fun.global()
      print(l.var)
 }
 main()




 On Fri, Aug 21, 2009 at 6:33 AM, Renaud
 Gaujouxren...@mancala.cbio.uct.ac.za wrote:



 Thanks Duncan, I agree that touching the environments is risky and not
 robust. I rather go for another solution.
 But the function solution still require to pass an extra object to the
 user's function. I'd like the user to simply be able to call function
 setVar
 as if it was a standard R function (visible from any of his -- possibly
 nested -- functions), but this function would act on a variable local
 to
 the
 main call, that I can setup on runtime. This variable should be
 protected
 from direct access as much as possible (my idea with the local layer
 was
 something to implement kind of a private variable). Maybe it's just
 impossible ?
 -- Sorry to insist :) --

 Renaud

 Duncan Murdoch wrote:



 On 8/20/2009 4:27 AM, Renaud Gaujoux wrote:



 Hi,

 in my project I want the user to be able to write hook functions that
 are
 in turn called in my main code. I'd like the user's hooks to be able
 to
 call
 some function that set a variable outside their running environment.



 The trick is that this variable is not global, but defined



 on runtime before calling the hooks, and I don't want to leave any
 trace
 (i.e. global variables) after the main code has finished.



 The best way to do this is to pass the function (setVar below) as an
 argument to the user's 

[R] creating gantt chart

2009-08-21 Thread rajclinasia

Hi every one,
I have a R dataset like this.

labels  starts ends
first task 2004-01-01   2004-03-03
second task 2004-02-02  2004-05-05
third task  2004-03-03  2004-06-06
fourth task  2004-04-04 2004-08-08
fifth task 2004-05-05   2004-09-09

now i want to create gantt chart for this data. can any body help us in
code, it will be very helpful for us.

Thanks in Advance.
-- 
View this message in context: 
http://www.nabble.com/creating-gantt-chart-tp25078977p25078977.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] eval and evironments: call local function in a global function

2009-08-21 Thread Duncan Murdoch

On 8/21/2009 6:33 AM, Renaud Gaujoux wrote:
Thanks Duncan, I agree that touching the environments is risky and not 
robust. I rather go for another solution.
But the function solution still require to pass an extra object to the 
user's function. I'd like the user to simply be able to call function 
setVar as if it was a standard R function (visible from any of his -- 
possibly nested -- functions), but this function would act on a variable 
local to the main call, that I can setup on runtime. This variable 
should be protected from direct access as much as possible (my idea with 
the local layer was something to implement kind of a private variable). 
Maybe it's just impossible ?


If you want the function visible to users, it should be an exported 
function from your NAMESPACE.  But then it is hard to have variables 
local to each caller.


Another approach that doesn't mess with things that aren't yours is to 
ask the user to provide some local storage, and pass that to setVar each 
time.   A sloppier way to do the same thing is to tell the user that 
they need to set up a variable with a fixed name, and setVar will in its 
caller's frame for that variable.  (The second solution is getting close 
to the edge of touching things that aren't yours...)


If the local storage is set up as an environment then the user will see 
your changes to it, because environments are passed by reference.  (You 
could also use an external pointer if you wanted it to be more opaque, 
but that's more work for you.)


The bottom line is that there are lots of ways to do what you want, but 
each has tradeoffs.  If you are intending your code to work in a complex 
environment, keeping it simple, and working within a very restrictive 
set of rules will really help.


Duncan Murdoch


-- Sorry to insist :) --

Renaud

Duncan Murdoch wrote:

On 8/20/2009 4:27 AM, Renaud Gaujoux wrote:

Hi,

in my project I want the user to be able to write hook functions that 
are in turn called in my main code. I'd like the user's hooks to be 
able to call some function that set a variable outside their running 
environment.

The trick is that this variable is not global, but defined
on runtime before calling the hooks, and I don't want to leave any 
trace (i.e. global variables) after the main code has finished.


The best way to do this is to pass the function (setVar below) as an 
argument to the user's function.  If it's the user's function, you 
have no business messing with it by changing its environment.  How do 
you know the user didn't spend hours working out some crazy scheme of 
creating a nested function with a carefully crafted environment, and 
evaluation of his function depends on you leaving it alone?





I thought that the following would work but it doesn't. I guess I got 
too messy with environment and enclosures:


# global function defined by the user
fun.global - function(){
message('fun.global')
setVar(5) #
}


Pass setVar as an arg:

fun.global - function(setVar) {
message('fun.global')
setVar(5)
}




# my main code
main - function(){
message('main')
 
# define a function to set some local variable

setVar - local({
l.var - 0
function(value){
message('setVar')
   l.var - value
}
})
.workspace - environment(setVar)
environment(setVar) - new.env()
 
eval(fun.global(), enclos=environment(setVar))

print(get('l.var', envir=.workspace, inherits=FALSE))
}


I wouldn't bother with the extra layer of local(), just put l.var in 
main's evalution frame.  (Since you're the one writing setVar, you can 
avoid any name clashes.)  That is:


main - function() {
message('main')
l.var - 0
setVar - function(value) {
message('setVar')
l.var - value
}
fun.global(setVar)
print(l.var)
}   



Duncan Murdoch



main()

I get the following output:
  main
  fun.global
  Error in fun.global() : could not find function setVar

There is definitely a problem of lookup somewhere. I first tried 
without eval, as I thought that function setVar would then be defined 
in a parent environment of the call to fun.global, but it does not 
work either.

Can anybody tell me what's the problem and how I should do my stuff?

Thanks,
Renaud

__
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] creating gantt chart

2009-08-21 Thread Gabor Grothendieck
Go to rseek.org and enter: gantt chart

On Fri, Aug 21, 2009 at 8:35 AM, rajclinasiar...@clinasia.com wrote:

 Hi every one,
 I have a R dataset like this.

 labels      starts                     ends
 first task         2004-01-01   2004-03-03
 second task 2004-02-02  2004-05-05
 third task          2004-03-03  2004-06-06
 fourth task  2004-04-04 2004-08-08
 fifth task         2004-05-05   2004-09-09

 now i want to create gantt chart for this data. can any body help us in
 code, it will be very helpful for us.

 Thanks in Advance.
 --
 View this message in context: 
 http://www.nabble.com/creating-gantt-chart-tp25078977p25078977.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] creating gantt chart

2009-08-21 Thread Paul Hiemstra

rajclinasia wrote:

Hi every one,
I have a R dataset like this.

labels  starts ends
first task 2004-01-01   2004-03-03
second task 2004-02-02  2004-05-05
third task  2004-03-03  2004-06-06
fourth task  2004-04-04 2004-08-08
fifth task 2004-05-05   2004-09-09

now i want to create gantt chart for this data. can any body help us in
code, it will be very helpful for us.

Thanks in Advance.
  

Hi,

RSiteSearch(gantt chart)
type R-help gantt chart in to google

cheers,
Paul

--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 274 3113 Mon-Tue
Phone:  +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul

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


Re: [R] multiple linear regression

2009-08-21 Thread Peter Ehlers

Ronggui Huang wrote:

pls use lm(y ~ x1+x2)


and perhaps have a look at chapter 11 in the Introduction to R
manual which you will probably find right there already on your
computer.

Peter Ehlers



2009/8/21 Inchallah Yarab inchallahya...@yahoo.fr:

Good morning,

I want to make a linear regression of a variable fuction of  two variables y = 
a1 x1 + a2 x2 + c

I found the function lm (y ~ x)  but it used  for a simple linear regression, 
but for  multiple regression i do not know which function do this!!

 Can you help me please!!

Thank you in advance



   [[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] 2d color coded line plot

2009-08-21 Thread baptiste auguie
geom_path in ggplot2 is another option, see two examples on this page:

http://had.co.nz/ggplot2/geom_path.html


HTH,

baptiste

2009/8/21 Jim Lemon j...@bitwrit.com.au:
 Gonçalo Graça wrote:

 Hi! I'm not experienced very experienced with R and i'm looking for a way
 doing plots like in this example
 http://www.mathworks.de/matlabcentral/fx_files/23566/2/color_line3.png,
 which basically it is a 2d plot in which the 3rd dimension (variable) is
 color coded. I have only seen elsewhere that it is possible to color code
 dots in a scatter plot and I tried it with success although I  I didn't find
 a way of including the color bar has legend to the plot.

 I wonder if any one can give me some hint on this.

 Hi Goncalo,
 Have a look at the color.scale.line, color.scale and smoothColor functions
 in the plotrix package. See color.legend for the color bar.

 Jim

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




-- 
_

Baptiste Auguié

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

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] Possible bug with lrm.fit in Design Library

2009-08-21 Thread Frank E Harrell Jr
Noah to use predict, nomogram, summary, anova, etc. you need the fit 
object to be from the high level function (e.g., lrm).


Frank


Noah Silverman wrote:

Hi,

I've come across a strange error when using the lrm.fit function and the 
subsequent predict function.


The model is created very quickly and can be verified by printing it on 
the console.  Everything looks good. (In fact, the performance measures 
are rather nice.)


Then, I want to use the model to predict some values.  I get the 
following error: fit was not created by a Design library fitting function


This is the exact same data and process I'm using with the lrm 
function.  I thought I'd try lrm.fit to see if the results where better.


Since the model WAS created by a function of the Design library, I can't 
see how it would then be rejected.


Below is the session transcript:

 

  fmodel - lrm.fit(cbind(trainlogdata$v1, trainlogdata$v2), 
trainlogdata$label)

  fmodel

Logistic Regression Model

lrm.fit(x = cbind(trainlogdata$v1, trainlogdata$v2), y = 
trainlogdata$label)



Frequencies of Responses
0 1
20988  6684

   Obs  Max Deriv Model L.R.   d.f.  P  C
Dxy
 27672  8e-133876.12  2  0  0.744  
0.488

 Gamma  Tau-a R2  Brier
  0.49  0.179  0.195  0.157

  Coef   S.E.Wald Z P
Intercept -2.890 0.04318 -66.92 0
x[1]   5.864 0.23341  25.12 0
x[2]   4.479 0.17256  25.95 0

  predictions - predict(fmodel, trainlogdata, type=fitted);
Error in getOldDesign(fit) :

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




--
Frank E Harrell Jr   Professor and Chair   School of Medicine
 Department of Biostatistics   Vanderbilt University

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


Re: [R] Video demo of using svSocket with data.table

2009-08-21 Thread Philippe Grosjean

Romain Francois wrote:

Hi Philippe,

When Matthew brought this up the first time on this list, there were 
several replies to warn about potential problems related to R not being 
thread safe, and that this might cause trouble.


Well, that is true, R is not thread safe. What happens, basically, is 
that R clients run in the tcltk event loop. When a client is doing 
something, R is locked, processing the client's request before returning 
to the main loop. On the contrary, something running in the main loop 
can be interrupted pretty much anytime by a client's request. Regarding 
different clients, it is first in, first served rule: requests are 
processed in the order they appear.


It would be possible to adapt svSocket to delay processing of 
(asynchronous only) requests from clients, waiting from flags set by, 
either the main loop, or another client. That would be rather easy to do.


Otherwise, every clients and the CLI are working with the same objects 
on the same environment (.GlobalEnv, as primary one), but that is a 
*feature*! One constraint for designing svSocket is that the behaviour 
of R has to be as much as possible identical when a command is run on 
the main loop through the CLI, or from within a client.


Of course, you can imagine all sorts of bad interactions, and it is 
very, very easy to write a bad-behaving client. The goal is not to write 
a client-server architecture, but a multitasking way of manipulating R 
by the same end-user (thus, not likely to feed bad code from one side to 
destroy what he is doing from another side :-)

Best,

Philippe

Since you were on holidays, we did not get your viewpoint. Could you 
elaborate on how you deal with this.


browser works off the REPL, so this is unlikely that svSocket can take 
advantage of it, since the socket runs on a different loop. or maybe you 
can add something that feeds the R main loop, but I'm not sure this is 
possible unless you embed R ...


Romain

On 08/21/2009 11:04 AM, Philippe Grosjean wrote:


Hello Matthew and all R-UseRs,

You video demo is very nice. This suggests various uses of svSocket that
I had not think about! The primary goal was to make it:
- flexible (I think it is clear from the demo),
- running in the background while not blocking the CLI (Rgui, R.app, or
the terminal, very clear from your demo too),
- stateful (yes, this is not in your demo, but a client can disconnect
and reconnect and got the same server state it had just before
disconnection, including possibly, partial command send to R server),

Not implemented yet, but planned for the future:
- binary transfer of R objects,
- connection to distant secured server using TSL (of course, distant
connection requires a lot of extra precautions because R is NOT an
Internet-secure language and environment, but that applies to all
client/server R solutions like Rserve or Rpad),
- mirroring of the commands, results and history on the different
clients to make a simple collaborative R session.

The primary use in SciViews is the communication engine between the
client (a code editor, or IDE program like Komodo Edit) and server (R).
Your demo gives an idea on the flexibility one got with it, including
the possibility to inspect and/or change objects while R is running a
long process. Your example of changing the plot in real-time without
interrupting the main server's process is very illustrative. So now,
imagine the debugging flexibility for long running tasks, and/or
combination of svSocket with browser()... But that's another story,
because svSocket does not work nicely with browser() for the moment.

All the best,

Philippe

..°}))
) ) ) ) )
( ( ( ( ( Prof. Philippe Grosjean
) ) ) ) )
( ( ( ( ( Numerical Ecology of Aquatic Systems
) ) ) ) ) Mons-Hainaut University, Belgium
( ( ( ( (
..

Matthew Dowle wrote:

Dear r-help,
If you haven't already seen this then :
http://www.youtube.com/watch?v=rvT8XThGA8o
The video consists of typing at the console and graphics, there is no
audio
or slides. Please press the HD button and maximise. Its about 8 mins.
Regards, Matthew




__
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] gantt chart for dataset

2009-08-21 Thread rajclinasia

hi,
Thanks for responding of gantt charts. but i have some problem regarding
with gantt charts. i.e.

Ymd.format - %Y/%m/%d 

Ymd - function(x){ as.POSIXct(strptime(x, format=Ymd.format))} 
gantt.info - list( 
  labels =c(First task,Second task,Third task,Fourth task,Fifth
task), 
  starts
=Ymd(c(2004/01/01,2004/02/02,2004/03/03,2004/05/05,2004/09/09)),
  ends  
=Ymd(c(2004/03/03,2004/05/05,2004/05/05,2004/08/08,2004/12/12)),
  priorities =c(1,2,3,4,5))

gantt.chart(gantt.info,main=Calendar date Gantt chart)

the above code is fworking for individual varibale, that variables we have
to specify manually for each variable.

but my question is assume that above data stored in a excel file 'sample'.
now i want gantt chart for the 'sample' dataset.

-- 
View this message in context: 
http://www.nabble.com/gantt-chart-for-dataset-tp25079653p25079653.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] gantt chart for dataset

2009-08-21 Thread Stefan Grosse
On Fri, 21 Aug 2009 06:19:53 -0700 (PDT) rajclinasia r...@clinasia.com
wrote:

R but my question is assume that above data stored in a excel file
R 'sample'. now i want gantt chart for the 'sample' dataset.

As a list is expected you need to convert your data frame into a list...

hth
Stefan

__
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] optimization free software

2009-08-21 Thread Prof. John C Nash
There are also several projects on r-forge.r-project.org that deal with 
optimization, including one I'm involved with that has been putting up a 
number of new or reworked methods so that they can be tested, evaluated 
and improved. These all deal with unconstrained or box-constrained 
minimization problems (minimize -f(x) to maximize). In particular, we 
have an implementation of Mike Powell's BOBYQA (derivative-free 
box-constrained method using quadratic approximation) that seems quite 
interesting. See package minqa in the project 
http://r-forge.r-project.org/R/?group_id=395.


There is also a reworking of conjugate gradients with a rather better 
automated choice of generation formula (using Dai and Yuan, 2001 ideas) 
with box-constraints. It handles very large problems, often amazingly 
quickly e.g., an n=5000 generalized Rosenbrock problem, with analytic 
gradients, in 3 secs on an Asus Eee 900 netbook. And that is an all-R 
implementation.


Caveat: all these are developmental codes. We believe they work, but 
we are trying to torture test them and are finding some situations where 
they have glitches. We welcome use and comments to improve them. I 
expect the same applies to other codes on r-forge.


John Nash




Message: 98
Date: Thu, 20 Aug 2009 11:08:29 -0700
From: Gaspar N??ez nuroga...@gmail.com
Subject: [R] optimization free software
To: r-help@r-project.org
Message-ID:
9cd4bb290908201108x554ad8a3h520417208a330...@mail.gmail.com
Content-Type: text/plain

Hi

i´m starting to work with free software
(with free as in freedom)

i've been working with GAMS
(General Algebraic Modeling System)
to solve static and dynamic optimization problems
and non-linear large systems of equations

i'm wondering if there is any free software
and documentation on the subject,
wether in R, Maxima, or something else

i will appreciate any help
and any references about this issue

thanks in advance

gaspar

__
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] gantt chart for dataset

2009-08-21 Thread David Winsemius


On Aug 21, 2009, at 9:19 AM, rajclinasia wrote:



hi,
Thanks for responding of gantt charts. but i have some problem  
regarding

with gantt charts. i.e.

Ymd.format - %Y/%m/%d

Ymd - function(x){ as.POSIXct(strptime(x, format=Ymd.format))}
gantt.info - list(
 labels =c(First task,Second task,Third task,Fourth  
task,Fifth

task),
 starts
= 
Ymd 
(c(2004/01/01,2004/02/02,2004/03/03,2004/05/05,2004/09/09)),

 ends
= 
Ymd 
(c(2004/03/03,2004/05/05,2004/05/05,2004/08/08,2004/12/12)),

 priorities =c(1,2,3,4,5))

gantt.chart(gantt.info,main=Calendar date Gantt chart)

the above code is fworking for individual varibale, that variables  
we have

to specify manually for each variable.

but my question is assume that above data stored in a excel file  
'sample'.

now i want gantt chart for the 'sample' dataset.



It appears that you need to avail yourself of the introductory  
material that is on CRAN and pay particular attention to descriptions  
of the transfer of information from Excel to R. While it is possible  
to read Excel files from R, you have provided none of the information  
needed to allow specific advice on that point. Creation of a tab  
separated or comma separated file from Excel and reading into R is a  
rather generic approach for such transfers and would be the most  
advisable for an R-newbie to use. Once you have mastered that basic  
procedure, you should come back to the help-list with specific code  
and specific examples showing what you have tried and where you got  
stuck (with complete copies of the console output).


http://cran.r-project.org/manuals.html  #in particular R Data Import/ 
Export


(With R-help there is an expectation that you _first_ read the manuals  
_and_ spend time working the examples you will find there. _Then_ post  
questions.)


--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


[R] Principle components analysis on a large dataset

2009-08-21 Thread Prof. John C Nash
The essential issue is that the matrix you need to manipulate is very 
large. This is not a new problem, and about a year ago I exchanged ideas 
with the Rff package developers (things have been on the back burner 
since due to recession woes and illness issues). These ideas were based 
on some very small codes from my 1979 book Compact numerical methods 
for computers. This contains a code that takes a matrix row-wise from a 
file and builds a triangular decomposition as well as a list of 
orthogonal transformations, then does an svd of the result. Your problem 
would work on the transpose. This is a whole lot different from how R 
users generally  work, so there are lots of interfacing and similar 
issues. Also there are likely more efficient computational methods than 
the one I used -- but I was working in 1974 on an HP9830 desk calculator 
with the matrix on punched cards to develop this. And it has a short 
code that can be written in a fairly vectorized way in R only, which may 
make the human/computer trade-off favourable, depending on how many 
times you need to run such problems.


However, the main point is that you need to use some sort of out of 
core (how dated that sounds!) method, which is and will remain an issue 
for systems like R that work on objects in memory.


I'm willing to kibbitz on such work, but it would go best if there are 
3-4 folk involved to bring different skills to the table.


John Nash




Message: 128
Date: Thu, 20 Aug 2009 17:45:00 -0700 (PDT)
From: misha680 mk144...@bcm.edu
Subject: [R]  Principle components analysis on a large dataset
To: r-help@r-project.org
Message-ID: 25072510.p...@talk.nabble.com
Content-Type: text/plain; charset=us-ascii


Dear Sirs:

Please pardon me I am very new to R. I have been using MATLAB.

I was wondering if R would allow me to do principal components analysis on a
very large
dataset.

Specifically, our dataset has 68800 variables and around 6000 observations.
Matlab gives out of memory errors. I have tried also doing princomp in
pieces, but this does not seem to quite work for our approach.

Anything that might help much appreciated. If anyone has had experience
doing this in R much appreciated.

Thank you
Misha
-- View this message in context: 
http://www.nabble.com/Principle-components-analysis-on-a-large-dataset-tp25072510p25072510.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] LASSO: glmpath and cv.glmpath

2009-08-21 Thread Peter Schüffler

Hi,

perhaps you can help me to find out, how to find the best Lambda in a 
LASSO-model.


I have a feature selection problem with 150 proteins potentially 
predicting Cancer or Noncancer. With a lasso model


fit.glm - glmpath(x=as.matrix(X), y=target, family=binomial)

(target is 0, 1 - Cancer non cancer, X the proteins, numerical in 
expression), I get following path (PICTURE 1)
One of these models is the best, according to its crossvalidation 
(PICTURE 2), the red line corresponds to the best crossvalidation. Its 
produced by


cv - cv.glmpath(x=as.matrix(X), y=unclass(T)-1, family=binomial, type 
=response, plot.it=TRUE, se=TRUE)
abline(v= cv$fraction[max(which(cv$cv.error==min(cv$cv.error)))], 
col=red, lty=2, lwd=3)



Does anyone know, how to conclude from the Normfraction in PICTURE 2 to 
the corresponding model in PICTURE 1? What is the best model? Which 
coefficients does it have? I can only see the best model's cross 
validation error, but not the actual model. How to see it?


Thank you,

Peter



PICTURE 1:


PICTURE 2:

__
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] LASSO: glmpath and cv.glmpath

2009-08-21 Thread Steve Lianoglou

Hi,

On Aug 21, 2009, at 9:47 AM, Peter Schüffler wrote:


Hi,

perhaps you can help me to find out, how to find the best Lambda in  
a LASSO-model.


I have a feature selection problem with 150 proteins potentially  
predicting Cancer or Noncancer. With a lasso model


fit.glm - glmpath(x=as.matrix(X), y=target, family=binomial)

(target is 0, 1 - Cancer non cancer, X the proteins, numerical in  
expression), I get following path (PICTURE 1)
One of these models is the best, according to its crossvalidation  
(PICTURE 2), the red line corresponds to the best crossvalidation.  
Its produced by


cv - cv.glmpath(x=as.matrix(X), y=unclass(T)-1, family=binomial,  
type =response, plot.it=TRUE, se=TRUE)
abline(v= cv$fraction[max(which(cv$cv.error==min(cv$cv.error)))],  
col=red, lty=2, lwd=3)



Does anyone know, how to conclude from the Normfraction in PICTURE 2  
to the corresponding model in PICTURE 1? What is the best model?  
Which coefficients does it have? I can only see the best model's  
cross validation error, but not the actual model. How to see it?


None of your pictures came through, so I'm not sure exactly what  
you're trying to point out, but in general the cross validation will  
help you find the best value for lambda for the lasso. I think it's  
the value of lambda that you'll use for your downstream analysis.


I haven't used the glmpath package, but I have been using the glmnet  
package which is also by Hastie, newer, and I believe covers the same  
use cases as the glmpath library (though, to be honest, I'm not quite  
familiar w/ the cox proportions hazard model). Perhaps you might want  
to look into it.


Anyway, speaking from my experience w/ the glmnet packatge, you might  
try this:


1. Determine the best value of lambda using CV. I guess you can use  
MSE or R^2 as you see fit as your yardstick of best.


2. Train a model over all of your data and ask it for the coefficients  
at the given value of lambda from 1.


3. See which proteins have non-zero coefficients.

tongue-in-cheek
4. Divine a biological story that is explained by your statistical  
findings


4. Publish.
/tongue-in-cheek

I guess there are many ways to do model selection, and I'm not sure  
it's clear how effective they are (which isn't to say that you  
shouldn't don't do them)[1] ... you might want to further divide your  
data into training/tuning/test (somewhere between steps 1 and 2) as  
another means of scoring models.


HTH,
-steve

[1] http://hunch.net/?p=29

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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] Convert list to data frame while controlling column types

2009-08-21 Thread Steve Lianoglou

Hi Allie,

On Aug 21, 2009, at 11:47 AM, Alexander Shenkin wrote:


Hello all,

I have a list which I'd like to convert to a data frame, while
maintaining control of the columns' data types (akin to the colClasses
argument in read.table).  My numeric columns, for example, are getting
converted to factors by as.data.frame.  Is there a way to do this, or
will I have to do as I am doing right now: allow as.data.frame to  
coerce

column-types as it sees fit, and then convert them back manually?


This doesn't sound right ... are there characters buried in your  
numeric columns somewhere that might be causing this?


I'm pretty sure this shouldn't happen, and a small test case here goes  
along with my intuition:


R a - list(a=1:10, b=rnorm(10), c=LETTERS[1:10])
R df - as.data.frame(a)
R sapply(df, is.factor)
a b c
FALSE FALSE  TRUE

Can you check to see if your data's wonky somehow?

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

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

2009-08-21 Thread William Dunlap

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of kfcnhl
 Sent: Thursday, August 20, 2009 7:34 PM
 To: r-help@r-project.org
 Subject: [R] extra .
 
 
 sigma0 - sqrt((6. * var(maxima))/pi)
 
 What does the '.' do here?

In R it does nothing: both '6' and '6.' parse as numerics
(in C, double precision numbers).  In SV4 and S+ '6' parses
as an integer (in C, a long) and '6.' parses as a numeric,
so putting the decimal point after numerics makes the
code a bit more portable, although there are not too many
cases where the difference is significant.   Calls to .C, etc.,
and oveflowing arithmetic are the main problem points.

In R and S+ '6L' represents an integer.

S+'s parse has a parse.mode=R argument that parses
text more like R does: '6' is a numeric, '_' is not the assignment
operator,  has higher precedence than ||, etc.


 
 -- 
 View this message in context: 
 http://www.nabble.com/extra-.-tp25073255p25073255.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] Convert list to data frame while controlling column types

2009-08-21 Thread Alexander Shenkin
Hello all,

I have a list which I'd like to convert to a data frame, while
maintaining control of the columns' data types (akin to the colClasses
argument in read.table).  My numeric columns, for example, are getting
converted to factors by as.data.frame.  Is there a way to do this, or
will I have to do as I am doing right now: allow as.data.frame to coerce
column-types as it sees fit, and then convert them back manually?

Thanks,
Allie

__
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] Is there a construct for conditional comment?

2009-08-21 Thread Stavros Macrakis
On Thu, Aug 20, 2009 at 1:27 PM, David Winsemiusdwinsem...@comcast.net wrote:
...
 But an extremely simple modification succeeds:

  if ( 0 ) {
  commented with zero
  } else {
  commented with one
  }

 Returns:
 [1] \ncommented with one\n

Yes, but of course that executes neither one nor the other.  This works, though:

eval(parse(textConnection(if (FALSE) 
  syntactically  incorrect ' code must not use double-quotes, though
 else 
 print('this is a test')
)))

though it is horribly ugly, so I second the suggestion to do this in
your text editor if you must do it at all.

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

2009-08-21 Thread Steve Lianoglou

Hi,

This is somehow unrelated, but your answer brings up a question that  
I've been curious about:


On Aug 21, 2009, at 11:48 AM, William Dunlap wrote:




-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of kfcnhl
Sent: Thursday, August 20, 2009 7:34 PM
To: r-help@r-project.org
Subject: [R] extra .


sigma0 - sqrt((6. * var(maxima))/pi)

What does the '.' do here?


In R it does nothing: both '6' and '6.' parse as numerics
(in C, double precision numbers).  In SV4 and S+ '6' parses
as an integer (in C, a long) and '6.' parses as a numeric,
so putting the decimal point after numerics makes the
code a bit more portable, although there are not too many
cases where the difference is significant.   Calls to .C, etc.,
and oveflowing arithmetic are the main problem points.

In R and S+ '6L' represents an integer.


If this is true, I'm curious as to why when I'm poking through some  
source code of different packages, I see that some people are careful  
to explicitly include the L after integers?


I can't find a good example at the moment, but you can see one such  
case in the source to the lm.fit function. The details aren't all that  
important, but here's one of the lines:


r2 - if (z$rank  p)
(z$rank + 1L):p

I mean, why not just (z$rank + 1):p ?

Just wondering if anybody has any insight into that. I've always been  
curious and I seem to see it done in many different functions and  
packages, so I feel like I'm missing something ...


Thanks,

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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] Repost - Calculating loess value

2009-08-21 Thread Noah Silverman

Hello,

I'm attempting to evaluate the accuracy of the probability predictions 
for my model.  As previously discussed here, the AUC is not a good 
measure as I'm not concerned with classification accuracy but 
probability accurcy.


It was suggested to me that the loess function would be a good measure 
to look at.


I can see some libraries (Design) will plot the loess function as a 
curve of the resulting model.  That's nice to look at, but I need a way 
to feed in a test set of data and measure the accuracy of my predicted 
probabilities.


I read the help page for loess and it looks like a learner of its own. I 
already have a model trained with SVM and can apply the test data for a 
result of output that is predicted probabilities and true labels.  How 
can I feed this to the loess function to both see a curve and get the 
mean absolute error among other measures.


Ultimately what I am trying to do is develop a model with high accuracy 
of predicted probabilities.  I'm testing many different learning 
functions, kernels, parameters, etc.  I'mm looking of a single 
performance measure that summarized the probability accuracy for a 
given model.  That way I can track my experiment's results and pick the 
best one.


Any suggestions along these lines would be greatly appreciated.

Thank You,

-Noah

__
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] Repost - Possible bug with lrm.fit in Design Library

2009-08-21 Thread Noah Silverman

Hi,

I've come across a strange error when using the lrm.fit function and the 
subsequent predict function.


The model is created very quickly and can be verified by printing it on 
the console.  Everything looks good. (In fact, the performance measures 
are rather nice.)


Then, I want to use the model to predict some values.  I get the 
following error: fit was not created by a Design library fitting function


This is the exact same data and process I'm using with the lrm function. 
 I thought I'd try lrm.fit to see if the results where better.


Since the model WAS created by a function of the Design library, I can't 
see how it would then be rejected.


Below is the session transcript:



fmodel - lrm.fit(cbind(trainlogdata$v1, trainlogdata$v2),

trainlogdata$label)

fmodel


Logistic Regression Model

lrm.fit(x = cbind(trainlogdata$v1, trainlogdata$v2), y = trainlogdata$label)


Frequencies of Responses
0 1
20988  6684

   Obs  Max Deriv Model L.R.   d.f.  P  C 
  Dxy
 27672  8e-133876.12  2  0  0.744 
0.488

 Gamma  Tau-a R2  Brier
  0.49  0.179  0.195  0.157

  Coef   S.E.Wald Z P
Intercept -2.890 0.04318 -66.92 0
x[1]   5.864 0.23341  25.12 0
x[2]   4.479 0.17256  25.95 0


predictions - predict(fmodel, trainlogdata, type=fitted);

Error in getOldDesign(fit) :

__
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] Query on Error : subscript out of bounds in Rclimdex

2009-08-21 Thread Bin1aya

Dear All,

I am trying for indices calculation in Rclimdex but I get following error

In addition: Warning messages:
1: In function ()  : NAs introduced by coercion
2: In function ()  : NAs introduced by coercion

How can I overcome this problem?

http://www.nabble.com/file/p25082608/GODAVARI.txt GODAVARI.txt 

Regards,
Binaya Pasakhala


-- 
View this message in context: 
http://www.nabble.com/Query-on-Error-%3A-subscript-out-of-bounds-in-Rclimdex-tp25082608p25082608.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] Repost - Possible bug with lrm.fit in Design Library

2009-08-21 Thread Marc Schwartz

On Aug 21, 2009, at 11:02 AM, Noah Silverman wrote:


Hi,

I've come across a strange error when using the lrm.fit function and  
the subsequent predict function.


The model is created very quickly and can be verified by printing it  
on the console.  Everything looks good. (In fact, the performance  
measures are rather nice.)


Then, I want to use the model to predict some values.  I get the  
following error: fit was not created by a Design library fitting  
function


This is the exact same data and process I'm using with the lrm  
function.  I thought I'd try lrm.fit to see if the results where  
better.


Since the model WAS created by a function of the Design library, I  
can't see how it would then be rejected.


Below is the session transcript:


snip

Noah, you seem to have missed Frank's reply to your original post  
about 3 hours ago:


  https://stat.ethz.ch/pipermail/r-help/2009-August/208940.html

HTH,

Marc Schwartz

__
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] eval and evironments: call local function in a global function

2009-08-21 Thread Gabor Grothendieck
Just one correction. The line environment(fun.global) - environment()
line below should be deleted. It was needed in a prior example but in this one
we use parent.frame()$setVar(4) in the call so that line is not needed in main.

On Fri, Aug 21, 2009 at 7:09 AM, Gabor
Grothendieckggrothendi...@gmail.com wrote:
 Yet another possibility is to simply mandate that the user call setVar
 directly from fun.global and ask them to do it like this:

 fun.global - function() parent.frame()$setVar(4)
 main - function() {
       l.var - 0
       setVar - function(value) { message(set Var); l.var - value }
       environment(fun.global) - environment()
       fun.global()
       print(l.var)
 }
 main()

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

2009-08-21 Thread William Dunlap

 -Original Message-
 From: Steve Lianoglou [mailto:mailinglist.honey...@gmail.com] 
 Sent: Friday, August 21, 2009 9:02 AM
 To: William Dunlap
 Cc: kfcnhl; r-help@r-project.org
 Subject: Re: [R] extra .
 
 Hi,
 
 This is somehow unrelated, but your answer brings up a question that  
 I've been curious about:
 
 On Aug 21, 2009, at 11:48 AM, William Dunlap wrote:
 
 
  -Original Message-
  From: r-help-boun...@r-project.org
  [mailto:r-help-boun...@r-project.org] On Behalf Of kfcnhl
  Sent: Thursday, August 20, 2009 7:34 PM
  To: r-help@r-project.org
  Subject: [R] extra .
 
 
  sigma0 - sqrt((6. * var(maxima))/pi)
 
  What does the '.' do here?
 
  In R it does nothing: both '6' and '6.' parse as numerics
  (in C, double precision numbers).  In SV4 and S+ '6' parses
  as an integer (in C, a long) and '6.' parses as a numeric,
  so putting the decimal point after numerics makes the
  code a bit more portable, although there are not too many
  cases where the difference is significant.   Calls to .C, etc.,
  and oveflowing arithmetic are the main problem points.
 
  In R and S+ '6L' represents an integer.
 
 If this is true, I'm curious as to why when I'm poking through some  
 source code of different packages, I see that some people are 
 careful  
 to explicitly include the L after integers?
 
 I can't find a good example at the moment, but you can see one such  
 case in the source to the lm.fit function. The details aren't 
 all that  
 important, but here's one of the lines:
 
  r2 - if (z$rank  p)
  (z$rank + 1L):p
 
 I mean, why not just (z$rank + 1):p ?
 
 Just wondering if anybody has any insight into that. I've 
 always been  
 curious and I seem to see it done in many different functions and  
 packages, so I feel like I'm missing something ...

Some developers are more fastidious than others.  Since lm.fit()$rank
is an integer and the sum must be integral it make senses to add an
integer instead of a numeric so you are passing an integer to colon.
The colon operator will return an integer vector in either case but it
seems cleaner (and very slightly faster) to pass it an integer.

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com 
 
 
 Thanks,
 
 -steve
 
 --
 Steve Lianoglou
 Graduate Student: Computational Systems Biology
|  Memorial Sloan-Kettering Cancer Center
|  Weill Medical College of Cornell University
 Contact Info: http://cbio.mskcc.org/~lianos/contact
 
 

__
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] Special LS estimation problem

2009-08-21 Thread megh

Hi, I have following kind of model : Y = X1 * a1 + X2 * a2 + error

Here sampled data for Y, X1, X2 are like that :

Y - replicate(10, matrix(rnorm(2),2), simplify = F)
X1 - replicate(10, matrix(rnorm(4),2), simplify = F)
X2 - replicate(10, matrix(rnorm(4),2), simplify = F)

My goal is to calculate LS estimates of vectors a1 and a2. Can anyone
please guide me how to do that in R? Is there any special function to handle
this kind of problem?

Thanks
-- 
View this message in context: 
http://www.nabble.com/%22Special%22-LS-estimation-problem-tp25083103p25083103.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] Repost - Possible bug with lrm.fit in Design Library

2009-08-21 Thread Noah Silverman
Thanks Marc,

My apologies to all for the unnecessary re-posting.

-Noah

On 8/21/09 9:13 AM, Marc Schwartz wrote:
 On Aug 21, 2009, at 11:02 AM, Noah Silverman wrote:

 Hi,

 I've come across a strange error when using the lrm.fit function and 
 the subsequent predict function.

 The model is created very quickly and can be verified by printing it 
 on the console.  Everything looks good. (In fact, the performance 
 measures are rather nice.)

 Then, I want to use the model to predict some values.  I get the 
 following error: fit was not created by a Design library fitting 
 function

 This is the exact same data and process I'm using with the lrm 
 function.  I thought I'd try lrm.fit to see if the results where better.

 Since the model WAS created by a function of the Design library, I 
 can't see how it would then be rejected.

 Below is the session transcript:

 snip

 Noah, you seem to have missed Frank's reply to your original post 
 about 3 hours ago:

   https://stat.ethz.ch/pipermail/r-help/2009-August/208940.html

 HTH,

 Marc Schwartz


[[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 with median for each row

2009-08-21 Thread Edward Chen
Hi,

I tried looking through google search on whether there's a way to computer
the median for each row of a nxn matrix and return the medians for each row
for further computation.
And also if the number of columns in the matrix are even, how could I
specify which median to use?

Thank you very much!

-- 
Edward Chen

[[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] help with median for each row

2009-08-21 Thread stephen sefick
?apply specifically the MARGINS argument

On Fri, Aug 21, 2009 at 11:50 AM, Edward Chenedche...@gmail.com wrote:
 Hi,

 I tried looking through google search on whether there's a way to computer
 the median for each row of a nxn matrix and return the medians for each row
 for further computation.
 And also if the number of columns in the matrix are even, how could I
 specify which median to use?

 Thank you very much!

 --
 Edward Chen

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




-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
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 with median for each row

2009-08-21 Thread Erik Iverson
Edward,

In general, if you have an nxn matrix, you can use the apply function to 
apply a function to each row of the matrix, and return the result. 

So, as a start, you could do, 

apply(your.mat, 1, median) 

or

apply(your.mat, 1, median, na.rm = TRUE) 

if you want to pass further arguments to median... You can also write your own 
function and pass it in, of course: 

E.g.,

apply(your.mat, 1, function(x) sum(x)+1001)

See ?apply.  

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Edward Chen
Sent: Friday, August 21, 2009 11:50 AM
To: r-help@r-project.org
Subject: [R] help with median for each row

Hi,

I tried looking through google search on whether there's a way to computer
the median for each row of a nxn matrix and return the medians for each row
for further computation.
And also if the number of columns in the matrix are even, how could I
specify which median to use?

Thank you very much!

-- 
Edward Chen

[[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] help with median for each row

2009-08-21 Thread Greg Hirson

Edward,

See ?apply

x = matrix(rnorm(100), ncol = 10)
apply(x, 1, median)

Hope this helps,

Greg

Edward Chen wrote:

Hi,

I tried looking through google search on whether there's a way to computer
the median for each row of a nxn matrix and return the medians for each row
for further computation.
And also if the number of columns in the matrix are even, how could I
specify which median to use?

Thank you very much!

  


--
Greg Hirson
ghir...@ucdavis.edu

Graduate Student
Agricultural and Environmental Chemistry

1106 Robert Mondavi Institute North
One Shields Avenue
Davis, CA 95616

__
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 summary() to an object created with ols()

2009-08-21 Thread Benjamin Volland

Hello R-list,

I am trying to calculate a ridge regression using first the *lm.ridge()* 
function from the MASS package and then applying the obtained Hoerl 
Kennard Baldwin (HKB) estimator as a penalty scalar to the *ols()* 
function provided by Frank Harrell in his Design package.

It looks like this:
 rrk1-lm.ridge(lnbcpc ~ lntex + lnbeerp + lnwinep + lntemp + pop, 
subset(aa, Jahr=1957  Jahr=1966))
 f - ols(lnbcpc ~ lntex + lnbeerp + lnwinep + lntemp + pop, 
subset(aa, Jahr=1957  Jahr=1966), penalty = rrk$kHKB)

 f

which returns
Linear Regression Model

ols(formula = lnbcpc ~ lntex + lnbeerp + lnwinep + lntemp + pop,
data = subset(aa, Jahr = 1957  Jahr = 1966), penalty = rrk$kHKB)

 n Model L.R.   d.f. R2  Sigma
10  38.59  8.814 0.98390.02796

Residuals:
1 2 3 4 5 6 
7 8 910
-0.014653 -0.002787  0.017515 -0.018145 -0.008757 -0.008035  0.006066  
0.045826 -0.001244 -0.015786


Coefficients:
Value Std. Error   t Pr(|t|)
Intercept  1.5240 3.3034  0.4613   0.8496
lntex  0.3722 0.2071  1.7975   0.6801
lnbeerp0.9085 0.5760  1.5771   0.6964
lnwinep   -0.1458 0.1874 -0.7781   0.7863
lntemp-0.0772 0.1344 -0.5743   0.8240
pop   -4.1889 1.9286 -2.1720   0.6571

Adjusted R-Squared: 0.2227

All in all beautiful (leaving aside that the results suck). The problem 
starts when I want to write the obtained coefficients (incl. Std. 
Errors, t-, and p-values) into a matrix.
Via the *f$coef* command I can only access the betas (1st column) and 
using the *summary(f)* function I get

 summary(f)
Fehler in summary.Design(f) :
adjustment values not defined here or with datadist for lntex lnbeerp 
lnwinep lntemp pop


Does anyone know how I can set the *datadist()* and the *options()* such 
that I will get access to all coefficients?


I tried:
 options(datadist=NULL)
 f - ols(lnbcpc ~ lntex + lnbeerp + lnwinep + lntemp + pop, 
subset(aa, Jahr=1957  Jahr=1966), penalty = rrk$kHKB)

 d - datadist(f)
but got:
 Fehler in sort.list(unique(y)) : 'x' must be atomic for 'sort.list'
 Have you called 'sort' on a list?

In the R documentation on ?ols() it states concerning the values 
returned: the same objects returned from |lm| (/unless |penalty| or 
|penalty.matrix| are given/ - then an abbreviated list is returned since 
|lm.pfit| is used as a fitter)... Unfortunately no information seems to 
be available on lm.pfit.
Does anyone know why the using that function leads to an abbreviated 
return list? Is there a trick to circumvent that?


Thanks
Benjamin Volland

P.S. Currently using R-version 2.7.1 on a Windows PC.

__
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 with median for each row

2009-08-21 Thread Matthias Kohl
if your matrix has many rows you might want to consider rowMedians from 
Bioconductor package Biobase.

hth,
Matthias

Greg Hirson schrieb:

Edward,

See ?apply

x = matrix(rnorm(100), ncol = 10)
apply(x, 1, median)

Hope this helps,

Greg

Edward Chen wrote:

Hi,

I tried looking through google search on whether there's a way to 
computer
the median for each row of a nxn matrix and return the medians for 
each row

for further computation.
And also if the number of columns in the matrix are even, how could I
specify which median to use?

Thank you very much!

  




--
Dr. Matthias Kohl
www.stamats.de

__
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 plot a gains chart in R?

2009-08-21 Thread clue_less

I have 1000 oberved binary reponses Y, and I also have 1000 predictited
probabilities predicted_prob (between 0 and 1) for those observed reponses.

How can I plot a gain chart in R?

Thanks.
-- 
View this message in context: 
http://www.nabble.com/how-to-plot-a-gains-chart-in-R--tp25083628p25083628.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 with pmvnorm function

2009-08-21 Thread Vaupo

Hi,

I´ve got a problem with using the pmvnorm function.

For example ,if i assume a bivariate normal distribution with mean=(0,0) and
sigma=(1,0.5,0.5,1)
how do i generate the probability for X1=2 and X2=3 ?


-- 
View this message in context: 
http://www.nabble.com/help-with-pmvnorm-function-tp25083846p25083846.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] survival analysis: time-variant covariates, right censored, re-current events

2009-08-21 Thread clue_less

I have a data set for survival analysis in R. The data have time-variant
covariates, and right-censored outcomes, which could also be re-current
events.

What R package should I use?

Thanks!
-- 
View this message in context: 
http://www.nabble.com/survival-analysis%3A-time-variant-covariates%2C-right-censored%2C-re-current-events-tp25083950p25083950.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] survival analysis: time-variant covariates, right censored, re-current events

2009-08-21 Thread David Winsemius


On Aug 21, 2009, at 1:16 PM, clue_less wrote:



I have a data set for survival analysis in R. The data have time- 
variant
covariates, and right-censored outcomes, which could also be re- 
current

events.

What R package should I use?


Have you considered recasting the data into interval-censored form and  
using either Harrell's package:Design or Therneau's package:survival?


--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


[R] Help with residuals function.

2009-08-21 Thread rkevinburton
I have a misunderstanding on the residuals function in 'R'. In the stats 
package the residuals for the output of a HoltWinters fit is 
residuals.HoltWinters and the source looks like:

 stats:::residuals.HoltWinters
function (object, ...) 
object$x - object$fitted[, 1]
environment: namespace:stats
 

If I execute the following code (I only include the forecast package for the 
data set):

library(forecast)
library(expsmooth)
library(fma)
f - HoltWinters(wineind)

This results in a HoltWinters fit to the data in the variable 'f'. If I look at 
the first few data points:

 f$x[1:10]
 [1] 15136 16733 20016 17708 18019 19227 22893 23739 21133 22591

And at the fitted values:

 f$fitted[1:10,1]
 [1] 14043.33 16849.90 18885.04 20474.27 18836.84 21665.11 24118.32 25198.27
 [9] 22901.40 24450.89

Then at the residuals:

 residuals(f)[1:10]
 [1]   984.6741  1127.0982  1122.9566   879.7321   661.1564   459.8873
 [7]  1698.6798  3580.7276 -1941.4028 -2196.8865

Take the first element. It is clearly not simply f$x[1] - f$fitted[1,1] (which 
is 1092.674 not 984.6741). So my question is, What is actually being 
subtracted to get the residuals?

Thank you.

Kevin

__
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] Problem with RHEL 5 repo and the latest R RPMs

2009-08-21 Thread Hugh Brown
Hi everyone -- I have a number of systems here running CentOS 5.2 and
5.3.  Recently, I tried adding a package unrelated to R and found that
yum is complaining about the R repo.  Here's the error I get when
running yum update:


$ sudo yum update
[snip]

http://cran.r-project.org/bin/linux/redhat/el5/x86_64/repodata/primary.xml.gz: 
[Errno -3] Error performing checksum
Trying other mirror.
primary.xml.gz  2.9 kB 00:00

http://cran.r-project.org/bin/linux/redhat/el5/x86_64/repodata/primary.xml.gz: 
[Errno -3] Error performing checksum
Trying other mirror.
Error: failure: repodata/primary.xml.gz from CRAN: [Errno 256] No more 
mirrors to try.


/etc/yum.conf has these lines:


# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
[CRAN]
name=CRAN
baseurl=http://cran.r-project.org/bin/linux/redhat/el5/x86_64


This error persists even after running yum clean all and rm -f
/var/lib/rpm/__db.00? ; rpm --rebuilddb.  I've disabled the CRAN repo
and applied all available updates, and I still get these problems.
I've checked with the folks at CentOS, and they suggested contacting
the repo manager.

Looking at the repo itself, it seems that there's a new version that
was uploaded 10 days ago; I'm wondering if the new package or repo
files are causing me problems somehow.

Has anyone else had this problem?  Is there something I need to do to
make updates work?

Please let me know if you need any further information, or if there's
another person or mailing list I should be contacting.

Thanks in advance for any help!

--
Hugh Brown, Systems Manager
The Centre for High-Throughput Biology
hbr...@chibi.ubc.ca

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


Re: [R] Special LS estimation problem

2009-08-21 Thread Ted Harding
On 21-Aug-09 16:28:26, megh wrote:
 Hi, I have following kind of model : Y = X1 * a1 + X2 * a2 + error
 
 Here sampled data for Y, X1, X2 are like that :
 
 Y - replicate(10, matrix(rnorm(2),2), simplify = F)
 X1 - replicate(10, matrix(rnorm(4),2), simplify = F)
 X2 - replicate(10, matrix(rnorm(4),2), simplify = F)
 
 My goal is to calculate LS estimates of vectors a1 and a2.
 Can anyone please guide me how to do that in R? Is there any
 special function to handle this kind of problem?
 
 Thanks

In your example, a1 and a2 cannot be vectors, since Y, X1 and X2
are all 2x2 matrices. On the other hand, either or both of a1, a2
could be either a scalar or a 2x2 matrix, any of which would make
X1*a1 + X2*a2 (provided you interpret * as %*% in R) into a
2x2 matrix. But if (say) a1 is a vector it can only be a 2x1
vector (for multiplication conformity), and then X1*a1 (or X1%*%a1
in R) would be a 2x1 vector (in the linear algebra sense, i.e.
a 2x1 matrix in the R sense).

So what is it that you want in the model?

Next, if in fact a1 and a2 are scalars, then in effect you are
looking at

  Y1[1,1] = a1*X1[1,1] + a2*X2[1,1] + error[1,1]
  Y1[1,2] = a1*X1[1,2] + a2*X2[1,2] + error[1,2]
  Y1[2,1] = a1*X1[2,1] + a2*X2[2,1] + error[2,1]
  Y1[2,2] = a1*X1[2,2] + a2*X2[2,2] + error[2,2]

10 times over. The relevant question here is: Are you wanting
to include possible covariance between the 4 elements of 'error'?

One possibility in this case is to treat this as a multilevel
or longitudinal model, with 4 observations per subject, and
correlated error within-subject.

But you really need to spell out more detail of the kind of
model you are seeking to fit. What you described is not enough!

Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 21-Aug-09   Time: 18:48:31
-- XFMail --

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


Re: [R] how to compute this summation...

2009-08-21 Thread Vitalie S.
On Thu, 20 Aug 2009 02:36:38 +0200, kathie kathryn.lord2...@gmail.com  
wrote:




Dear R users,

I try to compute this summation,

http://www.nabble.com/file/p25054272/dd.jpg

where

f(y|x) = Negative Binomial(y, mu=exp(x' beta), size=1/alp)

http://www.nabble.com/file/p25054272/aa.jpg

http://www.nabble.com/file/p25054272/cc.jpg


In fact, I tried to use do.call function to compute each u(y,x) before  
the
summation, but I got an error, Error in X[i, ] * t(beta) :  
non-conformable

arrays.


Here is my code.

#--



# data 
yy - c(2,2,10,3,6,7,9,9,14,6)
x1 - c(0,0,0,0,0,1,0,0,0,0)
x2 - c(1,1,0,1,0,0,0,0,0,0)
x3 - c(0,0,1,0,0,0,0,0,0,0)
x4 - c(0,0,0,0,0,0,0,0,0,0)
x5 - c(0,0,0,0,0,0,0,0,0,1)
x6 - c(0,0,0,0,1,0,0,0,0,0)

n - length(yy)
x - cbind(x1,x2,x3,x4,x5,x6)
X - cbind(1,x)
p - 7     p:#beta

library(numDeriv)

# u function ---

obj - function(theta,i,j)
{
beta - theta[1:p]
alp - theta[p+1]

log(dnbinom(yy[j], mu=exp(rowSums(X[i,] * t(beta))), size=1/alp))
}



list - expand.grid(j=seq(1,n),i=seq(1,n))

func - function(i,j) { grad(func=obj,i=i,j=j,
x=c(1.50, 0.02, 0.09, 0.22,  0.17, -0.08, -0.13, 0.04)) }

do.call( func, list )


I could not get what you were trying to do here, but here are a couple of  
suggestions shat might help:


--Look at function ?outer (applies you function to combinations of i and j  
- so no need of expand.grid)

--Look at ?Reduce - might help in your case.
--grad function does not have i and j variables - so you are doing  
something wrong there

--do not name your data.frame - list
--do not call your function - obj

Best,
Vitalie.




#


Any suggestion will be greatly appreciated.

Regards,

Kathryn Lord



--

__
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] Special LS estimation problem

2009-08-21 Thread megh

Y is 2 dimensional vector, X1 and X2 are 2x2 matrices. 


Ted.Harding-2 wrote:
 
 On 21-Aug-09 16:28:26, megh wrote:
 Hi, I have following kind of model : Y = X1 * a1 + X2 * a2 + error
 
 Here sampled data for Y, X1, X2 are like that :
 
 Y - replicate(10, matrix(rnorm(2),2), simplify = F)
 X1 - replicate(10, matrix(rnorm(4),2), simplify = F)
 X2 - replicate(10, matrix(rnorm(4),2), simplify = F)
 
 My goal is to calculate LS estimates of vectors a1 and a2.
 Can anyone please guide me how to do that in R? Is there any
 special function to handle this kind of problem?
 
 Thanks
 
 In your example, a1 and a2 cannot be vectors, since Y, X1 and X2
 are all 2x2 matrices. On the other hand, either or both of a1, a2
 could be either a scalar or a 2x2 matrix, any of which would make
 X1*a1 + X2*a2 (provided you interpret * as %*% in R) into a
 2x2 matrix. But if (say) a1 is a vector it can only be a 2x1
 vector (for multiplication conformity), and then X1*a1 (or X1%*%a1
 in R) would be a 2x1 vector (in the linear algebra sense, i.e.
 a 2x1 matrix in the R sense).
 
 So what is it that you want in the model?
 
 Next, if in fact a1 and a2 are scalars, then in effect you are
 looking at
 
   Y1[1,1] = a1*X1[1,1] + a2*X2[1,1] + error[1,1]
   Y1[1,2] = a1*X1[1,2] + a2*X2[1,2] + error[1,2]
   Y1[2,1] = a1*X1[2,1] + a2*X2[2,1] + error[2,1]
   Y1[2,2] = a1*X1[2,2] + a2*X2[2,2] + error[2,2]
 
 10 times over. The relevant question here is: Are you wanting
 to include possible covariance between the 4 elements of 'error'?
 
 One possibility in this case is to treat this as a multilevel
 or longitudinal model, with 4 observations per subject, and
 correlated error within-subject.
 
 But you really need to spell out more detail of the kind of
 model you are seeking to fit. What you described is not enough!
 
 Ted.
 
 
 E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
 Fax-to-email: +44 (0)870 094 0861
 Date: 21-Aug-09   Time: 18:48:31
 -- XFMail --
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 

-- 
View this message in context: 
http://www.nabble.com/%22Special%22-LS-estimation-problem-tp25083103p25084866.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] Convert list to data frame while controlling column types

2009-08-21 Thread David Winsemius


On Aug 21, 2009, at 11:47 AM, Alexander Shenkin wrote:


Hello all,

I have a list which I'd like to convert to a data frame, while
maintaining control of the columns' data types (akin to the colClasses
argument in read.table).  My numeric columns, for example, are getting
converted to factors by as.data.frame.  Is there a way to do this,


Perhaps this may help:
as.data.frame(xlist,stringsAsFactors = FALSE)
 ll -list( a=1:10, b=as.character(1:10)  )
 str( as.data.frame(ll) )
'data.frame':   10 obs. of  2 variables:
 $ a: int  1 2 3 4 5 6 7 8 9 10
 $ b: Factor w/ 10 levels 1,10,2,3,..: 1 3 4 5 6 7 8 9 10 2
 str( as.data.frame(ll, stringsAsFactors=FALSE) )
'data.frame':   10 obs. of  2 variables:
 $ a: int  1 2 3 4 5 6 7 8 9 10
 $ b: chr  1 2 3 4 ...
This will not force conversion to numeric if they started life as  
character. Maybe you need to use lapply with as.numeric?



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] Special LS estimation problem

2009-08-21 Thread Ted Harding
On 21-Aug-09 18:12:45, megh wrote:
 
 Y is 2 dimensional vector, X1 and X2 are 2x2 matrices. 

Sorry -- I mis-read your code! I will think about your problem.
Apologies.
Ted.

 Ted.Harding-2 wrote:
 
 On 21-Aug-09 16:28:26, megh wrote:
 Hi, I have following kind of model : Y = X1 * a1 + X2 * a2 + error
 
 Here sampled data for Y, X1, X2 are like that :
 
 Y - replicate(10, matrix(rnorm(2),2), simplify = F)
 X1 - replicate(10, matrix(rnorm(4),2), simplify = F)
 X2 - replicate(10, matrix(rnorm(4),2), simplify = F)
 
 My goal is to calculate LS estimates of vectors a1 and a2.
 Can anyone please guide me how to do that in R? Is there any
 special function to handle this kind of problem?
 
 Thanks
 
 In your example, a1 and a2 cannot be vectors, since Y, X1 and X2
 are all 2x2 matrices. On the other hand, either or both of a1, a2
 could be either a scalar or a 2x2 matrix, any of which would make
 X1*a1 + X2*a2 (provided you interpret * as %*% in R) into a
 2x2 matrix. But if (say) a1 is a vector it can only be a 2x1
 vector (for multiplication conformity), and then X1*a1 (or X1%*%a1
 in R) would be a 2x1 vector (in the linear algebra sense, i.e.
 a 2x1 matrix in the R sense).
 
 So what is it that you want in the model?
 
 Next, if in fact a1 and a2 are scalars, then in effect you are
 looking at
 
   Y1[1,1] = a1*X1[1,1] + a2*X2[1,1] + error[1,1]
   Y1[1,2] = a1*X1[1,2] + a2*X2[1,2] + error[1,2]
   Y1[2,1] = a1*X1[2,1] + a2*X2[2,1] + error[2,1]
   Y1[2,2] = a1*X1[2,2] + a2*X2[2,2] + error[2,2]
 
 10 times over. The relevant question here is: Are you wanting
 to include possible covariance between the 4 elements of 'error'?
 
 One possibility in this case is to treat this as a multilevel
 or longitudinal model, with 4 observations per subject, and
 correlated error within-subject.
 
 But you really need to spell out more detail of the kind of
 model you are seeking to fit. What you described is not enough!
 
 Ted.
 
 
 E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
 Fax-to-email: +44 (0)870 094 0861
 Date: 21-Aug-09   Time: 18:48:31
 -- XFMail --
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 
 -- 
 View this message in context:
 http://www.nabble.com/%22Special%22-LS-estimation-problem-tp25083103p250
 84866.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.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 21-Aug-09   Time: 18:59:54
-- XFMail --

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


[R] discriminant analysis

2009-08-21 Thread Beatriz Yannicelli
Dear all:

Is it possible to conduct a discriminant analysis in R with categorical and
continuous variables as predictors?

Beatriz

[[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] ROC curve and gains/lift chart

2009-08-21 Thread clue_less

What is the difference between ROC curve and gains/lift chart?

how to do them in R?

Thanks.
-- 
View this message in context: 
http://www.nabble.com/ROC-curve-and-gains-lift-chart-tp25083979p25083979.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] unable to connect to 'cran.r-project.org' on port 80.

2009-08-21 Thread clue_less

I tried to select a mirror site from R, but got the following error -


 chooseCRANmirror()
Warning message:
In open.connection(con, r) :
  unable to connect to 'cran.r-project.org' on port 80.


The consequence is that i have to install R-packages by downloading zip
files one by one, and then load them one by one.

Anybody has run into similiar problem?

Thanks.


-- 
View this message in context: 
http://www.nabble.com/unable-to-connect-to-%27cran.r-project.org%27-on-port-80.-tp25084138p25084138.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] unable to connect to 'cran.r-project.org' on port 80.

2009-08-21 Thread David Winsemius


On Aug 21, 2009, at 1:31 PM, clue_less wrote:



I tried to select a mirror site from R, but got the following error -



chooseCRANmirror()

Warning message:
In open.connection(con, r) :
 unable to connect to 'cran.r-project.org' on port 80.


The consequence is that i have to install R-packages by downloading  
zip

files one by one, and then load them one by one.


Dear clue_less:


PLEASE do read the posting guide http://www.R-project.org/posting-guide.html

***

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] Principle components analysis on a large dataset

2009-08-21 Thread misha680

Hi Moshe,

Your idea sounds reasonable to me. It seems analogous to have a system of
linear equations with
more unknowns that equations - there should be several solutions so there is
no exact PCA solution.

My plan (* = dot product)
1. Pick first nice vector to be longest - that is x1 * x1 is maximal.
2. For all second vectors x2 ~= x1, compute 
(x2 * x1)^2 / (x1 * x1)
and pick minimum as my second vector.
3. For all third vectors x3 ~= x2 ~= x1, compute
(x3 * x1)^2 / (x1 * x2) + (x3 * x2)^2/(x2 * x2)
and pick minimum as my third vector.
4. So on until we have 6000 vectors.
5. Perform PCA on this 6000x6000 resulting matrix.

What do you think?


Moshe Olshansky-2 wrote:
 
 Hi Misha,
 
 Since PCA is a linear procedure and you have only 6000 observations, you
 do not need 68000 variables. Using any 6000 of your variables so that the
 resulting 6000x6000 matrix is non-singular will do. You can choose these
 6000 variables (columns) randomly, hoping that the resulting matrix is
 non-singular (and checking for this). Alternatively, you can try something
 like choosing one nice column, then choosing the second one which is the
 mostly orthogonal to the first one (kind of Gram-Schmidt), then choose the
 third one which is mostly orthogonal to the first two, etc. (I am not sure
 how much rounoff may be a problem- try doing this using higher precision
 if you can). Note that you do not need to load the entire 6000x68000
 matrix into memory (you can load several thousands of columns, process
 them and discard them).
 Anyway, you will end up with a 6000x6000 matrix, i.e. 36,000,000 entries,
 which can fit into a memory and you can perform the usual PCA on this
 matrix.
 
 Good luck!
 
 Moshe.
 
 P.S. I am curious to see what other people think.
 
 --- On Fri, 21/8/09, misha680 mk144...@bcm.edu wrote:
 
 From: misha680 mk144...@bcm.edu
 Subject: [R]  Principle components analysis on a large dataset
 To: r-help@r-project.org
 Received: Friday, 21 August, 2009, 10:45 AM
 
 Dear Sirs:
 
 Please pardon me I am very new to R. I have been using
 MATLAB.
 
 I was wondering if R would allow me to do principal
 components analysis on a
 very large
 dataset.
 
 Specifically, our dataset has 68800 variables and around
 6000 observations.
 Matlab gives out of memory errors. I have tried also
 doing princomp in
 pieces, but this does not seem to quite work for our
 approach.
 
 Anything that might help much appreciated. If anyone has
 had experience
 doing this in R much appreciated.
 
 Thank you
 Misha
 -- 
 View this message in context:
 http://www.nabble.com/Principle-components-analysis-on-a-large-dataset-tp25072510p25072510.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.
 
 

-- 
View this message in context: 
http://www.nabble.com/Principle-components-analysis-on-a-large-dataset-tp25072510p25085859.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] Problem with RHEL 5 repo and the latest R RPMs

2009-08-21 Thread Marc Schwartz

On Aug 21, 2009, at 1:00 PM, Hugh Brown wrote:


Hi everyone -- I have a number of systems here running CentOS 5.2 and
5.3.  Recently, I tried adding a package unrelated to R and found that
yum is complaining about the R repo.  Here's the error I get when
running yum update:

   
   $ sudo yum update
   [snip]
   http://cran.r-project.org/bin/linux/redhat/el5/x86_64/repodata/primary.xml.gz 
: [Errno -3] Error performing checksum

   Trying other mirror.
   primary.xml.gz  2.9 kB 00:00
   http://cran.r-project.org/bin/linux/redhat/el5/x86_64/repodata/primary.xml.gz 
: [Errno -3] Error performing checksum

   Trying other mirror.
   Error: failure: repodata/primary.xml.gz from CRAN: [Errno 256] No  
more mirrors to try.

   

/etc/yum.conf has these lines:

   
   # PUT YOUR REPOS HERE OR IN separate files named file.repo
   # in /etc/yum.repos.d
   [CRAN]
   name=CRAN
   baseurl=http://cran.r-project.org/bin/linux/redhat/el5/x86_64
   

This error persists even after running yum clean all and rm -f
/var/lib/rpm/__db.00? ; rpm --rebuilddb.  I've disabled the CRAN repo
and applied all available updates, and I still get these problems.
I've checked with the folks at CentOS, and they suggested contacting
the repo manager.

Looking at the repo itself, it seems that there's a new version that
was uploaded 10 days ago; I'm wondering if the new package or repo
files are causing me problems somehow.

Has anyone else had this problem?  Is there something I need to do to
make updates work?

Please let me know if you need any further information, or if there's
another person or mailing list I should be contacting.

Thanks in advance for any help!


Hugh,

Take a look in /etc/yum.repos.d and see if there are any other yum  
config files (*.repo) with enabled repos that may be conflicting with  
the config you have in /etc/yum.conf.


You can use:

  sudo yum repolist

to get a quick list of repos that are enabled by default.

I would also remove the CRAN config from /etc/yum.conf and unless  
there is already one in /etc/yum.repos.d, create another (eg.  
CRAN.repo file) just for CRAN with the appropriate config information,  
including an explicit 'enabled=1' or 'enabled=0' directive. For  
several Fedora/RHEL releases, having separate yum config files, one  
per repo, is the preferred model.


An alternative, would be to not use the CRAN repo and add the EPEL (https://fedoraproject.org/wiki/EPEL 
), which has R and other add-on packages that are not part of the  
default RHEL/CentOS distribution. Instructions on how to set up and  
use the EPEL are on the page linked above.


I am also cc:ing Martyn Plummer and Bob Kinney here, just in case they  
have other ideas or are aware of other issues that may be relevant.


HTH,

Marc Schwartz

__
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] ROC curve and gains/lift chart

2009-08-21 Thread Christian Schulz

Have look in the ROCR package and Example's.

HTH Christian


What is the difference between ROC curve and gains/lift chart?

how to do them in R?

Thanks.



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


[R] Question about validating predicted probabilities

2009-08-21 Thread Noah Silverman

Hello,

Frank was nice enough to point me to the val.prob function of the Design 
library.


It creates a beautiful graph that really  helps me visualize how well my 
model is predicting probabilities.


By default, there are two lines on the graph
1) fitted logistic calibration curve
2) nonparametric fit using lowess

Right now, the nonparametric line doesn't look very good.

The fitted logistic line looks great.  It is right next to the ideal 
line!!


If I am understanding the graph correctly, whatever transformation the 
val.prob is doing to my predicted probability is making it really accurate.


Is there some standard function in R that will let me do the same 
transformation?  (I guess the long way around would be to tear into the 
actual val.prob function and try to reverse engineer what he's doing.  
But there must be something easier.)


Anybody  have any suggestions?

Thanks!

-N

__
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] Convert list to data frame while controlling column types

2009-08-21 Thread Alexander Shenkin
Thanks everyone for their replies, both on- and off-list.  I should
clarify, since I left out some important information.  My original
dataframe has some numeric columns, which get changed to character by
gsub when I replace spaces with NAs.  Thus, in going back to a
dataframe, those (now character) columns get converted to factors.  I
recently added stringsAsFactors to get characters to make things a bit
easier.  I wrote the column-type reset function below, but it feels
kludgey, so was wondering if there was some other way to specify how one
might want as.data.frame to handle the columns. 

str(final_dataf)
'data.frame':   1127 obs. of  43 variables:
 $ block  : Factor w/ 1 level 2: 1 1 1 1 1 1 1 1 1 1 ...
 $ treatment  : Factor w/ 4 levels I,M,N,T: 1 1 1 1 1 1 1 1 1 1 ...
 $ transect   : Factor w/ 1 level 4: 1 1 1 1 1 1 1 1 1 1 ...
 $ tag: chr  NA 121AL 122AL 123AL ...
...
 $ h1 : num  NA NA NA NA NA NA NA NA NA NA ...
...

reset_col_types - function (df, col_types) {
# Function to reset column types in dataframes.  col_types can be
constructed
# by using lapply(class,df)

coerce_fun = list (
character   = `as.character`,
factor  = `as.factor`,
numeric = `as.numeric`,
integer = `as.integer`,
POSIXct = `as.POSIXct`,
logical = `as.logical` )

for (i in 1:length(df)) {
df[,i] = coerce_fun[[ col_types[i] ]]( df[,i] ) #apply coerce
function
}
return(df)
}

col_types = lapply(final_dataf, class)
col_types = lapply(col_types, function(x) x[length(x)])  # for posix,
take the more specified class
names(col_types)=NULL
col_types = unlist(col_types)

final_dataf = as.data.frame(lapply(final_dataf, function(x)
gsub('^\\s*$',NA,x)), stringsAsFactors = FALSE)
final_dataf = reset_col_types(final_dataf, col_types)

Thanks,
Allie


On 8/21/2009 10:54 AM, Steve Lianoglou wrote:
 Hi Allie,

 On Aug 21, 2009, at 11:47 AM, Alexander Shenkin wrote:

 Hello all,

 I have a list which I'd like to convert to a data frame, while
 maintaining control of the columns' data types (akin to the colClasses
 argument in read.table).  My numeric columns, for example, are getting
 converted to factors by as.data.frame.  Is there a way to do this, or
 will I have to do as I am doing right now: allow as.data.frame to coerce
 column-types as it sees fit, and then convert them back manually?

 This doesn't sound right ... are there characters buried in your
 numeric columns somewhere that might be causing this?

 I'm pretty sure this shouldn't happen, and a small test case here goes
 along with my intuition:

 R a - list(a=1:10, b=rnorm(10), c=LETTERS[1:10])
 R df - as.data.frame(a)
 R sapply(df, is.factor)
 a b c
 FALSE FALSE  TRUE

 Can you check to see if your data's wonky somehow?

 -steve

 -- 
 Steve Lianoglou
 Graduate Student: Computational Systems Biology
   |  Memorial Sloan-Kettering Cancer Center
   |  Weill Medical College of Cornell University
 Contact Info: http://cbio.mskcc.org/~lianos/contact


__
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] data layout for crossed factors w/interaction in linear mix models

2009-08-21 Thread Rafael Diaz
Dear All,

I am trying to fit a simple linear mixed model (see below this paragraph) 
arising from a crossed factorial design with 2 factors and ubalanced number of 
replicates (from two to five) in each cell, but I keep getting an error message 
(see bottom of message).  The model is:

yijk = intercept + ai + bj + abij + ejik, where:

intercept is fixed, and the crosss factors, ai, i = 1,..,10, and bj, j= 
1,..,10, are random.  I am interested in estimating the variance components of 
these factors AND their interaction.  I have tried:

fm1 - lmer(formula = V1~1 + (1|V2) + (1|V3) + (1|V4), data = 'datos') using 
two types of data layout for datos:

1) using a matrix with 3 columns:

y intercept   ai's  bj's  abij's 
y111  1   1 1 1 (1x1)
y112  1   1 1  
y121  1   1 2 2 (1x2)
y122  1   1 2 
y123  1   1 2 
y131  1   1 3 3 (1x3)
. .   . . .
. .   . . .

2) using the design matrix from  Y = XBeta +Zb.  That is, using the same first 
two columns as above, but substituting 1020 columns (10 for ai's, 10 for bj's 
and 100 for abij's) for the last three columns.

I get the message: Error in eval(predvars, data, env) : invalid envir argument

Is my data layout mispecified? Do I need to input initial values for the random 
components in order to get the REML estimates?  I lmer valid for unbalanced 
designs?  Any help would be greatly appreciated.

Rafael Diaz
California State University Sacramento
Math and Stats

__
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] splitting a string up

2009-08-21 Thread stephen sefick
x - 1041281__2009_08_20_.lev

I would like to split this string up and only extract the leading numbers.

1041281

to use as a label for a data column in a bigger for loop function to
read in data.
regards,

-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
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] splitting a string up

2009-08-21 Thread Doran, Harold
 x - 1041281__2009_08_20_.lev
 strsplit(x, '_')[[1]][1]
[1] 1041281 

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of stephen sefick
 Sent: Friday, August 21, 2009 3:51 PM
 To: r-help@r-project.org
 Subject: [R] splitting a string up
 
 x - 1041281__2009_08_20_.lev
 
 I would like to split this string up and only extract the 
 leading numbers.
 
 1041281
 
 to use as a label for a data column in a bigger for loop 
 function to read in data.
 regards,
 
 --
 Stephen Sefick
 
 Let's not spend our time and resources thinking about things 
 that are so little or so large that all they really do for us 
 is puff us up and make us feel like gods.  We are mammals, 
 and have not exhausted the annoying little problems of being mammals.
 
   
 -K. Mullis
 
 __
 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] splitting a string up

2009-08-21 Thread Bert Gunter
gsub(\\_.*,,x)

This assume _ if the first character following the numbers. You may need a
character class if it can be one of several.

?gsub
?regex

for further (terse for the latter) details.

Bert Gunter
Genentech Nonclinical Biostatisics


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of stephen sefick
Sent: Friday, August 21, 2009 12:51 PM
To: r-help@r-project.org
Subject: [R] splitting a string up

x - 1041281__2009_08_20_.lev

I would like to split this string up and only extract the leading numbers.

1041281

to use as a label for a data column in a bigger for loop function to
read in data.
regards,

-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
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] splitting a string up

2009-08-21 Thread Henrique Dallazuanna
Try this:

gsub(__.*, , 1041281__2009_08_20_.lev)

On Fri, Aug 21, 2009 at 4:50 PM, stephen sefick ssef...@gmail.com wrote:

 x - 1041281__2009_08_20_.lev

 I would like to split this string up and only extract the leading numbers.

 1041281

 to use as a label for a data column in a bigger for loop function to
 read in data.
 regards,

 --
 Stephen Sefick

 Let's not spend our time and resources thinking about things that are
 so little or so large that all they really do for us is puff us up and
 make us feel like gods.  We are mammals, and have not exhausted the
 annoying little problems of being mammals.

-K. Mullis

 __
 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] splitting a string up

2009-08-21 Thread Bert Gunter
Actually _ is not a metacharacter so, gsub(_.*,,x) will do.

Bert Gunter
Genentech Nonclinical Biostatisics


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Doran, Harold
Sent: Friday, August 21, 2009 12:55 PM
To: stephen sefick; r-help@r-project.org
Subject: Re: [R] splitting a string up

 x - 1041281__2009_08_20_.lev
 strsplit(x, '_')[[1]][1]
[1] 1041281 

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of stephen sefick
 Sent: Friday, August 21, 2009 3:51 PM
 To: r-help@r-project.org
 Subject: [R] splitting a string up
 
 x - 1041281__2009_08_20_.lev
 
 I would like to split this string up and only extract the 
 leading numbers.
 
 1041281
 
 to use as a label for a data column in a bigger for loop 
 function to read in data.
 regards,
 
 --
 Stephen Sefick
 
 Let's not spend our time and resources thinking about things 
 that are so little or so large that all they really do for us 
 is puff us up and make us feel like gods.  We are mammals, 
 and have not exhausted the annoying little problems of being mammals.
 
   
 -K. Mullis
 
 __
 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] Convert list to data frame while controlling column types

2009-08-21 Thread David Winsemius


On Aug 21, 2009, at 3:41 PM, Alexander Shenkin wrote:


Thanks everyone for their replies, both on- and off-list.  I should
clarify, since I left out some important information.  My original
dataframe has some numeric columns, which get changed to character by
gsub when I replace spaces with NAs.


If you used is.na() -  that would not happen to a true _numeric_  
vector (but, of course, a numeric vector in a data.frame could not  
have spaces, so you are probably not using precise terminology). You  
would be well advised to include the actual code rather than applying  
loose terminology subject you your and our misinterpretation.


?is.na


I am guessing that you were using read.table() on the original data,  
in which case you should look at the colClasses parameter.


--
David Winsemius


Thus, in going back to a
dataframe, those (now character) columns get converted to factors.  I
recently added stringsAsFactors to get characters to make things a bit
easier.  I wrote the column-type reset function below, but it feels
kludgey, so was wondering if there was some other way to specify how  
one

might want as.data.frame to handle the columns.

str(final_dataf)
'data.frame':   1127 obs. of  43 variables:
$ block  : Factor w/ 1 level 2: 1 1 1 1 1 1 1 1 1 1 ...
$ treatment  : Factor w/ 4 levels I,M,N,T: 1 1 1 1 1 1 1 1 1  
1 ...

$ transect   : Factor w/ 1 level 4: 1 1 1 1 1 1 1 1 1 1 ...
$ tag: chr  NA 121AL 122AL 123AL ...
...
$ h1 : num  NA NA NA NA NA NA NA NA NA NA ...
...

reset_col_types - function (df, col_types) {
   # Function to reset column types in dataframes.  col_types can be
constructed
   # by using lapply(class,df)

   coerce_fun = list (
   character   = `as.character`,
   factor  = `as.factor`,
   numeric = `as.numeric`,
   integer = `as.integer`,
   POSIXct = `as.POSIXct`,
   logical = `as.logical` )

   for (i in 1:length(df)) {
   df[,i] = coerce_fun[[ col_types[i] ]]( df[,i] ) #apply coerce
function
   }
   return(df)
}

col_types = lapply(final_dataf, class)
col_types = lapply(col_types, function(x) x[length(x)])  # for posix,
take the more specified class
names(col_types)=NULL
col_types = unlist(col_types)

final_dataf = as.data.frame(lapply(final_dataf, function(x)
gsub('^\\s*$',NA,x)), stringsAsFactors = FALSE)
final_dataf = reset_col_types(final_dataf, col_types)

Thanks,
Allie


On 8/21/2009 10:54 AM, Steve Lianoglou wrote:

Hi Allie,

On Aug 21, 2009, at 11:47 AM, Alexander Shenkin wrote:


Hello all,

I have a list which I'd like to convert to a data frame, while
maintaining control of the columns' data types (akin to the  
colClasses
argument in read.table).  My numeric columns, for example, are  
getting
converted to factors by as.data.frame.  Is there a way to do this,  
or
will I have to do as I am doing right now: allow as.data.frame to  
coerce

column-types as it sees fit, and then convert them back manually?


This doesn't sound right ... are there characters buried in your
numeric columns somewhere that might be causing this?

I'm pretty sure this shouldn't happen, and a small test case here  
goes

along with my intuition:

R a - list(a=1:10, b=rnorm(10), c=LETTERS[1:10])
R df - as.data.frame(a)
R sapply(df, is.factor)
   a b c
FALSE FALSE  TRUE

Can you check to see if your data's wonky somehow?

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
 |  Memorial Sloan-Kettering Cancer Center
 |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] splitting a string up

2009-08-21 Thread Marc Schwartz

On Aug 21, 2009, at 2:50 PM, stephen sefick wrote:


x - 1041281__2009_08_20_.lev

I would like to split this string up and only extract the leading  
numbers.


1041281

to use as a label for a data column in a bigger for loop function to
read in data.
regards,



At least four options:

 gsub(_.*, , x)
[1] 1041281


 gsub(^([0-9]*)_.*, \\1, x)
[1] 1041281


 sapply(strsplit(x, split = _), [, 1)
[1] 1041281


 substr(x, 1, 7)
[1] 1041281


The fourth example presumes that the initial numeric sequence is  
always 7 characters in length. The first three do not make that  
presumption.


All will work where 'x' might contain multiple entries of a similar  
configuration as 'x'.


See ?gsub, ?regex, ?strsplit and ?substr for more information.

HTH,

Marc Schwartz

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


  1   2   >