[R] The "cloud" CRAN server.

2016-01-16 Thread Rolf Turner


In another thread you wrote:


One note:  The  "cloud" CRAN server is nowadays reachable as

https://cloud.r-project.org

and that is now the preferred URL.


Should I understand from this that it is considered advisable that I use 
this URL as my default repository for downloading R and contributed 
packages from CRAN?  Rather than making use of my "local mirror" (in my 
case http://cran.stat.auckland.ac.nz)?


I have set

   options(repos="https://cloud.r-project.org";)

in my .Rprofile, and everything seems to work, and go like a train.  Are 
there any disadvantages to so doing?


cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] The "cloud" CRAN server.

2016-01-17 Thread Rolf Turner

On 17/01/16 23:51, peter dalgaard wrote:





On 17 Jan 2016, at 05:07 , Rolf Turner 
wrote:


In another thread you wrote:


One note:  The  "cloud" CRAN server is nowadays reachable as

https://cloud.r-project.org

and that is now the preferred URL.


Should I understand from this that it is considered advisable that
I use this URL as my default repository for downloading R and
contributed packages from CRAN?  Rather than making use of my
"local mirror" (in my case http://cran.stat.auckland.ac.nz)?


No, not necessarily. It just means that the cloud service now has an
official name as an R-project server. The main issue is that the name
no longer implies a reliance on Rstudio as a company, nor can it be
interpreted as advertisment of their services.

(Rstudio still pioneered the service and, at least for now, also
provides the infrastructure, and they deserve a lot of thanks for
that. It was just that people were being apprehensive about using
Rstudio services without using their products and about the long-term
reliability of infrastructure rooted in a single commercial
company.)


Okay,  gottit.  Thanks Peter.

cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Reading a tab delimted file of varying length using read.table

2016-01-17 Thread Rolf Turner

On 18/01/16 10:48, Uwe Ligges wrote:

This is not a tab delimited file (as you apparently assume given the
code), but a fixed width format, hence I'd try:

url <- "http://data.princeton.edu/wws509/datasets/divorce.dat";
widths <- c(9, 13, 10, 8, 10, 6)
f5 <- read.fwf(url, widths = widths, skip = 1, strip.white = TRUE)

names(f5) <- as.character(unlist(read.fwf(url, widths = widths,
strip.white=TRUE, n=1)))

Not sure why reading it simply with header=TRUE des not work, but no
time to investiagte this now.


Dear Uwe,

I have fiddled around a bit and the situation seems to me to be of the 
nature of a bug in read.fwf.  It would seem that in order for 
header=TRUE to work, the entries of the header need to be separated by
the sep delimiter which defaults to "\t".  In the case in question the 
entries are separated by blanks, so presumably the header gets read in 
as a single entity, rather than 6 such, leading to a mismatch between 
the length of the header and the number of columns.


It seems that the specified widths get ignored when the header line is 
dealt with.


It also seems that if one specifies sep="" then the header gets read 
correctly but then strings of blanks get interpreted as field separators 
throughout and then blanks within the fields result in the

wrong number of columns.

I think that the code of read.fwf is easy enough to fix; a slight 
adjustment will make the header get treated the same way as the body of 
the file.


I don't see any problems/drawbacks with so-doing, and experimenting with 
my modified function resulted in the divorce data being read in with 
header=TRUE with no problems.


If this mod is made, I see no reason to keep the "sep" argument in 
read.fwf --- except maybe for backward compatibility issues, and I don't 
think there would be any since it never worked properly anyhow.


cheers,

Rolf

P. S. I can send you my modified version of read.fwf off-list if this 
would be of any use to you.


R.

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] find numbers that fall in a region or the next available.

2016-02-02 Thread Rolf Turner

On 03/02/16 11:04, Alaios via R-help wrote:

Dear all,I have GPS coordinates (one vector for longitude and one for
latitude: GPSLong and GPSLat) of small are that is around 300meters X
300 meters (location falls inside UK).At the same time I have two
more vectors (Longitude and Latitude) that include position of food
stores again the UK I would like to find within my 300x300 square
area which as the food stores that fall inside.I thought to try to
find which of the Longitude of the food stores fall inside my area. I
tried something the below

Longitude[Longitude>(min(GPSLong)-0.001)&&Longitude<(max(GPSLong)+0.001)]
but this returned me zero results.The next option would be the code
to return me at least the place that falls outside but still is close
to that region.'Do you have any idea how to do that and not fall back
in the time consuming look at each element iteration?
I would like to thank you for your reply



You could make use of the distfun() function from the spatstat package. 
 Represent your "small area" as an object of class "owin".  The 
longitude and latitude coordinates will be treated as if they were 
Euclidean coordinates, but over distances of the order of 300 metres 
this should not matter much.  You could of course convert your long and 
lat coordinates to metres, using some appropriate projection, which 
might make more sense in your context.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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: determine the year of a date

2016-02-03 Thread Rolf Turner

On 04/02/16 09:55, Boris Steipe wrote:

Who said this was Excel? What did I miss?


If data have been fucked up, it is odds-on that Excel is to blame.

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Generate arrival of time based on uniform random number

2016-02-03 Thread Rolf Turner


This looks very much like a homework problem and this list has a "no 
homework" policy.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

On 04/02/16 17:08, smart hendsome via R-help wrote:

Hi everyone,
I have problem regarding to generate arrival of time based on uniform random 
number.
Let day0 = 0.383, lambda = 0.2612

1) Generate uniform random number (already settled) using the code below:
set.seed(1234)
rand.no <- function(n,itr){
   matrix(runif(n*itr, 0, 1), nrow=n, ncol=itr)
}
x<-rand.no(10,1)
2) For day 1,
a) if 1st rand.no < day0, then its not rain,  else its rain (i want the 
rseult in next colum, let say rain)
3) For day 2 and so on ( it depend from next rain when it happened)
4) Next rain,
to know the next rain i need i need to calculate using the exponential

   a) 1st rain = - ln (1st rand.no) / lambda
   b) 2nd nextRain = 1st rain - ln (2nd rand.no) / lambda
   c) 3rd nextRain = 2nd next rain - ln (3rd rand.no)/lambda,  and so on
  eg: if nextRain = 2.435, then 2nd day will rain


Hope anyone can help me solve this problems. Thanks so much.


__
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] LaplacesDemon package installation

2016-02-04 Thread Rolf Turner


(1) You might get better mileage asking this on the r-sig-mac list.

(2) The phenomena you describe are puzzling and are beyond my capacity 
to explain.  Perhaps someone else will be able to enlighten you.


(3) Out of idle curiosity I went to the github site and downloaded the
zip file of the package.  (I could not see a *.tag.gz file, but perhaps 
I just don't understand how github works.  Actually, there's no 
"perhaps" about it!)


I unzipped the download and then did

R CMD build LaplacesDemon-master

in the appropriate directory.  This created a file

LaplacesDemon_15.03.19.tar.gz

Note that the version number seems to be as you require.

I then used your install.packages syntax, and the package installed 
seamlessly.  It also loaded seamlessly.


So I don't know why the computer gods are picking on you.

Note that I am not working on a Mac, but rather running Linux (as do all 
civilized human beings! :-) )


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

On 05/02/16 06:42, lluis.hurt...@uv.es wrote:

Dear all,

I've recently changed my Mac and I am trying to reinstall my commonly
used R-packages. I'm having troubles with a package called
LaplacesDemon.

This package is no more in the CRAN list and the developers web page
(http://www.bayesian-inference.com/software) is out for more than
half a year. Old versions of the package can still be found in tar.gz
in

https://cran.r-project.org/src/contrib/Archive/LaplacesDemon/

and in github

https://github.com/ecbrown/LaplacesDemon

Last version is LaplacesDemon_13.03.04.tar.gz, but I was able to get
version LaplacesDemon_15.03.19.tar.gz time ago (can't find it
anymore).

I have tried to install this packages from source in my computer
using


install.packages("/Users/.../LaplacesDemon_15.03.19.tar.gz", repos
= NULL, type="source")


answer:


Warning: invalid package 'Users/.../LaplacesDemon_15.03.19.tar.gz’
Error: ERROR: no packages specified Warning message: In
install.packages("Users/.../LaplacesDemon_15.03.19.tar.gz",  :

installation of package ‘Users/.../LaplacesDemon_15.03.19.tar.gz’ had
non-zero exit status

I also tried the 'Packages & Data' menu in R, selecting the source
file or the directory from Finder and I got this message:


* installing *source* package ‘LaplacesDemon’ ... ** R ** data **
inst ** byte-compile and prepare package for lazy loading ** help
*** installing help indices ** building package indices **
installing vignettes ** testing if installed package can be loaded
* DONE (LaplacesDemon)


but


library(LaplacesDemon)

Error in library(LaplacesDemon) : there is no package called
‘LaplacesDemon’

Finally I tried


install.packages("devtools") library(devtools)
install_github("ecbrown/LaplacesDemon")


but I am not able to install devtools (for similar reasons). So my
questions are:

-Do anyone knows how to install this packages in my Mac? -Do anyone
knows were can I find the information previously content in
http://www.bayesian-inference.com/software?


__
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] R project and the TPP

2016-02-04 Thread Rolf Turner



Quite a while ago I went to talk (I think it may have been at an NZSA 
conference) given by the great Ross Ihaka.  I forget the details but my 
vague recollection was that it involved a technique for automatic choice 
of some sort of smoothing parameter involved in a graphical display. 
Apparently Ross's ideas related peripherally to some patented technique 
owned by Texas Instruments, and TI was causing problems for Ross.  He 
seemed to be of the opinion that the TPP would make matters worse.


I suspect he's right.  It will make matters worse for everyone except 
the rich bastards in the multinationals, in all respects.


cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

On 05/02/16 11:33, Marc Schwartz wrote:

Ted and José,

The FSF has a blog post here that might provide some insights:

   
http://www.fsf.org/blogs/licensing/time-to-act-on-tpp-is-now-rallies-against-tpp-in-washington-d-c-november-14-18

That is from last November, but the relevant passage, perhaps in a temporal 
vacuum, seems to be the second paragraph with the following sentences focused 
on the GPL:

"The regulation would not affect freely licensed software, such as software under the GPL, 
that already comes with its own conditions ensuring users receive source code. Such licenses are 
grants of permission from the copyright holders on the work, who are not a "Party" to 
TPP."


The Software Freedom Conservancy has a post on this as well, from the same time 
frame:

   https://sfconservancy.org/blog/2015/nov/09/gpl-tpp/

Regards,

Marc



On Feb 4, 2016, at 4:01 PM, Ted Harding  wrote:

Saludos José!
Could you please give a summary of the relevant parts of TPP
that might affect the use of R? I have looked up TPP on Wikipedia
without beginning to understand what it might imply for the use of R.
Best wishes,
Ted.

On 04-Feb-2016 14:43:29 José Bustos wrote:

Hi everyone,

I have a question regarding the use R software under the new TPP laws
adopted by some governments in the region. Who know how this new agreements
will affect researchers and the R community?

Hope some of you knows better and can give ideas about it.

saludos,
José


__
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] Plot step function

2016-02-06 Thread Rolf Turner

On 07/02/16 01:11, jupiter wrote:

Hi,

I am just starting to learn R, sorry for asking a simple question. How can
plot a line x <= 0 y = 0, x > 0 y = 1?


One way:

plot(c(-1,0,1),c(0,1,1),type="s",xlab="x",ylab="y")

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Separating point symbols and line types in a legend.

2016-02-11 Thread Rolf Turner


I would like to have a legend given in the manner

legend("topleft",pch=c(20,8,1),lty=1:3,bty="n",
   legend=c("clyde","irving","melvin"))

but with the point symbol *NOT* being superimposed on the line segments 
that are plotted.


I saw that I can specify "merge=FALSE" in the call to legend() but this 
gives results like unto


   * irving

with the plot symbol being immediately juxtaposed to the plotted line 
segment.  I would like a space between them, like so:


    * irving

(See the difference?)

I can see no arguments to legend that allow me to effect this.  I can 
adjust positioning of the legend text, but not of the plotted point 
character or line segment.  Is there any way to effect the desired 
result?  Or is there a "simple" adjustment that one could make to the 
code for legend() that would allow me to accomplish what I want?


Ta.

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Separating point symbols and line types in a legend.

2016-02-12 Thread Rolf Turner


Thanks Greg.  Worked perfectly!!!

cheers,

Rolf

On 13/02/16 09:22, Greg Snow wrote:

One option is to call `legend` twice and do some manual positioning.
This worked for me:

plot(1:10)
legend('topleft', lty=1:3, bty="n", legend=c('','','') )
legend('topleft', pch=c(20,8,1), bty="n",
legend=c('clyde','irving','melvin'), inset=c(0.1,0))

You may need to fiddle with the amount of inset for your particular
plot and device combination.



On Thu, Feb 11, 2016 at 9:52 PM, Rolf Turner  wrote:


I would like to have a legend given in the manner

legend("topleft",pch=c(20,8,1),lty=1:3,bty="n",
legend=c("clyde","irving","melvin"))

but with the point symbol *NOT* being superimposed on the line segments that
are plotted.

I saw that I can specify "merge=FALSE" in the call to legend() but this
gives results like unto

* irving

with the plot symbol being immediately juxtaposed to the plotted line
segment.  I would like a space between them, like so:

 * irving

(See the difference?)

I can see no arguments to legend that allow me to effect this.  I can adjust
positioning of the legend text, but not of the plotted point character or
line segment.  Is there any way to effect the desired result?  Or is there a
"simple" adjustment that one could make to the code for legend() that would
allow me to accomplish what I want?

Ta.


--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Error installing the package "Cairo"

2016-02-15 Thread Rolf Turner

On 15/02/16 22:51, Sandeep Mallya wrote:

Hello all,

I am trying to install the package Cairo on RedHat running R version 3.2.3.
So far I have tried install.packages("Cairo")
R CMD INSTALL Cairo_1.5-9.tar.gz

Both the approaches giving me the same error below.


Error : .onLoad failed in loadNamespace() for 'Cairo', details:
   call: dyn.load(file, DLLpath = DLLpath, ...)
   error: unable to load shared object
'/home/sandeep/R/x86_64-pc-linux-gnu-library/3.2/Cairo/libs/Cairo.so':
   libpng15.so.15: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted


Can someone please guide me.


You apparently do not have the "cairo infrastructure" installed on your 
computer.  You probably need to do something like:


sudo yum install cairo.x86_64 # Prob'ly not necessary, this package
  # should be already there.
sudo yum install cairo-devel.x86_64

You may not need to include the ".x86.64" strings, I'm not sure.  Or you 
may need *not* to include them!


HTH.

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] readRDS problem

2016-02-24 Thread Rolf Turner

On 25/02/16 00:11, Erich Neuwirth wrote:

?data
will show you that data is a reserved word!


