[R] confusion matrix in randomForest

2008-07-20 Thread Miklos Kiss

I have a question on the output generated by randomForest in classification
mode, specifically, the confusion matrix.  The confusion matrix lists the
various classes and how the forest classified each one, plus the
classification error.  Are these numbers essentially averages over all the
trees in the forest?  If so, is there a way I can get the standard deviation
values out of the randomForest, or do I have to evaluate each tree
individually?  By way of illustration, let me show the confusion matrix
using the iris data.  The output below shows that the forest correctly
classified 47 versicolor irises, but this is the result for the entire
forest.  I'd like to know if every tree will have 47 correctly classified
versicolor irises, but I don't think it will.  Same for the class.error
value.  Not every tree will have those exact same values, right?

But this raises another question.  For this example, I used the entire data
set to generate the forest, and so I assume that the confusion matrix is
based on OOB data, so if I created a training set and evaluated trees
individually in the test set I could get averages and standard deviations on
the error rate.

Any thoughts?  Thanks in advance.

-Miklos Z. Kiss

 print(iris.rf)
Call:
 randomForest(formula = Species ~ ., data = iris, importance = TRUE, 
keep.forest = TRUE) 
   Type of random forest: classification
 Number of trees: 500
No. of variables tried at each split: 2

OOB estimate of  error rate: 5.33%
Confusion matrix:
   setosa versicolor virginica class.error
setosa 50  0 00.00
versicolor  0 47 30.06
virginica   0  5450.10
-- 
View this message in context: 
http://www.nabble.com/confusion-matrix-in-randomForest-tp18550873p18550873.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] problem with read.table

2008-07-20 Thread carol white
Hi,
Although I set check.names to FALSE in read.table, the duplicate names get 
modified. What should be done in this case?

the text file to be read by read.table

AM2  AM2 AM2 FAL
2   3 4 5
1   -1   -3    -2

t = read.table (my_file, check.names = FALSE, header = T)

 t
AM2  AM2.1     AM2.2     FAL

2   3 4 5

1   -1   -3    -2

instead of

AM2  AM2     AM2    FAL


2   3 4 5


1   -1   -3    -2


Best,
carol



  
[[alternative HTML version deleted]]

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


Re: [R] R version 2.7.1 (warnings)

2008-07-20 Thread Van Wyk, Jaap
Thanks, Mark, for the response.
The problem is vith SciViews. It is not stable under the latest version of R.
I found a solution by downloading the latest version of Tinn-R, which 
communicates with the latest version of R, and now I can carry on like normal 
(with both windows tiled horizontally).
 
Jacob
 
 
Jacob L van Wyk
Department of Statistics
University of Johannesburg, APK
Box 524
Auckland Park 2006
South Africa
Office Tel: +27 11 559 3080
Fax: +27 11 559 2832
 

[[alternative HTML version deleted]]

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


Re: [R] Sweave add code \201

2008-07-20 Thread Christophe Genolini

Peter Dalgaard a écrit :

Christophe Genolini wrote:

Hi the list,

I do not understand what change in my configuration, but Sweave add 
the code \201 before each special characters é è à ç ...

Does someone know when it come from ?

MULE  (multilingal environment) in Emacs used to be prone to do this, 
but I haven't seen it for a while, so I'm afraid I have forgotten the 
details (if I ever understood them).


Thanks ! I thaught I had a it was Sweave and thanks to you I start to 
search in emacs.


Christophe

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


Re: [R] R version 2.7.1 (warnings)

2008-07-20 Thread Mark Difford

Hi Jaap,

Great stuff! As the old adage went, Go well, go 

Bye, Mark.


Van Wyk, Jaap wrote:
 
 Thanks, Mark, for the response.
 The problem is vith SciViews. It is not stable under the latest version of
 R.
 I found a solution by downloading the latest version of Tinn-R, which
 communicates with the latest version of R, and now I can carry on like
 normal (with both windows tiled horizontally).
  
 Jacob
  
  
 Jacob L van Wyk
 Department of Statistics
 University of Johannesburg, APK
 Box 524
 Auckland Park 2006
 South Africa
 Office Tel: +27 11 559 3080
 Fax: +27 11 559 2832
  
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 

-- 
View this message in context: 
http://www.nabble.com/R-version-2.7.1-%28warnings%29-tp18542181p18552685.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Discretize continous variables....

2008-07-20 Thread Johannes Huesing
Frank E Harrell Jr [EMAIL PROTECTED] [Sun, Jul 20, 2008 at 12:20:28AM CEST]:
 Johannes Huesing wrote:
 Because regulatory bodies demand it? 
[...]
 
 And how anyway does this  
 relate to predictors in a model?

Not at all; you're correct. I was mixing the topic of this discussion
up with another kind of silliness.

I had a discussion with a biometrician in a pharmaceutical company
though who stated that when you have only one df to spend it will be
better to dichotomise it at a clinically meaningful point than to
include it as a linear term. He kept the discussion on the ground of
laboratory measurements like sodium, where a deviation from normal
ranges is very significant (and unlike, say, cholesterol, where you
have a gradual interpretation of the value). He has a point there, but
in general the reason for sacrificing information is a mixture of
laziness, the preference for presenting data in tables and to keep the
modelling consistent with the tables (for instance to assign an odds
ratio to each cell).
-- 
Johannes Hüsing   There is something fascinating about science. 
  One gets such wholesale returns of conjecture 
mailto:[EMAIL PROTECTED]  from such a trifling investment of fact.  
  
http://derwisch.wikidot.com (Mark Twain, Life on the Mississippi)

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

2008-07-20 Thread carol white

Hi,
Although I set check.names to FALSE in read.table, the duplicate names get 
modified. What should be done in this case?

the text file to be read by read.table

AM2  AM2 AM2 FAL
2   3 4 5
1   -1   -3    -2

t = read.table (my_file,
 check.names = FALSE, header = T)

 t
AM2  AM2.1     AM2.2     FAL

2   3 4 5

1   -1   -3    -2

instead of

AM2  AM2     AM2    FAL


2   3 4 5


1   -1   -3    -2


Best,
carol



  
[[alternative HTML version deleted]]

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


Re: [R] estimating volume from xyz points

2008-07-20 Thread Gabor Grothendieck
On Sat, Jul 19, 2008 at 5:21 PM, milton ruser [EMAIL PROTECTED] wrote:
 Dear all,

 I have several sets of x-y-z points and I need to estimate the volume that
 encompass all my points.
 Recently I got some adivice to show the convex hull of my points using
 geometry package (see code below).
 But now I need to calculate the volume of my set of points.

?convhulln
also in geometry package.

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

2008-07-20 Thread Roger Leenders


R2.7.1, WinXP

Hi,

My question is probably easy to answer, but I can't seem to solve it myself.
I need to read in a large number of datasets that were generated by 
another (old) software program. Each data file contains a bunch of 
additional code generated by the external software. It lists the data 
per respondent. So first the data for respondent 1, then the data for 
respondent 2, et cetera.
After the data for the final respondent, the file contains a , followed 
by some zeroes. R now needs to read the data until the  symbol. 
However, whenever it encounters the  symbol it interprets it as a quit 
command! So, rather than continuing, R wants to quit on me.
How can I make R see the  symbol as just a particular symbol and NOT as 
the command to q()?


Thanks, Roger

ps. I hope the symbol is readable in the various email programs

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

2008-07-20 Thread jim holtman
If you really want to do it, here is a way, but don't expect to be
able to reference the columns by name;  this is just so it 'prints
pretty':

 x - textConnection(AM2  AM2 AM2 FAL
+ 2   3 4 5
+ 1   -1   -3-2)
 # read the header row
 header - read.table(x, as.is=TRUE, nrows=1)
 # read in the rest of the data
 myData - read.table(x, header=FALSE)
 # put header on the table
 colnames(myData) - header
 myData
  AM2 AM2 AM2 FAL
1   2   3   4   5
2   1  -1  -3  -2
 myData$AM2  # only gives the first column
[1] 2 1




On Sun, Jul 20, 2008 at 3:45 AM, carol white [EMAIL PROTECTED] wrote:
 Hi,
 Although I set check.names to FALSE in read.table, the duplicate names get 
 modified. What should be done in this case?

 the text file to be read by read.table

 AM2  AM2 AM2 FAL
 2   3 4 5
 1   -1   -3-2

 t = read.table (my_file, check.names = FALSE, header = T)

 t
 AM2  AM2.1 AM2.2 FAL

 2   3 4 5

 1   -1   -3-2

 instead of

 AM2  AM2 AM2FAL


 2   3 4 5


 1   -1   -3-2


 Best,
 carol




[[alternative HTML version deleted]]


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





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

What is the problem you are trying to solve?

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


Re: [R] R interprets symbol as q()

2008-07-20 Thread jim holtman
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.  It
would be nice to see at least a subset of the data you are reading.  I
would assume that if you are using 'read.table' to read in the data,
then there is no reason for interpreting 'q()' as a quit command.  Are
you 'source'ing the data?  So an example of both the script and the
data are required to understand the problem you are trying to solve.

On Sun, Jul 20, 2008 at 6:41 AM, Roger Leenders [EMAIL PROTECTED] wrote:

 R2.7.1, WinXP

 Hi,

 My question is probably easy to answer, but I can't seem to solve it myself.
 I need to read in a large number of datasets that were generated by another
 (old) software program. Each data file contains a bunch of additional code
 generated by the external software. It lists the data per respondent. So
 first the data for respondent 1, then the data for respondent 2, et cetera.
 After the data for the final respondent, the file contains a  , followed by
 some zeroes. R now needs to read the data until the   symbol. However,
 whenever it encounters the   symbol it interprets it as a quit command! So,
 rather than continuing, R wants to quit on me.
 How can I make R see the   symbol as just a particular symbol and NOT as the
 command to q()?

 Thanks, Roger

 ps. I hope the symbol is readable in the various email programs

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

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


Re: [R] Parametric survival models with left truncated, right censored data

2008-07-20 Thread Göran Broström
I uploaded eha-1.2-0 to CRAN a day ago. This version can handle
accelerated failure time and proportional hazards parametric models
for right censored, left truncated, and stratified data. Included
distributions are: Weibull, lognormal, loglogistic, Gompertz, and
extreme value. The new inner structure of eha makes it very simple
(for me) to add families of distributions of a shape-scale type (i.e.
the distribution of the log of the baseline survival time is a
location-scale family). Suggestions are welcome. The Gompertz and
Gompertz-Makeham families of distributions are unfortunately not of
this type. While the Gompertz case could be solved by a trick
(always include an intercept in the regression model), the
Gompertz-Makeham case is harder. Needs special treatment; hints are
welcome.

With the possibility of keeping the shape parameter(s) fixed, special
cases of the abovementioned distributions are also possible to fit,
e.g., the exponential (Weibull with shape = 1).

Göran

On Wed, Jan 23, 2008 at 5:46 PM, Beth Ireland [EMAIL PROTECTED] wrote:
 Dear All,

 I would like to fit some parametric survival models using left
 truncated, right censored data in R. However I am having problems
 finding a function to fit parametric survival models which can handle
 left truncated data.

 I have tested both the survreg function in package survival:

 fit1 - survreg(Surv(start, stop, status) ~ X + Y + Z, data=data1)

 and the psm function in package Design:

 fit2 - psm(Surv(start, stop, status) ~ X + Y + Z, data=data1)


 But neither function appears to work with left truncated data. The error
 message Invalid survival type is received for both functions when left
 truncated data is specified.

 The function weibreg in the eha package fits Weibull survival models and
 works with left truncated data. This function is useful, but I need to
 fit parametric models other than Weibull.

 Any suggestions of functions that can fit parametric survival models
 other than Weibull on left truncated, right censored data would be
 greatly appreciated.

 Kind Regards,

 Beth
 
 Hymans Robertson LLP is a limited liability partnership registered in
 England and Wales with registered number OC310282. A list of members
 of Hymans Robertson LLP is available for inspection at One London
 Wall, London, EC2Y 5EA, the firm's registered office. Hymans
 Robertson LLP is authorised and regulated by the Financial Services
 Authority. Certain regulated services are provided by Hymans
 Robertson Financial Services LLP, a subsidiary of Hymans Robertson
 LLP. Hymans Robertson Financial Services LLP is a limited liability
 partnership registered in England and Wales with registered number
 OC310836. A list of members of Hymans Robertson Financial Services
 LLP is available for inspection at One London Wall, London, EC2Y 5EA,
 the firm's registered office.  Hymans Robertson Financial Services
 LLP is authorised and regulated by the Financial Services Authority.
 This e-mail and any attachments are confidential. If it ...{{dropped:9}}

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




-- 
Göran Broström
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Error in edit(name,file,title,editor)

2008-07-20 Thread David Epstein
Can anyone help me with the following attempt to use an external  
editor from within R


 vi(file=p286.R)
Error in edit(name, file, title, editor) : unable to open file to read
 edit(file=p286.R)
Error in edit(name, file, title, editor) : unable to open file to read

I have only recently re-started trying to learn R. (I tried before  
but failed.)
I am working with a Mac MacOsX 10.4.11. I have R 2.7.1 GUI 1.25  
(5166) which is the Cocoa version of R.
I have been reading Peter Dalgaard's book, which is very helpful, and  
I have not met any errors so far, so I don't understand why I should  
suddenly hit this one.


Since edit and vi appear to be in the utils package, I did
 library(utils)
to which I got a null response.

I have searched the R-help-archives for the error message, and have  
not found it.


I suppose I could use the function source(), but I haven't tried this.

Thanks for any help

David Epstein

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Order of columns(variables) in dataframe

2008-07-20 Thread Daniel Wagner
Dear R experts,
 
I have a dataframe with 4 columns (variables). I want to redorder (or 
reposition) these columns on the basis of a value in its last row. e.g.
 
df1-data.frame( v1= c(2,3,1,9,5), v2=c(8,5,12,4,11), v3=c(7,8,2,6,9), 
v4=c(1,4,6,3,6)) 
 
 df1
   v1 v2 v3 v4
1  2  8  7  1
2  3  5  8  4
3  1 12  2  6
4  9  4  6  3
5  5 11  9  6

I wanto to get the order of df1 on the basis of value in last row (descending 
order) like
 
   v2 v3 v4 v1
1  8  7  1  2
2  5  8  4  3
3 12  2  6  1
4  4  6  3  9
5 11  9  6  5
 
Could somebody help me?
 
Daniel
Amsterdam
 

 
 
 

Send instant messages to your online friends http://uk.messenger.yahoo.com 
[[alternative HTML version deleted]]

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


