Re: [R] Plotting Frequency Distribution in R

2008-05-14 Thread tony.sun

x - read.table(textConnection(   V1  V2
1   1 160.54%
2   1 201.59%
3   1  18.45%
4   1 179.03%
5   1 274.37%
6   1   0.00%
7   1  24.52%
8   1  39.17%
9   3  43.72%
10  1  53.06%
11  1  64.97%
12  1  79.84%
13  1  98.08%
14  1 115.32%
15  1 127.96%
16  1 155.38%
17  1 157.25%
18  1 193.17%
19  1  51.53%
20 15  99.32%
21  1 106.86%
22  1 219.44%), header=TRUE, as.is=TRUE)
# change to numeric
x$V2 - as.numeric(gsub(%, , x$V2))

#make some changes#
d-rep(x$V2,times=x$V1)
hist(d)




jholtman wrote:
 
 Does something like this do it for you:
 
 x - read.table(textConnection(   V1  V2
 1   1 160.54%
 2   1 201.59%
 3   1  18.45%
 4   1 179.03%
 5   1 274.37%
 6   1   0.00%
 7   1  24.52%
 8   1  39.17%
 9   3  43.72%
 10  1  53.06%
 11  1  64.97%
 12  1  79.84%
 13  1  98.08%
 14  1 115.32%
 15  1 127.96%
 16  1 155.38%
 17  1 157.25%
 18  1 193.17%
 19  1  51.53%
 20 15  99.32%
 21  1 106.86%
 22  1 219.44%), header=TRUE, as.is=TRUE)
 # change to numeric
 x$V2 - as.numeric(gsub(%, , x$V2))
 plot(x$V2, x$V1, type='h', lwd=2)
 
 
 On Tue, May 13, 2008 at 10:25 AM, Sachin J [EMAIL PROTECTED] wrote:
 
 Hi,
 How can plot a frequency distribution curve for the following data.
V1  V2
 1   1 160.54%
 2   1 201.59%
 3   1  18.45%
 4   1 179.03%
 5   1 274.37%
 6   1   0.00%
 7   1  24.52%
 8   1  39.17%
 9   3  43.72%
 10  1  53.06%
 11  1  64.97%
 12  1  79.84%
 13  1  98.08%
 14  1 115.32%
 15  1 127.96%
 16  1 155.38%
 17  1 157.25%
 18  1 193.17%
 19  1  51.53%
 20 15  99.32%
 21  1 106.86%
 22  1 219.44%

 Where V1 is count for each V2 value. for example there are 3 entries for
 43.72% value.
 Thanks in advance for the help.
 Regards,
 Sachin



