Re: [R] selecting rows for inclusion in lm

2007-01-18 Thread David Barron
Why not use the subset option?  Something like:

lm(diff ~ Age + Race, data=data, subset=data$Meno=="PRE")

should do the trick, and be much easier to read!

On 18/01/07, John Sorkin <[EMAIL PROTECTED]> wrote:
> I am having trouble selecting rows of a dataframe that will be included
> in a regression. I am trying to select those rows for which the variable
> Meno equals PRE. I have used the code below:
>
> difffitPre<-lm(data[,"diff"]~data[,"Age"]+data[,"Race"],data=data[data[,"Meno"]=="PRE",])
> summary(difffitPre)
>
> The output from the summary indicates that more than 76 rows are
> included in the regression:
>
> Residual standard error: 2.828 on 76 degrees of freedom
>
> where in fact only 22 rows should be included as can be seen from the
> following:
>
> print(data[length(data[,"Meno"]=="PRE","Meno"]))
> [1] 22
>
> I would appreciate any help in modifying the data= parameter of the lm
> so that I include only those subjects for which Meno=PRE.
>
> R 2.3.1
> Windows XP
>
> Thanks,
> John
>
> John Sorkin M.D., Ph.D.
> Chief, Biostatistics and Informatics
> Baltimore VA Medical Center GRECC,
> University of Maryland School of Medicine Claude D. Pepper OAIC,
> University of Maryland Clinical Nutrition Research Unit, and
> Baltimore VA Center Stroke of Excellence
>
> University of Maryland School of Medicine
> Division of Gerontology
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
>
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
> [EMAIL PROTECTED]
>
> Confidentiality Statement:
> This email message, including any attachments, is for the so...{{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.
>


-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

__
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] 3D Plot

2007-01-18 Thread Vladimir Eremeev
>

About 3D plots: 
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/6439.html

Many other plot examples:
http://addictedtor.free.fr/graphiques/allgraph.php

I used rgl, it can produce interactive plots, which can be rotated, increased 
and decreased with the mouse.
 
> Hi all R users,
> 
> I want to draw a 3D plot, where the Z-axis will represent the normal
> densities each with zero mean but different volatilities, Y-axis will
> represent the SD [volatilities), and X-axis will represent time at which
> these SD are calculated.
> 
> Can anyone give me any clue? Your help will be highly appreciated.
> 
> Thanks and regards,
> Arun
> 
>   [[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.


[R] about rgl package.

2007-01-18 Thread Vladimir Eremeev
The statement that it is for windows only in the first link in my previous post 
seems to me obsolete now.
Unfortunately, I don't remember exactly, probably, I have used it in Linux.

__
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] selecting rows for inclusion in lm

2007-01-18 Thread Vladimir Eremeev
> Why not use the subset option?  Something like:
> 
> lm(diff ~ Age + Race, data=data, subset=data$Meno=="PRE")

> should do the trick, and be much easier to read!

"data$" could be omitted, simply 
lm(diff ~ Age + Race, data=data, subset=Meno=="PRE")

__
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 Prof Brian Ripley
On Wed, 17 Jan 2007, Patrick Burns wrote:

> A logical reason for the phenomenon is that
> matrices are stored down their columns. For
> example:
>
> > matrix(1:15,5)
> [,1] [,2] [,3]
> [1,]16   11
> [2,]27   12
> [3,]38   13
> [4,]49   14
> [5,]5   10   15
>
> When an 'apply' across rows is done, it will be
> the values corresponding to each of the rows that
> are together.
>
> For matrices, merely transposing the result fixes
> the "problem", but it is considerably more complex
> in higher dimensional arrays.

[I don't think so, using aperm.]

> There could be a spectrum of opinion from:
>
> the original programmer was lazy and didn't adequately
> serve users
>
> to:
>
> the simpler the program the fewer bugs there will be.

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.

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.


Re: [R] how to get the index of entry with max value in an array?

2007-01-18 Thread Feng Qiu
Thank you guys! I got it.

Best,

Feng

- Original Message - 
From: "Benilton Carvalho" <[EMAIL PROTECTED]>
To: "Feng Qiu" <[EMAIL PROTECTED]>
Cc: 
Sent: Thursday, January 18, 2007 12:20 AM
Subject: Re: [R] how to get the index of entry with max value in an array?


> which.max()
> b
> 
> On Jan 17, 2007, at 11:20 PM, Feng Qiu wrote:
> 
>> Hi all:
>>  A short question:
>>  For example,  a=[3,4,6,2,3], obviously the 3rd entry of  
>> the array has the maxium value, what I want is index of the maxium  
>> value: 3. is there a neat expression to get this index?
>>
>> Thank you!
>>
>> Best,
>>
>> Feng

__
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] label option in 'barplot'?

2007-01-18 Thread Justin Gengler
Hello all,

When using the 'barplot' function, how would one go about creating 
labels on the top of the bars corresponding to the actual frequency 
values (i.e., the height of the bar).  For histograms, one can use 
the 'LABEL=T' parameter to this effect, but it is not available for 
barplot.  Must one manually create such labels for a barplot (perhaps 
using mtext)?

Thanks.

Justin Gengler

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


Re: [R] label option in 'barplot'?

2007-01-18 Thread Gabor Grothendieck
Try this where you probably only want one of the last two lines:


# population of 5 US states
pop <- state.x77[1:5,1]
bp <- barplot(pop, ylim = range(pop) * c(0, 1.1))
text(bp, pop, pop, adj = c(0.5, -0.5))  # place num above bar
mtext(1, at = bp, text = pop, line = 3)  # place num below label


On 1/17/07, Justin Gengler <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> When using the 'barplot' function, how would one go about creating
> labels on the top of the bars corresponding to the actual frequency
> values (i.e., the height of the bar).  For histograms, one can use
> the 'LABEL=T' parameter to this effect, but it is not available for
> barplot.  Must one manually create such labels for a barplot (perhaps
> using mtext)?
>
> Thanks.
>
> Justin Gengler
>
> __
> 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.


Re: [R] label option in 'barplot'?

2007-01-18 Thread talepanda
Probably, you have to manually create, but it is easy:

# for beside=F
mp <- barplot(VADeaths)
text(mp,y<-t(apply(VADeaths,2,cumsum)),y) # labels are values itself
# or
mp <- barplot(VADeaths)
text(mp,t(apply(VADeaths,2,cumsum)),VADeaths) # labels are cumsum of values

# for besides=T
mp <- barplot(VADeaths,beside=T)
text(mp,VADeaths,VADeaths)

## maybe some adjustment is required for y position, then, for example,

mp <- barplot(VADeaths,beside=T)
text(mp,VADeaths+3,VADeaths)

HTH

On 1/18/07, Justin Gengler <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> When using the 'barplot' function, how would one go about creating
> labels on the top of the bars corresponding to the actual frequency
> values (i.e., the height of the bar).  For histograms, one can use
> the 'LABEL=T' parameter to this effect, but it is not available for
> barplot.  Must one manually create such labels for a barplot (perhaps
> using mtext)?
>
> Thanks.
>
> Justin Gengler
>
> __
> 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.


Re: [R] label option in 'barplot'?

2007-01-18 Thread Chuck Cleland
Justin Gengler wrote:
> Hello all,
> 
> When using the 'barplot' function, how would one go about creating 
> labels on the top of the bars corresponding to the actual frequency 
> values (i.e., the height of the bar).  For histograms, one can use 
> the 'LABEL=T' parameter to this effect, but it is not available for 
> barplot.  Must one manually create such labels for a barplot (perhaps 
> using mtext)?

  Yes, I believe you would need to add those labels yourself.  Use
text() rather than mtext() to get something similar to what hist() does
when labels=TRUE.  Here is how you could put the labels either just
below or just above the top of the bar:

# Below
X <- barplot(VADeaths, beside=TRUE, ylim=c(0,80))
text(X, VADeaths, labels=VADeaths, pos=1, offset=.5, col="red")

# Above
X <- barplot(VADeaths, beside=TRUE, ylim=c(0,80))
text(X, VADeaths, labels=VADeaths, pos=3, offset=.5)

> Thanks.
> 
> Justin Gengler
> 
> __
> 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.

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

__
R-help@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] How to formulate an analytical gradient?

2007-01-18 Thread francogrex

How to formulate an analytical gradient?

Suppose I have the following function/expression:

fr<-function(x){
x1=x[1]
x2=x[2]
x3=x[3]
x4=x[4]
x5=x[5]
z<-((gamma(x1+n)))/((gamma(x1)*factorial(n))*((1+(e/x2))^x1)*((1+(x2/e))^n))
v<-((gamma(x3+n)))/((gamma(x3)*factorial(n))*((1+(e/x4))^x3)*((1+(x4/e))^n))

sum(log( (x5*z)+ ((1-x5)*v) ))
}

These are a mix of two negative binomial distributions, where n and e are
know vectors, and I would like to calculate the maxiumum likelihood
estimates of the parameters x1,x2,x3,x4 and X5
I am relying on numerical gradients but I think if I use an analytical one
it will be more accurate especially when number of parameters is more than
4.

Thanks.
-- 
View this message in context: 
http://www.nabble.com/How-to-formulate-an-analytical-gradient--tf3033293.html#a8428063
Sent from the R help mailing list archive at Nabble.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.


Re: [R] selecting rows for inclusion in lm

2007-01-18 Thread Michael Dewey
At 08:19 18/01/2007, David Barron wrote:
>Why not use the subset option?  Something like:
>
>lm(diff ~ Age + Race, data=data, subset=data$Meno=="PRE")
>
>should do the trick, and be much easier to read!

And indeed the advice in
 > library(fortunes)
 > fortune("dog")

Firstly, don't call your matrix 'matrix'. Would you call your dog 'dog'?
Anyway, it might clash with the function 'matrix'.
-- Barry Rowlingson
   R-help (October 2004)

 >
also helps to make life clearer I find


>On 18/01/07, John Sorkin <[EMAIL PROTECTED]> wrote:
>>I am having trouble selecting rows of a dataframe that will be included
>>in a regression. I am trying to select those rows for which the variable
>>Meno equals PRE. I have used the code below:
>>
>>difffitPre<-lm(data[,"diff"]~data[,"Age"]+data[,"Race"],data=data[data[,"Meno"]=="PRE",])
>>summary(difffitPre)
>>
>>The output from the summary indicates that more than 76 rows are
>>included in the regression:
>>
>>Residual standard error: 2.828 on 76 degrees of freedom
>>
>>where in fact only 22 rows should be included as can be seen from the
>>following:
>>
>>print(data[length(data[,"Meno"]=="PRE","Meno"]))
>>[1] 22
>>
>>I would appreciate any help in modifying the data= parameter of the lm
>>so that I include only those subjects for which Meno=PRE.
>>
>>R 2.3.1
>>Windows XP
>>
>>Thanks,
>>John
>>
>>John Sorkin M.D., Ph.D.
>>Chief, Biostatistics and Informatics
>>Baltimore VA Medical Center GRECC,
>>University of Maryland School of Medicine Claude D. Pepper OAIC,
>>University of Maryland Clinical Nutrition Research Unit, and
>>Baltimore VA Center Stroke of Excellence
>>
>>University of Maryland School of Medicine
>>Division of Gerontology
>>Baltimore VA Medical Center
>>10 North Greene Street
>>GRECC (BT/18/GR)
>>Baltimore, MD 21201-1524
>>
>>(Phone) 410-605-7119
>>(Fax) 410-605-7913 (Please call phone number above prior to faxing)
>>[EMAIL PROTECTED]
>>
>>Confidentiality Statement:
>>This email message, including any attachments, is for the so...{{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.
>
>
>--
>=
>David Barron
>Said Business School
>University of Oxford
>Park End Street
>Oxford OX1 1HP
>
>

Michael Dewey
http://www.aghmed.fsnet.co.uk

__
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] Fast Removing Duplicates from Every Column

2007-01-18 Thread Bert Jacobs
Thx Jim. The Code works perfect when I run it in a plain way.

It gives a dataframe with 160 columns (like it should) 

 

But when I run the code in a function it gives a dataframe with 161 columns
and the order of the columns has changed into an alfabethical order. Do you
know why this occurs?

 

 

Selection = function ()

{

TestUnique <- apply(Selection,2,unique)

MaxLen <- max(sapply(TestUnique,length))

TestUnique <- lapply(TestUnique,function(x)

{

c(x,rep('0',MaxLen-length(x)))

})

Selection.Unique <<- data.frame(TestUnique)

}

 

  _  

From: jim holtman [mailto:[EMAIL PROTECTED] 
Sent: 18 January 2007 02:28
To: Bert Jacobs
Cc: Petr Pikal; R help list
Subject: Re: [R] Fast Removing Duplicates from Every Column

 

Here is one way of doing it by 'padding' all the elements to the same
length:

 

>  x <- "Col1 Col2 Col3  Col159 Col160
+  Row1  0 0 LD  0   VD
+  Row2  HD0 0  0   MD
+  Row3  0 HDHD 0   LD
+  Row4  LDHDHD 0   0 
+  LastRowHDHDLD 0   MD"
>  input <- read.table(textConnection(x), header=TRUE)
> Uniq <- apply(input, 2, unique)
> # find maximum length of an element
> maxLen <- max(sapply(Uniq, length)) 
> # pad with '0' all element to maxLen
> Uniq <- lapply(Uniq, function(x){
+ c(x, rep('0', maxLen - length(x)))
+ })
> as.data.frame(Uniq)
  Col1 Col2 Col3 Col159 Col160
100   LD  0 VD
2   HD   HD0  0 MD
3   LD0   HD  0 LD
4000  0  0


 

On 1/17/07, Bert Jacobs <[EMAIL PROTECTED]> wrote: 

Hi,



Working further on this dataframe : my_data



 Col1 Col2 Col3 ... Col 159 Col 160 

Row 1  0 0 LD ... 0   VD

Row 2  HD0 0  0   MD

Row 3  0 HDHD 0   LD

Row 4  LDHDHD 0   0

......

LastRowHDHDLD 0   MD



Running this line of code:

Test = apply(X=my_data, MARGIN=2, FUN=unique)



I get this list:



$Col1

[1] "0" "HD" "LD" 

$Col2

[1] "0" "HD"

$Col3

[1] "LD" "0" "HD"

...

$Col159

[1] "0"

$Col160

[1] "VD" "MD" "LD" "0" 



Now I was wondering how I can get this list into a data.frame:

because a simple data.frame doesn't work (error: arguments imply differing
number of rows)



Can someone help me out on this. Thx 



So that I get the following result:

  Col1 Col2 Col3 ... Col 159 Col 160

Row 1   0   0LD   0VD

Row 2 HD   HD   00MD

Row 3 LD   0HD   0LD 

Row 4  00000









-Original Message-
From: Petr Pikal [mailto:[EMAIL PROTECTED]
Sent: 05 January 2007 11:51 
To: Bert Jacobs; 'R help list'
Subject: Re: [R] Fast Removing Duplicates from Every Column



Hi



I am not sure if I understand how do you want to select unique items.



with

sapply(DF, function(x) !duplicated(x))

you can get data frame with TRUE when an item in particular column is

unique and FALSE in opposite. However then you need to choose which

rows to keep or discard 



e.g.



DF[rowSums(sapply(comp, function(x) !duplicated(x)))>1,]



selects all rows in which are 2 or more unique values.



HTH

Petr





On 5 Jan 2007 at 9:54, Bert Jacobs wrote: 



From: "Bert Jacobs" <[EMAIL PROTECTED]>

To:   "'R help list'" < 
r-help@stat.math.ethz.ch>

Date sent:Fri, 5 Jan 2007 09:54:17 +0100

Subject:  Re: [R] Fast Removing Duplicates from Every Column



> Hi,

>

> I'm looking for some lines of code that does the following: 

> I have a dataframe with 160 Columns and a number of rows (max 30):

>

>  Col1 Col2 Col3 ... Col 159 Col 160

> Row 1 0 0 LD ... 0   VD

> Row 2 HD0 0  0   MD 

> Row 3 0 HDHD 0   LD

> Row 4 LDHDHD 0   0

> ...   ...

> LastRow   HDHDLD 0   MD

>

>

> Now I want a dataframe that looks like this. As you see all duplicates 

> are removed. Can this dataframe be constructed in a fast way?

>

>   Col1 Col2 Col3 ... Col 159 Col 160

> Row 1   00LD   0  VD

> Row 2   HD   HD   00MD 

> Row 3   LD   0HD   0LD

>

> Thx for helping me out.

> Bert

>

> __

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



Petr Pikal

[EMAIL PROTECTED]   




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

[R] arima function

2007-01-18 Thread yannig goude
I want to modify the arima function. Can anyone can tell me what are the 
objects: R_ARIMA_transPars,R_ARIMA_Like, R_ARIMA_Invtrans, R_ARIMA_undoPars...?
  Thanks.
  best regards.
  YG
   


-

[[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] eval while keeping NA-s

2007-01-18 Thread Ott Toomet
Dear R-people,

I would like to construct a model frame while keeping eventual NA-s in
it.  The code looks like in lm():

   m <- match(c("formula", "data", "subset", "weights", "na.action",
"offset"), names(mf), 0)
   mfO <- mf[c(1, m)]
   mfO$drop.unused.levels <- TRUE
   mfO[[1]] <- as.name("model.frame")
   names(mfO)[2] <- "formula"
   mfO <- eval(mfO, parent.frame())

The problem is that eval() removes all the observation which include
NA-s.  

Are there ways to get the frames and keep NA-s?  I see, I can play
around with the "na.action" attribute of the resulting frame, but how
can I set the na.action?

Thanks in advance,
Ott

__
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] Memory leak with character arrays?

2007-01-18 Thread Jean lobry
Dear Peter,

>The file that I'm reading contains the upstream regions of the yeast
>genome, with each upstream region labeled using a FASTA header, i.e.:
>
> FASTA header for gene 1
> upstream region.
> .
> 
> FASTA header for gene 2
> upstream
> 

you may want to have a look at the read.fasta() function in the
seqinr package. There is an example page 16 of this document:
http://pbil.univ-lyon1.fr/software/SeqinR/seqinr_1_0-6.pdf
about importing the content of a fasta file with 21,161 sequences
from Arabidopsis thaliana into an object which is about 15 Mb in RAM.

HTH,

-- 
Jean R. Lobry([EMAIL PROTECTED])
Laboratoire BBE-CNRS-UMR-5558, Univ. C. Bernard - LYON I,
43 Bd 11/11/1918, F-69622 VILLEURBANNE CEDEX, FRANCE
allo  : +33 472 43 27 56 fax: +33 472 43 13 88
http://pbil.univ-lyon1.fr/members/lobry/

__
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 regexpr in gsub

2007-01-18 Thread Marc Schwartz
On Thu, 2007-01-18 at 04:49 +, Prof Brian Ripley wrote:
> One thing to watch with experiments like this is that the locale will 
> matter.  Character operations will be faster in a single-byte locale (as 
> used here) than in a variable-byte locale (and I suspect Seth and Marc 
> used UTF-8), and the relative speeds may alter.  Also, the PCRE regexps 
> are often much faster, and 'useBytes' can be much faster with ASCII data 
> in UTF-8.
> 
> For example:
> 
> # R-devel, x86_64 Linux
> library(GO)
> goids <- ls(GOTERM)
> gids <- paste(goids, "ISS", sep=".")
> go.ids <- rep(gids, 10)
> > length(go.ids)
> [1] 205950
> 
> # In en_GB (single byte)
> 
> > system.time(z <- gsub("[.].*", "", go.ids))
> user  system elapsed
>1.709   0.004   1.716
> > system.time(z <- gsub("[.].*", "", go.ids, perl=TRUE))
> user  system elapsed
>0.241   0.004   0.246
> 
> > system.time(z <- gsub('\\..+$','', go.ids))
> user  system elapsed
>2.254   0.018   2.286
> > system.time(z <- gsub('([^.]+)\\..*','\\1',go.ids))
> user  system elapsed
>2.890   0.002   2.895
> > system.time(z <- sub("([GO:0-9]+)\\..*$", "\\1", go.ids))
> user  system elapsed
>2.716   0.002   2.721
> > system.time(z <- sub("\\..+", "", go.ids))
> user  system elapsed
>1.724   0.001   1.725
> > system.time(z <- substr(go.ids, 0, 10))
> user  system elapsed
>0.084   0.000   0.084
> 
> # in en_GB.utf8
> 
> > system.time(z <- gsub("[.].*", "", go.ids))
> user  system elapsed
>1.689   0.020   1.712
> > system.time(z <- gsub("[.].*", "", go.ids, perl=TRUE))
> user  system elapsed
>0.718   0.017   0.736
> > system.time(z <- gsub("[.].*", "", go.ids, perl=TRUE, useByte=TRUE))
> user  system elapsed
>0.243   0.001   0.244
> 
> > system.time(z <- gsub('\\..+$','', go.ids))
> user  system elapsed
>2.509   0.024   2.537
> > system.time(z <- gsub('([^.]+)\\..*','\\1',go.ids))
> user  system elapsed
>3.772   0.004   3.779
> > system.time(z <- sub("([GO:0-9]+)\\..*$", "\\1", go.ids))
> user  system elapsed
>4.088   0.007   4.099
> > system.time(z <- sub("\\..+", "", go.ids))
> user  system elapsed
>1.920   0.004   1.927
> > system.time(z <- substr(go.ids, 0, 10))
> user  system elapsed
>0.096   0.002   0.098
> 
> substr still wins, but by a much smaller margin.



Just to confirm Prof. Ripley's suspicion, that I am indeed running in
en_US.UTF-8.

Thanks for taking the time to point this out.

Best regards,

Marc

__
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] How to optimize this loop ?

2007-01-18 Thread Nicolas Prune
Dear R Users,

I request your help to optimize a loop.

Given a series of observations, I want to know how many consecutive past
observations are below the last one.

e.g :
my_series <- c(3, 4, 10,14,8,3,4,6,9)

As the last number (9)  is higher than the four preceding numbers (6, 4, 3, 8),
this function should return 4.

my_series <- c(3, 4, 10,14,8,3,4,11,9)
Here, it should return 0, as 9 is immediately preceeded by a higher number.

So far, I do this awful loop :

result <- 0
for (i in 1:length(my_series-1))
{
 if (my_series[length(my_series)-i]>end(my_series)[1])
{ result <- i-1 ; break }
}

I thing there's a better way...

my_series > my_series[end][1] returns :
TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE FALSE
, which seems more appealing (once the last "FALSE" is removed), but now, how to
know the size of the last consecutive series of "TRUE" ?

Can you see a better way ?

Thanks.

__
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] eval while keeping NA-s

2007-01-18 Thread Prof Brian Ripley
On Thu, 18 Jan 2007, Ott Toomet wrote:

> Dear R-people,
>
> I would like to construct a model frame while keeping eventual NA-s in
> it.  The code looks like in lm():
>
>   m <- match(c("formula", "data", "subset", "weights", "na.action",
>"offset"), names(mf), 0)
>   mfO <- mf[c(1, m)]
>   mfO$drop.unused.levels <- TRUE
>   mfO[[1]] <- as.name("model.frame")
>   names(mfO)[2] <- "formula"
>   mfO <- eval(mfO, parent.frame())
>
> The problem is that eval() removes all the observation which include
> NA-s.
>
> Are there ways to get the frames and keep NA-s?  I see, I can play
> around with the "na.action" attribute of the resulting frame, but how
> can I set the na.action?

Set na.action=na.pass on the call, or reset in your code (as that resets 
drop.unused.levels).


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


Re: [R] How to optimize this loop ?

2007-01-18 Thread Petr Pikal
Hi

discard your loop do not optimise it.
rle is your friend

> my_fun<-function(x) {
+ 
+ len<-length(x)
+ x1<-rle(x[len]>x[1:len-1])
+ last<-length(x1$values)
+ ifelse(x1$values[last],x1$lengths[last],0)
+ }
> my_fun(my_series)
[1] 0
> my_series <- c(3, 4, 10,14,8,3,4,6,9)
> my_fun(my_series)
[1] 4
>

and vectorise, vectorise, vectorise.

HTH
Petr




On 18 Jan 2007 at 14:11, Nicolas Prune wrote:

Date sent:  Thu, 18 Jan 2007 14:11:11 +0100
From:   Nicolas Prune <[EMAIL PROTECTED]>
To: r-help@stat.math.ethz.ch
Subject:[R] How to optimize this loop ?

> Dear R Users,
> 
> I request your help to optimize a loop.
> 
> Given a series of observations, I want to know how many consecutive
> past observations are below the last one.
> 
> e.g :
> my_series <- c(3, 4, 10,14,8,3,4,6,9)
> 
> As the last number (9)  is higher than the four preceding numbers (6,
> 4, 3, 8), this function should return 4.
> 
> my_series <- c(3, 4, 10,14,8,3,4,11,9)
> Here, it should return 0, as 9 is immediately preceeded by a higher
> number.
> 
> So far, I do this awful loop :
> 
> result <- 0
> for (i in 1:length(my_series-1))
> {
>  if (my_series[length(my_series)-i]>end(my_series)[1])
> { result <- i-1 ; break }
> }
> 
> I thing there's a better way...
> 
> my_series > my_series[end][1] returns :
> TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE FALSE
> , which seems more appealing (once the last "FALSE" is removed), but
> now, how to know the size of the last consecutive series of "TRUE" ?
> 
> Can you see a better way ?
> 
> Thanks.
> 
> __
> 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.

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


[R] building R on freebsd 6.2 (amd64)

2007-01-18 Thread Hiroyuki Kawakatsu
Hi,

I updated my os to freebsd 6.2 and built R-patched with no changes in
configure. I pass make check and copy the R executable to
/usr/local/bin/R. Then when I start R, I get

/libexec/ld-elf.so.1: Shared object "libRblas.so" not found, required by "R"

and have to copy/link the two shared object files (libRblas.so and
libRlapack.so) to somewhere "visible" like /usr/local/lib/ as well. I
didn't have to do this last step in freebsd 6.1. Is there some
configure setting I can use to avoid having to move the two shared
object files?

h.
-- 
--
Hiroyuki Kawakatsu
Business School
Dublin City University
Dublin 9, Ireland
Tel +353 (0)1 700 7496

__
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 optimize this loop ?

2007-01-18 Thread Chuck Cleland
Nicolas Prune wrote:
> Dear R Users,
> 
> I request your help to optimize a loop.
> 
> Given a series of observations, I want to know how many consecutive past
> observations are below the last one.
> 
> e.g :
> my_series <- c(3, 4, 10,14,8,3,4,6,9)
> 
> As the last number (9)  is higher than the four preceding numbers (6, 4, 3, 
> 8),
> this function should return 4.
> 
> my_series <- c(3, 4, 10,14,8,3,4,11,9)
> Here, it should return 0, as 9 is immediately preceeded by a higher number.
> 
> So far, I do this awful loop :
> 
> result <- 0
> for (i in 1:length(my_series-1))
> {
>  if (my_series[length(my_series)-i]>end(my_series)[1])
> { result <- i-1 ; break }
> }
> 
> I thing there's a better way...

  Just in terms of finding out which values are bigger than the
preceding value and avoiding the explicit loop, you could do something
like this:

seriesA <- c(3,4,10,14,8,3,4,6,9)
seriesB <- c(3,4,10,14,8,3,4,11,9)

sign(diff(seriesA)) == 1
[1]  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE

sign(diff(seriesB)) == 1
[1]  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE FALSE

> my_series > my_series[end][1] returns :
> TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE FALSE
> , which seems more appealing (once the last "FALSE" is removed), but now, how 
> to
> know the size of the last consecutive series of "TRUE" ?
> 
> Can you see a better way ?
> 
> Thanks.
> 
> __
> 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.

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

__
R-help@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 optimize this loop ?

2007-01-18 Thread Martin Becker
Petr Pikal schrieb:
> Hi
>
> discard your loop do not optimise it.
> rle is your friend
>   
I do not agree. For some purposes, an efficient loop is faster. IMHO 
this is one of these purposes.
I propose the following modification of the loop (to increase speed):

myfun1 <- function(series=c(3, 4, 10,14,8,3,4,6,9)) {
  len<-length(series)
  for (i in (len-1):1)
  {
if (series[i]>series[len])
{ result <- i-1 ; break }
  }
  return(result)
}

The speed measurement, in comparison with the rle approach:

 > system.time(for (i in 1:1) erg<-my_fun(c(3, 4, 10,14,8,3,4,6,9)))
[1] 4.48 0.00 4.48   NA   NA

 > system.time(for (i in 1:1) erg<-myfun1(c(3, 4, 10,14,8,3,4,6,9)))
[1] 0.33 0.00 0.33   NA   NA

Regards, Martin
>   
>> my_fun<-function(x) {
>> 
> + 
> + len<-length(x)
> + x1<-rle(x[len]>x[1:len-1])
> + last<-length(x1$values)
> + ifelse(x1$values[last],x1$lengths[last],0)
> + }
>   
>> my_fun(my_series)
>> 
> [1] 0
>   
>> my_series <- c(3, 4, 10,14,8,3,4,6,9)
>> my_fun(my_series)
>> 
> [1] 4
>   
>
> and vectorise, vectorise, vectorise.
>
> HTH
> Petr
>
>
>
>
> On 18 Jan 2007 at 14:11, Nicolas Prune wrote:
>
> Date sent:Thu, 18 Jan 2007 14:11:11 +0100
> From: Nicolas Prune <[EMAIL PROTECTED]>
> To:   r-help@stat.math.ethz.ch
> Subject:  [R] How to optimize this loop ?
>
>   
>> Dear R Users,
>>
>> I request your help to optimize a loop.
>>
>> Given a series of observations, I want to know how many consecutive
>> past observations are below the last one.
>>
>> e.g :
>> my_series <- c(3, 4, 10,14,8,3,4,6,9)
>>
>> As the last number (9)  is higher than the four preceding numbers (6,
>> 4, 3, 8), this function should return 4.
>>
>> my_series <- c(3, 4, 10,14,8,3,4,11,9)
>> Here, it should return 0, as 9 is immediately preceeded by a higher
>> number.
>>
>> So far, I do this awful loop :
>>
>> result <- 0
>> for (i in 1:length(my_series-1))
>> {
>>  if (my_series[length(my_series)-i]>end(my_series)[1])
>> { result <- i-1 ; break }
>> }
>>
>> I thing there's a better way...
>>
>> my_series > my_series[end][1] returns :
>> TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE FALSE
>> , which seems more appealing (once the last "FALSE" is removed), but
>> now, how to know the size of the last consecutive series of "TRUE" ?
>>
>> Can you see a better way ?
>>
>> Thanks.
>>
>> __
>> 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.
>> 
>
> Petr Pikal
> [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.
>

__
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 Benjamin Tyner
Thanks to all for your insightful comments. I must admit I was unaware 
of the application to arrays.

Ben

Prof Brian Ripley wrote:
> 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.
>
> 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.

__
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] building R on freebsd 6.2 (amd64)

2007-01-18 Thread Gordon Bergling
Hi,

Hiroyuki Kawakatsu wrote:
> Hi,
>
> I updated my os to freebsd 6.2 and built R-patched with no changes in
> configure. I pass make check and copy the R executable to
> /usr/local/bin/R. Then when I start R, I get
>
> /libexec/ld-elf.so.1: Shared object "libRblas.so" not found, required by "R"
>
> and have to copy/link the two shared object files (libRblas.so and
> libRlapack.so) to somewhere "visible" like /usr/local/lib/ as well. I
> didn't have to do this last step in freebsd 6.1. Is there some
> configure setting I can use to avoid having to move the two shared
> object files?
>   
have you tried to build R over the ports system?

regards,

Gordon

__
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 optimize this loop ? (correction)

2007-01-18 Thread Martin Becker
Sorry, I accidentaly lost one line of the function code (result <-0), 
see below...
Regards, Martin

Martin Becker schrieb:
>
> myfun1 <- function(series=c(3, 4, 10,14,8,3,4,6,9)) {
 result <- 0# NEW
>  len<-length(series)
>  for (i in (len-1):1)
>  {
>if (series[i]>series[len])
>{ result <- i-1 ; break }
>  }
>  return(result)
> }
>
...

__
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] building R on freebsd 6.2 (amd64)