That is simply not true.  There is no mention in help for data of "data" 
being a reserved word.


Moreover, if "data" *were* a reserved word " <- " wouldn't work either.

Compare:

data <- 42 # No problema.
and
TRUE <- 42 # Throws an error; "TRUE" really *is* a reserved word.

The real explanation is more subtle; it involves "locking" and the 
rather intricate behaviour of "<<-", which I do no claim to understand.


The best advice is: DON'T USE "<<-" !!!

See fortune("dumb down").

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Use of "quote" in Windows and Linux..

2016-02-24 Thread Rolf Turner


(1) Do not post in html.

(2) This is the R-help forum, not the Rstudio help forum.

(3) The call

a1 <- quote(ID)

works just fine under R (not Rstudio) on my Linux box.

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

On 25/02/16 08:03, Santosh wrote:

Dear Rxperts..

I noticed a puzzling behavior of  'quote' in Linux and Windows environment
based RStudio..

In Linux based RStudio ,

a1 <- quote(ID)

The error message I get is:






I dont get any error message when I do the same in Windows 7 based RStudio..


Could you please suggest how to use quote in Linux environment..and explain
why there is such a difference?

Thanks much in advance!!


__
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] Need help in installing packages in R

2016-02-25 Thread Rolf Turner

On 26/02/16 05:11, Bhavani Akila wrote:

Hi,

I have just started learning about "R" programming language. I tried to
connect it to SQL server using "RODBC". On trying to install packages in R
with the command
Eg., 'Install.Packages=="RODBC"', the zip file is not getting downloaded as
am not able to access to the webpage since am working in a restricted
environment.

I have some how managed to get the zip file, but I have no idea how to
install it into my system(Because on installing using "R Console", it
itself is getting unpacked and getting installed in a specific location)

Can I just install by unzipping and placing the file in some random
location and connect R with SQL or is there any procedure to install the
package?

Kindly help me install "R Packages" without the use of "R Console"(With the
use of zip file).

Thanks in advance..!!! 😄



Read the help for install.packages.  Essentially it says to

(a) set repos=NULL
(b) set pkgs equal to the file path to the source of the package that
you wish to install

If, as is likely, you are using Windoze, then (I believe) there is a 
point-and-click facility for installing packages "from local zip files".


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Get object name inside lapply

2016-02-25 Thread Rolf Turner

On 26/02/16 11:37, Huzefa Khalil wrote:

If you want the object names, you should use lapply over the names:

lapply(names(c), function(x) {c[[x]]})


This makes no sense at all to me; you get the same result simply by 
typing "c".


If the OP's message is interpreted literally, all he needs to do is type 
"names(c)".  But this may not be what he *really* wants.  It's hard to tell.


Note that "c" is *not* a good name for a data set, since it is the name 
of an (important) base function.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] ERROR in make.link(link)

2016-03-19 Thread Rolf Turner

On 18/03/16 09:47, CHIRIBOGA Xavier wrote:

Dear all,


I am using R version 3.1.3. I want to run this model:

m1<-glmer(hours~soil*volatile+(1|replicate),  data=data,family=Gamma(link = 
"inv"))


But I got this:

Erreur within make.link(link) : 'inv' link not recognised


What to do in this case?


What to do?  Use the correct syntax! Your call should be:

family=Gamma(link="inverse")

The name of the link must be specified *completely*; partial matching is 
not used, for fairly obvious reasons.


Actually you could just do "family=Gamma" since "inverse" is the 
*default* link.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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: degree sign

2016-03-20 Thread Rolf Turner

On 21/03/16 15:02, David Winsemius wrote:


It's a bit puzzling that neither of my replies to [Cathy Lee Gierke's]
postings have > appeared on the R help list Archive. I normally reply-all
to questions and despite the fact that you are sending in a formatted
style, I have my client configured to reply in plain text. My client
"Sent folder" has copies and the email addressees include
r-help@r-project.org. I suppose this is a further "test" posting sent
as reply-to-all. If it does not appear, then perhaps I can track down
the problem by examining headers.


I can confirm receiving your latest message, and that searching my 
deleted messages reveals no trace of any postings from you on the 
subject of "degree sign".  Weird.  I guess the Paranoids must be out to 
get you.


cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Manually inserting an extra tick on the y axis in ggplot2

2016-03-25 Thread Rolf Turner

On 26/03/16 03:07, KMNanus wrote:

I have called geom_hline to insert a horizontal line on the y axis of a plot at 
a given point.

How can I insert the corresponding tick and its value on the y axis itself?


I think that axis() is what you need, but it's hard to tell without a 
reproducible example.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] help in maximum likelihood estimation

2016-03-28 Thread Rolf Turner

On 29/03/16 09:19, heba eldeeb via R-help wrote:

  Dear All
I'm trying to find the maximum likelihood estimator of a certain
distribution using nlm command but I receive an error as:
non-finite value supplied by 'nlm' can't figure out what is wrong in
my function Any help? Thank you in advance.


Sorry, the mind_read() function in R has not yet been written.

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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: p values from GLM

2016-04-01 Thread Rolf Turner

On 02/04/16 13:01, Duncan Murdoch wrote:

On 01/04/2016 6:46 PM, Bert Gunter wrote:

... of course, whether one **should** get them is questionable...


They're just statistics.  How could it hurt to look at them?


Fortune nomination.

cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Generating random data with non-linear correlation between two variables

2016-04-08 Thread Rolf Turner

On 09/04/16 06:57, Muhammad Bilal wrote:

Hi All,

I am new to R and don't know how to achieve it.

I am interested in generating a hypothetical dataframe that is consisted of say 
two variables named v1 and v2, based on the following constraints:
1. The range of v1 is 500-1500.
2. The mean of v1 is say 1100
3. The range of v2 is 300-950.
4. The mean of v2 is say 400
5. There exists a positive trend between these two variables, meaning that as 
v1 increases, v2 be also increase.
6. But the trend should be slightly non-linear. i.e., curved line.

Is it possible to automatically generate through functions like rnorm.

Any help will be highly appreciated.


This sounds to me very much like a homework problem.  We don't do 
people's homework for them on this list.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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: identical() versus sapply()

2016-04-09 Thread Rolf Turner

On 09/04/16 16:24, Jeff Newmiller wrote:

I highly recommend making friends with the str function. Try

str( 1 )
str( 1:2 )


Interesting.  But to me counter-intuitive.  Since R makes no distinction 
between scalars and vectors of length 1 (or more accurately I think, 
since in R there is *no such thing as a scalar*, only a vector of length 
1) I don't see why "1" should be treated in a manner that is 
categorically different from the way in which "1:2" is treated.


Can you, or someone else with deep insight into R and its rationale, 
explain the basis for this difference in treatment?



for the clue you need, and then

sapply( 1:2, identical, 1L )


cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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: [FORGED] Re: identical() versus sapply()

2016-04-11 Thread Rolf Turner



On 12/04/16 13:09, Duncan Murdoch wrote:




The documentation aims to be accurate, not necessarily clear.




Fortune nomination!

cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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: [FORGED] Re: identical() versus sapply()

2016-04-11 Thread Rolf Turner

On 12/04/16 14:45, Duncan Murdoch wrote:

On 11/04/2016 10:18 PM, Bert Gunter wrote:

"The documentation aims to be accurate, not necessarily clear."

!!!

I hope that is not the case! Accurate documentation that is confusing
is not very useful.


I don't think it is ever intentionally confusing, but it is often
concise to the point of obscurity.  Words are chosen carefully, and
explanations are not repeated.  It takes an effort to read it.  It will
be clear to careful readers, but not to all readers.

I was thinking of the statement quoted earlier, 'as(x, "numeric") uses
the existing as.numeric function'.  That is different than saying 'as(x,
"numeric") is the same as as.numeric(x)'.



IMHO this is so *obviously* confusing and misleading --- even though it 
is technically correct --- that whoever wrote it was either 
intentionally trying to be confusing or is unbelievably obtuse and/or 
out of touch with reality.


It is not (again IMHO) clear even to *very* careful readers.

To my mind this documentation fails even the fortune(350) test.

cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] calculate sampel size?

2016-04-14 Thread Rolf Turner

On 14/04/16 19:28, Marna Wagley wrote:

Hi R user,
Can we calculate sample size when only mean and SE are given?
Let say one example,  I have mean with SE is  0.54+-0.0517 (mean+-SE). Is
there any way to find the samples (sample size n) in that condition in R?

i think this question is not related to R, I hope you won't mind.



You're correct, your question is not related to R.

But the answer (short, long or indifferent) to your question is No.

And furthermore, don't be silly.  SE = s/sqrt(n).  If you knew s you 
could solve for n, but you don't.  Full stop.  There's an end to it.

Any further mucking about is unproductive wishful thinking.

cheers,

Rolf Turner

P. S.  See fortune(299).

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Create a new variable and concatenation inside a "for" loop

2016-05-02 Thread Rolf Turner



You are quite wrong.  This is not "nonsense"; it is sound advice.  It is 
true that R is capable of distinguishing between a function and a 
non-function object with the same name.  However there are many 
circumstances in which using a function's name for the name of a data 
object will lead to errors in function calls and the resulting error 
messages will be difficult to interpret.  (Things like "object of type 
'builtin' is not subsettable".)


Indulging in using "c" (e.g.) for the name of a data object is bad 
practice and mental laziness.


I would suggest that you restrain your presumptuousness and arrogance, 
and refrain from telling experienced and wise R gurus, like Jeff 
Newmiller, that their ideas are "nonsense" until you have a little more 
experience with and knowledge of R.


I am sure that you will insist on arguing about this and that you will 
continue to claim that black is white, but the fact remains that you are 
wrong.  Others should pay no attention to your ranting.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

On 03/05/16 10:00, Raubertas, Richard wrote:

What nonsense. There is a group of finger-waggers on this list who
jump on every poster who uses the name of an R function as a variable
name. R is perfectly capable of distinguishing the two, so if 'c' (or
'data' or 'df', etc.) is the natural name for a variable then go ahead
and use it. Mr. Newmiller provides an excellent example of this: he
recommends 'C' instead of 'c', apparently without realizing that 'C' is
also a built-in R function--because there is "no such problem".

Richard Raubertas

-Original Message- From: R-help
[mailto:r-help-boun...@r-project.org] On Behalf Of JeffNewmiller
Sent: Wednesday, April 27, 2016 3:58 PM To: Gordon, Fabiana;
'r-help@R-project.org' Subject: Re: [R] Create a new variable and
concatenation inside a  "for" loop
"c" an extremely commonly-used function. Functions are first-class
objects that occupy the same namespaces that variables do, so they can
obscure each other. In short, don't use variables called "c" (R is case
sensitive, so "C" has no such problem).

Wherever possible, avoid incremental concatenation like the plague.
If  you feel you must use it, at least concatenate in lists and then use
functions like unlist, do.call, or pre-allocate vectors or matrix-like
objects with unuseful values like NA and then overwrite each element in
the vector or matrix-type object in a loop like your first one.


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

2016-10-03 Thread Rolf Turner


I have recently acquired a new laptop and a new OS (Ubuntu 16.04) and 
have encountered a problem when trying to install rgdal.


The initial hiccups were overcome by installing "libgdal-dev" and 
"libproj-dev" on my system, and then re-installing the package "sp" (as 
advised by postings that I googled up on StackOverflow.


But then I came to a shuddering halt when I got the following error 
response to run install.packages("rgdal",lib="/home/rolf/Rlib")


Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object '/home/rolf/Rlib/rgdal/libs/rgdal.so':
  /home/rolf/Rlib/rgdal/libs/rgdal.so: undefined symbol: 
CPLQuietErrorHandler


I've googled around a bit on that and could find nothing that I could 
comprehend.


Can anyone point me in the right direction?  Ta.

cheers,

Rolf Turner
--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

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

2016-10-04 Thread Rolf Turner

On 05/10/16 01:10, ProfJCNash wrote:

I found that I have libgdal1-dev installed too.

john@john-J6-2015 ~ $ dpkg -l | grep gdal
ii  libgdal-dev 1.10.1+dfsg-5ubuntu1
amd64
Geospatial Data Abstraction Library - Development files
ii  libgdal1-dev1.10.1+dfsg-5ubuntu1
all
Geospatial Data Abstraction Library - Transitional package
ii  libgdal1h   1.10.1+dfsg-5ubuntu1
amd64
Geospatial Data Abstraction Library
john@john-J6-2015 ~ $

and I get the following outputs in R:


library(rgdal)

Loading required package: sp
rgdal: version: 1.1-10, (SVN revision 622)
 Geospatial Data Abstraction Library extensions to R successfully loaded
 Loaded GDAL runtime: GDAL 1.10.1, released 2013/08/26
 Path to GDAL shared files: /usr/share/gdal/1.10
 Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
 Path to PROJ.4 shared files: (autodetected)
 Linking to sp version: 1.2-3

sessionInfo()

R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.4 LTS

locale:
 [1] LC_CTYPE=en_CA.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_CA.UTF-8LC_COLLATE=en_CA.UTF-8
 [5] LC_MONETARY=en_CA.UTF-8LC_MESSAGES=en_CA.UTF-8
 [7] LC_PAPER=en_CA.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] rgdal_1.1-10 sp_1.2-3

loaded via a namespace (and not attached):
[1] grid_3.3.1  lattice_0.20-33




Hope this is helpful.



Afraid not.  I did not have libgdal1-dev installed, but having installed 
it I tried install.packages("rgdal",lib="/home/rolf/Rlib")

again and got the same damned error message as before.


** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object '/home/rolf/Rlib/rgdal/libs/rgdal.so':
  /home/rolf/Rlib/rgdal/libs/rgdal.so: undefined symbol: CPLQuietErrorHandler
Error: loading failed
Execution halted


Has anyone out there any other ideas as to what's going wrong for me and 
how I might fix it?


cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

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

2016-10-04 Thread Rolf Turner

On 05/10/16 12:56, ProfJCNash wrote:

Can you build/install the source package? I had a problem once where my libraries were 
"too recent" for the R package,
but I could build against my installed base. In any event, it may point out the 
source of the problem.

I can appreciate your frustration -- been there, but wish I hadn't.


Essentially install.packages() builds from source.

I also tried to install from the source tarball; same error resulted.

Surely there *must* be somebody out there who understands what's going 
on and how to fix it.  Mustn't there?


cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

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

2016-10-05 Thread Rolf Turner

On 05/10/16 20:47, Rainer M Krug wrote:

Rolf Turner  writes:


On 05/10/16 12:56, ProfJCNash wrote:

Can you build/install the source package? I had a problem once where my libraries were 
"too recent" for the R package,
but I could build against my installed base. In any event, it may point out the 
source of the problem.

I can appreciate your frustration -- been there, but wish I hadn't.


Essentially install.packages() builds from source.