Re: [R] Order of columns(variables) in dataframe

2008-07-20 Thread jim holtman
Is this what you want:

 x - read.table(textConnection(   v1 v2 v3 v4
+ 1  2  8  7  1
+ 2  3  5  8  4
+ 3  1 12  2  6
+ 4  9  4  6  3
+ 5  5 11  9  6), header=TRUE)
 closeAllConnections()
 # order by the last row
 x[, order(unlist(x[5,]), decreasing=TRUE)]
  v2 v3 v4 v1
1  8  7  1  2
2  5  8  4  3
3 12  2  6  1
4  4  6  3  9
5 11  9  6  5


On Sun, Jul 20, 2008 at 7:32 AM, Daniel Wagner [EMAIL PROTECTED] wrote:
 Dear R experts,

 I have a dataframe with 4 columns (variables). I want to redorder (or 
 reposition) these columns on the basis of a value in its last row. e.g.

 df1-data.frame( v1= c(2,3,1,9,5), v2=c(8,5,12,4,11), v3=c(7,8,2,6,9), 
 v4=c(1,4,6,3,6))

 df1
v1 v2 v3 v4
 1  2  8  7  1
 2  3  5  8  4
 3  1 12  2  6
 4  9  4  6  3
 5  5 11  9  6

 I wanto to get the order of df1 on the basis of value in last row (descending 
 order) like

v2 v3 v4 v1
 1  8  7  1  2
 2  5  8  4  3
 3 12  2  6  1
 4  4  6  3  9
 5 11  9  6  5

 Could somebody help me?

 Daniel
 Amsterdam






 Send instant messages to your online friends http://uk.messenger.yahoo.com
[[alternative HTML version deleted]]


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





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

What is the problem you are trying to solve?

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


Re: [R] Error in edit(name,file,title,editor)

2008-07-20 Thread jim holtman
Make sure you are in the right directory; you can also use the full
path names.  It is basically saying it can not find the file.  Do
'list.files()' to see what is addressable in whatever directory you
are in.

On Sun, Jul 20, 2008 at 7:19 AM, David Epstein
[EMAIL PROTECTED] wrote:
 Can anyone help me with the following attempt to use an external editor from
 within R

 vi(file=p286.R)
 Error in edit(name, file, title, editor) : unable to open file to read
 edit(file=p286.R)
 Error in edit(name, file, title, editor) : unable to open file to read

 I have only recently re-started trying to learn R. (I tried before but
 failed.)
 I am working with a Mac MacOsX 10.4.11. I have R 2.7.1 GUI 1.25 (5166) which
 is the Cocoa version of R.
 I have been reading Peter Dalgaard's book, which is very helpful, and I have
 not met any errors so far, so I don't understand why I should suddenly hit
 this one.

 Since edit and vi appear to be in the utils package, I did
 library(utils)
 to which I got a null response.

 I have searched the R-help-archives for the error message, and have not
 found it.

 I suppose I could use the function source(), but I haven't tried this.

 Thanks for any help

 David Epstein

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

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


Re: [R] Order of columns(variables) in dataframe

2008-07-20 Thread Dimitris Rizopoulos

try this:

df1 - data.frame(v1 = c(2,3,1,9,5), v2 = c(8,5,12,4,11), v3 =  
c(7,8,2,6,9), v4 = c(1,4,6,3,6))

vals - unlist(df1[5, ])
df1[order(vals, decreasing = TRUE)]


I hope it helps.

Best,
Dimitris


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

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://perswww.kuleuven.be/dimitris_rizopoulos/


Quoting Daniel Wagner [EMAIL PROTECTED]:


Dear R experts,
 I have a dataframe with 4 columns (variables). I want to redorder  
 (or reposition) these columns on the basis of a value in its last   
row. e.g.
 df1-data.frame( v1= c(2,3,1,9,5), v2=c(8,5,12,4,11),   
v3=c(7,8,2,6,9), v4=c(1,4,6,3,6))Â Â

df1

   v1 v2 v3 v4
1Â  2Â  8Â  7Â  1
2Â  3Â  5Â  8Â  4
3Â  1 12Â  2Â  6
4Â  9Â  4Â  6Â  3
5Â  5 11Â  9Â  6

I wanto to get the order of df1 on the basis of value in last row   
(descending order) like

    v2 v3 v4 v1
1Â  8Â  7Â  1Â  2
2Â  5Â  8Â  4Â  3
3 12Â  2Â  6Â  1
4Â  4Â  6Â  3Â  9
5 11Â  9Â  6Â  5
 Could somebody help me?
 Daniel
Amsterdam
    Send instant messages to your online friends  
http://uk.messenger.yahoo.com

[[alternative HTML version deleted]]






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

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


Re: [R] Order of columns(variables) in dataframe

2008-07-20 Thread Ted Harding
On 20-Jul-08 11:32:14, Daniel Wagner wrote:
 Dear R experts,
 I have a dataframe withÂ_4 columns (variables). I want to redorder (or
 reposition) these columns on the basis of a value in its last row. e.g.
 df1-data.frame( v1= c(2,3,1,9,5), v2=c(8,5,12,4,11), v3=c(7,8,2,6,9),
 v4=c(1,4,6,3,6))
 
 I wanto to get the order of df1 on the basis of value in last row
 (descending order) like
 
 [Sorry, had to delete your examples because of intrusive special
  characters, but reproduced below anyway]
 
 Could somebody help me?
 Daniel
 Amsterdam

Try the following. It seems one needs to pass from dataframe to
matrix, since sort() does not like lists! Maybe others know better ...

  df1-data.frame( v1= c(2,3,1,9,5), v2=c(8,5,12,4,11),
v3=c(7,8,2,6,9), v4=c(1,4,6,3,6))
  df1
#   v1 v2 v3 v4
# 1  2  8  7  1
# 2  3  5  8  4
# 3  1 12  2  6
# 4  9  4  6  3
# 5  5 11  9  6

  M-as.matrix(df1)
  L-M[nrow(M),]

  ix-sort(L,decreasing=TRUE,index.return=TRUE)$ix
  df2-as.data.frame(M[,ix])
  df2
#   v2 v3 v4 v1
# 1  8  7  1  2
# 2  5  8  4  3
# 3 12  2  6  1
# 4  4  6  3  9
# 5 11  9  6  5


Hoping this helps,
Ted.


E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 094 0861
Date: 20-Jul-08   Time: 12:52:12
-- XFMail --

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


Re: [R] calculate differences - strange outcome

2008-07-20 Thread Bernardo Rangel Tura
Em Qui, 2008-07-17 às 11:47 +0200, Kunzler, Andreas escreveu:
 Dear List,
 
 I ran into some trouble by calculating differences. For me it is
 important that differences are either 0 or not.
 
 So I don't understand the outcome of this calculation
 
 865.56-(782.86+0+63.85+18.85+0)
 [1] -1.136868e-13
 
 I run R version 2.71 on WinXP

Hi Andreas Kunzler,

Your problem is cause by numeric represntation in computer
(Floating-Point numbers) and this topic is explain in R FAQ 7.31

But the solution for your calculations is possible using the guard
digits approach, so  if you needd solve:

865.56-(782.86+0+63.85+18.85+0)

Using 

865.56/100 -(782.86+0+63.85+18.85+0)/100

More details in http://docs.sun.com/source/806-3568/ncg_goldberg.html
(This links is indicated in R FAQ 7.31)


-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil

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


Re: [R] Error in edit(name,file,title,editor)

2008-07-20 Thread David Epstein
Thanks. The file didn't exist at the time I tried edit, and that  
was my error.

David

On 20 Jul, 2008, at 12:44, jim holtman wrote:


Make sure you are in the right directory; you can also use the full
path names.  It is basically saying it can not find the file.  Do
'list.files()' to see what is addressable in whatever directory you
are in.

On Sun, Jul 20, 2008 at 7:19 AM, David Epstein
[EMAIL PROTECTED] wrote:
Can anyone help me with the following attempt to use an external  
editor from

within R


vi(file=p286.R)
Error in edit(name, file, title, editor) : unable to open file to  
read

edit(file=p286.R)
Error in edit(name, file, title, editor) : unable to open file to  
read


I have only recently re-started trying to learn R. (I tried before  
but

failed.)
I am working with a Mac MacOsX 10.4.11. I have R 2.7.1 GUI 1.25  
(5166) which

is the Cocoa version of R.
I have been reading Peter Dalgaard's book, which is very helpful,  
and I have
not met any errors so far, so I don't understand why I should  
suddenly hit

this one.

Since edit and vi appear to be in the utils package, I did

library(utils)

to which I got a null response.

I have searched the R-help-archives for the error message, and  
have not

found it.

I suppose I could use the function source(), but I haven't tried  
this.


Thanks for any help

David Epstein

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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] drawing segments through points with pch=1

2008-07-20 Thread David Epstein

Please excuse me for asking such basic questions:

Here is my code

y=c(1.21,0.51,0.14,1.62,-0.8,0.72,-1.71,0.84,0.02,-0.12)
ybar=mean(y)
ll=length(y);
ybarv=rep(ybar,ll)
x=1:ll
plot(x,ybarv,pch=1)
segments(x[1],ybar,x[ll],ybar)


What I get is a collection of small circles, with a segment on top  
of the circles, which is almost what I want. But I don't want the  
segment to be visible inside any small circle.


Is there an easy way to arrange for the segment to lie behind the  
pch=1 markers, as in hidden line removal, so that the circles remain  
with nothing inside them? I tried putting the segments command first,  
but then no segment appeared at all.


In general, is there a method of laying a drawing on top of  
another. I tried inserting add=T as an argument to plot, and R  
objected strongly.


Thanks for any help

David Epstein

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


Re: [R] drawing segments through points with pch=1

2008-07-20 Thread Paul Smith
On Sun, Jul 20, 2008 at 1:44 PM, David Epstein
[EMAIL PROTECTED] wrote:
 Please excuse me for asking such basic questions:

 Here is my code

 y=c(1.21,0.51,0.14,1.62,-0.8,0.72,-1.71,0.84,0.02,-0.12)
 ybar=mean(y)
 ll=length(y);
 ybarv=rep(ybar,ll)
 x=1:ll
 plot(x,ybarv,pch=1)
 segments(x[1],ybar,x[ll],ybar)

 What I get is a collection of small circles, with a segment on top of the
 circles, which is almost what I want. But I don't want the segment to be
 visible inside any small circle.

 Is there an easy way to arrange for the segment to lie behind the pch=1
 markers, as in hidden line removal, so that the circles remain with nothing
 inside them? I tried putting the segments command first, but then no segment
 appeared at all.

 In general, is there a method of laying a drawing on top of another. I
 tried inserting add=T as an argument to plot, and R objected strongly.

What about replacing

segments(x[1],ybar,x[ll],ybar)
plot(x,ybarv,pch=1)

with

plot(x,ybarv,type=b)

?

Paul

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


Re: [R] Discretize continous variables....

2008-07-20 Thread Frank E Harrell Jr

Johannes Huesing wrote:

Frank E Harrell Jr [EMAIL PROTECTED] [Sun, Jul 20, 2008 at 12:20:28AM CEST]:

Johannes Huesing wrote:
Because regulatory bodies demand it? 

[...]
And how anyway does this  
relate to predictors in a model?


Not at all; you're correct. I was mixing the topic of this discussion
up with another kind of silliness.

I had a discussion with a biometrician in a pharmaceutical company
though who stated that when you have only one df to spend it will be
better to dichotomise it at a clinically meaningful point than to
include it as a linear term. He kept the discussion on the ground of
laboratory measurements like sodium, where a deviation from normal
ranges is very significant (and unlike, say, cholesterol, where you
have a gradual interpretation of the value). He has a point there, but
in general the reason for sacrificing information is a mixture of
laziness, the preference for presenting data in tables and to keep the
modelling consistent with the tables (for instance to assign an odds
ratio to each cell).


Nice points.  I think the desire to be able to present things in tables 
is a major reason.


The biometrician's idea that a piecewise flat line with one jump will 
fit a dataset better than a linear effect is quite a leap in logic.  If 
I only have one d.f. to spend I'll take linear any day, but better to 
spend a little more and fit a smooth nonlinear relationship.  A coherent 
approach is to shrink the fit down to the effective number of parameters 
the dataset will support estimating.


