Re: [R] Efficient sampling from a discrete distribution in R

2007-09-04 Thread Robin Hankin

On 4 Sep 2007, at 08:40, Issac Trotts wrote:

> On 9/3/07, Prof Brian Ripley <[EMAIL PROTECTED]> wrote:
>
>> Yes, vectorize, and don't grow vectors. See 'S  
>> Programming' (details in
>> the R FAQ).
>
> It's easy to avoid growing the samples vector but it doesn't seem to
> make much difference.  Vectorizing would be probably help, but in this
> algorithm each step depends on the one before it.  Do you know of an
> alternative to the Chinese restaurant process that is vectorizable?
>


The Chinese restaurant process is simulated in the untb package,
in what I believe is a reasonably efficient manner.

[I find to my horror that "help.search("Chinese restaurant") returns
empty-handed.  I will add a suitable \concept{} entry to untb.Rd]

Best wishes


Robin



>> We've no idea about you (the R posting guide does ask for a signature
>> block), but if this is homework some people are going to be annoyed.
>
> No, it's for my job at Google, so maybe I should use my work email
> address to avoid confusion.  Sorry if the questions are so basic that
> they sound like homework, but you and others on the list know things
> that aren't easy to find in the documentation.
>
> -- 
> Issac Trotts
> Web Operations Chair
> Silicon Valley Web Builder
> http://svwebbuilder.com
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Incomplete Gamma function

2007-09-03 Thread Robin Hankin
Hello Ted


thanks for the comments below.

You point out below some less-than-perfect aspects of
some of my documentation (bizarrely, this is not the first time that  
this
has happened.  The real problem is  that *other people* insist on
reading the docs, when as everyone knows, the real purpose
of documentation is to remind the *developer* what he's done ;-).

The issue with the gsl_sf_ prefix is interesting.  I decided that
having an R function named "gsl_sf_gamma_inc()" would be
a bit long-winded, so I removed the prefix.  I did this elsewhere
too, notably Bessel.Rd, because I felt that the GSL naming scheme
was sufficiently distinct from R's in the case of Bessel functions to
obviate typing "gsl_sf_" every single time.

But as you point out, this is potentially confusing to a user; as a
developer, one tends to see the Rd file as one of a number of files
that one must edit, and in the case of  the gsl library, the R and C
code is very regimented and has adequate inline comments.  But
I'd lost sight of the fact that many users' sole source of documentation
is the Rd files.  And in the  case of gsl, the documentation is just a
pointer to ams-55 via gsl-ref [the GSL reference manual].  I now
suspect that my short function definitions have unnecessarily
obscured that audit trail.

What I think I'll do  (read "will add to my to-do-list")
is to (eg) define R function gsl_sf_gamma_inc()
and then define gamma_inc <- gsl_sf_gamma_inc
and add appropriate aliases to the docs.

Then I could deprecate gsl_inc(); and then possibly defunct them.

Anyone got any comments on this?  Do other package developers
have any experiences of making functions defunct that would be  
interesting?
How long do folk leave functions deprecated before defuncting them?

best wishes

Robin


On 1 Sep 2007, at 15:50, (Ted Harding) wrote:


[snip]

>
> In the documenation for the Gamma functions in the gsl package,
> it is simply stated
>
>   All functions [including gamma_inc()] as documented in the
>   GSL reference manual section 7.19.
>
> There is no function named "gamma_inc" in the GSL reference
> manual. See:
>
> http://www.gnu.org/software/gsl/manual/html_node/Function-Index.html
>
> All functions are named like "gsl_sf_gamma_inc", so
> presumably this is what is intended; in which case it computes
> "the unnormalized incomplete Gamma Function
>  \Gamma(a,x) = \int_x^\infty dt t^{a-1} \exp(-t)
>  for a real and x >= 0."
>
> And again that is clear enough -- once you track it down!
>
> In many places in the R documentation (including the "?" pages)
> people have taken the trouble to spell out mathematical definitions
> (where these can be given in reasonable space). Especially in cases
> like the Incomplete Gamma and Beta functions, where there can be
> dispute over what is meant (see above), it is surely wise to spell
> it out!
>
> Best wishes to all,
> Ted.
>
>>> On 31 Aug 2007, at 00:29, [EMAIL PROTECTED] wrote:
>>>
>>>> Hello
>>>>
>>>> I am trying to evaluate an Incomplete gamma function
>>>> in R. Library Zipfr gives the Igamma function. From
>>>> Mathematica, I have:
>>>>
>>>> "Gamma[a, z] is the incomplete gamma function."
>>>>
>>>> In[16]: Gamma[9,11.1]
>>>> Out[16]: 9000.5
>>>>
>>>> Trying the same in R, I get
>>>>
>>>>> Igamma(9,11.1)
>>>> [1] 31319.5
>>>> OR
>>>>> Igamma(11.1,9)
>>>> [1] 1300998
>>>>
>>>> I know I have to understand the theory and the math
>>>> behind it rather than just ask for help, but while I
>>>> am trying to do that (and only taking baby steps, I
>>>> must admit), I was hoping someone could help me out.
>>>>
>>>> Regard
>>>>
>>>> Kris.
>
> --------
> E-Mail: (Ted Harding) <[EMAIL PROTECTED]>
> Fax-to-email: +44 (0)870 094 0861
> Date: 01-Sep-07   Time: 15:49:57
> -- XFMail --
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Incomplete Gamma function

2007-08-31 Thread Robin Hankin

On 31 Aug 2007, at 14:06, Prof Brian Ripley wrote:

> On Fri, 31 Aug 2007, Robin Hankin wrote:
>
>> Hi Kris
>>
>>
>> lgamma() gives the log of the gamma function.
>
> Yes, but he used Igamma.  According to ?pgamma,
>
>  'pgamma' is closely related to the incomplete gamma function.  As
>  defined by Abramowitz and Stegun 6.5.1
>
>  P(a,x) = 1/Gamma(a) integral_0^x t^(a-1) exp(-t) dt
>
>  P(a, x) is 'pgamma(x, a)'.  Other authors (for example Karl
>  Pearson in his 1922 tables) omit the normalizing factor, defining
>  the incomplete gamma function as 'pgamma(x, a) * gamma(a)'.
>
> and that seems to be what Igamma is following.  GSL on the other  
> hand has the other tail, so
>
>> a <- 9
>> x <- 11.1
>> pgamma(x, a, lower=FALSE)*gamma(a)
> [1] 9000.501
>
>>
>> You need gamma_inc() of the gsl package, a wrapper for the
>> GSL library:
>>
>> > gamma_inc(9,11.1)
>> [1] 9000.501
>> >
>
> As the above shows, you don't *need* this, but you do need the GSL  
> documentation to find out what R package gsl does.  Why it differs  
> from the usual references is something for you to explain.  Wikipedia
> http://en.wikipedia.org/wiki/Incomplete_gamma_function
> distinguishes them, as does MathWorld.
>
> I suggest you add a clarification to the gsl package as to what the  
> 'incomplete gamma function' means there.

GSL gives both tails for the normalized incomplete gamma function but  
not the unnormalized version, for which
only the upper incomplete gamma function is given.

This seems a strange omission; I'll raise it on the GSL mailing list.

re your request for clarification in the gsl helpfiles:  I'm  
uncertain about this.
The gsl library is supposed to be a "no-brainer" wrapper for GSL  
functions;  anything
documented in .Rd files will be 100% dominated by gsl-ref [the GSL  
manual].   That's
why the documentation in gsl is restricted to the rather curt  "see  
the GSL documentation".

But I appreciate that this seems rather unhelpful.

Best wishes



rksh




--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Incomplete Gamma function

2007-08-31 Thread Robin Hankin
Hi Kris


lgamma() gives the log of the gamma function.

You need gamma_inc() of the gsl package, a wrapper for the
GSL library:

 > gamma_inc(9,11.1)
[1] 9000.501
 >

HTH

rksh





On 31 Aug 2007, at 00:29, [EMAIL PROTECTED] wrote:

> Hello
>
> I am trying to evaluate an Incomplete gamma function
> in R. Library Zipfr gives the Igamma function. From
> Mathematica, I have:
>
> "Gamma[a, z] is the incomplete gamma function."
>
> In[16]: Gamma[9,11.1]
> Out[16]: 9000.5
>
> Trying the same in R, I get
>
>> Igamma(9,11.1)
> [1] 31319.5
> OR
>> Igamma(11.1,9)
> [1] 1300998
>
> I know I have to understand the theory and the math
> behind it rather than just ask for help, but while I
> am trying to do that (and only taking baby steps, I
> must admit), I was hoping someone could help me out.
>
> Regard
>
> Kris.
>
>
>
> __ 
> __
> Got a little couch potato?
> Check out fun summer activities for kids.
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Behaviour of very large numbers

2007-08-31 Thread Robin Hankin
Hello


On 30 Aug 2007, at 16:08, willem vervoort wrote:


>
> What happens when you raise a negative value to a power and the result
> is a very large number?
>

[snip]


>  I loaded package Brobdingnag and tried:
> as.brob(x^B)
>   [1] NAexp(NaN) NAexp(NaN) NAexp(NaN) NAexp(NaN) NAexp(NaN)
>> as.brob(x)^B
>   [1] NAexp(187.67) NAexp(187.65) NAexp(187.63) NAexp(187.61)
>
> I guess I must be misunderstanding something fundamental.
>


As others have said, in this case one needs complex arithmetic.  In a
Brobdingnagian context one would use Glubbdubdribian numbers:

 > x <- seq(-51,-49,length=10)
 > as.glub(x)^112313.3
[1] -exp(441600)-exp(441600)i   -exp(441110)-exp(441110)i   -exp 
(440610)-exp(440610)i
[4] -exp(440120)-exp(440120)i   -exp(439620)-exp(439620)i   -exp 
(439120)-exp(439120)i
[7] -exp(438620)-exp(438620)i   -exp(438120)-exp(438120)i   -exp 
(437610)-exp(437610)i
[10] -exp(437100)-exp(437100)i
 >




--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] integration over a simplex

2007-07-10 Thread Robin Hankin
Hello

The excellent adapt package integrates over multi-dimensional
hypercubes.

I want to integrate over a multidimensional simplex.  Has anyone
implemented such a thing in R?

I can transform an n-simplex to a hyperrectangle
but the Jacobian is a rapidly-varying (and very lopsided)
function and this is making adapt() slow.

[
A \dfn{simplex} is an n-dimensional analogue of a triangle or  
tetrahedron.
It is the convex hull of (n+1) points in an n-dimensional Euclidean  
space.

My application is a variant of the Dirichlet distribution:
With p~D(a), if length(p) = n+1 then the requirement that
all(p>0) and sum(p)=1 mean that the support of the
Dirichlet distribution is an n-simplex.
]


--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] (no subject)

2007-07-06 Thread Robin Hankin
Jonathan

the BACCO bundle (emulator package) does exactly what you require.

(it's easier to think in terms of the variance matrix than a matrix
of distances, tho')

HTH

Robin



On 5 Jul 2007, at 20:07, Jonathan Greenberg wrote:

> I'm trying to hunt down an appropriate kriging package for my specific
> application, and I was hoping someone on the R list might have some  
> pointers
> --  I'm interested in performing kriging and related spatial  
> interpolations
> with one of the R packages, but I need to be able to provide my own
> point-to-point distances (e.g. I do not want to use standard  
> between point
> distances, as calculated by Euclidean or other similar distance  
> measures).
> Is there an R package that *I* can provide the matrix of distances  
> between
> every pair of points (e.g. for 10 points, I would have a 10 x 10  
> matrix of
> distances)?  Similarly, if this is possible, can I then provide  
> this package
> a vector of distances from each point to an arbitrary unknown  
> location (in
> my example, this would be a 1x10 vector) and apply the model to  
> this vector
> to predict a single unknown point?  It seems most (if not all) of the
> kriging packages I'm finding for R take the x,y,z location as the  
> inputs and
> calculate these distances themselves.  Thanks!
>
> Sincerely,
>
> Jonathan Greenberg
>
> --
> Jonathan A. Greenberg, PhD
> Postdoctoral Scholar
> Center for Spatial Technologies and Remote Sensing (CSTARS)
> University of California, Davis
> One Shields Avenue
> The Barn, Room 250N
> Davis, CA 95616
> Cell: 415-794-5043
> AIM: jgrn307
> MSN: [EMAIL PROTECTED]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] vectorize a function

2007-06-22 Thread Robin Hankin
Hello everyone

suppose I have an integer vector "a" of length "n" and
a symmetric matrix "M" of size n-by-n.

Vector "a" describes a partition of a set of "n" elements
and matrix M describes a penalty function: row i column
j represents the penalty if element i and element j
are in the same partition.

Toy example follows; the real case is much larger
and I need to evaluate my penalty function many times.

If a <- c(1,1,2,1,3)  then elements 1,2,4 are in the
same partition; element 3 is in a partition on its own
and element 5 is in a partition on its own.

The total penalty  can be described by the following (ugly)
function:

f <- function(a,M){
   out <- 0
   for(i in unique(a)){
 out <- out + sum(M[which(a==i),which(a==i)])
   }
   return(out)
}


so with

M <- matrix(rpois(25,3),5,5)
M <- M+t(M)
diag(M) <- 0
a <- c(1,2,1,1,3)

f(a,M) gives the total penalty.


QUESTION:  how to rewrite f() so that it has no loop?






--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 create .rda file to be used in package building

2007-06-21 Thread Robin Hankin
Deli

the way I do it is to start with an
R session with the data objects in
memory.

Then package.skeleton() creates a
directory tree which is, well, a package skeleton,
including the data which appears as .rda files in
the data/ directory.

HTH

Robin


On 20 Jun 2007, at 21:50, Deli Wang wrote:

> Hi,
>
> Can someone tell me how to create .rda data files in R so that they  
> can be
> used contributed package?
>
> Thanks
>
> Deli Wang
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] data.frame

2007-06-18 Thread Robin Hankin

On 18 Jun 2007, at 14:16, Adaikalavan Ramasamy wrote:

> See help(dim) and please read the manuals before asking basic  
> questions
> like this. Thank you.
>


I think the questioner was looking for row() and col(), which (IMO) are
difficult to find if you don't know of their existence.


[as indeed are slice.index() or arow()  for the array case]

Robin


>
> elyakhlifi mustapha wrote:
>> hello,
>> are there functions giving the columns number and the rows number  
>> of a matrix?
>> thanks.
>>
>>
>>
>> _ 
>> 
>>
>>  [[alternative HTML version deleted]]
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] triangle contour plots

2007-06-18 Thread Robin Hankin
Suppose I have three numbers p1, p2, p3 with
0 <= p1,p2,p3 <= 1  and p1+p2+p3=1,
and a  function  f=f(p1,p2,p3)   =  f(p1,p2,1-p1-p2).

How to draw a contour plot of f() on the p1+p2+p3=1 plane,
that is, an equilateral triangle?

Functions triplot(), triangle.plot(), and ternaryplot()  give
only  scatterplots, AFAICS





--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] besselK

2007-06-14 Thread Robin Hankin
Hello

AFAIK, R has no capability for evaluating Bessel functions for  
complex arguments.

Bessel functions for complex arguments are difficult to evaluate  
numerically.
Some Bessel functions require cut lines or consideration of Riemann  
surfaces.

The GSL library (for which the gsl package is an R wrapper) does
not include such functionality although the issue has arisen
on the GSL email list a couple of times over the last few years.

Writing R functionality for Bessel functions (and in particular
the Airy function) is on my List of Things To Do, but
don't hold your breath  . . .

best wishes


Robin




On 14 Jun 2007, at 10:31, ivivi mwaniki wrote:

> Assistance,
> besselK- complex number problem
>  Im a student  intrested in using R in my learning and research  
> work in option pricing however i have a problem with besselK  
> function In R.
>  Would you assit me in computing the besselK of third kind of a  
> complex number in R.
>  Any code or suggestion will be highly appriceiated
>  eg
>  besselK(2,10)  works well.. but
>  besselK(2,10i) doesnt work !!
>
>  im supprised it works in MATLAB but NOT in R.
>  rgds
>  ivivi mwaniki
>  student kenya
>
>
> -
> Don't pick lemons.
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Filling array: No recycling

2007-05-03 Thread Robin Hankin
Felix

I'm not quite sure I understand your example, but try:

a <- array(NA,c(2,2,3))
jj <- c(12,33,22)
a[1:length(jj)] <- jj
a

which will fill only the first three elemens of array "a"


HTH

rksh



On 3 May 2007, at 10:41, Felix Wave wrote:

> Hello,
> is it possible to fill an array with no using of the recycling rule?
> My problem. I want to fill an array but my values have not always
> the same length.
> My aim. I want to fill the array only ONE TIME. All vacent places
> should be written with NA.
>
>
>
> Thank's a lot.
> Felix
>
>
> Example:
> 
>
> #Write 1 to 3 only one time. The last
> #5 place should be NA.
>
> dim(as.array(letters))
> array(1:3, c(2,4) )
>
> #na.strings = "NA"
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Inflate/Expand/Resize an array

2007-04-27 Thread Robin Hankin
[replying to myself]

it might be better to use

sweep(f,(1:6)[-2],m,"+")

instead.




On 27 Apr 2007, at 11:56, Robin Hankin wrote:

> Hi
>
>
>   f.dims <- c(10,25,1,1,1,14)
>   m.dims <- c(10, 1,1,1,1,14)
>   f <- array(1:prod(f.dims),f.dims)
>   m <- array(1:prod(m.dims),m.dims)
>   jj <- do.call(abind,c(rep(list(m),25),along=2))
>
>
> Then
>
> f + jj
>
> will give you what you want.
>
>
> The more general problem is a bit harder, as you say
>
>
> HTH
>
> rksh
>
>
> On 27 Apr 2007, at 10:41, Mark Payne wrote:
>
>> Gudday,
>>
>> I've had a good look everywhere trying to figure out how to do
>> this, but
>> I'm afraid I can seem to find an answer anywhere - maybe its
>> because I'm
>> not using the right terms, or maybe its because I'm a dummy. But
>> unfortunately, I am not completely and utterly stuck. Here's the
>> problem:
>>
>> I have two large, six dimensional arrays that I would like to add
>> together. Lets call them f and m. Their dimensions are respectively:
>>
>>> dim(f)
>> [1] 10  25  1  1  1 14
>>> dim(m)
>> [1] 10 1 1 1 1 14
>>
>> You can see that they're pretty close in size, but not identical.
>> What I
>> would like to do is expand or inflate m along its second dimension so
>> that it ends up with dimension 10 25 1 1 1 14, so that I can then add
>> the two together - the new values created along that second dimension
>> would simply be copies of the first value..
>>
>> What's the fastest way to do this? Is there a dedicated function?
>> Ideally I envisage something that you feed the input array, and the
>> desired dimensions, and it does the rest for you. Please also bear in
>> mind that this is a specific problem - the more general case is
>> where I
>> don't know which dimensions are "out of shape", so to speak...
>>
>> I hope that's clear, and that someone can me out here...
>>
>> Cheers,
>>
>> Mark
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-
>> guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton
> European Way, Southampton SO14 3ZH, UK
>   tel  023-8059-7743
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Inflate/Expand/Resize an array

2007-04-27 Thread Robin Hankin
Hi


  f.dims <- c(10,25,1,1,1,14)
  m.dims <- c(10, 1,1,1,1,14)
  f <- array(1:prod(f.dims),f.dims)
  m <- array(1:prod(m.dims),m.dims)
  jj <- do.call(abind,c(rep(list(m),25),along=2))


Then

f + jj

will give you what you want.


The more general problem is a bit harder, as you say


HTH

rksh


On 27 Apr 2007, at 10:41, Mark Payne wrote:

> Gudday,
>
> I've had a good look everywhere trying to figure out how to do  
> this, but
> I'm afraid I can seem to find an answer anywhere - maybe its  
> because I'm
> not using the right terms, or maybe its because I'm a dummy. But
> unfortunately, I am not completely and utterly stuck. Here's the
> problem:
>
> I have two large, six dimensional arrays that I would like to add
> together. Lets call them f and m. Their dimensions are respectively:
>
>> dim(f)
> [1] 10  25  1  1  1 14
>> dim(m)
> [1] 10 1 1 1 1 14
>
> You can see that they're pretty close in size, but not identical.  
> What I
> would like to do is expand or inflate m along its second dimension so
> that it ends up with dimension 10 25 1 1 1 14, so that I can then add
> the two together - the new values created along that second dimension
> would simply be copies of the first value..
>
> What's the fastest way to do this? Is there a dedicated function?
> Ideally I envisage something that you feed the input array, and the
> desired dimensions, and it does the rest for you. Please also bear in
> mind that this is a specific problem - the more general case is  
> where I
> don't know which dimensions are "out of shape", so to speak...
>
> I hope that's clear, and that someone can me out here...
>
> Cheers,
>
> Mark
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 problem about all possible sequences

2007-04-17 Thread Robin Hankin
Paul


f <- function(n){expand.grid(rep(list(0:1),n))}
f(10)
[snip]


HTH

Robin



On 17 Apr 2007, at 15:26, Paul Smith wrote:

> Dear All
>
> Suppose a sequence of length 10 generated by the following rule: the
> first element is 0 with 50% of probability or 1 with the same
> probability; the second element likewise; and so on.
>
> Is there some R command to obtain all possible different sequences
> formed by the above rule? I am aware that one could write a small
> program to do that, but I am speculating about whether a command is
> already existent.
>
> Thanks in advance,
>
> Paul
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Find zeros of analytic functions

2007-04-16 Thread Robin Hankin

>> Dear Partecipants to the list,
>
>> I am Enrico Foscolo, a student of the Faculty of Statistics,  
>> University of Bologna,
>> and I am interested under consideration of the search of zeros of  
>> one function.
>> I would want to write a code using the software R.
>> I have already read the book "Computing the Zeros of Analytic  
>> Functions" (P. Kravanja and M. Van Barel, 2000) that speaks about  
>> this problem, computing a Fortran 90 code.
>> Consequently, I would want to ask You if:
>> - already exists a R code,
>
> I presume you mean analytic functions of a complex argument.  Few R
> packages use complex vectors, and none of those few do this to my
> knowledge.
>

If iterative methods are appropriate,
it's perhaps worth pointing out that Newton-Rapheson
works nicely for complex functions.

The "elliptic" package includes function newton.rapheson()
for this, in addition to other utilities for analyzing
complex functions.


HTH




--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] quick legend() question

2007-03-22 Thread Robin Hankin
Hi

I have a scatterplot of points with pch=1 and a single point with  
pch=3, lwd=3.
It has a high line width to attract attention to it.

The following script



plot(rnorm(10),rnorm(10),col="black")
points(rnorm(10),rnorm(10),col="red")
points(0,0,pch=3,lwd=3)


if(TRUE){
   legend("bottomleft",c("a","b","Truth"),pch=c(1,1,3),col=c 
("black","red","black"))
} else {
   legend("bottomleft",c("a","b","Truth"),pch=c(1,1,3),col=c 
("black","red","black"),lwd=c(0,0,3))
}


doesn't quite work as desired:  the third symbol in the legend is not  
the right line width.

Replacing TRUE with FALSE doesn't work as desired either; the first two
symbols end up with a line I don't want.
The same happens with lwd=c(NA,NA,3).

How to coerce legend()   into doing what I want?




--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] character to numeric conversion

2007-03-19 Thread Robin Hankin

On 19 Mar 2007, at 11:20, Robin Hankin wrote:

> Hello everybody
>
> thanks for the tips.
>
> I *think* this should be the same thread
>
>
> The manpage for system() says that lines of over 8095
> characters will be split.  This is causing me problems.
> How do I get round the 8095 character limit?
>


Er, just paste the output together using paste(..., collapse = "")

The split is "clean" so concatenating the lines will not lose
any characters.


HTH






--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] character to numeric conversion

2007-03-19 Thread Robin Hankin
Hello everybody

thanks for the tips.

I *think* this should be the same thread


The manpage for system() says that lines of over 8095
characters will be split.  This is causing me problems.
How do I get round the 8095 character limit?


Simple toy example follows:



jj <- system("echo 4 | awk '{for(i=1;i<100;i++){printf(\"%s,\", 
$1)}}'| sed -e \"s/,$//\"",intern=T)


This is  fine.  But .. . .


jj <- system("echo 4 | awk '{for(i=1;i<1;i++){printf(\"%s,\", 
$1)}}'| sed -e \"s/,$//\"",intern=T)



has  "jj"  split into three bits, which is upsetting my call.  In my  
application
the split occurs in the middle of a multi-digit number, which messes up
my conversion to numeric?







--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] order of values in vector

2007-03-19 Thread Robin Hankin
Tord


 > x <-  c(20,30,50,40,60,10)
 > cbind(rank(x),x)
 x
[1,] 2 20
[2,] 3 30
[3,] 5 50
[4,] 4 40
[5,] 6 60
[6,] 1 10
 >



HTH

rksh



On 19 Mar 2007, at 09:05, Tord Snäll wrote:



Dear all,
I would like to get the order of the values in a vector. I have tried
rank(), order() and searched the archive, though without success.

Here is an example of a try
x= c(20,30,50,40,60,10)
cbind(sort.list(x),x)
 x
[1,] 6 20
[2,] 1 30
[3,] 2 50
[4,] 4 40
[5,] 3 60
[6,] 5 10
but I was hoping to get this:
 x
[1,] 2 20
[2,] 3 30
[3,] 5 50
[4,] 4 40
[5,] 6 60
[6,] 1 10

I'm most grateful for a tip!

cheers,
Tord


>

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] character to numeric conversion

2007-03-19 Thread Robin Hankin
Hi.

Is there a straightforward way to convert a character string  
containing comma-delimited
numbers  to a numeric vector?

In my application, I use

system(executable.string, intern=TRUE)

which returns a string like

"[0.E-38, 2.096751179214927596171268230,  
3.678944959657480671183123052, 4.976528845643001020345216157,  
6.072390165503099343887569007, 7.007958550337542210168866070,  
7.807464185827177139302778736, 8.486139455817034846608029724,  
9.053706780665060873259065771, 9.516172308326877463284426111,  
9.876856047379733199590985269, 10.13695826383869052536062804,  
10.29580989588667234885515374, 10.35092785255025551187463209,  
10.29795676261278695909972578, 10.13052574735986793562227138,  
9.839990935943625006580521345, 9.414977153151389385186358494,  
8.840562526759586215404890348, 8.096830792651667245232639586,  
7.156244887881612948153311800, 5.978569259122249264778017262,  
4.499809670330265066808481929, 2.602689685444383764768503589, 0.E-38]"


(the output is a single line).   In a big run, the string may contain  
10^5 or possibly 10^6 numbers.

What's the recommended way to convert this to a numeric vector?






--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] enumerating non-overlapping pairs of elements from a vector

2007-03-05 Thread Robin Hankin
Allan

the general problem you refer to is "set partitions", although
I'm not clear whether the order of the sets themselves
makes a  difference (we in the enumerative combinatorics
world refer to "indistinguishable boxes").

Your application would be set partitions with a specific shape,
in this case 2,2,2,...,2,2,1  or 2,2,2,2.

I am working on a generalization of your problem Right Now,
and hope to have a complete solution ready within a couple
of months (but then again I've been saying this for a long time
now ;-)


What's your application?


best wishes

Robin


On 5 Mar 2007, at 14:56, Allan Strand wrote:

> Hi All,
>
> I'm trying to come up with a clear and concise (and fast?) solution to
> the following problem.
>
> I would like to take a vector 'v' and enumerate all of the ways in
> which it can be broken into n sets of length 2 (if the length of the
> vector is odd, and an additional set of length 1).  An element of 'v'
> can
> only appear in one set. Order within sets is not important.  Vector
> 'v' can be of lengths 2-12
>
>  'n' is determined by length(v)%/%2
>  if length(v)%%2 is non-zero, the additional set of length 1 is used
>
> For example vector 'v':
> v = (1,2,3,4)
>
> The solution would be (rows are combinations of sets chosen, where
> each element only appears once)
>
> 1 2, 3 4
> 1 3, 2 4
> 1 4, 2 3
>
> In the case where length(v) is odd
> v = (1,2,3,4,5)
> 1 2, 3 4, 5
> 1 3, 2 4, 5
> 1 4, 2 3, 5
> 5 2, 3 4, 1
> 5 3, 2 4, 1
> 5 4, 2 3, 1
> 5 1, 3 4, 2
> 5 3, 1 4, 2
> 5 4, 1 3, 2
> and so on...
>
> Certainly pulling all combinations of two or one elements is not a big
> deal, for example
>
> combinations(5,2,c(1,2,3,4,5),repeats.allowed=T)
>
> from the 'gtools' package would do something like this.
>
> I'm stuck on a clean solution for enumerating all the non-overlapping
> sets without some elaborate looping and checking scheme.  No doubt
> this is a lapse in my understanding of combinatorics.  Any help would
> be greatly appreciated
>
> cheers,
> a.
>
> __________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] merge two colums

2007-02-27 Thread Robin Hankin
Hi.

Use paste(... , sep="_") to create a new variable, then
data.frame()  to join them.

Note that you have to name the columns explicitly; the
default names are long for my tastes.


HTH

rksh



 > a <- data.frame(V1=1:3,V2=letters[1:3],V3=3:1,V4=100:102)
 > a
   V1 V2 V3  V4
1  1  a  3 100
2  2  b  2 101
3  3  c  1 102
 > data.frame(n1=a$V1,n2=paste(a$V2,a$V3,sep="_"),n4=a$V4)
   n1  n2  n4
1  1 a_3 100
2  2 b_2 101
3  3 c_1 102
 >



On 27 Feb 2007, at 11:31, Aimin Yan wrote:

> I have a data set like this
>
>> head(data.1A24_aa_model)
>  V1V2 V3  V4 V5 V6
> 1 1A24 MODEL  1 ALA  1  84.47
> 2 1A24 MODEL  1 GLN  2  63.06
> 3 1A24 MODEL  1 TYR  3 107.72
> 4 1A24 MODEL  1 GLU  4  54.36
> 5 1A24 MODEL  1 ASP  5  67.01
> 6 1A24 MODEL  1 GLY  6 999.00
>
> I want to change this to the following format:
>
> V1 V2 V3  V4 V5
> 1 1A24 MODEL  1 ALA _1  84.47
> 2 1A24 MODEL  1 GLN _2  63.06
> 3 1A24 MODEL  1 TYR _3 107.72
> 4 1A24 MODEL  1 GLU _4  54.36
> 5 1A24 MODEL  1 ASP _5  67.01
> 6 1A24 MODEL  1 GLY _6 999.00
>
> anyone know how to do this?
>
> Aimin
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] 3F2 hypergeometric function

2007-02-22 Thread Robin Hankin
Hello Joe


On 21 Feb 2007, at 16:22, Lucke, Joseph F wrote:

> Does anyone have code for the 3F2 hypergeometric function? I am  
> looking
> for code similar to the 2F1 hypergeometric function implemented as
> hyperg_2F1 in the GSL package. TIA.  ---Joe
>


The GSL library does not have a hyperg_3F2, so neither does the gsl  
package.

BUT the Davies package does have a hyperg() function that is written in
such a way that it would be a cinch to convert it from 2F1 to 3F2.

Let me know how you get on


Robin





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

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Generating MVN Data

2007-02-13 Thread Robin Hankin
Hi

give rmvnorm() any symmetric positive definite matrix and it should  
work:



 > rmvnorm(n=10,mean=1:2,sigma=matrix(c(1,0.5,0.5,1),2,2))
  [,1]   [,2]
[1,] -0.1118  2.514
[2,]  1.8667  1.628
[3,]  3.2477  2.263
[4,]  1.0166  2.381
[5,] -0.0888 -0.132
[6,] -0.9249  0.610
[7,]  1.5046  3.578
[8,]  0.8530  0.802
[9,]  2.2940  2.240
[10,]  1.1660  2.528
 >



HTH

rksh


On 13 Feb 2007, at 14:14, Rauf Ahmad wrote:

> Dear All
>
> I want to generate multivariate normal data in R for a given  
> covariance
> matrix, i.e. my generated data must have the given covariance  
> matrix. I
> know the rmvnorm command is to be used but may be I am failing to
> properly assign the covariance matrix.
>
> Any help will be greatly appreciated
>
> thanks.
>
> M. R. Ahmad
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] blockwise matrix multiplication

2007-02-09 Thread Robin Hankin
Wow.


It generalizes nicely to arbitrary dimensional arrays too.

thanks a lot!


rksh


On 9 Feb 2007, at 14:19, Gabor Grothendieck wrote:

> Try this:
>
>   A * M[as.matrix(expand.grid(x,x))[,2:1]]
>
>
> On 2/9/07, Robin Hankin <[EMAIL PROTECTED]> wrote:
>> Hi
>>
>> Given an n-by-n  matrix A, say n=10 and
>>
>> A <- matrix(1:100,10,10)
>>
>> and a vector x of length n where 1 <=x[i] <= n for i=1..n
>> say
>>
>> x <- c(1,1,1,2,4,3,3,3,4,4)
>>
>> and a matrix M of size max(x)-by-max(x), say
>>
>> M <- matrix(c(1, 0.1, 0, 0.2, 0.1, 1, 0, 0, 0, 0, 1, 0.2, 0.2,
>> 0, 0.2, 1),4,4)
>>
>> how do I partition A according to the equivalence classes
>> of the elements  of x and  "block multiply"  by M?
>>
>> I want
>>
>> for(i in 1:4){for(j in 1:4){
>>   A[which(x==i),which(x==j)] <-  A[which(x==i),which(x==j)]*M[i,j]
>> }}
>>
>>
>> Is there a better way than this ghastly for() loop?
>>
>>
>> --
>> Robin Hankin
>> Uncertainty Analyst
>> National Oceanography Centre, Southampton
>> European Way, Southampton SO14 3ZH, UK
>>  tel  023-8059-7743
>>
>> ______
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting- 
>> guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] blockwise matrix multiplication

2007-02-09 Thread Robin Hankin
Hi

Given an n-by-n  matrix A, say n=10 and

A <- matrix(1:100,10,10)

and a vector x of length n where 1 <=x[i] <= n for i=1..n
say

x <- c(1,1,1,2,4,3,3,3,4,4)

and a matrix M of size max(x)-by-max(x), say

M <- matrix(c(1, 0.1, 0, 0.2, 0.1, 1, 0, 0, 0, 0, 1, 0.2, 0.2,
0, 0.2, 1),4,4)

how do I partition A according to the equivalence classes
of the elements  of x and  "block multiply"  by M?

I want

for(i in 1:4){for(j in 1:4){
   A[which(x==i),which(x==j)] <-  A[which(x==i),which(x==j)]*M[i,j]
}}


Is there a better way than this ghastly for() loop?


--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] circle fill problem

2007-02-08 Thread Robin Hankin
Hello Ingmar

In Kepler's sphere packing problem the
spheres are not allowed to overlap, which
would suggest to me that different tactics should
perhaps be used.

Mini's problem is formally a "cover problem", and
the sphere packing problem is a "packing problem".
The two are related, but tend not to have direct
relevance to one another.

Also be aware that Kepler's conjecture refers to the
packing fraction limit as  the space available tends to
infinity.

My understanding is that Kepler's conjecture has now been
proved beyond all reasonable doubt, but how to use this in
Mini's problem is not clear to me.


rksh


On 8 Feb 2007, at 09:21, Ingmar Visser wrote:

> Robin & Mini,
> For those interested, googling for the 'orange packing problem' as it
> is known, or more officially the sphere packing problems gives you
> quite a few hits on these and similar problems.
> So at least the 3-d case the problem has been solved (I imagine the
> problem is easier in 2-d ...)
> hth, Ingmar
>
> On 8 Feb 2007, at 09:52, Robin Hankin wrote:
>
>> Mini
>>
>> This is a hard problem in general.
>>
>> Recreational mathematics has wrestled with
>> this and similar problems over the years; the
>> general field is the "set cover problem" but
>> in your case the sets are uncountably infinite
>> (and there are uncountably many of them).
>>
>> I would be surprised if your problem were not NP complete.
>>
>>
>> HTH
>>
>>
>> Robin
>>
>>
>> On 8 Feb 2007, at 05:15, MINI GHOSH wrote:
>>
>>> Dear R user,
>>>
>>> I want to know is there a way to find the minimum
>>> number of circles (of given radius) required to fill a
>>> given area (say rectangular) where overlapping of
>>> circles is allowed.
>>>
>>> Thanks,
>>> Regards,
>>> Mini Ghosh
>>>
>>> __
>>> R-help@stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-
>>> guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> --
>> Robin Hankin
>> Uncertainty Analyst
>> National Oceanography Centre, Southampton
>> European Way, Southampton SO14 3ZH, UK
>>   tel  023-8059-7743
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] circle fill problem

2007-02-08 Thread Robin Hankin
Mini

This is a hard problem in general.

Recreational mathematics has wrestled with
this and similar problems over the years; the
general field is the "set cover problem" but
in your case the sets are uncountably infinite
(and there are uncountably many of them).

I would be surprised if your problem were not NP complete.


HTH


Robin


On 8 Feb 2007, at 05:15, MINI GHOSH wrote:

> Dear R user,
>
> I want to know is there a way to find the minimum
> number of circles (of given radius) required to fill a
> given area (say rectangular) where overlapping of
> circles is allowed.
>
> Thanks,
> Regards,
> Mini Ghosh
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Need help writing a faster code

2007-02-01 Thread Robin Hankin
Hi



 > A <- matrix(runif(10),ncol=2)
 > B <- matrix(runif(10),ncol=2)
 > g <- function(i4){theta <- atan2( (i4[4]-i4[2]),(i4[3]-i4[1]))
+ return(theta + 2*pi*(theta<0))}
 > apply(A,1,function(x){apply(B,1,function(y){g(c(x,y))})})
   [,1]  [,2] [,3][,4]  [,5]
[1,] 1.1709326 2.6521457 3.857477 0.219274562 1.2948374
[2,] 1.1770919 4.2109056 4.057313 4.918552967 1.9733967
[3,] 0.9171661 0.6721475 4.193675 0.434253839 0.9781060
[4,] 0.9181475 0.6911804 4.213295 0.455127422 0.9771797
[5,] 1.0467449 4.9263243 3.983248 0.004371504 1.1693707
 >



HTH

rksh


On 1 Feb 2007, at 15:10, Ravi Varadhan wrote:

> Hi,
>
>
>
> I apologize for this repeat posting, which I first posted  
> yesterday. I would
> appreciate any hints on solving this problem:
>
>
>
> I have two matrices A (m x 2) and B (n x 2), where m and n are large
> integers (on the order of 10^4).  I am looking for an efficient way to
> create another matrix, W (m x n), which can be defined as follows:
>
>
>
> for (i in 1:m){
>
> for (j in 1:n) {
>
> W[i,j] <- g(A[i,], B[j,])
>
> } }
>
> where g(x,y) is a function that takes two vectors and returns a  
> scalar.
>
>
>
> The following works okay, but is not fast enough for my purpose.  I  
> am sure
> that I can do better:
>
>
>
> for (i in 1:m) {
>
> W[i,] <- apply(B, 1, y=A[i,], function(x,y) g(y,x))
>
> }
>
>
>
> How can I do this in a faster manner? I attempted "outer",  
> "kronecker",
> "expand.grid", etc, but with no success.
>
>
>
> Here is an example:
>
>
>
> m <- 2000
>
> n <- 5000
>
> A <- matrix(rnorm(2*m),ncol=2)
>
> B <- matrix(rnorm(2*n),ncol=2)
>
> W <- matrix(NA, m, n)
>
>
>
> for (i in 1:m) {
>
> W[i,] <- apply(B, 1, y=A[i,], function(x,y) g(y,x))
>
> }
>
>
>
> g <- function(x,y){
>
> theta <- atan((y[2]-x[2]) / (y[1] - x[1]))
>
> theta + 2*pi*(theta < 0)
>
> }
>
>
>
> Thanks for any suggestions.
>
>
>
> Best,
>
> Ravi.
>
>
>
>
>
>
>
> -- 
> --
> ---
>
> Ravi Varadhan, Ph.D.
>
> Assistant Professor, The Center on Aging and Health
>
> Division of Geriatric Medicine and Gerontology
>
> Johns Hopkins University
>
> Ph: (410) 502-2619
>
> Fax: (410) 614-9625
>
> Email: [EMAIL PROTECTED]
>
> Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/ 
> Varadhan.html
>
>
>
> -- 
> --
> 
>
>
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743


-- 
This e-mail (and any attachments) is confidential and intend...{{dropped}}

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


Re: [R] Index mapping on arrays

2007-02-01 Thread Robin Hankin
Hello Demi


The trick for array indexing
on an array A, where length(dim(A))==n,
is to use an n-column matrix M to extract the elements
by rows of M.

If I understand correctly, the following should help:


 > A <- array(1:18,c(3,3,2))
 > x <- 2:3
 > y <- 1:2
 > A[cbind(x,y,1)]
[1] 2 6




You may find the following useful too:

 > A[as.matrix(cbind(1,expand.grid(x,y)))]
[1]  4  7 13 16
 >


best

rksh



On 1 Feb 2007, at 13:34, Demi Anderson wrote:

> Dear R-community,
>
> I have some trouble with index mappings for arrays. If, for example,
> I have the array
>
> R> A <- array(1:9, c(3,3,2))
>
> and two index mappings both of same size
>
> R> x <- c(2, 3)
> R> y <- c(1, 2)
>
> Now I want to access the elements (A[1, x[i], y[i]])_i of A, i.e.
> A[1, x[1], y[1]] = A[1, 2, 1] and A[1, x[2], y[2]] = A[1, 3, 2].
>
> If I use
>
> R> A[1, x, y]
>
> I would get every combinations of indices of all elements of x and y
> i.e. A[1, x[1], y[1]], A[1, x[1], y[2]], A[1, x[2], y[1]] and A[1,
> x[2], y[2]]. But how can I access the elements (A[1, x[i], y[i]])_i.
> My arrays dimensions are actually large in the second
> component (for example the dimension might be 10*1*10) so I'm
> looking for a method avoiding loops.
>
> The question is probably trivial for you, but I just could not
> figure it out. So sorry for bugging you and many thanks in advance
> for any help.
>
> Best wishes, Demi Anderson.
> --  
> "Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743


-- 
This e-mail (and any attachments) is confidential and intend...{{dropped}}

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


Re: [R] jump in sequence

2007-01-30 Thread Robin Hankin

 > f <- function(n){as.vector(sweep(matrix(4:6,nrow=3,ncol=n),2,seq 
(from=0,by=9,len=n),"+"))}
 > f(10)
[1]  4  5  6 13 14 15 22 23 24 31 32 33 40 41 42 49 50 51 58 59 60 67  
68 69 76 77 78 85 86 87
 >

HTH

rksh


On 30 Jan 2007, at 14:29, Adrian DUSA wrote:

> Dear list,
>
> This should be a simple one, I just cannot see it.
> I need to generate a sequence of the form:
> 4  5  6 13 14 15 22 23 24
>
> That is: starting with 4, make a 3 numbers sequence, jump 6, then  
> another 3
> and so on.
> I can create a whole vector with:
> myvec <- rep(rep(c(F, T, F), rep(3, 3)), 3)
>
> Then see which are TRUE:
> which(myvec)
> [1]  4  5  6 13 14 15 22 23 24
>
>
> I'd like to avoid creating the whole vector if possible; for very  
> large ones
> it can be time consuming. There should be a way to only create the  
> proper
> indexes...
>
> Thanks for any hint,
> Adrian
>
> -- 
> Adrian Dusa
> Romanian Social Data Archive
> 1, Schitu Magureanu Bd
> 050025 Bucharest sector 5
> Romania
> Tel./Fax: +40 21 3126618 \
>   +40 21 3120210 / int.101
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Permutation problem

2007-01-30 Thread Robin Hankin
Hi


 > library(gtools)
 > combinations(5,3)
   [,1] [,2] [,3]
[1,]123
[2,]124
[3,]125
[4,]134
[5,]135
[6,]145
[7,]234
[8,]235
[9,]245
[10,]345
 >






On 30 Jan 2007, at 12:22, michel lang wrote:

> Dear R-Users,
>
> I need a matrix containing line by line all possible permutations with
> length 'i'  of the integers 1:N, given the restriction that the
> integers in each row have to be in ascending order.
>
> For example: N = 5, length i = 3, should result in a matrix like this:
> 1  2  3
> 1  2  4
> 1  2  5
> 1  3  4
> 1  3  5
> 1  4  5
> 2  3  4
> 2  3  5
> 2  4  5
> 3  4  5
>
> I'm grateful for any advice on how to proceed,
>   Michel Lang
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] curious about dimension of 'apply' output when MARGIN=1

2007-01-18 Thread Robin Hankin

On 18 Jan 2007, at 08:42, Prof Brian Ripley wrote:

> On Wed, 17 Jan 2007, Patrick Burns wrote:
>
>> A logical reason for the phenomenon is that
>> matrices are stored down their columns. For
>> example:
>
[snip]

> Or that the vision of the original designer was not limited to  
> matrices.
> It just so happens that in this example the replacement is a single
> dimension the same size as the single margin used.  That's  
> atypical, and
> normally the result dimension has no connection to the margin.  The  
> design
> is to put the result dimension first, and the first item in the  
> 'seealso'
> list is aperm().
>
> To my mind the only general solutions are to put the result dimension
> first or last.  I would have used last, but using first is slightly  
> more
> efficient for the reason Pat gives.
>


The case Brian Ripley mentions above is indeed atypical,
but it's encountered reasonably often, at least in the world of
high-dimensional magic hypercubes.

The most prominent examples would be sort()  and the identity function.

Although the emphasis is different,
matlab's  "sort" function when called with  two
arguments,  as in "sort(a,i)", sorts along  dimension "i",
leaving the dimensions of the returned array unchanged.

R-and-octave.txt includes the following:



a <- array(1:24,2:4)




%Sort is a bit of a problem, due to the behaviour of apply():

sort(a,1)   aperm(apply(a,c(2,3),sort),c(1,2,3))
sort(a,2)   aperm(apply(a,c(1,3),sort),c(2,1,3))
sort(a,3)   aperm(apply(a,c(1,2),sort),c(2,3,1))


It's possible to get round this by defining a little function:
asort <- function(a,i){
   j <- 1:length(dim(a))
   aperm(apply(a,j[-i],sort),append(j[-1],1,i-1))
}

Then R's asort(a,1) will return the same as Octave's sort(a,1).

Function asort() could easily be adapted to take a function name as a  
third argument.




> apply() is for arrays, operating over one or more margins with a  
> function
> returning a 'scalar', vector or array result.  Perhaps any 'lazy'- 
> ness /
> limit of vision is not in handling array results as well as might be
> possible.
>
>> Patrick Burns
>> [EMAIL PROTECTED]
>> +44 (0)20 8525 0696
>> http://www.burns-stat.com
>> (home of S Poetry and "A Guide for the Unwilling S User")
>
>
> -- 
> Brian D. Ripley,  [EMAIL PROTECTED]
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford, Tel:  +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272866 (PA)
> Oxford OX1 3TG, UKFax:  +44 1865 272595
>
> ______
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] "[[" gotcha

2007-01-16 Thread Robin Hankin
The following gotcha caught me off-guard just now.

I have two matrices, a and b:


a <- matrix(1,3,3)
b <- matrix(1,1,1)

(note that both "a" and "b" are matrices).

I want them in a list:

 > B <- NULL
 > B[[1]] <- a
 > B[[2]] <- b
 > B
[[1]]
  [,1] [,2] [,3]
[1,]111
[2,]111
[3,]111

[[2]]
  [,1]
[1,]1

 >

This is fine.

But swapping "a" and "b" over does not behave as desired:


 > B <- NULL
 > B[[1]] <- b
 > B[[2]] <- a
Error in B[[2]] <- a : more elements supplied than there are to replace
 >



The error is given because after B[[1]] <- a,   the variable B is  
just a scalar and
not a matrix (why is this?)

What's the bulletproof method for assigning matrices to a list (whose  
length is
not known at runtime)?








--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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-pkgs] Dummy's guide to S4 methods: package Brobdingnag

2007-01-12 Thread Robin Hankin
Hello List.

please find uploaded to CRAN a new package, Brobdingnag.

This package does two things:

(1) allows computation of very large numbers using a logarithmic  
representation.

(2) provides a "Hello, World" example of S4 methods in use: there are  
two classes of object
   (brob and glub) and one virtual class (swift).  The package  
includes a vignette that is a
step-by-step guide to using S4 methods in the context of an R  
package.


Enjoy

Robin

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

___
R-packages mailing list
R-packages@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] image() and nonsquare matrices

2007-01-12 Thread Robin Hankin
How do I draw non-square matrices with image() and get the axes right?


Try 1:

  a <- matrix(rnorm(100),20,5)
image(1:20,1:5,a,asp=1,xlab="label here")
# No good because the axes don't touch the image



Try 2:

image(1:20,1:5,a,asp=1,axes=F,xlab="label here")
axis(side=1,pos=0)
# No good because the x axis label is floating far from the x axis.



Try 3:
  image(1:20,1:5,a,asp=1,axes=F,xlab="",ylab="")
  axis(side=1,pos=0)
# No good because the x axis label is absent.


How to use image() with a non-square matrix and make axes and labels  
appear correctly?





--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Software for kriging

2007-01-04 Thread Robin Hankin
Hi

the "emulator" package of the the BACCO bundle
includes kriging as a special case.

HTH

Robin


On 4 Jan 2007, at 04:56, <[EMAIL PROTECTED]> wrote:

>
> Dear R-list members,
>
> I wish everyone a happy and successful 2007!
>
> Does anyone know of R-based software for
> optimal spatial prediction (kriging)?
>
> We are working on a seismic event characterisation
> technique and need to do some kriging.
>
> Any help would be greatly appreciated.
>
> Augusto
>
>
>
> 
> Augusto Sanabria. MSc, PhD.
> Mathematical Modeller
> Risk Research Group
> Geospatial & Earth Monitoring Division
> Geoscience Australia (www.ga.gov.au)
> Cnr. Jerrabomberra Av. & Hindmarsh Dr.
> Symonston ACT 2601
> Ph. (02) 6249-9155
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] write() gotcha

2006-12-18 Thread Robin Hankin

On 18 Dec 2006, at 08:50, Prof Brian Ripley wrote:

> On Mon, 18 Dec 2006, Robin Hankin wrote:
>
>> Hi
>>
>> I used write() the other day to save some results.
>
> Why not save()?  It is the only way to preserve the results exactly.
>
>> It seems that write() does not record the full precision of
>> the objects being written:
>>
>> [snip]
>>
>> What's going on here?
>
> See ?cat, for which write is a wrapper.
>
>



Professor Ripley

Thanks for this.  I'll use save() instead.

Also, could we clarify this issue in the write() manpage?  Although its
behaviour is  clear from the code, I'm sure other R users would
appreciate a hint or a warning that precision might be lost.  It cost
me a few hours of worry last night!



--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] write() gotcha

2006-12-18 Thread Robin Hankin
Hi

I used write() the other day to save some results.

It seems that write() does not record the full precision of
the objects being written:


 > write(pi,file="~/f",ncolumns=1)
 > pi.saved <- scan("~/f")
Read 1 item
 > dput(pi)
3.14159265358979
 > dput(pi.saved)
3.141593
 > pi-pi.saved
[1] -3.464102e-07
 >


This difficulty was particularly difficult to find because pi.saved   
*looks*
the same as pi.



What's going on here?






 > R.Version()
$platform
[1] "powerpc-apple-darwin8.7.0"

$arch
[1] "powerpc"

$os
[1] "darwin8.7.0"

$system
[1] "powerpc, darwin8.7.0"

$status
[1] ""

$major
[1] "2"

$minor
[1] "4.0"

$year
[1] "2006"

$month
[1] "10"

$day
[1] "03"

$`svn rev`
[1] "39566"

$language
[1] "R"

$version.string
[1] "R version 2.4.0 (2006-10-03)"


--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


[R] two connected graphs

2006-12-14 Thread Robin Hankin
Hi

I have two datasets, A and B, consisting of two columns of numbers
representing x and y coordinates.

They have 10 and 6 rows respectively.

I want to plot two scattergraphs, one above the other.

The lower graph to contain A (10 points) and the upper
graph to contain B (six points).

The x-axes of the two graphs must line up.

I then want to draw straight lines that connect points
of  B to a particular point (or points)  of A.

How do I do this?


--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Welcome to the "R-help" mailing list

2006-12-14 Thread Robin Hankin
Hi

you could use interpolant() of the emulator package,
for a Gaussian process approach,
or approx() [or appproxfun()] if linear interpolation
is acceptable.

HTH


Robin



On 14 Dec 2006, at 10:20, Bird Fish wrote:

> Dear Colleagues
> I am a very new member here. If my question sounds silly to you, I  
> apologize
> in advance.
>
> If I have a complicated function without an explicit expression. ( For
> example, the price of  American put option p is a function of the  
> current
> stock price S and expected future volatility sigma, but there is no  
> clean
> elementary function that would map (S, sigma) to p, in fact, p has  
> to be
> calculated with a sophisticated procedure.
>
> In such case, is there a function in R to find sigma, with S and p  
> known?
> Also, is there a way to find the derivative of p with regard to sigma?
>
> Could anyone please shed some light on it? Your help will be highly
> appreciated!!!
>
> Best
> Bird and Fish
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] backticks

2006-12-04 Thread Robin Hankin
Peter