I also tried to install from the source tarball; same error resulted.

Surely there *must* be somebody out there who understands what's going
on and how to fix it.  Mustn't there?


I didn't follow the thread closely, but these types of errors can mean
version conflicts, i.e. that you have either two versions of gdal
installed and the installer picks up the wrong version or a mix of
versions or that you have the wrong version installed.

Check you gdal installations (from source, package manager, whatever
there is), uninstall gdal completely and search thoroughly if there are
any leftovers (apt-get purge ...). Then I would logout and login again -
just to be sure that all caches are up to date (although I doubt this
is necessary).

Than I would check if there are any stray installations or rgdal sitting
in any library.

Than I would install all ubuntu packages neeed for gdal (from the CRAN
for rgdal: "for building from source: GDAL >= 1.6.3, library from 
http://trac.osgeo.org/gdal/wiki/DownloadSource and PROJ.4 (proj >= 4.4.9) from 
http://download.osgeo.org/proj/";), make sure that
they are working from the commandline, and that try again installing the
version of rgdal.

And if not, there is r-sig-spatial which is a much better place to ask
rgdal related questions than r-help.

Hope this helps.


Thanks.  That seems to be good advice.  I'll try it.

cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] (no subject)

2016-10-06 Thread Rolf Turner

On 06/10/16 20:55, abhishek pandey wrote:

kindly solve my problem sir.


That's it, in its entirety.  Shouldn't that win some sort of prize?

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Font problem --- SOLVED.

2016-10-07 Thread Rolf Turner



On Mon, Oct 3, 2016 at 7:55 AM, Rolf Turner  wrote:


Dunno exactly whom I should ask about this problem, but I thought I'd start
with good old r-help.

I have recently acquired a new laptop, and have installed Ubuntu 16.04 on
it.  Still having some teething problems.

If I do

plot(1:10,ylab=expression(italic(J(r)))

I get the error:

Error in title(...) :
  X11 font -*-courier-%s-%s-*-*-%d-*-*-*-*-*-*-*, face 5 at size 15 could
not be loaded

So it would seem that I am missing a font.  Fonts have always been a
complete mystery to me.  Can anyone suggest how I might rectify this
deficiency in the fonts on my system?  If so, *please* be as explicit as you
can in your instructions; I am all at sea here.

cheers,

Rolf Turner

P. S.  I have also just noticed that if I do:

plot(1:10,ylab=expression(alpha))

I get an "a" as the y-axis label, rather than the Greek letter alpha.

Likewise if I do plot(1:10,ylab=expression(Sigma)) I get a capital "S"
rather than an upper case Greek Sigma symbol.  No error thrown, but.

Any ideas as to how to fix this problem?

For what it's worth, here is my sessionInfo():

R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.1 LTS

locale:
 [1] LC_CTYPE=en_NZ.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_NZ.UTF-8LC_COLLATE=en_NZ.UTF-8
 [5] LC_MONETARY=en_NZ.UTF-8LC_MESSAGES=en_NZ.UTF-8
 [7] LC_PAPER=en_NZ.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_NZ.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] misc_0.0-16

loaded via a namespace (and not attached):
 [1] deldir_0.1-13   Matrix_1.2-3mgcv_1.8-12
 [4] abind_1.4-3 spatstat_1.46-1.036 rpart_4.1-10
 [7] nlme_3.1-128grid_3.3.1  polyclip_1.5-0
[10] lattice_0.20-33 goftest_1.0-3   tensor_1.5


Turns out that all I had to do was:

sudo apt-get install xfonts-100dpi
sudo-apt-get install xfonts-75dpi

I'd had to do something like this on my old Fedora-running laptop. 
Finally figured out the apt-get command analogous to the old yum 
command.  (Different package name(s); took me a while to find/figure out 
what the appropriate names are.  I'm *slow*!!!)


Thanks to everyone who tried to help me overcome my stupidity!

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] simulate AR1 process with uniform distribution and different y0 values

2016-10-08 Thread Rolf Turner

On 09/10/16 09:42, Ashwini Patil wrote:

Hello

I need to plot an ar1 graph for process yk=0.75y (k-1) + ek, for y0=1 and
another graph for y0=10.

assume ek is uniformly distributed on interval [-0.5,0.5].

i have the following code but i am not sure how to control y0.

#--#Start#-#
rm(list=ls())
library(tseries)
#library(zoo)
set.seed(0)
y<-arima.sim(model=list(ar=.75), n=100, innov = runif(100, 0, 1))
y.1<-y-0.5
ts.plot(y.1)


I don't understand the last three lines; shouldn't "innov" be equal to 
runif(100, -0.5, 0.5), and subtracting 0.5 be skipped?


I think that the following does what you want:

set.seed(42)
y<- arima.sim(model=list(ar=0.75),n.start=1,start.innov=10,n=100,
 innov=runif(100,-0.5,0.5))

Or you could simply do:

set.seed(42)
e <- runif(100,-0.5,0.5)
yy <- numeric(101)
yy[1] <- 10
for(i in 1:100) yy[i+1] <- 0.75*yy[i] + e[i]
yy <- as.ts(yy[-1])

Same-same.

(Or you could apply filter() to c(10,e) with method="recursive".)

cheers,

Rolf Turner

P.S. I am not convinced that what you want to do makes much sense, but 
the foregoing shows how to do it if you must.


R. T.

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] How to read prediction intervals given by predict()?

2016-10-15 Thread Rolf Turner

On 16/10/16 04:24, mviljamaa wrote:

My conception of prediction intervals is the following:

"a prediction interval gives an interval within which we expect next y_i
to lie with a specified probability"

So when using predict() for my model:

predict(fit4, interval="prediction")[1:20,]

I get:

fit  lwr  upr
1  491.1783 381.3486 601.0081
2  515.4883 405.7128 625.2638
3  581.5957 447.9569 715.2344
4  522.4979 412.5086 632.4872
5  604.6008 492.2796 716.9221
6  520.2881 410.3108 630.2655
7  620.7379 507.9045 733.5713
8  621.0925 505.8731 736.3119
9  527.1810 417.2760 637.0859
10 519.4651 406.1622 632.7680
11 622.0051 512.0082 732.0021
12 536.6924 424.3415 649.0434
13 504.8618 394.9034 614.8202
14 545.5920 433.6530 657.5309
15 475.6153 362.4383 588.7923
16 462.5341 350.6090 574.4593
17 559.0888 448.1212 670.0564
18 544.0051 432.0583 655.9519
19 471.1450 355.2377 587.0523
20 604.3028 470.6925 737.9130

Now since the prediction interval gives the interval within which the
_next_ y_i will fall, then how to read the above results? Does the
previous row's "lwr" and "upr" refer to the next row's "fit"'s interval?


(a) This is really off-topic since it's more of a statistics question 
than an R question.


(b) Your understanding of prediction intervals is incorrect and 
confused.  A 95% (for example)  prediction interval will contain a *new*
independent observation of y, at the same predictor value(s) with 
probability 0.95.  Get your hands on an elementary statistics textbook 
and read it!


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Adjusting axis labels on lattice xyplot

2016-10-15 Thread Rolf Turner

On 16/10/16 11:28, Rich Shepard wrote:

On Fri, 14 Oct 2016, Rich Shepard wrote:


So typing ?xyplot at the console doesn't bring up a help page? That
would
imply that you need to reinstall R.



 Will rebuild and re-install tomorrow morning.


  Sigh. User error. I entered the string as a function, e.g., ?xyplot()
rather than by its name.

  When entered correctly the help page appears.

Apologies.


Just out of interest, I tried typing "?xyplot()" and it worked just as 
if I'd typed "?xyplot" (without the parentheses).


So I am puzzled as to why this didn't work for you (despite your --- 
very mild! --- user error).  Presumably you are running (yeuccch) 
Windoze, whereas I (being a Sensible Person) am running Ubuntu Linux.

Could this make a difference?

cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Adjusting axis labels on lattice xyplot

2016-10-15 Thread Rolf Turner

On 16/10/16 12:10, Rich Shepard wrote:

On Sat, 15 Oct 2016, David Winsemius wrote:


I am not the one to answer the windoze question but my Mac (being less
sensible than Rolf) also pops up a help window when queried with
?xyplot()


David,

  Well, on my Slackware system writing in emacs with ESS ?read.csv()
produces the error message that there's no documentation for that, while
?read.csv brings up the help page.

Shrug.


Ah!  It's Emacs.  Enuff said! :-)  (IMHO Emacs is too clever by half.)

cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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 installing rgdal on a laptop running Ubuntu 16.04.1

2016-10-17 Thread Rolf Turner



On 10/04/2016 05:54 PM, Rolf Turner wrote:


I previously sent a cri de coeur about this problem to the r-help list
but so far have not managed to extract a solution.  So I am trying here.
(Uh, Ubuntu *is* a "special instance" of Debian, isn't it?)

The problem is that I cannot install rgdal, and I need it.  Rather
desperately.

I do:

install.packages("rgdal",lib="/home/rolf/Rlib")

and get the error message:


** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object '/home/rolf/Rlib/rgdal/libs/rgdal.so':
  /home/rolf/Rlib/rgdal/libs/rgdal.so: undefined symbol:
CPLQuietErrorHandler
Error: loading failed
Execution halted


Since I (in my desperation) cross-posted to r-sig-debian and r-help, I 
am sending this "SOLVED" message to both lists.


The solution took a long while to find, but in the end it was very simple.

Quite a while back I was having problems with installing some package
(I *think* it was one of my own packages, hmm.discnp), and someone (the 
details are lost in the mists of time) advised me to create a directory 
".R" in my home directory and in it place a file "Makevars" containing 
the lines:



FCFLAGS = -g -O2 -mtune=native -fbounds-check
FFLAGS = -g -O2 -mtune=native -fbounds-check
PKG_LIBS=$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)


This solved the problem that I was having at that time.  I had long 
forgotten the directory ".R" and *that* was  what was causing the problem.


A *very* clever and knowledgeable young Linux whiz, who kindly agreed to 
help me with this problem, eventually tracked down the fact that it 
originated from ".R".  When I removed ".R", the problem with rgdal (and

problems with several other packages, that subsequently surfaced) went away.

My system is now humming away smoothly.

Thanks to everyone who (futilely!) attempted to help me out.

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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: Share R.net dll without having to share R script code?

2016-10-17 Thread Rolf Turner

On 18/10/16 14:04, David Winsemius wrote:



On Oct 17, 2016, at 3:22 PM, Narendra Modi  wrote:

Hi Bob,
Could you explain a bit more on this? How do I use/configure base64?
Any document/example do you have?



To Narendra;

I get the idea that this line of inquiry is designed to obfuscate R

code and derivative works, which in turn I see as an effort to defeat
the open source nature of the R movement. It at least violates the
spirit of the various licenses under which R and the CRAN packaging
policies are distributed.


I'm suggesting that those people who support an open source basis of
R

not continue to use Rhelp as a venue for an effort to undermine the
openness of coding supported by R. If Bob disagrees with me, he is at
liberty to correspond with you privately. I have no authority to enforce
such advice, and anyone is free to opine on the ethics and legality of
this proposed effort.

I concur with David completely.

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Dealing with -Inf in a maximisation problem.

2016-11-06 Thread Rolf Turner


I am trying to deal with a maximisation problem in which it is possible 
for the objective function to (quite legitimately) return the value 
-Inf, which causes the numerical optimisers that I have tried to fall over.


The -Inf values arise from expressions of the form "a * log(b)", with b 
= 0.  Under the *starting* values of the parameters, a must equal equal 
0 whenever b = 0, so we can legitimately say that a * log(b) = 0 in 
these circumstances.  However as the maximisation algorithm searches 
over parameters it is possible for b to take the value 0 for values of

a that are strictly positive.  (The values of "a" do not change during
this search, although they *do* change between "successive searches".)

Clearly if one is *maximising* the objective then -Inf is not a value of
particular interest, and we should be able to "move away".  But the 
optimising function just stops.


It is also clear that "moving away" is not a simple task; you can't 
estimate a gradient or Hessian at a point where the function value is -Inf.


Can anyone suggest a way out of this dilemma, perhaps an optimiser that 
is equipped to cope with -Inf values in some sneaky way?


Various ad hoc kludges spring to mind, but they all seem to be fraught 
with peril.


I have tried changing the value returned by the objective function from
"v" to exp(v) --- which maps -Inf to 0, which is nice and finite. 
However this seemed to flatten out the objective surface too much, and 
the search stalled at the 0 value, which is the antithesis of optimal.


The problem arises in a context of applying the EM algorithm where the 
M-step cannot be carried out explicitly, whence numerical optimisation.

I can give more detail if anyone thinks that it could be relevant.

I would appreciate advice from younger and wiser heads! :-)

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Dealing with -Inf in a maximisation problem.

2016-11-06 Thread Rolf Turner

On 07/11/16 13:07, William Dunlap wrote:

Have you tried reparameterizing, using logb (=log(b)) instead of b?


Uh, no.  I don't think that that makes any sense in my context.

The "b" values are probabilities and must satisfy a "sum-to-1" 
constraint.  To accommodate this constraint I re-parametrise via a 
"logistic" style parametrisation --- basically


   b_i = exp(z_i)/[sum_j exp(z_j)], j = 1, ... n

with the parameters that the optimiser works with being z_1, ..., 
z_{n-1} (and with z_n == 0 for identifiability).  The objective function 
is of the form sum_i(a_i * log(b_i)), so I transform back

from the z_i to the b_i in order calculate the value of the objective
function.  But when the z_i get moderately large-negative, the b_i 
become numerically 0 and then log(b_i) becomes -Inf.  And the optimiser 
falls over.


cheers,

Rolf



Bill Dunlap
TIBCO Software
wdunlap tibco.com <http://tibco.com>

On Sun, Nov 6, 2016 at 1:17 PM, Rolf Turner mailto:r.tur...@auckland.ac.nz>> wrote:


I am trying to deal with a maximisation problem in which it is
possible for the objective function to (quite legitimately) return
the value -Inf, which causes the numerical optimisers that I have
tried to fall over.

The -Inf values arise from expressions of the form "a * log(b)",
with b = 0.  Under the *starting* values of the parameters, a must
equal equal 0 whenever b = 0, so we can legitimately say that a *
log(b) = 0 in these circumstances.  However as the maximisation
algorithm searches over parameters it is possible for b to take the
value 0 for values of
a that are strictly positive.  (The values of "a" do not change during
this search, although they *do* change between "successive searches".)

Clearly if one is *maximising* the objective then -Inf is not a value of
particular interest, and we should be able to "move away".  But the
optimising function just stops.

It is also clear that "moving away" is not a simple task; you can't
estimate a gradient or Hessian at a point where the function value
is -Inf.

Can anyone suggest a way out of this dilemma, perhaps an optimiser
that is equipped to cope with -Inf values in some sneaky way?

