[R] Nonlinear programming problem

2010-09-17 Thread Xiaoxi Gao

Hello useRs,

I'm using the command solnp in package Rsolnp to solve a general nonlinear 
programming problem. But I got an error that  the leading minor of order 15 is 
not positive definite
. Can anybody tell what may cause this error? Does it have something to do 
with the starting values? 

Thanks a lot!!!

Xiaoxi
  
[[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] Calculate difference between dates in years

2010-09-17 Thread nzcoops

Just expanding on Brians code to something that will work for vector.

age_years - function(first, second) 
{
 lt - data.frame(first, second)
 age - as.numeric(format(lt[,2],format=%Y)) -
as.numeric(format(lt[,1],format=%Y))
 first 
as.Date(paste(format(lt[,1],format=%Y),-,format(lt[,2],format=%m-%d),sep=))
 age[which(first 
as.Date(paste(format(lt[,1],format=%Y),-,format(lt[,2],format=%m-%d),sep=)))]
- age[which(first 
as.Date(paste(format(lt[,1],format=%Y),-,format(lt[,2],format=%m-%d),sep=)))]
- 1
 age
}
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Calculate-difference-between-dates-in-years-tp835196p2543380.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] Odp: Programming: loop versus vector oriented

2010-09-17 Thread Petr PIKAL
Hi Jan

but I think this is how your code really works. Did you try it?

Regards
Petr

Jan private jrheinlaen...@gmx.de napsal dne 16.09.2010 13:22:05:

 Hello Petr,
 
  If you want to get results of your function for a vector of reynolds 
and 
  dk you can use function outer and probably get rid of for cycle in the 

  function.
  
  outer(c(100, 530,2410), c(10, 150,200),lambda_wall)
[,1]   [,2]   [,3]
  [1,] 0.640 0.6400 0.6400
  [2,] 0.1207547 0.12075472 0.12075472
  [3,] 0.1081338 0.04515774 0.04515774
 
 that gives me an array as an answer (and does more calculations than
 necessary, in this case 9 instead of 3). The result should be a vector.
 
 The function should work on the nth elements of the two input vectors
 and put the result into the nth element of the output vector. So it
 would work like c - a + b, only instead of '+' there are more complex
 calculations.
 
 Best regards,
Jan
 
 
 


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Question: how to obtain the clusters of genes (basically the ones in the row dendrograms) from an object obtained by heatmap.2 function

2010-09-17 Thread Michael Bedward
Hello Sunny,

Defining groups at a given height can be done with the cut function
(see ?cut.dendrogram).

Unfortunately, cut doesn't give you the option of specifying a number
of clusters rather than a height in the way that cutree does for
hclust objects. Perhaps someone else here knows of a package that
includes a function to do this (I did a quick sos search but didn't
find anything obvious).  Otherwise you could examine the cut function
and try to hack a version that takes number of groups as an argument.
You can see the function's code with the command getS3method(cut,
dendrogram).

Sorry I can't help more. Being a simple soul I find hclust objects so
much easier to deal with !

Michael


On 17 September 2010 11:30, Sunny Srivastava research.b...@gmail.com wrote:
 Hello R-Helpers,
 I have a question about extracting the clusters of genes after we make the
 heatmap (say ht4) using the heatmap.2 function. Basically, I want to get the
 clusters which are shown as row dendrogram in the heatmap.

 I understand that ht4$rowDendrogram is an object of dendrogram and it
 containes details of all the nodes and branches, but lets say I want to know
 the number of clusters and the genes in each cluster if I terminated the
 tree (dendrogram) at a particular height. Also, if I know that I want 12
 clusters, how do I know which height I should terminate the tree (or
 branching structure)

 I am sorry if I am not clear. Please let me know if you need any further
 clarifications. Thanks in advance for your help.

 Best Regards,
 S.

 PS: I had posted this question on the Bioconductor mailing list, but no one
 responded with the answer about my problem (some suggested to use other
 package). Probably this is more related to R, so I am reposting here.



 Below is the dump of the matrix *row.scaled.fc2* and the object *ht4* which
 was obtained by using the heatmap.2 function.

 -
 Dump of the matrix row.scaled.fc2 of dimension 47X4 for which I need to get
 the cluster
 -
 row.scaled.fc2 -
    structure(c(1.28370586906697, 0.045882176168387, -1.36708804887146,
                0.521861081643557, 0.931917365795697, -1.26811754842825,
 -0.72130612803134,
                0.997233560332114, 1.10914280037357, 0.906822512746599,
 0.124305385892705,
                0.243716750638903, -0.81506628597585, 0.9281945227055,
 -1.02514155647985,
                -0.0148828263869010, 0.610771143828774, -1.31512789127346,
 -1.03419747081316,
                -1.37364737258546, 1.25426184614502, -0.901983912371582,
 1.39208493297302,
                1.46330419386939, 1.46904838309704, 1.33893188130515,
 1.19407808189758,
                1.2218547353343, 1.19698274357976, 1.18155526998177,
 0.841732283108634,
                0.747807260442244, 0.714318042078153, -1.33532716080095,
 -0.313607205847584,
                0.355541486307312, -0.116351310506438, 0.77912190137299,
 1.19372966187956,
                -1.46614749631243, 1.05871763558761, -0.943184299406566,
 1.03714731356991,
                1.25047276064487, 0.851530489918317, 0.97326112450597,
 0.776853817614179,
                0.254354524536168, 1.31978778177031, 1.03174081073449,
 1.03284070831524,
                0.653353551741362, -0.215733545477378, -0.966047927590969,
 0.652368565446036,
                0.536560120952493, 0.807139899513123, 1.26763097889282,
 1.28335333872251,
                1.45704025225707, 0.57691754078049, 1.07113369815538,
 0.610158458070122,
                -0.762088920575592, 1.00819322156949, 1.14148232415467,
 0.297815716619546,
                0.143195107796418, -0.0065855621849476, 0.062650188298147,
 -0.177601977084224,
                -0.437288024655434, 0.178377570495840, 0.447251122498145,
 0.400521563178456,
                0.441487949431983, 0.46509369129, 0.754248218272813,
 0.657576754588525,
                0.832332574891687, -0.194585070239614, 1.09572866565514,
 1.04256940502540,
                0.583290457043162, 0.947182223637108, 0.453501818870319,
 0.362539212141846,
                0.64658837487362, 0.778492522245523, 0.406650195058153,
 -0.113538768459753,
                0.596257630693658, 0.652082611403661, 0.731202922578465,
 -0.540351240198989,
                -0.280636135117373, 0.0957282195118376, -0.301771114678491,
 -0.319287162711085,
                0.392333008215492, 0.595799016736027, -0.493631246722725,
 -0.570129842719142,
                -0.687622802632555, -0.243797611378268, -0.510913960310597,
 -0.263387651214153,
                -0.172495725682589, 0.609736001727743, 0.809229072877685,
 1.08430415610192,
                0.475088705288397, 0.503896215545131, 0.0658502505817462,
 -0.235112572720005,
                

Re: [R] KMedians clustering in R

2010-09-17 Thread Shubha Vishwanath Karanth
Thanks all. But I was looking for KMedian algorithm and not the KMedoids 
algorithm. The wiki says,  Note that this algorithm is often confused with 
k-medoids, which finds the optimal medoid, not median, for each cluster. (A 
medoid is an actual point from the dataset; a median is the mathematical median 
calculated separately for each dimension.)

Any package which does KMedian clustering algorthm? Many Thanks.
 
Regards,
Shubha.

-Original Message-
From: Christian Hennig [mailto:chr...@stats.ucl.ac.uk] 
Sent: Thursday, September 16, 2010 9:32 PM
To: Shubha Vishwanath Karanth
Cc: r-help@r-project.org; r-h...@stat.math.ethz.ch
Subject: Re: [R] KMedians clustering in R

pam/clara in package cluster are probably as close to it as you can be.

There is no unique definition of a multivariate median and therefore there 
is no unique definition of k-medians, but pam/clara is one possible 
version of it. (Of course if you think of k-medians as defined in a 
specific paper, it may still be something slightly different.)

Christian

On Thu, 16 Sep 2010, Shubha Vishwanath Karanth wrote:

 Hi R,

 Is there a package in R to perform KMedian clustering?

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

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


*** --- ***
Christian Hennig
University College London, Department of Statistical Science
Gower St., London WC1E 6BT, phone +44 207 679 1698
chr...@stats.ucl.ac.uk, www.homepages.ucl.ac.uk/~ucakche
This e-mail may contain confidential and/or privileged i...{{dropped:10}}

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


Re: [R] R Founding

2010-09-17 Thread Peter Dalgaard
On 09/17/2010 12:14 AM, Jeremy Miles wrote:
 I know from organizing a conference in Germany that the only really good way
 was and is ordinary money transfer via BIC and IBAN numbers. Unfortunately,
 this system is pretty unknown in the US. Europeans can easily use money
 transfer to the R foundation.

 
 Paypal?
 
 Many open source  projects have a 'donate with paypal' button.
 
 Jeremy
 
 

As far as I remember, this requires that a real person opens the
account, and takes on the associated tax issues. It may be different for
US-based projects.

Another option is to get the hosting institutions to accept credit
cards, but they tend to balk at the transaction costs (with the result
that conference organizers get driven to conference agencies with much
greater handling fees...)

But seriously, even Springer can do wire transfers nowadays. Maybe we
should just wait for the US banks to join the 21st century?

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


Re: [R] Converting tables to matrices

2010-09-17 Thread selthy

Thanks so much! I realise that probably seems very simple to you, but you've
just saved me hours of struggling with syntax and commands I'm not very
familiar with...excellent.
Cheers,
Selthy
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Converting-tables-to-matrices-tp2543309p2543423.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] Question: how to obtain the clusters of genes (basically the ones in the row dendrograms) from an object obtained by heatmap.2 function

2010-09-17 Thread Sunny Srivastava
Thanks Michael for your help. At least its good to know that there is no
function which does what I wanted. I will definitely try to code something
that fulfills my requirements.

Regards,
S.

On Fri, Sep 17, 2010 at 2:32 AM, Michael Bedward
michael.bedw...@gmail.comwrote:

 Hello Sunny,

 Defining groups at a given height can be done with the cut function
 (see ?cut.dendrogram).

 Unfortunately, cut doesn't give you the option of specifying a number
 of clusters rather than a height in the way that cutree does for
 hclust objects. Perhaps someone else here knows of a package that
 includes a function to do this (I did a quick sos search but didn't
 find anything obvious).  Otherwise you could examine the cut function
 and try to hack a version that takes number of groups as an argument.
 You can see the function's code with the command getS3method(cut,
 dendrogram).

 Sorry I can't help more. Being a simple soul I find hclust objects so
 much easier to deal with !

 Michael


 On 17 September 2010 11:30, Sunny Srivastava research.b...@gmail.com
 wrote:
  Hello R-Helpers,
  I have a question about extracting the clusters of genes after we make
 the
  heatmap (say ht4) using the heatmap.2 function. Basically, I want to get
 the
  clusters which are shown as row dendrogram in the heatmap.
 
  I understand that ht4$rowDendrogram is an object of dendrogram and it
  containes details of all the nodes and branches, but lets say I want to
 know
  the number of clusters and the genes in each cluster if I terminated the
  tree (dendrogram) at a particular height. Also, if I know that I want 12
  clusters, how do I know which height I should terminate the tree (or
  branching structure)
 
  I am sorry if I am not clear. Please let me know if you need any further
  clarifications. Thanks in advance for your help.
 
  Best Regards,
  S.
 
  PS: I had posted this question on the Bioconductor mailing list, but no
 one
  responded with the answer about my problem (some suggested to use other
  package). Probably this is more related to R, so I am reposting here.
 
 
 
  Below is the dump of the matrix *row.scaled.fc2* and the object *ht4*
 which
  was obtained by using the heatmap.2 function.
 
 
 -
  Dump of the matrix row.scaled.fc2 of dimension 47X4 for which I need to
 get
  the cluster
 
 -
  row.scaled.fc2 -
 structure(c(1.28370586906697, 0.045882176168387, -1.36708804887146,
 0.521861081643557, 0.931917365795697, -1.26811754842825,
  -0.72130612803134,
 0.997233560332114, 1.10914280037357, 0.906822512746599,
  0.124305385892705,
 0.243716750638903, -0.81506628597585, 0.9281945227055,
  -1.02514155647985,
 -0.0148828263869010, 0.610771143828774, -1.31512789127346,
  -1.03419747081316,
 -1.37364737258546, 1.25426184614502, -0.901983912371582,
  1.39208493297302,
 1.46330419386939, 1.46904838309704, 1.33893188130515,
  1.19407808189758,
 1.2218547353343, 1.19698274357976, 1.18155526998177,
  0.841732283108634,
 0.747807260442244, 0.714318042078153, -1.33532716080095,
  -0.313607205847584,
 0.355541486307312, -0.116351310506438, 0.77912190137299,
  1.19372966187956,
 -1.46614749631243, 1.05871763558761, -0.943184299406566,
  1.03714731356991,
 1.25047276064487, 0.851530489918317, 0.97326112450597,
  0.776853817614179,
 0.254354524536168, 1.31978778177031, 1.03174081073449,
  1.03284070831524,
 0.653353551741362, -0.215733545477378, -0.966047927590969,
  0.652368565446036,
 0.536560120952493, 0.807139899513123, 1.26763097889282,
  1.28335333872251,
 1.45704025225707, 0.57691754078049, 1.07113369815538,
  0.610158458070122,
 -0.762088920575592, 1.00819322156949, 1.14148232415467,
  0.297815716619546,
 0.143195107796418, -0.0065855621849476, 0.062650188298147,
  -0.177601977084224,
 -0.437288024655434, 0.178377570495840, 0.447251122498145,
  0.400521563178456,
 0.441487949431983, 0.46509369129, 0.754248218272813,
  0.657576754588525,
 0.832332574891687, -0.194585070239614, 1.09572866565514,
  1.04256940502540,
 0.583290457043162, 0.947182223637108, 0.453501818870319,
  0.362539212141846,
 0.64658837487362, 0.778492522245523, 0.406650195058153,
  -0.113538768459753,
 0.596257630693658, 0.652082611403661, 0.731202922578465,
  -0.540351240198989,
 -0.280636135117373, 0.0957282195118376,
 -0.301771114678491,
  -0.319287162711085,
 

Re: [R] Question: how to obtain the clusters of genes (basically the ones in the row dendrograms) from an object obtained by heatmap.2 function

2010-09-17 Thread Michael Bedward
Cool. If you get some code working and don't mind sharing it please
post it here.

Michael

On 17 September 2010 16:49, Sunny Srivastava research.b...@gmail.com wrote:
 Thanks Michael for your help. At least its good to know that there is no
 function which does what I wanted. I will definitely try to code something
 that fulfills my requirements.
 Regards,
 S.


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


[R] Simple question, name of the variable as string.

2010-09-17 Thread C.H.
Dear R users,

I have a very simple question and I've tried to search for the answer.
(But failed.)

there should be a function (func) that work like

 abc - c(1,2,3,4)
 func(abc)
abc

I would like to know the name of that function. Thank you very much
for your help.

Regards,

CH

-- 
CH Chan

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Simple question, name of the variable as string.

2010-09-17 Thread David Winsemius


On Sep 17, 2010, at 2:54 AM, C.H. wrote:


Dear R users,

I have a very simple question and I've tried to search for the answer.
(But failed.)

there should be a function (func) that work like


abc - c(1,2,3,4)
func(abc)

abc


 func - function(xyz) deparse(substitute(xyz))
 func(abc)
[1] abc



I would like to know the name of that function.


--
David.

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

2010-09-17 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 17/09/10 08:38, Peter Dalgaard wrote:
 On 09/17/2010 12:14 AM, Jeremy Miles wrote:
 I know from organizing a conference in Germany that the only really good way
 was and is ordinary money transfer via BIC and IBAN numbers. Unfortunately,
 this system is pretty unknown in the US. Europeans can easily use money
 transfer to the R foundation.


 Paypal?

 Many open source  projects have a 'donate with paypal' button.

 Jeremy


 
 As far as I remember, this requires that a real person opens the
 account, and takes on the associated tax issues. It may be different for
 US-based projects.
 
 Another option is to get the hosting institutions to accept credit
 cards, but they tend to balk at the transaction costs (with the result
 that conference organizers get driven to conference agencies with much
 greater handling fees...)
 
 But seriously, even Springer can do wire transfers nowadays. Maybe we
 should just wait for the US banks to join the 21st century?
 

1) I agree Jaroslaw - you can not buy the motivation you get from
participants who are doing it for the love of it, but especially now, in
tweaking out issues like memory usage and multicore, which effectively
are issues with which the user is only indirectly confronted (Wow - in
this release I can load a data.frame of 3GB... That's brilliant) would
be very suitable to be done by paid developers who have long working
expertise in these fields. I agree that the further development on the
outside (cli, packages, ...) will be most effectively done as it is now
- - by enthusiasts --- It worked so far, and why change it? Especially as
the main problems seem to be with the internal internals.

2) I just looked at GRASS and qgis - both have donate buttons ( see
http://grass.fbk.eu/donation.php and
http://www.qgis.org/en/sponsorship.html ). Foundations to GRASS are
managed through the Italien OSGeo Chapter. Maybe something similar would
be an option for R as well?

3) Funding not only has to contribute to financing coding, but also to
organise conferences, support participants, organise courses, etc.

Cheers,

Rainer




- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Tel:+33 - (0)9 53 10 27 44
Cell:   +27 - (0)8 39 47 90 42
Fax (SA):   +27 - (0)8 65 16 27 82
Fax (D) :   +49 - (0)3 21 21 25 22 44
Fax (FR):   +33 - (0)9 58 10 27 44
email:  rai...@krugs.de

Skype:  RMkrug
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyTE8MACgkQoYgNqgF2egquPQCbBGUve3/cLj6focACw7OFHrBx
uPkAnjM2r2r1crizQJKKMxKInMQM5/2Y
=dlem
-END PGP SIGNATURE-

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Simple question, name of the variable as string.

2010-09-17 Thread Barry Rowlingson
On Fri, Sep 17, 2010 at 7:54 AM, C.H. chainsawti...@gmail.com wrote:
 Dear R users,

 I have a very simple question and I've tried to search for the answer.
 (But failed.)

 there should be a function (func) that work like

 abc - c(1,2,3,4)
 func(abc)
 abc

 I would like to know the name of that function. Thank you very much
 for your help.

 Think: where does R do this?

 Answer: zzz = 1:10 ; plot(zzz)  # look at the y axis.

 How did it do this? Look at the code. Type 'plot' without () and
there's the code. Somewhere in there you will see where it sets the Y
axis label, or ylab.

 Then read and understand the help pages for those functions. What
happens if I do func(c(1,2,3,4))? What's the name of 'c(1,2,3,4)'?

 Its a good way to learn.

Barry

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


[R] R Founding

2010-09-17 Thread R P Herrold

On Fri, 17 Sep 2010, Peter Dalgaard wrote:


On 09/17/2010 12:14 AM, Jeremy Miles wrote:


As far as I remember, this requires that a real person opens 
the account, and takes on the associated tax issues. It may 
be different for US-based projects.


Nope -- all around the world, the governments think they 
should have an ability to look into who is receiving a money 
flow, and as banks and central banks operate within nation 
states, I suppose they can enforce that ;)



But seriously, even Springer can do wire transfers nowadays. Maybe we
should just wait for the US banks to join the 21st century?


In the US the process is called an 'ACH' -- automated clearing 
house -- transfer, and if one has a destination payee name, 
destination bank name and routing number, and destination 
bank account number or account number with that destination 
payee, it is the mattter of a few second's work with a 
'online bill payment' interface to make such transfers


The trick is that the variance and differing models of 
national rules about what is permissible, and optionally, tax 
deductable as a charitable contribution, vary all around the 
world, and everyone wants to transfer to something and in a 
way they understand


donation gridlock results until a donor someone simply asks 
(as has need done here) and the recipient someone engages to 
get the details solved.  I've worked through these details in 
some detail with CentOS and if the principals of the R 
foundation want more information, please contact me offlist 
[some of the questions as to organizational specifics are in a 
space where some personal data privacy matters come into play, 
and need not be aired on a public and archived mailing list]


-- Russ herrold

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

2010-09-17 Thread Stefan Petersson

First, I don't have the correct lingo for this topic, so I can't really find a 
solution for my problem. And 
maybe I formulate it incorrectly, so bear with me.

How would I calculate a 'constant transition matrix' if I know a given value at 
a given time? 

Let's say I know that my value is 54,0 at t=12. How do I get the initial chain 
value?

t   markov.growth
00  00.0
01  06.3 - My value of interest...
02  12.1
03  17.7
04  22.8
05  27.7
06  32.2
07  36.4
08  40.4
09  44.2
10  47.7
11  50.9
12  54.0 - These two is what I know...
13  56.9
14  59.6
15  62.1

I can't find out how to do this kind of 'reversed' calulation. Maybe there is 
some library that can do this 
for me? I know that there are a lot of packages covering different aspects of 
Markov Models. But my 
ignorance prevents me from finding out which one.

TIA

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