There is no clinical laboratory measure that has a jump discontinuity in 
its effect on mortality or other patient outcomes.  The fact that 
reference ranges exist (which are based only on supposedly normal 
subjects and don't related to the risk of an outcome) doesn't mean we 
should use them in formulated independent or dependent variables.


It is common but distorted logic to want to make an odds ratio in a 
model be comparable to one in a table from which regression coefficients 
were just anti-logged (so that 1-unit changes could be used).  The 
tabled odds ratio is a kind of crude population averaged odds ratio that 
may not apply to a single subject in the study.


My book has many examples where laboratory measurements are related to 
risk using restricted cubic splines.


Frank


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

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


Re: [R] drawing segments through points with pch=1

2008-07-20 Thread Prof Brian Ripley

On Sun, 20 Jul 2008, Uwe Ligges wrote:

You probably want to make your code readable, read ?points and go ahead by 
making the plot without points (plot(., type=n)), drawing segments and 
at the end paint points with white background colour in order to overwrite 
the segments:


Except that the background is not necessarily white (and you may want it 
to be transparent or translucent).


It looks to me like lines(type=b) might be what was wanted.



y - c(1.21, 0.51, 0.14, 1.62, -0.8,
  0.72, -1.71, 0.84, 0.02, -0.12)
ybar - mean(y)
ll - length(y)
ybarv - rep(ybar, ll)
x - 1:ll
plot(x, ybarv, type=n)
segments(x[1], ybar, x[ll], ybar)
points(x, ybarv, pch=21, bg=white)



Uwe Ligges



David Epstein wrote:

Please excuse me for asking such basic questions:

Here is my code

y=c(1.21,0.51,0.14,1.62,-0.8,0.72,-1.71,0.84,0.02,-0.12)
ybar=mean(y)
ll=length(y);
ybarv=rep(ybar,ll)
x=1:ll
plot(x,ybarv,pch=1)
segments(x[1],ybar,x[ll],ybar)


What I get is a collection of small circles, with a segment on top of the 
circles, which is almost what I want. But I don't want the segment to be 
visible inside any small circle.


Is there an easy way to arrange for the segment to lie behind the pch=1 
markers, as in hidden line removal, so that the circles remain with nothing 
inside them? I tried putting the segments command first, but then no 
segment appeared at all.


In general, is there a method of laying a drawing on top of another. I 
tried inserting add=T as an argument to plot, and R objected strongly.


Thanks for any help

David Epstein

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

and provide commented, minimal, self-contained, reproducible code.


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



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

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


Re: [R] drawing segments through points with pch=1

2008-07-20 Thread David Epstein
What I don't like about type=b, also suggested by Paul Smith, is  
that the segments do not go right up to the little circles---a gap is  
left, which I don't like. So far, Uwes' solution is what suits me  
best. However, I understand Brian's objection, though it doesn't  
apply in my case. The discussion makes me fear that it's a very long  
road ahead before I can get fine control of R graphics.


Thanks
David

On 20 Jul, 2008, at 14:54, Prof Brian Ripley wrote:


On Sun, 20 Jul 2008, Uwe Ligges wrote:

You probably want to make your code readable, read ?points and go  
ahead by making the plot without points (plot(., type=n)),  
drawing segments and at the end paint points with white background  
colour in order to overwrite the segments:


Except that the background is not necessarily white (and you may  
want it to be transparent or translucent).


It looks to me like lines(type=b) might be what was wanted.



y - c(1.21, 0.51, 0.14, 1.62, -0.8,
  0.72, -1.71, 0.84, 0.02, -0.12)
ybar - mean(y)
ll - length(y)
ybarv - rep(ybar, ll)
x - 1:ll
plot(x, ybarv, type=n)
segments(x[1], ybar, x[ll], ybar)
points(x, ybarv, pch=21, bg=white)



Uwe Ligges



David Epstein wrote:

Please excuse me for asking such basic questions:
Here is my code

y=c(1.21,0.51,0.14,1.62,-0.8,0.72,-1.71,0.84,0.02,-0.12)
ybar=mean(y)
ll=length(y);
ybarv=rep(ybar,ll)
x=1:ll
plot(x,ybarv,pch=1)
segments(x[1],ybar,x[ll],ybar)
What I get is a collection of small circles, with a segment on  
top of the circles, which is almost what I want. But I don't  
want the segment to be visible inside any small circle.
Is there an easy way to arrange for the segment to lie behind  
the pch=1 markers, as in hidden line removal, so that the circles  
remain with nothing inside them? I tried putting the segments  
command first, but then no segment appeared at all.
In general, is there a method of laying a drawing on top of  
another. I tried inserting add=T as an argument to plot, and R  
objected strongly.

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

and provide commented, minimal, self-contained, reproducible code.


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

and provide commented, minimal, self-contained, reproducible code.



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


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


Re: [R] R interprets symbol as q()

2008-07-20 Thread Dieter Menne
Roger Leenders r.t.a.j.leenders at rug.nl writes:

 After the data for the final respondent, the file contains a , followed 
 by some zeroes. R now needs to read the data until the  symbol. 

The symbol is not readable in my viewer, but try the following: put it into the
clipboard, and paste it into the GUI (assuming Windows). In an earlier version,
I had a similar case with Chinese characters that closed the application when
pasted. The error was corrected within hours by B.Ripley.

Dieter

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


Re: [R] smooth.spline

2008-07-20 Thread Spencer Graves
 Are you aware that there are many different kinds of splines?  
With spline and splinefun, you can use method = fmm (Forsyth, 
Malcolm and Moler), natural, or periodic.  I'm not familiar with 
fmm, but it seems to be adequately explained by the Manual spline 
evaluation you quoted from the documentation. 

 Natural splines are perhaps the simplest:  I(x-x0)*(x-x0)^j, where 
x0 is a knot, and I(z) = 1 if z0 and 0 otherwise. 

 However, computations using natural splines are numerically 
unstable.  The standard solution to this problem is to use B-splines, 
which are 0 outside a finite interval. 

 Let's look at your example: 


n - 9
x - 1:n
y - rnorm(n)
plot(x, y, main = paste(spline[fun](.) through, n, points))
spl - smooth.spline(x,y)
lines(spl)

 The 'smooth.spline' function uses B-splines.  To see what they 
look like, let's do the following: 


library(fda)
Bspl.basis - create.bspline.basis(unique(spl$fit$knot))

# Check to make sure: 
all.equal(knots(Bspl.basis, interior=FALSE), spl$fit$knot)

# TRUE

# What do B-splines look like? 
plot(Bspl.basis)

abline(v=knots(Bspl.basis), lty='dotted', col='red')
#  7 interior knots, 2 end knots replicated 4 times each, for a spline 
of order 4, degree 3 (cubic splines) 
# total of 15 knots
# Each spline uses 5 consecutive knots, which means there will be 11 
basis functions. 

# NOTE:  'smooth.spline' rescaled the interval [1, 9] to [0, 1]. 
# Evaluate the 11 B-splines at 'x'

Bspl.basis.x - eval.basis((x-1)/8, Bspl.basis)

round(Bspl.basis.x, 4)

# Now the manual computation: 
y.spl - Bspl.basis.x %*% spl$fit$coef


# Plot to confirm: 
plot(x, y, main = paste(spline[fun](.) through, n, points))

spl.xy - spline(x, y)
lines(spl.xy)
points(x, y.spl, pch=2, col='red')

 Hope this helps. 
 Spencer


[EMAIL PROTECTED] wrote:

Fair enough. FOr a spline interpolation I can do the following:

  

n - 9
x - 1:n
y - rnorm(n)
plot(x, y, main = paste(spline[fun](.) through, n, points))
lines(spline(x, y))



Then look at the coefficients generated as:

  

f - splinefun(x, y)
ls(envir = environment(f))

[1] ties ux   z   
  

splinecoef - get(z, envir = environment(f))
slinecoef


$method
[1] 3

$n
[1] 9

$x
[1] 1 2 3 4 5 6 7 8 9

$y
[1]  0.93571604  0.44240485  0.45451903 -0.96207396 -1.13246522 -0.60032698
[7] -1.77506105 -0.09171419 -0.23262573

$b
[1] -1.53673409  0.22775629 -0.81788209 -1.16966436  0.73558677 -0.68744178
[7]  0.08639287  1.86770869 -2.92992167

$c
[1]  1.3657783  0.3987121 -1.4443504  1.0925682  0.8126830 -2.2357115  3.0095462
[8] -1.2282303 -3.5694000

$d
[1] -0.32235542 -0.61435416  0.84563953 -0.09329507 -1.01613149  1.74841922
[7] -1.41259217 -0.78038989 -0.78038989

WHen I look at ?spline there is even an example of manually using these 
coefficeients:

## Manual spline evaluation --- demo the coefficients :
.x - get(ux, envir = environment(f))
u - seq(3,6, by = 0.25)
(ii - findInterval(u, .x))
dx - u - .x[ii]
f.u - with(splinecoef,
y[ii] + dx*(b[ii] + dx*(c[ii] + dx* d[ii])))
stopifnot(all.equal(f(u), f.u))


For the smooth.spline as

spl - smooth.spline(x,y)

I can also look at the coefficients:

spl$fit
$knot
 [1] 0.000 0.000 0.000 0.000 0.125 0.250 0.375 0.500 0.625 0.750 0.875 1.000
[13] 1.000 1.000 1.000

$nk
[1] 11

$min
[1] 1

$range
[1] 8

$coef
 [1]  0.90345898  0.73823276  0.40777431 -0.08046715 -0.54625461 -0.85205147
 [7] -0.96233408 -0.91373830 -0.66529714 -0.47674774 -0.38246971

attr(,class)
[1] smooth.spline.fit

But there isn't an example on how to manual use these coefficients. This is what I was 
asking about. Once I hae the coefficients how do I manually interpolate using the 
coefficients given and x.

Thank you.

Kevin


 Spencer Graves [EMAIL PROTECTED] wrote: 
  
  PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html and provide commented, 
minimal, self-contained, reproducible code.


  I do NOT know how to do what you want, but with a self-contained 
example, I suspect many people on this list -- probably including me -- 
could easily solve the problem.  Without such an example, there is a 
high probability that any answer might (a) not respond to your need, and 
(b) take more time to develop, just because we don't know enough of what 
you are asking. 


  Spencer

[EMAIL PROTECTED] wrote:


Like I indicated. I understand the coefficients in a B-spline context. If I use 
the the 'spline' or 'splinefun' I can get the coefficients and they are grouped 
as 'a', 'b', 'c', and 'd' coefficients. But the coefficients for smooth.spline 
is just an array. I basically want to take these coefficients and outside of 
'R' use them to form an interpolation. In other words I want 'R' to do the hard 
work and then export the results so they can be used else where.

Thank you.

Kevin
  
  

Spencer Graves wrote:

 I believe that a short answer to your question is that the 
smooth is a linear combination of B-spline basis 

Re: [R] principal factor analysis

2008-07-20 Thread Hans W. Borchers
Jinsong Zhao jszhao at mail.hzau.edu.cn writes:

 
 Hi,
 
 Is there a function to do principal factor analysis in R?

Do a 'RSiteSearch(factor analysis)' and you will find several packages for
Factor Analysis, such as:

FAiRFactor Analysis in R
FactoMineR  Factor Analysis and Data Mining with R

or  factor.pa(), Principal Axis Factor Analysis, in package 'psych'.

It seems, 'common factors' is a more colloquial term used in PCA books, or did
you mean to compare 'principal components' with 'principal factors'?
 
 I am reading through ``A user's guide to principal components'' by J. E.
 Jackson. In Table 17.1, a comparison between principal components and
 common factors, and there is obvious difference between them. However, I
 don't know how to get the common factors.
 
 Any suggestions? Thanks!
 
 Jinsong


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


Re: [R] smooth.spline

2008-07-20 Thread Duncan Murdoch

On 20/07/2008 11:11 AM, Spencer Graves wrote:
  Are you aware that there are many different kinds of splines?  
With spline and splinefun, you can use method = fmm (Forsyth, 
Malcolm and Moler), natural, or periodic.  I'm not familiar with 
fmm, but it seems to be adequately explained by the Manual spline 
evaluation you quoted from the documentation. 

  Natural splines are perhaps the simplest:  I(x-x0)*(x-x0)^j, where 
x0 is a knot, and I(z) = 1 if z0 and 0 otherwise. 


That's not what R means by natural spline in this context.  Here it 
means that the function becomes linear outside the range of the knots.


I would call the I(x-x0)*(x-x0)^j splines the truncated power basis 
for polynomial splines; B-splines are a different basis for the same set 
of splines (assuming the knots and degrees match).  Natural splines are 
a subspace of these (since linear functions are a subspace of 
polynomials).  I don't know of a simple basis for them.


Duncan Murdoch



  However, computations using natural splines are numerically 
unstable.  The standard solution to this problem is to use B-splines, 
which are 0 outside a finite interval. 

  Let's look at your example: 


n - 9
x - 1:n
y - rnorm(n)
plot(x, y, main = paste(spline[fun](.) through, n, points))
spl - smooth.spline(x,y)
lines(spl)

  The 'smooth.spline' function uses B-splines.  To see what they 
look like, let's do the following: 


library(fda)
Bspl.basis - create.bspline.basis(unique(spl$fit$knot))

# Check to make sure: 
all.equal(knots(Bspl.basis, interior=FALSE), spl$fit$knot)

# TRUE

# What do B-splines look like? 
plot(Bspl.basis)

abline(v=knots(Bspl.basis), lty='dotted', col='red')
#  7 interior knots, 2 end knots replicated 4 times each, for a spline 
of order 4, degree 3 (cubic splines) 
# total of 15 knots
# Each spline uses 5 consecutive knots, which means there will be 11 
basis functions. 
 
# NOTE:  'smooth.spline' rescaled the interval [1, 9] to [0, 1]. 
# Evaluate the 11 B-splines at 'x'

Bspl.basis.x - eval.basis((x-1)/8, Bspl.basis)

round(Bspl.basis.x, 4)

# Now the manual computation: 
y.spl - Bspl.basis.x %*% spl$fit$coef


# Plot to confirm: 
plot(x, y, main = paste(spline[fun](.) through, n, points))

spl.xy - spline(x, y)
lines(spl.xy)
points(x, y.spl, pch=2, col='red')

  Hope this helps. 
  Spencer


[EMAIL PROTECTED] wrote:

Fair enough. FOr a spline interpolation I can do the following:

  

n - 9
x - 1:n
y - rnorm(n)
plot(x, y, main = paste(spline[fun](.) through, n, points))
lines(spline(x, y))


Then look at the coefficients generated as:

  

f - splinefun(x, y)
ls(envir = environment(f))

[1] ties ux   z   
  

splinecoef - get(z, envir = environment(f))
slinecoef


$method
[1] 3

$n
[1] 9

$x
[1] 1 2 3 4 5 6 7 8 9

$y
[1]  0.93571604  0.44240485  0.45451903 -0.96207396 -1.13246522 -0.60032698
[7] -1.77506105 -0.09171419 -0.23262573

$b
[1] -1.53673409  0.22775629 -0.81788209 -1.16966436  0.73558677 -0.68744178
[7]  0.08639287  1.86770869 -2.92992167

$c
[1]  1.3657783  0.3987121 -1.4443504  1.0925682  0.8126830 -2.2357115  3.0095462
[8] -1.2282303 -3.5694000

$d
[1] -0.32235542 -0.61435416  0.84563953 -0.09329507 -1.01613149  1.74841922
[7] -1.41259217 -0.78038989 -0.78038989

WHen I look at ?spline there is even an example of manually using these 
coefficeients:

## Manual spline evaluation --- demo the coefficients :
.x - get(ux, envir = environment(f))
u - seq(3,6, by = 0.25)
(ii - findInterval(u, .x))
dx - u - .x[ii]
f.u - with(splinecoef,
y[ii] + dx*(b[ii] + dx*(c[ii] + dx* d[ii])))
stopifnot(all.equal(f(u), f.u))


For the smooth.spline as

spl - smooth.spline(x,y)

I can also look at the coefficients:

spl$fit
$knot
 [1] 0.000 0.000 0.000 0.000 0.125 0.250 0.375 0.500 0.625 0.750 0.875 1.000
[13] 1.000 1.000 1.000

$nk
[1] 11

$min
[1] 1

$range
[1] 8

$coef
 [1]  0.90345898  0.73823276  0.40777431 -0.08046715 -0.54625461 -0.85205147
 [7] -0.96233408 -0.91373830 -0.66529714 -0.47674774 -0.38246971

attr(,class)
[1] smooth.spline.fit

But there isn't an example on how to manual use these coefficients. This is what I was 
asking about. Once I hae the coefficients how do I manually interpolate using the 
coefficients given and x.

Thank you.

Kevin


 Spencer Graves [EMAIL PROTECTED] wrote: 
  
  PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html and provide commented, 
minimal, self-contained, reproducible code.


  I do NOT know how to do what you want, but with a self-contained 
example, I suspect many people on this list -- probably including me -- 
could easily solve the problem.  Without such an example, there is a 
high probability that any answer might (a) not respond to your need, and 
(b) take more time to develop, just because we don't know enough of what 
you are asking. 


  Spencer

[EMAIL PROTECTED] wrote:


Like I indicated. I understand the coefficients in a B-spline context. If I use 
the 

[R] Access to values of function arguments

2008-07-20 Thread willemf

Does anyone know of good reading material about the following? The R language
definition does not appear to explicitly address my problem (maybe I misread
that document?)

I have a function definition:

func(a)
  cat(Anova for variable ,a)

What I wish to achieve is to call func with a value such as:
func(Age)

and then obtain:

Anova for variable Age

Using names(formals()) inside function func yields a. That is not what I
need. I need the name contained in a, which in this case is Age.

Thanks for your time.
Willemf

-- 
View this message in context: 
http://www.nabble.com/Access-to-values-of-function-arguments-tp18554602p18554602.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] How do I install Joomla! 1.5?

2008-07-20 Thread Fido
Installing of Joomla! 1.5 is pretty easy. We assume you have set-up
your Web site, and it is accessible with your browser.

Download Joomla! 1.5, unzip it and upload/copy the files into the
directory you Web site points to, fire up your browser and enter your
Web site address and the installation will start.

For full details on the installation processes check out the
Installation Manual on the Joomla! Help Site where you will also find
download instructions for a PDF version too.

http://www.thecodeone.com

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


Re: [R] smooth.spline

2008-07-20 Thread Spencer Graves
in line 


Duncan Murdoch wrote:

On 20/07/2008 11:11 AM, Spencer Graves wrote:
  Are you aware that there are many different kinds of splines?  
With spline and splinefun, you can use method = fmm (Forsyth, 
Malcolm and Moler), natural, or periodic.  I'm not familiar with 
fmm, but it seems to be adequately explained by the Manual spline 
evaluation you quoted from the documentation.
  Natural splines are perhaps the simplest:  I(x-x0)*(x-x0)^j, 
where x0 is a knot, and I(z) = 1 if z0 and 0 otherwise. 


That's not what R means by natural spline in this context.  Here it 
means that the function becomes linear outside the range of the knots.


I would call the I(x-x0)*(x-x0)^j splines the truncated power basis 
for polynomial splines; B-splines are a different basis for the same 
set of splines (assuming the knots and degrees match).  Natural 
splines are a subspace of these (since linear functions are a subspace 
of polynomials).  I don't know of a simple basis for them.
 Thanks for the correction.  I erred by writing this from memory.  
Dierckx (1993, p. 4) says, A natural spline function is a spline of odd 
degree k = 2*m-1 (m=2) which satisfies the additional constraints


(D^(m+j))s(a) = (D^(m+j))s(b) = 0, j = 0, 1, ..., m-2. 

 He further (p. 5) defines the truncated power functions, which 
is what I mistakenly called natural splines. 

 Thanks again for the correction. 
 Spencer


Duncan Murdoch



  However, computations using natural splines are numerically 
unstable.  The standard solution to this problem is to use B-splines, 
which are 0 outside a finite interval.

  Let's look at your example:
n - 9
x - 1:n
y - rnorm(n)
plot(x, y, main = paste(spline[fun](.) through, n, points))
spl - smooth.spline(x,y)
lines(spl)

  The 'smooth.spline' function uses B-splines.  To see what they 
look like, let's do the following:

library(fda)
Bspl.basis - create.bspline.basis(unique(spl$fit$knot))

# Check to make sure: all.equal(knots(Bspl.basis, interior=FALSE), 
spl$fit$knot)