2007-01-18 Thread Prof Brian D Ripley
On Thu, 18 Jan 2007, Hiroyuki Kawakatsu wrote:

> Hi,
>
> I updated my os to freebsd 6.2 and built R-patched with no changes in
> configure. I pass make check and copy the R executable to
> /usr/local/bin/R. Then when I start R, I get
>
> /libexec/ld-elf.so.1: Shared object "libRblas.so" not found, required by "R"
>
> and have to copy/link the two shared object files (libRblas.so and
> libRlapack.so) to somewhere "visible" like /usr/local/lib/ as well. I
> didn't have to do this last step in freebsd 6.1. Is there some
> configure setting I can use to avoid having to move the two shared
> object files?

The R front end sets LD_LIBRARY_PATH to include the place it puts libR.so. 
It looks like that is not effective on your machine, but you will have to 
investigate for us why.  I am pretty sure other FreeBSD users (6.2 and 7) 
on AMD64 reported success on R 2.4.x.

How does FreeBSD 6.2 handle 64-bit systems?  Most OSes would use 
/usr/local/lib64, and there is a configure setting LIBnn to cover that 
issue.

Another solution for ELF systems is to include R_HOME/lib in the list of 
directories known to ldconfig.

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


[R] help with niave bayes

2007-01-18 Thread leah martell
 Hello