Re: [R] Help with customizing a histogram figure

2010-09-17 Thread Jim Lemon

On 09/16/2010 11:40 PM, Josh B wrote:

Hi all,

Please consider the following code:

require(plotrix)

l- list(rnorm(50),rnorm(50,sd=2),rnorm(50,mean=3))
multhist(l)

I have two things I need help with:

(1) In the output, there are empty spaces on the x-axis. How would I eliminate
these spaces? I want a nice, smooth, empty-spaceless x-axis.

(2) How could I add tracing lines to each histogram? I am undoubtedly using the
wrong terminology. What I want to do is something like this:
http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=55
Note that each histogram has a tracing line that summarizes the histogram.

In summary, I'd like to modify the code above to (1) get rid of the dead spaces
on the x-axis, and (2) add lines that traces to each of the histograms therein
(all on the same graph).

I am very bad at using R graphics at this point, so I need some pretty serious
hand-holding. Exact code that gets the job done would be most useful for me.
Thanks very much in advance!


Hi Josh,
You can get rid of the spaces like this:

multhist(l,space=c(0,0))

By tracing lines I think you mean smoothed densities of your three 
samples. The addictedtor site seems to be down at the moment, so I can't 
check the page suggested by Thomas and Jorge. This is a bit more 
complicated, as the functions underlying multhist don't usually place 
the bars at values corresponding to the intervals you need to calculate. 
Perhaps if you use multhist to calculate the histograms:


lhist-multhist(l,plot.it=FALSE)

Then plot the histogram with barp instead (barp places bars on integer 
values by default and this happens to match your breakpoints):


barp(lhist$out,names.arg=seq(-5.5,4.5,by=1),
 col=c(gray20,gray50,gray80)))

calculate the density:

l1dens-density(l[[1]])

and then display the lines:

# notice the x offset and the rescaling of the density values
lines(l1dens$x+6.5,rescale(l1dens$y,c(0,20)))

repeating for the other two samples, you can get the plot you want.

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] Markov Model problem

2010-09-17 Thread Ted Harding
On 17-Sep-10 08:19:20, Stefan Petersson wrote:
 First, I don't have the correct lingo for this topic, so I can't
 really find a solution for my problem. And maybe I formulate it
 incorrectly, so bear with me.
 
 How would I calculate a 'constant transition matrix' if I know a
 given value at a given time? 
 
 Let's say I know that my value is 54,0 at t=12. How do I get the
 initial chain value?
 
 t markov.growth
 0000.0
 0106.3 - My value of interest...
 0212.1
 0317.7
 0422.8
 0527.7
 0632.2
 0736.4
 0840.4
 0944.2
 1047.7
 1150.9
 1254.0 - These two is what I know...
 1356.9
 1459.6
 1562.1
 
 I can't find out how to do this kind of 'reversed' calulation.
 Maybe there is some library that can do this for me? I know
 that there are a lot of packages covering different aspects
 of Markov Models. But my ignorance prevents me from finding
 out which one.
 TIA

Am I correct to assume that the information you intend to work
from is that (here Y denotes the markov.growth variable):

At t = 00, Y = 00.0 (initial state)
At t = 12, Y = 54.0

??

From this information alone, it is impossible to calculate any
transition matrix for the evolution of the process, without
making some assumption about a generic law of growth.

However, taking the values you have supplied, I can see that:

  Y - c(00.0,06.3,12.1,17.7,22.8,27.7,32.2,36.4,40.4,
 44.2,47.7,50.9,54.0,56.9,59.6,62.1)
  t.diff-(0:14)
  plot(t.diff,log(diff(Y)))

looks like a very close approximation to a straight line,
with a little random variation. So:

  Z  - log(diff(Y))
  LM - lm(Z ~ t.diff)
  LM$coeff
  # (Intercept)  t.diff
  #   1.8369463  -0.0650716

And then:

  lines(t.diff, 1.8369463 - 0.0650716*t.diff)

shows that the fit is very close, and it looks as though the
random deviations have the same degree of dispersion over time
(though there may be some evidence of serial correlation in these).
Hence one could adopt a model

  log(Y[t+1] - Y[t]) = a + b*t.diff + error

where a = 1.8369463, b = -0.0650716, or

  Y[t+1] = Y[t] + A + B^t

where A = exp(a), B = exp(b). Then, since Y[0] = 0, for t=1,2,...

  Y[t] = t*A + B + B^2 + ... B^t

Now, assuming a model *of this form* -- i.e. without knowing the
values of A and B, you could use the (assumed above) information
that Y[0] = 0, Y[12] = 54.0, to solve this for values of A and B.
Then you could evaluate this for your value of interest Y[1].

However, incorporation of uncertainties due to the random error
between observed values and the fit would be more complicated
(and cannot be done given only the information about Y[0] and Y[12]).

Note that this approach, given only Y[0] and Y[12], depends on
*assuming* a model of the form  Y[t+1] = Y[t] + A + B^t, whereas
I was led to suggest this as an approach on the basis of looking
at *all* the values you supplied.

Just thoughts! Probably others can suggest ways of taking this
further, or approaching it differently.

Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 17-Sep-10   Time: 10:30:41
-- XFMail --

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


Re: [R] R Founding

2010-09-17 Thread Marianne Promberger
Hi,
 
 I would GLADLY donate 30-50$ each year just to see R develop, but there 
 needs to be a way for me to do it in a civilized manner. If the userbase of 
 R is over 2 million there will surely be 100,000 users who, like myself, 
 will happily fork out 40$ a year - would that help? you can do the 
 calculation yourselves. Set up a donation page in which I will be able to 
 pay by credit card or PayPal and you will start getting donations from 
 individual users. Advertise this at the startup message of the program: say 
 something like support us at www.suppoRtR.com and the money will start 
 coming. 

I think this is a great idea! (I emailed to the address on the R
page to that effect two days ago :) )

From the other replies, it seems there are three broad groups of
obstacles:

(1) Figure out the way to do it -- PayPal would be best for
international users, but there are now alternatives to PayPal such
as Moneybookers, who might do the same thing for those who want to
pay and might be better for the recipient -- I don't know.

(2) What the money is used for

(3) Convince the people who can make the decision, i.e. the
executives of the R foundation.

I think (2) is a fake problem. I for one would not care if the money I
donate is used for something I never use, or is even used
inefficiently. I gain so much from R from other people's work, I would
see my donation as a gift to them, and they could do with that gift
what they want to. They could go have lots of beer, for all I care
(unless it gets in the way of writing R, of course :) )

But one way around (3) might be even to have package developers accept
donations for packages.

Is there a way to take this off the r-help list to try to tackle this
as a project? Maybe set up a small Google Group?

Marianne

BTW after reading in this thread about the donation form and the
possbility to do IBAN, I went back to r-project.org and then found the
link how to donate. I had not seen this when I looked a few days
ago. You can say I'm stupid and didn't look hard enough, but from a
usability/ marketing perspective this means even this cumbersome
possibility is not salient enough at the moment.

-- 
Marianne Promberger PhD, King's College London
http://promberger.info
R version 2.11.1 (2010-05-31)
Ubuntu 9.04

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

2010-09-17 Thread Alaios
I would like to thank you again for your help.
But it seems that the floor function (ceiling, round too) create more dots in 
the matrix that line really touches.

unique( floor( cbind( seq(2,62, by=0.1), linefn(seq(2,62, by=0.1)) ) )  ) 

You can see that in the picture below

http://yfrog.com/5blineswj

So, how to select the only the cells that the line touches?

I would like to thank you in advance for your help
best Regards
Alex





From: David Winsemius dwinsem...@comcast.net

Cc: Rhelp list r-help@r-project.org
Sent: Wed, September 15, 2010 1:55:10 PM
Subject: Re: [R] Interpolate? a line


On Sep 15, 2010, at 7:24 AM, David Winsemius wrote:

 Replacing context:
 
 Hello everyone.
 I have created a 100*100 matrix in R.
 Let's now say that I have a line that starts from (2,3) point and ends to 
the
 (62,34) point. In other words this line starts at cell (2,3) and ends at 
cell
 (62,34).
 
 Is it possible to get by some R function all the matrix's cells that this 
line
 transverses?
 
 I would like to thank you for your feedback.
 
 Best Regards
 Alex
 
 On Sep 15, 2010, at 6:52 AM, Michael Bedward wrote:
 
 Hello Alex,
 
 Here is one way to do it. It works but it's not pretty :)
 
 If you want an alternative, consider that produces the Y cell indices (since 
the x cell indices are already 2:62):
 
  linefn - function(x) 3+((34-3)/(62-2)) *(x-2)
  findInterval(linefn(2:62), 3:34)
 [1]  1  1  2  2  3  3  4  4  5  5  6  6  7  7  8  8  9  9 10 10 11 11 12 12 
 13 
13 14
 [28] 14 15 15 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 
 27 
27 28
 [55] 28 29 29 30 30 31 32
 # that seems off by two
  linefn(62)
 [1] 34
  linefn(2)
 [1] 3 # but that checks out and I realized those were just indices for the 
 3:34 
findInterval vector
 
  (3:34)[findInterval(linefn(2:62), 3:34)]
 [1]  3  3  4  4  5  5  6  6  7  7  8  8  9  9 10 10 11 11 12 12 13 13 14 14 
 15 
15 16
 [28] 16 17 17 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 
 29 
29 30
 [55] 30 31 31 32 32 33 34
 
 ( no rounding and I think the logic is clearer.)

But I also realized it didn't enumerate all the the cells were crossed either, 
only indicating which cell was associated with an integer value of x. Also 
would 
have even more serious problems if the slope were greater than unity. To 
enumerate the cell indices that were crossed, try:

unique( floor( cbind( seq(2,62, by=0.1), linefn(seq(2,62, by=0.1)) ) )  )
  [,1] [,2]
[1,]23
[2,]33
[3,]44
[4,]54
[5,]55
[6,]65
[7,]75
[8,]76
snipping interior results
[83,]   58   32
[84,]   59   32
[85,]   60   32
[86,]   60   33
[87,]   61   33
[88,]   62   34

That could probably be passed to rect() to illustrate (and check logic):

rect(cellidxs[,1], cellidxs[,2], cellidxs[,1]+1, cellidxs[,2]+1, col=red)

#redraw line :
lines(2:62, 3+(34-3)/(62-2)*(0:60))


 
 --David.
 
 
 interp - approx(c(2, 62), c(3, 34), method=linear, xout=2:62)
 m - matrix(c(interp$x, round(interp$y)), ncol=2)
 tie - m[,2] == c(-Inf, m[-nrow(m),2])
 m - m[ !tie, ]
 
 You might want to examine the result like this...
 
 plot(m)  # plots points
 lines(c(2,26), c(3, 34))  # overlay line for comparison
 you can add a grid with
 abline(v=2:62, h=3:34)
 
 Michael
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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.

David Winsemius, MD
West Hartford, CT


  
[[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 variable from for loop in naming new variables

2010-09-17 Thread Ivan Calandra
  Hi Jim,

First, I think it's better if you reply to the list, other users might 
be interested and have better answers.

Second, as other replies showed you, using a list is actually way easier 
than creating new objects every time. Check especially the reply from 
Joshua Wiley, which gives you great examples and guidance.

Last, regarding rm(list=ls()), what's the point of creating new objects 
in your loop if you remove them right after?! Maybe you intend to do 
stuff on them first. Anyway, I don't use Emacs so not sure why you do it 
that way. Just my limited opinion.

HTH,
Ivan

Le 9/17/2010 12:35, Maas James Dr (MED) a écrit :

 Hi Ivan,

 Thanks for suggestions, was just hoping to do it all in one step, 
 creating a list and then filling it all seems rather complicated ... 
 will look up *apply.

 As for removing objects, I run R interactively from within Emacs (ESS) 
 and stuff hangs around for successive evaluations, not sure where it 
 came from so I clean it out every time ... is there a better way?

 Thanks

 Jim

 Message: 65

 Date: Thu, 16 Sep 2010 18:03:29 +0200

 From: Ivan Calandra ivan.calan...@uni-hamburg.de

 To: r-help@r-project.org

 Subject: Re: [R] using variable from for loop in naming new variables

 Message-ID: 4c923fd1.8000...@uni-hamburg.de

 Content-Type: text/plain

   Hi!

 assign() should do the job.

 But using a list, and filling each element iteratively (with a for loop

 or with *apply() ) might be better, up to you.

 Btw, why do you remove your objects?

 HTH,

 Ivan

 Le 9/16/2010 17:44, Maas James Dr (MED) a ?crit :

  Simple one here ... but can't get it to work ...

 

  for (i in 1:4){

   paste(stuff,[i]),sep=)- 3 + i

  }

 

  ls()

  rm(list=ls())

 

 

 

  I just want it to create 4 new variables called stuff1, stuff2, 
 stuff3, stuff4 with the corresponding assignments.  I realise that 
 there are more elegant functions but this is just a model of a bigger 
 situation.

 

  Thanks

 

  Jim

 

 ===

 Dr. Jim Maas

 Research Associate in Network Meta-Analysis

 School of Medicine, Health Policy and Practice

 CD Annex, Room 1.04

 University of East Anglia

 Norwich, UK

 NR4 7TJ

 +44 (0) 1603 591412


-- 
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php


[[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] Interpolate? a line

2010-09-17 Thread Michael Bedward
I think that's because of your definition for touches.

If I read it correctly, David's code assumes that a cell is a square
1 unit wide and then followed the normal geometric definition of
touches, ie. the line intersects with at least one point on the
cell's boundary.

You seem to have a different definition: cell centers perhaps ? or
cell lower-left corner points ?  Whether or not any particular
definition is valid depends on your requirements.  In other words -
it's all up to you :)

Michael


On 17 September 2010 21:22, Alaios ala...@yahoo.com wrote:
 I would like to thank you again for your help.
 But it seems that the floor function (ceiling, round too) create more dots in
 the matrix that line really touches.

 unique( floor( cbind( seq(2,62, by=0.1), linefn(seq(2,62, by=0.1)) ) )  )

 You can see that in the picture below

 http://yfrog.com/5blineswj

 So, how to select the only the cells that the line touches?

 I would like to thank you in advance for your help
 best Regards
 Alex




 
 From: David Winsemius dwinsem...@comcast.net

 Cc: Rhelp list r-help@r-project.org
 Sent: Wed, September 15, 2010 1:55:10 PM
 Subject: Re: [R] Interpolate? a line


 On Sep 15, 2010, at 7:24 AM, David Winsemius wrote:

 Replacing context:

 Hello everyone.
 I have created a 100*100 matrix in R.
 Let's now say that I have a line that starts from (2,3) point and ends to
 the
 (62,34) point. In other words this line starts at cell (2,3) and ends at
 cell
 (62,34).

 Is it possible to get by some R function all the matrix's cells that this
line
 transverses?

 I would like to thank you for your feedback.

 Best Regards
 Alex

 On Sep 15, 2010, at 6:52 AM, Michael Bedward wrote:

 Hello Alex,

 Here is one way to do it. It works but it's not pretty :)

 If you want an alternative, consider that produces the Y cell indices (since
the x cell indices are already 2:62):

  linefn - function(x) 3+((34-3)/(62-2)) *(x-2)
  findInterval(linefn(2:62), 3:34)
 [1]  1  1  2  2  3  3  4  4  5  5  6  6  7  7  8  8  9  9 10 10 11 11 12 12 
 13
13 14
 [28] 14 15 15 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 
 27
27 28
 [55] 28 29 29 30 30 31 32
 # that seems off by two
  linefn(62)
 [1] 34
  linefn(2)
 [1] 3 # but that checks out and I realized those were just indices for the 
 3:34
findInterval vector

  (3:34)[findInterval(linefn(2:62), 3:34)]
 [1]  3  3  4  4  5  5  6  6  7  7  8  8  9  9 10 10 11 11 12 12 13 13 14 14 
 15
15 16
 [28] 16 17 17 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 
 29
29 30
 [55] 30 31 31 32 32 33 34

 ( no rounding and I think the logic is clearer.)

 But I also realized it didn't enumerate all the the cells were crossed either,
 only indicating which cell was associated with an integer value of x. Also 
 would
 have even more serious problems if the slope were greater than unity. To
 enumerate the cell indices that were crossed, try:

 unique( floor( cbind( seq(2,62, by=0.1), linefn(seq(2,62, by=0.1)) ) )  )
      [,1] [,2]
 [1,]    2    3
 [2,]    3    3
 [3,]    4    4
 [4,]    5    4
 [5,]    5    5
 [6,]    6    5
 [7,]    7    5
 [8,]    7    6
 snipping interior results
 [83,]   58   32
 [84,]   59   32
 [85,]   60   32
 [86,]   60   33
 [87,]   61   33
 [88,]   62   34

 That could probably be passed to rect() to illustrate (and check logic):

 rect(cellidxs[,1], cellidxs[,2], cellidxs[,1]+1, cellidxs[,2]+1, col=red)

 #redraw line :
 lines(2:62, 3+(34-3)/(62-2)*(0:60))



 --David.


 interp - approx(c(2, 62), c(3, 34), method=linear, xout=2:62)
 m - matrix(c(interp$x, round(interp$y)), ncol=2)
 tie - m[,2] == c(-Inf, m[-nrow(m),2])
 m - m[ !tie, ]

 You might want to examine the result like this...

 plot(m)  # plots points
 lines(c(2,26), c(3, 34))  # overlay line for comparison
 you can add a grid with
 abline(v=2:62, h=3:34)

 Michael

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

 David Winsemius, MD
 West Hartford, CT



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

Re: [R] Odp: Programming: loop versus vector oriented

2010-09-17 Thread Petr PIKAL
Hi Jan

Jan private jrheinlaen...@gmx.de napsal dne 17.09.2010 12:43:40:

 Hello Petr,
 
  but I think this is how your code really works. Did you try it?
 
 it does, but the R documentation says somewhere:
 Warning: for() loops are used in R code much less often than in
 compiled languages. Code that takes a `whole object' view is likely to
 be both clearer and faster in R.

Yes and no. Try to go through R-Inferno from Patrick Burns. For loop is 
not necessarily slower if properly used.

Your problem was specified not very clearly because only in last mail you 
presented that what you have is 2 equal length vectors which shall give 
result of the same length. The problem is that (if I remember correctly as 
I do not keep original mails) you have 3 distinct computations based on 
values in vector1. So if you want some vectorised computation you has to 
use either switch or ifelse or cycle. However it is not necessary to do 
computation one by one as in your function but only 3 times based on 
threshold criteria.

I would do something like:

1.  make 3 distinct separate functions which compute relevant values 
from 2 vectors in a list
2.  split vectors according to thresholds to list see ?split
3.  make cycle in which for each part of list proper function is used 
something like }not very elegant.
for (i in 1:3) result[[1]] -  if (i==1) fun1(mylist1[[i]], mylist2[[1]]) 
else if(i==2) fun2(mylist1[[i]], ylist2[[1]]) else fun3(mylist1[[i]], 
ylist2[[1]])
4.  reconstruct result in original vector 
e.g.
cbind(unlist(mylist1), unlist(mylist2), unlist(result))

Regards
Petr


 
 So I am wondering in what way the whole object view could be applied
 to my function.
 
 Best regards,
Jan
 
   The function should work on the nth elements of the two input 
vectors
   and put the result into the nth element of the output vector. So it
   would work like c - a + b, only instead of '+' there are more 
complex
   calculations.
 


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

2010-09-17 Thread Alaios
Hello everyone,
please consider the following lines of a matrix


[574,]   59   32
[575,]   59   32
[576,]   59   32
[577,]   59   32
[578,]   59   32
[579,]   59   32
[580,]   59   32
[581,]   60   32
[582,]   60   33
[583,]   60   33
[584,]   60   33
[585,]   60   33
[586,]   60   33
[587,]   60   33
[588,]   60   33
[589,]   60   33
[590,]   60   33
[591,]   61   33
[592,]   61   33
[593,]   61   33
[594,]   61   33
[595,]   61   33
[596,]   61   33
[597,]   61   33
[598,]   61   33
[599,]   61   33
[600,]   61   33
[601,]   62   34

Is it possible somehow to count the similarities between the first and second 
column and put them on a third column like this?

59 32 3
60 33 5
62 34 1

where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34)

Best 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] count frequency

2010-09-17 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 17/09/10 14:19, Alaios wrote:
 Hello everyone,
 please consider the following lines of a matrix
 
 
 [574,]   59   32
 [575,]   59   32
 [576,]   59   32
 [577,]   59   32
 [578,]   59   32
 [579,]   59   32
 [580,]   59   32
 [581,]   60   32
 [582,]   60   33
 [583,]   60   33
 [584,]   60   33
 [585,]   60   33
 [586,]   60   33
 [587,]   60   33
 [588,]   60   33
 [589,]   60   33
 [590,]   60   33
 [591,]   61   33
 [592,]   61   33
 [593,]   61   33
 [594,]   61   33
 [595,]   61   33
 [596,]   61   33
 [597,]   61   33
 [598,]   61   33
 [599,]   61   33
 [600,]   61   33
 [601,]   62   34
 
 Is it possible somehow to count the similarities between the first and second 
 column and put them on a third column like this?
 
 59 32 3
 60 33 5
 62 34 1
 
 where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34)

One solution:

 x - data.frame(a=trunc(runif(10)*10), b=trunc(runif(10)*10))
 x
   a b
1  6 5
2  7 5
3  1 5
4  0 4
5  3 9
6  6 8
7  4 3
8  0 4
9  2 7
10 7 2
 x$comb - paste(x$a, x$b)
 x
   a b comb
1  6 5  6 5
2  7 5  7 5
3  1 5  1 5
4  0 4  0 4
5  3 9  3 9
6  6 8  6 8
7  4 3  4 3
8  0 4  0 4
9  2 7  2 7
10 7 2  7 2
 table(x$comb)

0 4 1 5 2 7 3 9 4 3 6 5 6 8 7 2 7 5
  2   1   1   1   1   1   1   1   1


I am sure, there are better ones

Cheers,

Rainer

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


- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Tel:+33 - (0)9 53 10 27 44
Cell:   +27 - (0)8 39 47 90 42
Fax (SA):   +27 - (0)8 65 16 27 82
Fax (D) :   +49 - (0)3 21 21 25 22 44
Fax (FR):   +33 - (0)9 58 10 27 44
email:  rai...@krugs.de

Skype:  RMkrug
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyTXoQACgkQoYgNqgF2egrgrgCfUOvMaUOwOC7HPSdbC2fFzdLo
4scAmwQ2M1E000PH4HoQmkpkLbANtjLy
=B2y8
-END PGP SIGNATURE-

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Odp: Programming: loop versus vector oriented

2010-09-17 Thread Jan private
Hello Petr,

 but I think this is how your code really works. Did you try it?

it does, but the R documentation says somewhere:
Warning: for() loops are used in R code much less often than in
compiled languages. Code that takes a `whole object' view is likely to
be both clearer and faster in R.

So I am wondering in what way the whole object view could be applied
to my function.

Best regards,
Jan

  The function should work on the nth elements of the two input vectors
  and put the result into the nth element of the output vector. So it
  would work like c - a + b, only instead of '+' there are more complex
  calculations.

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

2010-09-17 Thread Henrique Dallazuanna
Try this:

aggregate(rep(1, nrow(x)), x, sum)

On Fri, Sep 17, 2010 at 9:19 AM, Alaios ala...@yahoo.com wrote:

 Hello everyone,
 please consider the following lines of a matrix


 [574,]   59   32
 [575,]   59   32
 [576,]   59   32
 [577,]   59   32
 [578,]   59   32
 [579,]   59   32
 [580,]   59   32
 [581,]   60   32
 [582,]   60   33
 [583,]   60   33
 [584,]   60   33
 [585,]   60   33
 [586,]   60   33
 [587,]   60   33
 [588,]   60   33
 [589,]   60   33
 [590,]   60   33
 [591,]   61   33
 [592,]   61   33
 [593,]   61   33
 [594,]   61   33
 [595,]   61   33
 [596,]   61   33
 [597,]   61   33
 [598,]   61   33
 [599,]   61   33
 [600,]   61   33
 [601,]   62   34

 Is it possible somehow to count the similarities between the first and
 second
 column and put them on a third column like this?

 59 32 3
 60 33 5
 62 34 1

 where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34)

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




-- 
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] count frequency

