Re: [R] Question

2018-04-19 Thread Keith Jewell

On 15/04/2018 17:26, Marc Girondot via R-help wrote:

Le 15/04/2018 à 17:56, alireza daneshvar a écrit :

break-down point


Can you explain more what you plan to do and give an example of what you 
have tried to do until now to do a "break down point" in R. Perhaps a 
"break down point" is common in your field, but I have no idea about 
what it is !


https://en.wikipedia.org/wiki/Breakdown_(1997_film)

Sincerely

Marc

Perhaps the OP means "breakpoint" in which case the 'strucchange' 
package might be relevant 



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
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 choose.files(default=..., multi=FALSE)

2017-05-10 Thread Keith Jewell

Thanks for confirming that I wasn't being stupid :-}

When using default=pathlong I get the _correct_ starting directory...
(M:\test\Averyveryveryveryverylongfoldername\Averyveryveryveryverylongfoldername\Averyveryveryveryverylongfoldername) 

... both in the environment I indicated originally (Windows Server 2008 
R2 x64) and also in Windows 10 x64


Keith Jewell

On 09/05/2017 17:49, Duncan Murdoch wrote:

On 09/05/2017 12:06 PM, Keith Jewell wrote:

I'm very hesitant to suggest that there's a bug in such a venerable R
function, but I can't see what I'm doing wrong. Any comments are welcome


Yes, it looks like a bug.  One other thing I find a little strange: the
starting directory seems wrong when I have the pathlong default.  Did
you see that?  (I'm in Windows 10, not the same version as you.)

Duncan Murdoch



When using choose.files() where:
 default = something
 multi = FALSE
 selected file path is shorter than the default
... then the returned value is at least as long as the default,
characters from default appearing (wrongly) at the end of the returned
value.

Example, in which all but the first choose.files() select
"M:\\test\\target.dat". Note the last result.

 > pathlong <- choose.files(caption = "long")
 > pathlong # long file name to use as default for short selection
[1]
"M:\\test\\Averyveryveryveryverylongfoldername\\Averyveryveryveryverylongfoldername\\Averyveryveryveryverylongfoldername\\target.dat"

 > choose.files(caption = "short")  # no default without multi works
[1] "M:\\test\\target.dat"
 > choose.files(default=pathlong, caption = "short") # default without
multi= works
[1] "M:\\test\\target.dat"
 > choose.files(caption = "short", multi = FALSE) # multi = FALSE
without default works
[1] "M:\\test\\target.dat"
 > choose.files(default=pathlong, caption = "short", multi = TRUE) #
multi = TRUE with default works
[1] "M:\\test\\target.dat"
 > choose.files(default=pathlong, caption = "short", multi = FALSE) #
multi = FALSE with default fails
[1]
"M:\\test\\target.dat\\ryveryverylongfoldername\\Averyveryveryveryverylongfoldername\\Averyveryveryveryverylongfoldername\\target.dat"


 > # in case it's relevant
 > sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows Server 2008 R2 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United
Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C

[5] LC_TIME=English_United Kingdom.1252

attached base packages:
[1] graphics  grDevices datasets  stats tcltk utils tools
   methods
[9] base

other attached packages:
  [1] CBRIutils_1.0   stringr_1.2.0   svSocket_0.9-57 TinnR_1.0-5
R2HTML_2.3.2
  [6] Hmisc_4.0-3 ggplot2_2.2.1   Formula_1.2-1   survival_2.41-3
lattice_0.20-35

loaded via a namespace (and not attached):
  [1] RColorBrewer_1.1-2  htmlTable_1.9   digest_0.6.12
htmltools_0.3.6
  [5] splines_3.4.0   scales_0.4.1grid_3.4.0
checkmate_1.8.2
  [9] devtools_1.12.0 knitr_1.15.1munsell_0.4.3
compiler_3.4.0
[13] tibble_1.3.0nnet_7.3-12 acepack_1.4.1
Matrix_1.2-10
[17] svMisc_0.9-70   plyr_1.8.4  base64enc_0.1-3
data.table_1.10.4
[21] stringi_1.1.5   magrittr_1.5gtable_0.2.0
colorspace_1.3-2
[25] foreign_0.8-68  cluster_2.0.6   gridExtra_2.2.1
htmlwidgets_0.8
[29] withr_1.0.2 lazyeval_0.2.0  backports_1.0.5
memoise_1.1.0
[33] rpart_4.1-11Rcpp_0.12.10latticeExtra_0.6-28
 >

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 choose.files(default=..., multi=FALSE)

2017-05-09 Thread Keith Jewell
I'm very hesitant to suggest that there's a bug in such a venerable R 
function, but I can't see what I'm doing wrong. Any comments are welcome


When using choose.files() where:
default = something
multi = FALSE
selected file path is shorter than the default
... then the returned value is at least as long as the default, 
characters from default appearing (wrongly) at the end of the returned 
value.


Example, in which all but the first choose.files() select 
"M:\\test\\target.dat". Note the last result.


> pathlong <- choose.files(caption = "long")
> pathlong # long file name to use as default for short selection
[1] 
"M:\\test\\Averyveryveryveryverylongfoldername\\Averyveryveryveryverylongfoldername\\Averyveryveryveryverylongfoldername\\target.dat"

> choose.files(caption = "short")  # no default without multi works
[1] "M:\\test\\target.dat"
> choose.files(default=pathlong, caption = "short") # default without 
multi= works

[1] "M:\\test\\target.dat"
> choose.files(caption = "short", multi = FALSE) # multi = FALSE 
without default works

[1] "M:\\test\\target.dat"
> choose.files(default=pathlong, caption = "short", multi = TRUE) # 
multi = TRUE with default works

[1] "M:\\test\\target.dat"
> choose.files(default=pathlong, caption = "short", multi = FALSE) # 
multi = FALSE with default fails
[1] 
"M:\\test\\target.dat\\ryveryverylongfoldername\\Averyveryveryveryverylongfoldername\\Averyveryveryveryverylongfoldername\\target.dat"


> # in case it's relevant
> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows Server 2008 R2 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United 
Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C 


[5] LC_TIME=English_United Kingdom.1252

attached base packages:
[1] graphics  grDevices datasets  stats tcltk utils tools 
  methods

[9] base

other attached packages:
 [1] CBRIutils_1.0   stringr_1.2.0   svSocket_0.9-57 TinnR_1.0-5 
R2HTML_2.3.2
 [6] Hmisc_4.0-3 ggplot2_2.2.1   Formula_1.2-1   survival_2.41-3 
lattice_0.20-35


loaded via a namespace (and not attached):
 [1] RColorBrewer_1.1-2  htmlTable_1.9   digest_0.6.12 
htmltools_0.3.6
 [5] splines_3.4.0   scales_0.4.1grid_3.4.0 
checkmate_1.8.2
 [9] devtools_1.12.0 knitr_1.15.1munsell_0.4.3 
compiler_3.4.0
[13] tibble_1.3.0nnet_7.3-12 acepack_1.4.1 
Matrix_1.2-10
[17] svMisc_0.9-70   plyr_1.8.4  base64enc_0.1-3 
data.table_1.10.4
[21] stringi_1.1.5   magrittr_1.5gtable_0.2.0 
colorspace_1.3-2
[25] foreign_0.8-68  cluster_2.0.6   gridExtra_2.2.1 
htmlwidgets_0.8
[29] withr_1.0.2 lazyeval_0.2.0  backports_1.0.5 
memoise_1.1.0

[33] rpart_4.1-11Rcpp_0.12.10latticeExtra_0.6-28
>

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


Re: [R] Antwort: Re: RStudio: Place for Storing Options

2017-02-23 Thread Keith Jewell
RStudio seems to not pay due regard to the distinction between APPDATA 
and LOCALAPPDATA.


See 
https://support.rstudio.com/hc/en-us/community/posts/200650543-File-history-and-project-history-stored-in-LOCALAPPDATA


On 23/02/2017 08:00, g.maub...@weinwolf.de wrote:

Hi Martin,

the command

%localappdata%\RStudio-Desktop

gives on my machine

"The command is written wrong or could not be found.".

I found "RStudio-Desktop" under

C:\Users\\AppData\Local\RStudio-Desktop

There references on created notebooks and presentations are stored in the
folder "RStudio-Desktop". RStudio config is not documented yet.

Kind regards

Georg




Von:Martin Maechler 
An: Jeff Newmiller ,
Kopie:  Martin Maechler ,
, R-help mailing list 
Datum:  23.02.2017 08:37
Betreff:Re: [R] RStudio: Place for Storing Options




Jeff Newmiller 
 on Sat, 11 Feb 2017 08:09:36 -0800 writes:


 > For the record, then, Google listened to my incantation of
 > "rstudio configuration file" and the second result was:

 >
https://support.rstudio.com/hc/en-us/articles/200534577-Resetting-RStudio-Desktop-s-State


 > RStudio Desktop is also open source, so you can download
 > the source code and look at the operating-system-specific
 > bits (for "where") if the above link goes out of date or
 > disappears.

Thanks a lot, Jeff!

And for the archives:  On reasonable OS's,  the hidden
directory/folder containing all the info is
   ~/.rstudio-desktop/
and if "things are broken" the recommendation is to rename that
mv ~/.rstudio-desktop  ~/backup-rstudio-desktop
and (zip and) send along with your e-mail to the experts for diagnosis.


 > On Thu, 9 Feb 2017, Martin Maechler wrote:

 >>
 >>> Ulrik Stervbo  on Thu, 9
 >>> Feb 2017 14:37:57 + writes:
 >>
 >> > Hi Georg, > maybe someone here knows, but I think you
 >> are more likely to get answers to > Rstudio related
 >> questions with RStudio support: >
 >> https://support.rstudio.com/hc/en-us
 >>
 >> > Best, > Ulrik
 >>
 >> Indeed, thank you, Ulrik.
 >>
 >> In this special case, however, I'm quite sure many
 >> readers of R-help would be interested in the answer; so
 >> once you receive an answer, please post it (or a link to
 >> a public URL with it) here on R-help, thank you in
 >> advance.
 >>
 >> We would like to be able to *save*, or sometimes *set* /
 >> *reset* such options "in a scripted manner", e.g. for
 >> controlled exam sessions.
 >>
 >> Martin Maechler, ETH Zurich
 >>
 >> > On Thu, 9 Feb 2017 at 12:35 
 >> wrote:
 >>
 >> >> Hi All, >> I would like to make a backup of my RStudio
 >> IDE options I configure using >> "Tools/Global Options"
 >> from the menu bar. Searching the >> web did not reveal
 >> anything.
 >>
 >> >> Can you tell me where RStudio IDE does store its
 >> configuration?
 >>
 >> >> Kind regards >> Georg
 >>
 >> __
 >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and
 >> more, see https://stat.ethz.ch/mailman/listinfo/r-help
 >> PLEASE do read the posting guide
 >> http://www.R-project.org/posting-guide.html and provide
 >> commented, minimal, self-contained, reproducible code.
 >>

 >
---
 > Jeff Newmiller The .  .  Go Live...
 > DCN: Basics: ##.#.  ##.#.  Live
 > Go...  Live: OO#.. Dead: OO#..  Playing Research Engineer
 > (Solar/Batteries O.O#.  #.O#.  with /Software/Embedded
 > Controllers) .OO#.  .OO#.  rocks...1k
 >



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


Re: [R] Strange message after reading multiple scripts from one folder

2016-07-29 Thread Keith Jewell
I can't immediately see it in the help text but it seems that source 
returns a list with two named elements; value and visible.


I surmise that it is returned using withVisible (qv).

KJ

On 29/07/2016 13:26, jim holtman wrote:

Hard to tell without seeing the scripts.  Do you have a matrix in your
scripts that have "value" and "visible" as row names?  You probably have
some statement that is causing output and so the problem is "your" as to
how to avoid the message.  So look at your scripts to see if anything
refers to either "value" or "visible", and then you might find the cause of
your problem.


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

On Fri, Jul 29, 2016 at 6:52 AM, Frank S.  wrote:


Dear list,

I have one folder named "scripts_JMbayes", wich contains 10 R scripts.
I can read them properly by doing:


pathnames <- list.files(pattern="[.]R", path="Mydir/scripts_JMbayes",

full.names = TRUE)

sapply(pathnames, USE.NAMES = FALSE, FUN = source,)


However, R generates the following message:

 [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]  [,9]  [,10]
value   ? ? ? ? ? ? ? ? ? ?
visible FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE

What does it mean and what should I change to avoid this message?
Any help would be appreciated!

Best,

Frank


 [[alternative HTML version deleted]]

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



[[alternative HTML version deleted]]



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


Re: [R] [FORGED] Re: Generate list if sequence form two vector element

2016-06-22 Thread Keith Jewell

or as a one-liner
mapply(pmin(a, b), pmax(a,b), FUN=seq, SIMPLIFY=FALSE)

On 22/06/2016 10:23, peter dalgaard wrote:

There's also

mapply(a, b, FUN=seq, SIMPLIFY=FALSE)

(turn off simplication so that you don't unexpectedly get a matrix whenever all 
elements of results have same length. This also affects apply()-based 
solutions.)

...except that according to original spec, one should ensure a < b. So

myseq <- function(a,b) if(a wrote:

Now why didn't I think of that?

apply(matrix(c(a,b),ncol=2),1,function(x)x[1]:x[2])

Jim

On Wed, Jun 22, 2016 at 6:14 PM, Rolf Turner  wrote:

On 22/06/16 20:00, Jim Lemon wrote:


Hi Tanvir,
Not at all elegant, but:

make.seq<-function(x) return(seq(x[1],x[2]))
apply(matrix(c(a,b),ncol=2),1,make.seq)



Not sure that this is more "elegant" but it's a one-liner:

lapply(1:length(a),function(i,a,b){a[i]:b[i]},a=a,b=b)

cheers,

Rolf



On Wed, Jun 22, 2016 at 5:32 PM, Mohammad Tanvir Ahamed via R-help
 wrote:


Hi,
I want to do the follow thing

Input :
a <- c(1,3,6,9)


b<-c(10,7,20,2)


Expected outcome :

d<-list(1:10,3:7,6:20,2:9)


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] expand.model.frame issue

2016-06-09 Thread Keith Jewell
Following on from a stackoverflow question "Why does this simple 
function calling `lm(..., subset)` fail?"


--
myfun <- function(form., data., subs.) lm(form., data., subs.)
myfun(mpg ~ cyl + hp, mtcars, TRUE)
## Error in eval(expr, envir, enclos) : object 'subs.' not found
-

The answer to the stated question was in ?lm "If not found in data, the 
variables are taken from environment(formula), typically the environment 
from which lm is called"; the environment of the formula (mpg ~ cyl + 
hp) does not contain 'subs.'. A fix is quite straightforward, set the 
environment of the formula to that of the function, which does contain 
'subs.'. There are multiple ways of doing that, this works but to me 
seems a bit "clunky":

---
myfun <- function(form., data., subs.) lm(as.formula(deparse(form.)), 
data., subs.)

myfun(mpg ~ cyl + hp, mtcars, TRUE)
--
To me this seems more elegant, but then I have no taste :-}
--
myfun <- function(form., data., subs.){
  environment(form.) <- environment()
  lm(form., data., subs.)}
myfun(mpg ~ cyl + hp, mtcars, TRUE)
--

But the OP went on to consider `expand.model.frame` e.g.
-
myfun <- function(form., data., subs.){
  environment(form.) <- environment()
  model <- lm(form., data., subs.)
  print(ls(envir = environment(formula(model
  expand.model.frame(model, ~drat)}
myfun(mpg ~ cyl + hp, mtcars, TRUE)
## [1] "data." "form." "model" "subs."
## Error in eval(expr, envir, enclos) : object 'subs.' not found
-

myfun can be fixed by (e.g.) avoiding the subset argument of lm

myfun <- function(form., data., subs.){
  environment(form.) <- environment()
  model <- lm(form., data.[subs.,])
  expand.model.frame(model, ~drat)}
myfun(mpg ~ cyl + hp, mtcars, TRUE)

... but this message is about the apparent inconsistency between the 
behaviour of expand.model.frame and the help text which says:

?expand.model.frame:
---
Usage

expand.model.frame(model, extras,
   envir = environment(formula(model)),
   na.expand = FALSE)

envir   an environment to evaluate things in
-

In the example of the `expand.model.frame` issue above the result of the 
'ls()' clearly shows that 'subs.' is in that environment, but 
expand.model.frame fails to find it.


Am I misunderstanding?
Or is there an error in the help text?
Or is there a bug in expand.model.frame?

=
I don't think this is relevant, but for completeness
> sessionInfo()
R version 3.3.0 (2016-05-03)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows Server 2008 R2 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United 
Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C 


[5] LC_TIME=English_United Kingdom.1252

attached base packages:
[1] graphics  grDevices datasets  stats tcltk utils tools 
  methods   base


other attached packages:
 [1] CBRIutils_1.0   stringr_1.0.0   svSocket_0.9-57 TinnR_1.0-5 
R2HTML_2.3.1Hmisc_3.17-4ggplot2_2.1.0

 [8] Formula_1.2-1   survival_2.39-4 lattice_0.20-33

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.5 magrittr_1.5cluster_2.0.4 
splines_3.3.0   devtools_1.11.1
 [6] munsell_0.4.3   colorspace_1.2-6plyr_1.8.3 
nnet_7.3-12 grid_3.3.0
[11] data.table_1.9.6gtable_0.2.0latticeExtra_0.6-28 
withr_1.0.1 svMisc_0.9-70
[16] digest_0.6.9Matrix_1.2-6gridExtra_2.2.1 
RColorBrewer_1.1-2  acepack_1.3-3.3
[21] rpart_4.1-10memoise_1.0.0   stringi_1.1.1 
scales_0.4.0foreign_0.8-66

[26] chron_2.3-47

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


Re: [R] formula argument evaluation

2016-04-12 Thread Keith Jewell

On 12/04/2016 11:24, Adrian Dușa wrote:

I have a simple function such as:

foo <- function(x) {
 call <- lapply(match.call(), deparse)
 testit <- capture.output(tryCatch(eval(x), error = function(e) e))
 if (grepl("Error", testit)) {
 return(call$x)
 }
}

and I would like to detect a formula when x is not an object:

# this works

foo(A + B)

[1] "A + B"

# but this doesn't

foo(A + B => C)

Error: unexpected '=' in "foo(A + B ="

Can I prevent it from evaluating the "=" sign?
The addition sign "+" hasn't been evaluated, and I was hoping the "=" would
not get evaluated either. The "=>" sign is important for other purposes,
not related to this example.

Thank you in advance,
Adrian

--
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]


Did you mean
> foo (A + B >= C)
??

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

Re: [R] Issue with results from 'summary' function in R

2015-09-18 Thread Keith Jewell

On 18/09/2015 13:08, Praveen Surendran wrote:

Hi all,

Attached table (that contains summary for a genetic association study) was read 
using the command:

test <- read.table('testDat.txt',header=FALSE,stringsAsFactors=FALSE)

Results from the summary of the attached table is provided below:


summary(test$V5)

Min. 1st Qu.  MedianMean 3rd Qu.Max.
   22070   22070   22070   22070   22070   22070

As we can see column 5 of this table contains only one value - 22072
I am confused as to why I am getting a value 22070 in the summary of this 
column.

I tested this using versions of R including - R version 3.2.1 (2015-06-18) -- 
"World-Famous Astronaut"

Thank you for looking at this issue.
Kind Regards,

Praveen.


> summary(22072, digits=5)
   Min. 1st Qu.  MedianMean 3rd Qu.Max.
  22072   22072   22072   22072   22072   22072

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] predict.poly for multivariate data

2015-07-10 Thread Keith Jewell
A recent stackoverflow post 
http://stackoverflow.com/questions/31134985 How do you make R poly() 
evaluate (or “predict”) multivariate new data (orthogonal or raw)? made 
me look at poly and polym again.


predict.poly doesn't work with multivariate data because for such data 
poly calls polym which does not:

a) return an object inheriting from class poly;
b) return the coefficients needed to make predictions;
c) accept coefficients as an argument or include code to make predictions.

This does lead to some wrong answers without warnings. e.g.
## vanilla poly and polym ###
library(datasets)
alm - lm(stack.loss ~ poly(Air.Flow, Water.Temp, degree=3), stackloss)
# correct prediction values [1:10]
alm$fitted.values[1:10]
# predict(alldata)[1:10] gives correct values
predict(alm, stackloss)[1:10]
# predict(partdata) gives wrong values
predict(alm, stackloss[1:10,])
#
I guess - but haven't confirmed - that with multivariate newdata 
predict.lm(alm, newdata) calculates new orthogonal polynomials based on 
newdata rather than applying the original coefficients.


Below I append versions of:
a) polym edited to address the three points above;
b) poly slightly edited to reflect the changes in polym;
c) predict.poly unaltered, just to get it in the same environment as 
polym and poly for testing.

After implementing these the three sets of predictions above all agree.

I'm very ready to believe that I've got the wrong end of the stick 
and/or my suggestions can be improved so I welcome correction.


Otherwise, how do I go about getting these changes implemented?
I see stats is maintained by R Core Team. Are they likely to pick it up 
from here, or do I need to take any other action?


Best regards

Keith Jewell

### polym ##
polym - function (..., degree = 1, coefs = NULL, raw = FALSE)
# add coefs argument
{
  if(is.null(coefs)) {
dots - list(...)
nd - length(dots)
if (nd == 0)
  stop(must supply one or more vectors)
if (nd == 1)
  return(poly(dots[[1L]], degree, raw = raw))
n - sapply(dots, length)
if (any(n != n[1L]))
  stop(arguments must have the same length)
z - do.call(expand.grid, rep.int(list(0:degree), nd))
s - rowSums(z)
ind - (s  0)  (s = degree)
z - z[ind, ]
s - s[ind]
aPoly - poly(dots[[1L]], degree, raw = raw) # avoid 2 calcs
res - cbind(1, aPoly)[, 1 + z[, 1]]
# attribute coefs = list of coefs from individual variables
if (!raw) coefs - list(attr(aPoly, coefs))
for (i in 2:nd) {
  aPoly - poly(dots[[i]], degree, raw = raw)
  res - res * cbind(1, aPoly)[, 1 + z[, i]]
  if (!raw) coefs - c(coefs, list(attr(aPoly, coefs)))
}
colnames(res) - apply(z, 1L, function(x) paste(x, collapse = .))
attr(res, degree) - as.vector(s)
if (!raw) attr(res, coefs) - coefs
class(res) - c(poly, matrix) # add poly class
res
  }
  else
  {
nd - length(coefs)# number of variables
newdata - as.data.frame(list(...)) # new data
if (nd != ncol(newdata)) stop(wrong number of columns in newdata)
z - do.call(expand.grid, rep.int(list(0:degree), nd))
s - rowSums(z)
ind - (s  0)  (s = degree)
z - z[ind, ]
res - cbind(1, poly(newdata[[1]], degree=degree, 
coefs=coefs[[1]]))[, 1 + z[, 1]]
for (i in 2:nd) res - res*cbind(1, poly(newdata[[i]], 
degree=degree, coefs=coefs[[i]]))[, 1 + z[, i]]

colnames(res) - apply(z, 1L, function(x) paste(x, collapse = .))
res
  }
}
##

 poly ##