# TRUE

# What do B-splines look like? plot(Bspl.basis)
abline(v=knots(Bspl.basis), lty='dotted', col='red')
#  7 interior knots, 2 end knots replicated 4 times each, for a 
spline of order 4, degree 3 (cubic splines) # total of 15 knots
# Each spline uses 5 consecutive knots, which means there will be 11 
basis functions.  # NOTE:  'smooth.spline' rescaled the interval 
[1, 9] to [0, 1]. # Evaluate the 11 B-splines at 'x'

Bspl.basis.x - eval.basis((x-1)/8, Bspl.basis)

round(Bspl.basis.x, 4)

# Now the manual computation: y.spl - Bspl.basis.x %*% spl$fit$coef

# Plot to confirm: plot(x, y, main = paste(spline[fun](.) through, 
n, points))

spl.xy - spline(x, y)
lines(spl.xy)
points(x, y.spl, pch=2, col='red')

  Hope this helps.   Spencer

[EMAIL PROTECTED] wrote:

Fair enough. FOr a spline interpolation I can do the following:

 

n - 9
x - 1:n
y - rnorm(n)
plot(x, y, main = paste(spline[fun](.) through, n, points))
lines(spline(x, y))


Then look at the coefficients generated as:

 

f - splinefun(x, y)
ls(envir = environment(f))

[1] ties ux   z

splinecoef - get(z, envir = environment(f))
slinecoef


$method
[1] 3

$n
[1] 9

$x
[1] 1 2 3 4 5 6 7 8 9

$y
[1]  0.93571604  0.44240485  0.45451903 -0.96207396 -1.13246522 
-0.60032698

[7] -1.77506105 -0.09171419 -0.23262573

$b
[1] -1.53673409  0.22775629 -0.81788209 -1.16966436  0.73558677 
-0.68744178

[7]  0.08639287  1.86770869 -2.92992167

$c
[1]  1.3657783  0.3987121 -1.4443504  1.0925682  0.8126830 
-2.2357115  3.0095462

[8] -1.2282303 -3.5694000

$d
[1] -0.32235542 -0.61435416  0.84563953 -0.09329507 -1.01613149  
1.74841922

[7] -1.41259217 -0.78038989 -0.78038989

WHen I look at ?spline there is even an example of manually using 
these coefficeients:


## Manual spline evaluation --- demo the coefficients :
.x - get(ux, envir = environment(f))
u - seq(3,6, by = 0.25)
(ii - findInterval(u, .x))
dx - u - .x[ii]
f.u - with(splinecoef,
y[ii] + dx*(b[ii] + dx*(c[ii] + dx* d[ii])))
stopifnot(all.equal(f(u), f.u))


For the smooth.spline as

spl - smooth.spline(x,y)

I can also look at the coefficients:

spl$fit
$knot
 [1] 0.000 0.000 0.000 0.000 0.125 0.250 0.375 0.500 0.625 0.750 
0.875 1.000

[13] 1.000 1.000 1.000

$nk
[1] 11

$min
[1] 1

$range
[1] 8

$coef
 [1]  0.90345898  0.73823276  0.40777431 -0.08046715 -0.54625461 
-0.85205147

 [7] -0.96233408 -0.91373830 -0.66529714 -0.47674774 -0.38246971

attr(,class)
[1] smooth.spline.fit

But there isn't an example on how to manual use these 
coefficients. This is what I was asking about. Once I hae the 
coefficients how do I manually interpolate using the coefficients 
given and x.


Thank you.

Kevin


 Spencer Graves [EMAIL PROTECTED] wrote:  
  PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html and provide commented, 
minimal, self-contained, reproducible code.


  I do NOT know how to do what you want, but 

Re: [R] Access to values of function arguments

2008-07-20 Thread Prof Brian Ripley

See ?deparse .  E.g. (with several stylistic improvements)