2010-09-17 Thread Ted Harding
On 17-Sep-10 12:19:10, Alaios wrote:
 Hello everyone,
 please consider the following lines of a matrix
 
 [574,]   59   32
 [575,]   59   32
 [576,]   59   32
 [577,]   59   32
 [578,]   59   32
 [579,]   59   32
 [580,]   59   32
 [581,]   60   32
 [582,]   60   33
 [583,]   60   33
 [584,]   60   33
 [585,]   60   33
 [586,]   60   33
 [587,]   60   33
 [588,]   60   33
 [589,]   60   33
 [590,]   60   33
 [591,]   61   33
 [592,]   61   33
 [593,]   61   33
 [594,]   61   33
 [595,]   61   33
 [596,]   61   33
 [597,]   61   33
 [598,]   61   33
 [599,]   61   33
 [600,]   61   33
 [601,]   62   34
 
 Is it possible somehow to count the similarities between the first and
 second 
 column and put them on a third column like this?
 
 59 32 3
 60 33 5
 62 34 1
 
 where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34)
 
 Best Regards
 Alex

Does the following do what you want?

  a - c(59,59,59,59,59,59,59,60,60,60,60,60,60,60,
 60,60,60,61,61,61,61,61,61,61,61,61,61,62)
  b - c(32,32,32,32,32,32,32,32,33,33,33,33,33,33,
 33,33,33,33,33,33,33,33,33,33,33,33,33,34)

  table(data.frame(a=a,b=b))
  # b
  # a32 33 34
  #   59  7  0  0
  #   60  1  9  0
  #   61  0 10  0
  #   62  0  0  1

  T - t(as.matrix(table(data.frame(a=a,b=b
  L - c(table(data.frame(a=a,b=b)))
  B - as.integer(rep(rownames(T),each=ncol(T)))
  A - as.integer(rep(colnames(T),nrow(T)))
  cbind(A,B,L)[L0,]
  #   A  B  L
  # [1,] 59 32  7
  # [2,] 60 32  1
  # [3,] 60 33  9
  # [4,] 61 33 10
  # [5,] 62 34  1

Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 17-Sep-10   Time: 14:15:03
-- XFMail --

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


[R] ifelse statement

2010-09-17 Thread n.via...@libero.it
Dear list,
I have a question I'm trying to use the following command in R, but it gives 
me an error message.The command is:

data-ddply(data,c(year,name), transform, check1=ifelse(check1==1  
check2==1, 1,NULL))

so in my data frame I already have the check1 variable, if the conditions 
(check1==1  check2==1) is respected, check has to have 1 as value, whereas if 
it is not I want that variable to maintain its value.
Anyone knows, how to do this, by doing this for name and year??

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


Re: [R] Survival Analysis Daily Time-Varying Covariate....

2010-09-17 Thread Terry Therneau
Help!

I am unsure if I can analyze data from the following experiment.

Fish were placed in a tank at (t=0)
Measurements of Carbon Dioxide were taken each day for 120 days
(t=0,...120)
A few fish were then randomly pulled out of the tank at different days,
killed and examined for the presence of a disease
T= time of examination in days from start (i.e. 85th day), E = 0/1 for
nonevent/event



---

You need to decide on a mechanistic model.  On the day a fish is
sacrificed, does their risk of disease depend on
today's CO2 level
the average CO2 since the start of the experiment
cumulative CO2 dose
days over a threshold
etc
You can examine each of these one by one or in combinations.  It would
be very difficult, however, to ask your program to find the pattern.

Terry Therneau

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

2010-09-17 Thread Ivan Calandra
  Hi,

Not sure since I've never done it, but shouldn't it be NA instead of NULL?

Ivan

Le 9/17/2010 15:23, n.via...@libero.it a écrit :
 Dear list,
 I have a question I'm trying to use the following command in R, but it gives
 me an error message.The command is:

 data-ddply(data,c(year,name), transform, check1=ifelse(check1==1
 check2==1, 1,NULL))

 so in my data frame I already have the check1 variable, if the conditions
 (check1==1  check2==1) is respected, check has to have 1 as value, whereas if
 it is not I want that variable to maintain its value.
 Anyone knows, how to do this, by doing this for name and year??

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


-- 
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php


[[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] test to see if a s4 property is assigned?

2010-09-17 Thread darckeen


setClass(person,representation(name=character,age=numeric,kids=list))
[1] person
 bob - new(person)
 length(b...@name)
[1] 0
 length(b...@age)
[1] 0
 length(b...@kids)
[1] 0
 is.na(b...@kids)
logical(0)
 is.na(b...@age)
logical(0)
 is.na(b...@name)
logical(0)
 b...@kids - list(joe,sue)
 is.na(b...@kids)
[1] FALSE FALSE
 length(b...@kids)
[1] 2

Ah, length(obj...@property) is what i was looking for.  Thanks alot.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/test-to-see-if-a-s4-property-is-assigned-tp2541044p2543895.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] count frequency

2010-09-17 Thread Jorge Ivan Velez
Alaios,

Try

as.data.frame(table(x[,1], x[,2))

where x is your matrix.

HTH,
Jorge



On Fri, Sep 17, 2010 at 8:19 AM, Alaios  wrote:

 Hello everyone,
 please consider the following lines of a matrix


 [574,]   59   32
 [575,]   59   32
 [576,]   59   32
 [577,]   59   32
 [578,]   59   32
 [579,]   59   32
 [580,]   59   32
 [581,]   60   32
 [582,]   60   33
 [583,]   60   33
 [584,]   60   33
 [585,]   60   33
 [586,]   60   33
 [587,]   60   33
 [588,]   60   33
 [589,]   60   33
 [590,]   60   33
 [591,]   61   33
 [592,]   61   33
 [593,]   61   33
 [594,]   61   33
 [595,]   61   33
 [596,]   61   33
 [597,]   61   33
 [598,]   61   33
 [599,]   61   33
 [600,]   61   33
 [601,]   62   34

 Is it possible somehow to count the similarities between the first and
 second
 column and put them on a third column like this?

 59 32 3
 60 33 5
 62 34 1

 where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34)

 Best 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] Problems creating a Panel

2010-09-17 Thread Millo Giovanni
Dear Felipe,

maybe the data (which I can't see through the digest) do not have
variability, maybe something else.
Try sending me the data.frame, I'll see what happens.
Giovanni

--

Message: 72
Date: Thu, 16 Sep 2010 11:49:19 -0500
From: Luis Felipe Parra felipe.pa...@quantil.com.co
To: r-help@r-project.org
Subject: [R] Problems creating a Panel
Message-ID:
aanlktimnvuq8jcu=vesa6s7gr9tqn1bi9tf0xu3ok...@mail.gmail.com
Content-Type: text/plain; charset=iso-8859-1

Hello, I am trying to create a panel with the attached data frame. using
the
following code:

 PanelRio =  DataRiopaila[which(duplicated(DataRiopaila$SEC_STE)==T),]
 PanelRio=plm.data(PanelRio,index=c(SEC_STE,FechaSiembra))
series
Pluv3Meses,PluvMes4al10,Pluv2UltimosMeses,Rad3Meses,RadMes4al10,Rad2Ulti
mosMeses
are NA and have been removed

It tells me it removes couple of series because they are NA, and I don't
understand why because if I do:

 PanelRio =  DataRiopaila[which(duplicated(DataRiopaila$SEC_STE)==T),]
 length(which(is.na(PanelRio[,Pluv3Meses])==T))
[1] 474
 nrow(PanelRio)
[1] 4129

which means there are still around 3500 entries which aren't NA. Does
anybody what can be going on?

Thank you

Felipe Parra

---

Giovanni Millo
Research Dept.,
Assicurazioni Generali SpA
Via Machiavelli 4, 
34132 Trieste (Italy)
tel. +39 040 671184 
fax  +39 040 671160 


Ai sensi del D.Lgs. 196/2003 si precisa che le informazi...{{dropped:13}}

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


Re: [R] count frequency

2010-09-17 Thread Alaios
Just to confirm,
this one worked for me

 as.data.frame(table(temp[]))
   Var1 Freq
1 1   11
2 2   29
3 3   29
4 4   29
5 5   29
6 6   29
7 7   29
8 8   29
9 9   29
10   10   29
11   11   29
12   12   29
13   13   29
14   14   29
15   15   29
16   16   29
17   17   29
18   18   30
19   19   29
20   20   29



Best Regards
Alex






From: Jorge Ivan Velez jorgeivanve...@gmail.com

Cc: Rhelp r-help@r-project.org
Sent: Fri, September 17, 2010 4:24:59 PM
Subject: Re: [R] count frequency

Alaios,

Try 


as.data.frame(table(x[,1], x[,2))

where x is your matrix.

HTH,
Jorge

 


On Fri, Sep 17, 2010 at 8:19 AM, Alaios  wrote:

Hello everyone,
please consider the following lines of a matrix


[574,]   59   32
[575,]   59   32
[576,]   59   32
[577,]   59   32
[578,]   59   32
[579,]   59   32
[580,]   59   32
[581,]   60   32
[582,]   60   33
[583,]   60   33
[584,]   60   33
[585,]   60   33
[586,]   60   33
[587,]   60   33
[588,]   60   33
[589,]   60   33
[590,]   60   33
[591,]   61   33
[592,]   61   33
[593,]   61   33
[594,]   61   33
[595,]   61   33
[596,]   61   33
[597,]   61   33
[598,]   61   33
[599,]   61   33
[600,]   61   33
[601,]   62   34

Is it possible somehow to count the similarities between the first and second
column and put them on a third column like this?

59 32 3
60 33 5
62 34 1

where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34)

Best 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] Can I save my console contents automatically?

2010-09-17 Thread Nobuaki Michihata
Hello Greg,
Thank you for your comment.
I had a chance to use Windows GUI R and I found several interesting
differences between Mac and Windows GUI R.
1. txtStart() command
- Windows GUI R - worked perfectly
- Mac GUI R version.string R version 2.11.1 (2010-05-31) (both
32bit and 64bit) - only make a null file
- Mac R version.string R version 2.11.1 (2010-05-31) on terminal
window - worked perfectly
   (I also checked the permissions, but they were OK.)
2. Console
   - Mac GUI R   can display very long results and can save them from
the file menu (manually).
   - Windows GUI R can only short results and can save only the
displayed results from the file menu.
3. sink()
  - Mac GUI R  - split = TRUE worked.
  - Windows GUI R -split = TRUE didn't work (log on the file, but
didn't display the results on the console).

Thanks.
Nobu

 Currently comments (#) are ignored by txtStart and friends due to the task 
 callback mechanism used.  The txtComment function is available as a work 
 around to insert comments into the output/commands.

 I tried running date() as below and everything worked as expected (the 
 comments were missing, but the date command and result were in the file.  I 
 am running on windows where it looks like you are running on unix or linux.  
 Can you send your OS and version of R and TeachingDemos?  Also what are the 
 permissions on the logtest.txt file that is created? (I've seen problems 
 where the permissions for a directory allowed the creating of a file, but the 
 default permissions on the file then do not allow modification).

 --
 Gregory (Greg) L. Snow Ph.D.
 Statistical Data Center
 Intermountain Healthcare
 greg.s...@imail.org
 801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Nobuaki Michihata
 Sent: Thursday, September 16, 2010 8:24 AM
 To: r-help
 Subject: Re: [R] Can I save my console contents automatically?

 Hello David and Greg,
 Thank you for your suggestions. These really help me.

 I'm curious about txtStart function of TeachingDemos library. It looks
 exactly what I need.
 So I installed TeachingDemos library and tried following.
 -
 library(TeachingDemos)
 setwd(/Users/NOBU/Documents/R_data/)
 txtStart(logtest.txt, commands = TRUE, results = TRUE, append =
 FALSE)

 #Top of commands
 date()
 #End of commands

 txtStop()
 ---
 Then I got following outputs on my console window, but I only got a
 null file named logtest.txt.
 I tried several times by trial and error, but I couldn't find the
 solution to log outputs on the logtest.txt.
 ---
  library(TeachingDemos)
  setwd(/Users/NOBU/Documents/R_data/)
  txtStart(logtest.txt, commands = TRUE, results = TRUE, append =
 FALSE)
 Output being copied to text file,
 use txtStop to end
 txt
 txt #Top of commands
 txt date()
 [1] Thu Sep 16 07:16:29 2010
 txt #End of commands
 txt
 txt txtStop()

 Thank you for your help!
 Nobu



 2010/9/14 Nobuaki Michihata gha10...@gmail.com:
  Dear All,
  I found a following solution from http://r.789695.n4.nabble.com/;.
  However this command can save only the result.
  Is there any good solution to save both commands themselves and the
 results.
  Thank you for your help.
 
  sink(Filename_here.log, type=c(output,message), split=TRUE)
 
  # Put commands here
  # However this method save only the results.
 
  sink()
 
  Nobu
 
  Message: 33
  Date: Fri, 10 Sep 2010 07:07:37 -0700
  From: Nobuaki Michihata gha10...@gmail.com
  To: r-help@r-project.org, r-help@r-project.org
  Subject: [R] Can I save my console contents automatically?
  Message-ID:
         AANLkTimEZ-igqK6GzeYqERZaTg7m+chjbGJmAGmEL-
 y...@mail.gmail.com
  Content-Type: text/plain; charset=ISO-8859-1
 
  Dear All,
 
  I'm using R for Mac OS X Cocoa GUI R version 2.11.1.
  I can save contents of my console window by using command + s, but
 I
  would like to do same thing using R commands.
  My question is can I save the contents automatically by using R
 editor
  with some R commands.
 
  Thank you.
  Nobu
 

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


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


[R] removing specific rows from array

2010-09-17 Thread Maas James Dr (MED)
I'm attempting to create an array of treatment comparisons for modelling data 
generation.  This involves comparison of one treatment (c2) with another (c3), 
relative to a common comparator (c1).

Attached code gives me the correct array but need to remove duplicates.  
Duplicates relate only to c2 and c3
such that I need to remove 

r3 because c2 and c3 are same as r1 with c2 and c3 swapped 
r5 because c2 and c3 are same as r2 with c2 and c3 swapped 
r6 because c2 and c3 are same as r4 with c2 and c3 swapped
r9 because c2 and c3 are same as r7 with c2 and c3 swapped
r11 because c2 and c3 are same as r8 with c2 and c3 swapped
.
.
.

Any suggestions?

Thanks

Jim



 treats - c(t0,t1,t2,t3) 
 (combs1 - permutations(length(treats),3,treats))
  [,1] [,2] [,3]
 [1,] t0 t1 t2
 [2,] t0 t1 t3
 [3,] t0 t2 t1
 [4,] t0 t2 t3
 [5,] t0 t3 t1
 [6,] t0 t3 t2
 [7,] t1 t0 t2
 [8,] t1 t0 t3
 [9,] t1 t2 t0
[10,] t1 t2 t3
[11,] t1 t3 t0
[12,] t1 t3 t2
[13,] t2 t0 t1
[14,] t2 t0 t3
[15,] t2 t1 t0
[16,] t2 t1 t3
[17,] t2 t3 t0
[18,] t2 t3 t1
[19,] t3 t0 t1
[20,] t3 t0 t2
[21,] t3 t1 t0
[22,] t3 t1 t2
[23,] t3 t2 t0
[24,] t3 t2 t1



===
Dr. Jim Maas
University of East Anglia

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 variable from for loop in naming new variables

2010-09-17 Thread Joshua Wiley
On Fri, Sep 17, 2010 at 4:46 AM, Ivan Calandra
ivan.calan...@uni-hamburg.de wrote:
  Hi Jim,

 First, I think it's better if you reply to the list, other users might
 be interested and have better answers.

 Second, as other replies showed you, using a list is actually way easier
 than creating new objects every time. Check especially the reply from
 Joshua Wiley, which gives you great examples and guidance.

 Last, regarding rm(list=ls()), what's the point of creating new objects
 in your loop if you remove them right after?! Maybe you intend to do
 stuff on them first. Anyway, I don't use Emacs so not sure why you do it
 that way. Just my limited opinion.

 HTH,
 Ivan

 Le 9/17/2010 12:35, Maas James Dr (MED) a écrit :

 Hi Ivan,

 Thanks for suggestions, was just hoping to do it all in one step,
 creating a list and then filling it all seems rather complicated ...
 will look up *apply.

I'd be happy to try to help you simplify things, but to offer much
advice we would probably need to know more about your end goal.  At
least in the simple example you gave, the one step version is:
as.list(3 + 1:4)
but I am guessing you are not actually interested in that ;-)


 As for removing objects, I run R interactively from within Emacs (ESS)
 and stuff hangs around for successive evaluations, not sure where it
 came from so I clean it out every time ... is there a better way?

That will be because of the .Rhistory file I would think.  My
suggestion would be to clean it out once and save (so that its empty),
and from then on whenever you exit just use q(no) or just type q()
and R should ask you whether you want to save the workspace image and
you can hit n.

The only way I remember how to setup Emacs to not save by default is
to start R using C-u M-x R and then passing the command line
argument --no-save, but honestly that is so lengthy it would just be
easier to clean it out each time.  I know there's an easier way but I
never remember it.

Josh


 Thanks

 Jim

 Message: 65

 Date: Thu, 16 Sep 2010 18:03:29 +0200

 From: Ivan Calandra ivan.calan...@uni-hamburg.de

 To: r-help@r-project.org

 Subject: Re: [R] using variable from for loop in naming new variables

 Message-ID: 4c923fd1.8000...@uni-hamburg.de

 Content-Type: text/plain

   Hi!

 assign() should do the job.

 But using a list, and filling each element iteratively (with a for loop

 or with *apply() ) might be better, up to you.

 Btw, why do you remove your objects?

 HTH,

 Ivan

 Le 9/16/2010 17:44, Maas James Dr (MED) a ?crit :

  Simple one here ... but can't get it to work ...

 

  for (i in 1:4){

       paste(stuff,[i]),sep=)- 3 + i

  }

 

  ls()

  rm(list=ls())

 

 

 

  I just want it to create 4 new variables called stuff1, stuff2,
 stuff3, stuff4 with the corresponding assignments.  I realise that
 there are more elegant functions but this is just a model of a bigger
 situation.

 

  Thanks

 

  Jim

 

 ===

 Dr. Jim Maas

 Research Associate in Network Meta-Analysis

 School of Medicine, Health Policy and Practice

 CD Annex, Room 1.04

 University of East Anglia

 Norwich, UK

 NR4 7TJ

 +44 (0) 1603 591412


 --
 Ivan CALANDRA
 PhD Student
 University of Hamburg
 Biozentrum Grindel und Zoologisches Museum
 Abt. Säugetiere
 Martin-Luther-King-Platz 3
 D-20146 Hamburg, GERMANY
 +49(0)40 42838 6231
 ivan.calan...@uni-hamburg.de

 **
 http://www.for771.uni-bonn.de
 http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php


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


Re: [R] count frequency

2010-09-17 Thread Alaios
My bad :(
unfortunately does not work correct.

This is some of the output of the table
..
[494,]   50   27
[495,]   50   27
[496,]   50   27
[497,]   50   28
[498,]   50   28
[499,]   50   28
[500,]   50   28
[501,]   51   28
[502,]   51   28
[503,]   51   28
[504,]   51   28
[505,]   51   28
[506,]   51   28
[507,]   51   28
[508,]   51   28
[509,]   51   28
[510,]   51   28
[511,]   52   28
[512,]   52   28
[513,]   52   28
[514,]   52   28
[515,]   52   28
[516,]   52   29
[517,]   52   29
[518,]   52   29




I need the following results
50 27: 3
50 28: 4
51 28: 10
52 28: 5
52 29: 3


So far nothing worked.
Best Regards
Alex






From: Henrique Dallazuanna www...@gmail.com

Cc: Rhelp r-help@r-project.org
Sent: Fri, September 17, 2010 3:09:36 PM
Subject: Re: [R] count frequency

Try this:

aggregate(rep(1, nrow(x)), x, sum)




Hello everyone,
please consider the following lines of a matrix


[574,]   59   32
[575,]   59   32
[576,]   59   32
[577,]   59   32
[578,]   59   32
[579,]   59   32
[580,]   59   32
[581,]   60   32
[582,]   60   33
[583,]   60   33
[584,]   60   33
[585,]   60   33
[586,]   60   33
[587,]   60   33
[588,]   60   33
[589,]   60   33
[590,]   60   33
[591,]   61   33
[592,]   61   33
[593,]   61   33
[594,]   61   33
[595,]   61   33
[596,]   61   33
[597,]   61   33
[598,]   61   33
[599,]   61   33
[600,]   61   33
[601,]   62   34

Is it possible somehow to count the similarities between the first and second
column and put them on a third column like this?

59 32 3
60 33 5
62 34 1

where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34)

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



-- 
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] count frequency

2010-09-17 Thread Henrique Dallazuanna
So try this :

aggregate(rep(1, nrow(x)), as.data.frame(x), sum)

On Fri, Sep 17, 2010 at 11:54 AM, Alaios ala...@yahoo.com wrote:

 My bad :(
 unfortunately does not work correct.

 This is some of the output of the table
 ..
 [494,]   50   27
 [495,]   50   27
 [496,]   50   27
 [497,]   50   28
 [498,]   50   28
 [499,]   50   28
 [500,]   50   28
 [501,]   51   28
 [502,]   51   28
 [503,]   51   28
 [504,]   51   28
 [505,]   51   28
 [506,]   51   28
 [507,]   51   28
 [508,]   51   28
 [509,]   51   28
 [510,]   51   28
 [511,]   52   28
 [512,]   52   28
 [513,]   52   28
 [514,]   52   28
 [515,]   52   28
 [516,]   52   29
 [517,]   52   29
 [518,]   52   29
 


 I need the following results
 50 27: 3
 50 28: 4
 51 28: 10
 52 28: 5
 52 29: 3

 So far nothing worked.
 Best Regards
 Alex



 --
 *From:* Henrique Dallazuanna www...@gmail.com
 *To:* Alaios ala...@yahoo.com

 *Cc:* Rhelp r-help@r-project.org
 *Sent:* Fri, September 17, 2010 3:09:36 PM

 *Subject:* Re: [R] count frequency

 Try this:

 aggregate(rep(1, nrow(x)), x, sum)

 On Fri, Sep 17, 2010 at 9:19 AM, Alaios ala...@yahoo.com wrote:

 Hello everyone,
 please consider the following lines of a matrix


 [574,]   59   32
 [575,]   59   32
 [576,]   59   32
 [577,]   59   32
 [578,]   59   32
 [579,]   59   32
 [580,]   59   32
 [581,]   60   32
 [582,]   60   33
 [583,]   60   33
 [584,]   60   33
 [585,]   60   33
 [586,]   60   33
 [587,]   60   33
 [588,]   60   33
 [589,]   60   33
 [590,]   60   33
 [591,]   61   33
 [592,]   61   33
 [593,]   61   33
 [594,]   61   33
 [595,]   61   33
 [596,]   61   33
 [597,]   61   33
 [598,]   61   33
 [599,]   61   33
 [600,]   61   33
 [601,]   62   34

 Is it possible somehow to count the similarities between the first and
 second
 column and put them on a third column like this?

 59 32 3
 60 33 5
 62 34 1

 where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34)

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




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




-- 
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] function help?

2010-09-17 Thread Duke

 On 9/16/10 5:00 PM, Rolf Turner wrote:

On 17/09/2010, at 8:51 AM, Duke wrote:


  Hi Duncan,

On 9/16/10 3:47 PM, Duncan Murdoch wrote:

On 16/09/2010 3:40 PM, Duke wrote:

   Hi all,

I am writing a function (fun.R), but I dont know how to code the
function so that the Help Text will be shown up when one types ?fun (of
course, after he loads it up). Anyone has any advice for me how to do
that?



The help text is separate from the function (unless you use the
roxygen package or similar).  You need to write a package so that R
will find the help; instructions are in the Writing R Extensions manual.

I was expecting something simpler than writing a package, and that I can
integrate it into fun.R, but thanks anyway.

(a) Writing a package is not all that hard.


You can say so if you are fluent in R. I just started and have written 
only 20-30 lines of codes so far. Also, writing a package is still more 
complicated than writing a simple function (single file). Why R is so 
different from other languages (python, matlab or more basics like C/C++ 
etc...)? In fact I still feel very uncomfortable with R, for example, I 
hate when I type a function name, it shows the whole function.


Honestly I feel a world of programming is a mess, and it is tough when 
one wants to jump from one language to another.



(b) It focuses the mind wondrously.


I did try to write a simple package (followed a tutorial), but did not 
find what you said :). Maybe I need more practice.