poly - function (x, ..., degree = 1, coefs = NULL, raw = FALSE)
{
  dots - list(...)
  if (nd - length(dots)) {
if (nd == 1  length(dots[[1L]]) == 1L)
  degree - dots[[1L]]
# pass coefs argument as well
else return(polym(x, ..., degree = degree, coefs=coefs, raw = raw))
  }
  if (is.matrix(x)) {
m - unclass(as.data.frame(cbind(x, ...)))
# pass coefs argument as well
return(do.call(polym, c(m, degree = degree, raw = raw, 
list(coefs=coefs

  }
  if (degree  1)
stop('degree' must be at least 1)
  if (anyNA(x))
stop(missing values are not allowed in 'poly')
  n - degree + 1
  if (raw) {
Z - outer(x, 1L:degree, ^)
colnames(Z) - 1L:degree
attr(Z, degree) - 1L:degree
class(Z) - c(poly, matrix)
return(Z)
  }
  if (is.null(coefs)) {
if (degree = length(unique(x)))
  stop('degree' must be less than number of unique points)
xbar - mean(x)
x - x - xbar
X - outer(x, seq_len(n) - 1, ^)
QR - qr(X)
if (QR$rank  degree)
  stop('degree' must be less than number of unique points)
z - QR$qr
z - z * (row(z) == col(z))
raw - qr.qy(QR, z)
norm2 - colSums(raw^2)
alpha - (colSums(x * raw^2)/norm2 + xbar)[1L:degree]
Z - raw/rep(sqrt(norm2), each = length(x))
colnames(Z) - 1L:n - 1L
Z - Z[, -1, drop = FALSE]
attr(Z, degree) - 1L:degree
attr(Z, coefs) - list(alpha = alpha, norm2 = c(1

Re: [R] Problem with particular file in XML package?

2015-05-28 Thread Keith Jewell
The OP asked Has anyone else had trouble with the XML package lately 
and if so, how did you resolve it?


For what it's worth...

I failed to install XML using install() with the defaults; I can't 
remember the exact error message, something about access denied.


Downloading XML_3.98-1.1.zip with Internet Explorer 
http://cran.r-project.org/bin/windows/contrib/3.2/XML_3.98-1.1.zip 
gave a more informative error:


Threat Source: http://cran.r-project.or...trib/3.2/XML_3.98-1.1.zip

The file requested could not be scanned by Sophos Anti-Virus. This means 
it could be encrypted or may contain errors that prevent full scanning. 
As a result, the file was blocked from downloading.

=
... so my access was blocked by our systems anti-virus.

Our IT people bypassed the anti-virus to download the zip from which I 
successfully installed.


I note that in the library as installed there is a file
   ...\XML\exampleData\dtd.zip
Double-clicking in Windows Explorer gives an error:
=
Windows cannot open the folder. The Compressed (zipped) Folder ... is 
invalid.

=

I speculate that Sophos Anti-Virus could not scan dtd.zip because it 
tried to open it as a zipped folder and failed. I don't know if it 
really is a zipped folder or if that's just its name :-O


This 2013 thread seems relevant 
https://stat.ethz.ch/pipermail/r-sig-mac/2013-November/010494.html



On 28/05/2015 07:38, Prof Brian Ripley wrote:

This really should have been sent to the package maintainer.  But that
the zip file is corrupt has been reported several times, and does not
block installation for anyone else, so your (plural) diagnosis is wrong.

On 28/05/2015 03:56, Gen wrote:

I have been attempting to install the R devtools package at work.  The
version of R is 3.1.2 (Pumpkin Helmet).  However, the installation of
devtools fails because devtools depends on rversions which in turn
depends
upon the XML package (XML_3.98-1.1.tar.gz), and the XML package is not
importing correctly for us.

One of our system administrators tried scanning through the files in the
XML package, and he said that the particular file:
/src/contrib/XML_3.98-1.1.tar.gz/XML/inst/exampleData/dtd.zip looks
corrupted.  The actual error message he received was: Archive parsing
failed!  (Data is corrupted).  For the record, I tried downloading an
older version of the XML package (XML_3.95-0.1.tar.gz) but that was also
without success -- this time there was a separate error message about not
being able to locate xml2-config.  (Perhaps XML_3.95-0.1.tar.gz is
just not
compatible with R version 3.1.2?)

I tried browsing over to the CRAN checks link for the XML package and
noticed several red warning messages under the Status column -- not
sure
if that is typical?  Has anyone else had trouble with the XML package
lately and if so, how did you resolve it?  Would it be possible to remove
the potentially corrupted file and then re-upload the package source
XML_3.98-1.1.tar.gz to the CRAN webpage?  Thanks for your
help/suggestions!

[[alternative HTML version deleted]]

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


PLEASE do, including what it says about HTML mail, 'at a minimum'
information required and upgrading before posting: R 3.1.2 is already 2
versions obsolete.



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


Re: [R] rgl::writeWebGL( , prefix = , )

2015-02-03 Thread Keith Jewell

Thanks Duncan, your suggestions led me to a solution.

Perhaps this could be reflected in the help, but I'll leave that 
decision to you.


It comes down to the template. As well as including a single line for 
each scene containing

  paste(%, prefix, WebGL%); e.g. %WebGL% or %AWebGL%
the body   tag must contain an onload attribute with an element for 
each scene

  paste0(prefix, webGLStart();)
e.g. body onload=webGLStart(); AwebGLStart();

While I'm suggesting additions to the help, it took me a little while to 
work out that when writing multiple scenes the result from one 
writeWebGL was the template for the next. E.g. in the above example with 
two scenes:


outfile - writeWebGL(dir=getwd(), template = file.path(getwd(), 
template.html), prefix=)

# position to next scene
outfile - writeWebGL(dir=getwd(), template = outfile, prefix=A)

Thanks for your help (and a really nice package!)

Keith J

On 03/02/2015 15:14, Duncan Murdoch wrote:

On 03/02/2015 9:43 AM, keith.jew...@campdenbri.co.uk wrote:

Dear all,

I am using writeWebGL to create an HTML page containing an interactive
3D plot. It works fine with the default prefix= but fails when I
specify a prefix for different scenes displayed on the same web page
(quoting ?writeWebGL).  I'm sure I'm misreading the help, and would
appreciate guidance.

Briefly, it works fine with the default writeWebGL( ,prefix=, ) and
the template containing %WebGL%
I have not been able to make it work with any other value of prefix;
e.g. writeWebGL( ,prefix=A,) and the template containing %AWebGL%

Here is code illustrating the problem.

First create three templates:
a) Vanilla: copied system.file(file.path(WebGL, template.html),
package=rgl) to file.path(getwd(), template.html)

b) First attempt: ?writeWebGL says # [the template] should contain a
single line containing paste(%, prefix, WebGL%), e.g. %WebGL% with
the default empty prefix
paste(%, A, WebGL%)
# [1] % A WebGL%
so file.path(getwd(), templateA.html) is a copy of (a) replacing
%WebGL% with % A WebGL%

c) Second attempt: file.path(getwd(), templateB.html) is  a copy of
(a) replacing %WebGL% with %AWebGL%

then, in R
#---
library(rgl)
plot3d(1:5, 1:5, 1:5) # generate rgl scene
#---
# a) vanilla
writeWebGL(dir=getwd(), template = file.path(getwd(),
template.html), prefix=)
# works OK; result opens and works in IE
#
# b) First attempt, my reading of ?writeWebGL
writeWebGL(dir=getwd(), template = file.path(getwd(),
templateA.html), prefix=A)
# Error in writeWebGL(dir = getwd(), template = file.path(getwd(),
templateA.html),  :
#   template ‘m://templateA.html’ does not contain
%AWebGL%
# so it looks as if the help is trivially wrong, it should be paste0
paste0(%, A, WebGL%)


Yes, that's right.  I'll fix it.


# [1] %AWebGL%
#
# c) second attempt using %AWebGL%
writeWebGL(dir=getwd(), template = file.path(getwd(),
templateB.html), prefix=A)
# runs without error in R but IE displays You must enable Javascript
to view this page properly.
#--

I don't understand why (c) is different from (a).


There may be an error in the generated Javascript.  In Firefox, you
could ask to see the browser console log, and it would report if there
was an error on the page; sometimes those make the Javascript fail, and
it falls back to the error message you saw.  I don't know how/if you can
do that in IE.




Here are the system details:

R version 3.1.0 (2014-04-10)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

attached base packages:
[1] grDevices datasets  splines   graphics  stats tcltk utils
  [8] tools methods   base

other attached packages:
[1] knitr_1.8   animation_2.3   rgl_0.95.1158   CBRIutils_1.0


That's an old version of rgl; current on CRAN is 0.95.1201.
http://cran.r-project.org/src/contrib/rgl_0.95.1201.tar.gz (CRAN OSX
currently has an old binary; I don't recommend that you use it.  I don't
know why they haven't updated to the current one.) r-forge has even
newer versions, but I'm in the middle of some changes there, so I don't
recommend using that version right now.

Duncan Murdoch
http://cran.r-project.org/src/contrib/rgl_0.95.1201.tar.gz

  [5] stringr_0.6.2   svSocket_0.9-55 TinnR_1.0-5 R2HTML_2.3.1
  [9] Hmisc_3.12-2Formula_1.1-1   survival_2.37-7

loaded via a namespace (and not attached):
[1] cluster_1.15.3  devtools_1.6.1  evaluate_0.5.5  formatR_1.0
[5] grid_3.1.0  highr_0.4   lattice_0.20-29 rpart_4.1-8
[9] svMisc_0.9-70

Internet Explorer 11 Version 11.0.9600.17420

Any advice is welcome.


Keith Jewell - Statistician
Tel: +44 (0)1386 842055
Web:  www.campdenbri.co.uk
Email:  keith.jew...@campdenbri.co.uk

Campden BRI (Chipping Campden) Limited - part of the Campden BRI group
Station Road ♦ Chipping Campden

Re: [R] Is it possible to define another kind of NA

2014-11-13 Thread Keith Jewell

On 13/11/2014 11:08, Marc Girondot wrote:

Le 13/11/2014 01:26, MacQueen, Don a écrit :

Along the lines of what Bert Gunter said, the ideal way to represent LDL
results depends on the functions used later to analyze them. I deal with
such data on a daily basis and have never found it necessary to
incorporate that information in the same variable as the results. What
would you do if data were censored at both ends, both low and high?

Anyway, the functions I use mostly incorporate that information in a
second variable, a ³detection indicator² variable, and that¹s what I do.

-Don


I agree that LDL is a special case of what could be named ODL (Out of
detection limit).
To answer to Bert Gunter, indeed if LDL (or ODL) values are changed into
NA, the results will be biased. That's why I would like to introduce
another category. I don't plan to just transform them as NA.

But thinking again about this problem, a LDL must be always associated
with one value (or two in the case of ODL) that indicates the detection
limit. In a dataset, all values have not necessarily the same limit
depending on the experimental conditions.
The best solution that I find is to use attributes to indicate the
limits. A NA attribute for a NA value will be treated as a true NA.
For exemple:

  values - c(NA, 29, 30, NA, 3)
  attributes(values) - list(ODL=c(NA, [10, 40], [0, 40], [0,
40], [0, 40]))
  values
[1] NA 29 30 NA  3
attr(,ODL)
[1] NA [10, 40] [0, 40]  [0, 40]  [0, 40]
  values[3]
[1] 30
  attributes(values)$ODL[3]
[1] [0, 40]
  values[1]
[1] NA
  attributes(values)$ODL[1]
[1] NA

The attributes are retained in data.frame. So it seems to be a good
solution.

  essai - data.frame(c1=values)
  essai
   c1
1 NA
2 29
3 30
4 NA
5  3
  essai$c1
[1] NA 29 30 NA  3
attr(,ODL)
[1] NA [10, 40] [0, 40]  [0, 40]  [0, 40]

Thanks to the list members,

Marc

I strongly recommend you re-read and take action on Bert Gunter's 
comment, quoted here for truth!

-
Ouch!

The values are **NOT** missing -- they are (left) censored, and need
to be handled by appropriate censored data methods. I suggest you
(all!) either read up on this or consult someone locally who has
knowledge of such methods.

-- Bert

You are re-inventing the wheel and yours will probably end up square!
R already has facilities for handling censored data, e.g. Surv in the 
survival package (which despite its name is applicable to applications 
other than survival analysis).


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


Re: [R] Is xyz point inside 3d convex hull?

2014-10-13 Thread Keith Jewell

Back in 2009 I posted some code to this list, see:
http://tolstoy.newcastle.edu.au/R/e8/help/09/12/8784.html

I submitted the function 'inhull' to the geometry package maintainer, 
but I don't think it was ever included.


HTH

Keith J
On 12/10/2014 21:24, Don McKenzie wrote:

Check the R-news archive with approrpriate keywords.  There was a long exchange 
awhile back when I asked a similar question.

On Oct 12, 2014, at 1:20 PM, Camilo Mora cm...@dal.ca wrote:


Hi everyone,

I wonder if there is a code in r that can generate a 3d convex hull from a 
data-frame containing 3 columns and then use another database with the same 
three columns and for each row determine if the xyz point is inside or not the 
convex hull generated with the first database?

The package geometry allows to calculate a hull and it's volume. I was planning 
to calculate the volume of the convex hull after adding each point in the 
second database and if the hull gets bigger then the point is out and if not 
then the point is in. A problem with this method is that I have over 10 million 
points and the calculation for each point will take a lot of time.

Any guidance will be greatly appreciated,

Thanks,

Camilo

[[alternative HTML version deleted]]


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


Re: [R] How to check to see if a variable is within a range of another variable

2014-10-02 Thread Keith Jewell

On 01/10/2014 23:54, Peter Alspach wrote:

Tena koe Kate

If kateDF is a data.frame with your data, then

apply(kateDF, 1, function(x) isTRUE(all.equal(x[2], x[1], check.attributes = 
FALSE, tolerance=0.1)))

comes close to (what I think) you want (but not to what you have illustrated in 
your 'eventual outcome').  Anyhow, it may be enough to allow you to get there.

HTH 

Peter Alspach



I seem to need to specify all.equal(..., scale) to get correct values 
for some data/tolerances:

--
aDF - data.frame(a = 1:10, b=10:1)

apply(aDF, 1, function(x)
  isTRUE(all.equal(x[2], x[1], check.attributes = FALSE, tolerance = 5, 
scale = 1))

  )
#  [1] FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE
apply(aDF, 1, function(x)
  isTRUE(all.equal(x[2], x[1], check.attributes = FALSE, tolerance = 5))
)
#  [1]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE
--
I'm probably being stupid, but from reading ?all.equal I would have 
expected scale = 1 and the default scale = NULL to give identical 
results for the length one numerics being passed to all.equal.


Can anyone explain?

KJ

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


Re: [R] Windows R doesn't recognize shortcuts ?

2014-07-24 Thread Keith Jewell

On 23/07/2014 14:21, Duncan Murdoch wrote:

On 23/07/2014 9:08 AM, ce wrote:

Hi All,

In Windows 7 , R installation:

R version 3.1.1 Patched (2014-07-14 r66149) -- Sock it to Me
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

it doesn't recognize shortcuts in path :

  list.files(path = cygwin)
character(0)

cygwin is a shortcut,  in properties window  Target shows :
C:\Users\me\cygwin64\home\me
Real path works :

list.files(path = C:/Users/me/cygwin64/home/me)
   [1] 1010week.sh10week.sh
a.Raa.sh



I don't think R should recognize that.  Windows wouldn't recognize it
either, if you used dir cygwin in a shell, for example.

Duncan Murdoch


The shortcut which appears as cygwin is actually a file
called cygwin.lnk

readWindowsShellLink {R.utils} reads such files:
 readWindowsShellLink(con=cygwin.lnk)

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


Re: [R] Equation of a curve

2014-04-04 Thread Keith Jewell

On 03/04/2014 16:26, Frances Cheesman wrote:

Hi all,

I have a number of bacterial growth curves I would like to find the
equations for these and then integrate them to find the area under the
curves for me to do stats on later.

Is there any way I can do this in R?

Thanks,

Frances

[[alternative HTML version deleted]]

Responding to the curve fitting question and passing over the 
integration issue...


It is quite common to use nls to fit equations to log(count) v time 
data. You'll have to choose an appropriate model, ideally as a self 
starting nls model. Of those included in the stats package you might 
consider SSfpl, SSgompertz, SSlogis and SSweibull.


But choice of a model is really a microbiological issue and all those 
models might be considered a little passe. Fitting this kind of 
sigmoidal model can be difficult unless the data is good.


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


Re: [R] A vector of normal distributed values with a sum-to-zero constraint

2014-04-01 Thread Keith Jewell

It seems so simple to me, that I must be missing something.

Subject to Jeff Newmiller's reminder of FAQ 7.31; if the sum is zero 
then the mean is zero and vice versa.


The OP's original attempt of:
-
l - 100
aux - rnorm(l,0,0.5)
s - sum(aux)/l
aux2 - aux-s
sum(aux2)
-
is equivalent to

  aux2 - rnorm(l,0,0.5)
  aux2 - aux2-mean(aux2)

If calculations were exact then aux2 would have mean, and thus sum, 
equal to zero - any difference from zero is attributable entirely to 
machine precision.



On 01/04/2014 15:25, Boris Steipe wrote:

But the result is not Normal. Consider:

set.seed(112358)
N - 100
x - rnorm(N-1)
sum(x)

[1] 1.759446   !!!

i.e. you have an outlier at 1.7 sigma, and for larger N...

set.seed(112358)
N - 1
x - rnorm(N-1)
sum(x)
[1] -91.19731

B.


On 2014-04-01, at 10:14 AM, jlu...@ria.buffalo.edu wrote:


The sum-to-zero constraint imposes a loss of one degree of freedom.  Of  N 
samples, only (N-1) can be random.   Thus the solution is

N - 100
x - rnorm(N-1)
x - c(x, -sum(x))
sum(x)

[1] -7.199102e-17












Boris Steipe boris.ste...@utoronto.ca
Sent by: r-help-boun...@r-project.org
04/01/2014 09:29 AM

To
Marc Marí Dell'Olmo marceivi...@gmail.com,
cc
r-help@r-project.org r-help@r-project.org
Subject
Re: [R] A vector of normal distributed values with a sum-to-zero
constraint





Make a copy with opposite sign. This is Normal, symmetric, but no longer random.

  set.seed(112358)
  x - rnorm(5000, 0, 0.5)
  x - c(x, -x)
  sum(x)
  hist(x)

B.

On 2014-04-01, at 8:56 AM, Marc Marí Dell'Olmo wrote:


Dear all,

Anyone knows how to generate a vector of Normal distributed values
(for example N(0,0.5)), but with a sum-to-zero constraint??

The sum would be exactly zero, without decimals.

I made some attempts:


l - 100
aux - rnorm(l,0,0.5)
s - sum(aux)/l
aux2 - aux-s
sum(aux2)

[1] -0.0006131392


aux[1]- -sum(aux[2:l])
sum(aux)

[1] -0.03530422


but the sum is not exactly zero and not all parameters are N(0,0.5)
distributed...

Perhaps is obvious but I can't find the way to do it..

Thank you very much!

Marc

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


Re: [R] princomp/prcomp packages not available for 3.0.2

2014-02-19 Thread Keith Jewell

On 19/02/2014 15:47, Rich Shepard wrote:

   Running 3.0.2 on Slackware here. Tried to install.packages() for both
princomp and prcomp (Principal Components Analysis) but R responded by
telling me neither is available for this version of R.

   Has anyone an idea when either (but especially prcomp) might be
available?

TIA,

Rich

princomp and prcomp are not packages, they are functions in the 'stats' 
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.


Re: [R] grep for multiple pattern?

2014-02-13 Thread Keith Jewell

On 13/02/2014 15:51, Marc Schwartz wrote:


On Feb 13, 2014, at 8:43 AM, Rainer M Krug rai...@krugs.de wrote:


Hi

I want to search for multiple pattern as grep is doing for a single
pattern, but this obviously not work:


grep(an, month.name)

[1] 1

grep(em, month.name)

[1]  9 11 12

grep(eb, month.name)

[1] 2

grep(c(an, em, eb), month.name)

[1] 1
Warning message:
In grep(c(an, em, eb), month.name) :
  argument 'pattern' has length  1 and only the first element will be used




Is there an equivalent which returns the positions as grep is doing, but
not using the strict full-string matching of match()?

I could obviously do:


unlist( sapply(pat, grep, month.name ) )

an em1 em2 em3  eb
  1   9  11  12   2

but is there a more compact command I am missing?

Thanks,

Rainer



The vertical bar '|' acts as a logical 'or' operator in regex expressions:


grep(an|em|eb, month.name)

[1]  1  2  9 11 12


grep(an|em|eb, month.name, value = TRUE)

[1] January   February  September November  December


Regards,

Marc Schwartz


and if you want your patterns in a vector
 pat -c(an, em, eb)
 grep(paste(pat, collapse=|), month.name)
[1]  1  2  9 11 12

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


Re: [R] More Columns than column names Error

2013-10-22 Thread Keith Jewell

Carl is right.

Going to the nabble post and looking in the source data file 
http://r.789695.n4.nabble.com/file/n4678770/Garbage.txt I see the 
headings row has 'Material' tab 'Weight...' tab 'Percent'.
Each of the data rows has 1 tab character between the 'Material' and 
'Weight' columns and 3 tab characters between the 'Weight...' and 
'Percent' columns.


On 22/10/2013 14:15, Carl Witthoft wrote:

What is the exact code you are using to try to load this file?
I strongly suspect the problem is a mixture of spaces and multiple tabs in
your text file.



--
View this message in context: 
http://r.789695.n4.nabble.com/More-Columns-than-column-names-Error-tp4678770p4678787.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] Problem with converting F to FALSE

2013-09-05 Thread Keith Jewell

Depending what you're doing with the data, you might want
colClasses=c(factor,numeric)

On 05/09/2013 13:58, Joshua Wiley wrote:

Hi,

You can either manually specify colClasses or the asis argument.  See
?read.csv for more details.

If you just had those two columns, something like:

  read.table(header = TRUE, text = 
  sex group
  F 1
  T 2
  , colClasses = c(character, integer))

Cheers,

Josh


read.csv(file.csv, colClasses = c(character, integer))




On Thu, Sep 5, 2013 at 5:44 AM, Venkata Kirankumar
kiran4u2...@gmail.com  wrote:

Hi,
I have a peculier problem in R-Project that is when my CSV file have one
column with all values as 'F' the R-Project converting this 'F' to FALSE.
Can some one please suggest how to stop this convertion. Because I want to
use 'F' in my calculations and show it in screen. for example my data is
like

sex  group
F   1
F   2
F   3

but when I use read.csv and load the csv file data is converting it to

sex  group
FALSE   1
FALSE   2
FALSE   3
but i want it as source data like

sex group
F  1
F  2
F  3


Thanks in advance,
D V Kiran Kumar


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


Re: [R] XLSX package + Excel creation question

2013-09-04 Thread Keith Jewell
I'll skip over the courtesy implications of double posting/pointing to 
stackoverflow.


The stackoverflow thread makes it look as if you need to learn more 
Excel. Do you really not know what an Excel template is?


It sounds as if you want what Excel calls conditional formatting which 
you can specify as custom number formats, see 
http://www.ozgrid.com/Excel/CustomFormats.htm.


Excel's help on custom number formats says:

To specify number formats that will be applied only if a number meets a 
condition that you specify, enclose the condition in square brackets. 
The condition consists of a comparison operator (comparison operator: A 
sign that is used in comparison criteria to compare two values. 
Operators include: = Equal to,  Greater than,  Less than, = Greater 
than or equal to, = Less than or equal to, and  Not equal to.) and a 
value. For example, the following format displays numbers that are less 
than or equal to 100 in a red font and numbers that are greater than 100 
in a blue font.

[Red][=100];[Blue][100]
--

R package xlsx allows such formats (?DataFormat) as does R package 
XLConnect (?setDataFormat).


HTH

Keith J

On 04/09/2013 09:57, Zsurzsa Laszlo wrote:

http://stackoverflow.com/questions/18511249/excel-cell-coloring-using-xlsx

This is the initial post on stackoverflow. Please look at this maybe I'm
clearer here.

Thank you in advance,

-
- László-András Zsurzsa,-
- Msc. Infromatics, Technical University Munich, Germany -
- Scientific Employee, TUM -
-


On Fri, Aug 30, 2013 at 3:48 PM, jim holtmanjholt...@gmail.com  wrote:


You can also look at the XLConnect package.
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Thu, Aug 29, 2013 at 9:40 AM, Zsurzsa Laszlozsurzsalas...@gmail.com
wrote:

I understand you response but it does not solve the problem. I'am aware
that one can simply color every cell in an excel file by using his own
algorithm.

The question was if I can write my data to a *single* cells and use
different formatting for every piece of data.



-

- László-András Zsurzsa,-
- Msc. Infromatics, Technical University Munich, Germany -
- Scientific Employee, TUM -


-



On Thu, Aug 29, 2013 at 3:36 PM, Rainer Hurlingrhur...@gwdg.de  wrote:


Am 29.08.2013 15:03 (UTC+1) schrieb Zsurzsa Laszlo:

First of all thank you for the quick resposen.

I know I can color and set up every cell. I will take a look again *
CellStyle* but is it possbile for example to write an array to a

single

cell that has different colors for some data. Basically the color

depends

on the data.


As far as I know there is no ready to use functionality to mask groups
of selected cells. You have to write your own function, which selects
the right cells and changes their style with setCellStyle(cell,

cellStyle).


Some hints are given in the examples section of ?CellStyle.







-

- László-András Zsurzsa,

-

- Msc. Infromatics, Technical University Munich, Germany -
- Scientific Employee, TUM

   -





-



On Thu, Aug 29, 2013 at 2:55 PM, Rainer Hurlingrhur...@gwdg.de

wrote:



Am 29.08.2013 12:08 (UTC+1) schrieb Zsurzsa Laszlo:

Dear R users,

I have a question about the xlsx package. It's possible to create

excel

files and color cells and etc.


yes, with package xlsx you can colourize you data sheets, even the
fonts. See for example ?CellStyle .

A good demonstration of the capabilities is on





http://tradeblotter.wordpress.com/2013/05/02/writing-from-r-to-excel-with-xlsx/




My question would be that is it possible to color only some part of

the

data hold in a cell. Let's assume I've got the following data :
167,153,120,100 and I want to color to red everything that is bigger

then

120. How can I achive this using R.

Example file setup with a few lines in attachment. (SEL_MASS column

can

be

used for example)


Attachment missing ...

HTH,
Rainer



Thank you in advance,






-

- László-András Zsurzsa,

  -

- Msc. Infromatics, Technical University Munich, Germany -
- Scientific Employee, TUM

-







-




 

Re: [R] just a small variable-naming question

2013-08-27 Thread Keith Jewell
In case the OP wanted to append columns, rather than rename existing 
columns:


cbind(myData, var1=NA, var2=NA, var3=NA)
  col1 col2 col3 var1 var2 var3
1123   NA   NA   NA
2234   NA   NA   NA
3345   NA   NA   NA


On 24/08/2013 17:22, arun wrote:

Hi,
You could use ?paste()
colnames(myData)-paste(colnames(myData),paste0(var,1:3),sep=_)
  myData
#  col1_var1 col2_var2 col3_var3
#1 1 2 3
#2 2 3 4
#3 3 4 5

A.K.



- Original Message -
From: Richard Shermanrss@gmail.com
To: r-help@r-project.org
Cc:
Sent: Saturday, August 24, 2013 12:09 PM
Subject: [R] just a small variable-naming question

Hi all,

If I have this little data set:


myData- data.frame(col1 = 1:3, col2 =2:4, col3 = 3:5)
myData

   col1 col2 col3
1123
2234
3345

and I want to add (not replace) the names var1, var2, var3 to the existing 
col1, col2, col3, what is the right way to do that?

Thanks.

-Richard

---
Prof. Richard Sherman
Division of International Studies
Korea 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.




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


Re: [R] nls: example code throws error

2013-04-26 Thread Keith Jewell

On 26/04/2013 00:16, Steven LeBlanc wrote:
 Greets,

 I'm trying to learn to use nls and was running the example code for 
an exponential model:


  snip

 Perhaps also, a pointer to a comprehensive and correct document that 
details model formulae syntax if someone has one?


 Thanks  Best Regards,
 Steven

Others have pointed out that the error is probably from an unclean 
environment.


For model formula syntax, see ?nls
Under Arguments formula, follow the link to ?formula

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


Re: [R] approxfun values

2013-02-14 Thread Keith Jewell
Alternatively, with approx() use xout to specify which interpolated 
values you want returned:


approx(dat, xout=dat$V1[is.na(dat$V2)])

KJ

On 14/02/2013 11:43, Rui Barradas wrote:

Hello,

In what follows I've changed your df name to 'dat', to save some
keystrokes.
approxfun returns a function, so if you want just the interpolated
values, apply that function to the x values where y is NA.



dat - read.table(text = 
V1 V2
1 10 2
2 20 NA
3 30 5
4 40 7
5 50 NA
6 60 NA
7 70 2
8 80 6
9 90 9
10 100 NA
, header = TRUE)

f - approxfun(dat)
x - dat$V1[is.na(dat$V2)]
y - f(x)
y


Hope this helps,

Rui Barradas

Em 14-02-2013 08:43, e-letter escreveu:

Readers,

According to the help '?approxfun', the function can be used to obtain
the interpolated values. The following test was tried:


testinterpolation-read.csv('test.csv',header=FALSE)
testinterpolation

V1 V2
1 10 2
2 20 NA
3 30 5
4 40 7
5 50 NA
6 60 NA
7 70 2
8 80 6
9 90 9
10 100 NA

testinterpolationvalues-approxfun(testinterpolation,y=NULL)
testinterpolationvalues

function (v)
.C(C_R_approxfun, as.double(x), as.double(y), as.integer(n),
xout = as.double(v), as.integer(length(v)), as.integer(method),
as.double(yleft), as.double(yright), as.double(f), NAOK = TRUE,
PACKAGE = stats)$xout
bytecode: 0x33ffab84
environment: 0x34072eac

testinterpolationvalues-approx(testinterpolation,y=NULL)
testinterpolationvalues

$x
[1] 10.0 11.63265 13.26531 14.89796 16.53061 18.16327 19.79592
21.42857
[9] 23.06122 24.69388 26.32653 27.95918 29.59184 31.22449 32.85714
34.48980
[17] 36.12245 37.75510 39.38776 41.02041 42.65306 44.28571 45.91837
47.55102
[25] 49.18367 50.81633 52.44898 54.08163 55.71429 57.34694 58.97959
60.61224
[33] 62.24490 63.87755 65.51020 67.14286 68.77551 70.40816 72.04082
73.67347
[41] 75.30612 76.93878 78.57143 80.20408 81.83673 83.46939 85.10204
86.73469
[49] 88.36735 90.0

$y
[1] 2.00 2.244898 2.489796 2.734694 2.979592 3.224490 3.469388
3.714286
[9] 3.959184 4.204082 4.448980 4.693878 4.938776 5.244898 5.571429
5.897959
[17] 6.224490 6.551020 6.877551 6.829932 6.557823 6.285714 6.013605
5.741497
[25] 5.469388 5.197279 4.925170 4.653061 4.380952 4.108844 3.836735
3.564626
[33] 3.292517 3.020408 2.748299 2.476190 2.204082 2.163265 2.816327
3.469388
[41] 4.122449 4.775510 5.428571 6.061224 6.551020 7.040816 7.530612
8.020408
[49] 8.510204 9.00

How to obtain a vector consisting _only_ of the interpolated values?

It was expected that 'approx' would return both original and
interpolated values (which the above shows) and that 'approxfun' would
not show the original values.

--
r2151

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

2013-01-15 Thread Keith Jewell

On 14/01/2013 22:25, Hadley Wickham wrote:

I think codetools could do this reasonably well with the walkCode function,
but I've never done it so I don't have sample code, and walkCode is mostly
an internal function.


There are a couple of approaches here:
http://stackoverflow.com/questions/14276728/

Hadley


I've used foodweb in mvbutils for that kind of thing.

HTH

KJ

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


Re: [R] Effect of each term in the accuracy of Nonlinear multivariate regression fitting equation

2012-11-27 Thread Keith Jewell
In this context, linear model means linear in the _coefficients_ not 
(necessarily) linear in the predictors, so your model:

   JIM ~ z1*A + z2*B + z3*A*B^2 + z4*C*D^3 + z5*A^2*B^2 ...
is a linear model (in z1, z2, ...).

So you don't need to use nls, lm is probably favourite. You can use all 
the techniques around for evaluating linear models; anova.lm might give 
you a start.


KJ

On 27/11/2012 11:40, dsfakianakis wrote:

Dear all,

I have a set of data with 4 inputs (independent variables) and one output
(dependent variable). I want to perform a regression analysis in order to
fit these data to a regression model, however due to the non-linearity of
the model I do not have a clue which equation to use. I am thinking of
starting with a very general equation including ^3 terms and interactions
between the variables however this will lead to a very long equation. Is
there a way to assess the effect of each term to the accuracy of the
regression model in order to discard the terms with the least importance?
Something like a sensitivity analysis of the effect of each term to the
accuracy regression model. I know one possible solution to my problem is
simply 'trial and error' however before going down that road I want to check
if there is an easier way.

e.g. Let's say I have four input variables A B C and D, one output 'JIM' and
let z1, z2, ...  be the coefficients of the terms of the equation.  The
regression will be something like that:

Result = nls(JIM ~ z1*A + z2*B + z3*A*B^2 + z4*C*D^3 + z5*A^2*B^2 ... )

Is there a way to assess the contribution of each term (z1*A, z3*A*B^3 etc)
to the accuracy of the regression model?

Thanks a lot



--
View this message in context: 
http://r.789695.n4.nabble.com/Effect-of-each-term-in-the-accuracy-of-Nonlinear-multivariate-regression-fitting-equation-tp4650949.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] Mailing List

2012-09-05 Thread Keith Jewell
You might prefer to read list via the web or a news reader or an RSS 
feed, in which case http://dir.gmane.org/gmane.comp.lang.r.general might 
be helpful.


Keith J

On 05/09/2012 13:47, David Winsemius wrote:


On Sep 5, 2012, at 3:00 AM, Marcus Tullius wrote:


Hello there,

is there a way I can erase my name from the mailing list and still get mails 
concerning the topics


If you change your subscription options to daily digest ( at the page where you 
signed up), you can just read the top of the digest.


I am interested in? I cannot handle all those emails coming in constantly. I do 
not have time for that.

Greetings,
Francisco



David Winsemius, MD
Alameda, CA, USA



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


Re: [R] Tendonitis and R users

2012-09-04 Thread Keith Jewell
When I suffered from wrist pain I found changing from a standard mouse 
to a cordless trackball gave rapid and complete relief.


Your mileage may vary.

Keith J


I think I've avoided tendonitis by carefully stretching the affected
area when I begin to feel discomfort and, as John suggests, Carefully
watch posture and arm/hand actions to reduce strain.

Clint Bowman INTERNET: cl...@ecy.wa.gov
Air Quality Modeler INTERNET: cl...@math.utah.edu
Department of Ecology VOICE: (360) 407-6815
PO Box 47600 FAX: (360) 407-7534
Olympia, WA 98504-7600

USPS: PO Box 47600, Olympia, WA 98504-7600
Parcels: 300 Desmond Drive, Lacey, WA 98503-1274

On Tue, 4 Sep 2012, John Kane wrote:


I've come close a couple of times. Solutions: don't use computer-not
always practical. Carefully watch posture and arm/hand actions to
reduce strain.

If do a lot of keyboarding not just R type look into using a Dvoark
keyboard.

Something I have not done but which is likely to help is consult your
institutions health and safety people about solutions such as
ergonomic keyboards etc.

John Kane
Kingston ON Canada



-Original Message-
From: resea...@namibia.pharmaccess.org
Sent: Tue, 4 Sep 2012 12:55:36 +
To: r-help@r-project.org
Subject: [R] Tendonitis and R users


Hello
This request asks something beyond the technicalities of the R language,
I would like to ask you wonderful people if you have ever suffered as
programmers ( or de facto programmers like myself though I am a
'research
assistant') from tendonitis and how you coped with it, i have golfer's
elbow on both sides. Any resources?

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



FREE ONLINE PHOTOSHARING - Share your photos online with your friends
and family!
Visit http://www.inbox.com/photosharing to find out more!

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

2012-07-26 Thread Keith Jewell

Does

 delaunayn(scale(coord),options=Qbb)

help?

Keith J

On 26/07/2012 08:26, Jean-Luc Dupouey wrote:

Dear R helpers,

I try to use the 'delaunayn' function in the 'geometry' package for
Delaunay triangulation in 2 dimensions.

For the four following points, I get a warning message :

  coord=matrix(ncol=2,byrow=TRUE,c(622633,7073452,
+ 621228,7073517,
+ 621879,7071762,
+ 621065,7073331))
  library(geometry)
 
  test=delaunayn(coord,options=Qbb)

qhull precision warning:

The initial hull is narrow (cosine of min. angle is 0.).
Is the input lower dimensional (e.g., on a plane in 3-d)? Qhull may
produce a wide facet. Options 'QbB' (scale to unit box) or 'Qbb' (scale
last coordinate) may remove this warning. Use 'Pp' to skip this warning.
See 'Limitations' in qh-impre.htm.

I read carefully qh-impre.htm and I still do not understand why I get
this message. A simple call to plot(coord) shows that the points are not
aligned, nor very close.

What did I miss?

Thanking you in advance,

Jean-Luc Dupouey
INRA-Lorrain University
Forest Ecology  Ecophysiology Unit
F-54280 Champenoux
France
mail: dupo...@nancy.inra.fr



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


Re: [R] Interpreting Q-Q Plots

2012-05-15 Thread Keith Jewell

On 14/05/2012 23:21, Rich Shepard wrote:

On Tue, 15 May 2012, Peter Alspach wrote:

Probably highly skewed to the right, with discrete values (perhaps 
due to

the limitations in the accuracy of the assessment equipment).


Peter,

  Most of these data are near zero or the lower detection limit. A few
values are very much higher. I didn't think of skewness as a reason.


 But note:

library(fortunes)
fortune('chicken')


  And since I don't have the experience, the only way to gain it is by
learning from those with practice reading chicken entrails.

Thanks,

Rich

I found this page helpful 
http://www.cms.murdoch.edu.au/areas/maths/statsnotes/samplestats/qqplot.html


HTH

Keith J

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 'nls' fitting logistic model (5PL)

2012-05-03 Thread Keith Jewell
 ?nls.control
  fit- nls(MFI~a + b/((1+(nom/c)^d)^f), data=x, weights=x$weights,
+  start=c(a=100, b=1, c=100, d=-1, f=1), 
control=nls.control(warnOnly=TRUE))
Warning message:
In nls(MFI ~ a + b/((1 + (nom/c)^d)^f), data = x, weights = x$weights,  :
  step factor 0.000488281 reduced below 'minFactor' of 0.000976562
 fit
Nonlinear regression model
  model:  MFI ~ a + b/((1 + (nom/c)^d)^f)
   data:  x
 a  b  c  d  f
  165.4360 23866.124738.6157-0.4454 3.2210
 weighted residual sum-of-squares: 2627977

Number of iterations till stop: 23
Achieved convergence tolerance: 48.23
Reason stopped: step factor 0.000488281 reduced below 'minFactor' of 
0.000976563
 summary(fit)

Formula: MFI ~ a + b/((1 + (nom/c)^d)^f)

Parameters:
Estimate Std. Error t value Pr(|t|)
a  1.654e+02  2.742e+04   0.0060.995
b  2.387e+04  3.027e+06   0.0080.994
c  3.862e+01  3.030e+04   0.0010.999
d -4.454e-01  5.754e+01  -0.0080.994
f  3.221e+00  1.008e+03   0.0030.998

Residual standard error: 540.4 on 9 degrees of freedom

Number of iterations till stop: 23
Achieved convergence tolerance: 48.23
Reason stopped: step factor 0.000488281 reduced below 'minFactor' of 
0.000976563


Perhaps nls is a little more stringent than ANY  reliable statistical 
software in what, by default, it considers a fit worth reporting?

Keith J

Michal Figurski figur...@mail.med.upenn.edu wrote in message 
news:4fa2759c.3060...@mail.med.upenn.edu...
 Bert,

 Thank you for your thoughts.

 I can assure you I have plotted the data back and forth many times, and 
 that overfitting has nothing to do with it. This is not a _statistical_ 
 problem, but a _technical_ problem. Something that works well in ANY 
 reliable statistical software doesn't work in R with 'nls'.

 This just makes me think that 'nls' is a dysfunctional piece of junk that 
 can't handle even a very simple problem. Not to mention that 'predict()' 
 for 'nls' doesn't give you any sort of confidence interval.

 I wonder if there's another package in R that could be used to fit 
 5P-logistic model. Any idea?

 In the end I may attempt to write a fitting function myself, but that 
 would be the last resort.

 --
 Michal J. Figurski, PhD
 HUP, Pathology  Laboratory Medicine
 Biomarker Research Laboratory
 3400 Spruce St. 7 Maloney S
 Philadelphia, PA 19104
 tel. (215) 662-3413


 On 5/2/2012 3:47 PM, Bert Gunter wrote:
 Plot the data. You're clearly overfitting.

 (If you don't know what this means or why it causes the problems you
 see, try a statistical help list or consult your local statistician).

 -- Bert

 On Wed, May 2, 2012 at 12:32 PM, Michal Figurski
 figur...@mail.med.upenn.edu  wrote:
 Dear R-Helpers,

 I'm working with immunoassay data and 5PL logistic model. I wanted to
 experiment with different forms of weighting and parameter selection, 
 which
 is not possible in instrument software, so I turned to R.

 I am using R 2.14.2 under Win7 64bit, and the 'nls' library to fit the 
 model
 - I started with the same model and weighting type (1/y) as in the
 instrument to see if I'll get similar results. However, in some 
 instances I
 don't get any results - just errors.

 Here is an example calibration data, representative of my experiment.
 Instrument soft had no problem fitting it:
 x- structure(list(SPL = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L,
 4L, 5L, 5L, 6L, 6L, 7L, 7L), .Label = c(St1, St2, St3,
 St4, St5, St6, St7), class = factor), MFI = c(10755.5,
 9839, 5142.5, 4857, 1510.5, 1505, 502.5, 451, 215, 195.5, 58,
 57, 15, 15), nom = c(206, 206, 125, 125, 68, 68, 38, 38, 24,
 24, 13, 13, 6.5, 6.5), weights = c(0.0013946353028683, 
 0.00152454517735542,
 0.00291686922702965, 0.00308832612723904, 0.0099304865938431,
 0.00996677740863787, 0.0298507462686567, 0.0332594235033259,
 0.0697674418604651, 0.0767263427109974, 0.258620689655172,
 0.263157894736842,
 1, 1)), .Names = c(SPL, MFI, nom, weights), row.names = c(NA,
 -14L), class = data.frame)

 And here is the nls fit:
 fit- nls(MFI~a + b/((1+(nom/c)^d)^f), data=x, weights=x$weights,
 start=c(a=100, b=1, c=100, d=-1, f=1))

 I've tried every possible combination of starting values, including the
 values fitted by the instrument soft - to no avail. I've probably seen 
 all
 possible error messages from 'nls' trying to fit this.

 If anyone has an idea why it's not working - let me know.

 Best regards,

 --
 Michal J. Figurski, PhD
 HUP, Pathology  Laboratory Medicine
 Biomarker Research Laboratory
 3400 Spruce St. 7 Maloney S
 Philadelphia, PA 19104
 tel. (215) 662-3413

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

Re: [R] Different varable lengths

2012-04-30 Thread Keith Jewell
Missing comma between -1.180620213  and -0.525964648

Saint bahman.za...@comhem.se wrote in message 
news:1335779012548-4597768.p...@n4.nabble.com...
 Hi!

 I'm trying to do a lm() test on three objects. My problem is that R 
 protests
 and says that the variable lengths differ for one of the objects
 (Sweden.GDP.gap). But I have double checked that the number of 
 observations
 are the same. All three objects should contain 9 observations but R only
 accepts 9 observations in two of the objects. The third must have 10! Very
 confusing because there is no 10th observation!

 # Adjusted Real rate - P
 Sweden.p.adjust - c(4.70243, 1.3776655, 1.117755, 1.6695175, 1.59282,
 1.1017625, -0.04295, 2.2552875, 0.0552875)

 # Adjusted Inflation deviation
 Sweden.infl.dev.adjust  - c(0.110382497, -0.261612509, 0.040847515,
 -0.195062497, -0.234362485, -0.023408728, 0.206421261, -0.079401261,
 0.071828752)

 # Adjusted GDP-gap
 Sweden.GDP.gap.adjust - c(0.673792123, 1.196706756, 1.196131539,
 0.646944002, -0.312886525, -1.180620213 -0.525964648, -0.369401194,
 -0.003280389)

 # OLS regression using ADJUSTED data.#
 Sweden.Taylor.real.adjust - lm(Sweden.p.adjust ~ Sweden.infl.dev.adjust 
 +
 Sweden.GDP.gap.adjust)
 Error in model.frame.default(formula = Sweden.p.adjust ~
 Sweden.infl.dev.adjust +  :
  variable lengths differ (found for 'Sweden.GDP.gap.adjust')

 Why is this happening?

 / Saint


 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Different-varable-lengths-tp4597768.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] Area between 2 curves

2012-04-30 Thread Keith Jewell
A quick Google suggests that sintegral is in the Bolstad2 package: 
http://cran.r-project.org/web/packages/Bolstad2/

R. Michael Weylandt michael.weyla...@gmail.com wrote in message 
news:CAAmySGOCtNxWNHJDka=68criphxnppwap6fm7ufkhtx7xsz...@mail.gmail.com...
 You can't just decide a command exists and try to use it by your
 arbitrarily chosen name  did you look at the function integrate()
 which does exist? It uses a smarter algorithm than Simpson's rule.

 Alternatively, Simpson's rule is very easy to code with vectorization
 -- you should be able to implement it yourself in just a few lines
 after reading An Introduction to R.

 Michael

 On Mon, Apr 30, 2012 at 6:17 AM, sappy robert.wittk...@gmx.de wrote:
 Hello,

 i have a question calculating the shaped area between the two curves (see
 image).

 http://r.789695.n4.nabble.com/file/n4597813/test.png

 I try to use a Simpson-Integral but it doesn't work. R doesn't know the
 command!
 It is possible, that i need a library?

 Curve 1: y
 Curve 2: z

 q-abs(y-z); est-sintegral(x,z)

 Greetings

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Area-between-2-curves-tp4597813.html
 Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] Creating polygons from scattered points

2012-03-14 Thread Keith Jewell
No time to really think about this, but:

a) to convert scattered point distributions to polygons you might look at 
convex hulls; e.g. convhulln {geometry}
b) to identify islands some kind of cluster analysis

Hope that helps a little.

KJ

Louise Mair lm...@york.ac.uk wrote in message 
news:camkzt57pep1zkpgm2dg5tn6r0p-_o5tf+wsnurxdohf8zvm...@mail.gmail.com...
 Hello,

 I have a distribution dataset for species consisting of xy coordinates at
 the 1km resolution, with only presence data. So a simplified example of a
 species distribution might be:

 y - rbind(as.integer(rnorm(100,50,20)), as.integer(rnorm(200,100,30)),
 as.integer(rnorm(100,180,15)))
 x - rbind(as.integer(rnorm(200,50,20)), as.integer(rnorm(200,100,20)),
 as.integer(rnorm(100,200,15)))
 plot(y~x)

 I would like to create polygons for each species distribution, where if an
 island is present (as I have tried to show in the example), it would be a
 seperate polygon, and the jagged edges of coastlines etc are maintained. I
 have spent ages trying to find a package that will allow me to convert
 scattered point distributions to polygons but haven't found anything that
 works, the functions I have found require the data already to be in the
 format where the only xy coordinates present are the outline of the
 polygon.

 Can anyone please recommend a function I can use here, or suggest a way of
 extracting the outline points? I have tried this manually but cannot seem
 to write a code that will effectively take account of jagged edges and
 islands.

 Thanks very much for your help,

 Louise.

 [[alternative HTML version deleted]]


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


Re: [R] how to run system command

2012-03-08 Thread Keith Jewell
Yes, not cygwin\bin but Rtools\bin (which is in my path:)
 Sys.which(date)
  date
Z:\\R\\Rtools\\bin\\date.exe

The OP's error message (Error in system(date, intern = TRUE) : 'date' not 
found) suggests he has no 'date' in his path.
I see ?system says DOS internal commands, ... cannot be used: see shell, 
so you and others are correct in recommending 'shell' rather than 'system'.