[[alternative HTML version deleted]]


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


 
 
 -- 
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390
 
 What is the problem you are trying to solve?
 
   [[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.
 
 

-- 
View this message in context: 
http://www.nabble.com/Plotting-Frequency-Distribution-in-R-tp17210180p17224194.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] lattice: left-aligned text in strips?

2008-05-14 Thread RINNER Heinrich
[adapted repost of question
http://tolstoy.newcastle.edu.au/R/e4/help/08/03/6260.html]

Dear R community,

by default, text in the strips of a trellis plot is centered in the
strip.
Is there a way to have the text left-aligned?

For example:

library(lattice)
test - data.frame(x=rnorm(100), y=rnorm(100), a=rep(c(A: centered
text,B: centered text),50))
xyplot(y ~ x | a, data = test)  # ok, strip text is centered
test - data.frame(x=rnorm(100), y=rnorm(100), a=rep(c(A: left-aligned
text,B: left-aligned text (possibly lng
string),50))
xyplot(y ~ x | a, data = test)  # how???

I am using R 2.6.2 on Windows XP, package lattice Version 0.17-6.

[The reason I would like to do this is because in real life my
conditioning variable 'a' can have quite long strings as its value. I am
automatically creating a series of trellis plots, and in each one a
different number of panels will be produced (maybe 4, maybe 20,...). So
in some cases (few panels, short labels) text in the strips will be
perfectly readable, while in some cases (many panels, long labels) only
the middle of the text will.
I know I could abbreviate the strip text by using something like:
xyplot(y ~ x | substr(a,1,35), data = test) 
But there is no natural choice of string length here when I want to
cut off as few text as possible, so just left aligning the strip texts
would seem like a natural and easy(?) solution to me - if I was able to
do it...]

-Heinrich.



[[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] For Social Network Analysis-Graph Analysis - How to convert 2 mode data to 1 mode data?

2008-05-14 Thread Gabor Csardi
Hi Solomon,

On Tue, May 13, 2008 at 05:53:44PM -0400, Messing, Solomon O. wrote:
 Hi Gabor,
 
 Thank you for your help, and thanks for making the excellent igraph
 package.  The function below seems not generate an edge list that works
 for my data.  I coerced a my data from a data frame using
 graph.data.frame.  
 
 You asked in your previous post if 2-mode networks are bipartite.  I
 believe the answer is yes.  However, in 
 
 Hanneman, Robert A. and Mark Riddle.  2005.  Introduction to social
 network methods.  Riverside, CA:  University of California, Riverside (
 published in digital form at http://faculty.ucr.edu/~hanneman/ )
 
 I found the following: 
 
 Two-mode data are sometimes stored in a second way, called the
 bipartite matrix.  A bipartite matrix is formed by adding the rows as
 additional columns, and columns as additional rows.
 
 Did I need to convert my data frame to a bipartite matrix before
 applying the two.to.one function?

No. The function i've sent assumes that your network is bipartite, i.e. 
if A and B are connected by an edge, then they're assumed to be 
different types of nodes. Just create the graph, calculate the 'keep'
parameter, I assume that you know this from external information, and 
then call the function.

G.

 Solomon
 
 
 -Original Message-
 From: Gabor Csardi [mailto:[EMAIL PROTECTED]
 Sent: Saturday, May 10, 2008 1:09 PM
 To: Messing, Solomon O.
 Cc: r-help@r-project.org
 Subject: Re: [R] For Social Network Analysis-Graph Analysis - How to
 convert 2
 mode data to 1 mode data?
 
 Solomon, if i understand two-mode networks properly (they're bipartite,
 right?),
 then this is not hard to do with igraph. Basically, for each vertex
 create an
 order=2 neighborhood, and then create a graph from the adjacency list,
 it is something like this:
 
 two.to.one - function(g, keep) {
   neis - neighborhood(g, order=2)
   neis - lapply(seq(neis), function(x) neis[[x]][ neis[[x]] != x-1])
 ## drop
 self-loops
   neis - lapply(neis, function(x) x[ x %in% keep ])
 ## keep
 only these
   neis - lapply(seq(neis), function(x) t(cbind(x-1, neis[[x]])))
 ## create
 edge lists
   neis[-keep-1] - NULL
 ## these
 are not needed
   neis - matrix(unlist(neis), byrow=TRUE, nc=2)
 ## a
 single edge list
   neis - neis[ neis[,1]  neis[,2], ]
 ## count
 an edge once only
   mode(neis) - character
   g2 - graph.edgelist(neis, dir=FALSE)
   V(g2)$id - V(g2)$name
 ## 'id'
 is used in Pajek
   g2
 }
 
 It does not check that the graph is indeed two-mode, and it keeps the
 vertices given in the 'keep' argument. 'keep' is made of igraph vertex
 ids.
 You can use it like this:
 
 g - graph.ring(10)
 keep - seq(0,8,by=2) ## we keep the 'even' vertices
 
 g2 - two.to.one(g, keep)
 write.graph(two.to.one(g, keep), format=pajek, file=/tmp/a.net)
 
 I haven't tested it much. We'll have a better function in the next
 igraph
 version.
 Gabor
 
 On Fri, May 09, 2008 at 03:37:05PM -0400, Messing, Solomon O. wrote:
  Hi,
 
 
 
  Does anyone know of a package in R that has a function to convert
  network data (e.g. an adjacency matrix or ) from 2-mode to 1-mode?  I
 am
  conducting social network analysis.  I know that Pajek has this
 function
  under Net -- Transform -- 2-mode to 1-mode -- Rows.  I have
 searched
  the documentation under packages 'sna', 'network', 'igraph', and
  'dynamicgraph' but I was not able to identify a comparable function.
 
 
 
  I would just export my data to Pajek and import it to R, but I'm
 going
  to have to generate hundreds of these graphs, so it would take quite
 a
  bit of time to do it this way.
 
 
 
  Thanks,
 
 
 
  Solomon
 
 
 
 
 [[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.
 
 --
 Csardi Gabor [EMAIL PROTECTED]UNIL DGM

-- 
Csardi Gabor [EMAIL PROTECTED]UNIL DGM

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

2008-05-14 Thread Bert Jacobs
Hi,

 

I have two dataframes one with 144 rows and 160 columns (SDF1) and one with
12 rows and 160 columns (SDF2).

Now I'm trying to divide rows 1:12 with SDF2, rows 13:24 with SDF2, rows
25:36 with SDF 2, .

In S-Plus the following code works fine:

 

DFS = SDF1[1:144,1:60] / as.vector(SDF2[1:12,1:160])

 

but in R when I try to implement the formula I get  the following error:

/ only defined for equally-sized data frames

 

Can someone help me out on this one. Thx in advance.

Bert


[[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] For Social Network Analysis-Graph Analysis - How to convert 2 mode data to 1 mode data?

2008-05-14 Thread Gabor Csardi
Please stay on the list.

On Tue, May 13, 2008 at 06:05:15PM -0400, Messing, Solomon O. wrote:
 Gabor,
 
 By the way, this seems to work:

I'm a bit lost. So now you're converting your data frame 
to a matrix? Why? Or you're doing the two-mode to one-mode
conversion here? It does not seem so to me.

Btw. there is a get.adjacency function in igraph to convert 
a graph to an adjacency matrix.

G.

 
 df.to.nxn - function( x, y ){
 # x values will be the N x N values   
 M - matrix( nrow = length( unique( x ) ), ncol = length( unique( x
 ) ), 
   dimnames = list( unique( x ), unique( x ) ) )
 M[ 1:length( unique( x ) ), 1:length( unique( x ) ) ] - 0
 # initialize the values to 0 
 for( i in 1:length( x ) ) {
 # iterate through rows of data
 index = which( y == y[i] )
 M[ as.character( x[ index ] ), as.character( x[ index ]
 ) ] = 1
  }
 M
 # return M, an N x N matrix
 }

-- 
Csardi Gabor [EMAIL PROTECTED]UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] The try() function with read.delim().

2008-05-14 Thread Martin Maechler
 RT == Rolf Turner [EMAIL PROTECTED]
 on Wed, 14 May 2008 13:12:02 +1200 writes:

RT I have written a function which reads data from files using read.delim 
RT ().
RT The names of these files are complicated and are built using arguments
RT to the wrapper function.  Since the files in question may or may not
RT exist, I thought to enclose the read.delim() call in a try():

RT file - complicated expression
RT temp - try(read.delim(file))
RT if(inherits(temp,try-error)) {
RT   (Do something)
RT } else {
RT(Do something else)
RT }

RT But this doesn't work.  If file doesn't exist, then I get an error,

You get an error *message* but not an error, I'd think.

If you don't like the error *message* in this case, use

 try(..., silent=TRUE)

In R,  try() is now using tryCatch(), (type 'try' to see) 
and I would nowadays recommend using tryCatch() inside any function.
Another advantage of tryCatch(.) for you is that you can
decide yourself what to do with the error message.

The most simple thing would be something like

  if(is.null(tryCatch(temp - read.delim(file),
  error = function(e) NULL))) {
 ## error reading ... 
  } else {
 ## work with the 'temp' data frame
  }

Slightly more sophisticated

  temp - tryCatch(read.delim(file), error = function(e) e)
  if(inherits(e, error) {
 message(Caught error:, [EMAIL PROTECTED], \n)
 ## error reading ... 
  } else {
 ## work with the 'temp' data frame
  }


*However*, there's a small infelicity in the above:

You get an additional warning from file(..)  which you need to
suppress by another  suppressWarnings( . ) 
around the call.

Martin

RT and the wrapper function terminates, despite the presence of the try().
RT The object ``temp'' never gets created.

RT I can of course easily get around the problem by testing with

RT file.exists(file)

RT I just wondered --- why isn't try() working as expected here?  Am I  
RT being
RT silly to expect it to work?  If so, what am I not understanding about  
RT try()?

RT Thanks for any insights.

RT cheers,

RT Rolf

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

RT __
RT R-help@r-project.org mailing list
RT https://stat.ethz.ch/mailman/listinfo/r-help
RT PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
RT 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] Predictive Analytics event June 5-6, NYC

2008-05-14 Thread Elise Johnson

Hi, I wanted to make sure you were all aware of this upcoming event. There is
one remaining spring seminar in Predictive Analytics, on June 5-6 in New
York City.  This is intensive training for managers, marketers, and IT
people who need to make sense of customer data to predict buying behavior,
profit, etc.  Past attendees have given rave reviews. 

You can find more info at
http://www.predictionimpact.com/predictive-analytics-training.html, e-mail
[EMAIL PROTECTED], or call (415) 683-1146.

thanks --Elise Johnson, Prediction Impact

-- 
View this message in context: 
http://www.nabble.com/Predictive-Analytics-event-June-5-6%2C-NYC-tp17226517p17226517.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] The try() function with read.delim().

2008-05-14 Thread Martin Maechler
Oops, there where some typos / thinkos in my post,
in the more sophisticated  tryCatch() example. 
I append the full message with corrected example.
--
Martin
---

 RT == Rolf Turner [EMAIL PROTECTED]
 on Wed, 14 May 2008 13:12:02 +1200 writes:

RT I have written a function which reads data from files using read.delim 
RT ().
RT The names of these files are complicated and are built using arguments
RT to the wrapper function.  Since the files in question may or may not
RT exist, I thought to enclose the read.delim() call in a try():

RT file - complicated expression
RT temp - try(read.delim(file))
RT if(inherits(temp,try-error)) {
RT   (Do something)
RT } else {
RT(Do something else)
RT }

RT But this doesn't work.  If file doesn't exist, then I get an error,

You get an error *message* but not an error, I'd think.

If you don't like the error *message* in this case, use

 try(..., silent=TRUE)

In R,  try() is now using tryCatch(), (type 'try' to see) 
and I would nowadays recommend using tryCatch() inside any function.
Another advantage of tryCatch(.) for you is that you can
decide yourself what to do with the error message.

The most simple thing would be something like

  if(is.null(tryCatch(temp - read.delim(file),
  error = function(e) NULL))) {
 ## error reading ... 
  } else {
 ## work with the 'temp' data frame
  }

Slightly more sophisticated

  temp - tryCatch(read.delim(file), error = function(e) e)
  if(inherits(temp, error) {
 message(Caught error:, temp$message)
 ## error reading ... 
  } else {
 ## work with the 'temp' data frame
  }


*However*, there's a small infelicity in the above:

You get an additional warning from file(..)  which you need to
suppress by another  suppressWarnings( . ) 
around the call.

Martin

RT and the wrapper function terminates, despite the presence of the try().
RT The object ``temp'' never gets created.

RT I can of course easily get around the problem by testing with

RT file.exists(file)

RT I just wondered --- why isn't try() working as expected here?  Am I  
RT being
RT silly to expect it to work?  If so, what am I not understanding about  
RT try()?

RT Thanks for any insights.

RT cheers,

RT Rolf

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

RT __
RT R-help@r-project.org mailing list
RT https://stat.ethz.ch/mailman/listinfo/r-help
RT PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
RT 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] Negative Binomial Model

2008-05-14 Thread Ted Harding
On 14-May-08 09:11:31, Achim Zeileis wrote:
 On Wed, 14 May 2008, Mike Ryckman wrote:
 
 Hello,

 I am trying to run a negative binomial regression model in R and
 can't get the standard errors to match the output I get from the
 Stata nbreg command. I've tried a few different options but
 haven't had much luck. The closest I've found is:

 gamlss(formula, family = NBI, sigma.formula = ~ 1,data=dataframe)

 ...But this is still a little off most of the time and pretty far off
 at
 other
 times (compared with the Stata output). The glm.nb from the MASS
 package
 produces the correct coefficients, but different (usually very
 different)
 standard errors.

 Could anybody explain this and point me in the right direction? I'd
 really
 appreciate it.
 
 Well, you don't really give us enough information to know (a
 reproducible 
 R example and the desired standard errors from Stata would have been 
 helpful). My guess is that Stata uses some sort of robust standard 
 errors, i.e., sandwich standard errors. Try something like:
library(MASS)
library(sandwich)
library(lmtest)
fm - glm.nb(...)
coeftest(fm, vcov = sandwich)
 
 See also the following thread for some more discussion for count data 
 regression in R and Stata:
https://stat.ethz.ch/pipermail/r-help/2008-May/161640.html

Better links for following this thread are:

Start:
  https://stat.ethz.ch/pipermail/r-help/2008-May/161591.html

Then click on Next message: for the second. Unfortunately,
at that point the thread broke (Paul next responded to the list
as a reply to an off-list message I sent him). So to continue,
next take Achim's URL above:

  https://stat.ethz.ch/pipermail/r-help/2008-May/161640.html

and thereafter continue to click on Next message: until the
thread runs out.

That was a very helpful thread, for me!
Best wishes,
Ted.


E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 094 0861
Date: 14-May-08   Time: 10:38:24
-- 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] Negative Binomial Model

2008-05-14 Thread Mike Ryckman
Hello,

I am trying to run a negative binomial regression model in R and can't get
the
standard errors to match the output I get from the Stata nbreg command. I've
tried a few different options but haven't had much luck. The closest I've
found
is:

gamlss(formula, family = NBI, sigma.formula = ~ 1,data=dataframe)

...But this is still a little off most of the time and pretty far off at
other
times (compared with the Stata output). The glm.nb from the MASS package
produces the correct coefficients, but different (usually very different)
standard errors.

Could anybody explain this and point me in the right direction? I'd really
appreciate it.

Thank you,

Mike Ryckman
Department of Political Science
University of Arizona

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

2008-05-14 Thread Achim Zeileis

On Wed, 14 May 2008, Mike Ryckman wrote:


Hello,

I am trying to run a negative binomial regression model in R and can't get
the
standard errors to match the output I get from the Stata nbreg command. I've
tried a few different options but haven't had much luck. The closest I've
found
is:

gamlss(formula, family = NBI, sigma.formula = ~ 1,data=dataframe)

...But this is still a little off most of the time and pretty far off at
other
times (compared with the Stata output). The glm.nb from the MASS package
produces the correct coefficients, but different (usually very different)
standard errors.

Could anybody explain this and point me in the right direction? I'd really
appreciate it.


Well, you don't really give us enough information to know (a reproducible 
R example and the desired standard errors from Stata would have been 
helpful). My guess is that Stata uses some sort of robust standard 
errors, i.e., sandwich standard errors. Try something like:

  library(MASS)
  library(sandwich)
  library(lmtest)
  fm - glm.nb(...)
  coeftest(fm, vcov = sandwich)

See also the following thread for some more discussion for count data 
regression in R and Stata:

  https://stat.ethz.ch/pipermail/r-help/2008-May/161640.html

hth,
Z


Thank you,

Mike Ryckman
Department of Political Science
University of Arizona

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] upperbound of C index Conf.int. greater than 1

2008-05-14 Thread DAVID ARTETA GARCIA



Dear Frank

Frank E Harrell Jr [EMAIL PROTECTED] wrote:



A few observations.

1. With minimal overfitting, rcorr.cens(predict(fit), Y) gives a good
standard error for Dxy = 2*(C-.5) and bootstrapping isn't very necessary

2. If you bootstrap use the nonparametric bootstrap percentile method
or  other methods that constrain the confidence interval to be in [0,1].

3. I don't know why the model would be linear on the two predictors you
are using.


Do you mean using these predictors fitted with spline functions?? I  
have read about it in your Regression Modeling Strategies but I am  
not very sure I understand the use of them. I will read through it  
again.


David



Frank

--
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] Calling C code from R...wrapping C structures

2008-05-14 Thread Ramon Diaz-Uriarte
Dear Nathan,

How is you C function test defined? What type of argument is it
expecting? The mappings between R and C type of arguments you can pass
is explained in:

http://cran.r-project.org/doc/manuals/R-exts.html#Interface-functions-_002eC-and-_002eFortran

which also provides some examples. If you want to pass a list, you'll
probably have to use .Call, not .C.

HTH,

R.



On Tue, May 13, 2008 at 1:51 PM, Nathan Harmston
[EMAIL PROTECTED] wrote:
 Hi everyone,

  I am currently trying to call some C code from R, specifically calling a
  function which populates a C struct.

  typedef struct{
// contents
  } Model;

  void test(Model *m){
// fill the struct with crap
  }

  I compile the C code into a shared library, which loads into R properly. My
  simple test functions work (i.e adding numbers etc)
  setModel - function(){
model-vector(list, 6)
name(model) - c( SET THE NAMES OF THE MODEL HERE )
model
  }
  t - setModel()
  testcode - function(setModel){


  dyn.load(Simulation.so)

  foo - .C(test, Model=setModel)
  foo
  }

  testcode(t)

  However I get segfaults whenever I try to access any of the variables
  contained in Model. So my question is: am I doing something wrong here? Is
  list the right data type to wrap a structure in? I cant see any
  documentation about wrapping structs in R.

  Also when I pass strings to C from R they dont seem to be passed at all? Is
  this a problem with R or a problem with me and if so how do I fix it?



  Many Thanks in advance,

  Nathan

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




-- 
Ramon Diaz-Uriarte
Statistical Computing Team
Structural Biology and Biocomputing Programme
Spanish National Cancer Centre (CNIO)
http://ligarto.org/rdiaz

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


Re: [R] R benchmarking program

2008-05-14 Thread Martin Maechler
 PhGr == Philippe Grosjean [EMAIL PROTECTED]
 on Tue, 13 May 2008 16:10:15 +0200 writes:

PhGr Hello,
PhGr I did this bechmark test. Perhaps is it a good oppotunity to rewrite 
it 
PhGr and make it compatible with R 2.7.0, David?

I'll not really rewrite it (to make it nice in my eyes),
but I'm fixing the problems with the fact that the 'Matrix'
package you were using back then has been much changed in the
mean time.

Expect a corrected benchmark R script within a day or so.

Martin Maechler, ETH Zurich

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

PhGr Baker D.J. wrote:
 Hi All,
 
 I've just rebuild the latest R with the Goto BLAS on our new Intel quad 
core machines. I did a few basic matrix calculations, and I was very impressed 
by the performance I saw. I wonder if anyone has a more rigorous benchmarking 
program for R. I downloaded a old R test/benchmarking program (see below), and 
this didn't work with the current R, and so I wondered if anyone could please 
direct me to a more recent program that does a good all round test of R.
 
 Regards -- David.
 
 
 # R Benchmark 2.3 (21 April 2004)
 # Warning: changes are not carefully checked yet!
 # version 2.3 adapted to R 1.9.0
 # Many thanks to Douglas Bates ([EMAIL PROTECTED]) for improvements!
 # version 2.2 adapted to R 1.8.0
 # version 2.1 adapted to R 1.7.0
 # version 2, scaled to get 1 +/- 0.1 sec with R 1.6.2
 # using the standard ATLAS library (Rblas.dll)
 # on a Pentium IV 1.6 Ghz with 1 Gb Ram on Win XP pro
 
 # revised and optimized for R v. 1.5.x, 8 June 2002
 # Requires additionnal libraries: Matrix, SuppDists
 # Author : Philippe Grosjean
 # eMail  : [EMAIL PROTECTED]
 # Web: http://www.sciviews.org
 # License: GPL 2 or above at your convenience (see: http://www.gnu.org)
 #
 # Several tests are adapted from the Splus Benchmark Test V. 2
 # by Stephan Steinhaus ([EMAIL PROTECTED])
 # Reference for Escoufier's equivalents vectors (test III.5):
 # Escoufier Y., 1970. Echantillonnage dans une population de variables
 # aleatoires réles. Publ. Inst. Statis. Univ. Paris 19 Fasc 4, 1-47.
 
 ...
 Error in getClass(Class, where = topenv(parent.frame())) :
 geMatrix is not a defined class
 Calls: new - getClass
 Execution halted

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


Re: [R] R benchmarking program

2008-05-14 Thread Philippe Grosjean

Martin Maechler wrote:

PhGr == Philippe Grosjean [EMAIL PROTECTED]
on Tue, 13 May 2008 16:10:15 +0200 writes:


PhGr Hello,
PhGr I did this bechmark test. Perhaps is it a good oppotunity to rewrite it 
PhGr and make it compatible with R 2.7.0, David?


I'll not really rewrite it (to make it nice in my eyes),
but I'm fixing the problems with the fact that the 'Matrix'
package you were using back then has been much changed in the
mean time.

Expect a corrected benchmark R script within a day or so.


Thank you, Martin.


Martin Maechler, ETH Zurich

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

PhGr Baker D.J. wrote:
 Hi All,
 
 I've just rebuild the latest R with the Goto BLAS on our new Intel quad core machines. I did a few basic matrix calculations, and I was very impressed by the performance I saw. I wonder if anyone has a more rigorous benchmarking program for R. I downloaded a old R test/benchmarking program (see below), and this didn't work with the current R, and so I wondered if anyone could please direct me to a more recent program that does a good all round test of R.
 
 Regards -- David.
 
 
 # R Benchmark 2.3 (21 April 2004)

 # Warning: changes are not carefully checked yet!
 # version 2.3 adapted to R 1.9.0
 # Many thanks to Douglas Bates ([EMAIL PROTECTED]) for improvements!
 # version 2.2 adapted to R 1.8.0
 # version 2.1 adapted to R 1.7.0
 # version 2, scaled to get 1 +/- 0.1 sec with R 1.6.2
 # using the standard ATLAS library (Rblas.dll)
 # on a Pentium IV 1.6 Ghz with 1 Gb Ram on Win XP pro
 
 # revised and optimized for R v. 1.5.x, 8 June 2002

 # Requires additionnal libraries: Matrix, SuppDists
 # Author : Philippe Grosjean
 # eMail  : [EMAIL PROTECTED]
 # Web: http://www.sciviews.org
 # License: GPL 2 or above at your convenience (see: http://www.gnu.org)
 #
 # Several tests are adapted from the Splus Benchmark Test V. 2
 # by Stephan Steinhaus ([EMAIL PROTECTED])
 # Reference for Escoufier's equivalents vectors (test III.5):
 # Escoufier Y., 1970. Echantillonnage dans une population de variables
 # aleatoires réles. Publ. Inst. Statis. Univ. Paris 19 Fasc 4, 1-47.
 
 ...

 Error in getClass(Class, where = topenv(parent.frame())) :
 geMatrix is not a defined class
 Calls: new - getClass
 Execution halted

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

2008-05-14 Thread Shubha Vishwanath Karanth
 

Hi R,

 

I have the data frames, data1, data2data50. Now I want to put all of
these in a single list. But,

 

list(data1, data2,.data50) is very big to write. How do I then
do it?

 

Thanks,

Shubha

 

This e-mail may contain confidential and/or privileged i...{{dropped:13}}

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

2008-05-14 Thread Shubha Vishwanath Karanth
How do I proceed from this stage?
paste(data,1:10,sep=,collapse=,)

Shubha Karanth | Amba Research
Ph +91 80 3980 8031 | Mob +91 94 4886 4510 
Bangalore * Colombo * London * New York * San José * Singapore * 
www.ambaresearch.com

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shubha 
Vishwanath Karanth
Sent: Wednesday, May 14, 2008 3:59 PM
To: [EMAIL PROTECTED]
Subject: [R] dataframes to a list

 

Hi R,

 

I have the data frames, data1, data2data50. Now I want to put all of
these in a single list. But,

 

list(data1, data2,.data50) is very big to write. How do I then
do it?

 

Thanks,

Shubha

 

This e-mail may contain confidential and/or privileged i...{{dropped:13}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
This e-mail may contain confidential and/or privileged i...{{dropped:10}}

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

2008-05-14 Thread Serguei Kaniovski
Hallo All,

I have difficulties understanding how factors work in R. Suppose a have 
data in the panel form below. I would to compute a correlation coefficient 
(actually apply a different function of two time series) in the V variable 
between members of the two sexes in each city over time. How can this be 
done?

Thank you in advance,
Serguei

city, year, sex, V
1, 1975, 1, 25.3044
1, 1975, 0, 16.5711
1, 1976, 0, 16.6072
1, 1976, 1, 24.2841
1, 1977, 0, 14.8838
1, 1977, 1, 24.8124
1, 1978, 1, 23.0570
1, 1978, 0, 14.5627
1, 1979, 1, 21.2071
1, 1979, 0, 13.5277
2, 1975, 1, 62.4457
2, 1975, 0, 26.9745
2, 1976, 1, 67.3025
2, 1976, 0, 31.4600
2, 1977, 1, 53.0577
2, 1977, 0, 25.1941
2, 1978, 0, 23.3694
2, 1978, 1, 40.1452
2, 1979, 1, 44.5686
2, 1979, 0, 23.4042

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

2008-05-14 Thread Matthias Kohl

Does

mget(paste(data, 1:50, sep = ), envir = globalenv())

give what you want?

hth,
Matthias

Shubha Vishwanath Karanth wrote:

How do I proceed from this stage?
paste(data,1:10,sep=,collapse=,)

Shubha Karanth | Amba Research
Ph +91 80 3980 8031 | Mob +91 94 4886 4510 
Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shubha 
Vishwanath Karanth
Sent: Wednesday, May 14, 2008 3:59 PM
To: [EMAIL PROTECTED]
Subject: [R] dataframes to a list

 


Hi R,

 


I have the data frames, data1, data2data50. Now I want to put all of
these in a single list. But,

 

  

list(data1, data2,.data50) is very big to write. How do I then


do it?

 


Thanks,

Shubha

 


This e-mail may contain confidential and/or privileged i...{{dropped:13}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
This e-mail may contain confidential and/or privileged i...{{dropped:10}}

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


Re: [R] R benchmarking program

2008-05-14 Thread Martin Maechler
 MM == Martin Maechler [EMAIL PROTECTED]
 on Wed, 14 May 2008 12:05:00 +0200 writes:

 PhGr == Philippe Grosjean [EMAIL PROTECTED]
 on Tue, 13 May 2008 16:10:15 +0200 writes:

PhGr Hello,
PhGr I did this bechmark test. Perhaps is it a good oppotunity to rewrite 
it 
PhGr and make it compatible with R 2.7.0, David?

MM I'll not really rewrite it (to make it nice in my eyes),
MM but I'm fixing the problems with the fact that the 'Matrix'
MM package you were using back then has been much changed in the
MM mean time.

MM Expect a corrected benchmark R script within a day or so.

Here, it is {attachament in 'text/plain' which is allowed for R-help}

Note that I *do* agree with Prof. Brian Ripley about the
usefulness of benchmarks.

Martin Maechler, ETH Zurich

 R Benchmark 2.4 (May 2008)
benchVersion - structure(2.4,
  date = as.Date(2008-05-14))
 adapted to run in R 2.7.0 with Matrix 0.999735-9, Martin Maechler ETH 
Zurich
##
 R Benchmark 2.3 (21 April 2004)
 Warning: changes are not carefully checked yet!
 version 2.3 adapted to R 1.9.0
 Many thanks to Douglas Bates ([EMAIL PROTECTED]) for improvements!
 version 2.2 adapted to R 1.8.0
 version 2.1 adapted to R 1.7.0
 version 2, scaled to get 1 +/- 0.1 sec with R 1.6.2
 using the standard ATLAS library (Rblas.dll)
 on a Pentium IV 1.6 Ghz with 1 Gb Ram on Win XP pro

 revised and optimized for R v. 1.5.x, 8 June 2002
 Requires additionnal libraries: Matrix, SuppDists
 Author : Philippe Grosjean
 eMail  : [EMAIL PROTECTED]
 Web: http://www.sciviews.org
 License: GPL 2 or above at your convenience (see: http://www.gnu.org)

 Several tests are adapted from the Splus Benchmark Test V. 2
 by Stephan Steinhaus ([EMAIL PROTECTED])
 Reference for Escoufier's equivalents vectors (test III.5):
 Escoufier Y., 1970. Echantillonnage dans une population de variables
 aleatoires réelles. Publ. Inst. Statis. Univ. Paris 19 Fasc 4, 1-47.

 source(this file) to start the test
 -
 TODO: Rewrite all this to work nicely with 'R CMD BATCH'

runs - 3   # Number of times the tests are executed
times - rep(0, 15); dim(times) - c(5,3)
require(Matrix) # Optimized matrix operations
require(SuppDists)  # Optimized random number generators
Runif - rMWC1019   # The fast uniform number generator
## If you don't have SuppDists, you can use: Runif - runif
a - rMWC1019(10, new.start=TRUE, seed=492166)  # Init. the generator
Rnorm - rziggurat  # The fast normal number generator
## If you don't have SuppDists, you can use: Rnorm - rnorm
b - rziggurat(10, new.start=TRUE)  # Init. the generator
remove(a, b)
options(object.size=1)
maybeFlush - function()
if(R.Version()$os %in% c(Win32, mingw32)) flush.console()

MatrixRnorm - function(n, m=n) Matrix(Rnorm(n * m), nrow = n, ncol = m)

cat(\n\n   R Benchmark, benchVersion,
  \n   ===\n,
\nNumber of times each test is run__: , runs,
\n\n)


cat(   I. Matrix calculation\n)
cat(   -\n)
maybeFlush()

## (1)
cumulate - 0; a - 0; b - 0
for (i in 1:runs) {
  timing - system.time({
a - matrix(Rnorm(1500*1500)/10, ncol=1500, nrow=1500)
b - t(a)
dim(b) - c(750, 3000)
a - t(b)
  })[3]
  cumulate - cumulate + timing
}
timing - cumulate/runs
times[1, 1] - timing
cat(Creation, transp., deformation of a 1500x1500 matrix (sec): , timing, 
\n)
remove(a, b)
maybeFlush()

## (2)
cumulate - 0; b - 0
for (i in 1:runs) {
  a - abs(matrix(Rnorm(800*800)/2, ncol=800, nrow=800))
  timing - system.time({
b - a^1000
  })[3]
  cumulate - cumulate + timing
}
timing - cumulate/runs
times[2, 1] - timing
cat(800x800 normal distributed random matrix ^1000__ (sec): , timing, 
\n)
remove(a, b)
maybeFlush()

## (3)
cumulate - 0; b - 0
for (i in 1:runs) {
  a - Rnorm(200)
  timing - system.time({
b - sort(a, method=quick)# Sort is modified in v. 1.5.x
## And there is now a quick method that better competes with other 
packages!!!
  })[3]
  cumulate - cumulate + timing
}
timing - cumulate/runs
times[3, 1] - timing
cat(Sorting of 2,000,000 random values__ (sec): , timing, 
\n)
remove(a, b)
maybeFlush()

## (4)
cumulate - 0; b - 0
for (i in 1:runs) {
  a - Rnorm(700*700); dim(a) - c(700, 700)
  timing - system.time({
b - crossprod(a)   # equivalent to: b - t(a) %*% a
  })[3]
  cumulate - cumulate + timing
}
timing - cumulate/runs
times[4, 1] - timing
cat(700x700 cross-product matrix (b = a' * a)___ (sec): , timing, 
\n)
remove(a, b)
maybeFlush()

## (5)
cumulate - 0; c - 0; qra -0
for (i in 1:runs) {
  a - MatrixRnorm(600)
  b - as.double(1:600)
  timing - system.time({
c - solve(crossprod(a), crossprod(a,b))
  })[3]
  cumulate - cumulate + timing

  ## This is the old method
  ##a - Rnorm(600*600); 

[R] Odp: Help with factors

2008-05-14 Thread Petr PIKAL
Hi

I am not sure what you want to do as you speak about using different 
function for different part of your data.


 head(data)
  city year sex   V
11 1975   F 25.3044
21 1975   M 16.5711
31 1976   M 16.6072
41 1976   F 24.2841
51 1977   M 14.8838
61 1977   F 24.8124

If it was only correlation coefficients you could use lapply split 
construction like

lapply(split(data[,c(4,2)], interaction(data$city, data$sex)), function(x) 
summary(lm(x))$r.sq)

$`1.M`
[1] 0.923669

$`2.M`
[1] 0.5151131

$`1.F`
[1] 0.823817

$`2.F`
[1] 0.7483883

or

 lapply(split(data[,c(4,2)], interaction(data$city, data$sex)), cor)
$`1.M`
 V  year
V 1.00 -0.961077
year -0.961077  1.00

$`2.M`
  V   year
V 1.000 -0.7177138
year -0.7177138  1.000

Regards

Petr Pikal
[EMAIL PROTECTED]
724008364, 581252140, 581252257


[EMAIL PROTECTED] napsal dne 14.05.2008 11:46:02:

 Hallo All,
 
 I have difficulties understanding how factors work in R. Suppose a have 
 data in the panel form below. I would to compute a correlation 
coefficient 
 (actually apply a different function of two time series) in the V 
variable 
 between members of the two sexes in each city over time. How can this be 

 done?
 
 Thank you in advance,
 Serguei
 
 city, year, sex, V
 1, 1975, 1, 25.3044
 1, 1975, 0, 16.5711
 1, 1976, 0, 16.6072
 1, 1976, 1, 24.2841
 1, 1977, 0, 14.8838
 1, 1977, 1, 24.8124
 1, 1978, 1, 23.0570
 1, 1978, 0, 14.5627
 1, 1979, 1, 21.2071
 1, 1979, 0, 13.5277
 2, 1975, 1, 62.4457
 2, 1975, 0, 26.9745
 2, 1976, 1, 67.3025
 2, 1976, 0, 31.4600
 2, 1977, 1, 53.0577
 2, 1977, 0, 25.1941
 2, 1978, 0, 23.3694
 2, 1978, 1, 40.1452
 2, 1979, 1, 44.5686
 2, 1979, 0, 23.4042
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] lattice: left-aligned text in strips?

2008-05-14 Thread Charilaos Skiadas

On May 14, 2008, at 3:47 AM, RINNER Heinrich wrote:


[adapted repost of question
http://tolstoy.newcastle.edu.au/R/e4/help/08/03/6260.html]

Dear R community,

by default, text in the strips of a trellis plot is centered in the
strip.
Is there a way to have the text left-aligned?

For example:

library(lattice)
test - data.frame(x=rnorm(100), y=rnorm(100), a=rep(c(A: centered
text,B: centered text),50))
xyplot(y ~ x | a, data = test)  # ok, strip text is centered
test - data.frame(x=rnorm(100), y=rnorm(100), a=rep(c(A: left- 
aligned

text,B: left-aligned text (possibly lng
string),50))
xyplot(y ~ x | a, data = test)  # how???


Here's a way to do it, shamelessly stealing the main idea from:  
http://dsarkar.fhcrc.org/lattice/book/figures.html? 
chapter=10;figure=10_24


Mainly you just have to write your own strip function.

xyplot(Petal.Length~Petal.Width|Species, iris, strip=function 
(which.given,which.panel, factor.levels,...) {
  panel.rect(0, 0, 1, 1, col = trellis.par.get(strip.background) 
$col[which.given], border = 1)
  panel.text(x = 0, y = 0.5, pos = 4, lab = factor.levels[which.panel 
[which.given]])

} )

Better yet, you should probably write a more generic strip function  
that does what you want.


I would however consider using ?abbreviate for what you want to do  
instead.



I am using R 2.6.2 on Windows XP, package lattice Version 0.17-6.

[The reason I would like to do this is because in real life my
conditioning variable 'a' can have quite long strings as its value.  
I am

automatically creating a series of trellis plots, and in each one a
different number of panels will be produced (maybe 4, maybe  
20,...). So

in some cases (few panels, short labels) text in the strips will be
perfectly readable, while in some cases (many panels, long labels)  
only

the middle of the text will.
I know I could abbreviate the strip text by using something like:
xyplot(y ~ x | substr(a,1,35), data = test)
But there is no natural choice of string length here when I want to
cut off as few text as possible, so just left aligning the strip texts
would seem like a natural and easy(?) solution to me - if I was  
able to

do it...]

-Heinrich.


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Thanks! to my Very Simple Question

2008-05-14 Thread Yukihiro Ishii
Dear R Users!

Thanks very much!
I really don't know why the scale function didn't come to my mind when
writing my silly question.
But anyway thanks to all of you.

Yukihiro Ishii
2-3-28 Tsurumakiminami, Hadano, 250-0002 Japan
+81463691922

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


Re: [R] plotting different level of classficifaction

2008-05-14 Thread Jim Lemon

jiho.han wrote:

hello, useRs~
suppose i have a matrix as follows:
itemcategory  sub-category
  A   1  11
  B   1  12
  C   1  12
  D   2  21
  E   2  22

i like to draw a plot that represent the proportion of each 
category at each level. that is, i want a plot like this:
+-+   +-+  
||   |   11 |

||   +-+
|   1   |   |   12  |
||   ||
+-+   +-+
+-+   +-+
||   |   21 |
|   2   |   +-+
||   |   22 |
+-+   +-+
  category   sub-cateory

hope my plot makes sense. anyone know how to make such plot?
any hint/suggestion would be much appreciate. thank you.


Hi jiho,
An interesting request. Here is a very basic function that does what you 
want (I think) with a slightly expanded dataset to show its generality.


item cat subcat subsubcat
A 1 11 111
B 1 12 121
C 1 12 122
D 2 21 211
E 2 22 221
F 3 31 311
G 3 31 312
H 3 32 322
I 3 32 322
J 3 33 331
K 3 34 341
L 3 34 341
M 3 34 342

bh-read.table(bh.dat,header=TRUE)

barhier-function(x) {
 dimx-dim(x)
 plot(0,xlim=c(0,dimx[2]),ylim=c(0,dimx[1]),axes=FALSE,type=n,
  xlab=,ylab=)
 for(level in 1:dimx[2]) {
  top-dimx[1]
  levelfreq-freq(x[,level])
  valuenames-names(levelfreq[[1]])
  for(value in 1:length(levelfreq[[1]])) {
   bottom-top-levelfreq[[1]][value]
   rect(level-1,bottom,level,top)
   text(level-0.5,(bottom+top)/2,valuenames[value])
   top-bottom
  }
 }
}

barhier(bh[,-1])

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] Negative Binomial Model

2008-05-14 Thread Mike Ryckman
Hello,

Thank you for your replies. I think that information largely focuses on
robust
standard errors... maybe I wasn't clear. By default Stata parameterizes the
dispersion. From the stata help files it is calculated as 1 + alpha*exp(xb +
offset).

As I understand it, this process should happen outside of a decision to use
robust errors. I think the normal glm.nb function in MASS uses some kind of
constant in estimating the error process in a manner more analogous to how
they
would be estimated in any normal glm model.

I think the problem is that stata is using a different method to calculate
the
standard errors - and I'm not sure what that method is or how to do it in R.
The gamlss package produces the closest results - but even those are still
not
exactly the same.

Mike

-Original Message-
From: Ted Harding [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, May 14, 2008 2:38 AM
To: r-help@r-project.org
Cc: Mike Ryckman
Subject: Re: [R] Negative Binomial Model

On 14-May-08 09:11:31, Achim Zeileis wrote:
 On Wed, 14 May 2008, Mike Ryckman wrote:
 
 Hello,

 I am trying to run a negative binomial regression model in R and
 can't get the standard errors to match the output I get from the
 Stata nbreg command. I've tried a few different options but
 haven't had much luck. The closest I've found is:

 gamlss(formula, family = NBI, sigma.formula = ~ 1,data=dataframe)

 ...But this is still a little off most of the time and pretty far off
 at
 other
 times (compared with the Stata output). The glm.nb from the MASS
 package
 produces the correct coefficients, but different (usually very
 different)
 standard errors.

 Could anybody explain this and point me in the right direction? I'd
 really
 appreciate it.
 
 Well, you don't really give us enough information to know (a
 reproducible 
 R example and the desired standard errors from Stata would have been 
 helpful). My guess is that Stata uses some sort of robust standard 
 errors, i.e., sandwich standard errors. Try something like:
library(MASS)
library(sandwich)
library(lmtest)
fm - glm.nb(...)
coeftest(fm, vcov = sandwich)
 
 See also the following thread for some more discussion for count data 
 regression in R and Stata:
https://stat.ethz.ch/pipermail/r-help/2008-May/161640.html

Better links for following this thread are:

Start:
  https://stat.ethz.ch/pipermail/r-help/2008-May/161591.html

Then click on Next message: for the second. Unfortunately,
at that point the thread broke (Paul next responded to the list
as a reply to an off-list message I sent him). So to continue,
next take Achim's URL above:

  https://stat.ethz.ch/pipermail/r-help/2008-May/161640.html

and thereafter continue to click on Next message: until the
thread runs out.

That was a very helpful thread, for me!
Best wishes,
Ted.


E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 094 0861
Date: 14-May-08   Time: 10:38:24
-- 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] Dividing Two Dataframes

2008-05-14 Thread Henrique Dallazuanna
Try this:

DFS - lapply(split(seq(1, 144, by = 1), rep(1:12, each = 12)),
function(x)SDF1[x,]/SDF2)

On Wed, May 14, 2008 at 5:02 AM, Bert Jacobs [EMAIL PROTECTED] wrote:

 Hi,



 I have two dataframes one with 144 rows and 160 columns (SDF1) and one
 with
 12 rows and 160 columns (SDF2).

 Now I'm trying to divide rows 1:12 with SDF2, rows 13:24 with SDF2, rows
 25:36 with SDF 2, .

 In S-Plus the following code works fine:



 DFS = SDF1[1:144,1:60] / as.vector(SDF2[1:12,1:160])



 but in R when I try to implement the formula I get  the following error:

 / only defined for equally-sized data frames



 Can someone help me out on this one. Thx in advance.

 Bert


[[alternative HTML version deleted]]

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




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

[[alternative HTML version deleted]]

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


Re: [R] plotting different level of classficifaction

2008-05-14 Thread Jim Lemon

Oops, you will need:

library(prettyR)

to run the barhier function.

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.


[R] Double y axes plot

2008-05-14 Thread Caio Azevedo
Hi all,

How could I draw a plot with two y axes? For example, if I need too plot two
curves in the same graphic, which are measured in different scales.

Thanks a lot in advance,

Caio

[[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] Negative Binomial Model

2008-05-14 Thread Achim Zeileis

On Wed, 14 May 2008, Mike Ryckman wrote:


Hello,

Thank you for your replies. I think that information largely focuses on
robust standard errors... maybe I wasn't clear.


No, you were not and, as pointed out previously (and described in the 
posting guide), a reproducible example would clearly help.


By default Stata parameterizes the dispersion. From the stata help files 
it is calculated as 1 + alpha*exp(xb + offset).


If I interpret this correctly, this is would be a vector of length n, not 
a scaler dispersion.



As I understand it, this process should happen outside of a decision to use
robust errors. I think the normal glm.nb function in MASS uses some kind of
constant in estimating the error process in a manner more analogous to how
they would be estimated in any normal glm model.


There are different parametrizations of the negative binomial model but 
afaik both have dispersion = 1 (in the GLM sense) but have a variance 
function that can account for over-dispersion (compared to the Poisson 
variance function).


However, if you want to use a different dispersion, you can plug it into 
the summary method

  summary(fm, dispersion = ...)

Z



I think the problem is that stata is using a different method to calculate
the standard errors - and I'm not sure what that method is or how to do 
it in R.

The gamlss package produces the closest results - but even those are still
not
exactly the same.

Mike

-Original Message-
From: Ted Harding [mailto:[EMAIL PROTECTED]
Sent: Wednesday, May 14, 2008 2:38 AM
To: r-help@r-project.org
Cc: Mike Ryckman
Subject: Re: [R] Negative Binomial Model

On 14-May-08 09:11:31, Achim Zeileis wrote:

On Wed, 14 May 2008, Mike Ryckman wrote:


Hello,

I am trying to run a negative binomial regression model in R and
can't get the standard errors to match the output I get from the
Stata nbreg command. I've tried a few different options but
haven't had much luck. The closest I've found is:

gamlss(formula, family = NBI, sigma.formula = ~ 1,data=dataframe)

...But this is still a little off most of the time and pretty far off
at
other
times (compared with the Stata output). The glm.nb from the MASS
package
produces the correct coefficients, but different (usually very
different)
standard errors.

Could anybody explain this and point me in the right direction? I'd
really
appreciate it.


Well, you don't really give us enough information to know (a
reproducible
R example and the desired standard errors from Stata would have been
helpful). My guess is that Stata uses some sort of robust standard
errors, i.e., sandwich standard errors. Try something like:
   library(MASS)
   library(sandwich)
   library(lmtest)
   fm - glm.nb(...)
   coeftest(fm, vcov = sandwich)

See also the following thread for some more discussion for count data
regression in R and Stata:
   https://stat.ethz.ch/pipermail/r-help/2008-May/161640.html


Better links for following this thread are:

Start:
 https://stat.ethz.ch/pipermail/r-help/2008-May/161591.html

Then click on Next message: for the second. Unfortunately,
at that point the thread broke (Paul next responded to the list
as a reply to an off-list message I sent him). So to continue,
next take Achim's URL above:

 https://stat.ethz.ch/pipermail/r-help/2008-May/161640.html

and thereafter continue to click on Next message: until the
thread runs out.

That was a very helpful thread, for me!
Best wishes,
Ted.


E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 094 0861
Date: 14-May-08   Time: 10:38:24
-- 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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Double y axes plot

2008-05-14 Thread jim holtman
plot(...)
par(new=TRUE)
plot(...,axes=FALSE)

On Wed, May 14, 2008 at 8:11 AM, Caio Azevedo [EMAIL PROTECTED] wrote:

 Hi all,

 How could I draw a plot with two y axes? For example, if I need too plot
 two
 curves in the same graphic, which are measured in different scales.

 Thanks a lot in advance,

 Caio

[[alternative HTML version deleted]]

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




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

What is the problem you are trying to solve?

[[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] Odp: R: Help with factors

2008-05-14 Thread Petr PIKAL
Hi

so basically you want to

1.  select one city
2.  compute a correlation coeficient between value V for males and 
females
3.  repeat this for each city

As I am not an expert in statistics I could be off track but maybe

cor(do.call(cbind,split(data$V, interaction(data$city, data$sex

do what you want.

check how are data organised after do.call.

AFAIK also lme models from nlme package maybe can do what you want. So it 
could be worth to check.

Regards
Petr
[EMAIL PROTECTED]
724008364, 581252140, 581252257


Serguei Kaniovski [EMAIL PROTECTED] napsal dne 14.05.2008 
14:12:27:

 Hi Petr!
 
 I think this is not quite what I was looking for but close. I wanted the 

 correlation coefficient between female and male in each city. The 
command:
 
  lapply(split(data[,c(4,2)], interaction(data$city, data$sex)), 
 function(x) 
  summary(lm(x))$r.sq)
 
 ,as I understand, produces the autocorrelations separately for females 
and 
 males.
 
 Serguei
 
 Austrian Institute of Economic Research (WIFO)
 
 P.O.Box 91  Tel.: +43-1-7982601-231
 1103 Vienna, AustriaFax: +43-1-7989386
 
 Mail: [EMAIL PROTECTED]
 http://www.wifo.ac.at/Serguei.Kaniovski
 
 Petr PIKAL [EMAIL PROTECTED] schrieb am 14.05.2008 13:23:34:
 
  Hi
  
  I am not sure what you want to do as you speak about using different 
  function for different part of your data.
  
  
   head(data)
city year sex   V
  11 1975   F 25.3044
  21 1975   M 16.5711
  31 1976   M 16.6072
  41 1976   F 24.2841
  51 1977   M 14.8838
  61 1977   F 24.8124
  
  If it was only correlation coefficients you could use lapply split 
  construction like
  
  lapply(split(data[,c(4,2)], interaction(data$city, data$sex)), 
 function(x) 
  summary(lm(x))$r.sq)
  
  $`1.M`
  [1] 0.923669
  
  $`2.M`
  [1] 0.5151131
  
  $`1.F`
  [1] 0.823817
  
  $`2.F`
  [1] 0.7483883
  
  or
  
   lapply(split(data[,c(4,2)], interaction(data$city, data$sex)), cor)
  $`1.M`
   V  year
  V 1.00 -0.961077
  year -0.961077  1.00
  
  $`2.M`
V   year
  V 1.000 -0.7177138
  year -0.7177138  1.000
  
  Regards
  
  Petr Pikal
  [EMAIL PROTECTED]
  724008364, 581252140, 581252257
  
  
  [EMAIL PROTECTED] napsal dne 14.05.2008 11:46:02:
  
   Hallo All,
   
   I have difficulties understanding how factors work in R. Suppose a 
 have 
   data in the panel form below. I would to compute a correlation 
  coefficient 
   (actually apply a different function of two time series) in the V 
  variable 
   between members of the two sexes in each city over time. How can 
this 
 be 
  
   done?
   
   Thank you in advance,
   Serguei
   
   city, year, sex, V
   1, 1975, 1, 25.3044
   1, 1975, 0, 16.5711
   1, 1976, 0, 16.6072
   1, 1976, 1, 24.2841
   1, 1977, 0, 14.8838
   1, 1977, 1, 24.8124
   1, 1978, 1, 23.0570
   1, 1978, 0, 14.5627
   1, 1979, 1, 21.2071
   1, 1979, 0, 13.5277
   2, 1975, 1, 62.4457
   2, 1975, 0, 26.9745
   2, 1976, 1, 67.3025
   2, 1976, 0, 31.4600
   2, 1977, 1, 53.0577
   2, 1977, 0, 25.1941
   2, 1978, 0, 23.3694
   2, 1978, 1, 40.1452
   2, 1979, 1, 44.5686
   2, 1979, 0, 23.4042
   
   __
   R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/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] Double y axes plot

2008-05-14 Thread Ben Bolker
Caio Azevedo cnaberdl at gmail.com writes:
 How could I draw a plot with two y axes? For example, if I need too plot two
 curves in the same graphic, which are measured in different scales.

http://wiki.r-project.org/rwiki/doku.php?id=tips:graphics-base:2yaxes

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

2008-05-14 Thread Peter Dalgaard
Gabor Grothendieck wrote:
 Is it possible to use the console from within tcltk?

   
Not on Windows RGui, not without deeper magic, anyway (your examples
work quite happily in a terminal on Linux). If you can figure out how to
wire a Tcl channel to the R console, then I suppose it could be made to
work.

What might be easier to implement (currently it does not work) would be
something like

tcl(cat, Hello, World)

It almost works:

 .Tcl(paste(.Tcl.callback(cat), foo\\n))   
foo
Tcl


..but apparently there is a discrepancy between the single-string return
value from   .Tcl.callback(cat) and what .Tcl.objv expects.   
  library(tcltk)
 tcl(puts, stdout, Hello, World)
 
 Error in structure(.External(dotTclObjv, objv, PACKAGE = tcltk),
 class = tclObj) :
   [tcl] can not find channel named stdout.
   
 .Tcl('puts stdout Hello, World')
 
 Error in structure(.External(dotTcl, ..., PACKAGE = tcltk), class
 = tclObj) :
   [tcl] can not find channel named stdout.
   
 R.version.string  # Windows Vista
 
 [1] R version 2.7.0 RC (2008-04-17 r45367)

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


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

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


[R] rlm and lmrob error messages

2008-05-14 Thread Susanne Komhard

Hello all,

I'm using R2.7.0 (on Windows 2000) and I'm trying do run a robust 
regression on following model structure:


model = Y ~ x1*x2 / (x3 + x4 + x5 +x6)

where x1 and  x2 are both factors (either 1 or 0) and x3.x6 are numeric.
The error code I get when running rlm(as.formula(model), data=daymean) is:

error in rlm.default(x, y, weights, method = method, wt.method = 
wt.method,  :

 'x' is singular: singular fits are not implemented in rlm

As singular.ok = TRUE is default with lmrob from the robustbase package, 
I tried running the model using lmrob, but I get following error message


Too many singular resamples
Aborting fast_s()

error in lmrob.S(x = x, y = y, control = control) :
 C function R_lmrob_S() exited prematurely

I don't understand what the error messages mean, especially in the case 
of lmrob and greatly appreciate any help or ideas as to what might cause 
the error. The model works fine with lm.


Kind regards,

Susanne

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] upperbound of C index Conf.int. greater than 1

2008-05-14 Thread Frank E Harrell Jr

DAVID ARTETA GARCIA wrote:



Dear Frank

Frank E Harrell Jr [EMAIL PROTECTED] wrote:



A few observations.

1. With minimal overfitting, rcorr.cens(predict(fit), Y) gives a good
standard error for Dxy = 2*(C-.5) and bootstrapping isn't very necessary

2. If you bootstrap use the nonparametric bootstrap percentile method
or  other methods that constrain the confidence interval to be in [0,1].

3. I don't know why the model would be linear on the two predictors you
are using.


Do you mean using these predictors fitted with spline functions?? I have 
read about it in your Regression Modeling Strategies but I am not very 
sure I understand the use of them. I will read through it again.


Yes, or other types of splines.  In general I don't expect things to be 
linear.  If you have enough data you can always allow for nonlinearity. 
 The book has a strategy for allocating degrees of freedom based on the 
predictive potential for each variable, and the following strategy also 
works:


f - lrm(y ~ rcs(x1,5) + rcs(x2,5))
plot(anova(f))

That plot masks the contribution of nonlinear terms so you won't be 
biased.  You can reduce d.f. or force linearity for those variables 
having lower overall partial chi-squares.  The plot shows partial Wald 
chi-square minus its degrees of freedom.  The plot does not bias you as 
long as you agree to devote at least one d.f. (linear fit) to each 
predictor.  If you have used y to screen predictors to narrow it down to 
x1 and x2, all bets are off.


Frank



David



Frank

--
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] Dividing Two Dataframes

2008-05-14 Thread Bert Jacobs
Hi Henrique,

 

I think I understand your formula, but your final result is a 12x160
data.frame, while it should be a 144x160 data.frame

 

divide rows 1:12 with SDF2 (=12 rows)

divide rows 13:24 with SDF2 (=12 rows)

divide rows 25:36 with SDF2 (=12 rows)

…

divide rows 133:144 with SDF2 (=12 rows)

 

Is it easy to adapt your formula to get this result?

 

Thx,

Bert

 

  _  

From: Henrique Dallazuanna [mailto:[EMAIL PROTECTED] 
Sent: 14 May 2008 13:34
To: Bert Jacobs
Cc: r-help@r-project.org
Subject: Re: [R] Dividing Two Dataframes

 

Try this:

DFS - lapply(split(seq(1, 144, by = 1), rep(1:12, each = 12)),
function(x)SDF1[x,]/SDF2)

On Wed, May 14, 2008 at 5:02 AM, Bert Jacobs [EMAIL PROTECTED] wrote:

Hi,



I have two dataframes one with 144 rows and 160 columns (SDF1) and one with
12 rows and 160 columns (SDF2).

Now I'm trying to divide rows 1:12 with SDF2, rows 13:24 with SDF2, rows
25:36 with SDF 2, .

In S-Plus the following code works fine:



DFS = SDF1[1:144,1:60] / as.vector(SDF2[1:12,1:160])



but in R when I try to implement the formula I get  the following error:

/ only defined for equally-sized data frames



Can someone help me out on this one. Thx in advance.

Bert


   [[alternative HTML version deleted]]

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




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


[[alternative HTML version deleted]]

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


Re: [R] Dividing Two Dataframes

2008-05-14 Thread Greg Snow
SDF3 - SDF1/SDF2[ rep(1:12,12), ]


-Original Message-
From: Bert Jacobs [EMAIL PROTECTED]
To: 'Henrique Dallazuanna' [EMAIL PROTECTED]
Cc: r-help@r-project.org r-help@r-project.org
Sent: 5/14/08 7:41 AM
Subject: Re: [R] Dividing Two Dataframes


Hi Henrique,



I think I understand your formula, but your final result is a 12x160
data.frame, while it should be a 144x160 data.frame



divide rows 1:12 with SDF2 (=12 rows)

divide rows 13:24 with SDF2 (=12 rows)

divide rows 25:36 with SDF2 (=12 rows)

…

divide rows 133:144 with SDF2 (=12 rows)



Is it easy to adapt your formula to get this result?



Thx,

Bert



  _

From: Henrique Dallazuanna [mailto:[EMAIL PROTECTED]
Sent: 14 May 2008 13:34
To: Bert Jacobs
Cc: r-help@r-project.org
Subject: Re: [R] Dividing Two Dataframes



Try this:

DFS - lapply(split(seq(1, 144, by = 1), rep(1:12, each = 12)),
function(x)SDF1[x,]/SDF2)

On Wed, May 14, 2008 at 5:02 AM, Bert Jacobs [EMAIL PROTECTED] wrote:

Hi,



I have two dataframes one with 144 rows and 160 columns (SDF1) and one with
12 rows and 160 columns (SDF2).

Now I'm trying to divide rows 1:12 with SDF2, rows 13:24 with SDF2, rows
25:36 with SDF 2, .

In S-Plus the following code works fine:



DFS = SDF1[1:144,1:60] / as.vector(SDF2[1:12,1:160])



but in R when I try to implement the formula I get  the following error:

/ only defined for equally-sized data frames



Can someone help me out on this one. Thx in advance.

Bert


   [[alternative HTML version deleted]]

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




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


[[alternative HTML version deleted]]

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


Re: [R] Dividing Two Dataframes

2008-05-14 Thread ONKELINX, Thierry
Dear Bert,

Another option is to replicate SDF2 so the number of rows matches with those of 
SDF1.

SDF1 - data.frame(matrix(rnorm(144 * 2), nrow = 144))
SDF2 - data.frame(matrix(rnorm(12 * 2), nrow = 12))
SDF1 / SDF2 #yields the error

SDF2a - do.call(rbind, rep(list(SDF2), nrow(SDF1) / nrow(SDF2)))
SDF1 / SDF2a #this works

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
[EMAIL PROTECTED] 
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Bert Jacobs
Verzonden: woensdag 14 mei 2008 15:43
Aan: 'Henrique Dallazuanna'
CC: r-help@r-project.org
Onderwerp: Re: [R] Dividing Two Dataframes

Hi Henrique,



I think I understand your formula, but your final result is a 12x160
data.frame, while it should be a 144x160 data.frame



divide rows 1:12 with SDF2 (=12 rows)

divide rows 13:24 with SDF2 (=12 rows)

divide rows 25:36 with SDF2 (=12 rows)

...

divide rows 133:144 with SDF2 (=12 rows)



Is it easy to adapt your formula to get this result?



Thx,

Bert



  _  

From: Henrique Dallazuanna [mailto:[EMAIL PROTECTED] 
Sent: 14 May 2008 13:34
To: Bert Jacobs
Cc: r-help@r-project.org
Subject: Re: [R] Dividing Two Dataframes



Try this:

DFS - lapply(split(seq(1, 144, by = 1), rep(1:12, each = 12)),
function(x)SDF1[x,]/SDF2)

On Wed, May 14, 2008 at 5:02 AM, Bert Jacobs [EMAIL PROTECTED] wrote:

Hi,



I have two dataframes one with 144 rows and 160 columns (SDF1) and one with
12 rows and 160 columns (SDF2).

Now I'm trying to divide rows 1:12 with SDF2, rows 13:24 with SDF2, rows
25:36 with SDF 2, .

In S-Plus the following code works fine:



DFS = SDF1[1:144,1:60] / as.vector(SDF2[1:12,1:160])



but in R when I try to implement the formula I get  the following error:

/ only defined for equally-sized data frames



Can someone help me out on this one. Thx in advance.

Bert


   [[alternative HTML version deleted]]

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




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


[[alternative HTML version deleted]]

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


[R] wavlet analysis

2008-05-14 Thread stephen sefick
http://ion.researchsystems.com/cgi-bin/ion-p
I would like a continuous wavelet transform.  I have downloaded wavethresh,
Rwave, and waveslim.  I would like an output very similar to the above
website.  any suggestions?

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

[[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] Likelihood between observed and predicted response

2008-05-14 Thread Ben Bolker
Christophe LOOTS Christophe.Loots at ifremer.fr writes:

 
 Hi,
 
 I've two fitted models, one binomial model with presence-absence data 
 that predicts probability of presence and one gaussian model (normal or 
 log-normal abundances).
 
 I would like to evaluate these models not on their capability of 
 adjustment but on their capability of prediction by calculating the 
 (log)likelihood between predicted and observed values for each type of 
 model.
 
 I found the following formula for Bernouilli model :
 
 -2 log lik = -2 sum (y*log phat + (1-y)*log(1-phat) ), with phat is 
 the probaility (between 0 and 1) and y is the observed values (0 or 1).
 
 1) Is anybody can tell me if this formula is statistically true?

  This looks correct.

 2) Can someone tell me what is the formula of the likelihood between 
 observed and predicted values for a gaussian model ?
 

   -2 L = sum( (x_i - mu_i)^2)/sigma^2  - 2*n*log(sigma) + C

assuming independence and equal variances:
but don't trust my algebra, see ?dnorm and take the log of the
likelihood shown there for yourself.
You're reinventing the wheel a bit here:

-2*sum(dbinom(y,prob=phat,size=1,log=TRUE))

and

-2*sum(dnorm(x,mean=mu,sd=sigma,log=TRUE))

will do what you want.

  Ben Bolker

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


[R] PCA in Microarrays

2008-05-14 Thread Jorge Ivan Velez
Dear useRs:
I'm not sure if it's the correct place to ask but I'll try it out. I've been
reading about how to perform Principal Component Analysis (PCA) in
microarrays (see [1]) and there's something that I don't get it. Basically
it's related with performing PCA over data sets which number of variables is
greater than the number of samples. For example in the paper mentioned
above, the number of variables (genes) and samples (tumors) is 8538 and 104,
respectively. My understanding is that, in PCA, the number of samples (n)
must be greater than the number of variables (p) and its goal is to seek k
components, such as kp and the variance in this new data set be
maximized. Am I wrong?  Could somebody please tell me how is possible to
perform PCA when the number of variables is greater than the number of
samples and how to do it in R?   I'm really confused.  In R I've tried
prcomp and princomp but they didn't work.

I'm using Win XP SP2, Intel Core- 2 Duo 2.4 GHz and R 2.7.0 Patched.


Thanks in advance,


Jorge Ivan Velez



[1] Ringnér, M.  What is principal components analysis? Nature Biotechnology
 26, 303 - 304 (2008),
http://www.nature.com/nbt/journal/v26/n3/full/nbt0308-303.html

[[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] Parallel computing with rgenoud and snow: external file I/O possible?

2008-05-14 Thread Waichler, Scott R
I am trying to use rgenoud and snow with an external model and file I/O.
Unlike the typical application of rgenoud and snow, I need to run an
external executable and do pre- and post-processing of input and output
files for each parameter set generated by genoud().  I'm hoping that
someone can suggest improvements to my approach and a work-around for
file I/O problems I've encountered when trying to do this in parallel
processing under snow.  I'm using the SOCK cluster type. 

An external executable (the model) and file input and output for that
model are used.  For this example, the model is simply R's sin()
function, packaged in such a way that it is called by a shell script.
The model reads an input file and writes an output file.  My example
involves two nodes on different machines.  Each model run launched by
genoud uses a working directory named after the node to hold the
temporary input and output files.  The function called by genoud,
drive.calib(), saves the parameter and objective function values in a
file also named after the node, and after genoud finishes, the results
from all the runs are combined in one file for convenience.  I realize
that the communications in this simple example take much longer than the
model execution.  In my real application of concern the model runtimes
will be much longer than the communication time.

To simplify the scripts further, I tried to pass the variable
working.dir as an additional argument in genoud(), but it didn't work.
I seem to have to specify all the working.dir pathnames before the
genoud() call as well as the specific one for the particular model
execution inside the function drive.calib().  Also, a relative pathname
for the working directory does not work; I found I had to use absolute
pathnames.  

If I wanted to use more than one chip on the same machine, I believe I
would have to use random numbers to create unique directory names and
prevent conflict between model executions.  However, in my
trial-and-error development, I found that genoud and/or the cluster are
very touchy about file handling, and it was necessary to create the
working directories before genoud() was called, thus effectively
preventing me from using multiple chips on the same machine.  If you
have any insights as to why or can suggest a work-around, it would be
appreciated.  

The pasted-in files below are as follows:  test_cluster.r, the main R
script; call_R.csh, a shell script that calls the model; sin.r, an R
script that is the model.  Together call_R.csh and sin.r make up the
external model.

Thanks for any help,
Scott Waichler
Pacific Northwest National Laboratory 
Richland, WA  USA
509-372-4423 (voice)
509-372-6089 (fax)
[EMAIL PROTECTED]

 test_cluster.r
---
#  test_cluster.r
#
#  R script to test the parallelization capability.
#  This uses rgenoud and external processes outside of R, and file I/O.
#  These are the key characteristics of work with stand-alone models.

library(snow)  # Simple Network of Workstations
#library(rlecuyer) # for random number generator
library(rgenoud)   # calibrator of choice

# Set the working directory--must be an absolute pathname.  Also put
this statement inside
# drive.calib(), the function that is called by genoud().  I cannot get
genoud() to pass this
# as an argument without breaking.
working.dir - /projects/dhsvm/uvm/test/rhelp/

results.file - test_results.txt  # file to save results in

# Set up the cluster
this.host - system(hostname, intern=T)
node - c(this.host, escalante)  # add additional nodes here
setDefaultClusterOptions(master=this.host, type=SOCK, homogeneous=T,
outfile=/tmp/cluster1)
cl - makeCluster(node)
#clusterSetupRNG(cl)  # init random number generator to ensure each node
has a different seed

# Define the function that will be called by genoud()
drive.calib - function(xx) {  # parameter value that is being adjusted
  
  working.dir - /projects/dhsvm/uvm/test/rhelp/ # HARDWIRED WORKING
DIRECTORY
  
  this.host - as.character(system(hostname, intern=T))
  #this.rn - sample(1:1e6, 1)  # get a random number
  #this.dir - paste(sep=, working.dir, this.host, _, this.rn)  #
hostname and random number
  this.dir -  paste(sep=, working.dir, this.host)   # hostname only
  infile -  paste(sep=/, this.dir, tmp.in)   # input to external
model
  outfile - paste(sep=/, this.dir, tmp.out) # output from external
model
  
  # file that holds input parameter values and results for all model
runs on this node
  results.file - paste(sep=, this.dir, .out) 
  
  cat(file=infile, append=F, xx) # write the input file for the model

  # run the external model
  system(paste(sep=, working.dir, call_R.csh , this.dir), intern =
F, ignore.stderr = TRUE)

  # read the result from the external model run
  score - scan(file=outfile, quiet=T)
  
  # save the parameter value and result for this model run
  cat(file=results.file, append=T, xx, score, \n)

  return(score) # 

Re: [R] console from tcltk

2008-05-14 Thread Prof Brian Ripley
I assume by 'console' you mean the Rgui window.  That is not where stdout 
is connected -- it is not a file.  As the CHANGES file for 2.7.0 says


o   When Rgui is launched from a terminal, C output from ill-formed
packages that write to stdout or stderr rather than use
Rprintf will appear in the terminal rather than being lost.
(Only on XP or later.)  This can be very handy for debugging C
code in packages: just write debugging messages to stdout.

And indeed that is what your example does.  It also writes to the terminal 
from Rterm.


Tcl is no different from any other C-based add-on in this respect.

Note though that system() does provide a way to capture stdout to the Rgui 
window, so you can probably run tcl scripts via the tcl shell and capture 
their output.


On Tue, 13 May 2008, Gabor Grothendieck wrote:


Is it possible to use the console from within tcltk?


library(tcltk)
tcl(puts, stdout, Hello, World)

Error in structure(.External(dotTclObjv, objv, PACKAGE = tcltk),
class = tclObj) :
 [tcl] can not find channel named stdout.

.Tcl('puts stdout Hello, World')

Error in structure(.External(dotTcl, ..., PACKAGE = tcltk), class
= tclObj) :
 [tcl] can not find channel named stdout.

R.version.string  # Windows Vista

[1] R version 2.7.0 RC (2008-04-17 r45367)


Oh dear, not even the released version!  Please update as the posting 
guide asked you to do before posting.



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



--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


[R] for loop, my program does not make a cycle

2008-05-14 Thread J S

Dear R community,
 
I wrote a small program using for loop but it does not make cycles. 
 
My data: Dataframes: a2, a1, b0 and b1. Vector: d
 
I would like to get b1 for each of i., i.e. totally 11. However, the program 
gives me b1 only for the last i =11.
 
d-as.vector(levels(a2$combin2))
for (i in 1:11){
a1-a2[a2$combin2%in%d[i],]
b1-b0[b0$Date%in%(a1$Date),]
}
  
Your help is appreciated. Maybe someone could also recommend me good literature 
on for loops in R?
 
Thanks,
Julia
_
Get Free (PRODUCT) RED™  Emoticons, Winks and Display Pics.

[[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] Time differences (as.difftime?) issue

2008-05-14 Thread Lukas Rode
Dear all,

I have a vector generated using the function strptime:

 my.dt
[1] 2004-04-19 08:35:00 W. Europe Daylight Time 2004-04-19 09:35:00 W.
Europe Daylight Time 2004-04-19 11:35:00 W. Europe Daylight Time
[4] 2004-04-19 13:35:00 W. Europe Daylight Time 2004-04-20 07:50:00 W.
Europe Daylight Time
 class(my.dt)
[1] POSIXt  POSIXct

Now I would like to test if the difference from the times to the first time
is lower than a given threshold:
 my.dt - my.dt[1]  threshold

The issue is, I would like to specificy the threshold as flexibly as
possible, and I tried to do this using as.difftime
 as.difftime(23, '%H')
Time difference of 23 hours

However, I cannot specify a threshold larger than 23 hours in units of
hours:
 as.difftime(24, '%H')
Time difference of NA secs

I can hack around this in the following way:
 threshold - as.difftime(23, '%H')
 threshold
Time difference of 23 hours
 threshold[[1]] - 47
 threshold
Time difference of 47 hours

In that way I can use my original statement:
  my.dt - my.dt[1]  threshold
[1] TRUE TRUE TRUE TRUE TRUE

In summary, my question is: Is there a more elegant way than my hack from
above to specify time difference thresholds of for example 47 hours, or of
246 seconds, or of 33 days and 5 hours? This could be using as.difftime or
using other means.

Thanks in advance,
  Lukas

P.S.
 sessionInfo()
R version 2.4.1 (2006-12-18)
i386-pc-mingw32

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

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

other attached packages:
   chron odfWeave  XML   gplotsgdata
gtools RColorBrewer  lattice  foreign nlme
 2.3-9  0.7.3  1.4-0  2.3.2  2.3.1
2.3.0  0.2-30.14-16 0.8-18 3.1-79

[[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] A very simple question

2008-05-14 Thread Shubha Vishwanath Karanth
Hi R,

 

Suppose

l=c(1,1,1,2,2,1,1,1)

 

k[-which(k==1)]

[1] 2 2

 

k[-which(k==2)]

[1] 1 1 1 1 1 1

 

But,

 

k[-which(k==3)]

numeric(0)

 

I do not want this numeric(0), instead the whole k itself should be my
result... How do I do this?

 

 

Thanks,

Shubha

 

This e-mail may contain confidential and/or privileged i...{{dropped:13}}

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

2008-05-14 Thread GOUACHE David
Hello all,

I was wondering if there is a package in which someone would have created a 
quantile function that handles vectors of class Date.

In advance thanks.

David Gouache
ARVALIS - Institut du végétal
Station de La Minière
78280 Guyancourt
Tel: 01.30.12.96.22 / Port: 06.86.08.94.32

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

2008-05-14 Thread Christos Hatzis
 k - c(1,1,1,2,2,1,1,1)
 k[k != 1]
[1] 2 2
 k[k != 2]
[1] 1 1 1 1 1 1
 k[k != 3]
[1] 1 1 1 2 2 1 1 1
 

-Christos 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Shubha 
 Vishwanath Karanth
 Sent: Wednesday, May 14, 2008 11:16 AM
 To: [EMAIL PROTECTED]
 Subject: [R] A very simple question
 
 Hi R,
 
  
 
 Suppose
 
 l=c(1,1,1,2,2,1,1,1)
 
  
 
 k[-which(k==1)]
 
 [1] 2 2
 
  
 
 k[-which(k==2)]
 
 [1] 1 1 1 1 1 1
 
  
 
 But,
 
  
 
 k[-which(k==3)]
 
 numeric(0)
 
  
 
 I do not want this numeric(0), instead the whole k itself 
 should be my result... How do I do this?
 
  
 
  
 
 Thanks,
 
 Shubha
 
  
 
 This e-mail may contain confidential and/or privileged 
 i...{{dropped:13}}
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] A very simple question

2008-05-14 Thread Chuck Cleland

On 5/14/2008 11:16 AM, Shubha Vishwanath Karanth wrote:

Hi R,

 


Suppose

l=c(1,1,1,2,2,1,1,1)

 


k[-which(k==1)]

[1] 2 2

 


k[-which(k==2)]

[1] 1 1 1 1 1 1

 


But,

 


k[-which(k==3)]

numeric(0)

 


I do not want this numeric(0), instead the whole k itself should be my
result... How do I do this?

 

 


Thanks,

Shubha


  Look at the result of which(k==3) to see why your approach does not 
work.  You might try this instead:


k - c(1,1,1,2,2,1,1,1)

k[!(k==1)]

[1] 2 2

k[!(k==2)]

[1] 1 1 1 1 1 1

k[!(k==3)]

[1] 1 1 1 2 2 1 1 1


This e-mail may contain confidential and/or privileged i...{{dropped:13}}

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


--
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

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

2008-05-14 Thread Ingmar Visser
l[!l==3]

On 14 May 2008, at 17:16, Shubha Vishwanath Karanth wrote:

 Hi R,



 Suppose

 l=c(1,1,1,2,2,1,1,1)



 k[-which(k==1)]

 [1] 2 2



 k[-which(k==2)]

 [1] 1 1 1 1 1 1



 But,



 k[-which(k==3)]

 numeric(0)



 I do not want this numeric(0), instead the whole k itself should be my
 result... How do I do this?





 Thanks,

 Shubha



 This e-mail may contain confidential and/or privileged i... 
 {{dropped:13}}

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

Ingmar Visser
Department of Psychology, University of Amsterdam
Roetersstraat 15
1018 WB Amsterdam
The Netherlands
t: +31-20-5256723



[[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] console from tcltk

2008-05-14 Thread Gabor Grothendieck
Thanks.  I've updated to the latest R on the mirror I used and
 puts stdout 12
from tcl does indeed produce output from Rterm on Windows but gives an
error message from Rgui on Windows (both on Windows Vista SP1).

- this works

C:\tmp2Rterm

R version 2.7.0 Patched (2008-05-11 r45672)
[...deleted...]
 library(tcltk)
Loading Tcl/Tk interface ... done
 .Tcl(puts stdout 12)
12
Tcl
 xx - .Tcl(puts stdout 12)
12

-- this gives an error message

C:\tmp2Rgui

R version 2.7.0 Patched (2008-05-11 r45672)
[...deleted...]
 library(tcltk)
Loading Tcl/Tk interface ... done
 xx - .Tcl(puts stdout 12)
Error in structure(.External(dotTcl, ..., PACKAGE = tcltk), class
= tclObj) :
  [tcl] can not find channel named stdout.


On Wed, May 14, 2008 at 11:09 AM, Prof Brian Ripley
[EMAIL PROTECTED] wrote:
 I assume by 'console' you mean the Rgui window.  That is not where stdout is
 connected -- it is not a file.  As the CHANGES file for 2.7.0 says

o   When Rgui is launched from a terminal, C output from ill-formed
packages that write to stdout or stderr rather than use
Rprintf will appear in the terminal rather than being lost.
(Only on XP or later.)  This can be very handy for debugging C
code in packages: just write debugging messages to stdout.

 And indeed that is what your example does.  It also writes to the terminal
 from Rterm.

 Tcl is no different from any other C-based add-on in this respect.

 Note though that system() does provide a way to capture stdout to the Rgui
 window, so you can probably run tcl scripts via the tcl shell and capture
 their output.

 On Tue, 13 May 2008, Gabor Grothendieck wrote:

 Is it possible to use the console from within tcltk?

 library(tcltk)
 tcl(puts, stdout, Hello, World)

 Error in structure(.External(dotTclObjv, objv, PACKAGE = tcltk),
 class = tclObj) :
  [tcl] can not find channel named stdout.

 .Tcl('puts stdout Hello, World')

 Error in structure(.External(dotTcl, ..., PACKAGE = tcltk), class
 = tclObj) :
  [tcl] can not find channel named stdout.

 R.version.string  # Windows Vista

 [1] R version 2.7.0 RC (2008-04-17 r45367)

 Oh dear, not even the released version!  Please update as the posting guide
 asked you to do before posting.

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


 --
 Brian D. Ripley,  [EMAIL PROTECTED]
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595


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


Re: [R] quantiles for dates

2008-05-14 Thread Prof Brian Ripley

On Wed, 14 May 2008, GOUACHE David wrote:


Hello all,

I was wondering if there is a package in which someone would have 
created a quantile function that handles vectors of class Date.


What is the median of today and tomorrow, expressed as a day?

Quantiles of discrete distributions are not unambiguously defined. If you 
have an answer to that, quantile(type=1) may help you, e.g.



as.Date(quantile(as.vector(x), type=1), origin=1970-01-01)

  0%  25%  50%  75% 100%
1972-07-01 1977-01-01 1983-07-01 1993-07-01 2006-01-01



In advance thanks.

David Gouache
ARVALIS - Institut du végétal
Station de La Minière
78280 Guyancourt
Tel: 01.30.12.96.22 / Port: 06.86.08.94.32


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


Re: [R] Time differences (as.difftime?) issue

2008-05-14 Thread Prof Brian Ripley

On Wed, 14 May 2008, Lukas Rode wrote:


Dear all,

I have a vector generated using the function strptime:


my.dt

[1] 2004-04-19 08:35:00 W. Europe Daylight Time 2004-04-19 09:35:00 W.
Europe Daylight Time 2004-04-19 11:35:00 W. Europe Daylight Time
[4] 2004-04-19 13:35:00 W. Europe Daylight Time 2004-04-20 07:50:00 W.
Europe Daylight Time

class(my.dt)

[1] POSIXt  POSIXct


Somehow you didn't as that is not the class of a result from strptime.


Now I would like to test if the difference from the times to the first time
is lower than a given threshold:

my.dt - my.dt[1]  threshold


The issue is, I would like to specificy the threshold as flexibly as
possible, and I tried to do this using as.difftime

as.difftime(23, '%H')

Time difference of 23 hours

However, I cannot specify a threshold larger than 23 hours in units of
hours:

as.difftime(24, '%H')

Time difference of NA secs


It's much simpler to use


as.difftime(47, units=hours)

Time difference of 47 hours



I can hack around this in the following way:

threshold - as.difftime(23, '%H')
threshold

Time difference of 23 hours

threshold[[1]] - 47
threshold

Time difference of 47 hours

In that way I can use my original statement:

 my.dt - my.dt[1]  threshold

[1] TRUE TRUE TRUE TRUE TRUE

In summary, my question is: Is there a more elegant way than my hack from
above to specify time difference thresholds of for example 47 hours, or of
246 seconds, or of 33 days and 5 hours? This could be using as.difftime or
using other means.

Thanks in advance,
 Lukas

P.S.

sessionInfo()

R version 2.4.1 (2006-12-18)
i386-pc-mingw32

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

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

other attached packages:
  chron odfWeave  XML   gplotsgdata
gtools RColorBrewer  lattice  foreign nlme
2.3-9  0.7.3  1.4-0  2.3.2  2.3.1
2.3.0  0.2-30.14-16 0.8-18 3.1-79


--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


Re: [R] PCA in Microarrays

2008-05-14 Thread Prof Brian Ripley

On Wed, 14 May 2008, Jorge Ivan Velez wrote:


Dear useRs:
I'm not sure if it's the correct place to ask but I'll try it out. I've been
reading about how to perform Principal Component Analysis (PCA) in
microarrays (see [1]) and there's something that I don't get it. Basically
it's related with performing PCA over data sets which number of variables is
greater than the number of samples. For example in the paper mentioned
above, the number of variables (genes) and samples (tumors) is 8538 and 104,
respectively. My understanding is that, in PCA, the number of samples (n)
must be greater than the number of variables (p) and its goal is to seek k
components, such as kp and the variance in this new data set be
maximized. Am I wrong?


Yes, in detail. One of the properties of PCA is to seek projections 
(unit-length linear combinations of the variables) of maximal variance, 
each being uncorrelated with earlier ones.  That is well-defined for n  
p.  But you will only get at most n PCs of non-zero variance (and at most 
n-1 unless you centre externally), and the rest are pretty arbitrary basis 
vectors for the space of constant combinations.


Could somebody please tell me how is possible to perform PCA when the 
number of variables is greater than the number of samples and how to do 
it in R?  I'm really confused.  In R I've tried prcomp and princomp 
but they didn't work.


See any good book on multivariate analysis, or your statistical 
consultant.  (See the posting guide as to why this is not the list on 
which to ask that question.)


That you can do this does not make it sensible, but it can be 
interpretable if there is a strong signal associated with a handful of 
genes -- but then so can other methods.


And BTW, prcomp() *does* work, e.g.

X - matrix(rnorm(20*200), 20)
fit - prcomp(X)
str(fit)

so the problem is what you did (and you didn't manage to tell us what that 
was -- see the footer of the message).  ?princomp does tell you to use 
prcomp() in this case.



I'm using Win XP SP2, Intel Core- 2 Duo 2.4 GHz and R 2.7.0 Patched.


Thanks in advance,


Jorge Ivan Velez



[1] Ringn?r, M.  What is principal components analysis? Nature Biotechnology
26, 303 - 304 (2008),
http://www.nature.com/nbt/journal/v26/n3/full/nbt0308-303.html


Hmm, that's not a free resource.



[[alternative HTML version deleted]]




--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


[R] Split a string of oneline into 2 lines.

2008-05-14 Thread A Ezhil
Hi,

I am trying to split a string into 2 separate strings
in 2 lines. So, tried with

sprintf(%s \n %s, ID, Name)

But R prints: [1] ID \n Name instead of 

ID
Name

Is it something I am missing here? 

Thanks in advance.

Best regards,
Ezhil

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

2008-05-14 Thread John Fox
Dear Brian and Gabor,

When the Rcmdr console.output option is set to TRUE, the Rcmdr interface
does something very much like this using cat() for R output, which it
captures. The relevant code is in the doItAndPrint() function in the Rcmdr
sources.

I hope this helps,
 John 


 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On
 Behalf Of Prof Brian Ripley
 Sent: May-14-08 11:10 AM
 To: Gabor Grothendieck
 Cc: R help forum
 Subject: Re: [R] console from tcltk
 
 I assume by 'console' you mean the Rgui window.  That is not where stdout
 is connected -- it is not a file.  As the CHANGES file for 2.7.0 says
 
  o   When Rgui is launched from a terminal, C output from ill-formed
  packages that write to stdout or stderr rather than use
  Rprintf will appear in the terminal rather than being lost.
  (Only on XP or later.)  This can be very handy for debugging C
  code in packages: just write debugging messages to stdout.
 
 And indeed that is what your example does.  It also writes to the terminal
 from Rterm.
 
 Tcl is no different from any other C-based add-on in this respect.
 
 Note though that system() does provide a way to capture stdout to the Rgui
 window, so you can probably run tcl scripts via the tcl shell and capture
 their output.
 
 On Tue, 13 May 2008, Gabor Grothendieck wrote:
 
  Is it possible to use the console from within tcltk?
 
  library(tcltk)
  tcl(puts, stdout, Hello, World)
  Error in structure(.External(dotTclObjv, objv, PACKAGE = tcltk),
  class = tclObj) :
   [tcl] can not find channel named stdout.
  .Tcl('puts stdout Hello, World')
  Error in structure(.External(dotTcl, ..., PACKAGE = tcltk), class
  = tclObj) :
   [tcl] can not find channel named stdout.
  R.version.string  # Windows Vista
  [1] R version 2.7.0 RC (2008-04-17 r45367)
 
 Oh dear, not even the released version!  Please update as the posting
 guide asked you to do before posting.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 --
 Brian D. Ripley,  [EMAIL PROTECTED]
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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

2008-05-14 Thread Roland Rau

Dear all,

I have several datasets and I want to generate pdf plots from them.
I also want to generate automatically the names of the files. They are 
country-specific and the element mycurrentdata[1,1] contains this 
information.


So what I do is something like this:
pdf(file=paste(mycurrentdata[1,1], .pdf, sep=), width=...etc)

The only problem I have is that some of the country names contain white 
space (e.g., United Kingdom). This is no problem for generating the 
pdf plots but it may become problematic during further processing (e.g. 
incl. the plots in LaTeX documents).


Is there an easy function to strip white space out of character strings 
(similar to the strip.white=TRUE option in read.table/scan)?


I'd appreciate any kind of help and I hope I did not miss anything 
completely obvious.


Thanks,
Roland

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Split a string of oneline into 2 lines.

2008-05-14 Thread Uwe Ligges



A Ezhil wrote:

Hi,

I am trying to split a string into 2 separate strings
in 2 lines. So, tried with

sprintf(%s \n %s, ID, Name)

But R prints: [1] ID \n Name instead of 
ID

Name


Is it something I am missing here? 



Yes, in order to respect teh control character you have to cat() it as in:

cat(sprintf(%s \n %s, ID, Name))

Uwe Ligges



Thanks in advance.

Best regards,
Ezhil

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

2008-05-14 Thread pecardoso
Maybe another basic question but...
 
Is is possible to accomodate more than a single (independent, not resulting 
from arranjment of layout=c()) lattice graph in a single win.graph() device?
Thanks in advance,
 
PS Maybe duplicated
 
Paulo



De: [EMAIL PROTECTED] em nome de Roland Rau
Enviada: qua 14-05-2008 17:06
Para: '[EMAIL PROTECTED]'
Assunto: [R] strip white in character strings



Dear all,

I have several datasets and I want to generate pdf plots from them.
I also want to generate automatically the names of the files. They are
country-specific and the element mycurrentdata[1,1] contains this
information.

So what I do is something like this:
pdf(file=paste(mycurrentdata[1,1], .pdf, sep=), width=...etc)

The only problem I have is that some of the country names contain white
space (e.g., United Kingdom). This is no problem for generating the
pdf plots but it may become problematic during further processing (e.g.
incl. the plots in LaTeX documents).

Is there an easy function to strip white space out of character strings
(similar to the strip.white=TRUE option in read.table/scan)?

I'd appreciate any kind of help and I hope I did not miss anything
completely obvious.

Thanks,
Roland

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



[[alternative HTML version deleted]]

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


[R] Help to Draw Plot

2008-05-14 Thread ermimi

Hello friends!!

I have two questions, and I would like that you could answer me!!!

I have created a plot as   

plot(range(10,-10),range(10,-10),col=blue,col.axis=blue,col.lab=blue,col.main=blue,col.sub=blue);


1º) I want that the square of plot and the lines that indicates the value
-10,-5,0,5,10 have a blue colour too.

2º)It´s different to the question one. I want that the plot start and finish
in the two points that are drawn, is say... I want that the plot start in
(-10,-10) (corner left down) and finish in (10,10) (corner right up)... Now
the plot start in -11,-11 and finish in 11,11 more or less...

Sorry if I don´t write very well, but I´m spanish student.

I hope that you could help me.

Thank you very much, I greetings, Luismi
-- 
View this message in context: 
http://www.nabble.com/Help-to-Draw-Plot-tp17234957p17234957.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] Calling C code from R...wrapping C structures

2008-05-14 Thread Nathan Harmston
Hi,

My function test is properly declared in the header file of the code:

void test(Model *);

and we just discovered yesterday we should be using .Call instead ,of .C.
However we still can't get it to work. We arent trying to pass a primitive
type from R but a complex one. We are trying to interface R with a C shared
library, which is already written. Can structs be defined in R and passed to
C and returned (by reference obviously). We don't really want to pass a list
rather a struct, so would a frame be a better idea?

This seems like it should be possible in R...(sorry I dont have much
experience in linking C and R together)

Nathan

2008/5/14 Ramon Diaz-Uriarte [EMAIL PROTECTED]:

 Dear Nathan,

 How is you C function test defined? What type of argument is it
 expecting? The mappings between R and C type of arguments you can pass
 is explained in:


 http://cran.r-project.org/doc/manuals/R-exts.html#Interface-functions-_002eC-and-_002eFortran

 which also provides some examples. If you want to pass a list, you'll
 probably have to use .Call, not .C.

 HTH,

 R.



 On Tue, May 13, 2008 at 1:51 PM, Nathan Harmston
 [EMAIL PROTECTED] wrote:
  Hi everyone,
 
   I am currently trying to call some C code from R, specifically calling
 a
   function which populates a C struct.
 
   typedef struct{
 // contents
   } Model;
 
   void test(Model *m){
 // fill the struct with crap
   }
 
   I compile the C code into a shared library, which loads into R
 properly. My
   simple test functions work (i.e adding numbers etc)
   setModel - function(){
 model-vector(list, 6)
 name(model) - c( SET THE NAMES OF THE MODEL HERE )
 model
   }
   t - setModel()
   testcode - function(setModel){
 
 
   dyn.load(Simulation.so)
 
   foo - .C(test, Model=setModel)
   foo
   }
 
   testcode(t)
 
   However I get segfaults whenever I try to access any of the variables
   contained in Model. So my question is: am I doing something wrong here?
 Is
   list the right data type to wrap a structure in? I cant see any
   documentation about wrapping structs in R.
 
   Also when I pass strings to C from R they dont seem to be passed at
 all? Is
   this a problem with R or a problem with me and if so how do I fix it?
 
 
 
   Many Thanks in advance,
 
   Nathan
 
  [[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.
 



 --
 Ramon Diaz-Uriarte
 Statistical Computing Team
 Structural Biology and Biocomputing Programme
 Spanish National Cancer Centre (CNIO)
 http://ligarto.org/rdiaz


[[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] quantiles for dates

2008-05-14 Thread Dieter Menne
GOUACHE David D.GOUACHE at arvalisinstitutduvegetal.fr writes:

 I was wondering if there is a package in which someone would have 
 created a quantile function that handles vectors of class Date.

Since dates are just decorated numbers, you can convert in both way.
Written the long way:

dt = rpois(100,100)
class(dt)=Date
dt
# [1] 1970-03-30 1970-04-18 1970-04-08 1970-04-13 


# Dates are generated now 
dq= quantile(as.integer(dt))
dq
#   0%25%50%75%   100% 
# 77.00  93.00  98.50 106.25 119.00 
class(dq)=Date
dq
# 0%  25%  50%  75% 100% 
#1970-03-19 1970-04-04 1970-04-09 1970-04-17 1970-04-30 
 
---
Dieter

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


[R] npmc and data.frame problems

2008-05-14 Thread Barbra C. Utley
Hello,

I am trying to run a nonparametric comparison of multiple datasets (A-E).  

After importing my csv file I sorted the variable value by the letter class
(representing height along a streambank).

a=Z[Letter==A]

b=Z[Letter==B]

c=Z[Letter==C]

d=Z[Letter==D]

e=Z[Letter==E]

Next I tested normality and variance assumptions and the data was not normal
and the variances were not equal. So I ran a kruskal wallis test.

kruskal.test(Z~Y) came by with p0.05 for the group means not being equal.

 

Next I loaded the npmc library

library(npmc)

 

The npmc command calls for a dataset.  I think my problem lies in the
following commands and how they interact with the npmc command.  I also
tried just one response variable and a class variable like described in the
help file but received errors. 

 

dataset-data.frame(a,b,c,d,e)

 

npmc(dataset)

Error in as.vector(x, mode) : invalid argument 'mode'

 mode(dataset)

[1] list

 

I tried running the debug function on npmc; however, I am not much of a
programmer and the code did not make much sense to me.

I would appreciate any help you can give.  The professor I normally contact
with questions is not available.  Thanks,

Barb

 

 

Barbra C. Utley

Doctoral Candidate

Biological Systems Engineering

Virginia Tech

[EMAIL PROTECTED]

540-808-8800

 


[[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] Can R handle large dataset?

2008-05-14 Thread Mingjun Huang
Hello,

   I am new to R, can anyone give me an idea of how R handle a large dataset
   (e.g. couple of Gbytes)? Thanks a lot!


   Best,
   Mingjun

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

2008-05-14 Thread Peter Scacheri
Using the heatmap.2 function, I am trying to generate a heatmap of a 
2 column x 500 row matrix of numeric values.  I would like the 1st 
column of the matrix sorted from the highest to the lowest values - 
so that the colors reflected in the first column of the heatmap (top 
to bottom) go from red to green.


After sorting the matrix (z), I tried the following command, but the 
data remains clustered.


heatmap.2((z),col=greenred(100),dendrogram=NULL,Rowv=FALSE)

I also tried the following, but the data remained clustered.

heatmap.2((z),col=greenred(100),Colv=1:ncol(z))

ANY IDEAS??
Thanks so much,
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.


Re: [R] rlm and lmrob error messages

2008-05-14 Thread Dieter Menne
Susanne Komhard susanne.komhard at ise.fraunhofer.de writes:

 I'm using R2.7.0 (on Windows 2000) and I'm trying do run a robust 
 regression on following model structure:
 
 model = Y ~ x1*x2 / (x3 + x4 + x5 +x6)
 
 where x1 and  x2 are both factors (either 1 or 0) and x3.x6 are numeric.
 The error code I get when running rlm(as.formula(model), data=daymean) is:
 
 error in rlm.default(x, y, weights, method = method, wt.method = 
 wt.method,  :
   'x' is singular: singular fits are not implemented in rlm

Please supply a complete example, there is too much guessing involved here.
Assuming you use the function in MASS (there is one in limma), it could be that
the error comes from your  around the model:


library(MASS)
summary(rlm(stack.loss ~ Water.Temp, stackloss))


Error in qr.default(x) : NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning message:
In storage.mode(x) - double : NAs introduced by coercion

summary(rlm(stack.loss ~ Water.Temp, stackloss))

Call: rlm(formula = stack.loss ~ Water.Temp, data = stackloss)
Residuals:
Min  1Q  Median  3Q Max 
-7.6816 -3.6368  0.3632  3.2736  8.7960 

Coefficients:
ValueStd. Error t value 
(Intercept) -40.8262   8.5789-4.7589
Water.Temp2.7612   0.4024 6.8619

Residual standard error: 5.392 on 19 degrees of freedom



Dieter

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


Re: [R] strip white in character strings

2008-05-14 Thread Jeremiah Rounds




 Date: Wed, 14 May 2008 12:06:39 -0400
 From: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: [R] strip white in character strings

 Dear all,

 I have several datasets and I want to generate pdf plots from them.
 I also want to generate automatically the names of the files. They are
 country-specific and the element mycurrentdata[1,1] contains this
 information.

 So what I do is something like this:
 pdf(file=paste(mycurrentdata[1,1], .pdf, sep=), width=...etc)

 The only problem I have is that some of the country names contain white
 space (e.g., United Kingdom). This is no problem for generating the
 pdf plots but it may become problematic during further processing (e.g.
 incl. the plots in LaTeX documents).

 Is there an easy function to strip white space out of character strings
 (similar to the strip.white=TRUE option in read.table/scan)?


How about 


 a =  United Kingdom  
 paste(unlist(strsplit(a,split= )), collapse=)
[1] UnitedKingdom

Note better might is using generic trimming functions after the split to catch 
any left over non-space white space stuff in each split.











 I'd appreciate any kind of help and I hope I did not miss anything
 completely obvious.

 Thanks,
 Roland

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Split a string of oneline into 2 lines.

2008-05-14 Thread A Ezhil
Thank you very much. It works !

Ezhil

--- Uwe Ligges [EMAIL PROTECTED]
wrote:

 
 
 A Ezhil wrote:
  Hi,
  
  I am trying to split a string into 2 separate
 strings
  in 2 lines. So, tried with
  
  sprintf(%s \n %s, ID, Name)
  
  But R prints: [1] ID \n Name instead of 
  ID
  Name
 
  Is it something I am missing here? 
 
 
 Yes, in order to respect teh control character you
 have to cat() it as in:
 
 cat(sprintf(%s \n %s, ID, Name))
 
 Uwe Ligges
 
 
  Thanks in advance.
  
  Best regards,
  Ezhil
  
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/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] for loop, my program does not make a cycle

2008-05-14 Thread jim holtman
You got exactly what you were asking for: the value the last time through
the loop.  If you are trying to capture all 11 values, then you might
consider a list:

d-as.vector(levels(a2$combin2))
a1 - b1 - vector('list',11)
for (i in 1:11){
a1[[i]] -a2[a2$combin2%in%d[i],]
b1[[i]]-b0[b0$Date%in%(a1[[i]]$Date),]
}

or using 'lapply'

result - lapply(1:11, function(.index){
a1 - a2[a2$combin2 %in% d[.index],]
list(a1=a1, b1=b0[b0$Date %in% a1$Date, ]
})

'result' is a list with both values in it for each iteration.

On Wed, May 14, 2008 at 11:13 AM, J S [EMAIL PROTECTED] wrote:


 Dear R community,

 I wrote a small program using for loop but it does not make cycles.

 My data: Dataframes: a2, a1, b0 and b1. Vector: d

 I would like to get b1 for each of i., i.e. totally 11. However, the
 program gives me b1 only for the last i =11.

 d-as.vector(levels(a2$combin2))
 for (i in 1:11){
 a1-a2[a2$combin2%in%d[i],]
 b1-b0[b0$Date%in%(a1$Date),]
 }

 Your help is appreciated. Maybe someone could also recommend me good
 literature on for loops in R?

 Thanks,
 Julia
 _
 Get Free (PRODUCT) RED™  Emoticons, Winks and Display Pics.

[[alternative HTML version deleted]]


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




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

What is the problem you are trying to solve?

[[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] strip white in character strings

2008-05-14 Thread Scillieri, John
 a =  United Kingdom  
 gsub(  , , a, fixed=TRUE )
[1] UnitedKingdom

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Jeremiah Rounds
Sent: Wednesday, May 14, 2008 12:48 PM
To: '[EMAIL PROTECTED]'
Subject: Re: [R] strip white in character strings





 Date: Wed, 14 May 2008 12:06:39 -0400
 From: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: [R] strip white in character strings

 Dear all,

 I have several datasets and I want to generate pdf plots from them.
 I also want to generate automatically the names of the files. They are

 country-specific and the element mycurrentdata[1,1] contains this 
 information.

 So what I do is something like this:
 pdf(file=paste(mycurrentdata[1,1], .pdf, sep=), width=...etc)

 The only problem I have is that some of the country names contain 
 white space (e.g., United Kingdom). This is no problem for 
 generating the pdf plots but it may become problematic during further
processing (e.g.
 incl. the plots in LaTeX documents).

 Is there an easy function to strip white space out of character 
 strings (similar to the strip.white=TRUE option in read.table/scan)?


How about 


 a =  United Kingdom  
 paste(unlist(strsplit(a,split= )), collapse=)
[1] UnitedKingdom

Note better might is using generic trimming functions after the split to
catch any left over non-space white space stuff in each split.











 I'd appreciate any kind of help and I hope I did not miss anything 
 completely obvious.

 Thanks,
 Roland

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
 This e-mail and any attachments are confidential, may contain legal, 
 professional or other privileged information, and are intended solely for 
 the addressee.  If you are not the intended recipient, do not use the 
 information in this e-mail in any way, delete this e-mail and notify the 
 sender. CEG-IP1

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

2008-05-14 Thread Julian Burgos

Hi Stephen,

Your link doesn't work.  In any case, check out the wavCWT function in 
the wmtsa package.


Julian

stephen sefick wrote:

http://ion.researchsystems.com/cgi-bin/ion-p
I would like a continuous wavelet transform.  I have downloaded wavethresh,
Rwave, and waveslim.  I would like an output very similar to the above
website.  any suggestions?



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Can R handle large dataset?

2008-05-14 Thread Abhijit Dasgupta
I believe this is determined by how much memory your computer has, not 
particularly by R itself.


Mingjun Huang wrote:

Hello,

   I am new to R, can anyone give me an idea of how R handle a large dataset
   (e.g. couple of Gbytes)? Thanks a lot!


   Best,
   Mingjun

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

2008-05-14 Thread jim holtman
It depends on what you mean by striping the white space.  Here is an example
of how it might be done:

 x - c(United Kingdom, Europe, United States, a
longer string)
 gsub( +, _, x)
[1] United_Kingdom  Europe  United_States   a_longer_string



On Wed, May 14, 2008 at 12:06 PM, Roland Rau [EMAIL PROTECTED]
wrote:

 Dear all,

 I have several datasets and I want to generate pdf plots from them.
 I also want to generate automatically the names of the files. They are
 country-specific and the element mycurrentdata[1,1] contains this
 information.

 So what I do is something like this:
 pdf(file=paste(mycurrentdata[1,1], .pdf, sep=), width=...etc)

 The only problem I have is that some of the country names contain white
 space (e.g., United Kingdom). This is no problem for generating the pdf
 plots but it may become problematic during further processing (e.g. incl.
 the plots in LaTeX documents).

 Is there an easy function to strip white space out of character strings
 (similar to the strip.white=TRUE option in read.table/scan)?

 I'd appreciate any kind of help and I hope I did not miss anything
 completely obvious.

 Thanks,
 Roland

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




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

What is the problem you are trying to solve?

[[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] strip white in character strings

2008-05-14 Thread Roland Rau

Dear all,

I would like to say thanks for the help of Mark Leeds (off-list), 
Jeremiah Rounds (off-list), and Jim Holtman.


I will use the solution Mark and Jim provided using the gsub function.
A bit embarrassing for me that I did not remember the function since I 
used it myself awhile ago.


I am still impressed with the R community: three good answers in less 
than one hour.
What is the average time for support staff of proprietary (statistical) 
software providers to respond to user questions (and how much does it cost)?


Thanks again,
Roland


jim holtman wrote:
It depends on what you mean by striping the white space.  Here is an 
example of how it might be done:
 
  x - c(United Kingdom, Europe, United States, a   
longer string)

  gsub( +, _, x)
[1] United_Kingdom  Europe  United_States   a_longer_string
 


On Wed, May 14, 2008 at 12:06 PM, Roland Rau [EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED] wrote:


Dear all,

I have several datasets and I want to generate pdf plots from them.
I also want to generate automatically the names of the files. They
are country-specific and the element mycurrentdata[1,1] contains
this information.

So what I do is something like this:
pdf(file=paste(mycurrentdata[1,1], .pdf, sep=), width=...etc)

The only problem I have is that some of the country names contain
white space (e.g., United Kingdom). This is no problem for
generating the pdf plots but it may become problematic during
further processing (e.g. incl. the plots in LaTeX documents).

Is there an easy function to strip white space out of character
strings (similar to the strip.white=TRUE option in read.table/scan)?

I'd appreciate any kind of help and I hope I did not miss anything
completely obvious.

Thanks,
Roland

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




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

What is the problem you are trying to solve?


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


Re: [R] A very simple question

2008-05-14 Thread Greg Snow
Use logical subscripts rather than which:

 k - c(1,1,1,2,2,1,1,1)
 k[ k != 1 ]
[1] 2 2
 k[ k != 2 ]
[1] 1 1 1 1 1 1
 k[ k != 3 ]
[1] 1 1 1 2 2 1 1 1

Hope this helps,

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



 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of Shubha
 Vishwanath Karanth
 Sent: Wednesday, May 14, 2008 9:16 AM
 To: [EMAIL PROTECTED]
 Subject: [R] A very simple question

 Hi R,



 Suppose

 l=c(1,1,1,2,2,1,1,1)



 k[-which(k==1)]

 [1] 2 2



 k[-which(k==2)]

 [1] 1 1 1 1 1 1



 But,



 k[-which(k==3)]

 numeric(0)



 I do not want this numeric(0), instead the whole k itself
 should be my result... How do I do this?





 Thanks,

 Shubha



 This e-mail may contain confidential and/or privileged
 i...{{dropped:13}}

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

2008-05-14 Thread Bert Gunter
R-Fellow Travellers:

Asked from the perspective of a software development amateur ... 

Suppose one wishes to create data structures that have both data and
metadata -- e.g. a data.frame and details about where, when, and by whom the
data were gathered (specifics not important here).

1. Is there any inherent processing advantage in R in representing this as a
list that contains both the data and metadata as components vs as a
data.frame with the metadata as attributes?

2. Is there a compelling software architecture argument to favor one vs the
other?

I suspect the answer is no in both cases, but I thought I'd ask. This seems
to be mainly relevant for S3 programming, as in S4 one might stick the info
into different slots (if one wishes to dispatch on them). 

Cheers to all,

Bert Gunter
Genentech 








[[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] Plotting Frequency Distribution in R

2008-05-14 Thread Sachin J
Thank you everyone for your help. I tried the following. Please let me know if 
I can use this method.
df1$V2-as.numeric(gsub([%],, df1[,2]))
xbin - binning(df1$V2,df1$V1,nbins=12)
barplot(xbin$sums,xbin$x,xlab=V2,border = TRUE,ylab=V1,col=red)
Thanks,
Sachin


- Original Message 
From: Jorge Ivan Velez [EMAIL PROTECTED]
To: Sachin J [EMAIL PROTECTED]
Sent: Tuesday, May 13, 2008 11:33:56 AM
Subject: Re: [R] Plotting Frequency Distribution in R


Hi Sachin,

Is this what you want?

df-V1  V2
1   1 160.54%
2   1 201.59%
3   1  18.45%
4   1 179.03%
5   1 274.37%
6   1   0.00%
7   1  24.52%
8   1  39.17%
9   3  43.72%
10  1  53.06%
11  1  64.97%
12  1  79.84%
13  1  98.08%
14  1 115.32%
15  1 127.96%
16  1 155.38%
17  1 157.25%
18  1 193.17%
19  1  51.53%
20 15  99.32%
21  1 106.86%
22  1 219.44%

mydf-read.table(textConnection(df),header=TRUE)
mydf$V2-as.numeric(gsub([%],, mydf[,2]))

x-rep(mydf$V2,mydf$V1)

# Plots
par(mfrow=c(2,2))
hist(x,prob=TRUE)
plot(density(x),type='l',col=2)
plot(ecdf(x))
plot(x,xlab=Observation)

HTH,

Jorge




On Tue, May 13, 2008 at 10:25 AM, Sachin J [EMAIL PROTECTED] wrote:

Hi,
How can plot a frequency distribution curve for the following data.
   V1  V2
1   1 160.54%
2   1 201.59%
3   1  18.45%
4   1 179.03%
5   1 274.37%
6   1   0.00%
7   1  24.52%
8   1  39.17%
9   3  43.72%
10  1  53.06%
11  1  64.97%
12  1  79.84%
13  1  98.08%
14  1 115.32%
15  1 127.96%
16  1 155.38%
17  1 157.25%
18  1 193.17%
19  1  51.53%
20 15  99.32%
21  1 106.86%
22  1 219.44%

Where V1 is count for each V2 value. for example there are 3 entries for 43.72% 
value.
Thanks in advance for the help.
Regards,
Sachin



       [[alternative HTML version deleted]]


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


  
[[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] Attributes or list programming efficiency

2008-05-14 Thread Gabor Grothendieck
The key difference is inheritance.

Objects consisting of data frames with attributes, including a class attribute
such as c(myclass, data.frame), can inherit data frame methods but a list
with a data frame component will require entirely new methods to be constructed
for everything.




On Wed, May 14, 2008 at 2:15 PM, Bert Gunter [EMAIL PROTECTED] wrote:
 R-Fellow Travellers:

 Asked from the perspective of a software development amateur ...

 Suppose one wishes to create data structures that have both data and
 metadata -- e.g. a data.frame and details about where, when, and by whom the
 data were gathered (specifics not important here).

 1. Is there any inherent processing advantage in R in representing this as a
 list that contains both the data and metadata as components vs as a
 data.frame with the metadata as attributes?

 2. Is there a compelling software architecture argument to favor one vs the
 other?

 I suspect the answer is no in both cases, but I thought I'd ask. This seems
 to be mainly relevant for S3 programming, as in S4 one might stick the info
 into different slots (if one wishes to dispatch on them).

 Cheers to all,

 Bert Gunter
 Genentech








[[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] A very simple question

2008-05-14 Thread Julian Burgos

Try this:

k=c(1,1,1,2,2,1,1,1)

 k[(k!=1)]
[1] 2 2

 k[(k!=2)]
[1] 1 1 1 1 1 1

 k[(k!=3)]
[1] 1 1 1 2 2 1 1 1

Julian


Shubha Vishwanath Karanth wrote:

Hi R,

 


Suppose

l=c(1,1,1,2,2,1,1,1)

 


k[-which(k==1)]

[1] 2 2

 


k[-which(k==2)]

[1] 1 1 1 1 1 1

 


But,

 


k[-which(k==3)]

numeric(0)

 


I do not want this numeric(0), instead the whole k itself should be my
result... How do I do this?

 

 


Thanks,

Shubha

 


This e-mail may contain confidential and/or privileged i...{{dropped:13}}

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

2008-05-14 Thread Ping Wang
Dear List Members,

I have encountered two problems when using the step function to
select models. To better illustrate the problems, an R image
(step.add1.test.RData)
which includes the objects needed to run the code (step.add1.test.R) can be
found at
www.biostat.wisc.edu/~pwang/r-help/http://www.biostat.wisc.edu/%7Epwang/r-help/

lm.data.frame have factor variables with 3 levels.

The following run shows the first problem. AICs (* and **) are different.
I noticed that the Df for rs13482096:rs13483699 is 4, while I think
Df should be 6, 2 from rs13483699 and 4 from interactions. When I ran
add1 directly, I got Df=6 and AIC 848.75.

 step2.bic.out - step(step.bic.out, scope=list(lower=scope.lower2,
upper=scope.upper2),
+   direction=both, k=log(length(step.bic.out$y)),
trace=1)
Start:  AIC=841.18
pheno.dat ~ rs13479085 + rs13480057 + rs13482096 + rs8254221

   Df DevianceAIC
+ rs13482096:rs13483699  4   216.63 840.63 (*)
none   233.82 841.18
- rs8254221  2   244.08 842.90
- rs13482096 2   245.20 844.31
..

Step:  AIC=848.75 (**)
pheno.dat ~ rs13479085 + rs13480057 + rs13482096 + rs8254221 +
   rs13482096:rs13483699

 add1(step.bic.out, scope=rs13482096:rs13483699,
k=log(length(step.bic.out$y)))
Single term additions

Model:
pheno.dat ~ rs13479085 + rs13480057 + rs13482096 + rs8254221
 Df DevianceAIC
none 233.82 841.18
rs13482096:rs13483699  6   214.28 848.75 (**)

When I used add1 to handle terms to be added together and separately,
I got different results. The example is shown below. This might explain
the discrepancy shown above.
 add1(step.bic.out, scope=int.terms[11:12], k=log(length(step.bic.out$y)))
Single term additions

Model:
pheno.dat ~ rs13479085 + rs13480057 + rs13482096 + rs8254221
 Df DevianceAIC
none 233.82 841.18
rs13479085:rs13475933  6   224.95 863.66
rs13480057:rs13475933  4   226.72 854.62 (***)
 add1(step.bic.out, scope=int.terms[11], k=log(length(step.bic.out$y)))
Single term additions

Model:
pheno.dat ~ rs13479085 + rs13480057 + rs13482096 + rs8254221
 Df DevianceAIC
none 233.82 841.18
rs13479085:rs13475933  6   224.95 863.66
 add1(step.bic.out, scope=int.terms[12], k=log(length(step.bic.out$y)))
Single term additions

Model:
pheno.dat ~ rs13479085 + rs13480057 + rs13482096 + rs8254221
 Df DevianceAIC
none 233.82 841.18
rs13480057:rs13475933  6   215.95 851.12 (***)

Another problem is that the final model seems to be the first
model that satisfies (bAIC = AIC + 1e-07) if steps haven't used up,
rather than the one before that. Please see below.

 formula(step2.bic.out)
pheno.dat ~ rs13479085 + rs13480057 + rs13482096 + rs8254221 +
   rs13482096:rs13483699

 step2.bic.out$anova
 Step Df Deviance Resid. Df Resid. Dev  AIC
1  NA   NA   298   233.8226 841.1784

Any insights would be greatly appreciated. Thanks much !

Ping Wang

-- 
Ping Wang
Graduate Student
Department of Statistics
University of Wisconsin-Madison
Medical Sciences Center (1245)
1300 University Avenue
Madison, Wisconsin 53706

http://www.biostat.wisc.edu/~pwang/

[[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] Newbie question about vector matrix multiplication

2008-05-14 Thread Dan Stanger
Hello All,

I have a covariance matrix, generated by read.table, and cov:

co-cov(read.table(c:/r.x))

 XYZ

X 0.0012517684 0.0002765438 0.0007887114

Y 0.0002765438 0.0002570286 0.0002117336

Z 0.0007887114 0.0002117336 0.0009168750

 

And a weight vector generated by 

w- read.table(c:/r.weights)

  X Y Z

1 0.5818416 0.2158531 0.2023053

 

I want to compute the product of the matrix and vectors termwise to
generate a 3x3 matrix, where m[i,j]=w[i]*co[i,j]*w[j].

0.000423773 7.47216E-08 4.41255E-08

7.47216E-08 1.96566E-11 4.29229E-11

4.41255E-08 4.29229E-11 4.11045E-11

 

Is this possible without writing explicit loops?

Thank you,

Dan Stanger

Eaton Vance Management
200 State Street
Boston, MA 02109
617 598 8261

 


[[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] Newbie question about vector matrix multiplication

2008-05-14 Thread Dan Stanger
Hello Abhijit,
When I try that, I get:
 diag(w)%*%co%*%diag(w)
Error in diag(w) %*% co : requires numeric matrix/vector arguments

Dan Stanger
Eaton Vance Management
200 State Street
Boston, MA 02109
617 598 8261

-Original Message-
From: Abhijit Dasgupta [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, May 14, 2008 3:22 PM
To: Dan Stanger
Cc: r-help@r-project.org
Subject: Re: [R] Newbie question about vector matrix multiplication

Won't diag(w)%*%co%*%diag(w) do it?

Dan Stanger wrote:
 Hello All,

 I have a covariance matrix, generated by read.table, and cov:

 co-cov(read.table(c:/r.x))

  XYZ

 X 0.0012517684 0.0002765438 0.0007887114

 Y 0.0002765438 0.0002570286 0.0002117336

 Z 0.0007887114 0.0002117336 0.0009168750

  

 And a weight vector generated by 

 w- read.table(c:/r.weights)

   X Y Z

 1 0.5818416 0.2158531 0.2023053

  

 I want to compute the product of the matrix and vectors termwise to
 generate a 3x3 matrix, where m[i,j]=w[i]*co[i,j]*w[j].

 0.000423773 7.47216E-08 4.41255E-08

 7.47216E-08 1.96566E-11 4.29229E-11

 4.41255E-08 4.29229E-11 4.11045E-11

  

 Is this possible without writing explicit loops?

 Thank you,

 Dan Stanger

 Eaton Vance Management
 200 State Street
 Boston, MA 02109
 617 598 8261

  


   [[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] Newbie question about vector matrix multiplication

2008-05-14 Thread Dimitris Rizopoulos

try this:

V - var(matrix(rnorm(100*3), 100, 3))
w - c(0.5, 0.3, 0.2)

V * (w %o% w)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

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


Quoting Dan Stanger [EMAIL PROTECTED]:


Hello All,

I have a covariance matrix, generated by read.table, and cov:

co-cov(read.table(c:/r.x))

 XYZ

X 0.0012517684 0.0002765438 0.0007887114

Y 0.0002765438 0.0002570286 0.0002117336

Z 0.0007887114 0.0002117336 0.0009168750



And a weight vector generated by

w- read.table(c:/r.weights)

  X Y Z

1 0.5818416 0.2158531 0.2023053



I want to compute the product of the matrix and vectors termwise to
generate a 3x3 matrix, where m[i,j]=w[i]*co[i,j]*w[j].

0.000423773 7.47216E-08 4.41255E-08

7.47216E-08 1.96566E-11 4.29229E-11

4.41255E-08 4.29229E-11 4.11045E-11



Is this possible without writing explicit loops?

Thank you,

Dan Stanger

Eaton Vance Management
200 State Street
Boston, MA 02109
617 598 8261




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






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

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


[R] Accessing items in a list of lists

2008-05-14 Thread nalbicelli
Using R 2.6.2, say I have the following list of lists, comb:

data1 - list(a = 1, b = 2, c = 3)
data2 - list(a = 4, b = 5, c = 6)
data3 - list(a = 3, b = 6, c = 9)
comb - list(data1 = data1, data2 = data2, data3 = data3)

So that all names for the lowest level list are common.  How can I most
efficiently access all of the sublist items a indexed by the outer
list names?  For example, I can loop through comb[[i]], unlisting as I
go, and then look up the field a, as below, but there has got to be a
cleaner way.

finaldata - double(0)
for(i in 1:length(names(comb))) {
test - unlist(comb[[i]])
finaldata - c(finaldata, test[which(names(test) == a)])
}
data.frame(names(comb), finaldata)

Gives what I want:
  names.comb. finaldata
1   data1 1
2   data2 4
3   data3 3

Any help you can give would be greatly appreciated.  Thanks.




This information is being sent at the recipient's reques...{{dropped:16}}

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

2008-05-14 Thread Henrique Dallazuanna
Try this:

do.call(rbind, lapply(comb, '[', 'a'))


On Wed, May 14, 2008 at 4:40 PM, [EMAIL PROTECTED]
wrote:

 Using R 2.6.2, say I have the following list of lists, comb:

 data1 - list(a = 1, b = 2, c = 3)
 data2 - list(a = 4, b = 5, c = 6)
 data3 - list(a = 3, b = 6, c = 9)
 comb - list(data1 = data1, data2 = data2, data3 = data3)

 So that all names for the lowest level list are common.  How can I most
 efficiently access all of the sublist items a indexed by the outer
 list names?  For example, I can loop through comb[[i]], unlisting as I
 go, and then look up the field a, as below, but there has got to be a
 cleaner way.

 finaldata - double(0)
 for(i in 1:length(names(comb))) {
test - unlist(comb[[i]])
finaldata - c(finaldata, test[which(names(test) == a)])
 }
 data.frame(names(comb), finaldata)

 Gives what I want:
  names.comb. finaldata
 1   data1 1
 2   data2 4
 3   data3 3

 Any help you can give would be greatly appreciated.  Thanks.
 



 This information is being sent at the recipient's reques...{{dropped:16}}

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

2008-05-14 Thread Dan Stanger
Hi Phil,
That solved the problem.
Thanks,
Dan Stanger
Eaton Vance Management
200 State Street
Boston, MA 02109
617 598 8261

-Original Message-
From: Phil Spector [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, May 14, 2008 3:42 PM
To: Dan Stanger
Subject: RE: [R] Newbie question about vector matrix multiplication

Dan -
Most likely it's due to the fact that you used
read.table for your weight vector, and it gave you
a one row, three column data frame (as it should).
Your weights are in the first row of that, so

ww = as.numeric(w[1,])

will extract them as a vector, and

outer(ww,ww,'*) * X

should get what you want.
- Phil



On Wed, 14 May 2008, Dan Stanger wrote:

 Hi Phil,
 outer(w,w,*)
 Error in as.vector(X) %*% t(as.vector(Y)) :
  requires numeric matrix/vector arguments

 There must be something about the object I am creating when I read my
 weight vector in, which causes it to be treated improperly.
 My file is:
 \tX\tY\tZ
 1\t0.581841567\t0.215853099\t0.202305334
 where tabs have been replaced by \t for readability.

 Dan Stanger
 Eaton Vance Management
 200 State Street
 Boston, MA 02109
 617 598 8261

 -Original Message-
 From: Phil Spector [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, May 14, 2008 3:27 PM
 To: Dan Stanger
 Subject: Re: [R] Newbie question about vector matrix multiplication

 Dan -
 One possible way to do what you describe is

 outer(w,w,*) * co

- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
[EMAIL PROTECTED]



 On Wed, 14 May 2008, Dan Stanger wrote:

 Hello All,

 I have a covariance matrix, generated by read.table, and cov:

 co-cov(read.table(c:/r.x))

 XYZ

 X 0.0012517684 0.0002765438 0.0007887114

 Y 0.0002765438 0.0002570286 0.0002117336

 Z 0.0007887114 0.0002117336 0.0009168750



 And a weight vector generated by

 w- read.table(c:/r.weights)

  X Y Z

 1 0.5818416 0.2158531 0.2023053



 I want to compute the product of the matrix and vectors termwise to
 generate a 3x3 matrix, where m[i,j]=w[i]*co[i,j]*w[j].

 0.000423773 7.47216E-08 4.41255E-08

 7.47216E-08 1.96566E-11 4.29229E-11

 4.41255E-08 4.29229E-11 4.11045E-11



 Is this possible without writing explicit loops?

 Thank you,

 Dan Stanger

 Eaton Vance Management
 200 State Street
 Boston, MA 02109
 617 598 8261




  [[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] Accessing items in a list of lists

2008-05-14 Thread Tony Plate

Try this:

 data1 - list(a = 1, b = 2, c = 3)
 data2 - list(a = 4, b = 5, c = 6)
 data3 - list(a = 3, b = 6, c = 9)
 comb - list(data1 = data1, data2 = data2, data3 = data3)
 sapply(comb, [[, a)
data1 data2 data3
1 4 3
 # Also, this can be useful:
 comb[[c(data2, b)]]
[1] 5


[EMAIL PROTECTED] wrote:

Using R 2.6.2, say I have the following list of lists, comb:

data1 - list(a = 1, b = 2, c = 3)
data2 - list(a = 4, b = 5, c = 6)
data3 - list(a = 3, b = 6, c = 9)
comb - list(data1 = data1, data2 = data2, data3 = data3)

So that all names for the lowest level list are common.  How can I most
efficiently access all of the sublist items a indexed by the outer
list names?  For example, I can loop through comb[[i]], unlisting as I
go, and then look up the field a, as below, but there has got to be a
cleaner way.

finaldata - double(0)
for(i in 1:length(names(comb))) {
test - unlist(comb[[i]])
finaldata - c(finaldata, test[which(names(test) == a)])
}
data.frame(names(comb), finaldata)

Gives what I want:
  names.comb. finaldata
1   data1 1
2   data2 4
3   data3 3

Any help you can give would be greatly appreciated.  Thanks.




This information is being sent at the recipient's reques...{{dropped:16}}

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

2008-05-14 Thread Sundar Dorai-Raj
[EMAIL PROTECTED] said the following on 5/14/2008 
12:40 PM:

Using R 2.6.2, say I have the following list of lists, comb:

data1 - list(a = 1, b = 2, c = 3)
data2 - list(a = 4, b = 5, c = 6)
data3 - list(a = 3, b = 6, c = 9)
comb - list(data1 = data1, data2 = data2, data3 = data3)

So that all names for the lowest level list are common.  How can I most
efficiently access all of the sublist items a indexed by the outer
list names?  For example, I can loop through comb[[i]], unlisting as I
go, and then look up the field a, as below, but there has got to be a
cleaner way.

finaldata - double(0)
for(i in 1:length(names(comb))) {
test - unlist(comb[[i]])
finaldata - c(finaldata, test[which(names(test) == a)])
}
data.frame(names(comb), finaldata)

Gives what I want:
  names.comb. finaldata
1   data1 1
2   data2 4
3   data3 3

Any help you can give would be greatly appreciated.  Thanks.


Try

data.frame(names.comb = names(comb),
   finaldata = sapply(comb, [[, a))

HTH,

--sundar

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


Re: [R] Accessing items in a list of lists

2008-05-14 Thread Dimitris Rizopoulos

check the following:

sapply(comb, [[, a)
# or
data.frame(
names = names(comb),
value = sapply(comb, [[, a),
row.names = seq_along(comb)
)


I hope it helps.

Best,
Dimitris


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

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


Quoting [EMAIL PROTECTED]:


Using R 2.6.2, say I have the following list of lists, comb:

data1 - list(a = 1, b = 2, c = 3)
data2 - list(a = 4, b = 5, c = 6)
data3 - list(a = 3, b = 6, c = 9)
comb - list(data1 = data1, data2 = data2, data3 = data3)

So that all names for the lowest level list are common.  How can I most
efficiently access all of the sublist items a indexed by the outer
list names?  For example, I can loop through comb[[i]], unlisting as I
go, and then look up the field a, as below, but there has got to be a
cleaner way.

finaldata - double(0)
for(i in 1:length(names(comb))) {
test - unlist(comb[[i]])
finaldata - c(finaldata, test[which(names(test) == a)])
}
data.frame(names(comb), finaldata)

Gives what I want:
  names.comb. finaldata
1   data1 1
2   data2 4
3   data3 3

Any help you can give would be greatly appreciated.  Thanks.




This information is being sent at the recipient's reques...{{dropped:16}}

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






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

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


Re: [R] Newbie question about vector matrix multiplication

2008-05-14 Thread Jeremiah Rounds




 Date: Wed, 14 May 2008 15:18:32 -0400
 From: [EMAIL PROTECTED]
 To: r-help@r-project.org
 Subject: [R] Newbie question about vector matrix multiplication

 Hello All,

 I have a covariance matrix, generated by read.table, and cov:

 co-cov(read.table(c:/r.x))

 X Y Z

 X 0.0012517684 0.0002765438 0.0007887114

 Y 0.0002765438 0.0002570286 0.0002117336

 Z 0.0007887114 0.0002117336 0.0009168750



 And a weight vector generated by

 w- read.table(c:/r.weights)

 X Y Z

 1 0.5818416 0.2158531 0.2023053



 I want to compute the product of the matrix and vectors termwise to
 generate a 3x3 matrix, where m[i,j]=w[i]*co[i,j]*w[j].

 0.000423773 7.47216E-08 4.41255E-08

 7.47216E-08 1.96566E-11 4.29229E-11

 4.41255E-08 4.29229E-11 4.11045E-11


First off your example matrix does not seem to represent the equation you wrote 
down.  For example m[1,3] should be m[1,3] = 0.5818416 * 0.0007887114* 
0.2023053  = .000928.  I apologize if that represents something incorrect on 
part.  However if I am correct then I believe what you seek is the line below:


m = w %*% t(w)*co

To get there btw picture moving the weights together then picture multiplying 
two equal sized matrixes together by each coefficient.







 Is this possible without writing explicit loops?

 Thank you,

 Dan Stanger

 Eaton Vance Management
 200 State Street
 Boston, MA 02109
 617 598 8261




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

_


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

2008-05-14 Thread Anh Tran
I'm trying to work on a large dataset and after each segment of run, I need
a command to flush the memory. I tried gc() and rm(list=ls()) but they don't
seem to help. gc() does not do anything beside showing the memory usage.

I'm using the package BSgenome from BioC.

Thanks a bunch

-- 
Regards,
Anh Tran

[[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] Can R handle large dataset?

2008-05-14 Thread Julian Burgos
Depends on the RAM in your machine.  And in your definition of 'handle'. 
 You may be able to load a very large dataset into R, but won't be able 
to use some functions that require additional memory.


A vague answer to a vague question... :)

Julian


Mingjun Huang wrote:

Hello,

   I am new to R, can anyone give me an idea of how R handle a large dataset
   (e.g. couple of Gbytes)? Thanks a lot!


   Best,
   Mingjun

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

2008-05-14 Thread Patrick Connolly
On Wed, 14-May-2008 at 09:12AM -0700, ermimi wrote:

| 
| Hello friends!!
| 
| I have two questions, and I would like that you could answer me!!!
| 
| I have created a plot as   
| 
| 
plot(range(10,-10),range(10,-10),col=blue,col.axis=blue,col.lab=blue,col.main=blue,col.sub=blue);
| 
| 
| 1º) I want that the square of plot and the lines that indicates the value
| -10,-5,0,5,10 have a blue colour too.

There would be tidier ways, but this will work:

points(range(10,-10),range(10,-10), col = blue)
box(col = blue)


| 
| 2º)It´s different to the question one. I want that the plot start and finish
| in the two points that are drawn, is say... I want that the plot start in
| (-10,-10) (corner left down) and finish in (10,10) (corner right up)... Now
| the plot start in -11,-11 and finish in 11,11 more or less...

check out abline.

HTH

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~} Great minds discuss ideas
 _( Y )_Middle minds discuss events 
(:_~*~_:)Small minds discuss people  
 (_)-(_)   . Anon
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

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

2008-05-14 Thread apjaworski
Dan,

You need to do

 diag(w) %*% as.matrix(co) %*% diag(w)

The reason is that read.table creates a data frame.  Although it looks like
a matrix it is not - actually it is a special kind of list.  The
as.matrix function will coerce it to a matrix.

By the way, this will generate m[i,j]=w[i]*co[i,j]*w[j] but

0.000423773 7.47216E-08 4.41255E-08
7.47216E-08 1.96566E-11 4.29229E-11
4.41255E-08 4.29229E-11 4.11045E-11

is something different.

Hope this helps,

Andy

__
Andy Jaworski
518-1-01
Process Laboratory
3M Corporate Research Laboratory
-
E-mail: [EMAIL PROTECTED]
Tel:  (651) 733-6092
Fax:  (651) 736-3122


   
 Dan Stanger 
 [EMAIL PROTECTED] 
 nce.com   To 
 Sent by:  [EMAIL PROTECTED] 
 [EMAIL PROTECTED]  cc 
 project.org   r-help@r-project.org
   Subject 
   Re: [R] Newbie question about   
 05/14/2008 02:28  vector matrix multiplication
 PM
   
   
   
   
   




Hello Abhijit,
When I try that, I get:
 diag(w)%*%co%*%diag(w)
Error in diag(w) %*% co : requires numeric matrix/vector arguments

Dan Stanger
Eaton Vance Management
200 State Street
Boston, MA 02109
617 598 8261

-Original Message-
From: Abhijit Dasgupta [mailto:[EMAIL PROTECTED]
Sent: Wednesday, May 14, 2008 3:22 PM
To: Dan Stanger
Cc: r-help@r-project.org
Subject: Re: [R] Newbie question about vector matrix multiplication

Won't diag(w)%*%co%*%diag(w) do it?

Dan Stanger wrote:
 Hello All,

 I have a covariance matrix, generated by read.table, and cov:

 co-cov(read.table(c:/r.x))

  XYZ

 X 0.0012517684 0.0002765438 0.0007887114

 Y 0.0002765438 0.0002570286 0.0002117336

 Z 0.0007887114 0.0002117336 0.0009168750



 And a weight vector generated by

 w- read.table(c:/r.weights)

   X Y Z

 1 0.5818416 0.2158531 0.2023053



 I want to compute the product of the matrix and vectors termwise to
 generate a 3x3 matrix, where m[i,j]=w[i]*co[i,j]*w[j].

 0.000423773 7.47216E-08 4.41255E-08

 7.47216E-08 1.96566E-11 4.29229E-11

 4.41255E-08 4.29229E-11 4.11045E-11



 Is this possible without writing explicit loops?

 Thank you,

 Dan Stanger

 Eaton Vance Management
 200 State Street
 Boston, MA 02109
 617 598 8261




[[alternative HTML version deleted]]

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


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

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


Re: [R] Cleaning up memory in R

2008-05-14 Thread Duncan Murdoch

On 5/14/2008 3:59 PM, Anh Tran wrote:

I'm trying to work on a large dataset and after each segment of run, I need
a command to flush the memory. I tried gc() and rm(list=ls()) but they don't
seem to help. gc() does not do anything beside showing the memory usage.


How do you know it does nothing?  R won't normally release memory to the 
OS, but it is still freed to be reused internally in R.


On the other hand, if you still have references to the variables, then 
gc() really will do nothing.


Duncan Murdoch


I'm using the package BSgenome from BioC.

Thanks a bunch



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

2008-05-14 Thread Blay

Try 
par(fg=blue)
plot(range(10,-10),range(10,-10),col=blue,col.axis=blue,col.lab=blue,col.main=blue,col.sub=blue)

Blay

KATH


ermimi wrote:
 
 Hello friends!!
 
 I have two questions, and I would like that you could answer me!!!
 
 I have created a plot as   
 
 plot(range(10,-10),range(10,-10),col=blue,col.axis=blue,col.lab=blue,col.main=blue,col.sub=blue);
 
 
 1º) I want that the square of plot and the lines that indicates the value
 -10,-5,0,5,10 have a blue colour too.
 
 2º)It´s different to the question one. I want that the plot start and
 finish in the two points that are drawn, is say... I want that the plot
 start in (-10,-10) (corner left down) and finish in (10,10) (corner right
 up)... Now the plot start in -11,-11 and finish in 11,11 more or less...
 
 Sorry if I don´t write very well, but I´m spanish student.
 
 I hope that you could help me.
 
 Thank you very much, I greetings, Luismi
 


-
Blay S
KATH
Kumasi, Ghana.
-- 
View this message in context: 
http://www.nabble.com/Help-to-Draw-Plot-tp17234957p17237843.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] var function

2008-05-14 Thread Applejus

Hello,

I am trying to convert this splus line of code to R : 

var(outcome[1, ], unbiased = FALSE)

It seems the var function in R doesn't have the unbiased argument. Could
someone help me figure the correct equivalent line in R? 

Thank you

-- 
View this message in context: 
http://www.nabble.com/var-function-tp17239936p17239936.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] Help to Draw Plot

2008-05-14 Thread ermimi

Patrick and Blay Thank you very much for help me, I have drawn in blue the
axis 
Blay the solution that you give me for start in (-10,-10) and finish in
(10,10) isn´t very well because I want that if my range is (-10,10) the axis
is in -10,10. I need that there isn´t space between the less range and the
axis.





Patrick Connolly-4 wrote:
 
 On Wed, 14-May-2008 at 09:12AM -0700, ermimi wrote:
 
 | 
 | Hello friends!!
 | 
 | I have two questions, and I would like that you could answer me!!!
 | 
 | I have created a plot as   
 | 
 |
 plot(range(10,-10),range(10,-10),col=blue,col.axis=blue,col.lab=blue,col.main=blue,col.sub=blue);
 | 
 | 
 | 1º) I want that the square of plot and the lines that indicates the
 value
 | -10,-5,0,5,10 have a blue colour too.
 
 There would be tidier ways, but this will work:
 
 points(range(10,-10),range(10,-10), col = blue)
 box(col = blue)
 
 
 | 
 | 2º)It´s different to the question one. I want that the plot start and
 finish
 | in the two points that are drawn, is say... I want that the plot start
 in
 | (-10,-10) (corner left down) and finish in (10,10) (corner right up)...
 Now
 | the plot start in -11,-11 and finish in 11,11 more or less...
 
 check out abline.
 
 HTH
 
 -- 
 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
___Patrick Connolly   
  {~._.~}   Great minds discuss ideas
  _( Y )_  Middle minds discuss events 
 (:_~*~_:)  Small minds discuss people  
  (_)-(_) . Anon
 
 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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/Help-to-Draw-Plot-tp17234957p17239938.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] var function

2008-05-14 Thread Erik Iverson
See the 'variance' function in ifultools package.  If you'd like the 
unbiased estimate of the variance, just use 'var' without the extra 
argument.


Best,
Erik Iverson

Applejus wrote:

Hello,

I am trying to convert this splus line of code to R : 


var(outcome[1, ], unbiased = FALSE)

It seems the var function in R doesn't have the unbiased argument. Could
someone help me figure the correct equivalent line in R? 


Thank you



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


[R] win.graph() with more than one Lattice plot

2008-05-14 Thread Paulo Cardoso
Is is possible to accomodate more than a single independent (not resulting
from arranjment of layout=c()) lattice graphs in a single win.graph()
device?
Thanks in advance,
 
PS Maybe duplicated
 
Paulo



De: [EMAIL PROTECTED] em nome de Roland Rau
Enviada: qua 14-05-2008 17:06
Para: '[EMAIL PROTECTED]'
Assunto: [R] strip white in character strings



Dear all,

I have several datasets and I want to generate pdf plots from them.
I also want to generate automatically the names of the files. They are
country-specific and the element mycurrentdata[1,1] contains this
information.

So what I do is something like this:
pdf(file=paste(mycurrentdata[1,1], .pdf, sep=), width=...etc)

The only problem I have is that some of the country names contain white
space (e.g., United Kingdom). This is no problem for generating the
pdf plots but it may become problematic during further processing (e.g.
incl. the plots in LaTeX documents).

Is there an easy function to strip white space out of character strings
(similar to the strip.white=TRUE option in read.table/scan)?

I'd appreciate any kind of help and I hope I did not miss anything
completely obvious.

Thanks,
Roland

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



[[alternative HTML version deleted]]

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

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