I have a rather simple code and for some reason it produces an error
message.  If someone can tell me why and how to fix it, I would be very
greatful. Thank you in advance.


# create data
set.seed(10)
n <- 200 # number of training points
n.test <- 200   # number of test points
p<-2# dimension of input space
z <- matrix(rnorm((n+n.test)*p),ncol=p)
x <- matrix(0,nrow=n+n.test,ncol=p)
for (i in 1:p)
  x[,i] <- z%*%rnorm(p)
truecoef <- c(1,2)
prob1 <- exp(x%*%truecoef)/(1+exp(x%*%truecoef))
# prob is the true probability of class 1
y <- rbinom(n+n.test,1,prob1)
# separate the data into train and test sets
mydata <- data.frame(y=y[1:n],x=x[1:n,])
mydata.test <- data.frame(y=y[n+(1:n.test)],x=x[n+(1:n.test),])
##
library(e1071)
mydt.nb<-naiveBayes(y~ ., data=mydata)
m.pr<-predict(mydt.nb, mydata[,-1], type="class")


regards,
Leah

[[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] Problems replicating rows and associated increasing index

2007-01-18 Thread Niccolò Bassani
I have a dataset like this:

IDvalue week of visit
1  4.2  0  (baseline)
1  2.5  6
1  4.1  10
1  3.0  12
.
.
.

And so on for more than 11000 records (more than 1000 subjects). I need to
add rows in order to have 52 records per patients  (corresponding to the 52
weeks of the year); that is that weeks 1-2-3-4-5 will have the same content
of baseline one, except for the column "week of visit". The fact is that
each of the rows can have a very different timing, so the only thing I can
do is creating a vector giving the number of replications needed for each
row, but how can I practically replicate them increasing the index ok the
week?
thanks
niccolò

[[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 with problem - multilevel model?

2007-01-18 Thread Crabb, David
I have what is probably a very simple problem but I would be very
grateful to the list for any help or pointers to implement a solution in
R.

We have two types of measurements on the eye that we have collected in
62 patients at 5 fixed time points during a clinical visit over an
office day. We want to establish if there is an association between the
measurements. Obviously it would be wrong to generate a simple
scatterplot of all 62*5 observations and consider something like a
simple correlation coefficient. What I really need is to set up a
2-level model with measurements nested within patients and use, perhaps,
one variable as a response and the other as a predictor. I would also
like to add in time of day (probably as a categorical) to check this
isn't affecting things. I haven't used multi-level modelling in R and
wonder how I can simply go about fitting this model and looking at the
significance of the estimates in R. I also have a plot in my mind - 62
little regression lines (n=5) and think that this might be
informative.

Any help or pointers will be gratefully received - Many Thanks.

Dr. David Crabb
Department of Optometry and Visual Science,
City University, Northampton Square, London EC1V OHB
Tel: 44 207 040 0191   [EMAIL PROTECTED]
http://www.city.ac.uk/optometry/about/staff/crabb.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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to optimize this loop ? (correction)

2007-01-18 Thread Nicolas Prune
Thanks to everyone who answered, in public or in private.

I successfully rewrote my function with rle.

For my sample, the total computation times (I call this function around 1000
times) are roughly the same. However, I thank you for letting me know rle, and
S Poetry.

Regards,
Nicolas

__
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 problem - multilevel model?

2007-01-18 Thread Richard M. Heiberger
This should get you started


tmp <- data.frame(y1=rnorm(62*5),
  y2=rnorm(62*5),
  time=rep(1:5, 62),
  id=factor(rep(1:62, each=5))
  )

xyplot(y1 ~ y2 | id, data=tmp, group=time, pch=as.character(1:5))

tmp.aov <- aov(y1 ~ y2*factor(time) + Error(id), data=tmp)
summary(tmp.aov)

__
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] Problems replicating rows and associated increasing index

2007-01-18 Thread jim holtman
Try this.  It does a small sample with 15 weeks and only 10 patients, but
the algorithm is easily changed for 52.

require(zoo)  # need the 'zoo' library for 'na.locf'
# create test data
visits <- data.frame(id=rep(1:10, each=10),value=runif(100),
week=sample(1:15,100,TRUE))
# removed duplicated values
visits <- visits[!duplicated(paste(visits$id, visits$week)),]
# now do the algorithm
full <- by(visits, visits$id, function(x){
# fill to 15 weeks and add a baseline (0)
x <- rbind(x, data.frame(id=x$id[1], value=runif(1), week=0))
# determine which weeks are missing
missing <- setdiff(1:15, x$week)  # change to 52 for your case
# add missing weeks
x <- rbind(x, data.frame(id=x$id[1], value=NA, week=missing))
# sort by week
x <- x[order(x$week),]
# replace 'value' with previous good value
x$value <- na.locf(x$value)
x
})
# create new data frame
(full <- do.call(rbind, full))



On 1/18/07, Niccolò Bassani <[EMAIL PROTECTED]> wrote:
>
> I have a dataset like this:
>
> IDvalue week of visit
> 1  4.2  0  (baseline)
> 1  2.5  6
> 1  4.1  10
> 1  3.0  12
> .
> .
> .
>
> And so on for more than 11000 records (more than 1000 subjects). I need to
> add rows in order to have 52 records per patients  (corresponding to the
> 52
> weeks of the year); that is that weeks 1-2-3-4-5 will have the same
> content
> of baseline one, except for the column "week of visit". The fact is that
> each of the rows can have a very different timing, so the only thing I can
> do is creating a vector giving the number of replications needed for each
> row, but how can I practically replicate them increasing the index ok the
> week?
> thanks
> niccolò
>
>[[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.
>
>
>


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


[R] How to specify arguments in lme() ?

2007-01-18 Thread w jj

Hi,

I have a question about the function lme() in R.

I have a 2*2*3 layout with some missing data (labelled as *).  These 3 
factors are labelled as A,B,C, the response is Score. The layout is as 
follows:-


A  B CScore
1   1  1 5
1   1  2 *
1   1  3 1
1   2  1 4
1   2  2 4
1   2  3 *
2   1  1 3
2   1  2 *
2   1  3 4
2   2  1 2
2   2  2 *
2   2  3 5

Suppose these data are stored in a data frame called "test".

If all these 3 factors are fixed, then I can fit a model without the 3-way 
interaction as:-
fit1<-lm(Score~A*B+A*C+B*C,data=test)

If one of these factors, say A, is a random effect variable, then I need to 
fit a mixed effect model using lme(). I have read the R documention on 
lme(), but I am still not clear how to specify the random argument. I tried 
to do:-


fit2<-lme(Score~A*B+A*C+B*C,data=test,random=~A, na.action=na.pass) 


but the system give a message as follows:-
Error in getGroups.data.frame(dataMix, groups) : 
   Invalid formula for groups


So how should I specify the arguments? 


Thank you very much for your help!

Jiajie

__
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 problem - multilevel model?

2007-01-18 Thread Doran, Harold
Aov is not the right function for this problem. Lmer is designed for
multilevel modeling. There are a lot of resources, but start with the
following vignette

Library(lme4)
vignette("MlmRevSoft")

And then turn to Pinhiero and Bates

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> Richard M. Heiberger
> Sent: Thursday, January 18, 2007 10:22 AM
> To: Crabb, David; r-help@stat.math.ethz.ch
> Subject: Re: [R] Help with problem - multilevel model?
> 
> This should get you started
> 
> 
> tmp <- data.frame(y1=rnorm(62*5),
>   y2=rnorm(62*5),
>   time=rep(1:5, 62),
>   id=factor(rep(1:62, each=5))
>   )
> 
> xyplot(y1 ~ y2 | id, data=tmp, group=time, pch=as.character(1:5))
> 
> tmp.aov <- aov(y1 ~ y2*factor(time) + Error(id), data=tmp)
> summary(tmp.aov)
> 
> __
> 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.


[R] [R-pkgs] Version 2.0-9 of bayesm

2007-01-18 Thread Rossi, Peter E.
Version 2.0-9 of bayesm is now available on CRAN

changes include-

1. addition of rhierLinearMixture -- linear hierarchical models with a
mixture of normals prior
2. mixDenBi is now fully vectorized and run more than 10 times faster
3. minor documentation corrections have been made
4. rnmixGibbs allows the user to specify only one component
 
peter rossi

___
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] The math underlying the `betareg' package?

2007-01-18 Thread Ajay Narottam Shah
Folks,

The betareg package appears to be polished and works well. But I would
like to look at the exact formulas for the underlying model being
estimated, the likelihood function, etc. E.g. if one has to compute
\frac{\partial E(y)}{\partial x_i}, this requires careful calculations
through these formulas. I read "Regression analysis of variates
observed on (0,1): percentages, proportions and fractions", by
Kieschnick & MucCullogh, `Statistical Modelling" 2003, 3:193-213. They
say that the beta regression that they show is a proposal of theirs -
is this the same as what betareg does, or is this the Standard
Formulation?

What else should I be reading about beta regressions? :-)

-- 
Ajay Shah  http://www.mayin.org/ajayshah  
[EMAIL PROTECTED] http://ajayshahblog.blogspot.com
<*(:-? - wizard who doesn't know the answer.

__
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] fitCopula method in R

2007-01-18 Thread atreibel3


--
Hello,

I am attempting to fit monthly stock returns to possible copula functions using
the copula package in R.  Below is my code (mat2 is a 2x119 matrix of the two
stock returns):

my.cop <- normalCopula(param=.3, dim = 2, dispstr = "un")
myfit <- fitCopula(mat2,my.cop, start=.65, optim.control= list(NULL), method =
"BFGS")
myfit

Unfortunately, I continue to receive this error:

Error in optim(start, loglikCopula, method = method, copula = copula,  :
initial value in 'vmmin' is not finite
In addition: Warning message:
NaNs produced in: qnorm(p, mean, sd, lower.tail, log.p)

I don't know why my start value is wrong or how to choose a correct one.  Any
help is greatly appreicated.  Thanks.

Adam

__
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 specify arguments in lme() ?

2007-01-18 Thread Douglas Bates
On 1/18/07, w jj <[EMAIL PROTECTED]> wrote:

> I have a question about the function lme() in R.
>
> I have a 2*2*3 layout with some missing data (labelled as *).  These 3
> factors are labelled as A,B,C, the response is Score. The layout is as
> follows:-
>
> A  B CScore
> 1   1  1 5
> 1   1  2 *
> 1   1  3 1
> 1   2  1 4
> 1   2  2 4
> 1   2  3 *
> 2   1  1 3
> 2   1  2 *
> 2   1  3 4
> 2   2  1 2
> 2   2  2 *
> 2   2  3 5
>
> Suppose these data are stored in a data frame called "test".
>
> If all these 3 factors are fixed, then I can fit a model without the 3-way
> interaction as:-
> fit1<-lm(Score~A*B+A*C+B*C,data=test)
>
> If one of these factors, say A, is a random effect variable, then I need to
> fit a mixed effect model using lme(). I have read the R documention on
> lme(), but I am still not clear how to specify the random argument. I tried
> to do:-

You could do it but you don't really want to try to fit a model with
several random effects generated by a factor with only two levels.
Estimating variances, which is what is done for a random effect, is
more difficult than estimating means or other linear combinations of
the responses, which is what fixed effects parameters end up being
expressed as.  Trying to estimate a variance when observing a factor
at only two levels is overly optimistic.

Just for the record, the call to lmer in the lme4 package would be

fit2 <- lmer(Score ~ B*C+(1|A/B)+(1|C:A), data = test)

> fit2<-lme(Score~A*B+A*C+B*C,data=test,random=~A, na.action=na.pass)

I don't think you want to use na.pass here.  The underlying C code for
fitting lme or lmer models doesn't take kindly to finding NA's in the
data.

>
> but the system give a message as follows:-
> Error in getGroups.data.frame(dataMix, groups) :
> Invalid formula for groups
>
> So how should I specify the arguments?
>
> Thank you very much for your help!
>
> Jiajie
>
>
>
> __
> 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.


Re: [R] The math underlying the `betareg' package?

2007-01-18 Thread Gavin Simpson
On Thu, 2007-01-18 at 20:00 +0530, Ajay Narottam Shah wrote:
> Folks,
> 
> The betareg package appears to be polished and works well. But I would
> like to look at the exact formulas for the underlying model being
> estimated, the likelihood function, etc. E.g. if one has to compute
> \frac{\partial E(y)}{\partial x_i}, this requires careful calculations
> through these formulas. I read "Regression analysis of variates
> observed on (0,1): percentages, proportions and fractions", by
> Kieschnick & MucCullogh, `Statistical Modelling" 2003, 3:193-213. They
> say that the beta regression that they show is a proposal of theirs -
> is this the same as what betareg does, or is this the Standard
> Formulation?

If you want to know, the best place to look is the source code for the
package, available as a tar.gz file from all good CRAN Mirrors.

I suggest this as the Windows binary might not contain the original
source (i.e unprocessed with comments etc) - I forget now exactly how
the binaries on that platform differ.

> 
> What else should I be reading about beta regressions? :-)

The reference cited in the References section of ?betareg would also be
a good start, esp to understand what the betareg package is doing and
how it compares to the other ref you cite.

HTH

G
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
R-help@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] The math underlying the `betareg' package?

2007-01-18 Thread rdporto1
>What else should I be reading about beta regressions? :-)

Ajay,

you could begin by reading the paper cited in betareg package:

FERRARI, S.L.P., CRIBARI-NETO, F. (2004).
Beta regression for modeling rates and proportions.
Journal of Applied Statistics, v. 31, n. 7, p. 799-815

I'd bet that there are answers to some of your questions
there.

HTH,

Rogerio

__
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] problem in adf command

2007-01-18 Thread zahid khan

 

this command is used in tseries 

adf.test(x, alternative = c("stationary", "explosive"),

 k = trunc((length(x)-1)^(1/3)))

this command apply adf test on data given in x .here general 

equatiuon 

that is, equation with constant and trend is used.if i did not include 

constant or trend in the equation and run the

command then how i can run this command in tseries.

 
-
Never miss an email again!

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


Re: [R] sleep data

2007-01-18 Thread Martin Maechler
Thank you, Chuck and Tom.

I'd gladly improve the help page,

particularly if you can provide a patch against

https://svn.R-project.org/R/trunk/src/library/datasets/man/sleep.Rd

where I've already added the Cushny and Peebles reference,
thanks to Chuck.

Regards,
Martin Maechler, ETH Zurich


> "ChuckB" == Charles C Berry <[EMAIL PROTECTED]>
> on Wed, 17 Jan 2007 10:48:13 -0800 writes:

ChuckB> Yes, you refer to

ChuckB> Cushny, A. R. and Peebles, A. R. The action of
ChuckB> optical isomers: II hyoscines. The Journal of
ChuckB> Physiology, 1905, 32: 501.510.

ChuckB> which was used by 'Student' to illustrate the paired
ChuckB> t-test.

ChuckB> This is indeed a crossover design.

ChuckB> On Wed, 17 Jan 2007, Tom Backer Johnsen wrote:

>> When reading the documentation for the "sleep" data set
>> in R, the impression is clear, this is an "independent
>> groups" kind of design (two groups of 10 subjects each).
>> However, when browsing the original article (referred to
>> in the help file), my impression is quite clear, this is
>> really a "repeated measures" kind of data (one group of
>> 10 subjects, two observations).  What is correct?
>> 
>> Tom
>> 
>> __
>> 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.
>> 

ChuckB> Charles C. Berry (858) 534-2098 Dept of
ChuckB> Family/Preventive Medicine E
ChuckB> mailto:[EMAIL PROTECTED] UC San Diego
ChuckB> http://biostat.ucsd.edu/~cberry/ La Jolla, San Diego
ChuckB> 92093-0901

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


Re: [R] building R on freebsd 6.2 (amd64)

2007-01-18 Thread Prof Brian Ripley
On Thu, 18 Jan 2007, Hiroyuki Kawakatsu wrote:

> On 1/18/07, Prof Brian D Ripley <[EMAIL PROTECTED]> wrote:
>> 
>> The R front end sets LD_LIBRARY_PATH to include the place it puts libR.so.
>> It looks like that is not effective on your machine, but you will have to
>> investigate for us why.  I am pretty sure other FreeBSD users (6.2 and 7)
>> on AMD64 reported success on R 2.4.x.
>
> echo returns
> LD_LIBRARY_PATH: Undefined variable.

But I said 'The R front end sets LD_LIBRARY_PATH', so you need to check 
this from inside R, e.g. by Sys.getenv().

>> How does FreeBSD 6.2 handle 64-bit systems?  Most OSes would use
>> /usr/local/lib64, and there is a configure setting LIBnn to cover that
>> issue.
>
> I have /usr/lib/, /usr/lib32/, /usr/local/lib/, but no /usr/local/lib64/
>
>> Another solution for ELF systems is to include R_HOME/lib in the list of
>> directories known to ldconfig.
>
> Thanks for that tip. I suppose if I symlink to R_HOME/lib/ I won't
> have to redo them every time I rebuild R-patched. Just as note to
> myself, the following appears to work
>
> ln -s /opt/acml3.6.0/gnu64/lib/libacml.so /usr/local/lib/libRblas.so
> ln -s /opt/acml3.6.0/gnu64/lib/libacml_mv.so /usr/local/lib/libacml_mv.so
> ln -s R_HOME/lib/libRlapack.so /usr/local/lib/libRlapack.so
>
> h.
>

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


Re: [R] building R on freebsd 6.2 (amd64)

2007-01-18 Thread Hiroyuki Kawakatsu
On 1/18/07, Prof Brian D Ripley <[EMAIL PROTECTED]> wrote:
>
> The R front end sets LD_LIBRARY_PATH to include the place it puts libR.so.
> It looks like that is not effective on your machine, but you will have to
> investigate for us why.  I am pretty sure other FreeBSD users (6.2 and 7)
> on AMD64 reported success on R 2.4.x.

echo returns
LD_LIBRARY_PATH: Undefined variable.

> How does FreeBSD 6.2 handle 64-bit systems?  Most OSes would use
> /usr/local/lib64, and there is a configure setting LIBnn to cover that
> issue.

I have /usr/lib/, /usr/lib32/, /usr/local/lib/, but no /usr/local/lib64/

> Another solution for ELF systems is to include R_HOME/lib in the list of
> directories known to ldconfig.

Thanks for that tip. I suppose if I symlink to R_HOME/lib/ I won't
have to redo them every time I rebuild R-patched. Just as note to
myself, the following appears to work

ln -s /opt/acml3.6.0/gnu64/lib/libacml.so /usr/local/lib/libRblas.so
ln -s /opt/acml3.6.0/gnu64/lib/libacml_mv.so /usr/local/lib/libacml_mv.so
ln -s R_HOME/lib/libRlapack.so /usr/local/lib/libRlapack.so

h.
-- 
--
Hiroyuki Kawakatsu
Business School
Dublin City University
Dublin 9, Ireland
Tel +353 (0)1 700 7496

__
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] options("digits") and print.default()

2007-01-18 Thread Charles Dupont
Prof Brian Ripley wrote:
> On Mon, 15 Jan 2007, Ulrich Keller wrote:
> 
>> Hello everyone,
>>
>> I use latex() (Hmisc) for report generation and thus have been affected by
>> the problem with rounding decimals described, for example, in this post:
>>
>> http://thread.gmane.org/gmane.comp.lang.r.general/73287/focus=73287
>>
>> In short, numbers often are printed with 15 or so decimals even if there
>> far less significant digits. The problem has been confirmed by Frank
>> Harrell and Thomas Dupont according to this post:
>>
>> http://thread.gmane.org/gmane.comp.lang.r.general/73172/focus=73186
>>
>> But it has still not been fixed. Rather than changing all my reports I
>> decided I'd look at format.df() in Hmisc myself and try to fix the problem
>> there. I found that the problem is not in Hmisc at all, but in R itself:
>>
>>> print(1.001)
>> [1] 1.001
>>> options(digits=16) #format.df does this
>>> print(1.001)
>> [1] 1.001
>>> print(round(1.001, 3)) #rounding does not help
>> [1] 1.001
>>
>> This does not seem to be the behaviour described in the documentation,
>> which says:
>>
>> "The same number of decimal places is used throughout a vector,[sic!] This
>> means that digits specifies the minimum number of significant digits to be
>> used, and that at least one entry will be encoded with that minimum
>> number. However, if all the encoded elements then have trailing zeroes,
>> the number of decimal places is reduced until at least one element has a
>> non-zero final digit."
>>
>> If print.default() exhibited the behaviour desribed in the docs,
>> format.df() and thus latex() would work as advertised, I think. I would
>> have written a bug report instead of posting here, but the fact (?) that
>> Frank and Thomas have confirmed the bug seems to indicate that the problem
>> does indeed lie with Hmisc. Am I misunderstanding something here?
>>
>> I use R version 2.4.1 Patched (2007-01-13 r40470) on Windows.
> 
> The bug is that Hmisc uses more digits than the representation provides:
> 
>> .Machine$double.eps
> [1] 2.22044604925031e-16
> 
> If it used 15 digits (as R does for as.character) all would be well. 
> Since R has to do the calculations you quote in binary arithmetic, they 
> are also subject to representation error and there is no way they can be 
> done to 16 significant figures.  (I've traced the example, and that is 
> what happens.)  See ?as.character for more details.
> 

Is there an R object that contains the value of DBL_DIG for the current 
machine?  I have checked '.Machine' and '.Platform' and neither have the 
value of DBL_DIG in them.

Thank you

Charles Dupont

-- 
Charles Dupont  Computer System Analyst School of Medicine
Department of Biostatistics Vanderbilt University

__
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] options("digits") and print.default()

2007-01-18 Thread Prof Brian Ripley
On Thu, 18 Jan 2007, Charles Dupont wrote:

> Prof Brian Ripley wrote:
>> On Mon, 15 Jan 2007, Ulrich Keller wrote:
>> 
>>> Hello everyone,
>>> 
>>> I use latex() (Hmisc) for report generation and thus have been affected by
>>> the problem with rounding decimals described, for example, in this post:
>>> 
>>> http://thread.gmane.org/gmane.comp.lang.r.general/73287/focus=73287
>>> 
>>> In short, numbers often are printed with 15 or so decimals even if there
>>> far less significant digits. The problem has been confirmed by Frank
>>> Harrell and Thomas Dupont according to this post:
>>> 
>>> http://thread.gmane.org/gmane.comp.lang.r.general/73172/focus=73186
>>> 
>>> But it has still not been fixed. Rather than changing all my reports I
>>> decided I'd look at format.df() in Hmisc myself and try to fix the problem
>>> there. I found that the problem is not in Hmisc at all, but in R itself:
>>> 
 print(1.001)
>>> [1] 1.001
 options(digits=16) #format.df does this
 print(1.001)
>>> [1] 1.001
 print(round(1.001, 3)) #rounding does not help
>>> [1] 1.001
>>> 
>>> This does not seem to be the behaviour described in the documentation,
>>> which says:
>>> 
>>> "The same number of decimal places is used throughout a vector,[sic!] This
>>> means that digits specifies the minimum number of significant digits to be
>>> used, and that at least one entry will be encoded with that minimum
>>> number. However, if all the encoded elements then have trailing zeroes,
>>> the number of decimal places is reduced until at least one element has a
>>> non-zero final digit."
>>> 
>>> If print.default() exhibited the behaviour desribed in the docs,
>>> format.df() and thus latex() would work as advertised, I think. I would
>>> have written a bug report instead of posting here, but the fact (?) that
>>> Frank and Thomas have confirmed the bug seems to indicate that the problem
>>> does indeed lie with Hmisc. Am I misunderstanding something here?
>>> 
>>> I use R version 2.4.1 Patched (2007-01-13 r40470) on Windows.
>> 
>> The bug is that Hmisc uses more digits than the representation provides:
>> 
>>> .Machine$double.eps
>> [1] 2.22044604925031e-16
>> 
>> If it used 15 digits (as R does for as.character) all would be well. Since 
>> R has to do the calculations you quote in binary arithmetic, they are also 
>> subject to representation error and there is no way they can be done to 16 
>> significant figures.  (I've traced the example, and that is what happens.) 
>> See ?as.character for more details.
>> 
>
> Is there an R object that contains the value of DBL_DIG for the current 
> machine?  I have checked '.Machine' and '.Platform' and neither have the 
> value of DBL_DIG in them.

No, but please do as I suggested and read ?as.character: it is 15 on all 
current platforms.

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


[R] Robust PCA?

2007-01-18 Thread Talbot Katz
Hi.

I'm checking into robust methods for principal components analysis.  There 
seem to be several floating around.  I'm currently focusing my attention on 
a method of Hubert, Rousseeuw, and Vanden Branden 
(http://wis.kuleuven.be/stat/Papers/robpca.pdf) mainly because I'm familiar 
with other work by Rousseeuw and Hubert in robust methodologies.  Of course, 
I'd like to obtain code for this method, or another good robust PCA method, 
if there's one out there.  I haven't noticed the existence on CRAN of a 
package for robust PCA (the authors of the ROBPCA method do provide MATLAB 
code).

--  TMK  --
212-460-5430home
917-656-5351cell

__
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] weighted MDS, alscal

2007-01-18 Thread Martin Ivanov
Hello!
I need to perform weighted multidimensional scaling analysis(WMDS). I did 
rsitesearch, googled, but I could find no info on how to perform WMDS using R. 
In several places they say it is possible with the ALSCAL algorithm, but I 
could not find the relevant function to carry it out.


-
Заложете на късмета си със Спортингбет!

__
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] multiple seasonal time series models

2007-01-18 Thread sj
Is there an R package that can model time series with multiple seasonal
cycles, e.g., 7 wkdy x 24 hr , I have tried searching the Help, but have
been unable to find anything. Any help would be appreciated.

thank you,

Spencer

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


Re: [R] weighted MDS, alscal

2007-01-18 Thread Hisaji ONO
Hello.


--- Martin Ivanov <[EMAIL PROTECTED]> wrote:

> I need to perform weighted multidimensional scaling
> analysis(WMDS). I did rsitesearch, googled, but I
> could find no info on how to perform WMDS using R.
> In several places they say it is possible with the
> ALSCAL algorithm, but I could not find the relevant
> function to carry it out.
>

 I dont't know whether ALSCAL is available for R.

 However there's ALSCAL fortran code available in 
http://forrest.psych.unc.edu/research/alscal.html.


 Regards.

__
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] Laplace correction for rpart class probability estimate

2007-01-18 Thread Roberto Perdisci
Hello everybody,
  I'm using rpart to fit a classification tree. I'm interested in the
way rpart estimates the class membership probabilities. Does it
implement the Laplace correction rule? Is there any parameter I can
use to ask rpart to do that?
I was not able to find this option in the manual or on the internet.

thank you,
regards,
Roberto

__
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] selecting rows for inclusion in lm

2007-01-18 Thread John Sorkin
I must express thanks to Peter Konings, Gary Collins, David Barron,
Prof. Brian Ripley, Vladimir Eremeev, and Michael Dewey (I hope I did
not leave anyone out) all of whom suggested I used the subset parameter
of lm to restrict the subjects included in my lm. R is a special
programming language and statistics package, both because of the
wonderful features of R (thank you R developers), but equally
importantly because of the community of people who willingly give of
there time and knowledge to help other users. Many thanks.   
If any R developers are out there, may I suggest that the help page for
lm include more information (perhaps an example) on how one uses the
subset option. The current documentation states:
 

subsetan optional vector specifying a subset of observations to be used
in the fitting process.
 
Although I read the help page, I could not get subset to work until the
kind people mentioned above sent me examples.
 
Again, many thanks to one and all!
 
John
 
 
 
John Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
Baltimore VA Medical Center GRECC,
University of Maryland School of Medicine Claude D. Pepper OAIC,
University of Maryland Clinical Nutrition Research Unit, and
Baltimore VA Center Stroke of Excellence

University of Maryland School of Medicine
Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524

(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
[EMAIL PROTECTED] 

>>> Prof Brian Ripley <[EMAIL PROTECTED]> 1/18/2007 3:38 AM >>>
On Thu, 18 Jan 2007, David Barron wrote:

> Why not use the subset option?  Something like:
>
> lm(diff ~ Age + Race, data=data, subset=data$Meno=="PRE")
>
> should do the trick, and be much easier to read!

And

lm(diff ~ Age + Race, data = data, subset = (Meno=="PRE"))

would be easier still.

>
> On 18/01/07, John Sorkin <[EMAIL PROTECTED]> wrote:
>> I am having trouble selecting rows of a dataframe that will be
included
>> in a regression. I am trying to select those rows for which the
variable
>> Meno equals PRE. I have used the code below:
>>
>>
difffitPre<-lm(data[,"diff"]~data[,"Age"]+data[,"Race"],data=data[data[,"Meno"]=="PRE",])

You are missing a comma in data = data[<...>, ]

>> summary(difffitPre)
>>
>> The output from the summary indicates that more than 76 rows are
>> included in the regression:
>>
>> Residual standard error: 2.828 on 76 degrees of freedom
>>
>> where in fact only 22 rows should be included as can be seen from
the
>> following:
>>
>> print(data[length(data[,"Meno"]=="PRE","Meno"]))
>> [1] 22
>>
>> I would appreciate any help in modifying the data= parameter of the
lm
>> so that I include only those subjects for which Meno=PRE.
>>
>> R 2.3.1
>> Windows XP
>>
>> Thanks,
>> John
>>
>> John Sorkin M.D., Ph.D.
>> Chief, Biostatistics and Informatics
>> Baltimore VA Medical Center GRECC,
>> University of Maryland School of Medicine Claude D. Pepper OAIC,
>> University of Maryland Clinical Nutrition Research Unit, and
>> Baltimore VA Center Stroke of Excellence
>>
>> University of Maryland School of Medicine
>> Division of Gerontology
>> Baltimore VA Medical Center
>> 10 North Greene Street
>> GRECC (BT/18/GR)
>> Baltimore, MD 21201-1524
>>
>> (Phone) 410-605-7119
>> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>> [EMAIL PROTECTED] 
>>
>> Confidentiality Statement:
>> This email message, including any attachments, is for the
so...{{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 ( http://www.r/
)-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>

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

Confidentiality Statement:
This email message, including any attachments, is for the so...{{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] Reading contingency tables

2007-01-18 Thread Giovanni Petris

I am trying to read an ftable using read.ftable, but I get the
following error message:

> jobSatTable <- 
> read.ftable("http://definetti.uark.edu/~gpetris/stat5333/jobSatisfaction.dat",skip=2)
Error in seek(file, where = 0) : no applicable method for "seek"
In addition: Warning messages:
1: no non-missing arguments to max; returning -Inf 
2: no non-missing arguments to max; returning -Inf 


I also tried to play with the argument col.vars, to remove blank
lines in the file, to remove the blank in "Not
satisfied". Unfortunately nothing worked. 

Can anybody give me a suggestion on how to read that table?

Thanks in advance,
Giovanni

ps:

> version
   _   
platform   sparc-sun-solaris2.8
arch   sparc   
os solaris2.8  
system sparc, solaris2.8   
status 
major  2   
minor  4.1 
year   2006
month  12  
day18  
svn rev40228   
language   R   
version.string R version 2.4.1 (2006-12-18)

-- 

Giovanni Petris  <[EMAIL PROTECTED]>
Associate Professor
Department of Mathematical Sciences
University of Arkansas - Fayetteville, AR 72701
Ph: (479) 575-6324, 575-8630 (fax)
http://definetti.uark.edu/~gpetris/

__
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] sleep data

2007-01-18 Thread Charles C. Berry

A further note. The Cushny & Peebles article can be viewed here:

http://www.pubmedcentral.nih.gov/articlerender.fcgi?artid=1465734

and the page with the data is here:


http://www.pubmedcentral.nih.gov/pagerender.fcgi?artid=1465734&pageindex=9

A machine readable version of the data is at:

https://biostat.ucsd.edu/~cberry/t-test/sleep.dat

The version published in Student's Biometrika article has a typographical 
error, but it is evident that Student's computations were unaffected.

Chuck Berry

On Wed, 17 Jan 2007, Charles C. Berry wrote:

>
> Yes, you refer to
>
>Cushny, A. R. and Peebles, A. R. The action of optical isomers: II
>hyoscines. The Journal of Physiology, 1905, 32: 501.510.
>
> which was used by 'Student' to illustrate the paired t-test.
>
> This is indeed a crossover design.
>
> On Wed, 17 Jan 2007, Tom Backer Johnsen wrote:
>
>>  When reading the documentation for the "sleep" data set in R, the
>>  impression is clear, this is an "independent groups" kind of design
>>  (two groups of 10 subjects each).  However, when browsing the original
>>  article (referred to in the help file), my impression is quite clear,
>>  this is really a "repeated measures" kind of data (one group of 10
>>  subjects, two observations).  What is correct?
>>
>>  Tom
>>
>>  __
>>  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-0901
>
>
>
>

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

__
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] Robust PCA?

2007-01-18 Thread Bert Gunter
You seem not to have received a reply.  

You can use cov.rob in MASS or cov.Mcd in robustbase or undoubtedly others
to obtain a robust covariance matrix and then use that for PCA. 

-- Bert


Bert Gunter
Nonclinical Statistics
7-7374

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Talbot Katz
Sent: Thursday, January 18, 2007 11:44 AM
To: r-help@stat.math.ethz.ch
Subject: [R] Robust PCA?

Hi.

I'm checking into robust methods for principal components analysis.  There 
seem to be several floating around.  I'm currently focusing my attention on 
a method of Hubert, Rousseeuw, and Vanden Branden 
(http://wis.kuleuven.be/stat/Papers/robpca.pdf) mainly because I'm familiar 
with other work by Rousseeuw and Hubert in robust methodologies.  Of course,

I'd like to obtain code for this method, or another good robust PCA method, 
if there's one out there.  I haven't noticed the existence on CRAN of a 
package for robust PCA (the authors of the ROBPCA method do provide MATLAB 
code).

--  TMK  --
212-460-5430home
917-656-5351cell

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


Re: [R] Robust PCA?

2007-01-18 Thread Talbot Katz
Hi Bert.

Thank you, that sounds like an excellent idea.  After my initial post, I 
also found an implementation of ROBPCA in S-PLUS at 
(http://wis.kuleuven.be/stat/robust/programs.html).

--  TMK  --
212-460-5430home
917-656-5351cell


>From: Bert Gunter <[EMAIL PROTECTED]>
>To: "'Talbot Katz'" <[EMAIL PROTECTED]>, 
>Subject: RE: [R] Robust PCA?
>Date: Thu, 18 Jan 2007 15:28:47 -0800
>
>You seem not to have received a reply.
>
>You can use cov.rob in MASS or cov.Mcd in robustbase or undoubtedly others
>to obtain a robust covariance matrix and then use that for PCA.
>
>-- Bert
>
>
>Bert Gunter
>Nonclinical Statistics
>7-7374
>
>-Original Message-
>From: [EMAIL PROTECTED]
>[mailto:[EMAIL PROTECTED] On Behalf Of Talbot Katz
>Sent: Thursday, January 18, 2007 11:44 AM
>To: r-help@stat.math.ethz.ch
>Subject: [R] Robust PCA?
>
>Hi.
>
>I'm checking into robust methods for principal components analysis.  There
>seem to be several floating around.  I'm currently focusing my attention on
>a method of Hubert, Rousseeuw, and Vanden Branden
>(http://wis.kuleuven.be/stat/Papers/robpca.pdf) mainly because I'm familiar
>with other work by Rousseeuw and Hubert in robust methodologies.  Of 
>course,
>
>I'd like to obtain code for this method, or another good robust PCA method,
>if there's one out there.  I haven't noticed the existence on CRAN of a
>package for robust PCA (the authors of the ROBPCA method do provide MATLAB
>code).
>
>--  TMK  --
>212-460-5430   home
>917-656-5351   cell
>
>__
>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.


[R] integrate and quadratic forms

2007-01-18 Thread rdporto1
Hi all.

I'm trying to numerically invert the characteristic function
of a quadratic form following Imhof's (1961, Biometrika 48)
procedure.

The parameters are:

lambda=c(.6,.3,.1)
h=c(2,2,2)
sigma=c(0,0,0)
q=3

I've implemented Imhof's procedure two ways that, for me,
should give the same answer:

#more legible
integral1 = function(u) {
  o=(1/2)*sum(h*atan(lambda*u)+sigma^2*lambda*u/(1+lambda^2*u^2)) - q*u/2
  rho=prod((1+lambda^2*u^2)^(h/4))*exp( 
(1/2)*sum((sigma*lambda*u)^2/(1+lambda^2*u^2)) )
  integrand = sin(o)/(u*rho) 
}

#same as above
integral2= function(u) {
((1/2)*sum(h*atan(lambda*u)+sigma^2*lambda*u/(1+lambda^2*u^2)) - q*u/2)/
(u*(prod((1+lambda^2*u^2)^(h/4))*
exp( (1/2)*sum((sigma*lambda*u)^2/(1+lambda^2*u^2)) )))
}

The following should be near 0.18. However, nor the answers are near this
value neither they agree each other!

> 1/2+(1/pi)*integrate(integral1,0,Inf)$value
[1] 1.022537
> 1/2+(1/pi)*integrate(integral2,0,Inf)$value
[1] 1.442720

What's happening? Is this a bug or OS specific? Shouldn't they give the 
same answer? Why do I get results so different from 0.18? In time:
the procedure works fine for q=.2.

I'm running R 2.4.1 in a PC with Windows XP 32bits. Other ways (in R) to
find the distribution of general quadratic forms are welcome.

Thanks in advance.

Rogerio.

__
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] integrate and quadratic forms

2007-01-18 Thread jim holtman
The do give the same answer, unfortunately the examples you sent  were not
the same.  Integral2 was missing a 'sin'.  So I would assume there might be
something else wrong with your functions.  You might want to try breaking it
down into smaller steps so you can see what you are doing.  It definitely is
hard to read in both cases.

> integral1 = function(u) {
+  o=(1/2)*sum(h*atan(lambda*u)+sigma^2*lambda*u/(1+lambda^2*u^2)) - q*u/2
+  rho=prod((1+lambda^2*u^2)^(h/4))*exp(
(1/2)*sum((sigma*lambda*u)^2/(1+lambda^2*u^2)) )
+  integrand = sin(o)/(u*rho)
+ }
>
> #same as above
> integral2= function(u) {
+ sin((1/2)*sum(h*atan(lambda*u)+sigma^2*lambda*u/(1+lambda^2*u^2)) -
q*u/2)/
+ (u*(prod((1+lambda^2*u^2)^(h/4))*
+ exp( (1/2)*sum((sigma*lambda*u)^2/(1+lambda^2*u^2)) )))
+ }
>
>
> 1/2+(1/pi)*integrate(integral1,0,Inf)$value
[1] 1.022537
> 1/2+(1/pi)*integrate(integral2,0,Inf)$value
[1] 1.022537
>
>



On 1/18/07, rdporto1 <[EMAIL PROTECTED]> wrote:
>
> Hi all.
>
> I'm trying to numerically invert the characteristic function
> of a quadratic form following Imhof's (1961, Biometrika 48)
> procedure.
>
> The parameters are:
>
> lambda=c(.6,.3,.1)
> h=c(2,2,2)
> sigma=c(0,0,0)
> q=3
>
> I've implemented Imhof's procedure two ways that, for me,
> should give the same answer:
>
> #more legible
> integral1 = function(u) {
> o=(1/2)*sum(h*atan(lambda*u)+sigma^2*lambda*u/(1+lambda^2*u^2)) - q*u/2
> rho=prod((1+lambda^2*u^2)^(h/4))*exp(
> (1/2)*sum((sigma*lambda*u)^2/(1+lambda^2*u^2)) )
> integrand = sin(o)/(u*rho)
> }
>
> #same as above
> integral2= function(u) {
> ((1/2)*sum(h*atan(lambda*u)+sigma^2*lambda*u/(1+lambda^2*u^2)) - q*u/2)/
> (u*(prod((1+lambda^2*u^2)^(h/4))*
> exp( (1/2)*sum((sigma*lambda*u)^2/(1+lambda^2*u^2)) )))
> }
>
> The following should be near 0.18. However, nor the answers are near this
> value neither they agree each other!
>
> > 1/2+(1/pi)*integrate(integral1,0,Inf)$value
> [1] 1.022537
> > 1/2+(1/pi)*integrate(integral2,0,Inf)$value
> [1] 1.442720
>
> What's happening? Is this a bug or OS specific? Shouldn't they give the
> same answer? Why do I get results so different from 0.18? In time:
> the procedure works fine for q=.2.
>
> I'm running R 2.4.1 in a PC with Windows XP 32bits. Other ways (in R) to
> find the distribution of general quadratic forms are welcome.
>
> Thanks in advance.
>
> Rogerio.
>
> __
> 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.


[R] Problem with loading tkrplot

2007-01-18 Thread jim holtman
I asked the maintainer and he indicated that it might be a dll problem.  Has
anyone see this problem?  I had installed the latest copy of tkrplot.  I was
trying to use teachingDemos when I first got the error.

On 1/18/07, Luke Tierney <[EMAIL PROTECTED]> wrote:

> Looks like tcl can't find the dll or something along those lines. As
> this is windows you'll have to ask someone who uses that platform
> to help figure out why.
>
> luke
>
> On Thu, 18 Jan 2007, jim holtman wrote:
>
> > I was trying to use the teachingDemos package and was getting an error
> > trying to load tkrplot.
> >
> > I downloaded the latest copy and here is what I am getting on the
> console.
> > You were mentioned as the maintainer on the manual page.  Do you know
> why
> > this error might be occuring?
> >
> >
> >
> >> utils:::menuInstallPkgs()
> > --- Please select a CRAN mirror for use in this session ---
> > trying URL '
> > http://www.stathy.com/cran/bin/windows/contrib/2.4/tkrplot_0.0-16.zip'
> > Content type 'application/zip' length 24119 bytes
> > opened URL
> > downloaded 23Kb
> >
> > package 'tkrplot' successfully unpacked and MD5 sums checked
> >
> > The downloaded packages are in
> >   C:\Documents and Settings\Compaq_Administrator\Local
> > Settings\Temp\RtmpqEShrb\downloaded_packages
> > updating HTML package descriptions
> >> library(tkrplot)
> > Loading required package: tcltk
> > Loading Tcl/Tk interface ... done
> > Error in structure(.External("dotTcl", ..., PACKAGE = "tcltk"), class =
> > "tclObj") :
> >   [tcl] could not find interpreter "Rplot".
> > Error in library(tkrplot) : .First.lib failed for 'tkrplot'
> >> sessionInfo()
> > R version 2.4.1 (2006-12-18)
> > i386-pc-mingw32
> >
> > locale:
> > LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
> > States.1252;LC_MONETARY=English_United
> > States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
> >
> > attached base packages:
> > [1] "tcltk" "stats" "utils"
> "datasets"  "graphics"  "grDevices"
> > "methods"   "base"
> >>
> >
> >
> >



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


Re: [R] Problem with loading tkrplot

2007-01-18 Thread Duncan Murdoch
On 1/18/2007 8:57 PM, jim holtman wrote:
> I asked the maintainer and he indicated that it might be a dll problem.  Has
> anyone see this problem?  I had installed the latest copy of tkrplot.  I was
> trying to use teachingDemos when I first got the error.

I just installed tkrplot in R 2.4.1 and it worked fine.  I've never seen 
the error you're reporting.  However, I see what looks like a typo that 
might affect some systems:

In the tkrplot .First.lib function, I see

> if (is.character(.Platform$r_arch) && .Platform$r_arch != 
> "") 
> path <- file.path("libs", .Platform$r_arc, dlname)
> else path <- file.path("libs", dlname)

On the 3rd line, I think .Platform$r_arc should be .Platform$r_arch.  On 
my system I never execute that line, but if .Platform$r_arch is set on 
your system, it would likely cause problems.

Duncan Murdoch

> 
> On 1/18/07, Luke Tierney <[EMAIL PROTECTED]> wrote:
> 
>> Looks like tcl can't find the dll or something along those lines. As
>> this is windows you'll have to ask someone who uses that platform
>> to help figure out why.
>>
>> luke
>>
>> On Thu, 18 Jan 2007, jim holtman wrote:
>>
>>> I was trying to use the teachingDemos package and was getting an error
>>> trying to load tkrplot.
>>>
>>> I downloaded the latest copy and here is what I am getting on the
>> console.
>>> You were mentioned as the maintainer on the manual page.  Do you know
>> why
>>> this error might be occuring?
>>>
>>>
>>>
 utils:::menuInstallPkgs()
>>> --- Please select a CRAN mirror for use in this session ---
>>> trying URL '
>>> http://www.stathy.com/cran/bin/windows/contrib/2.4/tkrplot_0.0-16.zip'
>>> Content type 'application/zip' length 24119 bytes
>>> opened URL
>>> downloaded 23Kb
>>>
>>> package 'tkrplot' successfully unpacked and MD5 sums checked
>>>
>>> The downloaded packages are in
>>>   C:\Documents and Settings\Compaq_Administrator\Local
>>> Settings\Temp\RtmpqEShrb\downloaded_packages
>>> updating HTML package descriptions
 library(tkrplot)
>>> Loading required package: tcltk
>>> Loading Tcl/Tk interface ... done
>>> Error in structure(.External("dotTcl", ..., PACKAGE = "tcltk"), class =
>>> "tclObj") :
>>>   [tcl] could not find interpreter "Rplot".
>>> Error in library(tkrplot) : .First.lib failed for 'tkrplot'
 sessionInfo()
>>> R version 2.4.1 (2006-12-18)
>>> i386-pc-mingw32
>>>
>>> locale:
>>> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
>>> States.1252;LC_MONETARY=English_United
>>> States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
>>>
>>> attached base packages:
>>> [1] "tcltk" "stats" "utils"
>> "datasets"  "graphics"  "grDevices"
>>> "methods"   "base"
>>>
>>>
> 
> 
>

__
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] kate editor for R

2007-01-18 Thread Frank E Harrell Jr
Like kile for LaTeX, Linux/KDE's kate editor is an excellent editor for 
R, with easy code submission to a running R process.  Syntax 
highlighting is good.  I have  not been able to figure out two things:

- how to automatically reformat a line or region of text using good 
indentation rules (Emacs/ESS make this so easy by just hitting Tab while 
the cursor is in a line, or highlighting a region and hitting Esq q)

- how to cause auto-indenting as you type braces.  For me, kate puts a { 
in column one

Thanks for any pointers.

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

__
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] if else statement

2007-01-18 Thread H. Paul Benton
Hello,

I'm doing some scripting and I've noticed that R doesn't seem to
have an
if (cond){
do
}ifelse (cond) {
do
} else {
do
}

type block.

Is this correct or am I missing something.

THX

Paul

-- 
Research Technician
Mass Spectrometry
   o The
  /
o Scripps
  \
   o Research
  /
o Institute

__
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 optimize this loop ? (correction)

2007-01-18 Thread Berwin A Turlach
G'day Martin and others,

On Thu, 18 Jan 2007 15:22:07 +0100
Martin Becker <[EMAIL PROTECTED]> wrote:

> Sorry, I accidentaly lost one line of the function code (result <-0), 
> see below...

But even with that line, the code doesn't work properly. :)
Since you changed the order of the for loop (from "i in 1:(len-1)" to
"i in (len-1):1") you broke the logic of the code and the result
returned is wrong (should be something like "result <- len-i" instead
of "result <- i-1").

I agree that your function is faster than the one based on rle(),
presumably because rle() does just too many additional computations
that are not necessary to solve the problem at hand.  But I still don't
like to see for() loops in R code. :)  I would suggest the following
solution (which is only marginally slower than yours on these example
inputs):

myfun2 <- function(x){
  len <- length(x)
  which.max(c(x[len] <= rev(x[-len]), TRUE) ) - 1
}

The concatenation of TRUE at the end of the logical vector is necessary
for the case that all elements before the last are smaller than the
last one.  It also has the side benefit that myfun(2) will return 0
instead of numeric(0) (or something similar).  On my machine:

> system.time(for (i in 1:1) erg<-my_fun(c(3, 4, 10,14,8,3,4,6,9)))
[1] 2.860 0.016 2.950 0.000 0.000
> system.time(for (i in 1:1) erg<-myfun1(c(3, 4, 10,14,8,3,4,6,9)))
[1] 0.256 0.000 0.256 0.000 0.000
> system.time(for (i in 1:1) erg<-myfun2(c(3, 4, 10,14,8,3,4,6,9)))
[1] 0.280 0.000 0.283 0.000 0.000

Cheers,

Berwin

=== Full address =
Berwin A TurlachTel.: +65 6515 4416 (secr)
Dept of Statistics and Applied Probability+65 6515 6650 (self)
Faculty of Science  FAX : +65 6872 3919   
National University of Singapore 
6 Science Drive 2, Blk S16, Level 7  e-mail: [EMAIL PROTECTED]
Singapore 117546http://www.stat.nus.edu.sg/~statba

__
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] if else statement

2007-01-18 Thread Sebastian P. Luque
On Thu, 18 Jan 2007 19:02:49 -0800,
"H. Paul Benton" <[EMAIL PROTECTED]> wrote:

> Hello,

> I'm doing some scripting and I've noticed that R doesn't seem to
> have an
> if (cond){
> do
> }ifelse (cond) {
> do
> } else {
> do
> }

> type block.


It's legal to join if else statements together:


if (cond) {
do X
} else if (cond) {
do Y
} else if (cond) {
do Z
} else do W


-- 
Seb

__
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] Problem with loading tkrplot

2007-01-18 Thread jim holtman
On my system it is not set:  so it must be something else.  It happens on
both of my windows systems.  Guess I will have to look somewhere else to see
what might be missing.


> .Platform
$OS.type
[1] "windows"

$file.sep
[1] "/"

$dynlib.ext
[1] ".dll"

$GUI
[1] "Rgui"

$endian
[1] "little"

$pkgType
[1] "win.binary"

$path.sep
[1] ";"

$r_arch
[1] ""

>



On 1/18/07, Duncan Murdoch <[EMAIL PROTECTED]> wrote:
>
> On 1/18/2007 8:57 PM, jim holtman wrote:
> > I asked the maintainer and he indicated that it might be a dll
> problem.  Has
> > anyone see this problem?  I had installed the latest copy of tkrplot.  I
> was
> > trying to use teachingDemos when I first got the error.
>
> I just installed tkrplot in R 2.4.1 and it worked fine.  I've never seen
> the error you're reporting.  However, I see what looks like a typo that
> might affect some systems:
>
> In the tkrplot .First.lib function, I see
>
> > if (is.character(.Platform$r_arch) && .Platform$r_arch !=
> > "")
> > path <- file.path("libs", .Platform$r_arc, dlname)
> > else path <- file.path("libs", dlname)
>
> On the 3rd line, I think .Platform$r_arc should be .Platform$r_arch.  On
> my system I never execute that line, but if .Platform$r_arch is set on
> your system, it would likely cause problems.
>
> Duncan Murdoch
>
> >
> > On 1/18/07, Luke Tierney <[EMAIL PROTECTED]> wrote:
> >
> >> Looks like tcl can't find the dll or something along those lines. As
> >> this is windows you'll have to ask someone who uses that platform
> >> to help figure out why.
> >>
> >> luke
> >>
> >> On Thu, 18 Jan 2007, jim holtman wrote:
> >>
> >>> I was trying to use the teachingDemos package and was getting an error
> >>> trying to load tkrplot.
> >>>
> >>> I downloaded the latest copy and here is what I am getting on the
> >> console.
> >>> You were mentioned as the maintainer on the manual page.  Do you know
> >> why
> >>> this error might be occuring?
> >>>
> >>>
> >>>
>  utils:::menuInstallPkgs()
> >>> --- Please select a CRAN mirror for use in this session ---
> >>> trying URL '
> >>> http://www.stathy.com/cran/bin/windows/contrib/2.4/tkrplot_0.0-16.zip'
> >>> Content type 'application/zip' length 24119 bytes
> >>> opened URL
> >>> downloaded 23Kb
> >>>
> >>> package 'tkrplot' successfully unpacked and MD5 sums checked
> >>>
> >>> The downloaded packages are in
> >>>   C:\Documents and Settings\Compaq_Administrator\Local
> >>> Settings\Temp\RtmpqEShrb\downloaded_packages
> >>> updating HTML package descriptions
>  library(tkrplot)
> >>> Loading required package: tcltk
> >>> Loading Tcl/Tk interface ... done
> >>> Error in structure(.External("dotTcl", ..., PACKAGE = "tcltk"), class
> =
> >>> "tclObj") :
> >>>   [tcl] could not find interpreter "Rplot".
> >>> Error in library(tkrplot) : .First.lib failed for 'tkrplot'
>  sessionInfo()
> >>> R version 2.4.1 (2006-12-18)
> >>> i386-pc-mingw32
> >>>
> >>> locale:
> >>> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
> >>> States.1252;LC_MONETARY=English_United
> >>> States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
> >>>
> >>> attached base packages:
> >>> [1] "tcltk" "stats" "utils"
> >> "datasets"  "graphics"  "grDevices"
> >>> "methods"   "base"
> >>>
> >>>
> >
> >
> >
>
>


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


Re: [R] kate editor for R

2007-01-18 Thread Marc Schwartz
On Thu, 2007-01-18 at 20:30 -0600, Frank E Harrell Jr wrote:
> Like kile for LaTeX, Linux/KDE's kate editor is an excellent editor for 
> R, with easy code submission to a running R process.  Syntax 
> highlighting is good.  I have  not been able to figure out two things:
> 
> - how to automatically reformat a line or region of text using good 
> indentation rules (Emacs/ESS make this so easy by just hitting Tab while 
> the cursor is in a line, or highlighting a region and hitting Esq q)
> 
> - how to cause auto-indenting as you type braces.  For me, kate puts a { 
> in column one
> 
> Thanks for any pointers.

Frank,

I'm not sure if what I found provides an optimistic outlook, however,
you might find the following helpful:

See the questions:

  Can I use different indenters for different files?

  How can I get KatePart to autoindent XXX code?

at http://kate-editor.org/faq.  KatePart is the text editing component
in Kate.

In the two answers, there are links to articles that provide additional
insight into implementing indentation functionality in Kate.

HTH,

Marc

__
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] ability estimate with GRM of IRT

2007-01-18 Thread SHEN,FENG
Hi my friends,

I have an issue with ability estimates when running GRM of IRT.  I 
have responses from 242 subjects but got 183 ability estimates.  
Below is what I did to get the estimates.

1) I have a csv file "P1.csv" and I imported it into R and loaded 
the "ltm" package by doing:
p1<-read.table("P1.csv",header=TRUE,sep=",")
library(ltm)

2) I created a subset that included columns 2 to 9 for the 
analysis by doing:
s1<-p1[,2:9]

3) I converted the subset into data.frame format by doing:
s1df=data.frame(s1)

4) I checked the descriptive stats for the s1df by doing:
ds1df=descript(s1df)
ds1df

And it was confirmed that 242 subjects' responses were imported.

5)I ran GRM on the s1df dataset by doing:
grm<-grm(s1df, Hessian=T)
grm

6)Finally, I ran the ability estimated by doing:
aes1=factor.scores(grm)
aes1

And I got 183 factor-scores for observed response patterns.  
Besides, the 183 estimates are not for the first 183 subjects of 
the 242 because the response patterns of No 1 on the factor-scores 
list do not match those of No 1 in the s1 dataset and the same 
thing holds true for the rest of the response patterns.

Could you help me find out what the problem is?

Many thanks in advance!

Feng

__
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] Problem with loading tkrplot

2007-01-18 Thread Prof Brian Ripley
As it happens I used TeachingDemos/tkrplot on Windows (R 2.4.1) with a 
class example yesterday.

It looks to me as if the issue is in the R installation. Remember that Tcl 
support is optional when R is installed, and can be influenced by 
environment variables.  So my first check would be that the tcltk demos 
all work.

On Thu, 18 Jan 2007, jim holtman wrote:

> I asked the maintainer and he indicated that it might be a dll problem.  Has
> anyone see this problem?  I had installed the latest copy of tkrplot.  I was
> trying to use teachingDemos when I first got the error.
>
> On 1/18/07, Luke Tierney <[EMAIL PROTECTED]> wrote:
>
>> Looks like tcl can't find the dll or something along those lines. As
>> this is windows you'll have to ask someone who uses that platform
>> to help figure out why.
>>
>> luke
>>
>> On Thu, 18 Jan 2007, jim holtman wrote:
>>
>>> I was trying to use the teachingDemos package and was getting an error
>>> trying to load tkrplot.
>>>
>>> I downloaded the latest copy and here is what I am getting on the
>> console.
>>> You were mentioned as the maintainer on the manual page.  Do you know
>> why
>>> this error might be occuring?
>>>
>>>
>>>
 utils:::menuInstallPkgs()
>>> --- Please select a CRAN mirror for use in this session ---
>>> trying URL '
>>> http://www.stathy.com/cran/bin/windows/contrib/2.4/tkrplot_0.0-16.zip'
>>> Content type 'application/zip' length 24119 bytes
>>> opened URL
>>> downloaded 23Kb
>>>
>>> package 'tkrplot' successfully unpacked and MD5 sums checked
>>>
>>> The downloaded packages are in
>>>   C:\Documents and Settings\Compaq_Administrator\Local
>>> Settings\Temp\RtmpqEShrb\downloaded_packages
>>> updating HTML package descriptions
 library(tkrplot)
>>> Loading required package: tcltk
>>> Loading Tcl/Tk interface ... done
>>> Error in structure(.External("dotTcl", ..., PACKAGE = "tcltk"), class =
>>> "tclObj") :
>>>   [tcl] could not find interpreter "Rplot".
>>> Error in library(tkrplot) : .First.lib failed for 'tkrplot'
 sessionInfo()
>>> R version 2.4.1 (2006-12-18)
>>> i386-pc-mingw32
>>>
>>> locale:
>>> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
>>> States.1252;LC_MONETARY=English_United
>>> States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
>>>
>>> attached base packages:
>>> [1] "tcltk" "stats" "utils"
>> "datasets"  "graphics"  "grDevices"
>>> "methods"   "base"

>>>
>>>
>>>
>
>
>
>

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


[R] Vectorize rearrangement within each column

2007-01-18 Thread Osorio Roberto
Consider a matrix like

 > ma = matrix(10:15, nr = 3)
 > ma
  [,1] [,2]
[1,]   10   13
[2,]   11   14
[3,]   12   15

I want to rearrange each column according to row indexes (1 to 3)  
given in another matrix, as in

 > idx = matrix(c(1,3,2, 2,3,1), nr = 3)
 > idx
  [,1] [,2]
[1,]12
[2,]33
[3,]21

The new matrix mb will have for each column the corresponding column  
of ma indexed by the corresponding column of idx, as in

 > mb = ma
 > for (j in 1:2) mb[,j] = ma[idx[,j], j]   
 > mb
  [,1] [,2]
[1,]   10   14
[2,]   12   15
[3,]   11   13

Can I avoid the for() loop? I'm specially interested to find out if a  
fast implementation using lapply() would be feasible for large input  
matrices (analogues of ma and idx) transformed into data frames.

Roberto Osorio

__
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] Reading contingency tables

2007-01-18 Thread Prof Brian Ripley
You cannot seek on a url() connection.  Try downloading the file and 
reading it locally.

There's a bug in the function which forgets to open its temporary file: I 
will attend to that.

On Thu, 18 Jan 2007, Giovanni Petris wrote:

>
> I am trying to read an ftable using read.ftable, but I get the
> following error message:
>
>> jobSatTable <- 
>> read.ftable("http://definetti.uark.edu/~gpetris/stat5333/jobSatisfaction.dat",skip=2)
> Error in seek(file, where = 0) : no applicable method for "seek"
> In addition: Warning messages:
> 1: no non-missing arguments to max; returning -Inf
> 2: no non-missing arguments to max; returning -Inf
>
>
> I also tried to play with the argument col.vars, to remove blank
> lines in the file, to remove the blank in "Not
> satisfied". Unfortunately nothing worked.
>
> Can anybody give me a suggestion on how to read that table?
>
> Thanks in advance,
> Giovanni
>
> ps:
>
>> version
>   _
> platform   sparc-sun-solaris2.8
> arch   sparc
> os solaris2.8
> system sparc, solaris2.8
> status
> major  2
> minor  4.1
> year   2006
> month  12
> day18
> svn rev40228
> language   R
> version.string R version 2.4.1 (2006-12-18)
>
>

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


Re: [R] Reading contingency tables

2007-01-18 Thread Prof Brian Ripley
On Fri, 19 Jan 2007, Prof Brian Ripley wrote:

> You cannot seek on a url() connection.  Try downloading the file and reading 
> it locally.

You will need to edit it to fit the ftable format as well.

> There's a bug in the function which forgets to open its temporary file: I 
> will attend to that.

It was a bit worse than just that: fixed in 2.4.1 patched.

>
> On Thu, 18 Jan 2007, Giovanni Petris wrote:
>
>> 
>> I am trying to read an ftable using read.ftable, but I get the
>> following error message:
>> 
>>> jobSatTable <- 
>>> read.ftable("http://definetti.uark.edu/~gpetris/stat5333/jobSatisfaction.dat",skip=2)
>> Error in seek(file, where = 0) : no applicable method for "seek"
>> In addition: Warning messages:
>> 1: no non-missing arguments to max; returning -Inf
>> 2: no non-missing arguments to max; returning -Inf
>> 
>> 
>> I also tried to play with the argument col.vars, to remove blank
>> lines in the file, to remove the blank in "Not
>> satisfied". Unfortunately nothing worked.
>> 
>> Can anybody give me a suggestion on how to read that table?
>> 
>> Thanks in advance,
>> Giovanni
>> 
>> ps:
>> 
>>> version
>>   _
>> platform   sparc-sun-solaris2.8
>> arch   sparc
>> os solaris2.8
>> system sparc, solaris2.8
>> status
>> major  2
>> minor  4.1
>> year   2006
>> month  12
>> day18
>> svn rev40228
>> language   R
>> version.string R version 2.4.1 (2006-12-18)
>> 
>> 
>
>

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