Sorry for the noise :-(
At least I've learned something :-)

Best regards,

KJ

William Dunlap wdun...@tibco.com wrote in message 
news:e66794e69cfde04d9a70842786030b93283...@pa-mbx04.na.tibco.com...
 You wrote:
   Works for me:
   e - system(date, intern=TRUE)
   e
  [1] Wed Mar  7 08:58:32 GMTST 2012
 I suspect you have cygwin\bin in your PATH variable,
 as that does not look like Windows date command:
   system(cmd.exe /c date /T)
  Wed 03/07/2012
   shell(date /T)
  Wed 03/07/2012
   shell(date) # asks for new date if no /T
  The current date is: Wed 03/07/2012
  Enter the new date: (mm-dd-yy) Warning messages:
  1: running command 'C:\Windows\system32\cmd.exe /c date' had status 1
  2: In shell(date) : 'date' execution failed with error code 1

 sessionInfo() does not report PATH's contents.  You can
 look at it with
   strsplit(Sys.getenv(PATH), .Platform$path.sep)[[1]]

 Bill Dunlap

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 
 On
 Behalf Of Keith Jewell
 Sent: Wednesday, March 07, 2012 1:02 AM
 To: r-h...@stat.math.ethz.ch
 Subject: Re: [R] how to run system command

 Works for me:
 --
  sessionInfo()
 R version 2.14.1 (2011-12-22)
 Platform: i386-pc-mingw32/i386 (32-bit)

 locale:
 [1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United
 Kingdom.1252LC_MONETARY=English_United Kingdom.1252
 [4] LC_NUMERIC=CLC_TIME=English_United
 Kingdom.1252

 attached base packages:
  [1] grDevices datasets  splines   graphics  stats tcltk utils
 tools methods   base

 other attached packages:
 [1] CBRIutils_1.0stringr_0.5  svSocket_0.9-51  TinnR_1.0.3
 R2HTML_2.2   Hmisc_3.8-3  survival_2.36-10

 loaded via a namespace (and not attached):
 [1] cluster_1.14.1 grid_2.14.1lattice_0.20-0 plyr_1.7.1
 svMisc_0.9-63
  e - system(date, intern=TRUE)
  e
 [1] Wed Mar  7 08:58:32 GMTST 2012
 

 What's your sessionInfo()?

 KJ


 sagarnikam123 sagarnikam...@gmail.com wrote in message
 news:1331041713089-4449906.p...@n4.nabble.com...
 i used it on windows system, but giving error like
 
  e - system(date, intern=TRUE)
  Error in system(date, intern = TRUE) : 'date' not found
 
  --
  View this message in context:
  http://r.789695.n4.nabble.com/how-to-run-system-command-
 tp4449597p4449
  906.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] how to run system command

2012-03-07 Thread Keith Jewell
Works for me:
--
 sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United 
Kingdom.1252LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=CLC_TIME=English_United 
Kingdom.1252

attached base packages:
 [1] grDevices datasets  splines   graphics  stats tcltk utils 
tools methods   base

other attached packages:
[1] CBRIutils_1.0stringr_0.5  svSocket_0.9-51  TinnR_1.0.3 
R2HTML_2.2   Hmisc_3.8-3  survival_2.36-10

loaded via a namespace (and not attached):
[1] cluster_1.14.1 grid_2.14.1lattice_0.20-0 plyr_1.7.1 
svMisc_0.9-63
 e - system(date, intern=TRUE)
 e
[1] Wed Mar  7 08:58:32 GMTST 2012


What's your sessionInfo()?

KJ


sagarnikam123 sagarnikam...@gmail.com wrote in message 
news:1331041713089-4449906.p...@n4.nabble.com...
i used it on windows system, but giving error like

 e - system(date, intern=TRUE)
 Error in system(date, intern = TRUE) : 'date' not found

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/how-to-run-system-command-tp4449597p4449906.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] Sorting strings

2012-02-20 Thread Keith Jewell

Petr Savicky savi...@cs.cas.cz wrote in message 
news:20120220105153.gc21...@cs.cas.cz...
 On Mon, Feb 20, 2012 at 02:18:42AM -0800, statquant2 wrote:
 Hi all, I am having difficulties to understand how R sort strings:

 If I do
 R) sort(c(X.,X0B))
 [1] X.  X0B

 So for me, as far as lexicographic order is concerned I can add whatever 
 to
 the end, the order will remain the same, but :

 Hi.

 This neednot be true for strings of different length.
 For example

  ab
  abc

 become by concatenation with z

  abcz
  abz

 Petr Savicky.


That's not the explanation in this case.

The OP isn't telling us everything.
I get [R version 2.14.1 Platform: i386-pc-mingw32/i386 (32-bit)]:
 sort(c(X.,X0B))
[1] X.  X0B
 sort(c(X.Z,X0B.Z))
[1] X.Z   X0B.Z

KJ

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


Re: [R] unique combinations

2011-12-21 Thread Keith Jewell
OK, someone point it out to me; my wife tells me I can't see what's in front 
of me :-}

I read ?expand.grid carefully, went to ?combn and ?choose but still couldn't 
see an easy way to get what the OP asked for. The neatest I can get (which 
isn't very neat!) is:

 myVec - c(1,2,3)
 eg - expand.grid(myVec, myVec)
 eg[eg[,1] = eg[,2],]
  Var1 Var2
111
412
522
713
823
933

What am I missing?

Best regards,

KJ
Jeff Newmiller jdnew...@dcn.davis.ca.us wrote in message 
news:80cc9ff9-d867-4dfc-b6e3-9c1df7822...@email.android.com...
 You could read the help for expand.grid very carefully for the answer to 
 this question.
 ---
 Jeff NewmillerThe .   .  Go 
 Live...
 DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live 
 Go...
  Live:   OO#.. Dead: OO#..  Playing
 Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
 /Software/Embedded Controllers)   .OO#.   .OO#. 
 rocks...1k
 ---
 Sent from my phone. Please excuse my brevity.

 Antje Niederlein niederlein-rs...@yahoo.de wrote:

Hi there,

I have a vector and would like to create a data frame, which contains
all unique combination of two elements, regardless of order.

myVec - c(1,2,3)

what expand.grid does:

1,1
1,2
1,3
2,1
2,2
2,3
3,1
3,2
3,3

what I would like to have

1,1
1,2
1,3
2,2
2,3
3,3

Can anybody help?

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

2011-12-21 Thread Keith Jewell
Thanks Uwe,

I was happy that my 2 lines gave what the OP asked for, albeit in a 
different order.

My puzzlement arose from Jeff Newmillers comment:
 You could read the help for expand.grid very carefully for the answer to
 this question.
... which I reas as saying that ?expand.grid would lead to a solution.
I used [, which I couldn't see suggested on ?expand.grid.
I thought I'd missed a neater solution in the help pages, and hoped someone 
could point it out.

Best regards,

Keith Jewell
--
Uwe Ligges lig...@statistik.tu-dortmund.de wrote in message 
news:4ef1ec69.2080...@statistik.tu-dortmund.de...


 On 21.12.2011 14:39, Keith Jewell wrote:
 OK, someone point it out to me; my wife tells me I can't see what's in 
 front
 of me :-}

 I read ?expand.grid carefully, went to ?combn and ?choose but still 
 couldn't
 see an easy way to get what the OP asked for. The neatest I can get 
 (which
 isn't very neat!) is:

 myVec- c(1,2,3)
 eg- expand.grid(myVec, myVec)
 eg[eg[,1]= eg[,2],]
Var1 Var2
 111
 412
 522
 713
 823
 933

 What am I missing?

 You are just using a different order - sort accoriding to Var1...

 Best,
 Uwe Ligges


 Best regards,

 KJ
 Jeff Newmillerjdnew...@dcn.davis.ca.us  wrote in message
 news:80cc9ff9-d867-4dfc-b6e3-9c1df7822...@email.android.com...
 You could read the help for expand.grid very carefully for the answer to
 this question.
 ---
 Jeff NewmillerThe .   .  Go
 Live...
 DCN:jdnew...@dcn.davis.ca.us Basics: ##.#.   ##.#.  Live
 Go...
   Live:   OO#.. Dead: OO#..  Playing
 Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
 /Software/Embedded Controllers)   .OO#.   .OO#.
 rocks...1k
 ---
 Sent from my phone. Please excuse my brevity.

 Antje Niederleinniederlein-rs...@yahoo.de  wrote:

 Hi there,

 I have a vector and would like to create a data frame, which contains
 all unique combination of two elements, regardless of order.

 myVec- c(1,2,3)

 what expand.grid does:

 1,1
 1,2
 1,3
 2,1
 2,2
 2,3
 3,1
 3,2
 3,3

 what I would like to have

 1,1
 1,2
 1,3
 2,2
 2,3
 3,3

 Can anybody help?

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


Re: [R] Adding a year to existing date

2011-11-17 Thread Keith Jewell
Just looking at the ambiguity in adding a year

 dates - as.Date(c('2007-03-01','2008-02-29'))
 tmp - as.POSIXlt(dates)
 tmp$year - tmp$year+1
 dates2 - as.Date(tmp)
 dates2
[1] 2008-03-01 2009-03-01
 dates2 - dates
Time differences in days
[1] 366 366

KJ

MacQueen, Don macque...@llnl.gov wrote in message 
news:caea785f.7cfdb%macque...@llnl.gov...
 Here is an example that could probably be described as adding a year:

 dates - c('2008-01-01','2009-03-02')
 tmp - as.POSIXlt(dates)tmp$year - tmp$year+1
 dates2 - format(tmp)
 dates
 [1] 2008-01-01 2009-03-02
 dates2
 [1] 2009-01-01 2010-03-02

 ## to begin to understand how it works, give the command
 ##   unclass(tmp)
 ## (and read the help pages
 ##   ?as.POSIXlt
 ##   ?DateTimeClasses

 Another example:

 dates - as.Date(c('2008-01-01','2009-03-02'))
 tmp - as.POSIXlt(dates)
 tmp$year - tmp$year+1
 dates2 - as.Date(tmp)



 ##   ?as.Date
 ##   ?Date




 -Don


 -- 
 Don MacQueen

 Lawrence Livermore National Laboratory
 7000 East Ave., L-627
 Livermore, CA 94550
 925-423-1062





 On 11/16/11 8:33 PM, arunkumar akpbond...@gmail.com wrote:

Hi

 I need to add an year to and date field in the dataframe.

Please help me

X Date
1 2008-01-01
2 2008-02-01
3 2003-03-01


Thanks in advance

--
View this message in context:
http://r.789695.n4.nabble.com/Adding-a-year-to-existing-date-tp4078930p407
8930.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] UNC Windows path beginning with backslashes

2011-08-19 Thread Keith Jewell
Thanks Henrik, but I have 2 reasons for not using that approach:

A) If I don't map the drive until after R starts the UNC path is already 
present in several places I know about and probably some I don't, leading to 
the problems I started with.

So reason 'B' doesn't really matter to me, but as author of R.utils you may 
be interested that...
B) On my system those calls don't seem to work. Details here...
--
 library(R.utils)
Loading required package: R.oo
Loading required package: R.methodsS3
R.methodsS3 v1.2.1 (2010-09-18) successfully loaded. See ?R.methodsS3 for 
help.
R.oo v1.8.1 (2011-07-10) successfully loaded. See ?R.oo for help.
R.utils v1.7.8 (2011-07-24) successfully loaded. See ?R.utils for help.
 sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

attached base packages:
 [1] datasets  grDevices splines   graphics  stats utils tcltk
 [8] tools methods   base

other attached packages:
 [1] R.utils_1.7.8  R.oo_1.8.1 R.methodsS3_1.2.1  RODBC_1.3-3
 [5] tree_1.0-29nlme_3.1-102   MASS_7.3-14 
xlsReadWrite_1.5.4
 [9] svSocket_0.9-51TinnR_1.0.3R2HTML_2.2 Hmisc_3.8-3
[13] survival_2.36-9

loaded via a namespace (and not attached):
[1] cluster_1.14.0  grid_2.13.1 lattice_0.19-31 svMisc_0.9-61
#  It seems to think I have no mapped drives
 System$getMappedDrivesOnWindows()
named character(0)
# Although I clearly have (in fact I'm running R from Z:), so I can't
# find a 'spare' drive letter
 system(net use)
New connections will not be remembered.

Status   Local RemoteNetwork
---
OK   F:\\server10\microbiology   Microsoft Windows Network
OK   L:\\server23\Stats  Microsoft Windows Network
OK   M:\\server10\jewell Microsoft Windows Network
OK   Q:\\server04\pccommon (not backed up)
 Microsoft Windows Network
OK   R:\\server23\Template   Microsoft Windows Network
 Z:\\campden\shares\Workgroup\Stats
 Microsoft Windows Network
   \\TSCLIENT\C  Microsoft Terminal Services
   \\TSCLIENT\D  Microsoft Terminal Services
   \\TSCLIENT\E  Microsoft Terminal Services
   \\TSCLIENT\F  Microsoft Terminal Services
   \\TSCLIENT\G  Microsoft Terminal Services
   \\TSCLIENT\H  Microsoft Terminal Services
   \\TSCLIENT\I  Microsoft Terminal Services
   \\TSCLIENT\L  Microsoft Terminal Services
   \\TSCLIENT\M  Microsoft Terminal Services
   \\TSCLIENT\Q  Microsoft Terminal Services
   \\TSCLIENT\R  Microsoft Terminal Services
The command completed successfully.
#  The commands you cited throw errors...
 System$mapDriveOnWindows(K, campden\\shares\\Workgroup\\Stats)
Error in list(`System$mapDriveOnWindows(K, 
campden\\shares\\Workgroup\\Stats)` = environment,  :

[2011-08-19 09:16:28] Exception: Argument 'drive' is not a valid drive (e.g. 
'Y:'): K
  at throw(Exception(...))
  at throw.default(Argument 'drive' is not a valid drive (e.g. 'Y:'): , 
drive)
  at throw(Argument 'drive' is not a valid drive (e.g. 'Y:'): , drive)
  at method(static, ...)
  at System$mapDriveOnWindows(K, campden\\shares\\Workgroup\\Stats)
 driveLetters - System$getMappedDrivesOnWindows()
 driveLetters
named character(0)
 System$unmapDriveOnWindows(K)
Error in list(`System$unmapDriveOnWindows(K)` = environment, 
`method(static, ...)` = environment,  :

[2011-08-19 09:29:09] Exception: Argument 'drive' is not a valid drive (e.g. 
'Y:'): K
  at throw(Exception(...))
  at throw.default(Argument 'drive' is not a valid drive (e.g. 'Y:'): , 
drive)
  at throw(Argument 'drive' is not a valid drive (e.g. 'Y:'): , drive)
  at method(static, ...)
  at System$unmapDriveOnWindows(K)

Thanks for your interest,

Keith Jewell
-
Henrik Bengtsson h...@biostat.ucsf.edu wrote in message 
news:cafdcvcqe3uukmmqsjj0fpevfjgrabrgbt1g8drcxgpnsjeb...@mail.gmail.com...
I think you can also do this from within R (e.g. in your .Rprofile)
using the R.utils package;

library(R.utils)
System$mapDriveOnWindows(K, campden\\shares\\Workgroup\\Stats)
driveLetters - System$getMappedDrivesOnWindows()
System$unmapDriveOnWindows(K)

These methods utilize

Re: [R] UNC Windows path beginning with backslashes

2011-08-18 Thread Keith Jewell
Just to close this off, in case it helps anyone else in a similar 
situation...

Background: I have R installed on a UNC share with a site library named by 
major and minor version, thus:
\\campden\shares\Workgroup\Stats 'root'
\\campden\shares\Workgroup\Stats\R  base for R related things
\\campden\shares\Workgroup\Stats\R\R-2.13.1 one R installation
\\campden\shares\Workgroup\Stats\R\library site libraries go here
\\campden\shares\Workgroup\Stats\R\library\2.13 site library for R 2.13.x

I took the hint and mapped a drive from which to start R.
Because I don't have a pre-determined drive letter to use I wrote a little 
.bat file to do the job:
--
REM find or 'net use' a drive mapped to stats share
set remote=\\campden\shares\Workgroup\Stats
set drive=
:check
for /f delims=* %%a in ('net use ^| find %remote%') do set drive=%%a
if not defined drive net use * %remote% /persistent:NOnul  goto check
set StatsDrive=%drive:~13,2%
REM using that drive
REM a) ensure GTK+ is in the path (for packages such as 'playwith')
REM b) start 32 bit R
set path=%StatsDrive%/R/GTK+/bin;%path%
start %StatsDrive%\R\R-2.13.1\bin\i386\Rgui.exe

