Re: [R] source file for rnorm

2010-12-20 Thread David Winsemius


On Dec 20, 2010, at 5:40 PM, Yue Zhang wrote:


Dear Sir/Madam:

I am sorry if this is a simple question. I have downloaded the  
source code for R but could not find the source file that has the  
rnorm function definition. Could you please let me know which file  
has the function? Also, in general, how do I find the source file of  
a given function?


Uwe Ligges. R Help Desk: Accessing the sources. R News, 6(4):43-45,  
October 2006


http://cran.r-project.org/doc/Rnews/Rnews_2006-4.pdf



Thanks.

Yue Zhang, CFA
Cohen & Steers Capital Management, Inc.
280 Park Ave., 10th Floor


David Winsemius, MD
West Hartford, CT

__
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] install.packages() - old version deleted, new version did not install

2010-12-20 Thread Duncan Murdoch
I've just tentatively put code to fix this in place in R-devel.  By 
default it is not enabled, because if it goes wrong it could really mess 
things up.  To enable it, set


options(install.lock=TRUE)

before installing or updating binary packages in Windows.  It will slow 
down all installs, so it may be that the default should stay no-locking 
as it is now:  only people running multiple instances of R really need this.


Since it appealed to my sense of symmetry, you can also say

options(install.lock=FALSE)

which will mean that source installs done by install.packages() will 
default to act like R CMD INSTALL --unsafe, i.e. go ahead without 
locking.  The latter change affects all platforms, not just Windows.


You should be able to download R-devel builds containing this change by 
tomorrow; look for revision r53875 or newer.


Duncan Murdoch

On 17/12/2010 11:13 AM, Jon Olav Skoien wrote:

Dear list,

(R 2.12.0, Windows 7, 64bit)

I recently tried to install a new package ("spacetime"), that depends on
"sp" among others. I already had the last one installed, but there was
probably a newer version on CRAN, so the command
  >  install.packages("spacetime")
also gave me:
also installing the dependencies ‘sp’, ‘zoo’, ‘xts’

sp was already loaded in this session, so installation failed:
package 'sp' successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package 'sp'

Unfortunately, the warning should rather say:
"cannot completely remove prior installation of package 'sp'"
R managed to remove most of the prior installation of sp, except for the
.dll. I could go on using sp in the existing sessions, but not load the
package in a new session or open the help pages. This has happened to me
several times, and the only solution I have found to this is to close
all R-sessions and install the package again. This is normally ok, but
this time I had some long-time computations running in another R-session
that I did not want to interrupt. For the next time, is there a way to
reinstall a package without interrupting running R-sessions?

For me it seems like the cause of the problem could have been solved by
checking if the .dll can be removed before removing the rest of the
package, by adding something like the following in utils:::unpackPkgZip?
if (unlink(paste(instPath,"/libs/x64/sp.dll", sep = "")) != 0)
warning("cannot remove...")
before
ret<- unlink(instPath, recursive = TRUE) (line 95)
x64 in the path would have to be changed to something architecture
dependent...

Best wishes,
Jon

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


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


Re: [R] package "arules" - 'transpose' of the transactions

2010-12-20 Thread Kohleth Chia
Just found 'ngCMatrix' class, it must be the way to go?



-
Message: 47Date: Mon, 20 Dec 2010 17:41:20 +1100
From: Kohleth Chia 
To: r-help@r-project.org
Subject: [R] package "arules" - 'transpose' of the transactions
Message-ID:
   

>
Content-Type: text/plain

Suppose this is my list of transactions:



set.seed(200)