Various ad hoc kludges spring to mind, but they all seem to be
fraught with peril.

I have tried changing the value returned by the objective function from
"v" to exp(v) --- which maps -Inf to 0, which is nice and finite.
However this seemed to flatten out the objective surface too much,
and the search stalled at the 0 value, which is the antithesis of
optimal.

The problem arises in a context of applying the EM algorithm where
the M-step cannot be carried out explicitly, whence numerical
optimisation.
I can give more detail if anyone thinks that it could be relevant.

I would appreciate advice from younger and wiser heads! :-)

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276 

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





--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Dealing with -Inf in a maximisation problem.

2016-11-06 Thread Rolf Turner


On 07/11/16 14:14, ProfJCNash wrote:


Rolf, What optimizers did you try? There are a few in the optimrx package on 
R-forge that handle bounds, and it may be
useful to set bounds in this case. Transformations using log or exp can be 
helpful if done carefully, but as you note,
they can make the function more difficult to optimize.


I can't see how to impose bounds in my circumstances.  As you will have 
seen from my previous answer to Bill Dunlap's post, the b_i are 
probabilities, parametrised in terms of z_i:


b_i = exp(z_i)/[sum_j exp(z_j)] .

It is not at all clear to me how to impose constraints on the z_i that 
will bound the b_i away from 0.


I can constrain L <= z_i <= U for all i and get b_i >= exp(L)/[n*exp(U)]
--- I think; I may have things upsidedown and backwards --- but this 
leaves an infinitude of choices for L and U.


Also the starting values at each M-step are "naturally" given in terms 
of the b_i.  I.e. I can calculate "reasonable" values for the b_i and 
then transform these to provide starting values for the z_i.  The 
starting values for z_i might not satisfy a given set of constraints.
I guess I could simply truncate the starting values to fall within the 
constraints, but that "feels wrong" to me.


I also worry about the impact that imposing constraints will have on
the monotonicity of the successive values of the expected log likelihood 
in the EM algorithm context.



Be cautious about using the default numerical gradient approximations. optimrx 
allows selection of the numDeriv grad()
function, which is quite good. Complex step would be better, but you need a 
function which can be computed with complex
arguments. Unfortunately, numerical gradients often step over the cliff edge of 
computability of the function. The
bounds are not checked for the step to compute things like (f(x+h) - f(x) / h.


I think I can program up an analytic gradient function.  Maybe I'll try 
that.  I have been reluctant to do so because I have had peculiar (bad) 
experiences in the past in trying to use analytic gradients with nlm().


Of course the (analytic) gradient becomes undefined if one of the b_i is 0.

cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Dealing with -Inf in a maximisation problem.

2016-11-06 Thread Rolf Turner

On 07/11/16 15:46, Charles C. Berry wrote:

On Mon, 7 Nov 2016, Rolf Turner wrote:


On 07/11/16 13:07, William Dunlap wrote:

Have you tried reparameterizing, using logb (=log(b)) instead of b?


Uh, no.  I don't think that that makes any sense in my context.

The "b" values are probabilities and must satisfy a "sum-to-1"
constraint. To accommodate this constraint I re-parametrise via a
"logistic" style parametrisation --- basically

  b_i = exp(z_i)/[sum_j exp(z_j)], j = 1, ... n

with the parameters that the optimiser works with being z_1, ...,
z_{n-1} (and with z_n == 0 for identifiability).  The objective
function is of the form sum_i(a_i * log(b_i)),



This is sum_i(a_i * z_i) - sum(a_i)*log(sum_j(exp(z_j)), isn't it?

So you don't need to evaluate b_i here, do you?

Large values of z_j will lead to exp(z_j) == Inf, but using

sum_i(a_i * (z_i-max.z)) - sum(a_i)*log(sum_j(exp(z_j-max.z))

will handle that.


Wow!!!  That looks like it will work!!!  I won't completely believe it 
until I've programmed it up and tried it --- but for the first time in 
days I'm feeling hopeful.


HTH,

Chuck

p.s. Regarding "advice from younger and wiser heads", I probably cannot
claim to be either.


On present evidence you certainly appear to be one hell of a lot wiser!!!

Thanks.

cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Issues with the way Apply handled NA's

2016-11-14 Thread Rolf Turner

On 15/11/16 09:52, Olu Ola via R-help wrote:

 Hello,I have a data set called plabor and have the following format:

| ColA | ColB | Colc |
| 6 | 25 | 3 |
| NA | NA | NA |
| 3 | 2 | 19 |
| 4 | 7 | NA |


I wanted to find the product of the three columns for each of the rows and I 
used the apply function follows:
plabor$colD = apply(plabor[c("colA","colB","colc")],1,prod,na.rm=T)
The result are as follows:

| ColA | ColB | Colc | colD |
| 6 | 25 | 3 | 450 |
| NA | NA | NA | 1 |
| 3 | 2 | 19 | 114 |
| 4 | 7 | NA | 28 |


The second row results is 1 instead of being ignored.
How do I deal with this issue because I do not want to exclude these data 
points with all NA's?


What do you mean by "ignored"?  If you really want rows of your matrix 
that are all NA to be omitted from consideration, delete such rows from 
your matrix a priori.


If you want the product of such rows to be NA rather than 1, use a 
"customised" function rather than prod() in your apply, with an 
appropriate if-else construction in the customised function.


It's very easy, and I won't tell you the details because I think it's 
time you actually learned something about R (given that you are using 
R), and one learns by doing.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Problems using plsr() in the pls package

2016-11-20 Thread Rolf Turner

On 21/11/16 09:03, Rui Barradas wrote:

Hello,

I know nothing about the plsr package but in the data.frame 'gasoline'
the column NIR is numeric and in 'lid_allt2' the column lid_nose is
character. Maybe you need

lid_allt2$lid_nose <- as.numeric(lid_allt2$lid_nose)

but I really don't know if this is the problem.



I have no idea either, but surely your suggestion should be:

lid_allt2$lid_nose <- as.numeric(as.character(lid_allt2$lid_nose))

or (better):

lid_allt2$lid_nose <-
with(lid_allt2,as.numeric(levels(lid_nose))[lid.nose])


cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Partial Fraction Decomposition

2016-11-27 Thread Rolf Turner

On 27/11/16 22:09, WRAY NICHOLAS wrote:

I am not aware that R really does symbolic manipulation in the way which you
want, but I would have thought that this process would make a very pretty little
problem to solve for you yourself, in that you could write a programme to
analyse the original expression as a string of characters, whose particular
nature means that you have to make certain choices.  Start with a simple
example, say (x^2 + x +1)/(x+1) (i haven't actually worked this out) and
gradually work up


A quick Google search reveals Ryacas and rSymPy as (at least) two 
packages that do symbolic manipulations.  I have never used either, and 
don't know if they do the partial fraction calculations that the OP 
wanted.  But they'd be worth checking out.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Export R output in Excel

2016-12-28 Thread Rolf Turner

On 29/12/16 10:45, Bryan Mac wrote:

Hi,

How do I export results from R to Excel in a format-friendly way? For
example, when I copy and paste my results into excel, the formatting
is messed up.



Short answer:  *Don't*.  ("Friends don't let friends use excel for 
statistics.")


Longer answer:  Googling on "export R data to excel" yields lots of 
"useful" hits --- "useful" given the (false) assertion that it is useful 
to export things to excel.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Export R output in Excel

2016-12-28 Thread Rolf Turner

On 29/12/16 12:48, Bryan Mac wrote:

Hi Rolf,

I wanted to export the output/results of R to an Excel file for
easier comparisons/reporting. When I tried to copy and paste my
output to an excel file the formatting was off. I want to export my
descriptive stats and the linear regression.


This makes little to no sense to me.  Spreadsheets are for use in 
storing data, not for displaying the output of analyses.  (I know that 
Excel users do this sort of thing, but then people do all sorts of 
irrational things.)



I googled “Export R output to excel” but did not find most of the
hints “useful”. if anything, it got me more confused.

Thanks.


(1) The best advice is still "*Don't*."

(2) You do not need Excel to make comparisons and report.  In fact it is 
a handicap.  Re-think your strategy.


(3) If you insist in proceeding in a wrong-headed manner, isn't the item 
about XLConnect (3rd answer, 1st hit) "useful"?


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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: Problems when trying to install and load package "rzmq"

2017-01-03 Thread Rolf Turner

On 04/01/17 08:45, Paul Bernal wrote:

Hello Petr,

Is it possible to compile the package (rzmq) from Ubuntu for Windows?


No.  At least in my understanding, if you want a package to run on 
Windoze, you have to compile it for Windoze, on Windoze, using compilers 
that are adapted to Windoze.


A feasible approach for you would be to use the win-builder facility.
See the URL:

https://win-builder.r-project.org/

You would have to be able to

* un-tar the source package
* edit the DESCRIPTION file so as to insert *your* email address
  under "maintainer"
* rebuild the (edited) package

To do this you would probably need to work on a Linux system.

Good luck.

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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: Generating a Special Histogram

2017-01-05 Thread Rolf Turner

On 06/01/17 10:31, Jim Lemon wrote:

Hi Dan,
This may help if your data is in the format below:

waffle.mat<-matrix(c(rep(NA,14),137,135,rep(NA,6),144,149,
 rep(NA,3),150,152,159,157,154,
 NA,163,164,164,161,162,165,164,rep(NA,5),179,173,173,
 rep(NA,4),182,180,185,180,
 rep(NA,6),197,190,rep(NA,8)),ncol=9)
waffle.col<-matrix("lightblue",ncol=9,nrow=8)
waffle.col[is.na(waffle.mat)]<-NA
waffle.border<-matrix("blue",ncol=9,nrow=8)
waffle.border[is.na(waffle.mat)]<-NA
library(plotrix)
# use a waffle plot
color2D.matplot(waffle.mat,cellcolors=waffle.col,border=waffle.border,
 show.values=TRUE,xat=10,yat=10,xlab="",ylab="")
axis(1,at=1:8,labels=seq(130,200,by=10))
axis(2,at=1:8)
axis.break(1)


Being picky-picky-picky I would like to point out that Duncan's and 
David's functions don't *quite* reproduce the picture in the pdf file

that the OP attached, when called with the data from that picture:

egdat <- c(137,135,144,149,150,152,159,157,154,163,164,164,
   161,162,165,164,179,173,173,182,180,185,180,197,190)
myhist(egdat)
boxhist(egdat)

It's a matter of including the left or right endpoints in the bins.

Duncan's function needs to swap "<" and "<=" in the definition of "keep"
(and make a corresponding adjustment in the "|" clause, so as to look at
the last rather than the first break value).

David's function needs to set "right=FALSE" in the call to cut().

Jim's waffle plot gets it right, at the expense of needing to have the
data organised in an inconvenient form.

All that being said, all of you blokes came up with solutions that are 
far beyond my capability of producing.  Hat's off to you.


cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] file.exists() on device files

2017-01-11 Thread Rolf Turner

On 11/01/17 23:12, Benjamin Tyner wrote:

Hi,

On my linux machine (Ubuntu, and also tested on RHEL), I am curious to
know what might be causing file.exists (and also normalizePath) to not
see the final device file here:

   > list.files("/dev/fd", full.names = TRUE)
   [1] "/dev/fd/0" "/dev/fd/1" "/dev/fd/2" "/dev/fd/3"
   > file.exists(list.files("/dev/fd", full.names = TRUE))
   [1]  TRUE  TRUE  TRUE FALSE
   > normalizePath(list.files("/dev/fd", full.names = TRUE))
   [1] "/dev/pts/2" "/dev/pts/2" "/dev/pts/2" "/dev/fd/3"
   Warning message:
   In normalizePath(list.files("/dev/fd", full.names = TRUE)) :
 path[4]="/dev/fd/3": No such file or directory


(a) Exactly the same thing happens to me (I am also running Ubuntu 16.04).

(b) Things get a bit confused because /dev/fd is actually a symbolic link:


$ ls -l /dev/fd
lrwxrwxrwx 1 root root 13 Jan  6 20:16 /dev/fd -> /proc/self/fd/


(c) But then doing


file.exists(list.files("/proc/self/fd", full.names = TRUE))


Gives the same result as before:


[1]  TRUE  TRUE  TRUE FALSE


(d) It turns out that the four "files" in /proc/self/fd are again
symbolic links:


$ ls -l /proc/self/fd
total 0
lrwx-- 1 rolf rolf 64 Jan 12 12:32 0 -> /dev/pts/3
lrwx-- 1 rolf rolf 64 Jan 12 12:32 1 -> /dev/pts/3
lrwx-- 1 rolf rolf 64 Jan 12 12:32 2 -> /dev/pts/3
lr-x-- 1 rolf rolf 64 Jan 12 12:32 3 -> /proc/7150/fd/


(e) But now do it again!!!


$ ls -l /proc/self/fd
total 0
lrwx-- 1 rolf rolf 64 Jan 12 12:32 0 -> /dev/pts/3
lrwx-- 1 rolf rolf 64 Jan 12 12:32 1 -> /dev/pts/3
lrwx-- 1 rolf rolf 64 Jan 12 12:32 2 -> /dev/pts/3
lr-x-- 1 rolf rolf 64 Jan 12 12:32 3 -> /proc/7154/fd/


Different number; 7154 rather than 7150.

(f) The name "/proc" would seem to imply that this has something to do 
with processes; the directories "7150", "7154" etc. are being created 
and removed on the fly, as a result of some process (presumably the "ls"

process) starting and finishing.

I have no insight into what is being effected here, or what is really 
going on "deep down", but the foregoing is some sort of "explanation".
By the time file.exists() is invoked, the ls process called by 
list.files() has finished and the associated directory (e.g. "7150", 
"7154", ...) has ceased to be.


What you do with this "explanation" is up to you.  My advice would be to 
forget about it and go to the pub! :-)


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] file.exists() on device files

2017-01-11 Thread Rolf Turner

On 12/01/17 16:33, Henrik Bengtsson wrote:




FYI, the /proc is there because Unix has something called the "proc
filesystem (procfs; https://en.wikipedia.org/wiki/Procfs) is a special
filesystem in Unix-like operating systems that presents information
about processes and other system information in a hierarchical
file-like structure".  For instance, you can query the uptime of the
machine by reading from /proc/uptime:

$ cat /proc/uptime
332826.96 661438.10

$ cat /proc/uptime
332871.40 661568.50


You can get all IDs (PIDs) of all processes currently running:

$ ls /proc/ | grep -E '^[0-9]+$'

and for each process you there are multiple attributes mapped as
files, e.g. if I start R as:

$ R --args -e "message('hello there')"

then I can query that process as:

$ pid=$(pidof R)
$ echo $pid
26323

$ cat /proc/26323/cmdline
/usr/lib/R/bin/exec/R--args-emessage('hello there')

Unix is neat


Indeed.  Couldn't agree more.  Thanks for the insight.



cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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: output

2017-01-17 Thread Rolf Turner

On 18/01/17 10:28, Marc Schwartz wrote:

Hi Val,





Alternatively, there are other Excel file I/O packages available on
CRAN if you would prefer to consider other options as well. They will
typically require Java being installed, rather than Perl, as I and
Greg do.


The read_excel() function from the "readxl" package has an argument 
"sheet" which should facilitate what Val wants to do.


In my experience the read_excel() function (which is, as you indicate, 
Java rather than Perl based) is quite a bit faster than the Perl based 
alternatives.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Dimensionality reduction with ProDenICA

2017-01-17 Thread Rolf Turner

On 18/01/17 11:17, Neverstop . wrote:

Hello,

I have a dataset with many variables and I'd like to do dimensionality
reduction with Independent Component Analysis. There are many
statistical methods to estimate the latent variables of the ICA model.
I'm trying the R package "ProDenICA" that implements the penalized
maximum likelihood method proposed by Hastie, Tibshirani and Friedman in
Section 14.7.4 of the book "Elements of Statistical Learning". The
documentation of the ProDenICA function says that the argument "k" is
the "Number of components required, less than or equal to the number of
columns of x". If I choose a value of k less than the number of colomns
of x, I get an error message. It seems to me that I'm not using the
function proDenICA() as it is meant to be used. Am I missing something?

I've reproduced the problem with a smaller dataset here:

 > library(MASS)
 > data(crabs)
 > str(crabs)
'data.frame':200 obs. of  8 variables:
  $ sp   : Factor w/ 2 levels "B","O": 1 1 1 1 1 1 1 1 1 1 ...
  $ sex  : Factor w/ 2 levels "F","M": 2 2 2 2 2 2 2 2 2 2 ...
  $ index: int  1 2 3 4 5 6 7 8 9 10 ...
  $ FL   : num  8.1 8.8 9.2 9.6 9.8 10.8 11.1 11.6 11.8 11.8 ...
  $ RW   : num  6.7 7.7 7.8 7.9 8 9 9.9 9.1 9.6 10.5 ...
  $ CL   : num  16.1 18.1 19 20.1 20.3 23 23.8 24.5 24.2 25.2 ...
  $ CW   : num  19 20.8 22.4 23.1 23 26.5 27.1 28.4 27.8 29.3 ...
  $ BD   : num  7 7.4 7.7 8.2 8.2 9.8 9.8 10.4 9.7 10.3 ...
 > X=crabs[,4:8]
 > X=as.matrix(X)
 > library(ProDenICA)
 > out.proDen = ProDenICA(X, k = 2, whiten = TRUE, maxit = 20, trace=T)
Error in solve.default(V, W) : 'a' (5 x 2) must be square

I get the error with k = 1,2,3,4. The function works with k=5.


I have no idea how to help you --- sorry!!! --- but I would like to 
compliment you on the clarity of your extremely well structured 
question, complete with reproducible example.


My gut feeling is that there must be something wrong with the 
ProDenICA() function, but such is my ignorance that this gut feeling is 
not worth the paper it's written on! :-)


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] turning the output of cut into a waffle plot

2017-01-17 Thread Rolf Turner

On 18/01/17 12:21, Jim Lemon wrote:

Hi all,
A few days ago I offered a suggestion on how to display the initial
values that were cut into a factor as a waffle plot. As Rolf Turner
noted, a major problem for users would be constructing the matrix that
was fed to the color2D.matplot function. Here is a fairly general
purpose function for that with an example from the initial post.

egdat <- c(137,135,144,149,150,152,159,157,154,163,164,164,
   161,162,165,164,179,173,173,182,180,185,180,197,190)

cut2matrix<-function(x,breaks,ncol,nrow,right=TRUE) {
 xcut<-as.numeric(cut(x,breaks=breaks,right=right))
 if(missing(ncol)) ncol<-length(breaks)-1
 if(missing(nrow)) nrow<-max(table(xcut))
 xlist<-vector("list",ncol)
 for(xind in 1:ncol) xlist[[xind]]<-rev(x[xcut==xind])
 xdf<-as.data.frame(lapply(xlist,function(x) x[1:nrow]))
 names(xdf)<-paste("V",1:ncol,sep="")
 return(as.matrix(sapply(xdf,rev)))
}

egmat<-cut2matrix(egdat,seq(120,210,by=10),9,8,FALSE)
library(plotrix)
color2D.matplot(egmat,show.values=TRUE)


Nice work Jim.  Will the cut2matrix() function now be added to the 
plotrix package?


cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Fitting arima Models with Exogenous Variables

2017-01-20 Thread Rolf Turner

On 21/01/17 02:29, Paul Bernal wrote:

Dear friends,

I have 5 exogenous variables which I´d like to incorporate into my
auto.arima model.

I was able to incorporate the xreg, and I understand that newxreg should be
the forecast of my exogenous variables, but I have not been able to get it
to work.

Newxreg should only have one column? Should newxreg have the same number of
rows of the training data?

This is the error I keep getting but I don´t quite understand:

Error in forecast.Arima(ModelAfit, h = 12, newxreg = NewXreg) :
  No regressors provided
In addition: Warning message:
In forecast.Arima(ModelAfit, h = 12, newxreg = NewXreg) :
  The non-existent newxreg arguments will be ignored.

Any help will be greatly appreciated,


You need to provide a *reproducible example*.  (Including data --- 
built-in data set, dput output, or simulation recipe with a seed set --- 
and an indication of what *packages* you are using.)


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Fitting arima Models with Exogenous Variables

2017-01-23 Thread Rolf Turner


This should have been sent to the R-help mailing list, not to me 
personally.  I am not an expert on this sort of time series modelling
and cannot thereby provide any useful advice.  My reply to you was of a 
"generic" nature --- when making an enquiry, provide a reproducible 
example!!!


I am cc-ing this email to the R-help list, since someone on that list 
*may* be able to answer your question.  I have (re-) attached the data 
sets that you sent to me.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

On 24/01/17 04:36, Paul Bernal wrote:

Hello Rolf,

Thank you for your kind reply. I am attaching two datasets, one with the
historical data that I used to train the model, and the other one with
the exogenous variables.

The R code that I used is as follows:


library(forecast)
library(tseries)
library(TSA)
library(stats)
library(stats4)
TrainingDat<-read.csv("Training Data.csv")

ExogVars<-read.csv("ExogenousVariables5.csv")
#The file ExogVars contains 5 columns, one column for each regressor
Model1<-auto.arima(TrainingDat[,5], xreg=ExogVars)
#In Model1 I was able to incorporate xreg without any trouble
#The problem comes when trying to incorporate newxreg
Model2<-auto.arima(ExoVars[1:5])

Error in as.ts(x) : object 'ExoVars' not found


Model2<-auto.arima(ExogVars[1:5])


Error in auto.arima(ExogVars[1:5]) : No suitable ARIMA model found


Model2<-auto.arima(ExogVars[,1])

NewXReg<-forecast(Model2, h=12)

Forec<-forecast(Model1, newxreg=NewXReg)

Error in forecast.Arima(Model1, newxreg = NewXReg) :
  No regressors provided
In addition: Warning message:
In forecast.Arima(Model1, newxreg = NewXReg) :
  The non-existent newxreg arguments will be ignored.


Forec<-forecast(Model1, newxreg=NewXReg$mean)

Error in forecast.Arima(Model1, newxreg = NewXReg$mean) :
  No regressors provided
In addition: Warning message:
In forecast.Arima(Model1, newxreg = NewXReg$mean) :
  The non-existent newxreg arguments will be ignored.

I would like to generate the forecasts for all 4 variables included in
the Training set, along with all 5 regressors, but it seems like I can
only chose one training variable at a time, and one regressor at a time.

Please let me know if you can work this out,



__
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] Fitting arima Models with Exogenous Variables