That's a bit flakey, depending on the exact format of the output from 'net 
use'. If anyone has a better solution, I'll appreciate it!

Now the site library:
Putting a UNC path into Renviron.site thus...
  R_LIBS_SITE=//campden/shares/workgroup/stats/R/library/%v
... was the cause of my original problem.
I can't put it in as a mapped drive, because I don't know the drive until 
run time.
I tried to work up and down from the drive mapped R_HOME...
  R_LIBS_SITE=${R_HOME}/.../library/%v
... but that didn't work in Renviron.site.
 Sys.getenv(R_HOME)
[1] Z:/R/R-2.13.1
... which is fine, but...
 Sys.getenv(R_LIBS_SITE)
[1] Z:RR-2.13.1/.../library/2.13
I think this may be something to do with this quote from ?Startup...
value is then processed in a similar way to a Unix shell: in particular the 
outermost level of (single or double) quotes is stripped, and backslashes 
are removed except inside quotes
...but I don't have any control over R_HOME, specifically how and when 
forward- or back-slashes are used or removed.

In the end I used Renviron.site just to pass the version information...
   R_Libs_Site=%v
That directory doesn't exist so doesn't get added to .libPaths()
In Rprofile.site I worked up and down from R_HOME...
  .libPaths(file.path(dirname(R.home()),library,Sys.getenv(R_Libs_Site)))
... which seems to do the job.

It isn't pretty, and the .bat file will probably need changing in future 
versions of Windows.
But by the time R has started there isn't a UNC path in sight.
I still think I've probably re-invented a wheel and ended up with something 
square, but it is going round.

Best regards,

Keith Jewell

Keith Jewell k.jew...@campden.co.uk wrote in message 
news:j22q11$9u9$1...@dough.gmane.org...
 Thanks Uwe.

 I'm aware (and have been forcefully reminded) that using a mapped drive 
 avoids these problems. But there is no single drive letter which I can use 
 site-wide, so I have problems with things like R_LIBS_SITE. As I've 
 outlined I'm exploring a range of solutions, including mapping a drive 
 where I can.

 I posted in the hope of learning from and perhaps helping those with 
 similar problems. I hope that it is permissible to discuss non-canonical 
 use of R on this list, I certainly did not intend disrespect for the R 
 developers (or to make typing errors).

 Best regards

 Keith Jewell

 Uwe Ligges lig...@statistik.tu-dortmund.de wrote in message 
 news:4e44091e.7090...@statistik.tu-dortmund.de...
 This is extremely tricky since Windows does not always accept // rather 
 than \\. Additionally, there is not implemented system call in Windows, 
 hence ?Sys.glob tells us a partial emulation is provided and An 
 attempt is made to handle UNC paths starting with a double backslash.

 As you have seenm this does not work everywhere, therefore it is 
 advisable to run R from mapped drives - as I am doing in the network of 
 our university for 13 years without problems now.

 Best,
 Uwe Ligges


 On 11.08.2011 18:29, Keith Jewell wrote:
 Hi,

 Back in June I posted the message below, but had no replies. I've made a
 little progress since then so this is to update anyone interested (!) 
 and to
 ask for comments.

 Brief problem statement:
 Under Windows, some parts of R don't handle UNC paths beginning with
 backslashes. Specifically
 a) Sys.glob() fails to find some files breaking (e.g.) Rcmdr plugins
 Sys.glob(file.path(.libPaths(), */etc/menus.txt))
 fails to find files which are there

 b) update.packages(ask='graphics') fails when copying the updates into 
 the
 destination folders

 In Renviron.site I define the site library with forward slashes, not
 backslashes thus...
 R_LIBS_SITE=//campden/shares/workgroup/stats/R/library/%v
 ... but the startup process seems to replace them with forward slashes.
 I

[R] UNC windows path beginning with backslashes: normalizePath bug??

2011-08-12 Thread Keith Jewell
Hi,

Back in June I posted the message below, but had no replies. I've made a 
little progress since then so this is to update anyone interested (!) and to 
ask for comments.

Brief problem statement:
Under Windows, some parts of R don't handle UNC paths beginning with 
backslashes. Specifically
a) Sys.glob() fails to find some files breaking (e.g.) Rcmdr plugins
   Sys.glob(file.path(.libPaths(), */etc/menus.txt))
   fails to find files which are there

b) update.packages(ask='graphics') fails when copying the updates into the 
destination folders

In Renviron.site I define the site library with forward slashes, not 
backslashes thus...
   R_LIBS_SITE=//campden/shares/workgroup/stats/R/library/%v
... but the startup process seems to replace them with forward slashes.
I guess because  .libPaths with a 'new' argument calls normalizePath which 
changes leading slashes to backslashes, even with winslash=/
 normalizePath(//campden/shares/workgroup/stats/R/library, winslash=/)
[1] campden/shares/workgroup/Stats/R/library

I've corrected (??) this by inserting a line into Rprofile.site
  assign(.lib.loc, gsub(\\, /, .libPaths(), fixed=TRUE), 
env=environment(.libPaths))
That seems to fix problem (a) above, which was affecting a number of users.
But have I broken anything else?

I'm still experiencing problem (b).
I'm the only person on site who updates packages so I've mapped a drive 
letter (L:) and in my own .Rprofile I have a line
   assign(.lib.loc, sub(//campden/shares/workgroup/Stats, L:, 
.libPaths(), ignore.case = TRUE), env=environment(.libPaths))

So that's OK as far as it goes, but it's all a bit messy!
If .libPaths is called with a 'new' argument it will breaks things again.
normalizePath seems to produce paths that don't work with Sys.glob.

I have the feeling I'm being silly and making hard work of all this.

Any comments? Suggestions?

Best regards, and thanks in advance/

Keith Jewell

Keith Jewell k.jew...@campden.co.uk wrote in message news:...
 Hi,

 Back in 2010 I had a problem with 'update.packages()', which I worked 
 around by mapping a drive letter to a UNC path [described in 
 http://finzi.psych.upenn.edu/Rhelp10/2010-February/229820.html but my 
 current workaround is
 assign(.lib.loc, sub(Server02/stats, L:, .libPaths(), 
 ignore.case = TRUE), env=environment(.libPaths))].

 More recently a colleague had problems using the 'FactoMineR' plug in for 
 the Rcmdr package;
 a) directly loading 'RcmdrPlugin.FactoMineR' opened and crashed R 
 Commander;
 b) opening R Commander without FactoMiner, the Tools option 'Load Rcmdr 
 plug-in(s)...' was greyed out.

 It transpired that in .libPaths() the path to the library holding 
 'RcmdrPlugin.FactoMineR' was specified as a UNC address: 
 Server02/stats/R/library/2.13. Mapping a virtual drive letter (e.g. 
 L:) and specifying the path in .libPaths() as a 'local file system' (LFS) 
 address L:/R/library/2.13 fixed the problem.

 I contacted Professor Fox (maintainer of Rcmdr) who told me that Rcmdr 
 finds plug-in packages via the command
  plugins - unlist(lapply(.libPaths(), function(x) Sys.glob(file.path(x, 
 */etc/menus.txt
 Because file.path and Sys.glob are both vectorised I think (but am not 
 certain) that this could be simplified to:
  plugins - Sys.glob(file.path(.libPaths(), */etc/menus.txt))
 but that's by the way, the problem seems to lie in Sys.glob under Windows 
 operating systems.

 I note that 'help(Sys.glob)' on my Windows system  differs from 
 http://finzi.psych.upenn.edu/R/library/base/html/Sys.glob.html.
 The latter says For precise details, see your system's documentation on 
 the glob system call.  There is a POSIX 1003.2 standard  snip The rest 
 of these details are indicative (and based on the POSIX standard).
 On Windows The glob system call is not part of Windows, and we supply a 
 partial emulation. snip An attempt is made to handle UNC paths starting 
 with a double backslash which doesn't really inspire confidence.

 This was discussed in a 2009 R-devel thread starting here 
 https://stat.ethz.ch/pipermail/r-devel/2009-June/053879.html, but the 
 patch proposed in that thread seems not to have been implemented (??).

 Trying to avoid Sys.glob in the Rcmdr application I came up with this:
  list.files(path=file.path(list.files(path=.libPaths(), 
 full.names=TRUE), etc), pattern=^menus\\.txt$, full.names=TRUE)
 It seems to give identical results to Sys.glob for mapped drives, works 
 with UNC paths in Windows, and seems quite fast.

 So my questions relate to diagnosis, prognosis, and prescription (cure?).

 1) Diagnosis: Am I correct that my problem(s) originate in the partial 
 emulation of glob in Windows.

 2) Prognosis: If so, is there any likelihood that the emulation will 
 improve in the near future?

 3) Prescription: If not:

 a) is assign(.lib.loc, sub(Server02/stats, L:, .libPaths(), 
 ignore.case = TRUE), env=environment(.libPaths))
 a reasonable workaround

Re: [R] UNC Windows path beginning with backslashes: normalizePath bug??

2011-08-12 Thread Keith Jewell
Thanks Uwe.

I'm aware (and have been forcefully reminded) that using a mapped drive 
avoids these problems. But there is no single drive letter which I can use 
site-wide, so I have problems with things like R_LIBS_SITE. As I've outlined 
I'm exploring a range of solutions, including mapping a drive where I can.

I posted in the hope of learning from and perhaps helping those with similar 
problems. I hope that it is permissible to discuss non-canonical use of R on 
this list, I certainly did not intend disrespect for the R developers (or to 
make typing errors).

Best regards

Keith Jewell

Uwe Ligges lig...@statistik.tu-dortmund.de wrote in message 
news:4e44091e.7090...@statistik.tu-dortmund.de...
 This is extremely tricky since Windows does not always accept // rather 
 than \\. Additionally, there is not implemented system call in Windows, 
 hence ?Sys.glob tells us a partial emulation is provided and An attempt 
 is made to handle UNC paths starting with a double backslash.

 As you have seenm this does not work everywhere, therefore it is advisable 
 to run R from mapped drives - as I am doing in the network of our 
 university for 13 years without problems now.

 Best,
 Uwe Ligges


 On 11.08.2011 18:29, Keith Jewell wrote:
 Hi,

 Back in June I posted the message below, but had no replies. I've made a
 little progress since then so this is to update anyone interested (!) and 
 to
 ask for comments.

 Brief problem statement:
 Under Windows, some parts of R don't handle UNC paths beginning with
 backslashes. Specifically
 a) Sys.glob() fails to find some files breaking (e.g.) Rcmdr plugins
 Sys.glob(file.path(.libPaths(), */etc/menus.txt))
 fails to find files which are there

 b) update.packages(ask='graphics') fails when copying the updates into 
 the
 destination folders

 In Renviron.site I define the site library with forward slashes, not
 backslashes thus...
 R_LIBS_SITE=//campden/shares/workgroup/stats/R/library/%v
 ... but the startup process seems to replace them with forward slashes.
 I guess because  .libPaths with a 'new' argument calls normalizePath 
 which
 changes leading slashes to backslashes, even with winslash=/
 normalizePath(//campden/shares/workgroup/stats/R/library, 
 winslash=/)
 [1] campden/shares/workgroup/Stats/R/library

 I've corrected (??) this by inserting a line into Rprofile.site
assign(.lib.loc, gsub(\\, /, .libPaths(), fixed=TRUE),
 env=environment(.libPaths))
 That seems to fix problem (a) above, which was affecting a number of 
 users.
 But have I broken anything else?

 I'm still experiencing problem (b).
 I'm the only person on site who updates packages so I've mapped a drive
 letter (L:) and in my own .Rprofile I have a line
 assign(.lib.loc, sub(//campden/shares/workgroup/Stats, L:,
 .libPaths(), ignore.case = TRUE), env=environment(.libPaths))

 So that's OK as far as it goes, but it's all a bit messy!
 If .libPaths is called with a 'new' argument it will breaks things again.
 normalizePath seems to produce paths that don't work with Sys.glob.

 I have the feeling I'm being silly and making hard work of all this.

 Any comments? Suggestions?

 Best regards, and thanks in advance/

 Keith Jewell

 Keith Jewellk.jew...@campden.co.uk  wrote in message news:...
 Hi,

 Back in 2010 I had a problem with 'update.packages()', which I worked
 around by mapping a drive letter to a UNC path [described in
 http://finzi.psych.upenn.edu/Rhelp10/2010-February/229820.html  but my
 current workaround is
 assign(.lib.loc, sub(Server02/stats, L:, .libPaths(),
 ignore.case = TRUE), env=environment(.libPaths))].

 More recently a colleague had problems using the 'FactoMineR' plug in 
 for
 the Rcmdr package;
 a) directly loading 'RcmdrPlugin.FactoMineR' opened and crashed R
 Commander;
 b) opening R Commander without FactoMiner, the Tools option 'Load Rcmdr
 plug-in(s)...' was greyed out.

 It transpired that in .libPaths() the path to the library holding
 'RcmdrPlugin.FactoMineR' was specified as a UNC address:
 Server02/stats/R/library/2.13. Mapping a virtual drive letter (e.g.
 L:) and specifying the path in .libPaths() as a 'local file system' 
 (LFS)
 addressL:/R/library/2.13  fixed the problem.

 I contacted Professor Fox (maintainer of Rcmdr) who told me that Rcmdr
 finds plug-in packages via the command
   plugins- unlist(lapply(.libPaths(), function(x) Sys.glob(file.path(x,
 */etc/menus.txt
 Because file.path and Sys.glob are both vectorised I think (but am not
 certain) that this could be simplified to:
   plugins- Sys.glob(file.path(.libPaths(), */etc/menus.txt))
 but that's by the way, the problem seems to lie in Sys.glob under 
 Windows
 operating systems.

 I note that 'help(Sys.glob)' on my Windows system  differs from
 http://finzi.psych.upenn.edu/R/library/base/html/Sys.glob.html.
 The latter says For precise details, see your system's documentation on
 the glob system call.  There is a POSIX 1003.2 standardsnip

[R] UNC windows path beginning with backslashes: normalizePath bug??

2011-08-11 Thread Keith Jewell
Hi,

Back in June I posted the message below, but had no replies. I've made a 
little progress since then so this is to update anyone interested (!) and to 
ask for comments.

Brief problem statement:
Under Windows, some parts of R don't handle UNC paths beginning with 
backslashes. Specifically
a) Sys.glob() fails to find some files breaking (e.g.) Rcmdr plugins
   Sys.glob(file.path(.libPaths(), */etc/menus.txt))
   fails to find files which are there

b) update.packages(ask='graphics') fails when copying the updates into the 
destination folders

In Renviron.site I define the site library with forward slashes, not 
backslashes thus...
   R_LIBS_SITE=//campden/shares/workgroup/stats/R/library/%v
... but the startup process seems to replace them with forward slashes.
I guess because  .libPaths with a 'new' argument calls normalizePath which 
changes leading slashes to backslashes, even with winslash=/
 normalizePath(//campden/shares/workgroup/stats/R/library, winslash=/)
[1] campden/shares/workgroup/Stats/R/library

I've corrected (??) this by inserting a line into Rprofile.site
  assign(.lib.loc, gsub(\\, /, .libPaths(), fixed=TRUE), 
env=environment(.libPaths))
That seems to fix problem (a) above, which was affecting a number of users.
But have I broken anything else?

I'm still experiencing problem (b).
I'm the only person on site who updates packages so I've mapped a drive 
letter (L:) and in my own .Rprofile I have a line
   assign(.lib.loc, sub(//campden/shares/workgroup/Stats, L:, 
.libPaths(), ignore.case = TRUE), env=environment(.libPaths))

So that's OK as far as it goes, but it's all a bit messy!
If .libPaths is called with a 'new' argument it will breaks things again.
normalizePath seems to produce paths that don't work with Sys.glob.

I have the feeling I'm being silly and making hard work of all this.

Any comments? Suggestions?

Best regards, and thanks in advance/

Keith Jewell

Keith Jewell k.jew...@campden.co.uk wrote in message news:...
 Hi,

 Back in 2010 I had a problem with 'update.packages()', which I worked 
 around by mapping a drive letter to a UNC path [described in 
 http://finzi.psych.upenn.edu/Rhelp10/2010-February/229820.html but my 
 current workaround is
 assign(.lib.loc, sub(Server02/stats, L:, .libPaths(), 
 ignore.case = TRUE), env=environment(.libPaths))].

 More recently a colleague had problems using the 'FactoMineR' plug in for 
 the Rcmdr package;
 a) directly loading 'RcmdrPlugin.FactoMineR' opened and crashed R 
 Commander;
 b) opening R Commander without FactoMiner, the Tools option 'Load Rcmdr 
 plug-in(s)...' was greyed out.

 It transpired that in .libPaths() the path to the library holding 
 'RcmdrPlugin.FactoMineR' was specified as a UNC address: 
 Server02/stats/R/library/2.13. Mapping a virtual drive letter (e.g. 
 L:) and specifying the path in .libPaths() as a 'local file system' (LFS) 
 address L:/R/library/2.13 fixed the problem.

 I contacted Professor Fox (maintainer of Rcmdr) who told me that Rcmdr 
 finds plug-in packages via the command
  plugins - unlist(lapply(.libPaths(), function(x) Sys.glob(file.path(x, 
 */etc/menus.txt
 Because file.path and Sys.glob are both vectorised I think (but am not 
 certain) that this could be simplified to:
  plugins - Sys.glob(file.path(.libPaths(), */etc/menus.txt))
 but that's by the way, the problem seems to lie in Sys.glob under Windows 
 operating systems.

 I note that 'help(Sys.glob)' on my Windows system  differs from 
 http://finzi.psych.upenn.edu/R/library/base/html/Sys.glob.html.
 The latter says For precise details, see your system's documentation on 
 the glob system call.  There is a POSIX 1003.2 standard  snip The rest 
 of these details are indicative (and based on the POSIX standard).
 On Windows The glob system call is not part of Windows, and we supply a 
 partial emulation. snip An attempt is made to handle UNC paths starting 
 with a double backslash which doesn't really inspire confidence.

 This was discussed in a 2009 R-devel thread starting here 
 https://stat.ethz.ch/pipermail/r-devel/2009-June/053879.html, but the 
 patch proposed in that thread seems not to have been implemented (??).

 Trying to avoid Sys.glob in the Rcmdr application I came up with this:
  list.files(path=file.path(list.files(path=.libPaths(), 
 full.names=TRUE), etc), pattern=^menus\\.txt$, full.names=TRUE)
 It seems to give identical results to Sys.glob for mapped drives, works 
 with UNC paths in Windows, and seems quite fast.

 So my questions relate to diagnosis, prognosis, and prescription (cure?).

 1) Diagnosis: Am I correct that my problem(s) originate in the partial 
 emulation of glob in Windows.

 2) Prognosis: If so, is there any likelihood that the emulation will 
 improve in the near future?

 3) Prescription: If not:

 a) is assign(.lib.loc, sub(Server02/stats, L:, .libPaths(), 
 ignore.case = TRUE), env=environment(.libPaths))
 a reasonable workaround

Re: [R] list.files recursively to find files in a specific way...

2011-07-20 Thread Keith Jewell
I don't think the OP specified an operating system, but...

A few weeks ago I had a closely analogous problem, seeking files 'menus.txt' 
in subdirectories 'etc' but not from other subdirectories; 
'/etc/menus.txt'. I made this post 
http://tolstoy.newcastle.edu.au/R/e14/help/11/06/5685.html, but it was 
unanswered - I tend to ramble :-(

An appropriate Sys.glob construction was:
  Sys.glob(file.path(.libPaths(), */etc/menus.txt))

I suggested that under MS Windows Sys.glob() cannot handle a UNC path 
beginning with backslashes.
Was I correct?

If so, I suggested an equivalent list.files construction (where I did escape 
'.') as:
  list.files(path=file.path(list.files(path=.libPaths(), full.names=TRUE), 
etc), pattern=^menus\\.txt$, full.names=TRUE)
Does that look OK?

Best regards,

Keith Jewell

Prof Brian Ripley rip...@stats.ox.ac.uk wrote in message 
news:alpine.lfd.2.02.1107200711180.30...@gannet.stats.ox.ac.uk...
 But using the approproate tool, Sys.glob, whould be much simpler.

 Note that 'pattern' in list.files is

 - a regexp, and '.' is a special character in a regexp: Phil's solution 
 also needs to escape it or use fixed = TRUE
 - it is documented to match file *names*, not file paths.

 One of the authors of list.files and the author of Sys.glob

 On Tue, 19 Jul 2011, Phil Spector wrote:

 Pei -
   A file pattern can't contain a directory separator, but it's easy to 
 search for one outside the context of list.files.  I think

 grep('B/file2.txt',list.files(path = routeStr, all.files = TRUE,
  full.names = TRUE, recursive = 
 TRUE),value=TRUE)

 should give you what you want.

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


 On Tue, 19 Jul 2011, JIA Pei wrote:

 Hi, all:

 My folders are organized in such a way:


 root

 branch1
 ---A
 ---file1.txt
 ---file2.txt
 ---B
 ---file1.txt
 ---file2.txt

 branch2
 ---A
 ---file1.txt
 ---file2.txt
 ---B
 ---file1.txt
 ---file2.txt

 ...

 branch100
 ---A
 ---file1.txt
 ---file2.txt
 ---B
 ---file1.txt
 ---file2.txt



 I'd love to list all file2.txt from all subdirectories Bs but not from
 As, how to do that?

 I tried the following two

 a) allResults - list.files(path = routeStr, pattern = file2.txt,
 all.files = TRUE, full.names = TRUE, recursive = TRUE);
 gives me 200 files in allResults, which is wrong. There should be only 
 100
 files in allResults.

 b) allResults - list.files(path = routeStr, pattern = B/file2.txt,
 all.files = TRUE, full.names = TRUE, recursive = TRUE);
 still wrong. It give me nothing, namely, 0 file(s) in allResults.


 Can anybody help to solve this problem?


 Best Regards
 Pei

 -- 

 Pei JIA

 Email: jp4w...@gmail.com
 cell:+1 604-362-5816

 Welcome to Vision Open
 http://www.visionopen.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.


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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,  rip...@stats.ox.ac.uk
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595


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


[R] Sys.glob() doesn't handle a UNC windows path beginning with backslashes

2011-06-30 Thread Keith Jewell
Hi,

Back in 2010 I had a problem with 'update.packages()', which I worked around 
by mapping a drive letter to a UNC path [described in 
http://finzi.psych.upenn.edu/Rhelp10/2010-February/229820.html but my 
current workaround is
assign(.lib.loc, sub(Server02/stats, L:, .libPaths(), 
ignore.case = TRUE), env=environment(.libPaths))].

More recently a colleague had problems using the 'FactoMineR' plug in for 
the Rcmdr package;
a) directly loading 'RcmdrPlugin.FactoMineR' opened and crashed R 
Commander;
b) opening R Commander without FactoMiner, the Tools option 'Load Rcmdr 
plug-in(s)...' was greyed out.

It transpired that in .libPaths() the path to the library holding 
'RcmdrPlugin.FactoMineR' was specified as a UNC address: 
Server02/stats/R/library/2.13. Mapping a virtual drive letter (e.g. L:) 
and specifying the path in .libPaths() as a 'local file system' (LFS) 
address L:/R/library/2.13 fixed the problem.

I contacted Professor Fox (maintainer of Rcmdr) who told me that Rcmdr finds 
plug-in packages via the command
  plugins - unlist(lapply(.libPaths(), function(x) Sys.glob(file.path(x, 
*/etc/menus.txt
Because file.path and Sys.glob are both vectorised I think (but am not 
certain) that this could be simplified to:
  plugins - Sys.glob(file.path(.libPaths(), */etc/menus.txt))
but that's by the way, the problem seems to lie in Sys.glob under Windows 
operating systems.

I note that 'help(Sys.glob)' on my Windows system  differs from 
http://finzi.psych.upenn.edu/R/library/base/html/Sys.glob.html.
The latter says For precise details, see your system's documentation on the 
glob system call.  There is a POSIX 1003.2 standard  snip The rest of 
these details are indicative (and based on the POSIX standard).
On Windows The glob system call is not part of Windows, and we supply a 
partial emulation. snip An attempt is made to handle UNC paths starting 
with a double backslash which doesn't really inspire confidence.

This was discussed in a 2009 R-devel thread starting here 
https://stat.ethz.ch/pipermail/r-devel/2009-June/053879.html, but the 
patch proposed in that thread seems not to have been implemented (??).

Trying to avoid Sys.glob in the Rcmdr application I came up with this:
  list.files(path=file.path(list.files(path=.libPaths(), 
full.names=TRUE), etc), pattern=^menus\\.txt$, full.names=TRUE)
It seems to give identical results to Sys.glob for mapped drives, works with 
UNC paths in Windows, and seems quite fast.

So my questions relate to diagnosis, prognosis, and prescription (cure?).

1) Diagnosis: Am I correct that my problem(s) originate in the partial 
emulation of glob in Windows.

2) Prognosis: If so, is there any likelihood that the emulation will improve 
in the near future?

3) Prescription: If not:

a) is assign(.lib.loc, sub(Server02/stats, L:, .libPaths(), 
ignore.case = TRUE), env=environment(.libPaths))
a reasonable workaround in a specific case?

b) is list.files(path=file.path(list.files(path=.libPaths(), 
full.names=TRUE), etc), pattern=^menus\\.txt$, full.names=TRUE)
a reasonable replacement for the Sys.glob() construction in Rcmdr? I don't 
want to suggest to Prof. Fox an amendment which fixes my problem but 
'breaks' it for others!

Thanks in advance,

Keith Jewell

R version 2.13.0 (2011-04-13)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

attached base packages:
[1] datasets  grDevices splines   graphics  stats utils tcltk
 [8] tools methods   base

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


Re: [R] How to capture console output in a numeric format

2011-06-27 Thread Keith Jewell
Hmmm. Caution would seem more appropriate than fear.

My point was that if you want the results as numbers rather than characters, 
it seems perverse to convert them to characters with print; you should use a 
suitable mechanism to return them as numbers. If you're nervous of returning 
values via the environment list and scoping rules it seems curious to accept 
return via console output.

I used '-' as shorthand for a suitable mechanism. Depending on your 
circumstances, '-' may not be OK- in this example it seems very clear 
where it will find an existing definition of the variable being assigned. 
Others in this thread have covered more robust approaches, but as long as 
you're careful with environments and scoping it seems there are several ways 
to do what you want.

Best regards,