Aha!  so R backticks work just like bash backticks  (duh!)
unless they are on the LHS of an assignment.

[We bash people now use $(...) instead]

Could we add something to this effect to Quotes.Rd?


rksh


On 4 Dec 2006, at 14:33, Peter Dalgaard wrote:

> Robin Hankin wrote:
>>
[snip]
>> What exactly do backticks do that single or double quotes don't?
>>
> I don't know whether we really want to be that dogmatic about it,  
> but in
> a nutshell
>
> `like this` <- 2
> "like that" <- 3
> print(`like this`)
> print("like that")
>
> I.e. backtick'ed names work whereever ordinary names do, but quoted
> names work only on the LHS of assignments.
>
> The note in ?formula should probably be understood defensively: We
> intend backtick'ed names to work in all contexts, but  there may be
> programming practices where the backticks are not preserved  
> (notably if
> there is a deparse-reparse step involved).
>
>> Where do I look for documentation on this?
>>
>>
>>
>>
>> --
>> Robin Hankin
>> Uncertainty Analyst
>> National Oceanography Centre, Southampton
>> European Way, Southampton SO14 3ZH, UK
>>   tel  023-8059-7743
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting- 
>> guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
> -- 
>O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
>   c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
>  (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45)  
> 35327918
> ~~ - ([EMAIL PROTECTED])  FAX: (+45)  
> 35327907

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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

2006-12-04 Thread Robin Hankin
I noticed just now that
package.skeleton() produces R files in which
the function names are escaped with backticks.

?Quotes says that "The preferred quote is the backtick (`)",
but I don't understand _why_  this is preferred.

?formula gives some clues but points out that there
are no guarantees that formulae using non-syntactic names such as
`like this` will be accepted.

What exactly do backticks do that single or double quotes don't?
Where do I look for documentation on this?




--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] analog to the matlab buffer function?

2006-12-01 Thread Robin Hankin
 > do.call("rbind",lapply(0:4,function(i){i+(1:5)}))
  [,1] [,2] [,3] [,4] [,5]
[1,]12345
[2,]23456
[3,]34567
[4,]45678
[5,]56789
 >



On 1 Dec 2006, at 00:32, Charles C. Berry wrote:

>
> See
>
>   ?embed
>
> It is not quite the same, but this seems to be what you want - at  
> least
> for the example you give:
>
>> t( embed(1:5,3) )[3:1,]
>   [,1] [,2] [,3]
> [1,]123
> [2,]234
> [3,]345
>>
>
> On Fri, 1 Dec 2006, Martin Ivanov wrote:
>
>> Hello! I am new to R. I could not find a function analogous to  
>> matlab's
>> function buffer, which is used in signal processing. Is there such a
>> function in R? What I need to do is as follows. If I apply the  
>> function
>> to the vector c(1:5) for example with a window length 3 and  
>> overlapping
>> 2, I need to get a matrix like this:
>> 1 2 3
>> 2 3 4
>> 3 4 5
>> In matlab this is achieved with the function buffer. Is there  
>> ananalogous R function?
>>
>> Thank you very much in advance.
>> Regards,
>> Martin
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting- 
>> guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> Charles C. Berry(858) 534-2098
>   Dept of Family/Preventive  
> Medicine
> E mailto:[EMAIL PROTECTED] UC San Diego
> http://biostat.ucsd.edu/~cberry/ La Jolla, San Diego  
> 92093-0717
>
> ______
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] t.test()

2006-11-24 Thread Robin Hankin

On 23 Nov 2006, at 13:46, Peter Dalgaard wrote:

> Robin Hankin <[EMAIL PROTECTED]> writes:
>
>> Hi
>>
>> I have a vector x of length n.   I am interested in x[1]
>> being different from the other observations (ie x[-1]).
>>
[snip]

>>
>> What arguments do I need to send to t.test() to test my null?
>
>

[snip]

> Alternatively, just write up the formula for the t statistic:
>
>> x <- c(23,25,29,27,30,30)
>> (x[1]-mean(x[-1]))/sqrt(var(x[-1])*(1+1/(length(x)-1)))
>


The "gotcha" in Peter Dalgaard's formula is that the maximum  
likelihood estimate for the
variance, with a sample size of one, is zero.  This is why var[x[1]]  
doesn't appear.

[R reports var(1) as NA because it uses the unbiased formula with  
(n-1) on the denominator,
as documented]

Last night I derived the likelihood test for testing my null.  Consider

H1: x~N(mu_x,s^2);  y~N(mu_y,s^2)
H2: x,y~N(mu,s^2)


The support gained by allowing the two means to differ [ie compare H2  
to H1] is:

\[
E=
\frac{n}{2}\ln\left(
\frac{\sum(z_i-\overline{z})^2}{
\sum(x_i-\overline{x})^2+
\sum(y_i-\overline{y})^2
}\right)
\]

where z=c(x,y) is both sets of observations taken together.  This  
formula supposes one
uses the appropriate maximum likelihood estimate for the (common)  
variance.  Note that
the MLE  for the variance is different on H1 and H2.

Thus if E > 2 we can reject H2 and if  !(E <2) we can accept (sic) H2.





Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] t.test()

2006-11-23 Thread Robin Hankin
Hello everybody


thanks for your advice here.

I think I'm getting tangled up.

If I use Thierry's test on iid Gaussian data,
the returned p-value should be uniform(0,1),
right?

OK,


R> f <- function(x){t.test(x=x[-1],mu=x[1])$p.value}
R> hist(replicate(1000,f(rnorm(5


This is very skewed towards zero.  Why isn't the
histogram showing a uniform distribution?







On 23 Nov 2006, at 13:32, ONKELINX, Thierry wrote:

> There is no such thing as an unpaired t-test. A t-test can be a  
> paired,
> one sample or two sample t-test. Since you want to compare the sample
> against a given mean, you need a one sample t-test. You tried to do a
> two sample test. That didn't work because you need at least two
> observations in each group.
>
> x <- c(23,25,29,27,30,30)
> t.test(x[-1], mu = x[1])
>
> One Sample t-test
>
> data:  x[-1]
> t = 5.3634, df = 4, p-value = 0.005833
> alternative hypothesis: true mean is not equal to 23
> 95 percent confidence interval:
>  25.50814 30.89186
> sample estimates:
> mean of x
>  28.2
>
>
> Cheers,
>
> Thierry
>
> -- 
> --
> 
>
> ir. Thierry Onkelinx
>
> Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
> and Forest
>
> Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
> methodology and quality assurance
>
> Gaverstraat 4
>
> 9500 Geraardsbergen
>
> Belgium
>
> tel. + 32 54/436 185
>
> [EMAIL PROTECTED]
>
> www.inbo.be
>
>
>
> Do not put your faith in what statistics say until you have carefully
> considered what they do not say.  ~William W. Watt
>
> A statistical analysis, properly conducted, is a delicate  
> dissection of
> uncertainties, a surgery of suppositions. ~M.J.Moroney
>
> -Oorspronkelijk bericht-
> Van: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Namens Robin Hankin
> Verzonden: donderdag 23 november 2006 14:12
> Aan: [EMAIL PROTECTED]
> Onderwerp: [R] t.test()
>
> Hi
>
> I have a vector x of length n.   I am interested in x[1]
> being different from the other observations (ie x[-1]).
>
> My null hypothesis  is that x[1]
> is drawn from a Gaussian distribution of the same
> mean as observations x[-1], which are assumed
> to be iid Gaussian.   The (unknown) variance
> of x[1] is assumed to be the same as the
> variance of x[-1].
>
>
> This should be an unpaired t-test.
>
> But
>
>
>> x <- c(23,25,29,27,30,30)
>> t.test(x=x[1] , y=x[-1])
> Error in t.test.default(x = x[1], y = x[-1]) :
>  not enough 'x' observations
>>
>
>
>
> What arguments do I need to send to t.test() to test my null?
>
>
>
>
>
>
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton
> European Way, Southampton SO14 3ZH, UK
>   tel  023-8059-7743
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] t.test()

2006-11-23 Thread Robin Hankin
Hi

I have a vector x of length n.   I am interested in x[1]
being different from the other observations (ie x[-1]).

My null hypothesis  is that x[1]
is drawn from a Gaussian distribution of the same
mean as observations x[-1], which are assumed
to be iid Gaussian.   The (unknown) variance
of x[1] is assumed to be the same as the
variance of x[-1].


This should be an unpaired t-test.

But


 > x <- c(23,25,29,27,30,30)
 > t.test(x=x[1] , y=x[-1])
Error in t.test.default(x = x[1], y = x[-1]) :
 not enough 'x' observations
 >



What arguments do I need to send to t.test() to test my null?







--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] do.call("+", ...)

2006-11-17 Thread Robin Hankin

On 17 Nov 2006, at 14:14, Peter Dalgaard wrote:

[snip]

>
> so a+b+c is really (a+b)+c and I was calculating a+(b+c). That's
> actually a little bit harder because you don't get help from argument
> matching:
>
> "++" <- function(...) if ((n <- nargs()) == 1) ..1 else {
> l <- list(...)
> do.call("++",l[-n]) + l[[n]]
> }
>


Aha, the dreaded "..1" argument.   Where do I look for documentation  
on this?

[It is mentioned twice in The R Language Definition, but I'm no wiser]




--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] do.call("+", ...)

2006-11-17 Thread Robin Hankin
Thanks for this Duncan

>>


>> Why is Peter Dalgaard's suggestion necessary?  Why can't  "+"
>> take more than two arguments?
>
> One reason is that it's a binary operator, so that's all it needs to
> take.  We have the sum function for multiple operands.
>
> I would guess the historical reason is so that it can share code with
> other binary operators.  For example, + currently shares code with the
> other binary operators -, *, /, ^, %%, %/%, but the grouping needed
> varies between them:  a-b-c == (a-b)-c, but a^b^c == a^(b^c).  R lets
> the parser handle operator binding.
>


OK, I see.  But in algebra the  "+" symbol is special: it is reserved
exclusively for associative and commutative operations [thus a+b+c is
always well-defined]; perhaps the parser could fall in with this  
convention?


> By the way, another complaint is that sum() is supposed to be generic,
> but you can't define a sum.matrix() method so that sum(a,b,c) does the
> same as a+b+c when a is a matrix.  (This would probably be a bad idea
> because people may be relying on the current behaviour, but R tries  
> not
> to prevent people from testing out bad ideas.)  ...


Can  just clarify this?   I can see that it's a bad idea, but I don't  
quite
see why one *can't* do it.  sum() is generic, and the manpage says
that methods can be defined for it directly.

OK, so I define a function sum.matrix()
[for the moment just taking two arguments]:


  R> sum.matrix <- function(a,b){matrix(apply(matrix(c(a,b),ncol=2), 
1,sum),dim(a))}

R> a <- matrix(1:6,2,3)

R> sum(a,a)
[1] 42
  R> sum.matrix(a,a)
  [,1] [,2] [,3]
[1,]26   10
[2,]48   12
R>


So why doesn't  sum(a,a) dispatch to  sum.matrix()?



best wishes


rksh


> You need to apply your
> own class to the matrices (e.g. mymatrix), then it all works:



>> f  <- function(i){m <- matrix((1:6)^i,2,3); class(m) <-  
>> "mymatrix"; m}
>>
>> sum.mymatrix <- function(...) {
> + x <- list(...)
> + return(x[[1]] + do.call(sum, x[-1]))
> + }
>>
>> do.call("sum",sapply(1:4,f,simplify=FALSE))
>   [,1] [,2] [,3]
> [1,]4  120  780
> [2,]   30  340 1554
> attr(,"class")
> [1] "mymatrix"
>
> Duncan Murdoch
>
> ______
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] filling an array, vectorized

2006-11-17 Thread Robin Hankin
Hello again everyone.


I've further added to Martin and Gabor's suggestion an ellipsis to
pass additional arguments to f().   Cut-n-paste below.

BUT.do.index() comes with a Warning: function arow() of the magic
package is much much much  faster; use it if at  all possible:




  a <- array(0, c(2, 3, 4, 2, 3, 3, 2, 3, 2, 3))

  f1 <- function(i) {   arow(a, i)}
f2 <- function(x) {  sum(x) }

  "++" <- function(x, ...) if (nargs() == 1) x else x +
 Recall(...)


 > system.time(ignore1 <- do.call("++", sapply(1:4, f1,
 simplify = FALSE)))
[1] 0.041 0.013 0.054 0.000 0.000

 > system.time(ignore1 <- do.call("++", sapply(1:4, f1,
 simplify = FALSE)))
[1] 0.029 0.009 0.040 0.000 0.000

 > system.time(ignore1 <- do.call("++", sapply(1:4, f1,
 simplify = FALSE)))
[1] 0.028 0.009 0.038 0.000 0.000

 > system.time(ignore2 <- do.index(a, f2))
[1] 0.387 0.028 0.440 0.000 0.000

 > system.time(ignore2 <- do.index(a, f2))
[1] 0.380 0.025 0.406 0.000 0.000

 > system.time(ignore2 <- do.index(a, f2))
[1] 0.376 0.029 0.422 0.000 0.000
 >










  do.index <-
function (a, f, ...)
{
 jj <- function(i) {
 seq_len(dim(a)[i])
 }
 index <- as.matrix(expand.grid(lapply(seq_len(length(dim(a))),
 jj), KEEP.OUT.ATTRS = FALSE))
 a[index] <- apply(index, 1, f, ...)
 return(a)
}

arow <-
function (a, i)
{
 p <- 1:prod(dim(a))
 n <- length(dim(a))
 d <- dim(a)[i]
 permute <- c(i, (1:n)[-i])
 a <- aperm(a, permute)
 a[] <- p
 permute[permute] <- 1:n
 return(force.integer(aperm(process(a, d), permute)))
}






--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] do.call("+", ...)

2006-11-17 Thread Robin Hankin
Hello everyone

thanks for the replies.  My application (predictably) involves
arbitrary dimensioned arrays, so I will need to generalize
the suggestions slightly (except Peter Dalgaard's, which
works out-of-the-box).

At least I wasn't missing anything obvious about do.call().

Why is Peter Dalgaard's suggestion necessary?  Why can't  "+"
take more than two arguments?






On 17 Nov 2006, at 10:38, Peter Dalgaard wrote:

> [EMAIL PROTECTED] writes:
>
>> Hi,
>>
>> You could stack your list in an array and then use apply :
>>
>> myArray <- array( unlist(lapply(1:3, f) ) , dim =c(2, 3, 3))
>> apply(myArray, c(1,2), sum)
>
> Or fixup "+" to take more than two arguments, e.g.
>
> "++" <- function(x, ...) if (nargs() == 1) x else x + Recall(...)
>
> f  <- function(i){matrix((1:6)^i, 2, 3)}
> do.call("++", sapply(1:4, f, simplify=FALSE))
>
> ##
>
>> "++" <- function(x, ...) if (nargs() == 1) x else x + Recall(...)
>> f  <- function(i){matrix((1:6)^i, 2, 3)}
>> do.call("++", sapply(1:4, f, simplify=FALSE))
>  [,1] [,2] [,3]
> [1,]4  120  780
> [2,]   30  340 1554
>
>
>
>
>> Cheers,
>>
>> Romain
>>
>> Quoting Robin Hankin <[EMAIL PROTECTED]>:
>>
>>> Hi
>>>
>>> How do I make do.call() take "+" as a function for a list of more
>>> than two elements?
>>>
>>> Toy problem follows:
>>>
>>>
>>> f  <- function(i){matrix((1:6)^i,2,3)}
>>>
>>> # Thus f() returns a matrix of size 2x3; I want to add a whole bunch
>>> of such matrices,
>>> # as in  f(1) + f(2) + f(3) + f(4)
>>>
>>> # But:
>>>
>>>
>>>
>>>> do.call("+",sapply(1:4,f,simplify=FALSE))
>>> Error in do.call("+", sapply(1:4, f, simplify = FALSE)) :
>>> operator needs one or two arguments
>>>
>>>
>>>
>>>
>>> Also,
>>>
>>>
>>>> do.call(sum,sapply(1:4,f,simplify=FALSE))
>>> [1] 2828
>>>
>>>
>>> doesn't do what I want (I would like a 2x3 matrix whose elements  
>>> are the
>>> sum of corresponding elements in my list)
>>>
>>> How to do this nicely?
>>>
>>>
> ucible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] do.call("+", ...)

2006-11-17 Thread Robin Hankin
Hi

How do I make do.call() take "+" as a function for a list of more  
than two elements?

Toy problem follows:


f  <- function(i){matrix((1:6)^i,2,3)}

# Thus f() returns a matrix of size 2x3; I want to add a whole bunch  
of such matrices,
# as in  f(1) + f(2) + f(3) + f(4)

# But:



 > do.call("+",sapply(1:4,f,simplify=FALSE))
Error in do.call("+", sapply(1:4, f, simplify = FALSE)) :
operator needs one or two arguments




Also,


 > do.call(sum,sapply(1:4,f,simplify=FALSE))
[1] 2828


doesn't do what I want (I would like a 2x3 matrix whose elements are the
sum of corresponding elements in my list)

How to do this nicely?





--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] filling an array, vectorized

2006-11-16 Thread Robin Hankin
Gabor
Tamas

yet again I find myself trumped by Gabor because I forget that
TRUE is a perfectly acceptable argument to "[".

Heh.


I'll stick do.index2() in the magic package.


best wishes


rksh


On 16 Nov 2006, at 11:27, Gabor Grothendieck wrote:

> Here is minor simplification:
>
> do.index2 <- function(a,f){
>  jj <- function(i) seq(dim(a)[i])
>  index <- as.matrix(expand.grid(lapply(jj(TRUE), jj)))
>  a[index] <- apply(index, 1, f)
>  a
> }
>
> # test
> a <- array(0,c(2,3,4))
> identical(do.index(a, f), do.index2(a, f))
> b <- array(0,c(2,2,2,2))
> identical(do.index(b, f), do.index2(b, f))
>
>
> On 11/16/06, Robin Hankin <[EMAIL PROTECTED]> wrote:
>> Tamas
>>
>> first of all, Thank You for a really well-posed, interesting problem.
>> Answer follows.
>>
>>
>>
>> do.index <- function(a,f){
>>   jj <- function(i){seq_len(dim(a)[i])}
>>   index <- as.matrix(expand.grid(sapply(1:length(dim
>> (a)),jj,simplify=FALSE)))
>>   a[index] <- apply(index,1,f)
>>   return(a)
>> }
>>
>>
>>
>> f <- function(l){
>>   sum(unlist(l))
>> }
>>
>> a <- array(0,c(2,3,4))
>> b <- array(0,c(2,2,2,2))
>>
>> do.index(a,f)
>> do.index(b,f)
>>
>>
>>
>> best wishes
>>
>> Robin
>>
>>
>>
>>
>>
>> On 15 Nov 2006, at 19:16, Tamas K Papp wrote:
>>
>> > Hi,
>> >
>> > I am sure this has come up before, but my searches of the archive
>> > didn't give any results (maybe I didn't use the right keywords,  
>> but if
>> > I use too many, the search times out).
>> >
>> > I have a vector of dimensions n, length is not fixed, eg
>> >
>> > n <- c(4,5,7)
>> >
>> > or
>> >
>> > n <- c(19,4,5,7)
>> >
>> > and a function f that takes a vector of indices, same length of  
>> n, and
>> > gives a scalar.
>> >
>> > I would like to fill the array
>> >
>> > a <- array(dim=n)
>> >
>> > so that (... is just notation, not R's ...)
>> >
>> > a[i,j,k,...] <- f(list(i,j,k,...))
>> >
>> > I would use loops, but since n can have different lengths, I don't
>> > know how many loops I would need beforehand.  Is there a way to do
>> > this?
>> >
>> > Thanks,
>> >
>> > Tamas
>> >
>> > __
>> > R-help@stat.math.ethz.ch mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide http://www.R-project.org/posting-
>> > guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>>

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] filling an array, vectorized

2006-11-16 Thread Robin Hankin
Tamas

first of all, Thank You for a really well-posed, interesting problem.
Answer follows.



do.index <- function(a,f){
   jj <- function(i){seq_len(dim(a)[i])}
   index <- as.matrix(expand.grid(sapply(1:length(dim 
(a)),jj,simplify=FALSE)))
   a[index] <- apply(index,1,f)
   return(a)
}



f <- function(l){
   sum(unlist(l))
}

a <- array(0,c(2,3,4))
b <- array(0,c(2,2,2,2))

do.index(a,f)
do.index(b,f)



best wishes

Robin





On 15 Nov 2006, at 19:16, Tamas K Papp wrote:

> Hi,
>
> I am sure this has come up before, but my searches of the archive
> didn't give any results (maybe I didn't use the right keywords, but if
> I use too many, the search times out).
>
> I have a vector of dimensions n, length is not fixed, eg
>
> n <- c(4,5,7)
>
> or
>
> n <- c(19,4,5,7)
>
> and a function f that takes a vector of indices, same length of n, and
> gives a scalar.
>
> I would like to fill the array
>
> a <- array(dim=n)
>
> so that (... is just notation, not R's ...)
>
> a[i,j,k,...] <- f(list(i,j,k,...))
>
> I would use loops, but since n can have different lengths, I don't
> know how many loops I would need beforehand.  Is there a way to do
> this?
>
> Thanks,
>
> Tamas
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Multivariate regression

2006-10-30 Thread Robin Hankin
Hi

I discovered the other day that lm() does some of the work for
you:

library(mvtnorm)

X <- matrix(rnorm(60),ncol=3)
beta  <- matrix(1:6,ncol=2)
sig <- matrix(c(1,0.7,0.7,1),2,2)

Y <- X %*% beta + rmvnorm(n=20,sigma=sig)


  lm(Y ~ X-1)

Call:
lm(formula = Y ~ X - 1)

Coefficients:
 [,1]   [,2]
X1  1.015  4.065
X2  2.483  5.366
X3  2.762  5.727


This gives an estimate for beta.

But I don't know of a ready-made R solution for estimating
the covariance of  the elements of beta, or the "sig" matrix
for the covariance matrix of the observation errors.

Anyone?





On 30 Oct 2006, at 09:01, Andris Jankevics wrote:

> Also you can take a look on Partial Least Squares (PLS) regression.
> http://www.statsoft.com/textbook/stpls.html
> R-package: http://mevik.net/work/software/pls.html
>
> Andris Jankevics
>
> On Sestdiena, 28. Oktobris 2006 06:04, Ritwik Sinha wrote:
>> You can use gee (
>> http://finzi.psych.upenn.edu/R/library/geepack/html/00Index.html)  
>> or maybe
>> the function gls in nlme.
>>
>> Ritwik.
>>
>> On 10/27/06, Ravi Varadhan <[EMAIL PROTECTED]> wrote:
>>> Hi,
>>>
>>>
>>>
>>> Suppose I have a multivariate response Y (n x k) obtained at a  
>>> set of
>>> predictors X (n x p).  I would like to perform a linear  
>>> regression taking
>>> into consideration the covariance structure of Y within each unit  
>>> - this
>>> would be represented by a specified matrix V (k x k), assumed to  
>>> be the
>>> same
>>> across units.  How do I use "lm" to do this?
>>>
>>>
>>>
>>> One approach that I was thinking of is as follows:
>>>
>>>
>>>
>>> Flatten Y to a vector, say, Yvec (n*k x 1).  Create Xvec (n*k,  
>>> p*k) such
>>> that it is made up of block matrices Bij (k x k), where Bij is a  
>>> diagonal
>>> matrix with X_ij as the diagonal (i = 1,.n, and j = 1,.,p).  Now  
>>> I can
>>> use "lm" in a univariate mode to regress Yvec against Xvec, with
>>> covariance matrix Vvec (n*k x n*k).  Vvec is a block-diagonal  
>>> matrix with
>>> blocks of V along the diagonal.  This seems like a valid  
>>> approach, but I
>>> still don't know how to specify the covariance structure to do  
>>> weighted
>>> least squares.
>>>
>>>
>>>
>>> Any help is appreciated.
>>>
>>>
>>>
>>> Best,
>>>
>>> Ravi.
>>>
>>>
>>>
>>>
>>>  
>>> -
>>> --- ---
>>>
>>> Ravi Varadhan, Ph.D.
>>>
>>> Assistant Professor, The Center on Aging and Health
>>>
>>> Division of Geriatric Medicine and Gerontology
>>>
>>> Johns Hopkins University
>>>
>>> Ph: (410) 502-2619
>>>
>>> Fax: (410) 614-9625
>>>
>>> Email: [EMAIL PROTECTED]
>>>
>>> Webpage:
>>> http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html
>>>
>>>
>>>
>>>
>>>  
>>> -
>>> --- 
>>>
>>>
>>>
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] combinatorics

2006-10-13 Thread Robin Hankin
Hi Christos

thanks for this.  Unfortunately, this approach wouldn't work for me
because the real problem is too big for it: I have
letters A-F and two of each, giving

12!/(2^6) ~= 7e6 combinations (borderline feasible)

But in the approach you coded up below, matrix zz would have
  6^12 ~= 2e9 rows before eliminating the non-feasible ones.
This is too big for me.

Looks like it's going to be another weekend lost to C
[but at least I now have some confidence that I've not overlooked
anything obvious!]

With very best wishes, I really appreciate your efforts



Robin




On 13 Oct 2006, at 16:21, Christos Hatzis wrote:

> Hi Robin,
>
> This approach first generates all combinations and then eliminates the
> non-feasible ones.  It should work fine for smallish vectors but  
> might not
> scale well for larger vectors.  Hopefully it gives you what you  
> need for
> this problem.
>
> xx <- c("A","A","B","B","C")
> yy <- 1:length(xx)
> zz <- expand.grid(yy,yy,yy,yy,yy)
>
> ss <- zz[ apply(zz, 1, FUN=function(x) length(unique(x))) == length 
> (xx), ]
> ss <- as.matrix(ss)
>
> pp <- apply(ss, 1, FUN=function(x,v) paste(v[as.vector(x)],  
> collapse=""),
> v=xx)
> res <- unique(pp)
>
>> res
>  [1] "CBBAA" "BCBAA" "BBCAA" "CBABA" "BCABA" "CABBA" "ACBBA"  
> "BACBA" "ABCBA"
> "BBACA" "BABCA"
> [12] "ABBCA" "CBAAB" "BCAAB" "CABAB" "ACBAB" "BACAB" "ABCAB"  
> "CAABB" "ACABB"
> "AACBB" "BAACB"
> [23] "ABACB" "AABCB" "BBAAC" "BABAC" "ABBAC" "BAABC" "ABABC" "AABBC"
>> length(res)
> [1] 30
>
> -Christos
>
> Christos Hatzis, Ph.D.
> Nuvera Biosciences, Inc.
> 400 West Cummings Park
> Suite 5350
> Woburn, MA 01801
> Tel: 781-938-3830
> www.nuverabio.com
>
>
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Robin Hankin
> Sent: Friday, October 13, 2006 10:19 AM
> To: [EMAIL PROTECTED]
> Subject: [R] combinatorics
>
> Hi
>
> How do I generate all ways of ordering  sets of indistinguishable  
> items?
>
> suppose I have two A's, two B's and a C.
>
> Then I want
>
> AABBC
> AABCB
> AACBC
> ABABC
> . . .snip...
> BBAAC
> . . .snip...
> CBBAA
>
> [there are 5!/(2!*2!) = 30 arrangements.  Note AABBC != BBAAC]
>
> How do I do this?
>
>
>
>
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton European Way, Southampton  
> SO14
> 3ZH, UK
>   tel  023-8059-7743
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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

2006-10-13 Thread Robin Hankin
Hi

How do I generate all ways of ordering  sets of indistinguishable items?

suppose I have two A's, two B's and a C.

Then I want

AABBC
AABCB
AACBC
ABABC
. . .snip...
BBAAC
. . .snip...
CBBAA

[there are 5!/(2!*2!) = 30 arrangements.  Note AABBC != BBAAC]

How do I do this?





--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Block comments in R?

2006-10-05 Thread Robin Hankin

On 5 Oct 2006, at 10:05, Uwe Ligges wrote:

>
>
> Wee-Jin Goh wrote:
>> Hello list,
>>
>> Is there any way to perform a block comment in R? In C++, anything in
>> between a /* and */ is considered a comment, and it allows
>> programmers to comment out chunks of code for testing and debugging.
>> Is there such a feature in R?
>
>
> This has frequently been asked on the list. Try to google for it. You
> will find answers like
>
> if(FALSE){"
>  code block
>  commented
> "}
>
>


That method doesn't work for me:

if(FALSE){"

if(1<2)
   print("1<2")
else
   print("1>2")

"}


returns an error.  How would I comment out that block of (incorrect)  
code?







> or "use a good editor that supports commenting and uncommenting  
> blocks".
>
>
> Uwe Ligges
>
>

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 statement over multiple lines (i.e. the ... feature in Matlab)

2006-10-05 Thread Robin Hankin

On 5 Oct 2006, at 09:34, Bjørn-Helge Mevik wrote:

> Robin Hankin wrote:
>
>> For the line breaking, R deals with incomplete lines by not
>> executing the statement until you finish it.
>
> Beware, however, that syntactically valid lines do get executed
> immediately (at least at the prompt).


yes, you're quite right.  Your observation
leads to my number 1 gotcha:

if(1<2)  print("1<2")
else
print("1>2")

which (properly) returns an error because the first line is  
syntactically
complete, so the "else" statement is processed ab initio.

So now I always always always always type


if(1<2){
   print("1<2")
} else {
   print("1>2")
}


if by some chance I ignore emacs/ESS's indentation telling me I've  
forgotten
a brace.


best wishes


rksh




> So
>
> 1 + 2
> - 3
>
> will be interpreted as two commands (returning 3 and -3,
> respectively), while
>
> 1 + 2 -
> 3
>
> will be interpreted as a single command (returnig 0).
>
> -- 
> Bjørn-Helge Mevik
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 statement over multiple lines (i.e. the ... feature in Matlab)

2006-10-05 Thread Robin Hankin
Hi  Wee-Jin

you can block out bits of R code with

if(FALSE){
  
}

For the line breaking, R deals with incomplete lines by not executing  
the statement
until you finish it.  In the function case, it waits for you to close  
a bracket.


If you type:

myFunc(a=3,
b=5,
c=6,
d=7
)

myFunc() will only execute
when you close the bracket


HTH

rksh


On 5 Oct 2006, at 08:28, Wee-Jin Goh wrote:

> Hello again list,
>
> I thought I'd start a new thread, seeing as it's completely different
> from my previous question. Some functions I have written require many
> parameters, and so do not fit nicely into an 80 column width display.
> This is usually avoided, by spreading that particular statement over
> a few lines. This is something that I do in Matlab with the following:
>
> myFunc( parameter1, ...
> parameter2, ...
> parameter3, ...
> parameter4)
>
> The  ... operator in Matlab allows me to spread a statement over
> several lines. The ... operator in R seems to be more like the ...
> operator in C, which allows for a variable argument list.
>
> How do I accomplish this task in R? It's not a show stopper, but it
> would make reading my code much much easier.
>
> Cheers,
> Wee-Jin
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Some questions about plotting with R

2006-10-04 Thread Robin Hankin
Hi

>>>
>>
>> Thanks for the response Robin, but that document doesn't help me with
>> either my quest for plot3, or multiple figures (i.e. the 'figure'
>> command in Octave/Matlab).
>>
>> cheers,
>> Wee-Jin
>
> If you want three separate graphics windows (Devices) then,
>
> X11() # not really needed as plot() will produce a new device if  
> none is
>   # open
> plot(1:10)
> X11()
> plot(1:10)
> X11()
> plot(1:10)
>


This isn't in  R-and-octave.txt: I'll add it when I get a minute.

And come to think of it, R-and-octave.txt doesn't mention plot3,
probably because it's not implemented in octave AFAIR.
I'll add a section of 3D graphics, When I Get A Minute (tm).

You also have p3d() of the "onion" package for 3D plotting,
which you might find closer in spirit to the matlab functionality.

best wishes

rksh




> ...
>
> Will create a new device. see ?Devices for a list of devices you can
> open on your system or ?capabilities . It is so long since I used a
> Windows version of R, that I forget if X11() opens a Windows graphics
> device there as well.
>
> As for 3D stuff, you might take a look at persp() (in base R) and the
> scatterplot3D package. If you want to see what R's Graphics can do,  
> then
> the book R Graphics by Paul Murrell [1] will tell you all you need to
> know, and the excellent, online R graphics gallery [2] has lots of
> examples.
>





--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 generating diagnal blocks ?

2006-09-21 Thread Robin Hankin
Hello

You need adiag(), which
is now part of the magic package:


 > library(magic)
 > adiag(matrix(1:6,2,3),matrix(1:9,3,3))
  [,1] [,2] [,3] [,4] [,5] [,6]
[1,]135000
[2,]246000
[3,]000147
[4,]000258
[5,]000369
 >


the function also has extra functionality over the one Vito
points to in the archives.

HTH

rksh


On 21 Sep 2006, at 08:14, vito muggeo wrote:

> If I remember well, there should be a package including the function
> bdiag() making the job..but I am not able to remember its name..
>
> However a quick search via RSiteSearch("bdiag") yields
>
> http://finzi.psych.upenn.edu/R/Rhelp02a/archive/40393.html
>
> Hope this helps you,
>
> vito
>
>
> Tong Wang wrote:
>> Hi,
>>  I am trying to creat a matrix with diagnal blocks, say, I  
>> have a matrix X of any dimension (nxm) ,and would like to have:
>>
>> X
>> X
>> X
>>   
>>  .
>> otherwise space filled with 0's.   Is there a handy way to do this ?
>>
>> Thanks a lot in advance.
>>
>> best
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting- 
>> guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
> -- 
> 
> Vito M.R. Muggeo
> Dip.to Sc Statist e Matem `Vianelli'
> Università di Palermo
> viale delle Scienze, edificio 13
> 90128 Palermo - ITALY
> tel: 091 6626240
> fax: 091 485726/485612
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] functions and strings

2006-09-13 Thread Robin Hankin
Rich

that is swet

and does exactly what I want.

Thank you very much.


best wishes

rksh

On 13 Sep 2006, at 10:54, Rich FitzJohn wrote:

> Hi,
>
> Perhaps try this (based on 'bquote'):
>
> rewrite.expression <- function(expr, to, dep) {
>   f <- function(expr) {
> if ( length(expr) == 1 )
>   if ( expr == as.name(dep) )
> as.name(to)
>   else
> expr
> else
>   as.call(lapply(expr, f))
>   }
>   f(expr)
> }
>
> rewrite <- function(expr, to, dep='x') {
>   rewrite.expression(substitute(expr), to, dep)
> }
>
>> rewrite(1 + sin(cos(x)) + exp(x^2), 'xyz')
> 1 + sin(cos(xyz)) + exp(xyz^2)
>> rewrite(sin(x)+exp(x), 'xyz')
> sin(xyz) + exp(xyz)
>> rewrite(sin(i) + cos(sin(i^2)), 'tti', 'i')
> sin(tti) + cos(sin(tti^2))
> ## Or, closer to your example, using the name of the argument and body
> ## of the function:
> f <- function(r)
>   2*r/sin(r) - b
>
>> rewrite.expression(body(f), 'foo', names(formals(f)))
> 2 * foo/sin(foo) - b
>
> Hope that helps,
> Rich
>

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] functions and strings

2006-09-13 Thread Robin Hankin
Hello everyone

I know it looks like I'm making heavy weather of this, but
I don't think I communicated my problem properly.  I really
appreciate you guys' help here.

I am writing a wrapper for a mathematical library to
which I want to send character strings that it can execute,
and then pass the answer back to R.

Now, I want a user to be able to type _any_ function
and _any_ string.  For example:

f <- function(i){sin(i) + cos(sin(i^2))}
string <- "tti"

and then I want a function do() such that do(f,string) will return

"sin(tti) + cos(sin(tti^2))"

without worrying about whether f()'s arguments include or
do not include a particular letter, and without insisting that "i"
always appears as "(i)" .

Although thinking about it, it's not
actually that bad to require the user to use some otherwise
rare sequence of letters, say "XxX" as
an argument, and then Dmitris's first method would work.

Having said that, this is not an ideal solution
and it would be nicer to have some method that could detect
what the argument to f() is, where it is in the body, and substitute
those occurences for "string".

I want a method  that is perfectly general; I posted my
example of abcd...z(), not to be annoying and pedantic
but to illustrate that a simple gsub approach wouldn't work:
one has to know in advance which letters can and cannot
be used, and this information isn't available.

I don't have a function so named (yet ;-).


best wishes

rksh

>
> Hi Dmitris, Thierry,
>
> I'm getting there but it's still not quite right if f() includes
> something like x^2:
>
> f <- function(x){exp(x^2)}
>>>
>
> gsub("(x)", "(xyz)", deparse(body(f))[2], fixed = TRUE)
>
>
> [1] "x^2"
>
> [I don't care about the spaces]
>
>
>
> also,
>
>   I can't quite see how to implement Thierry's suggestion about
> changing the letter "x" into a letter that does not occur in f(),
> because of the
> following example:
>
>   f <- function(x){abcdefghijklmnopqrstuvwxyz(x^2)}
>
>
>
>
> On 13 Sep 2006, at 09:08, Dimitris Rizopoulos wrote:
>
>> yes you're right, maybe this is better
>>
>>> f <- function(x){sin(x)+exp(x)}
>>> strng <- gsub("(x)", "(xyz)", deparse(body(f))[2], fixed = TRUE)
>>> sub('^[[:space:]]+', '', strng)
>> [1] "sin(xyz) + exp(xyz)"
>>
>>
>> Best,
>> Dimitris
>>
>

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] functions and strings

2006-09-13 Thread Robin Hankin
Hi Dmitris, Thierry,

I'm getting there but it's still not quite right if f() includes  
something like x^2:

f <- function(x){exp(x^2)}
>>

gsub("(x)", "(xyz)", deparse(body(f))[2], fixed = TRUE)


[1] "x^2"

[I don't care about the spaces]



also,

  I can't quite see how to implement Thierry's suggestion about
changing the letter "x" into a letter that does not occur in f(),  
because of the
following example:

  f <- function(x){abcdefghijklmnopqrstuvwxyz(x^2)}




On 13 Sep 2006, at 09:08, Dimitris Rizopoulos wrote:

> yes you're right, maybe this is better
>
>> f <- function(x){sin(x)+exp(x)}
>> strng <- gsub("(x)", "(xyz)", deparse(body(f))[2], fixed = TRUE)
>> sub('^[[:space:]]+', '', strng)
> [1] "sin(xyz) + exp(xyz)"
>
>
> Best,
> Dimitris
>

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] functions and strings

2006-09-13 Thread Robin Hankin
Hi Dmitris

thanks for this  but it's not quite right:


 > f <- function(x){sin(x)+exp(x)}
 > strng <- gsub("x", "xyz", deparse(body(f))[2])
 > sub('^[[:space:]]+', '', strng)
[1] "sin(xyz) + exyzp(xyz)"


and I would want "sin(xyz) + exp(xyz)"




On 13 Sep 2006, at 08:45, Dimitris Rizopoulos wrote:

> strng <- gsub("x", "xyz", deparse(body(f))[2])
> sub('^[[:space:]]+', '', strng)

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] functions and strings

2006-09-13 Thread Robin Hankin
Hi

If

string <- "xyz"
f <- function(x){1 + sin(cos(x)) + exp(x^2)}

How do I manipulate "string" and f() to give the string

"1 + sin(cos(xyz)) + exp(xyz^2)"

?


--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] exactly representable numbers

2006-09-11 Thread Robin Hankin
Hi Duncan


[snip]

On 11 Sep 2006, at 12:12, Duncan Murdoch wrote:

> Here's my version:  not tested too much.
>
> f <- function(x) {
>u <- x
>l <- 0
>mid <- u/2
>while (l < mid && mid < u) {
>  if (x < x + mid) u <- mid
>  else l <- mid
>  mid <- (l + u)/2
>}
>u
> }
>



thanks for this.  Wouldn't it be a good idea to have some function
that returns "the smallest exactly representable number strictly  
greater than x"?

Or does this exist already?



Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] exactly representable numbers

2006-09-11 Thread Robin Hankin
Hi Sundar


thanks for this.  But I didn't make it clear that I'm interested in  
extreme numbers
such as 1e300 and 1e-300.

Then

 > f(1e300)
[1] 7.911257e+283

is different from

1e300*.Machine$double.eps


[I'm interested in the gap between successive different exactly  
representable
numbers right across the IEEE range]



rksh





On 11 Sep 2006, at 10:50, Sundar Dorai-Raj wrote:

>
>
> Robin Hankin said the following on 9/11/2006 3:52 AM:
>> Hi
>> Given a real number x,  I want to know how accurately R can  
>> represent  numbers near x.
>> In particular, I want to know the infimum of exactly representable
>> numbers greater than x, and the supremum of exactly representable   
>> numbers
>> less than x.  And then the interesting thing is the difference   
>> between these two.
>> I have a little function that does some of this:
>> f <- function(x,FAC=1.1){
>>delta <- x
>> while(x+delta > x){
>>delta <- delta/FAC
>> }
>> return(delta*FAC)
>> }
>> But this can't be optimal.
>> Is there a better way?
>
> I believe this is what .Machine$double.eps is. From ?.Machine
>
> double.eps: the smallest positive floating-point number 'x' such that
>   '1 + x != 1'.  It equals 'base^ulp.digits' if either 'base'
>   is 2 or 'rounding' is 0;  otherwise, it is  
> '(base^ulp.digits)
>   / 2'.
>
> See also .Machine$double.neg.eps. Is this what you need?
>
> --sundar

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] exactly representable numbers

2006-09-11 Thread Robin Hankin
Hi

Given a real number x,  I want to know how accurately R can represent  
numbers near x.

In particular, I want to know the infinum of exactly representable
numbers greater than x, and the supremum of exactly representable  
numbers
less than x.  And then the interesting thing is the difference  
between these two.


I have a little function that does some of this:


f <- function(x,FAC=1.1){
   delta <- x
while(x+delta > x){
   delta <- delta/FAC
}
return(delta*FAC)
}

But this can't be optimal.

Is there a better way?



--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] What is the matrix version of min()

2006-09-06 Thread Robin Hankin
Tong

you need to use apply().  The second argument specifies whether
you want to work with rows or columns.  The point of this is that
min() and max() operate on vectors and give a single value,
and you want to "apply" this function to all rows or all columns:

 > a <- matrix(rnorm(30),5,6)
 > apply(a,2,max)
[1] 2.6413241 0.9842076 1.7989560 0.6999855 2.0542201 0.1162821
 > apply(a,1,max)
[1] 1.1771370 0.9811693 2.6413241 0.9842076 2.0542201
 >

HTH

rksh


On 6 Sep 2006, at 09:37, Tong Wang wrote:

> Hi,
> Is there a function which operates on a matrix and return a  
> vector of min/max of each rol/col ?
> say,  X=  2,  1
> 3,  4
> min.col(X)=c(2,1)
>
> thanks a lot.
>
> tong
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Create a vector from another vector

2006-08-30 Thread Robin Hankin
OK,

With this extra detail, a
third solution follows, which may be closer in spirit
to your application.
It may or may not be faster than the other two,
depending on the exact parameters used:


library(partitions)
1+blockparts(n=15,y=c(3,4,2,5,6)-1,include.fewer=T)

(720 distinct solutions)


rksh

On 30 Aug 2006, at 15:49, Doran, Harold wrote:

> Hi Duncan
>
> Here is a bit more detail, this is a bit tough to explain, sorry  
> for not
> being clear. Ordering is not important because the vector I am  
> creating
> is used as a sufficient statistic in an optimization routine to get  
> some
> MLEs. So, any combination of the vector that sums to X is OK. But, the
> condition that x2[i] <= x[i] must be maintained. So, the example below
> would not work because x2[1] > x[1] as you note below.
>
>> I don't think it's really clear what you mean by "ordering is
>> not important".  Would
>>
>> x2 <- c(6,5,2,4,2)
>> be acceptable (a re-ordering of your first two examples),
>> even though x2[1] > x1[1]?
>
> To be concrete, the following is the optimization function. This is a
> psychometric problem where the goal is to get the MLE for a test taker
> conditional on their response pattern (i.e., number of points on the
> test) and the item parameters.
>
> pcm.max3 <- function(score, d){
> pcm <- function(theta, d, score)
> exp(sum(theta-d[1:score]))/sum(exp(cumsum(theta-d)))
> opt <- function(theta) -sum(log(mapply(pcm, d, theta = theta,  
> score=
> score )))
> start_val <- log(sum(score-1)/(length(score-1)/sum(score-1)))
> out <- optim(start_val, opt, method = "BFGS", hessian = TRUE)
> cat('theta is about', round(out$par, 2), ', se',
> 1/sqrt(out$hes),'\n')
>   }
>
> Suppose we have a three item test. I store the item parameters in a  
> list
> as
>
> items <- list(c(0,.5,1), c(0,1), c(0, -1, .5, 1))
>
> We can get the total possible number correct as
>
> (x <- sapply(items, length))
> [1] 3 2 4
>
> But, you cannot actually get the MLE for this because the  
> likelihood is
> unbounded in this case.
>
> So, let's say the student scored in the following categories for each
> item:
>
> x2 <- c(3,1,4)
>
> By x2[i] <= x[i], I mean that there are 3 possible categories for  
> item 1
> above. So, a student can only score in categories 1,2 or 3. He cannot
> score in category 4. This is why the condition that x2[i] <= x[i] is
> critical.
>
> But, because total score is a sufficient statistic, (i.e.,  
> "ordering is
> not important") we could either vector in the function pcm.
>
> x3 <- c(3,2,3)
>
> Using the function
>
> pcm.max3(x2, items)
> pcm.max3(x3, items)
>
> Gives the same MLE.
>
> But, the vector
>
> X_bad <- c(4,1,3)
>
> Would not work. You can see that the elements of this vector actually
> serve as indices denoting which category a test taker scored in for  
> each
> item in the list "items"
>
> I hope this is helpful and appreciate your time.
>
> Harold
>
>
>>>
>>> __
>>> R-help@stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Create a vector from another vector

2006-08-30 Thread Robin Hankin
I think I've got it now.

If I understand your question,  try:


 > x <- do.call("cbind",lapply(5:7,function(i){restrictedparts(i, 
5,include.zero=FALSE)}))
 > acceptable <- function(x){all(x<=c(3,4,5,2,6))}
 > x[,apply(x,2,acceptable)]
  [,1] [,2] [,3] [,4]
[1,]1232
[2,]1112
[3,]1111
[4,]1111
[5,]1111
 >


rksh



On 30 Aug 2006, at 14:49, Doran, Harold wrote:

> Dear list
>
> Suppose I have the following vector:
>
> x <-  c(3,4,2,5,6)
>
> Obviously, this sums to 20. Now, I want to have a second vector,  
> call it
> x2, that sums to x where 5 <= x <= 20, but there are constraints.
>
> 1) The new vector must be same length as x
> 2) No element of the new vector can be 0
> 3) Element x2[i] of the new vector cannot be larger than element x 
> [i] of
> the original vector
> 4) Ordering is not important
>
> The following would be an example of what I would want if the user
> wanted the vector x2 to sum to 19
>
> x2 <- c(2,4,2,5,6)
>
> Or, because ordering is not important, this is acceptable
>
> x2 <- c(3,3,2,5,6)
>
> Whereas this would not be appropriate
>
> x3 <- c(4, 2,2,5,6)
>
> Because element x3[1] is larger than x[1] even though it sums to 19.
>
> Ideally, the function would take as input the original vector, x, and
> the number that the new vector would sum to. In this example, the  
> vector
> could sum to any number 5 through 20.
>
> For example,
>
> myFun <- function(x, sumto) ... details ...
>
> Is there a preexisiting function that would already do this? I have
> spent too much (unsuccessful) time trying to write a function of my  
> own
> but can't seem to get this to work properly.
>
> Any hints would be greatly appreciated.
>
> Harold
>
>
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] Create a vector from another vector

2006-08-30 Thread Robin Hankin
Dear Harold

package "partitions" does almost this:



 > library(partitions)
 > x <- 1+restrictedparts(15,5)
 > x[,1:10]
  [,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,]   16   15   14   13   12   11   10
[2,]1234567
[3,]1111111
[4,]1111111
[5,]1111111
  [,8] [,9] [,10]
[1,]9   1413
[2,]82 3
[3,]12 2
[4,]11 1
[5,]11 1
 >

HTH

Robin


On 30 Aug 2006, at 14:49, Doran, Harold wrote:

> Dear list
>
> Suppose I have the following vector:
>
> x <-  c(3,4,2,5,6)
>
> Obviously, this sums to 20. Now, I want to have a second vector,  
> call it
> x2, that sums to x where 5 <= x <= 20, but there are constraints.
>
> 1) The new vector must be same length as x
> 2) No element of the new vector can be 0
> 3) Element x2[i] of the new vector cannot be larger than element x 
> [i] of
> the original vector
> 4) Ordering is not important
>
> The following would be an example of what I would want if the user
> wanted the vector x2 to sum to 19
>
> x2 <- c(2,4,2,5,6)
>
> Or, because ordering is not important, this is acceptable
>
> x2 <- c(3,3,2,5,6)
>
> Whereas this would not be appropriate
>
> x3 <- c(4, 2,2,5,6)
>
> Because element x3[1] is larger than x[1] even though it sums to 19.
>
> Ideally, the function would take as input the original vector, x, and
> the number that the new vector would sum to. In this example, the  
> vector
> could sum to any number 5 through 20.
>
> For example,
>
> myFun <- function(x, sumto) ... details ...
>
> Is there a preexisiting function that would already do this? I have
> spent too much (unsuccessful) time trying to write a function of my  
> own
> but can't seem to get this to work properly.
>
> Any hints would be greatly appreciated.
>
> Harold
>
>
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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

2006-08-29 Thread Robin Hankin
Hi

check out R-and-octave.txt on the contributed docs section of CRAN.


HTH


Robin

On 28 Aug 2006, at 17:50, Lord Tyranus wrote:

> Hello wizards, I need to convert the following functions (prestd,
> poststd, prepca)   of matlab to R. Does Somebody knows how to do it. A
> description of the functions is:
>
> prestd preprocesses the network training set by normalizing the inputs
> and targets so that they have means of zero and standard deviations of
> 1.
>
> poststd postprocesses the network training set which was preprocessed
> by prestd. It converts the data back into unnormalized units.
>
> prepca preprocesses the network input training set by applying a
> principal component analysis. This analysis transforms the input data
> so that the elements of the input vector set will be uncorrelated. In
> addition, the size of the input vectors may be reduced by retaining
> only those components which contribute more than a specified fraction
> (min_frac) of the total variation in the data set.
>
> Thanks in advance.
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] listing a sequence of vectors in a matrix

2006-08-22 Thread Robin Hankin
Gabor makes a good point about seq() vs a:b [a common gotcha
for me].


I'll revise my original function to:

 > f <- function(a,n){(seq(length=a))[1:n]}
 > t(sapply(c(2,3,4,4,4,5,6,0),f,n=5))
  [,1] [,2] [,3] [,4] [,5]
[1,]12   NA   NA   NA
[2,]123   NA   NA
[3,]1234   NA
[4,]1234   NA
[5,]1234   NA
[6,]12345
[7,]12345
[8,]   NA   NA   NA   NA   NA
 >




rksh

On 22 Aug 2006, at 13:55, Gabor Grothendieck wrote:

> Here are two solutions.  seq(length = ...) instead of
> just seq(...) is so that v can possibly contain zeros.
>
> # data
> v <- 3:5
>
> # solution 1 - rbind/lapply
> f <- function(n) {
>   s = seq(length = n)
>   replace(rep(NA, max(v)), s, s)
> }
> do.call(rbind, lapply(v, f))
>
> # solution 2 - loop
> mat <- matrix(NA, length(v), max(v))
> for(i in seq(v)) {
>   s <- seq(length = v[i])
>   mat[i, s] <- s
> }
>
>
> On 8/22/06, Sara-Jane Dunn <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> I'm having trouble applying the matrix function. I'd like to be  
>> able to
>> create a matrix of vectors filled in by rows, which are not all  
>> the same
>> length, and so I need it to fill in NAs where applicable.
>>
>> It's easiest to explain with a simple example:
>>
>> Suppose vec = c(3,4,5). How can I form a matrix of the vectors  
>> 1:vec[j]
>> for j=1:3?
>> i.e. 1   2   3   NA NA
>>  1   2   3   4   NA
>>  1   2   3   45
>> I've tried matrix(c(1:vec[j]),nrow=max(j),ncol=max(vec)) but it will
>> only give me a matrix with repeated values for j=1, like   1  2  3  1
>> 2
>>3  1  2  3  1
>>2  3  1  2  3
>>
>> Also using the list function hasn't got me anywhere either..
>>
>> Any help/ideas would be greatly appreciated!
>>
>> Many thanks,
>> Sara-Jane Dunn
>>
>> --
>> This message (and any attachments) is for the recipient only... 
>> {{dropped}}
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] listing a sequence of vectors in a matrix

2006-08-22 Thread Robin Hankin

Hi



 > f <- function(a,n){(1:a)[1:n]}
 > t(sapply(c(2,3,4,4,4,5,6),f,n=5))
  [,1] [,2] [,3] [,4] [,5]
[1,]12   NA   NA   NA
[2,]123   NA   NA
[3,]1234   NA
[4,]1234   NA
[5,]1234   NA
[6,]12345
[7,]12345
 >
 >


HTH

rksh





On 22 Aug 2006, at 12:29, Sara-Jane Dunn wrote:

> Hi,
>
> I'm having trouble applying the matrix function. I'd like to be  
> able to
> create a matrix of vectors filled in by rows, which are not all the  
> same
> length, and so I need it to fill in NAs where applicable.
>
> It's easiest to explain with a simple example:
>
> Suppose vec = c(3,4,5). How can I form a matrix of the vectors 1:vec 
> [j]
> for j=1:3?
> i.e. 1   2   3   NA NA
>   1   2   3   4   NA
>   1   2   3   45
> I've tried matrix(c(1:vec[j]),nrow=max(j),ncol=max(vec)) but it will
> only give me a matrix with repeated values for j=1, like   1  2  3  1
> 2
> 3  1  2  3  1
> 2  3  1  2  3
>
> Also using the list function hasn't got me anywhere either..
>
> Any help/ideas would be greatly appreciated!
>
> Many thanks,
> Sara-Jane Dunn
>
> --  
> This message (and any attachments) is for the recipient on...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] big numbers

2006-08-22 Thread Robin Hankin
Hi

Can I get R to handle really big numbers?I am not interested
in more than (say) 10 sig figs, but I would like to deal with numbers
up to, say, 10^1.

If

a <- 10^1
b <- pi* a

I would like  "a+b" to return 3.1415926e1.


Toy example, illustrating why I can't deal with log(a) and log(b),   
follows.



f <- function(a,n=100){
   out <- rep(0,n)
   out[1] <- a
   for(i in 2:n){
 out[i] <- sum(exp(out[1:i])) + rexp(1)
   }
   return(log(out))
}


then f(1,10)  has infinities in it, even though the values should be  
moderate size.

What are my options here?

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] mirror vector?

2006-07-28 Thread Robin Hankin
Hi

Not that there's anything wrong with Jacques's answer, but
the List might be interested in the following gotcha:



 > m <- matrix(1:30,5,6)
 > apply(m,2,rev)
  [,1] [,2] [,3] [,4] [,5] [,6]
[1,]5   10   15   20   25   30
[2,]49   14   19   24   29
[3,]38   13   18   23   28
[4,]27   12   17   22   27
[5,]16   11   16   21   26
 > apply(m,1,rev)
  [,1] [,2] [,3] [,4] [,5]
[1,]   26   27   28   29   30
[2,]   21   22   23   24   25
[3,]   16   17   18   19   20
[4,]   11   12   13   14   15
[5,]6789   10
[6,]12345
 >

See how the first usage of apply() works as expected (at least for  
me ;-)
but the second returns the transpose of what one might need.
That's why I wrote arev().


comments anyone?





On 28 Jul 2006, at 08:56, Jacques VESLOT wrote:

>> mat <- matrix(1:16,4,4)
>> mat
>   [,1] [,2] [,3] [,4]
> [1,]159   13
> [2,]26   10   14
> [3,]37   11   15
> [4,]48   12   16
>> apply(mat,2,rev)
>   [,1] [,2] [,3] [,4]
> [1,]48   12   16
> [2,]37   11   15
> [3,]26   10   14
> [4,]159   13
>
> ---
> Jacques VESLOT
>
> CNRS UMR 8090
> I.B.L (2ème étage)
> 1 rue du Professeur Calmette
> B.P. 245
> 59019 Lille Cedex
>
> Tel : 33 (0)3.20.87.10.44
> Fax : 33 (0)3.20.87.10.31
>
> http://www-good.ibl.fr
> ---
>
>
> [EMAIL PROTECTED] a écrit :
>> Hello,
>>
>> I'm an absolut beginner with R and now I got a 2D vector with  
>> numbers. I would like to mirror this vector now by the rows (so  
>> that the first row becomes last, second becomes one before  
>> last, ...).
>> I don't know if there is any method I can use to do this.
>> Could you please help me?
>>
>> Antje
>>
>>  
>> -
>> Was Sie schon immer wissen wollten aber nie zu Fragen trauten?  
>> Yahoo! Clever hilft Ihnen.
>>  [[alternative HTML version deleted]]
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] mirror vector?

2006-07-28 Thread Robin Hankin
Hi Antje


use the fact that n:1 counts backwards from n, and then use this as
a row index:

 > m <- matrix(1:30,5,6)
 > m[nrow(m):1,]
  [,1] [,2] [,3] [,4] [,5] [,6]
[1,]5   10   15   20   25   30
[2,]49   14   19   24   29
[3,]38   13   18   23   28
[4,]27   12   17   22   27
[5,]16   11   16   21   26


[
a more general answer would be

library(magic)
arev(m,1)
]



HTH

rksh



On 28 Jul 2006, at 08:50, <[EMAIL PROTECTED]> wrote:

> Hello,
>
> I'm an absolut beginner with R and now I got a 2D vector with  
> numbers. I would like to mirror this vector now by the rows (so  
> that the first row becomes last, second becomes one before last, ...).
> I don't know if there is any method I can use to do this.
> Could you please help me?
>
> Antje
>
>   
> -
> Was Sie schon immer wissen wollten aber nie zu Fragen trauten?  
> Yahoo! Clever hilft Ihnen.
>   [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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

2006-07-28 Thread Robin Hankin
Hi

two solutions, your best option depends on the level
of generality you need.


(i)


M[M< -4] <- -4
M[M > 3] <- 3


(ii)

M <- pmax(pmin(M,3),-4)




HTH

rksh


On 28 Jul 2006, at 07:44, Kartik Pappu wrote:

> Hi all,
>
> I have a square (a x a) matrix with values in a range. For example:
>
>   [,1] [,2] [,3] [,4]
> [1,]   -5   -13   -4
> [2,]   -404   -3
> [3,]   -315   -2
> [4,]   -22   -5   -1
>
> I want to take any number smaller than -4 (in this example -5) and
> replace it with -4 and similarly take any number greater than 3 (in
> this case 4 and 5) and replace it with 3. The other numbers (and the
> overall structure of the matrix should remain unchanged.
>
> Seems like something that would use an "if a logic, but I cannot figure out how to manipulate the entire matrix.
>
> Thanks much
>
> Kartik
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] inserting rows into a matrix

2006-07-27 Thread Robin Hankin
Gabor, Christos

great, two elegant  vectorized  solutions.  I spent quite a long time
trying to generalize my f() to accept zeroes with no luck (long
story), so either of these solutions is fine.



TDH  [this *did* help]

rksh



On 27 Jul 2006, at 15:34, Christos Hatzis wrote:

> Hi Robin,
>
> Ok.  I see.  Try this then:
>
> f <- function(a){if( any(a==0) ) stop("Zeros in input vector") else
> cbind(a,a+1,rev(a))}
> a2 <- c(1,0,0,2,4,0,3)
>
> f(a2) # error message
>
> f2 <- function(a) {
> indx.zero <- which(a==0)
> indx.nz <- (1:length(a))[-indx.zero]
>
> x <- f(a[indx.nz])
> xx <- matrix(NA,length(a),ncol(x))
> xx[ indx.zero, ] <- rep(0,ncol(x))
> xx[ indx.nz, ] <- x
> xx
> }
>
>> f2(a2)
>  [,1] [,2] [,3]
> [1,]123
> [2,]000
> [3,]000
> [4,]234
> [5,]    452
> [6,]000
> [7,]341
>
> -Christos
>
> -Original Message-
> From: Robin Hankin [mailto:[EMAIL PROTECTED]
> Sent: Thursday, July 27, 2006 10:16 AM
> To: [EMAIL PROTECTED]
> Cc: 'Robin Hankin'; 'RHelp'
> Subject: Re: [R] inserting rows into a matrix
>
> Hi Christos
>
> thanks for this, but it won't work because in my application
> f(A2) will fail if there are any zeroes in A2.
>
>
> cheers
>
> rksh
>
>
> On 27 Jul 2006, at 15:10, Christos Hatzis wrote:
>
>> This is not as elegant, but should work:
>>
>> a3 <- f(A2)
>> a3[ which( apply(a3,1,prod) == 0 ), ] <- rep(0,ncol(a3))
>> a3
>>
>> Essentially use the product to pick out the rows with at least one 0
>> and replace these rows with 0s.
>>
>> HTH.
>> -Christos
>>
>> -Original Message-
>> From: [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] On Behalf Of Robin Hankin
>> Sent: Thursday, July 27, 2006 9:54 AM
>> To: RHelp
>> Subject: [R] inserting rows into a matrix
>>
>> Hi
>>
>>
>> I have a little vector function that takes a vector A of strictly
>> positive integers and outputs a matrix M  each of whose columns is  
>> the
>> vector, modified in a complicated combinatorical way.
>>
>> Now I want to generalize the function so that A can include zeroes.
>> Given A,
>> I want to strip out the zeroes, pass it to my function, and pad  M
>>   with rows at positions corresponding to the zeroes of A.
>>
>> Commented, minimal, self-contained, reproducible toy example follows.
>>
>>
>> f <- function(a){cbind(a,a+1,rev(a))}  #real function a ghastly
>> nightmare
>>
>>   A <- 1:5
>>   f(A)
>>   a
>> [1,] 1 2 5
>> [2,] 2 3 4
>> [3,] 3 4 3
>> [4,] 4 5 2
>> [5,] 5 6 1
>>
>>
>> # f() works as desired.
>>
>> # Now introduce A2, that includes zeroes.  In my application, f(A2)
>> would fail because of the zeroes.
>>
>> A2 <- c(1,0,0,2,4,0,3)
>>
>> I can strip the zeroes out and call f():
>>   f(A2[A2>0])
>>   a
>> [1,] 1 2 3
>> [2,] 2 3 4
>> [3,] 4 5 2
>> [4,] 3 4 1
>>
>> which is fine.  How to put the zeroes back in in the appropriate rows
>> and get the following:
>>
>>> cbind(c(1,0,0,2,4,0,3),c(2,0,0,3,5,0,4),c(3,0,0,4,2,0,1))
>>   [,1] [,2] [,3]
>> [1,]    123
>> [2,]000
>> [3,]000
>> [4,]234
>> [5,]452
>> [6,]000
>> [7,]341
>>>
>>
>>
>>
>> anyone?
>>
>>
>>
>> --
>> Robin Hankin
>> Uncertainty Analyst
>> National Oceanography Centre, Southampton European Way, Southampton
>> SO14
>> 3ZH, UK
>>   tel  023-8059-7743
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-
>> guide.html and provide commented, minimal, self-contained,
>> reproducible code.
>>
>>
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton European Way, Southampton  
> SO14
> 3ZH, UK
>   tel  023-8059-7743
>
>
>

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] inserting rows into a matrix

2006-07-27 Thread Robin Hankin
Hi Christos

thanks for this, but it won't work because in my application
f(A2) will fail if there are any zeroes in A2.


cheers

rksh


On 27 Jul 2006, at 15:10, Christos Hatzis wrote:

> This is not as elegant, but should work:
>
> a3 <- f(A2)
> a3[ which( apply(a3,1,prod) == 0 ), ] <- rep(0,ncol(a3))
> a3
>
> Essentially use the product to pick out the rows with at least one  
> 0 and
> replace these rows with 0s.
>
> HTH.
> -Christos
>
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Robin Hankin
> Sent: Thursday, July 27, 2006 9:54 AM
> To: RHelp
> Subject: [R] inserting rows into a matrix
>
> Hi
>
>
> I have a little vector function that takes a vector A of strictly  
> positive
> integers and outputs a matrix M  each of whose columns is the vector,
> modified in a complicated combinatorical way.
>
> Now I want to generalize the function so that A can include zeroes.
> Given A,
> I want to strip out the zeroes, pass it to my function, and pad  M
>   with rows at positions corresponding to the zeroes of A.
>
> Commented, minimal, self-contained, reproducible toy example follows.
>
>
> f <- function(a){cbind(a,a+1,rev(a))}  #real function a ghastly  
> nightmare
>
>   A <- 1:5
>   f(A)
>   a
> [1,] 1 2 5
> [2,] 2 3 4
> [3,] 3 4 3
> [4,] 4 5 2
> [5,] 5 6 1
>
>
> # f() works as desired.
>
> # Now introduce A2, that includes zeroes.  In my application, f(A2)  
> would
> fail because of the zeroes.
>
> A2 <- c(1,0,0,2,4,0,3)
>
> I can strip the zeroes out and call f():
>   f(A2[A2>0])
>   a
> [1,] 1 2 3
> [2,] 2 3 4
> [3,] 4 5 2
> [4,] 3 4 1
>
> which is fine.  How to put the zeroes back in in the appropriate  
> rows and
> get the following:
>
>> cbind(c(1,0,0,2,4,0,3),c(2,0,0,3,5,0,4),c(3,0,0,4,2,0,1))
>   [,1] [,2] [,3]
> [1,]123
> [2,]000
> [3,]000
> [4,]234
> [5,]452
> [6,]000
> [7,]341
>>
>
>
>
> anyone?
>
>
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton European Way, Southampton  
> SO14
> 3ZH, UK
>   tel  023-8059-7743
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] inserting rows into a matrix

2006-07-27 Thread Robin Hankin
Hi


I have a little vector function that takes a vector A of strictly  
positive integers
and outputs a matrix M  each of whose columns is the vector, modified in
a complicated combinatorical way.

Now I want to generalize the function so that A can include zeroes.   
Given A,
I want to strip out the zeroes, pass it to my function, and pad  M
  with rows at positions corresponding to the zeroes of A.

Commented, minimal, self-contained, reproducible toy example follows.


f <- function(a){cbind(a,a+1,rev(a))}  #real function a ghastly  
nightmare

  A <- 1:5
  f(A)
  a
[1,] 1 2 5
[2,] 2 3 4
[3,] 3 4 3
[4,] 4 5 2
[5,] 5 6 1


# f() works as desired.

# Now introduce A2, that includes zeroes.  In my application, f(A2)  
would fail
because of the zeroes.

A2 <- c(1,0,0,2,4,0,3)

I can strip the zeroes out and call f():
  f(A2[A2>0])
  a
[1,] 1 2 3
[2,] 2 3 4
[3,] 4 5 2
[4,] 3 4 1

which is fine.  How to put the zeroes back in in the appropriate rows
and get the following:

 > cbind(c(1,0,0,2,4,0,3),c(2,0,0,3,5,0,4),c(3,0,0,4,2,0,1))
  [,1] [,2] [,3]
[1,]123
[2,]000
[3,]000
[4,]234
[5,]452
[6,]000
[7,]341
 >



anyone?



--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 resample (or resize) matrix?

2006-07-27 Thread Robin Hankin
Right, I think I understand the question.



library(magic)
?subsums

If you want a windowed moving average, do:

x <- matrix(1:100,10,10)
subsums(x,6,FUN="mean",pad=NA,wrap=F)[6:10,6:10]



If you want block average, do:

subsums(x,2,FUN="mean",pad=NA,wrap=F)[seq(2,10,2),seq(2,10,2)]

which agrees with Jim's solution below.


HTH

rksh




On 27 Jul 2006, at 11:20, jim holtman wrote:

> Is this what you want: the mean of the surrounding 4 cells?
>
>> x <- matrix(1:100, 10)  # create data
>> rmean <- matrix(0,5,5)  # result matrix
>> for (i in 1:5){
> + for (j in 1:5){
> + rmean[i, j] <- mean(x[c(-1,0) + 2 * i, c(-1,0) + 2 * j])
> + }
> + }
>> x
>   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
>  [1,]1   11   21   31   41   51   61   71   8191
>  [2,]2   12   22   32   42   52   62   72   8292
>  [3,]3   13   23   33   43   53   63   73   8393
>  [4,]4   14   24   34   44   54   64   74   8494
>  [5,]5   15   25   35   45   55   65   75   8595
>  [6,]6   16   26   36   46   56   66   76   8696
>  [7,]7   17   27   37   47   57   67   77   8797
>  [8,]8   18   28   38   48   58   68   78   8898
>  [9,]9   19   29   39   49   59   69   79   8999
> [10,]   10   20   30   40   50   60   70   80   90   100
>> rmean
>  [,1] [,2] [,3] [,4] [,5]
> [1,]  6.5 26.5 46.5 66.5 86.5
> [2,]  8.5 28.5 48.5 68.5 88.5
> [3,] 10.5 30.5 50.5 70.5 90.5
> [4,] 12.5 32.5 52.5 72.5 92.5
> [5,] 14.5 34.5 54.5 74.5 94.5
>>
>
>
>
> On 7/27/06, Vladimir Eremeev <[EMAIL PROTECTED]> wrote:
>>
>> Dear r-help,
>>
>> I have a matrix, suppose, 10x10, and I need the matrix 5x5, having
>> in each cell a mean value of the cells from the initial matrix.
>>
>> Please, point me to a function in R, which can help me doing that.
>>
>> Digging the documentation and mail archives didn't give me a result.
>>
>> Thank you.
>>
>> ---
>> Best regards,
>> Vladimirmailto:[EMAIL PROTECTED]
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --  
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem you are trying to solve?
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Stirling numbers

2006-07-19 Thread Robin Hankin
Hi

anyone coded up Stirling numbers in R?

[I need unsigned Stirling numbers of the first kind]


cheers

Robin




--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

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


Re: [R] par(mfrow,mai) and multiple plot problem

2006-07-10 Thread Robin Hankin
[apologies for possible multiple posting]

Hi Joris

great suggestion!  I never thought to use layout() in this way.


If I have

postscript(file="~/f.ps",width=5,height=8)

nf <- layout(matrix(
 c(00,01,00,02,00,03,
   04,05,00,06,00,07,
   00,00,00,00,00,00,
   08,09,00,10,00,11,
   00,00,00,00,00,00,
   12,13,00,14,00,15,
   00,00,00,00,00,00,
   16,17,00,18,00,19),8,6,byrow=TRUE), c(1,4,  
1,4, 1,4), c(1,4,1,4,1,4,1,4), TRUE)

layout.show(nf)
dev.off()

This is exactly what I want.

I hadn't appreciated that the empty rows and columns would be clear.

How best to put text in boxes 1,2,3 (that used to be main() and  
vertical text in
boxes 4,8,12,16 (that used to be ylab)?

best wishes

Robin



On 10 Jul 2006, at 10:27, Joris De Wolf wrote:

> Check
> ?layout
>
> It gives you more flexibility than
> par(mfrow=c(a,b))
>
> For instance, you can define your margins between the graphs as  
> cells in the layout without filling them by a plot.
>
> Joris
>
>
> Robin Hankin wrote:
>> Hi
>> I'm having difficulty with a multiple plot.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] par(mfrow,mai) and multiple plot problem

2006-07-10 Thread Robin Hankin
Hi

I'm having difficulty with a multiple plot.  What I want is 12
plots, all of which are the same size and shape, differing
only in colour.  Each one is a square, so there is an asp=1
in the plot call.  I'm working in an Sweave environment so I
am free to choose the height and width of the plot.

I want the columns to be labelled at  the head (here t=1,2,3)
and the rows to be labelled at the left hand side (here an animal),

I don't want axes.

I want the plots to occupy the majority of the area of the output
postscript.

I want the vertical distance between the plots to be the
same as the horizontal distance between the plots (not critical
but would be nice).

Can anyone help me with these requirements?

My best attempt is below, but it is no good because the
ylab argument that I'm trying to use for the row labelling
gets clipped.  Also, I can't get my horizontal spacing
to be equal to my vertical spacing (although the code
below isn't _too_ bad).





f <- function(...){
   jj <- expand.grid(1:10,1:10)
   colnames(jj) <- c("","")
   par(mai=rep(0,4)+0.2)
   plot(jj,pch=16,asp=1, axes=FALSE, ...)
}


postscript(file="~/f.ps",width=5,height=7)
par(mfrow=c(4,3))
f(main="t=1",ylab="fish")
f(main="t=2")
f(main="t=3")

f(ylab="dog")
f()
f()

f(ylab="slug")
f()
f()

f(ylab="pig")
f()
f()

dev.off()


--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] combining tables

2006-06-19 Thread Robin Hankin
Hi

Suppose I have two tables of counts of different animals and I
wish to pool them so the total of the sum is the sum of the total.

Toy example follows (the real ones are ~10^3 species and ~10^6  
individuals).
x and y are zoos that have merged and I need a combined inventory
including animals that are temporarily absent.


 > (x <- as.table(c(cats=3,squid=7,pigs=2,dogs=1,slugs=0)))
cats squid  pigs  dogs slugs
 3 7 2 1 0
 > (y <- as.table(c(cats=4,dogs=5,slugs=3,crabs=0)))
cats  dogs slugs crabs
 4 5 3 0
 > (desired.output <- as.table(c 
(cats=7,squid=7,pigs=2,dogs=6,slugs=3,crabs=0)))
cats squid  pigs  dogs slugs crabs
 7 7 2 6 3 0
 >




Note that we have 7 cats altogether, and the crabs correctly show
as zero counts.


How to do this nicely in R?




--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] [R-pkgs] new package on CRAN

2006-05-30 Thread Robin Hankin
Dear List

Please find uploaded to CRAN a new package, "partitions" that
enumerates integer partitions using C.  A paper describing the
package has recently been accepted by JSS (volume 16, codesnippet 1).

Integer partitions arise in many branches of combinatorics,
and the partition function P(n) is the subject of much investigation
in pure mathematics.

The package enumerates the partitions, unequal partitions, and  
restricted
partitions of an integer; the corresponding partition functions are  
also given.
The package can conjugate partitions and calculate the Durfee square
of a partition.

I would be very interested to hear any comments or suggestions that the
List may have.





--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

___
R-packages mailing list
[EMAIL PROTECTED]
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] package installation problem

2006-05-23 Thread Robin Hankin
Hello everyone.


After some very welcome offline advice, I now have the mvtnorm
package working on R-2.3.0; here is my solution for
MacOSX.

There were two problems: first, make could not find gcc-4.0.
To solve this, add the relevant directory to PATH.  For me, this is

PATH=$PATH:/usr/local/gcc4.0/bin/

Now the second problem is that the file for -lgfortran can't be found.
To solve this, add

FLIBS=-L/usr/local/gcc4.0/lib

to the Makevars file.



best wishes


rksh

On 23 May 2006, at 08:25, Robin Hankin wrote:

> (this after asking the package author)
>
> Hi
>
> I cannot install the rmvnorm package under R-2.3.0, or R-2.3.1 beta.
> It installs fine under R-2.2.1.
>
> transcript for installation under R-2.3.0 follows.
>
>
> Robin-Hankins-Computer:~/scratch% R --version
> R version 2.3.0 (2006-04-24)
> Copyright (C) 2006 R Development Core Team
>
> R is free software and comes with ABSOLUTELY NO WARRANTY.
> You are welcome to redistribute it under the terms of the
> GNU General Public License.  For more information about
> these matters, see http://www.gnu.org/copyleft/gpl.html.
>
> Robin-Hankins-Computer:~/scratch% sudo R CMD INSTALL
> mvtnorm_0.7-2.tar.gz
> * Installing *source* package 'mvtnorm' ...
> ** libs
> gfortran   -fPIC -fno-common  -g -O2 -c mvt.f -o mvt.o
> gcc -no-cpp-precomp -I/Library/Frameworks/R.framework/Resources/
> include -I/Library/Frameworks/R.framework/Resources/include  -I/sw/
> include -I/usr/local/include   -fPIC -fno-common  -Wall -pedantic -O2
> -std=gnu99 -c randomF77.c -o randomF77.o
> gcc -flat_namespace -bundle -undefined suppress -L/sw/lib -L/usr/
> local/lib -o mvtnorm.so mvt.o randomF77.o  -L/usr/local/gfortran/lib/
> gcc/powerpc-apple-darwin8.2.0/4.1.0 -L/usr/local/gfortran/lib -
> lgfortran -lgcc_s -lSystemStubs -lSystem -F/Library/Frameworks/
> R.framework/.. -framework R
> ** arch - i386
> gfortran-4.0 -arch i386   -fPIC -fno-common  -g -O2 -march=pentium-m -
> mtune=prescott -c mvt.f -o mvt.o
> make: gfortran-4.0: Command not found
> make: *** [mvt.o] Error 127
> chmod: /Library/Frameworks/R.framework/Versions/2.3/Resources/library/
> mvtnorm/libs/i386/*: No such file or directory
> ** arch - ppc
> gfortran-4.0 -arch ppc   -fPIC -fno-common  -g -O2 -c mvt.f -o mvt.o
> make: gfortran-4.0: Command not found
> make: *** [mvt.o] Error 127
> chmod: /Library/Frameworks/R.framework/Versions/2.3/Resources/library/
> mvtnorm/libs/ppc/*: No such file or directory
> ERROR: compilation failed for package 'mvtnorm'
> ** Removing '/Library/Frameworks/R.framework/Versions/2.3/Resources/
> library/mvtnorm'
> ** Restoring previous '/Library/Frameworks/R.framework/Versions/2.3/
> Resources/library/mvtnorm'
> Robin-Hankins-Computer:~/scratch%
>
>
>
>
> anyone?
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton
> European Way, Southampton SO14 3ZH, UK
>   tel  023-8059-7743
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting- 
> guide.html

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] package installation problem

2006-05-23 Thread Robin Hankin
(this after asking the package author)

Hi

I cannot install the rmvnorm package under R-2.3.0, or R-2.3.1 beta.
It installs fine under R-2.2.1.

transcript for installation under R-2.3.0 follows.


Robin-Hankins-Computer:~/scratch% R --version
R version 2.3.0 (2006-04-24)
Copyright (C) 2006 R Development Core Team

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License.  For more information about
these matters, see http://www.gnu.org/copyleft/gpl.html.

Robin-Hankins-Computer:~/scratch% sudo R CMD INSTALL  
mvtnorm_0.7-2.tar.gz
* Installing *source* package 'mvtnorm' ...
** libs
gfortran   -fPIC -fno-common  -g -O2 -c mvt.f -o mvt.o
gcc -no-cpp-precomp -I/Library/Frameworks/R.framework/Resources/ 
include -I/Library/Frameworks/R.framework/Resources/include  -I/sw/ 
include -I/usr/local/include   -fPIC -fno-common  -Wall -pedantic -O2  
-std=gnu99 -c randomF77.c -o randomF77.o
gcc -flat_namespace -bundle -undefined suppress -L/sw/lib -L/usr/ 
local/lib -o mvtnorm.so mvt.o randomF77.o  -L/usr/local/gfortran/lib/ 
gcc/powerpc-apple-darwin8.2.0/4.1.0 -L/usr/local/gfortran/lib - 
lgfortran -lgcc_s -lSystemStubs -lSystem -F/Library/Frameworks/ 
R.framework/.. -framework R
** arch - i386
gfortran-4.0 -arch i386   -fPIC -fno-common  -g -O2 -march=pentium-m - 
mtune=prescott -c mvt.f -o mvt.o
make: gfortran-4.0: Command not found
make: *** [mvt.o] Error 127
chmod: /Library/Frameworks/R.framework/Versions/2.3/Resources/library/ 
mvtnorm/libs/i386/*: No such file or directory
** arch - ppc
gfortran-4.0 -arch ppc   -fPIC -fno-common  -g -O2 -c mvt.f -o mvt.o
make: gfortran-4.0: Command not found
make: *** [mvt.o] Error 127
chmod: /Library/Frameworks/R.framework/Versions/2.3/Resources/library/ 
mvtnorm/libs/ppc/*: No such file or directory
ERROR: compilation failed for package 'mvtnorm'
** Removing '/Library/Frameworks/R.framework/Versions/2.3/Resources/ 
library/mvtnorm'
** Restoring previous '/Library/Frameworks/R.framework/Versions/2.3/ 
Resources/library/mvtnorm'
Robin-Hankins-Computer:~/scratch%




anyone?

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Matrix in 3D

2006-05-22 Thread Robin Hankin
Hi

there are dozens of examples of this kind of thing
in the R-and-octave.txt file,  in the contributed docs section
of CRAN.  See the "multidimensional arrays" section, near the
bottom, for reproduction of all of matlab/octave's array
handling capabilities.

best wishes


Robin



On 22 May 2006, at 09:56, Uwe Ligges wrote:

> [EMAIL PROTECTED] wrote:
>
>> Dear R Users,
>> Is it possible to add another (third) index to matrix (as in  
>> MATLAB). For some analysis e.g. finite mixture models is  
>> necessary. Simple example
>>
>> i<-3
>> matrix[, , i]<-matrixA[, ,i]%*%matrixB[, , i]
>
>
> See ?array
>
> Uwe Ligges
>
>
>> I would appreciate any help
>> Rob
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide! http://www.R-project.org/posting- 
>> guide.html
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting- 
> guide.html

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] sparklines

2006-05-17 Thread Robin Hankin
Hi everyone

well, quite a few people were interested in my little sparklines  
example,
and one suggestion was to post it on a webpage.

What would be a good place to post it?


[at this point, I'm becoming a little self conscious: the example was
written for my amusement and
probably could use some improvements]





On 16 May 2006, at 23:56, Robert M. Ullrey wrote:

> I am fairly new to R so I don;t know much about manipulating it yet.
> I would like to make some sparklines <http://www.edwardtufte.com/
> bboard/q-and-a-fetch-msg?msg_id=0001OR&topic_id=1> using R. I have th
> pre-compiled R for MacOS on intel. Any help would be greatly
> appreciated.
>
> Thanks
> Robert
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting- 
> guide.html

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] sparklines

2006-05-17 Thread Robin Hankin
Hi

Sweave can be used to produce some very nice sparkline-type
plots very easily.  I'll send you some examples offline.

best wishes


Robin




On 16 May 2006, at 23:56, Robert M. Ullrey wrote:

> I am fairly new to R so I don;t know much about manipulating it yet.
> I would like to make some sparklines <http://www.edwardtufte.com/
> bboard/q-and-a-fetch-msg?msg_id=0001OR&topic_id=1> using R. I have th
> pre-compiled R for MacOS on intel. Any help would be greatly
> appreciated.
>
> Thanks
> Robert
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting- 
> guide.html

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Legendre symbols

2006-05-02 Thread Robin Hankin
Hi

before I reinvent the wheel, has anyone coded up the Legendre symbol  
(a/p)?

[
If p is an odd prime number and a is an integer, then the Legendre  
symbol
(a/p)   is:

 * 0 if p divides a;
 * 1 if a is a square modulo p — that is to say there exists an  
integer k such that k^2 ≡ a (mod p)
 * −1 if not

[courtesy Wikipedia]

]

I might also need Jacobi's generalization of this.




--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Re: [R] summary(lm(x~y)) difference between R-2.2.1 and R-2.3.0

2006-04-27 Thread Robin Hankin
Hi Roger

good point.  I can reproduce the error much more simply:



 > x <- 1:10
 > y <- 10:1
 > summary(lm(x~y))

Call:
lm(formula = x ~ y)

Residuals:

*** caught bus error ***
address 0x18, cause 'invalid alignment'

Traceback:
1: sort(x, partial = unique(c(lo, hi)))
2: quantile.default(resid)
3: quantile(resid)
4: structure(quantile(resid), names = nam)
5: print.summary.lm(list(call = lm(formula = x ~
[snip]

On 27 Apr 2006, at 15:44, roger bos wrote:

> I don't know if this is causing the error, by in your traceback I  
> saw sort()
> was used and sort now removes all the attributes when it sorts.  I  
> used to
> use sort() to sort dates in character format and now it turns them  
> into
> integers and is breaking all my code.  The problem with upgrading  
> is your
> never know what the end result will be on your code.  Check and see  
> if your
> data needs the attributes to remain in order to function properly.
>
>
>
> On 4/27/06, Robin Hankin <[EMAIL PROTECTED]> wrote:
>>
>> Hi
>>

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] summary(lm(x~y)) difference between R-2.2.1 and R-2.3.0

2006-04-27 Thread Robin Hankin
Hi

[macOSX 10.4.6; R-2.3.0]

I have encountered a difference in behaviour between R-2.2.1 and  
R-2.3.0 when
performing a linear model.  Transcript follows for R-2.3.0 (R-2.2.1  
worked as
expected).   How to make R-2.3.0 perform as R-2.2.1 did?



 > dput(x)
c(29.13, 29.88, 30.09, 29.99, 29.74, 29.64, 29.65, 29.7, 30.04,
29.89, 29.96, 29.65, 28.76, 28.41, 28.38, 29.55, 29.76, 29.75,
29.84, 29.85, 29.75, 29.99, 29.32, 29.38, 28.97, 28.48, 29.06,
28.74, 29.23, 29.16, 29.19, 29.23, 29.17, 29.25, 29.24, 29.22,
29.15, 29.15, 28.78, 29.28, 29.31, 29.44, 29.28, 29.47, 29.28,
29.32, 29.39, 29.27, 28.68, 28.73, 28.09, 28.19, 29.1, 29.1,
29.14, 29.48, 29.48, 29.39, 29.39, 29.22, 28.95, 29.11, 27.94,
28.32, 27.98, 28.22, 28.89, 29.4, 29.28, 29.66, 30.05, 30.12,
30.09, 29.85, 29.99, 29.92, 28.44, 28.92, 28.92, 28.94, 28.97,
28.95, 29.39, 29.26, 29.7, 29.48, 29.72, 29.71, 29.84, 29.59,
29.17, 29.39, 29.27, 29.39, 28.53, 29.32, 29.32, 28.44, 29.39,
28.55, 29.39, 29.46, 29.73, 30.01, 30.11, 30.25, 30.37, 30.22,
30.33, 30.35, 30.38, 30.25, 29.27, 27.34)
 > dput(y)
c(36, 72.43, 37.57, 72.78, 55.88, 38.41, 79.79, 32, 56.92, 69.72,
63.53, 50.94, 82.82, 50.77, 41.05, 75.62, 64, 63.04, 35.83, 91.71,
93.29, 42.16, 65.57, 60.05, 27.38, 83.64, 67.6, 39, 53.21, 54.24,
49.58, 34.29, 81.5, 48.94, 64.84, 32.86, 66.71, 41.67, 42.27,
45.22, 51.23, 64.03, 58, 48.15, 59.8, 72.94, 40.33, 56.82, 32,
75.32, 49.25, 44.38, 27.5, 37, 40.22, 33.63, 43, 49.92, 36, 63.78,
41.74, 58.07, 37.5, 41.27, 54.28, 51.39, 49.92, 93, 33.75, 30.81,
102.31, 67.95, 64.48, 47, 33.56, 42.44, 44.25, 63.93, 38.92,
74.47, 58.46, 35.25, 94.45, 40.71, 38.35, 78.26, 65.1, 89.54,
43.34, 34.71, 37.83, 62.45, 31.43, 38.14, 50, 75.77, 88.14, 60.14,
42.02, 36.79, 34.9, 46.33, 47.55, 35.67, 75.41, 28.6, 61.29,
62.43, 59.08, 46.3, 84.56, 43.96, 91.68, 41.67)
 > summary(lm(x~y))

Call:
lm(formula = x ~ y)

Residuals:

*** caught bus error ***
address 0x18, cause 'invalid alignment'

Traceback:
1: sort(x, partial = unique(c(lo, hi)))
2: quantile.default(resid)
3: quantile(resid)
4: structure(quantile(resid), names = nam)
5: print.summary.lm(list(call = lm(formula = x ~ y), terms = x ~  
y, residuals = c(-0.0990169973225879, 0.442597843688031,  
0.852002363105233, 0.550595790280227, 0.397266369114154,  
0.397197434926506, 0.170497520598225, 0.493863613052272,  
0.691317410416682, 0.468099457217023, 0.573507201772172,  
0.335523922927148, -0.736834541760754, -0.903503651131917,  
-0.877903767920926, 0.0943505569140546, 0.370818730053123,  
0.366310076543096, 0.6119
[snip]




--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


  1   2   3   4   >