func - function(a)
cat(sprintf(Anova for variable %s\n,
sQuote(deparse(substitute(a)
func(Age)

Note that you expliciltly do not want the *vaiue* of 'a', but the symbol 
passed.  That is non-standard behaviour, and you might want to consider 
why func(Age) is not a better way to do this.


On Sun, 20 Jul 2008, willemf wrote:



Does anyone know of good reading material about the following? The R language
definition does not appear to explicitly address my problem (maybe I misread
that document?)


'S Programming' (see the R FAQ).


I have a function definition:


Well, that is not a function definition: please do use correct and 
reproducible examples as the posting guide asks.




func(a)
 cat(Anova for variable ,a)

What I wish to achieve is to call func with a value such as:
func(Age)

and then obtain:

Anova for variable Age

Using names(formals()) inside function func yields a. That is not what I
need. I need the name contained in a, which in this case is Age.

Thanks for your time.
Willemf



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

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


Re: [R] Access to values of function arguments

2008-07-20 Thread Marc Schwartz

on 07/20/2008 08:42 AM willemf wrote:

Does anyone know of good reading material about the following? The R language
definition does not appear to explicitly address my problem (maybe I misread
that document?)

I have a function definition:

func(a)
  cat(Anova for variable ,a)

What I wish to achieve is to call func with a value such as:
func(Age)

and then obtain:

Anova for variable Age

Using names(formals()) inside function func yields a. That is not what I
need. I need the name contained in a, which in this case is Age.

Thanks for your time.
Willemf



MyFun - function(a) {
   cat(Anova for variable, deparse(substitute(a)), \n)}

Age - 50:60

 MyFun(Age)
Anova for variable Age


The deparse(substitute(...)) idiom is what you are looking for.

See ?deparse and ?substitute

HTH,

Marc Schwartz

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

2008-07-20 Thread Sascha Bellaire
Hello All!
I like to do some indicator kriging with R. 
So far I used geoR for simple and ordinary kriging.
Does anybody know which package I should use?
Thanks for your help!
Sascha!


-- 

Jetzt dabei sein: http://www.shortview.de/[EMAIL PROTECTED]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] fill in area between 2 lines with a color

2008-07-20 Thread David Freedman

Hi - I'd like to have the area between 2 lines on a x-y plot be filled with
grey, but I haven't had
any luck using polygon or rect.  (In reality, I'd like to do this for twice
- once for a low group and once for a high group - and then I'd like to plot
a set of data points for a 'normal' group together with these 2 grey areas.)

Here's a simple example of the 2 lines:
 
age=1:10
y.low=rnorm(length(age),150,25)+10*age
y.high=rnorm(length(age),250,25)+10*age
plot(age,y.high,type='n',ylim=c(100,400),ylab='Y Range',xlab='Age (years)')
lines(age,y.low,col='grey')
lines(age,y.high,col='grey')

Is it possible to fill the area between the 2 lines filled with, for
example, 'grey30' ?

thanks very much in advance,
David Freedman

-
David Freedman
Atlanta
-- 
View this message in context: 
http://www.nabble.com/fill-in-area-between-2-lines-with-a-color-tp18556096p18556096.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Conditionally Updating Lattice Plots

2008-07-20 Thread Bryan Hanson
Hi All...

I can¹t seem to find an answer to this in the help pages, archives, or
Deepayan¹s Lattice Book.

I want to do a Lattice plot, and then update it, possibly more than once,
depending upon some logical options.  Code below; it produces a second plot
page when the second update is called, from which I would infer that you
can't update the update or I'm not calling it correctly.  I have a nagging
sense too that the real way to do this is with a non-standard use of
panel.superpose but I don't quite see how to do that from available
examples.

TIF for any suggestions, Bryan


 Example: a function then, the call to the function

fancy.lm - function(x, y, fit = TRUE, resid = TRUE){

model - lm(y ~ x)

y.pred - predict(model) # Compute residuals for plotting
res.x - as.vector(rbind(x, x, rep(NA,length(x # NAs induce breaks in
line
res.y - as.vector(rbind(y, y.pred, rep(NA,length(x # after Fig 5.1 of
DAAG (clever!)

p - xyplot(y ~ x, pch = 20,
panel = function(...) {
panel.xyplot(...) # not strictly necessary if I understand correctly
})

plot(p, more = TRUE)

if (fit) {
plot(update(p, more = TRUE,
panel = function(...){
panel.xyplot(...)
panel.abline(model, col = red)
}))}

if (resid) {
plot(update(p, more = TRUE,
panel = function(...){
panel.xyplot(res.x, res.y, col = lightblue, type = l)
}))}

}

x - jitter(c(1:10), factor = 5)
y - jitter(c(1:10), factor = 10)
fancy.lm(x, y, fit = TRUE, resid = TRUE)


 Session Info
 sessionInfo()
R version 2.7.1 (2008-06-23)
i386-apple-darwin8.10.1

locale:
en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
 [1] fastICA_1.1-9 DescribeDisplay_0.1.3 ggplot_0.4.2
 [4] RColorBrewer_1.0-2reshape_0.8.0 MASS_7.2-42
 [7] pcaPP_1.5 mvtnorm_0.9-0 hints_1.0.1-1
[10] mvoutlier_1.3 robustbase_0.2-8  lattice_0.17-8
[13] rggobi_2.1.9  RGtk2_2.12.5-3

loaded via a namespace (and not attached):
[1] tools_2.7.1


 

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


[R] Erro updating HTML package descriptions in packages.html

2008-07-20 Thread José Augusto Jr.
Dear all,

I have just installed the new version of R 2.7.1 and when i first
instaled some packages it asked me to create a personal directory.

It installed the packages, but not the html help page (packages.html)

The downloaded packages are in
C:\Users\jamaj\AppData\Local\Temp\Rtmp4MTuXN\downloaded_packages
updating HTML package descriptions
Warning message:
In file.create(f.tg) :
  cannot create file 'C:\PROGRA~1\R\R-27~1.1/doc/html/packages.html',
reason 'Permission denied'


How can i fix the packages.html file to reflect the packages' instalation?

Thanks in advance.

José Augusto M. de Andrade Jr. (jamaj)
Quant. Finance Researcher
FEA-RP - University of São Paulo

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


Re: [R] fill in area between 2 lines with a color

2008-07-20 Thread Dimitris Rizopoulos

try the following:

age - 1:10
y.low - rnorm(length(age), 150, 25) + 10*age
y.high - rnorm(length(age), 250, 25) + 10*age

plot(age,y.high,type = 'n', ylim = c(100, 400),
ylab = 'Y Range', xlab = 'Age (years)')
lines(age, y.low, col = 'grey')
lines(age, y.high, col = 'grey')

polygon(c(age, rev(age)), c(y.high, rev(y.low)),
col = grey30, border = NA)


I hope it helps.

Best,
Dimitris


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

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://perswww.kuleuven.be/dimitris_rizopoulos/


Quoting David Freedman [EMAIL PROTECTED]:



Hi - I'd like to have the area between 2 lines on a x-y plot be filled with
grey, but I haven't had
any luck using polygon or rect.  (In reality, I'd like to do this for twice
- once for a low group and once for a high group - and then I'd like to plot
a set of data points for a 'normal' group together with these 2 grey areas.)

Here's a simple example of the 2 lines:

age=1:10
y.low=rnorm(length(age),150,25)+10*age
y.high=rnorm(length(age),250,25)+10*age
plot(age,y.high,type='n',ylim=c(100,400),ylab='Y Range',xlab='Age (years)')
lines(age,y.low,col='grey')
lines(age,y.high,col='grey')

Is it possible to fill the area between the 2 lines filled with, for
example, 'grey30' ?

thanks very much in advance,
David Freedman

-
David Freedman
Atlanta
--
View this message in context:   
http://www.nabble.com/fill-in-area-between-2-lines-with-a-color-tp18556096p18556096.html

Sent from the R help mailing list archive at Nabble.com.

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






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

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


Re: [R] fill in area between 2 lines with a color

2008-07-20 Thread Marc Schwartz

on 07/20/2008 11:34 AM David Freedman wrote:

Hi - I'd like to have the area between 2 lines on a x-y plot be filled with
grey, but I haven't had
any luck using polygon or rect.  (In reality, I'd like to do this for twice
- once for a low group and once for a high group - and then I'd like to plot
a set of data points for a 'normal' group together with these 2 grey areas.)

Here's a simple example of the 2 lines:
 
age=1:10

y.low=rnorm(length(age),150,25)+10*age
y.high=rnorm(length(age),250,25)+10*age
plot(age,y.high,type='n',ylim=c(100,400),ylab='Y Range',xlab='Age (years)')
lines(age,y.low,col='grey')
lines(age,y.high,col='grey')

Is it possible to fill the area between the 2 lines filled with, for
example, 'grey30' ?

thanks very much in advance,
David Freedman


Try this:


age=1:10

y.low=rnorm(length(age),150,25)+10*age

y.high=rnorm(length(age),250,25)+10*age

plot(age,y.high,type='n',ylim=c(100,400),ylab='Y Range',
 xlab='Age (years)')

lines(age,y.low,col='grey')
lines(age,y.high,col='grey')


polygon(c(age, rev(age), age[1]), c(y.low, rev(y.high), y.low[1]),
col = grey30)


What you essentially need to do is to 'walk' the boundary of the 
polygon, be sure to 'close' the open end by returning to the starting 
point, and then fill it.


HTH,

Marc Schwartz

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


Re: [R] Conditionally Updating Lattice Plots

2008-07-20 Thread Gabor Grothendieck
Try this:

library(lattice)

fancy.lm - function(x, y, fit = TRUE, resid = TRUE){

model - lm(y ~ x)

y.pred - predict(model) # Compute residuals for plotting
res.x - as.vector(rbind(x, x, rep(NA,length(x # NAs induce breaks 
in line
res.y - as.vector(rbind(y, y.pred, rep(NA,length(x # after Fig
5.1 of DAAG (clever!)

plot(xyplot(y ~ x, pch = 20))
trellis.focus()
if (fit) panel.abline(model, col = red)
if (resid) panel.xyplot(res.x, res.y, col = lightblue, type = l)
trellis.unfocus()

}

x - jitter(c(1:10), factor = 5)
y - jitter(c(1:10), factor = 10)
fancy.lm(x, y, fit = TRUE, resid = TRUE)


On Sun, Jul 20, 2008 at 12:44 PM, Bryan Hanson [EMAIL PROTECTED] wrote:
 Hi All...

 I can¹t seem to find an answer to this in the help pages, archives, or
 Deepayan¹s Lattice Book.

 I want to do a Lattice plot, and then update it, possibly more than once,
 depending upon some logical options.  Code below; it produces a second plot
 page when the second update is called, from which I would infer that you
 can't update the update or I'm not calling it correctly.  I have a nagging
 sense too that the real way to do this is with a non-standard use of
 panel.superpose but I don't quite see how to do that from available
 examples.

 TIF for any suggestions, Bryan


  Example: a function then, the call to the function

 fancy.lm - function(x, y, fit = TRUE, resid = TRUE){

 model - lm(y ~ x)

 y.pred - predict(model) # Compute residuals for plotting
 res.x - as.vector(rbind(x, x, rep(NA,length(x # NAs induce breaks in
 line
 res.y - as.vector(rbind(y, y.pred, rep(NA,length(x # after Fig 5.1 of
 DAAG (clever!)

 p - xyplot(y ~ x, pch = 20,
panel = function(...) {
panel.xyplot(...) # not strictly necessary if I understand correctly
})

 plot(p, more = TRUE)

 if (fit) {
plot(update(p, more = TRUE,
panel = function(...){
panel.xyplot(...)
panel.abline(model, col = red)
}))}

 if (resid) {
plot(update(p, more = TRUE,
panel = function(...){
panel.xyplot(res.x, res.y, col = lightblue, type = l)
}))}

 }

 x - jitter(c(1:10), factor = 5)
 y - jitter(c(1:10), factor = 10)
 fancy.lm(x, y, fit = TRUE, resid = TRUE)


  Session Info
 sessionInfo()
 R version 2.7.1 (2008-06-23)
 i386-apple-darwin8.10.1

 locale:
 en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

 other attached packages:
  [1] fastICA_1.1-9 DescribeDisplay_0.1.3 ggplot_0.4.2
  [4] RColorBrewer_1.0-2reshape_0.8.0 MASS_7.2-42
  [7] pcaPP_1.5 mvtnorm_0.9-0 hints_1.0.1-1
 [10] mvoutlier_1.3 robustbase_0.2-8  lattice_0.17-8
 [13] rggobi_2.1.9  RGtk2_2.12.5-3

 loaded via a namespace (and not attached):
 [1] tools_2.7.1




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


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


Re: [R] Erro updating HTML package descriptions in packages.html

2008-07-20 Thread Uwe Ligges



José Augusto Jr. wrote:

Dear all,

I have just installed the new version of R 2.7.1 and when i first
instaled some packages it asked me to create a personal directory.

It installed the packages, but not the html help page (packages.html)

The downloaded packages are in
C:\Users\jamaj\AppData\Local\Temp\Rtmp4MTuXN\downloaded_packages
updating HTML package descriptions
Warning message:
In file.create(f.tg) :
  cannot create file 'C:\PROGRA~1\R\R-27~1.1/doc/html/packages.html',
reason 'Permission denied'


How can i fix the packages.html file to reflect the packages' instalation?



If you need to, run R with privileges that permit write access to that 
file...


Uwe Ligges



Thanks in advance.

José Augusto M. de Andrade Jr. (jamaj)
Quant. Finance Researcher
FEA-RP - University of São Paulo

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


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


Re: [R] Erro updating HTML package descriptions in packages.html

2008-07-20 Thread Gabor Grothendieck
Read the VISTA HOW TO section of this page:
http://batchfiles.googlecode.com


On Sun, Jul 20, 2008 at 12:48 PM, José Augusto Jr. [EMAIL PROTECTED] wrote:
 Dear all,

 I have just installed the new version of R 2.7.1 and when i first
 instaled some packages it asked me to create a personal directory.

 It installed the packages, but not the html help page (packages.html)

 The downloaded packages are in
C:\Users\jamaj\AppData\Local\Temp\Rtmp4MTuXN\downloaded_packages
 updating HTML package descriptions
 Warning message:
 In file.create(f.tg) :
  cannot create file 'C:\PROGRA~1\R\R-27~1.1/doc/html/packages.html',
 reason 'Permission denied'


 How can i fix the packages.html file to reflect the packages' instalation?

 Thanks in advance.

 José Augusto M. de Andrade Jr. (jamaj)
 Quant. Finance Researcher
 FEA-RP - University of São Paulo

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


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


Re: [R] Erro updating HTML package descriptions in packages.html

2008-07-20 Thread José Augusto Jr.
Dear all,

Unfortunately, i´m running as administrator. So, i cannot run R in an
upper level than this one i am already running.

jamaj

2008/7/20 Gabor Grothendieck [EMAIL PROTECTED]:
 Read the VISTA HOW TO section of this page:
 http://batchfiles.googlecode.com


 On Sun, Jul 20, 2008 at 12:48 PM, José Augusto Jr. [EMAIL PROTECTED] wrote:
 Dear all,

 I have just installed the new version of R 2.7.1 and when i first
 instaled some packages it asked me to create a personal directory.

 It installed the packages, but not the html help page (packages.html)

 The downloaded packages are in
C:\Users\jamaj\AppData\Local\Temp\Rtmp4MTuXN\downloaded_packages
 updating HTML package descriptions
 Warning message:
 In file.create(f.tg) :
  cannot create file 'C:\PROGRA~1\R\R-27~1.1/doc/html/packages.html',
 reason 'Permission denied'


 How can i fix the packages.html file to reflect the packages' instalation?

 Thanks in advance.

 José Augusto M. de Andrade Jr. (jamaj)
 Quant. Finance Researcher
 FEA-RP - University of São Paulo

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



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


Re: [R] Matching Up Values

2008-07-20 Thread Steve Murray

Hmm, I'm having a fair few difficulties using 'merge' now. I managed to get it 
to work successfully before, but in this case I'm trying to shorten (as oppose 
to lengthen as before) a file in relation to a 'master' file.

These are the commands I've been using, followed by the dimensions of the files 
in question - as you can see, the row numbers of the merged file don't 
correlate to that of the 'coordinates' file (which is what I'm aiming to get 
'merged' equal to):

 merge(PopDens.long, coordinates, by=c(Latitude,Longitude), all = TRUE) - 
 merged
 dim(PopDens.long); dim(coordinates); dim(merged)
[1] 67870 3
[1] 67420 2
[1] 69849 3


One thing I tried was swapping the order of the files in the merge command, but 
this causes 'merged' to have the same number of rows (69849).


Something else I tried was to leave out the 'all = TRUE' command, as I'm 
essentially attempting the shorten the file, but this makes the output file 
*too* short! (65441 as opposed to the intended 67420). Again, the same applies 
when the order of the input files are swapped.

 merge(PopDens.long, coordinates, by=c(Latitude,Longitude)) - merged
 dim(PopDens.long); dim(coordinates); dim(merged)
[1] 67870 3
[1] 67420 2
[1] 65441 3


Am I doing something obviously wrong? I'm pretty certain that 'coordinates' is 
a subset of 'PopDens.long' - so there should be equal numbers of common values 
when merged.

Is there perhaps a more suitable function I could use, or a way of performing 
checks to see where I might be going wrong?!

Many thanks,

Steve
_
100’s of Nikon cameras to be won with Live Search

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

2008-07-20 Thread David Epstein

#See David Williams' book Weighing the odds, p286

y - c(1.21, 0.51, 0.14, 1.62, -0.8,
0.72, -1.71, 0.84, 0.02, -0.12)
ybar - mean(y)
ylength - length(y)
ybarv - rep(ybar, ylength)
x - 1:ylength
plot(x,y,asp=1,xlab=position,ylab=ybar,type=n,ylim=c(-1,1))
segments(x[1], ybar, x[ylength], ybar)
segments(x,ybarv,x,y)
points(x, ybarv, pch=21, bg=white)
points(x,y,pch=19,col=black)

With asp=1, the value of ylim seems to be totally ignored, as in the  
above code. With asp not set, R plays close attention to the value of  
ylim. This is not intuitive behaviour, or is it?


How can I set the aspect ratio, and simultaneously set the plot  
region? The aspect ratio is one number and the plot region is given  
by four numbers (xleft, xright, yleft, yright). Logically, these 5  
numbers are independent of each other and arbitrary, provided  
xleftxright and yleftyright. This should give a one-to-one  
bijection between 5-tuples and plots, determined up to a change of  
scale that is uniform in the x- and y-dirctions. My code above shows  
the (to me) obvious attempt, which fails.


Thanks
David

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


Re: [R] Erro updating HTML package descriptions in packages.html

2008-07-20 Thread Gabor Grothendieck
Just in case you are mistaken try the suggestion given already.
If you determine that that does not work (and are not just guessing
that it won't work) then in Windows Explorer,

right click packages.html  Properties  Security

and set the security levels appropriately.  Not sure but you
may have to do the same thing on its folder as well.

On Sun, Jul 20, 2008 at 1:26 PM, José Augusto Jr. [EMAIL PROTECTED] wrote:
 Dear all,

 Unfortunately, i´m running as administrator. So, i cannot run R in an
 upper level than this one i am already running.

 jamaj

 2008/7/20 Gabor Grothendieck [EMAIL PROTECTED]:
 Read the VISTA HOW TO section of this page:
 http://batchfiles.googlecode.com


 On Sun, Jul 20, 2008 at 12:48 PM, José Augusto Jr. [EMAIL PROTECTED] wrote:
 Dear all,

 I have just installed the new version of R 2.7.1 and when i first
 instaled some packages it asked me to create a personal directory.

 It installed the packages, but not the html help page (packages.html)

 The downloaded packages are in
C:\Users\jamaj\AppData\Local\Temp\Rtmp4MTuXN\downloaded_packages
 updating HTML package descriptions
 Warning message:
 In file.create(f.tg) :
  cannot create file 'C:\PROGRA~1\R\R-27~1.1/doc/html/packages.html',
 reason 'Permission denied'


 How can i fix the packages.html file to reflect the packages' instalation?

 Thanks in advance.

 José Augusto M. de Andrade Jr. (jamaj)
 Quant. Finance Researcher
 FEA-RP - University of São Paulo

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




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


[R] Off topic: SS formulae for 3-way repeated measure anova (for when aov() fails)

2008-07-20 Thread Mike Lawrence
Pursuant to a prior on topic thread (http://tolstoy.newcastle.edu.au/R/e4/help/08/07/17192.html 
) where I found I could not use AOV to perform an anova on my large  
data set, I'm now trying to code the analysis by hand so to speak.


However, as demonstrated below, when comparing my attempt to aov()  
using a smaller data set, I seem to betray some sort of  
misunderstanding when I try to compute SSerr for the first interaction.


Obviously I have missed something and although I have looked around  
for the explicit SSerr formulas for this design (my work thus far was  
extrapolated from understanding of a 2-way design), I can't seem to  
find any.


Any help would be much obliged.

N = 20
levs.a = 2
levs.b = 2
levs.d = 10

temp.sub = factor(1:N)
temp.a = factor(1:levs.a)
temp.b = factor(1:levs.b)
temp.d = factor(1:levs.d)

temp = expand.grid(sub=temp.sub, a=temp.a, b=temp.b, d=temp.d)
temp$x = rnorm(length(temp[, 1])) #generate some random DV data

sub=temp$sub
a=temp$a
b=temp$b
d=temp$d
x=temp$x

this_aov = aov(
x~a*b*d+Error(sub/(a*b*d))
)
summary(this_aov)

#now let's try by hand,  checking each sum-of-squares
# ss against the analogous aov() produced ss (rounding
# each to avoid small computational differences)

#Get ss.subs
sub.means = aggregate(x,list(sub=sub), mean)
grand.mean = mean(sub.means$x)
ss.total = sum((x-grand.mean)^2)
ss.subs = levs.a*levs.b*levs.d*sum((sub.means$x-grand.mean)^2)
round(ss.subs, 10)==round(summary(this_aov)[[1]][[1]]$Sum, 10)

#Get ss.a
a.means = aggregate(x, list(a=a), mean)
ss.a = N*levs.b*levs.d*sum((a.means$x-grand.mean)^2)
round(ss.a, 10)==round(summary(this_aov)[[2]][[1]]$Sum[1], 10)
#ok!

#Get ss.a.error
a.cells = aggregate(x, list(a=a, sub=sub), mean)
ss.a.cells = levs.b*levs.d*sum((a.cells$x-grand.mean)^2)
ss.a.error = ss.a.cells - ss.a - ss.subs
round(ss.a.error, 10)==round(summary(this_aov)[[2]][[1]]$Sum[2], 10)
#ok!

#Get ss.b
b.means = aggregate(x, list(b=b), mean)
ss.b = N*levs.a*levs.d*sum((b.means$x-grand.mean)^2)
round(ss.b, 10)==round(summary(this_aov)[[3]][[1]]$Sum[1], 10)
#ok!

#Get ss.b.error
b.cells = aggregate(x, list(b=b, sub=sub), mean)
ss.b.cells = levs.a*levs.d*sum((b.cells$x-grand.mean)^2)
ss.b.error = ss.b.cells - ss.b - ss.subs
round(ss.b.error, 10)==round(summary(this_aov)[[3]][[1]]$Sum[2], 10)
#ok!

#Get ss.d
d.means = aggregate(x, list(d=d), mean)
ss.d = N*levs.a*levs.b*sum((d.means$x-grand.mean)^2)
round(ss.d, 10)==round(summary(this_aov)[[4]][[1]]$Sum[1], 10)
#ok!

#Get ss.d.error
d.cells = aggregate(x, list(d=d, sub=sub), mean)
ss.d.cells = levs.a*levs.b*sum((d.cells$x-grand.mean)^2)
ss.d.error = ss.d.cells - ss.d - ss.subs
round(ss.d.error, 10)==round(summary(this_aov)[[4]][[1]]$Sum[2], 10)
#ok!

#Get ss.aBYb
aBYb.means = aggregate(x, list(a=a, b=b), mean)
ss.aBYb = N*levs.d*sum((aBYb.means$x-grand.mean)^2) - ss.a - ss.b
round(ss.aBYb, 10)==round(summary(this_aov)[[5]][[1]]$Sum[1], 10)
#ok!

#Get ss.aBYb.error
aBYb.cells = aggregate(x, list(a=a, b=b, sub=sub), mean)
ss.aBYb.cells = levs.d*sum((aBYb.cells$x-grand.mean)^2)
ss.aBYb.error = ss.aBYb.cells - ss.aBYb - ss.subs
round(ss.aBYb.error, 10)==round(summary(this_aov)[[5]][[1]]$Sum[2], 10)
#not ok :(



--
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University
www.thatmike.com

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


Re: [R] Access to values of function arguments

2008-07-20 Thread willemf

Dear Mike and Brian,

Thank you very much, this solves my immediate problem. Thanks for your time
very much. I will do the reading on those two functions.

I have looked for books that deal with the more programmatic aspects of R
instead of the statistical side (e.g. dealing with R objects, manipulating
environments, lists in R and the like). I have not seen a huge lot. The
books that I have seen that deal with Programming in R are actually
statistically-focused and, as far as I could find out, do not really cover
the programmatic side. Any obvious suggestions for resources that I might
have missed? I have several books on R but R programming (as opposed to
performing statistical/graphical/mathematical manipulation) is one aspect
that I am getting into now and for which I do not have a good reference. The
language ref on CRAN is quite helpful but not a good tutorial at all.

Kind regards,
Willem

-- 
View this message in context: 
http://www.nabble.com/Access-to-values-of-function-arguments-tp18554602p18557568.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Erro: cannot allocate vector of size 216.0 Mb

2008-07-20 Thread José Augusto Jr.
Please,

I have a 2GB computer and a huge time-series to embedd, and i tried
increasing memory.limit() and memory.size(max=TRUE), but nothing.

Just before the command:

 memory.size(max=TRUE)
[1] 13.4375
 memory.limit()
[1] 1535.875
 gc()
 used (Mb) gc trigger (Mb) max used (Mb)
Ncells 209552  5.6 407500 10.9   35  9.4
Vcells 125966  1.0 786432  6.0   496686  3.8



I  increased the memory limit:

 memory.limit(3000)
NULL
 memory.limit()
[1] 3000
 memory.size()
[1] 11.33070
 memory.size(max=TRUE)
[1] 13.4375
 gc()
 used (Mb) gc trigger (Mb) max used (Mb)
Ncells 209552  5.6 407500 10.9   35  9.4
Vcells 125964  1.0 786432  6.0   496686  3.8



And even trying to increase the memory.limits, i still get and error.

Any sugestions?


Thanks in  advance.

jama

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


Re: [R] Non-linearly constrained optimisation

2008-07-20 Thread Hans W. Borchers

Please have a look at the 'Rdonlp2' package at http://arumat.net/Rdonlp2/. 
It provides non-linear optinization with nonlinear constraints, so it may be
exactly what you are looking for. 

Whether this algorithm is powerful enough for your task has to be seen. 
There are examples on the Web page that will enable a quick start.

You did not give information about the complexity of your task, nor whether
you are seeking local or global solutions.

Hans Werner Borchers
ABB Corporate Research



Dear R Users,
I am looking for some guidance on setting up an optimisation in R with
non-linear constraints.

Here is my simple problem:
- I have a function h(inputs) whose value I would like to maximise
- the 'inputs' are subject to lower and upper bounds
- however, I have some further constraints: I would like to constrain the
values for two other separate function f(inputs) and g(inputs) to be within
certain bounds

This means the 'inputs' must not only lie within the bounds specified by
the 'upper' and 'lower' bounds, but they must also not take on values such
that f(inputs) and g(inputs) take on values outside defined values. h, f
and g are all non-linear.

I believe constroptim would work if f and g were linear. Alas, they are
not. Is there any other way I can achieve this in R ?

Thanks in advance,
Tolga


-

Hans W. Borchers
ABB Corporate Research Germany
-- 
View this message in context: 
http://www.nabble.com/Non-linearly-constrained-optimisation-tp18549310p18558334.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] enumerate subsets

2008-07-20 Thread lamack lamack

Dear all, is there a R function that enumerate a partition of a vector of size 
n? (of course for n not very large).
I would like enumerate all the (2 power n)-1 sub-sets. (2 power n)-1 since (2 
power n) includes de empty subset.

Best Regards.

ps. It is not a homework. I never posted homework in this list.

LL



_
Cansado de espaço para só 50 fotos? Conheça o Spaces, o site de relac[[elided 
Hotmail spam]]

[[alternative HTML version deleted]]

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


Re: [R] Access to values of function arguments

2008-07-20 Thread jim holtman
Check out S Programming by Venables  Ripley.

On Sun, Jul 20, 2008 at 3:02 PM, willemf [EMAIL PROTECTED] wrote:

 Dear Mike and Brian,

 Thank you very much, this solves my immediate problem. Thanks for your time
 very much. I will do the reading on those two functions.

 I have looked for books that deal with the more programmatic aspects of R
 instead of the statistical side (e.g. dealing with R objects, manipulating
 environments, lists in R and the like). I have not seen a huge lot. The
 books that I have seen that deal with Programming in R are actually
 statistically-focused and, as far as I could find out, do not really cover
 the programmatic side. Any obvious suggestions for resources that I might
 have missed? I have several books on R but R programming (as opposed to
 performing statistical/graphical/mathematical manipulation) is one aspect
 that I am getting into now and for which I do not have a good reference. The
 language ref on CRAN is quite helpful but not a good tutorial at all.

 Kind regards,
 Willem

 --
 View this message in context: 
 http://www.nabble.com/Access-to-values-of-function-arguments-tp18554602p18557568.html
 Sent from the R help mailing list archive at Nabble.com.

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




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

What is the problem you are trying to solve?

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


Re: [R] asp and ylim

2008-07-20 Thread Rolf Turner


On 21/07/2008, at 5:27 AM, David Epstein wrote:


#See David Williams' book Weighing the odds, p286

y - c(1.21, 0.51, 0.14, 1.62, -0.8,
0.72, -1.71, 0.84, 0.02, -0.12)
ybar - mean(y)
ylength - length(y)
ybarv - rep(ybar, ylength)
x - 1:ylength
plot(x,y,asp=1,xlab=position,ylab=ybar,type=n,ylim=c(-1,1))
segments(x[1], ybar, x[ylength], ybar)
segments(x,ybarv,x,y)
points(x, ybarv, pch=21, bg=white)
points(x,y,pch=19,col=black)

With asp=1, the value of ylim seems to be totally ignored, as in  
the above code. With asp not set, R plays close attention to the  
value of ylim. This is not intuitive behaviour, or is it?


How can I set the aspect ratio, and simultaneously set the plot  
region? The aspect ratio is one number and the plot region is given  
by four numbers (xleft, xright, yleft, yright). Logically, these 5  
numbers are independent of each other and arbitrary, provided  
xleftxright and yleftyright. This should give a one-to-one  
bijection between 5-tuples and plots, determined up to a change of  
scale that is uniform in the x- and y-dirctions. My code above  
shows the (to me) obvious attempt, which fails.


I just tried

  set.seed(42)
  x - runif(10)
  y - runif(10)
  plot(x,y,ylim=c(-1,2),asp=1)

and it seemed to give results as expected/desired.

cheers,

Rolf Turner


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

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


Re: [R] Erro: cannot allocate vector of size 216.0 Mb

2008-07-20 Thread jim holtman
What is huge? How big is it and what are the commands you are trying
to use?  Have you tried a smaller size to see how much memory is being
used (do a 'gc' before and after).  Depending on what you are trying
to do, you may have memory fragmented.  What are the sizes of all the
other objects that you have in memory?  Exactly what is your
configuration.  Some more information is need to understand why you
are getting that error.  It typically means what it says; you do not
have enough memory to allocate the object of that size.

On Sun, Jul 20, 2008 at 3:24 PM, José Augusto Jr. [EMAIL PROTECTED] wrote:
 Please,

 I have a 2GB computer and a huge time-series to embedd, and i tried
 increasing memory.limit() and memory.size(max=TRUE), but nothing.

 Just before the command:

 memory.size(max=TRUE)
 [1] 13.4375
 memory.limit()
 [1] 1535.875
 gc()
 used (Mb) gc trigger (Mb) max used (Mb)
 Ncells 209552  5.6 407500 10.9   35  9.4
 Vcells 125966  1.0 786432  6.0   496686  3.8



 I  increased the memory limit:

 memory.limit(3000)
 NULL
 memory.limit()
 [1] 3000
 memory.size()
 [1] 11.33070
 memory.size(max=TRUE)
 [1] 13.4375
 gc()
 used (Mb) gc trigger (Mb) max used (Mb)
 Ncells 209552  5.6 407500 10.9   35  9.4
 Vcells 125964  1.0 786432  6.0   496686  3.8



 And even trying to increase the memory.limits, i still get and error.

 Any sugestions?


 Thanks in  advance.

 jama

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

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


Re: [R] enumerate subsets

2008-07-20 Thread Peter Dalgaard

lamack lamack wrote:

Dear all, is there a R function that enumerate a partition of a vector of size 
n? (of course for n not very large).
I would like enumerate all the (2 power n)-1 sub-sets. (2 power n)-1 since (2 
power n) includes de empty subset.

Best Regards.

ps. It is not a homework. I never posted homework in this list.

  
The easiest way is probably to generate the numbers 1:(2^n-1), convert 
them to binary, and use the bits to indicate in/out status.


E.g.,

n - 4
x - 1:(2^n-1)
sapply(1:n, function(i) {r - as.logical(x%%2)  ; x - x%/%2 ; r})


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

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


Re: [R] enumerate subsets

2008-07-20 Thread jim holtman
Can you give a small example of what you data looks like and what you
think the output should be.  Have you looked at 'combn'?

On Sun, Jul 20, 2008 at 4:33 PM, lamack lamack [EMAIL PROTECTED] wrote:

 Dear all, is there a R function that enumerate a partition of a vector of 
 size n? (of course for n not very large).
 I would like enumerate all the (2 power n)-1 sub-sets. (2 power n)-1 since (2 
 power n) includes de empty subset.

 Best Regards.

 ps. It is not a homework. I never posted homework in this list.

 LL



 _
 Cansado de espaço para só 50 fotos? Conheça o Spaces, o site de relac[[elided 
 Hotmail spam]]

[[alternative HTML version deleted]]


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





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

What is the problem you are trying to solve?

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


Re: [R] enumerate subsets

2008-07-20 Thread Gabor Grothendieck
Try this replacing letters[1:4] with your set:

 do.call(expand.grid, as.data.frame(rbind(letters[1:4], NA)))
 V1   V2   V3   V4
1 abcd
2  NAbcd
3 a NAcd
4  NA NAcd
5 ab NAd
6  NAb NAd
7 a NA NAd
8  NA NA NAd
9 abc NA
10 NAbc NA
11a NAc NA
12 NA NAc NA
13ab NA NA
14 NAb NA NA
15a NA NA NA
16 NA NA NA NA


On Sun, Jul 20, 2008 at 4:33 PM, lamack lamack [EMAIL PROTECTED] wrote:

 Dear all, is there a R function that enumerate a partition of a vector of 
 size n? (of course for n not very large).
 I would like enumerate all the (2 power n)-1 sub-sets. (2 power n)-1 since (2 
 power n) includes de empty subset.

 Best Regards.

 ps. It is not a homework. I never posted homework in this list.

 LL



 _
 Cansado de espaço para só 50 fotos? Conheça o Spaces, o site de relac[[elided 
 Hotmail spam]]

[[alternative HTML version deleted]]


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



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


Re: [R] asp and ylim

2008-07-20 Thread Gabor Grothendieck
Try lattice:

library(lattice)
xyplot(y ~ x, ylim = c(0.5, 0.7), aspect = iso)


On Sun, Jul 20, 2008 at 5:58 PM, David Epstein
[EMAIL PROTECTED] wrote:

 On 20 Jul, 2008, at 22:00, Rolf Turner wrote:

I just tried

  set.seed(42)
  x - runif(10)
  y - runif(10)
  plot(x,y,ylim=c(-1,2),asp=1)

and it seemed to give results as expected/desired.

cheers,

Rolf Turner



 I tried plot(x,y,ylim=c(0.5,0.7),asp=1) on your data above and it failed to
 restrict the y-coordinates to between 0.5 and 0.7.  In fact, the behaviour
 is independent of whether I insert the ylim=c(0.5,0.7) argument or omit it.
 So that's definitely not what I want to happen. Nor does the behaviour
 accord with the advertised behaviour seen from help(plot.window). I want the
 smallest y-coord seen on the plot to be .5 and the largest to be .7. I want
 points outside that range not to be displayed. This seems to be what
 help(plot.window) promises.

 When I added to your plot command the argument xlim=c(0,1), then that xlim
 instruction was also ignored. It seems that there is an unstated set of
 rules for how the plot should react to xlim and ylim settings when asp is
 set. I wonder if anyone knows what they are. I suppose one could always read
 the source. For example, one might guess from these examples discussed so
 far that asp=1 forces the forces the window to be square, but that is not
 the case. And the command plot(x,y,xlim=c(-6,-1),ylim=c(-1,2),asp=1) on your
 data suddenly decides that it ought to behave the way I think is
 reasonable---namely the plot is empty---in contrast to all the other
 examples where it has insisted on displaying ALL the points (x[i],y[i]),
 ignoring the values of xlim and ylim.

 It's fine by me to have xlim and ylim perform idiosyncratically. But can I
 achieve the degree of control I would like, perhaps using a different
 technique, or different tags?

 David

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


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


Re: [R] asp and ylim

2008-07-20 Thread Prof Brian Ripley

Take a look at eqscplot() in package MASS for a different approach.

You last para forgets that once you have set the device region and the 
margins the physical plot region and hence its aspect ratio is determined 
-- see the figures in 'An Introduction to R'.


On Sun, 20 Jul 2008, David Epstein wrote:


#See David Williams' book Weighing the odds, p286

y - c(1.21, 0.51, 0.14, 1.62, -0.8,
  0.72, -1.71, 0.84, 0.02, -0.12)
ybar - mean(y)
ylength - length(y)
ybarv - rep(ybar, ylength)
x - 1:ylength
plot(x,y,asp=1,xlab=position,ylab=ybar,type=n,ylim=c(-1,1))
segments(x[1], ybar, x[ylength], ybar)
segments(x,ybarv,x,y)
points(x, ybarv, pch=21, bg=white)
points(x,y,pch=19,col=black)

With asp=1, the value of ylim seems to be totally ignored, as in the above 
code. With asp not set, R plays close attention to the value of ylim. This is 
not intuitive behaviour, or is it?


How can I set the aspect ratio, and simultaneously set the plot region? The 
aspect ratio is one number and the plot region is given by four numbers 
(xleft, xright, yleft, yright). Logically, these 5 numbers are independent of 
each other and arbitrary, provided xleftxright and yleftyright. This should 
give a one-to-one bijection between 5-tuples and plots, determined up to a 
change of scale that is uniform in the x- and y-dirctions. My code above 
shows the (to me) obvious attempt, which fails.


Thanks
David

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


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

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


Re: [R] asp and ylim

2008-07-20 Thread Paul Smith
On Sun, Jul 20, 2008 at 11:14 PM, Gabor Grothendieck
[EMAIL PROTECTED] wrote:
 Try lattice:

 library(lattice)
 xyplot(y ~ x, ylim = c(0.5, 0.7), aspect = iso)

Alternatively,

set.seed(42)
x - runif(10)
y - runif(10)
plot(x[(y=0.5)  (y=0.7)],y[(y=0.5)  (y=0.7)],ylim=c(0.5,0.7),asp=1)

Paul

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Sum efficiently from large matrix according to re-occuring levels of factor?

2008-07-20 Thread Ralph S.

Hi,

I am trying to calculate the sum for each occurrence of the level of a factor 
in a very large matrix. In addition, I want to save that sum together with the 
information of the level of the factor and the level of a second factor.

My matrix looks like this:

x-matrix(c(1,1,1,2,2,3,3,1,1,7,7,7,4,4,2,2,7,7,1,1,1,1,1,1,2,5,5),9,3)

I want to sum according to the levels in the first column and save the sum with 
the information of the level in the first and the second column in a new matrix.

That is, I want output in the matrix of form:

1 7 3
2 4 2
3 2 3
1 7 10

The important thing is, that a factor level such as 1 in the example can 
re-occur many times. There are no regularities on the number of re-occurences 
etc.

How could I do this efficiently (the matrix is large:10^6 rows)?

Many thanks!!

-Ralph
_
[[elided Hotmail spam]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] coin package (conditional inference / permutation): parameter teststat

2008-07-20 Thread Paulo Barata


Dear R-list members,

This is in fact a question about statistics, not directly
about the R software.

The coin package, for conditional inference through permutation
methods, has as it main function the function  independence_test.
One of its parameters is teststat, about which the package
documentation says:

 teststat: a character, the type of test statistic to be applied:
 either a standardized scalar test statistic (scalar), or
 a maximum type statistic (max) or a quadratic form (quad).

My current problem is a two-sample (two-group) one, with
multivariate response consisting entirely of continuous numerical
observations.

Would someone please point me to references indicating the relative
merits of the max and quad test statistics in this case?

The pdf document Implementing a Class of Permutation Tests: The
coin Package, by Hothorn et al., which comes with the package,
says on page 5 that In the multivariate case (pq  1),
a maximum-type statistic (...) is appropriate. But no reasons
or references are provided.

P. Good, Permutation, Parametric, and Bootstrap Tests of Hypotheses.
3rd. ed. (Springer), says on page 180 (Section 9.4.4, Which
Statistic?) [my comments in brackets]:

 We've now considered three multivariate test statistics for
 testing hypothesis based on one or two samples. Which one should
 we use? To detect a simultaneous shift in the means of several
 variables, use Hotelling's T2 [a kind of 'quad' test statistics];
 to detect a shift in any of several variables, use the maximum t
 [a kind of 'max' test statistics] (...)

But again, no reasons or references are provided.

So, I would like to know if anyone could indicate me references
discussing the relative merits of the max and quad test
statistics, in the case of a two-sample problem with continuous
multivariate responses, when using permutation tests.

Just for information, I currently use R 2.7.1 running on
Windows XP. The coin package is version 0.6-9 (5 May 2008).

Thank you very much.

Regards,

Paulo Barata

---
Paulo Barata
Fundacao Oswaldo Cruz
Rua Leopoldo Bulhoes 1480 - 8A
21041-210  Rio de Janeiro - RJ
Brazil

E-mail: [EMAIL PROTECTED]
Alternative e-mail: [EMAIL PROTECTED]

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


Re: [R] Sum efficiently from large matrix according to re-occuring levels of factor?

2008-07-20 Thread hadley wickham
On Sun, Jul 20, 2008 at 4:16 PM, Ralph S. [EMAIL PROTECTED] wrote:

 Hi,

 I am trying to calculate the sum for each occurrence of the level of a factor 
 in a very large matrix. In addition, I want to save that sum together with 
 the information of the level of the factor and the level of a second factor.

 My matrix looks like this:

 x-matrix(c(1,1,1,2,2,3,3,1,1,7,7,7,4,4,2,2,7,7,1,1,1,1,1,1,2,5,5),9,3)

 I want to sum according to the levels in the first column and save the sum 
 with the information of the level in the first and the second column in a new 
 matrix.

 That is, I want output in the matrix of form:

 1 7 3
 2 4 2
 3 2 3
 1 7 10


Why that and not:

1 7 13
2 4 2
3 2 3

?

Hadley

-- 
http://had.co.nz/

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


Re: [R] Sum efficiently from large matrix according to re-occuring levels of factor?

2008-07-20 Thread hadley wickham
On Sun, Jul 20, 2008 at 4:47 PM, hadley wickham [EMAIL PROTECTED] wrote:
 On Sun, Jul 20, 2008 at 4:16 PM, Ralph S. [EMAIL PROTECTED] wrote:

 Hi,

 I am trying to calculate the sum for each occurrence of the level of a 
 factor in a very large matrix. In addition, I want to save that sum together 
 with the information of the level of the factor and the level of a second 
 factor.

 My matrix looks like this:

 x-matrix(c(1,1,1,2,2,3,3,1,1,7,7,7,4,4,2,2,7,7,1,1,1,1,1,1,2,5,5),9,3)

 I want to sum according to the levels in the first column and save the sum 
 with the information of the level in the first and the second column in a 
 new matrix.

 That is, I want output in the matrix of form:

 1 7 3
 2 4 2
 3 2 3
 1 7 10


 Why that and not:

 1 7 13
 2 4 2
 3 2 3

 ?

Here's a solution for that case:

index - x[, 2] + x[, 1] * max(x[, 2])
cbind(x[!duplicated(index), 1:2], tapply(x[, 3], index, sum))

It takes about half a second for a million row matrix.

Hadley



-- 
http://had.co.nz/

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


Re: [R] TeachingDemos question: my.symbols() alignment problems in complicated layout

2008-07-20 Thread Paul Murrell
Hi


[EMAIL PROTECTED] wrote:
 Hello,
 
 After usefull suggestions by Paul Murrell, i have been trying to use
 my.symbols to plot arrows of varying angles on my plot in order to create
 a time series of wind direction... however,i have been unable to figure
 out how the allignment of symbols works...
 
 below i have included a simplified code that illustrates my problem:
 (i am creating a .ps file ... so i've included this in my mock code, in
 case it might be part of the problem...)
 
 # TEST CODE #
 
 postscript(test.ps, horizontal=FALSE, width=7.5,
 height=11.5,pointsize=10, paper = special )
 
 library(TeachingDemos)
 
 opar - par(omi=c(0,0.1,0.7,0.1),xpd=T,mar=par()$mar+c(0,-1.5,-1,5))
 
 layout_mat = matrix(c(1,2,3,4),nrow=4,ncol=1,byrow=TRUE)
 
 my_layout -
 layout(layout_mat,widths=c(1,1,1,1),heights=c(1.0,0.45,1.0,1.2),respect=FALSE)
 
 plot(1,1)
 plot(2,2)
 plot(3,3)
 plot(1:100,rep(c(9,1.5,2,8),25))
 points(40,4,col=red)
 points(50,8,col=red)
 my.symbols(40,4,ms.polygon,n=3,inches=0.2,add=TRUE)
 my.symbols(40,4,ms.arrows,angle=pi/2,inches=0.2,add=TRUE)
 my.symbols(50,8,ms.arrows,angle=pi/4,inches=0.2,add=TRUE)
 dev.off()
 
  END of TEST CODE ###
 
 If i look at the output test.ps ... the first symbol is exactly where i
 want it to be i.e. at x=40,y=4 ... while the position of the two other
 ones is offset by some mysterious(!!) value
 
 then if i comment out the first my.symbols(...) command... the second
 symbol is at the right place, while the third is offset ...etc
 
 However if i simply do:
 
 plot(1:100,rep(c(9,1.5,2,8),25))
 points(40,4,col=red)
 points(50,8,col=red)
 my.symbols(40,4,ms.polygon,n=3,inches=0.2,add=TRUE)
 my.symbols(40,4,ms.arrows,angle=pi/2,inches=0.2,add=TRUE)
 my.symbols(50,8,ms.arrows,angle=pi/4,inches=0.2,add=TRUE
 
 
 then everything is exactly where i want it ... suggesting there is a
 problem with the layout ???


I think the issue is that my.symbols() does a lot of this ...

op - par(no.readonly = TRUE)
on.exit(par(op))

... which is not absolutely guaranteed to get you back to where you
started (see the comment in the 'Value' section of the help page ?par).
   Fixing that will need the cooperation of the author of TeachingDemos.

Here are a couple of options:

(i)  use the 'gridBase' package and do these arrow annotations using the
'grid' package, which allows you to control coordinate systems in a more
rational manner.  There's an example (perhaps slightly more complicated
than you need) in:
http://cran.r-project.org/doc/Rnews/Rnews_2003-2.pdf

(ii) draw your main plot using 'lattice' and the annotations using
'grid' or possibly 'grImport'.  There's a hint of an example of the
latter on slide 18 of:
http://www.stat.auckland.ac.nz/~paul/Talks/import.pdf

(iii) draw the whole thing using 'grid'.  You can start to get
acquainted with grid here:
http://www.stat.auckland.ac.nz/~paul/RGraphics/chapter5.pdf

Unfortunately, all of these require a reasonable amount of extra
learning on your part.

Paul


 Any help would be really appreciated,
 Thank You a lot,
 maria
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[EMAIL PROTECTED]
http://www.stat.auckland.ac.nz/~paul/

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


Re: [R] TeachingDemos question: my.symbols() alignment problems in complicated layout

2008-07-20 Thread hadley wickham
 Here are a couple of options:

 (i)  use the 'gridBase' package and do these arrow annotations using the
 'grid' package, which allows you to control coordinate systems in a more
 rational manner.  There's an example (perhaps slightly more complicated
 than you need) in:
 http://cran.r-project.org/doc/Rnews/Rnews_2003-2.pdf

 (ii) draw your main plot using 'lattice' and the annotations using
 'grid' or possibly 'grImport'.  There's a hint of an example of the
 latter on slide 18 of:
 http://www.stat.auckland.ac.nz/~paul/Talks/import.pdf

 (iii) draw the whole thing using 'grid'.  You can start to get
 acquainted with grid here:
 http://www.stat.auckland.ac.nz/~paul/RGraphics/chapter5.pdf

(iv) Use ggplot2 - particularly geom_segment
(http://had.co.nz/ggplot2/geom_segment.html) and stat_spoke
(http://had.co.nz/ggplot2/stat_spoke.html)

Hadley

-- 
http://had.co.nz/

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


Re: [R] smooth.spline

2008-07-20 Thread rkevinburton
Actually that was my next question. From the books that I have I see a natural 
spline and a clamped spline. I am assuming that natural (Umerical Analysis, 
Burden, et. all.) cooresponds to 'R''s natural method. I am not clear on what 
a clamped spline cooresponds to (fmm or perodic). Or what the difference 
between fmm and periodic.

Thank you.

Kevin
 Spencer Graves [EMAIL PROTECTED] wrote: 
   Are you aware that there are many different kinds of splines?  
 With spline and splinefun, you can use method = fmm (Forsyth, 
 Malcolm and Moler), natural, or periodic.  I'm not familiar with 
 fmm, but it seems to be adequately explained by the Manual spline 
 evaluation you quoted from the documentation. 
 
   Natural splines are perhaps the simplest:  I(x-x0)*(x-x0)^j, where 
 x0 is a knot, and I(z) = 1 if z0 and 0 otherwise. 
 
   However, computations using natural splines are numerically 
 unstable.  The standard solution to this problem is to use B-splines, 
 which are 0 outside a finite interval. 
 
   Let's look at your example: 
 
 n - 9
 x - 1:n
 y - rnorm(n)
 plot(x, y, main = paste(spline[fun](.) through, n, points))
 spl - smooth.spline(x,y)
 lines(spl)
 
   The 'smooth.spline' function uses B-splines.  To see what they 
 look like, let's do the following: 
 
 library(fda)
 Bspl.basis - create.bspline.basis(unique(spl$fit$knot))
 
 # Check to make sure: 
 all.equal(knots(Bspl.basis, interior=FALSE), spl$fit$knot)
 # TRUE
 
 # What do B-splines look like? 
 plot(Bspl.basis)
 abline(v=knots(Bspl.basis), lty='dotted', col='red')
 #  7 interior knots, 2 end knots replicated 4 times each, for a spline 
 of order 4, degree 3 (cubic splines) 
 # total of 15 knots
 # Each spline uses 5 consecutive knots, which means there will be 11 
 basis functions. 
  
 # NOTE:  'smooth.spline' rescaled the interval [1, 9] to [0, 1]. 
 # Evaluate the 11 B-splines at 'x'
 Bspl.basis.x - eval.basis((x-1)/8, Bspl.basis)
 
 round(Bspl.basis.x, 4)
 
 # Now the manual computation: 
 y.spl - Bspl.basis.x %*% spl$fit$coef
 
 # Plot to confirm: 
 plot(x, y, main = paste(spline[fun](.) through, n, points))
 spl.xy - spline(x, y)
 lines(spl.xy)
 points(x, y.spl, pch=2, col='red')
 
   Hope this helps. 
   Spencer
 
 [EMAIL PROTECTED] wrote:
  Fair enough. FOr a spline interpolation I can do the following:
 

  n - 9
  x - 1:n
  y - rnorm(n)
  plot(x, y, main = paste(spline[fun](.) through, n, points))
  lines(spline(x, y))
  
 
  Then look at the coefficients generated as:
 

  f - splinefun(x, y)
  ls(envir = environment(f))
  
  [1] ties ux   z   

  splinecoef - get(z, envir = environment(f))
  slinecoef
  
  $method
  [1] 3
 
  $n
  [1] 9
 
  $x
  [1] 1 2 3 4 5 6 7 8 9
 
  $y
  [1]  0.93571604  0.44240485  0.45451903 -0.96207396 -1.13246522 -0.60032698
  [7] -1.77506105 -0.09171419 -0.23262573
 
  $b
  [1] -1.53673409  0.22775629 -0.81788209 -1.16966436  0.73558677 -0.68744178
  [7]  0.08639287  1.86770869 -2.92992167
 
  $c
  [1]  1.3657783  0.3987121 -1.4443504  1.0925682  0.8126830 -2.2357115  
  3.0095462
  [8] -1.2282303 -3.5694000
 
  $d
  [1] -0.32235542 -0.61435416  0.84563953 -0.09329507 -1.01613149  1.74841922
  [7] -1.41259217 -0.78038989 -0.78038989
 
  WHen I look at ?spline there is even an example of manually using these 
  coefficeients:
 
  ## Manual spline evaluation --- demo the coefficients :
  .x - get(ux, envir = environment(f))
  u - seq(3,6, by = 0.25)
  (ii - findInterval(u, .x))
  dx - u - .x[ii]
  f.u - with(splinecoef,
  y[ii] + dx*(b[ii] + dx*(c[ii] + dx* d[ii])))
  stopifnot(all.equal(f(u), f.u))
 
 
  For the smooth.spline as
 
  spl - smooth.spline(x,y)
 
  I can also look at the coefficients:
 
  spl$fit
  $knot
   [1] 0.000 0.000 0.000 0.000 0.125 0.250 0.375 0.500 0.625 0.750 0.875 1.000
  [13] 1.000 1.000 1.000
 
  $nk
  [1] 11
 
  $min
  [1] 1
 
  $range
  [1] 8
 
  $coef
   [1]  0.90345898  0.73823276  0.40777431 -0.08046715 -0.54625461 -0.85205147
   [7] -0.96233408 -0.91373830 -0.66529714 -0.47674774 -0.38246971
 
  attr(,class)
  [1] smooth.spline.fit
 
  But there isn't an example on how to manual use these coefficients. This 
  is what I was asking about. Once I hae the coefficients how do I manually 
  interpolate using the coefficients given and x.
 
  Thank you.
 
  Kevin
 
 
   Spencer Graves [EMAIL PROTECTED] wrote: 

PLEASE do read the posting guide 
  http://www.R-project.org/posting-guide.html and provide commented, 
  minimal, self-contained, reproducible code.
 
I do NOT know how to do what you want, but with a self-contained 
  example, I suspect many people on this list -- probably including me -- 
  could easily solve the problem.  Without such an example, there is a 
  high probability that any answer might (a) not respond to your need, and 
  (b) take more time to develop, just because we don't know enough of what 
  you are asking. 
 
Spencer
 
  [EMAIL PROTECTED] 

[R] Lattice Version of grconvertX or variant on panel.text?

2008-07-20 Thread Bryan Hanson
Still playing with Lattice...

I want to use panel.text(x, y etc) but with x and y in plot coordinates
(0,1), not user coordinates.

I think if I had this problem with traditional graphics, I could use
grconvertX to make the change.  I did come across convertX {grid} but this
doesn't seem to be what I need.

Is there a function like grconvertX in Lattice, or is there a flag or some
other method of making panel.text use plot coordinates?

Thanks, Bryan

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


Re: [R] Lattice Version of grconvertX or variant on panel.text?

2008-07-20 Thread hadley wickham
On Sun, Jul 20, 2008 at 6:03 PM, Bryan Hanson [EMAIL PROTECTED] wrote:
 Still playing with Lattice...

 I want to use panel.text(x, y etc) but with x and y in plot coordinates
 (0,1), not user coordinates.

 I think if I had this problem with traditional graphics, I could use
 grconvertX to make the change.  I did come across convertX {grid} but this
 doesn't seem to be what I need.

Looking at the code for panel.text (lattice:::ltext.default) it looks
like the easiest way to go would be to call grid.text directly,
specifying the units (npc) that you want to use.

Hadley


-- 
http://had.co.nz/

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


Re: [R] Sum efficiently from large matrix according to re-occuring levels of factor?

2008-07-20 Thread jim holtman
Does this do what you want:

 # following up on another idea that was presented
 # where are the breaks
 dataBreaks - cumsum(c(0, (diff(x[, 2] + x[, 1] * max(x[, 2])) != 0)))
 # sum up column 3 and output the first two columns with the indices
 result - lapply(split(seq(nrow(x)), dataBreaks), function(.sect){
+ c(x[.sect[1], 1:2], sum(x[.sect, 3]))
+ })
 do.call(rbind, result)
  [,1] [,2] [,3]
0173
1242
2323
317   10


On Sun, Jul 20, 2008 at 7:57 PM, Ralph S. [EMAIL PROTECTED] wrote:

 The first and second column are actually indices of another matrix (my 
 example may make this not sufficiently clear). I want to compare the sum with 
 that corresponding entry, and then record the result of that.

 Any idea?

 Best,

 Ralph



 
 Date: Sun, 20 Jul 2008 16:50:41 -0700
 From: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: Re: [R] Sum efficiently from large matrix according to re-occuring 
 levels of factor?
 CC: r-help@r-project.org

 On Sun, Jul 20, 2008 at 4:47 PM, hadley wickham  wrote:
 On Sun, Jul 20, 2008 at 4:16 PM, Ralph S.  wrote:

 Hi,

 I am trying to calculate the sum for each occurrence of the level of a 
 factor in a very large matrix. In addition, I want to save that sum 
 together with the information of the level of the factor and the level of 
 a second factor.

 My matrix looks like this:

 x-matrix(c(1,1,1,2,2,3,3,1,1,7,7,7,4,4,2,2,7,7,1,1,1,1,1,1,2,5,5),9,3)

 I want to sum according to the levels in the first column and save the sum 
 with the information of the level in the first and the second column in a 
 new matrix.

 That is, I want output in the matrix of form:

 1 7 3
 2 4 2
 3 2 3
 1 7 10


 Why that and not:

 1 7 13
 2 4 2
 3 2 3

 ?

 Here's a solution for that case:

 index - x[, 2] + x[, 1] * max(x[, 2])
 cbind(x[!duplicated(index), 1:2], tapply(x[, 3], index, sum))

 It takes about half a second for a million row matrix.

 Hadley



 --
 http://had.co.nz/

 _
 With Windows Live for mobile, your contacts travel with you.

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

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


Re: [R] Lattice Version of grconvertX or variant on panel.text?

2008-07-20 Thread Bryan Hanson
Never mind, I just hard-coded it using ratios.  Simpler than I thought.
Thanks, Bryan


On 7/20/08 9:03 PM, Bryan Hanson [EMAIL PROTECTED] wrote:

 Still playing with Lattice...
 
 I want to use panel.text(x, y etc) but with x and y in plot coordinates
 (0,1), not user coordinates.
 
 I think if I had this problem with traditional graphics, I could use
 grconvertX to make the change.  I did come across convertX {grid} but this
 doesn't seem to be what I need.
 
 Is there a function like grconvertX in Lattice, or is there a flag or some
 other method of making panel.text use plot coordinates?
 
 Thanks, Bryan
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Sum efficiently from large matrix according to re-occuring levels of factor?

2008-07-20 Thread Ralph S.

yes - thank you very much! slowly getting to the full power of R . . .


 Date: Sun, 20 Jul 2008 21:21:35 -0400
 From: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: Re: [R] Sum efficiently from large matrix according to re-occuring 
 levels of factor?
 CC: [EMAIL PROTECTED]; r-help@r-project.org
 
 Does this do what you want:
 
 # following up on another idea that was presented
 # where are the breaks
 dataBreaks - cumsum(c(0, (diff(x[, 2] + x[, 1] * max(x[, 2])) != 0)))
 # sum up column 3 and output the first two columns with the indices
 result - lapply(split(seq(nrow(x)), dataBreaks), function(.sect){
 + c(x[.sect[1], 1:2], sum(x[.sect, 3]))
 + })
 do.call(rbind, result)
   [,1] [,2] [,3]
 0173
 1242
 2323
 317   10
 
 
 On Sun, Jul 20, 2008 at 7:57 PM, Ralph S.  wrote:

 The first and second column are actually indices of another matrix (my 
 example may make this not sufficiently clear). I want to compare the sum 
 with that corresponding entry, and then record the result of that.

 Any idea?

 Best,

 Ralph



 
 Date: Sun, 20 Jul 2008 16:50:41 -0700
 From: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: Re: [R] Sum efficiently from large matrix according to re-occuring 
 levels of factor?
 CC: r-help@r-project.org

 On Sun, Jul 20, 2008 at 4:47 PM, hadley wickham  wrote:
 On Sun, Jul 20, 2008 at 4:16 PM, Ralph S.  wrote:

 Hi,

 I am trying to calculate the sum for each occurrence of the level of a 
 factor in a very large matrix. In addition, I want to save that sum 
 together with the information of the level of the factor and the level of 
 a second factor.

 My matrix looks like this:

 x-matrix(c(1,1,1,2,2,3,3,1,1,7,7,7,4,4,2,2,7,7,1,1,1,1,1,1,2,5,5),9,3)

 I want to sum according to the levels in the first column and save the 
 sum with the information of the level in the first and the second column 
 in a new matrix.

 That is, I want output in the matrix of form:

 1 7 3
 2 4 2
 3 2 3
 1 7 10


 Why that and not:

 1 7 13
 2 4 2
 3 2 3

 ?

 Here's a solution for that case:

 index - x[, 2] + x[, 1] * max(x[, 2])
 cbind(x[!duplicated(index), 1:2], tapply(x[, 3], index, sum))

 It takes about half a second for a million row matrix.

 Hadley



 --
 http://had.co.nz/

 _
 With Windows Live for mobile, your contacts travel with you.

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

_


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


Re: [R] Lattice Version of grconvertX or variant on panel.text?

2008-07-20 Thread Gabor Grothendieck
Use grid.text instead:

library(lattice)
library(grid)
xyplot(demand ~ Time, BOD, panel = function(...) {
   panel.xyplot(...)
   grid.text(Some text, .1, .1) # near lower left
})


On Sun, Jul 20, 2008 at 9:03 PM, Bryan Hanson [EMAIL PROTECTED] wrote:
 Still playing with Lattice...

 I want to use panel.text(x, y etc) but with x and y in plot coordinates
 (0,1), not user coordinates.

 I think if I had this problem with traditional graphics, I could use
 grconvertX to make the change.  I did come across convertX {grid} but this
 doesn't seem to be what I need.

 Is there a function like grconvertX in Lattice, or is there a flag or some
 other method of making panel.text use plot coordinates?

 Thanks, Bryan

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


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


[R] RODBC - problems using odbcDriverConnect without DSN

2008-07-20 Thread Josiah Walker
Hi,

I'm trying to use RODBC without having to set up a DSN, using hte
direct connection string in odbcDriverConnect.  My connection attempt
looks something like:
 odbcDriverConnect(connection = 
 SERVER=localhost;DRIVER={/usr/lib/odbc/libmyodbc.so};DATABASE=myDB;UID=reader;PASSWORD=insecure;)

And this returns the message:
Warning messages:
1: In odbcDriverConnect(connection = conn) :
  [RODBC] ERROR: state IM002, code 0, message [unixODBC][Driver
Manager]Data source name not found, and no default driver specified
2: In odbcDriverConnect(connection = conn) : ODBC connection failed

I know this means it can't find x connection in the dsn... which means
my connection string isn't recognised as valid.  I've used ODBC and
ODBC connection strings before, but I can't work out why this wouldn't
work here.  I can successfully create the same connection using a user
DSN with the same settings as this, but this connection string won't
work.  It's fairly important for this project that the code can
connect without a DSN needing to be set on every computer that runs
it.  Does anyone know if I'm missing something in my connection
string, or can this not be done using RODBC?

Thanks,
Josiah.

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