2017-01-26 Thread Rolf Turner


I am re-sending this since I have been told that the attachments that I 
made did not get through.  So I am trying again with *.dput attachments.


You will need to read them in using dget().

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

On 24/01/17 10:35, Rolf Turner wrote:


This should have been sent to the R-help mailing list, not to me
personally.  I am not an expert on this sort of time series modelling
and cannot thereby provide any useful advice.  My reply to you was of a
"generic" nature --- when making an enquiry, provide a reproducible
example!!!

I am cc-ing this email to the R-help list, since someone on that list
*may* be able to answer your question.  I have (re-) attached the data
sets that you sent to me.

cheers,

Rolf Turner

On 24/01/17 04:36, Paul Bernal wrote:

Hello Rolf,

Thank you for your kind reply. I am attaching two datasets, one with the
historical data that I used to train the model, and the other one with
the exogenous variables.

The R code that I used is as follows:


library(forecast)
library(tseries)
library(TSA)
library(stats)
library(stats4)
TrainingDat<-read.csv("Training Data.csv")

ExogVars<-read.csv("ExogenousVariables5.csv")
#The file ExogVars contains 5 columns, one column for each regressor
Model1<-auto.arima(TrainingDat[,5], xreg=ExogVars)
#In Model1 I was able to incorporate xreg without any trouble
#The problem comes when trying to incorporate newxreg
Model2<-auto.arima(ExoVars[1:5])

Error in as.ts(x) : object 'ExoVars' not found


Model2<-auto.arima(ExogVars[1:5])


Error in auto.arima(ExogVars[1:5]) : No suitable ARIMA model found


Model2<-auto.arima(ExogVars[,1])

NewXReg<-forecast(Model2, h=12)

Forec<-forecast(Model1, newxreg=NewXReg)

Error in forecast.Arima(Model1, newxreg = NewXReg) :
  No regressors provided
In addition: Warning message:
In forecast.Arima(Model1, newxreg = NewXReg) :
  The non-existent newxreg arguments will be ignored.


Forec<-forecast(Model1, newxreg=NewXReg$mean)

Error in forecast.Arima(Model1, newxreg = NewXReg$mean) :
  No regressors provided
In addition: Warning message:
In forecast.Arima(Model1, newxreg = NewXReg$mean) :
  The non-existent newxreg arguments will be ignored.

I would like to generate the forecasts for all 4 variables included in
the Training set, along with all 5 regressors, but it seems like I can
only chose one training variable at a time, and one regressor at a time.

Please let me know if you can work this out,





structure(list(date = c("1994/Oct", "1994/Nov", "1994/Dec", "1995/Jan", 
"1995/Feb", "1995/Mar", "1995/Apr", "1995/May", "1995/Jun", "1995/Jul", 
"1995/Aug", "1995/Sep", "1995/Oct", "1995/Nov", "1995/Dec", "1996/Jan", 
"1996/Feb", "1996/Mar", "1996/Apr", "1996/May", "1996/Jun", "1996/Jul", 
"1996/Aug", "1996/Sep", "1996/Oct", "1996/Nov", "1996/Dec", "1997/Jan", 
"1997/Feb", "1997/Mar", "1997/Apr", "1997/May", "1997/Jun", "1997/Jul", 
"1997/Aug", "1997/Sep", "1997/Oct", "1997/Nov", "1997/Dec", "1998/Jan", 
"1998/Feb", "1998/Mar", "1998/Apr", "1998/May", "1998/Jun", "1998/Jul", 
"1998/Aug", "1998/Sep", "1998/Oct", "1998/Nov", "1998/Dec", "1999/Jan", 
"1999/Feb", "1999/Mar", "1999/Apr", "1999/May", "1999/Jun", "1999/Jul", 
"1999/Aug", "1999/Sep", "1999/Oct", "1999/Nov", "1999/Dec", "2000/Jan", 
"2000/Feb", "2000/Mar", "2000/Apr", "2000/May", "2000/Jun", "2000/Jul", 
"2000/Aug", "2000/Sep", "2000/Oct", "2000/Nov", "2000/Dec", "2001/Jan", 
"2001/Feb", "2001/Mar", "2001/Apr", "2001/May", "2001/Jun", "2001/Jul", 
"2001/Aug", "2001/Sep", "2001/Oct", "2001/Nov", "2001/Dec", "2002/Jan", 
"2002/Feb", "2002/Mar", "2002/Apr", "2002/May", "2002/Jun", "2002/Jul", 
"2002/Aug", "2002/Sep", "2002/Oct", "2002/Nov", "2002/Dec", "2003/Jan", 
"2003/Feb", "2003/Mar", "2003/Apr", "2003/May", "2003/Jun", "2003/Jul", 
&

Re: [R] [FORGED] filter correlation data

2017-01-31 Thread Rolf Turner


On 01/02/17 10:34, Elham - via R-help wrote:


hello everybody,I have a very very huge table in R from calculating
correlation,how can I filter it per spearman correlation and p-value
before export it,I mean what is the function that I use?I want to
select the pairs for value (r), , greater than 0.9 (directly
correlated) and less than -0.9 (inversely corerlated), and a p-value
< 0.001


I should say that I transformed the big matrix in a table by
library(reshape).


(a) In this instance it doesn't really matter, but *PLEASE* stop posting 
in HTML.


(b) It's not at all clear what the structure of your (table? matrix? 
data frame) is.  Please learn to be precise and explicit, otherwise it 
is difficult-to-impossible to provide useful advice.  (I.e. don't expect 
us to be mind-readers.)


Let us suppose (for the sake of saying *something* that might be 
helpful) that your correlations and p-values are stored in a data frame 
"X" as columns named "r" and "pval".


Then assign

ok <- with(X, (r < -0.9 | r > 0.9) & pval < 0.001)
Y  <- X[ok,]

Then export Y.

Really, if you are going to use R you should learn something about R.

cheers,

Rolf Turner

P.S.  Note that your p-value < 0.001 condition is redundant for any 
sample size greater than or equal to 7.


R. T.

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Export Forecasted output to a table (excel)

2017-02-01 Thread Rolf Turner

On 02/02/17 08:03, Lal Prasad wrote:

Hi All,

Is there any way to

1) Convert the below forecast to a datafram
2) Any way to write it to an excel table?


library(vars)
library(fpp)VARselect(usconsumption, lag.max = 3,
type="const")$selectionvar <- VAR(usconsumption, p=1,type =
"both",lag.max = 3)
serial.test(var, lags.pt = 3,type = "PT.asymptotic")

fcst <- forecast(var)


(1) Read the posting guide.

(2) In particular don't post in HTML.

(3) As it appears, your code makes no sense to me.

(4) DON'T use Excel.  Ever.  See:

http://www.stat.uiowa.edu/~jcryer/JSMTalk2001.pdf

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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: [FORGED] Export Forecasted output to a table (excel)

2017-02-01 Thread Rolf Turner

On 02/02/17 11:25, Daniel Nordlund wrote:

On 2/1/2017 2:05 PM, Rolf Turner wrote:

On 02/02/17 08:03, Lal Prasad wrote:

Hi All,