(c) Using R CMD check on the package is very useful for picking the
lint off the code.



It would be great if you share your experience a little more about this.

Thanks,

D.


cheers,

Rolf Turner

##
Attention:
This e-mail message is privileged and confidential. If you are not the
intended recipient please delete the message and notify the sender.
Any views or opinions presented are solely those of the author.

This e-mail has been scanned and cleared by MailMarshal
www.marshalsoftware.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] question on OPTIMX with installing and using

2010-09-17 Thread Hey Sky
Dear R users

I have tried to  install the optimx but met problems.

I have gone to the website you  suggested: 
https://r-forge.r-project.org/R/?group_id=395

and tried  to install it with the following method:
install.packages(optimx, repos=http://R-Forge.R-project.org;)

I have received the  following information:
package 'numDeriv' successfully unpacked and MD5 sums  checked
package 'BB' successfully unpacked and MD5 sums checked
package  'ucminf' successfully unpacked and MD5 sums checked
package 'Rcgmin'  successfully unpacked and MD5 sums checked
package 'Rvmmin' successfully  unpacked and MD5 sums checked
package 'minqa' successfully unpacked and MD5  sums checked
package 'setRNG' successfully unpacked and MD5 sums  checked
package 'optimx' successfully unpacked and MD5 sums  checked

The downloaded packages are in
C:\Documents and  Settings\mycomputer\Local  
Settings\Temp\Rtmpd7resh\downloaded_packages

after that, I have tried the  following example from the manual of optimx but 
encountered error message  as:
Error: could not find function optimx

after that I have tried  download the package for windows, optimx_0.86.zip, and 
all other support  routines, installed them from the menu of install package 
from local zip file.  but i still met the upper error message. 



I then use: library(optimx) this loaded the optimx, I think, but the 
optansout has been masked by Rvmmin and Rcgmin. then when I tried the 
following example, the error message shows: 


Error: package 'tools' does not have a name space


any suggestions for the question on the upper two parts? any suggestion are 
apprecitated


Nan  
from Montreal



Example code from  optimx manual:

require(graphics)
fr - function(x) { ## Rosenbrock  Banana function
x1 - x[1]
x2 - x[2]
100 * (x2 - x1 * x1)^2 + (1  - x1)^2
}
grr - function(x) { ## Gradient of 'fr'
x1 -  x[1]
x2 - x[2]
c(-400 * x1 * (x2 - x1 * x1) - 2 * (1 - x1),
200 *  (x2 - x1 * x1))
}
ans1-optimx(c(-1.2,1), fr)

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

2010-09-17 Thread Alaios
You are pretty good. 
Worked nicely :)
Thanks!

Alex





From: Henrique Dallazuanna www...@gmail.com

Cc: Rhelp r-help@r-project.org
Sent: Fri, September 17, 2010 4:58:50 PM
Subject: Re: [R] count frequency

So try this :

aggregate(rep(1, nrow(x)), as.data.frame(x), sum)




My bad :(
unfortunately does not work correct.

This is some of the output of the table
..
[494,]   50   27
[495,]   50   27
[496,]   50   27
[497,]   50   28
[498,]   50   28
[499,]   50   28
[500,]   50   28
[501,]   51   28
[502,]   51   28
[503,]   51   28
[504,]   51   28
[505,]   51   28
[506,]   51   28
[507,]   51   28
[508,]   51   28
[509,]   51   28
[510,]   5128
[511,]   52   28
[512,]   52   28
[513,]   52   28
[514,]   52   28
[515,]   52   28
[516,]   52   29
[517,]   52   29
[518,]   52   29




I need the following results
50 27: 3
50 28: 4
51 28: 10
52 28: 5
52 29: 3


So far nothing worked.
Best Regards
Alex






From: Henrique Dallazuanna www...@gmail.com


Cc: Rhelp r-help@r-project.org
Sent: Fri, September 17, 2010 3:09:36 PM

Subject: Re: [R] count frequency


Try this:

aggregate(rep(1, nrow(x)), x, sum)




Hello everyone,
please consider the following lines of a matrix


[574,]   59   32
[575,]   59   32
[576,]   59   32
[577,]   59   32
[578,]   59   32
[579,]   59   32
[580,]   59   32
[581,]   60   32
[582,]   60   33
[583,]   60   33
[584,]   60   33
[585,]   60   33
[586,]   60   33
[587,]   60   33
[588,]   60   33
[589,]   60   33
[590,]   60   33
[591,]   61   33
[592,]   61   33
[593,]   61   33
[594,]   61   33
[595,]   61   33
[596,]   61   33
[597,]   61   33
[598,]   61   33
[599,]   61   33
[600,]   61   33
[601,]   62   34

Is it possible somehow to count the similarities between the first and second
column and put them on a third column like this?

59 32 3
60 33 5
62 34 1

where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34)

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



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




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



  
[[alternative HTML version deleted]]

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


[R] Voting power indices

2010-09-17 Thread Thomas Jensen

Dear R-experts,

I was wondering if anyone know of a library in R that has functions  
for calculating the Banzhaf and Shaply-Shubik indeces?


Best, Thomas

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

2010-09-17 Thread btpagano

Here it is...

 str(Males$BMXHT)
 num [1:2801] 168 161 180 182 169 ...
 str(Females$BMXHT)
 num [1:3440] 162 159 164 165 159 ...
 str(Males$yourWeight)
 num [1:2801] 1148 788 10298 25115 8691 ...
 str(Females$myWeight)
 num [1:3440] 9169 4964 2608 2806 907 ...

I want to combine Males$BMXHT with Females$BMXHT.  I also want to combine
Males$yourWeight and Females$myWeight in a similar way so that I can use the
wtd.quantile() command in the following way:

wtd.quantile(Everybody$BMXHT, weights=ourWeight, 0.05)

I know that this might seem like some elementary stuff, but I'm not too
familiar with R yet.  I hope to become much better in the future.

Thanks for all of your help,

Brian

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Combining-Data-Sets-w-Weights-tp2543167p2543995.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] How to find STRESS criteria in MDS when there are negative eigenvalues....

2010-09-17 Thread Na.Ebrahimi
Hi,
I want to know whether there is any function in R to find STRESS after using 
cmdscale and estimating the coordinates, I have written these functions to find 
stress (for p =1,2,3,4,5)
 
stress-rep(0,5)
for(p in 1:5)
{
datahat-cmdscale(d,p)
deltahat-as.matrix(dist(datahat))
a-0
b-0
for(i in 1:n)
{
for(j in 1:n)
{
a-d[i,j]^2+a
b-(d[i,j]-deltahat[i,j])^2+b
}
}
stress[p]-b/a
} 
stress-sqrt(stress)
stress
 but it seems that it is not true when there are negative eigenvalues in 
dissimilarity matrix could you please help me to find the answer
thank you in anticipation

[[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] Combining Data Sets w/ Weights

2010-09-17 Thread btpagano

Sorry, 

Rather, it should be:

wtd.quantile(Everybody$BMXHT, weights=Everybody$ourWeight, 0.05) 

Thanks again,

Brian.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Combining-Data-Sets-w-Weights-tp2543167p2543998.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Unresolves symbol in libR.so

2010-09-17 Thread Buck, Kenneth
Hello,

I am having a problem configuring a Redhat server to run R as a shared library 
called from Perl.
The error message I get is:

Can't find 'boot_R' symbol in libR.so

Has anyone run across something similar?
Any help would be greatly appreciated.

Thank you,

Kenneth Buck
Emory Winship Cancer Institute


This e-mail message (including any attachments) is for t...{{dropped:14}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Is there a project to compile R scripts into stand-alone executable file?

2010-09-17 Thread yehengxin

I know Matlab's M file can be converted to a stand-alone executable file.  I
wonder if there is a project aimed at compiling R scripts into stand-alone
executable file.  I think it will be very promising for R to be more widely
used in different fields.  
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Is-there-a-project-to-compile-R-scripts-into-stand-alone-executable-file-tp2544045p2544045.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] convert to csv file

2010-09-17 Thread lord12

I get an error message:

Error in file(file, ifelse(append, a, w)) : invalid 'open' argument

How do I resolve this?
-- 
View this message in context: 
http://r.789695.n4.nabble.com/convert-to-csv-file-tp2543232p2544070.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] a reliable way to check the latest version of R on CRAN?

2010-09-17 Thread Barry Rowlingson
On Thu, Sep 16, 2010 at 5:29 PM, Yihui Xie x...@yihui.name wrote:
 Hi all,

 We know old.packages() can check for updates of add-on packages, but
 is there a way to check updates of R itself? go to R homepage is a
 way, of course, but I hope this can be done by R.

 I'm not sure about the reliable place to check; here is a simple
 example to check from one of the CRAN webpages (kind of nasty
 approach...):

 checkRVersion in gtools does it by looking for the .tar.gz releases in CRAN:

 library(gtools)
 checkRVersion()
A newer version of R is now available: 2.11.1

 and then a bit later

 checkRVersion()
The latest version of R is installed: 2.11.1

It returns the latest version and you can make it quiet for use in scripts.

Barry

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


[R] Matrix- create mean/min/max/stdev on column of matrix or rows?

2010-09-17 Thread Halabi, Anan
I made simulation with Weibull and create Matrix,
How can I create mean/min/max/stdev on column or rows of matrix?,
Thanks, 

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


Re: [R] convert to csv file

2010-09-17 Thread Sarah Goslee
More context would be useful, but my first guess is that you are
running into problems because both file and append are functions.
If you didn't explicitly set them to something else, R is using the
function.

What happens if you instead use:
filename - myfile.csv
toappend - FALSE
file(filename, ifelse(toappend, a, w))

Sarah

On Fri, Sep 17, 2010 at 12:02 PM, lord12 gaut...@yahoo.com wrote:

 I get an error message:

 Error in file(file, ifelse(append, a, w)) : invalid 'open' argument

 How do I resolve this?
 --


-- 
Sarah Goslee
http://www.functionaldiversity.org

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


Re: [R] convert to csv file

2010-09-17 Thread William Dunlap
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of lord12
 Sent: Friday, September 17, 2010 9:02 AM
 To: r-help@r-project.org
 Subject: Re: [R] convert to csv file
 
 
 I get an error message:
 
 Error in file(file, ifelse(append, a, w)) : invalid 
 'open' argument
 
 How do I resolve this?

More context would help.  E.g., what command did you
type to get that message?

You can get it from
   sink(junk.txt, append=NULL)
  Error in file(file, ifelse(append, a, w)) : invalid 'open'
argument
or
   sink(junk.txt, append=c(TRUE,FALSE))
  Error in file(file, ifelse(append, a, w)) : invalid 'open'
argument
or
   sink(junk.txt, append=NA)
  Error in file(file, ifelse(append, a, w)) : invalid 'open'
argument
because sink expect append to be either TRUE or FALSE.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

 -- 
 View this message in context: 
 http://r.789695.n4.nabble.com/convert-to-csv-file-tp2543232p25
44070.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

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


Re: [R] Interpolate? a line

2010-09-17 Thread David Winsemius


On Sep 17, 2010, at 7:22 AM, Alaios wrote:


I would like to thank you again for your help.
But it seems that the floor function (ceiling, round too) create  
more dots in the matrix that line really touches.


You said cells not dots. Are you trying to change the problem now?  
My concern is rather that it can still miss cells.




unique( floor( cbind( seq(2,62, by=0.1), linefn(seq(2,62,  
by=0.1)) ) )  )


You can see that in the picture below

http://yfrog.com/5blineswj

So, how to select the only the cells that the line touches?


If you had taken my suggestion of overlaying a grid rather than  
plotting dots that fail to represent a cell (which I was taking to  
be a square of dimension 1 x 1) you would see that my solution was  
correct (at least to the point of not missing any cells so defined  
that were touched up to a tolerance of 0.01 cell units. If you want to  
define cells differently, then it's your turn to step up and get  
mathematically precise. Calculus still works if you define  
neighborhoods as hyperspheres s  rather than epsilon by delta hyper- 
rectangles.


# Here is the the illustrated sequence of getting to what I am calling  
my final answer,

# even though it could still miss an occasional cell.

interp - approx(c(2, 62), c(3, 34), method=linear, xout=2:62)
 m - matrix(c(interp$x, round(interp$y)), ncol=2)
 tie - m[,2] == c(-Inf, m[-nrow(m),2])
 m - m[ !tie, ]

 plot(m)  # plots points
 lines(c(2,62), c(3, 34))  # overlay line for comparison
 #you can add a grid with
 abline(v=2:62, h=3:34)

## First attempt at integer values of x

linefn - function(x) 3+((34-3)/(62-2)) *(x-2)
 findInterval(linefn(2:62), 3:34)

# Second attempt at 0.1 intervals

#
cellidxs - unique( floor( cbind( seq(2,62, by=0.1), # There will be  
many duplicates after rounding down
linefn(seq(2,62, by=0.1)) ) )  ) # the same  
function that just gets a y value


rect(cellidxs[,1], cellidxs[,2], cellidxs[,1]+1, cellidxs[,2]+1,  
col=red)


#redraw line :
lines(2:62, 3+(34-3)/(62-2)*(0:60))
# That is the first plot with coarse tolerances
#Third attempt:
# Now calculate a set of cell ids with tolerances that at ten-fold  
more numerous


cellid2 -unique( floor(cbind(seq(2,62, by=0.01), linefn(seq(2,62,  
by=0.01) )) ) )

 NROW(cellid2) # 91 cells
 rect(cellid2[,1], cellid2[,2], cellid2[,1]+1, cellid2[,2]+1,  
col=blue)
 rect(cellidxs[,1], cellidxs[,2], cellidxs[,1]+1, cellidxs[,2]+1,  
col=red)

 lines(2:62, 3+(34-3)/(62-2)*(0:60))

--
Best
David.



I would like to thank you in advance for your help
best Regards
Alex

From: David Winsemius dwinsem...@comcast.net
To: Alaios ala...@yahoo.com
Cc: Rhelp list r-help@r-project.org
Sent: Wed, September 15, 2010 1:55:10 PM
Subject: Re: [R] Interpolate? a line


On Sep 15, 2010, at 7:24 AM, David Winsemius wrote:

 Replacing context:

 Hello everyone.
 I have created a 100*100 matrix in R.
 Let's now say that I have a line that starts from (2,3) point  
and ends to the
 (62,34) point. In other words this line starts at cell (2,3) and  
ends at cell

 (62,34).

 Is it possible to get by some R function all the matrix's cells  
that this line

 transverses?

 I would like to thank you for your feedback.

 Best Regards
 Alex

 On Sep 15, 2010, at 6:52 AM, Michael Bedward wrote:

 Hello Alex,

 Here is one way to do it. It works but it's not pretty :)

 If you want an alternative, consider that produces the Y cell  
indices (since the x cell indices are already 2:62):


  linefn - function(x) 3+((34-3)/(62-2)) *(x-2)
  findInterval(linefn(2:62), 3:34)
 [1]  1  1  2  2  3  3  4  4  5  5  6  6  7  7  8  8  9  9 10 10 11  
11 12 12 13 13 14
 [28] 14 15 15 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24  
25 25 26 26 27 27 28

 [55] 28 29 29 30 30 31 32
 # that seems off by two
  linefn(62)
 [1] 34
  linefn(2)
 [1] 3 # but that checks out and I realized those were just indices  
for the 3:34 findInterval vector


  (3:34)[findInterval(linefn(2:62), 3:34)]
 [1]  3  3  4  4  5  5  6  6  7  7  8  8  9  9 10 10 11 11 12 12 13  
13 14 14 15 15 16
 [28] 16 17 17 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26  
27 27 28 28 29 29 30

 [55] 30 31 31 32 32 33 34

 ( no rounding and I think the logic is clearer.)

But I also realized it didn't enumerate all the the cells were  
crossed either, only indicating which cell was associated with an  
integer value of x. Also would have even more serious problems if  
the slope were greater than unity. To enumerate the cell indices  
that were crossed, try:


unique( floor( cbind( seq(2,62, by=0.1), linefn(seq(2,62,  
by=0.1)) ) )  )

  [,1] [,2]
[1,]23
[2,]33
[3,]44
[4,]54
[5,]55
[6,]65
[7,]75
[8,]76
snipping interior results
[83,]  58  32
[84,]  59  32
[85,]  60  32
[86,]  60  33
[87,]  61  33
[88,]  62  34

That could probably be passed to rect() to illustrate (and check  
logic):


rect(cellidxs[,1], cellidxs[,2], cellidxs[,1]+1, 

[R] How to include rows with zeros in all columns when clustering data for heatmap?

2010-09-17 Thread BD

I am making a heatmap.  In the dataset, I have couple of rows with zero value
in all the columns.   When I cluster data using hierarchical clustering, R
gives an error message.  When I get rid of those particular rows, the script
runs smoothly with no problem.  I have to include those rows somehow and
also need to cluster the data.  Is there a way around to do this?

BD
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-include-rows-with-zeros-in-all-columns-when-clustering-data-for-heatmap-tp2544115p2544115.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] Combining Data Sets w/ Weights

2010-09-17 Thread btpagano

Good News!

I think I figured out my problem.

The command I was looking for was append(). 

Thank you for your help,

Brian
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Combining-Data-Sets-w-Weights-tp2543167p2544125.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] function help?

2010-09-17 Thread Jeff Newmiller
If having the definition of the function appear when you enter the name of the 
function elicits a hate response, then perhaps you should not be using R. 
That characteristic of R is fundamental and unlikely to change: in R everything 
is an object, and the result of evaluating an expression is displayed at the 
command line. Other languages have different unifying principles, and may be 
appropriate for different tasks.

Anything that can be done in R could be done in, say, C, but by the time you 
did so you might find yourself learning very similar lessons to the ones R 
assumes you know.

Duke duke.li...@gmx.com wrote:

  On 9/16/10 5:00 PM, Rolf Turner wrote:
 On 17/09/2010, at 8:51 AM, Duke wrote:

   Hi Duncan,

 On 9/16/10 3:47 PM, Duncan Murdoch wrote:
 On 16/09/2010 3:40 PM, Duke wrote:
Hi all,

 I am writing a function (fun.R), but I dont know how to code the
 function so that the Help Text will be shown up when one types ?fun (of
 course, after he loads it up). Anyone has any advice for me how to do
 that?


 The help text is separate from the function (unless you use the
 roxygen package or similar).  You need to write a package so that R
 will find the help; instructions are in the Writing R Extensions manual.
 I was expecting something simpler than writing a package, and that I can
 integrate it into fun.R, but thanks anyway.
 (a) Writing a package is not all that hard.

You can say so if you are fluent in R. I just started and have written 
only 20-30 lines of codes so far. Also, writing a package is still more 
complicated than writing a simple function (single file). Why R is so 
different from other languages (python, matlab or more basics like C/C++ 
etc...)? In fact I still feel very uncomfortable with R, for example, I 
hate when I type a function name, it shows the whole function.

Honestly I feel a world of programming is a mess, and it is tough when 
one wants to jump from one language to another.

 (b) It focuses the mind wondrously.

I did try to write a simple package (followed a tutorial), but did not 
find what you said :). Maybe I need more practice.

 (c) Using R CMD check on the package is very useful for picking the
 lint off the code.