Keith J
Ravi Varadhan rvarad...@jhmi.edu wrote in message 
news:2f9ea67ef9ae1c48a147cb41be2e15c303e...@dom-eb-mail1.win.ad.jhu.edu...
I did think of this solution, Keith, but I am generally uncomfortable (may 
be paranoid is a better word) with the use of `-'.  Perhaps, my fear is 
unjustified in this particular situation.

 Thanks,
 Ravi.
 ---
 Ravi Varadhan, Ph.D.
 Assistant Professor,
 Division of Geriatric Medicine and Gerontology School of Medicine Johns 
 Hopkins University

 Ph. (410) 502-2619
 email: rvarad...@jhmi.edu


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 
 On Behalf Of Keith Jewell
 Sent: Friday, June 24, 2011 11:49 AM
 To: r-h...@stat.math.ethz.ch
 Subject: Re: [R] How to capture console output in a numeric format

 If you don't want the information as character, why are you printing it
 rather than storing it in a matrix?
 Why not something along the lines of this...

 fr - function(x) {   ## Rosenbrock Banana function
on.exit(aMatrix - rbind(aMatrix,(cbind(x1, x2, f
x1 - x[1]
x2 - x[2]
f - 100 * (x2 - x1 * x1)^2 + (1 - x1)^2
f
 }
 aMatrix - NULL
 ans - optim(c(-1.2,1), fr)
 aMatrix

 HTH

 Keith J
 -Original Message-
 Ravi Varadhan rvarad...@jhmi.edu wrote in message
 news:2f9ea67ef9ae1c48a147cb41be2e15c303e...@dom-eb-mail1.win.ad.jhu.edu...
 Thank you very much, Jim.  That works!

 I did know that I could process the character strings using regex, but was
 also wondering if there was a direct way to get this.

 Suppose, in the current example I would like to obtain a 3-column matrix
 that contains the parameters and the function value:

 fr - function(x) {   ## Rosenbrock Banana function
on.exit(print(cbind(x1, x2, f)))
x1 - x[1]
x2 - x[2]
f - 100 * (x2 - x1 * x1)^2 + (1 - x1)^2
f
 }

 fvals - capture.output(ans - optim(c(-1.2,1), fr))

 Now, I need to tweak your solution to get the 3-column matrix.  It would 
 be
 nice, if there was a more direct way to get the numerical output, perhaps 
 a
 numeric option in capture.output().

 Best,
 Ravi.

 ---
 Ravi Varadhan, Ph.D.
 Assistant Professor,
 Division of Geriatric Medicine and Gerontology School of Medicine Johns
 Hopkins University

 Ph. (410) 502-2619
 email: rvarad...@jhmi.edu

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


Re: [R] How to capture console output in a numeric format

2011-06-24 Thread Keith Jewell
If you don't want the information as character, why are you printing it 
rather than storing it in a matrix?
Why not something along the lines of this...

fr - function(x) {   ## Rosenbrock Banana function
on.exit(aMatrix - rbind(aMatrix,(cbind(x1, x2, f
x1 - x[1]
x2 - x[2]
f - 100 * (x2 - x1 * x1)^2 + (1 - x1)^2
f
}
aMatrix - NULL
ans - optim(c(-1.2,1), fr)
aMatrix

HTH

Keith J
-Original Message-
Ravi Varadhan rvarad...@jhmi.edu wrote in message 
news:2f9ea67ef9ae1c48a147cb41be2e15c303e...@dom-eb-mail1.win.ad.jhu.edu...
Thank you very much, Jim.  That works!

I did know that I could process the character strings using regex, but was 
also wondering if there was a direct way to get this.

Suppose, in the current example I would like to obtain a 3-column matrix 
that contains the parameters and the function value:

fr - function(x) {   ## Rosenbrock Banana function
on.exit(print(cbind(x1, x2, f)))
x1 - x[1]
x2 - x[2]
f - 100 * (x2 - x1 * x1)^2 + (1 - x1)^2
f
}

fvals - capture.output(ans - optim(c(-1.2,1), fr))

Now, I need to tweak your solution to get the 3-column matrix.  It would be 
nice, if there was a more direct way to get the numerical output, perhaps a 
numeric option in capture.output().

Best,
Ravi.

---
Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology School of Medicine Johns 
Hopkins University

Ph. (410) 502-2619
email: rvarad...@jhmi.edu

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


Re: [R] QQ plot for normality testing

2011-05-03 Thread Keith Jewell
I have found this web page useful

http://www.cms.murdoch.edu.au/areas/maths/statsnotes/samplestats/qqplot.html

Your mileage may vary.

Keith J

Matevz Pavlic matevz.pav...@gi-zrmk.si wrote in message 
news:ad5ca6183570b54f92aa45ce2619f9b901208...@gi-zrmk.si...
 Hi all,



 I am trying to test wheater the distribution of my samples is normal with 
 QQ plot.



 I have a values of water content in clays in around few hundred samples. 
 Is the code :



 qqnorm(w)  #w being water content

 qqline(w)





 sufficient?



 How do I know when I get the plots which distribution is normal and which 
 is not?



 Thanks, m


 [[alternative HTML version deleted]]


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


Re: [R] error in nls, step factor reduced below minFactor

2011-03-29 Thread Keith Jewell
?nls.control
  warnOnly a logical specifying whether nls() should return instead of 
signalling an error in the case of termination before convergence. 
Termination before convergence happens upon completion of maxiter 
iterations, in the case of a singular gradient, and in the case that the 
step-size factor is reduced below minFactor.


hope that helps

Keith J

Peter Ehlers ehl...@ucalgary.ca wrote in message 
news:4d9143ca.6060...@ucalgary.ca...
 On 2011-03-28 10:25, Steve Greiner wrote:
 Hello,
 I've seen various threads on people reporting:


 step factor 0.000488281 reduced below `minFactor' of 0.000976563

 While I know how to set the minFactor, what I'd like to have happen is 
 for nls to return to me, the last or closest fitted parameters before it 
 errors out.  In other words, so I don't get convergence, I'd still like 
 to acquire the values of the parameters last tried?  Can you tell me how 
 get nls to return to me the last set of parameters rather than just 
 stopping?

 Isn't that what setting trace=TRUE does?

 Peter Ehlers


 Regards
 Steven P. Greiner, Ph.D.

 Risk Head / FactSet Research System
 311 South Wacker
 Chicago, IL 60606
 sgrei...@factset.commailto:sgrei...@factset.com
 312 566 5109 (w)
 585 261 7138 (c)


 [[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] extract printed value from a function

2011-02-24 Thread Keith Jewell
I don't think that third suggestion actually works:
  x - print( twotPermutation(c(2,3,4),c(3,6,5),plotit=F) )
[1] 0.289
NULL
 x
NULL

 twotPermutation returns the value of invisible() which is NULL:
x - print(invisible())
x

This conflicts with the documented behaviour of twotPermutation which states 
that it should return the p-value (Value: The p-value for the test of the 
hypothesis that the mean of x1 differs from x2) and makes no mention of 
returning it invisibly, or printing the value when it is returned. I suggest 
that the function is in error and should be corrected by replacing the final 
two lines
---
print(signif(pval, 3))
invisible()
-
with simply
--
signif(pval, 3)
-
Relying on the default behaviour of R to print the value when it is not 
assigned. I will copy this suggestion to the listed maintainer (W. John 
Braun br...@stats.uwo.ca)



David Winsemius dwinsem...@comcast.net wrote in message 
news:53d4d49f-f8e1-44c0-b663-8b24d8420...@comcast.net...

 On Feb 24, 2011, at 7:22 AM, Peter Ehlers wrote:

 On 2011-02-24 03:26, Duarte Viana wrote:
 Hello all,

 This shouldn't be difficult, but I am not able to extract a printed
 value from a function and assign it to an object.

 In my case,

 library(DAAG)
 twotPermutation(c(2,3,4),c(3,6,5),plotit=F)
 [1] 0.298

 I would like to assign this result to an object.

 A third suggestion which has virtues of simplicity and keeping the  result 
 numeric:

 x - print( twotPermutation(c(2,3,4),c(3,6,5),plotit=F) )

  x
 [1] 0.1
  x - print(invisible (0.2))
 [1] 0.2
  x
 [1] 0.2

 --



 Two suggestions:
 1.
 Modify the code for twotPermutation by removing the invisible()
 at the end.

 2.
 Use capture.output to capture the result and then convert
 to numeric:

 pvstring - capture.output(
 twotPermutation( c(2,3,4), c(3,6,5), plotit=FALSE) ))

 Now you can use strsplit or substr to extract the numeric part:

 pv - as.numeric(strsplit(pvstring,  )[[1]][2])

 or

 pv - as.numeric(
  substr(pvstring, nchar(pvstring) - 5, nchar(pvstring)))

 Peter Ehlers


 Thanks,

 Duarte

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


Re: [R] A question on Duplicating

2011-02-10 Thread Keith Jewell
Unless I've made a mistake (it happens!) that gives FALSE on the data which 
the OP said should give TRUE.
Ravi Varadhan suggested
  duplicated(a)  duplicated(b)
but that gives the same result for
  b - c(n, m, o, m)
for which I think the OP would like FALSE

I think this may do it
  all((a %in% a[duplicated(a)]) == (b %in% b[duplicated(b)]))

Hope that helps

Keith J

rex.dw...@syngenta.com wrote in message 
news:36180405f8418449918ad20618d110fc094e9db...@usetcmsxmb02.nafta.syngenta.org...
 ab = paste(a,b,sep=;~;~;~)
 flag = length(ab)==length(unique(ab))

 This should work unless you use 3 consecutive winking elephants in other 
 places in your program.



 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 
 On Behalf Of Nipesh Bajaj
 Sent: Wednesday, February 09, 2011 10:12 AM
 To: r-help@r-project.org
 Subject: [R] A question on Duplicating

 Hello I am struggling to accomplice an idea which is as follows:

 I have a vector say: a - c(a, b, c, a) and another: b - c(m,
 n, o, m). Length of those 2 vectors are essentially be same. Here 
 task
 is to check the duplicates in the vector 'a' and then to check whether any
 duplicates are there in the same places of 'b'. If not, flag a FALSE.

 I above example, it is correct hence TRUE. However in general how can I
 implement this?

 Can somebody please help me?

 Thanks,

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




 message may contain confidential information. If you are not the 
 designated recipient, please notify the sender immediately, and delete the 
 original and any copies. Any use of the message by you is prohibited.

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


Re: [R] subsets

2011-01-20 Thread Keith Jewell
I don't think Ivan's solution meets the OP's needs.

I think you could do it using %in% and the approriate logical operations 
e.g.

aDF - data.frame(id=c(1,2,2,2,3,3,4,4,4,5),
 diagnosis=c(ah, ah, ihd, im, ah, stroke, ah, ihd, 
angina, ihd))
aDF[with(aDF,(id %in% id[diagnosis==ah])  (id %in% 
id[diagnosis==ihd])),]
aDF[with(aDF,(id %in% id[diagnosis==ah])  !(id %in% 
id[diagnosis==ihd])),]
aDF[with(aDF,!(id %in% id[diagnosis==ah])  (id %in% 
id[diagnosis==ihd])),]

That starts to feel a bit fiddly for me. You might want to look at package 
sqldf.

HTH

Keith J
--
Ivan Calandra ivan.calan...@uni-hamburg.de wrote in message 
news:4d37fbea.5070...@uni-hamburg.de...
Hi!