3)
tran=random.transactions(100,

inspect(tran)

 itemstransactionID
1 {item80}trans1
2 {item8,
  item20}trans2
3 {item28}trans3



I want to get the 'transpose' of the data, i.e.

 transactionID  items
1 {trans2}item8
2 {trans2}item20
3 {trans3}item28
4 {trans1}item80



I tried converting tran into a matrix, then transpose it, then convert it
back to transactions. But my dataset is actually very very large, so I
wonder if there is any faster method?

Thanks

--
KC

   [[alternative HTML version deleted]]

[[alternative HTML version deleted]]

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


[R] logistic regression or not?

2010-12-20 Thread array chip
Hi, I have a dataset where the response for each person on one of the 2 
treatments was a proportion (percentage of certain number of markers being 
positive), I also have the number of positive & negative markers available for 
each person. what is the best way to analyze this kind of data?

I can think of analyzing this data using glm() with the attached dataset:

test<-read.table('test.txt',sep='\t')
fit<-glm(cbind(positive,total-positive)~treatment,test,family=binomial)
summary(fit)
anova(fit, test='Chisq')

First, is this still called logistic regression or something else? I thought 
with logistic regression, the response variable is a binary factor?

Second, then summary(fit) and anova(fit, test='Chisq') gave me different p 
values, why is that? which one should I use?

Third, is there an equivalent model where I can use variable "percentage" 
instead of "positive" & "total"?

Finally, what is the best way to analyze this kind of dataset where it's almost 
the same as ANOVA except that the response variable is a proportion (or success 
and failure)?

Thanks

John



  "treatment" "total" "positive"  "percentage"
"1" "exposed"   11  4   0.363636363636364
"2" "exposed"   10  4   0.4
"3" "exposed"   9   4   0.444
"4" "exposed"   7   4   0.571428571428571
"5" "exposed"   7   4   0.571428571428571
"6" "exposed"   6   5   0.833
"8" "exposed"   12  7   0.583
"9" "exposed"   8   5   0.625
"10""exposed"   13  12  0.923076923076923
"11""exposed"   10  5   0.5
"12""control"   10  1   0.1
"13""control"   11  2   0.181818181818182
"14""control"   8   0   0
"16""control"   12  1   0.0833
"15""control"   8   0   0
"17""control"   10  1   0.1
"18""control"   10  1   0.1
"19""control"   8   1   0.125
"20""control"   8   0   0
"21""control"   9   1   0.111
"22""control"   10  1   0.1
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Filter data

2010-12-20 Thread AlexZolot

You missed the first, the most important line of str() output.
What type is your data?
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Filter-data-tp3070069p3108011.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Plot a matrix recursively

2010-12-20 Thread AlexZolot

for data.frame: for(j in grep('Laser_', names(m)) lines(m[,j]) 

for matrix: for(j in grep('Laser_', colnames(m)) lines(m[,j]) 


or:   for(j in 2:4) lines(m[,j]) 


Shorter could be worse if you insert additional columns later.



alcesgabbo wrote:
> 
> Hi,
> 
> I have the following matrix (named m):
> key
>  sensor_date  Laser_1  Laser_2
>   
> Laser_3
>   2010-09-30T15:00:12+020063  
>  
> 1
>   2010-10-31T15:05:07+010054  
>  
> 2
>   2011-09-30T15:00:12+020063  
>  
> 1
>   2011-10-31T15:05:07+010054  
>  
> 2
> 
> I plot the first column with the following function:
> plot(m[,1],type="o", xaxt="n",ylim=c(min(m[,1:length(colnames(m))])-1,
> max(m[,1:length(colnames(m))])+1))
> 
> for the other columns I use there functions:
> 
> lines(m[,2],type=\"o\")
> 
> lines(m[,3],type=\"o\")
> 
> ok, it works.
> 
> But is there a way to do this prodcedures recursively??
> 
> for example:
> 
> for each columns {
>  lines(m[,column],type=\"o\")
> }
> 
> I try with :
> 
> lines(m[,2:length(colnames(m))],type=\"o\")
> 
> but it doesn't work.
> 
> Thanks .
> Alberto
> 

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Plot-a-matrix-recursively-tp3067283p3106392.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] source file for rnorm

2010-12-20 Thread Yue Zhang
Dear Sir/Madam:

I am sorry if this is a simple question. I have downloaded the source code for 
R but could not find the source file that has the rnorm function definition. 
Could you please let me know which file has the function? Also, in general, how 
do I find the source file of a given function?

Thanks.

Yue Zhang, CFA
Cohen & Steers Capital Management, Inc.
280 Park Ave., 10th Floor
New York, NY 10017
Tel: (212)796-9370
Fax: (212)319-8238
Email: yzh...@cohenandsteers.com



The information transmitted is only for the intended recipient and may contain 
confidential, privileged, copyrighted, or otherwise restricted material. It may 
not be reproduced or retransmitted without permission. If you have received 
this in error, please contact the sender, delete this transmission and dispose 
of any printed material as your review, retransmission, dissemination or other 
use of, or taking any action in reliance upon, this information is not 
authorized and may be prohibited by law. Cohen & Steers may review and retain 
this message and any addressed to its sender. Opinions or views herein do not 
necessarily reflect those of Cohen & Steers, Inc., its subsidiaries, or 
affiliates.

[[alternative HTML version deleted]]

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


Re: [R] plot more plots from one matrix

2010-12-20 Thread AlexZolot

See  library(reshape)
-- 
View this message in context: 
http://r.789695.n4.nabble.com/plot-more-plots-from-one-matrix-tp3069545p3107761.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Plot a matrix recursively

2010-12-20 Thread AlexZolot

for data.frame:  for(j in grep('Laser_', names(m)) lines(m[,j])

for matrix:  for(j in grep('Laser_', colnames(m)) lines(m[,j])

or

for(j in 2:4) lines(m[,j])

Shorter could be worse if you insert additional columns  later.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Plot-a-matrix-recursively-tp3067283p3106041.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

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


Re: [R] R.matlab memory use

2010-12-20 Thread Stefano Ghirlanda
Hi,
The data set is indeed highly redundant, mostly zeros (which means I
could use sparse matrices, but that's another issue). I have posted an
octave ascii file here:

http://dl.dropbox.com/u/4000198/freq.txt

and a .mat file here:

http://dl.dropbox.com/u/4000198/freq.mat


>    A few more questions about what's going on: it makes sense that
> your ASCII format file is about 75 M (i.e., 10x larger than mine);
> presumably your data set is highly redundant so that it can be compressed
> to 300Kb?
>   Any chance you can post your data somewhere, or figure out a way
> to generate a sample data set that is similar (i.e. starts at about
> 75 M and compresses to 300Kb when saved appropriately in octave)?
>
>
>  Ben Bolker

-- 
Stefano Ghirlanda
www.intercult.su.se/~stefano - drghirlanda.wordpress.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] .Rd file for S4-method warning

2010-12-20 Thread Duncan Murdoch

On 20/12/2010 5:18 PM, Mark Heckmann wrote:

Dear R users,

I want to create a proper .Rd file for the show method for an S4 class.
I am encountering problems in the \usage{} line, I guess. An example:

setClass("testClass",
 representation(a="character"))

setMethod("show", "testClass", function(object){
})


The .Rd file:

\name{show,-method}
\alias{show,testClass-method}
\alias{show}
\title{Show method for testClass...}
\usage{\S4method{show}{testClass}(object)
}
\description{Show method for testClass}
\arguments{\item{testClass}{object}
}

CHECK says:
* checking Rd \usage sections ... WARNING
Undocumented arguments in documentation object 'show,-method'
  object

What would be a correct \usage line? Writing R extensions says:
\S4method{generic}{signature_list}(argument_list)


That's okay, the warning is about the fact that you didn't document 
object in the \arguments section.


You had

\item{testClass}{object}

but you should have had

\item{object}{some description of what object is}

As yours was written, it's documentation for the "testclass" argument, 
which doesn't exist.



What am I doing wrong?
It works though if I simply delete the \usage line.
Unfortunately I use roxygen and the line is created automatically,
so I need to create it properly.


Does roxygen also create the argument?  Looks like a bug or limitation 
(I seem to recall that roxygen doesn't support S4, or didn't in the past...)


Duncan Murdoch



Thanks in advance,
Mark
–––
Mark Heckmann
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.com






[[alternative HTML version deleted]]




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


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


[R] .Rd file for S4-method warning

2010-12-20 Thread Mark Heckmann
Dear R users,

I want to create a proper .Rd file for the show method for an S4 class.
I am encountering problems in the \usage{} line, I guess. An example:

setClass("testClass",
representation(a="character"))

setMethod("show", "testClass", function(object){
})


The .Rd file:

\name{show,-method}
\alias{show,testClass-method}
\alias{show}
\title{Show method for testClass...}
\usage{\S4method{show}{testClass}(object)
}
\description{Show method for testClass}
\arguments{\item{testClass}{object}
}

CHECK says:
* checking Rd \usage sections ... WARNING
Undocumented arguments in documentation object 'show,-method'
 object

What would be a correct \usage line? Writing R extensions says:
\S4method{generic}{signature_list}(argument_list)
What am I doing wrong?
It works though if I simply delete the \usage line.
Unfortunately I use roxygen and the line is created automatically,
so I need to create it properly.

Thanks in advance,
Mark
–––
Mark Heckmann
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.com






[[alternative HTML version deleted]]

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


Re: [R] R Code and the Pygments Python SyntaxHighlighter

2010-12-20 Thread Liviu Andronic
(reviving from the grave)

On Thu, Mar 27, 2008 at 5:44 PM, Hans W. Borchers  wrote:
> is someone going to write a R/S language lexer for the Pygments Python syntax
> highlighter ? As it is used now by Trac, Django, or the
> Python documentation tool Sphinx, the R community can apply it in Python-based
> Wikis like Moinmoin and others.
>
I was once again [0] looking for some solution to automatic syntax
highlighting (or input/output colouring) in a bare bones R terminal
and I've stumbled on both Pygments and this thread. Current Pygemnts
fancies [1] support for both S and R.

Is anyone aware of any progress in this direction? Perhaps some R
interface to Pygments? Regards
Liviu

[0] http://www.mail-archive.com/r-help@r-project.org/msg86512.html
[1] http://pygments.org/languages/

__
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] finding and opening C source called from R functions.

2010-12-20 Thread Duncan Murdoch

On 20/12/2010 3:56 PM, Peter Langfelder wrote:

On Mon, Dec 20, 2010 at 12:48 PM, Chiquoine, Ben  wrote:
>  Hi,
>
>  As will soon be very clear I'm an R novice.  I'm trying to better understand the ks.test 
function in the stats package.  When I look at the source code there are several calls to C 
functions (for example .C("pkstwo", is.integer(length(x[IND])), p=as.double(x[IND]), 
as.double(tol), PACKAGE = "stats)$P).  I'm wondering if there is a way to view the source 
code for the underlying C functions?  I googled a post which said to open ks.c to see the source 
code but I can't find that file anywhere on my hard drive or on the web.  Any suggestions would 
be greatly appreciated.

Go to cran.r-project.org, find the package stats, download the tar.gz
bundle, unpack it (on a linux command line, you can type tar -xvzf
stats*.tar.gz), then navigate to the directory stats/src and look at
the source code in the directory.



In many cases that will work, but not in this one:  stats is a base 
package, so there is no tar.gz bundle.


See Uwe Ligges' article in R News on how to find source in general.  It's in

http://cran.r-project.org/doc/Rnews/Rnews_2006-4.pdf

and I think it is all still current.

Duncan Murdoch

__
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] Sine Regression in R

2010-12-20 Thread David Winsemius


On Dec 20, 2010, at 3:01 PM, Paolo Rossi wrote:


Hi everyone,

I am trying to fit a sine function on one year of wind data. I have  
two

questions below.

Looking around on the net I managed to get the following:

Sine Equation: y = a + b * sin( c + d*x )

b is the amplitude, c is the phase shift, d is something deal with
periodicty of data*.*

This can be linearised by   sin( c+dx ) = cos(c) * sin(dx) + sin(c) *
cos(dx).

If one calls dx = x1

y = a + b * sin( c + d*x )
y = a + b * [cos(c) * sin(x1) + sin(c) * cos(x1)]
y = a +  b * cos(c) * sin(x1) + b * sin(c) * cos(x1)
y = a +  b1 * sin(x1) + b2 * cos(x1)

where b1 = b * cos(c) and  b2 =  b * sin(c)

This works fine for me as I am not interested in the value for b and  
c. By
trial and error I also detemined that the sensibel value for d is  
1/58. I

have 366 days of data and want to fit a single sine onto it.

*First question*: 1/ 58 = (2 pi) / 366. I guess 366 is the period of  
my

data, I have 366 days. so *d = (2 pi) / Period*. Is this correct.
*Second question*: I reckon that all of this looks very DIY. Is  
there a

better way to do this in R? Maybe through a package I dont know?


The package "circular" might be a candidate.




Thanks in advance

Paolo




David Winsemius, MD
West Hartford, CT

__
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] finding and opening C source called from R functions.

2010-12-20 Thread Peter Langfelder
On Mon, Dec 20, 2010 at 12:48 PM, Chiquoine, Ben  wrote:
> Hi,
>
> As will soon be very clear I'm an R novice.  I'm trying to better understand 
> the ks.test function in the stats package.  When I look at the source code 
> there are several calls to C functions (for example .C("pkstwo", 
> is.integer(length(x[IND])), p=as.double(x[IND]), as.double(tol), PACKAGE = 
> "stats)$P).  I'm wondering if there is a way to view the source code for the 
> underlying C functions?  I googled a post which said to open ks.c to see the 
> source code but I can't find that file anywhere on my hard drive or on the 
> web.  Any suggestions would be greatly appreciated.

Go to cran.r-project.org, find the package stats, download the tar.gz
bundle, unpack it (on a linux command line, you can type tar -xvzf
stats*.tar.gz), then navigate to the directory stats/src and look at
the source code in the directory.

__
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] finding and opening C source called from R functions.

2010-12-20 Thread Chiquoine, Ben
Hi,

As will soon be very clear I'm an R novice.  I'm trying to better understand 
the ks.test function in the stats package.  When I look at the source code 
there are several calls to C functions (for example .C("pkstwo", 
is.integer(length(x[IND])), p=as.double(x[IND]), as.double(tol), PACKAGE = 
"stats)$P).  I'm wondering if there is a way to view the source code for the 
underlying C functions?  I googled a post which said to open ks.c to see the 
source code but I can't find that file anywhere on my hard drive or on the web. 
 Any suggestions would be greatly appreciated.

Thanks in advance,

Ben

___
This message and any attached documents contain
information which may be confidential, subject to 
privilege or exempt from disclosure under applicable
law. These materials are solely for the use of the 
intended recipient. If you are not the intended 
recipient of this transmission, you are hereby 
notified that any distribution, disclosure, printing, 
copying, storage, modification or the taking of any
action in reliance upon this transmission is strictly
prohibited. Delivery of this message to any person
other than the intended recipient shall not
compromise or waive such confidentiality, privilege
or exemption from disclosure as to this 
communication. 

If you have received this communication in error, 
please notify the sender immediately and delete
this message from your system. 

[[alternative HTML version deleted]]

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


Re: [R] sample() issue

2010-12-20 Thread Petr Savicky
On Mon, Dec 20, 2010 at 01:04:18PM -0600, cory n wrote:
> > length(sample(25000, 25000*(1-.55)))
> [1] 11249
> 
> > 25000*(1-.55)
> [1] 11250

Besides FAQ 7.31, look also at
  http://rwiki.sciviews.org/doku.php?id=misc:r_accuracy
for further examples and hints concerning rounding errors
in simple situations.

Petr Savicky.

__
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] RExcel doesn't get active dataset

2010-12-20 Thread jryan . daniels
Hey everyone

When I try to 'get active dataframe' from the context menu in excel using Rcmdr 
menus in excel, only the header and first row of data gets copied to the excel 
spread sheet. No clue why this is happening. I followed the instructions from 
'R through Excel' pg 25-26. I'm using excel 2010, Rcmdr v 1.6-0 and R 2.11.1. 

Much appreciate any help


Sent via my BlackBerry from Vodacom - let your email find you!

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


Re: [R] Metafor package

2010-12-20 Thread Viechtbauer Wolfgang (STAT)
Dear Mario,

1) Whether to use 1/2* or not is arbitary. It's just a multiplicative constant.

2) vi <- 1/(4*ni + 2)

If one leave off the 1/2* part, then it would be vi <- 1/(ni + 1/2).

3) Yes, but it takes a bit more work. Fortunately, the same issue was raised 
not very long ago, so the following post should essentially answer your 
question:

https://stat.ethz.ch/pipermail/r-help/2010-December/263286.html

Best,

--
Wolfgang Viechtbauer
Department of Psychiatry and Neuropsychology
School for Mental Health and Neuroscience
Maastricht University, P.O. Box 616
6200 MD Maastricht, The Netherlands
Tel: +31 (43) 368-5248
Fax: +31 (43) 368-8689
Web: http://www.wvbauer.com


Original Message
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of petre...@unina.it Sent: Monday, December 20, 2010 13:26
To: r-help@r-project.org
Subject: [R] Metafor package

> I have some question about metafor package.
>
> I'm interest to perform a random effect meta-analysis of proportion
> (single group summary of prevalence of disease in a population as
> reported by different study)
> It ask:
> 1. "PFT":  The Freeman-Tukey double arcsine transformed proportion is
> reported to be equal to 1/2*(asin(sqrt(xi/(ni+1))) +
> asin(sqrt((xi+1)/(ni+1. Hovewer, i also found the same formula but
> without 1/2*.
>
> 2. how "vi", the corresponding (estimated) sampling variance is
> calculated? (i.e. the formula used to estimate "vi")
>
> 3. it is possible to return a forest plot with the backtransformed
> value of proportion, confidenc interval and weight and not with the
> transformed value after performing rma.uni?
>
> Many thanks
>
> Mario Petretta
> Dipartimento di Medicina Clinica Scienze Cardiovascolari e Immunologiche
> Facoltà di Medicina e Chirurgia
> Università di Napoli Federico II
> 081 - 7462233
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] breaking an inner loop in R

2010-12-20 Thread Berend Hasselman


kayj wrote:
> 
> Hi All,
> 
> is there a way to break an inner loop in R? for example
> 
>  for ( i in 1: 100){
> 
> if ( condition){
> break
> }
> 
> }
> 
> I have search and I have seen exampels where they add a semicolon after
> "break",  do I need to do that? Also when I type "?break" in R in returns
> nothing on this command?
> thanks for your help
> 

?"break"

Also see section 3.2.2 of the R language manual (R-lang.pdf, version 2.12.0)

Berend
-- 
View this message in context: 
http://r.789695.n4.nabble.com/breaking-an-inner-loop-in-R-tp3095607p3096109.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Sine Regression in R

2010-12-20 Thread Dennis Murphy
Hi:

Try using package sos to address your question re which packages perform
sine/trig regression:

library(sos)
findFn('sine regression')# 12 matches on my system
findFn('trigonometric regression')  # 9 matches

The results point largely to the mFilter, oce, circStats and circular
packages. It's a place to start...

HTH,
Dennis

On Mon, Dec 20, 2010 at 12:01 PM, Paolo Rossi <
statmailingli...@googlemail.com> wrote:

> Hi everyone,
>
> I am trying to fit a sine function on one year of wind data. I have two
> questions below.
>
> Looking around on the net I managed to get the following:
>
> Sine Equation: y = a + b * sin( c + d*x )
>
> b is the amplitude, c is the phase shift, d is something deal with
> periodicty of data*.*
>
> This can be linearised by   sin( c+dx ) = cos(c) * sin(dx) + sin(c) *
> cos(dx).
>
> If one calls dx = x1
>
> y = a + b * sin( c + d*x )
> y = a + b * [cos(c) * sin(x1) + sin(c) * cos(x1)]
>  y = a +  b * cos(c) * sin(x1) + b * sin(c) * cos(x1)
>  y = a +  b1 * sin(x1) + b2 * cos(x1)
>
> where b1 = b * cos(c) and  b2 =  b * sin(c)
>
> This works fine for me as I am not interested in the value for b and c. By
> trial and error I also detemined that the sensibel value for d is 1/58. I
> have 366 days of data and want to fit a single sine onto it.
>
> *First question*: 1/ 58 = (2 pi) / 366. I guess 366 is the period of my
> data, I have 366 days. so *d = (2 pi) / Period*. Is this correct.
>  *Second question*: I reckon that all of this looks very DIY. Is there a
> better way to do this in R? Maybe through a package I dont know?
>
>
> Thanks in advance
>
> Paolo
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] Sine Regression in R

2010-12-20 Thread Paolo Rossi
Hi everyone,

I am trying to fit a sine function on one year of wind data. I have two
questions below.

Looking around on the net I managed to get the following:

Sine Equation: y = a + b * sin( c + d*x )

b is the amplitude, c is the phase shift, d is something deal with
periodicty of data*.*

This can be linearised by   sin( c+dx ) = cos(c) * sin(dx) + sin(c) *
cos(dx).

If one calls dx = x1

y = a + b * sin( c + d*x )
y = a + b * [cos(c) * sin(x1) + sin(c) * cos(x1)]
 y = a +  b * cos(c) * sin(x1) + b * sin(c) * cos(x1)
 y = a +  b1 * sin(x1) + b2 * cos(x1)

where b1 = b * cos(c) and  b2 =  b * sin(c)

This works fine for me as I am not interested in the value for b and c. By
trial and error I also detemined that the sensibel value for d is 1/58. I
have 366 days of data and want to fit a single sine onto it.

*First question*: 1/ 58 = (2 pi) / 366. I guess 366 is the period of my
data, I have 366 days. so *d = (2 pi) / Period*. Is this correct.
 *Second question*: I reckon that all of this looks very DIY. Is there a
better way to do this in R? Maybe through a package I dont know?


Thanks in advance

Paolo

[[alternative HTML version deleted]]

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


Re: [R] sample() issue

2010-12-20 Thread Viechtbauer Wolfgang (STAT)
Trying to make the fastest referal to FAQ 7.31 is becoming quite a sport around 
here. David beat us all to it on this round. Chances are there will be many 
more rounds to come.

Best,

Wolfgang

Original Message
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Jorge Ivan Velez Sent: Monday, December 20, 2010 20:42
To: cory n
Cc: R mailing list
Subject: Re: [R] sample() issue

> Hi Cory,
>
> Check out
> http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f
>
> HTH,
> Jorge
>
>
> On Mon, Dec 20, 2010 at 2:04 PM, cory n <> wrote:
>
>>> length(sample(25000, 25000*(1-.55)))
>> [1] 11249
>>
>>> 25000*(1-.55)
>> [1] 11250
>>
>>> length(sample(25000, 11250))
>> [1] 11250
>>
>>> length(sample(25000, 25000*.45))
>> [1] 11250
>>
>> So the question is, why do I get 11249 out of the first command and not
>> 11250?  I can't figure this one out.
>>
>> Thanks
>>
>> Cory

__
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] Passing parameter to a function

2010-12-20 Thread William Dunlap
> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Luca Meyer
> Sent: Monday, December 20, 2010 11:03 AM
> To: Duncan Murdoch
> Cc: R-help@r-project.org
> Subject: Re: [R] Passing parameter to a function
> 
> Hi Duncan,
> 
> Yes, A and B are columns in D. Having said that I and trying to avoid 
> 
> tab(D$A,D$B)
> 
> and I would prefer:
> 
> tab(A,B)
> 
> Unfortunately the syntax you suggest is giving me the same error:
> 
> Error in eval(expr, envir, enclos) : object "A" not found

You didn't show what you did, but Duncan's suggestion
works for me when it is in a function:

> f0 <- function (a, b) {
aExpr <- substitute(a)
bExpr <- substitute(b)
formula <- substitute(time ~ e1 + e2, list(e1 = aExpr, e2 = bExpr))
xtabs(formula, data = D)
}
> D <- data.frame(time=2^(0:9),A=rep(1:2,each=5),B=rep(11:13,c(3,3,4)))
> z <- f0(A, B)
> print(z)
   B
A11  12  13
  1   7  24   0
  2   0  32 960
> xtabs(time~A+B, data=D)
   B
A11  12  13
  1   7  24   0
  2   0  32 960

The main problem with f0() is that the call attribute of
xtabs' output is always xtabs(formula=formula, data=D).
If you want the formula expanded to its value you have to
do more tricks.  E.g., use call() and eval() to pass
some arguments by value and some by name:

f1 <- function (a, b) {
aExpr <- substitute(a)
bExpr <- substitute(b)
formula <- substitute(time ~ e1 + e2, list(e1 = aExpr, e2 = bExpr))
# pass formula by value and D by name
theCall <- call("xtabs", formula, data = quote(D))
# may have to use enclos= argument to get D from right place
eval(theCall)
}

or use substitute a fourth time to patch up the call
attribute:

f2 <- function (a, b) {
aExpr <- substitute(a)
bExpr <- substitute(b)
formula <- substitute(time ~ e1 + e2, list(e1 = aExpr, e2 = bExpr))
retval <- xtabs(formula, data = D)
attr(retval, "call") <- do.call("substitute", list(attr(retval, 
"call"), list(formula = formula)))
retval
}


  > z <- f2(A,B) # f0 does the same
  > attr(z, "call")
  xtabs(formula = time ~ A + B, data = D)
  > z
 B
  A11  12  13
1   7  24   0
2   0  32 960

 
> I have tried to add some deparse() but I have got the error 
> over again. The last version I have tried:
> 
> function(x,y){
> z <- substitute(time ~ x + y, list(x = 
> deparse(substitute(x)), y = deparse(substitute(y
> xtabs(z, data=D)
> 
> gives me another error:
> 
> Error in terms.formula(formula, data = data) : 
>   formula models not valid in ExtractVars 

Look at what 'z' is in the above:
  > g <- 
  + function(x,y){
  + z <- substitute(time ~ x + y, list(x = 
  + deparse(substitute(x)), y = deparse(substitute(y
  + z
  + }
  > print(g(A,B))
  time ~ "A" + "B"
The strings "A" and "B" don't make sense there.  They need
to be names (a.k.a. "symbols").  Remove the calls to deparse()
and it will work.


Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  


> Any idea on how I should modify the function to make it work?
> 
> Thanks,
> Luca
> 
> 
> Il giorno 20/dic/2010, alle ore 19.28, Duncan Murdoch ha scritto:
> 
> > On 20/12/2010 1:13 PM, Luca Meyer wrote:
> >> I am trying to pass a couple of variable names to a xtabs formula:
> >> 
> >> >  tab<- function(x,y){
> >> xtabs(time~x+y, data=D)
> >> }
> >> 
> >> But when I run:
> >> 
> >> >  tab(A,B)
> >> 
> >> I get:
> >> 
> >> Error in eval(expr, envir, enclos) : object "A" not found
> >> 
> >> I am quite sure that there is some easy way out, but I 
> have tried with different combinations of deparse(), 
> substitute(), eval(), etc without success, can someone help?
> > 
> > I assume that A and B are columns in D?  If so, you could use
> > 
> > tab(D$A, D$B)
> > 
> > to get what you want.  If you really want tab(A,B) to work, 
> you'll need to do messy work with substitute, e.g. in the tab 
> function, something like
> > 
> > fla <- substitute(time ~ x + y, list(x = substitute(x), y = 
> substitute(y))
> > xtabs(fla, data=D)
> > 
> > Duncan Murdoch
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

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


Re: [R] Complicated nls formula giving singular gradient message

2010-12-20 Thread Bert Gunter
Jared:

You realize, of course, that just because you get estimates of the
parameters from the software is no guarantee that the estimates mean
anything? Nor does it mean that they mean nothing, I hasten to add.
If, as one might suspect, the model is overparameterized, the
estimates may be so imprecise that they are effectively useless -- but
the fitted values may nevertheless (__Especially__ if
overarameterized) fit your data very well. The model just won't fit
future data. In other words, you may have a well-fitting,
scientifically meaningless model.

Cheers,
Bert

On Mon, Dec 20, 2010 at 10:26 AM, Jared Blashka  wrote:
> Though my topic is slightly old already, I feel that it is necessary to post
> an update on my situation.
> I ended being able to estimate the parameters for this problem without
> having to worry as much about initial parameter estimates using AD Model
> Builder.
> It calculates the exact gradient using automatic differentiation so it's
> able to avoid the singular gradient problem nls can give.
>
> I also used the R package PBSadmb, which allowed me to run AD Model Builder
> and retrieve the results from within R. Then I could do what I liked with
> the results: generate graphs, more analysis, etc.
>
> Thanks to everyone who helped,
>
> Jared
>
> On Wed, Dec 15, 2010 at 8:47 AM, dave fournier  wrote:
>
>> Jared Blashka wrote:
>>
>> Hi,
>>
>> Can you write a little note to the R list saying something like
>>
>>   Re: SOLVED    [R] Complicated nls formula giving singular gradient
>> message
>>
>>  I was able to estimate the parameters for this problem using AD Mode
>> Builder which calculates
>>  the exact gradient for you using automatic differentiation and is thus
>> able to avoid the singular gradient
>> problem I encountered in nls.
>>
>> That way other R users who might be able to take advantage of the software
>> will hear about it.
>>
>>      Cheers,
>>
>>       Dave
>>
>>
>>
>>
>>> Dave,
>>>
>>> That's exactly what I was looking for!
>>>
>>> Thanks for all your help!
>>> Jared
>>>
>>> On Tue, Dec 14, 2010 at 7:13 AM, dave fournier >> da...@otter-rsch.com>> wrote:
>>>
>>>    Jared Blashka wrote:
>>>
>>>    The source code for that is in jared.tpl
>>>
>>>    I changed from least squares to a concentrated likelihood so that you
>>>    could get estimated std devs via the delta method.  they are in
>>>    jared.std
>>>    I rescaled the parameters so that the condition number of the
>>>    Hessian is close to 1.
>>>    You can see the eigenvalues of the Hessian in jared.eva.
>>>    Your data are in jared.dat and the initial parameter values are in
>>>    jared.pin.
>>>
>>>    The parameter estimates with their estiamted std devs are:
>>>
>>>    index   name   value      std dev
>>>       1   NS     1.1254e-02 7.1128e-03
>>>       2   LogKi -8.8933e+00 8.2411e-02
>>>       3   LogKi -5.2005e+00 9.2179e-02
>>>       4   LogKi -7.2677e+00 7.7047e-02
>>>       5   BMax   2.1226e+05 5.1699e+03
>>>    ~                                            How does it look?
>>>
>>>     Cheers,
>>>       Dave
>>>
>>>
>>>
>>>
>>>        Dave - AD Model Builder looks like a great tool that I can
>>>        use, but I'm curious if it can also perform global parameter
>>>        estimations across multiple data sets.
>>>
>>>        In regards to the example I have provided, I have two similar
>>>        data sets that also need to be analyzed, but the values for NS
>>>        and BMax between the three data sets should be the same. Each
>>>        data set has a unique LogKi value however. In R, I
>>>        accomplished this by merging the three data sets and adding an
>>>        additional field for each data point that identified which set
>>>        it was originally from. Then in the regression formula I
>>>        specified the LogKi term as a vector: LogKi[dset]. The results
>>>        of the regression gave me one value each for NS and BMax, but
>>>        three LogKi values. I haven't had much time to look through
>>>        the AD Model Builder documentation yet, but are you aware if
>>>        such an analysis method is possible?
>>>
>>>        Here's one such example of a data set
>>>
>>>        all <-structure(list(X = c(-13, -11, -10, -9.5, -9, -8.5, -8,
>>>        -7.5, -7, -6.5, -6, -5, -13, -11, -10, -9.5, -9, -8.5, -8,
>>>        -7.5, -7, -6.5, -6, -5, -13, -11, -10, -9.5, -9, -8.5, -8,
>>>        -7.5, -7, -6.5, -6, -5, -13, -11, -10, -9.5, -9, -8.5, -8,
>>>        -7.5, -7, -6.5, -6, -5, -13, -11, -10, -9.5, -9, -8.5, -8,
>>>        -7.5, -7, -6.5, -6, -5, -13, -11, -10, -9.5, -9, -8.5, -8,
>>>        -7.5, -7, -6.5, -6, -5, -13, -11, -10, -9.5, -9, -8.5, -8,
>>>        -7.5, -7, -6.5, -6, -5, -13, -11, -10, -9.5, -9, -8.5, -8,
>>>        -7.5, -7, -6.5, -6, -5), Y = c(3146L, 3321L, 2773L, 2415L,
>>>        2183L, 1091L, 514L, 191L, 109L, 65L, 54L, 50L, 3288L, 3243L,
>>>        2826L, 2532L, 2060L, 896L, 517L, 275L, 164L, 106L, 202L, 53L,
>>>        3146L, 3502L, 2658L, 3038L, 3351L,

Re: [R] How to optimize function parameters?

2010-12-20 Thread Jonathan P Daily
If you can somehow add the sign of the output to the root square error, 
nlm, nlminb, and many options within optimx accept bounds.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
"Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it."
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 12/20/2010 01:13:53 PM:

> [image removed] 
> 
> Re: [R] How to optimize function parameters?
> 
> zbynek.jano...@gmail.com 
> 
> to:
> 
> r-help
> 
> 12/20/2010 02:35 PM
> 
> Sent by:
> 
> r-help-boun...@r-project.org
> 
> 
> Thanks for your suggestions, I will certainly look at that
> 
> To answer your question...
> I can calculate root square error between empirical data a those 
predicted
> by model (I used this to optimize the parameters using gafit()).
> 
> -- 
> View this message in context: http://r.789695.n4.nabble.com/How-to-
> optimize-function-parameters-tp3095603p3095938.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] sample() issue

2010-12-20 Thread Jorge Ivan Velez
Hi Cory,

Check out
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

HTH,
Jorge


On Mon, Dec 20, 2010 at 2:04 PM, cory n <> wrote:

> > length(sample(25000, 25000*(1-.55)))
> [1] 11249
>
> > 25000*(1-.55)
> [1] 11250
>
> > length(sample(25000, 11250))
> [1] 11250
>
> > length(sample(25000, 25000*.45))
> [1] 11250
>
> So the question is, why do I get 11249 out of the first command and not
> 11250?  I can't figure this one out.
>
> Thanks
>
> Cory
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] sample() issue

2010-12-20 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of cory n
> Sent: Monday, December 20, 2010 11:04 AM
> To: r-help@r-project.org
> Subject: [R] sample() issue
> 
> > length(sample(25000, 25000*(1-.55)))
> [1] 11249
> 
> > 25000*(1-.55)
> [1] 11250
> 
> > length(sample(25000, 11250))
> [1] 11250
> 
> > length(sample(25000, 25000*.45))
> [1] 11250
> 
> So the question is, why do I get 11249 out of the first command and not
> 11250?  I can't figure this one out.
> 
> Thanks
> 
> Cory

See FAQ 7.31

Then try

>.45 == (1-.55)

Hope this is helpful,

Dan


Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204

__
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] sample() issue

2010-12-20 Thread Peter Langfelder
On Mon, Dec 20, 2010 at 11:04 AM, cory n  wrote:
>> length(sample(25000, 25000*(1-.55)))
> [1] 11249
>
>> 25000*(1-.55)
> [1] 11250
>
>> length(sample(25000, 11250))
> [1] 11250
>
>> length(sample(25000, 25000*.45))
> [1] 11250
>
> So the question is, why do I get 11249 out of the first command and not
> 11250?  I can't figure this one out.

Let me make a wild guess:

> floor(25000*(1-.55))
[1] 11249
> 25000*(1-.55)
[1] 11250
> 25000*(1-.55) - 11250
[1] -1.818989e-12
> 25000*0.45 - 11250
[1] 0


I'm guessing that the machine representation of 0.55 is off by
something like 1e-16, which gets
multiplied by a lot (25000) and this is enough for the floor (or
whatever rounding the internal code uses) to make it 11249. The morale
of the story is do not multiply non-exact numbers by huge constants or
you may get small inaccuracies.

Peter

__
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] sample() issue

2010-12-20 Thread Viechtbauer Wolfgang (STAT)
See FAQ 7.31: 
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

And try this:

25000*(1-.55) - 11250

25000*.45 - 11250

Notice a difference?

Best,

--
Wolfgang Viechtbauer
Department of Psychiatry and Neuropsychology
School for Mental Health and Neuroscience
Maastricht University, P.O. Box 616
6200 MD Maastricht, The Netherlands
Tel: +31 (43) 368-5248
Fax: +31 (43) 368-8689
Web: http://www.wvbauer.com


Original Message
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of cory n Sent: Monday, December 20, 2010 20:04
To: r-help@r-project.org
Subject: [R] sample() issue

>> length(sample(25000, 25000*(1-.55)))
> [1] 11249
>
>> 25000*(1-.55)
> [1] 11250
>
>> length(sample(25000, 11250))
> [1] 11250
>
>> length(sample(25000, 25000*.45))
> [1] 11250
>
> So the question is, why do I get 11249 out of the first command and not
> 11250?  I can't figure this one out.
>
> Thanks
>
> Cory
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] After heteroskedasticity correction, how can I get new confidential interval?

2010-12-20 Thread Achim Zeileis

On Mon, 20 Dec 2010, JoonGi wrote:



First of all, thanks for your guide!

Let me be more specific, here.

Using
data(Housing) from Ecdat library

I ran a regression
raw.model<-lprice~llot+lbed+lbath+lsto+factor(driveway)+factor(recroom)+factor(fullbase)+factor(gashw)+factor(airco)+factor(prefarea)+factor(garagepl)
coeftest(lm(raw.model))

and I got heteroskedasticity in significant level 5% such as below.
bptest(lm(raw.model))

So, I corrected like this.
sqrt(diag(hccm(lm(raw.model),type="hc1")))

This gave me the corrected std.errors.


From this moment, I want to test whether my parameters are individually  and

jointly significant since the new std.error will change
coeftest(lm(raw.model))'s t, p and F value.

Then, How can I get these new t, p, F? Is there any R command for this?


You can team up coeftest() with other "vcov" functions, such as hccm() 
from "car" or vcovHC() from the "sandwich" package. Actually, there is an 
example on ?coeftest for the latter.


Also, there are various worked examples in

  vignette("sandwich", package = "sandwich")

Best,
Z


--
View this message in context: 
http://r.789695.n4.nabble.com/After-heteroskedasticity-correction-how-can-I-get-new-confidential-interval-tp3095643p3095852.html
Sent from the R help mailing list archive at Nabble.com.

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



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


Re: [R] Passing parameter to a function

2010-12-20 Thread Bert Gunter
Duncan's solution works for me. I strongly suspect that you have not
read the Help file for xtabs carefully enough. Does the "time" column
in D consist of a vector of counts?

> A <- factor(c("A","A","B","B"))

>  B <- factor(c(1,2,1,2))

>  D <- data.frame(A,B)
>  D$time <- c(10,12,14,16)

> tab(A,B)
   B
A1  2
  A 10 12
  B 14 16

-- Bert


On Mon, Dec 20, 2010 at 11:02 AM, Luca Meyer  wrote:
> Hi Duncan,
>
> Yes, A and B are columns in D. Having said that I and trying to avoid
>
> tab(D$A,D$B)
>
> and I would prefer:
>
> tab(A,B)
>
> Unfortunately the syntax you suggest is giving me the same error:
>
> Error in eval(expr, envir, enclos) : object "A" not found
>
> I have tried to add some deparse() but I have got the error over again. The 
> last version I have tried:
>
> function(x,y){
>    z <- substitute(time ~ x + y, list(x = deparse(substitute(x)), y = 
> deparse(substitute(y
>    xtabs(z, data=D)
>
> gives me another error:
>
> Error in terms.formula(formula, data = data) :
>  formula models not valid in ExtractVars
>
> Any idea on how I should modify the function to make it work?
>
> Thanks,
> Luca
>
>
> Il giorno 20/dic/2010, alle ore 19.28, Duncan Murdoch ha scritto:
>
>> On 20/12/2010 1:13 PM, Luca Meyer wrote:
>>> I am trying to pass a couple of variable names to a xtabs formula:
>>>
>>> >  tab<- function(x,y){
>>>     xtabs(time~x+y, data=D)
>>> }
>>>
>>> But when I run:
>>>
>>> >  tab(A,B)
>>>
>>> I get:
>>>
>>> Error in eval(expr, envir, enclos) : object "A" not found
>>>
>>> I am quite sure that there is some easy way out, but I have tried with 
>>> different combinations of deparse(), substitute(), eval(), etc without 
>>> success, can someone help?
>>
>> I assume that A and B are columns in D?  If so, you could use
>>
>> tab(D$A, D$B)
>>
>> to get what you want.  If you really want tab(A,B) to work, you'll need to 
>> do messy work with substitute, e.g. in the tab function, something like
>>
>> fla <- substitute(time ~ x + y, list(x = substitute(x), y = substitute(y))
>> xtabs(fla, data=D)
>>
>> Duncan Murdoch
>
> __
> 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.
>



-- 
Bert Gunter
Genentech Nonclinical Biostatistics

__
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] sample() issue

2010-12-20 Thread David Winsemius


On Dec 20, 2010, at 2:04 PM, cory n wrote:


length(sample(25000, 25000*(1-.55)))

[1] 11249


25000*(1-.55)

[1] 11250


length(sample(25000, 11250))

[1] 11250


length(sample(25000, 25000*.45))

[1] 11250

So the question is, why do I get 11249 out of the first command and  
not

11250?  I can't figure this one out.


Read the FAQ:
> 25000*(1-.55)-11250
[1] -1.818989e-12
> 25000*(1-.55)< 11250
[1] TRUE

?round
?all.equal
?zapsmall





--

David Winsemius, MD
West Hartford, CT

__
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] performance issue with merge

2010-12-20 Thread Maxim
Hi,

I'm trying to merge a couple of matrices together. The matrices are created
from a couple of input files that have very similar (but not in all cases)
values in first and second column. 1st and 2nd column are used to generate
rownames, the actually interesting value is in column 3. I'd like to merge
the different files by the rownames generated from 1st and 2nd column. Files
look like this:

ID1  100  3.14
ID1  200  2.71
ID1  300  0.92
...
ID2 100  2.45
.


etc. (sorry, I do not know how to create such files/ matrices with R
commands).

Some files do not have the full range of values in the second column, but I
don't want to loose any values during the merge. As far as I understood it I
have to merge using the all.x and all.y directives which appears to be
related to the outer join of relational dbs. This would give me something
like:

ID1_100  3.14  1.56  3.45
ID1_200  2.71   NA   1.34
ID1_300  0.92   1.22  NA
...


Merging works as long I do not set the all.x and all.y directive in the
merge command:


DF <- data.frame(NULL)

count=0

filenames <- list.files()

filenames

for(i in filenames) {

count<-count+1

tmp <- read.delim(i, header=FALSE)

rwnames <- paste(tmp[,1], tmp[,2], sep="_")

 tmp<-tmp[,3]

tmp<-as.matrix(tmp)

rownames(tmp)<-rwnames

if (count == 1) {

DF <- tmp

 } else {

DF <- merge(DF, tmp, by="row.names",all.x = TRUE, all.y = TRUE)

rownames(DF)<-DF$Row.names

DF<-DF[,2:ncol(DF)]

}

}


As soon as I set the all directives the script runs forever without any
effect (files sizes: a couple of million lines per file). Is it expected,
that this type of merge takes so much longer (I think it never finishes!)?
Or do I have a conceptual problem with how merge works?


Maxim


P.S.: I'd be really happy in case I receive comments how to make my easy
parsing problem a bit more straight forward in terms of how the code looks
like!

[[alternative HTML version deleted]]

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


Re: [R] How to optimize function parameters?

2010-12-20 Thread zbynek.jano...@gmail.com

Thanks for your suggestions, I will certainly look at that

To answer your question...
I can calculate root square error between empirical data a those predicted
by model (I used this to optimize the parameters using gafit()).

-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-optimize-function-parameters-tp3095603p3095938.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] sample() issue

2010-12-20 Thread cory n
> length(sample(25000, 25000*(1-.55)))
[1] 11249

> 25000*(1-.55)
[1] 11250

> length(sample(25000, 11250))
[1] 11250

> length(sample(25000, 25000*.45))
[1] 11250

So the question is, why do I get 11249 out of the first command and not
11250?  I can't figure this one out.

Thanks

Cory

[[alternative HTML version deleted]]

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


Re: [R] After heteroskedasticity correction, how can I get new confidential interval?

2010-12-20 Thread JoonGi

First of all, thanks for your guide!

Let me be more specific, here.

Using
data(Housing) from Ecdat library

I ran a regression
raw.model<-lprice~llot+lbed+lbath+lsto+factor(driveway)+factor(recroom)+factor(fullbase)+factor(gashw)+factor(airco)+factor(prefarea)+factor(garagepl)
coeftest(lm(raw.model))

and I got heteroskedasticity in significant level 5% such as below.
bptest(lm(raw.model))

So, I corrected like this.
sqrt(diag(hccm(lm(raw.model),type="hc1")))

This gave me the corrected std.errors.

>From this moment, I want to test whether my parameters are individually  and
jointly significant since the new std.error will change
coeftest(lm(raw.model))'s t, p and F value.

Then, How can I get these new t, p, F? Is there any R command for this?

-- 
View this message in context: 
http://r.789695.n4.nabble.com/After-heteroskedasticity-correction-how-can-I-get-new-confidential-interval-tp3095643p3095852.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] survexp - unable to reproduce example

2010-12-20 Thread Heinz Tuechler

Dear All,

when I try to reproduce an example of survexp, taken from the help 
page of survdiff, I receive the error message

"Error in floor(temp) : Non-numeric argument to mathematical function"
.
It seems to come from match.ratetable. I think, it has to do with 
character variables in a ratetable.
I would be interested to know, if it works for others. With an older 
version of survival, it worked well.


best regards,

Heinz

library(survival)
Loading required package: splines
> ## Example from help page of survdiff
> ## Expected survival for heart transplant patients based on
> ## US mortality tables
> expect <- survexp(futime ~ ratetable(age=(accept.dt - birth.dt),
+  sex=1,year=accept.dt,race="white"), jasa, cohort=FALSE,
+  ratetable=survexp.usr)
Error in floor(temp) : Non-numeric argument to mathematical function
> sessionInfo('survival')
R version 2.12.1 Patched (2010-12-18 r53869)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=German_Switzerland.1252  LC_CTYPE=German_Switzerland.1252
[3] LC_MONETARY=German_Switzerland.1252 LC_NUMERIC=C
[5] LC_TIME=German_Switzerland.1252

attached base packages:
character(0)

other attached packages:
[1] survival_2.36-2

loaded via a namespace (and not attached):
[1] base_2.12.1  graphics_2.12.1  grDevices_2.12.1 methods_2.12.1
[5] splines_2.12.1   stats_2.12.1 tools_2.12.1 utils_2.12.1
> traceback()
2: match.ratetable(rdata, ratetable)
1: survexp(futime ~ ratetable(age = (accept.dt - birth.dt), sex = 1,
   year = accept.dt, race = "white"), jasa, cohort = FALSE,
   ratetable = survexp.usr)
>

__
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] Passing parameter to a function

2010-12-20 Thread Luca Meyer
Hi Duncan,

Yes, A and B are columns in D. Having said that I and trying to avoid 

tab(D$A,D$B)

and I would prefer:

tab(A,B)

Unfortunately the syntax you suggest is giving me the same error:

Error in eval(expr, envir, enclos) : object "A" not found

I have tried to add some deparse() but I have got the error over again. The 
last version I have tried:

function(x,y){
z <- substitute(time ~ x + y, list(x = deparse(substitute(x)), y = 
deparse(substitute(y
xtabs(z, data=D)

gives me another error:

Error in terms.formula(formula, data = data) : 
  formula models not valid in ExtractVars 

Any idea on how I should modify the function to make it work?

Thanks,
Luca


Il giorno 20/dic/2010, alle ore 19.28, Duncan Murdoch ha scritto:

> On 20/12/2010 1:13 PM, Luca Meyer wrote:
>> I am trying to pass a couple of variable names to a xtabs formula:
>> 
>> >  tab<- function(x,y){
>> xtabs(time~x+y, data=D)
>> }
>> 
>> But when I run:
>> 
>> >  tab(A,B)
>> 
>> I get:
>> 
>> Error in eval(expr, envir, enclos) : object "A" not found
>> 
>> I am quite sure that there is some easy way out, but I have tried with 
>> different combinations of deparse(), substitute(), eval(), etc without 
>> success, can someone help?
> 
> I assume that A and B are columns in D?  If so, you could use
> 
> tab(D$A, D$B)
> 
> to get what you want.  If you really want tab(A,B) to work, you'll need to do 
> messy work with substitute, e.g. in the tab function, something like
> 
> fla <- substitute(time ~ x + y, list(x = substitute(x), y = substitute(y))
> xtabs(fla, data=D)
> 
> Duncan Murdoch

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


Re: [R] R.matlab memory use

2010-12-20 Thread Ben Bolker
Stefano Ghirlanda  gmail.com> writes:

> 
> Hi Ben,
> Thanks for your reply. My data structure is about 2 x 2000 so one
> order of magnitude the one you tried. I have no problem saving and
> reading smaller data structures (even large ones, just not his large)
> between octave and R using octave's "save -7" (which saves MATLAB v5
> files) and R.matlab's readMat. And I can save in text format in octave
> and read in R using read.octave (from package foreign) so it's not a
> big deal. I was just surprised that R.matlab needed more memory than I
> have (I have 3GB on this machine).
> 
> Thanks,
> Stefano
> 
> On Sun, Dec 19, 2010 at 10:54 PM, Ben Bolker  gmail.com> wrote:
> > Stefano Ghirlanda  gmail.com> writes:
> >
> >> I am trying to load into R a MATLAB format file (actually, as saved by
> >> octave). The file is about 300kB but R complains with a memory
> >> allocation error:

 [snip]

A few more questions about what's going on: it makes sense that
your ASCII format file is about 75 M (i.e., 10x larger than mine);
presumably your data set is highly redundant so that it can be compressed
to 300Kb?  
   Any chance you can post your data somewhere, or figure out a way
to generate a sample data set that is similar (i.e. starts at about
75 M and compresses to 300Kb when saved appropriately in octave)?


  Ben Bolker

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


Re: [R] sum with times

2010-12-20 Thread Martin Maechler
> "RRJ" == Ronaldo Reis Junior 
> on Sun, 19 Dec 2010 12:10:54 -0200 writes:

RRJ> Hi, Forget, the chron package work with this

No, don't forget, rather solve the problem:

  Date / dateTime  classes are "native R entities";
  extension package 'chron' objects are not.

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

2010-12-20 Thread Martin Maechler
> "JS" == Joel Schwartz 
> on Sat, 18 Dec 2010 19:09:24 -0800 writes:

>> -Original Message- From: David Winsemius
>> [mailto:dwinsem...@comcast.net] Sent: Saturday, December
>> 18, 2010 5:54 PM To: Joel Schwartz Cc:
>> r-help@r-project.org Subject: Re: [R] package survey
>> 
>> 
>> On Dec 18, 2010, at 8:11 PM, Joel Schwartz wrote:
>> 
>> >> and does anyone know if it is possible to find the
>> codes for >> functions in survey package?
>> >
>> > Yes, you can find the code by doing the following:
>> >
>> > 1) Go to the CRAN R package list >
>> (http://cran.r-project.org/web/packages/ > ), > scroll
>> down to the "survey" package link and click on it.
>> >
>> > 2) Scroll down to the "Downloads" section and download
>> the "package > source" > file. The "R" folder in this
>> file contains the code for the functions > in the
>> package.
>> >
>> > You can of course follow an analogous procedure to get
>> the code for > other packages.
>> >
>> > There might be an easier or quicker way to do it from
>> within R but ,if > there is, I haven't learned it yet.
>> 
>> (I suspect Joel knows this.)
>> 
>> If the package is loaded, you can just type the name of
>> the function at the console.
>> 
>> svyhist # produces about a half-page of code.
>> 
JS> Yes, I should have suggested that option as well. It's
JS> probably the quickest way if you just want the code for
JS> one or a few functions. But if you want the code for
JS> most or all functions in a package (including ones for
JS> which you might not know the name off the top of your
JS> head) is there some way of sending the code for all
JS> functions in particular package to a ".r" file from the
JS> command line with one or two lines of code?

Note that only the source package contains the real source code.
What you get when you print the object is the result of parsing
the original code and print()ing it.
In almost all cases, this will have lost all comments,
and will not format the same way the original authors have
formatted the original source ... 
which for good R programmers is typically better / easier to
read and understand than the parsed+deparsed version.

Martin Maechler, ETH Zurich (and R Core Team)

__
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] Passing parameter to a function

2010-12-20 Thread Duncan Murdoch

On 20/12/2010 1:13 PM, Luca Meyer wrote:

I am trying to pass a couple of variable names to a xtabs formula:

>  tab<- function(x,y){
 xtabs(time~x+y, data=D)
}

But when I run:

>  tab(A,B)

I get:

Error in eval(expr, envir, enclos) : object "A" not found

I am quite sure that there is some easy way out, but I have tried with 
different combinations of deparse(), substitute(), eval(), etc without success, 
can someone help?


I assume that A and B are columns in D?  If so, you could use

tab(D$A, D$B)

to get what you want.  If you really want tab(A,B) to work, you'll need 
to do messy work with substitute, e.g. in the tab function, something like


fla <- substitute(time ~ x + y, list(x = substitute(x), y = substitute(y))
xtabs(fla, data=D)

Duncan Murdoch

__
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] Complicated nls formula giving singular gradient message

2010-12-20 Thread Jared Blashka
Though my topic is slightly old already, I feel that it is necessary to post
an update on my situation.
I ended being able to estimate the parameters for this problem without
having to worry as much about initial parameter estimates using AD Model
Builder.
It calculates the exact gradient using automatic differentiation so it's
able to avoid the singular gradient problem nls can give.

I also used the R package PBSadmb, which allowed me to run AD Model Builder
and retrieve the results from within R. Then I could do what I liked with
the results: generate graphs, more analysis, etc.

Thanks to everyone who helped,

Jared

On Wed, Dec 15, 2010 at 8:47 AM, dave fournier  wrote:

> Jared Blashka wrote:
>
> Hi,
>
> Can you write a little note to the R list saying something like
>
>   Re: SOLVED[R] Complicated nls formula giving singular gradient
> message
>
>  I was able to estimate the parameters for this problem using AD Mode
> Builder which calculates
>  the exact gradient for you using automatic differentiation and is thus
> able to avoid the singular gradient
> problem I encountered in nls.
>
> That way other R users who might be able to take advantage of the software
> will hear about it.
>
>  Cheers,
>
>   Dave
>
>
>
>
>> Dave,
>>
>> That's exactly what I was looking for!
>>
>> Thanks for all your help!
>> Jared
>>
>> On Tue, Dec 14, 2010 at 7:13 AM, dave fournier > da...@otter-rsch.com>> wrote:
>>
>>Jared Blashka wrote:
>>
>>The source code for that is in jared.tpl
>>
>>I changed from least squares to a concentrated likelihood so that you
>>could get estimated std devs via the delta method.  they are in
>>jared.std
>>I rescaled the parameters so that the condition number of the
>>Hessian is close to 1.
>>You can see the eigenvalues of the Hessian in jared.eva.
>>Your data are in jared.dat and the initial parameter values are in
>>jared.pin.
>>
>>The parameter estimates with their estiamted std devs are:
>>
>>index   name   value  std dev
>>   1   NS 1.1254e-02 7.1128e-03
>>   2   LogKi -8.8933e+00 8.2411e-02
>>   3   LogKi -5.2005e+00 9.2179e-02
>>   4   LogKi -7.2677e+00 7.7047e-02
>>   5   BMax   2.1226e+05 5.1699e+03
>>~How does it look?
>>
>> Cheers,
>>   Dave
>>
>>
>>
>>
>>Dave - AD Model Builder looks like a great tool that I can
>>use, but I'm curious if it can also perform global parameter
>>estimations across multiple data sets.
>>
>>In regards to the example I have provided, I have two similar
>>data sets that also need to be analyzed, but the values for NS
>>and BMax between the three data sets should be the same. Each
>>data set has a unique LogKi value however. In R, I
>>accomplished this by merging the three data sets and adding an
>>additional field for each data point that identified which set
>>it was originally from. Then in the regression formula I
>>specified the LogKi term as a vector: LogKi[dset]. The results
>>of the regression gave me one value each for NS and BMax, but
>>three LogKi values. I haven't had much time to look through
>>the AD Model Builder documentation yet, but are you aware if
>>such an analysis method is possible?
>>
>>Here's one such example of a data set
>>
>>all <-structure(list(X = c(-13, -11, -10, -9.5, -9, -8.5, -8,
>>-7.5, -7, -6.5, -6, -5, -13, -11, -10, -9.5, -9, -8.5, -8,
>>-7.5, -7, -6.5, -6, -5, -13, -11, -10, -9.5, -9, -8.5, -8,
>>-7.5, -7, -6.5, -6, -5, -13, -11, -10, -9.5, -9, -8.5, -8,
>>-7.5, -7, -6.5, -6, -5, -13, -11, -10, -9.5, -9, -8.5, -8,
>>-7.5, -7, -6.5, -6, -5, -13, -11, -10, -9.5, -9, -8.5, -8,
>>-7.5, -7, -6.5, -6, -5, -13, -11, -10, -9.5, -9, -8.5, -8,
>>-7.5, -7, -6.5, -6, -5, -13, -11, -10, -9.5, -9, -8.5, -8,
>>-7.5, -7, -6.5, -6, -5), Y = c(3146L, 3321L, 2773L, 2415L,
>>2183L, 1091L, 514L, 191L, 109L, 65L, 54L, 50L, 3288L, 3243L,
>>2826L, 2532L, 2060L, 896L, 517L, 275L, 164L, 106L, 202L, 53L,
>>3146L, 3502L, 2658L, 3038L, 3351L, 3238L, 2935L, 3212L, 3004L,
>>3088L, 2809L, 1535L, 3288L, 2914L, 2875L, 2489L, 3104L, 2771L,
>>2861L, 3309L, 2997L, 2361L, 2687L, 1215L, 3224L, 3131L, 3126L,
>>2894L, 2495L, 2935L, 2516L, 2994L, 3074L, 3008L, 2780L, 1454L,
>>3146L, 2612L, 2852L, 2774L, 2663L, 3097L, 2591L, 2295L, 1271L,
>>1142L, 646L, 68L, 3288L, 2606L, 2838L, 1320L, 2890L, 2583L,
>>2251L, 2155L, 1164L, 695L, 394L, 71L, 3224L, 2896L, 2660L,
>>2804L, 2762L, 2525L, 2615L, 1904L, 1364L, 682L, 334L, 64L),
>>dset = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
>>1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
>>2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
>> 

Re: [R] Alternative to extended recode sintax? Bug?

2010-12-20 Thread Luca Meyer
Yes, I am seeing that at the end of 2010-beginning 2011. Try:

weekdays(as.POSIXct("2010-12-25")+(0:20)*24*60*60)
week(as.POSIXct("2010-12-25")+(0:20)*24*60*60)

Week 1 (2011) is made up of 6 days

Luca

Il giorno 20/dic/2010, alle ore 17.54, David Winsemius ha scritto:

> 
> On Dec 20, 2010, at 10:58 AM, Luca Meyer wrote:
> 
>> Right, I appreciate the first day of the year start date. I am just 
>> wondering why then the cut off day is not the same for the rest of the 
>> year...but it's all right to use other packages.
> 
> Are you saying it shifts within the year? I am not seeing that:
> 
> require(lubridate)
> 
> > weekdays(as.POSIXct("2010-01-01")+(0:8)*24*60*60)
> [1] "Friday""Saturday"  "Sunday""Monday""Tuesday"   "Wednesday"
> [7] "Thursday"  "Friday""Saturday"
> > week(as.POSIXct("2010-01-01")+(0:8)*24*60*60)
> [1] 1 1 1 1 1 1 2 2 2
> 
> Looks to be incrementing weeks between Wed and Thurs at the beginning of the 
> year just as it did in your example. I admit that I thought that it should be 
> shifting at the Thursday - Friday divide, but setting a zero point can be 
> ambiguous. I thought if it were  Midnight Thursday-Friday that all of 
> Thurdays would be in week 1. But at least it appears consistent.
> 
> 
>> Thanks,
>> Luca
>> 
>> Il giorno 20/dic/2010, alle ore 14.16, David Winsemius ha scritto:
>> 
>>> 
>>> On Dec 20, 2010, at 12:54 AM, Luca Meyer wrote:
>>> 
 All right, I get it now: lubridate's week() define weeks from Thursday 
 till the following Wednesday. You'd probably agree with me that it's a bit 
 strange what it is going to do over the turn of the year:
 
> y <- 
> as.POSIXct(c("2010-12-27","2010-12-28","2010-12-29","2010-12-30","2010-12-31","2011-01-01","2011-01-02","2011-01-03","2011-01-04","2011-01-05","2011-01-06","2011-01-07","2011-01-08","2011-01-09","2011-01-10","2011-01-11","2010-01-12","2010-01-13","2010-01-14"))
> week(y)
 [1] 52 52 52 53 53  1  1  1  1  1  1  2  2  2  2  2  2  2  3
 
 Why would the first week of the year be made of 6 days and the turn from 
 week 1 to week 2 on the night between Thursday and Friday and not 
 Wednesday and Friday like every other week?
>>> 
>>> weeks in lubridate start on whatever day of the week is the first of that 
>>> year.
>>> 
>>> If you want a Monday starting day (or the option to change to another 
>>> starting day), then package chron has such facilities.
>>> 
>>> 
 
 Cheers,
 Luca
 
 
 
 Il giorno 19/dic/2010, alle ore 18.14, Uwe Ligges ha scritto:
 
> 
> 
> On 19.12.2010 13:20, David Winsemius wrote:
>> 
>> On Dec 19, 2010, at 5:11 AM, Luca Meyer wrote:
>> 
>>> Something goes wrong with the week function of the lubridate package:
>>> 
 x= as.POSIXct(factor(c("2010-12-15 17:28:27",
>>> + "2010-12-15 17:32:34",
>>> + "2010-12-15 18:48:39",
>>> + "2010-12-15 19:25:00",
>>> + "2010-12-16 08:00:00",
>>> + "2010-12-16 08:25:49",
>>> + "2010-12-16 09:00:00")))
 require(lubridate)
>> 
 weekdays(x)
>>> [1] "Mercoledì" "Mercoledì" "Mercoledì" "Mercoledì" "Giovedì"
>>> "Giovedì" "Giovedì"
 week(x)
>>> [1] 50 50 50 50 51 51 51
>> 
>> But 2010-12-15 is a Wednesday and 2010-12-16 is a Thursday.
>> 
> 
> 
> Together with the description of ?week this shows that lubridate's week() 
> function works as documented rather than as expected by Luca Meyer.
> 
> Uwe Ligges
 
>>> 
>>> David Winsemius, MD
>>> West Hartford, CT
>>> 
>> 
> 
> David Winsemius, MD
> West Hartford, CT
> 

__
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] Passing parameter to a function

2010-12-20 Thread Luca Meyer
I am trying to pass a couple of variable names to a xtabs formula:

> tab <- function(x,y){
xtabs(time~x+y, data=D)
}

But when I run:

> tab(A,B)

I get:

Error in eval(expr, envir, enclos) : object "A" not found

I am quite sure that there is some easy way out, but I have tried with 
different combinations of deparse(), substitute(), eval(), etc without success, 
can someone help?

Thanks,
Luca

Luca Meyer
www.lucameyer.com
IBM SPSS Statistics release 19.0.0
R version 2.12.1 (2010-12-16)
Mac OS X 10.6.5 (10H574) - kernel Darwin 10.5.0

__
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] ideas, modeling highly discrete time-series data

2010-12-20 Thread Mike Williamson
Hello all,

First of all, thanks so those of you who helped me a week or so ago
managing a time series with varying gaps between the data series in 'R'.
(My final preferred solution was to use "its" function & then
forecast(Arima( ) ).  )

My next question is a general statistical question where I'd like some
advice, for those willing / able to proffer any wisdom:

   - I need to predict using this same time series, where the *data* are
   highly discrete.  E.g., I will have values like 1e5, 2.2e5, and 3.6e5, but I
   will never have 1.3e5 or 1.8e5, etc.
  - I could simply leave these values as discrete, similar to a binomial
  distribution, but then I am not sure how to use time series tricks like
  arima above.  For time-series analyses that I know of, an
assumption of an
  approximately normal distribution is expected.  No simple normalization
  (e.g., log(values) ) works, since the non-normality arises from
the highly
  discrete distribution more than any drastic asymmetry in the population
  spread.
  - I could leave the values as they are an work with a model where the
  assumption is violated... I am not sure how sensitive a model
such as arima
  is on the population distribution
  - Or I could... (here's where I am hoping for some collective genius).

Thanks in advance for any help!  If this isn't the best forum, since I
know this is not specifically an 'R' question, please let me know of a
better forum to post such a question.

  Thanks!
   Mike



"Telescopes and bathyscaphes and sonar probes of Scottish lakes,
Tacoma Narrows bridge collapse explained with abstract phase-space maps,
Some x-ray slides, a music score, Minard's Napoleanic war:
The most exciting frontier is charting what's already here."
  -- xkcd

--
Help protect Wikipedia. Donate now:
http://wikimediafoundation.org/wiki/Support_Wikipedia/en

[[alternative HTML version deleted]]

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


Re: [R] After heteroskedasticity correction, how can I get new confidential interval?

2010-12-20 Thread Andrew Miles
It is hard to say without knowing more about the type of model you are  
running.


A good place to look would be at the coeftest() function in the  
package lmtest.


Andrew Miles


On Dec 20, 2010, at 10:04 AM, JoonGi wrote:




I just corrected std.error of my 'model'(Multi Regression).
Then how can I get new t and p-values?
Isn't there any R command which shows new t and p values?

--
View this message in context: 
http://r.789695.n4.nabble.com/After-heteroskedasticity-correction-how-can-I-get-new-confidential-interval-tp3095643p3095643.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] Alternative to extended recode sintax? Bug?

2010-12-20 Thread David Winsemius


On Dec 20, 2010, at 10:58 AM, Luca Meyer wrote:

Right, I appreciate the first day of the year start date. I am just  
wondering why then the cut off day is not the same for the rest of  
the year...but it's all right to use other packages.


Are you saying it shifts within the year? I am not seeing that:

require(lubridate)

> weekdays(as.POSIXct("2010-01-01")+(0:8)*24*60*60)
[1] "Friday""Saturday"  "Sunday""Monday""Tuesday"
"Wednesday"

[7] "Thursday"  "Friday""Saturday"
> week(as.POSIXct("2010-01-01")+(0:8)*24*60*60)
[1] 1 1 1 1 1 1 2 2 2

Looks to be incrementing weeks between Wed and Thurs at the beginning  
of the year just as it did in your example. I admit that I thought  
that it should be shifting at the Thursday - Friday divide, but  
setting a zero point can be ambiguous. I thought if it were  Midnight  
Thursday-Friday that all of Thurdays would be in week 1. But at least  
it appears consistent.




Thanks,
Luca

Il giorno 20/dic/2010, alle ore 14.16, David Winsemius ha scritto:



On Dec 20, 2010, at 12:54 AM, Luca Meyer wrote:

All right, I get it now: lubridate's week() define weeks from  
Thursday till the following Wednesday. You'd probably agree with  
me that it's a bit strange what it is going to do over the turn of  
the year:


y <-  
as.POSIXct(c("2010-12-27","2010-12-28","2010-12-29","2010-12-30","2010-12-31","2011-01-01","2011-01-02","2011-01-03","2011-01-04","2011-01-05","2011-01-06","2011-01-07","2011-01-08","2011-01-09","2011-01-10","2011-01-11","2010-01-12","2010-01-13","2010-01-14"))

week(y)

[1] 52 52 52 53 53  1  1  1  1  1  1  2  2  2  2  2  2  2  3

Why would the first week of the year be made of 6 days and the  
turn from week 1 to week 2 on the night between Thursday and  
Friday and not Wednesday and Friday like every other week?


weeks in lubridate start on whatever day of the week is the first  
of that year.


If you want a Monday starting day (or the option to change to  
another starting day), then package chron has such facilities.





Cheers,
Luca



Il giorno 19/dic/2010, alle ore 18.14, Uwe Ligges ha scritto:




On 19.12.2010 13:20, David Winsemius wrote:


On Dec 19, 2010, at 5:11 AM, Luca Meyer wrote:

Something goes wrong with the week function of the lubridate  
package:



x= as.POSIXct(factor(c("2010-12-15 17:28:27",

+ "2010-12-15 17:32:34",
+ "2010-12-15 18:48:39",
+ "2010-12-15 19:25:00",
+ "2010-12-16 08:00:00",
+ "2010-12-16 08:25:49",
+ "2010-12-16 09:00:00")))

require(lubridate)



weekdays(x)

[1] "Mercoledì" "Mercoledì" "Mercoledì" "Mercoledì" "Giovedì"
"Giovedì" "Giovedì"

week(x)

[1] 50 50 50 50 51 51 51


But 2010-12-15 is a Wednesday and 2010-12-16 is a Thursday.




Together with the description of ?week this shows that  
lubridate's week() function works as documented rather than as  
expected by Luca Meyer.


Uwe Ligges




David Winsemius, MD
West Hartford, CT





David Winsemius, MD
West Hartford, CT

__
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] install.packages() - old version deleted, new version did not install

2010-12-20 Thread Jon Olav Skoien
This sounds like a good solution for the case I described in my first 
email.


Thanks a lot!
Jon

On 12/20/2010 4:05 PM, Duncan Murdoch wrote:

On 20/12/2010 9:29 AM, Duncan Murdoch wrote:

On 20/12/2010 9:26 AM, Uwe Ligges wrote:
>
>  On 20.12.2010 15:19, Duncan Murdoch wrote:
> >   On 20/12/2010 9:03 AM, Jon Olav Skoien wrote:


[ lots deleted ]


> >>   Yes, I had it open. In this case it was intentional to give a
> >>   reproducible example in case something had changed in the new 
version,
> >>   in other cases I have had to wait for 2 days before I could 
reinstall a
> >>   package. It seems the .dll is the one causing the problem, so 
wouldnt it
> >>   be possible to test if this file can be unlinked before trying 
to unlink
> >>   the complete directory in utils:::unpackPkgZip? Then the 
package should
> >>   be left untouched if it is in use, and not partly deleted as 
today.

> >
> >   I don't know. Perhaps we could try to rename the folder; if 
that fails,
> >   abort the whole thing. If that succeeds but something later 
fails, then
> >   remove all the new stuff and restore the old folder. Do you 
know of a

> >   better test?
>
>  I think we had something like that in the past which did not work
>  properly on network shares and we had to change the way it works for
>  that reason.

I just took a look at the code, and I see that something like that is
still there.  I haven't tried it yet, so I don't know if it is in use.


After a closer look I see that the code is there for source installs, 
but not binary installs.  For binary installs the procedure is:


 unzip the package to a temporary directory
 look at the DESCRIPTION to find the package name (since you can't 
trust the .zip name)
 abort if the package is in the search list.  (This is the test that 
could be stronger, because it doesn't detect a package in use in 
another instance of R.)
 remove the old package if it is there.  (This is the step that 
removes everything but the old DLL when the DLL is in use.)
 copy the new package into place. (This fails because of the collision 
with the old DLL.)


I'll look into strengthening the test at the 3rd step with something 
along the lines described above.  From Uwe's description, this might 
still not

be perfect, but it should help with local installs.

Duncan Murdoch




__
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] Alternative to extended recode sintax? Bug?

2010-12-20 Thread Luca Meyer
Right, I appreciate the first day of the year start date. I am just wondering 
why then the cut off day is not the same for the rest of the year...but it's 
all right to use other packages.
Thanks,
Luca

Il giorno 20/dic/2010, alle ore 14.16, David Winsemius ha scritto:

> 
> On Dec 20, 2010, at 12:54 AM, Luca Meyer wrote:
> 
>> All right, I get it now: lubridate's week() define weeks from Thursday till 
>> the following Wednesday. You'd probably agree with me that it's a bit 
>> strange what it is going to do over the turn of the year:
>> 
>>> y <- 
>>> as.POSIXct(c("2010-12-27","2010-12-28","2010-12-29","2010-12-30","2010-12-31","2011-01-01","2011-01-02","2011-01-03","2011-01-04","2011-01-05","2011-01-06","2011-01-07","2011-01-08","2011-01-09","2011-01-10","2011-01-11","2010-01-12","2010-01-13","2010-01-14"))
>>> week(y)
>> [1] 52 52 52 53 53  1  1  1  1  1  1  2  2  2  2  2  2  2  3
>> 
>> Why would the first week of the year be made of 6 days and the turn from 
>> week 1 to week 2 on the night between Thursday and Friday and not Wednesday 
>> and Friday like every other week?
> 
> weeks in lubridate start on whatever day of the week is the first of that 
> year.
> 
> If you want a Monday starting day (or the option to change to another 
> starting day), then package chron has such facilities.
> 
> 
>> 
>> Cheers,
>> Luca
>> 
>> 
>> 
>> Il giorno 19/dic/2010, alle ore 18.14, Uwe Ligges ha scritto:
>> 
>>> 
>>> 
>>> On 19.12.2010 13:20, David Winsemius wrote:
 
 On Dec 19, 2010, at 5:11 AM, Luca Meyer wrote:
 
> Something goes wrong with the week function of the lubridate package:
> 
>> x= as.POSIXct(factor(c("2010-12-15 17:28:27",
> + "2010-12-15 17:32:34",
> + "2010-12-15 18:48:39",
> + "2010-12-15 19:25:00",
> + "2010-12-16 08:00:00",
> + "2010-12-16 08:25:49",
> + "2010-12-16 09:00:00")))
>> require(lubridate)
 
>> weekdays(x)
> [1] "Mercoledì" "Mercoledì" "Mercoledì" "Mercoledì" "Giovedì"
> "Giovedì" "Giovedì"
>> week(x)
> [1] 50 50 50 50 51 51 51
 
 But 2010-12-15 is a Wednesday and 2010-12-16 is a Thursday.
 
>>> 
>>> 
>>> Together with the description of ?week this shows that lubridate's week() 
>>> function works as documented rather than as expected by Luca Meyer.
>>> 
>>> Uwe Ligges
>> 
> 
> David Winsemius, MD
> West Hartford, CT
> 

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


Re: [R] How to optimize function parameters?

2010-12-20 Thread Jonathan P Daily
Without an example, I'm not sure how much help I can be. Does your 
Variogram calculation return a single value that could be minimized? Or 
could it be coerced to be so?

I would suggest, if you haven't done so, a look at ?nlm and ?nlminb.
Alternatively, the CRAN package 'optimx' serves as a wrapper to many 
optimization algorithms and offers methods to compare them side-by-side.

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

r-help-boun...@r-project.org wrote on 12/20/2010 09:39:49 AM:

> [image removed] 
> 
> [R] How to optimize function parameters?
> 
> zbynek.jano...@gmail.com 
> 
> to:
> 
> r-help
> 
> 12/20/2010 10:43 AM
> 
> Sent by:
> 
> r-help-boun...@r-project.org
> 
> 
> Hi,
> 
> I have a dataset and I want to fit a function to it.
> The function is variogram model (http://en.wikipedia.org/wiki/Variogram)
> The variogram model is defined by three parameters and I want them to be
> automatically optimized for real time data.
> I tried to use gafit {gafit} for this, but there are some data
> configuration, where optimal results given by gafit() are negative, 
which is
> not correct and cannot be used for further calculating. gafit() does not
> enable me to set a range of possible results (at least I did not 
succeded in
> doing so), therefore I am looking for another solution (Powell´s 
gradient
> descent possibly?).
> 
> Can anyone give me a hint where to look?
> 
> Thanks
> 
> Zbynek
> -- 
> View this message in context: http://r.789695.n4.nabble.com/How-to-
> optimize-function-parameters-tp3095603p3095603.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] How to optimize function parameters?

2010-12-20 Thread zbynek.jano...@gmail.com

Hi,

I have a dataset and I want to fit a function to it.
The function is variogram model (http://en.wikipedia.org/wiki/Variogram)
The variogram model is defined by three parameters and I want them to be
automatically optimized for real time data.
I tried to use gafit {gafit} for this, but there are some data
configuration, where optimal results given by gafit() are negative, which is
not correct and cannot be used for further calculating. gafit() does not
enable me to set a range of possible results (at least I did not succeded in
doing so), therefore I am looking for another solution (Powell´s gradient
descent possibly?).

Can anyone give me a hint where to look?

Thanks

Zbynek
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-optimize-function-parameters-tp3095603p3095603.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] After heteroskedasticity correction, how can I get new confidential interval?

2010-12-20 Thread JoonGi


I just corrected std.error of my 'model'(Multi Regression).
Then how can I get new t and p-values?
Isn't there any R command which shows new t and p values?

-- 
View this message in context: 
http://r.789695.n4.nabble.com/After-heteroskedasticity-correction-how-can-I-get-new-confidential-interval-tp3095643p3095643.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] help on timeseries

2010-12-20 Thread cameron

Thanks Frederic.

that solved the problem.

Thanks again.
Cameron
-- 
View this message in context: 
http://r.789695.n4.nabble.com/help-on-timeseries-tp3076866p3095633.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] R.matlab memory use

2010-12-20 Thread Stefano Ghirlanda
Hi Ben,
Thanks for your reply. My data structure is about 2 x 2000 so one
order of magnitude the one you tried. I have no problem saving and
reading smaller data structures (even large ones, just not his large)
between octave and R using octave's "save -7" (which saves MATLAB v5
files) and R.matlab's readMat. And I can save in text format in octave
and read in R using read.octave (from package foreign) so it's not a
big deal. I was just surprised that R.matlab needed more memory than I
have (I have 3GB on this machine).

Thanks,
Stefano

On Sun, Dec 19, 2010 at 10:54 PM, Ben Bolker  wrote:
> Stefano Ghirlanda  gmail.com> writes:
>
>> I am trying to load into R a MATLAB format file (actually, as saved by
>> octave). The file is about 300kB but R complains with a memory
>> allocation error:
>>
>> > library(Rcompression)
>> > library(R.matlab)
>> Loading required package: R.oo
>> Loading required package: R.methodsS3
>> R.methodsS3 v1.2.0 (2010-03-13) successfully loaded. See ?R.methodsS3 for 
>> help.
>> R.oo v1.7.2 (2010-04-13) successfully loaded. See ?R.oo for help.
>> R.matlab v1.3.1 (2010-04-20) successfully loaded. See ?R.matlab for help.
>> > f <- readMat("freq.mat")
>> Error: cannot allocate vector of size 296.5 Mb
>>
>> On the other hand, if I save the same data in ascii format (from
>> octave: "save -text"), resulting in a 75MB file, then I can load it
>> without problems with the read.octave() function from package foreign.
>> Is this a known issue or am I doing something wrong? My R version is:
>
>  This is not a package I'm particularly familiar with, but:
>
>  what commands did you use to save the file in octave?  Based on
> 'help save' I think that 'save' by default would get you an octave
> format file ... you might have to do some careful reading in
> ?readMat (in R) and 'help save' (in octave) to figure out the
> correspondence between octave/MATLAB and R/MATLAB.
>   If possible, try saving a small file and see if it works; if
> you still don't know what's going on, post that file somewhere for
> people to try.
>
>  I was able to
>
> save -6 "save.mat" in octave and
> readMat("save.mat") in R successfully,
> saving a vector of integers from 1 to 1 million (which
> took about 7.7 Mb)
>
> __
> 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.
>



-- 
Stefano Ghirlanda
www.intercult.su.se/~stefano - drghirlanda.wordpress.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] contourplot help

2010-12-20 Thread David Winsemius


On Dec 20, 2010, at 5:36 AM, Andre Nathan wrote:


Hello

I'm using the following call to create a contourplot:

library(lattice)
m <- as.matrix(read.table("data.txt"))

contourplot(m[,3] ~ m[,2] * -m[,1],
   at = c(1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1),
   scales = list(x = list(log = 10,
  labels = c("1", "10", "100"),
  at = c(1, 10, 100)),
 y = list(labels = c("14", "12", "10", "8",
 "6", "4", "2")),
  at = c(-14, -12, -10, -8, -6, -4,
 -2)),
   labels = c(expression(10^-6), expression(10^-5),
  expression(10^-4), expression(10^-3),
  expression(10^-2), expression(10^-1),
  expression(10^0)),
   xlim = c(0.75, 10^2),
   xlab = "Out-degree", ylab = "In-degree")


Which gives the the output in the file below

 http://ompldr.org/vNm4xag/contour.eps

As it can be seen, the level labels are not displayed nicely because
there's not enough room for them. Also, the 10^-1 label is not
displayed.

Is there a way for me to hardcode the position of each label?


I don't see it, but that doesn't mean much unless it is echoed by  
Sarkar or Andrews.



I tried
setting labels = F and then calling text() for each one, but that
doesn't work.


Right, text() is a base graphics function. There are, however, lattice  
functions that supply the same functionality:


?ltext   # = l(attice)text

ltext(x, y = NULL, labels = seq_along(x), col, alpha, cex, srt = 0,  
lineheight, font, fontfamily, fontface, adj = c(0.5, 0.5), pos = NULL,  
offset = 0.5, ...)
You could first see if you can better results by not automatically  
labeling the 10^-6 level, because the -2, -3, -5 levels look ok. That  
might let the 10^-4 label move to a bit less hashed up position and  
then you could put 10^-1 and 10^-6 where you want them




If that's not possible, one option would be to color each level line
differently and then add a legend. Is it possible to do that?

Finally, how can I remove the tick marks from the top and right axes?


 ..., scales=list(tck=c(1,0)), ...   actually you would add the tck  
list to your existing scales. Found on the ?xyplot page, but tested  
with a modified volcano example from :

?contourplot




Thanks,
Andre


David Winsemius, MD
West Hartford, CT

__
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] install.packages() - old version deleted, new version did not install

2010-12-20 Thread Duncan Murdoch

On 20/12/2010 9:29 AM, Duncan Murdoch wrote:

On 20/12/2010 9:26 AM, Uwe Ligges wrote:
>
>  On 20.12.2010 15:19, Duncan Murdoch wrote:
>  >   On 20/12/2010 9:03 AM, Jon Olav Skoien wrote:


[ lots deleted ]


>  >>   Yes, I had it open. In this case it was intentional to give a
>  >>   reproducible example in case something had changed in the new version,
>  >>   in other cases I have had to wait for 2 days before I could reinstall a
>  >>   package. It seems the .dll is the one causing the problem, so wouldnt it
>  >>   be possible to test if this file can be unlinked before trying to unlink
>  >>   the complete directory in utils:::unpackPkgZip? Then the package should
>  >>   be left untouched if it is in use, and not partly deleted as today.
>  >
>  >   I don't know. Perhaps we could try to rename the folder; if that fails,
>  >   abort the whole thing. If that succeeds but something later fails, then
>  >   remove all the new stuff and restore the old folder. Do you know of a
>  >   better test?
>
>  I think we had something like that in the past which did not work
>  properly on network shares and we had to change the way it works for
>  that reason.

I just took a look at the code, and I see that something like that is
still there.  I haven't tried it yet, so I don't know if it is in use.


After a closer look I see that the code is there for source installs, 
but not binary installs.  For binary installs the procedure is:


 unzip the package to a temporary directory
 look at the DESCRIPTION to find the package name (since you can't 
trust the .zip name)
 abort if the package is in the search list.  (This is the test that 
could be stronger, because it doesn't detect a package in use in another 
instance of R.)
 remove the old package if it is there.  (This is the step that removes 
everything but the old DLL when the DLL is in use.)
 copy the new package into place. (This fails because of the collision 
with the old DLL.)


I'll look into strengthening the test at the 3rd step with something 
along the lines described above.  From Uwe's description, this might 
still not

be perfect, but it should help with local installs.

Duncan Murdoch

__
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] dotchart for matrix data

2010-12-20 Thread e-letter
On 18/12/2010, e-letter  wrote:
> On 18/12/2010, Peter Ehlers  wrote:
>> On 2010-12-18 07:50, e-letter wrote:
 Ben Bolker
 Sat, 18 Dec 2010 07:07:24 -0800
>>
>> [... snip ...]
>>
>>> I am trying to create a chart like this
>>> (http://www.b-eye-network.com/images/content/Fig4_3.jpg); so this is
>>> not possible using R?
>>
>> That looks an awful lot like what lattice's dotplot would
>> produce. So: have you tried dotplot() as Ben has suggested?
>>
>

If one set of value ranges for 10-20 and another set ranges form
1000-1500, how to adjust the graph such that:

with categories on the ordinate (y-axis), can the bottom abscissa
(x-axis bottom) be set with a scale suitable for the data set of range
1000-1500?
can the top abscissa (x-top) be set with a scale 10-20?
or is it better practice to change the scale of the data set 1000-1500
by two orders of magnitude?
how is it possible to control the order of the category variables? For
example, if the graph shows:

a
b
c
d

Is it possible to change to

a
d
b
c

Thanks

__
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] lower/upper case question

2010-12-20 Thread Bos, Roger
toupper() and tolower() 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Erin Hodgess
Sent: Friday, December 17, 2010 4:10 PM
To: R help
Subject: [R] lower/upper case question

Dear R People:

Is there a function to convert a character string to all uppercase or
all lowercase please?

I'm sure that I've used one before but I'm drawing a blank.

Thanks,
Erin


--
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences University of Houston -
Downtown
mailto: erinm.hodg...@gmail.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.
***

This message is for the named person's use only. It may\...{{dropped:20}}

__
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] moving average with gaps in time series

2010-12-20 Thread Josef . Kardos
Thank you for the suggestion Jannis. I ended up using the function 
'running' in package gregmisc.   'rollyapply' was not able to process all 
the data on my computer. Happy holidays to you and the R community 



Jannis  
12/16/2010 06:56 PM

To
josef.kar...@phila.gov
cc
r-help@r-project.org
Subject
Re: [R] moving average with gaps in time series






Hi Josef,

is there any particular reason why you want to use your own function? 
Have a look at the stats functions or special timeseries functions for 
R. I am sure you will find something that calculates an ordinary moving 
average (and a bunch of fancier stuff).

'filter' (stats) for example can be used for moving averages. You could 
also use 'rollmean' from package zoo.

Not sure how to handle the missing values here, though (both ways most 
probably work with NAs). You could try 'rollaply 'from package zoo with 
a function that sums the valid values in the window and returns TRUE in 
case all are valid and FALSE if they are not. Not sure whether this is 
faster than your solution though.

Are you sure you want to compute a moving average with your missing 
values specification? Or do you just want to aggregate your values to 
hourly means, with those values removed where not all values are valid? 
(in that case 'aggregate' would be your function)


HTH
Jannis


josef.kar...@phila.gov schrieb:
> I have a time series with interval of 2.5 minutes, or 24 observations 
per 
> hour.  I am trying to find a 1 hr moving average, looking backward, so 
> that moving average at n = mean(n-23 : n)
>
> The time series has about 1.5 million rows, with occasional gaps due to 
> poor data quality.  I only want to take a 1 hour moving average for 
those 
> periods that are complete, i.e. have 24 observations in the previous 
hour.
>
> The data is in 3 columns
>
> Value   DateTimeinterval
>
> For example:
> Value <- rnorm (100, 50, 3)  #my data has 1.5 million rows; using 100 
here 
> for simple example
> DateTime <-  seq(from = 915148800, to=915156150, by =150)  #time steps 
> 1:50 at 150 second intervals
> DateTime [51] <- 915156450 #skip one time step; 
> DateTime[52:100] <- seq(from = 915156600, to =915163800, by = 150) 
#resume 
> time steps of 150 seconds
> 
> x <- cbind (Value, DateTime)
> x <- as.data.frame(x)
> x$DateTime <-as.POSIXct(x$DateTime, origin="1970-01-01", tz="GMT") 
> x1 <- x[-c(1:23), ]   #trimming x to create direct comparison of 
DateTimes 
> in x and x1
> x[,3] <-difftime(x1[,2], x[,2], units="mins")  #ignore warning 
message
> colnames(x) [3]  <- "interval"
> x[24:nrow(x),3] <- x[1:(nrow(x)-23),3] #set interval to be the 
number 
> of minutes between n-23 and n. 
> #57.5 indicates no gaps in the previous hour up to and including 

> n. 
> #>57.5 indicates a gap in the previous n-23 rows. 
> x[1:23,3] <- 0/0  #NaN assigned to first 23 rows so as not to take 
average 
> of first hour.
> #as expected, row 51: 73 indicates a gap, i.e. interval > 57.5
>
> index <- which (x [,3] == 57.5)  #which rows have no gaps in previous 
hour
>
> #loop to calculate 1 hour moving average, only for periods which are 
> complete
> for (i in 1:length(index)) {
> x [index[i],4] <- mean(x[index[i]-23,1] : x[index[i],1])
>   } 
>
> #This loop works on this simple example; but this takes VERY long time 
to 
> run  on x with 1.5 million rows.  Over 1 hour running and still not 
> complete.  I also tried increasing memory.limit to 4095, but still very 
> slow.
> 
> Any suggestions to make this run faster?  I thought about using the lag 
> function but could not get it to work
>
>
> 
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> 



[[alternative HTML version deleted]]

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


Re: [R] install.packages() - old version deleted, new version did not install

2010-12-20 Thread Duncan Murdoch

On 20/12/2010 9:26 AM, Uwe Ligges wrote:


On 20.12.2010 15:19, Duncan Murdoch wrote:
>  On 20/12/2010 9:03 AM, Jon Olav Skoien wrote:
>>  On 12/20/2010 1:43 PM, Duncan Murdoch wrote:
>>  >  Jon Olav Skoien wrote:
>>  >>  On 12/17/2010 6:22 PM, Duncan Murdoch wrote:
>>  >>>  On 17/12/2010 11:13 AM, Jon Olav Skoien wrote:
>>    Dear list,
>>  
>>    (R 2.12.0, Windows 7, 64bit)
>>  
>>    I recently tried to install a new package ("spacetime"), that
>>    depends on
>>    "sp" among others. I already had the last one installed, but
>>  there was
>>    probably a newer version on CRAN, so the command
>>  >  install.packages("spacetime")
>>    also gave me:
>>    also installing the dependencies ‘sp’, ‘zoo’, ‘xts’
>>  
>>    sp was already loaded in this session, so installation failed:
>>    package 'sp' successfully unpacked and MD5 sums checked
>>    Warning: cannot remove prior installation of package 'sp'
>>  
>>    Unfortunately, the warning should rather say:
>>    "cannot completely remove prior installation of package 'sp'"
>>    R managed to remove most of the prior installation of sp, except
>>    for the
>>    .dll. I could go on using sp in the existing sessions, but not load
>>    the
>>    package in a new session or open the help pages. This has happened
>>    to me
>>    several times, and the only solution I have found to this is to
>>  close
>>    all R-sessions and install the package again. This is normally
>>  ok, but
>>    this time I had some long-time computations running in another
>>    R-session
>>    that I did not want to interrupt. For the next time, is there a
>>  way to
>>    reinstall a package without interrupting running R-sessions?
>>  
>>    For me it seems like the cause of the problem could have been
>>    solved by
>>    checking if the .dll can be removed before removing the rest of the
>>    package, by adding something like the following in
>>    utils:::unpackPkgZip?
>>    if (unlink(paste(instPath,"/libs/x64/sp.dll", sep = "")) != 0)
>>    warning("cannot remove...")
>>    before
>>    ret<- unlink(instPath, recursive = TRUE) (line 95)
>>    x64 in the path would have to be changed to something architecture
>>    dependent...
>>  >>>
>>  >>>  Could you try out the new 2.12.1 release? I recall hearing that
>>  >>>  something like this had changed, but I can't spot the NEWS item
>>  >>>  right now.
>>  >>>
>>  >>>  Duncan Murdoch
>>  >>
>>  >>  It seems it didnt change yet...
>>  >>  I installed 2.12.1 (on a different computer, still Windows, but Vista
>>  >>  and 32 bit), and after installing and loading sp in one session, I
>>  >>  opened a new session and got:
>>  >>
>>  >>  R version 2.12.1 (2010-12-16)
>>  >>  Copyright (C) 2010 The R Foundation for Statistical Computing
>>  >>  ISBN 3-900051-07-0
>>  >>  Platform: i386-pc-mingw32/i386 (32-bit)
>>  >>  
>>  >>
>>  >>  >  install.packages("sp")
>>  >>  Installing package(s) into ‘C:\Users\Jon\Documents/R/win-library/2.12’
>>  >>  (as ‘lib’ is unspecified)
>>  >>  --- Please select a CRAN mirror for use in this session ---
>>  >>  provo con l'URL
>>  >>  'http://cran.at.r-project.org/bin/windows/contrib/2.12/sp_0.9-76.zip'
>>  >>  Content type 'application/zip' length 997444 bytes (974 Kb)
>>  >>  URL aperto
>>  >>  downloaded 974 Kb
>>  >>
>>  >>  package 'sp' successfully unpacked and MD5 sums checked
>>  >>  Warning: cannot remove prior installation of package 'sp'
>>  >>
>>  >>  The downloaded packages are in
>>  >>  C:\Users\Jon\AppData\Local\Temp\RtmpCTJeBk\downloaded_packages
>>  >>  >  library(sp)
>>  >>  Errore in library(sp) : non c'è alcun pacchetto chiamato 'sp'
>>  >>  >
>>  >>
>>  >>  The error message is the same as earlier, there is no package called
>>  >>  "sp", the attempt to install it again removed the old version except
>>  >>  for the .dll.
>>  >>
>>  >>  Jon
>>  >
>>  >  Did you have it open at the time? Windows won't let open files be
>>  >  removed, so that could have caused the problem. If it's not that, it
>>  >  could be a permissions problem. Have you tried running R as
>>  >  administrator for the install?
>>  Yes, I had it open. In this case it was intentional to give a
>>  reproducible example in case something had changed in the new version,
>>  in other cases I have had to wait for 2 days before I could reinstall a
>>  package. It seems the .dll is the one causing the problem, so wouldnt it
>>  be possible to test if this file can be unlinked before trying to unlink
>>  the complete directory in utils:::unpackPkgZip? Then the package should
>>  be left untouched if it is in use, and not partly deleted as today.
>
>  I don't know. Perhaps we could try to rename the folder; if that fails,
>  abort the whole thing. If that succeeds but something later fails, then
>  remove all the new stu

Re: [R] install.packages() - old version deleted, new version did not install

2010-12-20 Thread Uwe Ligges



On 20.12.2010 15:19, Duncan Murdoch wrote:

On 20/12/2010 9:03 AM, Jon Olav Skoien wrote:

On 12/20/2010 1:43 PM, Duncan Murdoch wrote:
> Jon Olav Skoien wrote:
>> On 12/17/2010 6:22 PM, Duncan Murdoch wrote:
>>> On 17/12/2010 11:13 AM, Jon Olav Skoien wrote:
 Dear list,

 (R 2.12.0, Windows 7, 64bit)

 I recently tried to install a new package ("spacetime"), that
 depends on
 "sp" among others. I already had the last one installed, but
there was
 probably a newer version on CRAN, so the command
> install.packages("spacetime")
 also gave me:
 also installing the dependencies ‘sp’, ‘zoo’, ‘xts’

 sp was already loaded in this session, so installation failed:
 package 'sp' successfully unpacked and MD5 sums checked
 Warning: cannot remove prior installation of package 'sp'

 Unfortunately, the warning should rather say:
 "cannot completely remove prior installation of package 'sp'"
 R managed to remove most of the prior installation of sp, except
 for the
 .dll. I could go on using sp in the existing sessions, but not load
 the
 package in a new session or open the help pages. This has happened
 to me
 several times, and the only solution I have found to this is to
close
 all R-sessions and install the package again. This is normally
ok, but
 this time I had some long-time computations running in another
 R-session
 that I did not want to interrupt. For the next time, is there a
way to
 reinstall a package without interrupting running R-sessions?

 For me it seems like the cause of the problem could have been
 solved by
 checking if the .dll can be removed before removing the rest of the
 package, by adding something like the following in
 utils:::unpackPkgZip?
 if (unlink(paste(instPath,"/libs/x64/sp.dll", sep = "")) != 0)
 warning("cannot remove...")
 before
 ret<- unlink(instPath, recursive = TRUE) (line 95)
 x64 in the path would have to be changed to something architecture
 dependent...
>>>
>>> Could you try out the new 2.12.1 release? I recall hearing that
>>> something like this had changed, but I can't spot the NEWS item
>>> right now.
>>>
>>> Duncan Murdoch
>>
>> It seems it didnt change yet...
>> I installed 2.12.1 (on a different computer, still Windows, but Vista
>> and 32 bit), and after installing and loading sp in one session, I
>> opened a new session and got:
>>
>> R version 2.12.1 (2010-12-16)
>> Copyright (C) 2010 The R Foundation for Statistical Computing
>> ISBN 3-900051-07-0
>> Platform: i386-pc-mingw32/i386 (32-bit)
>> 
>>
>> > install.packages("sp")
>> Installing package(s) into ‘C:\Users\Jon\Documents/R/win-library/2.12’
>> (as ‘lib’ is unspecified)
>> --- Please select a CRAN mirror for use in this session ---
>> provo con l'URL
>> 'http://cran.at.r-project.org/bin/windows/contrib/2.12/sp_0.9-76.zip'
>> Content type 'application/zip' length 997444 bytes (974 Kb)
>> URL aperto
>> downloaded 974 Kb
>>
>> package 'sp' successfully unpacked and MD5 sums checked
>> Warning: cannot remove prior installation of package 'sp'
>>
>> The downloaded packages are in
>> C:\Users\Jon\AppData\Local\Temp\RtmpCTJeBk\downloaded_packages
>> > library(sp)
>> Errore in library(sp) : non c'è alcun pacchetto chiamato 'sp'
>> >
>>
>> The error message is the same as earlier, there is no package called
>> "sp", the attempt to install it again removed the old version except
>> for the .dll.
>>
>> Jon
>
> Did you have it open at the time? Windows won't let open files be
> removed, so that could have caused the problem. If it's not that, it
> could be a permissions problem. Have you tried running R as
> administrator for the install?
Yes, I had it open. In this case it was intentional to give a
reproducible example in case something had changed in the new version,
in other cases I have had to wait for 2 days before I could reinstall a
package. It seems the .dll is the one causing the problem, so wouldnt it
be possible to test if this file can be unlinked before trying to unlink
the complete directory in utils:::unpackPkgZip? Then the package should
be left untouched if it is in use, and not partly deleted as today.


I don't know. Perhaps we could try to rename the folder; if that fails,
abort the whole thing. If that succeeds but something later fails, then
remove all the new stuff and restore the old folder. Do you know of a
better test?


I think we had something like that in the past which did not work 
properly on network shares and we had to change the way it works for 
that reason.


Uwe



Duncan Murdoch


I know that it is possible to avoid this problem by not installing a
package in use, but
1) it seems only to affect packages with .dll's, so some packages can be
reinstalled while in use
2) you dont always know if a dependent package will download a new
version of an installed package

Best wishes,
Jon




Re: [R] box-and-whisker plots based on summary not data

2010-12-20 Thread David Winsemius


On Dec 20, 2010, at 8:33 AM, Matthew Vernon wrote:


Matthew Vernon  writes:


Is it possible to produce box-and-whisker plots given that I have the
median, interquartile and 5/95th centile values, but not the data  
from

which they come?


Please note that the whiskers of the default BWP are NOT at the 5th  
and 95th percentiles although I would have guessed that they were too  
before I looked a closely at the code and the help pages. They are at  
the most extreme data points which do not exceed 1.5 times the box  
values which in turn are at "versions of the first and third quartiles".


(So , no,  you cannot get what boxplot would have given unless you  
have the IQR values and all of the data outside those values. You can,  
of course, make up your own approach and use the boxplot machinery for  
plotting  as long as you inform your audience what you are  
plotting.)





The answer, which came from Steve Ellison (thanks!) is to note that
"stats" is the only bit of the "z" argument to bxp that has to be
present, so given a data file with columns year,mean,median,centiles,
something like this works:

# transform data so the rows are the various centiles in order
# there's probably a more elegant approach!
bsr <- matrix(allobs[,c(4,5,3,6,7)],nrow=5,byrow=TRUE)
# column 1 is the year, which is our factor
bsbox <- list( stats=bsr,names=allobs$V1)
bxp(bsbox,xlab="Year",ylab="Number of cattle per batch")

I thought I'd follow-up so the answer to my question will be in the
archives.

Thanks,

Matthew



David Winsemius, MD
West Hartford, CT

__
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] install.packages() - old version deleted, new version did not install

2010-12-20 Thread Duncan Murdoch

On 20/12/2010 9:03 AM, Jon Olav Skoien wrote:

On 12/20/2010 1:43 PM, Duncan Murdoch wrote:
>  Jon Olav Skoien wrote:
>>  On 12/17/2010 6:22 PM, Duncan Murdoch wrote:
>>>  On 17/12/2010 11:13 AM, Jon Olav Skoien wrote:
  Dear list,

  (R 2.12.0, Windows 7, 64bit)

  I recently tried to install a new package ("spacetime"), that
  depends on
  "sp" among others. I already had the last one installed, but there was
  probably a newer version on CRAN, so the command
>  install.packages("spacetime")
  also gave me:
  also installing the dependencies ‘sp’, ‘zoo’, ‘xts’

  sp was already loaded in this session, so installation failed:
  package 'sp' successfully unpacked and MD5 sums checked
  Warning: cannot remove prior installation of package 'sp'

  Unfortunately, the warning should rather say:
  "cannot completely remove prior installation of package 'sp'"
  R managed to remove most of the prior installation of sp, except
  for the
  .dll. I could go on using sp in the existing sessions, but not load
  the
  package in a new session or open the help pages. This has happened
  to me
  several times, and the only solution I have found to this is to close
  all R-sessions and install the package again. This is normally ok, but
  this time I had some long-time computations running in another
  R-session
  that I did not want to interrupt. For the next time, is there a way to
  reinstall a package without interrupting running R-sessions?

  For me it seems like the cause of the problem could have been
  solved by
  checking if the .dll can be removed before removing the rest of the
  package, by adding something like the following in
  utils:::unpackPkgZip?
  if (unlink(paste(instPath,"/libs/x64/sp.dll", sep = "")) != 0)
  warning("cannot remove...")
  before
  ret<- unlink(instPath, recursive = TRUE) (line 95)
  x64 in the path would have to be changed to something architecture
  dependent...
>>>
>>>  Could you try out the new 2.12.1 release? I recall hearing that
>>>  something like this had changed, but I can't spot the NEWS item
>>>  right now.
>>>
>>>  Duncan Murdoch
>>
>>  It seems it didnt change yet...
>>  I installed 2.12.1 (on a different computer, still Windows, but Vista
>>  and 32 bit), and after installing and loading sp in one session, I
>>  opened a new session and got:
>>
>>  R version 2.12.1 (2010-12-16)
>>  Copyright (C) 2010 The R Foundation for Statistical Computing
>>  ISBN 3-900051-07-0
>>  Platform: i386-pc-mingw32/i386 (32-bit)
>>  
>>
>>  >  install.packages("sp")
>>  Installing package(s) into ‘C:\Users\Jon\Documents/R/win-library/2.12’
>>  (as ‘lib’ is unspecified)
>>  --- Please select a CRAN mirror for use in this session ---
>>  provo con l'URL
>>  'http://cran.at.r-project.org/bin/windows/contrib/2.12/sp_0.9-76.zip'
>>  Content type 'application/zip' length 997444 bytes (974 Kb)
>>  URL aperto
>>  downloaded 974 Kb
>>
>>  package 'sp' successfully unpacked and MD5 sums checked
>>  Warning: cannot remove prior installation of package 'sp'
>>
>>  The downloaded packages are in
>>  C:\Users\Jon\AppData\Local\Temp\RtmpCTJeBk\downloaded_packages
>>  >  library(sp)
>>  Errore in library(sp) : non c'è alcun pacchetto chiamato 'sp'
>>  >
>>
>>  The error message is the same as earlier, there is no package called
>>  "sp", the attempt to install it again removed the old version except
>>  for the .dll.
>>
>>  Jon
>
>  Did you have it open at the time?  Windows won't let open files be
>  removed, so that could have caused the problem.  If it's not that, it
>  could be a permissions problem.  Have you tried running R as
>  administrator for the install?
Yes, I had it open. In this case it was intentional to give a
reproducible example in case something had changed in the new version,
in other cases I have had to wait for 2 days before I could reinstall a
package. It seems the .dll is the one causing the problem, so wouldnt it
be possible to test if this file can be unlinked before trying to unlink
the complete directory in utils:::unpackPkgZip? Then the package should
be left untouched if it is in use, and not partly deleted as today.


I don't know.  Perhaps we could try to rename the folder; if that fails, 
abort the whole thing.  If that succeeds but something later fails, then 
remove all the new stuff and restore the old folder.  Do you know of a 
better test?


Duncan Murdoch


I know that it is possible to avoid this problem by not installing a
package in use, but
1) it seems only to affect packages with .dll's, so some packages can be
reinstalled while in use
2) you dont always know if a dependent package will download a new
version of an installed package

Best wishes,
Jon





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listi

Re: [R] box-and-whisker plots based on summary not data

2010-12-20 Thread Matthew Vernon
Matthew Vernon  writes:

> Is it possible to produce box-and-whisker plots given that I have the
> median, interquartile and 5/95th centile values, but not the data from
> which they come?

The answer, which came from Steve Ellison (thanks!) is to note that
"stats" is the only bit of the "z" argument to bxp that has to be
present, so given a data file with columns year,mean,median,centiles,
something like this works:

# transform data so the rows are the various centiles in order
# there's probably a more elegant approach!
 bsr <- matrix(allobs[,c(4,5,3,6,7)],nrow=5,byrow=TRUE)
# column 1 is the year, which is our factor
 bsbox <- list( stats=bsr,names=allobs$V1)
 bxp(bsbox,xlab="Year",ylab="Number of cattle per batch")

I thought I'd follow-up so the answer to my question will be in the
archives.

Thanks,

Matthew

-- 
Matthew Vernon, Research Fellow
Ecology and Epidemiology Group,
University of Warwick
http://blogs.warwick.ac.uk/mcvernon

__
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] Defining Two-dimensional Separable Variance-Covariance Structure in nlme Package

2010-12-20 Thread Muhammad Yaseen
*Hello All,*
*
*
*I'd highly appreciate if someone can explain the way of defining
"Two-dimensional Separable Variance-Covariance Structure in nlme Package".
Thanks*
*
*
*
*
-- 
*

Muhammad Yaseen
*

[[alternative HTML version deleted]]

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


Re: [R] install.packages() - old version deleted, new version did not install

2010-12-20 Thread Jon Olav Skoien

On 12/20/2010 1:30 PM, Uwe Ligges wrote:



On 20.12.2010 09:41, Jon Olav Skoien wrote:

On 12/17/2010 6:22 PM, Duncan Murdoch wrote:

On 17/12/2010 11:13 AM, Jon Olav Skoien wrote:

Dear list,

(R 2.12.0, Windows 7, 64bit)

I recently tried to install a new package ("spacetime"), that 
depends on

"sp" among others. I already had the last one installed, but there was
probably a newer version on CRAN, so the command
> install.packages("spacetime")
also gave me:
also installing the dependencies ‘sp’, ‘zoo’, ‘xts’

sp was already loaded in this session, so installation failed:
package 'sp' successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package 'sp'

Unfortunately, the warning should rather say:
"cannot completely remove prior installation of package 'sp'"
R managed to remove most of the prior installation of sp, except 
for the
.dll. I could go on using sp in the existing sessions, but not load 
the
package in a new session or open the help pages. This has happened 
to me

several times, and the only solution I have found to this is to close
all R-sessions and install the package again. This is normally ok, but
this time I had some long-time computations running in another 
R-session

that I did not want to interrupt. For the next time, is there a way to
reinstall a package without interrupting running R-sessions?

For me it seems like the cause of the problem could have been 
solved by

checking if the .dll can be removed before removing the rest of the
package, by adding something like the following in 
utils:::unpackPkgZip?

if (unlink(paste(instPath,"/libs/x64/sp.dll", sep = "")) != 0)
warning("cannot remove...")
before
ret<- unlink(instPath, recursive = TRUE) (line 95)
x64 in the path would have to be changed to something architecture
dependent...



Could you try out the new 2.12.1 release? I recall hearing that
something like this had changed, but I can't spot the NEWS item right
now.

Duncan Murdoch


It seems it didnt change yet...
I installed 2.12.1 (on a different computer, still Windows, but Vista
and 32 bit), and after installing and loading sp in one session, I
opened a new session and got:

R version 2.12.1 (2010-12-16)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-pc-mingw32/i386 (32-bit)


> install.packages("sp")
Installing package(s) into ‘C:\Users\Jon\Documents/R/win-library/2.12’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
provo con l'URL
'http://cran.at.r-project.org/bin/windows/contrib/2.12/sp_0.9-76.zip'
Content type 'application/zip' length 997444 bytes (974 Kb)
URL aperto
downloaded 974 Kb

package 'sp' successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package 'sp'

The downloaded packages are in
C:\Users\Jon\AppData\Local\Temp\RtmpCTJeBk\downloaded_packages
> library(sp)
Errore in library(sp) : non c'è alcun pacchetto chiamato 'sp'
>

The error message is the same as earlier, there is no package called
"sp", the attempt to install it again removed the old version except for
the .dll.




Which suggests there may be another R session that has the package 
loaded (i.e. the dll locked).


Just close all your R sessions and try again.

Uwe Ligges



Yes, I know. The question was whether there is another way of 
reinstalling the missing parts, or if there is a way of avoiding that 
the package gets partly deleted when install.packages is called with the 
package itself or a dependent package.


It seems like the answer to the first is no, but a fix for the second 
one could save some trouble.


Cheers,
Jon

__
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] install.packages() - old version deleted, new version did not install

2010-12-20 Thread Jon Olav Skoien

On 12/20/2010 1:43 PM, Duncan Murdoch wrote:

Jon Olav Skoien wrote:

On 12/17/2010 6:22 PM, Duncan Murdoch wrote:

On 17/12/2010 11:13 AM, Jon Olav Skoien wrote:

Dear list,

(R 2.12.0, Windows 7, 64bit)

I recently tried to install a new package ("spacetime"), that 
depends on

"sp" among others. I already had the last one installed, but there was
probably a newer version on CRAN, so the command

install.packages("spacetime")

also gave me:
also installing the dependencies ‘sp’, ‘zoo’, ‘xts’

sp was already loaded in this session, so installation failed:
package 'sp' successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package 'sp'

Unfortunately, the warning should rather say:
"cannot completely remove prior installation of package 'sp'"
R managed to remove most of the prior installation of sp, except 
for the
.dll. I could go on using sp in the existing sessions, but not load 
the
package in a new session or open the help pages. This has happened 
to me

several times, and the only solution I have found to this is to close
all R-sessions and install the package again. This is normally ok, but
this time I had some long-time computations running in another 
R-session

that I did not want to interrupt. For the next time, is there a way to
reinstall a package without interrupting running R-sessions?

For me it seems like the cause of the problem could have been 
solved by

checking if the .dll can be removed before removing the rest of the
package, by adding something like the following in 
utils:::unpackPkgZip?

if (unlink(paste(instPath,"/libs/x64/sp.dll", sep = "")) != 0)
warning("cannot remove...")
before
ret<- unlink(instPath, recursive = TRUE) (line 95)
x64 in the path would have to be changed to something architecture
dependent...


Could you try out the new 2.12.1 release? I recall hearing that 
something like this had changed, but I can't spot the NEWS item 
right now.


Duncan Murdoch


It seems it didnt change yet...
I installed 2.12.1 (on a different computer, still Windows, but Vista 
and 32 bit), and after installing and loading sp in one session, I 
opened a new session and got:


R version 2.12.1 (2010-12-16)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-pc-mingw32/i386 (32-bit)


> install.packages("sp")
Installing package(s) into ‘C:\Users\Jon\Documents/R/win-library/2.12’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
provo con l'URL 
'http://cran.at.r-project.org/bin/windows/contrib/2.12/sp_0.9-76.zip'

Content type 'application/zip' length 997444 bytes (974 Kb)
URL aperto
downloaded 974 Kb

package 'sp' successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package 'sp'

The downloaded packages are in
C:\Users\Jon\AppData\Local\Temp\RtmpCTJeBk\downloaded_packages
> library(sp)
Errore in library(sp) : non c'è alcun pacchetto chiamato 'sp'
>

The error message is the same as earlier, there is no package called 
"sp", the attempt to install it again removed the old version except 
for the .dll.


Jon


Did you have it open at the time?  Windows won't let open files be 
removed, so that could have caused the problem.  If it's not that, it 
could be a permissions problem.  Have you tried running R as 
administrator for the install?
Yes, I had it open. In this case it was intentional to give a 
reproducible example in case something had changed in the new version, 
in other cases I have had to wait for 2 days before I could reinstall a 
package. It seems the .dll is the one causing the problem, so wouldnt it 
be possible to test if this file can be unlinked before trying to unlink 
the complete directory in utils:::unpackPkgZip? Then the package should 
be left untouched if it is in use, and not partly deleted as today.


I know that it is possible to avoid this problem by not installing a 
package in use, but
1) it seems only to affect packages with .dll's, so some packages can be 
reinstalled while in use
2) you dont always know if a dependent package will download a new 
version of an installed package


Best wishes,
Jon

__
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] Turning a Variable into String

2010-12-20 Thread Paolo Rossi
Thank you very much to the both of you

Paolo



On 20 December 2010 00:35, Duncan Murdoch  wrote:

> On 19/12/2010 7:21 PM, Paolo Rossi wrote:
>
>> I would like to know how to turn a variable into a string. I have tried
>> as.symbol and as.name but it doesnt work for what I'd like to do
>>
>> Essentially, I'd like to feed the function below with two variables. This
>> works fine in the bit working out number of elements in each variable.
>>
>> In the print(sprintf("OK with %s and %s\n", var1, var2))  line I would
>> like
>> var1 and var2 to be magically substituted with a string containing the
>> name
>> of var1 and name of var2.
>>
>
> The name of var1 is var1, so I assume you mean the expression passed to
> your function and bound to var1.  In that case, what you want is
>
> deparse(substitute(var1))
>
> Watch out:  if the expression is really long, that can be a vector with
> more than one element.  See ?deparse for ways to deal with that.
>
> Duncan Murdoch
>
>
>> Thanks in advance
>>
>> Paolo
>>
>>
>>
>> haveSameLength<- function(var1, var2) {
>>  if (length(var1)==length(var2))
>>   {
>>print(sprintf("OK with %s and %s\n", var1, var2))
>>  } else {
>>print("Problems!!")
>>  }
>> }
>>
>>[[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

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


Re: [R] transposing panel data

2010-12-20 Thread Ben Bolker
taby gathoni  yahoo.com> writes:

> 
> I am currently trying to transpose some large panel data set 
> ie transposing multiple rows in into a single
> column. instead the transpose functionality transposes
> all rows into columns. my sample data set looks
> like below:

  Try the melt and cast functions in the reshape (or reshape2)
packages (reshape2 may be faster).  It may take a bit of work
to get the syntax right (try it out on a small subset of your
data).

  Ben Bolker

__
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] For-loop

2010-12-20 Thread jim holtman
try this:

> # create indexing vector to select 3 adjacent columns
> indx <- sapply(seq(1, 36, 3), seq, length = 3)
> # process each row of the table
> ans <- t(apply(data, 1, function(.row){
+ # use indx to sum up the columns
+ apply(indx, 2, function(.indx){
+ sum(.row[.indx])
+ })
+ }))
> ans
 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[1,]   18   63  108  153  198  243  189   36   81   126   171   216
[2,]   21   66  111  156  201  246  192   39   84   129   174   219
[3,]   24   69  114  159  204  249  195   42   87   132   177   222
[4,]   27   72  117  162  207  252  198   45   90   135   180   225
[5,]   30   75  120  165  210  255  102   48   93   138   183   228



On Mon, Dec 20, 2010 at 5:48 AM, Anne-Christine Mupepele
 wrote:
> Hi,
> I have the following problem:
>
> I have a data.frame with 36 sample sites (colums) for which I have covariates 
> in 3 categories: Area, Month and River. Each Area consists of 3 rivers, which 
> were sampled over 3 month. Now I want to fuse River 1-3 for one area in one 
> month. To get a data.frame with 12 colums.
> I am trying to do a "for loop" (which may be a complicated solution, but I 
> don't see an easier way), which is not working, apparently because a[,ij] or 
> a[,c(i,j)] is not working as a definition of the matrix with a double 
> condition in the colums.
> How can  I make it work or what would be an easier solution?
>
> Thank you for your help,
> Anne
>
> data=data.frame(matrix(1:99,nrow=5,ncol=36))
> colnames(data)=c(paste("plot",1:36))
> cov=data.frame(rep(1:3,12),c(rep("Jan",12),rep("Feb",12),rep("Mar",12)),rep(c(1,1,1,2,2,2,3,3,3,4,4,4),3))
> dimnames(cov)=list(colnames(data),c("River","Month","Area"))
>
> ###loop###
> a=matrix(nrow=dim(data)[1],ncol=length(levels(factor(cov$Month)))*length(levels(factor(cov$Area
>
>  for(i in 1:length(levels(factor(cov$Month
>  {
>  for(j in 1:length(levels(factor(cov$Area
>  {
> a[,ij]=as.numeric(rowSums(data[,factor(cov$Month)==levels(factor(cov$Month))[i]&factor(cov$Area)==levels(factor(cov$Area))[j]]))
> }
> }
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

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


[R] Odp: For-loop

2010-12-20 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 20.12.2010 11:48:51:

> Hi,
> I have the following problem:
> 
> I have a data.frame with 36 sample sites (colums) for which I have 
covariates 
> in 3 categories: Area, Month and River. Each Area consists of 3 rivers, 
which 
> were sampled over 3 month. Now I want to fuse River 1-3 for one area in 
one 
> month. To get a data.frame with 12 colums. 
> I am trying to do a "for loop" (which may be a complicated solution, but 
I 
> don't see an easier way), which is not working, apparently because 
a[,ij] or a
> [,c(i,j)] is not working as a definition of the matrix with a double 
condition
> in the colums. 
> How can  I make it work or what would be an easier solution?
> 
> Thank you for your help,
> Anne
> 
> data=data.frame(matrix(1:99,nrow=5,ncol=36))
> colnames(data)=c(paste("plot",1:36))
> 
cov=data.frame(rep(1:3,12),c(rep("Jan",12),rep("Feb",12),rep("Mar",12)),rep(c
> (1,1,1,2,2,2,3,3,3,4,4,4),3))
> dimnames(cov)=list(colnames(data),c("River","Month","Area"))
> 
> ###loop###
> a=matrix(nrow=dim(data)[1],ncol=length(levels(factor(cov$Month)))*length
> (levels(factor(cov$Area
> 
>  for(i in 1:length(levels(factor(cov$Month 
>  {
>  for(j in 1:length(levels(factor(cov$Area 
>  {
> 
a[,ij]=as.numeric(rowSums(data[,factor(cov$Month)==levels(factor(cov$Month))
> [i]&factor(cov$Area)==levels(factor(cov$Area))[j]]))
> }
> }

I am not exactly sure what you want to do. What operation is fuse? If it 
is sum so having you data you can do

area<-rep(1:12, each=3)
data.t<-t(data)
> aggregate(data.t, list(area), sum)
   Group.1  V1  V2  V3  V4  V5
11  18  21  24  27  30
22  63  66  69  72  75
33 108 111 114 117 120
44 153 156 159 162 165
55 198 201 204 207 210
66 243 246 249 252 255
77 189 192 195 198 102
88  36  39  42  45  48
99  81  84  87  90  93
10  10 126 129 132 135 138
11  11 171 174 177 180 183
12  12 216 219 222 225 228
> t(aggregate(data.t, list(area), sum))
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
Group.1123456789101112
V118   63  108  153  198  243  189   36   81   126   171   216
V221   66  111  156  201  246  192   39   84   129   174   219
V324   69  114  159  204  249  195   42   87   132   177   222
V427   72  117  162  207  252  198   45   90   135   180   225
V530   75  120  165  210  255  102   48   93   138   183   228

but then there is Month value, which is not apparent from your example. 
Maybe

t(aggregate(data.t, list(area, data.t$Month), sum))

Could do the trick but you probably need to show us maybe str and/or head 
of your real data.

Regards
Petr

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

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


Re: [R] Alternative to extended recode sintax? Bug?

2010-12-20 Thread David Winsemius


On Dec 20, 2010, at 12:54 AM, Luca Meyer wrote:

All right, I get it now: lubridate's week() define weeks from  
Thursday till the following Wednesday. You'd probably agree with me  
that it's a bit strange what it is going to do over the turn of the  
year:


y <-  
as.POSIXct(c("2010-12-27","2010-12-28","2010-12-29","2010-12-30","2010-12-31","2011-01-01","2011-01-02","2011-01-03","2011-01-04","2011-01-05","2011-01-06","2011-01-07","2011-01-08","2011-01-09","2011-01-10","2011-01-11","2010-01-12","2010-01-13","2010-01-14"))

week(y)

[1] 52 52 52 53 53  1  1  1  1  1  1  2  2  2  2  2  2  2  3

Why would the first week of the year be made of 6 days and the turn  
from week 1 to week 2 on the night between Thursday and Friday and  
not Wednesday and Friday like every other week?


weeks in lubridate start on whatever day of the week is the first of  
that year.


If you want a Monday starting day (or the option to change to another  
starting day), then package chron has such facilities.





Cheers,
Luca



Il giorno 19/dic/2010, alle ore 18.14, Uwe Ligges ha scritto:




On 19.12.2010 13:20, David Winsemius wrote:


On Dec 19, 2010, at 5:11 AM, Luca Meyer wrote:

Something goes wrong with the week function of the lubridate  
package:



x= as.POSIXct(factor(c("2010-12-15 17:28:27",

+ "2010-12-15 17:32:34",
+ "2010-12-15 18:48:39",
+ "2010-12-15 19:25:00",
+ "2010-12-16 08:00:00",
+ "2010-12-16 08:25:49",
+ "2010-12-16 09:00:00")))

require(lubridate)



weekdays(x)

[1] "Mercoledì" "Mercoledì" "Mercoledì" "Mercoledì" "Giovedì"
"Giovedì" "Giovedì"

week(x)

[1] 50 50 50 50 51 51 51


But 2010-12-15 is a Wednesday and 2010-12-16 is a Thursday.




Together with the description of ?week this shows that lubridate's  
week() function works as documented rather than as expected by Luca  
Meyer.


Uwe Ligges




David Winsemius, MD
West Hartford, CT

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


[R] How to read japanese characters from a database/file

2010-12-20 Thread vikrant

Hi,

   I am using rodbc package to  connect with Sql Server 2005. I have a table
which contains some japanese characters. Now I want to use these japanese
characters as labels in simple x y plot?


Here is the data in the table 

サービスデスク 35355
データネットワーク   8417

I want to read this data from database table and plot it using R and give
xlabels as japanese words .
How is it possible in R ??
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-read-japanese-characters-from-a-database-file-tp3095466p3095466.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] install.packages() - old version deleted, new version did not install

2010-12-20 Thread Duncan Murdoch

Jon Olav Skoien wrote:

On 12/17/2010 6:22 PM, Duncan Murdoch wrote:

On 17/12/2010 11:13 AM, Jon Olav Skoien wrote:

Dear list,

(R 2.12.0, Windows 7, 64bit)

I recently tried to install a new package ("spacetime"), that depends on
"sp" among others. I already had the last one installed, but there was
probably a newer version on CRAN, so the command

install.packages("spacetime")

also gave me:
also installing the dependencies ‘sp’, ‘zoo’, ‘xts’

sp was already loaded in this session, so installation failed:
package 'sp' successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package 'sp'

Unfortunately, the warning should rather say:
"cannot completely remove prior installation of package 'sp'"
R managed to remove most of the prior installation of sp, except for the
.dll. I could go on using sp in the existing sessions, but not load the
package in a new session or open the help pages. This has happened to me
several times, and the only solution I have found to this is to close
all R-sessions and install the package again. This is normally ok, but
this time I had some long-time computations running in another R-session
that I did not want to interrupt. For the next time, is there a way to
reinstall a package without interrupting running R-sessions?

For me it seems like the cause of the problem could have been solved by
checking if the .dll can be removed before removing the rest of the
package, by adding something like the following in utils:::unpackPkgZip?
if (unlink(paste(instPath,"/libs/x64/sp.dll", sep = "")) != 0)
warning("cannot remove...")
before
ret<- unlink(instPath, recursive = TRUE) (line 95)
x64 in the path would have to be changed to something architecture
dependent...


Could you try out the new 2.12.1 release? I recall hearing that 
something like this had changed, but I can't spot the NEWS item right 
now.


Duncan Murdoch


It seems it didnt change yet...
I installed 2.12.1 (on a different computer, still Windows, but Vista 
and 32 bit), and after installing and loading sp in one session, I 
opened a new session and got:


R version 2.12.1 (2010-12-16)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-pc-mingw32/i386 (32-bit)


 > install.packages("sp")
Installing package(s) into ‘C:\Users\Jon\Documents/R/win-library/2.12’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
provo con l'URL 
'http://cran.at.r-project.org/bin/windows/contrib/2.12/sp_0.9-76.zip'

Content type 'application/zip' length 997444 bytes (974 Kb)
URL aperto
downloaded 974 Kb

package 'sp' successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package 'sp'

The downloaded packages are in
C:\Users\Jon\AppData\Local\Temp\RtmpCTJeBk\downloaded_packages
 > library(sp)
Errore in library(sp) : non c'è alcun pacchetto chiamato 'sp'
 >

The error message is the same as earlier, there is no package called 
"sp", the attempt to install it again removed the old version except for 
the .dll.


Jon


Did you have it open at the time?  Windows won't let open files be 
removed, so that could have caused the problem.  If it's not that, it 
could be a permissions problem.  Have you tried running R as 
administrator for the install?


Duncan Murdoch

__
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] install.packages() - old version deleted, new version did not install

2010-12-20 Thread Uwe Ligges



On 20.12.2010 09:41, Jon Olav Skoien wrote:

On 12/17/2010 6:22 PM, Duncan Murdoch wrote:

On 17/12/2010 11:13 AM, Jon Olav Skoien wrote:

Dear list,

(R 2.12.0, Windows 7, 64bit)

I recently tried to install a new package ("spacetime"), that depends on
"sp" among others. I already had the last one installed, but there was
probably a newer version on CRAN, so the command
> install.packages("spacetime")
also gave me:
also installing the dependencies ‘sp’, ‘zoo’, ‘xts’

sp was already loaded in this session, so installation failed:
package 'sp' successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package 'sp'

Unfortunately, the warning should rather say:
"cannot completely remove prior installation of package 'sp'"
R managed to remove most of the prior installation of sp, except for the
.dll. I could go on using sp in the existing sessions, but not load the
package in a new session or open the help pages. This has happened to me
several times, and the only solution I have found to this is to close
all R-sessions and install the package again. This is normally ok, but
this time I had some long-time computations running in another R-session
that I did not want to interrupt. For the next time, is there a way to
reinstall a package without interrupting running R-sessions?

For me it seems like the cause of the problem could have been solved by
checking if the .dll can be removed before removing the rest of the
package, by adding something like the following in utils:::unpackPkgZip?
if (unlink(paste(instPath,"/libs/x64/sp.dll", sep = "")) != 0)
warning("cannot remove...")
before
ret<- unlink(instPath, recursive = TRUE) (line 95)
x64 in the path would have to be changed to something architecture
dependent...



Could you try out the new 2.12.1 release? I recall hearing that
something like this had changed, but I can't spot the NEWS item right
now.

Duncan Murdoch


It seems it didnt change yet...
I installed 2.12.1 (on a different computer, still Windows, but Vista
and 32 bit), and after installing and loading sp in one session, I
opened a new session and got:

R version 2.12.1 (2010-12-16)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-pc-mingw32/i386 (32-bit)


 > install.packages("sp")
Installing package(s) into ‘C:\Users\Jon\Documents/R/win-library/2.12’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
provo con l'URL
'http://cran.at.r-project.org/bin/windows/contrib/2.12/sp_0.9-76.zip'
Content type 'application/zip' length 997444 bytes (974 Kb)
URL aperto
downloaded 974 Kb

package 'sp' successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package 'sp'

The downloaded packages are in
C:\Users\Jon\AppData\Local\Temp\RtmpCTJeBk\downloaded_packages
 > library(sp)
Errore in library(sp) : non c'è alcun pacchetto chiamato 'sp'
 >

The error message is the same as earlier, there is no package called
"sp", the attempt to install it again removed the old version except for
the .dll.




Which suggests there may be another R session that has the package 
loaded (i.e. the dll locked).


Just close all your R sessions and try again.

Uwe Ligges





Jon

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


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


Re: [R] R is not running well

2010-12-20 Thread Uwe Ligges



On 20.12.2010 10:29, Roslina Zakaria wrote:

Hi,

I'm working on windows 7.  Recently I install the latest R and also use together
with Tinn-R but it is not working well.  I got the following message.  I have
tried saving the Rprofile as suggested by the R forum, but still it is not
running.  What should I do?


source(.trPaths[5], echo=TRUE, max.deparse.length=150)

Error in source(.trPaths[5], echo = TRUE, max.deparse.length = 150) :
   object '.trPaths' not found



R is running well, Tinn-R is not. Please ask the Tinn-R maintainers or 
read the list archives where this has been discussed before.


Uwe Ligges






[[alternative HTML version deleted]]




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


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


[R] Metafor package

2010-12-20 Thread petretta

I have some question about metafor package.

I'm interest to perform a random effect meta-analysis of proportion  
(single group summary of prevalence of disease in a population as  
reported by different study)

It ask:
1. "PFT":  The Freeman-Tukey double arcsine transformed proportion is  
reported to be equal to 1/2*(asin(sqrt(xi/(ni+1))) +  
asin(sqrt((xi+1)/(ni+1. Hovewer, i also found the same formula but  
without 1/2*.


2. how "vi", the corresponding (estimated) sampling variance is  
calculated? (i.e. the formula used to estimate "vi")


3. it is possible to return a forest plot with the backtransformed  
value of proportion, confidenc interval and weight and not with the  
transformed value after performing rma.uni?


Many thanks

Mario Petretta
Dipartimento di Medicina Clinica Scienze Cardiovascolari e Immunologiche
Facoltà di Medicina e Chirurgia
Università di Napoli Federico II
081 - 7462233

__
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] Modifying effect display (effects package)

2010-12-20 Thread Anna Berthinussen

Hi,

I am using the effects package and plot() to produce an effect plot  
for a higher order term from a GLM. However, I need to modify the  
graph it produces by removing the tick marks and axes from the right  
and top of the graph, and moving the remaining tick marks inside the  
axes. Does anybody know how to do this? I can't find a way to modify  
the plot.


Thanks
Anna

__
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] transposing panel data

2010-12-20 Thread taby gathoni
I am currently trying to transpose some large panel data set ie transposing 
multiple rows in into a single column. instead the transpose functionality 
transposes all rows into columns. my sample data set looks like below:

 
 
 
 
 
 
  ACCT_NUM
  ACCOUNT_NAME
  TRAN_AMT
  DATE
  EMPLOYER
 
 
  101913
  GK
  7489
  30-Apr-10
  PENSION
 
 
  101913
  GK
  7489
  30-May-10
  PENSION
 
 
  101913
  GK
  7489
  30-Jun-10
  PENSION
 
 
  101913
  GK
  7489
  31-Jul-10
  PENSION
 
 
  101913
  GK
  7489
  31-Jan-10
  PENSION
 
 
  101913
  GK
  7489
  28-Feb-10
  PENSION
 
 
  101913
  GK
  7489
  31-Mar-10
  PENSION
 
 
  101913
  GK
  7489
  30-Oct-10
  PENSION
 
 
  101913
  GK
  7489
  30-Aug-10
  PENSION
 
 
  101913
  GK
  7489
  23-Sep-10
  PENSION
 
 
  101913
  GK
  53772
  30-Sep-10
  MKU
 
 
  101920
  CKM
  22739.7
  31-Jul-10
  POLICE
 
 
  101920
  CKM
  18327.6
  30-Sep-10
  POLICE
 
 
  101920
  CKM
  8840.4
  31-Mar-10
  POLICE
 
 
  101920
  CKM
  8986.25
  24-May-10
  POLICE
 
 
  101920
  CKM
  34252.2
  30-Jun-10
  POLICE
 
 
  101920
  CKM
  8913.35
  30-Apr-10
   POLICE
 

 
Ideally i would like a row to have one row of  ACCT_NUM and TranAmount and 
Date be transposed to columns.

Thanks









Kind regards,
  Tabitha Mundia ,  Project Management  Office,   Equity Bank 
Limited,P.O. Box 75104-00200
   Head Office, Upper  hill,   NHIF BLDG, 14th  Floor,   Nairobi, Kenya 
 Direct Extension : +254732112721  Mobile: +254722309538  
 Email: tabitha.mun...@equitybank.co.keskype ID: twamaeYahoo ID: 
tabygath...@yahoo.com


An idea not coupled with action will never get any bigger than the brain cell 
it occupied.
Arnold Glasgow
..
"Attempt something large enough that failure is guaranteed…unless God steps 
in!"


--- On Mon, 12/20/10, Kohleth Chia  wrote:

From: Kohleth Chia 
Subject: [R] package "arules" - 'transpose' of the transactions
To: r-help@r-project.org
Date: Monday, December 20, 2010, 8:41 AM

Suppose this is my list of
 transactions:


set.seed(200)

tran=random.transactions(100,3)

inspect(tran)

  items    transactionID
1 {item80}        trans1
2 {item8,
   item20}        trans2
3 {item28}        trans3


I want to get the 'transpose' of the data, i.e.

  transactionID  items
1 {trans2}        item8
2 {trans2}        item20
3 {trans3}        item28
4 {trans1}        item80


I tried converting tran into a matrix, then transpose it, then convert it
back to transactions. But my dataset is actually very very large, so I
wonder if there is any faster method?

Thanks

-- 
KC

    [[alternative HTML version deleted]]

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









  


  
[[alternative HTML version deleted]]

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


[R] For-loop

2010-12-20 Thread Anne-Christine Mupepele
Hi,
I have the following problem:

I have a data.frame with 36 sample sites (colums) for which I have covariates 
in 3 categories: Area, Month and River. Each Area consists of 3 rivers, which 
were sampled over 3 month. Now I want to fuse River 1-3 for one area in one 
month. To get a data.frame with 12 colums. 
I am trying to do a "for loop" (which may be a complicated solution, but I 
don't see an easier way), which is not working, apparently because a[,ij] or 
a[,c(i,j)] is not working as a definition of the matrix with a double condition 
in the colums. 
How can  I make it work or what would be an easier solution?

Thank you for your help,
Anne

data=data.frame(matrix(1:99,nrow=5,ncol=36))
colnames(data)=c(paste("plot",1:36))
cov=data.frame(rep(1:3,12),c(rep("Jan",12),rep("Feb",12),rep("Mar",12)),rep(c(1,1,1,2,2,2,3,3,3,4,4,4),3))
dimnames(cov)=list(colnames(data),c("River","Month","Area"))

###loop###
a=matrix(nrow=dim(data)[1],ncol=length(levels(factor(cov$Month)))*length(levels(factor(cov$Area

 for(i in 1:length(levels(factor(cov$Month  
 {
 for(j in 1:length(levels(factor(cov$Area 
 {
a[,ij]=as.numeric(rowSums(data[,factor(cov$Month)==levels(factor(cov$Month))[i]&factor(cov$Area)==levels(factor(cov$Area))[j]]))
}
}

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


[R] contourplot help

2010-12-20 Thread Andre Nathan
Hello

I'm using the following call to create a contourplot:

library(lattice)
m <- as.matrix(read.table("data.txt"))

contourplot(m[,3] ~ m[,2] * -m[,1],
at = c(1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1),
scales = list(x = list(log = 10,
   labels = c("1", "10", "100"),
   at = c(1, 10, 100)),
  y = list(labels = c("14", "12", "10", "8",
  "6", "4", "2")),
   at = c(-14, -12, -10, -8, -6, -4,
  -2)),
labels = c(expression(10^-6), expression(10^-5),
   expression(10^-4), expression(10^-3),
   expression(10^-2), expression(10^-1),
   expression(10^0)),
xlim = c(0.75, 10^2),
xlab = "Out-degree", ylab = "In-degree")


Which gives the the output in the file below

  http://ompldr.org/vNm4xag/contour.eps

As it can be seen, the level labels are not displayed nicely because
there's not enough room for them. Also, the 10^-1 label is not
displayed.

Is there a way for me to hardcode the position of each label? I tried
setting labels = F and then calling text() for each one, but that
doesn't work.

If that's not possible, one option would be to color each level line
differently and then add a legend. Is it possible to do that?

Finally, how can I remove the tick marks from the top and right axes?

Thanks,
Andre

__
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] barplot: width of label

2010-12-20 Thread Jim Lemon

On 12/20/2010 02:13 AM, fransiepansiekevertje wrote:

Hello,
I try to make barplots with rather wide labels. A simplified example of
this:

x<- c(12, 33, 56, 67, 15, 66)
names(x)<- c('Richard with a long surname','Minnie with a long
name,'Albert','Helen','Joe','Kingston')
barplot(x, las = 2)

Now the label 'Richard with a long surname' is too long to fit beneath the
bars. A simple solution would be enlarge the space for the labels by
positioning the bar region higher. But I cannot find how to do this. Please
Help!


Hi Frans,
Does this do what you want?

library(plotrix)
barp(x,names.arg=names(x),staxx=TRUE)

Jim

__
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] Layout of mulitpage conditioned lattice plots

2010-12-20 Thread Dieter Menne


David Winsemius wrote:
> 
> 
> Here's my latest guess at what you may want:
> 
> pdf(file="multpage.pdf")
> xyplot(val~time|subj + comp, data=dt,type="l",
>  layout=c(3,5, 3),
>  skip=rep(c(rep(FALSE,13), TRUE, TRUE), 3) )
> dev.off()
> 
> 

Not really, but "skip" was the right idea. I added another idea of Deepayan
from a cited thread, first to plot all, then to update indexed parts with a
computed skip.

The code has become a bit lengthy because I added a more flexible
orphan-avoiding scheme.

Dieter



library(lattice)
# Distribute panels on page, so that each panel has the same size, 
# even on last page
# Use adjustCol to adjust colPerPage to avoid orphans on the last page
# 

# - adjustedColPerPage
-
adjustedColPerPage = function(colPerPage, ncols){
  # Allow for 20% or plus/minus 2
  searchRange = max(2L,as.integer(colPerPage*0.2))
  colsPerPage = (colPerPage-searchRange):(colPerPage+searchRange)
  nColLast = ncols %% colsPerPage
  nPages = (ncols %/% colsPerPage)+ as.integer(nColLast!=0)
  # Prefer solution with equal number on a page
  matchPage = which(nColLast==0)
  if (length(matchPage) >0) {
colsPerPage[matchPage[which.min(abs(matchPage-searchRange))]]
  } else {
colsPerPage[which.max(nColLast)] # not perfect
  }
}

# - xyPaged
--
xyPaged = function(x, adjustCol = FALSE, colPerPage = 5,main=NULL) {
  nrows = nlevels(x$comp) # This is not very general
  ncols = nlevels(x$subj) # 
  if (adjustCol) # try to get an alternative layout that fits the pages
better
  {
colPerPage = adjustedColPerPage(colPerPage,ncols)
main = paste(main," usedCol= ",colPerPage)
  }
  p = xyplot(val~time|subj+comp, data=x,type="l",
layout = c(colPerPage,nrows),main=main)
# http://r-project.markmail.org/thread/rcztoawll5kduw4x
  page = 1
  for (fromCol in seq(1,ncols,by=colPerPage)){
toCol = min(fromCol+colPerPage-1,ncols)
showCol = toCol %% colPerPage
skip = rep(FALSE,colPerPage)
if (showCol != 0) skip[(showCol+1):colPerPage] = TRUE
print(update(p[fromCol:toCol],skip=skip,sub=page))
page = page +1
  }
}

# Test 
testFrame  = expand.grid(adjustCol=c(FALSE,TRUE),
 nsubj=c(5,11,13),colPerPage=c(5,9,14) )

pdf(file="multpage.pdf")

for (i in 1:nrow(testFrame)) {
  test = testFrame[i,]
  dt = expand.grid(time=1:20,comp=LETTERS[1:3],subj=letters[1:test$nsubj])
  dt$val = rnorm(nrow(dt)) 
  with (test, xyPaged(dt,adjustCol, colPerPage,
main=paste("nsubj=",test$nsubj, " requestedCol= ",colPerPage)))
}
dev.off()

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Layout-of-mulitpage-conditioned-lattice-plots-tp3094581p3095284.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Alternative to extended recode sintax? Bug?

2010-12-20 Thread Uwe Ligges



On 20.12.2010 06:54, Luca Meyer wrote:

All right, I get it now: lubridate's week() define weeks from Thursday till the 
following Wednesday. You'd probably agree with me that it's a bit strange what 
it is going to do over the turn of the year:


y<- 
as.POSIXct(c("2010-12-27","2010-12-28","2010-12-29","2010-12-30","2010-12-31","2011-01-01","2011-01-02","2011-01-03","2011-01-04","2011-01-05","2011-01-06","2011-01-07","2011-01-08","2011-01-09","2011-01-10","2011-01-11","2010-01-12","2010-01-13","2010-01-14"))
week(y)

  [1] 52 52 52 53 53  1  1  1  1  1  1  2  2  2  2  2  2  2  3

Why would the first week of the year be made of 6 days and the turn from week 1 
to week 2 on the night between Thursday and Friday and not Wednesday and Friday 
like every other week?



Well, it's the definition in that week() function from that package, if 
you don't like that definition, choose another one. I have not said that 
I like it, just that it seems to work as documented.


Uwe




Cheers,
Luca



Il giorno 19/dic/2010, alle ore 18.14, Uwe Ligges ha scritto:




On 19.12.2010 13:20, David Winsemius wrote:


On Dec 19, 2010, at 5:11 AM, Luca Meyer wrote:


Something goes wrong with the week function of the lubridate package:


x= as.POSIXct(factor(c("2010-12-15 17:28:27",

+ "2010-12-15 17:32:34",
+ "2010-12-15 18:48:39",
+ "2010-12-15 19:25:00",
+ "2010-12-16 08:00:00",
+ "2010-12-16 08:25:49",
+ "2010-12-16 09:00:00")))

require(lubridate)



weekdays(x)

[1] "Mercoledì" "Mercoledì" "Mercoledì" "Mercoledì" "Giovedì"
"Giovedì" "Giovedì"

week(x)

[1] 50 50 50 50 51 51 51


But 2010-12-15 is a Wednesday and 2010-12-16 is a Thursday.




Together with the description of ?week this shows that lubridate's week() 
function works as documented rather than as expected by Luca Meyer.

Uwe Ligges




__
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] incremental learning for LOESS time series model

2010-12-20 Thread ying zhang
Hi All,

 

I am currently working on some time series data, I know I can use
LOESS/ARIMA model. 

 

The  data is written to a vector whose length is 1000, which is a queue,
updating every 15 minutes,  

Thus the old data will pop out while the new data push in the vector.

 

I can rerun the whole model on a scheduler, e.g. retrain the model every 15
minutes, that is,  Use the whole 1000 value to train 

The LOESS model, However it is very inefficient, as every time only one
value is insert while another 999 vlaues still same as last time.

 

So how can I achieve better performance?

 

Many thanks

 

Ying

 

 

 


[[alternative HTML version deleted]]

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


[R] R is not running well

2010-12-20 Thread Roslina Zakaria
Hi,

I'm working on windows 7.  Recently I install the latest R and also use 
together 
with Tinn-R but it is not working well.  I got the following message.  I have 
tried saving the Rprofile as suggested by the R forum, but still it is not 
running.  What should I do?

> source(.trPaths[5], echo=TRUE, max.deparse.length=150)
Error in source(.trPaths[5], echo = TRUE, max.deparse.length = 150) : 
  object '.trPaths' not found



  
[[alternative HTML version deleted]]

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


Re: [R] Alternative to extended recode sintax? Bug?

2010-12-20 Thread Luca Meyer
All right, I get it now: lubridate's week() define weeks from Thursday till the 
following Wednesday. You'd probably agree with me that it's a bit strange what 
it is going to do over the turn of the year:

> y <- 
> as.POSIXct(c("2010-12-27","2010-12-28","2010-12-29","2010-12-30","2010-12-31","2011-01-01","2011-01-02","2011-01-03","2011-01-04","2011-01-05","2011-01-06","2011-01-07","2011-01-08","2011-01-09","2011-01-10","2011-01-11","2010-01-12","2010-01-13","2010-01-14"))
> week(y)
 [1] 52 52 52 53 53  1  1  1  1  1  1  2  2  2  2  2  2  2  3

Why would the first week of the year be made of 6 days and the turn from week 1 
to week 2 on the night between Thursday and Friday and not Wednesday and Friday 
like every other week?

Cheers,
Luca



Il giorno 19/dic/2010, alle ore 18.14, Uwe Ligges ha scritto:

> 
> 
> On 19.12.2010 13:20, David Winsemius wrote:
>> 
>> On Dec 19, 2010, at 5:11 AM, Luca Meyer wrote:
>> 
>>> Something goes wrong with the week function of the lubridate package:
>>> 
 x= as.POSIXct(factor(c("2010-12-15 17:28:27",
>>> + "2010-12-15 17:32:34",
>>> + "2010-12-15 18:48:39",
>>> + "2010-12-15 19:25:00",
>>> + "2010-12-16 08:00:00",
>>> + "2010-12-16 08:25:49",
>>> + "2010-12-16 09:00:00")))
 require(lubridate)
>> 
 weekdays(x)
>>> [1] "Mercoledì" "Mercoledì" "Mercoledì" "Mercoledì" "Giovedì"
>>> "Giovedì" "Giovedì"
 week(x)
>>> [1] 50 50 50 50 51 51 51
>> 
>> But 2010-12-15 is a Wednesday and 2010-12-16 is a Thursday.
>> 
> 
> 
> Together with the description of ?week this shows that lubridate's week() 
> function works as documented rather than as expected by Luca Meyer.
> 
> Uwe Ligges

__
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] install.packages() - old version deleted, new version did not install

2010-12-20 Thread Jon Olav Skoien

On 12/17/2010 6:22 PM, Duncan Murdoch wrote:

On 17/12/2010 11:13 AM, Jon Olav Skoien wrote:

Dear list,

(R 2.12.0, Windows 7, 64bit)

I recently tried to install a new package ("spacetime"), that depends on
"sp" among others. I already had the last one installed, but there was
probably a newer version on CRAN, so the command
> install.packages("spacetime")
also gave me:
also installing the dependencies ‘sp’, ‘zoo’, ‘xts’

sp was already loaded in this session, so installation failed:
package 'sp' successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package 'sp'

Unfortunately, the warning should rather say:
"cannot completely remove prior installation of package 'sp'"
R managed to remove most of the prior installation of sp, except for the
.dll. I could go on using sp in the existing sessions, but not load the
package in a new session or open the help pages. This has happened to me
several times, and the only solution I have found to this is to close
all R-sessions and install the package again. This is normally ok, but
this time I had some long-time computations running in another R-session
that I did not want to interrupt. For the next time, is there a way to
reinstall a package without interrupting running R-sessions?

For me it seems like the cause of the problem could have been solved by
checking if the .dll can be removed before removing the rest of the
package, by adding something like the following in utils:::unpackPkgZip?
if (unlink(paste(instPath,"/libs/x64/sp.dll", sep = "")) != 0)
warning("cannot remove...")
before
ret<- unlink(instPath, recursive = TRUE) (line 95)
x64 in the path would have to be changed to something architecture
dependent...



Could you try out the new 2.12.1 release? I recall hearing that 
something like this had changed, but I can't spot the NEWS item right 
now.


Duncan Murdoch


It seems it didnt change yet...
I installed 2.12.1 (on a different computer, still Windows, but Vista 
and 32 bit), and after installing and loading sp in one session, I 
opened a new session and got:


R version 2.12.1 (2010-12-16)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-pc-mingw32/i386 (32-bit)


> install.packages("sp")
Installing package(s) into ‘C:\Users\Jon\Documents/R/win-library/2.12’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
provo con l'URL 
'http://cran.at.r-project.org/bin/windows/contrib/2.12/sp_0.9-76.zip'

Content type 'application/zip' length 997444 bytes (974 Kb)
URL aperto
downloaded 974 Kb

package 'sp' successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package 'sp'

The downloaded packages are in
C:\Users\Jon\AppData\Local\Temp\RtmpCTJeBk\downloaded_packages
> library(sp)
Errore in library(sp) : non c'è alcun pacchetto chiamato 'sp'
>

The error message is the same as earlier, there is no package called 
"sp", the attempt to install it again removed the old version except for 
the .dll.


Jon

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