Re: [R] Trouble installing gsl wrapper

2010-10-30 Thread Prof Brian Ripley

On Sat, 30 Oct 2010, Gang Chen wrote:


Hi,

I'm trying to install the gsl wrapper source code
(http://cran.r-project.org/src/contrib/gsl_1.9-8.tar.gz) on a Linux
system (OpenSuse 11.1), but encountering the following problem. I've
already installed 'gsl' version 1.14
(ftp://ftp.gnu.org/gnu/gsl/gsl-1.14.tar.gz) on the system. What's
missing? Thanks a lot...


Installing the gsl library correctly?  I need to guess quite a bit 
here (and a clean install attempt would have given a few more clues).


I suspect you installed into /usr/local/lib whereas your OS probably 
uses /usr/local/lib64 (most x86_64 Linuxen do, and you seem to be 
using lib64 for R).  In that case ld.so most likely will not find the 
dynamic library in /usr/local/lib.


You can avoid such problems by installing auxiliary software such as 
gsl from RPMs -- I would be very surprised if OpenSuse did not have 
gsl and gsl-devel RPMs.  Otherwise you need to install from the 
sources by something like


make install libdir=/usr/local/lib64




R CMD INSTALL gsl


* installing to library ‘/usr/lib64/R/library’
* installing *source* package ‘gsl’ ...
checking for gsl-config... /usr/local/bin/gsl-config
checking if GSL version >= 1.12... checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
yes
configure: creating ./config.status
config.status: creating src/Makevars
** libs
make: Nothing to be done for `all'.


This was not a clean install 


installing to /usr/lib64/R/library/gsl/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices ...
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
 unable to load shared object '/usr/lib64/R/library/gsl/libs/gsl.so':
 libgsl.so.0: cannot open shared object file: No such file or directory
ERROR: loading failed
* removing ‘/usr/lib64/R/library/gsl’


sessionInfo()

R version 2.12.0 (2010-10-15)
Platform: x86_64-unknown-linux-gnu (64-bit)



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
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] Trouble installing gsl wrapper

2010-10-30 Thread Gang Chen
You nailed it, Prof. Ripley! Thanks a lot...

Gang

On Sat, Oct 30, 2010 at 2:58 PM, Prof Brian Ripley
 wrote:
> On Sat, 30 Oct 2010, Gang Chen wrote:
>
>> Hi,
>>
>> I'm trying to install the gsl wrapper source code
>> (http://cran.r-project.org/src/contrib/gsl_1.9-8.tar.gz) on a Linux
>> system (OpenSuse 11.1), but encountering the following problem. I've
>> already installed 'gsl' version 1.14
>> (ftp://ftp.gnu.org/gnu/gsl/gsl-1.14.tar.gz) on the system. What's
>> missing? Thanks a lot...
>
> Installing the gsl library correctly?  I need to guess quite a bit here (and
> a clean install attempt would have given a few more clues).
>
> I suspect you installed into /usr/local/lib whereas your OS probably uses
> /usr/local/lib64 (most x86_64 Linuxen do, and you seem to be using lib64 for
> R).  In that case ld.so most likely will not find the dynamic library in
> /usr/local/lib.
>
> You can avoid such problems by installing auxiliary software such as gsl
> from RPMs -- I would be very surprised if OpenSuse did not have gsl and
> gsl-devel RPMs.  Otherwise you need to install from the sources by something
> like
>
> make install libdir=/usr/local/lib64
>
>>
>>> R CMD INSTALL gsl
>>
>> * installing to library ‘/usr/lib64/R/library’
>> * installing *source* package ‘gsl’ ...
>> checking for gsl-config... /usr/local/bin/gsl-config
>> checking if GSL version >= 1.12... checking for gcc... gcc
>> checking for C compiler default output file name... a.out
>> checking whether the C compiler works... yes
>> checking whether we are cross compiling... no
>> checking for suffix of executables...
>> checking for suffix of object files... o
>> checking whether we are using the GNU C compiler... yes
>> checking whether gcc accepts -g... yes
>> checking for gcc option to accept ISO C89... none needed
>> yes
>> configure: creating ./config.status
>> config.status: creating src/Makevars
>> ** libs
>> make: Nothing to be done for `all'.
>
> This was not a clean install 
>
>> installing to /usr/lib64/R/library/gsl/libs
>> ** R
>> ** inst
>> ** preparing package for lazy loading
>> ** help
>> *** installing help indices
>> ** building package indices ...
>> ** testing if installed package can be loaded
>> Error in dyn.load(file, DLLpath = DLLpath, ...) :
>>  unable to load shared object '/usr/lib64/R/library/gsl/libs/gsl.so':
>>  libgsl.so.0: cannot open shared object file: No such file or directory
>> ERROR: loading failed
>> * removing ‘/usr/lib64/R/library/gsl’
>>
>>> sessionInfo()
>>
>> R version 2.12.0 (2010-10-15)
>> Platform: x86_64-unknown-linux-gnu (64-bit)
>
>
> --
> Brian D. Ripley,                  rip...@stats.ox.ac.uk
> 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, UK                Fax:  +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] how to find a function for plotting polygon surfaces: polgon3d(xc, yc, obs)

2010-10-30 Thread Wolfgang Polasek
I have  set of n coordinates xc, yc (but not a grid!) and n observations obs
 at these points.
Where to find a simple plot function (3D perspective) that plots a polygon
(alternative: just segmented points over a map, as eg in library maps).
rgl.surface(xc,yc,obs) is not working.

Thanks
W.Polasek

[[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] one function with 2 returnh points

2010-10-30 Thread Alaios
Hello everyone.
I have written quite a big function that at the end correctly returns the 
values 
I want. I found a rare exception that I want to cover also. The easier for me 
would be to write something like that


function(){

  if (rare exception happened)
  return that value

  # The comes the code for normal execution
  # ...
  # ...
  return value # Normal values to return

}



Would that be feasible with R or two returns statements are not accepted?

Regards
Alex


  
[[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] one function with 2 returnh points

2010-10-30 Thread Liviu Andronic
On Sat, Oct 30, 2010 at 11:09 AM, Alaios  wrote:
> Hello everyone.
> I have written quite a big function that at the end correctly returns the 
> values
> I want. I found a rare exception that I want to cover also. The easier for me
> would be to write something like that
>
>
> function(){
>
>  if (rare exception happened)
>      return that value
>
>  # The comes the code for normal execution
>  # ...
>  # ...
>  return value # Normal values to return
>
> }
>
Are you looking for something similar?
fun <-
function(x)
{
if(is.character(x)){
return(paste('Error: wrong!'))
}
res <- sum(1:10)
return(res)
}

> fun('asdf')
[1] "Error: wrong!"
> fun(1:10)
[1] 55



>
>
> Would that be feasible with R or two returns statements are not accepted?
>
> Regards
> Alex
>
>
>
>        [[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.
>



-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

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

2010-10-30 Thread Ajay Ohri
Hi

I would like to transform  a data frame like

SubjectItem   Score
Subject 1 Item 1 1
Subject 1 Item 2 0
Subject 1 Item 3 1
Subject 2 Item 1 1
Subject 2 Item 2 1
Subject 2 Item 3 0

*to *

Subject  Item1   Item2   Item3 .Item N
Subject1   1  0   1
Subject2   1  10

SubjectP..

Apologize for the simple nature of my query but I am stuck. How can I do
this transformation?

Regards

Ajay



Websites-
http://decisionstats.com
http://dudeofdata.com


Linkedin- www.linkedin.com/in/ajayohri




On Sat, Oct 30, 2010 at 2:39 PM, Alaios  wrote:

> Hello everyone.
> I have written quite a big function that at the end correctly returns the
> values
> I want. I found a rare exception that I want to cover also. The easier for
> me
> would be to write something like that
>
>
> function(){
>
>  if (rare exception happened)
>  return that value
>
>  # The comes the code for normal execution
>  # ...
>  # ...
>  return value # Normal values to return
>
> }
>
>
>
> Would that be feasible with R or two returns statements are not accepted?
>
> Regards
> Alex
>
>
>
>[[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] Differenciate numbers from reference for rows

2010-10-30 Thread David Winsemius


On Oct 29, 2010, at 11:16 PM, Dennis Murphy wrote:


Hi:

x <- matrix(20:35, ncol = 1)
u <- c(1, 4, 5, 6, 11)  # 'x values'
m <- c(1, 3, 1, 1, 0.5)

# Function to compute the inner product of the multipliers with the
extracted
# elements of x determined by u
f <- function(mat, inputs, mults) crossprod(mat[inputs], mults)
f(x, u, mults = c(1, 3, 1, 1, 0.5))
[,1]
[1,]  153
20 + 23 * 3 + 24 + 25 + 30 * 0.5
[1] 153

The function is flexible enough to allow you to play with the input  
matrix
(although a vector would also work), the 'observation vector' inputs  
and the
set of multipliers. Here's one way (not necessarily the most  
efficient):


uv <- matrix(sample(1:15, 25, replace = TRUE), ncol = 5)
uv   # like an X matrix, where each row provides the input values of  
the

vars
[,1] [,2] [,3] [,4] [,5]
[1,]   128   11   10   15
[2,]   15   11   14   148
[3,]484   10   12
[4,]   105217
[5,]   11491   11

# Apply the function f to each row of uv:
apply(uv, 1, function(y) f(x, y, mults = c(1, 3, 1, 1, 0.5)))
[1] 188.0 203.5 171.5 155.0 162.0

The direct matrix version:
crossprod(t(matrix(x[uv], ncol = 5)), c(1, 3, 1, 1, 0.5))
 [,1]
[1,] 188.0
[2,] 203.5
[3,] 171.5
[4,] 155.0
[5,] 162.0

Notice that the apply() call returns a vector whereas crossprod()  
returns a

matrix.
x[uv] selects the x values associated with the indices in uv and  
returns a
vector in column-major order. The crossprod() call transposes the  
reshaped
x[uv] and then 'matrix' multiplies it by the vector c(1, 3, 1, 1,  
0.5).


HTH,
Dennis

On Fri, Oct 29, 2010 at 3:54 PM, M.Ribeiro  
 wrote:




So, I am having a tricky reference file to extract information from.

The format of the file is

x   1 + 4 * 3 + 5 + 6 + 11 * 0.5


I saw the beginning of this task as parsing to extract the digits from  
a character string (possibly decimal digits in the case of the third  
and seventh positions) delimited by + and *:


library(gsubfn)
> x <-  "1 + 4 * 3 + 5 + 6 + 11 * 0.5"

 xin <- readLines(textConnection(x))
 xp <- strapply(xin, "^(\\d+) \\+ (\\d+) \\* (\\d+\\.*\\d*) \\+ (\\d 
+) \\+ (\\d+) \\+ (\\d+) \\* (\\d+\\.*\\d*)", c)

 sapply(xp, as.numeric)
 [,1]
[1,]  1.0
[2,]  4.0
[3,]  3.0
[4,]  5.0
[5,]  6.0
[6,] 11.0
[7,]  0.5

--
David



So, the elements that are not being multiplied (1, 5 and 6) and the
elements
before the multiplication sign (4 and 11) means actually the  
reference for

the row in a matrix where I need to extract the element from.

The numbers after the multiplication sign are regular numbers
Ex:


x<-matrix(20:35)
x

[,1]
[1,]   20
[2,]   21
[3,]   22
[4,]   23
[5,]   24
[6,]   25
[7,]   26
[8,]   27
[9,]   28
[10,]   29
[11,]   30
[12,]   31
[13,]   32
[14,]   33
[15,]   34
[16,]   35

I would like to read the rows 1,4,5,6 and 11 and sum then. However  
the

numbers in the elements row 4 and 11 are multiplied by 3 and 0.5

So it would be
20 + 23 * 3 + 24 + 25 + 30 * 0.5.

And I have this format in different files so I can't do all by hand.
Can anybody help me with a script that can differentiate this?
Thanks
--
View this message in context:
http://r.789695.n4.nabble.com/Differenciate-numbers-from-reference-for-rows-tp3019853p3019853.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.



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


David Winsemius, MD
West Hartford, CT

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


Re: [R] Trouble installing gsl wrapper

2010-10-30 Thread robin hankin
An interesting exchange.

The package has some installation tips in Misc.Rd, but
perhaps these are not sufficiently prominent.  I think it'd
be a good idea to include a READ.ME file in
inst/doc with installation information,
and include a pointer to this
in the DESCRIPTION file; I'll adapt parts of this thread
for the next release.

Robin




On Sat, Oct 30, 2010 at 8:14 AM, Gang Chen  wrote:
> You nailed it, Prof. Ripley! Thanks a lot...
>
> Gang
>
> On Sat, Oct 30, 2010 at 2:58 PM, Prof Brian Ripley
>  wrote:
>> On Sat, 30 Oct 2010, Gang Chen wrote:
>>
>>> Hi,
>>>
>>> I'm trying to install the gsl wrapper source code
>>> (http://cran.r-project.org/src/contrib/gsl_1.9-8.tar.gz) on a Linux
>>> system (OpenSuse 11.1), but encountering the following problem. I've
>>> already installed 'gsl' version 1.14
>>> (ftp://ftp.gnu.org/gnu/gsl/gsl-1.14.tar.gz) on the system. What's
>>> missing? Thanks a lot...
>>
>> Installing the gsl library correctly?  I need to guess quite a bit here (and
>> a clean install attempt would have given a few more clues).
>>
>> I suspect you installed into /usr/local/lib whereas your OS probably uses
>> /usr/local/lib64 (most x86_64 Linuxen do, and you seem to be using lib64 for
>> R).  In that case ld.so most likely will not find the dynamic library in
>> /usr/local/lib.
>>
>> You can avoid such problems by installing auxiliary software such as gsl
>> from RPMs -- I would be very surprised if OpenSuse did not have gsl and
>> gsl-devel RPMs.  Otherwise you need to install from the sources by something
>> like
>>
>> make install libdir=/usr/local/lib64
>>
>>>
 R CMD INSTALL gsl
>>>
>>> * installing to library ‘/usr/lib64/R/library’
>>> * installing *source* package ‘gsl’ ...
>>> checking for gsl-config... /usr/local/bin/gsl-config
>>> checking if GSL version >= 1.12... checking for gcc... gcc
>>> checking for C compiler default output file name... a.out
>>> checking whether the C compiler works... yes
>>> checking whether we are cross compiling... no
>>> checking for suffix of executables...
>>> checking for suffix of object files... o
>>> checking whether we are using the GNU C compiler... yes
>>> checking whether gcc accepts -g... yes
>>> checking for gcc option to accept ISO C89... none needed
>>> yes
>>> configure: creating ./config.status
>>> config.status: creating src/Makevars
>>> ** libs
>>> make: Nothing to be done for `all'.
>>
>> This was not a clean install 
>>
>>> installing to /usr/lib64/R/library/gsl/libs
>>> ** R
>>> ** inst
>>> ** preparing package for lazy loading
>>> ** help
>>> *** installing help indices
>>> ** building package indices ...
>>> ** testing if installed package can be loaded
>>> Error in dyn.load(file, DLLpath = DLLpath, ...) :
>>>  unable to load shared object '/usr/lib64/R/library/gsl/libs/gsl.so':
>>>  libgsl.so.0: cannot open shared object file: No such file or directory
>>> ERROR: loading failed
>>> * removing ‘/usr/lib64/R/library/gsl’
>>>
 sessionInfo()
>>>
>>> R version 2.12.0 (2010-10-15)
>>> Platform: x86_64-unknown-linux-gnu (64-bit)
>>
>>
>> --
>> Brian D. Ripley,                  rip...@stats.ox.ac.uk
>> 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, UK                Fax:  +44 1865 272595
>



-- 
Robin Hankin
Uncertainty Analyst
hankin.ro...@gmail.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] Clustering

2010-10-30 Thread dpender


David Winsemius wrote:
> 
> 
> On Oct 29, 2010, at 12:08 PM, David Winsemius wrote:
> 
>>
>> On Oct 29, 2010, at 11:37 AM, dpender wrote:
>>
>>> Apologies for being vague,
>>>
>>> The structure of the output is as follows:
>>
>> Still no code?
>>
> 
> I am using the Clusters function from the evd package
> 
>>>
>>> $ cluster1  : Named num [1:131] 3.05 2.71 3.26 2.91 2.88 3.11 3.21  
>>> -1 2.97
>>> 3.39 ...
>>> ..- attr(*, "names")= chr [1:131] "6667" "6668" "6669" "6670" ...
>>>
>>> With 613 clusters.  What I require is abstracting the first and  
>>> last value
>>> of
>>>
>>> - attr(*, "names")= chr [1:131] "6667" "6668" "6669" "6670"
>>
>> Those values are in an attribute:
> 
> Corrections:
>>
>> ? attribute
> 
> ?attributes
> 
>> ? attr
>>
>> Your specific request may (perhaps) be addressed by something like:
>>
>> attrnames <- attr(objname["cluster1"], "names")
> ^  ^   should be doubled square- 
> 
> This works to abstract the part that I am looking for but in order to loop
> this over every cluster I need an output object of the same form as
> clusters to write the names to.
> 
> brackets
>> attrnames[c(1, length(attrnames)]
>   ^  missing right-paren
> 
> Might work:
> attrnames <- attr(clusobj[["cluster1"]], "names")
> attrnames[c(1, length(attrnames))]
> --
> 
> David Winsemius, MD
> West Hartford, CT
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 


Additionally I can get the output as a matrix in form

 atomic [1:613] 3.01 4.1 3.04 3.81 3.55 3.37 3.09 4.1 3.61 6.36 ...
 - attr(*, "acs")= num 47.6

where "acs" is the average size.  Each height value in the vector has a
corresponding number relating to the location in the dataset.  When I change
the vector to matrix this looks like the row name but it isn't as
rownames(clusters) yields NULL.  

Do you have any idea how to abstract these values?

Doug
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Clustering-tp3017056p3020216.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] transforming a dataset for association analysis

2010-10-30 Thread Santosh Srinivas
A more usable problem input would definitely help ... use dput to send a
reproducible sample to the group

Think the below should solve your problem

> read.csv("Book1.csv")
Subject   Item Score
1 Subject 1 Item 1 1
2 Subject 1 Item 2 0
3 Subject 1 Item 3 1
4 Subject 2 Item 1 1
5 Subject 2 Item 2 1
6 Subject 2 Item 3 0

> library("reshape2")
> tDat.m <- melt(tDat)

> tDatCast <- acast(tDat.m,Subject~Item)
> tDatCast
  Item 1 Item 2 Item 3
Subject 1  1  0  1
Subject 2  1  1  0


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Ajay Ohri
Sent: 30 October 2010 16:27
To: Rhelp
Subject: [R] transforming a dataset for association analysis

Hi

I would like to transform  a data frame like

SubjectItem   Score
Subject 1 Item 1 1
Subject 1 Item 2 0
Subject 1 Item 3 1
Subject 2 Item 1 1
Subject 2 Item 2 1
Subject 2 Item 3 0

*to *

Subject  Item1   Item2   Item3 .Item N
Subject1   1  0   1
Subject2   1  10

SubjectP..

Apologize for the simple nature of my query but I am stuck. How can I do
this transformation?

Regards

Ajay



Websites-
http://decisionstats.com
http://dudeofdata.com


Linkedin- www.linkedin.com/in/ajayohri




On Sat, Oct 30, 2010 at 2:39 PM, Alaios  wrote:

> Hello everyone.
> I have written quite a big function that at the end correctly returns the
> values
> I want. I found a rare exception that I want to cover also. The easier for
> me
> would be to write something like that
>
>
> function(){
>
>  if (rare exception happened)
>  return that value
>
>  # The comes the code for normal execution
>  # ...
>  # ...
>  return value # Normal values to return
>
> }
>
>
>
> Would that be feasible with R or two returns statements are not accepted?
>
> Regards
> Alex
>
>
>
>[[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.

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

2010-10-30 Thread Rainer Hurling

On 30.10.2010 13:50 (UTC+1), Santosh Srinivas wrote:

A more usable problem input would definitely help ... use dput to send a
reproducible sample to the group

Think the below should solve your problem


read.csv("Book1.csv")

 Subject   Item Score
1 Subject 1 Item 1 1
2 Subject 1 Item 2 0
3 Subject 1 Item 3 1
4 Subject 2 Item 1 1
5 Subject 2 Item 2 1
6 Subject 2 Item 3 0


library("reshape2")
tDat.m<- melt(tDat)



tDatCast<- acast(tDat.m,Subject~Item)
tDatCast

   Item 1 Item 2 Item 3
Subject 1  1  0  1
Subject 2  1  1  0



# Or without using package reshape2, only function reshape from stats:

df <- data.frame(Subject=
   c("Subject 1","Subject 1","Subject 1","Subject 1",
 "Subject 2","Subject 2","Subject 2","Subject 2"),
 Item   =
   c("Item 1","Item 2","Item 3","Item 4",
 "Item 1","Item 2","Item 3","Item 4"),
 Score  = c(1,0,1,1,1,1,0,0))

df.wide <- reshape(df, idvar="Subject", timevar="Item", direction="wide")
names(df.wide) <- c("Subject",unique(as.character(df$Item)))

df.wide
Subject Item 1 Item 2 Item 3 Item 4
1 Subject 1  1  0  1  1
5 Subject 2  1  1  0  0



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Ajay Ohri
Sent: 30 October 2010 16:27
To: Rhelp
Subject: [R] transforming a dataset for association analysis

Hi

I would like to transform  a data frame like

SubjectItem   Score
Subject 1 Item 1 1
Subject 1 Item 2 0
Subject 1 Item 3 1
Subject 2 Item 1 1
Subject 2 Item 2 1
Subject 2 Item 3 0

*to *

Subject  Item1   Item2   Item3 .Item N
Subject1   1  0   1
Subject2   1  10

SubjectP..

Apologize for the simple nature of my query but I am stuck. How can I do
this transformation?

Regards

Ajay



Websites-
http://decisionstats.com
http://dudeofdata.com


Linkedin- www.linkedin.com/in/ajayohri




On Sat, Oct 30, 2010 at 2:39 PM, Alaios  wrote:


Hello everyone.
I have written quite a big function that at the end correctly returns the
values
I want. I found a rare exception that I want to cover also. The easier for
me
would be to write something like that


function(){

  if (rare exception happened)
  return that value

  # The comes the code for normal execution
  # ...
  # ...
  return value # Normal values to return

}


Would that be feasible with R or two returns statements are not accepted?

Regards
Alex


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

2010-10-30 Thread news
David Winsemius  writes:

Aha.. thankyou, I was not aware of that.

> Now you have changed plotting functions from plot and barplot over to
> barchart (a Lattice function) and were not aware of FAQ 7.22:
>
> http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f
>
> --
> David.
>>
>>
>> Tal Galili  writes:
>>
>>> Could you please paste the exact code you are using? (the one with
>>> the pdf and
>>> dev.off, outside the loop )
>>>
>>> Contact
>>>
>>> On Sat, Oct 23, 2010 at 4:53 PM,  wrote:
>>>
>>>David Winsemius  writes:
>>>
 On Oct 22, 2010, at 12:50 PM,  wrote:

> Tal Galili  writes:
>
>> I suspect that using "dev.copy2eps" Is not going to help you here.
>>
>> Please try again using:
>>
>>  pdf(...)  # Check: ?pdf
>>  for(i in something)
>>  {
>> plot(things)
>>  }
>>  dev.off()
>>
>> But give pdf() the file path.
>> Make sure you can make it work with simple plots.  then check it
>> on
>> your
>> situation, and let us know if it works :)
>> (I had it work with very heavy plots - so I trust it will work for
>> you)
>>
>> (p.s: please keep cc'ing the r-help list so others will know the
>> stage of your
>> problem, in case others would like to add more help :) )
>>
>> Cheers,
>> Tal
>>
>
> The problem is that the filename changes with each iteration of the
> loop, so I need to
> save the graph inside the loop.
> I tried this:
>
> for(...)
> {
>...
>pdf(...)
>barplot(...)
> }
>
> but I just got a load of empty graphs.

 Because you failed to follow Ted directions to use dev.off()

 pdf() just opens the file for writing, dev.off() executes the
 writing
 and closes properly.

 --
 David.
>>>I just tried with dev.off() but still the same problem.
>>>I tried with pdf() and dev.off() inside the loop, and with them
>>> outside
>>>(pdf before the loop,
>>>and dev.off after). Same results each time: an empty pdf file.
>>>I am using R version 2.11.1 if this makes any difference.
>>>--
>>>aleblanc
> David Winsemius, MD
> West Hartford, CT
-- 
aleblanc

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

2010-10-30 Thread David Winsemius


On Oct 30, 2010, at 7:49 AM, dpender wrote:


David Winsemius wrote:


On Oct 29, 2010, at 12:08 PM, David Winsemius wrote:



On Oct 29, 2010, at 11:37 AM, dpender wrote:


Apologies for being vague,

The structure of the output is as follows:


Still no code?




I am using the Clusters function from the evd package




$ cluster1  : Named num [1:131] 3.05 2.71 3.26 2.91 2.88 3.11  
3.21  -1 2.97 3.39 ...

..- attr(*, "names")= chr [1:131] "6667" "6668" "6669" "6670" ...

With 613 clusters.  What I require is abstracting the first and  
last value of


- attr(*, "names")= chr [1:131] "6667" "6668" "6669" "6670"


Those values are in an attribute:


Corrections:


? attribute

?attributes

? attr
Your specific request may (perhaps) be addressed by something like:
attrnames <- attr(objname["cluster1"], "names")

   ^  ^   should be doubled square-


This works to abstract the part that I am looking for but in order  
to loop

this over every cluster I need an output object of the same form as
clusters to write the names to.


THat is rather difficult to implement since the phrase "same form as  
the clusters" is still undetermined in the absence of full output from  
str() or an actual data object. The help page for the clusters  
function (not Clusters, BTW) could be used for a concrete example:


require(evd)
data(portpirie)
clusobj <- clusters(portpirie, 4.2, 3)
lapply(clusobj, attr, "names")
nclusters <- length(clusobj)
# This gives the locations (in the names) and values at the beginning  
and end of the 6 clusters


> lapply(clusobj, function(x) c(head(x,1), tail(x,1)))
$cluster1
   9   12
4.36 4.69

$cluster2
  20   26
4.25 4.37

$cluster3
  31   31
4.55 4.55

$cluster4
  38   43
4.21 4.21

$cluster5
  58   59
4.33 4.55

$cluster6
  65   65
4.33 4.33

# If you used sapply you could get the values as a matrix:

> sapply(clusobj, function(x) c(head(x,1), tail(x,1)))
   cluster1 cluster2 cluster3 cluster4 cluster5 cluster6
9  4.36 4.25 4.55 4.21 4.33 4.33
12 4.69 4.37 4.55 4.21 4.55 4.33

# (I don't know what the 9 and 12 represent.)

# You can also get the sequence boundary locations in a (character)  
matrix:

> sapply(clusobj, function(x) names(c(head(x,1), tail(x,1
 cluster1 cluster2 cluster3 cluster4 cluster5 cluster6
[1,] "9"  "20" "31" "38" "58" "65"
[2,] "12" "26" "31" "43" "59" "65"



brackets

attrnames[c(1, length(attrnames)]

 ^  missing right-paren

Might work:
attrnames <- attr(clusobj[["cluster1"]], "names")
attrnames[c(1, length(attrnames))]
--

David Winsemius, MD
West Hartford, CT






Additionally I can get the output as a matrix in form

atomic [1:613] 3.01 4.1 3.04 3.81 3.55 3.37 3.09 4.1 3.61 6.36 ...
- attr(*, "acs")= num 47.6

where "acs" is the average size.  Each height value in the vector  
has a

corresponding number relating to the location in the dataset.


Better would be to tell us _how_ "each height value" has a  
"corresponding number relating to the location". It is not apparent  
from the above. Some other object you are not naming or describing for  
us?



 When I change
the vector to matrix this looks like the row name but it isn't as
rownames(clusters) yields NULL.

Do you have any idea how to abstract these values?


First you need to figure out what these are. Better than guessing and  
applying extractor functions, would be to use str() and class() on the  
result ... and for Pete's sake , include the full console output  
rather than your guess at what is needed.




Doug
--


David Winsemius, MD
West Hartford, CT

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


Re: [R] Differenciate numbers from reference for rows

2010-10-30 Thread Gabor Grothendieck
On Fri, Oct 29, 2010 at 6:54 PM, M.Ribeiro  wrote:
>
> So, I am having a tricky reference file to extract information from.
>
> The format of the file is
>
> x   1 + 4 * 3 + 5 + 6 + 11 * 0.5
>
> So, the elements that are not being multiplied (1, 5 and 6) and the elements
> before the multiplication sign (4 and 11) means actually the reference for
> the row in a matrix where I need to extract the element from.
>
> The numbers after the multiplication sign are regular numbers
> Ex:
>
>> x<-matrix(20:35)
>> x
>      [,1]
>  [1,]   20
>  [2,]   21
>  [3,]   22
>  [4,]   23
>  [5,]   24
>  [6,]   25
>  [7,]   26
>  [8,]   27
>  [9,]   28
> [10,]   29
> [11,]   30
> [12,]   31
> [13,]   32
> [14,]   33
> [15,]   34
> [16,]   35
>
> I would like to read the rows 1,4,5,6 and 11 and sum then. However the
> numbers in the elements row 4 and 11 are multiplied by 3 and 0.5
>
> So it would be
> 20 + 23 * 3 + 24 + 25 + 30 * 0.5.
>
> And I have this format in different files so I can't do all by hand.
> Can anybody help me with a script that can differentiate this?


I assume that every number except for the second number in the pattern
number * number is to be replaced by that row number in x.  Try this.
We define a regular expression which matches the first number ([0-9]+)
of each potential pair and optionally (?) spaces ( *) a star (\\*),
more spaces ( *) and digits [0-9.]+ passing the first and second
backreferences (matches to the parenthesized portions of the regular
expression) to f and inserting the output of f where the matches had
been.

library(gsubfn)
f <- function(a, b) paste(x[as.numeric(a)], b)
s2 <- gsubfn("([0-9]+)( *\\* *[0-9.]+)?", f, s)

If the objective is to then perform the calculation that that
represents then try this:
sapply(s2, function(x) eval(parse(text = x)))

For example,

> s <- c("1 + 4 * 3 + 5 + 6 + 11 * 0.5", "1 + 4 * 3 + 5 + 6 + 11 * 0.5")
> x <- matrix(20:35)
> f <- function(a, b) paste(x[as.numeric(a)], b)
> s2 <- gsubfn("([0-9]+)( *\\* *[0-9.]+)?", f, s)
> s2
[1] "20  + 23  * 3 + 24  + 25  + 30  * 0.5" "20  + 23  * 3 + 24  + 25
+ 30  * 0.5"
> sapply(s2, function(x) eval(parse(text = x)))
20  + 23  * 3 + 24  + 25  + 30  * 0.5 20  + 23  * 3 + 24  + 25  + 30  * 0.5
  153   153

For more see the gsubfn home page at http://gsubfn.googlecode.com


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] overloading "[" and "[<-" using S3 classes

2010-10-30 Thread Mark Heckmann
How can I overload the "[" and "[<-" operators using S3 classes?
Something like '['.{class} did not work or at least I do not know how to define 
it properly.


For S4 it is straightforward:

setMethod("[", signature(x = "myClass", i = "numeric"),
function (x, i, j, ..., drop){
... some operations
})

How to do the same for S3?
TIA!
Mark
–––
Mark Heckmann
Dipl. Wirt.-Ing. cand. Psych.
Vorstraße 93 B01
28359 Bremen
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.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] one function with 2 returnh points

2010-10-30 Thread Alaios
Thanks a lot :)





From: Liviu Andronic 

Cc: Rhelp 
Sent: Sat, October 30, 2010 11:31:35 AM
Subject: Re: [R] one function with 2 returnh points


> Hello everyone.
> I have written quite a big function that at the end correctly returns the 
>values
> I want. I found a rare exception that I want to cover also. The easier for me
> would be to write something like that
>
>
> function(){
>
>  if (rare exception happened)
>  return that value
>
>  # The comes the code for normal execution
>  # ...
>  # ...
>  return value # Normal values to return
>
> }
>
Are you looking for something similar?
fun <-
function(x)
{
if(is.character(x)){
return(paste('Error: wrong!'))
}
res <- sum(1:10)
return(res)
}

> fun('asdf')
[1] "Error: wrong!"
> fun(1:10)
[1] 55



>
>
> Would that be feasible with R or two returns statements are not accepted?
>
> Regards
> Alex
>
>
>
>[[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.
>



-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail



  
[[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] overloading "[" and "[<-" using S3 classes

2010-10-30 Thread Gabor Grothendieck
On Sat, Oct 30, 2010 at 9:03 AM, Mark Heckmann  wrote:
> How can I overload the "[" and "[<-" operators using S3 classes?
> Something like '['.{class} did not work or at least I do not know how to 
> define it properly.
>
>
> For S4 it is straightforward:
>
> setMethod("[", signature(x = "myClass", i = "numeric"),
>        function (x, i, j, ..., drop){
>                ... some operations
> })
>
> How to do the same for S3?

Check out some examples by entering this into R:

methods("[") # lists [ methods
`[.data.frame`
stats:::`[.ts`



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] vertical list sum

2010-10-30 Thread Henrique Dallazuanna
Another way:

x <- list(c(9, 5, 7, 2, 14, 4, 4, 3), c(3, 6, 25, 2, 14, 3, 3, 4),
   c(28, 4, 14, 3, 14, 2, 4, 5), 28)
apply(array(unlist(lapply(x, '[', 1:max(sapply(x, length, dim = c(1, 8,
4)), 1:2, mean, na.rm = TRUE)

or

rowMeans(as.data.frame(lapply(x, '[', 1:max(sapply(x, length, na.rm =
TRUE)

On Fri, Oct 29, 2010 at 10:08 PM, Gregory Ryslik  wrote:

> Hi,
>
> Ah! Thanks for your help! I have even seen Reduce before but for some
> reason just didn't make the connection. This helps a ton! Thanks again.
>
> Kind regards,
> Greg
> On Oct 29, 2010, at 6:53 PM, Jorge Ivan Velez wrote:
>
> > Hi Greg,
> >
> > Here are two ways of doing it:
> >
> > > mylist <- list(x = rpois(10, 10), y = rpois(10, 20), z = rpois(10, 5))
> > > mylist
> > $x
> >  [1]  3 13 14 16 10  7  3  5 12 14
> >
> > $y
> >  [1] 17 16 26 13 23 24 16 28 23 12
> >
> > $z
> >  [1]  2  6  5  5  5  1  9 11  6  4
> >
> > >
> > > colMeans(do.call(rbind, mylist), na.rm = TRUE)
> >  [1]  7.33 11.67 15.00 11.33 12.67 10.67
>  9.33 14.67 13.67
> > [10] 10.00
> > >
> > > Reduce("+", mylist)/length(mylist)
> >  [1]  7.33 11.67 15.00 11.33 12.67 10.67
>  9.33 14.67 13.67
> > [10] 10.00
> >
> >
> > HTH,
> > Jorge
> >
> >
> > On Fri, Oct 29, 2010 at 6:46 PM, Gregory Ryslik <> wrote:
> > Hi Everyone,
> >
> > I have a list of vectors like this (in this case it's 3 vectors but
> assume the vector count and the length of each vector is not known):
> >
> > [[1]]
> > [1]  9  5  7  2 14  4  4  3
> >
> > [[2]]
> > [1]  3  6 25  2 14  3  3  4
> >
> > [[3]]
> > [1] 28  4 14  3 14  2  4  5
> >
> > What I want to do is take the average vertically. Thus I want to do
> 9+3+28 /3, 5+6+4 /3, etc... and then have it return a vector. I'm assuming
> that if I can sum it, I can count it to so summing this would be just as
> helpful.
> >
> > I understand I can first go through each element of the list, get a
> vector, cbind into  matrix and sum across but I was hoping to avoid that...
> I tried getting it to work with mapply but am having difficulties...
> >
> > Thanks!
> >
> > Kind regards,
> > Greg
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/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.
>



-- 
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] Differenciate numbers from reference for rows

2010-10-30 Thread David Winsemius


On Oct 30, 2010, at 8:42 AM, Gabor Grothendieck wrote:

On Fri, Oct 29, 2010 at 6:54 PM, M.Ribeiro  
 wrote:


So, I am having a tricky reference file to extract information from.

The format of the file is

x   1 + 4 * 3 + 5 + 6 + 11 * 0.5

So, the elements that are not being multiplied (1, 5 and 6) and the  
elements
before the multiplication sign (4 and 11) means actually the  
reference for

the row in a matrix where I need to extract the element from.

The numbers after the multiplication sign are regular numbers
Ex:


x<-matrix(20:35)


I would like to read the rows 1,4,5,6 and 11 and sum then. However  
the

numbers in the elements row 4 and 11 are multiplied by 3 and 0.5

So it would be
20 + 23 * 3 + 24 + 25 + 30 * 0.5.

And I have this format in different files so I can't do all by hand.
Can anybody help me with a script that can differentiate this?



I assume that every number except for the second number in the pattern
number * number is to be replaced by that row number in x.  Try this.
We define a regular expression which matches the first number ([0-9]+)
of each potential pair and optionally (?) spaces ( *) a star (\\*),
more spaces ( *) and digits [0-9.]+ passing the first and second
backreferences (matches to the parenthesized portions of the regular
expression) to f and inserting the output of f where the matches had
been.

library(gsubfn)
f <- function(a, b) paste(x[as.numeric(a)], b)
s2 <- gsubfn("([0-9]+)( *\\* *[0-9.]+)?", f, s)

If the objective is to then perform the calculation that that
represents then try this:
sapply(s2, function(x) eval(parse(text = x)))

For example,

s <- c("1 + 4 * 3 + 5 + 6 + 11 * 0.5", "1 + 4 * 3 + 5 + 6 + 11 *  
0.5")

x <- matrix(20:35)
f <- function(a, b) paste(x[as.numeric(a)], b)
s2 <- gsubfn("([0-9]+)( *\\* *[0-9.]+)?", f, s)
s2
[1] "20  + 23  * 3 + 24  + 25  + 30  * 0.5" "20  + 23  * 3 + 24  +  
25 + 30  * 0.5"

sapply(s2, function(x) eval(parse(text = x)))
20  + 23  * 3 + 24  + 25  + 30  * 0.5 20  + 23  * 3 + 24  + 25  +  
30  * 0.5
  
153   153


For more see the gsubfn home page at http://gsubfn.googlecode.com



I am scratching my head regarding the gsubfn workings. It appears that  
as gsubfn moves across the input strings that it will either match  
just "[0-9+]" or it will match "[0-9+] *\\* *[0-9.]+?".


In either case the match will do a lookup in x[] for the first match  
using the "a" index, and if there is a match for the second position  
assigned to "*b" then that x[a] will be followed by "*b"  and is  
therefore destined to be multiplied by "b". I cannot quite figure out  
how the NULL value gets not-matched to the second back-reference and  
then doesn't screw up the f() function by only providing one argument  
to a two argument function. Maybe it's due to this? (So can you  
comment on how optional back-references return values?)


> paste("a", NULL)
[1] "a "

Furthermore, somehow (and this is further functiona magic I am  
missing) these results are concatenated in a string, and then  
evaluated, a step which I do get.


--

David Winsemius, MD
West Hartford, CT

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


[R] solving equation consisting of factorials

2010-10-30 Thread Shant Ch


Hi, 


I was trying to solve for m such that,

choose(n-1,k-1)+choose(n-2,k-1)+...+choose(n-m+1,k-1) - ck=0

ck is calculated by the way given in the code. Now I solved for m using uniroot 
but the error messages appeared. 

n<-30
k=3
alpha<-0.05
nk<-choose(n,k);
ck<-(nk/2)+k*nk*qnorm(1-alpha)/(12*n)# computation of ck.

lhs<-function(z)
{
Smc=0;
fnk=0
for(y in 1:z)
{
   fnk[y]<-choose((n-y+1),(k-1))
   Smc=Smc+fnk[y]-ck
}
return(Smc);
}
   

In order to solve the equation first I tried to find out the point near which 
lhs=0 using curve function.

curve(lhs,-70,-60)
 
Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' and 'y' lengths differ
In addition: Warning message:
In 1:z : numerical expression has 101 elements: only the first used


 Then I computed lhs function for every z  one by one, I found that lhs changes 
its sign between (-64,-63), so I used the following uniroot function.

uniroot(lhs(-64,-63))   

Error in min(interval) : 'interval' is missing


Can anyone help me out? Thanks.

Shant


  
[[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] Differenciate numbers from reference for rows

2010-10-30 Thread Gabor Grothendieck
On Sat, Oct 30, 2010 at 9:43 AM, David Winsemius  wrote:
>
> On Oct 30, 2010, at 8:42 AM, Gabor Grothendieck wrote:
>
>> On Fri, Oct 29, 2010 at 6:54 PM, M.Ribeiro 
>> wrote:
>>>
>>> So, I am having a tricky reference file to extract information from.
>>>
>>> The format of the file is
>>>
>>> x   1 + 4 * 3 + 5 + 6 + 11 * 0.5
>>>
>>> So, the elements that are not being multiplied (1, 5 and 6) and the
>>> elements
>>> before the multiplication sign (4 and 11) means actually the reference
>>> for
>>> the row in a matrix where I need to extract the element from.
>>>
>>> The numbers after the multiplication sign are regular numbers
>>> Ex:
>>>
 x<-matrix(20:35)
>>>
>>> I would like to read the rows 1,4,5,6 and 11 and sum then. However the
>>> numbers in the elements row 4 and 11 are multiplied by 3 and 0.5
>>>
>>> So it would be
>>> 20 + 23 * 3 + 24 + 25 + 30 * 0.5.
>>>
>>> And I have this format in different files so I can't do all by hand.
>>> Can anybody help me with a script that can differentiate this?
>>
>>
>> I assume that every number except for the second number in the pattern
>> number * number is to be replaced by that row number in x.  Try this.
>> We define a regular expression which matches the first number ([0-9]+)
>> of each potential pair and optionally (?) spaces ( *) a star (\\*),
>> more spaces ( *) and digits [0-9.]+ passing the first and second
>> backreferences (matches to the parenthesized portions of the regular
>> expression) to f and inserting the output of f where the matches had
>> been.
>>
>> library(gsubfn)
>> f <- function(a, b) paste(x[as.numeric(a)], b)
>> s2 <- gsubfn("([0-9]+)( *\\* *[0-9.]+)?", f, s)
>>
>> If the objective is to then perform the calculation that that
>> represents then try this:
>> sapply(s2, function(x) eval(parse(text = x)))
>>
>> For example,
>>
>>> s <- c("1 + 4 * 3 + 5 + 6 + 11 * 0.5", "1 + 4 * 3 + 5 + 6 + 11 * 0.5")
>>> x <- matrix(20:35)
>>> f <- function(a, b) paste(x[as.numeric(a)], b)
>>> s2 <- gsubfn("([0-9]+)( *\\* *[0-9.]+)?", f, s)
>>> s2
>>
>> [1] "20  + 23  * 3 + 24  + 25  + 30  * 0.5" "20  + 23  * 3 + 24  + 25 + 30
>>  * 0.5"
>>>
>>> sapply(s2, function(x) eval(parse(text = x)))
>>
>> 20  + 23  * 3 + 24  + 25  + 30  * 0.5 20  + 23  * 3 + 24  + 25  + 30  *
>> 0.5
>>                                 153                                   153
>>
>> For more see the gsubfn home page at http://gsubfn.googlecode.com
>
>
> I am scratching my head regarding the gsubfn workings. It appears that as
> gsubfn moves across the input strings that it will either match just
> "[0-9+]" or it will match "[0-9+] *\\* *[0-9.]+?".

In the regular expression

   "([0-9]+)( *\\* *[0-9.]+)?"

it matches the first (...) and then the (...)?  part.  ? means 0 or 1
occurrences so it can match by matching the content or if that is not
possible it will match the empty string.

>
> In either case the match will do a lookup in x[] for the first match using
> the "a" index, and if there is a match for the second position assigned to
> "*b" then that x[a] will be followed by "*b"  and is therefore destined to
> be multiplied by "b". I cannot quite figure out how the NULL value gets
> not-matched to the second back-reference and then doesn't screw up the f()
> function by only providing one argument to a two argument function. Maybe
> it's due to this? (So can you comment on how optional back-references return
> values?)

(...)? says to match 0 or 1 occurrences of the ... expression.  Iif
(...) does not match then (...)? will be successful in matching the
empty string.  The function is always called with two arguments.  Try
this:

> s <- "1 + 4 * 3 + 5 + 6 + 11 * 0.5"
> g <- function(a, b) sprintf("", a, b)
> gsubfn("([0-9]+)( *\\* *[0-9.]+)?", g, s)
[1] " +  +  + 
+ "



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] date calculation

2010-10-30 Thread Ben Bolker
On 10-10-30 02:02 AM, Shi, Tao wrote:
> Hi Ben,
> 
> That must be the case!  In fact if I do:
> 
>> difftime(strptime("24NOV2004", format="%d%b%Y"), 
>> strptime("13MAY2004",format="%d%b%Y"), units="days", tz="GMT")
> Time difference of 195 days
> 
> 
> which supports your claim.
> 
> Can someone from the R development team confirm this?
> 
> Thanks!
> 
> ...Tao
> 
> 

   It sounds like you think this is a bug.  It's not (although it's
arguably not what you want).  The general advice when using dates and
time in R is to use the *least* specific date format that will do what
you want, i.e. don't use a format that incorporates time zone
information (daylight savings time) information if you don't want to
deal with these complexities.

 I would suggest the chron package:

library(chron)
diff(chron(dates.=c("24/11/2004","13/05/2004"),format="d/m/y"))

> 
> 
> 
> - Original Message -
>> From:Ben Bolker 
>> To:r-h...@stat.math.ethz.ch
>> Cc:
>> Sent:Friday, October 29, 2010 7:54:53 PM
>> Subject:Re: [R] date calculation
>>
>>
>> Shi, Tao  
>> href="http://yahoo.com";>yahoo.com> writes:
> 
>> Could someone 
>> explain to me why the following result is not a integer?
>>
>>>
>> difftime(strptime("24NOV2004", format="%d%b%Y"), strptime("13MAY2004", 
>>
>>> format="%d%b%Y"), units="days")
>> Time difference of 195.0417 
>> days
> 
>   Presumably because this goes across a daylight-savings 
>> time
> adjustment?  0.0417=1/24 days is 1 hour ...
> 
>   Ben 
>> Bolker
> 
> __
> 
>> ymailto="mailto:R-help@r-project.org"; 
>> href="mailto:R-help@r-project.org";>R-help@r-project.org mailing list
> 
>> href="https://stat.ethz.ch/mailman/listinfo/r-help"; target=_blank 
>>> https://stat.ethz.ch/mailman/listinfo/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] date calculation

2010-10-30 Thread Marc Schwartz

On Oct 30, 2010, at 9:22 AM, Ben Bolker wrote:

> On 10-10-30 02:02 AM, Shi, Tao wrote:
>> Hi Ben,
>> 
>> That must be the case!  In fact if I do:
>> 
>>> difftime(strptime("24NOV2004", format="%d%b%Y"), 
>>> strptime("13MAY2004",format="%d%b%Y"), units="days", tz="GMT")
>> Time difference of 195 days
>> 
>> 
>> which supports your claim.
>> 
>> Can someone from the R development team confirm this?
>> 
>> Thanks!
>> 
>> ...Tao
>> 
>> 
> 
>   It sounds like you think this is a bug.  It's not (although it's
> arguably not what you want).  The general advice when using dates and
> time in R is to use the *least* specific date format that will do what
> you want, i.e. don't use a format that incorporates time zone
> information (daylight savings time) information if you don't want to
> deal with these complexities.
> 
> I would suggest the chron package:
> 
> library(chron)
> diff(chron(dates.=c("24/11/2004","13/05/2004"),format="d/m/y"))

Ben,

If time and time zone are not relevant, any reason not to use:


> diff(as.Date(c("13/05/2004", "24/11/2004"), format = "%d/%m/%Y"))
Time difference of 195 days


or perhaps conceptually easier:

Date2 <- as.Date("24/11/2004", format = "%d/%m/%Y")
Date1 <- as.Date("13/05/2004", format = "%d/%m/%Y")

> Date2 - Date1
Time difference of 195 days


R has built in arithmetic operations for such dates, without the need to use 
another package, since they are effectively numerics with a Date class:

> str(Date1)
Class 'Date'  num 12551

> str(Date2)
Class 'Date'  num 12746


?

HTH,

Marc Schwartz



>> 
>> 
>> 
>> - Original Message -
>>> From:Ben Bolker 
>>> To:r-h...@stat.math.ethz.ch
>>> Cc:
>>> Sent:Friday, October 29, 2010 7:54:53 PM
>>> Subject:Re: [R] date calculation
>>> 
>>> 
>>> Shi, Tao  
>>> href="http://yahoo.com";>yahoo.com> writes:
>> 
>>> Could someone 
>>> explain to me why the following result is not a integer?
>>> 
 
>>> difftime(strptime("24NOV2004", format="%d%b%Y"), strptime("13MAY2004", 
>>> 
 format="%d%b%Y"), units="days")
>>> Time difference of 195.0417 
>>> days
>> 
>>  Presumably because this goes across a daylight-savings 
>>> time
>> adjustment?  0.0417=1/24 days is 1 hour ...
>> 
>>  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.


Re: [R] wilcox.test; data type conversion?

2010-10-30 Thread Peter Dalgaard
On 10/29/2010 05:41 AM, Dennis Murphy wrote:
> Hi:
> 
> Make grade an ordered factor:
> grade <- factor(grade, levels = c('G', 'VG', 'MVG'))
> as.numeric(as.character(grade)) will convert to numeric scores 1, 2 and 3,
> respectively, corresponding to the numerical codes of the ordered levels.

Not quite:

> g <-  c('G', 'VG', 'MVG')
> grade <- factor(g, levels = c('G', 'VG', 'MVG'))
> as.numeric(as.character(grade))
[1] NA NA NA

However:

> as.numeric(grade)
[1] 1 2 3

(also, that's not an ordered factor, but it doesn't matter, the levels
have an order anyway)

> 
> HTH,
> Dennis
> 
> On Thu, Oct 28, 2010 at 8:37 PM, Par Leijonhufvud
> wrote:
> 
>> I'm working on a quick tutorial for my students, and was planning on
>> using Mann-Whitney U as one of the tests.
>>
>> I have the following (fake) data
>>
>>  grade <- c("MVG", "VG", "VG", "G", "MVG", "G", "VG", "G", "VG")
>>  sex <- c( "male", "male", "female", "male", "female", "male", "female",
>> "male", "male")
>>  gradesbysex <- data.frame(grade, sex)
>>
>> The grades is in the Swedish system, where the order is G < VG < MVG
>>
>> The idea is that they will investigate if they can show a grade
>> difference by sex (i.e. that the teacher gives better grades to boys or
>> girls).
>>
>> Since the wilcox.test needs the order of the grades it wants numeric
>> vector  for the data. Is there a good and simple (i.e. student
>> compatible) way to handle this? I could tell them to enter data as
>> numbers instead, but an elegant way to do this inside R would be
>> preferable.
>>
>>
>> On the same theme, is there a way to tell barplot that, when making
>> stacked barplots, to stack the data in a particular order (default
>> appears to be alphabetical)?

Presumably, same thing: Ensure that the stacking factor is a factor with
the levels in the correct order. However, you (Par) didn't tell how the
barplot was generated. The argument to the default method is a matrix
and the row/col ordering determines the plot. If, in turn, it was
created by tabulating two factors, then factor level ordering (by
default alphabetic) applies to the table.


-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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] Any similar solution for C# (Integrating R with C++: Rcpp, RInside, and RProtobuf)

2010-10-30 Thread Haoda Fu
Friends -

I am pretty excited for the following talk and I was wondering
if there is a similar solution for C#. I googled but didn't find a 
good solution. Previously, I let C# to send R code to Rscript.exe.
But it is not an integrated solution.

Integrating R with C++: Rcpp, RInside, and RProtobuf
http://google-opensource.blogspot.com/2010/10/integrating-r-with-c-rcpp-rinside-and.html

Many thanks!
Haoda

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] wilcox.test; data type conversion?

2010-10-30 Thread Peter Dalgaard
On 10/29/2010 06:24 AM, Steven McKinney wrote:
>> > wilcox.test(as.integer(grade) ~ sex, data = gradesbysex)
>   Wilcoxon rank sum test with continuity correction
> 
> data:  as.integer(grade) by sex 
> W = 4.5, p-value = 0.2695
> alternative hypothesis: true location shift is not equal to 0 
> 
> Warning message:
> In wilcox.test.default(x = c(3L, 2L, 1L, 1L, 1L, 2L), y = c(2L,  :
>   cannot compute exact p-value with ties
> 
> You can break the ties by jittering the data.  Each jitter will of course
> produce different tie breakers.  A few repeats of the test, or a loop and
> some summaries of the outcomes, will give you an idea of the
> "average" result.

I wouldn't bother with that. The p-value is based on the correct
covariance matrix of the rank sums, tie-breaking just adds noise to the
analysis. If you really want an exact p-value, package exactRankTests is
the ticket. (Or, if there is really only 3 females in 9 students, you
can get ambitious and set up the permutation distribution by enumerating
the choose(9,3)=84 possible outcomes.)




-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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] compare quality of clustering methods?

2010-10-30 Thread Khanh Nguyen
Hi,

Suppose I want to compare the results of two clustering methods, what
is the best way to do it? Thanks

Regards,

-k

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

2010-10-30 Thread Mestat

Hi listers,
I am trying to plot some confidence intervals. The function FORESTPLOT,
would work, but I need something more simple. I dont need to define the text
labels. Is there another function that I can plot some confidence intervals.
Thanks in advance,
Marcio
-- 
View this message in context: 
http://r.789695.n4.nabble.com/ForestPlot-or-similar-tp3020374p3020374.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] plot pdf

2010-10-30 Thread mmstat


Subject: plot 

Your recent reply has got me underway.  However the savePlot command is not 
working.   
I am following refman example. Any thoughts?  

I am on a new windows 7 os.  I am not sure how to open a new device (output 
graphic
 window).  I wonder if that could be the problem? 

R Code
xcrit=135.9 
cord.x <- c(80,seq(80,xcrit,.1),xcrit) 
 cord.y <- c(0, dnorm(seq(80, xcrit, .1), 140, 15), 0) 
 curve(dnorm(x,140,15),xlim=c(80,200),main='Normal PDF',ylab="Probability") 
 polygon(cord.x,cord.y,col='orange') 
 savePlot(filename="c:\\lower.emf",type=c("emf"), device = 
dev.cur(),restoreConsole = TRUE) 
Warning messages: 
1: In savePlot(filename = "c:\\lower.emf", type = c("emf"), device = 
dev.cur(),  : 
  Unable to open metafile 'c:\lower.emf' for writing 
2: In savePlot(filename = "c:\\lower.emf", type = c("emf"), device = 
dev.cur(),  : 
  opening device failed 

Sincerely, 
Mary A. Marion 


 

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

2010-10-30 Thread Mestat

Here is one example:
I have three vectors (mean,lower interval, upper interval)
mean<-c(2,4,6,8)
l<-c(1,2,3,4)
u<-c(4,8,12,16)
How would I plot that if I want to use the FORESTPLOT function. I dont need
to use the TABLETEXT option.
I am working in something like this:
tabletext<-c(NA,NA,NA,NA,NA)
mean<-c(NA,2,4,6,8)
l<-c(NA,1,2,3,4)
u<-c(NA,4,8,12,16)
forestplot(tabletext,mean,l,u,zero=0)
But I am having a problem with the length of the dimension...
Thanks in advance,
Marcio

-- 
View this message in context: 
http://r.789695.n4.nabble.com/ForestPlot-or-similar-tp3020374p3020394.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] plot pdf

2010-10-30 Thread Uwe Ligges



On 30.10.2010 17:23, mms...@comcast.net wrote:



Subject: plot

Your recent reply has got me underway.  However the savePlot command is not 
working.
I am following refman example. Any thoughts?

I am on a new windows 7 os.  I am not sure how to open a new device (output 
graphic
  window).  I wonder if that could be the problem?

R Code
xcrit=135.9
cord.x<- c(80,seq(80,xcrit,.1),xcrit)
  cord.y<- c(0, dnorm(seq(80, xcrit, .1), 140, 15), 0)
  curve(dnorm(x,140,15),xlim=c(80,200),main='Normal PDF',ylab="Probability")
  polygon(cord.x,cord.y,col='orange')
  savePlot(filename="c:\\lower.emf",type=c("emf"), device = 
dev.cur(),restoreConsole = TRUE)


Probably you do not have administrator permissions when running R and 
hence you cannot write to c:\ directly.


Uwe Ligges



Warning messages:
1: In savePlot(filename = "c:\\lower.emf", type = c("emf"), device = dev.cur(), 
 :
   Unable to open metafile 'c:\lower.emf' for writing
2: In savePlot(filename = "c:\\lower.emf", type = c("emf"), device = dev.cur(), 
 :
   opening device failed

Sincerely,
Mary A. Marion




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

2010-10-30 Thread David Winsemius


On Oct 30, 2010, at 9:55 AM, Shant Ch wrote:




Hi,


I was trying to solve for m such that,

choose(n-1,k-1)+choose(n-2,k-1)+...+choose(n-m+1,k-1) - ck=0

ck is calculated by the way given in the code. Now I solved for m  
using uniroot

but the error messages appeared.

n<-30
k=3
alpha<-0.05
nk<-choose(n,k);
ck<-(nk/2)+k*nk*qnorm(1-alpha)/(12*n)# computation of ck.


Given this obviously non-integer value for ck and the obviously  
integer sum of the preceding terms in your equation above, why should  
we think there would be ANY solution?





lhs<-function(z)
{
   Smc=0;
   fnk=0
   for(y in 1:z)
   {
  fnk[y]<-choose((n-y+1),(k-1))
  Smc=Smc+fnk[y]-ck
   }
   return(Smc);
}


In order to solve the equation first I tried to find out the point  
near which

lhs=0 using curve function.

curve(lhs,-70,-60)


Try instead:

> plot(-60:70, sapply(-60:70, lhs) )

Which will show you that there are no values of lhs() in the range you  
are exploring , probably because you are trying to index that y object  
with negative values inside that lhs function.


Maybe you should describe what your real goal of all this is. There  
are packages for integer programing, but you need to provide a better  
problem specification ( .i.e, a problem that is solvable.)





Error in xy.coords(x, y, xlabel, ylabel, log) :
 'x' and 'y' lengths differ
In addition: Warning message:
In 1:z : numerical expression has 101 elements: only the first used


Then I computed lhs function for every z  one by one, I found that  
lhs changes

its sign between (-64,-63), so I used the following uniroot function.


Must have been a different function:
> lhs(-63)
numeric(0)

--
David.


uniroot(lhs(-64,-63))

Error in min(interval) : 'interval' is missing


Can anyone help me out? Thanks.

Shant



David Winsemius, MD
West Hartford, CT

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


[R] Using names function

2010-10-30 Thread Sudhakar Kumar

Just starting on my journey to learn R and the book I am using is "Using R for 
Introductory Statistics"

One of the problems (page 15, 1.10) goes as follows:
The monthly sales fig for 2002 were (2700, 2600, 3050, . . ). Using diff() find 
the month with greatest increase from prev month. 

I created a msales var:
msales = c(2700, 2600, 3050 . . )

I named them:
names(msales)=c("Jan", Feb", "Mar" . . .)

to find the month with greatest increase from prev month:
max(diff(msales))

I get the numeric value displayed when I execute the above function, but not 
the month. cumsum(msales) displays the results under each month, but not max. 
How can I get both the month and value displayed?

Thanks
-Sudhakar

ps: no, I am not a student seeking answers to exercises :)
  
[[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] Using names function

2010-10-30 Thread Jorge Ivan Velez
Hi Sudhakar,

Take a look at ?which.max

msales <- c(2700, 2600, 3050)
names(msales) <- c("Jan", "Feb", "Mar")
names(which.max(diff(msales)))
# [1] "Mar"

HTH,
Jorge


On Sat, Oct 30, 2010 at 12:27 PM, Sudhakar Kumar <> wrote:

>
> Just starting on my journey to learn R and the book I am using is "Using R
> for Introductory Statistics"
>
> One of the problems (page 15, 1.10) goes as follows:
> The monthly sales fig for 2002 were (2700, 2600, 3050, . . ). Using diff()
> find the month with greatest increase from prev month.
>
> I created a msales var:
> msales = c(2700, 2600, 3050 . . )
>
> I named them:
> names(msales)=c("Jan", Feb", "Mar" . . .)
>
> to find the month with greatest increase from prev month:
> max(diff(msales))
>
> I get the numeric value displayed when I execute the above function, but
> not the month. cumsum(msales) displays the results under each month, but not
> max. How can I get both the month and value displayed?
>
> Thanks
> -Sudhakar
>
> ps: no, I am not a student seeking answers to exercises :)
>
>[[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.


[R] For loop

2010-10-30 Thread 20c
Hi all,

how can i make the following loop faster?

vv[20001,22]=v[20001,22]
for(k in 21:1) {
 for(j in 20001:2) {
   vv[j-1,k+1]=min(xx[j-1]*v[j-1,k+1],vv[j,k+1])
   v[j,k]=h[1,k]+vv[j-1,k+1]
 }
vv[20001,k]=v[20001,k]
}



Thanks

Lorenzo

 

 

 --

 Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP 
autenticato? GRATIS solo con Email.it http://www.email.it/f

 

 Sponsor:

 Idee Regalo Personalizzate a partire da euro 3.90! Su MisterCupido.com alta 
qualitÿ a prezzi imbattibili... e questa settimana GRATIS per te, la confezione 
regalo!

 Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=11027&d=30-10


[[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] Using names function

2010-10-30 Thread Sudhakar Kumar

Thanks Jorge. That is very helpful. Hadnt seen 'which' yet.

So it is a matter of combining functions if I wanted both the value and the 
month?

From: jorgeivanve...@gmail.com
Date: Sat, 30 Oct 2010 12:33:12 -0400
Subject: Re: [R] Using names function
To: ksudha...@live.com
CC: r-help@r-project.org

Hi Sudhakar,
Take a look at ?which.max


msales <- c(2700, 2600, 3050) names(msales) <- c("Jan", "Feb", "Mar")

names(which.max(diff(msales)))# [1] "Mar"

HTH,Jorge

On Sat, Oct 30, 2010 at 12:27 PM, Sudhakar Kumar <> wrote:




Just starting on my journey to learn R and the book I am using is "Using R for 
Introductory Statistics"



One of the problems (page 15, 1.10) goes as follows:

The monthly sales fig for 2002 were (2700, 2600, 3050, . . ). Using diff() find 
the month with greatest increase from prev month.



I created a msales var:

msales = c(2700, 2600, 3050 . . )



I named them:

names(msales)=c("Jan", Feb", "Mar" . . .)



to find the month with greatest increase from prev month:

max(diff(msales))



I get the numeric value displayed when I execute the above function, but not 
the month. cumsum(msales) displays the results under each month, but not max. 
How can I get both the month and value displayed?



Thanks

-Sudhakar



ps: no, I am not a student seeking answers to exercises :)



[[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] Using names function

2010-10-30 Thread David Winsemius


On Oct 30, 2010, at 12:27 PM, Sudhakar Kumar wrote:



Just starting on my journey to learn R and the book I am using is  
"Using R for Introductory Statistics"


One of the problems (page 15, 1.10) goes as follows:
The monthly sales fig for 2002 were (2700, 2600, 3050, . . ). Using  
diff() find the month with greatest increase from prev month.


I created a msales var:
msales = c(2700, 2600, 3050 . . )

I named them:
names(msales)=c("Jan", Feb", "Mar" . . .)


Get in the habit of copy-pasting from the console. This is not valid  
code.




to find the month with greatest increase from prev month:
max(diff(msales))

I get the numeric value displayed when I execute the above function,  
but not the month. cumsum(msales) displays the results under each  
month, but not max. How can I get both the month and value displayed?




> diff(msales)[which.max(diff(msales))]
Mar
450

--

David Winsemius, MD
West Hartford, CT

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


Re: [R] Using names function

2010-10-30 Thread Jorge Ivan Velez
Hi Sudhakar,

Use

 diff(msales)[which.max(diff(msales))]

HTH,
Jorge


On Sat, Oct 30, 2010 at 12:38 PM, Sudhakar Kumar <> wrote:

>
> Thanks Jorge. That is very helpful. Hadnt seen 'which' yet.
>
> So it is a matter of combining functions if I wanted both the value and the
> month?
>
> From:
> Date: Sat, 30 Oct 2010 12:33:12 -0400
> Subject: Re: [R] Using names function
> To: ksudha...@live.com
> CC: r-help@r-project.org
>
> Hi Sudhakar,
> Take a look at ?which.max
>
>
> msales <- c(2700, 2600, 3050) names(msales) <- c("Jan", "Feb", "Mar")
>
> names(which.max(diff(msales)))# [1] "Mar"
>
> HTH,Jorge
>
> On Sat, Oct 30, 2010 at 12:27 PM, Sudhakar Kumar <> wrote:
>
>
>
>
> Just starting on my journey to learn R and the book I am using is "Using R
> for Introductory Statistics"
>
>
>
> One of the problems (page 15, 1.10) goes as follows:
>
> The monthly sales fig for 2002 were (2700, 2600, 3050, . . ). Using diff()
> find the month with greatest increase from prev month.
>
>
>
> I created a msales var:
>
> msales = c(2700, 2600, 3050 . . )
>
>
>
> I named them:
>
> names(msales)=c("Jan", Feb", "Mar" . . .)
>
>
>
> to find the month with greatest increase from prev month:
>
> max(diff(msales))
>
>
>
> I get the numeric value displayed when I execute the above function, but
> not the month. cumsum(msales) displays the results under each month, but not
> max. How can I get both the month and value displayed?
>
>
>
> Thanks
>
> -Sudhakar
>
>
>
> ps: no, I am not a student seeking answers to exercises :)
>
>
>
>[[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.
>

[[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] summary.lm as a post-hoc test?

2010-10-30 Thread Alex F. Bokov
Let's assume that according to Anova(lm(y~a*b, data=d)) the a:b interaction is 
significant, and I would like to know if there are specific combinations of a 
and b levels that differ from the control group. Are there any caveats against 
simply looking at the p-values in the output generated by 
summary(lm(y~a*b,data=d))? The documentation for summary.lm says nothing about 
multiple comparison correction, so I assume I need to do that myself, is that 
correct?

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] Confidence interval for response variable in mixed effects models

2010-10-30 Thread Brian Willis
HI,

I am using lmer() for a simple mixed effects model. The model is of the form
logit(y)~ x + (1|z), where x is an indicator variable and z a multi-level
factor.

I would like an estimate of the response variable (either y or logit y) with
an associated confidence interval for a given value of x.

There does not appear to be a predict function written for lmer().

The output for the fixed effects gives a standard error for the intercept,
the coefficient of x and the correlation. For n observations, I transform
the std errors to variances, and with the correlation, I think I can use the
formula Var(intercept + x) = Var(intercept) + Var(x) + 2Cov(x,intercept) to
get the variance of the fixed effects component of the response variable.

However, I would like to include the random effects component of the
variance, so I may derive a standard error and confidence interval for the
variance.

Does anyone know how to do this? Is there a ready made function like
predict() or does anyone know how to incorporate the variance of random
effects term to derive the std error of the response variable?

Regards,

Brian

[[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] 'tcltk' does not have a name space

2010-10-30 Thread chen chao
Hi, All

I got trouble on installing the qvalue package. Error message: package
'tcltk' does not have a name space

[cch...@ibibmem Yale_CB]$ R CMD INSTALL qvalue.tar.gz
* installing to library '/cchome/cchen1/R/x86_64-unknown-linux-gnu-library/2.10'

* installing *source* package 'qvalue' ...
** R
** data
** inst
** preparing package for lazy loading
Error : package 'tcltk' does not have a name space
ERROR: lazy loading failed for package 'qvalue'
* removing '/cchome/cchen1/R/x86_64-unknown-linux-gnu-library/2.10/qvalue'

Or by bioconductor

> source("http://bioconductor.org/biocLite.R";)
biocLite("qvalue")
> biocLite("qvalue")
Using R version 2.10.1, biocinstall version 2.5.11.
Installing Bioconductor version 2.5 packages:
[1] "qvalue"
Please wait...

Warning in install.packages(pkgs = pkgs, repos = repos, ...) :
  argument 'lib' is missing: using '/cchome/cchen1/R/x86_64-unknown-linux-gnu-li
brary/2.10'
trying URL 'http://cran.fhcrc.org/src/contrib/qvalue_1.24.0.tar.gz'
Content type 'application/x-gzip' length 458634 bytes (447 Kb)
opened URL
==
downloaded 447 Kb

* installing *source* package 'qvalue' ...
** R
** data
** inst
** preparing package for lazy loading
Error : package 'tcltk' does not have a name space
ERROR: lazy loading failed for package 'qvalue'
* removing '/userhom2/3/cchen1/R/x86_64-unknown-linux-gnu-library/2.10/qvalue'

The downloaded packages are in
'/tmp/RtmpzDBPsF/downloaded_packages'
Warning message:
In install.packages(pkgs = pkgs, repos = repos, ...) :
  installation of package 'qvalue' had non-zero exit status

> version
   _
platform   x86_64-unknown-linux-gnu
arch   x86_64
os linux-gnu
system x86_64, linux-gnu
status
major  2
minor  10.1
year   2009
month  12
day14
svn rev50720
language   R
version.string R version 2.10.1 (2009-12-14)

Any helps? Thanks so much.

-- 
Chen, Chao
Psychiatry
University of Chicago
924 E 57th St, Chicago, IL 60637
U. S. A.
MOE Key Laboratory of Contemporary Anthropology and Center for
Evolutionary Biology,
School of Life Sciences and Institutes of Biomedical Sciences,
Fudan University
220# Handan Road, Shanghai (200433)
P.R.China

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] wilcox.test; data type conversion?

2010-10-30 Thread Par Leijonhufvud
Peter Dalgaard  [2010.10.30] wrote:
> I wouldn't bother with that. The p-value is based on the correct
> covariance matrix of the rank sums, tie-breaking just adds noise to the
> analysis. 

Good to know.

> If you really want an exact p-value, package exactRankTests is

In this case I suspect that for upper secondary students we won't get
that fancy. This is the first time they deal with statistics beyond
mean, median and possibly standard deviation (and simple graphs, of
course).  Thus the request for simple and elegant solutions; arcane
incantations won't make them leave the comforts of Excel.

> the ticket. (Or, if there is really only 3 females in 9 students, you
> can get ambitious and set up the permutation distribution by enumerating
> the choose(9,3)=84 possible outcomes.)

Well, this being totally fake data I created for a student exercise,
there can be as many male and female students in the class as I think
they can be bothered typing in... :-)

/Par

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

2010-10-30 Thread Matevž Pavlič
Hi, 

 

I know this is probalby a very trivial thing to do for most of the R users, but 
since I just strated using it I have some problems

 

I have a data.frame with a field called "razred". This field has values from 1 
up to 15. 

Is it possible to create a for loop that would create a new data frame for each 
of the "razred" values.

 

Thanks for the help, m

 

 

 


[[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] Confidence interval for response variable in mixed effects models

2010-10-30 Thread Ben Bolker
Brian Willis  manchester.ac.uk> writes:

> I am using lmer() for a simple mixed effects model. The model is of the form
> logit(y)~ x + (1|z), where x is an indicator variable and z a multi-level
> factor.
> 
> I would like an estimate of the response variable (either y or logit y) with
> an associated confidence interval for a given value of x.

[snippage: sorry to remove context, but I am posting via gmane, which
will complain if I have too much quoted context ...]

> Does anyone know how to do this? Is there a ready made function like
> predict() or does anyone know how to incorporate the variance of random
> effects term to derive the std error of the response variable?

  You should search the r-sig-mixed-models archive for answers, and
post there if you don't find what you need.  The problem is that it
can actually be a bit tricky to define these things properly for mixed
models, decide which random effects to include (or not) in the prediction
of the mean and include (or not) in the definition of the variance.
So far there has not been a confluence of people who want this,
people who know enough to construct a nice general solution, and
people who have time to do it ...

  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.


Re: [R] for loop

2010-10-30 Thread David Winsemius


On Oct 30, 2010, at 2:07 PM, Matevž Pavlič wrote:


Hi,

I know this is probalby a very trivial thing to do for most of the R  
users, but since I just strated using it I have some problems


I have a data.frame with a field called "razred". This field has  
values from 1 up to 15.


Is it possible to create a for loop that would create a new data  
frame for each of the "razred" values.


The R-way would be to use the split function and leave the result in a  
list to which the same operation could be also repeatedly performed  
using lapply.


?split

And take a look at the fourth example applying split to the builtin  
airquality dataframe.


The plyr package also provides functions on dataframes.

--

David Winsemius, MD
West Hartford, CT

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


Re: [R] for loop

2010-10-30 Thread Jorge Ivan Velez
Hi Matevž,

Perhaps split() is what you are looking for:

# some data

x <- rep(rpois(5, 10), 4)

y <- rnorm(20)

d <- data.frame(x, y)

d

split(d, x)

See ?split and ?strsplit for more information.

HTH,
Jorge


On Sat, Oct 30, 2010 at 2:07 PM, Matevž Pavlič <> wrote:

> Hi,
>
>
>
> I know this is probalby a very trivial thing to do for most of the R users,
> but since I just strated using it I have some problems
>
>
>
> I have a data.frame with a field called "razred". This field has values
> from 1 up to 15.
>
> Is it possible to create a for loop that would create a new data frame for
> each of the "razred" values.
>
>
>
> Thanks for the help, m
>
>
>
>
>
>
>
>
>[[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] Confidence interval for response variable in mixed effects models

2010-10-30 Thread David Winsemius


On Oct 30, 2010, at 11:33 AM, Brian Willis wrote:


HI,

I am using lmer() for a simple mixed effects model. The model is of  
the form
logit(y)~ x + (1|z), where x is an indicator variable and z a multi- 
level

factor.

I would like an estimate of the response variable (either y or logit  
y)


There is a fitted method for objects of class "mer".

?"mer-class"


 with an associated confidence interval for a given value of x.


That is the sticking point as I understand it. See below.


There does not appear to be a predict function written for lmer().

The output for the fixed effects gives a standard error for the  
intercept,
the coefficient of x and the correlation. For n observations, I  
transform
the std errors to variances, and with the correlation, I think I can  
use the
formula Var(intercept + x) = Var(intercept) + Var(x) +  
2Cov(x,intercept) to
get the variance of the fixed effects component of the response  
variable.


However, I would like to include the random effects component of the
variance, so I may derive a standard error and confidence interval  
for the

variance.

Does anyone know how to do this? Is there a ready made function like
predict() or does anyone know how to incorporate the variance of  
random

effects term to derive the std error of the response variable?


I see Ben Bolker has offered a suggestion that you search the mixed  
models list.


An earlier question on this topic elicited this citation (from Bolker):

http://glmm.wikidot.com/faq

One of the available choices in Baron's search page is R-sig-mixed- 
models and here are a few links to threads (by people who know more  
than me) that may offer at least informed commentary and options if  
not a general solution (from  both R-help and the SIG-ME archives):


http://search.r-project.org/cgi-bin/namazu.cgi?query=+confidence+intervals+lmer&max=100&result=normal&sort=score&idxname=functions&idxname=Rhelp08&idxname=Rhelp10&idxname=R-sig-mixed-models&idxname=Rhelp02

http://finzi.psych.upenn.edu/Rhelp10/2008-May/161516.html

http://rwiki.sciviews.org/doku.php?id=guides:lmer-tests

http://finzi.psych.upenn.edu/R/Rhelp02/archive/76742.html

http://finzi.psych.upenn.edu/R/Rhelp02/archive/81237.html

http://finzi.psych.upenn.edu/R/Rhelp02/archive/82567.html

--

David Winsemius, MD
West Hartford, CT

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


[R] summary.lm for post-hoc tests

2010-10-30 Thread Alex Bokov
Let's say I've run Anova(lm(y~a*b)) and found the a:b interaction to be 
significant. Now I'm interested in which specific level combinations of 
a and b significantly differ from the control group. Can I use the 
t-tests from summary(lm(y~a*b)) to answer that question?


I saw no mention of multiple comparison in the documentation for 
summary.lm, so am I right in assuming I need to run p.adjust on the 
p-values column?


Thanks.

PS: I am aware of TukeyHSD and that works fine if a and b are both 
factors. However, if 'a' is numeric and I'm interested in which levels 
of 'b' have a different slope from the control group, TukeyHSD cannot do 
that, and I'm hoping the above can.


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

2010-10-30 Thread julien cuisinier

Hi List,



Is there any way to pass on directly VBA variable content into a R variable? 

on windows XP & using R 2.12.0
I have installed RExcel addin (with associated D(COM)) 
>> It function fine when trying to pass Excel Range to R but I failed (sorry if 
>> it is only my own limitation, search till now unsuccessful) to find out how 
>> to pass directly VBA array into R

Below an example - sorry it is VBA - including a very simple call to R
>> The below code function perfectly, my question is: How could I pass directly 
>> DblArray into R variable "test"
>> So it would be something like: Call RInterface.PutArray("test", DblArray)

>> But as could be expected I have an error because the RInterface.PutArray() 
>> is expecting an Excel range as second argument


Any hint very appreciated!


Thanks & regards,
Julien Cuisinier




Sub Demo1()


Dim i   As Long
Dim j   As Long
Dim ElementsAs Long

Dim Start   As Double
Dim Length  As Double
Dim DblMedian   As Double
Dim DblArray() As Double

Dim RngData As Range
Dim RngData2As Range

Set RngData = Range("A1:A10")

Set RngData2 = Range("B1")

Elements = 100
ReDim DblArray(0 To Elements - 1)
For i = 0 To Elements - 1
DblArray(i) = Rnd()
Next i


Start = Timer
Call RInterface.StartRServer
Call RInterface.PutArray("test", RngData)
Call RInterface.RRun("z<-median(test)")
Call RInterface.GetArray("z", RngData2)
Call RInterface.StopRServer

'Range("B1") = RngData2
Length = Length + Timer - Start
Debug.Print Length


End Sub


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

2010-10-30 Thread Matevž Pavlič
Just one more thing...
I get a list with 15 data.frames :

List of 15
 $ 1:'data.frame':  7 obs. of  9 variables:
  ..$ vrtina : Factor w/ 6 levels "T1A-1","T1A-2",..: 1 1 2 2 5 5 5
  ..$ globina.meritve: num [1:7] 7.6 8.5 10.4 17.4 12.5 15.5 16.5
  ..$ E0 : num [1:7] 4109 2533 491 810 2374 ...
  ..$ Eur1   : num [1:7] 6194 4713 605 1473 NA ...
  ..$ Eur2   : num [1:7] 3665 7216 266 4794 7387 ...
  ..$ Eur3   : num [1:7] 3221 3545 920 3347 6768 ...
  ..$ H  : num [1:7] 8 5.9 5.9 6.9 9.3 10.9 10
  ..$ Mpl: num [1:7] 61.9 136.7 19.9 96.4 178.5 ...
  ..$ class  : int [1:7] 1 1 1 1 1 1 1
.
.
.

But how would I acces them (i.e. to draw a plot for each data.frame for each 
data.frame in a list)?

Thanks,m

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Saturday, October 30, 2010 8:24 PM
To: Matevž Pavlič
Cc: r-help@r-project.org
Subject: Re: [R] for loop


On Oct 30, 2010, at 2:07 PM, Matevž Pavlič wrote:

> Hi,
>
> I know this is probalby a very trivial thing to do for most of the R 
> users, but since I just strated using it I have some problems
>
> I have a data.frame with a field called "razred". This field has 
> values from 1 up to 15.
>
> Is it possible to create a for loop that would create a new data frame 
> for each of the "razred" values.

The R-way would be to use the split function and leave the result in a list to 
which the same operation could be also repeatedly performed using lapply.

?split

And take a look at the fourth example applying split to the builtin airquality 
dataframe.

The plyr package also provides functions on dataframes.

-- 

David Winsemius, MD
West Hartford, CT

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


Re: [R] for loop

2010-10-30 Thread David Winsemius


On Oct 30, 2010, at 3:00 PM, Matevž Pavlič wrote:


Just one more thing...
I get a list with 15 data.frames :

List of 15
$ 1:'data.frame':  7 obs. of  9 variables:
 ..$ vrtina : Factor w/ 6 levels "T1A-1","T1A-2",..: 1 1 2 2  
5 5 5

 ..$ globina.meritve: num [1:7] 7.6 8.5 10.4 17.4 12.5 15.5 16.5
 ..$ E0 : num [1:7] 4109 2533 491 810 2374 ...
 ..$ Eur1   : num [1:7] 6194 4713 605 1473 NA ...
 ..$ Eur2   : num [1:7] 3665 7216 266 4794 7387 ...
 ..$ Eur3   : num [1:7] 3221 3545 920 3347 6768 ...
 ..$ H  : num [1:7] 8 5.9 5.9 6.9 9.3 10.9 10
 ..$ Mpl: num [1:7] 61.9 136.7 19.9 96.4 178.5 ...
 ..$ class  : int [1:7] 1 1 1 1 1 1 1
.
But how would I acces them (i.e. to draw a plot for each data.frame  
for each data.frame in a list)?


Something along the lines of one of these:

lapply(dfrm.list, function(xfrm) with(xfrm, plot(Mpl, E0) ) )

lapply(dfrm.list, function(xfrm) plot(E0 ~ Mpl, data=xfrm) ) )

... assuming you wanted a scatterplot. If you wanted them all on one  
page, then see:


?layout

If you used lattice or ggplot plotting function they do not work via  
side-effects and so you could assign the results creating a list of  
plots.


--
DAvid.




Thanks,m

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net]
Sent: Saturday, October 30, 2010 8:24 PM
To: Matevž Pavlič
Cc: r-help@r-project.org
Subject: Re: [R] for loop


On Oct 30, 2010, at 2:07 PM, Matevž Pavlič wrote:


Hi,

I know this is probalby a very trivial thing to do for most of the R
users, but since I just strated using it I have some problems

I have a data.frame with a field called "razred". This field has
values from 1 up to 15.

Is it possible to create a for loop that would create a new data  
frame

for each of the "razred" values.


The R-way would be to use the split function and leave the result in  
a list to which the same operation could be also repeatedly  
performed using lapply.


?split

And take a look at the fourth example applying split to the builtin  
airquality dataframe.


The plyr package also provides functions on dataframes.

--

David Winsemius, MD
West Hartford, CT



David Winsemius, MD
West Hartford, CT

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


Re: [R] R & VBA

2010-10-30 Thread RICHARD M. HEIBERGER
Look at the macro
RInterface.PutArrayFromVBA
documented in the RExcel help file.

Please send followup questions on RExcel and statconnDCOM to
the mailing list at

"statconnDCOM, rcom, and RExcel server related issues" <
rco...@mailman.csd.univie.ac.at>
Rich
On Sat, Oct 30, 2010 at 1:44 PM, julien cuisinier
wrote:

>
> Hi List,
>
>
>
> Is there any way to pass on directly VBA variable content into a R
> variable?
>

[[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] date calculation

2010-10-30 Thread Shi, Tao
Hi Ben and Josh,

No, I don't think that there is a bug.  It's just due to my lack of knowledge 
on Date class, I was simply amazed that it has the daylight saving time built 
in at first.  But on the second thought, it really should.

Thank you all for the explanations!

...Tao




From: Ben Bolker 
To: "Shi, Tao" 
Cc: "r-h...@stat.math.ethz.ch" 
Sent: Saturday, October 30, 2010 7:22:04 AM
Subject: Re: [R] date calculation

On 10-10-30 02:02 AM, Shi, Tao wrote:
> Hi Ben,
> 
> That must be the case!  In fact if I do:
> 
>> difftime(strptime("24NOV2004", format="%d%b%Y"), 
>> strptime("13MAY2004",format="%d%b%Y"), units="days", tz="GMT")
> Time difference of 195 days
> 
> 
> which supports your claim.
> 
> Can someone from the R development team confirm this?
> 
> Thanks!
> 
> ...Tao
> 
> 

   It sounds like you think this is a bug.  It's not (although it's
arguably not what you want).  The general advice when using dates and
time in R is to use the *least* specific date format that will do what
you want, i.e. don't use a format that incorporates time zone
information (daylight savings time) information if you don't want to
deal with these complexities.

I would suggest the chron package:

library(chron)
diff(chron(dates.=c("24/11/2004","13/05/2004"),format="d/m/y"))

> 
> 
> 
> - Original Message -
>> From:Ben Bolker 
>> To:r-h...@stat.math.ethz.ch
>> Cc:
>> Sent:Friday, October 29, 2010 7:54:53 PM
>> Subject:Re: [R] date calculation
>>
>>
>> Shi, Tao  
>> href="http://yahoo.com";>yahoo.com> writes:
> 
>> Could someone 
>> explain to me why the following result is not a integer?
>>
>>>
>> difftime(strptime("24NOV2004", format="%d%b%Y"), strptime("13MAY2004", 
>>
>>> format="%d%b%Y"), units="days")
>> Time difference of 195.0417 
>> days
> 
>   Presumably because this goes across a daylight-savings 
>> time
> adjustment?  0.0417=1/24 days is 1 hour ...
> 
>   Ben 
>> Bolker
> 
> __
> 
>> ymailto="mailto:R-help@r-project.org"; 
>> href="mailto:R-help@r-project.org";>R-help@r-project.org mailing list
> 
>> href="https://stat.ethz.ch/mailman/listinfo/r-help"; target=_blank 
>>> https://stat.ethz.ch/mailman/listinfo/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] date calculation

2010-10-30 Thread Shi, Tao
I think this demonstrate on of the differences between Class 'Date' and 
'POSIXlt'.  Thanks, Marc!

...Tao




From: Marc Schwartz 
To: Ben Bolker 
Cc: "Shi, Tao" ; "r-h...@stat.math.ethz.ch" 

Sent: Saturday, October 30, 2010 7:48:05 AM
Subject: Re: [R] date calculation


On Oct 30, 2010, at 9:22 AM, Ben Bolker wrote:

> On 10-10-30 02:02 AM, Shi, Tao wrote:
>> Hi Ben,
>> 
>> That must be the case!  In fact if I do:
>> 
>>> difftime(strptime("24NOV2004", format="%d%b%Y"), 
>>> strptime("13MAY2004",format="%d%b%Y"), units="days", tz="GMT")
>> Time difference of 195 days
>> 
>> 
>> which supports your claim.
>> 
>> Can someone from the R development team confirm this?
>> 
>> Thanks!
>> 
>> ...Tao
>> 
>> 
> 
>   It sounds like you think this is a bug.  It's not (although it's
> arguably not what you want).  The general advice when using dates and
> time in R is to use the *least* specific date format that will do what
> you want, i.e. don't use a format that incorporates time zone
> information (daylight savings time) information if you don't want to
> deal with these complexities.
> 
> I would suggest the chron package:
> 
> library(chron)
> diff(chron(dates.=c("24/11/2004","13/05/2004"),format="d/m/y"))

Ben,

If time and time zone are not relevant, any reason not to use:


> diff(as.Date(c("13/05/2004", "24/11/2004"), format = "%d/%m/%Y"))
Time difference of 195 days


or perhaps conceptually easier:

Date2 <- as.Date("24/11/2004", format = "%d/%m/%Y")
Date1 <- as.Date("13/05/2004", format = "%d/%m/%Y")

> Date2 - Date1
Time difference of 195 days


R has built in arithmetic operations for such dates, without the need to use 
another package, since they are effectively numerics with a Date class:

> str(Date1)
Class 'Date'  num 12551

> str(Date2)
Class 'Date'  num 12746


?

HTH,

Marc Schwartz



>> 
>> 
>> 
>> - Original Message -
>>> From:Ben Bolker 
>>> To:r-h...@stat.math.ethz.ch
>>> Cc:
>>> Sent:Friday, October 29, 2010 7:54:53 PM
>>> Subject:Re: [R] date calculation
>>> 
>>> 
>>> Shi, Tao  
>>> href="http://yahoo.com";>yahoo.com> writes:
>> 
>>> Could someone 
>>> explain to me why the following result is not a integer?
>>> 
 
>>> difftime(strptime("24NOV2004", format="%d%b%Y"), strptime("13MAY2004", 
>>> 
 format="%d%b%Y"), units="days")
>>> Time difference of 195.0417 
>>> days
>> 
>>  Presumably because this goes across a daylight-savings 
>>> time
>> adjustment?  0.0417=1/24 days is 1 hour ...
>> 
>>  Ben 
>>> Bolker


  
[[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] summary.lm for post-hoc tests

2010-10-30 Thread Dimitri Liakhovitski
Check this out:

http://www.rforge.net/doc/packages/NCStats/compSlopes.html

However, it looks like one need to install NCStats
(http://www.rforge.net/NCStats/files/).
Or is there a more "mainstream" method of running multiples
comparisons among slopes?

Dimitri


On Sat, Oct 30, 2010 at 1:20 PM, Alex Bokov  wrote:
> Let's say I've run Anova(lm(y~a*b)) and found the a:b interaction to be
> significant. Now I'm interested in which specific level combinations of a
> and b significantly differ from the control group. Can I use the t-tests
> from summary(lm(y~a*b)) to answer that question?
>
> I saw no mention of multiple comparison in the documentation for summary.lm,
> so am I right in assuming I need to run p.adjust on the p-values column?
>
> Thanks.
>
> PS: I am aware of TukeyHSD and that works fine if a and b are both factors.
> However, if 'a' is numeric and I'm interested in which levels of 'b' have a
> different slope from the control group, TukeyHSD cannot do that, and I'm
> hoping the above can.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Dimitri Liakhovitski
Ninah Consulting
www.ninah.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] two group cox model

2010-10-30 Thread cheba meier
Dear all,

I am doing

library(survival)
fit   <- coxph(Surv(futime,fustat) ~ rx, ovarian)

plot(survfit(fit,newdata=ovarian),col=c(1,2))
legend("bottomleft", legend=c("rx = 0", "rx = 1"),
   lty=c(1,2),col=c(1,2))
Is this correct to compare these two groups? Is the 0.31 the p-value that
the median f two groups are equal
Why lty does not work here?

Many thanks in advance.
Cheba

[[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] doubt in climate variability analysis in R! - code included!

2010-10-30 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of govin...@msu.edu
> Sent: Friday, October 29, 2010 11:56 AM
> To: r-help@r-project.org
> Subject: Re: [R] doubt in climate variability analysis in R! - code
> included!
> 
> 
> 
> the following code was used 
> 
> library(akima)
> library(clim.pact)
> nc.1 <- "RF_80-05.nc"
> nc.rf.in <- open.ncdf(nc.1)
> 
> x1 <- retrieve.nc(nc.1, v.nam="Rainfall",l.scale=FALSE,  x.rng=c(70,
> 80), y.rng=c(10, 13.5))
> 
> #dimension is checked for the subset. (lon, lat, time) is changed as
> (time, lat, lon)
> >dim(x1$dat)
> #[1] 2192    8   20
> 
> My question is - how can i convert this array into a dataframe so that
> i have "lat", "lon", "precipitation values" in 3 different columns
> (note, I will have it for just a single day). So, my expected dataframe
> will have rainfall values for each given pair of "lon" and "lat".
> 
> Or is there any other better way to do my spatial variogram analysis
> for a single day given the above dataset?
> 
> here is the link for the dataset.
> HTTP://WWW.4SHARED.COM/FILE/4ZV0G3JR/RF_80-85.HTML
> 

The link to the data did not work, so we still don't have a self-contained, 
reproducible example.

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204


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


Re: [R] summary.lm as a post-hoc test?

2010-10-30 Thread Alex Bokov



On 10/30/2010 03:34 PM, Dimitri Liakhovitski wrote:

You are asking a statistics question, not an R question. R-list people
never react to such posts.
Or they give you a nasty reply of the type: "Do you homework first,
and then ask questions here."
   
Good point. I thought it was an R question because it was about 
confirming what the output of an R function actually represents, and it 
is not explicitly documented in the help file. I was about 80% sure that 
it is what you just confirmed it to be in your answer, but I didn't want 
to yet again make an assumption about the behavior of this software that 
I'd have to retract later. I am going to hold on to my assumption that 
no multiple comparison corrections were done and it's up to me to do that.

Each of the t tests for b:c2, b:c3, and b:c4 test the null hypotheses:
difference in slopes of a onto b between groups scored c2 (or c3 or
c4) and the group scored c1 is equal to zero.

Yes! This is precisely the hypothesis I'm testing at the moment.

The package I refered to seems to be what you want.
   
Thank you, I will look into that because most of the time I really do 
need to do pairwise tests of all combinations. Just not this time.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] doubt in climate variability analysis in R! - code included!

2010-10-30 Thread govindas


--- Begin Message ---

   I am sorry, i think the link was broken..! here is the correct one!!![1]
   http://www.4shared.com/file/4zV0g3JR/RF_80-85.htmlÂ

   --
   Regards,
   Mahalakshmi
   Graduate Student
   #20, Department of Geography
   Michigan State University
   East Lansing, MI 48824
   Quoting "Nordlund, Dan (DSHS/RDA)" :
   >> -Original Message-
   >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
   >> project.org] On Behalf Of govin...@msu.edu
   >> Sent: Friday, October 29, 2010 11:56 AM
   >> To: r-help@r-project.org
   >> Subject: Re: [R] doubt in climate variability analysis in R! - code
   >> included!
   >>
   >>
   >>
   >> the following code was used 
   >>
   >> library(akima)
   >> library(clim.pact)
   >> nc.1 <- "RF_80-05.nc"
   >> nc.rf.in <- open.ncdf(nc.1)
   >>
   >> x1 <- retrieve.nc(nc.1, v.nam="Rainfall",l.scale=FALSE,  x.rng=c(70,
   >> 80), y.rng=c(10, 13.5))
   >>
   >> #dimension is checked for the subset. (lon, lat, time) is changed as
   >> (time, lat, lon)
   >> >dim(x1$dat)
   >> #[1] 2192Â Â Â  8Â Â  20
   >>
   >> My question is - how can i convert this array into a dataframe so that
   >> i have "lat", "lon", "precipitation values" in 3 different columns
   >> (note, I will have it for just a single day). So, my expected dataframe
   >> will have rainfall values for each given pair of "lon" and "lat".
   >>
   >> Or is there any other better way to do my spatial variogram analysis
   >> for a single day given the above dataset?
   >>
   >> here is the link for the dataset.
   >> [2]HTTP://WWW.4SHARED.COM/FILE/4ZV0G3JR/RF_80-85.HTML
   >>
   >
   > The link to the data did not work, so we still don't have a
   > self-contained, reproducible example.
   >
   > Dan
   >
   > Daniel J. Nordlund
   > Washington State Department of Social and Health Services
   > Planning, Performance, and Accountability
   > Research and Data Analysis Division
   > Olympia, WA 98504-5204
   >
   >
   >

References

   1. http://www.4shared.com/file/4zV0g3JR/RF_80-85.html
   2. http://WWW.4SHARED.COM/FILE/4ZV0G3JR/RF_80-85.HTML
--- End Message ---
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] ForestPlot or similar

2010-10-30 Thread Matt Shotwell
Here is a small function for forest plots in R, with an example:

http://biostatmatt.com/wiki/r-credplot

-Matt

On Sat, 2010-10-30 at 11:40 -0400, Mestat wrote:
> Here is one example:
> I have three vectors (mean,lower interval, upper interval)
> mean<-c(2,4,6,8)
> l<-c(1,2,3,4)
> u<-c(4,8,12,16)
> How would I plot that if I want to use the FORESTPLOT function. I dont need
> to use the TABLETEXT option.
> I am working in something like this:
> tabletext<-c(NA,NA,NA,NA,NA)
> mean<-c(NA,2,4,6,8)
> l<-c(NA,1,2,3,4)
> u<-c(NA,4,8,12,16)
> forestplot(tabletext,mean,l,u,zero=0)
> But I am having a problem with the length of the dimension...
> Thanks in advance,
> Marcio
> 

-- 
Matthew S. Shotwell
Graduate Student 
Division of Biostatistics and Epidemiology
Medical University of South Carolina

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


Re: [R] summary.lm as a post-hoc test?

2010-10-30 Thread Dimitri Liakhovitski
Then look at that package I referred in the other e-mail. It does
exactly what you need - I am just not sure if it's still available.
The author's e-mail is there, though - you can ask.
Good luck.
Dimitri

On Sat, Oct 30, 2010 at 5:04 PM, Alex Bokov  wrote:
>
>
> On 10/30/2010 03:34 PM, Dimitri Liakhovitski wrote:
>>
>> You are asking a statistics question, not an R question. R-list people
>> never react to such posts.
>> Or they give you a nasty reply of the type: "Do you homework first,
>> and then ask questions here."
>>
>
> Good point. I thought it was an R question because it was about confirming
> what the output of an R function actually represents, and it is not
> explicitly documented in the help file. I was about 80% sure that it is what
> you just confirmed it to be in your answer, but I didn't want to yet again
> make an assumption about the behavior of this software that I'd have to
> retract later. I am going to hold on to my assumption that no multiple
> comparison corrections were done and it's up to me to do that.
>>
>> Each of the t tests for b:c2, b:c3, and b:c4 test the null hypotheses:
>> difference in slopes of a onto b between groups scored c2 (or c3 or
>> c4) and the group scored c1 is equal to zero.
>
> Yes! This is precisely the hypothesis I'm testing at the moment.
>>
>> The package I refered to seems to be what you want.
>>
>
> Thank you, I will look into that because most of the time I really do need
> to do pairwise tests of all combinations. Just not this time.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Dimitri Liakhovitski
Ninah Consulting
www.ninah.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] two group cox model

2010-10-30 Thread David Winsemius


On Oct 30, 2010, at 4:36 PM, cheba meier wrote:


Dear all,

I am doing

library(survival)
fit   <- coxph(Surv(futime,fustat) ~ rx, ovarian)

plot(survfit(fit,newdata=ovarian),col=c(1,2))
legend("bottomleft", legend=c("rx = 0", "rx = 1"),
  lty=c(1,2),col=c(1,2))
Is this correct to compare these two groups?


Is this a trick question?


Is the 0.31 the p-value that
the median f two groups are equal


That seems unlikely because one of the curves has not even reached the  
median. You might want to look at


?anova.coxph


Why lty does not work here?


Perhaps you should define "not work". It seems to create a solid and  
dashed line in the legend when I use it.


?par # 1=solid (default), 2=dashed,




Many thanks in advance.
Cheba




David Winsemius, MD
West Hartford, CT

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


Re: [R] compare quality of clustering methods?

2010-10-30 Thread Tal Galili
It depends on how your clustered objects are stored.

As written here: http://www.statmethods.net/advstats/cluster.html

The function *cluster.stats() *in the
*fpc
* package provides a mechanism for comparing the similarity of two cluster
solutions using a variety of validation criteria (Hubert's gamma
coefficient, the Dunn index and the corrected rand index)

I see there is no mention of this topic (of the comparison of clustering
solutions) on the clustering task views (
http://cran.r-project.org/web/views/Cluster.html), I hope it would get
extended in the future.


Best,
Tal



Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Sat, Oct 30, 2010 at 5:10 PM, Khanh Nguyen wrote:

> Hi,
>
> Suppose I want to compare the results of two clustering methods, what
> is the best way to do it? Thanks
>
> Regards,
>
> -k
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] For loop

2010-10-30 Thread Tal Galili
I can't see how to vectorized your code, maybe it's possible.

That leaves you with either using parallel processing (for example using the
foreach package)

Or, If you know C, you could put that calculation into a C code inside the R
code using Rcpp.

There was a recent video on the topic on a google tech talk:
http://www.r-bloggers.com/integrating-r-with-c-rcpp-rinside-and-rprotobuf/

That's all I can think of, sorry...

Tal


Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




2010/10/30 20c <2...@email.it>

> Hi all,
>
> how can i make the following loop faster?
>
> vv[20001,22]=v[20001,22]
> for(k in 21:1) {
>  for(j in 20001:2) {
>   vv[j-1,k+1]=min(xx[j-1]*v[j-1,k+1],vv[j,k+1])
>   v[j,k]=h[1,k]+vv[j-1,k+1]
>  }
> vv[20001,k]=v[20001,k]
> }
>
>
>
> Thanks
>
> Lorenzo
>
>
>
>
>
>  --
>
>  Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP
> autenticato? GRATIS solo con Email.it http://www.email.it/f
>
>
>
>  Sponsor:
>
>  Idee Regalo Personalizzate a partire da euro 3.90! Su MisterCupido.com
> alta qualitя a prezzi imbattibili... e questa settimana GRATIS per te, la
> confezione regalo!
>
>  Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=11027&d=30-10
>
>
>[[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] For loop

2010-10-30 Thread Joshua Wiley
Hi,

In general, the way to speed up for loops in R is to avoid them.  It
looks like some of the operations could be vectorized (e.g., h[1,k] +
vv[j-1,k+1] looks like you could just add entire columns at once).  If
you provide sample data for all the variables in your loop, it will be
possible to give you more detailed feedback.

Cheers,

Josh

2010/10/30 20c <2...@email.it>:
> Hi all,
>
> how can i make the following loop faster?
>
> vv[20001,22]=v[20001,22]
> for(k in 21:1) {
>  for(j in 20001:2) {
>   vv[j-1,k+1]=min(xx[j-1]*v[j-1,k+1],vv[j,k+1])
>   v[j,k]=h[1,k]+vv[j-1,k+1]
>  }
> vv[20001,k]=v[20001,k]
> }
>
>
>
> Thanks
>
> Lorenzo
>
>
>
>
>
>  --
>
>  Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP 
> autenticato? GRATIS solo con Email.it http://www.email.it/f
>
>
>
>  Sponsor:
>
>  Idee Regalo Personalizzate a partire da euro 3.90! Su MisterCupido.com alta 
> qualitя a prezzi imbattibili... e questa settimana GRATIS per te, la 
> confezione regalo!
>
>  Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=11027&d=30-10
>
>
>        [[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.
>
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.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] return value for grep

2010-10-30 Thread Ulrich

Hi,

is it possible to easily change the return value for the grep function  
for cases where there is no match, for example the value 0 or "No"  
instead of integer (0) )?


Thanks, Uli

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

2010-10-30 Thread David Winsemius


On Oct 30, 2010, at 10:51 PM, Ulrich wrote:


Hi,

is it possible to easily change the return value for the grep  
function for cases where there is no match, for example the value 0  
or "No" instead of integer (0) )?




Seems like is should be  pretty easy. Test for length(grep(...)) == 0  
or equivalently !length(grep(...))


> gvec <- function(patt, x) sapply (x, function(y) if ( ! 
length(grep(patt, y)) ) {"No"} else {grep(patt, y)} )

> gvec("b", c("abc", "abc\n"))
  abc abc\n
1 1
> gvec("\n", c("abc", "abc\n"))
  abc abc\n
 "No"   "1"

--

David Winsemius, MD
West Hartford, CT

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


Re: [R] for loop

2010-10-30 Thread Dennis Murphy
Hi:

If your objective is to make 15 plots, one for each level of razred, then
you don't need to make 15 individual data frames first. The lattice and
ggplot2 packages allow conditioning plots. You haven't mentioned what types
of plots you're interested in getting, but if it's something simple like a
scatterplot of y vs. x for each level of razred, it's not that hard to do.
Let's fake some data:

d <- data.frame(razred = rep(LETTERS[1:15], each = 10),
   x = rep(1:10, 15),
   y = rep(2 + 0.5 * 1:10, 15) + rnorm(150))

d has 15 levels of razred with 10 observations at each level. razred is a
factor, the other variables are either integer or numeric.

Produce scatterplots of y vs. x for each level of razred, using both the
lattice and ggplot2 packages:

library(lattice)
# each plot adds a new feature - run one plot at a time.
xyplot(y ~ x | razred, data = d, type = c('p', 'r'))
xyplot(y ~ x | razred, data = d, type = c('p', 'r'), layout = c(3, 5))
xyplot(y ~ x | razred, data = d, type = c('p', 'r'), layout = c(3, 5),
as.table = TRUE)

library(ggplot2)
ggplot(d, aes(x, y)) + geom_point() + geom_smooth(method = 'lm') +
facet_wrap( ~ razred, ncol = 3)
ggplot(d, aes(x, y)) + geom_point() + geom_smooth(method = 'lm', se = FALSE)
+
   facet_wrap( ~ razred, ncol = 3)

If instead you want something like a scatterplot matrix for each data subset
defined by level of razred, then maybe something like this (?):

# add a new variable to the data frame
# splom is the scatterplot matrix function in lattice
d$z1 <- rnorm(150)
splom(~ d[, -1] | razred, data = d, layout = c(2, 2, 4))

Just guessing here since you didn't make your objective explicit.

It's entirely possible that you can conduct a significant part of your data
analysis without having to split the data into subsets. Several summary
functions, for example, can compute a number of summary functions by group
with a one-line call. Here are a couple of examples, one using aggregate()
from the base package and another using function ddply() from the plyr
package:

aggregate(y ~ razred, data = d, FUN = mean)
   razredy
1   A 4.816841
2   B 4.520804
3   C 5.196329
4   D 4.615575
5   E 3.982240
6   F 4.466559
7   G 4.938669
8   H 4.539541
9   I 4.354991
10  J 4.573654
11  K 4.450624
12  L 5.138087
13  M 4.93
14  N 4.879493
15  O 5.087452

library(plyr)
ddply(d, 'razred', summarise, mx = mean(x), my = mean(y), mz1 = mean(z1))
   razred  mx   my mz1
1   A 5.5 4.816841 -0.01745305
2   B 5.5 4.520804  0.24724069
3   C 5.5 5.196329  0.18717750
4   D 5.5 4.615575  0.18885590
5   E 5.5 3.982240 -0.91284339
6   F 5.5 4.466559  0.36479266
7   G 5.5 4.938669 -0.36359562
8   H 5.5 4.539541  0.06061162
9   I 5.5 4.354991  0.05138409
10  J 5.5 4.573654  0.31160018
11  K 5.5 4.450624  0.17458712
12  L 5.5 5.138087 -0.26482357
13  M 5.5 4.93 -0.39194953
14  N 5.5 4.879493  0.33154075
15  O 5.5 5.087452  0.32816931

There are a number of functions and packages that will do this sort of thing
quite well - I'll mention doBy, data.table, Hmisc and sqldf as excellent
options, noting that there are other packages and functions in the apply
family that can perform groupwise processing seamlessly. The point of
mentioning this is so that you don't automatically think you have to split
the data in myriad ways before you can process a function. The good folks
that designed this language, and the many people who have contributed code
to the R project, are pretty smart, and have devised fairly simple ways to
process data, even if it's large.

Of course, it's always possible that splitting is necessary; if you're
willing to be a little more forthcoming about your analysis goals, you might
get a better targeted response..

HTH,
Dennis


On Sat, Oct 30, 2010 at 12:00 PM, Matev¾ Pavliè wrote:

> Just one more thing...
> I get a list with 15 data.frames :
>
> List of 15
>  $ 1:'data.frame':  7 obs. of  9 variables:
>  ..$ vrtina : Factor w/ 6 levels "T1A-1","T1A-2",..: 1 1 2 2 5 5 5
>  ..$ globina.meritve: num [1:7] 7.6 8.5 10.4 17.4 12.5 15.5 16.5
>  ..$ E0 : num [1:7] 4109 2533 491 810 2374 ...
>  ..$ Eur1   : num [1:7] 6194 4713 605 1473 NA ...
>  ..$ Eur2   : num [1:7] 3665 7216 266 4794 7387 ...
>  ..$ Eur3   : num [1:7] 3221 3545 920 3347 6768 ...
>  ..$ H  : num [1:7] 8 5.9 5.9 6.9 9.3 10.9 10
>  ..$ Mpl: num [1:7] 61.9 136.7 19.9 96.4 178.5 ...
>  ..$ class  : int [1:7] 1 1 1 1 1 1 1
> .
> .
> .
>
> But how would I acces them (i.e. to draw a plot for each data.frame for
> each data.frame in a list)?
>
> Thanks,m
>
> -Original Message-
> From: David Winsemius [mailto:dwinsem...@comcast.net]
> Sent: Saturday, October 30, 2010 8:24 PM
> To: Matev¾ Pavliè
> Cc: r-help@r-project.org
> Subject: Re: [R] for loop
>
>
> On Oct 30, 2010, 

Re: [R] return value for grep

2010-10-30 Thread Gabor Grothendieck
On Sat, Oct 30, 2010 at 10:51 PM, Ulrich  wrote:
> Hi,
>
> is it possible to easily change the return value for the grep function for
> cases where there is no match, for example the value 0 or "No" instead of
> integer (0) )?
>

Try this:

> Find(length, list(grep("X", letters), 0))
[1] 0
> Find(length, list(grep("X", LETTERS), 0))
[1] 24


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] make many barplot into one plot

2010-10-30 Thread Jim Lemon

On 10/29/2010 11:33 PM, "Sibylle Stöckli" wrote:

Dear R users


I would like to group my barplot graph (see example on the R help link). The 
proposed R code, adding individual bars to the plot, looks really overwhelming. 
My specific dataset just consists of five groups and three different levels 
within each groups (the individual bars). The .txt file is read as matrix 
(horizontal: group, vertical: levels).

The R trellis barchart (function group="") is an easy function, but 
unfortunately the upper plot part look much different from other graphs. I would 
therefore prefer barplot to stansdardize my plots within the manuscript.

It would be very  helpful for me to know if anyone else has worked on the 
barplot group function.


Hi Sibylle,
I think you want something like barNest (plotrix). It will plot nested 
bars to whatever depth of nesting you want (although I don't think 
anyone would want more than three or four levels), and you can just 
display the final level if you want. I am competely rewriting this 
function at the moment to make it more flexible, and there should be a 
new version of plotrix turning up soon. However, the present function 
will give you an idea of what it will do.


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] return value for grep

2010-10-30 Thread David Winsemius


On Oct 30, 2010, at 11:13 PM, David Winsemius wrote:



On Oct 30, 2010, at 10:51 PM, Ulrich wrote:


Hi,

is it possible to easily change the return value for the grep  
function for cases where there is no match, for example the value 0  
or "No" instead of integer (0) )?




Seems like is should be  pretty easy. Test for length(grep(...)) ==  
0 or equivalently !length(grep(...))


> gvec <- function(patt, x) sapply (x, function(y) if ( ! 
length(grep(patt, y)) ) {"No"} else {grep(patt, y)} )

> gvec("b", c("abc", "abc\n"))
 abc abc\n
   1 1
> gvec("\n", c("abc", "abc\n"))
 abc abc\n
"No"   "1"



It later occurred to me that you might only want the alternate  
behavior when no matches were present:


gvec2 <- function(patt, x) if ( !length(grep(patt, y)) ) {0} else  
{grep(patt, y)}


> gvec2 <- function(patt, x) if ( length(grep(patt, x))==0 ) {0} else  
{grep(patt, x)}

> grep("\n", c("abc", "abc\n"))
[1] 2
> gvec2("\n", c("abc", "abc"))
[1] 0



--

David Winsemius, MD
West Hartford, CT


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


[R] Fwd: ForestPlot or similar

2010-10-30 Thread Abhijit Dasgupta

> From: Abhijit Dasgupta 
> Date: October 31, 2010 1:30:02 AM EDT
> To: Matt Shotwell 
> Subject: Re: [R] ForestPlot or similar
> 
> I just did something very similar using ggplot's pointrange geom. In the 
> following, I'm plotting hazard ratios, for which the nominal value is 1 and 
> not 0. x has 5 columns: drug, hr, hr.lcb, hr.ucb, and group, and I'm faceting 
> by group.  If you want the plots horizontal, add coord_flip() to the command 
> --- as it stands the plots are vertically oriented. 
> 
>require(ggplot2)
>p <- ggplot(x, aes(x=drug, y = hr, ymin=hr.lcb, ymax=hr.ucb))+
>geom_pointrange()+ facet_grid(.~group)
>p <- p + xlab('Drug') + ylab('Hazard ratio')+
>geom_hline(y=1, col='red', lty=2)
> 
> 
> Abhijit
> On Oct 30, 2010, at 5:31 PM, Matt Shotwell wrote:
> 
>> Here is a small function for forest plots in R, with an example:
>> 
>> http://biostatmatt.com/wiki/r-credplot
>> 
>> -Matt
>> 
>> On Sat, 2010-10-30 at 11:40 -0400, Mestat wrote:
>>> Here is one example:
>>> I have three vectors (mean,lower interval, upper interval)
>>> mean<-c(2,4,6,8)
>>> l<-c(1,2,3,4)
>>> u<-c(4,8,12,16)
>>> How would I plot that if I want to use the FORESTPLOT function. I dont need
>>> to use the TABLETEXT option.
>>> I am working in something like this:
>>> tabletext<-c(NA,NA,NA,NA,NA)
>>> mean<-c(NA,2,4,6,8)
>>> l<-c(NA,1,2,3,4)
>>> u<-c(NA,4,8,12,16)
>>> forestplot(tabletext,mean,l,u,zero=0)
>>> But I am having a problem with the length of the dimension...
>>> Thanks in advance,
>>> Marcio
>>> 
>> 
>> -- 
>> Matthew S. Shotwell
>> Graduate Student 
>> Division of Biostatistics and Epidemiology
>> Medical University of South Carolina
>> 
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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] Constrained Regression

2010-10-30 Thread Jim Silverton
Hello everyone,
I have 3 variables Y, X1 and X2. Each variables lies between 0 and 1. I want
to do a constrained regression such that a>0 and (1-a) >0

for the model:

Y = a*X1 + (1-a)*X2

I tried the help on the constrained regression in R but I concede that it
was not helpful.

Any help is greatly appreciated
-- 
Thanks,
Jim.

[[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] make many barplot into one plot

2010-10-30 Thread Sibylle Stöckli
Dear R users


I would like to group my barplot graph (see example on the R help  
link). The proposed R code, adding individual bars to the plot, looks  
really overwhelming. My specific dataset just consists of five groups  
and three different levels within each groups (the individual bars).  
The .txt file is read as matrix (horizontal: group, vertical: levels).

The R trellis barchart (function group="") is an easy function, but  
unfortunately the upper plot part look much different from other  
graphs. I would therefore prefer barplot to stansdardize my plots  
within the manuscript.

It would be very  helpful for me to know if anyone else has worked on  
the barplot group function.

Thanks
Sibylle


http://onertipaday.blogspot.com/2007/05/make-many-barplot-into-one-plot.html

R code from the link
## I have 4 tables like this:satu <- array(c(5,15,20,68,29,54,84,119),  
dim=c(2,4), dimnames=list(c("Negative", "Positive"), c("Black",  
"Brown", "Red", "Blond")))dua <- array(c(50,105,30,8,29,25,84,9),  
dim=c(2,4), dimnames=list(c("Negative", "Positive"), c("Black",  
"Brown", "Red", "Blond")))tiga <- array(c(9,16,26,68,12,4,84,12),  
dim=c(2,4), dimnames=list(c("Negative", "Positive"), c("Black",  
"Brown", "Red", "Blond")))empat <- array(c(25,13,50,78,19,34,84,101),  
dim=c(2,4), dimnames=list(c("Negative", "Positive"), c("Black",  
"Brown", "Red", "Blond")))# rbind() the tables togetherTAB <-  
rbind(satu, dua, tiga, empat)# Do the barplot and save the bar  
midpointsmp <- barplot(TAB, beside = TRUE, axisnames = FALSE)# Add the  
individual bar labelsmtext(1, at = mp, text = c("N", "P"),line = 0,  
cex = 0.5)# Get the midpoints of each sequential pair of bars# within  
each of the four groupsat <- t(sapply(seq(1, nrow(TAB), by =  
2),function(x) colMeans(mp[c(x, x+1), ])))# Add the group labels !
for each pairmtext(1, at = at, text = rep(c("satu", "dua", "tiga",  
"empat"), 4),line = 1, cex = 0.75)# Add the color labels for each  
groupmtext(1, at = colMeans(mp), text = c("Black", "Brown", "Red",  
"Blond"), line = 2)
[[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.