I think you should read the intro to R, as well as ?[ and ?subset. It
should help you to understand.

Let's say your data is in a data.frame called df:
# 1. ah and ihd
df_ah_ihd - df[df$diagnosis==ah | df$diagnosis==ihd, ]  ## the |
is the boolean OR (you want one OR the other). Note the last comma

#2. ah
df_ah - df[df$diagnosis==ah, ]

#3. ihd
df_ihd - df[df$diagnosis==ihd, ]

You could do the same using subset() if you feel better with this function.

HTH,
Ivan

Le 1/20/2011 09:53, Den a écrit :
 Dear R people
 Could you please help.

 Basically, there are two variables in my data set. Each patient ('id')
 may have one or more diseases ('diagnosis'). It looks like

 id diagnosis
 1 ah
 2 ah
 2 ihd
 2 im
 3 ah
 3 stroke
 4 ah
 4 ihd
 4 angina
 5 ihd
 ..
 Q: How to make three data sets:
 1. Patients with ah and ihd
   2. Patients with ah but no ihd
 3. Patients with  ihd but no ah?

   If you have any ideas could just guide what should I look for. Is a
 subset or aggregate, or loops, or something else??? I am a bit lost. (F1
 F1 F1 !!!:)
 Thank you

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


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

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

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


Re: [R] subsets

2011-01-20 Thread Keith Jewell
I did try it. It gave me
[[1]]
   id diagnosis
1   1ah
5   3ah
7   4ah
8   4   ihd
10  5   ihd

[[2]]
  id diagnosis
1  1ah
2  2ah
5  3ah
7  4ah

[[3]]
   id diagnosis
3   2   ihd
8   4   ihd
10  5   ihd

Which isn't what the OP asked for

 Q: How to make three data sets:
1. Patients with ah and ihd
  id diagnosis
2  2ah
3  2   ihd
4  2im
7  4ah
8  4   ihd
9  4angina

2. Patients with ah but no ihd
  id diagnosis
1  1ah
5  3ah
6  3stroke

3. Patients with  ihd but no ah?
   id diagnosis
10  5   ihd

Regards,

KJ
-
Henrique Dallazuanna www...@gmail.com wrote in message 
news:aanlktikqnw_hntdyxdrj+ytyqf6tghlmh0qsleouf...@mail.gmail.com...
Try this:

lapply(list(c('ah', 'ihd'), 'ah', 'ihd'), function(x)subset(aDF, diagnosis
== x))


On Thu, Jan 20, 2011 at 6:53 AM, Den d.kazakiew...@gmail.com wrote:

 Dear R people
 Could you please help.

 Basically, there are two variables in my data set. Each patient ('id')
 may have one or more diseases ('diagnosis'). It looks like

 id  diagnosis
 1   ah
 2   ah
 2   ihd
 2   im
 3   ah
 3   stroke
 4   ah
 4   ihd
 4   angina
 5   ihd
 ..
 Q: How to make three data sets:
1. Patients with ah and ihd
2. Patients with ah but no ihd
3. Patients with  ihd but no ah?

  If you have any ideas could just guide what should I look for. Is a
 subset or aggregate, or loops, or something else??? I am a bit lost. (F1
 F1 F1 !!!:)
 Thank you

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




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

[[alternative HTML version deleted]]









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


Re: [R] median by geometric mean -- are we missing what's important?

2011-01-18 Thread Keith Jewell
Yes, of course. I think all the posts up to Bert's addressed the coding 
question as asked - how to calculate a particular version of the median (not 
the mean) rather than any underlying, unstated, statistical or scientific 
question.

IIRC there hasn't been any indication that non-positive values do occur in 
the OPs environment, so the extension to zero and negatives was (at least 
for me) an R programming diversion, I was interested in robust answers to 
the coding question as asked. I'd caution against any assumption that 
anything I presented was applicable in any particular circumstances!

Best regards,

Keith J

Joshua Wiley jwiley.ps...@gmail.com wrote in message 
news:AANLkTinqFQtHodoLw=3romdksyinxbwg5tqjqjm0-...@mail.gmail.com...
 On Mon, Jan 17, 2011 at 9:23 AM, Bert Gunter gunter.ber...@gene.com 
 wrote:
 Folks:

 I know this may be overreaching, but are we missing what's important?
 WHY do the zeros occur? Are they values less then a known or unknown
 LOD? -- and/or is there positive mass on zero? In either case, using
 logs to calculate a geometric mean may not make sense. Paraphrasing

 Isn't this a bit of a general problem with the geometric mean if there
 are 0s or an odd number of negative numbers it becomes 0 or imaginary
 (please do correct me if I'm wrong)?

 sqrt(prod(c(2, 0, 54)))
 sqrt(prod(c(-2, 2)))


 Greg Snow, what is the scientific question? What is the model?

 Cheers,
 Bert



 On Mon, Jan 17, 2011 at 9:13 AM, Keith Jewell k.jew...@campden.co.uk 
 wrote:
 Just in case some of x are negative (the desired median still exists, as
 long as the two middle values are non -ve), how about:

 x - runif(20, -1, 100)
 exp(median(log(pmax(0,x

 It'll give -Inf if the two middle values are negative, when I guess we
 should get NaN, but I can't see a 1-line way to handle that!

 Keith J

 Peter Ehlers ehl...@ucalgary.ca wrote in message
 news:4d3468ef.5010...@ucalgary.ca...
 I've been reminded by Prof. Brian Ripley that R's
 log() function will indeed handle zeros appropriately.

 Apologies to S Ellison and Hadley Wickham.

 Peter Ehlers

 On 2011-01-17 06:55, Peter Ehlers wrote:
 On 2011-01-17 02:19, S Ellison wrote:
 Will this do?

 x- runif(20, 1, 100)

 exp( median( log( x) ) )

 S Ellison


 That's what Hadley proposed, too. It's fine for
 your example, but there is potentially a small
 problem with this method: the data must be positive.
 Since it's not unusual to see data with some zeros,
 the log() would fail.

 Depending on what type of data I was going to use
 this modification of the median for, I would consider
 modifying the (quite short) median.default function,
 with appropriate additional data checks.

 Peter Ehlers


 Skull Crossboneswitch.of.agne...@gmail.com 15/01/2011 16:26
 Hi All,

 I need to calculate the median for even number of data points.However
 instead of calculating
 the arithmetic mean of the two middle values,I need to calculate 
 their
 geometric mean.

 Though I can code this in R, possibly in a few lines, but wondering 
 if
 there
 is
 already some built in function.

 Can somebody give a hint?

 Thanks in advance

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


Re: [R] median by geometric mean

2011-01-17 Thread Keith Jewell
Just in case some of x are negative (the desired median still exists, as 
long as the two middle values are non -ve), how about:

x - runif(20, -1, 100)
exp(median(log(pmax(0,x

It'll give -Inf if the two middle values are negative, when I guess we 
should get NaN, but I can't see a 1-line way to handle that!

Keith J

Peter Ehlers ehl...@ucalgary.ca wrote in message 
news:4d3468ef.5010...@ucalgary.ca...
 I've been reminded by Prof. Brian Ripley that R's
 log() function will indeed handle zeros appropriately.

 Apologies to S Ellison and Hadley Wickham.

 Peter Ehlers

 On 2011-01-17 06:55, Peter Ehlers wrote:
 On 2011-01-17 02:19, S Ellison wrote:
 Will this do?

 x- runif(20, 1, 100)

 exp( median( log( x) ) )

 S Ellison


 That's what Hadley proposed, too. It's fine for
 your example, but there is potentially a small
 problem with this method: the data must be positive.
 Since it's not unusual to see data with some zeros,
 the log() would fail.

 Depending on what type of data I was going to use
 this modification of the median for, I would consider
 modifying the (quite short) median.default function,
 with appropriate additional data checks.

 Peter Ehlers


 Skull Crossboneswitch.of.agne...@gmail.com   15/01/2011 16:26
 Hi All,

 I need to calculate the median for even number of data points.However
 instead of calculating
 the arithmetic mean of the two middle values,I need to calculate their
 geometric mean.

 Though I can code this in R, possibly in a few lines, but wondering if
 there
 is
 already some built in function.

 Can somebody give a hint?

 Thanks in advance



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


Re: [R] how to wrap a long line in R scripts?

2011-01-10 Thread Keith Jewell

Jonathan P Daily jda...@usgs.gov wrote in message 
news:of588e803b.869e9aff-on85257814.004d298d-85257814.004d4...@usgs.gov...
a - rey lo
ong charrr

 Although the indentation is just personal preference.
 --
 Jonathan P. Daily
 Technician - USGS Leetown Science Center
 11649 Leetown Road
 Kearneysville WV, 25430
 (304) 724-4480
 Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly


Did you test that? Printing a to see the result so the commands are
-
a - rey lo
ong charrr
a

Pasting directly into Rgui
 a - rey lo
+ ong charrr
 a
[1] rey lo\nong 
charrr

Saving to file 'test.r' and sourcing
 source(C:\\Documents and Settings\\jewell\\Desktop\\test.r, echo=TRUE)
 a - rey lo
+ ong charrr
 a
[1] rey lo\nong 
charrr

I don't think this is what the OP wanted.
I guess he wants rey loong 
charrr

I don't know the answer (other than, as suggested by Peter Ehlers) to build 
it bit by bit.

KJ

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


Re: [R] String to array

2010-12-09 Thread Keith Jewell

Romildo Martins romildo.mart...@gmail.com wrote in message 
news:aanlktinbiaexcobzyqdbtr62xr9q=kjvwaazaqi-k...@mail.gmail.com...
 Hello,

 how convert x in xarray (numbers)?

 x
 [1] 0 - 13
 y
 [1] 11 - 23
 z
 [1] 220 - 9
 xarray
 [1]  0 13
 yarray
 [1] 11 23
 zarray
 [1] 220   9



 Thanks,

 RMB

-
 x - 0 - 13
 x
[1] 0 - 13
 as.numeric(unlist(strsplit(x, -)))
[1]  0 13

HTH

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


Re: [R] colname refered by a variable

2010-12-03 Thread Keith Jewell
or even shorter
df[,paste(A,C,sep=)]


Santosh Srinivas santosh.srini...@gmail.com wrote in message 
news:aanlktikcjy7bvyfbwuwmrq4dhg4pbdau+qh_7+k+b...@mail.gmail.com...
try this ..

df[,colnames(df)==paste(A,C,sep=)]

On Fri, Dec 3, 2010 at 12:05 PM, Yuan Jian jayuan2...@yahoo.com wrote:
 Hello,

 I tried to use a variable to refer colname, but I got error, could anyone 
 give me advice?

df=data.frame(cbind(AB=1:3,AC=3:5))
 df$AC
 [1] 3 4 5
 df$paste(A,C,sep=)
 Error: attempt to apply non-function

 thanks
 Jian




 [[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] How to get a specific named element in a nested list

2010-11-11 Thread Keith Jewell
Neat!

I think replacing
 out - rmatch(el, name)
with
out - Recall(el, name)
will avoid the dependence of the code on the function name

Keith J

Michael Bedward michael.bedw...@gmail.com wrote in message 
news:aanlktikv9zepxipbp7ftr8vmpgsjaptjyj_dudy-m...@mail.gmail.com...
On 11 November 2010 21:08, Janko Thyson janko.thy...@ku-eichstaett.de 
wrote:

 Could it be that you forgot to supply 'getEL()'? Or do I have to use some
 package to make it available?


Oops - no. The problem was me stupidly renaming the function without
modifying the code.  Try this instead...

rmatch - function(x, name) {
 pos - match(name, names(x))
 if (!is.na(pos))
   return(x[[pos]])

 for (el in x) {
   if (class(el) == list) {
 out - rmatch(el, name)
 if (!is.null(out)) return(out)
   }
 }
}


Sorry about that.

Michael


 -Ursprüngliche Nachricht-
 Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 
 Im
 Auftrag von Michael Bedward
 Gesendet: Donnerstag, 11. November 2010 10:56
 An: friedericksen.h...@gmail.com
 Cc: r-h...@stat.math.ethz.ch
 Betreff: Re: [R] How to get a specific named element in a nested list

 Hi Friedericksen,

 This function will do it. No doubt there are more elegant ways :)

 rmatch - function(x, name) {
 pos - match(name, names(x))
 if (!is.na(pos))
 return(x[[pos]])

 for (el in x) {
 if (class(el) == list) {
 out - getEl(el, name)
 if (!is.null(out)) return(out)
 }
 }
 }


 Michael

 On 11 November 2010 19:05, Friedericksen Hope
 friedericksen.h...@gmail.com wrote:
  Hello,
 
  I have a nested named list structure, like the following:
 
  x - list(
  list(
  list(df1,df2)
  list(df3,
  list(df4,df5))
  list(df6,df7)))
 
  with df1...d7 as data frames. Every data frame is named.
 
  Is there a way to get a specific named element in x?
 
  so, for example,
 
  x[[c(df5)]] gives me the data frame 5?
 
  Thank you in advance!
 
  Best,
  Friedericksen
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Installing R and an editor on a USB drive

2010-11-10 Thread Keith Jewell
As I recall (my memory may be faulty), Tinn-R installation required admin 
privileges, but running does not and the installation does not include the 
specific file path in any files.

To make Tinn-R available on a machine where I do not have admin privileges I 
have
a) installed onto a machine where I do have privileges
b) copied the entire Tinn-R folder to the target. I guess that could be a 
USB stick

HTH

Keith J

PAC2 pacheval...@gmail.com wrote in message 
news:1289393991376-3036030.p...@n4.nabble.com...

 Tinn R does not require administrator privileges. I've installed it on my 
 USB
 stick and it works fine.
 -- 
 View this message in context: 
 http://r.789695.n4.nabble.com/Installing-R-and-an-editor-on-a-USB-drive-tp3035839p3036030.html
 Sent from the R help mailing list archive at Nabble.com.


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


Re: [R] Is there a way to have 'comment' keep a list?

2010-11-09 Thread Keith Jewell
I hadn't seen 'comment' before, so don't take my suggestion as 
authoritative. It looks useful, so I investigated a bit.

This technique seems to work and is (perhaps?) easier than names:
tlist - list(a=c(1:3), b=7)
   comment(x) - unlist(sapply(tlist, as.character))
or in one line
   comment(x) - unlist(sapply(list(a=c(1:3), b=7), as.character))

If at least one of the list elements is already character you could simplify 
to:
tlist - list(a=c(1:3), b=fred)
   comment(x) - unlist(tlist)
or in one line
   comment(x) - unlist(list(a=c(1:3), b=fred))

Not as nice as having a _real_ list, but I guess that would really be a case 
for attributes

HTH

Keith J

Tal Galili tal.gal...@gmail.com wrote in message 
news:aanlktimpmma9_h1+=oj1bhrf27rlp2j5veodhjxqp...@mail.gmail.com...
 Hello all,

 I recently discovered the comment command.
 I see it can only hold a vector of characters.

 Is there a way (or an alternative), to make it possible to have it keep a
 list?
 (for example, to keep different pieces of information like date of 
 creation,
 information of each variable and so on)

 The closest solution I can think of is using 'names' on the vector, like
 this:
 x - 1
 comment(x) - letters
 names(comment(x)) - LETTERS
 x
 comment(x)


 Any other suggestions?
 (or general best practices for the comment command ?)

 Thanks,
 Tal

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

 [[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] Changing sign on absolute numbers 0 problems

2010-10-21 Thread Keith Jewell

Sadz A sadz_a1...@yahoo.co.uk wrote in message 
news:419230.77523...@web24610.mail.ird.yahoo.com...
 Hi,

 I am trying to do some calculations turning DMS data to decimal degrees 
 using
 the formula (D+(M/60)+(S/3600)), some of the D's involve -ve numbers, the
 easiest way to do the calculation is to use absolute numbers then use the 
 'sign'
 function in R to change the answer back to the correct -ve or +ve,

 for example, if;
 D--69
 M-8
 S-10
 then
 decimal-D+(M/60)+(S/3600)
 -69+(8/60)+(10/3600)   = this would equal -68.86389  (which is wrong, it 
 should
 be -69.13611,  so i used the following function)

 decimal-(abs(D)+(M/60)+(S/3600))
 decimal.degs-sign(D)*decimal
 decimal.degs
 -69.13611

 because ((69+(8/60)+(10/3600)=69.13611) and then the -sign is put back in.

 This works fine untill D=0
 because then 'sign' does not give 0 a +ve sign it takes it as 0 and 
 multiplies
 decimal by 0 to give 0.
 example
 D-0
 decimal-D+(M/60)+(S/3600)
 decimal.degs-sign(D)*decimal
 decimal.degs
 0

 Is there anyway to get around this??
 and make D=0 a positive and not a 0 with sign or another function??

 Any help is appreciated
 Thank you
 sadz

 ps please email me if you need more info




 [[alternative HTML version deleted]]

In addition to the other comments, you might be interested in package 'sp' 
which has:
Class DMS for degree, minute, decimal second values
and facilities to convert between DMS, decimal, and character.

HTH

Keith J

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


Re: [R] Changing sign on absolute numbers 0 problems

2010-10-21 Thread Keith Jewell
In case it helps...

 test - c(-0:00:53, -0:01:10., -0:01:26., -0:01:38., -0:01:43,
+ -0:01:59., -0:03:50., -0:04:46, -0:05:01., -0:05:16.,
+ 3:41:33.0, 3:43:09.4, 3:44:26.3, 3:47:26.0, 3:48:19.3,
+ 3:52:13.4, 3:57:10.2, 4:29:37.6, 5:01:28.4, 5:08:45.6 )
 require(sp)
 as.numeric.DMS(char2dms(paste(sub($, '',sub(:, ',sub(:, d, 
 test))),ifelse(substring(test,1,1)==-,W,E), sep=)))
 [1] -0.0147 -0.0194 -0.0239 -0.0272 -0.0286 -0.03305556 
 -0.0639 -0.0794 -0.0836
[10] -0.0878  3.6925  3.71927778  3.74063889  3.7906  3.80536111 
3.87038889  3.9528  4.4938
[19]  5.0246  5.1460



David Winsemius dwinsem...@comcast.net wrote in message 
news:9c5d0d83-2ceb-4f5c-a57e-c75fbbda9...@comcast.net...
 With permission I am copying a private communication to the list.

 On Oct 21, 2010, at 9:20 AM, Sadz A wrote:

 Hi,

 I think maybe I did not explain myself properly, I'll try again;

 I am trying to convert location data in DMS degrees to decimal  degrees 
 format.

 I have attached my data and below is the work I have done so far and 
 notes explaining what I have done. The problem is negative 0, the  +/- 
 sign indicates direction so it is very important to have the  right sign 
 in front, but R takes 0 and -0 as 0.

 #approach
 #download 'gsubfn' from R CRAN.

 #please insert appropriate directory, the table is attached#
 data-read.table(vol by genous lat lon.txt,header=T)
 names(data)
 attach(data)
 library(gsubfn)

 #the latitude data is in MD_LATITUD so to separate out the numbers  and 
 convert to decimal degrees i used...

 At this point I realized that my earlier assumption that -0 == 0 might 
 not be as obvious as I had thought, at least when it applies to the 
 leading degrees entry in a latitude, which I was not thinking about  very 
 clearly.

 latitude-as.vector(MD_LATITUD)
 x - c(latitude)
 Convert - function(d, m, s, dd = as.numeric(d), mm = as.numeric(m),  ss 
 = as.numeric(s)) sign(dd) * (abs(dd) + mm / 60 + ss / 3600)

 The problem as I saw it was that the as.numeric conversion of d to dd  was 
 throwing away the sign.

 test - c(-0:00:53, -0:01:10., -0:01:26., -0:01:38., -0:01:43,
 -0:01:59., -0:03:50., -0:04:46, -0:05:01., -0:05:16.,
 3:41:33.0, 3:43:09.4, 3:44:26.3, 3:47:26.0, 3:48:19.3,
 3:52:13.4, 3:57:10.2, 4:29:37.6, 5:01:28.4, 5:08:45.6 )

 So I substituted an ifelse( grepl(d) -1,1) test for - from the 
 unconverted degree entry:

  Convert - function(d, m, s, dd = as.numeric(d), mm = as.numeric(m),
ss = as.numeric(s)){
  ifelse(grepl(-, d),-1,1) * (abs(dd) + mm /  60 
 + ss / 3600) }

  Lat-strapply(test, (.*):(.*):(.*), Convert, simplify = TRUE)

  Lat
 
 [1] -0.0147 -0.0194 -0.0239 -0.0272 -0.0286  -0.03305556 
  -0.0639 -0.0794
  [9] -0.0836 -0.0878  3.6925  3.71927778  3.74063889 
 3.7906  3.80536111  3.87038889
 [17]  3.9528  4.4938  5.0246  5.1460


 Lat-strapply(x, (.*):(.*):(.*), Convert, simplify = TRUE)
 Lat

 #as you can see in Lat there are lots of 0's, which should not be  there 
 but are because 'sign(dd)' takes +ve when +ve, -ve when -ve  and 
 multiplies it by 'abs(dd)' which is correct, BUT for 0 it  assigns 
 niether +ve or -ve, giving 0 a 0, and anything times 0 is  0..

 #I modified the code to

 latitude-as.vector(MD_LATITUD)
 x - c(latitude)
 Convert - function(d, m, s, dd = as.numeric(d), mm = as.numeric(m),  ss 
 = as.numeric(s)) sign(ifelse(dd==0,sign(dd))) * (abs(dd) + mm /  60 + ss 
 / 3600)
 Lat-strapply(x, (.*):(.*):(.*), Convert, simplify = TRUE)
 Lat

 #so I now have the correct absolute decimal degrees in all cases and  the 
 correct direction in all cases except where there should be a  -0!, 
 because -0's are ignored and assumed to be the same as +0 which  is wrong 
 because the + and - indicate direction.

 # Do you know of a way I can get R to separate out the sign from 
 MD_LATITUD, so that I can change
 # 'Convert - function(d, m, s, dd = as.numeric(d), mm =  as.numeric(m), 
 ss = as.numeric(s)) sign(dd) * (abs(dd) + mm / 60 +  ss / 3600)' to 
 something like
 # 'Convert - function(sign, d, m, s, dd = as.numeric(d), mm = 
 as.numeric(m), ss = as.numeric(s)) sign * (abs(dd) + mm / 60 + ss / 
 3600) #(this does not work but something similar, or a different 
 approach may?)

 Any help will be appreciated.
 Thank you
 sadz


 From: David Winsemius dwinsem...@comcast.net
 To: David Winsemius dwinsem...@comcast.net
 Cc: Sadz A sadz_a1...@yahoo.co.uk; r-help@r-project.org
 Sent: Wed, 20 October, 2010 20:45:39
 Subject: Re: [R] Changing sign on absolute numbers 0 problems


 On Oct 20, 2010, at 3:19 PM, David Winsemius wrote:

 
  On Oct 20, 2010, at 11:47 AM, Sadz A wrote:
 
  Hi,
 
  I am trying to do some calculations turning DMS data to decimal
 degrees using
  the formula (D+(M/60)+(S/3600)), some of the D's involve -ve
 numbers, the
  easiest way to do the calculation is 

Re: [R] Nonlinear Regression Parameter Shared Across Multiple DataSets

2010-10-15 Thread Keith Jewell
Hi,

I've had to do something like that before. It seems to be a feature of nls 
(in R, but not as I recall in Splus) that it accepts a list with vector 
components as 'start' values, but flattens the result values to a single 
vector.

I can't spend much time explaining, but here's a fragment of code that might 
get you started:
---
# Fit the nls, correct coef names lost by nls
   val - nls(formula=formulaIn, data=DataList, start= tCoefs, 
control=control)
  CoefList - list()  # initialise CoefList
   for(aName in names(tCoefs)) {# for each vector of 
coefficients
 tvec - get(aName, envir=val$m$getEnv()) # get it from the nls 
environment
 names(tvec) - names(tCoefs[[aName]]) # correct its names
  assign(aName, tvec, envir=val$m$getEnv()) # return it to nls
 CoefList[[aName]] - tvec# store in CoefList
}

As I recall,
tCoefs is a list of starting values that can have vector components
CoefList ends up as a similar structure and named list of result values

hth

Keith J

Jared Blashka evilamaran...@gmail.com wrote in message 
news:aanlktimprowm-mne9n_bu8ty=jylitq4ewhpph1hy...@mail.gmail.com...
 Looking at the source for nlrob, it looks like it saves the coefficients
 from the results of running an nls and then passes those coefficients back
 into the next nls request. The issue that it's running into is that nls
 returns the coefficients as upper, LOGEC501, LOGEC502, and LOGEC503, 
 rather
 than just upper and a vector named LOGEC50. Does anyone know a way to
 restructure the formula/start parameter so that coef returns a vector
 instead of each element individually? Right now, I've had to 'hack' nlrob 
 so
 it recombines similarly named elements into a vector, but was wondering if
 there was a way to accomplish the end goal without those measures.

 Thanks,
 Jared

 On Wed, Oct 13, 2010 at 3:14 PM, Jared Blashka 
 evilamaran...@gmail.comwrote:

 As an addendum to my question, I'm attempting to apply the solution to 
 the
 robust non-linear regression function nlrob from the robustbase package, 
 and
 it doesn't work in that situation. I'm getting

 allRobustFit - nlrob(Y ~ (upper)/(1+10^(X-LOGEC50[dset])), data=all
 ,start=list(upper=max(all$Y),LOGEC50=c(-8.5,-8.5,-8.5)))
 Error in nls(formula, data = data, start = start, algorithm = algorithm,
  :
   parameters without starting value in 'data': LOGEC50

 I'm guessing this is because the nlrob function doesn't know what to do
 with a vector for a start value. Am I correct and is there another method 
 of
 using nlrob in the same way?

 Thanks,
 Jared

 On Tue, Oct 12, 2010 at 8:58 AM, Jared Blashka 
 evilamaran...@gmail.comwrote:

 Thanks so much! It works great.

 I had thought the way to do it relied on combining the data sets, but I
 couldn't figure out how to alter the formula to work with the 
 combination.

 Jared


 On Tue, Oct 12, 2010 at 7:07 AM, Keith Jewell 
 k.jew...@campden.co.ukwrote:


 Jared Blashka evilamaran...@gmail.com wrote in message
 news:aanlktinffmudugqnkudvr=fmf0wrrtsbjxjexuki_...@mail.gmail.com...
  I'm working with 3 different data sets and applying this non-linear
  regression formula to each of them.
 
  nls(Y ~ (upper)/(1+10^(X-LOGEC50)), data=std_no_outliers,
  start=list(upper=max(std_no_outliers$Y),LOGEC50=-8.5))
 
  Previously, all of the regressions were calculated in Prism, but I'd
 like
  to
  be able to automate the calculation process in a script, which is why
 I'm
  trying to move to R. The issue I'm running into is that previously, 
  in
  Prism, I was able to calculate a shared value for a constraint so 
  that
 all
  three data sets shared the same value, but have other constraints
  calculated
  separately. So Prism would figure out what single value for the
 constraint
  in question would work best across all three data sets. For my 
  formula,
  each
  data set needs it's own LOGEC50 value, but the upper value should be
 the
  same across the 3 sets. Is there a way to do this within R, or with a
  package I'm not aware of, or will I need to write my own nls function
 to
  work with multiple data sets, because I've got no idea where to start
 with
  that.
 
  Thanks,
  Jared
 
  [[alternative HTML version deleted]]
 
 An approach which works for me (code below to illustrate principle, not
 tried...)

 1) combine all three data sets into one dataframe with a column (e.g.
 dset) indicating data set (1, 2 or 3)

 2) express your formula with upper as single valued and LOGEC50 as a
 vector
 inderxed by dest e.g.
 Y ~ upper/(1+10^(C-LOGEC50[dset]))

 3) in the start list, make LOGEC50 a vector e.g. using -8.5 as start 
 for
 all
 three LOGEC50 values
   start =
 list(start=list(upper=max(std_no_outliers$Y),LOGEC50=c(-8.5, -8.5, -8.5))

 Hope that helps,

 Keith J

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help

Re: [R] Nonlinear Regression Parameter Shared Across Multiple Data Sets

2010-10-12 Thread Keith Jewell

Jared Blashka evilamaran...@gmail.com wrote in message 
news:aanlktinffmudugqnkudvr=fmf0wrrtsbjxjexuki_...@mail.gmail.com...
 I'm working with 3 different data sets and applying this non-linear
 regression formula to each of them.

 nls(Y ~ (upper)/(1+10^(X-LOGEC50)), data=std_no_outliers,
 start=list(upper=max(std_no_outliers$Y),LOGEC50=-8.5))

 Previously, all of the regressions were calculated in Prism, but I'd like 
 to
 be able to automate the calculation process in a script, which is why I'm
 trying to move to R. The issue I'm running into is that previously, in
 Prism, I was able to calculate a shared value for a constraint so that all
 three data sets shared the same value, but have other constraints 
 calculated
 separately. So Prism would figure out what single value for the constraint
 in question would work best across all three data sets. For my formula, 
 each
 data set needs it's own LOGEC50 value, but the upper value should be the
 same across the 3 sets. Is there a way to do this within R, or with a
 package I'm not aware of, or will I need to write my own nls function to
 work with multiple data sets, because I've got no idea where to start with
 that.

 Thanks,
 Jared

 [[alternative HTML version deleted]]

An approach which works for me (code below to illustrate principle, not 
tried...)

1) combine all three data sets into one dataframe with a column (e.g. 
dset) indicating data set (1, 2 or 3)

2) express your formula with upper as single valued and LOGEC50 as a vector 
inderxed by dest e.g.
 Y ~ upper/(1+10^(C-LOGEC50[dset]))

3) in the start list, make LOGEC50 a vector e.g. using -8.5 as start for all 
three LOGEC50 values
   start = 
list(start=list(upper=max(std_no_outliers$Y),LOGEC50=c(-8.5, -8.5, -8.5))

Hope that helps,

Keith J

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


Re: [R] boundary check

2010-09-24 Thread Keith Jewell
/matlabcentral/fileexchange/10226-inhull
with some modifications and simplifications
}
\usage{
inhull(testpts, calpts, hull = convhulln(calpts), tol = 
mean(mean(abs(calpts))) * sqrt(.Machine$double.eps))
}
%- maybe also 'usage' for other objects documented here.
\arguments{
  \item{testpts}{
numeric n x p array representing n points in p dimensions; converted to 
matrix by \code{as.matrix(testpts); each point is tested whether inside the 
convex hull (defined by calpts or hull). }
}
  \item{calpts}{
numeric m x p array representing m points in p dimensions; converted to 
matrix by \code{as.matrix(testpts). If 'hull' is not given, 
\code{geometry::convhulln(calpts)} is used to define the convex hull }
}
  \item{hull}{
(OPTIONAL) tessellation (or triangulation) generated by convhulln. If hull 
is left empty or not supplied, then it will be generated.
}
  \item{tol}{
(OPTIONAL) tolerance on the tests for inclusion in the convex hull. You can 
think of tol as the distance a point
may possibly lie outside the hull, and still be perceived
as on the surface of the hull. Because of numerical slop
nothing can ever be done exactly here.
}
}
\details{
%%  ~~ If necessary, more details than the description above ~~
}
\value{
An integer vector of length n \tabular{rl}{
1 \tab inside hull\cr
-1 \tab inside hull\cr
0 \tab on hull (to precision indicated by tol)
}}
\references{
\url{http://www.mathworks.com/matlabcentral/fileexchange/10226-inhull}
}
\author{
Keith Jewell 2009
}
\note{
submitted for inclusion in geometry package~
}

%% ~Make other sections like Warning with \section{Warning }{} ~

\seealso{
%% ~~objects to See Also as \code{\link{help}}, ~~~
}
\examples{
set.seed(1234)
ps - matrix(rnorm(4000),ncol=4)
xs - matrix(rnorm(1200),ncol=4)
inhull(xs, ps)
  }
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
\keyword{ ~kwd1 }
\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line

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


Re: [R] efficient list indexing

2010-09-22 Thread Keith Jewell
Also, it may be that you want bigfred to be a list of 5 lists each of 2 
elements (happy and name) rather than a list of 10 elements.

Thus (also using double bracketing)

fred- list(happy = 1:10, name = squash)
bigfred - replicate(5, fred, FALSE)
bigfred[[2]][[2]]

hth

Keith J

Patrick Burns pbu...@pburns.seanet.com wrote in message 
news:4c99e118.2010...@pburns.seanet.com...
 I'm confused by what you are looking for.
 There's some slight possibility that you
 are looking for double bracket subscripting
 with a vector:

  list(a=1:5, b=letters)[[c(2,4)]]
 [1] d


 On 22/09/2010 10:58, Alaios wrote:
 Hello everyone,

 I need some help with lists inside lists (a good way to emulate a 
 struct)\

 Assume that there is a small list called fred:
 fred- list(happy = 1:10, name = squash)


 and a big list called bigfred that includes fred list 5 times
 bigfred- rep(fred,5)

 Is it possible somehow to index all these sublists(fred) inside bigfred 
 with a
 more direct way like this:
 bigfred[1] shows the first sublist fred
 bigfred[2][2] shows the second sublist fred, the second element of the 
 fred list

 So far I found some way to do this by refering to the sublists by the 
 following:
 bigfred[1+index*length(fred)]
 where index shows the beginning of a sublist.

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




 [[alternative HTML version deleted]]

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


 -- 
 Patrick Burns
 pbu...@pburns.seanet.com
 http://www.burns-stat.com
 (home of 'Some hints for the R beginner'
 and 'The R Inferno')


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


Re: [R] How to generate a particular sequence ?

2010-09-13 Thread Keith Jewell

Ted Harding ted.hard...@manchester.ac.uk wrote in message 
news:xfmail.100913104250.ted.hard...@manchester.ac.uk...
 On 13-Sep-10 09:19:21, Feng Li wrote:
 Dear R,
 I have a vector, say a = c(1,2,4,5,6,8). Can I generate a vector
 or array (2-by-3-by-3) of this form
 c(1,2,1,2,1,2,4,5,4,5,4,5,6,8,6,8,6,8)
 in which every two elements in a have been repeated twice?

 I am to stupid today and could not figure this simple question out...
 Many many thanks!

 Feng

 A possible solution (somewhat generalisable):

  a - c(1,2,4,5,6,8)
  Reps - 3

  pairs - matrix(a,nrow=2)
  as.vector(pairs[,rep(c(1,2,3),each=Reps)])
  # [1] 1 2 1 2 1 2 4 5 4 5 4 5 6 8 6 8 6 8

 (By the way, you have 3 repetitions but wrote twice -- I assume
 you meant thrice but the above generalises to 2 repetitions ... :)

 Ted.
The pedant in me couldn't resist asking:
  If he'd said repeated once would you expect only one occurence of each 
pair?

Sorry. I'll get my coat

Keith J

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


Re: [R] Calculating with tolerances (error propagation)

2010-09-09 Thread Keith Jewell
Jan private jrheinlaen...@gmx.de wrote in message 
news:1284029454.2740.361.ca...@localhost.localdomain...
 Hello Bernardo,

 -
 If I understood  your problem this script solve your problem:

 q-0.15 + c(-.1,0,.1)
 h-10 + c(-.1,0,.1)
 5*q*h
 [1]  2.475  7.500 12.625
 -

 OK, this solves the simple example.
 But what if the example is not that simple. E.g.

 P = 5 * q/h

 Here, to get the maximum tolerances for P, we need to divide the maximum
 value for q by the minimum value for h, and vice versa. Is there any way
 to do this automatically, without thinking about every single step?

 There is a thing called interval arithmetic (I saw it as an Octave
 package) which would do something like this.

 I would have thought that tracking how a (measuring) error propagates
 through a complex calculation would be a standard problem of
 statistics?? In other words, I am looking for a data type which is a
 number with a deviation +- somehow attached to it, with binary operators
 that automatically knows how to handle the deviation.

 Thank you,
 Jan

Ahhh! tracking how a (measuring) error propagates through a complex 
calculation

That doesn't depend only on values+errors, it also depends on the 
calculations, so - as you imply - you'd have to define a new data type and 
appropriate methods for all the mathematical operators (not just the binary 
ones!). Not a trivial task!

If you don't already know it, you should look at  Evaluation of measurement 
data - Guide to the expression of uncertainty in measurement 
http://www.bipm.org/utils/common/documents/jcgm/JCGM_100_2008_E.pdf 
especially section 5.

Hope that helps,

Keith J

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


Re: [R] Where the data file is stored?

2010-08-12 Thread Keith Jewell
You're not seeing the .Rdata file containing the data objects. Try:

list.files(getwd(),full.name=TRUE, all.files=TRUE)


Stephen Liu sati...@yahoo.com wrote in message 
news:961426.85478...@web113203.mail.gq1.yahoo.com...
- Original Message 

From: Alain Guillet alain.guil...@uclouvain.be
To: Stephen Liu sati...@yahoo.com
Cc: r-help@r-project.org
Sent: Thu, August 12, 2010 5:28:32 PM
Subject: Re: [R] Where the data file is stored?

 You can find your current working directory with the getwd() function.


Hi Alain,


Thanks for your advice.


 getwd()
[1] /home/userA


 list.files(getwd())
 [1] Desktop   Documents Downloads
 [4] examples.desktop  last-packages.txt Music
 [7] myR   petdrug.csv   Pictures
[10] PublicR Templates
[13] Videos


 list.files(getwd(),full.name=TRUE)
 [1] /home/userA/Desktop
 [2] /home/userA/Documents
 [3] /home/userA/Downloads
 [4] /home/userA/examples.desktop
 [5] /home/userA/last-packages.txt
 [6] /home/userA/Music
 [7] /home/userA/myR
 [8] /home/userA/petdrug.csv
 [9] /home/userA/Pictures
[10] /home/userA/Public
[11] /home/userA/R
[12] /home/userA/Templates
[13] /home/userA/Videos


How to show on the printout which is directory?  TIA

B.R.
Stephen L


On 12-Aug-10 11:22, Stephen Liu wrote:
 - Original Message 

 From: Philipp Pagelp.pa...@wzw.tum.de
 To: r-help@r-project.org
 Sent: Thu, August 12, 2010 3:54:53 PM
 Subject: Re: [R] Where the data file is stored?

 You dont't tell us what you did to create a datafile - to me it
 sounds like you created an object (probably a data frame) in your R
 workspace. If that's  the case it is stored in a file called .RData in
 your current work directory (together with other variables in your
 workspace). If that is not what you did please give us mre
 information.

 Hi Philipp,

 Yes, it is data frame.

 I have run the step
 write.csv ...

 Other advice noted.  Thanks


 B.R.
 Stephen L




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


-- 
Alain Guillet
Statistician and Computer Scientist

SMCS - IMMAQ - Université catholique de Louvain
Bureau c.316
Voie du Roman Pays, 20
B-1348 Louvain-la-Neuve
Belgium

tel: +32 10 47 30 50

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


Re: [R] nls with some coefficients fixed

2010-07-21 Thread Keith Jewell

Gabor Grothendieck ggrothendi...@gmail.com wrote in message 
news:aanlktilszaicycu3lz2f5d_bxq1g8m8f7jsjsbj2l...@mail.gmail.com...
 On Tue, Jul 20, 2010 at 9:58 AM,  nas...@uottawa.ca wrote:
 For nls, the fixing (or masking) of parameters is not, to my knowledge,
 possible.

 This is something I've been trying to get in such routines for over 2
 decades. Masks are
 available, but not yet well documented, in Rcgmin and Rvmmin packages.
 However, these use
 an optim() style approach, which is quite different from nls(). If 
 there's
 sufficient
 interest and some collaboration, I'd be willing to have a go at providing
 such
 functionality, but it would take quite a bit of work to provide the full
 capability of nls().


 You can optimize over b while fixing m like this:

 m - 1
 nls(demand ~ m + b * Time, BOD, start = c(b = 1))

Thanks Gabor,

I'd recognised that approach in my original post starting this thread (19 
July) where I'd used the example:
#
# fix parameter and use explicit start values works fine
nls(density ~ SSgompertz(log(conc), Asym, b2, b3=0.8), data = DNase.1, 
start=list(Asym=3, b2=2))
#---

I'm fitting many different models so I need a more generic approach.
I'd appreciate any comments on the suggestion in my 20 July post? (repeated 
here with some typo's corrected)
-
nls - function(formula, data=parent.frame(), start, ...){
  if (missing(start)) start - getInitial(formula, data)
  stats:::nls(formula, data, start=start[names(start) %in% 
all.vars(formula)], ...)
}
--

I see it breaks nls for non-selfStart functions; e.g. omitting the explicit 
start from your example
  nls(demand ~ m + b * Time, BOD)
works fine with vanilla nls (albeit with a warning)
#   No starting values specified for some parameters.
# Intializing 'b' to '1.'.
# Consider specifying 'start' or using a selfStart model
but my wrapper breaks it altogether.
 # Error in getInitial.default(func, data, mCall = as.list(match.call(func, 
:
 #  no 'getInitial' method found for function objects

I think that's OK in my application - I either use selfStart functions or 
explicit start lists - but I don't really want to remove existing 
functionality.

I guess I could (!?!) dive into nls and implement the same kind of approach 
internally, but that's very deep water for me :-{

Best regards,

Keith J

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


Re: [R] nls with some coefficients fixed

2010-07-21 Thread Keith Jewell

Gabor Grothendieck ggrothendi...@gmail.com wrote in message 
news:aanlktilszaicycu3lz2f5d_bxq1g8m8f7jsjsbj2l...@mail.gmail.com...
 On Tue, Jul 20, 2010 at 9:58 AM,  nas...@uottawa.ca wrote:
 For nls, the fixing (or masking) of parameters is not, to my knowledge,
 possible.

 This is something I've been trying to get in such routines for over 2
 decades. Masks are
 available, but not yet well documented, in Rcgmin and Rvmmin packages.
 However, these use
 an optim() style approach, which is quite different from nls(). If 
 there's
 sufficient
 interest and some collaboration, I'd be willing to have a go at providing
 such
 functionality, but it would take quite a bit of work to provide the full
 capability of nls().


 You can optimize over b while fixing m like this:

 m - 1
 nls(demand ~ m + b * Time, BOD, start = c(b = 1))

Thanks Gabor,

I'd recognised that approach in my original post starting this thread (19 
July) where I'd used the example:
#
# fix parameter and use explicit start values works fine
nls(density ~ SSgompertz(log(conc), Asym, b2, b3=0.8), data = DNase.1, 
start=list(Asym=3, b2=2))
#---

I'm fitting many different models so I need a more generic approach.
I'd appreciate any comments on the suggestion in my 20 July post? (repeated 
here with some typo's corrected)
-
nls - function(formula, data=parent.frame(), start, ...){
  if (missing(start)) start - getInitial(formula, data)
  stats:::nls(formula, data, start=start[names(start) %in% 
all.vars(formula)], ...)
}
--

I see it breaks nls for non-selfStart functions; e.g. omitting the explicit 
start from your example
  nls(demand ~ m + b * Time, BOD)
works fine with vanilla nls (albeit with a warning)
#   No starting values specified for some parameters.
# Intializing 'b' to '1.'.
# Consider specifying 'start' or using a selfStart model
but my wrapper breaks it altogether.
 # Error in getInitial.default(func, data, mCall = as.list(match.call(func, 
:
 #  no 'getInitial' method found for function objects

I think that's OK in my application - I either use selfStart functions or 
explicit start lists - but I don't really want to remove existing 
functionality.

I guess I could (!?!) dive into nls and implement the same kind of approach 
internally, but that's very deep water for me :-{

Best regards,

Keith J

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


Re: [R] nls with some coefficients fixed

2010-07-20 Thread Keith Jewell
nas...@uottawa.ca wrote in message 
news:33466.129.6.253.2.1279634282.squir...@webmail02.uottawa.ca...
 For nls, the fixing (or masking) of parameters is not, to my knowledge,
 possible.

 This is something I've been trying to get in such routines for over 2
 decades. Masks are
 available, but not yet well documented, in Rcgmin and Rvmmin packages.
 However, these use
 an optim() style approach, which is quite different from nls(). If there's
 sufficient
 interest and some collaboration, I'd be willing to have a go at providing
 such
 functionality, but it would take quite a bit of work to provide the full
 capability of nls().

 JN


Thanks for that. It would be burdensome to move away from nls, a lot of my 
functions depend on nls-like properties of fitted objects.

I'm considering 'fixing' nls by creating a 'wrapper' with the same name to:
a) if start is unspecified, call getInitial
b) call 'vanilla' nls with start restricted to 'non-fixed' terms,
something like...
-
nls - function(formula, data=parent.frame(), start, ...){
  if missing(start) start - getInitial(formula, data)
  stats:::nls(formula, data, start=start[names(start) %in% 
all.vars(formula)], ...]
}
--
The getInitial values will be calculated ignoring the fact that some 
parameters are 'fixed' (unless the particular 'initial' attribute is very 
clever!), but they shouldn't be too bad, and I don't really see a practical 
alternative way of getting the required starting values.

I think this will work, but I'm very doubtful if it will work reliably. 
Issues that concern me include:

a) How will 'data=parent.frame()' behave?
   I've had troubles before with scope and nls!

b) Will other callers of nls (e.g. nlme:::nlsList) call mine or the 
original?
   Search list is something like
   [1].GlobalEnv[n]mine   [n+l]package:nlme [n+l+m]package:stats

Any comments?

Thanks in advance,

Keith J

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

2010-07-19 Thread Keith Jewell
I'm using nls to fit a variety of different models. Here I use SSgompertz as 
an example.

I want the ability to fix one (or more) of the coefficients that would 
normally be optimised (e.g. fix b3=0.8).

Examples; based on and using data from example(SSgompertz)
#-
# vanilla call to nls, no coefficients fixed, works fine
nls(density ~ SSgompertz(log(conc), Asym, b2, b3), data = DNase.1)

#-
# naive attempt to fix one parameter. I don't believe the error message
nls(density ~ SSgompertz(log(conc), Asym, b2, b3=0.8), data = DNase.1)
# Error in nlsModel(formula, mf, start, wts) :
#  singular gradient matrix at initial parameter estimates

#
# fix parameter and use explicit start values works fine
nls(density ~ SSgompertz(log(conc), Asym, b2, b3=0.8), data = DNase.1, 
start=list(Asym=3, b2=2))

#
# getInitial returns third coeff, treating value as a name
getInitial(density ~ SSgompertz(log(conc), Asym=a, b2=b, b3=0.8), data = 
DNase.1)
a b   0.8
4.608 2.2713391 0.7164666


I guess the best approach in principle is to change the initial attribute so 
it only estimates and returns values of those coefficients for which 
is.name(mCall[coef]) == TRUE. BUT,that means handling all combinations of 
fixed coefficients so it's a bit of work even for one model. I'm working 
with a large number of models and really don't want to face all that work!

An alternative would be for nls to recognise fixed coefficients and omit 
their values from the start list; the other coefficients might not be 
optimal for the values of the fixed, but it does seem to work and wouldn't 
need all those SSxxx altering. BUT I don't want to get into nls internals.

Any suggestions?

Thanks in advance,

Keith J

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


Re: [R] Using if statement on function

2010-06-28 Thread Keith Jewell

You could also consider
isTRUE(all.equal(FUN, mean))

 isTRUE(all.equal(mean, mean))
[1] TRUE
 isTRUE(all.equal(mean, median))
[1] FALSE

HTH

Keith J
Patrick Burns pbu...@pburns.seanet.com wrote in message 
news:4c28777f.1040...@pburns.seanet.com...
 If I understand the problem properly,
 you want something like this:

 function(FUN, ...)
 {
 FunName - deparse(substitute(FUN))
 if(FunName == mean) {
 ...
 } else if(FunName == median) {
 ...
 }
 }

 Using 'switch' is an alternative to 'if'.


 On 28/06/2010 10:50, Etienne Stockhausen wrote:
 Hello everybody,

 I'm trying to use a if-statment on a function. For a better
 understanding I want to present a small example:

 FUN=mean # could also be median,sd or any other function
 if (FUN == mean)
 plot(...)
 if (FUN == median)
 plot(...) ...

 This doesn't work, because FUN is a function. I've already tried to
 coerce the type of FUN with as.character( ), but that's also not
 possible. I'm stuck with this task and it is absolutely necessary to
 give FUN the class of a function.
 I'm looking forward for any hints, clues or solutions for my problem.

 So much thanks in advance

 Etienne

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


 -- 
 Patrick Burns
 pbu...@pburns.seanet.com
 http://www.burns-stat.com
 (home of 'Some hints for the R beginner'
 and 'The R Inferno')


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

2010-06-10 Thread Keith Jewell
In MS Windows I
  a) invoke Rterm from a batch file (test.bat)
  b) to execute commands from a script (m:\test.rsc)
  c) capturing output in a log file (m:\test.log)
BUT if the script results in an error the error message is NOT written to 
the log file, leaving me problems when the error is from a complicated 
function.

Simplified example:.

test.bat 
REM ensure 'R' is in path
path \\Server02\stats\R\R-Current\bin\;%PATH%
Rterm  --no-init-file --no-restore-data --no-save --silent  m:\test.rsc  
m:\test.log
-

m:\test.rsc -
print(this is a test)
#generate an error
nls()
--

The error message:
  Error in .Internal(inherits(x, what, which)) : 'x' is missing
is is NOT written to the log file, which just ends

m:\test.log --
  snip
 print(this is a test)
[1] this is a test
 #generate an error
 nls()
-

I surmise this is due to output buffering (?). In an S-Plus version I turned 
off buffering with
  guiSetOption(option.name=BufferOutputWindows, value.string=F)
but I don't think this is available in R (?).

Has anyone any suggestions?

Thanks in advance,

Keith Jewell
--please do not edit the information below--

R Version:
 platform = i386-pc-mingw32
 arch = i386
 os = mingw32
 system = i386, mingw32
 status =
 major = 2
 minor = 11.0
 year = 2010
 month = 04
 day = 22
 svn rev = 51801
 language = R
 version.string = R version 2.11.0 (2010-04-22)