It would be great if you share your experience a little more about this.

Thanks,

D.

  cheers,

  Rolf Turner

 ##
 Attention:
 This e-mail message is privileged and confidential. If you are not the
 intended recipient please delete the message and notify the sender.
 Any views or opinions presented are solely those of the author.

 This e-mail has been scanned and cleared by MailMarshal
 www.marshalsoftware.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.

---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.

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

2010-09-17 Thread David Winsemius


On Sep 17, 2010, at 11:15 AM, btpagano wrote:



Here it is...


str(Males$BMXHT)

num [1:2801] 168 161 180 182 169 ...

str(Females$BMXHT)

num [1:3440] 162 159 164 165 159 ...

str(Males$yourWeight)

num [1:2801] 1148 788 10298 25115 8691 ...

str(Females$myWeight)

num [1:3440] 9169 4964 2608 2806 907 ...

I want to combine Males$BMXHT with Females$BMXHT.


If you have already gone to the trouble of splitting the data into  
separate male and female dataset (an entirely unnecessary and probably  
wasteful step I might add) then you can recombine particular vectors  
with the c() function (c for concatenate).



 I also want to combine
Males$yourWeight and Females$myWeight in a similar way so that I can  
use the

wtd.quantile() command in the following way:

wtd.quantile(Everybody$BMXHT, weights=ourWeight, 0.05)


I hope you are using the weights argument correctly. You need to be  
clear about whether these are: sampling weights, frequency weights  
(which I believe is the correct form for this particular function) or  
weights in pounds (and that would make no sense but the HT and Weight  
terminology made me ask).


wtd.quantile(  c(Males$BMXHT,Females$BMXHT) ,
 weights= c(Males$yourWeight, Females$myWeight), 0.05)

If those values had been in the same object with a sex variable, there  
would have been much more efficient methods available.




I know that this might seem like some elementary stuff, but I'm not  
too

familiar with R yet.  I hope to become much better in the future.


I fear that you have some unlearning of inefficient statistical  
practices that were taught you in Minitab classes.




Thanks for all of your help,

Brian

--
View this message in context: 
http://r.789695.n4.nabble.com/Combining-Data-Sets-w-Weights-tp2543167p2543995.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.


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] grouping dataframe entries using a categorical variable

2010-09-17 Thread Bastien Ferland-Raymond
 DearR Users,

I have a problem which I think you might be able to help.  I have a dataframe 
which I'm trying to filter following different groups I specified.  It's a 
little hard to explain, so here is an example:

My dataframe:

   ESS DHP
1  EPB  22
2  SAB  10
3  SAB  20
4  BOJ  14
5  ERS  28
11 SAB  10
12 SAB  22
13 BOJ  26
20 SAB  10
21 SAB  22
22 BOJ  32
29 SAB  14
30 SAB  22
38 SAB  14
47 SAB  18

I'm trying to filter it by selecting a subgroup of ESS, for example:
 softwood- c(EPB,SAB)

So I can obtain:
NEW dataframe:
   ESS DHP
1  EPB  22
2  SAB  10
3  SAB  20
11 SAB  10
12 SAB  22
20 SAB  10
21 SAB  22
29 SAB  14
30 SAB  22
38 SAB  14
47 SAB  18

(my real groups are actually bigger and so are my dataframe but you get the 
idea).

I have looked at subset and aggregate but it doesn't work and the loop would be 
totally inefficient. I'm sure there is a function in R that does something like 
that but I couldn't find the proper keyword to search for it.  

Thanks for your help,

Bastien
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Matrix- create mean/min/max/stdev on column of matrix or rows?

2010-09-17 Thread Dennis Murphy
Hi:

Here's a simple example that you can tune to your needs:

m - matrix(rpois(100, 10), nrow = 10)

# Function to compute summary statistics:
f - function(x) c(min = min(x), med = median(x), mean = mean(x), max =
max(x))

# Apply to rows (index 1)
apply(m, 1, f)
 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
min   5.0  7.0  5.0  6.0  5.0  5.0  8.0  5.0  2.0   6.0
med  11.5  9.5 10.0  9.5  9.0  8.0 10.0 10.0  6.0  10.0
mean 11.1  9.8 10.4 10.3  9.6  7.6 10.5  9.3  6.6   9.8
max  15.0 14.0 17.0 15.0 17.0 10.0 14.0 14.0 16.0  12.0

# Apply to columns (index 2)
apply(m, 2, f)
 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
min   3.0  6.0  5.0  6.0  2.0  5.0  5.0  5.0  8.0   6.0
med   9.0  9.5 11.0  9.5  8.5  9.5  9.0  6.0 10.5  10.0
mean  8.6  9.6 10.8  9.8  8.5  9.7  9.7  7.8 11.0   9.5
max  12.0 15.0 15.0 17.0 14.0 15.0 17.0 14.0 16.0  14.0

HTH,
Dennis

On Fri, Sep 17, 2010 at 9:08 AM, Halabi, Anan anan.hal...@hp.com wrote:

 I made simulation with Weibull and create Matrix,
 How can I create mean/min/max/stdev on column or rows of matrix?,
 Thanks,

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


[[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] convert to csv file

2010-09-17 Thread Dennis Murphy
Hi:

The first argument of ifelse is a logical statement that must evaluate to
either TRUE or FALSE. I'm guessing that you're using the append function
here, which is not a logical statement. Perhaps it would help if you
described what you wanted to do with a reproducible example to illustrate
the problem.

HTH,
Dennis

On Fri, Sep 17, 2010 at 9:02 AM, lord12 gaut...@yahoo.com wrote:


 I get an error message:

 Error in file(file, ifelse(append, a, w)) : invalid 'open' argument

 How do I resolve this?
 --
 View this message in context:
 http://r.789695.n4.nabble.com/convert-to-csv-file-tp2543232p2544070.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.


Re: [R] convert to csv file

2010-09-17 Thread Dennis Murphy
I might add that ifelse() is a vectorized function - is the operation you're
trying to perform vectorized?

D.

On Fri, Sep 17, 2010 at 10:21 AM, Dennis Murphy djmu...@gmail.com wrote:

 Hi:

 The first argument of ifelse is a logical statement that must evaluate to
 either TRUE or FALSE. I'm guessing that you're using the append function
 here, which is not a logical statement. Perhaps it would help if you
 described what you wanted to do with a reproducible example to illustrate
 the problem.

 HTH,
 Dennis


 On Fri, Sep 17, 2010 at 9:02 AM, lord12 gaut...@yahoo.com wrote:


 I get an error message:

 Error in file(file, ifelse(append, a, w)) : invalid 'open' argument

 How do I resolve this?
 --
 View this message in context:
 http://r.789695.n4.nabble.com/convert-to-csv-file-tp2543232p2544070.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.


Re: [R] grouping dataframe entries using a categorical variable

2010-09-17 Thread Ista Zahn
Hi Bastien,

You can use match(), or the convenience function %in%, like this
(assuming your data.frame is named dat):

subset(dat, ESS %in% c(EPB,SAB))

dat[dat$ESS %in% c(EPB,SAB), ]

best,
Ista

On Fri, Sep 17, 2010 at 1:02 PM, Bastien Ferland-Raymond
bastien.ferland-raymon...@ulaval.ca wrote:
  DearR Users,

 I have a problem which I think you might be able to help.  I have a dataframe 
 which I'm trying to filter following different groups I specified.  It's a 
 little hard to explain, so here is an example:

 My dataframe:

   ESS DHP
 1  EPB  22
 2  SAB  10
 3  SAB  20
 4  BOJ  14
 5  ERS  28
 11 SAB  10
 12 SAB  22
 13 BOJ  26
 20 SAB  10
 21 SAB  22
 22 BOJ  32
 29 SAB  14
 30 SAB  22
 38 SAB  14
 47 SAB  18

 I'm trying to filter it by selecting a subgroup of ESS, for example:
  softwood- c(EPB,SAB)

 So I can obtain:
 NEW dataframe:
   ESS DHP
 1  EPB  22
 2  SAB  10
 3  SAB  20
 11 SAB  10
 12 SAB  22
 20 SAB  10
 21 SAB  22
 29 SAB  14
 30 SAB  22
 38 SAB  14
 47 SAB  18

 (my real groups are actually bigger and so are my dataframe but you get the 
 idea).

 I have looked at subset and aggregate but it doesn't work and the loop would 
 be totally inefficient. I'm sure there is a function in R that does something 
 like that but I couldn't find the proper keyword to search for it.

 Thanks for your help,

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




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

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

2010-09-17 Thread David Winsemius


On Sep 17, 2010, at 12:42 PM, btpagano wrote:



Good News!

I think I figured out my problem.

The command I was looking for was append().


Er, maybe.
It does appear that you could use append() but c() is much more the  
typical R way of concatenating objects like vectors and lists. The  
only advantage of append() over c() would appear to be the capacity  
for insertion of the second argument somewhere in the middle of the  
the first.  The cbind and rbind functions are used for more complex  
objects like dataframes and matrices.


--
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] grouping dataframe entries using a categorical variable

2010-09-17 Thread Phil Spector

Bastien -
   In what way did

subset(yourdataframe,ESS %in% softwood)

not work?
- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu



On Fri, 17 Sep 2010, Bastien Ferland-Raymond wrote:


DearR Users,

I have a problem which I think you might be able to help.  I have a dataframe which I'm 
trying to filter following different groups I specified.  It's a little hard 
to explain, so here is an example:

My dataframe:

  ESS DHP
1  EPB  22
2  SAB  10
3  SAB  20
4  BOJ  14
5  ERS  28
11 SAB  10
12 SAB  22
13 BOJ  26
20 SAB  10
21 SAB  22
22 BOJ  32
29 SAB  14
30 SAB  22
38 SAB  14
47 SAB  18

I'm trying to filter it by selecting a subgroup of ESS, for example:
softwood- c(EPB,SAB)

So I can obtain:
NEW dataframe:
  ESS DHP
1  EPB  22
2  SAB  10
3  SAB  20
11 SAB  10
12 SAB  22
20 SAB  10
21 SAB  22
29 SAB  14
30 SAB  22
38 SAB  14
47 SAB  18

(my real groups are actually bigger and so are my dataframe but you get the 
idea).

I have looked at subset and aggregate but it doesn't work and the loop would be totally 
inefficient. I'm sure there is a function in R that does something like that but I 
couldn't find the proper keyword to search for it.

Thanks for your help,

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



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


[R] Preparing data frame for Plotrix kiteChart

2010-09-17 Thread Graham Smith
Although, I can fix this, I am trying to sort out something as 
straighforward as possible for my students, and I have some questions 
that hopefully someone can help me with.


My data is:

Species DistanceCount
A   5   0
A   10  5
A   15  5
A   20  3
A   25  1
B   5   8
B   10  20
B   15  28
B   20  12
B   25  12
C   5   5
C   10  12
C   15  19
C   20  27
C   25  34

But I am struggling to get this into a data frame that does what I 
expect. I have tried various arrangements.


What I am hoping for is:

an x-axis labelled Distance with tick marks at 0, 5, 10,15,20 and 25.

And, an y-axis labelled Species and tick marks labelled A, B and C.


So I would appreciate some help on how the data should be prepared for 
kiteChart, to maximise the lablels being added automatically. If possible.


Many thanks,

Graham

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] keep par settings after device closes

2010-09-17 Thread Uwe Ligges



On 16.09.2010 22:40, Jack Siegrist wrote:


I am saving several plots to different formats. I want to be able to change
the font size for all of them at once. Is there a way to do this without
having to have a call to par every time a new device is opened?


No.

At least you will need some wrapper that does it for you.

Uwe Ligges



I know that
the par settings are removed after each device is closed.

Thanks for your help,

Jack


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

2010-09-17 Thread Ravi Varadhan
Hi,

You have not provided a reproducible example, so I can only make an educated
guess.  This is likely a numerical problem with trying to solve a linear
system of equations in the Lagrange-Newton method (sequential quadratic
programming or SQP) for solving nonlinearly programming problems.  I am not
sure what you can do about this, but here is a strategy:

1. be try a different, more reasonable, starting value.  

2. If that does not help, you may want to check your problem specification
to make sure that everything (objective function, constraints) is specified
correctly

3. If (1) and (2) do not help, look at the scaling of the parameters,
objective function, and the scaling of equality and inequality constraints.
You can sometimes get convergence by simple scaling so that all these
different entities are roughly of the same order of magnitude.