Is there any way to

1) Convert the below forecast to a datafram
2) Any way to write it to an excel table?


library(vars)
library(fpp)VARselect(usconsumption, lag.max = 3,
type="const")$selectionvar <- VAR(usconsumption, p=1,type =
"both",lag.max = 3)
serial.test(var, lags.pt = 3,type = "PT.asymptotic")

fcst <- forecast(var)


(1) Read the posting guide.

(2) In particular don't post in HTML.

(3) As it appears, your code makes no sense to me.

(4) DON'T use Excel.  Ever.  See:

 http://www.stat.uiowa.edu/~jcryer/JSMTalk2001.pdf

cheers,

Rolf Turner



Unfortunately, that link appears to be broken / does not exist anymore.



Thanks for pointing that out Dan.  The following rather messy link does 
seem to work. The line gets wrapped (at least it does in my mailer) so 
you may need to mess around copying and pasting.


https://www.google.co.nz/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwilxsmC_O_RAhVEmJQKHeTKDrkQFggYMAA&url=https%3A%2F%2Foit.utk.edu%2Fresearch%2Fdocumentation%2FDocuments%2FExcelStatProbs.pdf&usg=AFQjCNEocZnHA4b9_9FNxkD2lzHBA9EaNw

cheers,

Rolf

P.S.  See also:

http://www.burns-stat.com/documents/tutorials/spreadsheet-addiction/

R.

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Equality of two probabilities (proportions?)

2017-02-10 Thread Rolf Turner


On 10/02/17 21:12, mamuash bukana wrote:


Dear R users,
I wanted to test if there is significant difference between
probabilities of the same event calculated in different ways. I am
aware about the prop.test() which does the comparison between two
proportions given the number of successes and sample sizes. But in my
case the only values I do have are the probabilities the event.

Your kind suggestions will be very appreciated.


I think that it is pretty clear from your question that you are way out 
of your depth and that you do not understand the concept of "significant 
difference".


You should therefore seek help from a competent local statistician.

Although I could be wrong about my estimate of your depth of 
understanding, it is at the very least true that you need to read the 
posting guide carefully and learn how to ask a question that actually 
makes sense, includes necessary details, and gives list members a 
fighting chance of providing a meaningful answer.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Equality of two probabilities (proportions?)

2017-02-10 Thread Rolf Turner


On 11/02/17 00:27, mamuash bukana wrote:


Suppose we calculate probability of an event using Binomial
distribution and got p1. Then probability of that same event is
calculated using the Normal approximation to Binomial and got p2.
Can't we evaluate the goodness of our approximation by comparing the
difference between p1&p2? If yes, how to implement this in R?

I wouldn't have been here seeking for help if I had that "deep"
understanding of the issue under question Rolf!


In your original post you asked about whether the difference was 
"statistically significant".  As I suspected, the question is totally 
inappropriate.  The concept of "statistical significance" does not apply 
in this context.  There are no statistics; there are only calculations 
of probabilities.


As I said, you are out of your depth and need to learn the basics of the 
subject that you are trying to deal with.  Learn to walk before you try 
to run.  There are no short cuts to an understanding of probability and 
statistics.  A lot of hard graft is required.


Michael Dewey's suggestion of studying "scoring rules" or the "Brier 
score" might be useful to you, but you need to get the basic principles 
of the subject (probability and statistics) straight in your mind before 
you dive into these ideas.


As others have said, this issue is off topic for this list.

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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: remove

2017-02-11 Thread Rolf Turner


On 12/02/17 18:36, Bert Gunter wrote:

Basic stuff!

Either subscripting or ?subset.

There are many good R tutorials on the web. You should spend some
(more?) time with some.


Uh, Bert, perhaps I'm being obtuse (a common occurrence) but it doesn't 
seem basic to me.  The only way that I can see how to go at it is via

a for loop:

rdln <- function(X) {
# Remove discordant last names.
ok <- logical(nrow(X))
for(nm in unique(X$first)) {
xxx <- unique(X$last[X$first==nm])
if(length(xxx)==1) ok[X$first==nm] <- TRUE
}
Y <- X[ok,]
Y <- Y[order(Y$first),]
rownames(Y) <- 1:nrow(Y)
Y
}

Calling the toy data frame "melvin" rather than "df" (since "df" is the 
name of the built in F density function, it is bad form to use it as the 
name of another object) I get:


> rdln(melvin)
  first week last
1   Bob1 John
2   Bob2 John
3   Bob3 John
4  Cory1 Jack
5  Cory2 Jack

which is the desired output.  If there is a "basic stuff" way to do this
I'd like to see it.  Perhaps I will then be toadally embarrassed, but 
they say that this is good for one.


cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276


On Sat, Feb 11, 2017 at 9:02 PM, Val  wrote:

Hi all,
I have a big data set and want to  remove rows conditionally.
In my data file  each person were recorded  for several weeks. Somehow
during the recording periods, their last name was misreported.   For
each person,   the last name should be the same. Otherwise remove from
the data. Example, in the following data set, Alex was found to have
two last names .

Alex   West
Alex   Joseph

Alex should be removed  from the data.  if this happens then I want
remove  all rows with Alex. Here is my data set

df <- read.table(header=TRUE, text='first  week last
Alex1  West
Bob 1  John
Cory1  Jack
Cory2  Jack
Bob 2  John
Bob 3  John
Alex2  Joseph
Alex3  West
Alex4  West ')

Desired output

  first  week last
1 Bob 1   John
2 Bob 2   John
3 Bob 3   John
4 Cory 1   Jack
5 Cory 2   Jack


__
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: get() return nothing

2017-02-14 Thread Rolf Turner


On 14/02/17 05:50, Fix Ace via R-help wrote:


Well, I am not trying to print anything. I just would like to get the dimension 
information for all the dataframes I created. Could you please help me to 
develop the script?
Thanks.
Ace


Yes you *are* trying to print something.  You are trying to print the 
dimension information, i.e. dim(get(i))!!! For Pete's sake (a) *think* 
about what you are doing and (b) *try* example that Duncan suggested to you.


cheers,

Rolf Turner


On Saturday, February 11, 2017 7:53 PM, Duncan Murdoch 
 wrote:


 On 11/02/2017 1:33 PM, Fix Ace via R-help wrote:

Hello, there,
I wrote a loop to check the dimension of all the .txt dataframes:> ls()
  [1] "actualpca.table" "b4galnt2""b4galnt2.txt""data"
  [5] "galnt4"  "galnt4.txt"  "galnt5"  "galnt5.txt"
  [9] "galnt6"  "galnt6.txt"  "glyco"  "glyco.txt"
[13] "i"  "mtscaled""newsig.table""nicepca"
[17] "pca""sig.txt""st3gal3""st3gal3.txt"
[21] "st3gal5""st3gal5.txt""st6gal1""st6gal1.txt"

for(i in ls(pattern="txt")){dim(get(i))}


If I check individual ones, they are ok:

dim(get("galnt4.txt"))

[1] 8 3



could anyone help me to figure out why it did not work with a loop?
Thanks a lot!


It's the difference between

for (i in 1:10) i

(which prints nothing) and

for (i in 1:10) print(i)

Duncan Murdoch




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




--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Empirical k-quantile function

2017-02-17 Thread Rolf Turner

On 17/02/17 12:12, Art U wrote:

Hello,

Suppose I have one vector of values or even matrix of those vectors and I
want to calculate q_k(V/k), where V is the vector, k is a quantile and q_k
is empirical k-quantile function. Finally I want to calculate Q_k=min(1,
q_k) for k=(0,1).

Can you please help me with this code?
quantile function provides value

Basically I'm trying to reproduce results from paper "P-values for
High-Dimensional Regression", Meinshausen, Meier, Buhlmann.


Your question is IMHO vague and to my limited mental capacities, 
incomprehensible.  Please try to adhere to the R-help desideratum of 
providing (minimal) *reproducible* examples of whatever it is that you 
are trying to accomplish.  (This includes data, code, and the *desired* 
result that you are not at present able to obtain.


cheers,

Rolf Turner

P.S.  Are you familiar with the functions (a) quantile(), and
(b) apply()?  If not, become so!

R. T.


--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] help with grep list files

2017-02-20 Thread Rolf Turner

On 21/02/17 10:41, Glenn Schultz wrote:

All,

I have the following files in a directory and I would like only a list of those 
starting with “lld" and ending with “dat”.  I used the following and it gives 
me the lld files

 list.files(path = readpath, pattern = "^lld[A-Z0-9]")

to get just .dat files I tried

 list.files(path = readpath, pattern = "^lld[A-Z0-9].dat$”) but nothing is 
returned


below is a dput from the first command.  $ is an end of line anchor correct?  
What am I doing wrong?


Best,
Glenn

c("lld022017_AB7755_AS0038.dat", "lld022017_AS0039_AS5210.dat",
"lld022017_AS5211_AS7917.dat", "lld022017_AS7918_AT8661.dat",
"lld022017_AT8662_AW6667.dat", "lld022017_AW6668_AZ3066.dat",
"lld022017_AZ3067_BC9534.dat", "lld022017_BC9535_MA2230.dat",
"lld022017_MA2231_MB0288.dat", "lld022017.zip")


list.files(pattern="^lld.*\\.dat$")

seems to work for me.

cheers,

Rolf


--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Yates correction

2017-02-21 Thread Rolf Turner

On 21/02/17 23:47, Jomy Jose wrote:

 I tried to do chi square test for the following observed frequencies
-
   A  B
A  8  4
B 12 10

R gave the following output:
---
Pearson's Chi-squared test with Yates' continuity correction

data:  M
X-squared = 0.10349, df = 1, p-value = 0.7477

Warning message:
In chisq.test(M) : Chi-squared approximation may be incorrect

---
Whether this result can be relied or we have to use Fishers exact test ?


(a) With a p-value of 0.7477 there is no evidence against the null 
hypothesis no matter how you slice it.


(b) To assuage your trepidations, use "simulate.p.value=TRUE".

E.g.

   chisq.test(M,simulate.p.value=TRUE,B=)

Note that the value of X-squared that is returned is "of course" the 
same as what you'd get by setting correct=FALSE. I got a p-value of 
0.7178; you will get something slightly different, since a simulated 
p-value is random, but it will be about 0.71 or 0.72.


Bottom line:  Don't reject H_0!!!

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] function for remove white space

2017-02-21 Thread Rolf Turner

On 22/02/17 12:51, José Luis Aguilar wrote:

Hi all,

i have a dataframe with 34 columns and 1534 observations.

In some columns I have strings with spaces, i want remove the space.
Is there a function that removes whitespace from the entire dataframe?
I use gsub but I would need some function to automate this.


Something like

X <- as.data.frame(lapply(X,function(x){gsub(" ","",x)}))

Untested, since you provide no reproducible example (despite being told 
by the posting guide to do so).


I do not know what my idea will do to numeric columns or to factors.

However it should give you at least a start.

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] if and

2017-02-27 Thread Rolf Turner

On 28/02/17 14:47, Val wrote:

Currently I have  about  six or more  scripts that do the same job.  I
thought it might be possible and more efficient to use one script by using
IF ELSE statements. Here is an example but this will be expandable for
several countries ans year-months


Year-month = FEB2015, FEB2012,  Feb2010
 country  = USA, CAN.MEX
First I want to do if country = USA and year-month = FEB2015, FEB2012 do
the statements
second if country = CAN and year-month =Feb2010 do  the statements


if(country="USA" & year-month = "FEB2015" | "FEB2012" ){
statemnt1
.
statemnt10

} else if (country="USA" & year-month ="FEB2015") {
statemnt1
.
statemnt10
}

else
{
statemnt1
.
statemnt10
}

The above script did not work. is there a different ways of doing it?


Uh, yes.  Get the syntax right.  Use R, when you are using R.

Looking at ?Syntax and ?Logic might help you a bit.

Other than that, there's not much that one can say without seeing a 
reproducible example.  And if you sat down and wrote out a *reproducible 
example*, using correct R syntax, you probably wouldn't need any 
assistance from R-help.


Have you read any of the readily available R tutorials?  If not do so. 
If so, read them again and actually take note of what they say!


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] how to draw the confidence interval

2017-03-05 Thread Rolf Turner

On 04/03/17 19:39, laomeng_3 wrote:

hi all I have a question about drawing the confidence interval .

For instance,if I want to sample 100 times,and each time,the sample
size is 10,and the mean and sd is 15 and 1 respectively .I want to draw
the 100 confidence intervals(as the attachment) .Which function should
be used to draw the confidence interval ?


This list does not answer questions about homework.

(BTW, no attachment came through; only a *very* limited range of file 
types is permitted for attachments).


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] array - how to create "logical expression" for subset dynamically

2017-03-05 Thread Rolf Turner

On 04/03/17 06:59, exponential wrote:

Hi! I've tried on SO, but without success. Maybe you will be
able

to help. I have the following array (I use 3-dimensional in this example
for simplicity, but it can be 3+ dims - 10,11 or more): a <-
c('a1', 'a2', 'a3') b <- c('bb',
'bbb') c <- c('C', 'CC', 'CCC') dimNa
<- list('a' = a, 'b' = b, 'c' = c)
outputArray <- array(NA, unname(sapply(dimNa, function(x) length(x),
simplify = T)), unname(dimNa)) I can subset it using name from one
dimension manually, like: > outputArray[,'bb',] C CC CCC a1
NA NA NA a2 NA NA NA a3 NA NA NA or > outputArray[,,'CCC'] bb
bbb a1 NA NA a2 NA NA a3 NA NA I would like to write a function which
subsets particular named element from one dimension (I mean I don't
expect one dimension as a result by slicing using one named element, if
that makes sense). Something like myfunc <- function(inputArray,
namedElement) thus I can call it (using above example):
myfunc(outputArray, 'bb') or myfunc(outputArray, 'CCC')
to get identical as above results. I know how to deal with finding to
which dimension "namedElement" belongs (in my case all names are
unique). The question is how to subset it from the array? One idea is to
construct what is inside [ ] (in example: ,'bb', or
,,'CCC'). I've tried something like this: inputDims <-
",,'CCC'" outputArray[parse(text=inputDi But this
doesn't work. Maybe different approach should be used... Any ideas
are welcome:)! Cheers!


DO NOT post in HTML.  Your mail was an incomprehensible mess.

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] AED package

2017-03-05 Thread Rolf Turner

On 05/03/17 20:20, Ibrahim Salman wrote:

Dear all,

I am trying to run corvif command in R and apparently it needs AED package.
Does anyone know where can I find this package ?


Have you ever heard of "Google"?

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Error in curve 'expr' did not evaluate to an object of length 'n'

2017-03-05 Thread Rolf Turner

On 04/03/17 01:43, Allan Tanaka wrote:

Please help. I try to re-produce R-script by plotting a set of functionWhen i 
running code: plot(Vectorize(running.acf.max))it gets the error message like 
this: Error in curve(expr = x, from = from, to = to, xlim = xlim, ylab = ylab,  
:   'expr' did not evaluate to an object of length 'n'
Even though i have vectorized the function argument.


Your example is not reproducible.  We do not have the file 
EURJPY.m14401.csv.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] how to draw the confidence interval

2017-03-06 Thread Rolf Turner

On 06/03/17 19:35, laomeng_3 wrote:


this is not homework, just a case which I made by myself.


Be that as it may, if you are going to use R you should learn something 
about using R, rather than treating it as a magical black box.


There is, as far as I know (not really very far!) no currently existing 
function to "draw the confidence intervals".  (Well, actually there is 
probably one out there somewhere.  There is so *much* out there.  But 
finding it is probably more effort than rolling your own.)


It is actually very easy to roll your own --- I think I could do it in 5 
or 10 minutes.  But I am *NOT* going to.  (a) I am not going to do your 
work for you, even if it's not homework, and (b) you will *learn* 
something by figuring out how to do it yourself.


Hint:  Read up on the functions lines() and segments().  And maybe 
arrows().  The function abline() might be of use as well.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276


On 2017-03-06 06:47 , Rolf Turner <mailto:r.tur...@auckland.ac.nz> Wrote:

On 04/03/17 19:39, laomeng_3 wrote:
> hi all I have a question about drawing the confidence interval .
>
> For instance,if I want to sample 100 times,and each time,the sample
> size is 10,and the mean and sd is 15 and 1 respectively .I want to
draw
> the 100 confidence intervals(as the attachment) .Which function
should
> be used to draw the confidence interval ?

This list does not answer questions about homework.

(BTW, no attachment came through; only a *very* limited range of file
types is permitted for attachments).


__
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] Override/Insert (Change) a value (default value) inside a function

2017-03-11 Thread Rolf Turner

On 12/03/17 10:26, Mohammad Tanvir Ahamed via R-help wrote:

Hi!,

Lets I have a function form a package.
The function is,  as an example,

myplot <- function(x,y) { plot(x,y) }


Now I can use the function according to function's defined argument.

x<- sort(runif(200))
y<- 1:200
myplot(x,y)

Now I want to input extra argument or override default value of plot inside the 
function myplot.

If I use  myplot (x,y, col = "red", cex = 0.1 )  it does not work . I clearly 
understand , why it does not work .
But in this situation how can i solve the problem ?

I will be grateful if any one can help.
Thanks in advance !!


Learn about the "..." argument.  See e.g. section 10.4 of "An 
Introduction to R" (first item under R home page -> Documentation -> 
Manuals).


cheers,

Rolf Turner


--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Override/Insert (Change) a value (default value) inside a function

2017-03-11 Thread Rolf Turner

On 12/03/17 11:11, Mohammad Tanvir Ahamed wrote:

Thanks for reply.
as I said , the function in the package is like
myplot <- function(x,y) { plot(x,y) }

not like
myplot <- function(x,y) { plot(x,y,...) }

And I cant change the function inside the package!!

So , in this case how to solve the problem ?


As the problem is stated, you cannot solve it.

Depending on circumstances, there are various approaches that you could 
take.  One would be to get the package source, edit the "myplot" 
function so that it has a "..." argument, and then install the edited 
version.


Since we don't know your circumstances, nor what it is that you really 
need to accomplish (your description of the problem is very vague), it 
is difficult to make suggestions.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] same column name in a data frame

2017-03-13 Thread Rolf Turner

On 14/03/17 14:56, Jinsong Zhao wrote:

Hi there,

I happened to find the following code can generate a data frame with
same column name.


x <- data.frame(a=c(1,2,3))
y <- data.frame(a=c(2,3,4))
z <- cbind(x,y)


However, in this case, one can not use the $ to extract the second
column, right?

Is it possible to prevent the cbind() produce a data frame with same
column name?


No.

Why not either:

(a) Just make sure the names in "x" and "y" differ?

Or:

(b) Change the names of "z", e.g. names(z) <- c("clyde","irving")?

Or maybe names(z) <- make.unique(names(z)).

You could probably write a wrapper function for cbind() to automate (b) 
if you really want to.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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: Crete stats course

2017-03-15 Thread Rolf Turner

On 16/03/17 03:57, Bert Gunter wrote:

Perhaps this has been asked and settled before, but while such courses
certainly might be of interest to those who read this list, they are
for profit, and therefore advertising them here does seem somewhat
inappropriate.

Please, I don't want to start a long discussion or war. Just slap me
down if I am wrong about this.



I have a *vague* recollection that it *has* been asked before and that 
there was a consensus, or a pronouncement from R core (or a combination 
of the two; or something like that) that such announcements were OK as 
long as they were reasonably brief and not overly frequent.  Or 
something like that.


It seems to me that the Highland Statistics ads fall within these 
vaguely remembered guidelines.


cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] standard error for regression coefficients corresponding to factor levels

2017-03-16 Thread Rolf Turner


You have been posting to the R-help list long enough so that you should 
have learned by now *not* to post in html.  Your code is mangled so as 
to be unreadable.


A few comments:

(1) Your data frame "data1" seems to have a mysterious (and irrelevant?) 
column named "data1" as well.


(2) The covariance matrix of your coefficient estimates is indeed (as 
you hint) a constant multiple of (X^T X)^{-1}.  So do:


X <- model.matrix(~response*week,data=data1)
S <- solve(t(X)%*%X)
print(S)

and you will see the same pattern of constancy that your results exhibit.

(3) You could get the results you want much more easily, without all the
fooling around buried in your (illegible) code, by doing:

mod <- lm(response ~ (region - 1)/week,data=data1)
    summary(mod)

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

On 17/03/17 07:26, li li wrote:

Hi all,
  I have the following data called "data1". After fitting the ancova model
with different slopes and intercepts for each region, I calculated the
regression coefficients and the corresponding standard error. The standard
error (for intercept or for slope) are all the same for different regions.
Is there something wrong?
  I know the SE is related to (X^T X)^-1, where X is design matrix. So does
this happen whenever each factor level has the same set of values for
"week"?
 Thanks.
 Hanna




mod <- lm(response ~ region*week, data1)> tmp <- coef(summary(mod))> res <- matrix(NA, 5,4)> res[1,1:2] <- 
tmp[1,1:2]> res[2:5,1] <- tmp[1,1]+tmp[2:5,1]> res[2:5,2] <- sqrt(tmp[2:5,2]^2-tmp[1,2]^2)> res[1,3:4] <- 
tmp[6,1:2]> res[2:5,3] <- tmp[6,1]+tmp[7:10,1]> res[2:5,4] <- sqrt(tmp[7:10,2]^2-tmp[6,2]^2)



colnames(res) <- c("intercept", "intercept SE", "slope", "slope SE")> rownames(res) 
<- letters[1:5]> res   intercept intercept SEslope   slope SE

a 0.18404464   0.08976301 -0.018629310 0.01385073
b 0.17605666   0.08976301 -0.022393789 0.01385073
c 0.16754130   0.08976301 -0.022367770 0.01385073
d 0.12554452   0.08976301 -0.017464385 0.01385073
e 0.06153256   0.08976301  0.007714685 0.01385073








data1week region response

5  3  c  0.057325067
6  6  c  0.066723632
7  9  c -0.025317808
12 3  d  0.024692613
13 6  d  0.021761492
14 9  d -0.099820335
19 3  c  0.119559235
20 6  c -0.054456186
21 9  c  0.078811180
26 3  d  0.091667189
27 6  d -0.053400777
28 9  d  0.090754363
33 3  c  0.163818085
34 6  c  0.008959741
35 9  c -0.115410852
40 3  d  0.193920693
41 6  d -0.087738914
42 9  d  0.004987542
47 3  a  0.121332285
48 6  a -0.020202707
49 9  a  0.037295785
54 3  b  0.214304603
55 6  b -0.052346480
56 9  b  0.082501222
61 3  a  0.053540767
62 6  a -0.019182819
63 9  a -0.057629113
68 3  b  0.068592791
69 6  b -0.123298216
70 9  b -0.230671818
75 3  a  0.330741562
76 6  a  0.013902905
77 9  a  0.190620360
82 3  b  0.151002874
83 6  b  0.086177696
84 9  b  0.178982656
89 3  e  0.062974799
90 6  e  0.062035391
91 9  e  0.206200831
96 3  e  0.123102197
97 6  e  0.040181790
98 9  e  0.121332285
1033  e  0.147557564
1046  e  0.062035391
1059  e  0.144965770

[[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] Stratified random sample

2008-07-16 Thread Rolf Turner


On 17/07/2008, at 11:45 AM, lamack lamack wrote:



Dear all, I have two vector:
 strata response1   11   21   32   12   22   3.  ..  ..  .10  110   
210  3.  ..  ..  .100  1100  2100  3

I need to get a stratified random sample of size = 100, such that:
if I select response = 1 in strata 1 then I need sample 2 or 3 in  
strata 2


if I select response = 2 in strata 2 then I need to sample 1 or 3  
in strata 3
if I select response = 3 in strata 2 then I need to sample 1 or 2  
in strata 3

and so on. Please, how can I do this?


You really should do your own homework.

cheers,

Rolf Turner

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

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


Re: [R] Stratified random sample

2008-07-16 Thread Rolf Turner


On 17/07/2008, at 1:11 PM, Daniel Malter wrote:




Rolf, is he taking a course of yours? :)


No, I don't actually ``teach'' these days.  (If ever I did.)

It just looked like a homework problem to me.

Still does, actually.

cheers,

Rolf

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

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


Re: [R] Matching Up Values

2008-07-17 Thread Rolf Turner


On 18/07/2008, at 8:42 AM, Steve Murray wrote:



So what I'm looking to do is, 'pad out' the shorter file, by adding  
in the rows with those that are 'missing' from the longer file (ie.  
if a particular coordinate isn't present in the shorter file but is  
in the 'longer/master' file), and having 'zero' as its Population  
Density value (column C).


Aaarrghh!!! Zero is not the same as a missing value.
	Surely to gumdrops you should say ``having NA as its Population  
Density value''.


Elsewise you are lying about your data.


cheers,

Rolf Turner

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

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


Re: [R] asp and ylim

2008-07-20 Thread Rolf Turner


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


#See David Williams' book "Weighing the odds", p286

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

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


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


I just tried

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

and it seemed to give results as expected/desired.

cheers,

Rolf Turner


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

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


Re: [R] Editor fpr Mac OS

2008-07-21 Thread Rolf Turner


On 22/07/2008, at 5:39 AM, Angelo Scozzarella wrote:


Hi,
is there a good editor for Mac Os?


Yes; vi[m].

cheers,

Rolf Turner

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

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


Re: [R] Parameter names in nls

2008-07-21 Thread Rolf Turner


On 22/07/2008, at 3:49 AM, [EMAIL PROTECTED] wrote:


Dear R-help,

Could you please examine the following code, and see if I have  
discovered a bug or not, or am just doing something silly.


I am trying to create a package to do fish stock assessment using  
the nls() function to fit the modelled stock size to the various  
pieces of information that we have. The main problem with this sort  
of task is that the number and type of parameters that go into the  
model are highly variable between stocks, but the method needs to  
be "intelligent" enough to handle this. The way I have chosen to  
handle this is through the names in my parameter vector, and using  
code inside the objective function to figure out which parameter is  
which.


The problem I have encountered is that I don't think nls() always  
passes a named vector - indeed, after the first set of function  
evaluations, it drops the names from the parameters vector  
altogether. I believe this to be a bug - it certaintly plays havoc  
with my code!


As a demonstration of this problem, consider the piece of code  
below. It is basically fitting a straight line to some synthetic  
data (with noise). I have setup the objective function so that it  
prints the names of the parameters every time that it is called. As  
you can see, the names are there to begin with, but rapidly  
disappear after the first "step" is made.


Is this a bug? Or is it intended behaviour? Or is this a completely  
daft approach I am taking?


I think the latter.  You are simply not using nls correctly.  Try

fit <- nls(data.y ~ a + b*data.x, start=ips)

(and compare with the result of lm(data.y ~ data.x)).
cheers,

    Rolf Turner


I look forward to your comments.

cheers,

Mark



rm(list=ls())
fitting.fn <-function(x,params) {
 #The model - so that it works
 y <- params[1] + x*params[2]
 #How I would prefer it to work
#  y <- params["a"] + x*params["b"]

 #Display information about function eval
 cat(paste("Evaluation # :",counter,"\t Names :"))
 print(names(params))
 counter <<- counter +1
 return(y)
}
counter <<- 1

data.x <- 1:50
data.y <- pi*data.x + rnorm(50,sd=20)
plot(data.x,data.y)
ips <-  c(a=0,b=0)
nls("data.y~fitting.fn(data.x,params)",data=data.frame(data.x,data.y),
 start=list(params=ips),trace=TRUE,control=nls.control(tol=1e-8))

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

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



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

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


[R] Table of tables?

2008-07-21 Thread Rolf Turner


I have occasion to want to produce a ``table of tables''.  I.e. I have
a number of subjects; to each subject there corresponds a 4 x 5 table
of numbers.  I would like to arrange these tables into a (say) 4 x 4
array.  I would also like (said he, wistfully) to have each of these
16 tables in the array distinguished by a header identifying the  
``subject'';

a string of the form ``Subject xxx'', ``Subject yyy'' etc.

I could bind together my 16 tables into a 16 x 20 numerical matrix,  
output

this to a file, and then manually mark it up with the appropriate LaTeX
commands to get the effect I want.  But that would be a most tedious
experience  and since I have to do something like 12 or 15 of these,
it could take a while.

So I thought I'd ask if any of those clever people out there had written
functions that might produce such a table of tables.  Preferably with a
LaTeX filter at the end.

Are there such functions anywhere?  I have of course looked at the  
xtable

package and I can't see a facility for doing what I want.

cheers,

Rolf Turner

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

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


Re: [R] help with simulate AR(1) data

2008-07-22 Thread Rolf Turner


On 23/07/2008, at 7:52 AM, cathelf wrote:



Hi, sorry for bothering your guys again.
I want to simulate 100 AR(1) data with cor(x_t, x_t-1)=rho=0.3. The  
mean of
the first 70 data (x_1 to x_70) is 0 and the mean of the last 30  
data (x_71

to x_100) is 2. Can I do it in the following way?

x <- arima.sim(list=(ar=0.3), 100)
mean <- c(rep(0, 70), rep(2, 30))
xnew <- x+mean


If the above code to simulate 100 AR(1) data is right, what should  
I do if I
want to simulate 1000 independent group of this data? Each group  
contains
100 AR(1) data. So it is a matrix of 1000*100. Each row is a AR(1).  
I think
there should be a quicker way to do that? (the easies way is  
simulate ar(1)

1000 times, but it waste time, I think).