Windows Server 2003 x64 (build 3790) Service Pack 2

Locale:
LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United 
Kingdom.1252;LC_MONETARY=English_United 
Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252

Search Path:
 .GlobalEnv, package:datasets, CBRIForecast, package:RODBC, package:tree, 
package:locfit, package:lattice, package:akima, package:nlme, package:MASS, 
package:grDevices, package:geometry, KJRutils, package:xlsReadWrite, 
package:svSocket, package:TinnR, package:R2HTML, package:Hmisc, 
package:survival, package:splines, package:graphics, package:stats, 
CBRIutils, package:utils, package:tcltk, package:tools, package:methods, 
TempEnv, Autoloads, package:base

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


Re: [R] Capturing errors [not buffered output] from Rterm

2010-06-10 Thread Keith Jewell
Thanks to both Prof. Ripley and Duncan Murdoch for correctly diagnosing my 
problem as failure to redirect stderr (nothing to do with buffering).

Both pointed me to R CMD BATCH which would have done the job, if I hadn't 
wanted to run interactively - in my real task (not the example below) I had 
Rterm --ess. I guess I could use R CMD BATCH  --ess but instead I'm using 
the suggestion in rw-FAQ Q2.12 of simply adding 21 to redirect stderr to 
stdout.

Rtermm:\test.rsc  m:\test.log 21

Problem solved. The answer was in rw-FAQ , mea culpa for not spotting it 
myself, thanks for treating me kindly!

Prof Brian Ripley rip...@stats.ox.ac.uk wrote in message 
news:alpine.lfd.2.00.1006101333520.25...@gannet.stats.ox.ac.uk...
 On Thu, 10 Jun 2010, Keith Jewell wrote:

 In MS Windows I
  a) invoke Rterm from a batch file (test.bat)
  b) to execute commands from a script (m:\test.rsc)
  c) capturing output in a log file (m:\test.log)

 BUT if the script results in an error the error message is NOT written to
 the log file, leaving me problems when the error is from a complicated
 function.

 Sure, warning and errors are written to stderr, which you did not 
 redirect.  This is covered in rw-FAQ Q2.12.  Using R CMD BATCH would have 
 done this for you 

 This is not to do with 'buffered output': in any case R uses minimal 
 buffering so stdout and stderr can be mixed nicely on a single log file.

 Simplified example:.

 test.bat 
 REM ensure 'R' is in path
 path \\Server02\stats\R\R-Current\bin\;%PATH%
 Rterm  --no-init-file --no-restore-data --no-save --silent  m:\test.rsc 
  
 m:\test.log
 -

 m:\test.rsc -
 print(this is a test)
 #generate an error
 nls()
 --

 The error message:
  Error in .Internal(inherits(x, what, which)) : 'x' is missing
 is is NOT written to the log file, which just ends

 m:\test.log --
  snip
 print(this is a test)
 [1] this is a test
 #generate an error
 nls()
 -

 I surmise this is due to output buffering (?). In an S-Plus version I 
 turned
 off buffering with
  guiSetOption(option.name=BufferOutputWindows, value.string=F)
 but I don't think this is available in R (?).

 Has anyone any suggestions?

 Thanks in advance,

 Keith Jewell
 --please do not edit the information below--

 R Version:
 platform = i386-pc-mingw32
 arch = i386
 os = mingw32
 system = i386, mingw32
 status =
 major = 2
 minor = 11.0
 year = 2010
 month = 04
 day = 22
 svn rev = 51801
 language = R
 version.string = R version 2.11.0 (2010-04-22)

 Windows Server 2003 x64 (build 3790) Service Pack 2

 Locale:
 LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United
 Kingdom.1252;LC_MONETARY=English_United
 Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252

 Search Path:
 .GlobalEnv, package:datasets, CBRIForecast, package:RODBC, package:tree,
 package:locfit, package:lattice, package:akima, package:nlme, 
 package:MASS,
 package:grDevices, package:geometry, KJRutils, package:xlsReadWrite,
 package:svSocket, package:TinnR, package:R2HTML, package:Hmisc,
 package:survival, package:splines, package:graphics, package:stats,
 CBRIutils, package:utils, package:tcltk, package:tools, package:methods,
 TempEnv, Autoloads, package:base

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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,  rip...@stats.ox.ac.uk
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595


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


Re: [R] how to update R files included assource ?

2010-03-29 Thread Keith Jewell
Hi,

I'm afraid I really don't have time to enter into a dialogue :-{ but this 
fragment from a function of mine might help...
--
  outfile - sub(Rd$, html, hfile, ignore.case=TRUE)  # name of 
corresponding html
  out.mod - file.info(outfile)[,mtime]  # if html absent or needs 
updating
  if (is.na(out.mod)||file.info(hfile)[,mtime]  out.mod) 
tools::Rd2HTML(hfile, outfile, .Package) # do it
---
The third line (inter alia) checks the modification time of the 'target' 
file and decides whether to process it.

Hope that helps,

Keith J
---
arnaud chozo arnaud.ch...@gmail.com wrote in message 
news:caebefd51003290824m67bebf96wd61315359ae97...@mail.gmail.com...
 Hi all,

 I have a main file main.R in which I include some other R files. For
 example, in main.R I have: source(functions.R).
 When I modify the file functions.R, I'd like R to take into account the
 changes and to reload the file functions.R when I run main.R
 Is it possible?

 Thanks,
 Arnaud

 [[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] Error Running TinnR with R

2010-03-12 Thread Keith Jewell
Many people seem to have trouble defining '.trPaths' which is the set of 
file names which TinnR uses to communicate with R; the user must be able to 
create/write/read these files/folders.

In my Rprofile.site I have the single assingment:
.trPaths - paste(paste(Sys.getenv(APPDATA), \\Tinn-R\\tmp\\, sep=),
 c(, search.txt, objects.txt, file.r, selection.r, block.r, 
lines.r), sep=)

At Rstartup this defines a user-specific vector based on the current value 
of the Windows environment variable APPDATA. In my particular case, on this 
particular machine, at the moment, it results in this vector:
 .trPaths
[1] C:\\Documents and Settings\\jewell\\Application Data\\Tinn-R\\tmp\\
[2] C:\\Documents and Settings\\jewell\\Application 
Data\\Tinn-R\\tmp\\search.txt
[3] C:\\Documents and Settings\\jewell\\Application 
Data\\Tinn-R\\tmp\\objects.txt
[4] C:\\Documents and Settings\\jewell\\Application 
Data\\Tinn-R\\tmp\\file.r
[5] C:\\Documents and Settings\\jewell\\Application 
Data\\Tinn-R\\tmp\\selection.r
[6] C:\\Documents and Settings\\jewell\\Application 
Data\\Tinn-R\\tmp\\block.r
[7] C:\\Documents and Settings\\jewell\\Application 
Data\\Tinn-R\\tmp\\lines.r

I'm on Windows Server 2003 R2; I don't know if the same construction will 
work on Vista, but I think it probably would, I suggest trying it!

If that doesn't work, I have a few comments on your code which might be 
helpful:
a) you have .trPath - , not .trPaths -

b) you are defining a list, not a vector, so .trPath[5] (for example) will 
return a single entry list, not a single character value. That doesn't work 
for me!
 as.list(.trPaths)[5]
[[1]]
[1] C:\\Documents and Settings\\jewell\\Application 
Data\\Tinn-R\\tmp\\selection.r
 source(as.list(.trPaths)[5])
Error in source(as.list(.trPaths)[5]) : invalid connection

c) you are hard-coding the file paths, so if they change your TinnR will 
break.

d) I don't think the elements need to be named, but it probably does no 
harm.

If you want to hard-code your file paths, and want the elements named, I 
suggest this might work:
.trPaths - c('C:/Users/dennis/AppData/Roaming/Tinn-R/tmp/',
  'C:/Users/dennis/AppData/Roaming/Tinn-R/tmp/search.txt',
  'C:/Users/dennis/AppData/Roaming/Tinn-R/tmp/objects.txt',
  'C:/Users/dennis/AppData/Roaming/Tinn-R/tmp/file.r',
  'C:/Users/dennis/AppData/Roaming/Tinn-R/tmp/selection.r',
  'C:/Users/dennis/AppData/Roaming/Tinn-R/tmp/block.r',
  'C:/Users/dennis/AppData/Roaming/Tinn-R/tmp/lines.r'
)
 names(.trPaths) - c(Tmp, Search, Objects, File, Selection, 
Block,Lines)

Hope that helps,

Keith J

teck-corp d.tu...@maastrichtuniversity.nl wrote in message 
news:1268404061254-1590576.p...@n4.nabble.com...

 Hi Stephen,

 Thanks a lot for your answer. Unfortunately this does not work for me
 neither.
 Could you maybe let me know what is written in you RprofileSite-file now?

 Best
 Dennis

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


Re: [R] locfit: max number of predictors = 6? How interpolate in 5-10D?

2010-02-26 Thread Keith Jewell
Thanks for that suggestion

I've investigated a little more using...
y - rowSums(x) + runif(n)
... just so I had some correlation to play with.

The error I get when it fails is Invalid what in exvval, which I don't 
understand either!
With n=5e3 it worked with 6 variables but not with 7.

I wasn't sure the error was caused by number of variables rather than 
something else, so I tried with...
n - 100

I also tried locfit rather than locfit.raw using...
xd - lapply(1:10, function(x) runif(n))
xd - as.data.frame(xd)
names(xd) - paste(x, 1:10, sep=)
y=rowSums(xd)
xd$y - y
aF - formula(paste(y ~ lp(,paste(names(xd)[1:6], collapse=,), )))
locfit(aF, xd)

Both of these gave the same results, success with 6 variables but not with 
7.

IT APPEARS, the maximum number of predictors is 6, but I don't know locfit 
well, and it may be that other settings would allow more variables.
CAN anyone give a more DEFINITIVE ANSWER?

My current data sets currently reach 5 predictors, and I expect this it 
increase.
 In S-Plus (v6.2.1) I used loess in which Locally quadratic models may have 
at most 4 predictor variables; locally linear models may have at most 15. 
In R stats::loess allows only one to four numeric predictors.
I'd assumed (foolishly) that because locfit didn't mention limits, the only 
limits were practical (memory, time,...) - it seems not :-(
I guess I could write something myself, I only need rough interpolation, 
even straight line interpolation between nearest neighbours would be OK. 
But at first glance it seems non-trivial with a substantial non-fixed number 
of dimensions (nnclust::nnfind to identify neighbours??), and I don't want 
to re-invent wheels.
Can anyone suggest an ALTERNATIVE route for INTERPOLATION in 5-10 
DIMENSIONS?

Best...
(apologies for capitals, not shouting, just highlighting key points for 
those skimming quickly)

Keith Jewell

Liaw, Andy andy_l...@merck.com wrote in message 
news:b10baa7d28d88b45af82813c4a6ffa934ce...@usctmx1157.merck.com...
 Well, I should think there's an obvious (if not elegant) way to test it:

 n - 5e3
 m - 20
 x - matrix(runif(n * m), nrow=n)
 y - rnorm(n)

 require(locfit)
 fit - locfit.raw(x[, 1:10], y)

 The code above took a while on my laptop, and ended up giving some error
 I don't understand.  Not sure if the error was caused by insufficient
 sample size, or some inherent limitation.  At least it didn't choke on
 five variables.  However, if all 20 columns of x is used, locfit.raw()
 will choke because it can't compute the dimension of some variable that
 it needs to allocate memory for.

 I had vague recollection of reading that 5 is the limit somewhere.
 Unfortunately my copy of Local Regression and Likelihood has been MIA
 for a few years, so I can't check there.  In any case it doesn't seem
 like the number of data points and/or computing power are bigger issue.

 Andy

 -Original Message-
 From: r-help-boun...@r-project.org
 [mailto:r-help-boun...@r-project.org] On Behalf Of Keith Jewell
 Sent: Thursday, February 25, 2010 4:11 AM
 To: r-h...@stat.math.ethz.ch
 Subject: [R] locfit: max number of predictors?

 Hi All,

 In another thread Andy Liaw, who CRAN lists as locfit
 maintainer; said:
 quote
 From: Liaw, Andy andy_l...@merck.com
 To: Guy Green guygr...@netvigator.com; r-help@r-project.org
 Subject: Re: Alternatives to linear regression with multiple variables
 Date: 22 February 2010 17:50

 You can try the locfit package, which I believe can handle up to 5
 variables.  E.g.,
 /quote

 Looking in the locfit documentation (e.g.
 http://www.stats.bris.ac.uk/R/web/packages/locfit/locfit.pdf)
 I can't see an
 upper limit on the number of predictors; if it is 5 I'm
 getting close in one
 of my applications.

 Can anyone confirm or deny the existence of a 'crisp' upper
 limit on the
 number of predictors in locfit?

 If it is 5, or thereabouts, can anyone suggest an alternative
 which can
 handle a few more? (I'm using it for multidimensional interpolation).

 Best regards,

 Keith Jewell

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

 Notice:  This e-mail message, together with any attachme...{{dropped:10}}


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


[R] update.packages with UNC library path

2010-02-26 Thread Keith Jewell
Hi all,

I hit a small snag. Here is my workaround (copied verbatim from my aide 
memoire) in case it helps others. (or anyone knows a better way... ;-)

Best regards,

Keith Jewell.

The site library file is defined (in Renviron.site 
R_LIBS_SITE=//Server02/stats/R/library/%v) via a UNC name something like 
//Server02/stats/R/library/2.10.

As of now [Feb 2010, R version 2.10.1 (2009-12-14)] the menu Packages|Update 
Packages... [=update.packages(ask='graphics')] fails at the last step when 
it can't copy files to a directory named like that. It works if the site 
library is defined via a mapped drive like L:\\R\\library\\2.10, but we 
don't want to require all users to have this drive mapped. The workaround is 
thus:

In order to update packages:

a) have an appropriate mapped drive (e.g. Stats on 'server02')

b) start R-Gui from that mapped drive. This will give the site library via 
the UNC and the base library via the mapped drive thus:
 .libPaths()
[1] //Server02/stats/R/library/2.10 L:/R/R-Current/library

c) use .LibPaths(new= ) to add the drive mapped path to the beginning of the 
list
 .libPaths(new=choose.dir()) # navigate to folder on mapped drive
 .libPaths()
[1] L:\\R\\library\\2.10//Server02/stats/R/library/2.10 
L:/R/R-Current/library

update.packages(ask='graphics') will now work

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

2010-02-25 Thread Keith Jewell
Hi All,

In another thread Andy Liaw, who CRAN lists as locfit maintainer; said:
quote
From: Liaw, Andy andy_l...@merck.com
To: Guy Green guygr...@netvigator.com; r-help@r-project.org
Subject: Re: Alternatives to linear regression with multiple variables
Date: 22 February 2010 17:50

You can try the locfit package, which I believe can handle up to 5
variables.  E.g.,
/quote

Looking in the locfit documentation (e.g. 
http://www.stats.bris.ac.uk/R/web/packages/locfit/locfit.pdf) I can't see an 
upper limit on the number of predictors; if it is 5 I'm getting close in one 
of my applications.

Can anyone confirm or deny the existence of a 'crisp' upper limit on the 
number of predictors in locfit?

If it is 5, or thereabouts, can anyone suggest an alternative which can 
handle a few more? (I'm using it for multidimensional interpolation).

Best regards,

Keith Jewell

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] update.packages on MS Windows with //server/share paths

2010-01-26 Thread Keith Jewell
Hi,

 update.packages(ask='graphics')

  gives me  multiple warning (one per updated package?) similar to ...

Warning: unable to move temporary installation 
'\\Server02\stats\R\library\2.10\file3de56e0d\locfit' to 
'\\Server02\stats\R\library\2.10\locfit'

The final, updated, folders do not end up where they should be. I can move 
them 'by hand', but it is an inconvenience.

Checking the archives I find 
http://finzi.psych.upenn.edu/Rhelp08/2008-April/160963.html where Prof 
Ripley opines The issue appears to be that your OS is garbling file names, 
and it surely does seem to be a filename problem - in combination R and 
Windows don't seem to be handling the '//server/share' path construction. I 
have:
 .libPaths()
[1] //Server02/stats/R/library/2.10 
//Server02/stats/R/R-Current/library

I can work around by mapping a drive letter to the '//server/share', but 
prefer not to (for local reasons).

In CHANGES.R-2.10.1pat I find
  CHANGES IN R VERSION 2.7.2 patched
o dir.create(recursive = TRUE) was not working on //server/share  paths.

In CHANGES.R-2.11.0dev I find
  CHANGES IN R VERSION 2.11.0
NEW FEATURES
o file.rename() can work across volumes (by copy-and-delete)

In another R function I've hit a similar problem and solved it using the 
construction:
  file.path(dirname(x), basename(x))
to convert  '//server/share' to (printed as) 'server/share' which worked 
in that function. In this case:
 file.path(dirname(.libPaths()), basename(.libPaths()))
[1] Server02/stats/R/library/2.10 
Server02/stats/R/R-Current/library
which looks OK but
 .libPaths(file.path(dirname(.libPaths()), basename(.libPaths(
 .libPaths()
[1] //Server02/stats/R/library/2.10 
//Server02/stats/R/R-Current/library
doesn't actually change the internal paths.

I don't see the problem in V2.9.2 .
I do see the problem in
   V2.10.1,
   V2.10.1 Patched (2010-01-24 r51030)
   V2.11.0 Under development (unstable) (2010-01-24 r51030)

Grateful for any suggestions,

Keith Jewell
-
Version:
 platform = i386-pc-mingw32
 arch = i386
 os = mingw32
 system = i386, mingw32
 status = Patched
 major = 2
 minor = 10.1
 year = 2010
 month = 01
 day = 24
 svn rev = 51030
 language = R
 version.string = R version 2.10.1 Patched (2010-01-24 r51030)

Windows Server 2003 x64 (build 3790) Service Pack 2

Locale:
LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United 
Kingdom.1252;LC_MONETARY=English_United 
Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252

Search Path:
 .GlobalEnv, package:stats, package:graphics, package:grDevices, 
package:utils, package:datasets, package:methods, Autoloads, package:base

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


Re: [R] update.packages on MS Windows with //server/share paths

2010-01-26 Thread Keith Jewell
Thanks Gabor, but expanding on my remark...

 I can work around by mapping a drive letter to the '//server/share', but
 prefer not to (for local reasons).

R is installed on our network, used by others (with readonly access), 
maintained by me.
In 'Renviron.site' I have...
   R_LIBS_SITE=//Server02/stats/R/library/%v
...which works for everyone else (and for me as long as I don't try 
update.packages).

I (but not everyone else!) routinely have a drive (L:) mapped to 
//Server02/stats so that I can (and currently do) update.packages by
a) altering 'Renviron.site' to R_LIBS_SITE=L://R/library/%v
b) starting Rgui.exe from (e.g.)  L:\R\R-2.10.1\bin
BUT while 'Renviron.site' is altered, users who don't have the drive mapping 
don't get the site library, so I have to be quick and risk a couple of 
complaints.

I've tried putting a '.Renviron' file in my personal home directory 
containing R_LIBS_SITE=L://R/library/%v hoping I could implement a 
'personal' site library, but it doesn't seem to have any effect (not 
unreasonably?). As I outlined, my attempts to alter .libPaths() or 
.Library.site within my R session haven't worked.

Anyway, (although I say this with trepidation) this does look to me like a 
minor bug. It seems to me that (for example)...
 shell.exec(.libPaths()[1])
  and
 shell.exec(file.path(dirname(.libPaths()[1]), basename(.libPaths()[1])))
...should give the same result, especially when (as in this case) the syntax 
of the file spec...
 .libPaths()[1]
[1] //Server02/stats/R/library/2.10
... is controlled by R (in this example the former fails with ...not 
found, the latter opens the folder in Windows Explorer).

Best regards,

Keith Jewell
-
Gabor Grothendieck ggrothendi...@gmail.com wrote in message 
news:971536df1001260714i430b9ddcm37ffa12642321...@mail.gmail.com...

Try mapping a drive letter to \\Server02 and then use that.  For more,
google for: map network drive

On Tue, Jan 26, 2010 at 10:01 AM, Keith Jewell k.jew...@campden.co.uk 
wrote:
 Hi,

 update.packages(ask='graphics')

 gives me multiple warning (one per updated package?) similar to ...

 Warning: unable to move temporary installation
 '\\Server02\stats\R\library\2.10\file3de56e0d\locfit' to
 '\\Server02\stats\R\library\2.10\locfit'

 The final, updated, folders do not end up where they should be. I can move
 them 'by hand', but it is an inconvenience.

 Checking the archives I find
 http://finzi.psych.upenn.edu/Rhelp08/2008-April/160963.html where Prof
 Ripley opines The issue appears to be that your OS is garbling file 
 names,
 and it surely does seem to be a filename problem - in combination R and
 Windows don't seem to be handling the '//server/share' path construction. 
 I
 have:
 .libPaths()
 [1] //Server02/stats/R/library/2.10
 //Server02/stats/R/R-Current/library

 I can work around by mapping a drive letter to the '//server/share', but
 prefer not to (for local reasons).

 In CHANGES.R-2.10.1pat I find
 CHANGES IN R VERSION 2.7.2 patched
 o dir.create(recursive = TRUE) was not working on //server/share paths.

 In CHANGES.R-2.11.0dev I find
 CHANGES IN R VERSION 2.11.0
 NEW FEATURES
 o file.rename() can work across volumes (by copy-and-delete)

 In another R function I've hit a similar problem and solved it using the
 construction:
 file.path(dirname(x), basename(x))
 to convert '//server/share' to (printed as) 'server/share' which 
 worked
 in that function. In this case:
 file.path(dirname(.libPaths()), basename(.libPaths()))
 [1] Server02/stats/R/library/2.10
 Server02/stats/R/R-Current/library
 which looks OK but
 .libPaths(file.path(dirname(.libPaths()), basename(.libPaths(
 .libPaths()
 [1] //Server02/stats/R/library/2.10
 //Server02/stats/R/R-Current/library
 doesn't actually change the internal paths.

 I don't see the problem in V2.9.2 .
 I do see the problem in
 V2.10.1,
 V2.10.1 Patched (2010-01-24 r51030)
 V2.11.0 Under development (unstable) (2010-01-24 r51030)

 Grateful for any suggestions,

 Keith Jewell
 -
 Version:
 platform = i386-pc-mingw32
 arch = i386
 os = mingw32
 system = i386, mingw32
 status = Patched
 major = 2
 minor = 10.1
 year = 2010
 month = 01
 day = 24
 svn rev = 51030
 language = R
 version.string = R version 2.10.1 Patched (2010-01-24 r51030)

 Windows Server 2003 x64 (build 3790) Service Pack 2

 Locale:
 LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United
 Kingdom.1252;LC_MONETARY=English_United
 Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252

 Search Path:
 .GlobalEnv, package:stats, package:graphics, package:grDevices,
 package:utils, package:datasets, package:methods, Autoloads, package:base

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

Re: [R] find the corresponding mean y

2010-01-12 Thread Keith Jewell
Not very clear what you want, but perhaps...
?sortedXyData
...might help.

hth

KJ
luciferyan anniehyh...@googlemail.com wrote in message 
news:1263231740556-1011427.p...@n4.nabble.com...

 Hello, I have 49 paired data, x, y.
 I have sampled x (where replacement is true), and find its mean.
 How can I find the corresponding mean y, which is the paired data of above
 sample x?
 Thank you very much,
 Annie
 -- 
 View this message in context: 
 http://n4.nabble.com/find-the-corresponding-mean-y-tp1011427p1011427.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 expand.grid

2009-12-22 Thread Keith Jewell
Hi All,

This example code

dDF - structure(list(y = c(4.75587, 4.8451, 5.04139, 4.85733, 5.20412,
 5.92428, 5.69897, 4.78958, 4, 4), t = c(0, 48, 144, 192, 240,
 312, 360, 0, 48, 144), Batch = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1
 ), T = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2), pH = c(4.6, 4.6, 4.6,
 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6), S = c(0, 0, 0, 0, 0, 0, 0,
 0, 0, 0), N = c(0, 0, 0, 0, 0, 0, 0, 80, 80, 80)), .Names = c(y,
 t, Batch, T, pH, S, N), row.names = c(NA, 10L), class = 
data.frame)
str(dDF)
expand.grid(dDF)

'hangs' for a while and then gives an error

Error in `[[-.data.frame`(`*tmp*`, i, value = c(4.75587, 4.8451, 5.04139, 
:
  replacement has 1000 rows, data has 10

In NEWS.R-2.11.0dev I read:
o   The new (in 2.9.0) 'stringsAsFactors' argument to expand.grid()
was not working: it now does work but has default TRUE for
backwards compatibility.

but I don't think that's relevant, I have no factors.

I'm probably being silly. Can anyone point out where?

Best...

Keith Jewell

--please do not edit the information below--

Version:
 platform = i386-pc-mingw32
 arch = i386
 os = mingw32
 system = i386, mingw32
 status = Patched
 major = 2
 minor = 10.1
 year = 2009
 month = 12
 day = 21
 svn rev = 50796
 language = R
 version.string = R version 2.10.1 Patched (2009-12-21 r50796)

Windows Server 2003 x64 (build 3790) Service Pack 2

Locale:
LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United 
Kingdom.1252;LC_MONETARY=English_United 
Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252

Search Path:
 .GlobalEnv, package:stats, package:graphics, package:grDevices, 
package:utils, package:datasets, package:methods, Autoloads, package:base

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

2009-12-22 Thread Keith Jewell
Just confirming it isn't the bug fixed in 2.11.0dev, and giving an even 
simpler example:

R version 2.11.0 Under development (unstable) (2009-12-20 r50794)

 expand.grid(data.frame(y=1:10, t=1:10))
Error in `[[-.data.frame`(`*tmp*`, i, value = c(1L, 2L, 3L, 4L, 5L, 6L,  :
  replacement has 100 rows, data has 10

Keith Jewell k.jew...@campden.co.uk wrote in message 
news:hgqqja$rk...@ger.gmane.org...
 Hi All,

 This example code
 
 dDF - structure(list(y = c(4.75587, 4.8451, 5.04139, 4.85733, 5.20412,
 5.92428, 5.69897, 4.78958, 4, 4), t = c(0, 48, 144, 192, 240,
 312, 360, 0, 48, 144), Batch = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1
 ), T = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2), pH = c(4.6, 4.6, 4.6,
 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6), S = c(0, 0, 0, 0, 0, 0, 0,
 0, 0, 0), N = c(0, 0, 0, 0, 0, 0, 0, 80, 80, 80)), .Names = c(y,
 t, Batch, T, pH, S, N), row.names = c(NA, 10L), class = 
 data.frame)
 str(dDF)
 expand.grid(dDF)
 
 'hangs' for a while and then gives an error

 Error in `[[-.data.frame`(`*tmp*`, i, value = c(4.75587, 4.8451, 5.04139, 
 :
  replacement has 1000 rows, data has 10

 In NEWS.R-2.11.0dev I read:
o The new (in 2.9.0) 'stringsAsFactors' argument to expand.grid()
 was not working: it now does work but has default TRUE for
 backwards compatibility.

 but I don't think that's relevant, I have no factors.

 I'm probably being silly. Can anyone point out where?

 Best...

 Keith Jewell

 --please do not edit the information below--

 Version:
 platform = i386-pc-mingw32
 arch = i386
 os = mingw32
 system = i386, mingw32
 status = Patched
 major = 2
 minor = 10.1
 year = 2009
 month = 12
 day = 21
 svn rev = 50796
 language = R
 version.string = R version 2.10.1 Patched (2009-12-21 r50796)

 Windows Server 2003 x64 (build 3790) Service Pack 2

 Locale:
 LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United 
 Kingdom.1252;LC_MONETARY=English_United 
 Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252

 Search Path:
 .GlobalEnv, package:stats, package:graphics, package:grDevices, 
 package:utils, package:datasets, package:methods, Autoloads, package:base


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

2009-12-22 Thread Keith Jewell
bangs head on desk

Thanks, Prof Ripley (and everyone else who's responding while I type this!).

I thought I was being stupid. What I wanted was:
  expand.grid(lapply(dDF, unique))
which works fine!

hangs head in shame

Seasonal greetings to all,

Keith Jewell

Prof Brian Ripley rip...@stats.ox.ac.uk wrote in message 
news:alpine.lfd.2.00.0912221619440.20...@gannet.stats.ox.ac.uk...
 1) Look at the help: a data frame may be a list, but do pass a list such 
 as unclass(dDF) when it says 'list'.

 2) You have 7 columns of 10 items, which gives 10 million rows.  Is that 
 really what you want (especially as some of the columns are constant)? 
 It's an object of ca 500MB.

 On Tue, 22 Dec 2009, Keith Jewell wrote:

 Hi All,

 This example code
 
 dDF - structure(list(y = c(4.75587, 4.8451, 5.04139, 4.85733, 5.20412,
 5.92428, 5.69897, 4.78958, 4, 4), t = c(0, 48, 144, 192, 240,
 312, 360, 0, 48, 144), Batch = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1
 ), T = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2), pH = c(4.6, 4.6, 4.6,
 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6), S = c(0, 0, 0, 0, 0, 0, 0,
 0, 0, 0), N = c(0, 0, 0, 0, 0, 0, 0, 80, 80, 80)), .Names = c(y,
 t, Batch, T, pH, S, N), row.names = c(NA, 10L), class =
 data.frame)
 str(dDF)
 expand.grid(dDF)
 
 'hangs' for a while and then gives an error

 Error in `[[-.data.frame`(`*tmp*`, i, value = c(4.75587, 4.8451, 
 5.04139,
 :
  replacement has 1000 rows, data has 10

 In NEWS.R-2.11.0dev I read:
o The new (in 2.9.0) 'stringsAsFactors' argument to expand.grid()
 was not working: it now does work but has default TRUE for
 backwards compatibility.

 but I don't think that's relevant, I have no factors.

 I'm probably being silly. Can anyone point out where?

 Best...

 Keith Jewell

 --please do not edit the information below--

 Version:
 platform = i386-pc-mingw32
 arch = i386
 os = mingw32
 system = i386, mingw32
 status = Patched
 major = 2
 minor = 10.1
 year = 2009
 month = 12
 day = 21
 svn rev = 50796
 language = R
 version.string = R version 2.10.1 Patched (2009-12-21 r50796)

 Windows Server 2003 x64 (build 3790) Service Pack 2

 Locale:
 LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United
 Kingdom.1252;LC_MONETARY=English_United
 Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252

 Search Path:
 .GlobalEnv, package:stats, package:graphics, package:grDevices,
 package:utils, package:datasets, package:methods, Autoloads, package:base

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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,  rip...@stats.ox.ac.uk
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595


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


Re: [R] mutlidimensional in.convex.hull (wasmultidimensionalpoint.in.polygon??)

2009-12-18 Thread Keith Jewell
Hi All,

I couldn't resist doing this the right way!
A colleague explained the vector algebra to me (thanks Martin!) and I've 
followed the structure of the Matlab code referenced below, but all errors 
are mine!

I don't pretend to great R expertise, so this code may not be optimal (in 
time or the memory issue addressed by the Matlab code), but it is a lot 
faster than the other algorithm discussed in this thread. These timings are 
on the real example data described in my previous message in this thread.

 system.time(inhull(xs,ps))  # the right way
   user  system elapsed
   1.340.071.41
 system.time({phull -  convhulln(ps) # the other algorithm
+ phull2 - convhulln(rbind(ps,xs))
+ nrp - nrow(ps)
+ nrx - nrow(xs)
+ outside - unique(phull2[phull2nrp])-nrp
+ done - FALSE
+ while(!done){
+ phull3 - convhulln(rbind(ps,xs[-(outside),]))
+ also.outside - (1:nrx)[-outside][unique(phull3[phull3nrp])-nrp]
+ outside - c(outside,also.outside)
+ done - length(also.outside)==0
+ }})
   user  system elapsed
  15.090.09   15.22

Although I really must move on now, if anyone has comments, criticisms, 
suggestions for improvement I would be interested.

Enjoy!

Keith Jewell

inhull - function(testpts, calpts, hull=convhulln(calpts), 
tol=mean(mean(abs(calpts)))*sqrt(.Machine$double.eps)) {
#
# R implementation of the Matlab code by John D'Errico 04 Mar 2006 (Updated 
30 Oct 2006)
# downloaded from 
http://www.mathworks.com/matlabcentral/fileexchange/10226-inhull
# with some modifications and simplifications
#
# Efficient test for points inside a convex hull in n dimensions
#
#% arguments: (input)
#%  testpts - nxp array to test, n data points, in p dimensions
#%   If you have many points to test, it is most efficient to
#%   call this function once with the entire set.
#%
#%  calpts - mxp array of vertices of the convex hull, as used by
#%   convhulln.
#%
#%  hull - (OPTIONAL) tessellation (or triangulation) generated by convhulln
#%   If hull is left empty or not supplied, then it will be
#%   generated.
#%
#%  tol - (OPTIONAL) tolerance on the tests for inclusion in the
#%   convex hull. You can think of tol as the distance a point
#%   may possibly lie outside the hull, and still be perceived
#%   as on the surface of the hull. Because of numerical slop
#%   nothing can ever be done exactly here. I might guess a
#%   semi-intelligent value of tol to be
#%
#% tol = 1.e-13*mean(abs(calpts(:)))
#%
#%   In higher dimensions, the numerical issues of floating
#%   point arithmetic will probably suggest a larger value
#%   of tol.
#%
# In this R implementation default 
tol=mean(mean(abs(calpts)))*sqrt(.Machine$double.eps)
#   DEFAULT: tol = 1e-6
#
# VALUE: Matlab returns a vector of TRUE (inside/on) or FALSE (outside)
#   This R implementation returns an integer vector of length n
#   1 = inside hull
#  -1 = inside hull
#   0 = on hull (to precision indicated by tol)
#
   require(geometry, quietly=TRUE)  # for  convhulln
   require(MASS, quietly=TRUE)  # for Null
# ensure arguments are matrices (not data frames) and get sizes
   calpts - as.matrix(calpts)
   testpts - as.matrix(testpts)
   p - dim(calpts)[2]   # columns in calpts
   cx - dim(testpts)[1]  # rows in testpts
   nt - dim(hull)[1]# number of simplexes in hull
# find normal vectors to each simplex
   nrmls - matrix(NA, nt, p) # predefine each nrml as NA, 
degenerate
   degenflag - matrix(TRUE, nt, 1)
   for (i in  1:nt) {
nullsp - t(Null(t(calpts[hull[i,-1],] - 
matrix(calpts[hull[i,1],],p-1,p, byrow=TRUE
if (dim(nullsp)[1] == 1) { nrmls[i,] - nullsp
   degenflag[i] - FALSE}}
# Warn of degenerate faces, and remove corresponding normals
   if(length(degenflag[degenflag])  0) 
warning(length(degenflag[degenflag]), degenerate faces in convex hull)
   nrmls - nrmls[!degenflag,]
   nt - dim(nrmls)[1]
# find center point in hull, and any (1st) point in the plane of each 
simplex
   center = apply(calpts, 2, mean)
   a - calpts[hull[!degenflag,1],]
# scale normal vectors to unit length and ensure pointing inwards
   nrmls - nrmls/matrix(apply(nrmls, 1, function(x) sqrt(sum(x^2))), nt, p)
   dp - sign(apply((matrix(center, nt, p, byrow=TRUE)-a) * nrmls, 1, sum))
   nrmls - nrmls*matrix(dp, nt, p)
# if  min across all faces of dot((x - a),nrml) is
#  +ve then x is inside hull
#  0   then x is on hull
#  -ve then x is outside hull
# Instead of dot((x - a),nrml)  use dot(x,nrml) - dot(a, nrml)
   aN - diag(a %*% t(nrmls))
   val - apply(testpts %*% t(nrmls) - matrix(aN, cx, nt, byrow=TRUE), 
1,min)
# code  values inside 'tol' to zero, return sign as integer
   val[abs(val)  tol] - 0
   as.integer(sign(val))
}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r

Re: [R] mutlidimensional in.convex.hull(wasmultidimensionalpoint.in.polygon??)

2009-12-18 Thread Keith Jewell
Syntax suggestions implemented.
Inhull's original author consulted.
Function submitted for potential inclusion in geometry package.

Seasons greetings to all.

Keith Jewell
-
baptiste auguie baptiste.aug...@googlemail.com wrote in message 
news:de4e29f50912180238m45c4b7c3g792113d5b6c4c...@mail.gmail.com...
Hi,

Excellent, thanks for doing this!

I had tried the 2D case myself but I was put off by the fact that
Octave's convhulln had a different ordering of the points to R's
geometry package (an improvement to Octave's convhulln was made after
it was ported to R). I'm not sure how you got around this but it's
good to see that the result was worth the effort!

Below are a few minor syntax suggestions,

# p - dim(calpts)[2]   # columns in calpts
# and other similar lines could be replaced with
ncol(calpts)
nrow(testpts)
nrow(hull)

# length(degenflag[degenflag])
# can probably be written
sum(degenflag)

# center = apply(calpts, 2, mean)
# more efficient
colMeans(calpts)

Would you consider submitting this function to the maintainer of the
geometry package, after checking it's OK with inhull's original
author?

Best regards,

baptiste

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


Re: [R] mutlidimensional in.convex.hull (was multidimensionalpoint.in.polygon??)

2009-12-11 Thread Keith Jewell
%), 6 (2800, 25%)
-
N
  n missing  uniqueMean
  11200   0   4 120
0 (2800, 25%), 80 (2800, 25%), 160 (2800, 25%), 240 (2800, 25%)
-
 cor(xs)
  tpH T S N
t  1.00e+00  4.276263e-23  2.346103e-20 0  0.00e+00
pH 4.276263e-23  1.00e+00 -1.716171e-19 0  0.00e+00
T  2.346103e-20 -1.716171e-19  1.00e+00 0 -3.925415e-21
S  0.00e+00  0.00e+00  0.00e+00 1  0.00e+00
N  0.00e+00  0.00e+00 -3.925415e-21 0  1.00e+00
 phull -  convhulln(ps)
 phull2 - convhulln(rbind(ps,xs))
 nrp - nrow(ps)
 nrx - nrow(xs)
 outside - unique(phull2[phull2nrp])-nrp
 done - FALSE
 print(length(outside))
[1] 20
 while(!done){
phull3 - convhulln(rbind(ps,xs[-(outside),]))
also.outside - (1:nrx)[-outside][unique(phull3[phull3nrp])-nrp]
outside - c(outside,also.outside)
print(length(outside))
done - length(also.outside)==0
}
[1] 97
[1] 243
[1] 395
[1] 501
[1] 571
[1] 642
[1] 718
[1] 790
[1] 836
[1] 876
[1] 927
[1] 973
[1] 1012
[1] 1038
[1] 1060
[1] 1088
[1] 1120
[1] 1148
[1] 1162
[1] 1168
[1] 1170
[1] 1170
 describe(xs[-(outside),])
xs[-(outside), ]
 5  Variables  10030  Observations
-
t
  n missing  uniqueMean .05 .10 .25 .50 .75 
.90 .95
  10030   0  35   120.5   2   4  30 120 172 
240 336
lowest :   0   2   3   4  24, highest: 312 336 360 384 504
-
pH
  n missing  uniqueMean
  10030   0   4   5.781
4.6 (2548, 25%), 5.4 (2559, 26%), 6.2 (2520, 25%), 7 (2403, 24%)
-
T
  n missing  uniqueMean
  10030   0   5   9.584

 258   15   22
Frequency 2099 2232 2174 2024 1501
%   21   22   22   20   15
-
S
  n missing  uniqueMean
  10030   0   4   3.067
0 (2371, 24%), 2 (2512, 25%), 4 (2572, 26%), 6 (2575, 26%)
-
N
  n missing  uniqueMean
  10030   0   4   120.0
0 (2502, 25%), 80 (2514, 25%), 160 (2515, 25%), 240 (2499, 25%)
-
 cor(xs[-(outside),])
   tpH T S N
t   1.00 -0.0252190240 -0.1599673922  0.0260853161 -0.0001862074
pH -0.0252190240  1.00 -0.0308956477 -0.0109761096  0.0006346428
T  -0.1599673922 -0.0308956477  1.00  0.0506125967  0.0005164211
S   0.0260853161 -0.0109761096  0.0506125967  1.00  0.0006132354
N  -0.0001862074  0.0006346428  0.0005164211  0.0006132354  1.00
### end example

Baptiste said:

Regarding the inhull Matlab code, I came to the opposite conclusion:
it should be easily ported to R. 1) it is a very short piece of code
(even more so if one disregards the various checks and handling of
special cases), with no Matlab-specific objects (only integers,
booleans, matrices and vectors). 2) The core of the program relies on
the qhull library, and the same applies to R I think. 3) Matlab and R
use very similar indexing for matrices and similar linear algebra in
general.

That said, I'm a bit short on time to give it a go myself. I think the
open-source Octave could run this code too, so it might help in
checking the code step-by-step.


All the best,

baptiste

I agree the Matlab code didn't look very complicated. The main reason I 
thought it non-trival (for me) to code in R was my ignorance; lines like...
nullsp = null(xyz(tess(i,2:end),:) - repmat(xyz(tess(i,1),:),p-1,1))';
...seem important but I don't know what 'null' and 'repmat' do. I don't even 
understand the algebra being implemented and I'm wary of coding in those 
circumstances.

If I had time, I'd like to understand and code the Matlab algorithm, but 
this is a small part of a much bigger task, on which I must progress. So 
I'll thank Baptiste, Duncan and Charles for their invaluable help and move 
on.

Best regards,

Keith Jewell

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

Re: [R] multidimensional point.in.polygon??

2009-12-10 Thread Keith Jewell
Hi,

Doing some more reading, I think the problem is easier because the hull is 
convex. Then an algorithm for testing points might be:

a) Define the convex hull as a set of planes (simplexes).
[as returned by convhulln!!]

b) Define one point, i, known to be interior
[e.g. mean of all the points defining the hull]

c) If point x is
i) for every plane, on the same side as i; x is interior
   ii) for every plane, on the same side as i or in the plane; x is in the 
surface
 iii) else x is exterior