4. If all else fails, try a different algorithm.  For example, the alabama
package has `constrOptim.nl' 
function that you could try.

But in future, when you ask these questions you should always send us a
minimally self-contained, reproducible example, so that we can better help
you.

Hope this is helpful,
Ravi.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Xiaoxi Gao
Sent: Friday, September 17, 2010 2:03 AM
To: R Help
Subject: [R] Nonlinear programming problem


Hello useRs,

I'm using the command solnp in package Rsolnp to solve a general
nonlinear programming problem. But I got an error that  the leading minor
of order 15 is not positive definite
. Can anybody tell what may cause this error? Does it have something to do
with the starting values? 

Thanks a lot!!!

Xiaoxi
  
[[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] Can I save my console contents automatically?

2010-09-17 Thread Greg Snow
So it looks like the problem is with the mac GUI.  Here are a couple more 
things to test.

Try it with just sink and see if the output comes through.  Also try with some 
other functions besides date (maybe summary(rnorm(100))).

If there are other Mac users out there reading this, can some of you try as 
well and see if you get similar results?

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Nobuaki Michihata
 Sent: Friday, September 17, 2010 7:03 AM
 To: r-help
 Subject: Re: [R] Can I save my console contents automatically?
 
 Hello Greg,
 Thank you for your comment.
 I had a chance to use Windows GUI R and I found several interesting
 differences between Mac and Windows GUI R.
 1. txtStart() command
 - Windows GUI R - worked perfectly
 - Mac GUI R version.string R version 2.11.1 (2010-05-31) (both
 32bit and 64bit) - only make a null file
 - Mac R version.string R version 2.11.1 (2010-05-31) on terminal
 window - worked perfectly
(I also checked the permissions, but they were OK.)
 2. Console
- Mac GUI R   can display very long results and can save them from
 the file menu (manually).
- Windows GUI R can only short results and can save only the
 displayed results from the file menu.
 3. sink()
   - Mac GUI R  - split = TRUE worked.
   - Windows GUI R -split = TRUE didn't work (log on the file, but
 didn't display the results on the console).
 
 Thanks.
 Nobu
 
  Currently comments (#) are ignored by txtStart and friends due to the
 task callback mechanism used.  The txtComment function is available as
 a work around to insert comments into the output/commands.
 
  I tried running date() as below and everything worked as expected
 (the comments were missing, but the date command and result were in the
 file.  I am running on windows where it looks like you are running on
 unix or linux.  Can you send your OS and version of R and
 TeachingDemos?  Also what are the permissions on the logtest.txt file
 that is created? (I've seen problems where the permissions for a
 directory allowed the creating of a file, but the default permissions
 on the file then do not allow modification).
 
  --
  Gregory (Greg) L. Snow Ph.D.
  Statistical Data Center
  Intermountain Healthcare
  greg.s...@imail.org
  801.408.8111
 
 
  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
  project.org] On Behalf Of Nobuaki Michihata
  Sent: Thursday, September 16, 2010 8:24 AM
  To: r-help
  Subject: Re: [R] Can I save my console contents automatically?
 
  Hello David and Greg,
  Thank you for your suggestions. These really help me.
 
  I'm curious about txtStart function of TeachingDemos library. It
 looks
  exactly what I need.
  So I installed TeachingDemos library and tried following.
  -
  library(TeachingDemos)
  setwd(/Users/NOBU/Documents/R_data/)
  txtStart(logtest.txt, commands = TRUE, results = TRUE, append =
  FALSE)
 
  #Top of commands
  date()
  #End of commands
 
  txtStop()
  ---
  Then I got following outputs on my console window, but I only got a
  null file named logtest.txt.
  I tried several times by trial and error, but I couldn't find the
  solution to log outputs on the logtest.txt.
  ---
   library(TeachingDemos)
   setwd(/Users/NOBU/Documents/R_data/)
   txtStart(logtest.txt, commands = TRUE, results = TRUE, append =
  FALSE)
  Output being copied to text file,
  use txtStop to end
  txt
  txt #Top of commands
  txt date()
  [1] Thu Sep 16 07:16:29 2010
  txt #End of commands
  txt
  txt txtStop()
 
  Thank you for your help!
  Nobu
 
 
 
  2010/9/14 Nobuaki Michihata gha10...@gmail.com:
   Dear All,
   I found a following solution from
 http://r.789695.n4.nabble.com/;.
   However this command can save only the result.
   Is there any good solution to save both commands themselves and
 the
  results.
   Thank you for your help.
  
   sink(Filename_here.log, type=c(output,message), split=TRUE)
  
   # Put commands here
   # However this method save only the results.
  
   sink()
  
   Nobu
  
   Message: 33
   Date: Fri, 10 Sep 2010 07:07:37 -0700
   From: Nobuaki Michihata gha10...@gmail.com
   To: r-help@r-project.org, r-help@r-project.org
   Subject: [R] Can I save my console contents automatically?
   Message-ID:
          AANLkTimEZ-igqK6GzeYqERZaTg7m+chjbGJmAGmEL-
  y...@mail.gmail.com
   Content-Type: text/plain; charset=ISO-8859-1
  
   Dear All,
  
   I'm using R for Mac OS X Cocoa GUI R version 2.11.1.
   I can save contents of my console window by using command + s,
 but
  I
   would like to do same thing using R commands.
   My question is can I save the contents automatically by using R
  editor
   with some R commands.
  
   Thank you.
   Nobu
  
 
  __
  R-help@r-project.org mailing list
  

Re: [R] How to find STRESS criteria in MDS when there are negative eigenvalues....

2010-09-17 Thread Ravi Varadhan
Perhaps, the smacof package on CRAN might be useful to you.

Ravi.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Na.Ebrahimi
Sent: Friday, September 17, 2010 11:08 AM
To: r-help@r-project.org
Subject: [R] How to find STRESS criteria in MDS when there are negative
eigenvalues

Hi,
I want to know whether there is any function in R to find STRESS after using
cmdscale and estimating the coordinates, I have written these functions to
find stress (for p =1,2,3,4,5)
 
stress-rep(0,5)
for(p in 1:5)
{
datahat-cmdscale(d,p)
deltahat-as.matrix(dist(datahat))
a-0
b-0
for(i in 1:n)
{
for(j in 1:n)
{
a-d[i,j]^2+a
b-(d[i,j]-deltahat[i,j])^2+b
}
}
stress[p]-b/a
} 
stress-sqrt(stress)
stress
 but it seems that it is not true when there are negative eigenvalues in
dissimilarity matrix could you please help me to find the answer
thank you in anticipation

[[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] Preparing data frame for Plotrix kiteChart

2010-09-17 Thread Ben Bolker
Graham Smith graham.smith at myotis.co.uk writes:

 
 Although, I can fix this, I am trying to sort out something as 
 straighforward as possible for my students, and I have some questions 
 that hopefully someone can help me with.
 
 My data is:
 
 Species   DistanceCount
 A 5   0
 A 10  5
 A 15  5
 A 20  3
 A 25  1
 B 5   8
 B 10  20
 B 15  28
 B 20  12
 B 25  12
 C 5   5
 C 10  12
 C 15  19
 C 20  27
 C 25  34
 
 But I am struggling to get this into a data frame that does what I 
 expect. I have tried various arrangements.
 
 What I am hoping for is:
 
 an x-axis labelled Distance with tick marks at 0, 5, 10,15,20 and 25.
 
 And, an y-axis labelled Species and tick marks labelled A, B and C.
 
 So I would appreciate some help on how the data should be prepared for 
 kiteChart, to maximise the lablels being added automatically. If possible.
 
 Many thanks,
 
 Graham
 
 


X - read.table(textConnection(Species DistanceCount
A   5   0
A   10  5
A   15  5
A   20  3
A   25  1
B   5   8
B   10  20
B   15  28
B   20  12
B   25  12
C   5   5
C   10  12
C   15  19
C   20  27
C   25  34),header=TRUE)

library(reshape)
X2 - recast(X,Distance~Species,id.var=1:2)
X3 - as.matrix(X2[,-1])
rownames(X3) - X2$Distance
colnames(X3) - names(X2)[-1]
library(plotrix)
kiteChart(t(X3),xlab=Distance,ylab=Species)

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


Re: [R] Can I save my console contents automatically?

2010-09-17 Thread David Winsemius


On Sep 17, 2010, at 2:04 PM, Greg Snow wrote:

So it looks like the problem is with the mac GUI.  Here are a couple  
more things to test.


Try it with just sink and see if the output comes through.  Also try  
with some other functions besides date (maybe summary(rnorm(100))).


If there are other Mac users out there reading this, can some of you  
try as well and see if you get similar results?



Greg;

Running the example on your txtStart help page did not seem to produce  
any file output that the Finder.app interface recognized as being  
created on this date. However that app does not do a full systemwide  
search.


Then  ... running the system() calls  to enscript and ps2pdf did  
produce evidence that somewhere an external log existed, since I got  
ps and pdf files with the message and histogram (but no console input).



R version 2.11.1 Patched (2010-06-14 r52281)
[R.app GUI 1.35 (5590) x86_64-apple-darwin9.8.0]
MacOSX 10.5.8

--
David.

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
project.org] On Behalf Of Nobuaki Michihata
Sent: Friday, September 17, 2010 7:03 AM
To: r-help
Subject: Re: [R] Can I save my console contents automatically?

Hello Greg,
Thank you for your comment.
I had a chance to use Windows GUI R and I found several interesting
differences between Mac and Windows GUI R.
1. txtStart() command
   - Windows GUI R - worked perfectly
   - Mac GUI R version.string R version 2.11.1 (2010-05-31) (both
32bit and 64bit) - only make a null file
   - Mac R version.string R version 2.11.1 (2010-05-31) on terminal
window - worked perfectly
  (I also checked the permissions, but they were OK.)
2. Console
  - Mac GUI R   can display very long results and can save them from
the file menu (manually).
  - Windows GUI R can only short results and can save only the
displayed results from the file menu.
3. sink()
 - Mac GUI R  - split = TRUE worked.
 - Windows GUI R -split = TRUE didn't work (log on the file, but
didn't display the results on the console).

Thanks.
Nobu

Currently comments (#) are ignored by txtStart and friends due to  
the
task callback mechanism used.  The txtComment function is available  
as

a work around to insert comments into the output/commands.


I tried running date() as below and everything worked as expected
(the comments were missing, but the date command and result were in  
the

file.  I am running on windows where it looks like you are running on
unix or linux.  Can you send your OS and version of R and
TeachingDemos?  Also what are the permissions on the logtest.txt file
that is created? (I've seen problems where the permissions for a
directory allowed the creating of a file, but the default permissions
on the file then do not allow modification).


--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
project.org] On Behalf Of Nobuaki Michihata
Sent: Thursday, September 16, 2010 8:24 AM
To: r-help
Subject: Re: [R] Can I save my console contents automatically?

Hello David and Greg,
Thank you for your suggestions. These really help me.

I'm curious about txtStart function of TeachingDemos library. It

looks

exactly what I need.
So I installed TeachingDemos library and tried following.
-
library(TeachingDemos)
setwd(/Users/NOBU/Documents/R_data/)
txtStart(logtest.txt, commands = TRUE, results = TRUE, append =
FALSE)

#Top of commands
date()
#End of commands

txtStop()
---
Then I got following outputs on my console window, but I only got a
null file named logtest.txt.
I tried several times by trial and error, but I couldn't find the
solution to log outputs on the logtest.txt.
---

library(TeachingDemos)
setwd(/Users/NOBU/Documents/R_data/)
txtStart(logtest.txt, commands = TRUE, results = TRUE, append =

FALSE)
Output being copied to text file,
use txtStop to end
txt
txt #Top of commands
txt date()
[1] Thu Sep 16 07:16:29 2010
txt #End of commands
txt
txt txtStop()

Thank you for your help!
Nobu



2010/9/14 Nobuaki Michihata gha10...@gmail.com:

Dear All,
I found a following solution from

http://r.789695.n4.nabble.com/;.

However this command can save only the result.
Is there any good solution to save both commands themselves and

the

results.

Thank you for your help.

sink(Filename_here.log, type=c(output,message), split=TRUE)

# Put commands here
# However this method save only the results.

sink()

Nobu


Message: 33
Date: Fri, 10 Sep 2010 07:07:37 -0700
From: Nobuaki Michihata gha10...@gmail.com
To: r-help@r-project.org, r-help@r-project.org
Subject: [R] Can I save my console contents automatically?
Message-ID:
   AANLkTimEZ-igqK6GzeYqERZaTg7m+chjbGJmAGmEL-

y...@mail.gmail.com

Content-Type: text/plain; charset=ISO-8859-1

Dear All,

I'm 

Re: [R] Is there a project to compile R scripts into stand-alone executable file?

2010-09-17 Thread Ben Bolker
yehengxin xye78 at hotmail.com writes:

 I know Matlab's M file can be converted to a stand-alone executable file.  I
 wonder if there is a project aimed at compiling R scripts into stand-alone
 executable file.  I think it will be very promising for R to be more widely
 used in different fields.  

  You could ask in R-devel, but so far there has been no one who
has needed this badly enough to go to the trouble of doing it.
What is your use case?

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

2010-09-17 Thread Liina Pilv

Dear friends,
thank you

Liina Pilv
On Jan 24, 2010, at 6:56 PM, Jim Holtman wrote:

where did you save it to; what directory?  did you restart in the  
same directory?  most likely a procedural error.


What is the problem you are trying to solve?

Sent from my iPhone.

On Jan 24, 2010, at 9:46, Liina Pilv li...@kodu.ee wrote:


Dear adviser,

I am fond of R, and enjoy it very much. But...
I have great problems.  I have saved the data before quitting but  
when

I return to the R session I can not find my saved Data again.
It is said:  Data which is saved will be available in future R
sessions. ... is not TRUE.
I work with iMAC (System Version:Mac OS X 10.5.8 (9L31a);  Kernel
Version: Darwin 9.8.0) There should be some differences between UNIX
and Mac.

thankfully waiting your answer

Liina Pilv
GP in Estonia
  [[alternative HTML version deleted]]

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




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


[R] lmer() vs. lme() gave different variance component estimates

2010-09-17 Thread array chip
Hi, I asked this on mixed model mailing list, but that list is not very active, 
so I'd like to try the general R mailing list. Sorry if anyone receives the 
double post.


Hi, I have a dataset of animals receiving some eye treatments. There are 8 

treatments, each animal's right and left eye was measured with some scores 
(ranging from 0 to 7) 4 times after treatment. So there are nesting groups eyes 
within animal. Dataset attached

 dat-read.table(dat.txt,sep='\t',header=T,row.names=1)
 dat$id-factor(dat$id)
 str(dat)
'data.frame':   640 obs. of  5 variables:
$ score: int  0 2 0 7 4 7 0 2 0 7 ...
$ id   : Factor w/ 80 levels 1,3,6,10,..: 7 48 66 54 18 26 38 52 39 63 
...
$ rep  : int  1 1 1 1 1 1 1 1 1 1 ...
$ eye  : Factor w/ 2 levels L,R: 2 2 2 2 2 2 2 2 2 2 ...
$ trt  : Factor w/ 8 levels A,B,C,Control,..: 1 1 1 1 1 1 1 1 1 1 ...

I fit a mixed model using both lmer() from lme4 package and lme() from nlme 
package:

 lmer(score~trt+(1|id/eye),dat)

Linear mixed model fit by REML 
Formula: score ~ trt + (1 | id/eye) 
   Data: dat 
   AIC   BIC logLik deviance REMLdev
446.7 495.8 -212.4430.9   424.7
Random effects:
Groups   NameVariance   Std.Dev.  
eye:id   (Intercept) 6.9208e+00 2.630742315798
id   (Intercept) 1.4471e-16 0.00012030
Residual 1.8750e-02 0.136930641909
Number of obs: 640, groups: eye:id, 160; id, 80

 summary(lme(score~trt, random=(~1|id/eye), dat))

Linear mixed-effects model fit by REML
Data: dat 
   AIC  BIClogLik
  425.1569 474.0947 -201.5785

Random effects:
Formula: ~1 | id
(Intercept)
StdDev:1.873576

Formula: ~1 | eye %in% id
(Intercept)  Residual
StdDev:1.896126 0.1369306

As you can see, the variance components estimates of random effects are quite 
different between the 2 model fits. From the data, I know that the variance 
component for id can't be near 0, which is what lmer() fit produced, so I 
think the lme() fit is correct while lmer() fit is off. This can also be seen 
from AIC, BIC etc. lme() fit has better values than lmer() fit. 


I guess this might be due to lmer() didn't converge very well, is there anyway 
to adjust to make lmer() converge better to get similar results as lme()?

Thanks

John


  score   id  rep eye trt
1   0   15  1   R   A
2   2   72  1   R   A
3   0   102 1   R   A
4   7   82  1   R   A
5   4   28  1   R   A
6   7   42  1   R   A
7   0   60  1   R   A
8   2   79  1   R   A
9   0   61  1   R   A
10  7   95  1   R   A
11  0   15  2   R   A
12  2   72  2   R   A
13  0   102 2   R   A
14  7   82  2   R   A
15  4   28  2   R   A
16  7   42  2   R   A
17  0   60  2   R   A
18  2   79  2   R   A
19  0   61  2   R   A
20  7   95  2   R   A
21  0   15  3   R   A
22  2   72  3   R   A
23  0   102 3   R   A
24  7   82  3   R   A
25  4   28  3   R   A
26  7   42  3   R   A
27  0   60  3   R   A
28  2   79  3   R   A
29  0   61  3   R   A
30  7   95  3   R   A
31  0   15  4   R   A
32  2   72  4   R   A
33  0   102 4   R   A
34  7   82  4   R   A
35  4   28  4   R   A
36  7   42  4   R   A
37  0   60  4   R   A
38  2   79  4   R   A
39  0   61  4   R   A
40  7   95  4   R   A
41  3   15  1   L   A
42  0   72  1   L   A
43  0   102 1   L   A
44  5   82  1   L   A
45  0   28  1   L   A
46  7   42  1   L   A
47  0   60  1   L   A
48  0   79  1   L   A
49  0   61  1   L   A
50  7   95  1   L   A
51  3   15  2   L   A
52  0   72  2   L   A
53  0   102 2   L   A
54  5   82  2   L   A
55  0   28  2   L   A
56  7   42  2   L   A
57  0   60  2   L   A
58  0   79  2   L   A
59  0   61  2   L   A
60  7   95  2   L   A
61  3   15  3   L   A
62  0   72  3   L   A
63  0   102 3   L   A
64  5   82  3   L   A
65  0   28  

[R] how to work with Year-Month dates

2010-09-17 Thread Joshua Wiley
Hi all,

Is there a built in or easier way to work with dates that are *just* Year-Month?
Right now I paste() on a day as a work around, but it ultimately needs to be
in Year-Month form, so then I use format() to get rid of the day.

x - c(2006-December, 2006-July)
x - paste(x, -01, sep='')
x - as.Date(x, %Y-%B-%d)
x - sort(x)
x - format(x, format = %Y-%B)
 x
[1] 2006-July 2006-December

Thanks,

Josh


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


Re: [R] how to work with Year-Month dates

2010-09-17 Thread Henrique Dallazuanna
Try this:

library(zoo)
as.yearmon(x, %Y-%B)


On Fri, Sep 17, 2010 at 4:23 PM, Joshua Wiley jwiley.ps...@gmail.comwrote:

 Hi all,

 Is there a built in or easier way to work with dates that are *just*
 Year-Month?
 Right now I paste() on a day as a work around, but it ultimately needs to
 be
 in Year-Month form, so then I use format() to get rid of the day.

 x - c(2006-December, 2006-July)
 x - paste(x, -01, sep='')
 x - as.Date(x, %Y-%B-%d)
 x - sort(x)
 x - format(x, format = %Y-%B)
  x
 [1] 2006-July 2006-December

 Thanks,

 Josh


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




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

[[alternative HTML version deleted]]

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


[R] odfWeave UTF-8 error and latin characters

2010-09-17 Thread Pedro Emmanuel Alvarenga Americano do Brasil
Hello R masters,

I have sent this same message to other lists and none so far could give some
light. I was trying to use odfWeave to generate a report from R and Im
getting an error that I think is related to latin characters. I looked
around and did find some stuff related to this problem about Sweave
http://labmoluscos.wordpress.com/2010/02/18/sweave-latex-character-encoding/
but
did not find a way to fix it so far for odfWeave. Perhaps some one could
give me some light on how to workaround it.

I think my problem is that I have a table with characters such as 'ç', 'ó'
and 'ã' that odfWeave is not recognizing properly. The error follows below.

Just to make it clear: Windows vista (default language - Brazilian
Portuguese), R 2.11.1, odfWeave 0.7.11, OpenOffice 3.0.1

in my odt file ...

  tabela2, echo = FALSE, results = xml=

odfTable(tabela2,useRowNames=T,name ='Tabela 2')

@

in R console ...

library(odfWeave)
imageDefs - getImageDefs()
imageDefs$type - 'bmp'
imageDefs$device - 'bmp'
 setImageDefs(imageDefs)
options(SweaveSyntax=SweaveSyntaxNoweb)
odfWeave('teste.odt','figura1.odt')
  Copying  teste.odt
  Setting wd to
C:\Users\PEDROE~1\AppData\Local\Temp\Rtmpfv32oJ/odfWeave0215405313
  Unzipping ODF file using unzip -o teste.odt
Archive:  teste.odt
 extracting: mimetype
   creating: Configurations2/statusbar/
  inflating: Configurations2/accelerator/current.xml
   creating: Configurations2/floater/
   creating: Configurations2/popupmenu/
   creating: Configurations2/progressbar/
   creating: Configurations2/menubar/
   creating: Configurations2/toolbar/
   creating: Configurations2/images/Bitmaps/
   inflating: content.xml
  inflating: styles.xml
 extracting: meta.xml
  inflating: Thumbnails/thumbnail.png
  inflating: settings.xml
  inflating: META-INF/manifest.xml

  Removing  teste.odt
  Creating a Pictures directory

  Pre-processing the contents
  Sweaving  content.Rnw

  Writing to file content_1.xml
  Processing code chunks ...
1 : term verbatim(label=fluxograma)
Loading required package: shape
Loading required package: shape
2 : term xml(label=tabela2)

  'content_1.xml' has been Sweaved

  Removing content.xml

  Post-processing the contents
Input is not proper UTF-8, indicate encoding !
Bytes: 0xE2 0x6E 0x63 0x69
Erro: 1: Input is not proper UTF-8, indicate encoding !
Bytes: 0xE2 0x6E 0x63 0x69


 tabela2[1:5,] # a piece of table 2
Concordância observada  Kappa p valor
Sexo:   1. 1.   0e+00
Referenciamento para diagnóstico:   0.6863 0.5081   4e-03
Reteste na doação de sangue:0.9379 0.7874   0e+00
Resultado do reteste da doação: 0.9317 0.6607   2e-04
Indicação médica para investigação: 0.6957 0.5556   1e-04

Considering some sugestions form other lists I tryed to encode the table
using enc2utf8 and descr::toUTF8 such as

tabela2, echo = FALSE, results = xml=

odfTable(enc2utf8(tabela2),useRowNames=T,name ='Tabela 2')

@

OR

tabela2, echo = FALSE, results = xml=

enc2utf8(odfTable(tabela2,useRowNames=T,name ='Tabela 2'))

@

OR

tabela2, echo = FALSE, results = xml=

toUTF8(odfTable(tabela2,useRowNames=T,name ='Tabela 2'))

@

But all of them gave the same error. However, if I set the table without the
rownames such as:

tabela2, echo = FALSE, results = xml=

odfTable(tabela2,useRowNames=F,name ='Tabela 2')

@

It works fine... but the rownames are not there. I tryed to bind the
rownames as column but the error comes back.

After a couple days banging my head around Im about to appeal to old friend
copy and paste. Any sugestion is most welcome.

Kind regards to all and thanks in advance,

Abraço forte e que a força esteja com você,

Dr. Pedro Emmanuel A. A. do Brasil
Instituto de Pesquisa Clínica Evandro Chagas
Fundação Oswaldo Cruz
Rio de Janeiro - Brasil
Av. Brasil 4365
Tel 55 21 3865-9648
email: pedro.bra...@ipec.fiocruz.br
email: emmanuel.bra...@gmail.com

---Apoio aos softwares livres
www.zotero.org - gerenciamento de referências bibliográficas.
www.broffice.org ou www.openoffice.org - textos, planilhas ou apresentações.
www.epidata.dk - entrada de dados.
www.r-project.org - análise de dados.
www.ubuntu.com - sistema operacional

[[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] Is there a bisection method in R?

2010-09-17 Thread Gregory Gentlemen
If uniroot is not a bisection method, then what function in R does use 
bisection?

Thanks.

--- On Fri, 9/10/10, David Winsemius dwinsem...@comcast.net wrote:

From: David Winsemius dwinsem...@comcast.net
Subject: Re: [R] Is there a bisection method in R?
To: huang min minhua...@gmail.com
Cc: Gregory Gentlemen gregory_gentle...@yahoo.ca, r-help@r-project.org
Received: Friday, September 10, 2010, 9:56 PM


On Sep 10, 2010, at 8:35 PM, huang min wrote:

 uniroot

 ... is not a bisection method.

 
 On Sat, Sep 11, 2010 at 6:10 AM, Gregory Gentlemen 
 gregory_gentle...@yahoo.ca wrote:
 
 Dear fellow R-users,
 
 Is there a function that does the bisection method? I was unable to find
 one.
 
 Thanks in advance.
 Gregory

--David Winsemius, MD
West Hartford, CT




[[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] how to work with Year-Month dates

2010-09-17 Thread Joshua Wiley
I had started thinking of writing my own class...this is much nicer.  Thanks!

Josh

On Fri, Sep 17, 2010 at 12:27 PM, Henrique Dallazuanna www...@gmail.com wrote:

 Try this:

 library(zoo)
 as.yearmon(x, %Y-%B)


 On Fri, Sep 17, 2010 at 4:23 PM, Joshua Wiley jwiley.ps...@gmail.com
 wrote:

 Hi all,

 Is there a built in or easier way to work with dates that are *just*
 Year-Month?
 Right now I paste() on a day as a work around, but it ultimately needs to
 be
 in Year-Month form, so then I use format() to get rid of the day.

 x - c(2006-December, 2006-July)
 x - paste(x, -01, sep='')
 x - as.Date(x, %Y-%B-%d)
 x - sort(x)
 x - format(x, format = %Y-%B)
  x
 [1] 2006-July     2006-December

 Thanks,

 Josh


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



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




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


Re: [R] function help?

2010-09-17 Thread Duke

 On 9/17/10 12:46 PM, Jeff Newmiller wrote:

If having the definition of the function appear when you enter the name of the function 
elicits a hate response, then perhaps you should not be using R. That 
characteristic of R is fundamental and unlikely to change: in R everything is an object, 
and the result of evaluating an expression is displayed at the command line. Other 
languages have different unifying principles, and may be appropriate for different tasks.



Well, *hate* or *love* is just a matter of time and / or habit, so it 
will not interfere with me doing anything, especially in work related. I 
dont mind learning anything that will serve me well. Indeed, some 
projects that I am currently working with involve some R packages and 
hence some R coding as well, so I will use R no matter if I hate it or not.



Anything that can be done in R could be done in, say, C, but by the time you 
did so you might find yourself learning very similar lessons to the ones R 
assumes you know.


I have zero background on programming, so I prefer to work and learn in 
C/C++ if I have a chance (and time). But if I need something quick, then 
I will have to use something like matlab, R or python.



Dukeduke.li...@gmx.com  wrote:


  On 9/16/10 5:00 PM, Rolf Turner wrote:

On 17/09/2010, at 8:51 AM, Duke wrote:


   Hi Duncan,

On 9/16/10 3:47 PM, Duncan Murdoch wrote:

On 16/09/2010 3:40 PM, Duke wrote:

Hi all,

I am writing a function (fun.R), but I dont know how to code the
function so that the Help Text will be shown up when one types ?fun (of
course, after he loads it up). Anyone has any advice for me how to do
that?



The help text is separate from the function (unless you use the
roxygen package or similar).  You need to write a package so that R
will find the help; instructions are in the Writing R Extensions manual.

I was expecting something simpler than writing a package, and that I can
integrate it into fun.R, but thanks anyway.

(a) Writing a package is not all that hard.

You can say so if you are fluent in R. I just started and have written
only 20-30 lines of codes so far. Also, writing a package is still more
complicated than writing a simple function (single file). Why R is so
different from other languages (python, matlab or more basics like C/C++
etc...)? In fact I still feel very uncomfortable with R, for example, I
hate when I type a function name, it shows the whole function.

Honestly I feel a world of programming is a mess, and it is tough when
one wants to jump from one language to another.


(b) It focuses the mind wondrously.

I did try to write a simple package (followed a tutorial), but did not
find what you said :). Maybe I need more practice.


(c) Using R CMD check on the package is very useful for picking the
lint off the code.


It would be great if you share your experience a little more about this.

Thanks,

D.


cheers,

Rolf Turner

##
Attention:
This e-mail message is privileged and confidential. If you are not the
intended recipient please delete the message and notify the sender.
Any views or opinions presented are solely those of the author.

This e-mail has been scanned and cleared by MailMarshal
www.marshalsoftware.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.

---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.us Basics: ##.#.   ##.#.  Live Go...
   Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] lmer() vs. lme() gave different variance component estimates

2010-09-17 Thread Peter Dalgaard
On 09/17/2010 09:14 PM, array chip wrote:
 Hi, I asked this on mixed model mailing list, but that list is not very 
 active, 
 so I'd like to try the general R mailing list. Sorry if anyone receives the 
 double post.
 
 
 Hi, I have a dataset of animals receiving some eye treatments. There are 8 
 
 treatments, each animal's right and left eye was measured with some scores 
 (ranging from 0 to 7) 4 times after treatment. So there are nesting groups 
 eyes 
 within animal. Dataset attached
 
 dat-read.table(dat.txt,sep='\t',header=T,row.names=1)
 dat$id-factor(dat$id)
 str(dat)
 'data.frame':   640 obs. of  5 variables:
 $ score: int  0 2 0 7 4 7 0 2 0 7 ...
 $ id   : Factor w/ 80 levels 1,3,6,10,..: 7 48 66 54 18 26 38 52 39 
 63 
 ...
 $ rep  : int  1 1 1 1 1 1 1 1 1 1 ...
 $ eye  : Factor w/ 2 levels L,R: 2 2 2 2 2 2 2 2 2 2 ...
 $ trt  : Factor w/ 8 levels A,B,C,Control,..: 1 1 1 1 1 1 1 1 1 1 ...
 
 I fit a mixed model using both lmer() from lme4 package and lme() from nlme 
 package:
 
 lmer(score~trt+(1|id/eye),dat)
 
 Linear mixed model fit by REML 
 Formula: score ~ trt + (1 | id/eye) 
Data: dat 
AIC   BIC logLik deviance REMLdev
 446.7 495.8 -212.4430.9   424.7
 Random effects:
 Groups   NameVariance   Std.Dev.  
 eye:id   (Intercept) 6.9208e+00 2.630742315798
 id   (Intercept) 1.4471e-16 0.00012030
 Residual 1.8750e-02 0.136930641909
 Number of obs: 640, groups: eye:id, 160; id, 80
 
 summary(lme(score~trt, random=(~1|id/eye), dat))
 
 Linear mixed-effects model fit by REML
 Data: dat 
AIC  BIClogLik
   425.1569 474.0947 -201.5785
 
 Random effects:
 Formula: ~1 | id
 (Intercept)
 StdDev:1.873576
 
 Formula: ~1 | eye %in% id
 (Intercept)  Residual
 StdDev:1.896126 0.1369306
 
 As you can see, the variance components estimates of random effects are quite 
 different between the 2 model fits. From the data, I know that the variance 
 component for id can't be near 0, which is what lmer() fit produced, so I 
 think the lme() fit is correct while lmer() fit is off. This can also be seen 
 from AIC, BIC etc. lme() fit has better values than lmer() fit. 
 
 
 I guess this might be due to lmer() didn't converge very well, is there 
 anyway 
 to adjust to make lmer() converge better to get similar results as lme()?

That's your guess... I'd be more careful about jumping to conclusions.
If this is a balanced data set, perhaps you could supply the result of

summary(aov(score~trt+Error(id/eye), data=dat))

The correct estimates should be computable from the ANOVA 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.


Re: [R] Is there a bisection method in R?

2010-09-17 Thread Greg Snow
Why does it matter what method is used?  The uniroot function used a quicker 
method than bisection, but solves the same problem, so why do you need 
bisection?  The only reason I can think is this is a homework problem, in which 
case we don't do homework.

In fact I have assigned this as homework before (to write a function to find 
roots using bisection) so I know it has been done, and is not that hard for you 
to do yourself.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Gregory Gentlemen
 Sent: Friday, September 17, 2010 1:29 PM
 To: huang min; David Winsemius
 Cc: r-help@r-project.org
 Subject: Re: [R] Is there a bisection method in R?
 
 If uniroot is not a bisection method, then what function in R does use
 bisection?
 
 Thanks.
 
 --- On Fri, 9/10/10, David Winsemius dwinsem...@comcast.net wrote:
 
 From: David Winsemius dwinsem...@comcast.net
 Subject: Re: [R] Is there a bisection method in R?
 To: huang min minhua...@gmail.com
 Cc: Gregory Gentlemen gregory_gentle...@yahoo.ca, r-h...@r-
 project.org
 Received: Friday, September 10, 2010, 9:56 PM
 
 
 On Sep 10, 2010, at 8:35 PM, huang min wrote:
 
  uniroot
 
  ... is not a bisection method.
 
 
  On Sat, Sep 11, 2010 at 6:10 AM, Gregory Gentlemen 
  gregory_gentle...@yahoo.ca wrote:
 
  Dear fellow R-users,
 
  Is there a function that does the bisection method? I was unable to
 find
  one.
 
  Thanks in advance.
  Gregory
 
 --David Winsemius, MD
 West Hartford, CT
 
 
 
 
   [[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] Is there a bisection method in R?

2010-09-17 Thread Peter Dalgaard
On 09/17/2010 09:28 PM, Gregory Gentlemen wrote:
 If uniroot is not a bisection method, then what function in R does use 
 bisection?
 

Why do you assume that there is one? uniroot contains a better algorithm
for finding bracketed roots.

It shouldn't be too hard to roll your own if you need one for
pedagogical purposes.

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


Re: [R] glm: formula vs character

2010-09-17 Thread Greg Snow
I think what is going on (and someone is likely to correct me otherwise) is 
that formulas have an associated environment that gets passed along with them 
while character strings do not.

This means that when you pass the object to another function which passes it to 
another function, etc. that eventually one of those nested functions is going 
to do something with the formula, if it is an actual formula then it can look 
in that environment that has been passed along and find the variables that the 
formula refers to and everything is happy.

When you just use the text string, the deeply nested function that is using it 
does not know where to look for the variables referred to in the formula and 
you get your error.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Krishna Tateneni
 Sent: Thursday, September 16, 2010 4:56 PM
 To: r-help
 Subject: [R] glm: formula vs character
 
 Hello,
 
 This is a question motivated by curiosity, not a pressing problem.  Any
 responses are much appreciated!  In the following code, function reg1
 calls
 glm with a formula object while reg2 uses a string.  In both cases, glm
 works; however, in the second case, the add1 function fails with the
 following message: Error in eval(predvars, data, env) : invalid
 'envir'
 argument.  Any insight into what is going on under the hood?
 
 Many thanks,
 --Krishna
 
 x1 = rnorm(100)
 x2 = rnorm(100)
 x3 = rnorm(100)
 y = x1 + 2*x2 + 3*x3 + 0.05*rnorm(100)
 
 d = data.frame(y,x1,x2,x3)
 xset = paste(x,1:3,sep=)
 
 reg1-function(dep,cand,data){
   f = paste(dep,~1,sep=)
   reg = glm(as.formula(f),family=gaussian,data)
   add = add1(reg,cand,test=F)
 }
 
 reg2-function(dep,cand,data){
   f = paste(dep,~1,sep=)
   reg = glm(f,family=gaussian,data)
   add = add1(reg,cand,test=F)
 }
 
 r1 = reg1(y,xset,d)
 r2 = reg2(y,xset,d)
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Help with graphic margin

2010-09-17 Thread Greg Snow
I can't see the graphs (my work has a rather strict policy about file sharing 
websites and apparently imageshack is redlisted).

But try adding outer=TRUE to the axis function calls and see if that fixes the 
problem.  If not, play with the par(xpd= ) setting.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Filoche
 Sent: Thursday, September 16, 2010 5:55 PM
 To: r-help@r-project.org
 Subject: Re: [R] Help with graphic margin
 
 
 Hi there and thank you for reply.
 
 I have been trying that, using mar to set margin around each plot and
 oma to
 specify bottom space.  However, it wont display the xlab.
 
 Here's my code :
 
 pdf(file=/home/persican/Desktop/test.pdf, width = 3.5, height = 5.6,
 pointsize = 8);
 
 par(mfcol = c(3,1), mar = c(1,1,1,1), oma = c(10,1,1,1));
 
 plot(x,y, pch = 21, bg = gray, xaxt = n, yaxt = n, ylab =
 ylab);
 ...
 
 plot(x,y, pch = 21, bg = gray, xaxt = n, yaxt = n, ylab =
 ylab);
 ...
 
 plot(x,y, pch = 21, bg = gray, xaxt = n, yaxt = n, ylab = ylab,
 xlab
 =X axis);
 axis(1, tck = 0.02);
 axis(2, tck = 0.02);
 
 dev.off();
 
 This produce :
 http://img837.imageshack.us/img837/5397/testpdfpages.jpg
 http://img837.imageshack.us/img837/5397/testpdfpages.jpg
 
 As we can figure, we dont see the xlab on the last plot.
 
 With regards,
 Phil
 
 
 
 --
 View this message in context: http://r.789695.n4.nabble.com/Help-with-
 graphic-margin-tp2542469p2543136.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


[R] Data Cube in R from CSV

2010-09-17 Thread clangkamp

Hello
I am at the moment trying to get to grips with a data cube in R, and I am
increasingly wondering whether I am actually making things unnecessarily
difficult for myself.
The idea is that I have a data cube with three dimensions (so a 3D matrix):
companies, figures, and years.
So along the z axis the vectors are essentially time series, the horizontals
are all about a single figure and the verticals are all the data from a
single company.

I create the data cube with the reshape package from a 2D CSV file (which in
turn is saved as a CSV file from an Excel File, which is the data master),
which works so far very fine indeed. 

Data_m-melt(Data, id=1:8, na.rm=TRUE)
Data_cube-cast(Data_m, Figure~Company~variable)

The question now comes how one can browse through this object, as view gives
it out as A.B and gets rather large. Does anyone know a way to save
resulting data cubes elegantly, i.e. maybe so that there is a tool where one
can scroll through the result, etc. ?

I presume there are several researchers here who also find that Excel is not
at all levels the best repository for R data, but who don't want to toy
around with Linux and for whom Matlab + Stats box is a little pricey.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Data-Cube-in-R-from-CSV-tp2544404p2544404.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] Preparing data frame for Plotrix kiteChart

2010-09-17 Thread Graham Smith

Ben,

Thanks for your help on this. Obviously a bit of a mental block on my 
part, as it seems painfully obvious now.


Graham

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Merging data frames on a variety of columns

2010-09-17 Thread Chris Poliquin
Hello,

This is a semi-complicated question about comparing two datasets,
probably using merge, but I am open to other ideas.  I have a large
frame of information about companies.  It's over 30,000 rows and looks
something like...

df1 -

identifier1 identifier2nameother_nameyear
   H34   C56   ACME   ACME_LTD   2001
   H34   NAACME   ACME_LTD   2002
   X20   C40   FOO_COFOO_CO  2004
   NANABAR_SABAR_SAB2004
   NANABAR_SABAR_SAB2005

As you can see, many observations are missing values.
I have a second data frame with information about these same
companies, in fewer rows, and often with slightly different info...

df2 -

identifier1 identifier2name   year
   H34   NAACME_LTD  2001
   H34   NAACME_LTD  2002
   X20   C40   FOO2004

The idea is to figure out which companies in the first set are not in
the second set.  My approach so far is to do various merges and then
remove the matches from the original data frame...

m1 - merge(df1, df2, by = c(identifier1, identifier2, year),
incomparables=NA)
m2 - merge(df1, df2, by = c(name, year), incomparables=NA)
m3 - merge(df1, df2, by.x = c(other_name, year), by.y = c(name,
year), incomparables = NA)


Is this really the best way to accomplish my goal?

Also, for some reason when I do merges like m3, my resulting data
frame is missing columns and I am getting rows that do not appear to
match on the variables I have specified, e.g. ...

year other_name   identifier1name
identifier2
2001  AMDOCS_LTDG0260210 AMDOCS_LTDED C42913


Help is much appreciated,
Chris

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] lmer() vs. lme() gave different variance component estimates

2010-09-17 Thread array chip


Thank you Peter. Actually 3 people from mixed model mailing list tried my code 
using lmer(). They got the same results as what I got from lme4(). So they 
couldn't replicate my lmer() results:

Random effects:
Groups   NameVariance Std.Dev.
eye:id   (Intercept) 3.59531  1.89613 
id   (Intercept) 3.51025  1.87357 
Residual 0.01875  0.13693 
Number of obs: 640, groups: eye:id, 160; id, 80

The only difference they can think of is they are using Mac and FreeBSD while 
mine is PC. I can't imagine this can be the reason. I re-install lme4 package, 
but still got weird results with lmer().

Per your suggestion, here is the results for aov()

summary(aov(score~trt+Error(id/eye), data=dat))

Error: id
  Df Sum Sq Mean Sq F valuePr(F)
trt7 1353.6 193.378   4.552 0.0002991 ***
Residuals 72 3058.7  42.482  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Error: id:eye
  Df Sum Sq Mean Sq F value Pr(F)
Residuals 80   115214.4   

Error: Within
   Df Sum Sq Mean Sq F value Pr(F)
Residuals 480  9 0.01875

As can be seen, thr within subject variance estimate (0.01875) is the same 
between aov, lmer and lme. But I am not sure how to relate results between aov 
and lmer/lme for the other 2 variance components (id and eye%in%id).

Thanks

John






- Original Message 
From: Peter Dalgaard pda...@gmail.com
To: array chip arrayprof...@yahoo.com
Cc: r-help@r-project.org
Sent: Fri, September 17, 2010 1:05:27 PM
Subject: Re: [R] lmer() vs. lme() gave different variance component estimates

On 09/17/2010 09:14 PM, array chip wrote:
 Hi, I asked this on mixed model mailing list, but that list is not very 
 active, 

 so I'd like to try the general R mailing list. Sorry if anyone receives the 
 double post.
 
 
 Hi, I have a dataset of animals receiving some eye treatments. There are 8 
 
 treatments, each animal's right and left eye was measured with some scores 
 (ranging from 0 to 7) 4 times after treatment. So there are nesting groups 
 eyes 

 within animal. Dataset attached
 
 dat-read.table(dat.txt,sep='\t',header=T,row.names=1)
 dat$id-factor(dat$id)
 str(dat)
 'data.frame':   640 obs. of  5 variables:
 $ score: int  0 2 0 7 4 7 0 2 0 7 ...
 $ id   : Factor w/ 80 levels 1,3,6,10,..: 7 48 66 54 18 26 38 52 39 
 63 

 ...
 $ rep  : int  1 1 1 1 1 1 1 1 1 1 ...
 $ eye  : Factor w/ 2 levels L,R: 2 2 2 2 2 2 2 2 2 2 ...
 $ trt  : Factor w/ 8 levels A,B,C,Control,..: 1 1 1 1 1 1 1 1 1 1 ...
 
 I fit a mixed model using both lmer() from lme4 package and lme() from nlme 
 package:
 
 lmer(score~trt+(1|id/eye),dat)
 
 Linear mixed model fit by REML 
 Formula: score ~ trt + (1 | id/eye) 
Data: dat 
AIC   BIC logLik deviance REMLdev
 446.7 495.8 -212.4430.9   424.7
 Random effects:
 Groups   NameVariance   Std.Dev.  
 eye:id   (Intercept) 6.9208e+00 2.630742315798
 id   (Intercept) 1.4471e-16 0.00012030
 Residual 1.8750e-02 0.136930641909
 Number of obs: 640, groups: eye:id, 160; id, 80
 
 summary(lme(score~trt, random=(~1|id/eye), dat))
 
 Linear mixed-effects model fit by REML
 Data: dat 
AIC  BIClogLik
   425.1569 474.0947 -201.5785
 
 Random effects:
 Formula: ~1 | id
 (Intercept)
 StdDev:1.873576
 
 Formula: ~1 | eye %in% id
 (Intercept)  Residual
 StdDev:1.896126 0.1369306
 
 As you can see, the variance components estimates of random effects are quite 
 different between the 2 model fits. From the data, I know that the variance 
 component for id can't be near 0, which is what lmer() fit produced, so I 
 think the lme() fit is correct while lmer() fit is off. This can also be seen 
 from AIC, BIC etc. lme() fit has better values than lmer() fit. 
 
 
 I guess this might be due to lmer() didn't converge very well, is there 
 anyway 

 to adjust to make lmer() converge better to get similar results as lme()?

That's your guess... I'd be more careful about jumping to conclusions.
If this is a balanced data set, perhaps you could supply the result of

summary(aov(score~trt+Error(id/eye), data=dat))

The correct estimates should be computable from the ANOVA 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.


Re: [R] navel-gazing

2010-09-17 Thread Joshua Wiley
I have been tinkering around with this for a bit, and I am proud to
share navel gazer 1.0.

If no arguments are passed, it will look up the top 50 authors on the
r-help list, for the given month in the given year. You can also
specify one or more months as a character vector (e.g., August or
c(August, September) ). The same goes for years.  Thanks to some
help from Henrique (although I promise this was not the only reason I
wanted it), it will not try to pull a month beyond the current one.
You can also choose a different list (such as r-devel).  If you have
the time, you can set argument entire = TRUE, which will look up every
month from whatever year(s) you specified (or the current year if you
did not). It will return a named list with each element corresponding
to one month. Also, by default it will create a dotplot in lattice
(though this may be turned off via plot = FALSE). Finally, you can
specify how many authors you want. It defaults to 50.

It is also available at here:
http://gist.github.com/584910

###

navel.gazer - function(month = NULL, year = NULL, entire = FALSE,
 list = r-help, n = 50, plot = TRUE) {
  # Ben Bolker came up with most of the code
  # Henrique Dallazuanna provided an edit to the z - line of code
  # Brian Diggs provided capwords() to properly count Peter Dalgaard
  # Joshua Wiley adapted all of it to one function


  if(is.null(month)) {
month - format(Sys.Date(), format = %B)
  }
  if(isTRUE(entire)) {
month - unique(months(as.Date(1:365, 2000-01-01)))
  }
  if(is.null(year)) {
year - format(Sys.Date(), format = %Y)
  }
  if(length(year)  1) {
tmp - vector(mode = list, length = length(year))
for(i in seq_along(year)) {
  tmp[[i]] - paste(year[i], month, sep = -)
}
times - unlist(tmp)
  } else {
times - paste(year, month, sep = -)
  }

  require(zoo)

  times - sort(as.yearmon(times, %Y-%B))
  current - as.yearmon(Sys.Date(), %Y-%m)
  times - format(times[times = current], %Y-%B)

  # Function to extract the names
  # Originally by Ben Bolker
  namefun - function(x) {
gsub(\\n,,gsub(^.+I,,gsub(/I.+$,,x)))
  }

  # Based on a suggestion by Brian Diggs
  # Capitalizes the first letter of each word
  capwords - function(s, strict = FALSE) {
cap - function(s) paste(toupper(substring(s,1,1)),
 {s - substring(s,2); if(strict) tolower(s) else s},
 sep = , collapse =   )
sapply(strsplit(s, split =  ), cap, USE.NAMES = !is.null(names(s)))
  }

  # Collects the author names for the relevant month and list
  # from the R archives
  # Originally by Ben Bolker
  grabber - function(month, list, n) {
baseurl - https://stat.ethz.ch/pipermail/;
require(RCurl)
# z - getURL(paste(baseurl,list,/,month,/author.html,sep=))
z - getURL(paste(baseurl,list,/, month,/author.html,sep=),
ssl.verifypeer = FALSE)
zz - strsplit(z,LI)[[1]]
cnames - capwords(sapply(zz[3:(length(zz)-1)],namefun))
rr - rev(sort(table(cnames)))
output - rr[1:n]
return(output)
  }

  # Create dot plots of the number of posts
  # lattice dotplot() code primarily by Ben Bolker
  plotter - function(dat) {
require(lattice)
if(length(dat)  1) {
  old.par - par(no.readonly = TRUE)
  on.exit(par(old.par))
  par(ask = TRUE)
}
for(i in seq_along(dat)) {
  print(dotplot(~rev(dat[[i]]), xlab = Number of posts,
main = names(dat)[i]))
}
invisible()
  }

  numbers - lapply(times, function(x)
{grabber(month = x, list = list, n = n)})
  names(numbers) - times

  if(plot) {
plotter(dat = numbers)
  }

  return(numbers)
}

###


Two examples:

navel.gazer(year = 2009, entire = TRUE)
navel.gazer(month = September, year = 2007)

This basically works out to be a tribute to David Winsemius:
navel.gazer(n = 1, entire = TRUE)

Hope you get a bit of fun out of this.  I certainly enjoyed writing it!

Josh

On Tue, Aug 17, 2010 at 1:10 PM, Henrique Dallazuanna www...@gmail.com wrote:
 I think that gsub example on help page is more clear:

 library(XML)

 # could be used the XML package to get the names
 cnames - gsub('\n', '', head(tail(sapply(getNodeSet(htmlParse(z, asText =
 TRUE), //i), xmlValue), -3), -3))
 gsub((\\w)(\\w*), \\U\\1\\L\\2, cnames, perl=TRUE)



 On Tue, Aug 17, 2010 at 4:44 PM, Brian Diggs dig...@ohsu.edu wrote:

 Since Peter Dalgaard is splitting his considerable contributions between
 Peter Dalgaard and peter dalgaard, I made the following changes (which
 shouldn't be a problem unless e e cummings becomes a regular poster):

 # from base::chartr documentation
 capwords - function(s, strict = FALSE) {
    cap - function(s) paste(toupper(substring(s,1,1)),
                  {s - substring(s,2); if(strict) tolower(s) else s},
                             sep = , collapse =   )
    sapply(strsplit(s, split =  ), 

Re: [R] lmer() vs. lme() gave different variance component estimates

2010-09-17 Thread Kevin Wright
I confirm John's problems with lmer.  I'm using R 2.11.1. on Windows XP.

R m4 - lmer(score~trt+(1|id/eye),dat)
R m4
Linear mixed model fit by REML
Formula: score ~ trt + (1 | id/eye)
   Data: dat
   AIC   BIC logLik deviance REMLdev
 446.7 495.8 -212.4430.9   424.7
Random effects:
 Groups   NameVariance   Std.Dev.
 eye:id   (Intercept) 6.9208e+00 2.6307e+00
 id   (Intercept) 1.4471e-16 1.2030e-08
 Residual 1.8750e-02 1.3693e-01
Number of obs: 640, groups: eye:id, 160; id, 80

One other note--the variance components from asreml agree with *lme*:

ma - asreml(score~trt , random=~id + id:eye, data=dat)
R sqrt(ma$gammas * ma$sigma2)
id!id.var id:eye!id.varR!variance
1.8735643 1.8961309 0.1369306

Kevin


On Fri, Sep 17, 2010 at 3:50 PM, array chip arrayprof...@yahoo.com wrote:



 Thank you Peter. Actually 3 people from mixed model mailing list tried my
 code
 using lmer(). They got the same results as what I got from lme4(). So they
 couldn't replicate my lmer() results:

 Random effects:
 Groups   NameVariance Std.Dev.
 eye:id   (Intercept) 3.59531  1.89613
 id   (Intercept) 3.51025  1.87357
 Residual 0.01875  0.13693
 Number of obs: 640, groups: eye:id, 160; id, 80

 The only difference they can think of is they are using Mac and FreeBSD
 while
 mine is PC. I can't imagine this can be the reason. I re-install lme4
 package,
 but still got weird results with lmer().

 Per your suggestion, here is the results for aov()

 summary(aov(score~trt+Error(id/eye), data=dat))

 Error: id
  Df Sum Sq Mean Sq F valuePr(F)
 trt7 1353.6 193.378   4.552 0.0002991 ***
 Residuals 72 3058.7  42.482
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

 Error: id:eye
  Df Sum Sq Mean Sq F value Pr(F)
 Residuals 80   115214.4

 Error: Within
   Df Sum Sq Mean Sq F value Pr(F)
 Residuals 480  9 0.01875

 As can be seen, thr within subject variance estimate (0.01875) is the same
 between aov, lmer and lme. But I am not sure how to relate results between
 aov
 and lmer/lme for the other 2 variance components (id and eye%in%id).

 Thanks

 John






 - Original Message 
 From: Peter Dalgaard pda...@gmail.com
 To: array chip arrayprof...@yahoo.com
 Cc: r-help@r-project.org
 Sent: Fri, September 17, 2010 1:05:27 PM
 Subject: Re: [R] lmer() vs. lme() gave different variance component
 estimates

 On 09/17/2010 09:14 PM, array chip wrote:
  Hi, I asked this on mixed model mailing list, but that list is not very
 active,
 
  so I'd like to try the general R mailing list. Sorry if anyone receives
 the
  double post.
 
 
  Hi, I have a dataset of animals receiving some eye treatments. There are
 8
 
  treatments, each animal's right and left eye was measured with some
 scores
  (ranging from 0 to 7) 4 times after treatment. So there are nesting
 groups eyes
 
  within animal. Dataset attached
 
  dat-read.table(dat.txt,sep='\t',header=T,row.names=1)
  dat$id-factor(dat$id)
  str(dat)
  'data.frame':   640 obs. of  5 variables:
  $ score: int  0 2 0 7 4 7 0 2 0 7 ...
  $ id   : Factor w/ 80 levels 1,3,6,10,..: 7 48 66 54 18 26 38 52
 39 63

  ...
  $ rep  : int  1 1 1 1 1 1 1 1 1 1 ...
  $ eye  : Factor w/ 2 levels L,R: 2 2 2 2 2 2 2 2 2 2 ...
  $ trt  : Factor w/ 8 levels A,B,C,Control,..: 1 1 1 1 1 1 1 1 1 1
 ...
 
  I fit a mixed model using both lmer() from lme4 package and lme() from
 nlme
  package:
 
  lmer(score~trt+(1|id/eye),dat)
 
  Linear mixed model fit by REML
  Formula: score ~ trt + (1 | id/eye)
 Data: dat
 AIC   BIC logLik deviance REMLdev
  446.7 495.8 -212.4430.9   424.7
  Random effects:
  Groups   NameVariance   Std.Dev.
  eye:id   (Intercept) 6.9208e+00 2.630742315798
  id   (Intercept) 1.4471e-16 0.00012030
  Residual 1.8750e-02 0.136930641909
  Number of obs: 640, groups: eye:id, 160; id, 80
 
  summary(lme(score~trt, random=(~1|id/eye), dat))
 
  Linear mixed-effects model fit by REML
  Data: dat
 AIC  BIClogLik
425.1569 474.0947 -201.5785
 
  Random effects:
  Formula: ~1 | id
  (Intercept)
  StdDev:1.873576
 
  Formula: ~1 | eye %in% id
  (Intercept)  Residual
  StdDev:1.896126 0.1369306
 
  As you can see, the variance components estimates of random effects are
 quite
  different between the 2 model fits. From the data, I know that the
 variance
  component for id can't be near 0, which is what lmer() fit produced, so
 I
  think the lme() fit is correct while lmer() fit is off. This can also be
 seen
  from AIC, BIC etc. lme() fit has better values than lmer() fit.
 
 
  I guess this might be due to lmer() didn't converge very well, is there
 anyway

  to adjust to make lmer() converge better to get similar results as lme()?

 That's your guess... I'd be more careful about jumping to conclusions.
 If this is a balanced data set, perhaps you could supply the result of

 

Re: [R] Data Cube in R from CSV

2010-09-17 Thread dajohnst

(This is my first post -- I hope I am doing this right)

Why not use an array?

An array can be indexed in as many dimensions as you would like, and do not
require any extra packages.  

x = array(1:27, dim = c(3, 3, 3))
x
x[1, , ]
x[ , 1, ]
x[ , , 1]

-David A. Johnston
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Data-Cube-in-R-from-CSV-tp2544404p2544486.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] Is there a bisection method in R?

2010-09-17 Thread Ravi Varadhan
Here is something simple (does not have any checks for bad input), yet
should be adequate:

bisect - function(fn, lower, upper, tol=1.e-07, ...) {
f.lo - fn(lower, ...) 
f.hi - fn(upper, ...) 
feval - 2

if (f.lo * f.hi  0) stop(Root is not bracketed in the specified interval
\n)
chg - upper - lower

while (abs(chg)  tol) {
x.new - (lower + upper) / 2
f.new - fn(x.new, ...)
if (abs(f.new) = tol) break
if (f.lo * f.new  0) upper - x.new 
if (f.hi * f.new  0) lower - x.new 
chg - upper - lower
feval - feval + 1
}
list(x = x.new, value = f.new, fevals=feval)
}

# An example
fn1 - function(x, a) {
exp(-x) - a*x 
}

bisect(fn1, 0, 2, a=1)
 
bisect(fn1, 0, 2, a=2)


Ravi.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Peter Dalgaard
Sent: Friday, September 17, 2010 4:16 PM
To: Gregory Gentlemen
Cc: r-help@r-project.org
Subject: Re: [R] Is there a bisection method in R?

On 09/17/2010 09:28 PM, Gregory Gentlemen wrote:
 If uniroot is not a bisection method, then what function in R does use
bisection?
 

Why do you assume that there is one? uniroot contains a better algorithm
for finding bracketed roots.

It shouldn't be too hard to roll your own if you need one for
pedagogical purposes.

-- 
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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Matrix- create mean/min/max/stdev on column of matrix or rows?

2010-09-17 Thread Henrik Bengtsson
See also the matrixStats package on CRAN.

/Henrik

On Fri, Sep 17, 2010 at 10:17 AM, Dennis Murphy djmu...@gmail.com wrote:
 Hi:

 Here's a simple example that you can tune to your needs:

 m - matrix(rpois(100, 10), nrow = 10)

 # Function to compute summary statistics:
 f - function(x) c(min = min(x), med = median(x), mean = mean(x), max =
 max(x))

 # Apply to rows (index 1)
 apply(m, 1, f)
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 min   5.0  7.0  5.0  6.0  5.0  5.0  8.0  5.0  2.0   6.0
 med  11.5  9.5 10.0  9.5  9.0  8.0 10.0 10.0  6.0  10.0
 mean 11.1  9.8 10.4 10.3  9.6  7.6 10.5  9.3  6.6   9.8
 max  15.0 14.0 17.0 15.0 17.0 10.0 14.0 14.0 16.0  12.0

 # Apply to columns (index 2)
 apply(m, 2, f)
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 min   3.0  6.0  5.0  6.0  2.0  5.0  5.0  5.0  8.0   6.0
 med   9.0  9.5 11.0  9.5  8.5  9.5  9.0  6.0 10.5  10.0
 mean  8.6  9.6 10.8  9.8  8.5  9.7  9.7  7.8 11.0   9.5
 max  12.0 15.0 15.0 17.0 14.0 15.0 17.0 14.0 16.0  14.0

 HTH,
 Dennis

 On Fri, Sep 17, 2010 at 9:08 AM, Halabi, Anan anan.hal...@hp.com wrote:

 I made simulation with Weibull and create Matrix,
 How can I create mean/min/max/stdev on column or rows of matrix?,
 Thanks,

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


        [[alternative HTML version deleted]]

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


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


[R] R Console - pasting into

2010-09-17 Thread Troy Lynch
For some reason, I have trouble pasting commands into the R Console (XP Pro and 
R v 2.11.1). This occurs mainly when copying from a PDF document and then 
pasting into the R Console. It will work for a while and then stop. It is 
difficult to identify what the sequence is prior to it not allowing further 
commands to be pasted into the R Console. 

Yes, the commands can be copied from the PDF into Notepad. However, after I 
have posted into the R Console for some time, it will not allow me to continue 
to do this, but I can type commands in (which can be frustrating when wanting 
to copy from another source). When it hangs, as described, I can still copy 
from the PDF into Notepad, but not from Notepad into the R Console, though I am 
still able to type commands in R Console. This means that it is not only a PDF 
but Notepad, which implies that the problem rests with the R Console.

Any ideas would be welcomed.




  
[[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] how to import this kind of data?

2010-09-17 Thread Soyeon Kim
Dear All,

I am in a trouble with reading data.

It is in txt file looking like this.

 0.00632  18.00   2.310  0  0.5380  6.5750  65.20  4.0900   1  296.0  15.30
  396.90   4.98  24.00
 0.02731   0.00   7.070  0  0.4690  6.4210  78.90  4.9671   2  242.0  17.80
  396.90   9.14  21.60
 0.02729   0.00   7.070  0  0.4690  7.1850  61.10  4.9671   2  242.0  17.80
  392.83   4.03  34.70
 0.03237   0.00   2.180  0  0.4580  6.9980  45.80  6.0622   3  222.0  18.70
  394.63   2.94  33.40
 0.06905   0.00   2.180  0  0.4580  7.1470  54.20  6.0622   3  222.0  18.70
  396.90   5.33  36.20
 0.02985   0.00   2.180  0  0.4580  6.4300  58.70  6.0622   3  222.0  18.70
  394.12   5.21  28.70
 0.08829  12.50   7.870  0  0.5240  6.0120  66.60  5.5605   5  311.0  15.20
  395.60  12.43  22.90
 0.14455  12.50   7.870  0  0.5240  6.1720  96.10  5.9505   5  311.0  15.20
  396.90  19.15  27.10

There are 14 variables. Therefore, the first of row should be at the
end of the second row.
So after importing the data, this should look like
  v1   v2v3   v4 v5v6 v7   v8
v9 v10  v11   v12v13v14
  0.00632  18.00   2.310  0  0.5380  6.5750  65.20  4.0900   1  296.0
15.30 396.90   4.98  24.00
and so on.

How can import this kind of data into R?

Thank you,

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


[R] How to compare, match two columns from diferent dataframe and assign values from one datafram to the other

2010-09-17 Thread Wang, Ying
Dear R experts,

I'm new to R. It seems to be a simple question but I just can't find a way to 
do it. Please help me.

I have two data sets x and y as shown in the following. I want to compare the 
first two columns in x and y, find the matched ones and assign the relative 
value from column 2 of y to generate the third column of x. Any help wil be 
appreciated. Thanks.

 x
  [,1] [,2]
 [1,] 1  0
 [2,] 2  0
 [3,] 3  0
 [4,] 4  0
 [5,] 5  0
 [6,] 6  0
 [7,] 7  0
 [8,] 8  0
 [9,] 9  0
[10,] 10 0
 y
 [,1] [,2]
[1,] 7  a
[2,] 4  b
[3,] 2  c
[4,] 8  d
[5,] 12 e
[6,] 15 f

The result I expect is:
x
  [,1] [,2] [,3]
 [1,] 1  0  NA
 [2,] 2  0  c
 [3,] 3  0  NA
 [4,] 4  0  b
 [5,] 5  0  NA
 [6,] 6  0  NA
 [7,] 7  0  a
 [8,] 8  0  d
 [9,] 9  0  NA
[10,] 10 0 NA


Best,

Ying

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

2010-09-17 Thread Joshua Wiley
Hi Troy,

If you are using the R GUI for Windows, I highly recommend just
copying and pasting everything into the accompanying script editor,
and then you can run the commands you want directly from there.

The Windows clipboard can be finicky sometimes, so I would not be too
hasty to think the problem rests with the R console.  You can also try
pasting using the mouse (this is actually what you have to do with the
Windows command prompt...), or using Shift+Insert as an alternate to
Ctrl + v.

Best of luck,

Josh

On Fri, Sep 17, 2010 at 2:57 PM, Troy Lynch tpl...@yahoo.com wrote:
 For some reason, I have trouble pasting commands into the R Console (XP Pro 
 and R v 2.11.1). This occurs mainly when copying from a PDF document and then 
 pasting into the R Console. It will work for a while and then stop. It is 
 difficult to identify what the sequence is prior to it not allowing further 
 commands to be pasted into the R Console.

 Yes, the commands can be copied from the PDF into Notepad. However, after I 
 have posted into the R Console for some time, it will not allow me to 
 continue to do this, but I can type commands in (which can be frustrating 
 when wanting to copy from another source). When it hangs, as described, I can 
 still copy from the PDF into Notepad, but not from Notepad into the R 
 Console, though I am still able to type commands in R Console. This means 
 that it is not only a PDF but Notepad, which implies that the problem rests 
 with the R Console.

 Any ideas would be welcomed.





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


Re: [R] how to import this kind of data?

2010-09-17 Thread Phil Spector

Soyeon -
   I think scan() (combined with matrix and data.frame) is the 
easiest way.

   Suppose your text file is called data.txt.  Then

data.frame(matrix(scan('data.txt'),byrow=TRUE,ncol=14))

should give you what you want.
- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu


On Fri, 17 Sep 2010, Soyeon Kim wrote:


Dear All,

I am in a trouble with reading data.

It is in txt file looking like this.

0.00632  18.00   2.310  0  0.5380  6.5750  65.20  4.0900   1  296.0  15.30
 396.90   4.98  24.00
0.02731   0.00   7.070  0  0.4690  6.4210  78.90  4.9671   2  242.0  17.80
 396.90   9.14  21.60
0.02729   0.00   7.070  0  0.4690  7.1850  61.10  4.9671   2  242.0  17.80
 392.83   4.03  34.70
0.03237   0.00   2.180  0  0.4580  6.9980  45.80  6.0622   3  222.0  18.70
 394.63   2.94  33.40
0.06905   0.00   2.180  0  0.4580  7.1470  54.20  6.0622   3  222.0  18.70
 396.90   5.33  36.20
0.02985   0.00   2.180  0  0.4580  6.4300  58.70  6.0622   3  222.0  18.70
 394.12   5.21  28.70
0.08829  12.50   7.870  0  0.5240  6.0120  66.60  5.5605   5  311.0  15.20
 395.60  12.43  22.90
0.14455  12.50   7.870  0  0.5240  6.1720  96.10  5.9505   5  311.0  15.20
 396.90  19.15  27.10

There are 14 variables. Therefore, the first of row should be at the
end of the second row.
So after importing the data, this should look like
 v1   v2v3   v4 v5v6 v7   v8
   v9 v10  v11   v12v13v14
 0.00632  18.00   2.310  0  0.5380  6.5750  65.20  4.0900   1  296.0
15.30 396.90   4.98  24.00
and so on.

How can import this kind of data into R?

Thank you,

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



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


  1   2   >