What else can you do?  To simulate 1000 independent realizations
of an AR(1) process you need to, uh, simulate 1000 independent
realizations of an AR(1) process.  Like.

For compact ***code*** you could write something like:

	junk <- matrix(unlist(lapply(1:1000,function(x){arima.sim(list 
(ar=0.3),100)+mean})),nrow=1000,byrow=TRUE)


(as long as ``mean'' is there in your global workspace).

This took 0.619 seconds on my Imac; not too much time wasted.

But by turning your results into a matrix, you lose the time series
attributes of your simulated series.  Are you sure you need a matrix?
You could simply create a *list* of length 1000, each entry of which
is a realization of an AR(1) process.  Just by doing:

junk <- lapply(1:1000,function(x){arima.sim(list(ar=0.3),100)+mean}))

Each entry of junk will be an object of class "ts" --- which might be
a Good Thing.

    cheers,

Rolf Turner



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

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


Re: [R] help with simulate AR(1) data

2008-07-22 Thread Rolf Turner


On 23/07/2008, at 9:50 AM, Peter Dalgaard wrote:


Rolf Turner wrote:
 matrix(unlist(lapply(1:1000,function(x){arima.sim(list(ar=0.3), 
100)+mean})),nrow=1000,byrow=TRUE)
Whatever did replicate() ever do to you to deserve getting so  
rudely ignored?


replicate(1000, arima.sim(list(ar=.3),100)) + mean

(OK, so t(...) then)


	Another of the many lacunae in my knowledge ... I'd either never  
learned

about, or had forgotten, replicate().

BTW --- to retain the time series nature of the results, you can do:

replicate(1000, arima.sim(list(ar=.3),100) + mean, simplify=FALSE)

cheers,

Rolf

P. S. Just occurred to me --- ``mean'' is a Bad Name for a mean  
vector, since
there is a function called ``mean''.  No disasters imminent, but it's  
a bad

policy.

R.

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

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


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

2008-07-22 Thread Rolf Turner


On 23/07/2008, at 10:03 AM, José Augusto Jr. wrote:



I'm writing this message to encourage people migrating to Ubuntu. W$ e
M$  are shit.


Such language in a young gentleman!!!  I agree, but.

I'm also amazed that your message got past the censorious
censoring program ``mailmarshal'' which all too vigilantly
guards the email threshold at my institution.

cheers,

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


This e-mail has been scanned and cleared by MailMarshal 
www.marshalsoftware.com

##

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


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

2008-07-22 Thread Rolf Turner


On 23/07/2008, at 10:54 AM, José Augusto Jr. wrote:


My apologies,

I used an improper language in my last email.  My sincere apologies
for anyone that became offended.


I certainly wasn't offended!  I was kidding.  Sorry if I
sounded as if I were criticizing you.

cheers,

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


This e-mail has been scanned and cleared by MailMarshal 
www.marshalsoftware.com

##

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


Re: [R] Coefficients of Logistic Regression from bootstrap - how to get them?

2008-07-22 Thread Rolf Turner


On 23/07/2008, at 1:17 PM, Frank E Harrell Jr wrote:


Michal Figurski wrote:

Hmm...
It sounds like ideology to me. I was asking for technical help. I  
know what I want to do, just don't know how to do it in R. I'll go  
back to SAS then. Thank you.

--
Michal J. Figurski


You don't understand any of the theory and you are using techniques  
you don't understand and have provided no motivation for.  And you  
are the one who is frustrated with others.  Wow.


	Come off it guys.  It is indeed very frustrating when one asks ``How  
can I do X''
	and gets told ``Don't do X, do Y.''  It may well be the case that  
doing X is
	wrong-headed, misleading, and may cause the bridge to fall down, or  
the world to
	come to an end.  Fair enough to point this out --- but then why not  
just tell

the poor beggar, who asked, how to do X?

	The only circumstance in which *not* telling the poor beggar how to  
do X is
	justified is that in which it takes considerable *work* to figure  
out how to
	do X.  In this case it is perfectly reasonable to say ``I think  
doing X is
	stupid so I am not going to waste my time figuring out for you how  
to do it.''


	I don't know enough about the bootstrapping software (don't know  
*anything*
	about it actually) to know whether the foregoing circumstance  
applies here.
	But I suspect it doesn't.  And I suspect that you (Frank) could tell  
Michal in
	a few lines the answer to the question that he *asked* (as opposed,  
possibly,

to the question that he should have asked).

	If it were my problem I'd just write my own bootstrapping function  
to apply
	to the problem in hand.  It can't be that hard ... just a for loop  
and a

call to sample(...,replace=TRUE).

If you can write macros in SAS then .

cheers,

Rolf

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

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


Re: [R] how can I write code to detect whether the machine is Windows or Linux?

2008-07-23 Thread Rolf Turner


On 24/07/2008, at 9:53 AM, Philip James Smith wrote:


Hi R-People:

I use 2 machines: a machine with a Windows XP operating system, and  
another with a Linux Ubuntu OS. I transport my code between these 2  
machines. However, pathnames to data files always need to be  
"adjusted" to account for the OS that I'm working on.


Here is my question:

How do I write code to detect whether I'm using the XP or the Linux  
machine?


If I knew this, I could write my code in a way so that I didn't  
have to adjust path names to data file all the time.


I checked the archives... didn't find anything, but perhaps didn't  
know the right search terms...


The help for ``version'' says to use .Platform$OS.type
to check what platform the code is running on.

    cheers,

Rolf Turner

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

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


Re: [R] Dividing by 0

2008-07-24 Thread Rolf Turner


On 25/07/2008, at 5:24 AM, Robert Baer wrote:



I'm trying to calculate the percent change for a time-series  
variable.

Basically the first several observations often look like this,

x <- c(100, 0, 0, 150, 130, 0, 0, 200, 0)

and then later in the life of the variable they're are generally  
no more
0's.  So when I try to calculate the percent change from one  
observation to
the next, I end up with a lot of NA/Nan/INF, and sometimes 0's  
which is what

I want, in the beginning.

I know I can use x <- na.omit(x), and other forms of this, to get  
rid of
some of these errors.  But I would rather use some kind of  
function that
would by defult give a 0 while dividing by zero so that I don't  
lose the

observation, which is what happens when I use na.omit.



Well, this is not an error but proper behavior in the world of math  
that I know.


However, to get what you want you could try
x=(100-0)/0
if(!is.finite(x))x=0
x


The foregoing response exemplifies what I think is the ***RIGHT*** way
to answer wrong-headed questions on this list.  ``What you want to do
makes no sense, but if you insist on doing it, here's how.''

To my mind, wanting the result of division by zero to be zero *in  
general*
is nothing short of idiotic.  But if someone wants to impose this  
convention

in his or her own calculations, well that's their ``democratic right''.
And Robert Baer clearly and succinctly (and more tactfully than I) makes
this clear.

A similar style of response would have been appropriate in respect of  
the

fooferaw that has been going on, on this mailing list on the topic of
``Coefficients of Logistic Regression from bootstrap - how to get  
them?''


cheers,

Rolf Turner

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

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


Re: [R] Should this PDF render correctly without font embedding?

2008-07-24 Thread Rolf Turner


On 25/07/2008, at 8:29 AM, Jeffrey Horner wrote:

A professor here at Vanderbilt sent me the following code. Each of  
the text strings should right justify against the center vertical  
bar, but because of font issues it doesn't. I understand that there  
are workarounds, but I was just curious if this was consistent  
across all platforms. On linux with R 2.7.1 and R-trunk (r46103),  
both acrobat reader 8 and kpdf render it incorrectly. How about Mac  
or Windows? Is this a platform config issue, or something else?


pdf('temp.pdf', width=11, height=8.5)
plot(0,0,xlim=c(0,1),ylim=c(0,1),type='n')
abline(v=.5)
# pos=2 is for right-alignment
text(0.5,0.9, 'Yo', pos=2)
text(0.5,0.8, 'Yo Yo', pos=2)
text(0.5,0.7, 'Yo Yo Yo', pos=2)
text(0.5,0.6, 'Yo Yo Yo Yo', pos=2)
text(0.5,0.5, 'Yo Yo Yo Yo Yo', pos=2)
text(0.5,0.4, 'Yo Yo Yo Yo Yo Yo', pos=2)
text(0.5,0.3, 'Yo Yo Yo Yo Yo Yo Yo', pos=2)
dev.off()


Did a quick check on my Imac --- both Preview and Adobe Reader render  
the
result incorrectly; the text string encroach increasingly upon the  
vertical
line as the number of ``Yo's'' increases.  It renders fine on the on- 
screen

X11 device.

Session info:

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

locale:
C

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

other attached packages:
[1] misc_0.0-4 fortunes_1.3-4 MASS_7.2-41

cheers,

Rolf Turner

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

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


Re: [R] still more dumb questions

2008-07-24 Thread Rolf Turner


On 25/07/2008, at 9:58 AM, Edna Bell wrote:


Hello.

When I type in "median", I get the following:


median

function (x, na.rm = FALSE)
UseMethod("median")





How do I look at the code, please?


It seems that median() is ``generic'' (although with only one --- the  
default --- ``method''.


Typing ``methods(median)'' shows this.

Typing ``median.default'' shows you the code for this default  
``method''.


cheers,

Rolf Turner

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

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


Re: [R] simple random number generation

2008-07-24 Thread Rolf Turner


Duncan Murdoch recently (24 July 2008) posted code providing a much more
elegant and efficient approach.  (Subject line:  truncated normal). Also
there is apparently a function in the msm package which will do this  
for you.


cheers,

Rolf Turner

On 25/07/2008, at 2:43 PM, jim holtman wrote:


Generate more than you need and then just keep 500 of them:


x <- rnorm(3000)  # make sure we have enough
y <- x[(x > -1.5) & (x < 1.5)][1:500]  # keep 500 0f them
hist(y)



On Thu, Jul 24, 2008 at 7:35 PM, dxc13 <[EMAIL PROTECTED]>  
wrote:


useR's,

I want to randomly generate 500 numbers from the standard normal
distribution, i.e. N(0,1), but I only want them to be generated in  
the range

-1.5 to 1.5.  Does anyone have a simple way to do this?

Thanks,

dxc13
--
View this message in context: http://www.nabble.com/simple-random- 
number-generation-tp18642611p18642611.html

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

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

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





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

What is the problem you are trying to solve?

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

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



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

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


[R] Mixed model question.

2008-07-27 Thread Rolf Turner


I continue to struggle with mixed models.  The square zero version
of the problem that I am trying to deal with is as follows:

A number (240) of students are measured (tested; for reading  
comprehension)

on 6 separate occasions.  Initially (square zero) I want to treat the
test time as a factor (with 6 levels).  The students are of course
``random effects''.  Later I want to look at reduced models, with the
means at the 6 times following patterns:

(mu1, mu2, mu2, mu3, mu3, mu4)

or

(mu1, mu1+theta, mu1+theta, mu1+2*theta, mu1+2*theta, mu1+3*theta)

the idea begin that the tests are given ``in pairs'' at the beginning  
and

end of the school year.  Progress is expected over the school year, no
progress over the two intervening summers.  The summers fall between
times 2 and 3 and between times 4 and 5.  The second of the two models
assumes a constant amount of progress (``theta'') in each of three
school years in which the students are observed.

But the square zero model is just a trivial repeated measures model.

The estimate of the means at the 6 observation times is just
mu-hat = xbar <- apply(X,2,mean) where X is the ``data matrix'',
and the estimate of the covariance structure is just given by
Sigma-hat = S <- var(X).

No problem so far.  I can also fit the two reduced models (I'm pretty
sure) via maximum likelihood, using optim(), for example.  Assuming
normal data.  Rash assumption, but that's not the issue here.

But the thing is, I also want (later!) to include such things as
a school effect (there are 6 different schools), a sex effect, and
an ethnicity effect.

Things start to get complicated --- sounds like a job for lmer().

So I'd just like to get a toe in the door by fitting the trivial
(square 0) model with lmer() --- and then if I can get my head
around that, move on to the two reduced models.  I.e. I'd like to
reproduce my simple-minded computations using lmer() --- which would
give me a little bit of confidence that I'm driving lmer() correctly.

*Can* the trivial model be fitted in lmer()?  I tried using

fit <- lmer(y ~ tstnum + (1|stdnt), data=schooldat)

and got estimates of the coefficients for tstnum as follows:

Fixed effects:
Estimate Std. Error t value
(Intercept)  3.229170.09743   33.14
tstnum2  0.466670.084615.52
tstnum3  0.50.084615.91
tstnum4  0.837500.084619.90
tstnum5  0.470830.084615.56
tstnum6  0.975000.08461   11.52

The mean of (the columns of) the data matrix is

3.229167 3.695833 3.729167 4.07 3.70 4.204167

which is in exact agreement with the lmer() results when converted to
the same parameterization (mu_i = mu + alpha_i, with alpha_1 = 0).

(Notice the surprizing, depressing, and so far unexplained *drop*
in the response over the second summer.)

What I *don't* understand is the correlation structure of the estimates
produced by lmer(), which is:

Correlation of Fixed Effects:
(Intr) tstnm2 tstnm3 tstnm4 tstnm5
tstnum2 -0.434
tstnum3 -0.434  0.500
tstnum4 -0.434  0.500  0.500
tstnum5 -0.434  0.500  0.500  0.500
tstnum6 -0.434  0.500  0.500  0.500  0.500

So apparently the way I called lmer() places substantial constraints
on the covariance structure.  How can I (is there any way that I can)
tell lmer() to fit the most general possible covariance structure?

As usual, advice, insight, tutelage humbly appreciated.

If anyone wishes to experiment with the real data set (it's a bit
too big to post here) I can make it available to them via email.

Thanks.

cheers,

Rolf Turner


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

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


Re: [R] Converting english words to numeric equivalents

2008-07-27 Thread Rolf Turner


On 28/07/2008, at 12:32 PM, oscar Linares wrote:


Hello,

I am trying to convert english words to numeric equivalents, e.g.,  
abc to 123. Is there a function or library or package for doing  
this in R? If not, can it be done easily in R?


Your question is very ill-posed.  What ``english word'' would  
correspond to 0?

What would the ``english word'' xyz (?!?!) correspond to?

If you can phrase a coherent question, it can probably be answered.

cheers,

    Rolf Turner

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

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


Re: [R] read.table question

2008-07-27 Thread Rolf Turner


On 28/07/2008, at 3:26 PM, Edna Bell wrote:


Dear R list:

I have a data set that I would like to bring it.  The fourth column
shows as numeric, but I want it to be a factor.  Is there a way to do
this from the read.table statement, or should I just wait and use the
factor function please?


Look at the colClasses argument to read.table().

cheers,

Rolf Turner

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

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


<    1   2   3   4   5   6   7   8   9   10   >