So now I need to find the directions of points from multidimensional 
planes.Perhaps I can find the vectors of the perpendiculars from the points 
to the planes (possibly extended) and test for parallel/anti-parallel?

I feel that I'm in the right direction because this uses the structure of a 
convex hull returned by convhulln. But, I still feel I'm re-inventing the 
wheel. Surely this has been done before? Isn't a (the?) major purpose of a 
convex hull to test other points for inclusion?

Perhaps when I get the geometry sorted this will be so easy I'll understand 
why noone has pointed me to an existing R function, but currently I feel I 
and Baptiste are wandering in the dark :-(

Any hints?

Thanks in advance,

Keith Jewell
-
baptiste auguie baptiste.aug...@googlemail.com wrote in message 
news:de4e29f50912040550m71fbffafnfa1ed6e0f4451...@mail.gmail.com...
Hi,

Yet another one of my very naive ideas on the subject: maybe you can
first evaluate the circumscribed and inscribed spheres of the base set
of points (maximum and minimum of their distances to the center of
gravity). Any points within a distance smaller than the infimum is
good, any point further than the supremum is not good. This should be
faster than the calculation of a convex hull for each point. Of course
the usefulness of this first test really depends on how aspherical is
your base convex hull.

I do hope to read a real answer from someone who knows this stuff!

HTH,

baptiste


2009/12/4 Keith Jewell k.jew...@campden.co.uk:
 Hi,

 I seek to identify those points in/outside a multidimensional convex hull
 (geometry::convhulln). Any suggestions?

 Background just in case I'm going down a really wrong road:

 Given an observed data set with one dependent/observed variable (Y) and
 multiple (3 to 10) independent/design variables (X1, X2, ...) I want to
 increase the number of points by interpolating. I'm using expand.grid(X) 
 to
 generate the X points and locfit::predict.locfit to interpolate the Y
 values. No problem so far.

 BUT my observed X data set is very far from rectangular, so the set of
 points produced by expand.grid includes many extrapolations which I'd
 want to remove. I'm aware of the problems of defining extrapolation in
 multiple dimensions and am minded to define it as outside the convex 
 hull,
 hence my question.

 In searching r-project.org I came across a thread in which baptiste auguie
 said one general way to do this would be to compute the convex hull
 (?chull) of the augmented set of points and test if the point belongs to
 it; an approach I'd considered generalising to multiple points thus 
 (pseudo
 R code)...
 
 baseHull - convhulln(baseSet)
 augHull - convhulln(augSet)
 while (augHull != baseHull)
 { augSet - augSet [-(augHull !%in% baseHull)]
 augHull - convhulln(augSet)
 }
 
 ... but this has that horrible loop including a convhulln!

 In the (real, typical) test data set I'm using for development baseSet is 
 5
 columns by 2637 rows while baseHull has only 42 distinct points. If 
 augHull
 has a similarly simple hull, then each time round the loop will remove 
 only
 a few dozen points; I need to remove many thousands.

 And (in my naivete) I think there must be a better way of testing for a
 point inside a polygon, I'd have thought convhulln must need to do that
 often!

 Thanks in advance for any pointers,

 Keith Jewell

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] mutlidimensional in.convex.hull (was multidimensional point.in.polygon??)

2009-12-10 Thread Keith Jewell
Hi All (especially Duncan and Baptiste),

Summary (of lengthy bits below):
I will have a convex hull in multiple (3 to 10) dimensions derived from many 
(thousands) of points by geometry::convhulln.
I will need to categorise other 'test' points as inside/outside that convex 
hull . e.g. given:
--
require(geometry)
ps - matrix(rnorm(4000),ncol=4) # 'calibration' set
phull -  convhulln(ps)  # convex hull
xs - matrix(rnorm(1200),ncol=4)# 'test' set
-
How do I categorise each point (row) in xs as inside/outside(/on) phull???
There is tripack::in.convex.hull but that doesn't handle my dimensionality.

Thanks to Duncan Murdoch for the suggestion (just a few lines down, 
previously made by Baptiste Auguie): of testing a single point thus:
  i) add the test point to the set of points defining the convex hull,
  ii) recalculate the convex hull
  iii) if the test point is part of the new convex hull, then it was outside 
the original

BUT I have many (thousands) of test points, so this would involve very many 
convex hull calculations. My suggestion, immediately below, requires finding 
the signs of perpendicular distances from each test point to each 
multidimensional 'plane' defining the convex hull (NB: phull  is a matrix in 
which each row defines such a 'plane').

Baptiste has found a Matlab implementation 
http://www.mathworks.com/matlabcentral/fileexchange/10226-inhull of (what 
looks like) my algorithm. I don't speak Matlab, but this looks non-trivial 
to code in R. I'll do it if I have to, but if it already exists it would be 
nice. If I do have to code it, I'd really appreciate an expression in 
algebra rather than Matlab!

Any pointers will be much appreciated,

Keith Jewell
Duncan Murdoch murd...@stats.uwo.ca wrote in message 
news:4b20e1ea.3030...@stats.uwo.ca...
 On 10/12/2009 5:15 AM, Keith Jewell wrote:
 Hi,

 Doing some more reading, I think the problem is easier because the hull 
 is convex. Then an algorithm for testing points might be:

 a) Define the convex hull as a set of planes (simplexes).
 [as returned by convhulln!!]

 b) Define one point, i, known to be interior
 [e.g. mean of all the points defining the hull]

 c) If point x is
 i) for every plane, on the same side as i; x is interior
ii) for every plane, on the same side as i or in the plane; x is in 
 the surface
  iii) else x is exterior

 That looks like it would work, but wouldn't it be easier to do the 
 following:

 Compute the convex hull with the new point added. If the point is 
 exterior, the new point will be part of the hull.  If interior, it won't 
 be.  If it is on the boundary, it's probably unpredictable, but due to 
 rounding error, that's probably true even with a perfect algorithm.

 I didn't notice that you said how your original polygon is defined, but if 
 it is defined as a convex hull or in terms of its vertices, the above 
 method would work.  If it's defined some other way, it might be hard.

 Duncan Murdoch



 So now I need to find the directions of points from multidimensional 
 planes.Perhaps I can find the vectors of the perpendiculars from the 
 points to the planes (possibly extended) and test for 
 parallel/anti-parallel?

 I feel that I'm in the right direction because this uses the structure of 
 a convex hull returned by convhulln. But, I still feel I'm re-inventing 
 the wheel. Surely this has been done before? Isn't a (the?) major purpose 
 of a convex hull to test other points for inclusion?

 Perhaps when I get the geometry sorted this will be so easy I'll 
 understand why noone has pointed me to an existing R function, but 
 currently I feel I and Baptiste are wandering in the dark :-(

 Any hints?

 Thanks in advance,

 Keith Jewell
 -
 baptiste auguie baptiste.aug...@googlemail.com wrote in message 
 news:de4e29f50912040550m71fbffafnfa1ed6e0f4451...@mail.gmail.com...
 Hi,

 Yet another one of my very naive ideas on the subject: maybe you can
 first evaluate the circumscribed and inscribed spheres of the base set
 of points (maximum and minimum of their distances to the center of
 gravity). Any points within a distance smaller than the infimum is
 good, any point further than the supremum is not good. This should be
 faster than the calculation of a convex hull for each point. Of course
 the usefulness of this first test really depends on how aspherical is
 your base convex hull.

 I do hope to read a real answer from someone who knows this stuff!

 HTH,

 baptiste


 2009/12/4 Keith Jewell k.jew...@campden.co.uk:
 Hi,

 I seek to identify those points in/outside a multidimensional convex 
 hull
 (geometry::convhulln). Any suggestions?

 Background just in case I'm going down a really wrong road:

 Given an observed data set with one dependent/observed variable (Y) and
 multiple (3 to 10) independent/design variables (X1, X2, ...) I want to
 increase

[R] multidimensional point.in.polygon??

2009-12-04 Thread Keith Jewell
Hi,

I seek to identify those points in/outside a multidimensional convex hull 
(geometry::convhulln). Any suggestions?

Background just in case I'm going down a really wrong road:

Given an observed data set with one dependent/observed variable (Y) and 
multiple (3 to 10) independent/design variables (X1, X2, ...) I want to 
increase the number of points by interpolating. I'm using expand.grid(X) to 
generate the X points and locfit::predict.locfit to interpolate the Y 
values. No problem so far.

BUT my observed X data set is very far from rectangular, so the set of 
points produced by expand.grid includes many  extrapolations which I'd 
want to remove. I'm aware of the problems of defining extrapolation in 
multiple dimensions and am minded to define it as outside the convex hull, 
hence my question.

In searching r-project.org I came across a thread in which baptiste auguie 
said one general way to do this would be to compute the convex hull 
(?chull) of the augmented set of points and test if the point belongs to 
it; an approach I'd considered generalising to multiple points thus (pseudo 
R code)...

  baseHull - convhulln(baseSet)
  augHull - convhulln(augSet)
  while (augHull != baseHull)
{   augSet - augSet [-(augHull !%in% baseHull)]
augHull - convhulln(augSet)
}

... but this has that horrible loop including a convhulln!

In the (real, typical) test data set I'm using for development baseSet is 5 
columns by 2637 rows while baseHull has only 42 distinct points. If augHull 
has a similarly simple hull, then each time round the loop will remove only 
a few dozen points; I need to remove many thousands.

And (in my naivete) I think there must be a better way of testing for a 
point inside a polygon, I'd have thought convhulln must need to do that 
often!

Thanks in advance for any pointers,

Keith Jewell

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

2009-10-14 Thread Keith Jewell
Problem is demonstrated with this code, intended to find the approximate 'x' 
at which the 'y' is midway between the left and right asymptotes. This 
particular data set returns NA, which is a bit silly!
--
sXY - structure(list(x = c(0, 24, 27, 48, 51, 72, 75, 96, 99), y = 
c(4.98227,
6.38021, 6.90309, 7.77815, 7.64345, 7.23045, 7.27875, 7.11394,
6.95424)), .Names = c(x, y), row.names = c(NA, 9L), class = 
c(sortedXyData,
data.frame))
a - NLSstLfAsymptote(sXY)
d - NLSstRtAsymptote(sXY)
NLSstClosestX(sXY, (a+d)/2)

I think the problem arises when the target y value is exactly equal to one 
of the y values in sXY and can be fixed by trapping that situation thus:

NLSstClosestX.sortedXyData -   function (xy, yval)
{
deviations - xy$y - yval
if (any(deviations==0)) xy$x[match(0, deviations)] else {   # new line 
inserted
  if (any(deviations = 0)) {
  dev1 - max(deviations[deviations = 0])
  lim1 - xy$x[match(dev1, deviations)]
  if (all(deviations = 0)) {
  return(lim1)
  }
  }
  if (any(deviations = 0)) {
  dev2 - min(deviations[deviations = 0])
  lim2 - xy$x[match(dev2, deviations)]
  if (all(deviations = 0)) {
  return(lim2)
  }
  }
  dev1 - abs(dev1)
  dev2 - abs(dev2)
  lim1 + (lim2 - lim1) * dev1/(dev1 + dev2)
   }   # new line inserted
}
---

Comments/corrections welcome.

Keith Jewell

=

 sessionInfo()
R version 2.9.2 (2009-08-24)
i386-pc-mingw32

locale:
LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United 
Kingdom.1252;LC_MONETARY=English_United 
Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252

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

other attached packages:
[1] nlme_3.1-93xlsReadWrite_1.3.3 svSocket_0.9-43svMisc_0.9-48 
TinnR_1.0.3R2HTML_1.59-1
[7] Hmisc_3.6-1

loaded via a namespace (and not attached):
[1] cluster_1.12.0  grid_2.9.2  lattice_0.17-25 stats4_2.9.2 
tools_2.9.2 VGAM_0.7-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] How to use nls when [selfStart] function returns NA or Inf??

2009-09-22 Thread Keith Jewell
Thanks Gabor, but my problem isn't finding reasonable starting parameter 
values, it's preventing nls giving up when it tries parameter values 
resulting in NA or Inf.

I know queries are often over-specific and the appropriate response is 
don't start there, so I'm trying to balance between simplifying to 
essentials, and providing enough background. Here's some more background.

I've had this whole system working for several years in S-plus where it's 
routinely and successfully applied to a variety of models and data sets. I'm 
gradually porting it all into R

I'm using several sigmoidal models; the 4-optimisable-parameter Baranyi 
model I mentioned is just one of them. I have algorithms to find starting 
values for each of the sigmoidal models. However, even with reasonable 
starting values, nls sometimes tries illegal parameter values resulting in 
a crash of the nls process.

Later I fit a more complicated model in which each of the parameters in the 
sigmoidal is a function of several other variables; these models typically 
have dozens of parameters. I use the simple sigmoidal fits to generate 
starting values for the complicated model. Even when the simple sigmoidal 
fits have all converged, nls sometimes tries illegal parameter values when 
fitting the complicated model, so (even) better starting values for the 
original sigmoidals wouldn't solve my ultimate problem.

I think I've correctly identified my problem as preventing nls giving up 
when it tries parameter values resulting in NA or Inf - but I have been 
wrong before :-}

I've considered modifying the sigmoidals to return extreme numeric values 
instead of NA or Inf; but
a) it's non-trivial to choose an appropriate extreme
b) it might break numericDeriv
c) it offends me (!) to return a  (wrong!) value when the right answer is NA

Any suggestions/comments gratefully received.

Keith Jewell
===
Gabor Grothendieck ggrothendi...@gmail.com wrote in message 
news:971536df0909210923r3fd13fb0we72850bf73232...@mail.gmail.com...

With a small number of parameters just use brute force on grid
to calculate starting values.  See nls2 package.

On Mon, Sep 21, 2009 at 12:17 PM, Keith Jewell k.jew...@campden.co.uk 
wrote:
 Hi Everyone,

 I posted this a couple of weeks ago with no responses. My interface (via
 gmane) seemed a bit flakey at the time, so I'm venturing to repost with 
 some
 additional information.

 I'm trying to write selfStart non-linear models for use with nls. In these
 models some combinations of parameter values are illegal; the function 
 value
 is undefined.
 That's OK when calling the function directly [e.g. SSmodel(x, pars...)]; 
 it
 is appropriate to return an appropriate non-value such as NA or Inf.
 However, when called from nls [e.g. nls(y~SSmodel(x, pars...), ...)] those
 non-values lead to errors such as (but not limited to):
 Error in numericDeriv(form[[3L]], names(ind), env) :
 Missing value or an infinity produced when evaluating the model
 or (if I provide a gradient attribute)
 Error in qr.default(.swts * attr(rhs, gradient)) :
 NA/NaN/Inf in foreign function call (arg 1)

 A toy example demonstrating my problem (legal values of param are 1):
 #---
 SSexample-selfStart(
 model=function(x, param) x^log(param-1),
 initial = function(mCall, data, LHS){
 val- 1.001
 names(val) - mCall[c(param)]
 val
 },
 parameters=c(param)
 )
 #
 nls(y~SSexample(x, par), data=data.frame(x=1:10,y=rnorm(10)))
 #-

 (repeat the last line a few times and you'll get the error).

 I can't see a way of making nls either
 a) stick to legal parameter values (which I'd have trouble specifying
 anyway), or
 b) (ideally) accept NA/NaN/Inf as indicating bad parameter values,
 equivalent to very large errors in 'y' values

 I really do want to use nls rather than a bounded optimisation tool (such 
 as
 optim) because this fits into a much bigger picture predicated on nls.

 I'd appreciate any suggestions.

 Keith Jewell
 ==
 sessionInfo() is given below.

 I think the toy example above is enough to demonstrate my problem, but in
 case it is relevant (I don't think it is) here is some more info about the
 models I'm fitting:

 I'm fitting sigmoidal models to microbial growth over time. The specific
 model giving me problems at the moment is only one of a whole class of 
 such
 models which I need to work with. I specify it here to illustrate that it 
 is
 not always obvious what the bounds on the parameters are.

 SSbaranyiBR94-selfStart(
 model=function(Time, y0, ymax, mu, lambda, m = 1, v = mu)
 {
 #+
 # From the paper Baranyi J.  Roberts T. A. (1994). A dynamic approach to
 predicting bacterial growth in food. Int J. of Fd. Micro. 23. 277-294
 # Papers equations (6), (5b), (4b)
 # eq 4b: y(Time) = y0 + mu' * A(Time) - ln(1+(exp(m' * mu' * A(Time)) -
 1)/exp(m' * (ymax-y0)))/m'
 # eq 5b: A(Time) = Time + ln((exp(-v * Time) + q0)/(1+ q0))/v
 # from eq 6: q0 = 1

  1   2   >